hapi-factory is a public, best-practices reference stack for an end-to-end agentic software factory. HAPi stands for Hermes + Archon + Pi: Hermes is the coordinator you talk to, Archon is the run engine and Pi is the worker. The stack puts existing tools together into one working system. It also covers the steps most factories skip: discovery research, architecture, threat modeling and breaking work into tasks. Security is designed in from the start: one policy compiled into every tool's config, rootless containers behind default-deny egress, secrets from a pluggable secret provider (sops + age by default), short-lived GitHub App tokens, and an audit that catches drift. Read the design in docs/superpowers/specs/2026-10-26-hapi-factory-design.md. It is the binding reference for everything here.
Status: Plan 01 (Phase 0 foundations) is in progress. Today the repo has the pinned toolchain, the
hapiCLI skeleton, CI,policy/with its JSON Schemas, loader, tighten-only repo overlay and work-order validator, the generators that compile policy into Hermes, Archon, Pi and egress-proxy configs (mise run policy:build), the pinned per-zone MCP catalog with its tool-description lock, fail-closed secrets from a pluggable provider, sops + age by default (mise run secrets:init,hapi secrets resolve) with per-machine keys and a 10-word recovery key, scoped GitHub App token minting (hapi token mint), the stack itself (stack/compose.yaml: Hermes and Archon on internal-only networks behind per-zone Squid egress proxies, started bymise run upas thehapiuser, withscripts/host-setup.shfor the one-time host setup and integration tests that prove the egress boundary on real Docker), the audit (mise run audit: config drift, the running stack's settings, pins, Archon's and Hermes's own validation, the MCP lock, the secrets setup, and each repo's rulesets, App permissions and AI workflows), the setup runbooks, the MAESTRO threat model v0 (docs/security/threat-model.md), the kill-switch runbook (docs/runbooks/kill-switches.md) and the notes of the verify-early spikes, Tasks 8–13 (docs/spikes/; Task 14 is on hold, H-177). Anything marked arrives in Plan 01 Task N is not built yet. The plan is docs/superpowers/plans/2026-10-26-hapi-factory-01-foundations.md.Plan 02 (the worker) is built:
hapi runstarts one hardened Archon container per run, on a network of its own, and copies out only a bundle, a transcript, a decision log and a result (docs/runbooks/runs.md); hapi-guard, Pi's only extension in a run, enforces protected paths, the budget, the model pins, secret hygiene and the level-6 gates;hapi decideanddecide()answer typed decisions; and the policy gained per-enforcer budget modes,runs.yamlandgates.yaml. The run engine (Plan 03) is next. Plan 02's design is docs/superpowers/specs/2026-10-29-hapi-factory-02-worker-design.md; what it left is in the register.
- Prerequisites
- Quick start
- Repo layout
- mise tasks
- The
hapiCLI - Toolchain and pinning
- CI
- Using hapi-factory with another repo
- Manual setup steps (the operator)
- Documentation map
- License
- Linux. It is the only supported OS (spec §3).
- mise 2026.10.9 or newer. It installs every other tool at a pinned version.
mise.tomlenforces the minimum withmin_version. - Docker Engine with Compose v2. You need it only for the stack and the integration tests. Linting and unit tests don't need Docker. The stack runs on rootless Docker as a dedicated
hapiuser, whichscripts/host-setup.shcreates (docs/runbooks/stack.md). - git.
You don't need to install Bun, Node, Python, uv, gh, gitleaks, shellcheck, sops or age yourself. mise install installs them all.
git clone https://github.com/j4th/hapi-factory.git # the public remote is a manual step, see below
cd hapi-factory
mise trust # first time only: let mise load this repo's mise.toml
mise install # install the exact tool versions pinned in mise.toml
git config core.hooksPath .githooks # the commit hooks: gitleaks on staged changes, and no personal strings
mise run lint # install JS deps from bun.lock, then type-check
mise run test # run the unit tests
mise run hapi -- --version # run the CLI (prints 0.1.0)The unit tests need no secrets. To run the stack you also need a secrets store (docs/secrets.md):
mise run secrets:init -- --file private/secrets.enc.yaml
# this machine's key, a recovery key, the encrypted store (all empty) and the config,
# the store in private/, where the stack's handoff to hapi reads it;
# it shows 10 recovery words once: store them where you can't lose them
mise run secrets:drill # prove the words open the store
mise run secrets:edit # fill in each value in your editor; sops encrypts it again
mise run secrets:check # every secret should say foundAnother machine or user gets its own key, never a copy: secrets:join there, then secrets:add-machine where the store already opens (docs/secrets.md).
The stack runs as a dedicated hapi user on rootless Docker. Set the host up once with sudo scripts/host-setup.sh, give hapi its own key to the store, then mise run up from any account (docs/runbooks/stack.md). A run of a work order is hapi run start, also as hapi (docs/runbooks/runs.md).
The run engine. mise run up also starts the poller, a systemd user timer that runs as hapi every runs.poll_interval_s (120 s). Each tick, for every repo policy/repos.yaml registers, it fetches the repo's mirror, takes up each work order a merged planning PR added under .factory/work/<id>/, and moves it one step: a worker run, a keyless verify, an independent review, at most one fix before the PR, then one factory PR (factory/<id>, lane:factory) whose description says what was asked, what was built, the evidence and a verdict, and, with flags.coderabbit.enabled on (it ships off), at most one automatic CodeRabbit round on it. You merge it, send it back with hapi:rework, or close it; nothing merges on its own. The planning PR's status comment and hapi status show each work order's phase and spend, every run is capped (the run, the repo's month, the day), and a failed work order waits for your hapi retry (docs/runbooks/engine.md).
What exists now:
| Path | What it is |
|---|---|
mise.toml |
Tool pins and the mise tasks. This is a protected path (spec §8.2): an interactive agent session must ask the operator before editing it, and unattended sessions and workers may not edit it at all. |
mise.lock |
What each mise.toml pin resolved to on linux-x64: the version, the download URL and its sha256, and the provenance where mise checked one. mise checks each download against it, and CI installs with --locked. Made by mise lock --platform linux-x64 (see To upgrade a tool). A protected path, like mise.toml. |
package.json, bun.lock |
JS project metadata and dependencies, pinned to exact versions: ajv (JSON Schema validation) and yaml at runtime, typescript and @types/bun for development. The lockfile is committed. |
.factory/config.yaml |
hapi-factory's own repo overlay (spec §7): when the factory works on this repo, it also protects policy/**, stack/**, .githooks/** and templates/**. An overlay can only tighten the central policy, and .factory/** is itself a protected path. Enforced for every run since Plan 03 (H-172): the run's own hapi-guard.json and run config come from the overlaid policy, and the harvester's host gates read it. |
.githooks/ |
The commit hooks, installed with git config core.hooksPath .githooks. pre-commit runs gitleaks, at the version mise.toml pins, on the staged changes, with .githooks/gitleaks.toml as its config and inline gitleaks:allow comments ignored, so neither a .gitleaks.toml nor an allow comment can turn the scan off (gitleaks still reads a root .gitleaksignore here, which CI refuses). Then it stops the commit if a staged line or path holds one of the operator's personal strings (private/personal-strings.txt): binary files, type changes and paths git would quote are checked too. pre-merge-commit runs the same checks on a merge commit. commit-msg checks the message the same way, down to git's own cut block only (the scissors line commit -v writes, then git's "Do not modify" line). The personal strings come from the main checkout's private/, also when you commit in a linked worktree. In a clone without private/, the personal-strings check is skipped with a notice. Don't bypass them with --no-verify. A protected path in hapi-factory's overlay, since they run on your machine at every commit. |
.coderabbit.yaml |
CodeRabbit's review-only config (spec §9.6): every way it can write to the repo is off, and its tools stay on as a second opinion beside CI. A protected path, since CodeRabbit reviews a PR with that branch's own copy. |
bunfig.toml |
Bun install settings: exact versions and a 3-day release-age cooldown (see Toolchain and pinning). |
LICENSE |
MIT. |
tsconfig.json |
Strict TypeScript settings, used only for type-checking. Bun runs the .ts files directly. |
src/cli.ts |
The hapi CLI: the entry point, the command registry and main(argv). |
src/version.ts |
HAPI_VERSION. It must match version in package.json, and a test checks that it does. |
policy/ |
The single source of truth: protected paths, commands, trusted sources, budgets, approvals, roles, flags, the model rosters (policy/rosters/), and the MCP catalog (mcp.yaml) with its tool-description lock (mcp.lock.json). See docs/policy.md and docs/mcp.md. |
policy/schemas/ |
JSON Schemas (draft 2020-12) for every policy file, the MCP lock, the repo overlay (.factory/config.yaml), the work order (order.yaml), the secrets manifest (stack/secrets.yaml), the local secrets config and a sops store's recipients file |
src/policy/ |
loadPolicy (load and validate policy/, the repo registry included), loadOverlay and applyOverlay (the repo overlay, which may only tighten policy), effectiveModes (a file's protected-path modes: the strictest across every matching glob), matchCommand (whether Hermes's argv-exact command rules allow a command), forgeDomain (forge hosts, which the archon zone may never reach), isHostname (a plain domain name, as the schema defines it), zoneHosts (an egress zone's allowlist), serversForZone (a zone's MCP servers, with the catalog's floor, blocklist and tool checks in mcp.ts), the policy types and the shared schema checker |
src/mcp/ |
The MCP tool-description lock (lock.ts): hashToolSurface, verifyLock, and the hapi mcp verify and hapi mcp pin commands |
src/workorder/ |
validateWorkOrder and the hapi workorder validate command |
stack/secrets.yaml |
The secrets manifest: per zone (hermes, archon, research, host), which env var gets which logical name (hapi-hermes-anthropic-api-key). Public and provider-neutral: no ids, no values. It is the single list of what your store must hold. See docs/secrets.md. |
src/secrets/ |
manifest.ts: loadManifest and mcpSecretGaps (the manifest covers the MCP catalog's secret: references). provider.ts: the SecretProvider interface, SecretError, loadSecretsConfig (the local config), resolveSecrets (fail-closed: every name into memory, then the env files), checkSecrets and describeSecretsConfig. cli.ts: every hapi secrets command handler, and providerFor (exactly the configured provider, no fallback). providers/: sops.ts (the default, and the pinned-age lookup), bws.ts (optional) and env-file.ts (a downgrade). init.ts: hapi secrets init. lifecycle.ts: per-machine keys and recipient changes: join, add-machine, recover, drill, revoke and new-recovery. store-files.ts: what init and those commands share: the no-replace writes, the path checks, the config text, and the store's lock (under $XDG_RUNTIME_DIR/hapi/locks/, never beside the store; a stale one is cleared) that every lifecycle command and edit hold. interrupt.ts: what a command undoes on Ctrl-C, SIGTERM or SIGHUP (the lock, the terminal's echo), and the steps a signal waits for. recipients.ts: the recipients file (with recovery.age's SHA-256), the post-quantum/classic check and drift against the store. recovery.ts and wordlist.ts: the recovery key and its 10 words (age's BIP-39 list, BSD-3-Clause). files.ts: secrets on disk: runtimeDir ($XDG_RUNTIME_DIR/hapi, no fallback), secureDir (0700 under a 0700 XDG_RUNTIME_DIR), writeSecretFiles (the whole set at once, by symlink swap), writeNewSecretFile (no-replace), the env-file format, and the checks that keep keys and plaintext outside the checkout. |
templates/repo-contract/ |
The repo contract (design §3.3): the 29 files hapi new-repo renders into a new repo's first commit, each ending in .tmpl so nothing here treats one as a live file. A protected path, like policy/. See docs/runbooks/new-repo.md. |
src/newrepo/ |
hapi new-repo: render.ts (renderTemplate, .factory/template.lock, and the checks a render must pass before anything is pushed), steps.ts (the eleven steps, in order) and cli.ts (the flags, and the operator's gh auth token, held in memory). |
src/forge/ |
Every forge call goes through here (spec §16): index.ts the Forge interface and the contract's settings and labels; github/forge.ts the GitHub adapter (githubForge); github/rest.ts the REST client, which refuses redirects and off-host URLs before the bearer is sent; github/git.ts authenticated git (authedGit: the token in the environment only); github/token.ts the engine's per-purpose tokens (forgeToken); github/app-token.ts: appJwt, findInstallationId, mintInstallationToken (one repo, checked scope, a broader token revoked) and hapi token mint |
src/generate/ |
The config generators and hapi policy build: one pure emitter per tool (hermes.ts, archon.ts, pi.ts, egress.ts, mcp.ts for the MCP servers, claude.ts for the review's Claude Code settings, and systemd.ts for the poller's user units) and buildAll (index.ts). See docs/generated-configs.md. |
build/ |
Generated by mise run policy:build, and gitignored: hermes/config.yaml, archon/config.yaml and archon.env, pi/models.json, models-store.json, settings.json, hapi-guard.json and extensions/hapi-guard.js, decide/hapi-decide.js, egress/{hermes,archon,research,review}.squid.conf, mcp/{hermes,research}.mcp.json, claude/managed-settings.json, systemd/hapi-poll.{service,timer} and roster. Never edit it by hand. |
stack/compose.yaml |
The stack's six services: hermes, archon (a profile-only template: hapi run makes one container of it per run, and up starts none) and one Squid egress proxy per zone (egress-hermes, egress-archon, egress-research, and egress-review, which the launcher joins to a review run's network; its review-net holds only it), on internal-only zone networks whose one way out is the zone's proxy. up also pulls each smoke sidecar image policy/sidecars.yaml pins. Every service hardened (no capabilities, non-root, read-only, limits, no published ports), every image pinned by digest. See docs/runbooks/stack.md. |
stack/hermes/Dockerfile, stack/archon/Dockerfile |
The Hermes (v0.22.5) and Archon (0.12.1, with Pi 1.3.0, baked Node, uv and Python toolchains, mise with the repo contract's tools, and CodeRabbit's CLI) images, each FROM pinned by digest, each download by checksum |
stack/archon/run.sh, verify.sh, review.sh |
The run container's fixed preludes, one per run kind, each bound read-only at /opt/hapi/<prelude>. run.sh (a worker, a fix): a sparse clone without .pi/, .agents/ and .archon/, archon workflow run, then the bundle, result.json and the transcript read back into /out. verify.sh (a verify, which holds no key): the same, with Claude Code's files left out too and no bundle. review.sh (a review, which runs no repo code): verify.sh with its symlinks made plain files and the checkout made read-only. The three share their clone, trap, wait and read-back byte for byte (tests/run/prelude.test.ts). Nothing a run, a repo or a work order says is in them. See run kinds. |
archon/workflows/hapi/ |
The workflow pack bound read-only into a run: Plan 02's two bash-only check workflows, hapi-check-run and hapi-check-guard, and Plan 03's factory workflows, factory-task (a worker or a fix: preflight, the Pi session, the gates, one commit per piece), factory-verify and factory-review, with the two scripts they share (mise-config-scan.sh, time-left.sh). See the factory workflows. |
archon/prompts/ |
The factory workflows' fixed prompts (factory-implement.md, factory-fix.md, factory-review.md), copied byte for byte into the YAML, where a test holds them equal. |
scripts/host-setup.sh |
The one-time host setup, run by the host admin with sudo: the hapi user (refused if it can become root: a root-equivalent group such as docker or sudo, or any sudo rule), rootless Docker with lingering, a pinned mise and hapi's own checkout. Idempotent. |
scripts/copy-secrets-to-hapi.sh |
Hands the hapi user its copy of your secrets store (the store, its recipients file and recovery.age), run as yourself: a tar running as hapi writes them, since root never writes into hapi's home. |
src/audit/ |
hapi audit (index.ts: runAudit, the command, and the order of the checks; types.ts: a check's result and the context every check gets, whose exec and fetch the tests replace with fakes) and the checks, one file per group in checks/: generated.ts (config drift and the containers' build labels), runtime.ts (the running containers), pins.ts, tools.ts (Archon's and Hermes's own validation, in their images), mcp.ts (the MCP lock), secrets.ts, github.ts (rulesets, App permissions, a registered repo's settings and labels, AI workflows), policy.ts (budget enforcement, the repo registry, sidecars, decision models), repo.ts (the checkout's private/) and util.ts (what the checks share). See docs/audit.md. |
src/run/ |
hapi run start, stop, watch, list (and the internal supervise): the launcher. kinds.ts the run kinds' profiles (a worker, a verify, a review, a fix: each one's zone, proxy, prelude, workflow, inputs and outputs); spec.ts builds the run container's docker run arguments from the archon service, for its kind; lifecycle.ts is start, stop, finalize and the reaper; records.ts the per-run records, the run key and the admission rules; copyout.ts how outputs leave a run; disk.ts the run disk and its check; sidecar.ts the smoke sidecar; spend.ts a run's spend; git.ts the host's hardened git; locks.ts the run disk's lock; mount.ts the mount-path check; sanitize.ts terminal and secret redaction; view.ts watch and list; cli.ts the usage lines and the host-side defaults. See docs/runbooks/runs.md. |
src/engine/ |
The run engine (Plan 03): poll.ts the poller's tick and cli.ts hapi poll, hapi status and hapi retry; pipeline.ts a work order's state machine; state.ts its state files and events; discover.ts and mirror.ts the mirror and discovery of merged work orders; caps.ts the repo and day caps; harvest.ts the host gates, the push and the PR; pr.ts the PR's description; evidence.ts the runs' outputs read as data; decisions.ts the advisory decide() screens and their ledger; coderabbit.ts the CodeRabbit round, rework and the operator's actions; status.ts the planning PR's status comment. See docs/runbooks/engine.md. |
src/guard/ |
hapi-guard, Pi's only extension in a run, bundled to build/pi/extensions/hapi-guard.js: protected paths, the budget, the model pins, secret hygiene and the level-6 gates. See docs/generated-configs.md. |
src/decide/ |
decide() with the vendored Jev client, a Haiku fallback and the decision files' semantics, and the hapi decide command (docs/policy.md). |
src/stack/ |
hapi stack up and hapi stack down (up.ts): the re-exec as hapi, the dev bypass (currentUserOverride), the policy build, secrets and Compose steps, and the zone-network check; cidr.ts, the CIDR maths it shares with the egress tests; env.ts, the environment hapi sets in each zone container (serviceEnvironment) and the env names no secret may have (RESERVED_ENV_NAMES) |
tests/ |
Unit tests for bun test. tests/fixtures/ holds example work orders, overlays, a broken policy directory, and command-vectors.json, the command-allowlist cases that Plan 04's Python hook must also pass. tests/docs/ checks the GitHub ruleset JSON in this README and the GitHub Apps runbook, and the threat model's residual and register entries and the repo paths it and the kill-switch runbook name. tests/audit/ runs every audit check over a world of fakes, with fixtures captured from the pinned Archon and Hermes images and a copy of a comment-triggered AI workflow. tests/engine/ runs the poller, the pipeline and the harvester over Task 3's fake forge and real git; tests/forge/ the forge over a fake GitHub; tests/run/ the launcher over a fake Docker; tests/guard/, tests/decide/, tests/generate/, tests/newrepo/, tests/scripts/ and tests/secrets/ their own modules. Integration tests are *.int.test.ts (tests/stack/ for the stack's egress boundary on real Docker and Squid, tests/run/ for real runs), run by mise run test:int. |
.github/workflows/ci.yml |
CI for this repo. |
.github/workflows/gates.yml |
The reusable gates workflow every repo made from the contract calls: its mise run check, gitleaks, OSV-Scanner, zizmor and the factory-commit trailer check, reported as ci / gates (docs/runbooks/new-repo.md). |
docs/policy.md |
The policy files (the MCP catalog and its lock included), the command-allowlist semantics, the overlay rule, the work-order format and the hapi mcp commands |
docs/audit.md |
hapi audit: every check, what it verifies and why, its credential, how to fix a failure and what its skip means; --strict and --dev; the GitHub permissions each read needs |
docs/generated-configs.md |
Every file under build/: what it is, which policy files feed it, what each hardening setting does and why, and how to regenerate it |
docs/mcp.md |
The MCP layer: which zone gets which server, how to add or upgrade one, the release cooldown, advisory floors, the tool-description lock and the CI scanners |
docs/secrets.md |
Secrets: manifest, config and store; the zones and their keys; sops + age onboarding; keys and recovery (per-machine keys, the 10 recovery words, post-quantum keys and the lifecycle commands); hapi secrets init, edit, check and resolve; the env files; rotation; optional bws; the env-file downgrade; hapi token mint; threat notes |
docs/runbooks/ |
Runbooks: the stack (host setup, the hapi user's secrets, up/down, troubleshooting, what each test proves), runs (hapi run, the outputs, retention, the rollout), the kill switches, GitHub Apps and rulesets, hapi new-repo (a new repo from the contract), provider keys and spend caps, Slack |
docs/security/threat-model.md |
The threat model, v0: CSA MAESTRO's layers and steps over the Phase 0 stack and the planned Phase 1 flow, each threat with its OWASP and MITRE ATLAS IDs, every control grouped by SANS domain with its status, spec §11.9's six residual risks and the other accepted residuals |
docs/superpowers/specs/ |
The design spec. It is the binding authority. |
docs/superpowers/plans/ |
Implementation plans. Plan 01 is the current one. |
docs/research/ |
What the research behind the design covered, and which of its conclusions the spec adopted, by section. The sources themselves are private. |
docs/spikes/ |
The verify-early spikes' notes (Plan 01 Tasks 8–13; Plan 02's run container and guard hooks, spikes 07 and 08), each with its result, evidence, decision and consequence for the later plans. Task 14, the smoke sidecar, is on hold until the showcase's subject is picked (H-177). spikes/scratch/ holds throwaway spike work and is gitignored. |
Run mise tasks to list them with descriptions. Run any of them with mise run <task>.
| Task | What it does | Status |
|---|---|---|
setup |
bun install --frozen-lockfile: installs the JS dependencies exactly as bun.lock records them. It fails if package.json and bun.lock disagree. |
Works |
lint |
Runs setup, then type-checks the whole project with node_modules/.bin/tsc --noEmit (strict). Never bunx, which downloads from npm when a binary is missing. |
Works |
test |
bun test: the unit suite. It needs no Docker, network or secrets. Integration tests are skipped unless HAPI_INT is set. |
Works |
test:int |
bun test .int.test.ts with HAPI_INT=1: every integration test. The stack's egress boundary on real Docker and Squid, in a throwaway Compose project it removes afterwards; the real sops + age lifecycle; policy:build's flags through mise. They need Docker, and the internet for the tests named so (skipped with a warning offline). See docs/runbooks/stack.md. |
Works |
hapi |
bun run src/cli.ts: runs the hapi CLI. Put -- before the CLI's arguments: mise run hapi -- --help. |
Works |
secrets:init |
hapi secrets init: sets up the default sops + age store: this machine's key, a recovery key wrapped with 10 words it shows once and checks you kept, an encrypted file of every name in stack/secrets.yaml (all empty), its recipients file, recovery.age and the config. It never overwrites anything. Flags after --, e.g. mise run secrets:init -- --file private/secrets.enc.yaml. See docs/secrets.md. |
Works |
secrets:edit |
hapi secrets edit: opens your sops store in $EDITOR (sops edit), with the plaintext temp file on your tmpfs. |
Works |
secrets:check |
hapi secrets check: prints found, missing, empty or invalid for every secret in the manifest, never a value, and the store's recipients; exits 1 unless all are found and the recipients agree with the store. |
Works |
secrets:drill |
hapi secrets drill: proves your 10 recovery words and recovery.age open the store, in an isolated temp dir. Prints a count, never a value. See docs/secrets.md. |
Works |
secrets:join, secrets:add-machine |
A new machine or user makes its own key (join --store <file>), and a machine that opens the store adds it (add-machine --name <n> --recipient <age1...>). See docs/secrets.md. |
Works |
secrets:recover, secrets:revoke, secrets:new-recovery |
Give a box its own key with the 10 words; remove a recipient; replace lost or exposed words. Each recipient change makes a new data key. See docs/secrets.md. | Works |
policy:build |
hapi policy build: compiles policy/ into the Hermes, Archon, Pi, egress and MCP configs under build/. Pass CLI flags after --, e.g. mise run policy:build -- --roster budget. See docs/generated-configs.md. |
Works |
audit |
hapi audit: checks the deployed config, the running stack, the pins, Archon's and Hermes's own validation, the MCP lock, the secrets setup and each --repo's GitHub settings against policy. One line per check (pass, fail or skip, with why) and a summary; exits 1 on any fail. Run it as hapi; --strict turns every skip into a fail, e.g. mise run audit -- --strict --repo <owner>/<name> --github-token-file <file> (the operator's token, 0600: a strict run fails without it). See docs/audit.md. |
Works |
up |
hapi stack up: as the hapi user (it re-execs with sudo -u hapi -H, passing your flags as separate arguments, never through a login shell), builds policy, resolves secrets, then starts the stack and waits until every service is healthy. Nothing starts if a step before Compose fails. Flags after --, e.g. mise run up -- --roster budget. See docs/runbooks/stack.md. |
Works |
down |
hapi stack down: stops the stack and removes its containers and networks, keeping its volumes. It is kill switch 3 (docs/runbooks/kill-switches.md). |
Works |
new-repo |
hapi new-repo: makes a new public repo ready for the factory with your own gh login, from templates/repo-contract/. Flags after --, e.g. mise run new-repo -- <name> --clone --dry-run. See docs/runbooks/new-repo.md. |
Works |
A task that isn't built yet is a stub that prints which task implements it and exits 1, so a stub can never pass as a real check. None is left in Plan 01's tasks.
hapi is a single TypeScript CLI, run on Bun. It owns policy loading, config generation, secrets, forge tokens and audit.
Usage: hapi <command> [args...]
hapi --version | --help
You can run it two ways:
mise run hapi -- <command> [args...]. The--is needed. Without it, mise reads flags such as--helpas its own.bun run src/cli.ts <command> [args...], inside the repo with the mise tools active.
Exit codes:
0: success.1: the command failed. If a command throws,hapiprintshapi <command>: <message>to stderr.2: a usage error: an unknown command, no command at all, or the wrong arguments for a command.
Commands:
| Command | What it does | Arrives in |
|---|---|---|
--version |
Prints the version (0.1.0) |
Works |
--help, -h |
Prints usage and the registered commands | Works |
workorder validate <path> |
Validates a work order (order.yaml) against policy/schemas/work-order.schema.json. Valid: prints its id and exits 0. Invalid: prints one path: message line per problem to stderr (e.g. /trace/traceparent: must match pattern ...) and exits 1. See docs/policy.md. |
Works |
policy build [--policy dir] [--out dir] [--roster name] |
Loads and checks --policy (default policy), writes the generated configs under --out (default build) and prints each path. --roster (budget, anthropic or portable; default anthropic) picks Archon's tiers and Pi's models; Hermes always uses anthropic. A usage error exits 2; a bad policy file exits 1 and names the file. See docs/generated-configs.md. |
Works |
mcp verify [--policy dir] [--lock file] |
Checks every MCP server's live tool surface against policy/mcp.lock.json. Prints ok, changed or unpinned per server, and orphaned for a lock entry whose server left the catalog, and exits 1 unless all are ok. Until the live fetch is wired it exits 1. See docs/policy.md. |
The command works now; the live fetch arrives in Plan 04 |
mcp pin --server name [--policy dir] [--lock file] |
Records one MCP server's live tool surface and its hash in policy/mcp.lock.json. A re-pin is a reviewed change (docs/mcp.md). |
The command works now; the live fetch arrives in Plan 04 |
secrets init [--config file] [--file file] [--age-key file] [--name name] [--classic] [--no-confirm] |
Sets up the default sops + age store: reuses or makes this machine's post-quantum age key (outside the checkout, 0600), makes a recovery key and 10 words, shows the words once on the terminal and asks for 2 of them back, then encrypts every manifest name with an empty value to both keys by piping it to sops encrypt (plaintext never touches disk), and writes the store, recovery.age, the recipients file and the config, each no-replace. It never overwrites anything, and an abort writes nothing. See docs/secrets.md. |
Works |
secrets join --store file [--name name] [--config file] [--age-key file] |
On a new machine or user: makes its own key and config for a copy of the store, without touching the store, and prints the add-machine command to run where the store already opens. See docs/secrets.md. |
Works |
secrets add-machine --name name --recipient age1... [--config file] |
Adds a machine's public key (sops rotate -i --add-age, a new data key) and its recipients-file entry. Refuses a duplicate, a malformed key or a post-quantum/classic mix. See docs/secrets.md. |
Works |
secrets recover [--store file] [--name name] [--config file] [--age-key file] |
For a box with the store, recovery.age, the recipients file and the words, but no key: makes its own key, reads the words, and adds itself with the unwrapped recovery key (in memory). See docs/secrets.md. |
Works |
secrets drill [--config file] |
Proves the words open the store: decrypts it in an isolated temp HOME with only the recovery key, and prints recovery works: N names readable, never a value. See docs/secrets.md. |
Works |
secrets revoke --name name [--config file] |
Removes a recipient (sops rotate -i --rm-age); refuses the last machine key or the only recovery recipient, and reminds you to reissue the credentials if the key may be compromised. See docs/secrets.md. |
Works |
secrets new-recovery [--config file] [--no-confirm] |
Replaces the recovery key, its words and recovery.age (lost or exposed words), with the same show-and-confirm as init. See docs/secrets.md. |
Works |
secrets edit [--config file] |
Runs sops edit on the configured file in your terminal (sops provider only), holding the store's lock, after the same store checks as the lifecycle commands (age recipients only, no setting that leaves values in plaintext, the recipients file in step) and the age key checks, with TMPDIR on your tmpfs, your shell's SOPS_* variables dropped and GPG_AGENT_INFO=. When sops ends, it runs the store checks again, and exits 1 if the store now fails them, telling you not to commit it. See docs/secrets.md. |
Works |
secrets check [--config file] |
Reads the configured store and prints found, missing, empty or invalid for every env var of stack/secrets.yaml, missing for an MCP reference it doesn't map, and unknown for store names it doesn't list; for sops, also the store's recipients. Never a value; writes nothing; exits 1 if anything is missing, empty or invalid, or the recipients file disagrees with the store, mixes post-quantum and classic keys, or records another recovery.age than the one beside the store. It warns when there is no recovery recipient or recovery.age. See docs/secrets.md. |
Works |
secrets resolve [--config file] [--dry-run] |
Resolves stack/secrets.yaml from the configured provider (the config at --config, $HAPI_SECRETS_CONFIG or ~/.config/hapi/secrets.yaml), all into memory first, then writes $XDG_RUNTIME_DIR/hapi/env/<zone>.env (mode 0600) as one set, by symlink swap, and prints each path. A provider failure, or any missing or empty secret, fails, naming it, and nothing is written; there is no fallback to another provider. It fails if XDG_RUNTIME_DIR is unset or isn't yours and 0700 (no /tmp fallback). --dry-run is secrets check. See docs/secrets.md. |
Works |
token mint --app planner|factory --repo owner/name |
Mints a 1-hour GitHub App installation token for that one repo, with the App's fixed permissions. It reads the App's id and key from $XDG_RUNTIME_DIR/hapi/env/host.env, rejects (and revokes) a token broader than requested or without a valid expiry, writes the token to $XDG_RUNTIME_DIR/hapi/tokens/<app>.<owner>.<repo>.token (mode 0600), then deletes token files more than an hour old (a failure there is only a warning). It prints the path and expiry, never the token. See docs/secrets.md. |
Works |
stack up [--roster name] [--config file] |
Starts the stack (docs/runbooks/stack.md). As any user but hapi it re-execs mise run up as hapi with sudo -u hapi -H, in hapi's checkout, each flag an argument of its own, never re-parsed by a login shell; HAPI_ALLOW_CURRENT_USER=1 skips that, a dev-only downgrade it warns about and labels. Then it stops the poller's timer, runs hapi policy build, hapi secrets resolve, docker compose up --no-start --build, a check that every zone network is internal and private, and docker compose up -d --wait, and last links and starts the poller's timer (build/systemd/; not under the dev bypass). Any failure before Compose starts nothing, and is printed with exit 1. |
Works |
run start --repo path --work-order file [--public] [--budget-usd n] [--retry-of id] |
Starts one run of a work order in a hardened one-shot Archon container on a network of its own, and prints its id. As hapi, with a bare clone as the repo (docs/runbooks/runs.md). |
Works |
run stop id, run watch id, run list |
Stop one run (30 s grace), follow one (docker logs, then its stored transcript, sanitized and redacted), list the runs the host knows. run supervise id is internal: start spawns it. |
Works |
decide name [--state-file file] [--public] [--mock] |
Runs one typed decision (the bash gate or the result screen) on a state read from a file or stdin and prints the result as JSON (docs/policy.md). | Works |
stack down |
Stops the poller's timer, removes the runs, then docker compose -p hapi down: removes the stack's containers and networks, keeping its volumes. It needs no compose file or XDG_RUNTIME_DIR, and re-execs as hapi like up. |
Works |
poll [--once] |
The poller (docs/runbooks/engine.md): one tick over every repo policy/repos.yaml registers with --once (what the systemd timer runs), or a tick every runs.poll_interval_s without it. A tick fetches each repo's mirror, gives each newly merged work order a state, keeps one pipeline per repo, advances every work order on a PR, and edits each planning PR's status comment; a repo whose tick fails (a forge or git error) fails closed alone, and the next tick retries. Prints one line per repo; --once exits 1 when a repo failed. As hapi, re-execing like run. |
Works |
status [<owner>/<name>] |
Each planning PR's work orders, as its status comment shows them: state, verdict and reason, last run, PR, rounds (automatic, rework, retry) and cost, then the total. From hapi's local state alone: its state files, and each plan's overlay at its merge from the repo's mirror (read-only host git), so the costs match the comment's; no forge, Docker or network call. Ends with a line when gates.decisions.mode isn't enforce. An unregistered repo exits 1. As hapi. |
Works |
retry <owner>/<name> <id> |
Queues a failed work order with no PR again, at the back of its repo's queue: a poll tick starts a fresh pass from its worker, at the same merge commit, once none is ahead and the caps allow. At most runs.max_retries (2) times; it refuses anything but a failed work order, and while a tick holds the poll lock. The operator's own command, from your terminal: never in Hermes's allowlist (H-245). It runs no git and calls no forge or Docker. As hapi. |
Works |
new-repo <name> [--clone] [--collaborators-only] [--dry-run] |
Makes <your-login>/<name>, public, from the repo contract, with your own gh login (gh auth token, held in memory; it needs the workflow scope): it checks first and reads only, renders and checks the contract, creates the repo, pushes the first commit, sets the repo up, applies the four rulesets and reads them back, makes the labels, adds the Apps (or waits on a web step), registers the repo in policy/repos.yaml (uncommitted) and runs the strict audit's GitHub checks. --clone also clones it into ../<name>; --dry-run changes nothing. A failed step stops it, saying what was done and what to undo; exit 1. See docs/runbooks/new-repo.md. |
Works |
audit [--repo owner/name ...] [--strict] [--dev] [--github-token-file path] [--build-dir dir] [--policy dir] |
Runs every audit check (docs/audit.md) and prints one line per check and a summary. The github.* and repo.* checks run once per --repo and make GET requests only, with the operator's token from --github-token-file (never printed) or a read-only App token it mints and revokes. A skip (no stack, no --repo, no credentials) is never a pass; --strict makes it a fail, and --dev makes the dev-only downgrades a skip. Exits 1 on any fail, 2 on a usage error. |
Works |
Adding a command (for contributors). Write the handler in its own module, as policyBuild is in src/generate/index.ts. Then register it in the Commands section at the bottom of src/cli.ts:
import { policyBuild } from "./generate/index";
register("policy build", policyBuild, "Compile policy/ into Hermes, Archon, Pi, egress and MCP configs under build/");Here is how commands work:
- A name can be several words.
mainmatches the longest registered name against the leading words of argv, and passes the remaining args to the handler. - No word in a name may start with
-. - Registering the same name twice throws.
- A handler gets the args after its name, as
(args: string[]) => number | Promise<number>, and returns the exit code. - Print results to stdout and diagnostics to stderr.
- Error messages name keys, never values. Name the zone, key, file, line or JSON Pointer; never print a secret or token, and never pass through text that might hold one (a tool's stdout,
JSON.parse's own message). See docs/secrets.md.
mise.toml pins every tool to an exact version. For each tool's version, read mise.toml; this README doesn't copy them, so they can't drift apart.
| Tool | Why it's here |
|---|---|
bun |
Runtime, package manager and test runner for the hapi CLI |
node |
For Node-based tools (for example a standalone Pi CLI later) |
uv, python |
Python tooling on the Hermes side |
gh |
GitHub CLI, used only for the operator's manual setup steps. Factory code calls GitHub through src/forge/, never raw gh (spec §11). |
gitleaks |
Secret scanning |
shellcheck |
Lints the shell scripts and commit hooks, in their tests |
sops |
The default secret provider: one age-encrypted file, decrypted into memory when the stack starts (spec §11.5, docs/secrets.md) |
age |
Provides age, age-keygen and age-plugin-batchpass: the keys the sops file is encrypted to, and the wrapped recovery key. hapi uses this pinned age (mise where age, at least 1.3.2), never one on PATH |
bws (Bitwarden Secrets Manager) is an optional provider and isn't pinned here; a bws user pins it in their global mise config (mise use -g), never in a mise file in the checkout, which CI and hapi audit refuse (docs/secrets.md).
Supply-chain defaults (spec §11.6–11.7):
- Exact versions everywhere. That covers
mise.toml,package.json(bunfig.tomlsetsexact = true, sobun addnever writes^) and the mise version CI uses. - Committed lockfiles.
bun.lockis in git, andmise run setupinstalls with--frozen-lockfile.mise.lockrecords each mise tool's download URL and sha256 for linux-x64, so a release file replaced after it was locked fails its checksum. CI installs withmise install --locked, so amise.tomlchange without its lock fails there. The lockfile checks downloads only: a tool already installed, or restored from CI's cache, isn't checked again. - A release-age cooldown.
bunfig.tomlsetsminimumReleaseAgeto 3 days, so Bun won't resolve a package version published less than 3 days ago. - Pinned actions. CI actions are pinned to full commit SHAs, CI runs with a read-only token, and checkout doesn't persist credentials.
- No plaintext secrets in the repo, or in a file hapi writes to disk.
.env*,private/,keys.txt,*.agekey,secrets.envandmise.local.tomlare gitignored. The store is encrypted (sops + age) by default, and hapi writes resolved secrets only to0600files on the user's tmpfs ($XDG_RUNTIME_DIR/hapi/env/), never to the repo or a.envfile on disk. Docker, though, keeps each zone container's environment, its secrets included, in the container's config on hapi's disk untilmise run downremoves the container: an accepted residual (H-189, docs/secrets.md).
To upgrade a tool:
- Find the version with
mise ls-remote <tool>ormise latest <tool>. - Bump it in
mise.toml. - Run
mise lock --platform linux-x64. It updates that tool's entry inmise.lockand nothing else. Run it beforemise install: after a bump, a plainmise installupdates the lock too, but it also adds three more linux-x64 variants for every tool. - Run
mise install && mise run lint && mise run test. The tests fail if the tool's linux-x64 entry has no sha256, which happens when a release publishes no checksum (shellcheck 0.10.0's, for one). - Commit
mise.tomlandmise.locktogether, and say why in the PR.
For JS dependencies, use bun add -d <pkg>@<exact-version> (or without -d for a runtime dependency) and commit bun.lock with the change.
.github/workflows/ci.yml runs on every pull request and on every push to main, in three jobs on ubuntu-latest:
buildruns the PR's code:- Checks out the repo.
- Only the root
mise.tomlconfigures mise: before mise is installed, a plain file scan fails, naming each one, on any mise file in the checkout besides the rootmise.tomland the rootmise.lockthat locks it, at any depth and in any case (a.mise.toml,mise.local.toml,mise.<env>.toml, a nestedmise.toml,.config/mise.toml,mise/or.mise/,mise-tasks/,.tool-versions, a nestedmise.lock,mise.local.lockandmise.<env>.lock). mise loads them overmise.toml, andjdx/mise-actioninstalls the tools they name and exports the env they set to every later step, so one could change what the job runs, a check after it included. - Installs the pinned mise with
jdx/mise-action, then, as a second net for a file the scan doesn't know by name, fails ifmise config lsormise tasks lslists any config or task file in the checkout besidesmise.toml. - Runs
mise install --locked && mise run lint && mise run test.--lockedfails on a toolmise.lockdoesn't cover, instead of resolving a version.
secretsscans the whole history for secrets on its own fresh runner and checkout, with no mise and none of the PR's code. It is the reusable gates' history scan (below), step for step: the* diffattributes, the refusal of a root.gitleaks.tomlor.gitleaksignore, gitleaks pinned by URL and sha256, the git 2.40 gate, the dry run of gitleaks's owngit log, and gitleaks with inlinegitleaks:allowignored, failing on a finding, an ERR, a WRN other than its findings line, or 0 commits. Its one difference is the config:--config .githooks/gitleaks.toml(gitleaks's default rules), where a false positive is allowed. That file is under the protected.githooks/**, and a PR that edits it changes what the scan finds, so its review is the operator's.tests/scripts/ci-workflow.test.tsholds the steps equal togates.yml's (H-241, closed).cipasses only whenbuildandsecretsboth succeeded. It runs even when one failed (if: always()), since GitHub reports a job skipped for a failed need as a success.
The main-protect ruleset requires the ci check to pass, and nobody can bypass it, not even the repo admin (see the manual steps below). build and secrets show beside it and aren't required.
Target repos run the reusable gates workflow instead, .github/workflows/gates.yml, from their own .github/workflows/hapi-gates.yml pinned to a hapi-factory commit (spec §11.7). It has three jobs. scan runs on a fresh runner that never runs the PR's code, with no mise, and ignores the PR's scanner configs, .gitattributes, .mailmap and .gitmodules. It runs the mise-file scan and refuses a root .gitleaks.toml or .gitleaksignore. The history scan needs /usr/bin/git 2.40 or later. It first runs gitleaks's own git log itself (every commit on every fetched ref, merges' own diffs and type changes included, rename detection off, no system git config) and fails on a non-zero exit or any byte on stderr, since gitleaks 8.30.1 ignores git's exit status and logs some git errors only as warnings. Then gitleaks, which fails on a finding, on any ERR line, on any WRN line but its findings count, or on a scan of 0 commits; its output is shown between a random ::stop-commands:: token and its end, so a file name a PR picks can't issue a workflow command. Then OSV-Scanner over bun.lock, zizmor over the repo's workflows, and the trailer check on every commit of a factory/** PR. Each scanner is downloaded from a release URL checked against a sha256 pinned in gates.yml, and run under env -i with the gates' own config. gitleaks's default path allowlist (*.png, node_modules/, lockfiles of other ecosystems and such) is a known residual (H-240), and so is a token outside file contents, in a commit message, a file name or a tag's message (H-242). check runs ci.yml's two mise checks, word for word, and mise install --locked && mise run check. gates passes only when both did. The required check is ci / gates; ci / scan and ci / check show beside it and aren't required (docs/runbooks/new-repo.md). A PR that changes .github/workflows/ runs its own copy of the workflows, so its ci / gates proves nothing (H-239). SAST and the work-order schema check are still to come (H-163).
A target repo references hapi-factory rather than copying it (spec §17), through a small per-repo contract (spec §7; Plan 03 design §3.3) that mise run new-repo lays down from templates/repo-contract/, with your own gh login (docs/runbooks/new-repo.md):
AGENTS.md, written for an unattended agent: the work order overrides it, and nothing in it waits for a confirmation;mise.tomltasks (setup,fmt,lint,test,check,smoke,scan) and themise.lockthat pins their tools;- a
.factory/config.yamlpolicy overlay, which may only tighten the central policy (see docs/policy.md), and protects the gates' own config; - a thin CI wrapper around the reusable gates workflow, pinned by commit SHA (spec §11.7; a tag only the operator could make);
- CODEOWNERS and the four rulesets:
main-protect(requiringci / gates),main-review,agent-branch-scopeandtags-admin-only; - the files a public repo needs from day one: MIT, a security policy, the Contributor Covenant, contributing rules, issue forms, a PR template and Dependabot.
To drop a new repo in:
- Once:
gh auth refresh -s workflow, so your login can push a workflow file; both Apps installed on selected repositories, with the installation idspolicy/repos.yamlrecords; your checkout's HEAD pushed, since the new repo's wrapper calls the gates at that commit. - Check:
mise run new-repo -- <name> --dry-runreads and checks everything and prints what it would do. - Make it:
mise run new-repo -- <name>, with--clonefor a clone in../<name>. It creates the public repo, pushes the contract as its first commit before any ruleset exists, sets the repo up, applies the rulesets and reads them back, makes the labels, adds the Apps, registers the repo and runs the strict audit's GitHub checks. A failed step stops it, saying what to undo. - Commit the registration:
policy/repos.yamlholds the new entry as an uncommitted change; review it and merge it by PR. The poller acts only on registered repos. - Audit the Apps: as hapi,
mise run audit -- --strict --repo <owner>/<name> --github-token-file <file>; itsgithub.app-permsproves each App's reach (Verify), andpolicy.reposthat the installation idspolicy/repos.yamlrecords are the Apps' on the repo.
Every file under templates/repo-contract/ ends in .tmpl, which the render strips, so hapi-factory's own protected paths, its CI's mise-file scan and its tests never read a template as a live file; .factory/template.lock in the new repo records the hapi-factory commit it came from and a sha256 per contract file (changing the template). Once the registration is on main, a merged planning PR's work orders are the poller's: the engine runbook covers what it does with them, the caps, the factory PR and what to do when one fails.
These steps are outward-facing or privileged, so agents never do them; the operator does them by hand. Later tasks add their own steps here.
The order. Each step needs the ones before it:
- Your secrets store, the provider keys and the MCP keys (Tasks 4, 4b and 4c, Task 3b).
- The Slack app (step 3 of Tasks 4, 4b and 4c).
- Task 7b, the pre-publish cleanup. Agents do most of it; you approve its gated steps: the edits to protected files, the license and the history rewrite.
- Publishing, the GitHub Apps and CodeRabbit (Publishing). The rulesets need a public repo, and the Apps need the rulesets.
- The host and the stack, stage b (Task 5).
mise run uprefuses an empty secret, so the Slack and App values must be in your store first.
policy/mcp.yaml names each MCP server's secret by its logical name (secret:hapi-mcp-<name>). Add each to your secrets store under exactly this name (mise run secrets:edit, docs/secrets.md):
| Logical name | Manifest entry | What it is | Needed when |
|---|---|---|---|
hapi-mcp-context7-api-key |
research / HAPI_MCP_CONTEXT7_API_KEY (already in stack/secrets.yaml) |
A Context7 API key, on a spend-capped, search-only account (spec §10.1). Task 4's provider-keys runbook covers it. | Now: hapi secrets resolve needs every name in the manifest |
hapi-mcp-phoenix-viewer-key |
hermes / HAPI_MCP_PHOENIX_VIEWER_KEY (add it to the manifest then) |
A Phoenix API key minted by a VIEWER-role user, never an admin or member | Before you turn on the observability profile (flags.otel.enabled: true); until it's in the manifest and your store, hapi secrets resolve fails |
Each key belongs to one server only. The generated configs reference it as ${HAPI_MCP_<NAME>} (for example ${HAPI_MCP_CONTEXT7_API_KEY}), never by value. See docs/mcp.md and docs/secrets.md.
Do these in order. Each runbook gives the logical name each secret goes under in your store.
- Your secrets store (sops + age, the default):
mise run secrets:init -- --file private/secrets.enc.yaml, in a terminal (the store, its recipients file andrecovery.ageinprivate/, so they are backed up with your private repo; this machine's key stays in~/.config/sops/age/and is never copied). It shows 10 recovery words once: store them where you keep things you can't lose (a password manager, paper in a safe, or both), and type back the two it asks for. Thenmise run secrets:drillto prove the words open the store (docs/secrets.md). Later, thehapiuser and the VM each get their own key withsecrets:joinandsecrets:add-machine(keys and recovery). Bitwarden is an optional alternative (docs/secrets.md). - Provider keys: the Anthropic Console workspaces
hapi-hermes($60),hapi-factory($100) andhapi-evals($40), OpenCode Go, the OpenRouter keyhapi-jev($2/month, set as a $0.06 limit that resets daily, with ZDR enforced unless the documented Jev exception applies), and the Brave, Exa and Context7 search keys (provider keys). Add each to your store withmise run secrets:edit. - Slack: a dedicated workspace,
#hapi-intakeand#hapi-alerts, and the app's tokens (Slack). The app is created from a manifest that a one-offdocker runof the pinned Hermes image prints, with no network and no stack, so do this before the stack's stage b:mise run uprefuses an empty secret. - Check:
mise run secrets:check. Expected: every line saysfoundand it exits 0, with the recipients listed (this machine andrecovery) and no value printed. Until you have made the Slack app (step 3) and the GitHub Apps (Publishing, step 6), their values show asemptyand it exits 1 naming just those: the three Slack values (hapi-hermes-slack-bot-token,hapi-hermes-slack-app-token,hapi-hermes-slack-allowed-users) and the four App values (hapi-host-planner-app-id,hapi-host-planner-app-private-key,hapi-host-factory-app-id,hapi-host-factory-app-private-key).
Set OWNER to your GitHub login first (export OWNER=<your-login>); the commands below use it.
-
Both repos already exist, private and empty:
$OWNER/hapi-factoryand$OWNER/hapi-factory-private. Push nothing until Task 7b is done. Until its history rewrite, the history still holds the research and the personal details that Task 7b removes (H-056), and a push can't be taken back. -
Push the cleaned history, once Task 7b's checks pass. Confirm each first push yourself.
private/already holds the research in its own repo; commit your secrets store there too before its first push, so it is backed up with the repo (it is encrypted, so that's safe):git remote add origin "https://github.com/$OWNER/hapi-factory.git" git push -u origin main git push -u origin plan-01-foundations # then open a PR from it into main git -C private add secrets.enc.yaml secrets.recipients.yaml recovery.age git -C private commit -m "The secrets store, its recipients file and recovery.age" git -C private remote add origin "https://github.com/$OWNER/hapi-factory-private.git" git -C private push -u origin main
-
Make hapi-factory public; hapi-factory-private stays private. Free-plan rulesets need a public repo.
gh repo edit "$OWNER/hapi-factory" --visibility public --accept-visibility-change-consequences gh repo edit "$OWNER/hapi-factory" --description "Hermes + Archon + Pi: a reference stack for an end-to-end agentic software factory"
-
Add two rulesets on
main. Together they make the operator the only one who can merge intomain(always through a PR), require a passingcicheck for every merge, the operator's included, and block force-pushes and deletion. They are two rulesets, not one, because a ruleset's bypass list covers every rule in that ruleset. If the approval bypass and thecicheck sat in one ruleset, the bypass would also let a merge through withcired or missing. GitHub applies every ruleset that targets a branch, and a bypass in one ruleset doesn't carry over to another.main-protectholds the requiredcicheck and the force-push and deletion blocks. It has no bypass actors. Nobody, the operator included, can merge withcifailing or not yet run, force-pushmainor delete it. This is how every lane,lane:directincluded, gets the same CI gates (spec §5.1).main-reviewholds the pull-request rule (1 approving review, from a code owner) and Restrict updates. Its only bypass actor is the repository Admin role, in PR-only mode. Without that bypass, the operator couldn't merge their ownlane:directPRs, because GitHub doesn't let a PR's author approve it (spec §18). The bypass covers these two rules and nothing else;cican never be bypassed. Because the bypass is PR-only, it applies only when merging a PR. The operator still can't push straight tomain.- Restrict updates is what stops an App merging (spec §11.5: "Neither can merge"). It lets only the ruleset's bypass actors update
main, and merging a PR updatesmain. So once the operator has approved an App's PR andciis green, the App still can't merge it through the API; only the operator can, through the Admin bypass. It sits inmain-review, never inmain-protect:main-protecthas no bypass actors, so there it would stop every merge, the operator's included. The code-owner review is a second layer: with.github/CODEOWNERSnaming only the operator (GitHub Apps runbook), an App's approval doesn't count either.
The GitHub Apps get no bypass in either ruleset.
integration_id15368 is GitHub Actions, so only Actions can satisfy thecicheck. Inbypass_actors,actor_id5 is the repository Admin role.The two rulesets are files,
policy/github/rulesets/main-protect.jsonandmain-review.json. Apply each from your checkout of hapi-factory:gh api -X POST "repos/$OWNER/hapi-factory/rulesets" --input policy/github/rulesets/main-protect.json gh api -X POST "repos/$OWNER/hapi-factory/rulesets" --input policy/github/rulesets/main-review.json
hapi new-repoapplies the same files to a new repo (Plan 03 Task 5).main-review.jsonsetsrequire_last_push_approval: true(design §3.2 step 5): the last push to a PR needs an approval from someone other than the pusher. hapi-factory's ownmain-reviewkeepsfalseuntil Task 5's operator step applies the file.Check the result. Run
gh api repos/$OWNER/hapi-factory/rulesets, or open Settings → Rules → Rulesets. You should see both rulesets, andmain-protectshould list no bypass actors. To see the combined rules that apply tomain, rungh api repos/$OWNER/hapi-factory/rules/branches/main.Then open a test PR and confirm three things:
- The
cicheck runs and is required. - Merging needs the admin bypass. Because of Restrict updates, every merge into
mainis the operator's, through that bypass, even after an approval. - While
ciis still running or has failed, merging stays blocked, even with the admin bypass.
Once the GitHub Apps exist, also confirm that an App's merge call is refused, even with the operator's approval and
cigreen (GitHub Apps runbook, Check it).These commands were first run on 2026-10-27 as pasted JSON, with
require_last_push_approval: false, and GitHub accepted every field. Read back, each ruleset also holds GitHub's own defaults:do_not_enforce_on_create: falsein the status-check rule;required_reviewers: [],require_extra_approval_for_unattributed_changes: trueand all three merge methods in the pull-request rule. If GitHub ever rejects a field, set up the same two rulesets in the UI. Keep the rules split the same way: never put thecicheck in a ruleset that has a bypass actor, and never put Restrict updates in one that has none.tests/docs/rulesets.test.tsholds the files to those rules. -
CODEOWNERS: your own PR adds
.github/CODEOWNERSwith* @<your-login>, before either App is installed.main-reviewrequires a code owner's review, and with you as the only code owner, no App's approval counts (GitHub Apps runbook). -
The GitHub Apps (GitHub Apps): create
hapi-plannerandhapi-factorywith exactly their permissions, and put their IDs and keys in your store under thehostzone; then apply theagent-branch-scopeandtags-admin-onlyrulesets; only then install each App, on selected repos only. Oncehapi secrets resolvecan run (it needs the Slack values too), check that an App's merge call is refused, even with your approval andcigreen, and that an App can't push other branches or tags (Check it). -
CodeRabbit (optional), once CODEOWNERS is merged and its threat-model entry and audit checks (H-169) are on
main: install it on hapi-factory only, never on hapi-factory-private. Never tick its "Commit the changes to this branch" checkbox or run@coderabbitai autopiloton a factory or planning PR: either commits under your own GitHub sign-in, past the factory's checks. The register's H-164 has the checks to run after installing. -
Task 5's host setup clones from this remote once it's pushed:
scripts/host-setup.shdefaults to your checkout'sorigin. Until then, give it your checkout's path (Plan 01 Task 5).
Task 5 wrote the stack and proved its egress boundary on the build host's own Docker, with fake secrets (stage a). Stage b is the real host, as the operator, following docs/runbooks/stack.md. It ran on 2026-10-28, with spike T12 (spike 05); on a new host, these are the steps:
-
The Slack app and the GitHub Apps first, with their values in your store (Tasks 4, 4b and 4c, step 3; Publishing, step 6):
mise run uprefuses an empty secret. -
Host setup, once:
sudo scripts/host-setup.sh "$PWD"from your checkout (or with no argument once the GitHub remote exists; with an SSHorigin, pass its HTTPS URL, since hapi clones it with its own credentials). It creates thehapiuser, rootless Docker with lingering, a pinned mise and hapi's checkout, then prints the next steps. Check:sudo -iu hapi docker info --format '{{.SecurityOptions}}'containsrootless. -
hapi's toolchain: as
hapi,export XDG_RUNTIME_DIR=/run/user/$(id -u), thencd ~/hapi-factory && mise trust && mise install && mise run setup. -
hapi's secrets: as yourself, from your checkout,
scripts/copy-secrets-to-hapi.sh(it hands your store, its recipients file andrecovery.ageto atarrunning as hapi, which writes them into hapi's~/.config/hapi/: root never writes into hapi's home); ashapi,mise run secrets:join -- --store ~/.config/hapi/secrets.enc.yaml --name hapi; run theadd-machinecommand it prints in your checkout; runscripts/copy-secrets-to-hapi.shagain; ashapi,mise run secrets:check. -
Start and test:
- Run
mise run up. - As
hapi, runmise run test:int. It runs its own throwaway copy of the stack, with its own generated configs, so it leaves the running stack and the checkout'sbuild/alone. - Check that
docker compose -p hapi psshows the five running services healthy: the four proxies andhermes(archonis a run template, and never runs as a service).
Until the Slack and App values are in your store, and copied to hapi,
upstops at the secrets step. - Run
-
The audit, last: as
hapi, in its checkout, with the stack up,mise run audit -- --strict --repo "$OWNER/hapi-factory" --github-token-file <file>(your own GitHub token in a0600file, which the bypass-actor checks need: a fine-grained token for the one repo with Administration and Contents read-only is enough, docs/audit.md). Expected, until Plan 04 wires the live MCP fetch (H-101): every checkpassexcept one fail,mcp.tool-hashes, whose detail starts--strict: skipped:(it can't compare a running server's tool surface yet), so21 pass, 1 fail, 0 skipand exit 1; any other fail is real. After H-101: exit 0,0 fail(docs/audit.md, the stack runbook).
| Document | What's in it |
|---|---|
| Design spec | Intent, architecture, policy, security, phases. It is the binding authority. |
| The audit | hapi audit / mise run audit: each check, what it verifies and why, its credential, how to fix a failure, what a skip means, --strict and --dev |
| Policy | Each policy file and its schema (the MCP catalog mcp.yaml and its lockfile included), how Hermes's command rules match (and what the Plan 04 hook must do first), the tighten-only overlay rule with examples, the work-order format, hapi workorder validate, and hapi mcp verify and hapi mcp pin |
| Generated configs | Each file hapi policy build writes under build/, its policy sources, every hardening setting and why, how protected paths stay strictest-wins, and how to regenerate |
| Secrets | Manifest, config and store; the zones and their keys; sops + age onboarding and adding a secret; keys and recovery: per-machine keys, the 10 recovery words, post-quantum keys, join, add-machine, recover, drill, revoke and new-recovery, with a worked example; hapi secrets init, edit, check and resolve and the env files; rotating a secret or replacing a machine's key; optional bws; the env-file downgrade; hapi token mint; the "keys, never values" rule; threat notes |
| Threat model | v0, with CSA MAESTRO: the system and its trust boundaries, the Rule of Two per stage, threats per layer with OWASP ASI, LLM and MCP Top 10 and MITRE ATLAS IDs, cross-layer chains, every control by SANS domain with its status, spec §11.9's six residual risks and the other accepted residuals, each with an owner control and a next level; how to update it |
| Runbook: the stack | What runs where, host setup (scripts/host-setup.sh), the hapi user's toolchain and secrets (join, add-machine, re-syncing), mise run up and down, the dev bypass, the pinned images and their digests, the hardening and its exceptions, troubleshooting, and what each test proves |
| Runbook: the run engine | What the engine does with a merged work order: the poller and its timer, the pipeline's phases, the acceptance tests and the verify container, the harvester and its host gates, the factory PR and its verdicts, the decisions, the status comment, hapi status and events.jsonl, the caps, hapi retry, stopping everything, and troubleshooting |
| Runbook: runs | hapi run start, watch, list and stop as hapi, the container's layout, the outputs and where they live, retention, the public flag, the rollout on hapi's checkout, the integration tests, and troubleshooting |
| Runbook: kill switches | Spec §11.8's four kill switches, fastest first: disable the provider keys, suspend the GitHub Apps, stop the stack (with a fallback that needs no checkout or mise, and a hard stop), firewall-drop the hapi user; for each, what it stops and doesn't, how to confirm and undo it, and how fast it works |
Runbook: hapi new-repo |
Making a new repo from the contract with your own gh login: what to set up first, the flags, the eleven steps and each one's undo, the contract's files and the gates (ci / gates), verifying it, deleting a sandbox, changing the template, and Plan 03's operator steps |
| Runbook: GitHub Apps | Creating hapi-planner and hapi-factory with exact permissions, the rulesets (both on main, Restrict updates so no App can merge, code owners, branch and tag scope), checks (including that an App's merge call is refused), suspending an installation, rotating a key |
| Runbook: provider keys | The Console workspaces and their limits, OpenCode Go settings, the OpenRouter keys (daily-reset limits, ZDR guardrails, the Jev exception if it has no ZDR endpoint), the Brave, Exa and Context7 search keys, and where each goes |
| Runbook: Slack | The workspace and channels, creating the app from Hermes's manifest, the three Slack secrets, Hermes's Slack settings |
| MCP servers | Which zone gets which MCP server and why, how to add or upgrade one (a planning PR plus a re-pin), the release cooldown and its security-fix exception, advisory floors, the tool-description lock and the CI scanners |
| Plan 01: Foundations | Tasks 1–14: toolchain, policy, generators, secrets, stack, audit, threat model, spikes |
| Research | What the research behind the design covered, and the conclusions the spec adopted, by section (the sources are private) |
| Spikes | The notes of Plan 01's verify-early spikes, Tasks 8–13 (Task 14 is on hold, H-177): Pi under Archon, Hermes's path guard, Archon's budget, trigger and env, Anthropic's history check and billing, the images under rootless Docker, Hermes's Slack gateway; Plan 02's spikes: the run container and the guard's hooks, offline |
MIT.