Skip to content

afx/porch: four small CLI additions (afx send --message-file/--exit-code/--retry, afx cleanup --keep-ignored, afx spawn --max-load, porch -C) #1950

Done

Description

@waleedkadous

Summary

Four small additions to afx and porch, suggested by an adopter workspace's architect at its owner's request. Each replaces a sequence that architects there typed by hand hundreds of times in one week of shell history (16,117 commands), often with silent failures. One PR.

1. afx send: a message file, opt-in exit codes, and a safe retry

Today a held message exits 0, the same as a delivered one, so a script cannot tell them apart. A message with quotes or newlines has to survive shell quoting unless the caller knows about - (stdin).

  • --message-file <path>: the message body is read from the file. It never passes through a shell. This is distinct from --file, which appends a file to a message given on the command line; the two may be combined. The 48 KB limit applies to the result as it does today.

  • --exit-code: opt in to outcome exit codes, in the manner of git diff --exit-code:

    Outcome Exit
    delivered, or scheduled by --delay 0
    failed or refused 1
    held 3

    Without the flag, exit codes stay exactly as they are today. Reason: agents chain afx send … && … and read a non-zero exit as an error. A held message is persisted and will deliver; an agent that sees it "fail" will send it again, and the recipient gets it twice. Check in the source whether a send can come back delivered-but-unverified; if it can, give it its own code (4) under --exit-code and document it. With --all, the exit is the worst outcome across recipients.

  • --retry <n>: resend only when the request provably never reached Tower (connection refused, Tower not running). Never after held, a refusal, or a timeout on a request that was sent: the mailbox may already hold it, and a resend would duplicate it. Back off between tries and say on stderr what happened.

2. afx cleanup --keep-ignored

Cleanup removes the worktree with force, and every untracked and ignored file in it goes too: review outputs, project status folders, scratch notes. Some of that is evidence someone wants later.

  • Before removing anything, copy to ~/.agent-farm/kept/<workspace-name>/<builder-id>/:
    • every untracked file that is not ignored;
    • ignored files matching a keep list. Default: codev/projects/**, codev/state/**, .builder-*, tmp/**, scratch/**. Configurable under cleanup.keepIgnored in .codev/config.json.
  • Never copy dependency or build output (node_modules, dist, virtualenvs, and the like), whatever the keep list says.
  • Compare a checksum per file after copying.
  • Refuse to overwrite: if the kept folder for that builder already exists, stop with an error naming it.
  • If any copy or checksum fails, abort before removing the worktree, the branch or the registry row.
  • Print the kept folder and the number of files.

3. afx spawn --max-load <n>

  • Read the one-minute load average before creating anything. At or above n, exit 75 with a message giving the load and the limit. No branch, no worktree, no registry row.
  • --wait <seconds> with it: re-read every 15 seconds up to that long, then spawn or exit 75.
  • On a platform with no load average (native Windows reports zeros), --max-load fails loudly as unsupported. No guessing.

4. porch -C <dir>

Like git -C: run the command as if porch had been started in <dir>. It works with every subcommand and prints the directory it resolved.

Today an architect must cd into a builder worktree to run porch status, and a cd that persists in the shell later nests builders when afx spawn runs from the wrong place. -C removes the cd.

porch approve and porch skip-phase still require their explicit human-approval flag. -C grants nothing.

Notes for the builder

  • Update the docs and skills that teach these commands in both trees: the afx and porch skills, agent-farm.md and overview.md under resources/commands/, and their codev-skeleton/ twins. If CLAUDE.md changes, AGENTS.md changes identically.
  • Tests: each exit code under --exit-code, and unchanged exits without it; --retry does not resend after held or a timeout; --keep-ignored aborts before removal on a checksum mismatch and on an existing kept folder; --max-load creates nothing when over; porch -C resolves the same project as running from inside the directory.
  • Run targeted tests while iterating and the full suite once, for the porch check. If the one-minute load average is above 18 on this machine, wait for it to drop first.

Activity

  1. added
    area/cross-cutting
    on Nov 23, 2026
  2. added 4 commits that reference this issue on Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/cross-cutting

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions