Skip to content

Commit 93ae8c0

Browse files
roodboiclaude
andcommitted
docs: full accuracy pass against the v3 surface
Audit-driven rewrite of 27 files: docs-ia and cli.md rebuilt (cli.md defers exhaustive flags to the generated reference), 7 architecture stale claims fixed, env/sessions/lifecycle corrected (secret-key inheritance order, tmux-only daemon sessions, envelope error codes), experimental banner standardized across all remote/gateway docs, tickets reframed as opt-in. Every relative link and documented command verified against the generated CLI reference. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent e9e013e commit 93ae8c0

29 files changed

Lines changed: 653 additions & 139 deletions

.claude/skills/hack-init/SKILL.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
name: hack-init
3+
description: >
4+
Stand up or adopt hack in a project (agent-assisted onboarding).
5+
Trigger when asked to set a repo up with hack, migrate a project onto
6+
hack, or finish/repair a partial hack setup.
7+
---
8+
9+
# hack init (agent-assisted onboarding)
10+
11+
The full onboarding prompt is generated by the hack CLI — do not improvise the steps.
12+
13+
1. Fetch the canonical onboarding prompt:
14+
- With shell access: run `hack agent onboard` (works for new and existing projects).
15+
- Without shell access: fetch the `hack-init` MCP prompt from the hack MCP server.
16+
2. Follow the printed prompt phase by phase (inventory, setup, platform nuances, running things, verification).
17+
3. Finish only when `hack doctor` is clean and every routable service responds.

.codex/skills/hack-init/SKILL.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
name: hack-init
3+
description: >
4+
Stand up or adopt hack in a project (agent-assisted onboarding).
5+
Trigger when asked to set a repo up with hack, migrate a project onto
6+
hack, or finish/repair a partial hack setup.
7+
---
8+
9+
# hack init (agent-assisted onboarding)
10+
11+
The full onboarding prompt is generated by the hack CLI — do not improvise the steps.
12+
13+
1. Fetch the canonical onboarding prompt:
14+
- With shell access: run `hack agent onboard` (works for new and existing projects).
15+
- Without shell access: fetch the `hack-init` MCP prompt from the hack MCP server.
16+
2. Follow the printed prompt phase by phase (inventory, setup, platform nuances, running things, verification).
17+
3. Finish only when `hack doctor` is clean and every routable service responds.

README.md

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,15 @@ supporting services at the same time.
1919
- Open stable local HTTPS URLs like `https://myapp.hack` with `hack open`.
2020
- Route service subdomains through local Caddy and trusted development TLS.
2121
- Resolve env overlays and secrets from `.hack/` and inject them into compose, host commands, and sessions.
22+
- In a linked git worktree, `hack up` defaults to a branch instance named after the worktree's git
23+
branch (opt out with `worktree.auto_branch=false`, or target one explicitly with `--branch <name>`).
2224
- Keep tmux-backed project workspaces alive with `hack session`.
23-
- Diagnose Docker, DNS, TLS, env, lifecycle, and stale runtime state with `hack doctor`.
24-
- Track optional repo-local work with `hack tickets`.
25+
- Diagnose Docker, DNS, TLS, env, lifecycle, and stale runtime state with `hack doctor` /
26+
`hack doctor --fix`.
27+
- Script and automate against a stable surface: `--no-interactive` (or `HACK_NO_INTERACTIVE=1`)
28+
never prompts, and `up`/`down`/`restart`/`doctor --json` emit a `{ok, data | error: {code,
29+
message}}` envelope; `NO_COLOR` disables ANSI output.
30+
- Track optional repo-local work with the opt-in `hack tickets` extension.
2531
- Use a slim macOS companion for local project status, controls, logs, and quick actions.
2632

2733
Hack v3 is intentionally self-contained. The supported product is the local CLI/runtime and macOS
@@ -68,6 +74,9 @@ cd /path/to/project
6874
hack init
6975
```
7076

77+
Prefer an agent to drive setup? `hack init --with claude|codex|both` hands the onboarding prompt to
78+
an agent CLI for a new repo; `hack agent onboard` does the same for an existing project.
79+
7180
Run it:
7281

7382
```bash
@@ -100,8 +109,12 @@ hack logs --pretty
100109
hack logs <service>
101110
hack exec <service> -- bun test
102111
hack run <service> -- bun db:migrate
112+
hack projects prune
103113
```
104114

115+
`hack projects prune` removes stale entries from the local project registry and stops orphaned
116+
containers.
117+
105118
Host-side commands can use the same resolved project env:
106119

107120
```bash
@@ -117,9 +130,11 @@ hack session start <project>
117130
hack session exec <workspace> "bun test"
118131
```
119132

120-
Optional repo-local tickets:
133+
Optional repo-local tickets (opt-in extension, not part of default agent instructions — `hack tickets
134+
setup` is the one subcommand that bypasses the enable check and auto-enables the extension):
121135

122136
```bash
137+
hack tickets setup
123138
hack tickets create --title "Fix lifecycle cleanup"
124139
hack tickets list
125140
hack tickets show T-00001
@@ -137,7 +152,10 @@ Hack uses YAML env files in `.hack/` as the source of truth:
137152
.hack/hack.env.<overlay>.local.yaml
138153
```
139154

140-
Shared files can be committed. `*.local.yaml` files are worktree-local overrides.
155+
Shared files can be committed. `*.local.yaml` files are worktree-local overrides. Hack owns a
156+
committed `.hack/.gitignore` that keeps machine-local generated files (`.internal/`, `.branch/`,
157+
`.env`, `.env.state.json`, `hack.env*.local.yaml`) out of git; it self-heals on `init`/`up`, and if
158+
generated files ever leak into git, `hack doctor --fix` untracks them (files stay on disk).
141159

142160
Runtime commands read the YAML model directly. Use `hack env materialize` only when an external tool
143161
needs a compatibility `.hack/.env` file on disk.
@@ -146,7 +164,8 @@ Secret key lookup is local-first:
146164

147165
1. current checkout `.hack.secret.key`
148166
2. shared key under the git common dir for linked worktrees
149-
3. `HACK_ENV_SECRET_KEY`
167+
3. key inherited from the primary checkout's `.hack.secret.key` (linked worktrees)
168+
4. `HACK_ENV_SECRET_KEY`
150169

151170
Use `HACK_ENV_SECRET_KEY` in CI and managed containers instead of copying `.hack.secret.key` into an
152171
image.
@@ -182,7 +201,9 @@ Use `hackdance/hack:slim` as a smaller base for Codex, CI, or managed containers
182201
`hack`, Bun, env resolution, sessions, and tickets without the full host stack.
183202

184203
For reproducible remote or managed environments, install project dependencies normally, install Hack,
185-
and pass `HACK_ENV_SECRET_KEY` at runtime so encrypted project env can be resolved.
204+
and pass `HACK_ENV_SECRET_KEY` at runtime so encrypted project env can be resolved. Set `HACK_HOME`
205+
alongside it when you also want to redirect global state (registry, daemon, secrets) to an isolated
206+
root instead of `~/.hack`.
186207

187208
Start with [Codex managed environments](./docs/guides/codex-managed-environments.md) for a concrete
188209
setup guide.

docs/README.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@ The docs are split into three areas so the default path stays on core local work
1010

1111
Use this path for the main product story:
1212

13-
- local project setup
14-
- isolated runtime orchestration
13+
- local project setup (including agent-assisted onboarding via `hack init --with` / `hack agent onboard` — see the [agent-first setup guide](guides/agent-first-setup.md))
14+
- isolated runtime orchestration (including branch instances and linked worktrees)
1515
- stable local hostnames
1616
- env and secret management
1717
- lifecycle hooks
1818
- persistent sessions
19+
- diagnostics (`hack doctor` / `hack doctor --fix`)
1920

2021
Start here if you want to understand and use `hack` without remote or beta complexity by default.
2122

@@ -35,7 +36,7 @@ out of the default path.
3536

3637
Use this path for:
3738

38-
- full command reference
39+
- full command reference: [CLI overview](cli.md) plus the generated [CLI reference](reference/cli.md) (every command and flag)
3940
- extension configuration and authoring
4041
- tickets and integrations
4142
- gateway API and SDK details
@@ -45,14 +46,17 @@ This section is easy to find, but it does not lead the product story.
4546
## Quick links
4647

4748
- New to `hack`: [Core docs](core.md)
49+
- Setting up with a coding agent: [Agent-first setup](guides/agent-first-setup.md)
50+
- Looking for command or API details: [Extensions & reference](reference.md), including the generated [CLI reference](reference/cli.md)
4851
- Need unsupported experimental remote workflows: [Beta workflows](beta.md)
49-
- Looking for command or API details: [Extensions & reference](reference.md)
5052
- Need the bucket definitions: [Docs information architecture](docs-ia.md)
5153

5254
## Repo notes
5355

54-
- Specs remain in `SPECS/` as working notes
56+
- Working notes and historical design docs live in `docs/plans/`; they are not the supported product contract
5557
- Root scripts orchestrate workspace tasks through Turbo
5658
- Package-local commands remain available via `bun run --cwd <workspace> <script>`
57-
- Agent-facing docs and setup output are generated from `src/agents/*` and `src/mcp/agent-docs.ts`; update those renderers when changing AGENTS/Codex/MCP guidance.
59+
- Agent-facing docs and setup output are generated from `src/agents/instruction-source.ts` via `src/agents/*` and `src/mcp/agent-docs.ts`; update the canonical source (not the rendered surfaces) when changing AGENTS/Codex/MCP guidance.
60+
- The generated [CLI reference](reference/cli.md) is rendered from the command spec (`bun run docs:cli-reference`); a drift test fails when it is stale.
61+
- End-to-end coverage that backs docs claims lives in `tests/e2e/` (`bun run test:e2e:local`).
5862
- `.factory/validation/` contains historical evidence from retired hosted/web/integration work and is not the current product contract.

docs/architecture.md

Lines changed: 48 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
## System overview
22

33
`hack` is a Bun CLI that writes per-project Compose files under `.hack/` and manages a machine-wide
4-
proxy, DNS helpers, and logging stack under `~/.hack/`.
4+
proxy, DNS helpers, and logging stack under `~/.hack/` (overridable via the `HACK_HOME` env var,
5+
which redirects all global state — registry, daemon, secrets — to another root).
56

67
- **Caddy** (docker-proxy) routes `*.hack` based on container labels.
78
- **CoreDNS** resolves `*.hack` inside containers to the Caddy IP, with `extra_hosts` mappings for resolver compatibility.
@@ -65,8 +66,11 @@ graph LR
6566
- `controlPlane.gateway.enabled` marks the project as gateway-capable
6667
- Optional overrides:
6768
- `.internal/compose.override.yml` (generated internal DNS/TLS injection)
68-
- `.internal/extra-hosts.json` (user-managed extra_hosts merged into the override)
69+
- `.internal/extra-hosts.json` — CLI-managed, not hand-edited (use
70+
`hack internal extra-hosts set/unset/list`)
6971
- `.branch/compose.<branch>.override.yml` (branch builds)
72+
- Everything under `.hack/.internal` is a hack-managed artifact; do not hand-edit generated files
73+
there.
7074

7175

7276
## Internal DNS + TLS (containers)
@@ -96,7 +100,9 @@ Projects can declare shareable env overlays and safely inject secrets into compo
96100

97101
- Canonical env: `.hack/hack.env.default.yaml` plus optional `.hack/hack.env.<overlay>.yaml`
98102
- Compatibility output: `.hack/.env` only when explicitly materialized
99-
- Secret key: `.hack.secret.key` locally, or `HACK_ENV_SECRET_KEY` in CI/managed environments
103+
- Secret key: checkout-local `.hack.secret.key`, or — in a linked git worktree — inherited
104+
automatically from the primary checkout through the shared git common dir; `HACK_ENV_SECRET_KEY`
105+
covers CI/detached environments. `hack doctor` flags divergent keys across checkouts.
100106

101107
At runtime, hack resolves the selected overlay and injects the effective env directly into compose and
102108
host-side command flows. For service-scoped values, hack still generates
@@ -152,7 +158,8 @@ sequenceDiagram
152158
- **compose**: fast, direct `docker compose logs`
153159
- **loki**: searchable history + LogQL filters
154160

155-
NDJSON streaming (`hack logs --json`) emits `start`, `log`, and `end` events for MCP/TUI consumers.
161+
NDJSON streaming (`hack logs --json`) emits `start`, `log`, `error`, and `end` events for MCP/TUI
162+
consumers.
156163

157164
Retention:
158165
- Loki retention is set in the global Loki config (`~/.hack/logging/loki.yaml`), default `168h` in the template.
@@ -208,33 +215,36 @@ graph LR
208215
The control plane keeps the core CLI minimal while adding features as extensions. `hackd` loads
209216
extension manifests and exposes their APIs; the CLI dispatches extension commands via `hack x`.
210217

211-
- **Gateway**: optional HTTP/WS access to `hackd` (localhost by default).
212-
- **Supervisor**: job execution + streaming for agents.
218+
Builtin extensions: **Tickets** (opt-in local ticket store — disabled by default, requires enabling
219+
before use), **Supervisor** (job execution + streaming for agents), **Gateway** (optional HTTP/WS
220+
access to `hackd`), **Cloudflare**, and **Tailscale** (exposure/tunnel helpers).
221+
222+
> Gateway, remote, node, and dispatch surfaces are experimental and unsupported. They are hidden
223+
> from default `hack help` (use `hack help --all` to see them) and print a warning when invoked.
224+
> See [Beta workflows](beta.md) and [Gateway API](gateway-api.md) for details — this doc only
225+
> summarizes where they fit in the system.
213226
214227
```mermaid
215228
graph LR
216229
CLI["hack CLI"] --> Hackd["hackd"]
217230
Hackd --> ExtMgr["ExtensionManager"]
218231
ExtMgr --> Gateway["Gateway"]
219232
ExtMgr --> Supervisor["Supervisor"]
220-
ExtMgr --> Tickets["Tickets"]
233+
ExtMgr --> Tickets["Tickets (opt-in)"]
234+
ExtMgr --> Cloudflare["Cloudflare"]
235+
ExtMgr --> Tailscale["Tailscale"]
221236
Remote["Remote client"] -->|HTTP/WS| Gateway
222237
Gateway --> Hackd
223238
```
224239

225-
### Gateway API + remote workflows
240+
### Gateway API + remote workflows (unsupported experimental)
226241

227-
The gateway exposes:
242+
Summary only — see `gateway-api.md` for full usage, security posture, and end-to-end examples:
228243
- `GET /v1/projects` with `project_id` for remote workflow routing
229244
- job execution + streaming (`/control-plane/projects/:id/jobs`)
230245
- PTY-backed shells (`/control-plane/projects/:id/shells`, WS stream)
231-
232-
Current gateway routing:
233-
- One gateway instance is active per machine (global config).
234-
- Projects opt in with `controlPlane.gateway.enabled` in their project config.
235-
- Remote clients route by `project_id` in the API paths.
236-
237-
For full usage, security posture, and end-to-end examples, see `gateway-api.md`.
246+
- One gateway instance is active per machine (global config); projects opt in with
247+
`controlPlane.gateway.enabled`; remote clients route by `project_id` in the API paths.
238248

239249
## Branch builds
240250

@@ -245,9 +255,18 @@ For full usage, security posture, and end-to-end examples, see `gateway-api.md`.
245255

246256
This enables parallel worktrees without port or hostname collisions.
247257

258+
In a linked git worktree, `hack up` defaults to a branch instance named after the worktree's git
259+
branch instead of requiring an explicit `--branch` — opt out with config `worktree.auto_branch=false`
260+
or pass an explicit `--branch`. The secret key for a linked worktree is inherited automatically from
261+
the primary checkout through the shared git common dir (see "Project env + secrets" above), and
262+
`hack doctor` checks for divergent secret keys and `dev_host` collisions across checkouts sharing the
263+
same repo.
264+
248265
## Files and directories
249266

250-
- `~/.hack/`
267+
- `~/.hack/` (default; override the whole root with `HACK_HOME`)
268+
- `hack.config.json` (global config: control-plane defaults, gateway bind/port/allowWrites,
269+
extension settings)
251270
- `daemon/hackd.sock`
252271
- `daemon/hackd.pid`
253272
- `daemon/hackd.log`
@@ -260,13 +279,24 @@ This enables parallel worktrees without port or hostname collisions.
260279
- `schemas/hack.config.schema.json`
261280
- `schemas/hack.branches.schema.json`
262281
- `certs/` (mkcert output for non-Caddy services)
263-
- `projects.json` (best-effort registry)
282+
- `projects.json` (best-effort registry; `hack projects prune` removes stale entries and stops
283+
orphaned containers)
264284

265285
- `<repo>/.hack/`
266286
- `docker-compose.yml`
267287
- `hack.config.json`
268288
- `hack.branches.json` (optional)
289+
- `.gitignore` (committed, self-healing on `init`/`up`; covers machine-local generated files —
290+
`.internal/`, `.branch/`, `.env`, `.env.state.json`, `hack.env*.local.yaml`. If generated files
291+
leaked into git, `hack doctor --fix` untracks them without deleting them from disk.)
292+
- `hack.env.default.yaml` plus optional `hack.env.<overlay>.yaml` (committed env)
293+
- `hack.env.local.yaml` / `hack.env.<overlay>.local.yaml` (worktree-local overrides)
294+
- `.env.state.json`
295+
- `.env` (optional, only when explicitly materialized)
269296
- `.internal/compose.override.yml`
297+
- `.internal/compose.env.override.yml`
298+
- `.internal/extra-hosts.json`
299+
- `.internal/lifecycle/state.json` and `.internal/lifecycle/*.log`
270300
- `.branch/compose.<branch>.override.yml`
271301

272302
## Key design choices

docs/beta.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Beta Workflows
22

3+
> **Status: unsupported experimental.** These surfaces are source-available but outside the supported v3 product contract. They are hidden from default `hack --help` (see `hack help --all`) and print a warning when invoked.
4+
35
This section holds unsupported experimental remote workflows.
46

57
Start in [Core docs](core.md) first if you are new to `hack`. Beta workflows build on the core

0 commit comments

Comments
 (0)