hstack 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (99) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/LICENSE +21 -0
  3. package/README.md +169 -0
  4. package/VERSION +1 -0
  5. package/dist/cli.js +55 -0
  6. package/dist/cli.js.map +1 -0
  7. package/dist/commands/doctor.js +155 -0
  8. package/dist/commands/doctor.js.map +1 -0
  9. package/dist/commands/init.js +87 -0
  10. package/dist/commands/init.js.map +1 -0
  11. package/dist/commands/update.js +118 -0
  12. package/dist/commands/update.js.map +1 -0
  13. package/dist/lib/diff.js +120 -0
  14. package/dist/lib/diff.js.map +1 -0
  15. package/dist/lib/git.js +26 -0
  16. package/dist/lib/git.js.map +1 -0
  17. package/dist/lib/paths.js +35 -0
  18. package/dist/lib/paths.js.map +1 -0
  19. package/dist/lib/wire.js +314 -0
  20. package/dist/lib/wire.js.map +1 -0
  21. package/dist/manifest.js +53 -0
  22. package/dist/manifest.js.map +1 -0
  23. package/package.json +54 -0
  24. package/template/.claude/agents/adversarial-reviewer.md +123 -0
  25. package/template/.claude/agents/data-specialist.md +126 -0
  26. package/template/.claude/agents/implementer.md +154 -0
  27. package/template/.claude/agents/planner.md +110 -0
  28. package/template/.claude/agents/product-manager.md +111 -0
  29. package/template/.claude/agents/researcher.md +123 -0
  30. package/template/.claude/agents/security-reviewer.md +123 -0
  31. package/template/.claude/agents/spec-author.md +118 -0
  32. package/template/.claude/agents/test-strategist.md +129 -0
  33. package/template/.claude/agents/ui-ux-briefer.md +105 -0
  34. package/template/.claude/agents/verifier.md +109 -0
  35. package/template/.claude/skills/hstack-adr-new/SKILL.md +118 -0
  36. package/template/.claude/skills/hstack-adversarial-review/SKILL.md +187 -0
  37. package/template/.claude/skills/hstack-branch/SKILL.md +103 -0
  38. package/template/.claude/skills/hstack-change-new/SKILL.md +109 -0
  39. package/template/.claude/skills/hstack-change-plan/SKILL.md +119 -0
  40. package/template/.claude/skills/hstack-commit/SKILL.md +122 -0
  41. package/template/.claude/skills/hstack-configure/SKILL.md +126 -0
  42. package/template/.claude/skills/hstack-data-review/SKILL.md +132 -0
  43. package/template/.claude/skills/hstack-finalize/SKILL.md +159 -0
  44. package/template/.claude/skills/hstack-help/SKILL.md +174 -0
  45. package/template/.claude/skills/hstack-implement/SKILL.md +185 -0
  46. package/template/.claude/skills/hstack-init/SKILL.md +152 -0
  47. package/template/.claude/skills/hstack-module-spec/SKILL.md +105 -0
  48. package/template/.claude/skills/hstack-research/SKILL.md +145 -0
  49. package/template/.claude/skills/hstack-security-review/SKILL.md +133 -0
  50. package/template/.claude/skills/hstack-ship/SKILL.md +128 -0
  51. package/template/.claude/skills/hstack-story-draft/SKILL.md +117 -0
  52. package/template/.claude/skills/hstack-tech-debt-new/SKILL.md +122 -0
  53. package/template/.claude/skills/hstack-tech-debt-resolve/SKILL.md +158 -0
  54. package/template/.claude/skills/hstack-tech-debt-stale/SKILL.md +113 -0
  55. package/template/.claude/skills/hstack-tech-debt-wontfix/SKILL.md +104 -0
  56. package/template/.claude/skills/hstack-telemetry/SKILL.md +96 -0
  57. package/template/.claude/skills/hstack-test-plan/SKILL.md +182 -0
  58. package/template/.claude/skills/hstack-ui-brief/SKILL.md +108 -0
  59. package/template/.claude/skills/hstack-verify/SKILL.md +139 -0
  60. package/template/CLAUDE.md +390 -0
  61. package/template/scripts/telemetry/__init__.py +6 -0
  62. package/template/scripts/telemetry/insights/__init__.py +0 -0
  63. package/template/scripts/telemetry/insights/contract_drift.py +137 -0
  64. package/template/scripts/telemetry/insights/overengineering.py +115 -0
  65. package/template/scripts/telemetry/insights/quality_outcomes.py +131 -0
  66. package/template/scripts/telemetry/insights/token_economics.py +129 -0
  67. package/template/scripts/telemetry/insights/workflow_shape.py +198 -0
  68. package/template/scripts/telemetry/parsers/__init__.py +0 -0
  69. package/template/scripts/telemetry/parsers/bodies.py +87 -0
  70. package/template/scripts/telemetry/parsers/commits.py +219 -0
  71. package/template/scripts/telemetry/parsers/frontmatter.py +322 -0
  72. package/template/scripts/telemetry/parsers/transcripts.py +181 -0
  73. package/template/scripts/telemetry/render.py +311 -0
  74. package/template/scripts/telemetry/report.py +112 -0
  75. package/template/templates/adr.md +38 -0
  76. package/template/templates/adversarial-review.md +54 -0
  77. package/template/templates/change-spec.md +80 -0
  78. package/template/templates/ci-cd.md +27 -0
  79. package/template/templates/data-architecture.md +35 -0
  80. package/template/templates/data-review.md +54 -0
  81. package/template/templates/figma-handoff.md +38 -0
  82. package/template/templates/glossary.md +20 -0
  83. package/template/templates/hardening-checklist.md +73 -0
  84. package/template/templates/incident-runbook.md +57 -0
  85. package/template/templates/infrastructure.md +190 -0
  86. package/template/templates/module-spec.md +49 -0
  87. package/template/templates/mvp-scope.md +34 -0
  88. package/template/templates/persona.md +38 -0
  89. package/template/templates/plan.md +49 -0
  90. package/template/templates/security-review.md +63 -0
  91. package/template/templates/story.md +37 -0
  92. package/template/templates/tech-debt.md +61 -0
  93. package/template/templates/tech-stack.md +41 -0
  94. package/template/templates/telemetry-sidecar.md +184 -0
  95. package/template/templates/test-plan.md +119 -0
  96. package/template/templates/threat-model.md +54 -0
  97. package/template/templates/ui-brief.md +49 -0
  98. package/template/templates/verification.md +63 -0
  99. package/template/templates/vision.md +34 -0
