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

As code: infra.json in a repo, written by the UI, reconciled on merge (#16696) #17149

opened this

Merged 37h 44m ago, live in production

Phases 1 and 2 of #17075 are on this branch: the infra.json schema and a read-only diff against what runs. Writing the file from the UI and reconciling on merge are not built. The earlier pull #17089 was closed on conflicts; this brings the branch up to date with main.

Notes

opened this

Phases 1 and 2 of #17075 are on this branch: the infra.json schema and a read-only diff against what runs. Writing the file from the UI and reconciling on merge are not built. The earlier pull #17089 was closed on conflicts; this brings the branch up to date with main.

What changed

  • Schema and diff: src/cloud/infra_file.ts parses the file and diffs it, as pure functions. The schema is closed, so an unknown key is refused. Every problem is named with its path, and the file is capped at 64 KiB and 50 machines. The file never names an app, so it can't touch another repo's machines. A declared name that another app already runs shows as blocked and is never applied.
  • Reading: src/cloud/infra_read.ts reads each app's file from its default branch, diffs it against the pinned machines, and caches the read per forge and tip.
  • Where it shows: an "As code" block on /infra, rows on the terminal Infrastructure screen, GET /api/v1/admin/infra/code (with its OpenAPI route), and the infra tool's code action. docs/features/infra.md is updated, and forge.json lists /infra as a look.
  • Conflicts: merging main hit four conflicts, in docs/features/infra.md, src/http/api/admin.ts, src/http/mcp/tools/infra.ts and src/tui/screens/infra.ts. I kept both sides in each, so main's managed-database work (#17074) sits alongside the code block.

Checks

  • bun x tsc --noEmit is clean.
  • test/infra-file.test.ts and test/route-timing-coverage.test.ts pass (15 tests).
  • bun scripts/gate.ts reports no failures, only a note about long comment lines that the nightly rewrap handles.
  • I did not run the full suite; the forge's check does that on push.

Left out

  • UI commits: the page writing infra.json as a commit.
  • Reconcile on merge: applying the file when it lands on main. Nothing here makes or ends a machine.
  • Both are named as "not yet" in the docs.

Try it: as an admin, commit an infra.json to an app's default branch, then open /infra, or call GET /api/v1/admin/infra/code.

Closes #17075

3 earlier comments
commented

Phases 1 and 2 of #17075 are on this branch: the infra.json schema and a read-only diff against what runs. Writing the file from the UI and reconciling on merge are not built. The earlier pull #17089 was closed on conflicts; this brings the branch up to date with main.

What changed

  • Schema and diff: src/cloud/infra_file.ts parses the file and diffs it, as pure functions. The schema is closed, so an unknown key is refused. Every problem is named with its path, and the file is capped at 64 KiB and 50 machines. The file never names an app, so it can't touch another repo's machines. A declared name that another app already runs shows as blocked and is never applied.
  • Reading: src/cloud/infra_read.ts reads each app's file from its default branch, diffs it against the pinned machines, and caches the read per forge and tip.
  • Where it shows: an "As code" block on /infra, rows on the terminal Infrastructure screen, GET /api/v1/admin/infra/code (with its OpenAPI route), and the infra tool's code action. docs/features/infra.md is updated, and forge.json lists /infra as a look.
  • Conflicts: merging main hit four conflicts, in docs/features/infra.md, src/http/api/admin.ts, src/http/mcp/tools/infra.ts and src/tui/screens/infra.ts. I kept both sides in each, so main's managed-database work (#17074) sits alongside the code block.

Checks

  • bun x tsc --noEmit is clean.
  • test/infra-file.test.ts and test/route-timing-coverage.test.ts pass (15 tests).
  • bun scripts/gate.ts reports no failures, only a note about long comment lines that the nightly rewrap handles.
  • I did not run the full suite; the forge's check does that on push.

Left out

  • UI commits: the page writing infra.json as a commit.
  • Reconcile on merge: applying the file when it lands on main. Nothing here makes or ends a machine.
  • Both are named as "not yet" in the docs.

Try it: as an admin, commit an infra.json to an app's default branch, then open /infra, or call GET /api/v1/admin/infra/code.

commented

Title (retitle the pull to this): infra.json: a read-only view of what the repo declares against what runs (#17075, phases 1–2). This does not close #17075 or #16696.

An app's repo may hold infra.json at its root. /infra, the terminal's Infrastructure screen, GET /api/v1/admin/infra/code and the infra tool's code action show what applying it would add, change or remove. Nothing is applied. Every door is admin-only, the schema is closed and capped at 64 KiB and 50 machines, and output is escaped through html``.

Changes after review

  1. lifetimeDays: I dropped it from the schema rather than compare it. A file that sets it is now refused as an unknown key, so "matches what runs" can't be false for it. The new test fails if the field is accepted again. A lifetime comes back with the reconcile, when the diff can compare it.
  2. Speed: infraCode now looks up each repo's tip at most once every 5 s, in a per-forge cache. A blob is read only when the tip moves. The terminal screen already loads the block after first paint. I did not measure the time on the preview, so there is no figure to show. I ran test/infra-file.test.ts, tsc and design-lint, which pass. scripts/fast.ts named 3082 test files (about 260 min), so I did not run it, and the forge's check will run the full suite.
  3. Follow-ups: I did not open issues for the UI write and the reconcile. Please open them and link them under #17075.
  4. forge.json: /infra is not a look. It was removed in f939e62 because app.looks is at its 32-path cap. The earlier description was wrong about this.
  5. Design: the As code block is now one rowList. Each app has a row (title: the app, meta: its summary), followed by its problems and changes as rows. The <h3> and the muted paragraph are gone. No new classes, and design-lint is clean.

Not done: writing the file from the UI, reconciling on merge, and lifetimeDays.

Try it: as an admin, commit an infra.json to an app's main branch and open /infra. The same text appears with GET /api/v1/admin/infra/code.

[
 {"go":"/infra (admin, an app repo with infra.json on main)","look":"An 'As code' section, one row per app with its summary, then its changes as rows","expect":"No headings or paragraphs inside the section; 'matches what runs' appears only on the app row","ask":"Is the per-app row enough to see which file a change belongs to?"},
 {"go":"/infra with a malformed infra.json (an unknown key, or lifetimeDays)","look":"A row 'infra.json is refused: machines[0].… : not a key of a machine'","expect":"The path of the problem is named; nothing is applied"},
 {"go":"/infra as a non-admin","look":"The page","expect":"403, no As code block"}
]

🤖 Generated with Claude Code

commented

I merged main into the branch and pushed it. The only conflict was the import block in src/http/mcp/tools/infra.ts. I kept both sides: this pull's infraCode import and main's new firewallWant.

tsc is clean and test/infra-file.test.ts passes (12 tests). I did not run the wider suite, because scripts/fast.ts names about 260 minutes of tests. The forge's check will run it on this push.

Title: infra.json: a read-only view of what the repo declares against what runs (#17075, phases 1–2). It does not close #17075 or #16696.

An app's repo may hold infra.json at its root. /infra, the terminal's Infrastructure screen, GET /api/v1/admin/infra/code and the infra tool's code action show what applying it would add, change or remove. Nothing is applied. Every door is admin-only, the schema is closed and capped at 64 KiB and 50 machines, and output is escaped.

Changes after review

  • lifetimeDays: it is dropped from the schema, because the diff cannot compare it. A file that sets it is refused as an unknown key, and a test covers that.
  • Speed: each repo's branch tip is looked up at most once every 5 seconds, and a file is read only when the tip moves. I did not measure the time on the preview.
  • As code block: it is one row per app, with its problems and changes as rows underneath. There are no new classes, and design-lint is clean.
  • forge.json: /infra is not a look. It was removed because app.looks is at its 32-path cap, so the earlier description was wrong.

Not done: writing the file from the UI, reconciling on merge, and a lifetime in the file. The follow-up issues for the first two still need opening and linking under #17075.

Try it: as an admin, commit an infra.json to an app's main branch and open /infra. GET /api/v1/admin/infra/code returns the same text.

[
 {"go":"/infra (admin, an app repo with infra.json on main)","look":"An 'As code' section, one row per app with its summary, then its changes as rows","expect":"No headings or paragraphs inside the section; 'matches what runs' appears only on the app row"},
 {"go":"/infra with a malformed infra.json (an unknown key, or lifetimeDays)","look":"A row 'infra.json is refused: machines[0].… : not a key of a machine'","expect":"The path of the problem is named; nothing is applied"},
 {"go":"/infra as a non-admin","look":"The page","expect":"403, no As code block"}
]

🤖 Generated with Claude Code

commented

The only failure this pull caused was in test/mcp-talk-tools.test.ts. I fixed it and pushed. The other seven failing files (guest-pull, runner-adopt, phone-targets and the rest) are also red on main, and the check didn't count them against this pull.

Cause. The new code action on the infra tool added its name to that tool's action enum. That pushed Talk's tool list to 18503 bytes, 3 over the 18500 ceiling.

Fix. I shortened the infra tool's description in src/http/mcp/tools/infra.ts from "Cloud machines and spend." to "Cloud machines, spend". I did not raise the ceiling.

Checks. test/mcp-talk-tools.test.ts and test/talk-infra-says.test.ts pass, and bun x tsc --noEmit is clean. I did not run the rest of the suite; the forge's full check runs on this push.

What the pull does.

  • infra.json in an app's repo is now read and compared with what runs, and the result shows what applying it would change.
  • It is reachable four ways:
    • the code action of the infra tool;
    • GET /api/v1/admin/infra/code;
    • the infra page;
    • the infra terminal screen.
  • It is read-only.

Left out. The pull adds no write path from infra.json to the cloud. Applying still goes through the existing plan and apply steps.

Try it. Call infra with action: "code", or GET /api/v1/admin/infra/code as an admin.

🤖 Generated with Claude Code

Sign in to join this conversation.

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

Keyboard shortcuts

Docs