Docs / How it works
Stack of the local admin app
Status: in use (app/). Node 22.20 or newer (engines of app/package.json and apps/installer), pnpm from packageManager, TypeScript 6.0.3 (the typescript line of the app/pnpm-workspace.yaml catalog and the root devDependencies; 7.x waits until typescript-eslint admits it and next build's type check is measured on it, P69). Pairs with 06.
Language: TypeScript only
The app is local, so there is no reason to keep a second language. One toolchain (Node + pnpm), one set of types from the database to the screen.
- UI: Next.js 16 (App Router, Turbopack) + React 19 + Tailwind v4 + coss ui (skills
coss,coss-particles). Routing: real paths with the framework's typed routes under our own typed layer (src/routes,src/hooks,AppLink; decisions 0014 and 0015). Server and client: route files are thin server components, every screen is a client component, and the browser reaches the API through a same-origin rewrite of/api; no Server Actions, no database in the Next app.hub upserves a production build (next build, replayed from the turbo cache when nothing changed, thennext start -H 127.0.0.1) on the instance's admin port (admin_portinconfig/config.json, elseHUB_ADMIN_PORT, default 5173; the API port isapi_port, elseHUB_PORT, default 4317), so two instances run side by side with different ports;hub uprefuses a port that is already in use and says so; after a restart of the Mac the server is started by the instance's LaunchAgent (P67, decision 0033:~/Library/LaunchAgents/com.reforms.hub.<instance>.plistruns./run.sh up --service, written by the installer stepautostart.agent, on by default, switched in Settings ▸ This Mac orhub autostart on|off; an autostarted instance needs explicit ports that are not the default pair, whichhub up --demoandpnpm liveuse), andhub upby hand then opens that server instead of starting a second (--foregroundruns in the terminal as before;hub stop,hub restart);--servicenever loops launchd: switched off (state/autostart/off), ports held by a hand-run, a forwarded SIGTERM and the fifth failed start in 15 minutes are exit 0, and its logstate/autostart/launchd.logrotates at 5 MB; the hot-reload loop ispnpm live(next devin a worktree); e2e serves its own production build from its own directory. - Server: small local API (Hono, decided in 0001) on 127.0.0.1. It serves the admin (drafts, send, overview, activity, connections, the instance's brand), runs the Sent detection loop (an
osascriptread of each project's Sent mailbox in Apple Mail, only while drafts wait, never launching Mail; a draft is matched only by its own recorded Message-IDs, a reply in its thread that is not the Hub's is noted on it, and the clients' NotionLast sentstamps by other people are read at most every 30 minutes per open draft, P90), the optional Telegram bot poller, the two user-account supervisors (apps/server/src/messengers/accounts/telegram-user.tsfor the owner's Telegram account,whatsapp.tsfor his WhatsApp number as a linked device: one connection per session understate/secrets/sessions/, a parked account never reconnected by itself, the sender handed only to the send door;packages/messengers/README.md), the autolink's client directory (P84: the Notion Clients read into memory at start and every 6 h), the messenger pre-analysis pass after a poll that stored messages (P71 M-P, through@hub/llm;27), the hourly purge of expired messenger messages, and writes the ops log (28). The agent does not talk to it: a session records a draft withdraft_write's record, which writes the database directly. - Storage: SQLite 3, one file
data/app.dbunder the instance root, WAL,foreign_keys=ON. Every table has threelive_*triggers that record each write inlive_seqandlive_versions(migration 0019); the server tails them for the admin's live stream (06, Live updates).
Where files live (HUB_HOME)
Every location comes from one function, hubPaths() in @hub/config/paths. Nothing else joins a repo root onto projects, state, config, .claude/skills or data (a gate test fails on new direct joins).
- The instance is found in this order:
HUB_HOME, else the nearest folder at or above the current one that holdscore.version. Sohub agent <project>works from anywhere inside an instance without./run.sh; started that way, the optionalhubshortcut (hub link; an instance runs without it, with./run.sh) hands over to that instance's own pinnedcore/(an explicitHUB_HOMEis never overridden). A command needs one of the two exactly when it resolves a data path throughhubPaths()(the projects, the database,state/,config/). With neither, it exits 2: "no instance: run hub inside an instance folder (one with core.version), or export HUB_HOME". Commands that resolve no data path (--help,docs,test,link,guide,init,status) work without it. It must be an existing folder other than the core checkout:<home>/projects,<home>/data/app.db. - Nothing lives in the user's home except the optional
hubshortcut (hub link): an instance owns its data, config, secrets, backups and skills. - Always under the home:
state/(evidence,log/the agent session log (25-agent-log.md) and beside its project folders the ops loglog/ops-<day>.jsonl, what failed or happened in the server and every package (28-ops-log.md,hub logs; the server's stderr still goes tostate/autostart/launchd.log, now one human line per ops line),secrets/,projects/<slug>/with the send policy and the session files,codex/<slug>/the Codex homes (codex/_unbound/for a session bound to no project): 24-terminal.md,drops/<slug or _shell>/<session>/the files dropped on a terminal tab (P76, decision 0041: removed when the tab closes, emptied at server start, never backed up)),config/,.mcp.json,.claude/skills. Always under the core:skills/, the project template, thehubbinary, MCP defaults. - Precedence:
HUB_PROJECTS,HUB_DB,HUB_CONFIG_DIR,HUB_CONFIG_FILEbeat the home-derived default;HUB_LEDGER_ROOTstill overrides the ledger root; an explicithome/coreoption beats the environment. With onlyHUB_PROJECTSset, state sits under<home>/state. - An instance states the core version it runs on in ONE file,
<home>/core.version(first non-comment line: a core commit or tag).hub doctor(stepinstance.core, read-only, only whenHUB_HOMEis set) fails when the file is missing, when the core in use is not that commit or has uncommitted changes, when a core file (app/apps,app/packages,skills,@docs/core,install.sh, ...) is inside the instance, when the core tracks an instance file (a project folder other than the template,@dev,@docs/custom,@refs), or when a generated skill link dangles. While the core is still a folder inside another repository the pin check is a warning. For newer cores it reads the server's last update check (below) when that answer is about this pin: WARN for an update recommended or required, PASS with a note for a patch or a followed branch, never FAIL for an origin that did not answer; with no such answer it WARNs "core is behind: N newer tag(s)" when the core checkout holdsvX.Y.Ztags newer than the pin (local tags only). The doctor reads no network, so an instance cannot sit on an old core unnoticed and a doctor run stays offline. - A new instance is made with
hub new-instance <name> [--kind <kind> [--project <slug>]] [--core-url <url>] [--pin <tag|main>] [--no-install] [--dry-run](noHUB_HOMEneeded, plans P35 and P89; a bare name makes the folderhub-<name>): it refuses a folder that is not empty, runsgit init, adds the core as thecore/submodule at the pin (newestvX.Y.Ztag, elsemain; any other tag is never pinned, and--pinaccepts only a version tag ormain; the file carries one managed comment,# tag: vX.Y.Zor# follows: main), copiesapp/apps/installer/templates/instance/with{{NAME}}filled in (run.sh, README,.gitignore, AGENTS/CLAUDE stubs, the@devkanban skeleton,@docs/custom,@refs), writescore.version, links the core skills into.claude/skills, installs the core's dependencies, runsinstall --only FilesanddoctorwithHUB_HOMEset to the new folder, and makes one commit (a commit that fails, for want ofgit user.name, is an error that says how to finish, not a success). With--kindit also writes the first project (project.mdwith schema, kind, name and status draft, the template's workflows, sequences and@dev, the kind's taxonomy, an emptyknowledge/files/). Under 5 GB free it skips the dependency install and says so;--no-installskips install and doctor on purpose. It never pushes and creates no remote: it prints the onegh repo create <owner>/hub-<name> --private --source … --remote origin --pushline. Without--kind, on a terminal it asks one question listing the kinds (a number, a name, or Enter for no project); a script without a TTY is asked nothing. There are no starter or template repositories (decision 0043, amended 2026-11-20); the team workflow is@docs/setup/team.md. The files it writes are plain files in the core, not an archive; a test pins the list. hub status [--root <dir...>] [--json](noHUB_HOME): one read-only table over the instances next to the core in use (or the roots given, plus the instance the current folder is in): the core each one runs and whether it differs from its pin, the pin andfollows main, projects with their status, drafts waiting (ready, read from the database opened read-only), the admin port and whether it is up.- An instance moves to another core version with
hub core update(HUB_HOME set): no argument lists thevX.Y.Ztags of the core and the one in use;hub core update <tag>shows the plan;--applychecks the tag out incore/, rewrites the pin incore.version(exactly one managed# tag: vX.Y.Zcomment; a hand-written comment that names a version is dropped, so the file cannot state a stale one), runs theinstance.corecheck and puts everything back when that check fails, then runspnpm install --frozen-lockfile --prefer-offlineincore/appwhen the lockfile differs between the two commits,node_modulesis missing, or a workspace member's dependency is not installed at the version the checkout names (when pnpm fails, it prints the exact command to run). On an instance with its own workspace files (decision 0018) it regenerates them from the new core (hub workspace init --apply: versions, the pnpm catalog, turbo tasks). Already on the tag, it still installs whennode_modulesis behind the checkout (a pin moved by a pull). It never commits: commitcore/,core.versionand any regenerated workspace file together, in one commit. Going to an older tag is a rollback and is reported as one. Instances update independently of each other. A test instance may follow the core'smaininstead of a tag:hub core update --branch main --applychecks out the tip oforigin/main, pins that commit incore.versionand marks it with a# follows: maincomment; the next tag pin replaces the mark with# tag:. A real-business instance stays on tags. - The instance learns of a newer core from its origin's tags (P68, decision 0034). The server checks 2 minutes after it starts, then every 6 hours, and when the owner presses Check now on Settings ▸ This Mac (at most once a minute, else 429):
git ls-remote --refs originin the core (no prompt, 15 s; it writes nothing), and only when origin has avX.Y.Ztag newer than the pin that the core does not hold, onegit fetch --tags origin(no--force, so a moved tag is reported and never taken; a fetch that meets a lock is skipped until the next run; a fetch changes no working-tree file, soinstance.core's clean check is unaffected). The answer,@hub/config/core-version(judgeCoreUpdate), is cached instate/core-update.json(hubPaths().coreUpdate) and served byGET /api/instance/core, which never runs git. Levels: current; update available (patch releases only, fewer than 5 behind, and the newest tag less than 14 days newer than the pin's); update recommended (a new minor or major, 5 or more patches behind, or 14 days newer); update required (a tag in the range carries[update: required]in its first line); an instance that follows a branch shows how many commits it is behind, no level. With it come the newer tags' subject lines, whether dependencies change (the lockfile differs) and whether the database migrates (a new file underapp/packages/db/drizzle/), and the instance's own three lines:cd <home> && ./run.sh core update vX.Y.Z --apply, the commit ofcore core.version(plus the workspace files when the instance has them),./run.sh restart. A check that does not reach the origin keeps the last good answer and adds when and why. There is no switch to turn it off, and no Update button: the server would have to replace the code it runs (a later track, after P67's service). - Releasing a core version (the rule the check reads). A release is an annotated tag on
main,git tag -a vX.Y.Z -m "core: vX.Y.Z (<what>)", pushed withgit push origin vX.Y.Z: the subject line is what every instance's admin shows for that release, so it says what changed in the owner's words (track numbers in parentheses). When every instance must take it (a security or data fix), the subject ends with[update: required]. A tag is never moved or deleted once pushed (instances fetch without--forceand report a moved tag); a mistake is the next patch. Lightweight tags still count (their commit subject is shown), but the release rule is annotated. There is no CHANGELOG or release-notes file: the tag is the one statement of a release (decision 0009). core/is the submodule by default (hub core install: submodule at the pin). For core development inside a real instance,hub core dev <path>(dry run;--applyto do it) deinitialises the submodule checkout and symlinkscore/to your core checkout, withskip-worktreeset oncorefirst sogit status,add -Aandcommit -aignore the link (the gitlink,.gitmodulesandcore.versionstay).hub core installremoves the link and checks the pinned commit out again. While linked:hub core updaterefuses andinstance.corewarns; never deploy in that state.- In an instance
hub agentruns Claude Code or Codex in<home>, setsHUB_HOMEin the child, links the core skills into<home>/.claude/skills(relative symlinks, git-ignored, regenerated on every start and byinstall --only skills.runtime; Claude Code loads project skills from.claude/skills/of the folder it starts in and follows symlinked skill folders, so nothing is written to~/.claude/skills;hub uninstallremoves only these links, and stepskills.legacyreports old links an earlierhub setupleft in~/.claude/skillswith the onermcommand to remove them), and gives stdio MCP servers absolute core paths plusHUB_HOME. - Start-up: before the CLI is loaded,
bin/hub.mjschecks that every workspace member ofcore/apphas its dependencies installed at the versions the checkout names (apps/installer/src/deps.ts, Node built-ins only); when not, it runs the samepnpm installfirst (output on stderr), so a core whose checkout moved ahead of itsnode_modulesnever crashes on an import. - ORM: Drizzle ORM over
better-sqlite3, behind an async repository layer (decision 0001; libsql is the fallback). - MCP: the knowledge tools (
knowledge_search,knowledge_get) are a stdio MCP server inapp/packages/knowledge, built on the official@modelcontextprotocol/server. Mail is reached only through Apple Mail (decision 0026): the agent reads through the installedmail-mcp, the hub writes throughosascript(hub mcpdraft_write, the send door, the open draft's text, Sent detection). The hub holds no mail login. - Tests: Vitest (unit, and the rules test of
app/@rules); Playwright with axe for the screens, in light and dark.
What lives in SQLite (working state only)
The schema is app/packages/db/src/schema.ts; every table has a project column. Client keys (clients, client_identifiers), marks, drafts (status ready hold done sent skipped; Checked is a flag, not a status), the Hub's own record of each Mail draft version it wrote (mail_versions, and mail_writes for a write in flight, so a late save of Mail's is adopted by hash: P65), batches, send_log (mail and, since 0027, messenger sends: channel, messenger_draft_id) and send_control, safety_rules, inbox_rows, enrollments (follow-up sequences, 23), the project index (projects, project_addresses, project_questions), the knowledge index (knowledge_docs, and the FTS5 virtual table knowledge_fts its migration makes), the messenger tables (messenger_accounts, messenger_chats, messenger_messages, messenger_drafts; since 0025 messenger_chats also holds each linked chat's rules, P71 M2b; messenger_triage, the pre-analysis verdict per message, deleted with its message, 0029; messenger_link_refusals, the HMAC of each chat the owner said is not a client, P84, 0028; unlinking a chat deletes its messages, verdicts and drafts in the same transaction, and the server purges expired messages at start and every hour, connected or not), agent_settings (the agent's model and advisor per project, set on Settings ▸ Agent, P55), the LLM ledger llm_calls (one row per attempt, P78, 27), owner_fixes (a refusal of the agent's tool only the owner can fix, one row per project and code, shown on Overview until the tool's next success or 24 hours, P133, 0038), and the action log agent_runs and agent_events. Mail is read live and Notion stays the CRM; the Notion side has a dump and a dry-run restore (app/packages/notion/README.md).
Rules for agents who change the app
app/@rules/.
Monorepo
Turborepo + pnpm workspaces, best practices. Domains are packages, so each can be tested and replaced alone:
apps/admin(Next.js + React + coss),apps/server(Hono API),apps/installer(thehubCLI).packages/db(Drizzle schema, migrations, repositories; includes the agent log),packages/notion(read-only dump and restore dry-run),packages/messengers(the Telegram bot's long polling, the Telegram user account on mtcute and WhatsApp on Baileys, the autolink matcher; see its README),packages/config./chat-rules(the vocabulary, defaults and bounds of a chat's rules, P71 M2b),packages/send(the Mailer and the send checks,16section 3B),packages/connections(the Notion token and the Telegram bot derived fromstate/secrets: inspect, probe, write-only store; used by the server, the CLI and the installer),packages/contract(the API's request and response schemas, shared with the admin;@hub/contract/localis the one registry of the local Open actions, P61: ids, argument schemas, transport, themessage:/mailto:/notion:builders and the URL allowlist;@hub/contract/schemethe Hub's parts andbuildScheme, their Mermaid text, P63;@hub/contract/tipsthe dock's tips with the CLI version each was checked on and@hub/contract/helpHelp's phrases, P63 patch B),packages/projects(project.mdschema and registry;@hub/projects/local-openresolves an Open's key to a path inside its root and runs/usr/bin/open, injected:HUB_OPENER=fake(server only, refused withoutHUB_DB) appends each argv tostate/opener.jsonland opens nothing),packages/sequences(follow-up sequences: definition parser, transitions, due dates, stop rule;23),packages/knowledge,packages/mail-filters,packages/config(paths, settings, shared constants, the lint size caps, the instance switchagent.default),packages/agent(what a Claude Code or Codex session gets: deny lists, the OS sandbox, the generated session config, the Agent tools checks;24),packages/terminal(the embedded terminal's sessions onnode-pty, Node only, imported byapps/serveralone, except@hub/terminal/readiness, which the installer's doctor row also runs;24),packages/llm(@hub/llm, P78 and P144: the one door to a model API, declared tasks (defineTask,llm.run) in three shapes (object, batch, window) over OpenRouter through theopenaiSDK with a strict schema from zod, presets, a row per attempt inllm_callsofpackages/db, the monthly cap and a task budget; it imports@hub/config, zod andopenaionly, the caller hands it the ledger;HUB_LLM=fakeis its fake transport;27),packages/log(@hub/log: the agent session log of25, its writer,hub log's reading and the activity feed's labels,feed.ts; the server reads it forGET /api/projects/:slug/agent-feedand watchesstate/logfor the live topicagent-log; and@hub/log/ops, the ops log of28(P86): the one logger of the server and every package, its redactor,hub logs,GET /api/ops/errorsand the live topicops-log),apps/adminalone depends onmermaid12.3.0 (P63 patch B, decision 0035: the Help scheme, loaded byimport()on that page only),packages/ui(@hub/ui: the coss copies, the product primitives (ActionButton,Field, the page shell, list-detail, the data table, the brand header, the theme provider and switcher onnext-themes), the feed's three synthesised tones anduseSound(@hub/ui/sound, P59),cnand the tokens instyles.css; subpath exports, no barrel; the admin and any instance app import it, it imports no app and no other@hub/*package; decision 0024 in the owner's plan repo).- Rules: packages never import from apps; one public entry per package (
contractanduiexport by subpath instead); the UI talks only to the server; internal packages export TypeScript source and each is checked by its owntsc --noEmit(no project references; every tsconfig extends a base of@hub/config:tsconfig.base.json,tsconfig.node.jsonfor code that uses Node's globals ("types": ["node"], since TypeScript 6 no longer loads every@typespackage by itself) ortsconfig.dom.jsonfor the browser and JSX; everyvitest.config.tsis onehubVitestcall of@hub/config/vitest; everyeslint.config.mjsbuilds on@hub/config/eslint,pnpm lintruns it in all workspaces); Turbo pipelinebuild,test,lint,typecheckcached.
Update this page when the architecture changes.