Skip to content

Commit d32e743

Browse files
roodboiclaude
andcommitted
docs: plan for worktree DX + agent experience overhaul
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent 7da1cc2 commit d32e743

1 file changed

Lines changed: 129 additions & 0 deletions

File tree

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
# Worktree DX + Agent Experience (AX) Overhaul — Plan
2+
3+
Date: 2026-07-07
4+
Branch: `feat/worktree-ax-overhaul`
5+
Status: in progress
6+
7+
## Goal
8+
9+
Make hack excellent for agent-driven development: worktree workflows that just work
10+
(secret key, branch instances, doctor checks), a single source of truth for agent
11+
instructions with drift enforcement, a machine-readable CLI surface (JSON envelope,
12+
error codes, non-interactive), agent-assisted onboarding (`hack init --with claude|codex`),
13+
and phase-out of tickets from default instructions.
14+
15+
## Acceptance criteria
16+
17+
- All agent instruction surfaces (AGENTS.md/CLAUDE.md snippet, codex skill, cursor rules,
18+
primer) render from one structured source; a test fails if any surface drifts or if a
19+
documented command doesn't exist in `CLI_SPEC`.
20+
- `hack setup sync --check` detects STALE content (not just marker presence).
21+
- In a linked worktree: secrets decrypt using the primary/shared key with zero setup;
22+
hack never silently mints a divergent key; `hack doctor` flags divergent keys and
23+
cross-checkout dev_host collisions.
24+
- `hack up` in a linked worktree defaults to a branch instance named for the worktree
25+
branch (opt-out via config/flag) so two checkouts never fight over hostnames.
26+
- `hack up/down/restart/doctor --json` emit `{ok, data?, error?: {code, message}}`;
27+
errors carry stable codes (e.g. E_DOCKER_UNAVAILABLE, E_CONFIG_PARSE).
28+
- Prompting commands honor `--no-interactive` (and detect non-TTY) with sane defaults
29+
or structured failure; `hack init` fully scriptable via flags.
30+
- Experimental commands (node/dispatch/gateway/remote) are marked in the spec, hidden
31+
from default help, and warn on use.
32+
- `hack init --with claude|codex` generates a detailed project-onboarding prompt
33+
(inventory, deps-container pattern, ops container, exec/env guidance) and hands off
34+
to the agent CLI.
35+
- Tickets no longer appear in default agent instructions; extension still works.
36+
- Tests never touch the real `~/.hack` (HACK_HOME-style isolation) and full suite,
37+
lint (`bun x ultracite check`), and build pass.
38+
39+
## Verified findings driving this plan
40+
41+
- Secret key resolution already has a worktree chain: local → shared (git common dir) →
42+
inherited from primary → `HACK_ENV_SECRET_KEY` (`src/lib/project-env-config.ts:1373-1411`).
43+
BUT `resolveProjectEnvSharedKeyPath` returns null when the shared FILE doesn't exist, so
44+
the write path (`ensureProjectEnvSecretKey`, :1413) can mint a fresh checkout-local key in
45+
a worktree → divergent keys.
46+
- Registry dedupes worktrees by `git rev-parse --git-common-dir` family identity
47+
(`src/lib/projects-registry.ts:486`), migrates registration if primary path dies. Good.
48+
No tracking of sibling checkouts; no runtime collision protection (two checkouts, same
49+
dev_host → caddy routes to last-up).
50+
- `checkAgentDocs` (`src/mcp/agent-docs.ts:89`) only checks marker PRESENCE, never content
51+
equality with the current render — auto-sync never detects stale content. Repo's own
52+
CLAUDE.md contains pre-v3 text (`hack env exec`, tickets mandate, remote-as-normal).
53+
- Four hand-maintained instruction renderers: `agents/codex-skill.ts`, `agents/cursor.ts`,
54+
`agents/primer.ts`, `mcp/agent-docs.ts` (~850 LOC overlapping prose).
55+
- No `--json` on up/down/restart/doctor/init; no error envelope; 73 interactive prompt
56+
sites without a `--no-interactive` convention; experimental commands sit unmarked in
57+
`src/cli/spec.ts`.
58+
- `projects-registry.ts`/`config-paths.ts` have no HACK_HOME-style override → tests
59+
pollute the real `~/.hack/projects.json` (observed stale `/private/tmp/hack-project-*`
60+
entries on this machine).
61+
62+
## Phases
63+
64+
### Phase 1 — Instruction single source + drift enforcement (keystone)
65+
- New `src/agents/instruction-source.ts`: structured sections (id, title, bullets,
66+
audience tags: full|primer|rules). All four renderers consume it; surface-specific
67+
framing (frontmatter, headers) stays in each renderer.
68+
- Content updates while consolidating: drop tickets from default sections (one optional
69+
pointer max), keep experimental warning prominent, add linked-worktree section
70+
(key inheritance, branch instances per worktree), keep host exec/--scope semantics.
71+
- Fix `checkAgentDocs` to compare rendered snippet vs on-disk marker content (report
72+
`stale` status); `setup sync --check` surfaces stale; auto-sync repairs stale.
73+
- Drift tests: every `hack <cmd>` mentioned in rendered surfaces exists in CLI_SPEC;
74+
banned stale patterns (`hack env exec`, `--service` on host exec, tickets-in-default);
75+
all surfaces share the canonical section content.
76+
77+
### Phase 2 — Worktree DX
78+
- Write-path key fix: new resolveProjectEnvSharedKeyLocation (location even when file
79+
absent); `ensureProjectEnvSecretKey` in a linked worktree writes to shared location or
80+
adopts primary's key; never silently create a divergent checkout-local key (loud warning
81+
+ explicit override only).
82+
- `hack up` in a linked worktree with no `--branch`: default to sanitized worktree branch
83+
name as branch instance; notice logged; opt-out `worktree.auto_branch=false` in config
84+
or `--branch main-instance` explicit. `open/logs/down` resolve the same default.
85+
- `hack doctor`: divergent-key check across `git worktree list` checkouts; duplicate
86+
dev_host detection across running compose projects of the same family.
87+
- Registry: record sibling checkouts (worktrees array on the entry); show in
88+
`hack projects --details`.
89+
- Tests: worktree-first key creation, degraded git detection, up-in-worktree defaulting,
90+
doctor checks (fixture repos with worktrees).
91+
92+
### Phase 3 — AX CLI surface
93+
- `src/lib/cli-result.ts`: envelope helpers + `HackErrorCode` union; wire into
94+
up/down/restart/doctor `--json`.
95+
- `--no-interactive` global convention (flag + `HACK_NO_INTERACTIVE` + non-TTY detect)
96+
via a `canPrompt()` helper; apply to init/global/setup/env prompt sites.
97+
- Spec: `experimental: true` on node/dispatch/gateway/remote; default help hides them
98+
behind an "experimental (unsupported)" one-liner; runtime warning banner on use.
99+
- Respect `NO_COLOR` in gum/logger/help.
100+
101+
### Phase 4 — Agent-assisted onboarding
102+
- `hack init --with claude|codex|both` (and `hack agent onboard` for existing projects):
103+
render a detailed setup prompt: inventory steps (services, ports, dbs, package manager),
104+
which hack features to use, deps-container pattern (named node_modules volume so
105+
macOS-host installs never leak into linux containers), ops/tooling container pattern,
106+
`hack run` vs `exec` vs `host exec` vs env overlays guidance, verification loop
107+
(up → open --json → logs). Launch agent CLI if present, else print prompt.
108+
- `docs/guides/agent-first-setup.md` + surface via `hack agent patterns` and the
109+
instruction source (Phase 1 section).
110+
111+
### Phase 5 — Tickets phase-out + cleanup
112+
- Docs: tickets marked optional/legacy; removed from README quickstart and repo CLAUDE.md;
113+
`hack setup tickets` prints a deprecation-leaning note. Commands keep working.
114+
- HACK_HOME-style isolation for global paths (`config-paths.ts`); tests use it; prune
115+
command or doctor fix for dead registry paths.
116+
- planet-animations data out of src/ (or lazy import); deprecation TODOs on legacy .env
117+
migration; refresh repo CLAUDE.md/AGENTS.md via new sync.
118+
119+
### Phase 6 — Verification
120+
- Full `bun test`, `bun x ultracite check`, build, `hack setup sync --all-scopes --check`.
121+
- Live smoke: temp repo + linked worktree → init, env add --secret, up --detach in both,
122+
open --json, doctor, down. Document verified vs assumed in the PR description.
123+
124+
## Execution notes
125+
126+
- Phases 1 and 2 run in parallel (disjoint files). 3 → 4 → 5 sequential (shared files:
127+
project.ts, instruction source). Phase 6 gates the whole branch.
128+
- Every phase lands with tests in the same change; run targeted tests during phases,
129+
full gates at 6.

0 commit comments

Comments
 (0)