The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.
TypeScript 3d-modelingagent-frameworkagent-harnessai-agentscadclaude-codecodexcoding-agentsdeveloper-toolsesp32game-developmentmcp-servermulti-agentopen-hardwareopencodeopenharnesspcbroboticsterminaltmux
docs: the daemon's guides and plans match main: every process, what it hosts, and what starts on demand (#956)
Dee47864d92f890
diff --git a/cli/AGENTS.md b/cli/AGENTS.mdindex dc3272571..b3bd86406 100644--- a/cli/AGENTS.md+++ b/cli/AGENTS.md@@ -15,6 +15,29 @@ SERVICES src/services/ everything else: search, viewers, models, workspaces,Reaches the core only through core/api.ts; can fail without the core.```+### The processes++The master runs the core and every service process (`SERVICE_HOSTS` in `src/harnessd/services.ts`). Each+service process runs one or more services, each on its own link to the core. In Activity Monitor and `ps`+they show as `harnessd`, `harnessd-core` and `harnessd-<process>` (`src/harnessd/processName.ts`).++| Process | Runs | Started |+|---|---|---|+| master | supervision only (`src/harnessd/`) | by `harness start`, `harness start -f`, or launchd or systemd after `harness service install` |+| core | sessions (`src/core/`), and the shell service | always |+| search | session search | always |+| viewers | the harness viewers, their remote streams and rendered surfaces, and the Store | always |+| edge | workspaces, usage, the monitor, the project readers, the change-agent handoff, the recaps | always |+| gateway | the relay and its E2EE (`src/gateway/`) | always |+| models | grid, local models, the Model Manager | always |+| updater | checks, downloads and stages a new build (`src/services/updaterProcess.ts`) | by the master, for the installed copy only |+| devices | the dials, the window bridges, the fleet, the voice router, the Wi-Fi device | on demand: once there is a device |+| orchestrator, teams (with Tab collaboration), sharing, commandBar | the experiments | on demand: on a request, or saved state at start |++`HARNESSD_SERVICES` names a subset to run in their own processes, by service or by process.+`HARNESSD_SERVICES=none` runs every service in the core's process, for debugging or a quick way back. How+to add a service, and how to make one start on demand, is in [src/services/AGENTS.md](src/services/AGENTS.md).+`src/core/main.ts` `runForeground()` is the composition root: it creates the modules and wires themtogether. It is the core's own entry (`harness __run`), which the master starts; `src/cli.ts` is the CLI,and calls in for `__run`. `harness start -f` runs the master in the foreground, as launchd and systemd do.@@ -22,7 +45,8 @@ The updater is the master's, in a process of its own (`src/services/updaterProcedownloads a build. When it stages one, the master has the core hand over (`harnessd:update`) and judges thenew build. A core with no master gets no updates: one an older release's own handoff started hands itselfto a master once that release has gone, and one `HARNESS_NO_MASTER=1` asked for runs as it is-(`src/core/updateHandoff.ts`). `src/backendSocket.ts` is the transport: it receives frames and dispatches+(`src/core/updateHandoff.ts`). A core under a master too old to run the updater starts it beside itself, in+its own process (`src/core/updaterBeside.ts`). `src/backendSocket.ts` is the transport: it receives frames and dispatchesthem.`src/gateway/` is the relay: the backend link, the E2EE sessions and keys, and every rule about what aremote client may send and how what it is sent is sealed. It runs in a process of its owndiff --git a/cli/src/core/AGENTS.md b/cli/src/core/AGENTS.mdindex 922f911a7..7040e3d69 100644--- a/cli/src/core/AGENTS.md+++ b/cli/src/core/AGENTS.md@@ -23,16 +23,22 @@ questions. Everything else is a service ([../services/AGENTS.md](../services/AGE## Where things are-- `agents/`: create, fork, restart, retarget, stop, resume, close, discovery, binding.+- `agents/`: create, fork, restart, retarget, stop, resume, close, discovery, adoption, binding, the list.- `transcripts/`: attach (bounded reads from the end), ingest, live tail, relaunch marks, normalizers.-- `turns/`: working/idle, the event funnel, cancel, recaps, heartbeats, hooks.-- `terminals/`: who controls a pane (the control lease).+- `turns/`: working/idle, the event funnel, cancel, heartbeats, hooks, and `recaps.ts`, the core's whole+ side of the recaps: the turn lifecycle it tells them, and what it reads back.+- `terminals/`: who controls a pane (the control lease), opening a terminal with a literal argv (`open.ts`),+ and the requests about a terminal itself (`requests.ts`: `terminal_info`, `theme_set`).- `engines/`: the engines' hooks.- `input.ts`, `questions.ts`: messages into a pane; an agent's question and its answer.`deviceInput.ts`: the pane writer lock every write takes, and a device's queued turns behind it.`cardText.ts`: an engine's error, rewritten for a device's card.- `deliveries.ts`: delivered turns, the Wi-Fi device's, a team's and the orchestrator's: text written into anagent under a delivery id of its maker's, and what became of it, told back to that maker in its process.+- `updateHandoff.ts`: the core handing over to a build the updater staged (exit 75, when the master asks),+ and a core with no master handing itself to one. `updaterBeside.ts`: the updater started beside a core whose+ master is too old to run it, still in its own process.+- `stall.ts`: a test-only fault that holds the core's event loop still (`HARNESSD_TEST_FAULTS=core.stall:…`).- `main.ts`: the core's entry (`harness __run`) and composition root, `runForeground`: it builds thesemodules, starts the services through `serviceHost` and wires the socket. The one core file that importsservices and the socket, and the one outside the 100% coverage: wiring only, run end to end. The@@ -53,7 +59,8 @@ questions. Everything else is a service ([../services/AGENTS.md](../services/AGE`experimentQueries.ts`: what an experiment acts on the core through; `experiments.ts`: which are on as thecore starts; `orchestratorLink.ts`: what the core keeps of the orchestrator in its own process;`sharingLink.ts`: Share's observers' frames to its process; `terminalWatch.ts`: a read-only view of the- agents' terminals, which Share shows its observers.+ agents' terminals, which Share shows its observers. `conversationQueries.ts`: the conversation facts the+ change-agent handoff in the edge host asks for, one at a time.`gatewayLink.ts`: the relay and its E2EE in their own process (src/gateway/), as the core sees them:the link's state and the remote clients it reads in line, the frames it hands over in the clear, awindow's sessions to another machine or a shared harness, and the fleet's lane's sealingdiff --git a/cli/src/harnessd/AGENTS.md b/cli/src/harnessd/AGENTS.mdindex 1abf98334..7a8bf2651 100644--- a/cli/src/harnessd/AGENTS.md+++ b/cli/src/harnessd/AGENTS.md@@ -44,3 +44,7 @@ It keeps the core and the services running, and nothing else.the new core on probation, as before. The master itself still makes no network call. Every core thismaster starts hears `HARNESSD_UPDATES=master`; a core under a master from before that runs the updaterbeside itself, in its own process (`../core/updaterBeside.ts`).+10. **A process on demand starts only when the core asks** (`onDemand` in `SERVICE_HOSTS`, `services.ts`).+ The core sends `harnessd:want` for one of its services; from then on it is kept running like any other.+ A core that speaks an older protocol than the process's `askedSince` never asks, so `unasked` starts it+ as that core binds. Making a process on demand bumps `HARNESSD_PROTOCOL` and sets `askedSince` to it.diff --git a/cli/src/services/AGENTS.md b/cli/src/services/AGENTS.mdindex 0db846fc9..8f7b8bcd4 100644--- a/cli/src/services/AGENTS.md+++ b/cli/src/services/AGENTS.md@@ -47,15 +47,30 @@ let several people build features at once without touching the core or each othe## Running in its own processA service that can crash natively, hang or leak should run in a process of its own, where it costs only-that process. A process per risk, not per feature: search (native `node:sqlite`), the viewers (their-servers) with the Store (its minutes-long installs), each experiment (below), models (grid's installs,-downloads and commands), the devices (the dials' serial ports, the fleet's lane, the voice router's-worker, and the Wi-Fi device), and the edge host, one process for the light services-(workspaces, usage, the monitor, the project readers, the recaps). A fault in one of the edge host's services can-cost the others in it, never the core. Every service in `KNOWN_SERVICES` runs out of the core's process-by default, unless `HARNESSD_SERVICES` names a subset, by service (`search,usage`) or by process-(`edge`), and `HARNESSD_SERVICES=none` runs them all inside the core's process (for debugging or a quick-way back).+that process. A process per risk, not per feature (`SERVICE_HOSTS` in `src/harnessd/services.ts`):++| Process | Services | Why its own | Started |+|---|---|---|---|+| `search` | search | native `node:sqlite`, the index's memory | always |+| `viewers` | viewers, store | the viewer servers, the remote viewer streams and rendered surfaces, minutes-long installs | always |+| `edge` | workspaces, usage, monitor, projects, handoff, recaps | light pure-JS services: isolated from the core, not from each other | always |+| `gateway` | gateway | network, crypto and pure-JS WebRTC: the attack surface | always |+| `models` | models | grid's installs, downloads and commands | always |+| `devices` | devices, wifi | the dials' serial ports, the fleet's lane, the voice router's worker, the Wi-Fi device | on demand |+| `orchestrator` | orchestrator | an experiment | on demand |+| `teams` | teams, collaboration | an experiment: Tab collaboration beside the prompt scopes | on demand |+| `sharing` | sharing | an experiment: Share | on demand |+| `commandBar` | commandBar | an experiment: the command bar | on demand |++A fault in one of the edge host's services can cost the others in it, never the core. Every service in+`KNOWN_SERVICES` runs out of the core's process by default, unless `HARNESSD_SERVICES` names a subset, by+service (`search,usage`) or by process (`edge`). `HARNESSD_SERVICES=none` runs them all inside the core's+process (for debugging or a quick way back). The shell service always runs in the core's process.++The updater is not in `SERVICE_HOSTS`: the core neither routes to it nor runs it, and `HARNESSD_SERVICES` does+not turn it off. The master runs it (`UPDATER_HOST`, `src/services/updaterProcess.ts`) for the installed copy,+with updates on. It stages a new build and tells the master, which has the core hand over. A core under a+master too old to run it starts it beside itself, still in its own process (`src/core/updaterBeside.ts`).- `src/harnessd/services.ts` runs it (`SERVICE_HOSTS`: each process, the services it hosts and itsmemory budget, one heartbeat for all of them). The core routes the requests it declared (its@@ -74,7 +89,7 @@ way back).- **What a service imports is what its process costs.** Import from small modules: one schema modulepulled in for a constant brought zod to search and workspaces, 8 MiB each (`src/dsh/id.ts`). Afailing import fails the service's start, loudly, and the master parks it. `src/leanEntry.spec.ts`- holds each process to its own code, and the master, search and the edge host to no zod.+ holds each process to its own code, and the master, search, the updater and the edge host to no zod.- `src/services/process.ts` is the process's side: `hostServices` beats to the master and stops everyservice before the process exits; `runServiceProcess` is each service's own connection to the core,with the master's token, reconnecting after core restarts. `<host>.crash` and `<host>.leak`, or a@@ -88,7 +103,9 @@ way back).`serviceLinks.call`, under types only it sends (the port's member names, so a test's fault names thesame member either way), and reads an answer that does not come as the port's fallbacks. A lightservice that reads the agents asks for them as each request starts (`service_query live` or- `advertised`, `src/core/agentQueries.ts`; `src/services/processCoreApi.ts`).+ `advertised`, `src/core/agentQueries.ts`; `src/services/processCoreApi.ts`). The change-agent handoff+ asks for each conversation fact as it needs it (`core.conversations`, `src/core/conversationQueries.ts`,+ `src/services/handoffProcess.ts`) and keeps no copy of the registry.- A port the core calls in line (while it builds a frame, say) cannot wait on another process. Theviewers show how (`src/services/viewersProcess.ts`, `src/core/viewersLink.ts`): the process tellsthe core its answers whenever they change (a `service_query` kind the core answers), the core keeps@@ -148,6 +165,25 @@ way back).process last reported, and is "unknown" (the fallback) while a change to it is on its way.`e2e/teamsProcess.e2e.ts` proves it.+## On demand++A process with `onDemand: true` in `SERVICE_HOSTS` is not started with the others. The master starts it when+the core asks for one of its services (`harnessd:want`, sent by `coreLink.want`), and then keeps it running+like any other. Named in `HARNESSD_SERVICES`, it starts with the others.++- **What asks.** A request for a service that has not connected yet (`serviceLinks` `onDemand`, in+ `src/core/main.ts`) asks for it and waits for it, within the request's own wait. The service is welcomed+ before its queued requests are delivered. Each experiment with saved state in the data folder is+ asked for as the core starts (`src/core/experiments.ts`). The devices are asked for once there is a device:+ a dial's port in /dev, a paired Wi-Fi device, or its session (`src/core/devicesWake.ts`).+- **Older cores.** `askedSince` is the core protocol (`HARNESSD_PROTOCOL`, `src/harnessd/protocol.ts`) from+ which a core asks for this process. A core that speaks an older one never asks, so the master starts the+ process as that core binds (`ServiceSupervisor.unasked`). It is 3 by default, the experiments'; the+ devices became on demand at protocol 4. Making another process on demand needs a protocol bump, and that+ number in its `askedSince`.+- **Proof.** `e2e/experiments.e2e.ts` and `e2e/devicesOnDemand.e2e.ts`: off, it has no process; asked for, it+ starts and answers.+## ExperimentsAn experiment (the orchestrator, Tab collaboration, Share, the command bar) is a service that costs nothingdiff --git a/docs/design/2026-10-04-harnessd-before-after.md b/docs/design/2026-10-04-harnessd-before-after.mdindex 2635deaf2..848a5e287 100644--- a/docs/design/2026-10-04-harnessd-before-after.md+++ b/docs/design/2026-10-04-harnessd-before-after.md@@ -4,6 +4,10 @@ A one-page picture of what changed in the daemon between the last release (v0.3.and the harnessd rebuild, for explaining the refactor to the team. The full design, its rules andits plan are in [2026-10-03-harnessd.md](2026-10-03-harnessd.md). Paths are under `cli/src/`.+The "after" picture below is the rebuild as it was on 4 October. [Today](#today-one-process-per-risk)+shows where it went next: most services now run in processes of their own+([2026-10-06-core-boundary-next.md](2026-10-06-core-boundary-next.md)).+## Before: one process, one function```@@ -104,11 +108,11 @@ and it crash-looped: every agent on the machine lost its daemon at once.ask the core what `CoreApi` offers.2. If the apps call it, declare its requests (`<NAME>_REQUESTS`) and return their handlers from itsstart. The core routes each request to it, with who asked. Nothing changes in `backendSocket.ts`- or `cli.ts` but the one line that starts the service. While it is off, its requests are answered+ or `core/main.ts` but the one line that starts the service. While it is off, its requests are answered`SERVICE_UNAVAILABLE`.3. If the core must call it, add a port to `CorePorts` in `core/api.ts`, with fallbacks beside it:what the core does while the service is off or failing. Most features need no port.-4. Start it in `cli.ts` through `serviceHost.serve(...)`, or `serviceHost.start(...)` when it has a+4. Start it in `core/main.ts` through `serviceHost.serve(...)`, or `serviceHost.start(...)` when it has aport; never directly. The host guards its start, every call and every request, and switches it offwhen it keeps failing.5. Hold the file to 100% (`npm run test:core` covers `src/services/`). For the end-to-end suite,@@ -147,10 +151,41 @@ desk of 50 agents runs in 268 MiB, and all of them are back 8.3 s after a restarThe full list is in the design doc's "Found while mapping".+## Today: one process per risk++Most services now run in processes of their own, which the master starts and watches beside the core.+The core keeps sessions, and reaches each service only through its link. Measured on `main` at b4027cbd1:++```+┌──────────────────────────────────────────────────────────────────────────────┐+│ MASTER harnessd starts, watches and restarts every process below │+└───────┬──────────────────────────────────────────────────────────────────────┘+ │ spawn channel, heartbeats, memory budgets, crash-loop parking+ ├── CORE harnessd-core sessions: agents · terminals · transcripts ·+ │ turns · input · questions (71,244 lines loaded,+ │ from 114,622; runForeground 2,211 lines)+ ├── search session search+ ├── viewers harness viewers, their remote streams · the Store+ ├── edge workspaces · usage · monitor · project readers ·+ │ change-agent handoff · recaps+ ├── gateway the relay and its E2EE: every remote client+ ├── models grid · local models · the Model Manager+ ├── updater checks and stages a new build (installed copy only)+ │+ │ on demand: no process until it is needed+ ├── devices dials · window bridges · fleet · Wi-Fi device+ ├── orchestrator experiment+ ├── teams experiment: Tab collaboration+ ├── sharing experiment: Share+ └── commandBar experiment: the command bar+```++One service failing costs its own process, and the master restarts it. The core answers its requests+`SERVICE_UNAVAILABLE` meanwhile, and every agent goes on. `HARNESSD_SERVICES=none` still runs every service+inside the core's process, for debugging. The end-to-end suite has 82 files.+## Next-Search already runs in its own process when `HARNESSD_SERVICES=search` is set. Killed, hung, leaking-or crash-looping, it costs search alone (`e2e/serviceProcesses.e2e.ts`). It is off by default until-it has been run for real. The other services follow the same way, devices next, so that a native crash-or a memory leak in any of them cannot touch the core either. After that come platform supervision-(launchd, systemd) and the state directory move.+The core still loads the engines' own code: the engine-interface refactor+([2026-10-05-engine-interface.md](2026-10-05-engine-interface.md)) is paused. The core's process still+parses all of cli.js, so its memory falls only with a lean core bundle, which is in progress.diff --git a/docs/design/2026-10-06-core-boundary-next.md b/docs/design/2026-10-06-core-boundary-next.mdindex 0640e952d..4ae0c8363 100644--- a/docs/design/2026-10-06-core-boundary-next.md+++ b/docs/design/2026-10-06-core-boundary-next.md@@ -1,28 +1,37 @@# The core boundary, next-> **Status, 2026-10-07.** Steps 1–11 have landed, except where noted. The core's closure, measured by-> `cli/src/architecture.spec.ts`, went from 114,622 lines in 488 files (walked from `cli.ts`) to 75,746-> lines in 345 files.+> **Status, 2026-10-07.** Steps 1 to 11 have landed, and so have moves the plan did not list: the recaps,+> the viewers' remote serving and the updater. The core's closure went from 114,622 lines in 488 files+> (walked from `cli.ts`) to **71,244 lines in 332 files** on `main` at b4027cbd1. That is measured by+> `cli/src/architecture.spec.ts` with `CORE_CLOSURE_BUDGET` set to 1. The target was 61,000.>> | Step | Landed as | Note |> |---|---|---|> | 1 The core's own entry, and its size test | #871 | |-> | 2 Dead code | #845 | |+> | 2 Dead code | #845, #919 | #919 deleted the web dashboard (`webui.ts`): nothing opened it |> | 3 Slow work off the event loop | #826 | |-> | 4 Requests into services | #851 | Left behind: the command bar (#927, #937) and the change-agent handoff (#931) |-> | 5 Several services per process, the edge host | #875 | |-> | 6 The Store into the viewers' process | #879 | |+> | 4 Requests into services | #851, #931, #937 | The change-agent handoff runs in the edge host (#931). The command bar is an on-demand experiment (#937). A routed request knows its connection, and its service hears when that connection closes (#927) |+> | 5 Several services per process, the edge host | #875 | The edge host now runs workspaces, usage, the monitor, the project readers, the handoff and the recaps |+> | 6 The Store into the viewers' process | #879, #922 | The viewer forwarder and the rendered viewer surfaces followed the viewers (#922) |> | 7 Models in its own process | #896 | Found: routed requests were cut off at 30 s (`LONG_ANSWERS`) |-> | 8 The experimental host, move only | #921, #924, #932, #933 | On-demand processes per experiment: orchestrator, Tab collaboration, Share |-> | 9 Devices in their own process | #918, #928, #929, #946 | Per-device guards in one devices process; the Wi-Fi device on the gateway; the process on demand, once there is a device |+> | 8 The experimental host, move only | #921, #924, #932, #933, #937 | One on-demand process per experiment: the orchestrator, Tab collaboration, Share, the command bar. Found: a cold experiment got its first request before it was welcomed (#940) |+> | 9 Devices in their own process | #918, #928, #929, #946 | One devices process, with a guard per device, and the Wi-Fi device beside the dials. It starts only once there is a device (protocol 4, #946). A dial's port is streamed over its own descriptor (#953) |> | 10 The relay: the gateway process | #899, #905, #911 | |-> | 11 The unsupervised handoff | #895 | `harness start -f` runs the master; the updater leaves the core in #925 |+> | 11 The unsupervised handoff | #895, #925 | `harness start -f` runs the master. The updater runs in a process the master runs; the core never downloads a build (#925) |+> | Recaps (not in the plan) | #923 | The plan kept the commander mirror in the core. The recaps now run in the edge host, and the core only tells them each turn's lifecycle |>-> What still loads in the core and isn't session machinery: the engines' own code (the engine-interface-> refactor, docs/design/2026-10-05-engine-interface.md, is paused), and the in-flight moves above. The-> core's process still parses all of cli.js, so its memory falls only with a lean core bundle (in-> progress).-+> The processes now: the master, the core, search, the viewers with the Store, the edge host, the gateway,+> models, and the updater (the master's, for the installed copy). Five more start on demand: the devices,+> the orchestrator, the teams with Tab collaboration, Share and the command bar. Each process and what it+> hosts is in [../../cli/src/services/AGENTS.md](../../cli/src/services/AGENTS.md).+>+> What is left:+> - **The engines' own code still loads in the core.** The engine-interface refactor+> ([2026-10-05-engine-interface.md](2026-10-05-engine-interface.md)) is paused.+> - **The core's process still parses all of cli.js.** Its memory falls only with a lean core bundle, which+> is in progress (#955).+> - **The core grew where every session needs it.** #950 added a gate for tmux before 3.7, whose server+> crashes when a terminal attaches during a notification (`lib/tmuxControlGate.ts`).A plan, not a change. It takes stock of everything that still runs in the core's process and is notsession handling, decides where each piece goes, and orders the moves so that each lands green on its