2026-11-06 08:28:04 +00:00
|
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
|
|
import threading
|
|
|
|
|
from dataclasses import dataclass
|
|
|
|
|
from pathlib import Path
|
|
|
|
|
|
|
|
|
|
import jinja2
|
2026-11-07 15:03:14 +00:00
|
|
|
from markupsafe import Markup
|
2026-11-06 08:28:04 +00:00
|
|
|
|
|
|
|
|
from .approving import Approving
|
2026-11-07 15:03:14 +00:00
|
|
|
from .artifacts import Touched
|
2026-11-06 08:28:04 +00:00
|
|
|
from .asking import Asking
|
|
|
|
|
from .batches import Pending
|
2026-11-07 15:03:14 +00:00
|
|
|
from .cleanup import Cleaning, Spool
|
2026-11-07 18:14:21 +00:00
|
|
|
from .denying import Denying
|
2026-11-06 08:28:04 +00:00
|
|
|
from .engines import Engines, Speech
|
|
|
|
|
from .events import Log, Watch
|
2026-11-07 15:03:14 +00:00
|
|
|
from .icons import sheet
|
2026-11-06 08:28:04 +00:00
|
|
|
from .inbox import Inbox
|
|
|
|
|
from .jobs import Jobs
|
|
|
|
|
from .language import Language, Model
|
|
|
|
|
from .ledger import Ledger, Marks, Reviews
|
|
|
|
|
from .mcp import Mcp
|
|
|
|
|
from .messaging import Messaging
|
|
|
|
|
from .names import Names
|
2026-11-07 17:46:39 +00:00
|
|
|
from .offices import Offices
|
2026-11-07 18:14:21 +00:00
|
|
|
from .requesting import Requesting
|
2026-11-06 08:28:04 +00:00
|
|
|
from .reviewing import Reviewing
|
|
|
|
|
from .rules import Rules
|
|
|
|
|
from .settings import Settings
|
|
|
|
|
from .signed import signing
|
|
|
|
|
from .skill_scripts import Runner
|
|
|
|
|
from .sources import Sources
|
|
|
|
|
from .timeline import Timeline
|
|
|
|
|
from .transcripts import Transcripts
|
2026-11-07 06:51:49 +00:00
|
|
|
from .tree import TREE_HEARTBEAT, Tree
|
2026-11-06 08:28:04 +00:00
|
|
|
from .view import View
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
|
|
|
class Places:
|
2026-11-07 06:51:49 +00:00
|
|
|
tree_file: Path
|
2026-11-06 08:28:04 +00:00
|
|
|
timers: Path
|
2026-11-07 15:03:14 +00:00
|
|
|
vendor: Path
|
|
|
|
|
cleanup: Path
|
2026-11-07 17:46:39 +00:00
|
|
|
offices: Path
|
2026-11-06 08:28:04 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def environment(templates: Path) -> jinja2.Environment:
|
2026-11-06 22:20:06 +00:00
|
|
|
env = jinja2.Environment(
|
2026-11-06 08:28:04 +00:00
|
|
|
loader=jinja2.FileSystemLoader(templates),
|
|
|
|
|
autoescape=True,
|
|
|
|
|
undefined=jinja2.StrictUndefined,
|
|
|
|
|
trim_blocks=True,
|
|
|
|
|
lstrip_blocks=True,
|
|
|
|
|
)
|
2026-11-06 22:20:06 +00:00
|
|
|
env.policies["json.dumps_kwargs"] = {"sort_keys": False}
|
|
|
|
|
return env
|
2026-11-06 08:28:04 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
@dataclass(frozen=True)
|
2026-11-07 18:14:21 +00:00
|
|
|
class Hub(Mcp, Reviewing, Asking, Messaging, Approving, Denying, Requesting, Cleaning, Offices, Inbox, Rules, Jobs, Sources, Timeline, View, Language):
|
2026-11-06 08:28:04 +00:00
|
|
|
council: Path
|
|
|
|
|
pages: Path
|
|
|
|
|
public_port: int
|
|
|
|
|
reviews: Reviews
|
|
|
|
|
asks: Ledger
|
|
|
|
|
decisions: Ledger
|
|
|
|
|
messages: Ledger
|
2026-11-07 18:14:21 +00:00
|
|
|
rule_requests: Ledger
|
2026-11-06 08:28:04 +00:00
|
|
|
uploads: Path
|
|
|
|
|
host_state: Path
|
|
|
|
|
transcripts: Transcripts
|
|
|
|
|
scripts: Runner
|
|
|
|
|
templates: jinja2.Environment
|
|
|
|
|
rules: Ledger
|
|
|
|
|
jobs: Ledger
|
|
|
|
|
marks: Marks
|
|
|
|
|
log: Log
|
|
|
|
|
batches: Pending
|
|
|
|
|
names: Names
|
|
|
|
|
watch: Watch
|
|
|
|
|
tree: Tree
|
|
|
|
|
model: Model
|
|
|
|
|
timers: Path
|
|
|
|
|
settings: Settings
|
|
|
|
|
speech: Speech
|
|
|
|
|
approvers: Path
|
2026-11-07 15:03:14 +00:00
|
|
|
vendor: Path
|
|
|
|
|
icons: Markup
|
|
|
|
|
spool: Spool
|
2026-11-07 17:46:39 +00:00
|
|
|
office_spool: Spool
|
2026-11-07 15:03:14 +00:00
|
|
|
touched: Touched
|
2026-11-07 18:14:21 +00:00
|
|
|
replay: Path
|
2026-11-06 08:28:04 +00:00
|
|
|
|
|
|
|
|
def hosts(self) -> tuple[str, str]:
|
|
|
|
|
return f"127.0.0.1:{self.public_port}", f"localhost:{self.public_port}"
|
|
|
|
|
|
|
|
|
|
def url(self) -> str:
|
|
|
|
|
return f"{signing.origin_of(self.public_port)}/"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def open_hub(council: Path, pages: Path, public_port: int, state: Path, host_state: Path, transcripts: Path, scripts: Runner, templates: Path, places: Places, model: Model, engines: Engines, approvers: Path) -> Hub:
|
|
|
|
|
uploads = state / "uploads"
|
|
|
|
|
uploads.mkdir(exist_ok=True)
|
2026-11-07 15:03:14 +00:00
|
|
|
reviews = Reviews(state)
|
2026-11-06 08:28:04 +00:00
|
|
|
return Hub(
|
2026-11-07 15:03:14 +00:00
|
|
|
vendor=places.vendor,
|
|
|
|
|
icons=sheet(places.vendor, templates),
|
|
|
|
|
spool=Spool(places.cleanup).ready(),
|
2026-11-07 17:46:39 +00:00
|
|
|
office_spool=Spool(places.offices).ready(),
|
2026-11-07 15:03:14 +00:00
|
|
|
touched=Touched(reviews.stored),
|
2026-11-06 08:28:04 +00:00
|
|
|
approvers=approvers,
|
|
|
|
|
speech=Speech(engines, state / "tts"),
|
2026-11-07 18:14:21 +00:00
|
|
|
replay=state / "replay" / "messages.json",
|
2026-11-06 08:28:04 +00:00
|
|
|
rules=Ledger(state / "rules.json"),
|
|
|
|
|
jobs=Ledger(state / "jobs.json"),
|
|
|
|
|
marks=Marks(state / "marks.json"),
|
|
|
|
|
log=Log(state / "log.jsonl"),
|
|
|
|
|
batches=Pending(),
|
|
|
|
|
names=Names(state / "names.json"),
|
|
|
|
|
settings=Settings(state / "settings.json"),
|
|
|
|
|
watch=Watch(),
|
2026-11-07 06:51:49 +00:00
|
|
|
tree=Tree(file=places.tree_file, heartbeat=state / TREE_HEARTBEAT, lock=threading.Lock(), cached=None, stamp=None),
|
2026-11-06 08:28:04 +00:00
|
|
|
model=model,
|
|
|
|
|
timers=places.timers,
|
|
|
|
|
council=council,
|
|
|
|
|
pages=pages,
|
|
|
|
|
public_port=public_port,
|
2026-11-07 15:03:14 +00:00
|
|
|
reviews=reviews,
|
2026-11-06 08:28:04 +00:00
|
|
|
asks=Ledger(state / "asks.json"),
|
|
|
|
|
decisions=Ledger(state / "decisions.json"),
|
|
|
|
|
messages=Ledger(state / "messages.json"),
|
2026-11-07 18:14:21 +00:00
|
|
|
rule_requests=Ledger(state / "rule-requests.json"),
|
2026-11-06 08:28:04 +00:00
|
|
|
uploads=uploads,
|
|
|
|
|
host_state=host_state,
|
|
|
|
|
transcripts=Transcripts(transcripts),
|
|
|
|
|
scripts=scripts,
|
|
|
|
|
templates=environment(templates),
|
|
|
|
|
)
|