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
Fix routing eligibility for contributed members (#1603)
0xken153e1c3439b865
diff --git a/cli/src/superTabs/route.ts b/cli/src/superTabs/route.tsindex a519079aa..159157eb7 100644--- a/cli/src/superTabs/route.ts+++ b/cli/src/superTabs/route.ts@@ -38,6 +38,7 @@ export interface Probe {quota: Quota; activity: string; known: boolean; refusals: string[]/** Members: the frame (null when it could not be read), whether the member is in the task's repository, and its earlier work in this Super Tab. */frame?: MemberFrame | null; repo?: 'same' | 'different' | 'unknown'; earlier?: Array<{ group: string; outcome: string }>+ terminalUnverified?: boolean/** New agents: what the machine has. */load?: MachineLoad}diff --git a/cli/src/superTabs/routeCommand.spec.ts b/cli/src/superTabs/routeCommand.spec.tsindex a00e6a6e2..4eec3fd69 100644--- a/cli/src/superTabs/routeCommand.spec.ts+++ b/cli/src/superTabs/routeCommand.spec.ts@@ -608,7 +608,7 @@ describe('what the route log says about each candidate', () => {describe('routing contributed capacity', () => {const healthy = () => ({ machineId: 'm1', name: 'Contributed laptop', cwd: '/owner/project', engines: ['claude'], paused: false,observation: { receivedAt: Date.now(), resources: { memoryTotalBytes: 32e9, memoryUsedBytes: 2e9, projectDiskFreeBytes: 200e9 },- tools: { git: true }, runningHarnessIds: [], quotas: [{ engine: 'claude', known: true, windows: [{ name: '5-hour', usedPercent: 20, resetsAt: Date.now() + 3600000 }] }] } })+ tools: { git: true }, runningHarnessIds: ['h1'], quotas: [{ engine: 'claude', known: true, windows: [{ name: '5-hour', usedPercent: 20, resetsAt: Date.now() + 3600000 }] }] } })async function runPool(pool: Record<string, any>, members = false, needs: Record<string, unknown> = {}, project?: Record<string, unknown>) {const groups = conversations()if (project) Object.assign(groups[1]!, { projectId: project.id })@@ -625,6 +625,45 @@ describe('routing contributed capacity', () => {const member = await runPool(healthy(), true)expect(member.answer.ok).toBe(true)})+ it('keeps a healthy contributed member pickable', async () => {+ const { answer, s } = await runPool(healthy(), true)+ expect(answer.ok).toBe(true)+ expect(recorded(s).command.decision.candidates).toEqual(expect.arrayContaining([expect.objectContaining({ title: expect.stringContaining('Multiply') })]))+ })+ it('withholds a contributed member whose engine account has an exhausted usage window', async () => {+ const pool = healthy(); pool.observation.quotas[0]!.windows[0]!.usedPercent = 100+ const { answer } = await runPool(pool, true)+ expect(answer).toMatchObject({ error: 'NO_CANDIDATE' })+ expect(answer.excluded).toEqual(expect.arrayContaining([expect.objectContaining({ title: expect.stringContaining('Multiply'),+ reason: expect.stringContaining('exhausted usage window') })]))+ })+ it('withholds a contributed member when a required tool was reported missing', async () => {+ const pool = healthy(); pool.observation.tools.git = false+ const { answer } = await runPool(pool, true)+ expect(answer).toMatchObject({ error: 'NO_CANDIDATE' })+ expect(answer.excluded).toEqual(expect.arrayContaining([expect.objectContaining({ title: expect.stringContaining('Multiply'),+ reason: expect.stringContaining('Required tool unavailable: git.') })]))+ })+ it('withholds a contributed member absent from an explicit running-terminal list', async () => {+ const pool = healthy(); pool.observation.runningHarnessIds = []+ const { answer, s } = await runPool(pool, true)+ expect(answer).toMatchObject({ ok: true, pick: { kind: 'new' } })+ expect(recorded(s).command.decision.excluded).toEqual(expect.arrayContaining([expect.objectContaining({ title: expect.stringContaining('Multiply'),+ reason: 'Its terminal is not running.' })]))+ })+ it('keeps a contributed member with no running-terminal list pickable and warns that its terminal is unverified', async () => {+ const pool = healthy(); delete (pool.observation as Partial<typeof pool.observation>).runningHarnessIds+ const { answer, s } = await runPool(pool, true)+ expect(answer.ok).toBe(true)+ expect(recorded(s).command.decision.candidates).toEqual(expect.arrayContaining([expect.objectContaining({ title: expect.stringContaining('Multiply') })]))+ expect(answer.warnings).toEqual(expect.arrayContaining([expect.stringContaining('terminal could not be verified')]))+ })+ it('withholds a contributed member when a required device was not reported', async () => {+ const { answer } = await runPool(healthy(), true, { devices: ['/dev/ttyUSB0'] })+ expect(answer).toMatchObject({ error: 'NO_CANDIDATE' })+ expect(answer.excluded).toEqual(expect.arrayContaining([expect.objectContaining({ title: expect.stringContaining('Multiply'),+ reason: expect.stringContaining('Required device unavailable: /dev/ttyUSB0.') })]))+ })it('routes each swarm project to its own checkout and never widens an old folder grant', async () => {const project = { id: 'project-two', repository: { machineId: 'other', cwd: '/elsewhere', repositoryUrl: 'https://github.com/example/two' } }expect((await runPool(healthy(), false, {}, project)).answer.ok).not.toBe(true)diff --git a/cli/src/superTabs/routeCommand.ts b/cli/src/superTabs/routeCommand.tsindex f48346ac4..34b909680 100644--- a/cli/src/superTabs/routeCommand.ts+++ b/cli/src/superTabs/routeCommand.ts@@ -22,6 +22,16 @@ const NO_PROJECT_FOLDER = 'This machine does not have the project folder. Add itconst OFFLINE = 'Machine is offline or unreachable.'const UNKNOWN_QUOTA: Probe['quota'] = { known: false, leftPercent: null, resetsAt: null }const UNKNOWN_LOAD: NonNullable<Probe['load']> = { agents: null, freeMemoryBytes: null, hasFolder: null }+const EXHAUSTED_WINDOW = 'The subscription has an exhausted usage window. Wait for a fresh allowance reading or choose another account.'+/** A running member keeps its engine and memory, but still needs a live terminal, account allowance and the task's tools. */+function memberRefusals(running: boolean | null, quota: Probe['quota'], tools: string[], devices: string[], reportedTools: Json, reportedDevices: Json): string[] {+ return [+ ...(running === false ? ['Its terminal is not running.'] : []),+ ...tools.filter(tool => reportedTools[tool] !== true).map(tool => `Required tool unavailable: ${tool}.`),+ ...devices.filter(device => reportedDevices[device] !== true).map(device => `Required device unavailable: ${device}.`),+ ...(quota.leftPercent === 0 ? [EXHAUSTED_WINDOW] : []),+ ]+}const active = (assignment: unknown) => { const a = object(assignment); return !!a.id && !ENDED_WORK.includes(String(a.status)) }const list = (value: unknown) => Array.isArray(value) ? value.map(object) : []/** The Lead's machine, for the task's folder; replaced in tests. */@@ -183,7 +193,9 @@ export async function routeTask(input: { tabId: string; conversationId: string;ok: true, ...(typeof routeDecisionId === 'string' ? { routeDecisionId } : { unrecorded: true }),pick: publicOf(verdict.pick), via: verdict.via, p: verdict.p, belowFloor: choice.belowFloor, why: verdict.why,alternatives: choice.shown.filter(s => s.id !== verdict.pick.id).slice(0, 2).map(publicOf),- warnings: [...(Array.isArray(effective.warnings) ? effective.warnings : []), ...(value.machinesUnreadable === true ? [MACHINES_UNREADABLE] : []), ...(choice.short ? [choice.short] : [])],+ warnings: [...(Array.isArray(effective.warnings) ? effective.warnings : []), ...(value.machinesUnreadable === true ? [MACHINES_UNREADABLE] : []),+ ...(choice.shown.some(p => p.kind === 'member' && p.terminalUnverified) ? ["A member's terminal could not be verified from its machine's snapshot. Check it before assignment."] : []),+ ...(choice.short ? [choice.short] : [])],next: verdict.pick.kind === 'member'? `Assign with: command OPERATION_ID {"type":"work.assign","conversationId":"${input.conversationId}","agentId":"${verdict.pick.agentId}"${decision}}`: `Start with: start OPERATION_ID ${JSON.stringify({ conversationId: input.conversationId, name: review ? 'Reviewer' : 'Builder', ...(review ? { role: 'reviewer' } : {}), cwd: text(machines.get(verdict.pick.machineId)?.pool?.cwd) ?? assessment.needs.cwd ?? '/absolute/repo/on/that/machine',@@ -196,24 +208,25 @@ async function probeMachine(machineId: string, { name: machineName, status, accomembers: Json[], allModels: Policy['models'], policy: Policy, a: Assessment, where: Where, open: typeof openDaemon): Promise<Probe[]> {const models = pool ? allModels.filter(m => Array.isArray(pool.engines) && pool.engines.includes(m.engine)) : account ? allModels : []const engines = [...new Set([...models.map(m => m.engine), ...members.map(m => String(object(m.configuration).engine) as 'claude' | 'codex')])]- const memberProbe = (m: Json, refusals: string[] = [], quota = UNKNOWN_QUOTA, frame: MemberFrame | null = null): Probe => {+ const memberProbe = (m: Json, refusals: string[] = [], quota = UNKNOWN_QUOTA, frame: MemberFrame | null = null, terminalUnverified = false): Probe => {const c = object(m.configuration), engine = String(c.engine) as 'claude' | 'codex'const model = typeof c.model === 'string' ? c.model : null, effort = typeof c.effort === 'string' ? c.effort : nullreturn { kind: 'member', agentId: String(m.id), name: String(m.name ?? 'Member'), machineId, machineName, engine,model: model ?? 'default', effort: effort ?? 'default', ...rateFor(policy, engine, model, effort),- quota, activity: 'idle', known: quota.known, refusals, frame }+ quota, activity: 'idle', known: quota.known, refusals, frame, terminalUnverified }}const newProbe = (m: Policy['models'][number], refusals: string[], quota: Probe['quota'], known: boolean, load: Probe['load'] = UNKNOWN_LOAD): Probe => ({kind: 'new', machineId, machineName, engine: m.engine, model: m.model, effort: m.effort, quality: m.quality, cost: m.cost,quota, activity: 'new agent', known, refusals, load })const offline = () => models.map(m => newProbe(m, [OFFLINE], UNKNOWN_QUOTA, false))+ const needs = startRequirements(a.needs)if (pool) {const observed = object(pool.observation), resources = object(observed.resources)const fresh = finite(observed.receivedAt) && Date.now() - observed.receivedAt < 45_000const quotas = list(observed.quotas)const quota = (engine: string) => { const q = quotas.find(q => q.engine === engine); return fresh && q ? quotaOf2({ known: q.known === true, windows: list(q.windows).filter(w => finite(w.usedPercent)).map(w => ({ usedPercent: w.usedPercent as number, resetsAt: w.resetsAt, name: text(w.name) ?? undefined })) }) : UNKNOWN_QUOTA }const blocked = [...(!fresh ? [OFFLINE] : []), ...(pool.paused ? ['New work is paused on this machine.'] : [])]- const needs = startRequirements(a.needs), tools = object(observed.tools)+ const tools = object(observed.tools)const newReasons = [...blocked,...(pool.projectUnavailable === true ? ['Its owner must add this machine to the swarm again to support other projects.'] : []),...(pool.repositoryUnavailable === true ? ['Share a repository for this project before starting agents on this machine.'] : []),@@ -222,7 +235,12 @@ async function probeMachine(machineId: string, { name: machineName, status, acco...(!finite(resources.memoryTotalBytes) || !finite(resources.memoryUsedBytes) || resources.memoryTotalBytes - resources.memoryUsedBytes < needs.memoryBytes ? ['Insufficient measured free memory.'] : []),...needs.tools.filter(t => tools[t] !== true).map(t => `Required tool not reported: ${t}.`),...(needs.devices.length ? ['Required devices have not been reported.'] : [])]- return [...members.map(m => memberProbe(m, fresh ? [] : [OFFLINE], quota(String(object(m.configuration).engine)))),+ return [...members.map(m => {+ const allowance = quota(String(object(m.configuration).engine))+ const running = Array.isArray(observed.runningHarnessIds) ? observed.runningHarnessIds.includes(m.harnessId) : null+ return memberProbe(m, fresh ? memberRefusals(running, allowance, needs.tools, needs.devices, tools, object(observed.devices)) : [OFFLINE],+ allowance, null, fresh && running === null)+ }),...models.map(m => newProbe(m, [...newReasons, ...(quota(m.engine).leftPercent === 0 ? ['Subscription exhausted.'] : [])], quota(m.engine), fresh && quota(m.engine).known,{ agents: Array.isArray(observed.runningHarnessIds) ? observed.runningHarnessIds.length : null,freeMemoryBytes: finite(resources.memoryTotalBytes) && finite(resources.memoryUsedBytes) ? resources.memoryTotalBytes - resources.memoryUsedBytes : null,@@ -249,13 +267,12 @@ async function probeMachine(machineId: string, { name: machineName, status, accoconst probes: Probe[] = []for (const m of members) {const inspected = byEngine.get(String(object(m.configuration).engine))!- const refusals = [- ...(live.has(String(m.harnessId)) ? [] : ['Its terminal is not running.']),- // A running member already has its engine, memory and sign-in; only these three can still rule it out.- ...inspected.reasons.filter(r => /usage window|Required tool|Required device/.test(r)),- ]+ const allowance = quotaOf2(inspected.quota)+ const capacity = object(inspected.capacity)+ const refusals = memberRefusals(live.has(String(m.harnessId)), allowance, needs.tools, needs.devices,+ object(capacity.tools), object(capacity.devices))const frame = frames.find(f => f.id === m.harnessId)- probes.push(memberProbe(m, refusals, quotaOf2(inspected.quota), frame ? frameOf(frame) : null))+ probes.push(memberProbe(m, refusals, allowance, frame ? frameOf(frame) : null))}for (const m of models) {const inspected = byEngine.get(m.engine)!