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.
Crew members sleep when idle, wake in seconds, and move when a machine fails (task #3398) Plan
Worked by the Engineer, test first (project instructions: Engineer). No Execution Handoff.
Goal: A crew member idle for an hour sleeps: its session closes and frees memory and its slot, and its folder stays. New work wakes it in the same folder in seconds. If its machine is offline over 5 minutes, signed out, out of quota for over an hour, or low on disk, it moves to the next fallback machine. It keeps the same name and gets a hand-off note, and its task goes back to the head of the queue. Folders and branch copies are cleaned up by four rules.
Architecture:
- The rules are data. One pure function,
crewKeep(state, now)inbackend/src/superTabs/crewKeep.ts, reads the Swarm state (agents, machines' latest readings, groups) and returns actions:sleep,move,dropFolder,dropBranch. Its thresholds are constants increwRules.tsuntil the project rules record (Ledger's task) lands. - Where it runs.
sweepLiveness, the per-Swarm sweep that already runs on machine reports, applies the actions at most every 30 s per Swarm, in the same write. Every machine report triggers it, so a Swarm with any live machine is checked. A Swarm whose machines are all offline has no machine to move to, soworker.tsneeds no new loop. - Sleep: the server sets
Agent.asleep = { since }. The host seessleepon the row and closes the session withcloseMember, keeping its folder. Keeper's keep-alive skips asleep rows (agreed in #3397). - Wake:
work.assignto an asleep member clearsasleepin its own transaction. The host feed pushes the change within a second, and Keeper's keep-alive resumes the engine's own conversation (claude --resume,codex resume) in the same folder. - Move: the server sets
Agent.movedTo = { machineId, startId, reason, at }. It puts the member's active task back at the head of the queue (placeAfter(…, null)) with a lost reasoncrew-moved. It places a start on the fallback machine throughadmitMachineStart(Team rules, room, engines), with the same name, role, engine, model and effort and ahandoffNote. Onagent.startedfor that start, the new agent takes over: the crew flag, the display name, its groups and itsmovedFrom. The old record leaves as a retired entry, which tells the old host (whenever it is back) to close the session and drop the folder. - Cleanup: the server says what to drop and the host does it, refusing a folder with uncommitted or unpushed work,
as
sweepOnealready does.
Tech Stack: TypeScript backend (vitest, integration suite in PR CI), CLI (vitest).
Spec: task #3398 brief (anh Dee, Swarm redesign approved 11-05). It builds on #3397 (Keeper: Agent.crew,
isCrew, crew keep-alive and retention) and is read by #3400 (Budget: dispatch counts an asleep member as free).
Decisions made while building (2026-11-05)
These change the plan above where they differ.
- Fallback order (River): the route's own order, as the project's Order and quota rule applies it: the same account
kind as the machine left, then the account whose weekly quota resets soonest, then the most left, then the fewest
agents working, then by name (
crewKeep.ts fallbacks). - "Out of quota for over an hour" is read without a stored clock: a used-up window that won't reset within the hour. Unknown quota is never trouble. A withdrawn contribution reads as offline, and the sweep never throws on it.
- Retiring the old session uses the existing removal. A move's take-over calls
removeAgent, whose close record makes the old host close the session and drop its folder when clean, the same as any removed agent. That replaces the plan'screwRetiredlist and its host command, and is the "member's folder goes on retire" rule. - Branch copies are pruned by the host. The server records no branch names for tasks. Each hour, in each crew
folder, the host deletes local branches that were pushed and then merged into the default branch, or whose remote
branch is gone. It never deletes the current branch, one tracking the default branch, or one never pushed. A
gone-upstream branch's tip is kept under
refs/harness/dropped/, so no commit is lost. (crewFolders.ts pruneBranches) - Wake after a dropped folder: before the drop, the host remembers the folder's path and clone. On wake, it brings
the folder back at the same path from the clone (
git worktree add --detach) before the keep-alive resumes the engine's conversation there. - Wake grace:
work.assignon an asleep member resetsdownSinceto now, so #3397's 5-minute reopen grace counts from the wake and the new task is not lost while the session reopens. - No new host row fields: host rows already carry the whole agent record, so the host reads
asleepandmovedTothere, as Keeper's keep-alive does. - Task 4 contract for the Desktop machine row (River opens it as its own task), from what clients already get:
- crew sessions:
state.agentson the machine withcrew; - state:
asleep(since),movedTo(moving), or awake; - idle hours:
now - asleep.sincewhile asleep; - free disk:
machines[].observation.resources.projectDiskFreeBytes ?? diskFreeBytes.
- crew sessions:
After the security reviews (Curlew3, SecKeep)
- A move stays within its account kind. A member in a Team account, or one in Team-written work, moves only to a Team
account. A main-account member moves only to a main account. With no such machine, it stays put and says so once. A
take-over never joins a conversation the new session is barred from, and marks what a Team session joins
(
barredFromTeamWritten,markTeamWritten). - A member in a Team account doesn't sleep. There, the core's only member close deletes the session's own data
(
inCore/agents.ts ended,teamPurge.ts), so a wake couldn't resume in place. Such a member stays awake under the crew keep-alive. Follow-up for the PM: a member close that keeps the session needs acli/src/corechange, outside this task's owned paths. - A machine whose move start failed (no token, no room) isn't picked for that member again for an hour
(
crewMoveRefused). The move's start skips agent.start's repository-reach and push-origin checks; this wait keeps a machine that can't reach the repository from being retried every sweep. - Branch pruning covers only branches this member's own folder was on (its HEAD's history). A person's own branches and other agents' in the shared clone are never touched.
- A dropped folder is remembered on disk, so a wake after a host restart still brings it back.
- Accepted as is:
- A move's start is recorded as asked by the target machine's contributor, as the PM's own start is (leadStart.ts).
No system actor exists for starts, and their grant check at
agent.starteduses it. - Server moves follow the server's rules (Team accounts, room, engines, project scope). They don't read the project's
free-text routing instructions, such as "no Codex on this Mac", which the server enforces nowhere. A machine kept
from a project (
machine.projects) is enforced byadmitMachineStart. - Waking clears
asleepwhatever closed the session meanwhile. For crew, any closed session is reopened by the keep-alive anyway, and removing an agent removes its record. - The old agent removed by a take-over is not brought back when its machine returns, because
removeAgentdrops its restore record.
- A move's start is recorded as asked by the target machine's contributor, as the PM's own start is (leadStart.ts).
No system actor exists for starts, and their grant check at
After the review (ReviewSleep, River)
- A moved member's task goes to the head of the list when the move is placed, before the old session can lose it
(liveness loses it after 2 minutes offline, or when the old host closes the session). The task counts if it is
active, or if its machine took it from the member within the last hour (
lostTask). The take-over also puts at the head a task the old session lost after the move began. - Members with no work stay put. An asleep member never moves. An awake member with no work on a machine that went offline (a laptop closed for the night) stays too. It moves once it holds work.
- Machine rules come from the project rules record only (Ledger's task; River, 11-05). They cover a machine's
away hours and the engines it takes no move of, matched by machine id. People's machines and hours never go in this
public repository. The keeper takes them as input (
CrewDeps.machineRules), and until the record is on main, no machine rule applies to moves. - A take-over marks nothing Team-written (Curlew3). Since #3198 a mark is permanent. The barred check keeps main-account sessions out, and a push read marks real Team code.
- The Team-account facts are read from the database only when some member needs another machine.
- A folder drop the removal refused (work not committed or pushed) is tried again an hour later.
- Waits on #3222: the keep-alive waits for a folder restore before it reopens, which builds on Keeper's crew
keep-alive in
host.ts. This branch merges main once #3222 lands, then reruns the host tests. - Platforms: the backend runs on the server. The host code runs on macOS, Linux and Windows through core close/resume and git (Git for Windows). It opens no window and starts no new long-lived process.
Global Constraints
Owns:
backend/src/superTabs/,backend/src/worker.ts(unchanged by this plan) andcli/src/superTabs/. Keeper'screw.tsfiles are not edited. Swarm code stays out ofcli/src/core.Numbers, in
crewRules.tsonly:Constant Value SLEEP_IDLE_MS1 h MOVE_OFFLINE_MS5 min MOVE_QUOTA_OUT_MS1 h MOVE_LOW_DISK_BYTES5 GB FOLDER_ASLEEP_MS7 days DISK_FLOOR_BYTES10 GB RETIRED_KEEP_MS7 days RETIRED_MAX200 Never a PM (Lead) or a Buddy. A crew member with active work never sleeps.
A crew member is moved at most once per
MOVE_OFFLINE_MS. A move with no admitting fallback changes nothing and says so once in the project chat.Lifecycle code is tested with fake machines and a fake host. No test signs the Mac out of the real CLI.
The PR body's first line is "Requested by dee through Harness." It gets one review and one security review.
Design
- Growth:
asleepandmovedTo/movedFromare small objects on the agent.state.crewRetiredholds at most 200 entries and drops each after 7 days, or once the host confirms it. - Concurrency: the actions are written in the liveness sweep's own transaction, which conflicts with any command
touching the same parts and retries on the next pass. Wake is inside
work.assign. - Read cost: no new read. The function runs on the state the sweep already loaded, and hosts get three optional row
fields:
sleep,dropFolder,dropBranches. - Scale: O(crew members × machines) per sweep, a handful each. At 10x, the first warning is the "moved" notices per hour in the project chat.
- Compatibility: an older host ignores the new row fields. A sleeping member then stays open, which is today's behaviour for crew. An older server sends none of them.
- Migration and rollback: none. Absent fields mean awake and not moved.
- Audience: only the server sets these fields; no command lets a client set
asleepormovedTo. - Identity: a move's start is placed as the crew member's project's start, under the Team rules, never with the machine owner's login.
- Failure: no fallback, a refused start, or a host that can't drop a folder (dirty or unpushed) each say why once, and change nothing else.
- Platforms: the host code is platform-neutral (core close/resume, git). Windows follows the same path without new processes.
Review Focus
- A member that wakes while its sleep close is still in flight must end up open: a
work.assignclearsasleep, and the host never closes a row whosesleephas cleared. - A move while the failed machine comes back: the old session must not keep working the task. Its row reads
movedTo, its host closes it, and its task was already taken back. - Two moves for one member (flapping machine):
movedToset means no second move until that start ends. - A folder with uncommitted or unpushed work is never deleted by any rule.
- A quota window read as "unknown" is not "out of quota".
Task 1: Rules and the decision function (backend)
Files:
- Create
backend/src/superTabs/crewRules.tsandcrewKeep.ts. - Modify
model.ts(Agentasleep?,movedTo?,movedFrom?; statecrewRetired?). - Test
crewKeep.test.ts.
Interfaces:
Produces
crewKeep(state: SuperTabState, now: number): CrewAction[], whereCrewActionis{ kind: 'sleep', agentId },{ kind: 'move', agentId, toMachineId, reason: 'offline'|'signed-out'|'quota'|'disk' },{ kind: 'dropFolder', agentId, why: 'asleep-7d'|'low-disk' }or{ kind: 'dropBranch', agentId, branch }.Consumes
isCrew(agent)from #3397. Until #3397 merges, a localcrew?read guards it.Failing tests, using fake machines built from readings:
- idle 59 min stays awake, 61 min sleeps, and active work never sleeps;
- a Lead and a Buddy are never touched;
- offline 4 min stays, 6 min moves to the first admitting machine;
- signed out moves at once;
- quota at 100% for 59 min stays, 61 min moves, and unknown quota never moves;
- disk under 5 GB moves;
- no fallback gives no move;
movedToalready set gives no second move;- asleep 7 days drops the folder;
- disk under 10 GB drops the oldest asleep folder first, one per pass;
- a merged or closed PR of the member's task drops its branch.
Implement, run
npx vitest run src/superTabs/crewKeep.test.tsgreen, and commit (test, then code).
Task 2: Apply the actions in the liveness sweep; wake on assign; move start and take-over (backend)
Files:
Modify
liveness.ts(sweepLivenessappliescrewKeep),commands.ts(work.assignclearsasleep;agent.startedtakes over for a move start;agent.crewRetiredfrom the host),read/hostRows.ts(row fieldssleep,dropFolder,dropBranches; retired entries for the host).Test
crewKeep.apply.test.ts(state-level) andintegration/superTabCrew.test.ts.Failing tests:
- the sweep sets
asleep, and the host row carriessleep; work.assignwakes:asleepis cleared and the row'ssleepis gone;- a move re-queues the task at the head with reason
crew-moved, places a start on the fallback with the same name, role, engine and a hand-off note, and afteragent.startedthe new agent has the crew flag, the same display name, the old groups andmovedFrom, while the old one is a retired entry for its host; - a member is moved at most once until its move start ends;
agent.crewRetiredfrom the old host clears the entry.
- the sweep sets
Implement, run the files green, and commit.
Task 3: Host sleeps, drops folders and branches (CLI)
Files:
Create
cli/src/superTabs/crewFolders.ts.Modify
host.ts(rowsleep→closeMemberwithout removing the worktree;dropFolderand retired entries → drop the folder;dropBranches→git branch -Dwhen safe).Test
crewFolders.spec.tsandhost.spec.ts.Failing tests (fake core, temp git repos in
mktemp -d):sleepcloses the session and keeps the folder;- a cleared
sleepbefore the close starts closes nothing; dropFolderremoves a clean worktree, and refuses a dirty one or one with unpushed commits, reporting why;- a retired entry closes the session if it is open, drops the folder, and reports
agent.crewRetired; dropBranchesdeletes a merged branch that isn't checked out and leaves the current one.
Implement, run the files green, and commit.
Task 4: Machine rows show crew sessions, free disk and idle hours
- Backend (this PR):
machineRowsin the read view carriescrew: [{ name, asleep, idleHours }]anddiskFreeBytesper machine. Test increwKeep.apply.test.ts. - Desktop: the machine row shows them. It needs Flutter on a Mac, so it goes to the PM to give to a Desktop Engineer against this field contract (mockup first).