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(cli): send Jev the tier state as four text fields (#1504)
tony496s1d1c39a57c49
diff --git a/cli/e2e/harness/fakeBackend.ts b/cli/e2e/harness/fakeBackend.tsindex 3897ecf6a..898af9093 100644--- a/cli/e2e/harness/fakeBackend.ts+++ b/cli/e2e/harness/fakeBackend.ts@@ -225,7 +225,15 @@ export class FakeBackend {req.on('data', (chunk) => { raw += chunk })req.on('end', () => {if (!backend.jev) { res.statusCode = 503; res.end(json({ success: false, error: { code: 'JEV_BUSY', message: 'Fixture Jev is off.' } })); return }- res.end(json({ success: true, data: { answers: backend.jev(JSON.parse(raw || '{}')) } }))+ const body = JSON.parse(raw || '{}') as Record<string, any>+ // As the real route validates it (backend routes/jevRoute.ts): `state` is a record of strings, four keys+ // at most. A fixture that took anything let a state of numbers and objects through for two days, while+ // the real route answered every one of them with a 400 (2026-10-21).+ const state = body.state+ const valid = !!state && typeof state === 'object' && !Array.isArray(state) && Object.keys(state).length <= 4+ && Object.values(state).every((value) => typeof value === 'string')+ if (!valid) { res.statusCode = 400; res.end(json({ success: false, error: { code: 'VALIDATION_ERROR', message: 'Invalid input: state is a record of at most four strings' } })); return }+ res.end(json({ success: true, data: { answers: backend.jev(body) } }))})return}diff --git a/cli/e2e/notifyTier.e2e.ts b/cli/e2e/notifyTier.e2e.tsnew file mode 100644index 000000000..67a622d0b--- /dev/null+++ b/cli/e2e/notifyTier.e2e.ts@@ -0,0 +1,55 @@+/**+ * A finished turn's tier, decided by Harness's hosted Jev, on the real daemon signed in on the fake backend+ * with a phone paired on the fake relay (services/recaps.ts). The fake route validates the request as the+ * real one does (backend routes/jevRoute.ts: `state` is a record of at most four strings), so a state the+ * real route would refuse fails here too: on 2026-10-21 every decision in production was refused with a 400+ * and fell back to the duration rule, while a fixture that took anything said all was well.+ */+import { mkdirSync } from 'node:fs'+import { join } from 'node:path'+import { afterEach, describe, expect, it, onTestFailed } from 'vitest'+import { LocalClient } from './harness/client.js'+import { until } from './harness/daemon.js'+import { startPhoneMachine, type PhoneMachine } from './harness/fleet.js'+import { RelayPhone } from './harness/relayPhone.js'++describe('a finished turn\'s tier, decided by Harness\'s Jev', () => {+ let world: PhoneMachine | undefined+ let phone: RelayPhone | undefined+ afterEach(async () => {+ phone?.close()+ await world?.close()+ world = undefined; phone = undefined+ })++ it('asks the hosted route in the shape it takes, and the phone hears the tier Jev chose', async () => {+ const w = await startPhoneMachine()+ world = w+ const { backend, machine } = w+ onTestFailed(() => { console.log(`---- daemon log\n${machine.daemon.log().split('\n').slice(-120).join('\n')}`) })+ const asked: Array<Record<string, any>> = []+ backend.jev = (body) => { asked.push(body); return { tier: { choice: 'alert', probabilities: { alert: 0.9, list: 0.05, silent: 0.05 } } } }+ const desk = await LocalClient.connect(machine.daemon, { machineId: machine.machineId })+ const cwd = join(machine.daemon.projectsDir, 'tiered')+ mkdirSync(cwd, { recursive: true })+ const created = await desk.request('agent_create', { engine: 'claude', cwd, bypassPermission: true }, 60_000)+ expect(created.error, JSON.stringify(created)).toBeUndefined()+ const agentId: string = created.agent.id+ await until('the agent to bind its conversation', async () =>+ ((await desk.request<{ agents: Array<Record<string, any>> }>('agents_list', { includeStopped: true })).agents.find((a) => a.id === agentId)?.sessionId) || null, 45_000, 500)+ desk.close()++ phone = new RelayPhone({ backend, machineId: machine.machineId, identity: w.phone.identity, machinePub: machine.identity.pub, token: w.phone.token })+ await until('the machine to be on the relay', () => backend.nodeUp(machine.machineId) || null, 30_000)+ await phone.open(30_000)+ const summary = phone.next((frame) => frame.type === 'turn_summary' && frame.agentId === agentId, 60_000, 'turn_summary')+ expect(phone.send('message', { agentId, content: 'ship it' })).toBe(true)+ expect((await summary).payload?.tier).toBe('alert')++ expect(asked).toHaveLength(1)+ const state = asked[0].state as Record<string, unknown>+ expect(Object.keys(state).sort()).toEqual(['agent', 'recap', 'recent', 'turn'])+ expect(Object.values(state).every((value) => typeof value === 'string')).toBe(true)+ expect(machine.daemon.log()).toMatch(/\[recap\] notify · .* · alert · jev · p=alert=0\.90/)+ })+})diff --git a/cli/src/lib/notifyTier.spec.ts b/cli/src/lib/notifyTier.spec.tsindex 015bf5532..c9cf4ca3c 100644--- a/cli/src/lib/notifyTier.spec.ts+++ b/cli/src/lib/notifyTier.spec.ts@@ -1,6 +1,6 @@import { describe, expect, it, vi } from 'vitest'import { JevUnavailable } from './jev/jevClient.js'-import { createTierDecider, fallbackTier, isTier, type TierInput } from './notifyTier.js'+import { createTierDecider, fallbackTier, isTier, tierState, type TierInput } from './notifyTier.js'const base: TierInput = {agent: 'lamp', engine: 'codex', recap: 'Shipped the thing.', durationS: 300,@@ -49,14 +49,32 @@ describe('notifyTier', () => {expect(jev).toHaveBeenCalledTimes(1)const [state, questions] = jev.mock.calls[0] as any[]expect(state.recap.length).toBeLessThanOrEqual(600)- expect(state).toMatchObject({- agent: 'lamp', engine: 'codex', duration_s: 300,- work: { tests_passed: 640, tests_failed: 0, commits: 1 }, recent: { alerts_30m: 0, lists_30m: 0 },+ expect(state).toEqual({+ agent: 'lamp (codex)', recap: 'x'.repeat(600), turn: 'ran 300 s; tests 640 passed, 0 failed; 1 commit',+ recent: '0 alerts and 0 list entries in the last 30 minutes',})expect(Object.keys(questions)).toEqual(['tier'])expect(Object.keys(questions.tier.criteria)).toEqual(['alert', 'list', 'silent'])})+ it('shows Jev four fields of text, as the hosted route takes them (a record of strings, four keys at most)', () => {+ const shapes = [+ tierState(base, { alerts: 2, lists: 5 }),+ tierState({ ...base, agent: '', engine: '', durationS: null, stats: {} }, { alerts: 0, lists: 0 }),+ tierState({ ...base, engine: '', stats: { testsFailed: 2, commits: 3 } }, { alerts: 0, lists: 1 }),+ tierState({ ...base, agent: '', stats: { testsPassed: 4 } }, { alerts: 0, lists: 0 }),+ ]+ for (const state of shapes) {+ expect(Object.keys(state)).toHaveLength(4)+ expect(Object.values(state).every((value) => typeof value === 'string')).toBe(true)+ }+ expect(shapes[0]).toEqual({ agent: 'lamp (codex)', recap: 'Shipped the thing.', turn: 'ran 300 s; tests 640 passed, 0 failed; 1 commit',+ recent: '2 alerts and 5 list entries in the last 30 minutes' })+ expect(shapes[1]).toMatchObject({ agent: 'an agent', turn: 'duration unknown' })+ expect(shapes[2]).toMatchObject({ agent: 'lamp', turn: 'ran 300 s; tests 0 passed, 2 failed; 3 commits' })+ expect(shapes[3]).toMatchObject({ agent: 'an agent (codex)', turn: 'ran 300 s; tests 4 passed, 0 failed' })+ })+it('Jev unavailable / too slow / null answer → fallback by duration', async () => {const down = make(vi.fn(async () => { throw new JevUnavailable('NO_KEY', 'no key') }))expect(await down.decide(base)).toMatchObject({ tier: 'list', by: 'fallback:NO_KEY' })@@ -93,10 +111,10 @@ describe('notifyTier', () => {for (let i = 0; i < 3; i++) { t = i * 60_000; await decide(base) }t = 4 * 60_000await decide(base)- expect((jev.mock.calls[3] as any[])[0].recent.alerts_30m).toBe(3)+ expect((jev.mock.calls[3] as any[])[0].recent).toBe('3 alerts and 0 list entries in the last 30 minutes')t = 31 * 60_000await decide(base)- expect((jev.mock.calls[4] as any[])[0].recent.alerts_30m).toBe(2)+ expect((jev.mock.calls[4] as any[])[0].recent).toBe('2 alerts and 0 list entries in the last 30 minutes')})it('5 concurrent decisions resolve independently within the budget', async () => {diff --git a/cli/src/lib/notifyTier.ts b/cli/src/lib/notifyTier.tsindex bc84bab54..552caf241 100644--- a/cli/src/lib/notifyTier.ts+++ b/cli/src/lib/notifyTier.ts@@ -29,13 +29,34 @@ const QUESTIONS: Record<string, JevChoice> = {type: 'choice',instructions: 'An AI coding agent just finished a turn while its owner was looking at something else. Choose how loudly to tell them.',criteria: {- alert: 'A substantial result the person would want to know about now, such as a long task finished, a build or deploy done, or a requested deliverable ready. Less likely when alerts_30m is already high.',+ alert: 'A substantial result the person would want to know about now, such as a long task finished, a build or deploy done, or a requested deliverable ready. Less likely when recent already shows several alerts.',list: 'Real progress worth a glance later, such as a small feature or a fix with edits.',silent: 'Chatter, such as an acknowledgement, a short answer, a no-op, or a step inside a longer job.',},},}+/**+ * What Jev is shown of a turn: four fields of text. Harness's hosted Jev takes nothing else (backend+ * routes/jevRoute.ts: `state` is a record of strings, four keys at most), and on 2026-10-21 every decision+ * there was refused with a 400 — the state carried numbers and nested objects — so every turn fell back+ * to the duration rule and none was ever an alert.+ */+export function tierState(input: TierInput, recent: { alerts: number; lists: number }): Record<string, string> {+ const { testsPassed, testsFailed, commits } = input.stats+ const turn = [+ input.durationS === null ? 'duration unknown' : `ran ${input.durationS} s`,+ ...(testsPassed !== undefined || testsFailed !== undefined ? [`tests ${testsPassed ?? 0} passed, ${testsFailed ?? 0} failed`] : []),+ ...(commits ? [`${commits} ${commits === 1 ? 'commit' : 'commits'}`] : []),+ ]+ return {+ agent: input.engine ? `${input.agent || 'an agent'} (${input.engine})` : input.agent || 'an agent',+ recap: input.recap.slice(0, RECAP_MAX),+ turn: turn.join('; '),+ recent: `${recent.alerts} alerts and ${recent.lists} list entries in the last 30 minutes`,+ }+}+/** Logs one decision line and the day's running count per tier, so the volume can be read from the log (no storage). */export function createTally(log: (line: string) => void, now: () => number = Date.now): (agent: string, tier: Tier, by: string, detail: string, ms: number) => void {let day = ''@@ -82,11 +103,7 @@ export function createTierDecider(opts: {finish(fallbackTier(input.durationS), `fallback:${reason}`, input.durationS === null ? 'duration unknown' : `${input.durationS}s`)if (!opts.jev) return fallback('off')- const state = {- agent: input.agent, engine: input.engine, recap: input.recap.slice(0, RECAP_MAX), duration_s: input.durationS,- work: { tests_passed: input.stats.testsPassed, tests_failed: input.stats.testsFailed, commits: input.stats.commits },- recent: { alerts_30m: count('alert'), lists_30m: count('list') },- }+ const state = tierState(input, { alerts: count('alert'), lists: count('list') })const abort = new AbortController()let timer: ReturnType<typeof setTimeout> | undefinedconst late = new Promise<'timeout'>((resolve) => { timer = setTimeout(() => { abort.abort(); resolve('timeout') }, budgetMs) })diff --git a/cli/src/services/devices.spec.ts b/cli/src/services/devices.spec.tsindex 3091348bf..72944d382 100644--- a/cli/src/services/devices.spec.ts+++ b/cli/src/services/devices.spec.ts@@ -418,9 +418,8 @@ describe('what the windows say, reaching the dial', () => {]))expect(backend).toHaveBeenCalledExactlyOnceWith('POST', '/api/route/jev', {state: {- agent: '', engine: '', recap: 'The requested build is ready.', duration_s: null,- work: { tests_passed: undefined, tests_failed: undefined, commits: undefined },- recent: { alerts_30m: 0, lists_30m: 0 },+ agent: 'an agent', recap: 'The requested build is ready.', turn: 'duration unknown',+ recent: '0 alerts and 0 list entries in the last 30 minutes',},questions: { tier: {type: 'choice', instructions: expect.any(String),diff --git a/cli/src/services/recaps.spec.ts b/cli/src/services/recaps.spec.tsindex 5ba0e377e..4daacea6e 100644--- a/cli/src/services/recaps.spec.ts+++ b/cli/src/services/recaps.spec.ts@@ -317,7 +317,7 @@ describe('the recaps', () => {await turn(tell, watching)await vi.waitFor(() => expect(core.clients.turnSummary).toHaveBeenCalled())expect(backend).toHaveBeenCalledExactlyOnceWith('POST', '/api/route/jev', expect.objectContaining({- state: expect.objectContaining({ agent: 'app', engine: 'codex', duration_s: 0 }) }))+ state: { agent: 'app (codex)', recap: expect.any(String), turn: 'ran 0 s', recent: '0 alerts and 0 list entries in the last 30 minutes' } }))expect(vi.mocked(core.clients.turnSummary).mock.calls[0][0]).toMatchObject({ payload: { tier: 'alert' } })})})