@@ -0,0 +1,174 @@
1
+ ---
2
+ name: hstack-help
3
+ description: |
4
+ Use this skill when the engineer (or a cofounder opening the repo cold) wants situation awareness — "where are we, what can I run, what's next." Read-only across every artifact; no subagents invoked, no disk writes, safe to run any time. Examples:
5
+
6
+ <example>
7
+ Context: The cofounder hasn't touched the repo in two weeks and wants to know what's in flight before starting work.
8
+ user: "/hstack:help"
9
+ assistant: "I'll read every change folder, the context layer, ADRs, tech-debt, research sessions, and the git state. You'll get a three-section report: where you are, health, commands you can run right now with READY / BLOCKED markers."
10
+ <commentary>
11
+ Default mode is the full status report. No arguments needed. Output is computed entirely from disk frontmatter — no subagent invocations, no MCP calls, fast even on a large repo.
12
+ </commentary>
13
+ </example>
14
+
15
+ <example>
16
+ Context: The engineer is mid-change and wants a focused view of one change-spec's phase progression.
17
+ user: "/hstack:help --change 2026-05-billing-overage-warning"
18
+ assistant: "I'll read every artifact for that change and render the phase DAG: spec → ui-brief / figma-handoff / data-review / security-review / plan → implement (N of M phases) → verify → adversarial-review → ship. Each phase shows status and the next action."
19
+ <commentary>
20
+ Detailed mode for one change. Useful when resuming work after an interruption — the DAG view shows exactly which phase is next and what artifact gates it.
21
+ </commentary>
22
+ </example>
23
+ tools:
24
+ - Read
25
+ - Grep
26
+ - Glob
27
+ - Bash
28
+ - "{{TODO-SCRIPT: hstack/scripts/validate-spec.ts — invoked in --validate sub-mode to surface any artifact drift}}"
29
+ ---
30
+
31
+ ## Purpose
32
+
33
+ `hstack-help` is the read-only situation-awareness Skill. Its job is to answer three questions without writing anything: where is the team in their hstack-governed work, what is healthy / unhealthy, and what commands are available to run right now. It invokes no subagent. It writes no artifact. It is safe to run any time, by any team member, on any branch.
34
+
35
+ ## When to invoke
36
+
37
+ Invoke when:
38
+ - You open the repo after a break and need a refresher.
39
+ - A cofounder or new contributor is orienting themselves.
40
+ - Something feels off (a Skill halted, a status seems wrong) and you want a system-level view before debugging.
41
+ - Mid-change, before invoking the next workflow Skill, when you want to confirm preconditions are met without trial-and-error halts.
42
+
43
+ Safe to run repeatedly. Output is computed from current disk state.
44
+
45
+ ## Inputs
46
+
47
+ - No flag (default): full three-section status report.
48
+ - `--change <id>`: detailed view of one change-spec, including the phase DAG.
49
+ - `--commands`: print only the Skills cheat sheet (no current-state computation).
50
+ - `--explain <concept>`: look up a concept from the kernel, the template schemas, or the glossary. Examples: `--explain invariant`, `--explain tenant-isolation`, `--explain trivial-tag`.
51
+ - `--validate`: run `{{TODO-SCRIPT: hstack/scripts/validate-spec.ts}}` against every artifact under `hstack/` and report violations.
52
+
53
+ ## Preconditions
54
+
55
+ Minimal. The Skill is best-effort and degrades gracefully:
56
+
57
+ - Verify `hstack/` exists. If not, print "hstack is not installed in this repo. See `hstack/README.md` if vendoring, or run the vendoring procedure from the framework source."
58
+ - Verify `hstack/config.yaml` exists. If not (init not started), print "hstack is installed but not initialized. Run `/hstack:init` to bootstrap. Other Skills will halt until init completes."
59
+ - Beyond that, the Skill tolerates missing or partial artifacts — they show up in the report as "not present" or "draft", which is useful information, not an error.
60
+
61
+ ## Orchestration steps
62
+
63
+ No subagents are invoked. Every step is a direct file read or shell call.
64
+
65
+ ### Default mode (no flag)
66
+
67
+ 1. **Section 1 — Where you are.**
68
+ - Read `hstack/config.yaml` for `init-status` and the active MCP set.
69
+ - Glob `hstack/specs/changes/*/spec.md`. For each, read frontmatter (`id`, `status`, `surfaces`, `owner`, `internal-tooling`, `trivial`, `parent-change`). Filter to non-terminal status (anything before `shipped`, `archived`).
70
+ - For each in-flight change, compute the **next blocking action**:
71
+ - `status: draft` → "Author via `spec-author` directly (or run `/hstack:story-draft` first if user-facing)."
72
+ - `status: ready-to-plan` and missing conditional artifacts → name them; suggest the appropriate Skill (`/hstack:test-plan` first if missing — it gates the planner, `/hstack:security-review`, `/hstack:data-review` if db, `/hstack:ui-brief` if ui, `/hstack:change-plan`).
73
+ - `status: ready-for-implementation` and plan has un-completed phases → "/hstack:implement <id> <next-task-id>" with the next phase id computed from `plan.steps-completed`.
74
+ - `status: in-progress` → continue implementing remaining phases; verify after.
75
+ - `status: ready-for-review` and no `verification.md` at passed → "/hstack:verify <id>".
76
+ - `status: ready-for-review` and no `adversarial-review.md` at `findings-resolved` → "/hstack:adversarial-review <id> (FRESH SESSION REQUIRED)".
77
+ - `status: ready-to-ship` → "/hstack:ship <id>" (if pr-body not yet produced) or "open/merge the PR, then run /hstack:finalize <id>" (if pr-body exists).
78
+ - `status: shipped` and `resolves-tech-debt` is non-empty but referenced TDs are still at `in-progress` → "/hstack:finalize <id>" (finalize is incomplete; this is an inconsistent state).
79
+ - Glob `hstack/adr/ADR-*.md`, count those at `status: proposed`. List ids.
80
+ - Glob `hstack/tech-debt/TD-*.md`. For `status: open`: count and list the top 3 by severity, with the suggested command `/hstack:tech-debt-resolve <td-id>` for each. For `status: in-progress`: list each with its resolving change-spec id (from the Resolution Log) and the change-spec's current status — flag any inconsistency where the change-spec is `shipped` but the TD is still `in-progress` as "run /hstack:finalize <change-id> to complete resolution".
81
+ - Glob `hstack/research/sessions/*.md`, count those within the 30-day retention window. List the most recent 3.
82
+ - **Context docs.** Walk the canonical list from the kernel's "Product context" section: `vision`, `glossary`, `mvp-scope`, `personas/`, `data-architecture`, `tech-stack`, `ci-cd`, `infrastructure`, `threat-model`, `hardening-checklist`, `incident-runbook`. For each, classify:
83
+ - Missing entirely → "Run `/hstack:configure --interview <name>` (or `/hstack:init` if `init-status != complete`)."
84
+ - Status not `current` (e.g., `drafted`, `needs-refresh`) → flag with the same routing.
85
+ Author routing mirrors `/hstack:configure` §`--interview`:
86
+ - `vision`, `glossary`, `mvp-scope`, `personas`, `data-architecture`, `tech-stack`, `ci-cd` → `product-manager`.
87
+ - `infrastructure`, `incident-runbook` → `spec-author`.
88
+ - `threat-model`, `hardening-checklist` → `security-reviewer`.
89
+ - Glob `hstack/specs/*/spec.md`, list any module-spec at `status: needs-refresh`.
90
+
91
+ 2. **Section 2 — Health.**
92
+ - MCPs: read `hstack/context/mcp-status.md` for wired vs degraded.
93
+ - **Branch hygiene.** Run `git branch --show-current`. For each in-flight non-trivial change-spec, the expected branch is `change/<change-id>` per the kernel's branch-hygiene rule. Compare:
94
+ - Current branch is `main` AND ≥ 1 non-trivial in-flight change exists → flag explicitly: "On `main` with in-flight non-trivial change `<id>`; expected `change/<id>`. Run `/hstack:branch <id>` to switch."
95
+ - Current branch matches the expected `change/<id>` of one in-flight change → "Branch `change/<id>` matches in-flight change `<id>`."
96
+ - Current branch is `change/<other-id>` and `<other-id>` is no longer in-flight (shipped or archived) → "On `change/<other-id>` (shipped); ready to start something new."
97
+ - Trivial-only in-flight changes → no branch warning (trivial may commit on main).
98
+ - Git state: `git status --short` count. Flag uncommitted hstack-relevant files.
99
+ - Last hstack commit: `git log -1 --format='%h %s (%cr)' -- hstack/`. Shows when hstack-touching work last landed.
100
+ - Local-ahead-of-remote: `git rev-list --count @{u}..HEAD 2>/dev/null` (silently skip if no upstream).
101
+
102
+ 3. **Section 3 — Commands you can run right now.**
103
+ - List every Skill grouped by category (setup, workflow, cross-cutting).
104
+ - For each, compute a marker:
105
+ - `READY` — preconditions detectable as met.
106
+ - `BLOCKED: <reason>` — name the missing precondition.
107
+ - `N/A — context` — e.g., `/hstack:ui-brief` for a repo with no in-flight ui-surface change.
108
+ - For Skills that take arguments, show a parameterized example using the most likely current value (e.g., the active in-flight change-id).
109
+
110
+ ### `--change <id>` mode
111
+
112
+ Read every artifact in `hstack/specs/changes/<id>/`. Render the phase DAG as ASCII with status per node:
113
+
114
+ ```
115
+ spec [ready-for-implementation]
116
+ ├── test-plan [passed] ✓
117
+ ├── ui-brief [drafted] ✓
118
+ ├── figma-handoff [ready] ✓
119
+ ├── data-review [passed] ✓
120
+ ├── security-review [concerns-acknowledged] ✓
121
+ └── plan [in-progress]
122
+ steps-completed: phase-1, phase-2, phase-3 of phase-1..phase-5
123
+ next phase: phase-4-wire (depends on phase-3 ✓)
124
+ verification [not present]
125
+ adversarial-review [not present]
126
+ ```
127
+
128
+ Below the DAG, the explicit next-action recommendation.
129
+
130
+ ### `--commands` mode
131
+
132
+ Just the Skills cheat sheet. No state computation. Useful when typing in muscle memory.
133
+
134
+ ### `--explain <concept>` mode
135
+
136
+ Grep `hstack/CLAUDE.md`, `hstack/context/glossary.md`, and (if available) the cached template schemas for the concept. Print the most relevant paragraph plus a pointer to the source file. If the concept is not found in any source, print: "Not in the kernel, glossary, or template schemas. Try the architecture doc at the URL in `hstack/README.md`, or ask in natural language and I'll pull from kernel context."
137
+
138
+ ### `--validate` mode
139
+
140
+ Run `{{TODO-SCRIPT: hstack/scripts/validate-spec.ts}}` against every artifact under `hstack/`. Group failures by validation-rule id (SP-*, PL-*, AR-*, etc.) and name the offending file. Read-only — does not auto-fix anything.
141
+
142
+ ## Outputs
143
+
144
+ - Console-rendered status report. No disk writes. No commits.
145
+ - No mutation of any artifact frontmatter.
146
+
147
+ ## Auto-commit triggers
148
+
149
+ None. This Skill is strictly read-only.
150
+
151
+ ## Idempotency contract
152
+
153
+ Trivially idempotent. Re-runs produce a fresh report from current disk state. No persisted state, no side effects.
154
+
155
+ ## Stop conditions
156
+
157
+ Beyond the kernel's general stop conditions:
158
+
159
+ - The `--explain <concept>` lookup finds no match in any canonical source. Print the "not found" message and exit cleanly — not a failure.
160
+ - `--validate` mode requires the validator script. If absent, print a clear "validator not yet implemented" message (it's a known TODO) and skip the validation; the other modes still work.
161
+
162
+ ## Failure modes
163
+
164
+ - **Cofounder runs the Skill before vendoring is complete.** Print the install pointer; do not try to compute a status report.
165
+ - **Many in-flight change-specs with conflicting next-action recommendations.** Just list them all; let the engineer prioritize.
166
+ - **Git state cannot be read (not a git repo).** Skip the git-related health lines; surface a "git not initialized" note.
167
+
168
+ ## Anti-patterns
169
+
170
+ - Never write to any artifact, never auto-commit. The Skill's value is that it's safe to run any time.
171
+ - Never invoke a subagent. Status awareness does not require the conversational interview machinery.
172
+ - Never invent a "next action" for an artifact whose status is ambiguous — print the ambiguity, not a guess.
173
+ - Never run the validators with `--fix` or any write flag (when the validator gains those).
174
+ - Never call MCPs or perform network requests for the status report. Local file reads only.
@@ -0,0 +1,185 @@
1
+ ---
2
+ name: hstack-implement
3
+ description: |
4
+ Use this skill when a change-spec is at `ready-for-implementation` and the engineer wants to execute one task from the plan. This is the only Skill that causes code to be written, and it does so exclusively by invoking the `implementer` subagent against one `task-id` at a time, scope-locked to the change-spec's `in-scope` allowlist. Defense in depth: the Skill checks preconditions and forbidden surfaces before invoking the subagent, and the subagent re-checks at every Read / Edit / Write. Examples:
5
+
6
+ <example>
7
+ Context: A UI-only change-spec for the billing-overage banner is at ready-for-implementation; the plan has five phases and phase-3 is next.
8
+ user: "/hstack:implement 2026-05-billing-overage-warning phase-3-component"
9
+ assistant: "I'll verify upstream gates (security-review passed, ui-brief drafted, figma-handoff ready), then invoke implementer for phase-3. Files Touched is a strict subset of in-scope; the subagent refuses any path outside it."
10
+ <commentary>
11
+ The Skill enforces the scope-lock contract from the kernel — Reads as well as Writes are restricted to `in-scope` plus the canonical session-start context loads. Phase-3 is the only thing executed; the Skill does not anticipate phase-4.
12
+ </commentary>
13
+ </example>
14
+
15
+ <example>
16
+ Context: A multi-surface change touching ui, db, and api is at ready-for-implementation; phase-2 lands a migration and regenerates types.
17
+ user: "/hstack:implement 2026-06-knowledge-citations phase-2-migration"
18
+ assistant: "I'll invoke implementer for phase-2. The migration runs against local Supabase only; types regen via `supabase gen types typescript --local`; no `supabase db push` against any remote project."
19
+ <commentary>
20
+ The kernel's database workflow is enforced both at the Skill level (the Skill refuses to invoke if the engineer attempts a remote-environment migration) and at the subagent level. Defense in depth on the highest-risk surface.
21
+ </commentary>
22
+ </example>
23
+
24
+ <example>
25
+ Context: Mid-phase, the implementer halts because lib/billing/queries.ts is needed but is not in `in-scope`.
26
+ user: "/hstack:implement 2026-05-billing-overage-warning phase-4-wire"
27
+ assistant: "The implementer halted at the queries.ts edit — that file is out-of-scope. Don't proceed; emit the scope-amendment request to the conversation, halt, and wait for the engineer to update the change-spec via spec-author."
28
+ <commentary>
29
+ This is the precondition-failure / scope-amendment case. The Skill does not unilaterally extend in-scope. The engineer invokes spec-author to amend the change-spec, the Skill re-runs, the implementer re-loads and continues.
30
+ </commentary>
31
+ </example>
32
+ tools:
33
+ - Read
34
+ - Write
35
+ - Edit
36
+ - Grep
37
+ - Glob
38
+ - Bash
39
+ - Task
40
+ - "{{TODO-SCRIPT: hstack/scripts/validate-spec.ts — validates plan.steps-completed updates against PL-03/PL-04/PL-05}}"
41
+ - "{{TODO-OTHER: in-scope-enforcement guard — runtime check at every Edit/Write that refuses paths outside change-spec.in-scope; v1 implemented inside the implementer subagent's prompt; v2 substrate moves to a subagent-runtime hook}}"
42
+ ---
43
+
44
+ ## Purpose
45
+
46
+ `hstack-implement` is the only Skill that causes code to be written. It orchestrates the `implementer` subagent against one named task from the plan, scope-locked to the change-spec's `in-scope` allowlist. It is the workflow's last line of gating before code lands on disk: it re-checks every upstream gate, enumerates the kernel's forbidden tools, and refuses to invoke the implementer when preconditions are not met.
47
+
48
+ ## When to invoke
49
+
50
+ Invoke once the change-spec is at `status: ready-for-implementation` (which means every upstream gate is terminal: test-plan at `passed` or `concerns-acknowledged`, plan at `ready`, security-review at `passed` or `concerns-acknowledged`, data-review at `passed` or `concerns-acknowledged` when applicable, ui-brief at `drafted` and figma-handoff at `ready` when applicable, user-stories non-empty unless internal-tooling). One invocation per phase. Re-invoke for each subsequent phase.
51
+
52
+ ## Inputs
53
+
54
+ - `<change-id>` (required, positional): the change-spec id.
55
+ - `<task-id>` (required, positional): the phase id (e.g., `phase-3-component`). Must match an existing `step-id` in the plan body.
56
+
57
+ ## Preconditions
58
+
59
+ Before any work — the Skill re-checks every gate even when the change-spec carries `status: ready-for-implementation`, because frontmatter can drift:
60
+
61
+ - Change-spec at `hstack/specs/changes/<change-id>/spec.md`. `status` must be `ready-for-implementation` or `in-progress`. `Invariants` ≥ 3 bullets, `in-scope` non-empty, every `in-scope` glob resolves.
62
+ - Plan at `hstack/specs/changes/<change-id>/plan.md` at `status: ready` or `in-progress`. `<task-id>` must match a phase id in the plan body. `Files Touched` for the phase must be a strict subset of `in-scope`.
63
+ - **Test-plan at `hstack/specs/changes/<change-id>/test-plan.md` at `status: passed` or `concerns-acknowledged`.** The implementer reads it at session start and writes the tests it specifies; without a terminal test-plan, the implementer halts.
64
+ - Security-review at `status: passed` or `concerns-acknowledged`.
65
+ - Data-review at `status: passed` or `concerns-acknowledged` when `surfaces` includes `db`.
66
+ - ui-brief at `status: drafted` and figma-handoff at `status: ready` when `surfaces` includes `ui`.
67
+ - User-stories non-empty unless `internal-tooling: true`.
68
+ - The relevant module-spec at `status: current`.
69
+ - **Branch state.** Run `git branch --show-current`. If the current branch is `main` (or the configured default) AND `change-spec.trivial` is not `true`, HARD HALT with: "Refusing to implement on `main` — change-spec `<id>` is not marked trivial. Check out `change/<id>` first, or run `/hstack:branch <id>` to create-and-switch." Trivial changes (`trivial: true`) may proceed on main per the kernel's trivial-changes carve-out. This check enforces the kernel's branch-hygiene contract at the last moment before code lands.
70
+
71
+ Enumerate the kernel's forbidden tool surfaces explicitly before invoking the subagent — defense in depth with the implementer's own check:
72
+
73
+ - `service_role` Supabase keys in agent-touching code paths.
74
+ - Raw shell (`psql`, `bash`, `sh`) executed against production or remote Supabase. Local Supabase only.
75
+ - `supabase db push` / `supabase db reset` against any remote project. Local stack only.
76
+ - Pipedream Connect against live customer accounts without per-invocation explicit human approval.
77
+ - Any tool that mutates state outside the `in-scope` list.
78
+ - MCPs not in the consuming repo's configured allow set.
79
+ - `--no-verify` or other hook-bypassing git flags.
80
+ - `--update-snapshots`, `jest --updateSnapshot`, `vitest -u`, or any equivalent bulk snapshot-update flag.
81
+ - Destructive git operations (`git push --force`, `git reset --hard`, `git checkout .`) without explicit per-invocation authorization.
82
+ - Modifications to existing test files without per-test authorization via the test-immutability protocol (`Ok to change test <name>`, `Ok to delete test <name>`, `Ok to update snapshot <name>`, `Ok to refresh fixture <name>`).
83
+
84
+ If the named phase appears to require any of the above, halt before invoking — surface the violation, ask the engineer to either reshape the phase or authorize per-invocation.
85
+
86
+ ## Orchestration steps
87
+
88
+ 1. **Re-verify gates.** Run the precondition checks above. Any failure halts the Skill with a precise message naming the failing artifact and field.
89
+
90
+ 2. **Invoke `implementer`.** Use the Task tool with `subagent_type: implementer` and context = [kernel, change-spec, plan, test-plan, security-review, data-review when present, ui-brief and figma-handoff when present, module-spec, tech-stack]. The subagent loads only the In-Scope file list for code reading; everything outside the canonical session-start context plus In-Scope is refused per the kernel.
91
+
92
+ 3. **Phase execution.** The subagent executes one phase per invocation. It writes the code diff scoped to the phase's Files Touched, updates `plan.steps-completed` to include `<task-id>` when the phase completes, and writes the tests named in the test-plan sections the phase's Test Strategy references. Test names, file paths, and assertion shape come from the test-plan; the implementer does not rename or omit tests.
93
+
94
+ 4. **Database workflow enforcement.** For phases touching schema: the subagent creates migration files via `supabase migration new <descriptive_name>`; enables RLS in the same migration as a new table; regenerates types via `supabase gen types typescript --local > types/database.types.ts`. Never `supabase db push` / `supabase db reset` against a remote project.
95
+
96
+ 5. **Trigger.dev v4 only.** For phases touching trigger code, the subagent uses `@trigger.dev/sdk` task / schemaTask; never `client.defineJob` (v2 deprecated). `triggerAndWait` returns a `Result`; `result.ok` is checked before reading `result.output`.
97
+
98
+ 6. **Scope-amendment halt.** If the subagent would touch a file outside `in-scope`, it halts and emits a scope-amendment request to the conversation. The Skill does not extend `in-scope` unilaterally. The engineer invokes `spec-author` (typically via direct request, not a Skill) to amend the change-spec, the Skill re-runs, the subagent re-loads.
99
+
100
+ 7. **Hook failures.** If a pre-commit hook fails on the auto-commit, the subagent investigates and fixes the underlying issue; does not bypass via `--no-verify`. If the fix would require out-of-scope edits, halt with a scope-amendment request.
101
+
102
+ 8. **Test-immutability protocol.** When the subagent determines an existing test file must be modified, deleted, or have a snapshot updated, it halts before touching the file and runs the kernel's authorization protocol: surface the test name, the reason, the proposed change, and the alternatives; wait for the canonical phrase verbatim (`Ok to change test <name>`, `Ok to delete test <name>`, `Ok to update snapshot <name>`, `Ok to refresh fixture <name>`); echo the phrase in the commit message body and add a footnote under the relevant phase in `plan.md`. The Skill enforces this defense-in-depth — if a subagent's diff shows a modified pre-existing test file without a matching authorization in the conversation, the Skill blocks the commit.
103
+
104
+ 8. **Validate.** Run `{{TODO-SCRIPT: hstack/scripts/validate-spec.ts}}` against the plan — PL-03 (every `steps-completed` entry matches a plan phase id), PL-04 (every Files Touched path is a subset of `in-scope`), PL-05 (plan status gating).
105
+
106
+ ## Outputs
107
+
108
+ - Code diffs in the consuming repo, scoped to `change-spec.in-scope` and matching the phase's Files Touched.
109
+ - Test files written or updated per the phase's Test Strategy.
110
+ - `plan.md` updated with `<task-id>` appended to `steps-completed`; `blocked-on: null` (or set to a phase id when interactive blocker stops progress).
111
+ - One git commit on the active working branch naming `<change-id>` and `<task-id>`.
112
+
113
+ The change-spec is never written by the implementer or by this Skill (architecture amendment A3).
114
+
115
+ ## Auto-commit triggers
116
+
117
+ - One commit when the phase completes and `steps-completed` advances. Commit message: `implement(<change-id>) <task-id>`.
118
+ - An additional commit when `plan.status` advances to `completed` after the final phase.
119
+
120
+ ## Telemetry sidecar
121
+
122
+ At the phase-completion auto-commit above, write `hstack/specs/changes/<change-id>/.telemetry/implement-<task-id>.json` in the same `git add && git commit` as the canonical phase commit. The sidecar is derivative of git + frontmatter (see `hstack/templates/telemetry-sidecar.md`). Schema:
123
+
124
+ ```json
125
+ {
126
+ "schema_version": 1,
127
+ "skill": "hstack-implement",
128
+ "change_id": "<change-id>",
129
+ "phase_id": "<task-id>",
130
+ "started_at": "<ISO-8601, session start of this phase>",
131
+ "completed_at": "<ISO-8601, now>",
132
+ "files_touched_count": <int>,
133
+ "tests_written_count": <int, new test files only>,
134
+ "scope_amendment_emitted": <bool>,
135
+ "halt_reasons": [<kernel halt-sentinel enum values, if any>],
136
+ "test_immutability_authorizations": [<canonical phrase strings, if any>]
137
+ }
138
+ ```
139
+
140
+ `.telemetry/` is git-ignored in the consuming repo. The sidecar write must not introduce any new LLM turn or confirmation gate — it is a deterministic write bundled with the existing commit. If the sidecar write fails, log and continue; the canonical commit must still land.
141
+
142
+ ## Idempotency contract
143
+
144
+ - Re-running with the same `<task-id>` after the phase already landed: the subagent reads `steps-completed`, recognizes the phase as done, and produces a no-op diff. Re-running on a partially applied phase: the subagent reads current file state and applies only the remaining diff.
145
+ - Re-running on a phase whose dependencies are not yet complete (`depends-on` references a phase not in `steps-completed`): the subagent halts and surfaces the missing dependency.
146
+
147
+ ## Stop conditions
148
+
149
+ Beyond the kernel's general stop conditions:
150
+
151
+ - A modification outside `in-scope` is needed. Halt; emit scope-amendment request.
152
+ - An invariant would be weakened, dropped, or modified.
153
+ - A required upstream artifact is non-terminal.
154
+ - A forbidden tool would be used (see enumeration above).
155
+ - A load-bearing MCP is unreachable mid-phase.
156
+ - The change requires a migration against a remote environment.
157
+ - A pre-commit or pre-push hook fails after investigation — halt and surface; do not bypass.
158
+ - An existing test would need to be modified, deleted, or have its snapshot updated, and the human has not yet typed the canonical authorization phrase.
159
+ - The engineer has not authorized a destructive git operation that the situation seems to call for.
160
+ - An ambiguity in the plan or change-spec would require the implementer to make a design call beyond its role.
161
+
162
+ ## Failure modes
163
+
164
+ - **Phase depends-on a phase not yet in `steps-completed`.** Halt and surface the dependency.
165
+ - **Type regen fails after a migration.** The phase is incomplete; `steps-completed` is not advanced; halt and surface.
166
+ - **Tests written but failing.** Halt at `steps-completed` not advanced; the engineer either re-invokes after fixing or amends the plan via the planner.
167
+ - **Validator fails PL-04.** A Files Touched path crept outside `in-scope` — halt; this should have been caught upstream.
168
+
169
+ ## Anti-patterns
170
+
171
+ - Never bypass scope-lock by one file, even one line. Halt and amend.
172
+ - Never modify the change-spec. `steps-completed` lives on the plan.
173
+ - Never weaken or remove an invariant.
174
+ - Never use `service_role` Supabase keys in agent code paths.
175
+ - Never use raw shell or `supabase db push` against production or any remote project.
176
+ - Never use Pipedream Connect against live customer accounts without explicit per-invocation approval.
177
+ - Never skip a hook with `--no-verify`. Fix the failing check.
178
+ - Never execute destructive git operations without explicit authorization in the current conversation.
179
+ - Never anticipate the next phase. Execute the named task and stop.
180
+ - Never use `client.defineJob` (Trigger.dev v2 deprecated).
181
+ - Never invent a migration filename. Use `supabase migration new <descriptive_name>`.
182
+ - Never claim a phase complete when tests fail or types are stale.
183
+ - Never edit, delete, or neutralize an existing test without per-test authorization. The kernel's test-immutability rule is non-negotiable; the default fix for a failing test is to fix the code under test.
184
+ - Never run bulk snapshot-update flags. Each snapshot update needs its own authorization.
185
+ - Never accept a blanket "fix the tests" authorization. Per-test scope is mandatory.
@@ -0,0 +1,152 @@
1
+ ---
2
+ name: hstack-init
3
+ description: |
4
+ Use this skill when an engineer is adopting hstack on a fresh repository for the first time and needs to produce `hstack/config.yaml` and populate every required document under `hstack/context/`. Until init completes, no other hstack Skill works — every workflow Skill checks for init completion at session start and halts otherwise. Init is structured as six-to-eight mini-sessions of ten-to-fifteen minutes each (one per product-context document) rather than one ninety-minute block, so that an interruption costs at most one in-flight field. Examples:
5
+
6
+ <example>
7
+ Context: A fresh Moso clone has no `hstack/config.yaml` and no `hstack/context/` content; the engineer wants to bootstrap hstack from scratch.
8
+ user: "Start /hstack:init on this repo."
9
+ assistant: "I'll invoke the product-manager subagent for the first mini-session — vision.md. We'll commit when vision is done and resume with glossary next."
10
+ <commentary>
11
+ Init is the only Skill permitted to write `hstack/config.yaml` and to populate the product-context layer. It orchestrates the product-manager subagent across five-to-seven document interviews, each ending at a commit point. The "no other Skill works until init complete" rule is enforced by every downstream Skill's precondition checks.
12
+ </commentary>
13
+ </example>
14
+
15
+ <example>
16
+ Context: Init was started two days ago, three documents were committed, and a session crash dropped the fourth. The engineer wants to resume rather than restart.
17
+ user: "Resume /hstack:init — vision, glossary, and mvp-scope are already done."
18
+ assistant: "I'll read hstack/.session-state/<session-id>.yaml, confirm which documents are at status `current`, and resume with the next missing one — data-architecture, based on what I see on disk."
19
+ <commentary>
20
+ Idempotency is load-bearing here: the Skill reads disk state, recognizes which documents are already terminal, and continues at the next empty mini-session boundary rather than re-running completed interviews.
21
+ </commentary>
22
+ </example>
23
+ tools:
24
+ - Read
25
+ - Write
26
+ - Edit
27
+ - Grep
28
+ - Glob
29
+ - Bash
30
+ - Task
31
+ - "{{TODO-SCRIPT: hstack/scripts/validate-spec.ts — frontmatter validator run after every confirmed field write}}"
32
+ - "{{TODO-SCRIPT: hstack/scripts/init-detect-mcps.sh — probes the consuming repo's Claude Code config for available MCPs and writes hstack/context/mcp-status.md}}"
33
+ ---
34
+
35
+ ## Purpose
36
+
37
+ `hstack-init` is the first-run, conversational bootstrap Skill. It writes `hstack/config.yaml` and populates the canonical product-context layer at `hstack/context/`. It is the longest Skill in the system by elapsed time, structured deliberately as a series of short mini-sessions so the user can stop and resume without losing work. It is not the workflow itself: it does not author change-specs, plans, or any per-change artifact. It is also not the editor of an existing config — that is `hstack-configure`'s role.
38
+
39
+ ## When to invoke
40
+
41
+ Invoke when the consuming repo has no `hstack/config.yaml`, or when `hstack/config.yaml` exists but at least one required product-context document is missing or below `status: current`. Every other hstack Skill checks for init completion at session start; if init is incomplete, those Skills halt with a message directing the engineer here. Init runs once per repo lifetime, although `hstack-configure --migrate` may re-invoke targeted slices of it on schema-version upgrades.
42
+
43
+ ## Inputs
44
+
45
+ - No positional arguments. The Skill drives entirely from on-disk state and conversation.
46
+ - Optional flag `--resume` is implicit: the Skill always reads `hstack/.session-state/<session-id>.yaml` when present and continues from the next un-confirmed field.
47
+
48
+ ## Preconditions
49
+
50
+ Before any work:
51
+
52
+ - Verify `hstack/` directory exists at the repo root. If not, halt and ask the engineer to confirm they are in the right directory.
53
+ - Read `hstack/CLAUDE.md` (kernel) and `hstack/templates/` — both must be present. If either is missing, halt and ask the engineer to install or restore the hstack source. **The kernel describes the framework, not the consuming repo's product.** Treat it as behavioral rules, never as content to be configured.
54
+ - **Load the consuming-repo context layer.** Read every artifact in the consuming repo (the working directory, NOT `hstack/`) that hints at its product, stack, or design system: `CLAUDE.md`, `README.md`, `package.json`, `docs/` if present, `.claude/agents/` and `.claude/skills/` for sibling tooling. This is the product being configured. Every interview prompt below frames against THIS context, not against `hstack/CLAUDE.md`.
55
+ - Probe Claude Code's MCP configuration for the consuming repo and write a draft `hstack/context/mcp-status.md` listing which MCPs are wired (Notion, Linear, GitHub, Figma, Supabase) and which are absent. Run `{{TODO-SCRIPT: hstack/scripts/init-detect-mcps.sh}}` for this; if absent, the Skill produces the file by interviewing the engineer instead.
56
+ - If `hstack/.session-state/` contains a prior init session-state file, read it and confirm with the engineer that resumption is the intent.
57
+
58
+ If the engineer signals "start fresh, abandon the prior partial init," archive the existing session-state file before proceeding.
59
+
60
+ ## Orchestration steps
61
+
62
+ Init is split into discrete mini-sessions, each commitable independently. The order is fixed because later documents reference earlier ones.
63
+
64
+ 1. **Mini-session 0 — config skeleton.** Every prompt in this mini-session is about THE CONSUMING REPO (not about hstack itself). Interview the engineer for:
65
+ - **Story store** for this repo's user stories — Notion DB, Linear, GitHub Issues, or `hstack/stories/`.
66
+ - **Personas store** for this repo's personas — typically `hstack/context/personas/` or a Notion DB.
67
+ - **Design system** for this repo. The schema is per-resource because partial / external states are common (Figma MCP for components, Notion for brand-guidelines, in-repo for tokens later). For each of `components`, `tokens`, `brand-guidelines`, ask:
68
+ - `source` — controlled enum: `in-repo` | `figma-mcp` | `notion-mcp` | `submodule` | `npm` | `external-other` | `none`.
69
+ - Source-specific follow-up: `path` for `in-repo`; `figma-file-id` for `figma-mcp`; `notion-page-id` for `notion-mcp`; `package` name for `npm`; `repo-url` for `submodule` / `external-other`.
70
+ - Optional `notes` — especially useful for in-progress states like "via Figma MCP until vendored into the repo."
71
+ - The `none` value is honest when the resource genuinely isn't documented yet; the agent does not invent paths to fill the field.
72
+ - **Module-to-area mapping** for this repo — a list of module ids with their canonical path globs. Read `package.json` and the consuming repo's directory layout to propose a starting set; the engineer confirms or revises.
73
+ - **Adversarial-review floor** — default 3, 5 for `agent`/`auth`/`billing`.
74
+ - **Production-runtime agent ledger** — enabled or not. This logs the consuming repo's *runtime* AI agents (the orchestrator, tool calls into customer accounts, MCP-mediated actions) to `audit/agent-ledger/` at the consuming repo root. **It is NOT about hstack's own subagents** (`spec-author`, `planner`, `implementer`, etc.) — those are already audited via the kernel's auto-commit-at-status-transition rule and visible in `git log`. The v1 ledger is useful telemetry (debugging, cost attribution, per-tenant breakdowns), not defensible audit evidence; v2 substrate adds hash-chain integrity, signed records, and WORM storage. Frame the question to the engineer accordingly so the term "agent" isn't ambiguous.
75
+ - **Active MCP set** — pre-populated from the MCP probe above; the engineer confirms.
76
+
77
+ Write `hstack/config.yaml` with `schemaVersion: 1`. The `init-status` field starts at `minimal-complete` after this mini-session ends, advancing to `complete` only when every required context document is at `current`. Commit.
78
+
79
+ 2. **Mini-session 1 — vision.** Invoke `product-manager` via the Task tool with `subagent_type: product-manager` and context = [`hstack/CLAUDE.md`, `hstack/templates/vision.md`, any pointer the engineer offers to an existing vision source]. The subagent walks the five vision sections, confirms each, writes `hstack/context/vision.md` at `status: drafted` and advances to `current` at the end. Prompt cleanup of the source per the subagent's contract. Commit.
80
+
81
+ 3. **Mini-session 2 — glossary.** Same orchestration with `hstack/templates/glossary.md`. Output: `hstack/context/glossary.md` at `current`. Commit.
82
+
83
+ 4. **Mini-session 3 — mvp-scope.** Same orchestration with `hstack/templates/mvp-scope.md`. Output: `hstack/context/mvp-scope.md` at `current`. Commit.
84
+
85
+ 5. **Mini-session 4 — personas.** For each persona the engineer names, the `product-manager` subagent runs a persona sub-interview against `hstack/templates/persona.md`, including the challenge prompt "What is this persona explicitly not?" Personas are written to the configured store (typically `hstack/context/personas/<slug>.md`). Commit after each persona individually so partial completion is durable.
86
+
87
+ 6. **Mini-session 5 — data-architecture, tech-stack, ci-cd.** These three are interview-light because the engineer has often already documented them in `CLAUDE.md`, `package.json`, or `.github/workflows/`. The Skill orchestrates by handing each in turn to `product-manager` (or `spec-author` if the engineer prefers a more code-grounded read) with the relevant existing source plus the canonical template. Output: three files at `current`. Commit after each.
88
+
89
+ 7. **Mini-session 6 — infrastructure.** Invoke `spec-author` via the Task tool with `subagent_type: spec-author` and context = [`hstack/CLAUDE.md`, `hstack/templates/infrastructure.md`, `hstack/context/tech-stack.md`, `hstack/context/ci-cd.md`, `hstack/context/data-architecture.md`, any existing infra source the engineer points to — cloud console screenshots, Terraform / Pulumi / CDK files, GitHub Actions YAML, Dockerfile, supabase config]. The subagent walks every H2 section of the template via interview, biasing toward grounded truth-gathering rather than aspirational design. **For engineers unfamiliar with infrastructure concepts, the subagent is expected to explain each section's intent before asking, and to spawn the `researcher` subagent for unfamiliar terms (e.g., "what is point-in-time recovery?", "what does a CDN actually do?") rather than asking the engineer to guess.** This mini-session is interview-heavy and often the longest of init for pre-prod teams. Output: `hstack/context/infrastructure.md` at `current`. The Blast-Radius Matrix must have at least one row before status advances to `current` (INF-03); the Unknowns section must be present even when empty (INF-02). Honest "we don't have this yet" answers are explicitly preferred over fabricated content; the resulting gaps land as tech-debt items in the Known Gaps section. Commit.
90
+
91
+ 8. **Mini-session 7 — threat-model, hardening-checklist, incident-runbook.** The security-context triplet. By this point `infrastructure.md` is at `current`, so the security-reviewer has the operational ground truth it needs to model threats accurately. Author orchestration is per-document:
92
+ - `threat-model.md` and `hardening-checklist.md` are authored by `security-reviewer` via the Task tool with `subagent_type: security-reviewer`. The same subagent that scores per-change security-reviews at change time also authors the slow-changing policy these reviews score against — different cadence, same security framing (bias toward CONCERNS, challenge-driven prompts). Generalist subagents (spec-author, product-manager) are NOT offered here; the security-specific framing is load-bearing.
93
+ - `incident-runbook.md` is authored by `spec-author` from a founder-style interview — kill switches, revocation flows, comms templates are operational content, not threat-modeling.
94
+
95
+ `incident-runbook.md` is written with `git-ignored: true` in its frontmatter; the Skill verifies an entry exists in the repo's `.gitignore` before proceeding (creating the entry with confirmation if absent). The Skill warns the engineer at the start of this mini-session that incident-runbook content will not be committed to git and will need an out-of-band sync target named in `hstack/config.yaml`. Commit each context file as it lands.
96
+
97
+ The Skill maintains `hstack/.session-state/<session-id>.yaml` continuously, updating after every confirmed field write. The state file captures which mini-session is in progress, which fields within it are confirmed, and what the next prompt should be.
98
+
99
+ ## Outputs
100
+
101
+ - `hstack/config.yaml` (status field on the config carries `init-status: minimal-complete` once mini-session 0 ends, advancing to `complete` only when every required context document is at `current`).
102
+ - `hstack/context/vision.md` at `current`.
103
+ - `hstack/context/glossary.md` at `current`.
104
+ - `hstack/context/mvp-scope.md` at `current`.
105
+ - `hstack/context/personas/<slug>.md` per persona, or sync stubs when the store is Notion / Linear.
106
+ - `hstack/context/data-architecture.md`, `tech-stack.md`, `ci-cd.md`, `infrastructure.md`, `threat-model.md`, `hardening-checklist.md` — all at `current`.
107
+ - `hstack/context/incident-runbook.md` at `current` with `git-ignored: true`; corresponding `.gitignore` entry verified.
108
+ - `hstack/context/mcp-status.md` documenting active and degraded MCPs.
109
+
110
+ ## Auto-commit triggers
111
+
112
+ Each of the following emits an auto-commit on the active working branch:
113
+
114
+ - `hstack/config.yaml` reaches `init-status: minimal-complete` (end of mini-session 0).
115
+ - Each product-context document's status moves to `current` (end of each mini-session).
116
+ - Each persona's status moves to `current` (end of each persona sub-interview).
117
+ - `hstack/config.yaml`'s `init-status` advances to `complete` (end of mini-session 7).
118
+
119
+ The commit message names the mini-session and the artifact. Aside from these, init does not auto-commit.
120
+
121
+ ## Idempotency contract
122
+
123
+ Re-running `hstack-init` on a repo where init has progressed partway through:
124
+
125
+ - Reads `hstack/config.yaml` and every existing `hstack/context/*.md`. Any file at `status: current` is considered done; the Skill does not re-interview it.
126
+ - Reads `hstack/.session-state/<session-id>.yaml` if present and resumes the in-flight mini-session at its next un-confirmed field.
127
+ - Produces a no-op diff for completed mini-sessions; the only writes happen to the first incomplete document.
128
+ - Re-running after all mini-sessions are complete is a no-op that prints the init-status summary.
129
+
130
+ ## Stop conditions
131
+
132
+ Beyond the kernel's general stop conditions, this Skill halts when:
133
+
134
+ - The `product-manager` subagent halts (e.g., because a persona answer is too vague, or because a referenced source document is unreachable). The Skill surfaces the subagent's halt message and waits.
135
+ - A configured MCP the engineer named as the story store is not wired in Claude Code. The Skill does not silently fall back to a different store; it asks the engineer to wire the MCP or pick a different store, then re-runs the relevant config field.
136
+ - The engineer signals end-of-session mid-mini-session. The Skill writes the session-state file, commits any field that has been confirmed and written, and exits cleanly.
137
+ - `incident-runbook.md` would be committed to git. Halt; verify the gitignore entry first.
138
+
139
+ ## Failure modes
140
+
141
+ - **Missing kernel or templates.** Halt with a clear message; this is a hstack installation problem, not an init problem.
142
+ - **Subagent unreachable mid-mini-session.** Persist current state; instruct the engineer to retry in a moment.
143
+ - **Notion/Linear/GitHub MCP unreachable but configured as the story store.** Halt and ask the engineer to wire it; do not silently fall back to `hstack/stories/`.
144
+ - **`.gitignore` write refused.** The Skill cannot proceed past mini-session 7's incident-runbook step without it. Halt and surface the issue.
145
+
146
+ ## Anti-patterns
147
+
148
+ - Never write `hstack/config.yaml` silently from inferred defaults. Every field passes through the engineer's confirmation gate via the `product-manager` subagent.
149
+ - Never collapse the eight mini-sessions into one long block. The mini-session structure is the resumability contract.
150
+ - Never advance `init-status: complete` while any required context document is below `current`.
151
+ - Never write `incident-runbook.md` content to the conversation transcript more than necessary; the file's contents are sensitive and should be confirmed in summary form rather than pasted verbatim.
152
+ - Never re-interview a completed mini-session on resume. Read the disk; trust the prior commit.
@@ -0,0 +1,105 @@
1
+ ---
2
+ name: hstack-module-spec
3
+ description: |
4
+ Use this skill when an engineer needs a baseline `hstack/specs/<module>/spec.md` reverse-engineered for an existing module on a brownfield repo. Module-specs are foundational: every change-spec validates that `area` references an existing module-spec at `status: current`, and every per-change downstream subagent loads the relevant module-spec at session start. Examples:
5
+
6
+ <example>
7
+ Context: The team has just finished `hstack-init` and the engineer wants to produce a module-spec for the billing module before any change work begins there.
8
+ user: "Run /hstack:module-spec billing."
9
+ assistant: "I'll invoke spec-author with the billing paths from hstack/config.yaml, pack the module via RepoMix, and walk the seven module-spec sections through an interview."
10
+ <commentary>
11
+ Module-specs are the only artifact the `spec-author` reverse-engineers from existing code rather than authoring fresh. The Skill is run once per critical module on adoption; thereafter the spec is refreshed via `hstack-configure --interview` or by re-running this Skill when the cron flags it `needs-refresh`.
12
+ </commentary>
13
+ </example>
14
+
15
+ <example>
16
+ Context: A 60-day refresh cron has flagged `hstack/specs/orchestrator/spec.md` as `needs-refresh` because the orchestrator module has been heavily modified.
17
+ user: "Refresh the orchestrator module-spec."
18
+ assistant: "I'll re-run /hstack:module-spec orchestrator. The existing spec is the proposal layer; spec-author walks each section, confirming or correcting against the current code."
19
+ <commentary>
20
+ Refresh mode is idempotent — when the existing module-spec is read in as the proposal layer, sections that remain accurate produce a no-op confirmation and the timestamp updates without churning the body.
21
+ </commentary>
22
+ </example>
23
+ tools:
24
+ - Read
25
+ - Write
26
+ - Edit
27
+ - Grep
28
+ - Glob
29
+ - Bash
30
+ - Task
31
+ - "{{TODO-TOOL: RepoMix — packs the module slice (paths from hstack/config.yaml) into a single context bundle for spec-author}}"
32
+ - "{{TODO-SCRIPT: hstack/scripts/validate-spec.ts — validates module-spec frontmatter and MS-01/MS-02/MS-03}}"
33
+ ---
34
+
35
+ ## Purpose
36
+
37
+ `hstack-module-spec` produces a baseline `hstack/specs/<module>/spec.md` for one named module by orchestrating the `spec-author` subagent against a packed module slice. It is the one Skill where `spec-author` is permitted to grep the code in service of authorship — the module-spec is the system's anchor between its `area` controlled enum and the actual codebase, and a module-spec disconnected from real paths is worthless.
38
+
39
+ ## When to invoke
40
+
41
+ Invoke once per critical module after `hstack-init` completes, before any change-spec in that module's `area` can validate. Re-invoke when the 60-day `needs-refresh` cron flags the spec, when the module's shape materially changes (new owned table, new public surface, new dependency), or on demand when the engineer wants a refresh.
42
+
43
+ ## Inputs
44
+
45
+ - `<module>` (required, positional): the module key as declared in `hstack/config.yaml`'s module-to-area mapping. Must match an existing entry.
46
+
47
+ ## Preconditions
48
+
49
+ Before any work:
50
+
51
+ - Verify `hstack/config.yaml` exists at `init-status: complete`. If not, halt and direct the engineer to `hstack-init`.
52
+ - Verify the named module exists in the config's module-to-area mapping. If not, halt and ask the engineer to add it via `hstack-configure` first.
53
+ - Read the module's declared `paths` globs from config and verify at least one path resolves to existing files. If none resolve, halt — the module-to-paths mapping is stale.
54
+ - Check whether `hstack/specs/<module>/spec.md` already exists. If yes and at `status: current`, ask the engineer whether this is a refresh (proceed with the existing spec as the proposal layer) or a re-author (archive the existing spec first).
55
+ - Read `hstack/context/glossary.md` and `hstack/context/tech-stack.md` (required by `spec-author`'s session-start protocol).
56
+
57
+ ## Orchestration steps
58
+
59
+ 1. **Pack the module slice.** Run `{{TODO-TOOL: RepoMix}}` over the module's `paths` globs and write the packed bundle to a temporary location. If RepoMix is unavailable, fall back to having `spec-author` grep the paths directly; flag the degraded read in the conversation.
60
+
61
+ 2. **Invoke `spec-author`.** Use the Task tool with `subagent_type: spec-author` and context = [kernel, `hstack/templates/module-spec.md`, glossary, tech-stack, packed module bundle, existing module-spec instance if refresh]. The subagent reads the bundle, walks the seven module-spec sections — Purpose, Public Surface, Data Owned, External Dependencies, Invariants, Known Tech-Debt and ADRs, Refresh Policy — with confirmation gates per field.
62
+
63
+ 3. **Exercise the Invariants challenge prompt.** Per the `spec-author` contract and MS-03, the Invariants section requires a minimum of three bullets, elicited via the challenge "What would a careless refactor in this module break that the tests would not catch?" The Skill does not bypass this even on refresh.
64
+
65
+ 4. **Validate.** After each confirmed field write, the subagent runs `{{TODO-SCRIPT: hstack/scripts/validate-spec.ts}}` against the in-progress file. The Skill verifies MS-01 (paths non-empty and resolve), MS-02 (no overlap with other module-specs' paths — important to surface mis-aligned module-to-paths mapping), MS-03 (Invariants ≥ 3 bullets).
66
+
67
+ 5. **Transition to `status: current`.** When every section is confirmed and the validator passes, `spec-author` advances status from `drafted` to `current` and updates `last-refreshed` to today. Auto-commit fires.
68
+
69
+ ## Outputs
70
+
71
+ - `hstack/specs/<module>/spec.md` at `status: current`, with frontmatter including the module's `paths` array mirrored from `hstack/config.yaml`.
72
+
73
+ ## Auto-commit triggers
74
+
75
+ - Status moves from absent to `drafted` after the first section is confirmed (so partial work survives).
76
+ - Status moves from `drafted` to `current` when the full spec lands. Commit message: `module-spec(<module>): draft baseline` or `module-spec(<module>): refresh` depending on prior state.
77
+
78
+ ## Idempotency contract
79
+
80
+ - Re-running on a `current` module-spec without specifying refresh intent: the Skill detects the existing spec and asks the engineer whether to refresh.
81
+ - Re-running mid-authoring after a halt: `spec-author` reads the partial file, identifies the first un-confirmed section, and resumes the interview there.
82
+ - Re-running on a refresh where the engineer accepts every section unchanged: a no-op diff body with only the `updated` and `last-refreshed` timestamps changing.
83
+
84
+ ## Stop conditions
85
+
86
+ Beyond the kernel's general stop conditions:
87
+
88
+ - The module's `paths` globs resolve to zero existing files. Halt; the module-to-paths mapping in config is wrong.
89
+ - MS-02 fails — the module's paths overlap with another module's paths. Halt and ask the engineer to reconcile the mapping via `hstack-configure`.
90
+ - The Invariants challenge prompt cannot produce three bullets after honest interview. Halt; either the module is too small to merit its own spec (fold into a parent module via `hstack-configure`) or the engineer needs more time to think.
91
+ - `spec-author` halts because a referenced glossary term cannot be reconciled. Halt and surface; the engineer either updates the glossary via `hstack-configure --interview glossary` or rephrases.
92
+
93
+ ## Failure modes
94
+
95
+ - **RepoMix unavailable.** Degraded mode — flag in the conversation, fall back to direct grep, continue.
96
+ - **Existing module-spec frontmatter does not match config's paths.** Halt; the engineer reconciles before the refresh can proceed.
97
+ - **Validator failure on a partial write.** `spec-author` halts at the field; the Skill surfaces the validator's message and waits.
98
+
99
+ ## Anti-patterns
100
+
101
+ - Never invent paths. The module's `paths` come from `hstack/config.yaml`; the Skill never edits them and never substitutes.
102
+ - Never skip the Invariants challenge. Three-or-more bullets is a hard validator rule, not a heuristic.
103
+ - Never run this Skill against a module that does not appear in the config. The right move is to add the module to config first.
104
+ - Never overwrite an existing `current` module-spec without explicit refresh-or-re-author confirmation from the engineer.
105
+ - Never write code. `spec-author` is the only subagent invoked, and it reads code without modifying it.