spec-manager 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 (159) hide show
  1. package/AGENTS.md +27 -0
  2. package/CODEBUDDY.md +19 -0
  3. package/LICENSE +21 -0
  4. package/README.md +531 -0
  5. package/dist/cli/audit.d.ts +10 -0
  6. package/dist/cli/audit.d.ts.map +1 -0
  7. package/dist/cli/audit.js +62 -0
  8. package/dist/cli/audit.js.map +1 -0
  9. package/dist/cli/change.d.ts +10 -0
  10. package/dist/cli/change.d.ts.map +1 -0
  11. package/dist/cli/change.js +103 -0
  12. package/dist/cli/change.js.map +1 -0
  13. package/dist/cli/common.d.ts +5 -0
  14. package/dist/cli/common.d.ts.map +1 -0
  15. package/dist/cli/common.js +17 -0
  16. package/dist/cli/common.js.map +1 -0
  17. package/dist/cli/decision.d.ts +13 -0
  18. package/dist/cli/decision.d.ts.map +1 -0
  19. package/dist/cli/decision.js +185 -0
  20. package/dist/cli/decision.js.map +1 -0
  21. package/dist/cli/dict.d.ts +10 -0
  22. package/dist/cli/dict.d.ts.map +1 -0
  23. package/dist/cli/dict.js +73 -0
  24. package/dist/cli/dict.js.map +1 -0
  25. package/dist/cli/incident.d.ts +10 -0
  26. package/dist/cli/incident.d.ts.map +1 -0
  27. package/dist/cli/incident.js +119 -0
  28. package/dist/cli/incident.js.map +1 -0
  29. package/dist/cli/index.d.ts +3 -0
  30. package/dist/cli/index.d.ts.map +1 -0
  31. package/dist/cli/index.js +30 -0
  32. package/dist/cli/index.js.map +1 -0
  33. package/dist/cli/project.d.ts +3 -0
  34. package/dist/cli/project.d.ts.map +1 -0
  35. package/dist/cli/project.js +144 -0
  36. package/dist/cli/project.js.map +1 -0
  37. package/dist/cli/spec.d.ts +3 -0
  38. package/dist/cli/spec.d.ts.map +1 -0
  39. package/dist/cli/spec.js +289 -0
  40. package/dist/cli/spec.js.map +1 -0
  41. package/dist/cli/task.d.ts +14 -0
  42. package/dist/cli/task.d.ts.map +1 -0
  43. package/dist/cli/task.js +287 -0
  44. package/dist/cli/task.js.map +1 -0
  45. package/dist/cli/usability.d.ts +3 -0
  46. package/dist/cli/usability.d.ts.map +1 -0
  47. package/dist/cli/usability.js +153 -0
  48. package/dist/cli/usability.js.map +1 -0
  49. package/dist/core/agents.d.ts +43 -0
  50. package/dist/core/agents.d.ts.map +1 -0
  51. package/dist/core/agents.js +194 -0
  52. package/dist/core/agents.js.map +1 -0
  53. package/dist/core/archive.d.ts +35 -0
  54. package/dist/core/archive.d.ts.map +1 -0
  55. package/dist/core/archive.js +360 -0
  56. package/dist/core/archive.js.map +1 -0
  57. package/dist/core/audit-events.d.ts +12 -0
  58. package/dist/core/audit-events.d.ts.map +1 -0
  59. package/dist/core/audit-events.js +16 -0
  60. package/dist/core/audit-events.js.map +1 -0
  61. package/dist/core/audit.d.ts +78 -0
  62. package/dist/core/audit.d.ts.map +1 -0
  63. package/dist/core/audit.js +157 -0
  64. package/dist/core/audit.js.map +1 -0
  65. package/dist/core/constants.d.ts +28 -0
  66. package/dist/core/constants.d.ts.map +1 -0
  67. package/dist/core/constants.js +30 -0
  68. package/dist/core/constants.js.map +1 -0
  69. package/dist/core/decision.d.ts +69 -0
  70. package/dist/core/decision.d.ts.map +1 -0
  71. package/dist/core/decision.js +210 -0
  72. package/dist/core/decision.js.map +1 -0
  73. package/dist/core/delta.d.ts +85 -0
  74. package/dist/core/delta.d.ts.map +1 -0
  75. package/dist/core/delta.js +264 -0
  76. package/dist/core/delta.js.map +1 -0
  77. package/dist/core/dict.d.ts +28 -0
  78. package/dist/core/dict.d.ts.map +1 -0
  79. package/dist/core/dict.js +57 -0
  80. package/dist/core/dict.js.map +1 -0
  81. package/dist/core/frontmatter.d.ts +19 -0
  82. package/dist/core/frontmatter.d.ts.map +1 -0
  83. package/dist/core/frontmatter.js +57 -0
  84. package/dist/core/frontmatter.js.map +1 -0
  85. package/dist/core/incident.d.ts +45 -0
  86. package/dist/core/incident.d.ts.map +1 -0
  87. package/dist/core/incident.js +128 -0
  88. package/dist/core/incident.js.map +1 -0
  89. package/dist/core/paths.d.ts +68 -0
  90. package/dist/core/paths.d.ts.map +1 -0
  91. package/dist/core/paths.js +162 -0
  92. package/dist/core/paths.js.map +1 -0
  93. package/dist/core/repository.d.ts +13 -0
  94. package/dist/core/repository.d.ts.map +1 -0
  95. package/dist/core/repository.js +29 -0
  96. package/dist/core/repository.js.map +1 -0
  97. package/dist/core/spec-io.d.ts +125 -0
  98. package/dist/core/spec-io.d.ts.map +1 -0
  99. package/dist/core/spec-io.js +260 -0
  100. package/dist/core/spec-io.js.map +1 -0
  101. package/dist/core/status.d.ts +22 -0
  102. package/dist/core/status.d.ts.map +1 -0
  103. package/dist/core/status.js +54 -0
  104. package/dist/core/status.js.map +1 -0
  105. package/dist/core/task.d.ts +118 -0
  106. package/dist/core/task.d.ts.map +1 -0
  107. package/dist/core/task.js +340 -0
  108. package/dist/core/task.js.map +1 -0
  109. package/dist/core/usability.d.ts +25 -0
  110. package/dist/core/usability.d.ts.map +1 -0
  111. package/dist/core/usability.js +136 -0
  112. package/dist/core/usability.js.map +1 -0
  113. package/dist/core/validate.d.ts +34 -0
  114. package/dist/core/validate.d.ts.map +1 -0
  115. package/dist/core/validate.js +195 -0
  116. package/dist/core/validate.js.map +1 -0
  117. package/dist/index.d.ts +11 -0
  118. package/dist/index.d.ts.map +1 -0
  119. package/dist/index.js +12 -0
  120. package/dist/index.js.map +1 -0
  121. package/dist/schemas/change.d.ts +138 -0
  122. package/dist/schemas/change.d.ts.map +1 -0
  123. package/dist/schemas/change.js +38 -0
  124. package/dist/schemas/change.js.map +1 -0
  125. package/dist/schemas/spec.d.ts +233 -0
  126. package/dist/schemas/spec.d.ts.map +1 -0
  127. package/dist/schemas/spec.js +56 -0
  128. package/dist/schemas/spec.js.map +1 -0
  129. package/package.json +66 -0
  130. package/rules/_TEMPLATE.md +20 -0
  131. package/rules/code-discipline.md +47 -0
  132. package/rules/codebase-survey.md +37 -0
  133. package/rules/delta.md +42 -0
  134. package/rules/doc-governance.md +195 -0
  135. package/rules/flow-control.md +65 -0
  136. package/rules/quality-gate.md +73 -0
  137. package/skill/SKILL.md +90 -0
  138. package/skill/subskills/adr.md +73 -0
  139. package/skill/subskills/change.md +118 -0
  140. package/skill/subskills/design.md +53 -0
  141. package/skill/subskills/impl.md +100 -0
  142. package/skill/subskills/plan.md +46 -0
  143. package/skill/subskills/postmortem.md +77 -0
  144. package/skill/subskills/prd.md +72 -0
  145. package/skill/subskills/quick.md +25 -0
  146. package/skill/subskills/release.md +50 -0
  147. package/skill/subskills/research.md +35 -0
  148. package/skill/subskills/runbook.md +44 -0
  149. package/skill/subskills/testplan.md +48 -0
  150. package/templates/L0-prd.md +43 -0
  151. package/templates/L1-prd.md +130 -0
  152. package/templates/L2-design.md +135 -0
  153. package/templates/L3-impl.md +125 -0
  154. package/templates/agent-plan.json +17 -0
  155. package/templates/agents/AGENTS.md +27 -0
  156. package/templates/agents/CLAUDE.md +11 -0
  157. package/templates/agents/CODEBUDDY.md +23 -0
  158. package/templates/agents/codebuddy-skill/SKILL.md +46 -0
  159. package/templates/decision.md +42 -0
