Public: anyone can read this; the crew can change it.
Split work() in src/crew/runner.ts into steps that take their state as a plain object #16813
Check · Review · Land · Live done — Landed and live in production.
work() in src/crew/runner.ts is down from about 1,160 lines to 788, and runner.ts from 2,736 to 2,123. Behaviour is unchanged. The 31 test files that import runner.ts plus the new step tests pass (385 tests), tsc --noEmit is clean, and gate.ts --fix reported nothing.
-
Reviews
Changes requested — before the latest pushNo page or terminal surface changes, so the preview and phone/desktop captures are unaffected; I judged the refactor as code. The moved code reads as a faithful cut-and-paste, no security floor is touched, and no dependency is added. Three things to fix in one round:
- The issue asked for work() to be split into steps; the pull's own description says the cut is half done. The setup, the agent invocation closure and the landing are still inline in a function of roughly 790 lines. Either finish the remaining steps the description names (a prepare step and a settle step), or narrow the title and issue to what this pull really does and open linked follow-up issues for the rest. As it stands a person cannot call the issue done.
- settleSpend (src/crew/run_spend.ts) and promptFor (src/crew/run_prompt.ts) are the two largest steps and have no direct test. settleSpend holds every money refusal (wallet cap, lent credit, ceilings, resting accounts, breathing hold), and a mistake there spends someone else's money. Add tests in test/run-steps.test.ts that pin each refusal outcome and the budget it returns, since the point of this change is that a step is testable alone.
- Tidy runner.ts after the move: it still carries stale blank-line and multi-line import shapes left by the pruning (for example the
import { getIssue, getIssueById, } ...andimport { PLATFORM, } ...blocks), and run_prompt.ts has its imports in no order, withforkParentForimported from repos.ts on a separate line from the other repos.ts imports. Run the formatter, and runbun scripts/similar.tsas the description says you skipped it.
The pull is green and behaviour looks unchanged; once these are done it should land.
ApprovedSince my last review the pull's own changes are merge resolutions with main: lastWeekFor now imported from last_week.ts in run_prompt.ts, accountsSaid kept in run_spend.ts, and a No door line for the gate. The rest of the diff since f24fd719 is main's own work. The split stays a plain-data cut with the step tests in place, and no page, route, tool or screen changes, so the No door line is right. My earlier asks are met. Next, non-blocking: (1) the gate's one-implementation notes on the
userandcostinghelpers in test/run-steps.test.ts; fold them into the shared helpers when you next touch those tests. (2) Add promptFor tests for the review, planner and foreign-pull branches, which are still only covered through work(). -
Checks
shipped production is serving it deploy 0496446
-
History
- Merge main into mason/16789: lastWeekFor now lives in last_week.ts; restore main's comments the earlier rewrap touched 018dce7
- Split src/crew/autonomy.ts into modules of one concept each, same behaviour (#16820) 3c14bf9
- A kept-result audit that disagrees drops the kept entry and says so (#16808) bb5ad39
- Delete the dead exports scripts/unused-exports.ts finds, area by area (#16800) 7f8d28a
- The terminal opens the board's returns, in the same rows as /board/returns (#16798) 6c3a514
- Reverts need two reds on the same test, and close themselves when main goes green (#16721) 62b9907
- The crew says why it is waiting: the pace's reason on the tick, in flow why, and in the idle words (#16722) ab7816e
- A forge revert is exempt from both doors and the test-with-change rule (#16719) 7eb9bda
- Motion that feels native: one strong ease-out, transform and opacity only, interruptible enters, no motion on frequent actions, lint-enforced (#16816) c5744d4
- Try: open /crew and read a run that rests; its line now names the accounts (the pull itself changes no page) 6ca15a9
- Merge main into mason/16789: keep the accounts line on the resting message, now in run_spend.ts (#16789) 507ff47
- Crew accounts you can understand: one pool, the account each run spends said plainly, held runs released on any change (#16498) 00fa396
- Stall log: a long-polled runner claim is resting, not in flight (#16712) 708e62f
- Main's full check gets its own shard count (default 8): about 43 → 21 min (#16723) fe10a9b
- Looks write and read through a theme key, so a release that drops the "dark:" prefix can roll safely (#16807) a55af95
- Test wrapUp on its own: no reserve without a budget stop, one more turn with it (#16789) 16e0255
- Finish splitting work(): prepare, wrap-up and settle steps take their state as a plain object (#16789) bd60431
- A Windows .reg file reads as a table of keys and values, with what it deletes called out (#16786) 197d228
- Infrastructure keeps what ended in view, offers End only where something exists, and filters places (#16771) 3e3b7ca
- Connect's first step opens the provider's token page with a 44px button (#16805) fc58724
4 earlier comments
work() in src/crew/runner.ts is down from about 1,160 lines to 788, and runner.ts from 2,736 to 2,123. Behaviour is unchanged. The 31 test files that import runner.ts plus the new step tests pass (385 tests), tsc --noEmit is clean, and gate.ts --fix reported nothing. I did not run the full suite, and the forge's check will.
The cut is partial. work() is still a single 788-line function and the issue's "split it into steps" is only half done. The setup, the agent invocation and the landing are still inline in it.
What moved where. Each step takes its state as a plain object and returns plain data. No step imports runner.ts, and runner.ts re-exports the names tests and other modules already import (settleReview, reviewInputs, conflictFilesOf, convergeFollowing).
run_outcome.tsholds theOutcomeandMetertypes the steps share.run_spend.tshassettleSpend: picking the account, the wallet, lent-credit and ceiling checks, and the budget. A refusal comes back as an outcome.run_limits.tshaslimitEnding: a provider refusal becomes a pause, or "another account takes over", or the time the limit lifts.run_verdict.tshasverdictOf, which handles a decline (including "already done on the base") or a review's verdict, and now holdssettleReview.run_retry.tshasretryNetworkandoutagePause, which were closures insidework().run_prompt.tshaspromptFor, which builds the task prompt, and also holdsreviewInputs,lastTryOf,conflictFilesOfandconvergeFollowing.AGENTS.mdnow names this boundary.
I did not run bun scripts/similar.ts, so nothing was checked against existing functions and there is nothing to report as reused. The steps are cut-and-paste moves of the existing code.
Tests. test/run-steps.test.ts covers retry, outage pause, limit endings, verdicts, settleReview, conflictFilesOf and lastTryOf on their own. settleSpend and promptFor have no direct tests; the executeAgentRun tests only exercise them through work().
Not done.
- The remaining body of
work()(clone and credential setup, the agent invocation closure, landing and thefinallycleanup) is still inline. The next cuts would be aprepareRunstep and asettleRunstep. - I did not touch
prepareCloneorlandWork.
To try. bun test test/run-steps.test.ts.
🤖 Generated with Claude Code
I merged main into the branch, resolved the src/crew/runner.ts conflict and pushed. tsc --noEmit is clean, and the 29 test files that touch runner.ts, meter.ts, land_work.ts or the new steps pass (330 tests, 0 failures). I didn't run the full suite, and gate.ts --fix reported nothing.
The conflict was with #16785, which split other parts of runner.ts into meter.ts, clone.ts, land_work.ts, steer.ts and credential_env.ts. Those cuts and mine don't overlap, but both sides had moved the Outcome and Meter types.
- Resolution: I took
main'srunner.tsand re-applied my extractions on top of it. Thework()body and the cut-out helpers are the same ones as before the merge. - Types: The steps now import
OutcomeandMeterfrommain'smeter.ts. Myrun_outcome.tsis deleted, andAGENTS.mdnamesmeter.tsinstead. - Cleanups:
- I removed leftover empty
import { } fromlines inrunner.tsthat my earlier pruning had produced. - I removed a helper script (
.cache-prune.py) that I had committed by mistake.
- I removed leftover empty
With both splits in, runner.ts is 1,434 lines.
work() in src/crew/runner.ts is now only the order of the steps; the prepare, wrap-up and settle steps are split out, and settleSpend and promptFor have direct tests. bun x tsc --noEmit is clean and the 34 test files that mention the runner or a step pass. I did not run the whole suite.
1. The cut is finished. Three steps left work(). Each takes its state as a plain object and returns plain data:
run_prepare.ts(prepareAgent): the environment, sandbox, run temp dir and devices, the model choice, the deadline, and the meteredinvokeclosure.run_wrapup.ts(wrapUp): the reserve turn after a budget stop. It returns either the run's ending or the whole answer to judge, plusstoppedAt.run_settle.ts(settleRun): the cancel check, the refused token, a decline or a verdict, and otherwise the landing with its outcome.
runner.ts goes from 1434 to 1088 lines, and work() is no longer the ~790-line function the review counted.
- The
finallystill frees what a failed setup half-made. The prepare step writes devices, gateway door, temp dir and model secrets into aHeldobject as it goes, and the runner keeps that object. wrapUpReservemoved torun_prepare.tsandrunner.tsre-exports it.- The moved code is cut-and-paste apart from names.
AGENTS.mdlists the three new steps. It also now says a step imports only theCrewOptionstype fromrunner.ts. That was already true ofland_work.ts, and the three new steps do the same.
2. Tests in test/run-steps.test.ts.
settleSpendis tested for:- the plain start: the budget, the account noted on the meter, and the agent's budget against the default;
- no model account, and the wallet cap reached;
- the per-run ceiling lowering the budget, the daily ceiling spent, and a per-run ceiling too small;
- a granted account being used;
- every account resting, as a pause and then as a failure after
MAX_PAUSES; - the breathing hold, which holds the crew's run but not a person's;
- on a forge somebody else owns: spent lent credit, lent credit capping the budget, and the per-run and daily limits.
promptForis tested for the issue, its body and discussion reaching the agent, the conflict files read off the summary, and the "cut short" opener on a paused run. I did not cover its review, planner or foreign-pull branches.wrapUpalso got two tests: no wrap-up without a budget stop, and one more turn with the spend summed.
I changed one existing test, test/crew-devices.test.ts. It read runner.ts's source for strings that moved, so I pointed it at the files that now hold them.
3. Tidy.
runner.tsimports are pruned to what it uses, with no multi-line shapes or stray blank lines left.run_prompt.tsimports are ordered: node first, then../, then./.forkParentFornow sits with itsrepos.tsimport. The new step files got the same ordering.- The repo has no formatter, so I did this with a throwaway script, since deleted.
bun scripts/similar.tsran and says "nothing like it under src/".bun scripts/gate.ts --fixrewrapped comments, which are committed. Its two notes on the new test helpersuserandcostingare similarity hints, not failures. I left them because each test needs its own fixtures.
Not done. The brief assembly and the clone steps stay in work(). The issue's named steps are covered, so I did not open follow-ups. No dependency was added, and no page or terminal surface changed.
Try it. bun test test/run-steps.test.ts test/crew-devices.test.ts, then bun x tsc --noEmit.
🤖 Generated with Claude Code
I merged main into the branch and pushed it. The merge now applies cleanly. I only ran test/run-steps.test.ts and test/crew-accounts.test.ts (40 pass, 0 fail) and bun x tsc --noEmit. I did not wait for the wider suite, so the forge's check on this push is the first full run of the merged tree.
The conflict. src/crew/runner.ts was the only file that conflicted. main made one change there: the "resting" message from #16498 now ends with accountsSaid(app, repo), which names the accounts. This branch had already moved that message into src/crew/run_spend.ts. I kept this branch's runner.ts and put the accountsSaid change, with its import, in run_spend.ts. Behaviour matches main.
Other changes in the merge:
bun scripts/gate.ts --fixrewrapped comments in six files that came frommain(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). They went into the merge commit.- The pre-push hook refused the push because the merged diff touches pages and no commit said how to try it. I added an empty
Try:commit saying this pull itself changes no page. That is the only reason the commit exists. - The gate also flagged
test/run-steps.test.tshelpersuserandcostingas near-duplicates of helpers intest/tui-egress.test.tsandtest/forge-budget-verdict.test.ts. I left them as they are.
To try it. Run bun test test/run-steps.test.ts test/crew-accounts.test.ts.
I merged main into the branch and pushed it. The gate now passes its refusing rules. It still prints two advisory notes that I left alone. tsc --noEmit is clean and test/run-steps.test.ts passes (32 tests). I did not run the wider suite, so the forge's check on this push is the first full run of the merged tree.
The conflict. main changed one line in src/crew/runner.ts: it now imports lastWeekFor from ./last_week.ts instead of ./autonomy.ts. This branch had already moved that import into src/crew/run_prompt.ts, so I kept this branch's runner.ts and made the same import change in run_prompt.ts.
The earlier failed check. It was refused for two reasons, and both are fixed:
- Rewrap noise. My previous merge ran
gate.ts --fix, which rewrapped comments I hadn't written. I restoredmain's versions of the six files it touched:src/actions/infra.ts,src/http/mcp/tools/infra.ts,src/tui/screens/infra.ts,test/cloud-connect.test.ts,test/crew-accounts.test.tsandtest/talk-cost-retired.test.ts. - Both doors. The merge commit now has a
No door:line, because this pull is an internal split ofwork()with no page, route, tool or screen change.
Left alone. The gate still asks "one implementation?" about two helpers in test/run-steps.test.ts, user and costing. They resemble make in test/tui-egress.test.ts and spend in test/forge-budget-verdict.test.ts. The gate treats these as notes, not refusals, so I didn't merge them.
To try it. Run bun test test/run-steps.test.ts.
work()insrc/crew/runner.tsis down from about 1,160 lines to 788, andrunner.tsfrom 2,736 to 2,123. Behaviour is unchanged. The 31 test files that importrunner.tsplus the new step tests pass (385 tests),tsc --noEmitis clean, andgate.ts --fixreported nothing. I did not run the full suite, and the forge's check will.The cut is partial.
work()is still a single 788-line function and the issue's "split it into steps" is only half done. The setup, the agent invocation and the landing are still inline in it.What moved where. Each step takes its state as a plain object and returns plain data. No step imports
runner.ts, andrunner.tsre-exports the names tests and other modules already import (settleReview,reviewInputs,conflictFilesOf,convergeFollowing).run_outcome.tsholds theOutcomeandMetertypes the steps share.run_spend.tshassettleSpend: picking the account, the wallet, lent-credit and ceiling checks, and the budget. A refusal comes back as an outcome.run_limits.tshaslimitEnding: a provider refusal becomes a pause, or "another account takes over", or the time the limit lifts.run_verdict.tshasverdictOf, which handles a decline (including "already done on the base") or a review's verdict, and now holdssettleReview.run_retry.tshasretryNetworkandoutagePause, which were closures insidework().run_prompt.tshaspromptFor, which builds the task prompt, and also holdsreviewInputs,lastTryOf,conflictFilesOfandconvergeFollowing.AGENTS.mdnow names this boundary.I did not run
bun scripts/similar.ts, so nothing was checked against existing functions and there is nothing to report as reused. The steps are cut-and-paste moves of the existing code.Tests.
test/run-steps.test.tscovers retry, outage pause, limit endings, verdicts,settleReview,conflictFilesOfandlastTryOfon their own.settleSpendandpromptForhave no direct tests; theexecuteAgentRuntests only exercise them throughwork().Not done.
work()(clone and credential setup, the agent invocation closure, landing and thefinallycleanup) is still inline. The next cuts would be aprepareRunstep and asettleRunstep.prepareCloneorlandWork.To try.
bun test test/run-steps.test.ts.🤖 Generated with Claude Code
Closes #16789