@astrohacker/factory
ahfact is the command an Astrohacker Factory worker and
its subagents use. A worker runs once per project, harness and computer, waits
for the factory to lease it a job, and starts one subagent per lease. The
subagents report progress, so the factory shows who is doing what.
npm install -g @astrohacker/factory # or: bun add -g @astrohacker/factory (either way, Node 22+ runs it)
ahfact worker register --harness claude # the worker registers itself, e.g. rxc-ahfact-claude-worker; a person confirms in the browser
ahfact wait # lease the next job
ahfact worktree start LEASE # the job's worktree, recorded on the lease
ahfact log LEASE "Opened PR #5" # report progress; renews the lease
ahfact done LEASE "Merged"
Each role has a generic protocol, the same for every project, that ships
with the CLI: ahfact role list lists the roles (chat, worker,
code, review, deploy, release, and the legacy issues) with a
one-line summary, and
ahfact role show ROLE prints one: the commands it runs, its lease and
event lifecycle, and what it must never do. Each repository's own role files
add what's specific to it. The files are in the package's roles/ folder.
A worker gives each subagent ahfact job prompt LEASE as its whole prompt:
the role's protocol, the repository's file for the role (from
.ahfact.json's roles) and the job's details; --json returns the parts.
It reads the role file only as a regular file inside the repository: a
symlink, or a path that resolves outside it, is refused and nothing from it
is printed.
End a lease with done (finished), drop LEASE REASON (nothing left to do:
its PR merged or closed, its issue closed; the job is cancelled) or release
(hand it back; this worker won't lease it again for 10 minutes unless it
changes).
File issues with ahfact issue create --title T --body-file F (the body
follows ahfact issue template: What, Why, Done when), which ends with a line
naming the agent. Discuss them on their threads in the factory, never on
GitHub: ahfact issue comment N and ahfact pr comment M post a note on
issue-N's or pr-M's thread, ahfact thread show SUBJECT reads one, and
ahfact thread post SUBJECT --kind K posts any other kind. A worker posts as
itself, or with --lease as that lease's subagent. A subagent asks a
question with ahfact issue ask LEASE --body "…" (a question post), or
needs a person with ahfact issue block LEASE (a decision-needed post,
which flags the job needs-human in the factory), and its lease waits until
someone else posts on the thread (for a block, a person, whose answer clears
the flag). A block with --needs release [--version X.Y.Z] waits on a CLI
release no one filed: the board's Needs you offers Cut release, and filing a
release that covers it (releases.create, from the board or ahfact release create) answers the block.
A post on a job's issue or PR thread from anyone but its own subagents wakes the holder with a
discussion event. The holder answers it by posting on that thread with
--lease, or with ahfact discussion answer LEASE --note "…";
ahfact discussion LEASE lists what's unanswered. Until it is answered, a
review's pass and merge are refused and the reviewer waits for unblocked.
ahfact check in a job's worktree (or with --lease LEASE) checks the clean
HEAD and records the result on the lease: the commit, whether it passed, and a
summary, shown on the job's page. For a review it also checks HEAD merged with
the default branch's current head, in place on a throwaway merge commit, and
records that. ahfact pr ready checks the PR's exact head and records it, and
the factory refuses a ready without a passing check of that commit; it refuses
a pass without passing checks of the commit alone and merged with the default
branch's head the CLI names. Merges go one at a time per project (#260):
ahfact review merge (and a pass, which merges) takes the project's merge slot
in the factory (lease.mergeSlot), waiting while another review holds it,
reads the default branch's head holding it, checks the commit merged with that
head when the pass's check wasn't, and merges; a head that moves on the way
starts the merge over, and a merged check that fails is recorded as
conflict. The factory refuses the merge (lease.mergeCheck) unless the lease
holds the slot and recorded a passing check of the commit merged with its
head, whatever the CLI.
Under roles.review.checklists in .ahfact.json, each entry names a
repository-relative Markdown skill and the paths that require its review.
For example, {"skill":"docs/api.md","paths":["api/**","cli/client.ts"]}
covers the API directory and one client file. Patterns are relative to the
root. Use * and ? within a path segment, or ** across directories.
ahfact check validates the globs and each skill’s level-two headings.
A skill may also say what requiring it means for a PR with a flag: line
in its YAML frontmatter, such as flag: changes the check gate (at most
200 characters): the template carries it, and the PR thread shows it on
the verdict. The flag always comes from the skill, never the reviewer’s
file.
Enable this role field only after workers run a CLI with checklist support;
CLIs through 0.35.0 reject unfamiliar role fields.
ahfact review checklist LEASE prints JSON using the default branch's
rules and paths changed since the merge base. Each selected skill lists its
## sections at the reviewed commit. Fill each result with ok, n/a,
or finding and give a note for the latter two. Save that JSON outside
the worktree and pass --checklist FILE to the verdict command. An empty
template needs no file. The PR thread on the job page shows each section,
result, and note. A finding prevents a pass.
A reviewer gives ahfact review verdict LEASE pass|changes|conflict. The CLI
first checks that the PR still merges with its base (gh pr view --json mergeable, plus migration numbers and CLI versions the base took since the PR
branched); if it doesn't, a pass is recorded as conflict, which wakes the
coder to merge the base and doesn't count toward the three reviews that
escalate. The verdict and its findings are posted on the PR's thread. The
third changes escalates, flagging both jobs needs-human. While a PR is
escalated, pr ready and verdicts are refused; a
person continues it with ahfact review continue PR [--note TEXT],
confirmed in the browser, which allows three more reviews, wakes the coder
and reviewer with unblocked, posts the note on the PR's thread, clears
needs-human and removes the labels an older CLI added.
While waiting, a subagent takes its own events with ahfact wait --lease LEASE
and acknowledges them with ahfact ack EVENT --lease LEASE. The factory sends the
worker one message for each event pending ten minutes. When ahfact wait returns an event for a lease the worker holds, the worker
passes it to that lease's subagent and then runs ahfact ack EVENT. Until then
the event stays pending: it comes back after 5 minutes, and ahfact leases
lists its status. A restarting worker recovers the subagents from that list
and forwards only events its own wait claims.
Each job works in its own worktree beside the primary checkout,
../<repo>-worktrees/issue-N (on branch issue-N) or review-pr-M (detached
at the commit under review). worktree start LEASE creates or reuses it and
runs the repository's setup hook; worktree list shows them with their jobs.
retire LEASE removes the job's worktree and branches once its PR has merged
or closed, and retire alone does that for every finished job, deleting the
remote issue-N branches of merged PRs too.
Person commands act as you through your sign-in: login, logout,
inbox, project pause and resume, deploy hold and resume,
release create, hold and resume, worker rename and revoke, agents, lease takeback, lease handoff,
review continue, and job create with no worker. An agent running as your OS user can read
your token, so the CLI token alone is not trusted for the destructive ones.
The destructive ones, lease takeback, lease handoff,
worker rename, worker revoke WORKER, project pause, project resume,
deploy hold, deploy resume, release hold, release resume with no version and
review continue, also need you to confirm them in your
browser. The CLI prints what it will do, a link to
/confirm and a short code, like login, and waits; it acts only after you
confirm there while signed in to the factory, and stops if you deny it or
ten minutes pass. The factory refuses these calls from a CLI token without
a confirmation for exactly that action, so your token alone can't do them.
They need a factory that has confirmations (CLI 0.16.0 and later).
worker revoke stops the worker's token working but leaves its live leases
held until they expire; take their jobs back separately.
Every agent has an identity on the factory: ahfact agents [NAME] lists the
workers, foremen, legacy issues sessions and live subagents with their role, computer,
harness, job and presence (NAME finds one by a name it has or had).
A worker or a chat agent registers itself, so a person never runs a
command in a terminal for it: ahfact worker register --harness H [--machine M] [--name NAME] and ahfact agent register --role chat --harness H need
no sign-in on the computer. Each prints what it asks for, a link to
/confirm and a short code, opens the link in the default browser where it
can (--no-open only prints it), and waits. Any person signed in to the
factory checks the code and confirms it there, or with Confirm in the
board's Needs you; the CLI then saves the session's own token under
~/.config/ahfact/workers/ or ~/.config/ahfact/agents/. Denial or ten
minutes passing changes nothing, an approval works once, and no token can
approve one. Registering again replaces the session's token. The machine
defaults to the one this computer's sign-in used, else the hostname.
worker start and agent start are older names for them.
The issues session is legacy (#395): chat agents replace it (#406).
agent register --role issues refuses a new one, pointing to chat agents;
one registered before may register again in its own place (project,
computer and harness) until the person retires it. A post
with --agent naming an issues session uses its token and is attributed
to the session alone; its person commands still act through the person's
sign-in.
Every worker launches and keeps alive its own chat agent (#406), on its
computer and harness: <computer>-<project>-<harness>-chat, beside
<computer>-<project>-<harness>-worker. The person who approves its
registration is its person, and a person with several workers has several
chat agents and talks to whichever they like. Its wait (ahfact wait --agent NAME) brings only the messages addressed to it, never its
person's inbox or their mail: Needs you is the person's alert. With
--agent naming a chat agent saved on the computer, the person commands
but login, logout, inbox and messages go with its own token, and
the factory runs them as its person, only in its project; the destructive
ones still wait for that person's browser confirmation, whose summary
names the chat agent. It files and refines issues, explains status and
looks into stuck work when asked (ahfact status, ahfact agents),
nudging a stuck bot, but never does a worker's or a subagent's job;
ahfact role show chat is its protocol. Its registration replaces its
person's foreman (#392, from CLIs through 0.37.0) on the same computer and
harness, which works until then.
ahfact chat status tells the worker whether its chat agent is live
(missing: none, or unseen for 10 minutes) and whether to launch it now;
ahfact chat prompt prints the prompt the worker starts its session with;
and ahfact chat asked records that the worker could only ask its person
to start it by hand. ahfact wait checks every 10 minutes and returns
{chat: STATUS} when a launch is due, then not again for 15 minutes (6
hours after chat asked); --no-chat turns that off. The worker protocol
(ahfact role show worker) says how each harness starts the session.
A repository registers itself the same way (#282): its agent runs ahfact project register [--slug S] [--name N] [--repo OWNER/NAME] in a checkout
(project add is its older name), and a person's approval creates the
project; no token alone can. worker register in a checkout whose
repository isn't a project yet asks to add it in the same approval
(--slug picks its slug), so a new repository's first worker needs one
approval for both. Several workers of a new repository can ask at once:
the first approval adds the project, and approving any other starts just
its worker there. If its request is refused or expires because the project
was added meanwhile, worker register asks once more for just the worker,
with a new link and code. The SDK's register.project and register.pollProject
do the same.
A worker is named like the session it runs in,
<computer>-<project>-<harness>-worker (worker register --name NAME picks
another for a new worker). ahfact worker rename [WORKER] NEW_NAME renames
this checkout's worker, or WORKER, in place: same token, leases and history,
no restart. The token saved on this computer moves to the new name, and the
old name keeps finding the worker (--worker, handoffs, exclusions). On
other computers, the first command that names the worker by its new name
finds the token still saved under the old one (it asks the
factory who each saved token belongs to now) and moves it, so they need no
restart or manual file moves either (CLI 0.26.0 and later). New subagents
take the new name; live ones keep theirs. A name can't be another worker's
name followed by -…, or the start of one (as rxc-ahfact is of
rxc-ahfact-claude-worker), in any project, so no worker passes for
another's subagents.
Cancelling a job is
the board's Cancel button only: no CLI token can.
A person takes a job back with ahfact lease takeback LEASE, or moves a
live lease to another worker of the project with
ahfact lease handoff LEASE WORKER (by worker name, or the subagent name it
would run). Handoff keeps the job's rounds and PR and moves its pending
events and open questions; the new worker's wait returns a handover
event (start a subagent for the lease, which runs worktree start for its
own worktree) and the old worker's a handedoff event (stop yours, then
retire OLD_LEASE to remove its worktree and local branch, keeping
uncommitted or unpushed work; on the same computer the new holder's
worktree start waits for that). Both are person commands.
A person pauses a project's work with ahfact project pause [--reason …]:
its workers lease no new jobs and the sync files none, while leases already
held carry on, until ahfact project resume. Workers can't pause or resume.
Deploy jobs: when a project's default branch moves past the commit last
deployed, the sync files one deploy job for its head. Deploys start held:
a person turns them on with ahfact deploy resume --machine M, naming the
computer whose workers have the deploy tools and credentials, and can hold
them again with ahfact deploy hold [--reason …]. The deploy subagent runs
ahfact deploy run LEASE in the job's worktree (clean, at exactly the job's
commit): it runs the .ahfact.json deploy hook with AHFACT_SHA set and
records deployed, failed, or held (the hook exited 3 before changing
anything). A failure or hold holds the project's deploys and reaches the
inbox. For a structured guard hold, ahfact deploy resume retries the same
commit and will hold again if the cause remains. Review the findings and
approve a single deploy in the board's Needs you or Project tab. The CLI
claims an existing approval for the job's hook. Creating an approval
requires a browser session. ahfact deploy history shows the hold, the
deploy machine, the commit deployed, the results and who approved them.
Deploy commands need CLI 0.27.0.
Deploying from GitHub Actions