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

Split src/crew/autonomy.ts into modules of one concept each, same behaviour #16820

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

src/crew/autonomy.ts (2,530 lines) is gone, split into 23 modules of one concept each. The code was moved, not rewritten. Callers in src, test and the docs point at the new modules, and none of the old export { parkPull }, { pickBuilder } or { getPull } re-exports remain.

Notes

opened this

src/crew/autonomy.ts (2,530 lines) is gone, split into 23 modules of one concept each. The code was moved, not rewritten. Callers in src, test and the docs point at the new modules, and none of the old export { parkPull }, { pickBuilder } or { getPull } re-exports remain. bun x tsc --noEmit is clean and gate.ts exits 0. 108 test files touching the crew modules pass, as do the module-state, hollow, doorless and trusted-source checks. I did not run the full suite; the forge's check does that on push.

The new modules (all in src/crew/):

  • Spend and status: autonomy_spend, autonomy_status, autonomy_pace, autonomy_tick.
  • One turn of the loop: drive, unstick, next_pick, last_week.
  • Planner: planner_hold, plan_owed, planner_decline, direction_issue.
  • Parking and settling: park_issue, settle_run.
  • Conflicts: conflict_sweep, conflict_release, conflicted_tips.
  • Landing: green_sweep, review_gate, land_queue, land_admit, regate, land_gated.

Changes outside the split:

  • Import order: the new module graph made the maintenance roster's require() of flow_keeper fail. registry.ts loads before snapshot/verify.ts, and verify.ts ended up in the graph with a top-level await in its import.meta.main block.
    • verify.ts's CLI is now an async function cli() called with void. The CLI behaves the same.
    • CAP_NOTE moved from guard.ts to a new leaf module, cap_note.ts, because the new order hit a "cannot access before initialization" error between breaker.ts and guard.ts.
  • Trusted-source wall: fold_walls.ts held crew/autonomy* against trusted sources by name prefix. It now lists each module autonomy.ts became, so none of the code drops out of the wall. trusted-sources.test.ts covers four of them.
  • Module-state baseline: the asked, checked, cleanAt, conflictedAt and sweeping entries now point at their new files. conflicted is dropped because it is written from other modules now, so the scan no longer sees it. It is still process-wide state.
  • Stale references:
    • landing-doors-review.test.ts lists both mergePull calls, now in land_admit.ts and land_gated.ts.
    • Comments and docs that named autonomy.ts point at the right module.
    • docs/features/batch-doctor.md said handBack was in autonomy.ts; it is in actions/give_back.ts, and the doc now says so.

Reuse: nothing new was written. bun scripts/similar.ts was not run, since there are no new functions. The gate lists pairs such as closeSuperseded / releaseConflicted / parkPull as similar; they were already in the old file or elsewhere, and I left them (moving them to one implementation is a behaviour change).

What I did not do:

  • I did not touch the cycle-prone import graph beyond the two fixes above.
  • I did not run keep_plan or estimate: neither tool was available.
  • There is no page, route or tool change, so no terminal screen or how-to was added (No door: is in the commit). The src/web/ edits are import paths only, and I did not run a look (No look: is in the commit).

To try: bun test test/autonomy.test.ts test/conflict_sweep.test.ts test/merge-queue.test.ts test/landing-doors-review.test.ts test/module-state.test.ts, then check that the crew's tick log line on the preview reads as before.

🤖 Generated with Claude Code

Closes #16788

2 earlier comments
commented

src/crew/autonomy.ts (2,530 lines) is gone, split into 23 modules of one concept each. The code was moved, not rewritten. Callers in src, test and the docs point at the new modules, and none of the old export { parkPull }, { pickBuilder } or { getPull } re-exports remain. bun x tsc --noEmit is clean and gate.ts exits 0. 108 test files touching the crew modules pass, as do the module-state, hollow, doorless and trusted-source checks. I did not run the full suite; the forge's check does that on push.

The new modules (all in src/crew/):

  • Spend and status: autonomy_spend, autonomy_status, autonomy_pace, autonomy_tick.
  • One turn of the loop: drive, unstick, next_pick, last_week.
  • Planner: planner_hold, plan_owed, planner_decline, direction_issue.
  • Parking and settling: park_issue, settle_run.
  • Conflicts: conflict_sweep, conflict_release, conflicted_tips.
  • Landing: green_sweep, review_gate, land_queue, land_admit, regate, land_gated.

Changes outside the split:

  • Import order: the new module graph made the maintenance roster's require() of flow_keeper fail. registry.ts loads before snapshot/verify.ts, and verify.ts ended up in the graph with a top-level await in its import.meta.main block.
    • verify.ts's CLI is now an async function cli() called with void. The CLI behaves the same.
    • CAP_NOTE moved from guard.ts to a new leaf module, cap_note.ts, because the new order hit a "cannot access before initialization" error between breaker.ts and guard.ts.
  • Trusted-source wall: fold_walls.ts held crew/autonomy* against trusted sources by name prefix. It now lists each module autonomy.ts became, so none of the code drops out of the wall. trusted-sources.test.ts covers four of them.
  • Module-state baseline: the asked, checked, cleanAt, conflictedAt and sweeping entries now point at their new files. conflicted is dropped because it is written from other modules now, so the scan no longer sees it. It is still process-wide state.
  • Stale references:
    • landing-doors-review.test.ts lists both mergePull calls, now in land_admit.ts and land_gated.ts.
    • Comments and docs that named autonomy.ts point at the right module.
    • docs/features/batch-doctor.md said handBack was in autonomy.ts; it is in actions/give_back.ts, and the doc now says so.

Reuse: nothing new was written. bun scripts/similar.ts was not run, since there are no new functions. The gate lists pairs such as closeSuperseded / releaseConflicted / parkPull as similar; they were already in the old file or elsewhere, and I left them (moving them to one implementation is a behaviour change).

What I did not do:

  • I did not touch the cycle-prone import graph beyond the two fixes above.
  • I did not run keep_plan or estimate: neither tool was available.
  • There is no page, route or tool change, so no terminal screen or how-to was added (No door: is in the commit). The src/web/ edits are import paths only, and I did not run a look (No look: is in the commit).

To try: bun test test/autonomy.test.ts test/conflict_sweep.test.ts test/merge-queue.test.ts test/landing-doors-review.test.ts test/module-state.test.ts, then check that the crew's tick log line on the preview reads as before.

🤖 Generated with Claude Code

commented

I merged main into the branch and pushed it. The only conflict was src/crew/autonomy.ts, which this pull deletes and main had edited in #16722.

I kept the deletion and moved #16722's changes into the new modules:

  • paceHold: it now lives in src/crew/autonomy_pace.ts, next to repoPace.
  • Tick log: src/crew/autonomy_tick.ts logs the pace reason on a waiting tick, as #16722 did.
  • Imports: src/flow/why.ts and test/pace-reason.test.ts now import from the new module files. There are still no re-exports.

bun x tsc --noEmit is clean. test/pace-reason.test.ts and test/module-state.test.ts pass (8 tests); I did not run anything wider, since the forge runs the full check on push. bun scripts/gate.ts --fix changed nothing. It printed "one implementation?" similarity notes, which I left alone and did not check against main.

test/first-change.test.ts.bak is tracked and still imports src/crew/autonomy.ts. It was already there and is not run as a test, so I left it.

commented

The gate failure is fixed and pushed.

The cause was my own: when I ran bun scripts/gate.ts --fix during the earlier merge, it rewrapped comments in six files this pull didn't write, and I committed them with the merge. I restored those six files to what main has:

  • src/actions/infra.ts
  • src/http/mcp/tools/infra.ts
  • src/tui/screens/infra.ts
  • test/cloud-connect.test.ts
  • test/crew-accounts.test.ts
  • test/talk-cost-retired.test.ts

I also merged main again first, and that merge was clean. bun scripts/gate.ts now reports no "the diff is the change" violations. bun x tsc --noEmit is clean. I ran test/pace-reason.test.ts and test/talk-cost-retired.test.ts, which pass (6 tests). I did not run test/cloud-connect.test.ts or test/crew-accounts.test.ts, which cover two of the restored files. The forge runs the full check on this push.

The gate's "one implementation?" similarity notes are still printed. They are advisory and I left them alone.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs