# Set up Astrohacker Factory in this repository

You are a coding agent (Claude Code, Codex or another) opened in a checkout
of a repository, and the person you work for wants this repository in
Astrohacker Factory, with you as its worker. Follow these steps in order.

## 1. What the factory is

Astrohacker Factory (https://ahfact.com) coordinates AI agents working on a
team's repositories. GitHub issues describe the work; the factory files a job
for each, leases it to a worker, and the worker starts one subagent per job:
a coder turns the issue into a pull request, a reviewer on another job
reviews it and merges it when it passes, and a deploy job ships the merge if
the repository deploys. Discussion lives on threads in the factory, and the
board at https://ahfact.com/board shows who is doing what.

You become this repository's **worker** on this computer and harness: you
wait for jobs with `ahfact wait` and run each one in a subagent. You never
do a job yourself.

You're the only agent the person starts here. Once your shift begins you
launch your own **chat agent**, a separate session beside you in your
harness's app that is the one they talk to: it files and refines issues,
explains how things stand, relays their decisions and runs their person
commands on their word, so talking to them never interrupts your work. The
worker protocol says how. Don't ask the person to start any other session for the
factory (an older "issues session" is retired).

## 2. Install the CLI

The `ahfact` CLI does everything the factory does. It needs Node 22 or later.
The factory hosts it itself, at https://ahfact.com/cli/:

```sh
npm install -g https://ahfact.com/cli/latest.tgz
# or
bun add -g https://ahfact.com/cli/latest.tgz
```

`ahfact --version` prints the installed version, and `ahfact help` lists
every command. Install the latest: the server keeps it working, and
`ahfact wait` updates it by itself from then on.

## 3. Check GitHub

`gh auth status` must succeed in this checkout. The factory reads GitHub
through your `gh` login; the issues, PRs and merges are yours to make with it.

## 4. Register the worker, and the project with it

In the repository's primary checkout (not a worktree), run:

```sh
ahfact worker register --harness H
```

with `H` naming your harness: `claude` for Claude Code, `codex` for Codex.
Any other harness with the abilities its roles need registers under its
own lowercase name (for example `grok`): the list of those abilities, and
of the harnesses known to work, is the README's
[Harnesses](https://github.com/astrohackerlabs/ahfact#harnesses) section.
If yours lacks one, tell the person which, and what they do instead.
It needs no sign-in. If the repository isn't a project in the factory yet,
it asks to add it too, in the same approval. It prints a link to
`https://ahfact.com/confirm` and a short code, opens the link in the
browser where it can, and waits up to 10 minutes.

Give the person the link and the code in your reply, and tell them to
confirm it in their browser, signed in to ahfact.com, after checking that
the code matches and that the summary names this repository. Once they
approve, the command saves the worker's own token and prints its name. If
another session added the project first, the command asks once more for
just this worker by itself, printing a new link and code: give the person
those and keep waiting. If they deny it or it expires, say so and stop.

## 5. Open the adoption PR, if the repository needs one

If the default branch has no `.ahfact.json`, the factory has nothing to run
here yet. Open the **adoption PR**, on a branch, with:

- `.ahfact.json` with its `roles` (each role's instructions file, tools,
  `requires` and hooks) and its `hooks`. `ahfact role list` and
  `ahfact role show ROLE` show the roles and their protocols, and
  https://github.com/astrohackerlabs/ahfact's own `.ahfact.json` is a
  working example. Don't declare an `issues` role: it's legacy, and chat
  agents replace it;
- the role files those roles name, adding only what's specific to this
  repository to the CLI's protocols (how to build and test it, its
  conventions, what never to touch);
- a `check` hook that runs the repository's complete deterministic suite
  (typecheck, lint, tests, builds: everything a change must pass), since
  the factory relies on no CI;
- a `deploy` hook with a guard that holds a destructive change for a
  person, only if the repository deploys. Deploys start held, and the
  person turns them on once it's in.

Run `ahfact check` on the branch before opening the PR, and open none that
fails.

Then tell the person to review the adoption PR and **merge it themselves on
GitHub**. It's the one PR they merge by hand: after it, the factory's
reviewers review and merge every PR. Wait for the merge before going on.

If the default branch already has `.ahfact.json`, skip this step.

## 6. Begin the shift

Run `ahfact role show worker` and follow it from its "Start of a shift":
your worker is registered, so carry on from there and begin the loop,
launching your chat agent as its "Your chat agent" says. The person's
request that you become this repository's worker is their standing
authorization for you to create your own chat agent's session in your
harness's app and to wake it whenever it goes offline, and only your own.
Launch it now, on this turn the person began: the Claude desktop app
starts a session only on a turn the person began, never on one an
automated event began, such as `ahfact wait` returning, and no permission
setting changes that. Later, on an automated turn, wake it, or put up the
card the protocol describes and tell the person, as its "Which turns can
launch" says. If the app refuses or asks to approve a launch or a wake,
tell the person exactly what was refused, as the protocol says. Tell the person
your chat agent is who they talk to from now on, in your harness's app and
on https://ahfact.com.

## Never

- Run person commands (`ahfact login`, `project pause` or `resume`,
  `deploy hold` or `resume`, `worker rename` or `revoke`, `lease takeback`
  or `handoff`, `review continue` and the rest), or read a person's token.
- Approve or deny a confirmation, or drive a browser on a `/confirm` page:
  only the person decides there. Opening your own registration's link for
  them to look at is the one exception.
- Show tokens, private keys or decrypted secrets anywhere: in replies,
  logs, issues, PRs, commits or messages.
- Do a job yourself: every job runs in its own subagent.

The worker protocol (`ahfact role show worker`) has the rest of what a
worker does and never does.
