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
Merge batch 11-06 j0950: #3262 #3246 (#3268)
0xken151d746153024b
diff --git a/backend/integration/superTabMachineLiveness.test.ts b/backend/integration/superTabMachineLiveness.test.tsindex 83d010ad8..8dc5f6d3c 100644--- a/backend/integration/superTabMachineLiveness.test.ts+++ b/backend/integration/superTabMachineLiveness.test.ts@@ -175,3 +175,50 @@ describe('the whole readings on demand', () => {await expect(f.reads.machineReadings(outsider, f.tab)).rejects.toThrow()})})++// Task #3462: a crew member's wake is timed from the work that woke it to the first machine reading that shows its session+// running again, and the timing row is stored in its project chat for the daily scorecard.+describe('a crew wake timed by the machine report that shows it back (#3462)', () => {+ it('stores one timing row in the project chat, from the assignment to that reading', async () => {+ const sweeping: ReportMemory = { get: async () => undefined, set: async () => {}, sweepDue: async () => true }+ const store = new SuperTabStore(db, () => clock.now, null, { reports: sweeping })+ const tab = (await store.create(owner, randomUUID(), 'Crew', 'public')).id+ const execute = (command: Command, user = owner) => store.execute(user, tab, { operationId: randomUUID(), command })+ const invitation = await execute({ type: 'invite.create', email: host.email, role: 'collaborator', conversationId: 'lead' })+ await execute({ type: 'invite.accept', inviteId: invitation.result.inviteId as string }, host)+ await execute({ type: 'machine.contribute', machineId: 'mac', name: 'Mac', cwd: '/repo', engines: ['codex'], maxAgents: 4 }, host)+ const generation = (await poolRows(store, host, 'mac')).find(p => p.tabId === tab)!.machine.generation+ const beat = (running: string[]) => store.observeMachine(host, tab, 'mac', { generation, resources: { cpuPercent: 10, memoryTotalBytes: 32e9,+ memoryUsedBytes: 4e9, diskFreeBytes: 120e9, diskTotalBytes: 500e9, projectDiskFreeBytes: 120e9, deviceType: 'Laptop', chip: 'Fixture', os: 'macOS',+ gpuPercent: null }, quotas: [], tools: {}, runningHarnessIds: running, stoppedHarnessIds: [] })+ const config = { engine: 'codex', model: 'fixture-model', effort: 'high', contextWindow: 200000, engineVersion: 'fixture' }+ // Its machine's owner's own session: a member on another person's machine runs in its Team account, which the keeper keeps awake.+ const ada = String((await execute({ type: 'agent.add', conversationId: 'lead', machineId: 'mac', harnessId: 'h-ada', name: 'Ada', configuration: config,+ lead: false }, host)).result.agentId)+ await execute({ type: 'crew.add', agentId: ada, role: 'Engineer' })+ await beat(['h-ada'])+ // Asleep, as the keeper leaves it after an idle hour (crewKeep.ts, its own tests): its record says so, and its host closed+ // the session. Written straight to its stored record, as only the keeper's sweep sets it.+ const stored = await db.swarmAgent.findFirstOrThrow({ where: { tabId: tab, key: ada } })+ await db.swarmAgent.update({ where: { id: stored.id }, data: { data: { ...(stored.data as object), asleep: { since: clock.now } } } })+ clock.now += 60_000+ await beat([])+ // New work wakes it; its host reopens the session in place, and the next reading shows it running.+ const task = String((await execute({ type: 'conversation.create', title: 'Fix login', brief: 'Fix it', checks: [] })).result.conversationId)+ clock.now += 1_000+ const wokeAt = clock.now+ await execute({ type: 'work.assign', conversationId: task, agentId: ada })+ clock.now += 7_000+ await beat([])+ clock.now += 11_000+ const backAt = clock.now+ await beat(['h-ada'])+ clock.now += 30_000+ await beat(['h-ada'])+ const rows = (await db.superTabMessage.findMany({ where: { tabId: tab, conversationId: 'lead' } }))+ .filter(m => (m.source as { kind?: string } | null)?.kind === 'crew-timing')+ expect(rows).toHaveLength(1)+ expect(rows[0]!.source).toMatchObject({ what: 'wake', agentId: ada, startedAt: wokeAt, runningAt: backAt })+ expect(rows[0]!.recipientIds).toEqual([])+ })+})diff --git a/backend/integration/superTabRead.test.ts b/backend/integration/superTabRead.test.tsindex ec4ae0f13..053b8f925 100644--- a/backend/integration/superTabRead.test.ts+++ b/backend/integration/superTabRead.test.ts@@ -44,7 +44,9 @@ const DAY = 86_400_000beforeAll(async () => {replica = await MongoMemoryReplSet.create({ binary: { version: '7.0.24', downloadDir: join(tmpdir(), 'harness-super-tab-mongodb-binaries') },replSet: { count: 1, ip: '127.0.0.1', storageEngine: 'wiredTiger' } })- const uri = replica.getUri(`swarm_read_test_${randomUUID().replaceAll('-', '_')}`)+ // The driver's heartbeat (every ten seconds, two answers of about 745 bytes) is traffic the byte count of 'what a read costs' would+ // take for a read's: this client asks once an hour instead. The one node never changes, so nothing here needs the heartbeat.+ const uri = `${replica.getUri(`swarm_read_test_${randomUUID().replaceAll('-', '_')}`)}&heartbeatFrequencyMS=3600000`await promisify(execFile)(join(process.cwd(), 'node_modules/.bin/prisma'), ['db', 'push', '--skip-generate'], {env: { ...process.env, DATABASE_URL: uri }, timeout: 60000,})@@ -1507,6 +1509,13 @@ describe('what a read costs the database (group 3b)', () => {await leftover})+ it('counts none of the driver\'s own heartbeat answers: an idle database sends nothing for longer than one heartbeat', async () => {+ // The driver asks MongoDB how it is every ten seconds and the answer, two of them about 745 bytes each, lands in whatever window+ // is open (1,490 bytes in the batch of 11-06): a window longer than the heartbeat period always holds a whole pair.+ await scene()+ expect(await databaseBytes(() => new Promise(done => setTimeout(done, 11_500)))).toBeLessThan(1_000)+ }, 30_000)+it('a Desktop change read with nothing changed loads a few tens of KB, not the Swarm', async () => {const s = await scene(f => bulky(f))const whole = await swarmBytes(s.tabId)diff --git a/backend/src/superTabs/commands.ts b/backend/src/superTabs/commands.tsindex f772c17ae..26f02a710 100644--- a/backend/src/superTabs/commands.ts+++ b/backend/src/superTabs/commands.ts@@ -1,6 +1,7 @@import { pulseProjectOf, recordPulse, owe, settleDeleted, settleReaction, settleReply, settleRequest } from './pulse.js'import { applyPushOrigin, failPushUnknown, failTeamWritten, mainAccountMembers, markTeamWritten, mayName, requireTeamWrittenAccount, requireTeamWrittenMachine, stepMark, TEAM_WRITTEN_REASON, TEAM_WRITTEN_STOP, teamWrittenTask } from './teamWritten.js'import { crewMoveFailed, takeOverCrewMember, wakeCrewMember } from './crewKeep.js'+import { moveTimingRow, startWake } from './crewTimes.js'import type { PushOrigin } from '../github/pushOrigin.js'import { requireRepositoryReach, unknownPushReason, type RepositoryReach } from './repositoryReach.js'import { admitByRoom, admitMachineStart, noRepositoryStart, failOwnAccountTeamEntry, ownAccountTeamEntry, defaultProfileId, storedProfileId, BUDDY_WINDOWS_REFUSAL, refusesWindowsBuddy, buddyHomeFolder, buddyProjectsOn, SWARM_BUDDY_CAPABILITY, cleanupOverdue, dropIdleBuddyMachines, machineLimitReached, MACHINE_LIMIT_MESSAGE, NOT_SWARM_MACHINE, downSince, expireRemoval, expireRemovals, failTeamWork, machineContribution, machineOffline, machineSlots, contributedEngines, ownedMachine, productManagerOn, projectFolder, projectsOnMachine, requireTeamWork, teamMachineFor, teamAccountPool, teamPoolsOf, teamStartRequest, teamWorkCheck, movedToTeamAccount, type ContributedMachine } from './machines.js'@@ -1666,8 +1667,9 @@ function applyCommandOnce(original: SuperTabState, actor: Actor, input: Command,/** [worker] takes [group]'s work as assignment [assignmentId], after assignRefusal let it: what work.assign writes, and its* brief to the worker. */const assignTo = (group: Conversation, worker: Agent, assignmentId: string) => {- // An asleep crew member wakes for it: its host reopens the session in place (crewKeep.ts).- wakeCrewMember(worker, context.now)+ // An asleep crew member wakes for it: its host reopens the session in place (crewKeep.ts). The wake is timed from here to+ // the first reading that shows it running (crewTimes.ts, task #3462).+ if (wakeCrewMember(worker, context.now)) startWake(worker, group.id, context.now)// A Team agent's work marks the task (teamWritten.ts, audit H2).marking(group, () => markTeamWritten(state, group, worker))delete worker.workDecision@@ -3248,7 +3250,14 @@ function applyCommandOnce(original: SuperTabState, actor: Actor, input: Command,noteStartSucceeded(state, start)result.agentId = agentId// A crew member's move: its new session becomes the same member, and the old one is retired (crewKeep.ts).- if (start.request.crewMoveOf) takeOverCrewMember(state, start, agentId, context.now, target => removeAgent(target))+ if (start.request.crewMoveOf) {+ const move = state.agents.find(a => a.id === start.request.crewMoveOf)?.movedTo+ takeOverCrewMember(state, start, agentId, context.now, target => removeAgent(target))+ // The move is timed from the keeper's pick to this takeover (crewTimes.ts, task #3462), once it took the member over.+ const timed = move && state.agents.find(a => a.id === agentId)?.movedFrom?.agentId === start.request.crewMoveOf+ ? moveTimingRow(state, agentId, move.at, move.reason, context.now) : null+ if (timed) effects.messages.push(timed)+ }// A thread session joins its chat's record, and hears the person's messages sent while it started, by delivery as any// other: its host's person check, run: judging and read grant apply to them too (spec: Security).if (start.request.buddySession) {diff --git a/backend/src/superTabs/crewKeep.ts b/backend/src/superTabs/crewKeep.tsindex 77338fd34..3f2f780e5 100644--- a/backend/src/superTabs/crewKeep.ts+++ b/backend/src/superTabs/crewKeep.ts@@ -7,6 +7,7 @@import type { MachineRule } from './crewRules.js'import { activeWork, actorKey, stableId, type Agent, type AgentStart, type AgentStartRequest, type CrewTrouble, type MessageDraft, type SuperTabState } from './model.js'import { isBuddy } from './buddies.js'+import { isCrew } from './crew.js'import { AGENT_MEMORY_BYTES, projectFolder, type ContributedMachine } from './machines.js'import { agentProjectId, groupProject, onTeamAccount, projectsOf, teamAccountPool } from './projects.js'import { barredFromTeamWritten, teamWrittenTask } from './teamWritten.js'@@ -30,7 +31,6 @@ export interface CrewDeps {}/** Whether [agent] is crew (#3397's `crew` record), read without its type until that change lands. */-export const isCrewMember = (agent: Agent): boolean => !!(agent as Agent & { crew?: { role?: unknown } }).crew/** [machineId]'s contribution while it stands: a withdrawn one (its person left or became a viewer) reads as none, never a* refusal, so a sweep never stops on it. */@@ -136,7 +136,7 @@ export function crewNeedsMachine(state: SuperTabState, now: number): boolean {/** What the keeper does now for the Swarm's crew: one action per member at most, and one low-disk drop per machine. */export function crewKeep(state: SuperTabState, now: number, deps: CrewDeps): CrewAction[] {const actions: CrewAction[] = []- const members = state.agents.filter(a => isCrewMember(a) && !isBuddy(a) && !isLead(state, a) && !a.movedTo)+ const members = state.agents.filter(a => isCrew(a) && !isBuddy(a) && !isLead(state, a) && !a.movedTo)for (const agent of members) {const trouble = crewTrouble(state, standingPool(state, agent.machineId), agent.configuration.engine, now)// An asleep member, or an awake one with no work on a machine gone offline (a laptop closed for the night), stays where itdiff --git a/backend/src/superTabs/crewTimes.test.ts b/backend/src/superTabs/crewTimes.test.tsnew file mode 100644index 000000000..a1a7cc3b3--- /dev/null+++ b/backend/src/superTabs/crewTimes.test.ts@@ -0,0 +1,129 @@+// Task #3462: each crew wake and move is recorded when it finishes, from its start to the moment the agent runs again,+// with its reason (docs/plans/2026-11-06-crew-wake-move-times-plan.md).+import { describe, expect, it } from 'vitest'+import { agentOnly, type Agent, type SuperTabState } from './model.js'+import { crewTimingOf, finishedWakes, moveTimingRow, startWake } from './crewTimes.js'+import { applyCommand, type Command } from './commands.js'+import { applyCrewKeep } from './crewKeep.js'+import { config as crewConfig, fixture, machine, NOW, person } from './crewKeep.test-support.js'++const SECOND = 1000+const T = Date.UTC(2026, 10, 6, 3)+const config = { engine: 'claude', model: 'opus', effort: 'high', contextWindow: null, engineVersion: null }+const member = (over: Partial<Agent> = {}): Agent => ({ id: 'ada', machineId: 'mac', harnessId: 'h-ada', machineOwnerId: 'o', contributorId: 'p',+ membershipGeneration: 'g', name: 'Ada', configuration: config, crew: { role: 'Engineer', at: 1, by: 'p' }, ...over }) as Agent+/** A Swarm whose project chat `chat` is led by `pm`, with [agents], and machine `mac`'s last reading when given. */+const swarm = (agents: Agent[], reading?: { receivedAt: number; running: string[] }) => ({+ id: 't', ownerId: 'p', name: 'S', environment: 'prod', paused: false,+ people: [{ id: 'p', email: '[email protected]', role: 'owner', generation: 'g' }],+ agents: [member({ id: 'pm', harnessId: 'h-pm', name: 'River', crew: undefined }), ...agents],+ projects: [{ id: 'lead', name: 'App', ownerId: 'p', leadConversationId: 'chat', visibility: 'public', members: [] }],+ machines: reading ? [{ machineId: 'mac', name: 'Studio', observation: { runningHarnessIds: reading.running, stoppedHarnessIds: [], receivedAt: reading.receivedAt } }] : [],+ conversations: [{ id: 'chat', title: 'App', leadId: 'pm', agentIds: ['pm', 'ada'], archived: false, brief: '', checks: [], assignment: null, lastMessageSequence: 0 },+ { id: 'task7', number: 7, title: 'Fix login', leadId: null, agentIds: ['ada'], archived: false, brief: '', checks: [], assignment: null, lastMessageSequence: 0 }],+} as unknown as SuperTabState)++describe('a crew wake is timed from the work that woke it to its session running again (#3462)', () => {+ it('finishes at the first reading that lists the session running, with the task as its reason', () => {+ const ada = member()+ startWake(ada, 'task7', T)+ expect(ada.crewWaking).toEqual({ at: T, conversationId: 'task7' })+ // Its session is not back yet: nothing is recorded, and the wake stays open.+ expect(finishedWakes(swarm([ada], { receivedAt: T + 5 * SECOND, running: ['h-pm'] }), T + 6 * SECOND)).toEqual([])+ expect(ada.crewWaking).toBeDefined()+ const rows = finishedWakes(swarm([ada], { receivedAt: T + 12 * SECOND, running: ['h-pm', 'h-ada'] }), T + 14 * SECOND)+ expect(rows).toHaveLength(1)+ expect(rows[0]).toMatchObject({ conversationId: 'chat', recipients: [], author: expect.objectContaining({ kind: 'agent', id: 'pm' }) })+ expect(crewTimingOf(rows[0]!.source)).toEqual({ what: 'wake', agentId: 'ada', startedAt: T, runningAt: T + 12 * SECOND, reason: 'work on #7' })+ // The coordinator's alone: people do not read it.+ expect(agentOnly(rows[0]!.source, rows[0]!.recipients)).toBe(true)+ expect(ada.crewWaking).toBeUndefined()+ })++ it('never counts a reading from before the wake, or a machine that has not read since', () => {+ const ada = member()+ startWake(ada, 'task7', T)+ expect(finishedWakes(swarm([ada], { receivedAt: T - SECOND, running: ['h-ada'] }), T + SECOND)).toEqual([])+ expect(finishedWakes(swarm([ada]), T + SECOND)).toEqual([])+ expect(ada.crewWaking).toBeDefined()+ })++ it('keeps the time it ran again until its project chat is loaded, so a dormant chat loses no wake', () => {+ const ada = member()+ startWake(ada, 'task7', T)+ const unloaded = swarm([ada], { receivedAt: T + 9 * SECOND, running: ['h-ada'] })+ unloaded.conversations = unloaded.conversations.filter(c => c.id !== 'chat')+ expect(finishedWakes(unloaded, T + 10 * SECOND)).toEqual([])+ expect(ada.crewWaking).toEqual({ at: T, conversationId: 'task7', runningAt: T + 9 * SECOND })+ // Later, with the chat loaded and a newer reading: timed to the first reading that showed it running.+ const rows = finishedWakes(swarm([ada], { receivedAt: T + 300 * SECOND, running: ['h-ada'] }), T + 301 * SECOND)+ expect(crewTimingOf(rows[0]!.source)).toMatchObject({ startedAt: T, runningAt: T + 9 * SECOND })+ expect(ada.crewWaking).toBeUndefined()+ })++ it('records one row per wake: a second pass after it finished writes nothing', () => {+ const ada = member()+ startWake(ada, 'task7', T)+ const state = swarm([ada], { receivedAt: T + 3 * SECOND, running: ['h-ada'] })+ expect(finishedWakes(state, T + 4 * SECOND)).toHaveLength(1)+ expect(finishedWakes(state, T + 34 * SECOND)).toEqual([])+ })+})++describe('a crew move is timed from the keeper picking a machine to the new session taking over (#3462)', () => {+ it('writes one row with the move start, the takeover and the trouble that moved it', () => {+ const moved = member({ id: 'ada2', harnessId: 'h-ada2', machineId: 'mini' })+ const state = swarm([moved])+ const row = moveTimingRow(state, moved.id, T, 'offline', T + 140 * SECOND)+ expect(row).toMatchObject({ conversationId: 'chat', recipients: [] })+ expect(crewTimingOf(row!.source)).toEqual({ what: 'move', agentId: 'ada2', startedAt: T, runningAt: T + 140 * SECOND, reason: 'offline' })+ // Retried with the same times: the same row, so it is written once.+ expect(moveTimingRow(state, moved.id, T, 'offline', T + 140 * SECOND)!.id).toBe(row!.id)+ })++ it('reads nothing but its own rows', () => {+ expect(crewTimingOf({ kind: 'system', status: 'done' })).toBeNull()+ expect(crewTimingOf({ kind: 'crew-timing', what: 'nap', agentId: 'a', startedAt: 1, runningAt: 2, reason: 'x' })).toBeNull()+ expect(crewTimingOf({ kind: 'crew-timing', what: 'wake', agentId: 'a', startedAt: 5, runningAt: 2, reason: 'x' })).toBeNull()+ expect(crewTimingOf(null)).toBeNull()+ })+})++// The crew keeper's hooks (#3229 on main): work.assign starts a wake, agent.started's takeover finishes a move.+describe('the crew keeper times its own wakes and moves (#3462)', () => {+ const host = { contribution: { machineOwnerId: 'owner', contributorId: 'owner' } }+ const run = (state: SuperTabState, command: Command, operationId: string, now: number, extra: Record<string, unknown> = {}) =>+ applyCommand(state, person, command, { now, operationId, ...extra })+ const task = (f: ReturnType<typeof fixture>) => {+ f.state = run(f.state, { type: 'conversation.create', title: 'Fix it', brief: 'Fix the thing', checks: [] } as Command, 'task-1', NOW - 3_600_000).state+ return f.state.conversations.find(c => c.title === 'Fix it')!+ }++ it('new work on an asleep member starts its wake; work for an awake one starts none', () => {+ const asleep = fixture()+ asleep.ada.asleep = { since: NOW - 7_200_000 }+ const work = task(asleep)+ asleep.state = run(asleep.state, { type: 'work.assign', conversationId: work.id, agentId: asleep.ada.id } as Command, 'assign-1', NOW).state+ expect(asleep.state.agents.find(a => a.id === asleep.ada.id)!.crewWaking).toEqual({ at: NOW, conversationId: work.id })+ const awake = fixture()+ const other = task(awake)+ awake.state = run(awake.state, { type: 'work.assign', conversationId: other.id, agentId: awake.ada.id } as Command, 'assign-1', NOW).state+ expect(awake.state.agents.find(a => a.id === awake.ada.id)!.crewWaking).toBeUndefined()+ })++ it('a move\'s new session taking over writes one timing row, from the keeper\'s pick to the takeover', () => {+ const f = fixture([machine('mac', { signedIn: false }), machine('mini')])+ applyCrewKeep(f.state, NOW, { admits: () => true })+ const start = f.state.starts!.find(s => s.request.crewMoveOf === f.ada.id)!+ const effects = run(f.state, { type: 'agent.started', startId: start.id, harnessId: 'ada-2', configuration: crewConfig } as Command, 'started-1', NOW + 95_000, host)+ const moved = effects.state.agents.find(a => a.harnessId === 'ada-2')!+ const timings = effects.messages.flatMap(m => crewTimingOf(m.source) ? [{ row: m, timing: crewTimingOf(m.source)! }] : [])+ expect(timings).toHaveLength(1)+ expect(timings[0]!.timing).toEqual({ what: 'move', agentId: moved.id, startedAt: NOW, runningAt: NOW + 95_000, reason: 'signed-out' })+ expect(timings[0]!.row.conversationId).toBe('lead')+ })++ it('the crew keeper reads crew membership through crew.ts isCrew, with no copy of its own', async () => {+ expect(Object.keys(await import('./crewKeep.js'))).not.toContain('isCrewMember')+ })+})diff --git a/backend/src/superTabs/crewTimes.ts b/backend/src/superTabs/crewTimes.tsnew file mode 100644index 000000000..d4857fa68--- /dev/null+++ b/backend/src/superTabs/crewTimes.ts@@ -0,0 +1,82 @@+// Task #3462 (docs/plans/2026-11-06-crew-wake-move-times-plan.md): the design promises a crew member "wakes in seconds" and is+// "moved and running again within 5 minutes". Each wake and each move is recorded when it finishes: its start, the moment the+// agent runs again, and its reason, as one row in its project's chat that only the server reads (NOTICE_READERS+// `crew-timing`). The daily scorecard reads the day's rows (scorecard/figures.ts crewTimesOf), so a member removed since, or+// moved to a new agent, still counts. The crew keeper (crewKeep.ts) calls startWake when new work wakes an asleep member,+// and moveTimingRow when a move's new session takes the member over; the sweep on machine reports calls finishedWakes.+import { agentDisplayName } from './agentNames.js'+import { stableId, type Agent, type Author, type MessageDraft, type SuperTabState } from './model.js'+import { agentProjectId, projectsOf } from './projects.js'++export const CREW_TIMING_KIND = 'crew-timing'+export interface CrewTiming { what: 'wake' | 'move'; agentId: string; startedAt: number; runningAt: number; reason: string }++/** New work in [conversationId] woke [agent] at [now]: its wake is timed from here. */+export function startWake(agent: Agent, conversationId: string, now: number): void {+ agent.crewWaking = { at: now, conversationId }+}++/** The project chat a row about [agentId] goes to, and who writes it: the chat's coordinator, or the member itself without one.+ * Never a lookup that throws: this runs in the sweep on machine reports. */+function placeFor(state: SuperTabState, agentId: string): { conversationId: string; author: Author } | null {+ const member = state.agents.find(a => a.id === agentId)+ if (!member) return null+ const project = projectsOf(state).find(p => p.id === agentProjectId(state, member))+ const chat = project && state.conversations.find(c => c.id === project.leadConversationId)+ if (!chat) return null+ const writer = state.agents.find(a => a.id === chat.leadId) ?? member+ return { conversationId: chat.id, author: { kind: 'agent', id: writer.id, name: writer.name, displayName: agentDisplayName(state.agents, writer.id),+ membershipGeneration: writer.membershipGeneration } }+}++const seconds = (ms: number) => Math.round(ms / 1000)++/** The row recording one finished wake or move: read by the scorecard, by no person, and waking no one. Named by the member and+ * the start, so a retried write is the same row. */+function timingRow(state: SuperTabState, timing: CrewTiming): MessageDraft | null {+ const place = placeFor(state, timing.agentId)+ if (!place) return null+ const name = agentDisplayName(state.agents, timing.agentId) ?? timing.agentId+ const verb = timing.what === 'wake' ? 'woke' : 'moved and ran again'+ return { id: stableId('crew-timing', timing.what, timing.agentId, String(timing.startedAt)), conversationId: place.conversationId, author: place.author,+ replyTo: null, recipients: [], text: `${name} ${verb} in ${seconds(timing.runningAt - timing.startedAt)} s (${timing.reason}).`,+ source: { kind: CREW_TIMING_KIND, ...timing } }+}++/** Every woken crew member whose machine's reading, made since the wake, lists its session running: its wake is recorded as+ * timed to the first such reading, and the mark cleared. A reading from before the wake, or none, finishes nothing; with its+ * project chat not loaded, the time is kept on the mark until a pass that can write the row. */+export function finishedWakes(state: SuperTabState, _now: number): MessageDraft[] {+ const rows: MessageDraft[] = []+ for (const agent of state.agents) {+ const waking = agent.crewWaking+ if (!waking) continue+ const reading = state.machines?.find(m => m.machineId === agent.machineId)?.observation+ if (waking.runningAt === undefined && reading && reading.receivedAt >= waking.at && reading.runningHarnessIds.includes(agent.harnessId)) {+ waking.runningAt = reading.receivedAt+ }+ if (waking.runningAt === undefined) continue+ const task = state.conversations.find(c => c.id === waking.conversationId)+ const row = timingRow(state, { what: 'wake', agentId: agent.id, startedAt: waking.at, runningAt: waking.runningAt,+ reason: task?.number !== undefined ? `work on #${task.number}` : 'new work' })+ // Its project chat not loaded (a dormant one): the time it ran again is kept, and a later pass writes the row.+ if (!row) continue+ delete agent.crewWaking+ rows.push(row)+ }+ return rows+}++/** The row recording a move of the member now [agentId]: from when the keeper picked its machine ([startedAt]) to [now], when+ * its new session took the member over, for [reason] (the trouble that moved it). */+export function moveTimingRow(state: SuperTabState, agentId: string, startedAt: number, reason: string, now: number): MessageDraft | null {+ return timingRow(state, { what: 'move', agentId, startedAt, runningAt: now, reason })+}++/** A timing row's record, or null for any other row or one that does not hold together. */+export function crewTimingOf(source: unknown): CrewTiming | null {+ const s = source as Partial<CrewTiming> & { kind?: unknown } | null | undefined+ if (!s || s.kind !== CREW_TIMING_KIND || (s.what !== 'wake' && s.what !== 'move') || typeof s.agentId !== 'string' || typeof s.reason !== 'string'+ || typeof s.startedAt !== 'number' || typeof s.runningAt !== 'number' || s.runningAt < s.startedAt) return null+ return { what: s.what, agentId: s.agentId, startedAt: s.startedAt, runningAt: s.runningAt, reason: s.reason }+}diff --git a/backend/src/superTabs/model.ts b/backend/src/superTabs/model.tsindex 52f57990b..8f6f99924 100644--- a/backend/src/superTabs/model.ts+++ b/backend/src/superTabs/model.ts@@ -155,6 +155,10 @@ export interface Agent {/** Joined on a Harness Team account's machine: kept, so a machine row that went never brings back the rules of an* ordinary machine (projects.ts teamSessionAccess, security re-review of #2089). */teamAccount?: true+ /** A crew member woken by new work (crewTimes.ts startWake): when, and the task that woke it, until a machine reading shows+ * its session running again (`runningAt`, the first reading that did) and the wake's timing row is written (task #3462). Set+ * only by the server. */+ crewWaking?: { at: number; conversationId: string; runningAt?: number }}/** A thread session's thread root and the main chat's last sequence it may read (buddySessions.ts). A project session also* names its project (buddies.ts; Dee, 10-31): it reads that project alone, and is the only Buddy that writes into it. */@@ -702,6 +706,8 @@ export const NOTICE_READERS = {'tidy-request': 'recipients',// Two agents that may be talking in a loop, told to the coordinator (commands.ts pairLoop, project instructions phase 1).'pair-loop': 'recipients',+ // A crew member's finished wake or move, timed for the daily scorecard (crewTimes.ts, task #3462): read by nobody.+ 'crew-timing': 'agent',// The server's routine notices to the coordinator, gathered into one message (noticeDigest.ts).'notice-digest': 'recipients',// An agent's tag, ask or line to a person, routed to the PM instead (crewNeeds.ts): the PM's alone. Never gathered.diff --git a/backend/src/superTabs/scorecard/figures.test.ts b/backend/src/superTabs/scorecard/figures.test.tsindex c81217933..d2b5b638f 100644--- a/backend/src/superTabs/scorecard/figures.test.ts+++ b/backend/src/superTabs/scorecard/figures.test.ts@@ -200,3 +200,28 @@ describe('scorecardDay', () => {expect(day.agentPosts).toBe(4)})})++// Task #3462: the day's crew wakes and moves, from their timing rows in the project chat.+describe('crew wake and move times (#3462)', () => {+ const timing = (what: 'wake' | 'move', runningAt: number, seconds: number, over: Partial<ScorecardMessage> = {}) =>+ row({ conversationId: 'chat', createdAt: runningAt, source: { kind: 'crew-timing', what, agentId: 'ada', startedAt: runningAt - seconds * 1000,+ runningAt, reason: what === 'wake' ? 'work on #7' : 'offline' }, text: `${what} ${seconds}s`, ...over })++ it('shows the median and slowest wake and move of the day', () => {+ const figures = scorecardDay(input({ messages: [timing('wake', at(2), 8), timing('wake', at(5), 30), timing('wake', at(9), 12),+ timing('move', at(3), 120), timing('move', at(11), 300)] }))+ expect(figures.crewWake).toEqual({ count: 3, medianSeconds: 12, slowestSeconds: 30 })+ expect(figures.crewMove).toEqual({ count: 2, medianSeconds: 210, slowestSeconds: 300 })+ })++ it('counts only the rows of the day, and shows none on a day without any', () => {+ const figures = scorecardDay(input({ messages: [timing('wake', START - MIN, 50), timing('wake', at(1), 6), timing('move', END, 90)] }))+ expect(figures.crewWake).toEqual({ count: 1, medianSeconds: 6, slowestSeconds: 6 })+ expect(figures.crewMove).toEqual({ count: 0, medianSeconds: null, slowestSeconds: null })+ })++ it('reads timing rows only from the project chat, never one a client could write elsewhere', () => {+ const figures = scorecardDay(input({ messages: [timing('wake', at(2), 8, { conversationId: 'task7' }), timing('wake', at(3), 9, { author: { kind: 'person', id: 'dee' } })] }))+ expect(figures.crewWake).toEqual({ count: 0, medianSeconds: null, slowestSeconds: null })+ })+})diff --git a/backend/src/superTabs/scorecard/figures.ts b/backend/src/superTabs/scorecard/figures.tsindex 3e4413b62..04a1a3f41 100644--- a/backend/src/superTabs/scorecard/figures.ts+++ b/backend/src/superTabs/scorecard/figures.ts@@ -2,6 +2,7 @@* A project's scorecard for one local day (task #3386, Dee: judge each change by numbers, daily), from the Swarm's own* records: the reader (records.ts) gathers them, this turns them into counts and minutes. Pure: no clock, no database.*/+import { crewTimingOf } from '../crewTimes.js'import { isAcknowledgement } from '../acknowledgements.js'/** What the figures measure against, written into each row with them so an old row keeps its meaning. */@@ -70,7 +71,12 @@ export interface ScorecardFigures {typedIntoPm: numberackPosts: numberagentPosts: number+ /** The day's crew wakes and moves, from start to running again (crewTimes.ts, task #3462). Absent on days stored before. */+ crewWake?: CrewTimes+ crewMove?: CrewTimes}+/** How many of a kind finished in the day, and their median and slowest time in seconds (null with none). */+export interface CrewTimes { count: number; medianSeconds: number | null; slowestSeconds: number | null }const MIN = 60_000const DAY = 24 * 60 * MIN@@ -161,9 +167,21 @@ export function scorecardDay(input: ScorecardInput): ScorecardFigures {typedIntoPm: dayRows.filter(m => m.source?.kind === 'terminal-input' && pm.has(m.source.agentId as string)).length,ackPosts: ownPosts.filter(m => isAcknowledgement(m.text)).length,agentPosts: ownPosts.length,+ ...crewTimesOf(dayRows, input.chatId),}}+/** The day's crew wakes and moves (crewTimes.ts): the server's timing rows in the project chat, never a person's row or one in+ * another conversation. The chat is read back further than the day, so the rows are the day's already (dayRows). */+function crewTimesOf(dayRows: ScorecardMessage[], chatId: string): { crewWake: CrewTimes; crewMove: CrewTimes } {+ const timings = dayRows.filter(m => m.conversationId === chatId && m.author.kind === 'agent').flatMap(m => crewTimingOf(m.source) ?? [])+ const of = (what: 'wake' | 'move'): CrewTimes => {+ const times = timings.filter(t => t.what === what).map(t => Math.round((t.runningAt - t.startedAt) / 1000))+ return { count: times.length, medianSeconds: median(times), slowestSeconds: times.length ? Math.max(...times) : null }+ }+ return { crewWake: of('wake'), crewMove: of('move') }+}+/** People's top-level asks in the project chat in the lookback (isAsk) that nothing answered by day end: no agent's row in their* thread or replying to them, no delivery answered, no task opened from them. */function unansweredAsks(input: ScorecardInput, messages: ScorecardMessage[], limits: ScorecardLimits): ScorecardMessage[] {diff --git a/backend/src/superTabs/store.ts b/backend/src/superTabs/store.tsindex 39a90add6..b4bfdac6d 100644--- a/backend/src/superTabs/store.ts+++ b/backend/src/superTabs/store.ts@@ -1,5 +1,7 @@import { refusalLogFields, type DeclaredClient } from './refusalLog.js'-import { applyCrewKeep, crewMoveRequest, crewNeedsMachine, isCrewMember, type CrewDeps } from './crewKeep.js'+import { applyCrewKeep, crewMoveRequest, crewNeedsMachine, type CrewDeps } from './crewKeep.js'+import { finishedWakes } from './crewTimes.js'+import { isCrew } from './crew.js'import { writeReactionActivity, writeReplyActivity } from './activity.js'import { phoneNotices, type DecisionRow, type ReplyRow, type TagRow } from '../push/notices.js'import type { PhoneNotice } from '../push/sender.js'@@ -4106,10 +4108,12 @@ export class SuperTabStore {// The crew keeper with the Swarm's time checks (crewKeep.ts): sleep, move off a failing machine, drop folders. A move is// placed only where a start would be admitted now, Team rules included.// The Team facts are read only when a member needs another machine (review of #3229); sleeps and folders need none.- const crew = sweep && state.agents.some(isCrewMember)+ const crew = sweep && state.agents.some(isCrew)? crewNeedsMachine(state, now) ? await this.crewDeps(tx, state, now) : { admits: () => false } : nullconst checked = [...failRefusedStarts(state, machineId, now), ...loseTasks(state, now, worker => worker.machineId === machineId),- ...sweep ? sweepLiveness(state, now) : [], ...crew ? applyCrewKeep(state, now, crew) : []]+ ...sweep ? sweepLiveness(state, now) : [], ...crew ? applyCrewKeep(state, now, crew) : [],+ // A woken crew member this reading shows running again: its wake's timing row (crewTimes.ts, task #3462).+ ...finishedWakes(state, now)]// The 30-second sweep also hands out work when the Swarm, as loaded here, has a free crew member and a task for it.if (sweep && this.hooks.dispatch && projectsOf(state).some(p => !this.pmWaiting(tabId, state, p, now)&& dispatchPlan(state, p.id, DISPATCH_RULES, now, this.refusedSkip(tabId, state, now)).length)) {diff --git a/desktop/lib/super_tabs/scorecard.dart b/desktop/lib/super_tabs/scorecard.dartindex 91810e60a..68b59a331 100644--- a/desktop/lib/super_tabs/scorecard.dart+++ b/desktop/lib/super_tabs/scorecard.dart@@ -20,6 +20,10 @@ class SuperTabScorecardDay {final Map<String, dynamic> figures;int? number(String key) => (figures[key] as num?)?.round();++ /// A figure with parts, such as crewWake's median and slowest (task #3462).+ Map<String, dynamic> parts(String key) =>+ (figures[key] as Map?)?.cast<String, dynamic>() ?? const {};}/// "–" for no figure, "45m" under an hour, "3h10" or "10h" above.@@ -32,6 +36,25 @@ String scorecardDuration(int? minutes) {: '${hours}h${rest.toString().padLeft(2, '0')}';}+/// "–" for no figure, "12s" under a minute, "3m30" or "5m" above.+String scorecardSeconds(int? seconds) {+ if (seconds == null) return '–';+ if (seconds < 60) return '${seconds}s';+ final minutes = seconds ~/ 60, rest = seconds % 60;+ return rest == 0+ ? '${minutes}m'+ : '${minutes}m${rest.toString().padLeft(2, '0')}';+}++/// A crew time's median · slowest of the day, or "–" with none (task #3462).+String _crewTime(SuperTabScorecardDay day, String key) {+ final figure = day.parts(key);+ final median = (figure['medianSeconds'] as num?)?.round();+ final slowest = (figure['slowestSeconds'] as num?)?.round();+ if (median == null || slowest == null) return '–';+ return '${scorecardSeconds(median)} · ${scorecardSeconds(slowest)}';+}+/// One row of the table: its label, the figure it reads and how it says it.class SuperTabScorecardRow {const SuperTabScorecardRow(this.key, this.label, this._say);@@ -105,6 +128,16 @@ final scorecardRows = <SuperTabScorecardRow>['Ack-only posts',(d) => _count(d, 'ackPosts'),),+ SuperTabScorecardRow(+ 'crewWake',+ 'Crew wake time',+ (d) => _crewTime(d, 'crewWake'),+ ),+ SuperTabScorecardRow(+ 'crewMove',+ 'Crew move time',+ (d) => _crewTime(d, 'crewMove'),+ ),];/// The table's columns: [newest] and the 6 days before it, newest first.diff --git a/desktop/lib/super_tabs/scorecard_view.dart b/desktop/lib/super_tabs/scorecard_view.dartindex 477e0758f..67ca6f64b 100644--- a/desktop/lib/super_tabs/scorecard_view.dart+++ b/desktop/lib/super_tabs/scorecard_view.dart@@ -10,7 +10,9 @@ import 'scorecard.dart';/// The widest the table grows.const _maxWidth = 960.0;const _labelWidth = 240.0;-const _cellWidth = 72.0;++/// Wide enough for a crew time's "9m59 · 9m59" on one line (task #3462).+const _cellWidth = 96.0;const _rowHeight = 32.0;/// Manage ▸ Scorecard (task #3386): one project's figures for its last 7diff --git a/desktop/test/super_tab_scorecard_test.dart b/desktop/test/super_tab_scorecard_test.dartindex 29a3f4198..b5a9d38ee 100644--- a/desktop/test/super_tab_scorecard_test.dart+++ b/desktop/test/super_tab_scorecard_test.dart@@ -11,6 +11,8 @@ import 'package:harness/super_tabs/model.dart';import 'package:harness/super_tabs/scorecard.dart';import 'package:harness/super_tabs/scorecard_view.dart';+import 'package:harness/widgets/desktop_chrome.dart';+import 'box_render_preview_test.dart' show loadPreviewFonts;import 'support/super_tab_fixture.dart';@@ -68,6 +70,35 @@ void main() {expect(scorecardRows.first.cell(null), '–');});+ // Task #3462: crew wake and move times, as median · slowest.+ test('crew wake and move times as median and slowest', () {+ expect(scorecardSeconds(null), '–');+ expect(scorecardSeconds(12), '12s');+ expect(scorecardSeconds(210), '3m30');+ expect(scorecardSeconds(300), '5m');+ String cell(String label, Map<String, dynamic> figures) => scorecardRows+ .firstWhere((r) => r.label == label)+ .cell(SuperTabScorecardDay.fromJson(_day('2026-11-05', figures)));+ final day = {+ 'crewWake': {'count': 3, 'medianSeconds': 12, 'slowestSeconds': 30},+ 'crewMove': {'count': 2, 'medianSeconds': 210, 'slowestSeconds': 300},+ };+ expect(cell('Crew wake time', day), '12s · 30s');+ expect(cell('Crew move time', day), '3m30 · 5m');+ // None that day, or a day stored before the figure existed.+ expect(+ cell('Crew wake time', {+ 'crewWake': {+ 'count': 0,+ 'medianSeconds': null,+ 'slowestSeconds': null,+ },+ }),+ '–',+ );+ expect(cell('Crew move time', {}), '–');+ });+test('columns are the 7 days back from the newest row', () {expect(scorecardColumns('2026-11-05'), ['2026-11-05',@@ -211,6 +242,57 @@ void main() {reader.dispose();});+ // Task #3462: a crew time's median · slowest is the widest cell; it stays on one line in its row.+ testWidgets('keeps a crew move time on one line', (tester) async {+ await loadPreviewFonts();+ // Width is a property of a real face: without one (Linux CI has neither the system face nor Roboto), Flutter's test font+ // draws every glyph an em wide, so "i" and "W" measure the same and nothing here means anything. Roboto at the table's+ // 13 px puts "9m59 · 9m59" at 76 px, inside the 96 px cell.+ double width(String text) => (TextPainter(+ text: TextSpan(text: text, style: DesktopChrome.control()),+ textDirection: TextDirection.ltr,+ )..layout()).width;+ if (width('i') == width('W')) {+ markTestSkipped(+ 'needs a real text face to measure; the test font is one em per glyph',+ );+ return;+ }+ final reader = SuperTabScorecardReader(+ tabId: 'tab',+ request: (method, path, {body}) async => {+ 'days': [+ _day('2026-11-05', {+ 'asksShipped': 9,+ 'crewMove': {+ 'count': 2,+ 'medianSeconds': 186,+ 'slowestSeconds': 599,+ },+ }),+ ],+ },+ );+ await tester.binding.setSurfaceSize(const Size(1100, 640));+ addTearDown(() => tester.binding.setSurfaceSize(null));+ await tester.pumpWidget(+ MaterialApp(+ home: Scaffold(+ body: SuperTabScorecardView(+ projects: _projects,+ projectId: 'p0',+ reader: reader,+ ),+ ),+ ),+ );+ await tester.pumpAndSettle();+ final move = tester.getSize(find.text('3m06 · 9m59'));+ final count = tester.getSize(find.text('9'));+ expect(move.height, count.height);+ reader.dispose();+ });+group('screenshots', () {setUpAll(() async {if (shots != null) await loadPreviewFonts();@@ -220,7 +302,7 @@ void main() {final picture = GlobalKey();grid.AppTheme.brightness.value = brightness;addTearDown(() => grid.AppTheme.brightness.value = Brightness.light);- await tester.binding.setSurfaceSize(const Size(1100, 560));+ await tester.binding.setSurfaceSize(const Size(1100, 640));addTearDown(() => tester.binding.setSurfaceSize(null));final reader = SuperTabScorecardReader(tabId: 'tab',@@ -244,6 +326,19 @@ void main() {'routeDecisions': f[9],'typedIntoPm': f[10],'ackPosts': f[11],+ // Crew times start with #3462: older days show "–".+ if (on == '2026-11-05') ...{+ 'crewWake': {+ 'count': 4,+ 'medianSeconds': 14,+ 'slowestSeconds': 41,+ },+ 'crewMove': {+ 'count': 1,+ 'medianSeconds': 186,+ 'slowestSeconds': 186,+ },+ },}),],},diff --git a/docs/plans/2026-11-06-crew-wake-move-times-plan.md b/docs/plans/2026-11-06-crew-wake-move-times-plan.mdnew file mode 100644index 000000000..922cf1106--- /dev/null+++ b/docs/plans/2026-11-06-crew-wake-move-times-plan.md@@ -0,0 +1,77 @@+# The Swarm measures how long a crew member takes to wake or move: implementation plan++> Written by the project's Engineer way of working (project instructions, Engineer): plan first, then each task test first,+> the failing test committed before its code. No Execution Handoff.++**Goal:** Each wake and each move of a crew member is recorded when it finishes, with its start, the moment the agent runs+again and its reason. The daily scorecard shows the median and slowest wake and move of the day, so "wakes in seconds" and+"moved and running again within 5 minutes" are measured (task #3462, requested by Dee through Harness).++**Architecture:** Built on #3229 (crew sleep, wake and move: `crewKeep.ts`) and #3212 (the daily scorecard: `scorecard/`),+both open; this branch merges their heads and its own commits come after. A finished wake or move is one row in the+project chat, coordinator-only (`NOTICE_READERS` `crew-timing`: `agent`), whose source carries+`{ kind: 'crew-timing', what: 'wake' | 'move', agentId, startedAt, runningAt, reason }`. The scorecard already reads the+project chat's rows of the day (scorecard/records.ts), so the figures need no new read and survive the member's removal.++- **Wake:** starts when work.assign wakes an asleep member (`wakeCrewMember`): the agent gets `crewWaking { at, conversationId }`.+ It finishes in the crew sweep on machine reports (store.ts, beside `applyCrewKeep`) when its machine's reading lists the+ session running again (`runningHarnessIds`), at that reading's time. Reason: the task that woke it (`work #N`).+- **Move:** starts when the keeper picks a machine (`movedTo.at`); finishes when the new session starts and takes the member+ over (`takeOverCrewMember`, agent.started), at that command's time. Reason: the move's trouble (offline, signed-out, quota,+ disk).+- **Scorecard:** `crewWake` and `crewMove` figures, each `{ count, medianSeconds, slowestSeconds }` (nulls with none), from+ the day's `crew-timing` rows.+- The crew check is `crew.ts isCrew`; `crewKeep.ts`'s second copy (`isCrewMember`) goes (brief).++**Tech Stack:** TypeScript backend (vitest unit tests; the Super Tab integration suite runs in PR CI).++**Spec:** task #3462 brief and its two acceptance checks.++## Design++- growth: one row per finished wake or move in the project chat (a few a day per member); rows age as any chat row.+ `crewWaking` is cleared when the wake finishes, or by the next sleep.+- concurrency: the wake starts in work.assign's write and finishes in the sweep's write of the same Swarm; a move finishes in+ agent.started's write. No new lock.+- read cost: none new: the scorecard reads the project chat's day already; the sweep reads only the loaded agents.+- scale: 10x crew is 10x rows a day, still small next to the chat's own rows (CHAT_ROW_CAP 20,000 over 7 days).+- compatibility: older clients do not show the row (coordinator-only notice); older scorecard rows have no crew figures and+ read as none.+- migration + rollback: none; rolling back leaves rows nobody reads.+- audience: the server writes the row; its times come from the server's own clock and machine readings, never a client.+- identity: N/A because nothing here acts as a person.+- failure: a wake whose session never runs again is not recorded and is not counted; the scorecard counts only finished+ ones and says how many (count).+- platforms: backend only.++## Global Constraints++- Owns backend/src/superTabs/ only. Swarm code stays out of cli/src/core.+- Numbers none new. No new refusal code.+- Tests use fixture events and fixed clocks; temp files only in mktemp -d folders.++## Review Focus++- A wake is timed from the assignment that woke it to the first reading that shows the session running, not earlier.+- A move is timed from the keeper's pick to the takeover, and the row survives the old agent's removal.+- Median and slowest are right for odd, even and empty days.++## Task 1: a wake and a move are timed from start to running++**Files:** backend/src/superTabs/crewTimes.ts (new), crewTimes.test.ts (new), crewKeep.ts, commands.ts, store.ts, model.ts++**Interfaces:** `startWake(agent, conversationId, now)`, `finishedWakes(state, now): MessageDraft[]`,+`moveTimingRow(state, from, moved, now): MessageDraft | null`, `crewTimingOf(source)`.++- [ ] Test: work.assign wakes an asleep member and marks `crewWaking`; a reading without the session finishes nothing; the+ first reading with it writes one row with startedAt, runningAt and the reason, and clears the mark.+- [ ] Test: a move's takeover writes one row timed from `movedTo.at` to the takeover, with the trouble as reason.+- [ ] Test: crewKeep uses `isCrew` (one crew check).+- [ ] Code.++## Task 2: the scorecard shows median and slowest wake and move times++**Files:** backend/src/superTabs/scorecard/figures.ts, figures.test.ts++- [ ] Test: from fixture rows, median and slowest per kind, odd and even counts, rows outside the day ignored, none -> nulls.+- [ ] Code.