package/AGENTS.md ADDED
@@ -0,0 +1,27 @@
1
+ # spec-manager Workflow Capsule
2
+
3
+ This file is the spec-manager skill-like entrypoint for Codex, OpenCode, and other `AGENTS.md`-compatible tools. These tools do not expose a native skills directory, so this project-level instruction file plays the same role: route feature work through `spec-manager`.
4
+
5
+ This project uses `spec-manager` for local-first spec-driven development. Specs, tasks, decisions, changes, and audit data are stored as markdown/JSON files in the repository.
6
+
7
+ ## Mandatory Workflow
8
+
9
+ - Feature work MUST go through `spec-manager`; do not jump directly from a user request to implementation code.
10
+ - New or non-trivial work follows L1 PRD -> L2 Design -> L3 Impl -> Agent Task.
11
+ - Never write implementation code unless the relevant L3 spec is `frozen`.
12
+ - `draft -> confirmed` and `confirmed -> frozen` are user review actions. After writing spec content, stop and wait for explicit user approval.
13
+ - Before creating a new spec, inspect existing specs and decisions with `spec-manager spec list` and `spec-manager decision list --topic <topic>`.
14
+ - Before code edits, read the relevant frozen L3 spec and create/start an Agent Task.
15
+ - Record execution with `spec-manager task step`; finish with `spec-manager task complete`.
16
+
17
+ ## Common Commands
18
+
19
+ ```bash
20
+ spec-manager project status
21
+ spec-manager spec list
22
+ spec-manager spec show <code> --include-content
23
+ spec-manager decision list --topic <topic>
24
+ spec-manager task list --topic <topic>
25
+ ```
26
+
27
+ When the user asks for `/spec-manager <request>` or asks to use spec-manager, treat it as a request to follow this workflow.
package/CODEBUDDY.md ADDED
@@ -0,0 +1,19 @@
1
+ # Spec-Driven Development
2
+
3
+ This repository uses `spec-manager`. CodeBuddy should follow the same workflow as `AGENTS.md` and use spec-manager commands for non-trivial work.
4
+
5
+ - All feature work should go through `spec-manager`.
6
+ - New work follows L1 PRD -> L2 Design -> L3 Impl -> Agent Task.
7
+ - Never write implementation code without a frozen L3 spec.
8
+ - `confirm` and `freeze` are user review actions.
9
+
10
+ ## Commands
11
+
12
+ ```bash
13
+ npm run build
14
+ npm run lint
15
+ npm test
16
+ spec-manager project status
17
+ ```
18
+
19
+ Use `src/cli/` for command registrations and `src/core/` for business logic.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 loki
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,531 @@
1
+ # spec-manager
2
+
3
+ [![npm version](https://img.shields.io/npm/v/spec-manager)](https://www.npmjs.com/package/spec-manager)
4
+ [![CI](https://github.com/loki-ai-ch/spec-manager/actions/workflows/ci.yml/badge.svg)](https://github.com/loki-ai-ch/spec-manager/actions/workflows/ci.yml)
5
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
6
+
7
+ [Chinese version](readme_zh.md)
8
+
9
+ **Local-first spec-driven development platform.** Pure markdown + git storage. No network, no MCP, no backend.
10
+
11
+ ---
12
+
13
+ ## What it does
14
+
15
+ - **Four-layer funnel** — Requirements → Design → Implementation → Continuity, with human review gates at each layer
16
+ - **L0/L1/L2/L3 spec hierarchy** — vision / PRD / design / implementation spec
17
+ - **24 rules** with `applies_to` filtering — no need to load all 24 every time
18
+ - **Status machine** `draft → confirmed → frozen → implemented`
19
+ - **Agent Task lifecycle** — `create → start → step → complete`, steps in spec frontmatter; R5 blocks complete if steps are skipped
20
+ - **Decision cards** with `what/why/affectedCriteria` + topic query
21
+ - **Rule audit** with at-least-once local JSON accumulator
22
+ - **Delta specs** (OpenSpec-style `changes/<name>/` with ADDED/MODIFIED/REMOVED/RENAMED + archive merge)
23
+ - **Multi-agent setup** — one command installs Claude Code, Codex, OpenCode, and CodeBuddy instructions
24
+ - **RFC 2119** keywords (SHALL/MUST/SHOULD) validation in acceptance criteria
25
+ - **Incident tracking** — rule violations drive rule evolution
26
+
27
+ > Full methodology: [docs/methodology.md](docs/methodology.md)
28
+
29
+ ## Install
30
+
31
+ ```bash
32
+ # Clone and install globally
33
+ git clone https://github.com/loki-ai-ch/spec-manager.git
34
+ cd spec-manager
35
+ npm install
36
+ npm run build
37
+ npm install -g .
38
+
39
+ # Or run without installing
40
+ npx spec-manager <command>
41
+ ```
42
+
43
+ ## AI Agent Setup
44
+
45
+ spec-manager is agent-agnostic: the CLI stores the source of truth locally, and AI tools only need a workflow entrypoint that enforces the same rules. Built-in setup supports Claude Code, Codex, OpenCode, CodeBuddy, and other `AGENTS.md`-compatible agents.
46
+
47
+ Not every tool has a native "skills" directory. spec-manager installs the closest equivalent for each platform: real skills where the platform supports them, and a project-level `AGENTS.md` workflow capsule where it does not.
48
+
49
+ ### Recommended
50
+
51
+ ```bash
52
+ cd my-project
53
+ spec-manager project init --name my-project
54
+ spec-manager project agents --provider all
55
+ ```
56
+
57
+ This writes:
58
+
59
+ | Provider | spec-manager entrypoint | Files |
60
+ |---|---|---|
61
+ | Claude Code | Native skill | `CLAUDE.md`, `.claude/skills/spec-manager/` |
62
+ | Codex | `AGENTS.md` workflow capsule, not a native skill | `AGENTS.md` |
63
+ | OpenCode | `AGENTS.md` workflow capsule, not a native skill | `AGENTS.md` |
64
+ | CodeBuddy | Native skill | `CODEBUDDY.md`, `.codebuddy/skills/spec-manager/` |
65
+
66
+ Use a narrower install when needed:
67
+
68
+ ```bash
69
+ spec-manager project agents --provider list
70
+ spec-manager project agents --provider all --dry-run
71
+ spec-manager project agents --provider codex,opencode
72
+ spec-manager project agents --provider codebuddy --force
73
+ ```
74
+
75
+ Use `--dry-run` to preview created, overwritten, and skipped files before touching the project.
76
+
77
+ References: [Codex `AGENTS.md`](https://github.com/openai/codex/blob/main/docs/agents_md.md), [OpenCode rules](https://opencode.ai/docs/rules/), [CodeBuddy skills](https://www.codebuddy.ai/docs/cli/skills).
78
+
79
+ For Codex CLI, do not look for a `skills` command or directory. Run Codex from the project root and it will read `AGENTS.md`. Ask it to "Use spec-manager ..." and the file acts as the spec-manager workflow entrypoint.
80
+
81
+ ### Manual install
82
+
83
+ If you do not want to use the installer, copy the templates directly:
84
+
85
+ ```bash
86
+ # Codex / OpenCode / AGENTS.md-compatible tools (skill-like workflow capsule)
87
+ cp path/to/spec-manager/templates/agents/AGENTS.md my-project/AGENTS.md
88
+
89
+ # Claude Code
90
+ mkdir -p my-project/.claude/skills/spec-manager
91
+ cp -r path/to/spec-manager/skill/* my-project/.claude/skills/spec-manager/
92
+ cp -r path/to/spec-manager/rules my-project/.claude/skills/spec-manager/rules
93
+ cp -r path/to/spec-manager/templates my-project/.claude/skills/spec-manager/templates
94
+ cp path/to/spec-manager/templates/agents/CLAUDE.md my-project/CLAUDE.md
95
+
96
+ # CodeBuddy
97
+ mkdir -p my-project/.codebuddy/skills/spec-manager
98
+ cp -r path/to/spec-manager/skill/subskills my-project/.codebuddy/skills/spec-manager/subskills
99
+ cp -r path/to/spec-manager/rules my-project/.codebuddy/skills/spec-manager/rules
100
+ cp -r path/to/spec-manager/templates my-project/.codebuddy/skills/spec-manager/templates
101
+ cp path/to/spec-manager/templates/agents/CODEBUDDY.md my-project/CODEBUDDY.md
102
+ cp path/to/spec-manager/templates/agents/codebuddy-skill/SKILL.md my-project/.codebuddy/skills/spec-manager/SKILL.md
103
+ ```
104
+
105
+ ### Start iterating
106
+
107
+ ```bash
108
+ # Claude Code / CodeBuddy skill:
109
+ /spec-manager add user authentication feature
110
+
111
+ # Codex / OpenCode / other AGENTS.md agents:
112
+ Use spec-manager to add user authentication feature.
113
+ ```
114
+
115
+ The AI will follow the L1→L2→L3→Task pipeline with human review gates at each layer. See [rules/](rules/) for the full 24-rule set.
116
+
117
+ ## Quick start
118
+
119
+ ```bash
120
+ cd my-project
121
+ spec-manager project init --name my-project
122
+ spec-manager project agents --provider all
123
+ spec-manager spec new L1 --topic auth --title "User authentication" # auto-generates auth-L1
124
+ # write the body to ./l1.md, then:
125
+ spec-manager spec update auth-L1 --content ./l1.md \
126
+ --ai-summary "OAuth 2.0 + JWT, 3 endpoints" --change-summary "Initial L1"
127
+ # wait for user review
128
+ spec-manager spec confirm <code>
129
+ # L2/L3 follow the same shape: spec new L2 --parent <L1 code>
130
+ ```
131
+
132
+ Or use an AI agent configured with spec-manager:
133
+
134
+ ```bash
135
+ /spec-manager add user authentication feature
136
+ ```
137
+
138
+ ## Easier workflows
139
+
140
+ For day-to-day use, these helper commands reduce command memorization:
141
+
142
+ ```bash
143
+ spec-manager project doctor # check setup, agent files, skill assets, placeholders, audit
144
+ spec-manager flow status --topic auth # show L1/L2/L3/Task progress and the next command
145
+ spec-manager guide "add user auth" # print the next useful step for a request
146
+ spec-manager new feature --topic auth "User authentication"
147
+ spec-manager approve auth-L1 # draft→confirmed, or L3 confirmed→frozen
148
+ spec-manager run auth-L3.1.1 --plan ./plan.json
149
+ spec-manager template L1 --title "User authentication" > l1.md
150
+ ```
151
+
152
+ Long-form commands remain available; the shortcuts only wrap the same rules and state machine.
153
+
154
+ | Command | Use it when | What it gives you |
155
+ |---|---|---|
156
+ | `project doctor` | You are unsure whether the project is ready | Setup checks plus concrete fix commands |
157
+ | `flow status` | You need to know where a topic is blocked | L1/L2/L3/Task state and the next command |
158
+ | `guide` | You have a request but do not know which command starts it | The next useful step without changing files |
159
+ | `new feature` | You want the fastest safe way to start an L1 | Creates the L1 shell and prints the next update command |
160
+ | `approve` | The user has explicitly approved a spec | Advances `draft→confirmed` or `L3 confirmed→frozen` |
161
+ | `run` | A frozen L3 is ready to execute | Creates and starts the task from a plan file |
162
+ | `template` | You need a draft file for L1/L2/L3 or `agent-plan` | Prints or writes the bundled template |
163
+
164
+ Examples:
165
+
166
+ ```bash
167
+ spec-manager project doctor
168
+ spec-manager flow status --topic auth
169
+ spec-manager template L2 --title "Invoice module" --output l2.md
170
+ spec-manager guide "add billing export"
171
+ ```
172
+
173
+ ## Usage scenarios
174
+
175
+ ### 1. Quick fix (typo / one-line change)
176
+
177
+ ```bash
178
+ spec-manager spec show <code> --include-content # read current spec
179
+ # edit the file directly, then:
180
+ spec-manager spec update <code> --content ./fixed.md --ai-summary "fix typo in AC-2" --change-summary "typo fix"
181
+ ```
182
+
183
+ ### 2. Research (browse existing specs)
184
+
185
+ ```bash
186
+ spec-manager spec list # all specs
187
+ spec-manager spec list --level L1 --status confirmed # filtered
188
+ spec-manager spec show <code> # metadata only (R19)
189
+ spec-manager decision list --topic auth # decision history
190
+ ```
191
+
192
+ ### 3. Full feature (L1 → L2 → L3 → Task)
193
+
194
+ ```bash
195
+ spec-manager spec new L1 --topic billing --title "Billing system"
196
+ spec-manager spec update <l1-code> --content ./l1.md --ai-summary "..." --change-summary "init"
197
+ spec-manager spec confirm <l1-code> # user reviews
198
+
199
+ spec-manager spec new L2 --topic billing --title "Invoice module" --parent <l1-code>
200
+ spec-manager spec update <l2-code> --content ./l2.md --ai-summary "..." --change-summary "init"
201
+ spec-manager spec confirm <l2-code>
202
+
203
+ spec-manager spec new L3 --topic billing --title "PDF generation" --parent <l2-code>
204
+ spec-manager spec update <l3-code> --content ./l3.md --ai-summary "..." --change-summary "init"
205
+ spec-manager spec confirm <l3-code>
206
+ spec-manager spec freeze <l3-code> # frozen → can create task
207
+
208
+ spec-manager task create <l3-code> --plan ./plan.json --auto-confirm
209
+ spec-manager task start T-001
210
+ spec-manager task step T-001 --no 1 --status succeeded --output-json '{"summary":"..."}'
211
+ spec-manager task complete T-001 # cascades L3→L2→L1
212
+ ```
213
+
214
+ ### 4. Delta change (modify shipped spec)
215
+
216
+ ```bash
217
+ spec-manager change new add-2fa --description "Add 2FA"
218
+ # edit changes/add-2fa/proposal.md + deltas/<code>.md
219
+ spec-manager change archive add-2fa # applies & archives
220
+ ```
221
+
222
+ ### 5. Postmortem (incident review)
223
+
224
+ ```bash
225
+ spec-manager incident new --severity high --rule R5 --spec <code>
226
+ # fill in .spec-manager/incidents/INC-*.md
227
+ spec-manager incident list
228
+ ```
229
+
230
+ ## Tutorial — end-to-end feature
231
+
232
+ A realistic walk-through of taking a feature from idea to shipped code, using a "user authentication" feature as the running example. Each step maps to one CLI invocation plus a human review gate.
233
+
234
+ ### 1. Initialize the project
235
+
236
+ ```bash
237
+ mkdir my-project && cd my-project
238
+ git init
239
+ spec-manager project init --name my-project
240
+ ```
241
+
242
+ This creates `.spec-manager/` (config + audit + incidents). Add `.spec-manager/audit.json` to `.gitignore` if you don't want the audit log in commits — or commit it, your call.
243
+
244
+ ### 2. Write an L1 PRD (what & why)
245
+
246
+ ```bash
247
+ spec-manager spec new L1 --topic auth --title "User authentication"
248
+ # → outputs: code auth-L1, file specs/auth/auth-L1.md
249
+ ```
250
+
251
+ Before writing the L1 body, the agent should ask 3-4 PRE-WRITE questions (see `templates/L1-prd.md`): who is the user, what's the success metric, what's explicitly out of scope, and — if there's an active decision card on this topic — whether the new spec is consistent with it (`spec-manager decision list --topic auth`).
252
+
253
+ Then write the L1 body to a draft file and update:
254
+
255
+ ```bash
256
+ cat > /tmp/auth-l1.md <<'EOF'
257
+ # User authentication — L1 PRD
258
+
259
+ ## Background
260
+ ... (user stories, MoSCoW ranking, acceptance criteria, scope boundaries)
261
+
262
+ EOF
263
+
264
+ spec-manager spec update auth-L1 \
265
+ --content /tmp/auth-l1.md \
266
+ --ai-summary "OAuth 2.0 + JWT, 3 endpoints: /login /refresh /me" \
267
+ --change-summary "Initial L1"
268
+ ```
269
+
270
+ `update` automatically runs warning-only validation (required sections + RFC 2119 keywords). **Don't advance the status yet** — `update` leaves it as `draft`.
271
+
272
+ ### 3. Confirm the L1 (user approval gate)
273
+
274
+ ```bash
275
+ spec-manager spec confirm auth-L1
276
+ # status: draft → confirmed
277
+ ```
278
+
279
+ The user reviews the L1 body (`spec show auth-L1 --include-content`) and approves. Only then do you proceed to L2.
280
+
281
+ ### 4. Write an L2 design (how)
282
+
283
+ L2s are scoped 1:1 or 1:2 against their L1, split by module boundary, not feature. Each L2 must bind to a parent L1.
284
+
285
+ ```bash
286
+ spec-manager spec new L2 --topic auth --title "OAuth 2.0 backend design" --parent auth-L1
287
+ # → outputs: code auth-L2.1
288
+
289
+ # write L2 body (technical approach, module boundaries, interface contracts, L3 breakdown)
290
+ cat > /tmp/auth-l2.md <<'EOF'
291
+ # OAuth 2.0 backend design — L2
292
+
293
+ ## Approach
294
+ ...
295
+
296
+ ## Interface contract
297
+ | Endpoint | Method | Input | Output | Error codes |
298
+ |---|---|---|---|---|
299
+ | /login | POST | {email, password} | {accessToken, refreshToken} | 401 |
300
+
301
+ ## L3 breakdown
302
+ | L3 code | Scope | Prerequisite |
303
+ |---|---|---|
304
+ | auth-L3.1.1-jwt | JWT signing module | none |
305
+ | auth-L3.1.2-refresh | Refresh token module | auth-L3.1.1-jwt implemented |
306
+ EOF
307
+
308
+ spec-manager spec update auth-L2.1 \
309
+ --content /tmp/auth-l2.md \
310
+ --ai-summary "JWT sign/verify, refresh rotation, 3 endpoints" \
311
+ --change-summary "Initial L2"
312
+ ```
313
+
314
+ User reviews → `spec confirm auth-L2.1`.
315
+
316
+ ### 5. Write L3 implementation specs (precise steps)
317
+
318
+ ```bash
319
+ spec-manager spec new L3 --topic auth --title "JWT signing module" --parent auth-L2.1 --desc jwt
320
+ # → outputs: code auth-L3.1.1-jwt
321
+ ```
322
+
323
+ L3 is where implementation precision lives: file paths, function signatures, planJson steps. Build the planJson as a separate file:
324
+
325
+ ```bash
326
+ cat > /tmp/jwt-plan.json <<'EOF'
327
+ {
328
+ "coveredSpecs": ["auth-L3.1.1-jwt"],
329
+ "steps": [
330
+ {"stepNo": 1, "stepType": "mcp_tool", "name": "Read parent L2 + sibling L1 historical spec, confirm no duplicate implementation"},
331
+ {"stepNo": 2, "stepType": "mcp_tool", "name": "Create src/auth/jwt.ts implementing signJwt(payload, secret, ttl)"},
332
+ {"stepNo": 3, "stepType": "mcp_tool", "name": "Create src/auth/__tests__/jwt.test.ts covering sign + verify + expiry"},
333
+ {"stepNo": 4, "stepType": "mcp_tool", "name": "Verify: pnpm test src/auth/jwt.test.ts reports 0 failures"}
334
+ ]
335
+ }
336
+ EOF
337
+
338
+ # validate the planJson before committing to the L3
339
+ spec-manager spec validate-plan /tmp/jwt-plan.json
340
+
341
+ # write L3 body referencing the plan
342
+ cat > /tmp/jwt-l3.md <<'EOF'
343
+ # JWT signing module — L3
344
+
345
+ ## Goal
346
+ Implements the "JWT signing" part of auth-L2.1's deliverables 1/2/3.
347
+
348
+ ## Implementation steps
349
+ See /tmp/jwt-plan.json (4 steps; the last step must be a verification).
350
+ EOF
351
+
352
+ spec-manager spec update auth-L3.1.1-jwt \
353
+ --content /tmp/jwt-l3.md \
354
+ --ai-summary "signJwt/verifyJwt functions + unit tests + 4-step planJson" \
355
+ --change-summary "Initial L3"
356
+ ```
357
+
358
+ L3 needs two confirmations: `spec confirm auth-L3.1.1-jwt`, then `spec freeze auth-L3.1.1-jwt`. `frozen` is the prerequisite for creating an Agent Task.
359
+
360
+ ### 6. Create and run the Agent Task
361
+
362
+ ```bash
363
+ spec-manager task create auth-L3.1.1-jwt --plan /tmp/jwt-plan.json --auto-confirm
364
+ # → outputs: taskId T-001, file specs/auth/tasks/auth-L3.1.1-jwt-T-001.json
365
+
366
+ spec-manager task start T-001 --spec auth-L3.1.1-jwt
367
+ # step 1
368
+ spec-manager task step T-001 --spec auth-L3.1.1-jwt --no 1 --type mcp_tool --name "Context gathering" \
369
+ --status succeeded --output-json '{"summary":"read L2 + L1","read":["auth-L2.1"]}' --latency 1200
370
+ # ... repeat for each step
371
+
372
+ spec-manager task complete T-001 --spec auth-L3.1.1-jwt
373
+ # → L3 status: frozen → implemented
374
+ # → if all L3 children of L2 are implemented: L2 cascades to implemented
375
+ # → if all L2 children of L1 are implemented: L1 cascades to implemented
376
+ ```
377
+
378
+ `task step` is the per-step report (with required `outputJson` per R15); `task complete` triggers the cascade — it never goes the other way (R2).
379
+
380
+ ### 7. Record a decision card (R18: L1 implemented)
381
+
382
+ Once the L1 is `implemented`, you MUST record at least one decision card capturing the key what/why:
383
+
384
+ ```bash
385
+ spec-manager decision create auth-L1 \
386
+ --topic auth \
387
+ --what "Adopt JWT over session" \
388
+ --why "Stateless scaling, easier to share identity across services" \
389
+ --criteria "AC-1,AC-2"
390
+ # → outputs: DC-001
391
+ ```
392
+
393
+ `task complete` automatically prints an R18 checklist for any L1 that just cascaded to `implemented` — for each, it shows whether a decision card already exists and the exact CLI commands to create one (and `audit hit R18` to record the check).
394
+
395
+ ```text
396
+ ⚠ R18 (decision cards): these L1s just cascaded to implemented — verify a card exists:
397
+ ✗ auth-L1 [auth] — pending
398
+ spec-manager decision create auth-L1 \
399
+ --topic auth --what "..." --why "..." --criteria AC-1,AC-2
400
+ spec-manager audit hit R18 --spec auth-L1
401
+ ✓ billing-L1 [billing] — 2 cards (active: 2)
402
+ spec-manager audit hit R18 --spec billing-L1
403
+ ```
404
+
405
+ **Query decisions** by topic or by AC reference (AC-7 — track which requirements have changed and why):
406
+
407
+ ```bash
408
+ spec-manager decision list --topic auth
409
+ # ● DC-001 [auth] Adopt JWT over session {AC-1,AC-2}
410
+ # ● DC-002 [auth] Use refresh-token rotation
411
+
412
+ spec-manager decision list --criteria AC-1 --include-all
413
+ # ● DC-001 [auth] Adopt JWT over session
414
+ # ○ DC-003 [auth] Switch to PASETO (superseded by DC-005)
415
+ # ◐ DC-004 [auth] Skip refresh-token (partial — see INC-20260604-001)
416
+ ```
417
+
418
+ **Lifecycle** — three states, one transition path:
419
+
420
+ | From | To | Command | When |
421
+ |---|---|---|---|
422
+ | active | superseded | `decision supersede DC-001 --by DC-005` | new decision fully replaces old |
423
+ | active | partial | `decision set-partial DC-004 --reason "INC-...:AC-3 assumption no longer holds"` | part of the decision is no longer valid |
424
+ | (any) | (deleted) | `decision delete DC-001` | only if `active`; otherwise recover first |
425
+
426
+ **Edit** a card's `what`/`why`/`affectedCriteria` without changing its status:
427
+
428
+ ```bash
429
+ spec-manager decision update DC-001 \
430
+ --what "Adopt JWT with short TTL + refresh-token rotation" \
431
+ --criteria "AC-1,AC-2,AC-3"
432
+ ```
433
+
434
+ Use the [template](templates/decision.md) when writing the body manually (the CLI auto-renders this format).
435
+
436
+ ### 8. Modify an existing spec (delta change)
437
+
438
+ When you need to change an already-shipped spec, use a change proposal — never edit the spec body directly:
439
+
440
+ ```bash
441
+ spec-manager change new add-2fa --description "Add 2FA two-factor authentication"
442
+ # → creates changes/add-2fa/ (proposal.md + deltas/ + specs/)
443
+
444
+ # 1. edit changes/add-2fa/proposal.md (why + scope + risk)
445
+ # 2. write changes/add-2fa/deltas/<code>.md with ## MODIFIED Requirements
446
+ # 3. if ADDED, drop a placeholder at changes/add-2fa/specs/<topic>/<code>/<code>.md
447
+
448
+ spec-manager change archive add-2fa
449
+ # applies RENAMED→REMOVED→MODIFIED→ADDED in order, then moves changes/add-2fa/ to archive/
450
+ ```
451
+
452
+ This gives you a full audit trail: who proposed what, when, and what the spec looked like before the change.
453
+
454
+ ## Common commands
455
+
456
+ | Command | What it does |
457
+ |---|---|
458
+ | `spec-manager project init --name X` | Initialize `.spec-manager/` |
459
+ | `spec-manager project status` | Project overview (specs by level, recent activity) |
460
+ | `spec-manager spec list [--level L1] [--topic X] [--status draft]` | List specs (filterable) |
461
+ | `spec-manager spec show <code> [--include-content]` | View spec; default is narrow (metadata only, R19) |
462
+ | `spec-manager spec update <code> --content F --ai-summary S --change-summary R` | Write spec body |
463
+ | `spec-manager spec confirm \| freeze \| implement <code>` | Advance status (human-triggered) |
464
+ | `spec-manager spec validate <code>` | Re-run warning-only validation |
465
+ | `spec-manager spec add-relation <code> --target T --type based_on\|supersedes\|implements\|references` | Cross-spec reference |
466
+ | `spec-manager task create \| start \| step \| complete \| fail \| list \| show` | Agent Task lifecycle |
467
+ | `spec-manager decision create \| list \| show \| update \| set-partial \| supersede \| delete` | Decision cards (R18) |
468
+ | `spec-manager change new \| archive \| list \| show` | Delta spec workflow |
469
+ | `spec-manager incident new \| list` | Rule violation tracking |
470
+ | `spec-manager audit hit \| report \| show` | Local rule audit |
471
+
472
+ Get full help any time: `spec-manager <command> --help`.
473
+
474
+ ## File layout
475
+
476
+ Specs are stored flat — dotted codes (`auth-L2.1`, `auth-L3.1.1-jwt`) encode the hierarchy, so no nested directories are needed. `decisions/` and `tasks/` live at the topic level.
477
+
478
+ ```
479
+ my-project/
480
+ ├── .spec-manager/
481
+ │ ├── config.yaml
482
+ │ ├── audit.json
483
+ │ └── incidents/
484
+ ├── specs/<topic>/
485
+ │ ├── <L1-code>-<date>.md
486
+ │ ├── <L2-code>-<date>.md
487
+ │ ├── <L3-code>[-desc]-<date>.md
488
+ │ ├── decisions/ # R18: L1 implemented → decision cards
489
+ │ │ └── DC-001.md
490
+ │ └── tasks/ # R3: L3 frozen → agent tasks
491
+ │ └── <specCode>-T-001.json
492
+ ├── changes/<name>/
493
+ │ ├── proposal.md
494
+ │ ├── deltas/<code>.md
495
+ │ └── specs/<topic>/<code>/<code>.md # ADDED placeholder
496
+ └── archive/<name>/ # merged changes
497
+ ```
498
+
499
+ Spec codes follow `<topic>-L<N>[.<M>][-desc]` (e.g. `auth-L1`, `auth-L2.1`, `auth-L3.1.1-jwt`): the code self-documents the hierarchy — no need to trace parent directories. `spec new` auto-generates the code when `--code` is omitted. Use `--desc` to add a ≤15 char suffix for readability.
500
+
501
+ ## Documentation
502
+
503
+ - [docs/methodology.md](docs/methodology.md) — the public-facing methodology
504
+
505
+ ## Architecture
506
+
507
+ ```
508
+ spec-manager/
509
+ ├── src/ TypeScript CLI source
510
+ │ ├── cli/ command implementations
511
+ │ ├── core/ spec IO, validation, state machine
512
+ │ └── schemas/ Zod schemas
513
+ ├── templates/ L0/L1/L2/L3/proposal/decision/incident markdown
514
+ ├── rules/ 24 markdown rules with YAML frontmatter
515
+ ├── skill/ Agent skill content (SKILL.md + 12 subskills)
516
+ ├── docs/ public docs
517
+ └── examples/ migration examples
518
+ ```
519
+
520
+ ## Design choices
521
+
522
+ - **Markdown + YAML frontmatter** over JSON or DB: git-friendly, human-readable, diff-able
523
+ - **Atomic file writes** (temp + rename) prevent half-written specs
524
+ - **Narrow view by default** (`spec show` returns metadata only, R19) — saves context
525
+ - **Warning-only validation** — never throws on content quality issues (per R22, R13); R22 blocks confirm/freeze if content is still placeholder
526
+ - **Local rule audit** — JSON file with at-least-once pending queue (no network to fail)
527
+ - **No DAG, strict tree** — L1→L2→L3→Task linear; delta changes are separate concept
528
+
529
+ ## License
530
+
531
+ MIT
@@ -0,0 +1,10 @@
1
+ /**
2
+ * audit 子命令:
3
+ * session start [--session-id ID] [--topic T]
4
+ * hit <ruleId> [--spec S] [--task T]
5
+ * report
6
+ * show [--rule R1]
7
+ */
8
+ import { Command } from 'commander';
9
+ export declare function registerAuditCommands(program: Command): void;
10
+ //# sourceMappingURL=audit.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"audit.d.ts","sourceRoot":"","sources":["../../src/cli/audit.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAKpC,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAqD5D"}
@@ -0,0 +1,62 @@
1
+ /**
2
+ * audit 子命令:
3
+ * session start [--session-id ID] [--topic T]
4
+ * hit <ruleId> [--spec S] [--task T]
5
+ * report
6
+ * show [--rule R1]
7
+ */
8
+ import { randomBytes } from 'node:crypto';
9
+ import { getPaths } from '../core/paths.js';
10
+ import { hit, report, showSummary, startSession, RULE_ID_RE } from '../core/audit.js';
11
+ export function registerAuditCommands(program) {
12
+ const audit = program
13
+ .command('audit')
14
+ .description('规则合规审计(at-least-once 语义,本地存档)');
15
+ audit
16
+ .command('session')
17
+ .description('启动一个 audit session(不调也能 hit,sessionId 自动生成)')
18
+ .option('--session-id <id>', '自定义 session ID')
19
+ .option('--topic <topic>', '绑定 topic')
20
+ .action((opts) => {
21
+ const paths = getPaths();
22
+ const sessionId = opts.sessionId ?? `sess-${randomBytes(4).toString('hex')}`;
23
+ const state = startSession(paths, { sessionId, topic: opts.topic });
24
+ console.log(`✓ Audit session started: ${state.sessionId}`);
25
+ if (state.topic)
26
+ console.log(` topic: ${state.topic}`);
27
+ console.log(` file: ${paths.auditFile}`);
28
+ });
29
+ audit
30
+ .command('hit <ruleId>')
31
+ .description('递增某条规则的命中计数(at-least-once: 总是写 pending)')
32
+ .option('--spec <specCode>', '关联的 spec code')
33
+ .option('--task <taskCode>', '关联的 task code')
34
+ .action((ruleId, opts) => {
35
+ if (!RULE_ID_RE.test(ruleId)) {
36
+ console.error(`✗ ruleId 格式非法: ${ruleId}(必须 /^R([1-9]|1[0-9]|2[0-4])$/)`);
37
+ process.exit(2);
38
+ }
39
+ const paths = getPaths();
40
+ const state = hit({ paths, ruleId, specCode: opts.spec, taskCode: opts.task });
41
+ console.log(`✓ ${ruleId} hit (count: ${state.rules[ruleId]})`);
42
+ console.log(` pending: ${state.pending.filter(e => !e.reported).length} unreported`);
43
+ });
44
+ audit
45
+ .command('report')
46
+ .description('flush pending 队列 → 本地 archive')
47
+ .action(() => {
48
+ const paths = getPaths();
49
+ const result = report(paths);
50
+ console.log(`✓ Audit reported: ${result.markedReported} entries → archive`);
51
+ console.log(` remaining pending: ${result.remaining}`);
52
+ });
53
+ audit
54
+ .command('show')
55
+ .description('查看 audit 摘要(24 条规则 + pending 数量)')
56
+ .option('--rule <ruleId>', '只看一条规则')
57
+ .action((opts) => {
58
+ const paths = getPaths();
59
+ console.log(showSummary(paths, { ruleId: opts.rule }));
60
+ });
61
+ }
62
+ //# sourceMappingURL=audit.js.map