Public: anyone can read this; the crew can change it.

Lending speaks the versioned agent protocol, and each machine's page shows when it last used the old sync route #18521

opened this

Merged 2h 30m ago, live in production

Lending now speaks agent protocol 1, and the runners page, terminal and game-box page show each machine's protocol version and last old-route use. The new tests pass, the type check is clean, and so do the existing lend, runners and page-budget suites I ran. I did not run the whole suite.

Notes

opened this

Lending now speaks agent protocol 1, and the runners page, terminal and game-box page show each machine's protocol version and last old-route use. The new tests pass, the type check is clean, and so do the existing lend, runners and page-budget suites I ran. I did not run the whole suite. The gate still flags the commit's Looks: line, because /settings/runners is not a page named in forge.json app.looks. The push went through.

What changed

  • Lender: the lending code is in src/games/agent.sh, not lend.ts, which only enrols and revokes the runner on the forge side. Its claim now goes to /api/v1/agent/v1/claim with v:1 and the runner token. Its job reports go to /logs (an empty lines renews the lease) or /result (when the body has done, abandon or interrupted), using the job token. The box's own runner process already sent version 1, so only the shell lender was left.
  • Version 0: a lender still on /api/v1/runner/* is answered as before and recorded as lender, version 0. The alias route and shell.ts are untouched.
  • Machine pages: a new protocolWords in src/machines/agent_use.ts gives "Speaks agent protocol N. Last used the old sync route on <date>." It adds "over 30 days ago: the alias may go" after 30 days, and "Never used the old sync route: the alias may go." if the machine never used it. It shows as a Protocol fact on Settings → Runners and as a line in the game box's live block. The terminal screens for runners and games carry the same words, and docs/features/lending.md has a short section on it.
  • Tests: test/agent-lend-v1.test.ts covers:
    • a lender's heartbeat, claim, logs and result on version 1;
    • a version 0 lender replay;
    • agent.sh sending only the new routes;
    • the words for each case;
    • the runners page showing the last use.
  • Reuse: I did not run similar.ts. I reused the existing noteUse/agent_use table, the runner handlers behind v1, and row facts.

Left out

  • There is no test for the game-box page line or the terminal lines.
  • I did not check agent.sh against a live box or the preview, only its text and the unit tests.
  • The old routes are not removed.

For forge-apple (the Mac helper, not in this repo)

  • Auth: send with a helper-role token to POST /api/v1/agent/v1/<message>, as JSON with "v": 1 in every body.
  • Messages: the five are heartbeat, claim, logs, result and containers.
  • Helper limits: the helper role may send only heartbeat ({v:1, state:"idle"|"busy"|"paused"}), and anything else returns 403 naming the role.
  • If it also works as a runner: that role needs claim (wait 0–25, cells, jobs, machine), logs (job, lines, optional step and paused) and result (job plus exactly one of done, abandon or interrupted, with optional kept). It sends logs and result with the job token from the claim.
  • Version: a missing or different v returns 400 bad_version.

Try it: open /settings/runners on the preview as an admin and read the Protocol fact on a runner that has spoken.

Closes #18515

3 earlier comments
commented

Lending now speaks agent protocol 1, and the runners page, terminal and game-box page show each machine's protocol version and last old-route use. The new tests pass, the type check is clean, and so do the existing lend, runners and page-budget suites I ran. I did not run the whole suite. The gate still flags the commit's Looks: line, because /settings/runners is not a page named in forge.json app.looks. The push went through.

What changed

  • Lender: the lending code is in src/games/agent.sh, not lend.ts, which only enrols and revokes the runner on the forge side. Its claim now goes to /api/v1/agent/v1/claim with v:1 and the runner token. Its job reports go to /logs (an empty lines renews the lease) or /result (when the body has done, abandon or interrupted), using the job token. The box's own runner process already sent version 1, so only the shell lender was left.
  • Version 0: a lender still on /api/v1/runner/* is answered as before and recorded as lender, version 0. The alias route and shell.ts are untouched.
  • Machine pages: a new protocolWords in src/machines/agent_use.ts gives "Speaks agent protocol N. Last used the old sync route on <date>." It adds "over 30 days ago: the alias may go" after 30 days, and "Never used the old sync route: the alias may go." if the machine never used it. It shows as a Protocol fact on Settings → Runners and as a line in the game box's live block. The terminal screens for runners and games carry the same words, and docs/features/lending.md has a short section on it.
  • Tests: test/agent-lend-v1.test.ts covers:
    • a lender's heartbeat, claim, logs and result on version 1;
    • a version 0 lender replay;
    • agent.sh sending only the new routes;
    • the words for each case;
    • the runners page showing the last use.
  • Reuse: I did not run similar.ts. I reused the existing noteUse/agent_use table, the runner handlers behind v1, and row facts.

Left out

  • There is no test for the game-box page line or the terminal lines.
  • I did not check agent.sh against a live box or the preview, only its text and the unit tests.
  • The old routes are not removed.

For forge-apple (the Mac helper, not in this repo)

  • Auth: send with a helper-role token to POST /api/v1/agent/v1/<message>, as JSON with "v": 1 in every body.
  • Messages: the five are heartbeat, claim, logs, result and containers.
  • Helper limits: the helper role may send only heartbeat ({v:1, state:"idle"|"busy"|"paused"}), and anything else returns 403 naming the role.
  • If it also works as a runner: that role needs claim (wait 0–25, cells, jobs, machine), logs (job, lines, optional step and paused) and result (job plus exactly one of done, abandon or interrupted, with optional kept). It sends logs and result with the job token from the claim.
  • Version: a missing or different v returns 400 bad_version.

Try it: open /settings/runners on the preview as an admin and read the Protocol fact on a runner that has spoken.

commented

<!-- look-pages bb85037a2e79 --> Look pages for bb85037, from the gate:

  • look pages (none): "Looks: /settings/runners" is not a page of app.looks in forge.json; this pull changes src/web/games_machine.ts, src/web/pages/runners.ts but the forge could not trace the route of /, /admin/telemetry, /explore and 28 more (an inline or wrapped handler), so it could not infer a page; the reviewer decides. A "Looks: <path>" line naming the nearest page, or a "No look: <why>" line (10+ characters), says it
commented

I fixed the look-pages complaint and pushed. bun scripts/gate.ts now passes with no look-pages line. I ran only the gate, so tsc and the tests were not run this round. No source changed.

  • Look pages: /settings/runners isn't in app.looks, and the gate couldn't trace a nearest page. So the new commit carries a No look: line instead. It says the page needs a signed-in owner with a runner that has spoken, which the look fixtures don't have. I didn't add the page to app.looks, because that would need a fixture runner, which is a larger change than this pull.
  • Both doors: this pull already changes src/tui/screens/runners.ts, src/tui/screens/games.ts and docs/features/lending.md. The new commit message names them.
  • Not touched: the other three refusals (duplicate import, dead code, first-view budget) have no new exports, imports or page weight behind them in this pull, so I changed nothing for them.
  • Gate note: the gate says two files have comment lines over 100 columns and the nightly rewrap handles them on main, so I left them.

What the pull does: lending sends claim, logs and result as agent protocol 1. A machine's page shows its protocol version and when it last used the old sync route.

To try it: open /settings/runners on the preview and read the Protocol fact of a runner that has spoken.

🤖 Generated with Claude Code

commented

Round two changes how runner protocol words are read, and adds tests that run the real jq and routes. Source changes are in src/machines/agent_use.ts and the two runners screens; the rest is tests. The new tests pass, the gate is clean and tsc is clean. I did not run the full suite, which the forge runs on this push.

What changed

  • N+1 removed. protocolWordsFor(db, ids, now) reads agent_use once with WHERE machine IN (...) for every runner. Settings → Runners and the terminal runners screen each make one call per redraw and read from that map. protocolWords (single machine) is now a call to it and still serves the game box.
  • Round-trip test: test/agent-lend-v1.test.ts now offers a job through a real pull whose check is waiting, with a lent runner past its canary. The claim must return 200. logs must return exactly 200 and leave the job claimed; result with abandon must return 200 and the job must stop being claimed.
  • jq test: the test cuts lend_post out of agent.sh and runs it in bash with curl stubbed to print the data and URL it would send. It runs three bodies:
    • {} gives logs with {v:1, job, lines:[]}.
    • {step, lines} gives logs with the same lines.
    • {done} gives result with no lines key.

    Each output is posted to the real /api/v1/agent/v1/logs or result route and must get 200, and the final {ended:true} is checked.

  • Game box and terminal tests:
    • Game box: liveBlock has no data-protocol before the box has spoken. After noteUse it has the line.
    • Terminal box screen: it shows "Speaks agent protocol" only after the box has spoken.
    • Terminal runners screen: the row shows the protocol line once.
  • Doors: the commit says No door: because the page and terminal already showed the same words; this only batches their read and adds tests.
  • Test shape: the old test accepted [200,503,404] for logs and result, and the job was never claimed. The 404 I first got was because a hand-offered job has no waiting check, so the job needs a real pull.

What I left out

  • The runners screen test uses a 300-column terminal. The row's meta is dropped when it doesn't fit 120 columns.
  • The old sync route is not removed, as the issue says.
  • /settings/runners is not in app.looks (the earlier No look: line stands).

What the Mac helper must send (from src/machines/protocol.ts; I could not find a builder's comment with this list, so I wrote it from the code):

  • Endpoint: POST /api/v1/agent/v1/<message>, with Authorization: Bearer <token> and a JSON body that carries "v": 1.
  • Role and message: the token's role is helper, and a helper token may send heartbeat only. Any other message gets 403 wrong_role.
  • The five messages and who may send each:
    • heartbeat: box, runner, lender, helper.
    • claim: runner, lender.
    • logs: box, runner, lender.
    • result: box, runner, lender.
    • containers: box only.
  • Old route: version 0 (/api/v1/games/agent/sync, /api/v1/runner/…) still works. agent_use records the last day each machine used it, and after 30 days without a call the pages say the alias may go.

To try it: open /settings/runners on the preview and read the Protocol fact of a runner that has spoken. A game box's page shows the same line under its status.

🤖 Generated with Claude Code

Sign in to join this conversation.

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs