Skip to content

Commit 498e9c3

Browse files
authored
fix: harden runtime integrity and diagnostics
Addresses linked-worktree env inheritance, lifecycle ownership and timeout recovery, dependency preflight/cache behavior, targeted service operations, Doctor diagnostics, generated-agent freshness, and deprecated Tickets guidance.
1 parent ff866ba commit 498e9c3

76 files changed

Lines changed: 4894 additions & 870 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

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

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@ description: >
1010

1111
Use `hack` as the primary interface for local-first development.
1212

13+
## Integration freshness
14+
15+
- These instructions were generated by hack CLI v3.3.5; treat cached rules from another version as potentially stale.
16+
- At session start, audit project and global integrations with `hack setup sync --all-scopes --check`.
17+
- If anything is stale, missing, or deprecated, run `hack setup sync --all-scopes`, then reload the agent session so cached instructions are replaced.
18+
- Never copy or hand-edit generated Hack rules to refresh them; update the CLI and run the sync command.
19+
- Content revision: `b8663fad3ef4` (version alone is not a freshness guarantee).
20+
1321
## Product boundary
1422

1523
- Supported v3 surface: project init, up/down/restart, open, logs, env, host exec/shell, sessions, doctor, and daemon.
@@ -65,12 +73,13 @@ Use `hack` as the primary interface for local-first development.
6573
- Generated (do not hand-edit): `.hack/.internal/compose.override.yml`, `.hack/.internal/compose.env.override.yml`, `.hack/.branch/compose.<branch>.override.yml`.
6674
- Managed via CLI: `.hack/.internal/extra-hosts.json` (use `hack internal extra-hosts ...` commands).
6775
- Lifecycle runtime files: `.hack/.internal/lifecycle/state.json`, `.hack/.internal/lifecycle/*.log`.
68-
- Ignore rules: hack owns a committed `.hack/.gitignore` (self-healing on init/up) covering machine-local generated files (`.internal/`, `.branch/`, `.env`, `.env.state.json`, `hack.env*.local.yaml`, `tickets/`); keep it committed, and if generated files leaked into git, `hack doctor --fix` untracks them (files stay on disk).
76+
- Ignore rules: hack owns a committed `.hack/.gitignore` (self-healing on init/up) covering machine-local generated files (`.internal/`, `.branch/`, `.env`, `.env.state.json`, `hack.env*.local.yaml`); keep it committed, and if generated files leaked into git, `hack doctor --fix` untracks them (files stay on disk).
6977

7078
## Linked git worktrees
7179

7280
- Secret key inherits from the primary checkout automatically through the shared git common dir; set `HACK_ENV_SECRET_KEY` for CI or detached environments.
7381
- `hack up` in a linked worktree defaults to a branch instance named after the worktree's git branch; a detached linked worktree requires an explicit `--branch`, unless config `worktree.auto_branch=false` explicitly opts into the base instance.
82+
- Before `hack up` or `hack restart` auto-targets a new branch instance, Hack warns when the same worktree already owns a non-terminal instance; pass `--branch <name>` to make the target explicit.
7483
- `hack doctor` flags divergent secret keys and dev_host collisions across checkouts.
7584

7685
## Advanced networking (extra_hosts + local proxies/tunnels)
@@ -110,11 +119,17 @@ Use `hack` as the primary interface for local-first development.
110119

111120
- Put host setup in `.hack/hack.config.json` under `startup`/`lifecycle` (not ad-hoc terminal tabs).
112121
- Use `lifecycle.up.before` for pre-start hooks and `lifecycle.processes` for long-running host tasks.
122+
- Lifecycle hooks and processes receive the selected overlay's `global` values plus `host` overrides; service-scoped values remain container-specific unless a host command explicitly selects that scope.
113123
- For fixed-port host helpers such as SSM tunnels or local proxies, set `singleton.ports` and usually `onConflict: "adopt"` so Hack reuses a healthy existing listener instead of starting duplicate tunnel stacks.
114124
- `singleton` is a listener guard, not process ownership transfer; adopted external processes are left running on `hack down`.
115125
- Inspect lifecycle status via `hack projects --details` and stream via `hack logs <service-or-process>`.
116126
- Lifecycle session recovery is ownership-proven: Hack adopts healthy token-, definition-, and environment-matched sessions, replaces owned stale sessions, and refuses to kill same-name sessions without deterministic ownership proof.
117127
- `hack doctor --fix` reaps an orphan lifecycle session only when mux ownership is proven and its Compose instance is absent; unverified same-name sessions are never modified.
128+
- After `hack up` or `hack restart`, running services and successful one-shot services (`exited` with code 0) count as successful; other states return `E_STARTUP_INCOMPLETE`, and `hack doctor` warns about containers stuck in `Created`.
129+
- Detached startup is bounded; a hung Compose operation returns `E_STARTUP_TIMEOUT`, terminates its process group, and `hack doctor --fix` can start exact containers left in `Created`.
130+
- Target only affected services with `hack up <service...> --detach`, `hack restart <service...>`, or `hack env apply --service <service>`; scoped operations skip project lifecycle hooks and implicit dependency startup.
131+
- Use `hack env explain <KEY> --env <overlay> --service <service> --target <host|compose>` for redacted source, precedence, availability, and delivery diagnostics.
132+
- Dependency installer services are detected generically by command or `hack.dependencies.bootstrap=true`; registry env references are preflighted before container mutation. Optional `hack.dependencies.cache-volume`, `hack.dependencies.lockfiles`, and `hack.dependencies.runtime-files` labels enable lockfile/runtime-keyed volumes shared across compatible worktrees.
118133

119134
## Workspaces (mux-managed, tmux-first by default)
120135

@@ -171,7 +186,8 @@ Use `hack` as the primary interface for local-first development.
171186

172187
## Agent integration maintenance
173188

174-
- Project-level hack commands auto-check integration drift and attempt auto-sync (docs/skills/MCP).
189+
- Project-level hack commands auto-check integration drift and attempt auto-sync (project docs, client skills/rules, shared global skills, and MCP).
190+
- When drift is detected, Hack reports it before repair and tells the agent to reload after repair; it never silently leaves the session using cached rules.
175191
- Set `HACK_SETUP_SYNC_MODE=warn` to only warn, or `HACK_SETUP_SYNC_MODE=off` to disable.
176192
- Refresh project + user integrations: `hack setup sync --all-scopes`
177193
- Audit integration state only: `hack setup sync --all-scopes --check`
@@ -190,7 +206,3 @@ Use `hack` as the primary interface for local-first development.
190206
- Init patterns: `hack agent patterns`
191207
- MCP (no-shell only): `hack setup mcp`
192208
- MCP install (explicit): `hack mcp install --all --scope project`
193-
194-
## Optional extensions
195-
196-
- A local git-backed tickets extension exists (`hack tickets`) — only use it when the project explicitly uses it.

.cursor/rules/hack.mdc

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@
55
Hack v3 is local-first. This project uses `hack` for local runtime orchestration (compose + DNS/TLS + logs + sessions).
66
Prefer `hack` when shell access is available. Use MCP only when shell access is unavailable.
77

8+
## Integration freshness
9+
10+
- These instructions were generated by hack CLI v3.3.5; treat cached rules from another version as potentially stale.
11+
- At session start, audit project and global integrations with `hack setup sync --all-scopes --check`.
12+
- If anything is stale, missing, or deprecated, run `hack setup sync --all-scopes`, then reload the agent session so cached instructions are replaced.
13+
- Never copy or hand-edit generated Hack rules to refresh them; update the CLI and run the sync command.
14+
- Content revision: `b8663fad3ef4` (version alone is not a freshness guarantee).
15+
816
## Product boundary
917

1018
- Supported v3 surface: project init, up/down/restart, open, logs, env, host exec/shell, sessions, doctor, and daemon.
@@ -29,12 +37,13 @@ Prefer `hack` when shell access is available. Use MCP only when shell access is
2937
- Generated (do not hand-edit): `.hack/.internal/compose.override.yml`, `.hack/.internal/compose.env.override.yml`, `.hack/.branch/compose.<branch>.override.yml`.
3038
- Managed via CLI: `.hack/.internal/extra-hosts.json` (use `hack internal extra-hosts ...` commands).
3139
- Lifecycle runtime files: `.hack/.internal/lifecycle/state.json`, `.hack/.internal/lifecycle/*.log`.
32-
- Ignore rules: hack owns a committed `.hack/.gitignore` (self-healing on init/up) covering machine-local generated files (`.internal/`, `.branch/`, `.env`, `.env.state.json`, `hack.env*.local.yaml`, `tickets/`); keep it committed, and if generated files leaked into git, `hack doctor --fix` untracks them (files stay on disk).
40+
- Ignore rules: hack owns a committed `.hack/.gitignore` (self-healing on init/up) covering machine-local generated files (`.internal/`, `.branch/`, `.env`, `.env.state.json`, `hack.env*.local.yaml`); keep it committed, and if generated files leaked into git, `hack doctor --fix` untracks them (files stay on disk).
3341

3442
## Linked git worktrees
3543

3644
- Secret key inherits from the primary checkout automatically through the shared git common dir; set `HACK_ENV_SECRET_KEY` for CI or detached environments.
3745
- `hack up` in a linked worktree defaults to a branch instance named after the worktree's git branch; a detached linked worktree requires an explicit `--branch`, unless config `worktree.auto_branch=false` explicitly opts into the base instance.
46+
- Before `hack up` or `hack restart` auto-targets a new branch instance, Hack warns when the same worktree already owns a non-terminal instance; pass `--branch <name>` to make the target explicit.
3847
- `hack doctor` flags divergent secret keys and dev_host collisions across checkouts.
3948

4049
## Standard workflow
@@ -58,11 +67,17 @@ Prefer `hack` when shell access is available. Use MCP only when shell access is
5867

5968
- Put host setup in `.hack/hack.config.json` under `startup`/`lifecycle` (not ad-hoc terminal tabs).
6069
- Use `lifecycle.up.before` for pre-start hooks and `lifecycle.processes` for long-running host tasks.
70+
- Lifecycle hooks and processes receive the selected overlay's `global` values plus `host` overrides; service-scoped values remain container-specific unless a host command explicitly selects that scope.
6171
- For fixed-port host helpers such as SSM tunnels or local proxies, set `singleton.ports` and usually `onConflict: "adopt"` so Hack reuses a healthy existing listener instead of starting duplicate tunnel stacks.
6272
- `singleton` is a listener guard, not process ownership transfer; adopted external processes are left running on `hack down`.
6373
- Inspect lifecycle status via `hack projects --details` and stream via `hack logs <service-or-process>`.
6474
- Lifecycle session recovery is ownership-proven: Hack adopts healthy token-, definition-, and environment-matched sessions, replaces owned stale sessions, and refuses to kill same-name sessions without deterministic ownership proof.
6575
- `hack doctor --fix` reaps an orphan lifecycle session only when mux ownership is proven and its Compose instance is absent; unverified same-name sessions are never modified.
76+
- After `hack up` or `hack restart`, running services and successful one-shot services (`exited` with code 0) count as successful; other states return `E_STARTUP_INCOMPLETE`, and `hack doctor` warns about containers stuck in `Created`.
77+
- Detached startup is bounded; a hung Compose operation returns `E_STARTUP_TIMEOUT`, terminates its process group, and `hack doctor --fix` can start exact containers left in `Created`.
78+
- Target only affected services with `hack up <service...> --detach`, `hack restart <service...>`, or `hack env apply --service <service>`; scoped operations skip project lifecycle hooks and implicit dependency startup.
79+
- Use `hack env explain <KEY> --env <overlay> --service <service> --target <host|compose>` for redacted source, precedence, availability, and delivery diagnostics.
80+
- Dependency installer services are detected generically by command or `hack.dependencies.bootstrap=true`; registry env references are preflighted before container mutation. Optional `hack.dependencies.cache-volume`, `hack.dependencies.lockfiles`, and `hack.dependencies.runtime-files` labels enable lockfile/runtime-keyed volumes shared across compatible worktrees.
6681

6782
## Host-side env helpers
6883

@@ -74,16 +89,13 @@ Prefer `hack` when shell access is available. Use MCP only when shell access is
7489

7590
## Agent integration maintenance
7691

77-
- Project-level hack commands auto-check integration drift and attempt auto-sync (docs/skills/MCP).
92+
- Project-level hack commands auto-check integration drift and attempt auto-sync (project docs, client skills/rules, shared global skills, and MCP).
93+
- When drift is detected, Hack reports it before repair and tells the agent to reload after repair; it never silently leaves the session using cached rules.
7894
- Set `HACK_SETUP_SYNC_MODE=warn` to only warn, or `HACK_SETUP_SYNC_MODE=off` to disable.
7995
- Refresh project + user integrations: `hack setup sync --all-scopes`
8096
- Audit integration state only: `hack setup sync --all-scopes --check`
8197
- Remove generated integration artifacts: `hack setup sync --all-scopes --remove`
8298
- After upgrading CLI: `hack update` then `hack setup sync --all-scopes`
8399
- When changing hack itself: interface or behavior changes must update docs/ in the same change (regenerate the CLI reference with `bun run docs:cli-reference`).
84100

85-
## Optional extensions
86-
87-
- A local git-backed tickets extension exists (`hack tickets`) — only use it when the project explicitly uses it.
88-
89101
# END HACK INTEGRATION

0 commit comments

Comments
 (0)