Repository navigation
[Air #1950] feat: afx send --message-file/--exit-code/--retry, cleanup --keep-ignored, spawn --max-load, porch -C - #1954
Merged
Merged
Conversation
…p --keep-ignored, spawn --max-load, porch -C - afx send: --message-file reads the body from a file; opt-in --exit-code (0 delivered/scheduled, 1 failed/refused, 3 held, 4 delivered but unverified; worst across --all); --retry resends only on a refused connection. - sdk: recognise ECONNREFUSED on err.cause (Node fetch reports 'fetch failed'), and carry a typed connectionRefused flag through request()/sendMessage(). - afx cleanup --keep-ignored: copy untracked + keep-listed ignored files to ~/.agent-farm/kept/<workspace>/<builder-id>/ with SHA-256 verification, refusing an existing folder and aborting before any removal on failure. - afx spawn --max-load/--wait: exit 75 before anything is created. - porch -C <dir>: run as if started in <dir>, like git -C. - Docs: afx/porch skills and command references in both trees. Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts: # packages/codev/src/lib/shipped-skill-hashes.ts
…eep-ignored reporting, zero-recipient exit - --message-file drops only the single line ending that terminates the file (was trimEnd()). - --keep-ignored counts matches left out as dependency/build output; the abort message says the session was already stopped; nested directories walked by hand (Node 20.0 has no recursive readdir). - afx send --all --exit-code exits 1 when there are no builders to reach. - End-to-end cleanup() test with the real keep module, a real git worktree and a configured keep list. - Docs and skills updated; shipped-skill hashes regenerated after merging main.
On a real Windows runner the gate correctly refuses (no load average), so the load-path cases must force a POSIX platform through the host-platform seam.
waleedkadous
marked this pull request as ready for review
November 23, 2026 21:50
waleedkadous
added a commit
that referenced
this pull request
Nov 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds four small CLI features that replace sequences architects were typing by hand.
afx sendgains--message-file, opt-in--exit-codeand a safe--retry.afx cleanupgains--keep-ignored,afx spawngains--max-load/--wait, andporchgains-C <dir>. It also fixes a small adjacent SDK bug: a refused connection to Tower was never recognised.Closes #1950
What Changed
1.
afx send--message-file <path>: the message body is read from a file and never goes through a shell. Only the single line ending that terminates the file is dropped. It is separate from--file, which appends a file; the two can be combined, and the 48 KB limit applies to the result.--exit-code(opt-in): 0 delivered or scheduled, 1 failed or refused, 3 held, 4 delivered but unverified. Without the flag, exit codes are unchanged (a held message still exits 0).verified: false, anunverifiedCause(no-echoorinput-raced), ordegraded(the write was not serialized). All three already printed warnings; under--exit-codethey exit 4.--all, the exit is the worst outcome across recipients, in this order: failed, unverified, held, then scheduled or delivered. It exits 1 when there are no builders to reach.--retry <n>: up to N retries in total, only when the request provably never reached Tower (connection refused)./healthpre-check sends nothing, so any failure of it may be retried.2.
afx cleanup --keep-ignoredBefore the worktree is removed, it copies to
~/.agent-farm/kept/<workspace-name>/<builder-id>/:codev/projects/**,codev/state/**,.builder-*,tmp/**,scratch/**;cleanup.keepIgnoredin.codev/config.jsonreplaces it.Rules:
ls-files --others, plus--ignoredwith:(glob)pathspecs), so git never walksnode_modules.node_modules,dist,build,target, virtualenvs and the like) is never copied, whatever the list says. Neither are symlinks.3.
afx spawn --max-load <n> [--wait <seconds>]--waitre-reads every 15 seconds up to that long, with a last read at the deadline.4.
porch -C <dir>git -C: it goes before the command, can be repeated (each-Cresolves against the last), applies to every subcommand, and prints the resolved directory on stderr.approveandskip-phasestill require--a-human-explicitly-approved-this.Docs
afxandporchskills, in all four copies of each (.claude,.codex, and theircodev-skeleton/twins).resources/commands/agent-farm.mdandoverview.mdin bothcodev/andcodev-skeleton/.CLAUDE.mdandAGENTS.mdare unchanged.Adjacent bug fixed in place
The SDK never recognised a refused connection.
TowerClient.request()(and two sibling call sites) looked forECONNREFUSEDinerr.message. Node's fetch throwsTypeError('fetch failed')and putsECONNREFUSEDonerr.cause, so callers gotfetch failedinstead ofTower not running. The check now readserr.causeas well, andrequest()andsendMessage()carry a typedconnectionRefusedflag, which--retryrelies on. Verified against a real refused port:{"ok":false,"error":"Tower not running","connectionRefused":true}.Key Decisions
verified: false,unverifiedCause,degraded). Each means the message is recorded as delivered and will never be re-sent, but may not have arrived clean.--all: failed > unverified > held > scheduled/delivered. An unverified message needs a human to check it, while a held one will deliver on its own.--retrybudget for the whole invocation (--allincluded), so a dead Tower costs at most N back-offs in total.connectionRefusedflag, not by string-matching the error..env.--keep-ignoredonly acts where cleanup removes a worktree (bugfix and task builders). For other builders it says there is nothing to keep.--max-loadrefusals that retrying cannot fix exit 1, not 75. That covers Windows and bad arguments, so a script that retries on 75 cannot loop forever.porch -Cusesprocess.chdir, so every cwd-keyed behaviour matches running porch from that directory.Test Plan
Unit tests added:
air-1950-send-exit-retry.test.ts(34)--exit-codethrough the real CLI; unchanged exits without it, including--allwith a failure; worst-of under--all, and zero recipients;--retryresends after a refused connection, but never after held, a refusal or a timeout; waits out a down Tower;--message-fileas written (quotes,$HOME, backticks, inner and trailing whitespace; only the final line ending, CRLF included, dropped), combined with--file, both-ways refusal, 48 KB on the combined resultair-1950-keep-files.test.ts(9)air-1950-cleanup-keep-ignored-e2e.test.ts(2)cleanup()with the real keep module, a real git worktree and a realcleanup.keepIgnoredin.codev/config.json: the right files land before removal is attempted (and.env,node_modulesand keep-listed dependency output do not); a second cleanup refuses on the existing folder and touches nothingair-1950-cleanup-keep-ignored.test.ts(5)air-1950-spawn-max-load.test.ts(11)spawn();--waitcadence and deadline; Windows unsupported; argument validationair-1950-porch-dash-c.test.ts(7)porch -C <wt> status --jsongives output identical to running inside the worktree; repeated-C; approve and skip-phase still refused without the flag; bad or missing directorytower-client.test.ts(+3)fetch failedwithECONNREFUSEDoncausecounts as refused, as does a non-Errorthrow; a timeout does notBuild passes, both locally (porch build check) and on CI.
All tests pass on CI: GitHub 8/8 checks at
666c0965c, and again at the final head2ebbefbbd. Locally the full suite does not pass on this machine; see Flaky Tests. The porch local tests check was skipped under the owner's standing ruling main-32: GitHub's green run stands in for the local suite when the local failures are unrelated, each passes alone, and CI on the same code is green.Checked by hand with the built binaries, from a scratch directory:
porch -C <worktree> statusprinted[porch -C: running in …]and resolved project 1950.porch -C <missing> statusexited 1 naming the path.afx spawn 99999 --protocol air --max-load 0.01exited 75 ("load average is 20.55 … Nothing was created"); with--wait 1it re-checked once, then exited 75. The scratch directory stayed empty.sendMessageto a port with nothing listening returnedconnectionRefused: true.Native Windows (on-demand workflow, suites on):
e9049abfd: https://github.com/cluesmith/codev/actions/runs/45270353269. Red on one file, this PR's ownair-1950-spawn-max-load.test.ts: on a real Windows host the gate correctly refused as unsupported, and the test had not pinned a POSIX host for its load-path cases. Fixed in2ebbefbbd. 416 other files passed, including the real-git--keep-ignoredandporch -Ctests.2ebbefbbd: green, every job (unit and CLI on Node 22 and 24, install verification, probes on windows-latest and windows-11-arm): https://github.com/cluesmith/codev/actions/runs/45272569045Not run against the real thing:
afx cleanup --keep-ignoredon a real builder (it needs a disposable bugfix builder; the end-to-end test runs the realcleanup()and keep code on a real git worktree) andafx send --retryagainst a stopped Tower (stopping Tower needs the owner's permission).Review Notes
CMAP, round 1: codex REQUEST_CHANGES, claude APPROVE. All addressed in
e9049abfd:main(merged; only the generated skill-hash file conflicted, regenerated after the merge);--message-fileusedtrimEnd()(now drops only the file's final line ending, which would otherwise submit under--raw --no-enter); the Windows workflow was not linked (dispatched above).cleanup()test; the abort message now says the session was already stopped; dependency and build output left out is counted;--allwith no builders exits 1 under--exit-code; the nested-directory walk no longer needs Node 20.1; the non-Errorrefusal branch is tested.Attribution: the first feature commit (
b6dbb1377) carries aCo-Authored-Bytrailer, against this repo's commit rules. It is already pushed, and removing it means rewriting history, so it was left for the owner to decide. Later commits and this body carry no attribution.Where to look:
send.ts(outcome classification and the retry loop),lib/keep-files.ts(the copy and verify, and abort-before-removal incleanup.ts), and the SDK'sisConnectionRefused.Lessons:
cause. Prefer a typed flag set where the error is classified.ls-fileswith:(glob)pathspecs) avoids re-implementing gitignore semantics and keeps git out of dependency trees.Noticed, not changed:
porch status --jsonwith an auto-detected project prints[auto-detected …]on stdout before the JSON. This was true before this PR and is left out of scope.Flaky Tests
The local porch
testscheck (npm test -- --exclude='**/e2e/**') failed three times on tests this PR does not touch. Every failure was a test hitting its time limit.Run 1 (load about 20–30): 15 of 8,438 tests failed, each hitting the ~5s test timeout, in 9 files:
src/commands/consult/__tests__/claude-cli-lane.test.ts(4)src/commands/consult/__tests__/bugfix-1754-dotenv-auth.test.ts(2)src/commands/consult/__tests__/tripwire-wiring.test.ts(2)src/commands/consult/__tests__/agy-auth-cache.test.ts(1)src/agent-farm/__tests__/bugfix-1267-launch-loop.test.ts(2)src/agent-farm/__tests__/pir-1233-session-launch-loop.test.ts(1)src/agent-farm/__tests__/ide-command.test.ts(1)src/__tests__/doctor.test.ts(1)src/__tests__/bugfix-1455-pr-create-concept.test.ts(1)Run on their own, all 9 files pass (221/221).
Run 2 (the one retry the architect allowed): porch's summary does not name the failing tests, and the load reached 44 during it.
Run 3 (asked for by the architect once the machine was quiet): the load was 7.7 at the start and 59 at the end, so the suite itself saturates this machine. vitest's results cache names 5 failed files, all from the list above, each taking 15–48s instead of a few seconds:
bugfix-1267-launch-loop,ide-command,pir-1233-session-launch-loop,agy-auth-cache,tripwire-wiring. All fiveair-1950-*test files passed.CI on a clean runner (
666c0965c): all green. The codev unit suite ran the same 422 files with no failures (409 passed, 13 skipped), including all 9 files above. The CLI integration, Tower integration, browser and package install checks also passed.None of these tests were skipped or reconfigured. After the owner's ruling, the porch local tests check was skipped for one
porch donerun only, through this worktree's gitignored.codev/config.local.json, and the skip was removed straight after; nothing under.codevis committed.