freeharness 0.4.1 → 0.4.3

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 (203) hide show
  1. package/NOTICE +2 -1
  2. package/README.md +24 -19
  3. package/canonical/HARVEST.yaml +27 -16
  4. package/canonical/PROVENANCE.yaml +3 -3
  5. package/canonical/agents/README.md +77 -36
  6. package/canonical/agents/agentic-architect.md +2 -1
  7. package/canonical/agents/database-reviewer.md +6 -8
  8. package/canonical/agents/explorer-ai-engineer-analyst.md +2 -6
  9. package/canonical/agents/implementer.md +30 -0
  10. package/canonical/agents/pr-reviewer.md +9 -11
  11. package/canonical/agents/python-reviewer.md +7 -9
  12. package/canonical/agents/report-formatter.md +7 -3
  13. package/canonical/agents/security-reviewer.md +14 -9
  14. package/canonical/agents/test-writer.md +5 -2
  15. package/canonical/hooks/cost-prices.json +11 -9
  16. package/canonical/hooks/freeharness-config-guard.mjs +4155 -93
  17. package/canonical/hooks/freeharness-context-monitor.mjs +88 -54
  18. package/canonical/hooks/freeharness-converge.mjs +78 -23
  19. package/canonical/hooks/freeharness-cost-tracker.mjs +1116 -218
  20. package/canonical/hooks/freeharness-memory-guard.mjs +20 -23
  21. package/canonical/hooks/freeharness-precompact.mjs +206 -87
  22. package/canonical/hooks/freeharness-quota-tap.mjs +173 -0
  23. package/canonical/hooks/freeharness-reload-context.mjs +197 -0
  24. package/canonical/hooks/freeharness-repeat-tool.mjs +1 -1
  25. package/canonical/hooks/freeharness-sdd-context.mjs +959 -0
  26. package/canonical/hooks/freeharness-session-start +297 -59
  27. package/canonical/hooks/hooks.claude-code.json +1 -1
  28. package/canonical/hooks/hooks.config-guard.claude-code.json +2 -2
  29. package/canonical/hooks/hooks.context-monitor.claude-code.json +1 -1
  30. package/canonical/hooks/hooks.converge.claude-code.json +1 -1
  31. package/canonical/hooks/hooks.memory-guard.claude-code.json +1 -1
  32. package/canonical/hooks/hooks.reload-context.claude-code.json +15 -0
  33. package/canonical/openspec/schema.spec-driven.yaml +29 -8
  34. package/canonical/openspec/templates/follow-ups.md +3 -2
  35. package/canonical/openspec/templates/proposal.md +1 -1
  36. package/canonical/openspec/templates/tasks.md +8 -0
  37. package/canonical/rules/CLAUDE.md +5 -4
  38. package/canonical/rules/routing.md +10 -9
  39. package/canonical/skills/agent-evaluation/SKILL.md +17 -6
  40. package/canonical/skills/agent-evaluation/evals/cases.yaml +38 -23
  41. package/canonical/skills/agentic-architecture/SKILL.md +4 -0
  42. package/canonical/skills/agentic-architecture/evals/cases.yaml +27 -0
  43. package/canonical/skills/code-review/SKILL.md +10 -3
  44. package/canonical/skills/code-review/evals/cases.yaml +1118 -27
  45. package/canonical/skills/git-workflow/SKILL.md +2 -0
  46. package/canonical/skills/local-code/SKILL.md +2 -2
  47. package/canonical/skills/local-code/evals/cases.yaml +1 -1
  48. package/canonical/skills/report-formatting/SKILL.md +10 -2
  49. package/canonical/skills/report-formatting/reference/ARCHITECTURE.md +3 -3
  50. package/canonical/skills/report-formatting/reference/HELPERS.md +10 -5
  51. package/canonical/skills/report-formatting/reference/RELEASE.md +1 -2
  52. package/canonical/skills/report-formatting/reference/TEMPLATES.md +3 -2
  53. package/canonical/skills/report-formatting/reference/authoring.md +25 -37
  54. package/canonical/skills/report-formatting/scripts/build-architecture.js +1 -1
  55. package/canonical/skills/report-formatting/scripts/build-md-claro.js +5 -8
  56. package/canonical/skills/report-formatting/scripts/check-env.js +0 -4
  57. package/canonical/skills/report-formatting/scripts/docmodel.js +3 -11
  58. package/canonical/skills/report-formatting/scripts/example-build.js +8 -10
  59. package/canonical/skills/report-formatting/scripts/example_build_ArchitectureReview_docx.js +8 -10
  60. package/canonical/skills/report-formatting/scripts/example_build_ExecutiveReport_docx.js +8 -10
  61. package/canonical/skills/report-formatting/scripts/theme-claro.js +39 -10
  62. package/canonical/skills/subagent-driven-development/SKILL.md +35 -28
  63. package/canonical/skills/subagent-driven-development/evals/cases.yaml +3625 -19
  64. package/canonical/skills/subagent-driven-development/reference/brief.md +187 -35
  65. package/canonical/skills/subagent-driven-development/reference/handoff.md +96 -2
  66. package/canonical/skills/subagent-driven-development/reference/loop.md +56 -0
  67. package/canonical/skills/subagent-driven-development/reference/trees.md +40 -0
  68. package/canonical/skills/subagent-driven-development/reference/workspace.md +31 -0
  69. package/canonical/skills/subagent-driven-development/scripts/validate-handoff.mjs +4035 -327
  70. package/dist/adapters/harness/claude-code.d.ts +26 -3
  71. package/dist/adapters/harness/claude-code.js +214 -43
  72. package/dist/adapters/harness/opencode.js +17 -3
  73. package/dist/adapters/harness/plugin.js +28 -17
  74. package/dist/adapters/memory/doctor.d.ts +172 -33
  75. package/dist/adapters/memory/doctor.js +750 -139
  76. package/dist/adapters/memory/migrate.d.ts +95 -0
  77. package/dist/adapters/memory/migrate.js +497 -0
  78. package/dist/adapters/memory/paths.d.ts +15 -0
  79. package/dist/adapters/memory/paths.js +47 -0
  80. package/dist/adapters/memory/vendored.d.ts +52 -30
  81. package/dist/adapters/memory/vendored.js +161 -169
  82. package/dist/adapters/memory/worker-control.d.ts +9 -0
  83. package/dist/adapters/memory/worker-control.js +30 -0
  84. package/dist/adapters/sync/diff.js +4 -1
  85. package/dist/cli/cleanup-prompt.d.ts +35 -0
  86. package/dist/cli/cleanup-prompt.js +68 -0
  87. package/dist/cli/cleanup.d.ts +22 -24
  88. package/dist/cli/cleanup.js +204 -75
  89. package/dist/cli/cost-quota.d.ts +158 -0
  90. package/dist/cli/cost-quota.js +645 -0
  91. package/dist/cli/cost.d.ts +408 -46
  92. package/dist/cli/cost.js +1731 -57
  93. package/dist/cli/doctor.d.ts +52 -13
  94. package/dist/cli/doctor.js +199 -45
  95. package/dist/cli/hard-cleanup.d.ts +93 -0
  96. package/dist/cli/hard-cleanup.js +552 -0
  97. package/dist/cli/install-facts.d.ts +29 -0
  98. package/dist/cli/install-facts.js +68 -0
  99. package/dist/cli/json-key-edit.d.ts +18 -0
  100. package/dist/cli/json-key-edit.js +118 -0
  101. package/dist/cli/memory-import.d.ts +74 -0
  102. package/dist/cli/memory-import.js +469 -0
  103. package/dist/cli/plugin-validate.d.ts +12 -0
  104. package/dist/cli/plugin-validate.js +43 -0
  105. package/dist/cli/profile.d.ts +1 -1
  106. package/dist/cli/profile.js +10 -10
  107. package/dist/cli/uninstall.d.ts +1 -1
  108. package/dist/cli/uninstall.js +2 -2
  109. package/dist/cli/upstream-launchers.d.ts +49 -0
  110. package/dist/cli/upstream-launchers.js +287 -0
  111. package/dist/index.js +252 -73
  112. package/dist/infra/fsutil.d.ts +30 -3
  113. package/dist/infra/fsutil.js +68 -6
  114. package/dist/infra/manifest.d.ts +2 -1
  115. package/dist/infra/manifest.js +3 -2
  116. package/dist/infra/prices.d.ts +18 -0
  117. package/dist/infra/prices.js +64 -0
  118. package/node_modules/@freeharness/core/dist/registry.d.ts +1 -1
  119. package/node_modules/@freeharness/core/dist/registry.js +3 -3
  120. package/node_modules/@freeharness/core/dist/tiers.d.ts +10 -1
  121. package/node_modules/@freeharness/core/dist/tiers.js +24 -2
  122. package/node_modules/@freeharness/core/package.json +1 -1
  123. package/node_modules/@freeharness/sdd/PROVENANCE.yaml +279 -2
  124. package/node_modules/@freeharness/sdd/dist/src/bin/openspec.js +34 -8
  125. package/node_modules/@freeharness/sdd/dist/src/shim/archive.d.ts +7 -6
  126. package/node_modules/@freeharness/sdd/dist/src/shim/archive.js +72 -64
  127. package/node_modules/@freeharness/sdd/dist/src/shim/follow-up.d.ts +48 -16
  128. package/node_modules/@freeharness/sdd/dist/src/shim/follow-up.js +168 -70
  129. package/node_modules/@freeharness/sdd/dist/src/shim/instructions.d.ts +36 -6
  130. package/node_modules/@freeharness/sdd/dist/src/shim/instructions.js +110 -49
  131. package/node_modules/@freeharness/sdd/dist/src/shim/list.d.ts +1 -1
  132. package/node_modules/@freeharness/sdd/dist/src/shim/list.js +57 -14
  133. package/node_modules/@freeharness/sdd/dist/src/shim/nested-change.d.ts +7 -0
  134. package/node_modules/@freeharness/sdd/dist/src/shim/nested-change.js +118 -0
  135. package/node_modules/@freeharness/sdd/dist/src/shim/new-change.js +3 -1
  136. package/node_modules/@freeharness/sdd/dist/src/shim/proposal-capabilities.d.ts +12 -0
  137. package/node_modules/@freeharness/sdd/dist/src/shim/proposal-capabilities.js +94 -0
  138. package/node_modules/@freeharness/sdd/dist/src/shim/shared.d.ts +17 -0
  139. package/node_modules/@freeharness/sdd/dist/src/shim/shared.js +182 -1
  140. package/node_modules/@freeharness/sdd/dist/src/shim/status.d.ts +2 -2
  141. package/node_modules/@freeharness/sdd/dist/src/shim/status.js +34 -5
  142. package/node_modules/@freeharness/sdd/dist/src/shim/validate.d.ts +9 -0
  143. package/node_modules/@freeharness/sdd/dist/src/shim/validate.js +49 -41
  144. package/node_modules/@freeharness/sdd/dist/src/shim/warnings.d.ts +21 -0
  145. package/node_modules/@freeharness/sdd/dist/src/shim/warnings.js +66 -0
  146. package/node_modules/@freeharness/sdd/dist/vendor/openspec/apply/line-endings.d.ts +4 -0
  147. package/node_modules/@freeharness/sdd/dist/vendor/openspec/apply/line-endings.js +17 -0
  148. package/node_modules/@freeharness/sdd/dist/vendor/openspec/apply/specs-apply.js +95 -22
  149. package/node_modules/@freeharness/sdd/dist/vendor/openspec/engine/change-status-policy.d.ts +6 -0
  150. package/node_modules/@freeharness/sdd/dist/vendor/openspec/engine/change-status-policy.js +14 -6
  151. package/node_modules/@freeharness/sdd/dist/vendor/openspec/engine/index.d.ts +1 -1
  152. package/node_modules/@freeharness/sdd/dist/vendor/openspec/engine/index.js +1 -1
  153. package/node_modules/@freeharness/sdd/dist/vendor/openspec/engine/outputs.d.ts +3 -3
  154. package/node_modules/@freeharness/sdd/dist/vendor/openspec/engine/outputs.js +24 -4
  155. package/node_modules/@freeharness/sdd/dist/vendor/openspec/engine/task-progress.js +4 -7
  156. package/node_modules/@freeharness/sdd/dist/vendor/openspec/engine/types.js +13 -1
  157. package/node_modules/@freeharness/sdd/dist/vendor/openspec/generation/templates/workflows/apply-change.js +21 -6
  158. package/node_modules/@freeharness/sdd/dist/vendor/openspec/generation/templates/workflows/archive-change.js +80 -19
  159. package/node_modules/@freeharness/sdd/dist/vendor/openspec/generation/templates/workflows/explore.js +42 -22
  160. package/node_modules/@freeharness/sdd/dist/vendor/openspec/generation/templates/workflows/project-root.d.ts +32 -0
  161. package/node_modules/@freeharness/sdd/dist/vendor/openspec/generation/templates/workflows/project-root.js +39 -0
  162. package/node_modules/@freeharness/sdd/dist/vendor/openspec/generation/templates/workflows/propose.js +16 -9
  163. package/node_modules/@freeharness/sdd/dist/vendor/openspec/generation/templates/workflows/sync-specs.js +36 -1
  164. package/node_modules/@freeharness/sdd/dist/vendor/openspec/generation/templates/workflows/update-change.js +65 -30
  165. package/node_modules/@freeharness/sdd/dist/vendor/openspec/validation/constants.d.ts +1 -1
  166. package/node_modules/@freeharness/sdd/dist/vendor/openspec/validation/constants.js +1 -1
  167. package/node_modules/@freeharness/sdd/dist/vendor/openspec/validation/parsers/change-parser.d.ts +8 -13
  168. package/node_modules/@freeharness/sdd/dist/vendor/openspec/validation/parsers/change-parser.js +79 -102
  169. package/node_modules/@freeharness/sdd/dist/vendor/openspec/validation/parsers/markdown-parser.js +4 -9
  170. package/node_modules/@freeharness/sdd/dist/vendor/openspec/validation/parsers/requirement-blocks.d.ts +50 -10
  171. package/node_modules/@freeharness/sdd/dist/vendor/openspec/validation/parsers/requirement-blocks.js +165 -37
  172. package/node_modules/@freeharness/sdd/dist/vendor/openspec/validation/parsers/requirement-text.d.ts +24 -3
  173. package/node_modules/@freeharness/sdd/dist/vendor/openspec/validation/parsers/requirement-text.js +55 -8
  174. package/node_modules/@freeharness/sdd/dist/vendor/openspec/validation/parsers/spec-structure.js +4 -1
  175. package/node_modules/@freeharness/sdd/dist/vendor/openspec/validation/purpose-placeholder.js +19 -9
  176. package/node_modules/@freeharness/sdd/dist/vendor/openspec/validation/spec-discovery.d.ts +10 -0
  177. package/node_modules/@freeharness/sdd/dist/vendor/openspec/validation/spec-discovery.js +115 -0
  178. package/node_modules/@freeharness/sdd/dist/vendor/openspec/validation/task-lines.d.ts +3 -3
  179. package/node_modules/@freeharness/sdd/dist/vendor/openspec/validation/task-lines.js +20 -20
  180. package/node_modules/@freeharness/sdd/dist/vendor/openspec/validation/validator.d.ts +6 -0
  181. package/node_modules/@freeharness/sdd/dist/vendor/openspec/validation/validator.js +75 -14
  182. package/node_modules/@freeharness/sdd/package.json +1 -1
  183. package/node_modules/@freeharness/sdd/vendor/openspec/assets/schema.upstream.yaml +47 -7
  184. package/node_modules/@freeharness/sdd/vendor/openspec/assets/skills/openspec-apply-change/SKILL.md +25 -7
  185. package/node_modules/@freeharness/sdd/vendor/openspec/assets/skills/openspec-archive-change/SKILL.md +50 -11
  186. package/node_modules/@freeharness/sdd/vendor/openspec/assets/skills/openspec-bulk-archive-change/SKILL.md +48 -10
  187. package/node_modules/@freeharness/sdd/vendor/openspec/assets/skills/openspec-continue-change/SKILL.md +27 -7
  188. package/node_modules/@freeharness/sdd/vendor/openspec/assets/skills/openspec-explore/SKILL.md +25 -12
  189. package/node_modules/@freeharness/sdd/vendor/openspec/assets/skills/openspec-ff-change/SKILL.md +17 -5
  190. package/node_modules/@freeharness/sdd/vendor/openspec/assets/skills/openspec-new-change/SKILL.md +12 -1
  191. package/node_modules/@freeharness/sdd/vendor/openspec/assets/skills/openspec-onboard/SKILL.md +47 -33
  192. package/node_modules/@freeharness/sdd/vendor/openspec/assets/skills/openspec-propose/SKILL.md +17 -5
  193. package/node_modules/@freeharness/sdd/vendor/openspec/assets/skills/openspec-sync-specs/SKILL.md +29 -1
  194. package/node_modules/@freeharness/sdd/vendor/openspec/assets/skills/openspec-update-change/SKILL.md +31 -13
  195. package/node_modules/@freeharness/sdd/vendor/openspec/assets/skills/openspec-verify-change/SKILL.md +75 -27
  196. package/package.json +6 -4
  197. package/provenance/canonical.PROVENANCE.yaml +3 -3
  198. package/provenance/memory.PROVENANCE.yaml +472 -6
  199. package/provenance/sdd.PROVENANCE.yaml +279 -2
  200. package/canonical/hooks/freeharness-auto-memory.mjs +0 -158
  201. package/canonical/hooks/hooks.auto-memory.claude-code.json +0 -16
  202. package/canonical/openspec/config.base.yaml +0 -89
  203. package/canonical/rules/safety.md +0 -41
@@ -1,14 +1,17 @@
1
1
  import { STORE_SELECTION_GUIDANCE } from './store-selection.js';
2
+ import { PROJECT_ROOT_GUARD } from './project-root.js';
2
3
  export function getSyncSpecsSkillTemplate() {
3
4
  return {
4
5
  name: 'openspec-sync-specs',
5
- description: 'Sync delta specs from a change to main specs. Use when the user wants to update main specs with changes from a delta spec, without archiving the change.',
6
+ description: 'Sync delta specs from an OpenSpec change to main specs. Use when the user wants to update main specs with changes from a delta spec, without archiving the change.',
6
7
  instructions: `Sync delta specs from a change to main specs.
7
8
 
8
9
  This is an **agent-driven** operation - you will read delta specs and directly edit main specs to apply the changes. This allows intelligent merging (e.g., adding a scenario without copying the entire requirement).
9
10
 
10
11
  ${STORE_SELECTION_GUIDANCE}
11
12
 
13
+ ${PROJECT_ROOT_GUARD}
14
+
12
15
  \`<capability-path>\` is the spec directory relative to \`specs/\` (for example, \`user-auth\` or \`identity/user-auth\`). Preserve the full path from each delta spec when resolving its main spec.
13
16
 
14
17
  **Input**: Optionally specify a change name. If omitted, check if it can be inferred from conversation context. If vague or ambiguous you MUST prompt for available changes.
@@ -89,6 +92,13 @@ ${STORE_SELECTION_GUIDANCE}
89
92
 
90
93
  b. **Read the main spec** at \`<planningHome.root>/openspec/specs/<capability-path>/spec.md\` (may not exist yet)
91
94
 
95
+ **If it does not exist yet** (a new capability), match what \`openspec archive\` does:
96
+ only ADDED requirements may be applied - step d creates the spec from them.
97
+ MODIFIED and RENAMED have no requirement to act on, so stop the sync for that
98
+ capability and report that its main spec does not exist and only ADDED is allowed
99
+ for a new spec; never invent the missing requirement. REMOVED has nothing to
100
+ remove - skip it and warn.
101
+
92
102
  c. **Apply changes intelligently**:
93
103
 
94
104
  **ADDED Requirements:**
@@ -136,6 +146,14 @@ ${STORE_SELECTION_GUIDANCE}
136
146
  (this is what \`openspec archive\` does; it warns and moves on)
137
147
 
138
148
  d. **Create new main spec** if capability doesn't exist yet:
149
+ - Only when the delta has ADDED requirements to put in it and no MODIFIED or
150
+ RENAMED requirements blocked this capability in step b. Otherwise create nothing
151
+ and leave the specs directory untouched. For a REMOVED-only delta, if the change's
152
+ \`.openspec.yaml\` declares \`retire_capabilities: true\`, report it as already retired
153
+ and continue without recreating the spec. Without that marker, report the sync as blocked:
154
+ \`openspec archive\` rejects it with \`Spec must have at least one requirement\`.
155
+ An empty delta has no operations to sync; report it as blocked too.
156
+ Never write an empty \`## Requirements\` section.
139
157
  - Create \`<planningHome.root>/openspec/specs/<capability-path>/spec.md\`
140
158
  - Add Purpose section: copy the delta's \`## Purpose\` body verbatim when it has one
141
159
  (this is what \`openspec archive\` does); only write a brief TBD placeholder when it does not
@@ -270,6 +288,8 @@ This is an **agent-driven** operation - you will read delta specs and directly e
270
288
 
271
289
  ${STORE_SELECTION_GUIDANCE}
272
290
 
291
+ ${PROJECT_ROOT_GUARD}
292
+
273
293
  \`<capability-path>\` is the spec directory relative to \`specs/\` (for example, \`user-auth\` or \`identity/user-auth\`). Preserve the full path from each delta spec when resolving its main spec.
274
294
 
275
295
  **Input**: Optionally specify a change name after \`/opsx:sync\` (e.g., \`/opsx:sync add-auth\`). If omitted, check if it can be inferred from conversation context. If vague or ambiguous you MUST prompt for available changes.
@@ -350,6 +370,13 @@ ${STORE_SELECTION_GUIDANCE}
350
370
 
351
371
  b. **Read the main spec** at \`<planningHome.root>/openspec/specs/<capability-path>/spec.md\` (may not exist yet)
352
372
 
373
+ **If it does not exist yet** (a new capability), match what \`openspec archive\` does:
374
+ only ADDED requirements may be applied - step d creates the spec from them.
375
+ MODIFIED and RENAMED have no requirement to act on, so stop the sync for that
376
+ capability and report that its main spec does not exist and only ADDED is allowed
377
+ for a new spec; never invent the missing requirement. REMOVED has nothing to
378
+ remove - skip it and warn.
379
+
353
380
  c. **Apply changes intelligently**:
354
381
 
355
382
  **ADDED Requirements:**
@@ -397,6 +424,14 @@ ${STORE_SELECTION_GUIDANCE}
397
424
  (this is what \`openspec archive\` does; it warns and moves on)
398
425
 
399
426
  d. **Create new main spec** if capability doesn't exist yet:
427
+ - Only when the delta has ADDED requirements to put in it and no MODIFIED or
428
+ RENAMED requirements blocked this capability in step b. Otherwise create nothing
429
+ and leave the specs directory untouched. For a REMOVED-only delta, if the change's
430
+ \`.openspec.yaml\` declares \`retire_capabilities: true\`, report it as already retired
431
+ and continue without recreating the spec. Without that marker, report the sync as blocked:
432
+ \`openspec archive\` rejects it with \`Spec must have at least one requirement\`.
433
+ An empty delta has no operations to sync; report it as blocked too.
434
+ Never write an empty \`## Requirements\` section.
400
435
  - Create \`<planningHome.root>/openspec/specs/<capability-path>/spec.md\`
401
436
  - Add Purpose section: copy the delta's \`## Purpose\` body verbatim when it has one
402
437
  (this is what \`openspec archive\` does); only write a brief TBD placeholder when it does not
@@ -1,4 +1,21 @@
1
1
  import { STORE_SELECTION_GUIDANCE } from './store-selection.js';
2
+ import { PROJECT_ROOT_GUARD } from './project-root.js';
3
+ /**
4
+ * Passages that would hand off to \`/opsx:continue\` or \`/opsx:new\`. Neither
5
+ * workflow is among FreeHarness's six emitted workflows, so each always
6
+ * renders the CLI fallback rather than naming a skill that was never
7
+ * generated.
8
+ */
9
+ const CONTINUE_SCOPE_NOTE = 'This workflow revises artifacts that already exist; it never creates missing ones. When an artifact is missing, `openspec status --change "<name>" --json` names the next one and `openspec instructions "<artifact-id>" --change "<name>" --json` explains how to write it.';
10
+ const CONTINUE_CREATE_THEM = 'point the user to `openspec instructions "<artifact-id>" --change "<name>" --json` for how to create them';
11
+ const CONTINUE_NEXT_STEP = 'run `openspec status --change "<name>" --json` for the next artifact and point the user to `openspec instructions "<artifact-id>" --change "<name>" --json` for how to create it';
12
+ const CONTINUE_DEFERRED = 'Anything deferred because it does not exist yet (artifacts with no files and status `ready` or `blocked`, never `skipped` artifacts)';
13
+ const CONTINUE_FRONTIER = 'creating them is a separate step, outside this workflow';
14
+ const INTENT_CHANGE_GUARDRAIL = 'ask for a distinct unused change name and recommend `openspec new change "<new-change-name>"` instead (the "Update vs. Start Fresh" heuristic)';
15
+ /** \`apply\` and \`archive\` are both shipped, so their handoffs always name the slash command. */
16
+ const APPLY_DELTA_HANDOFF = 'suggest `/opsx:apply` to carry the delta into code';
17
+ const APPLY_GUARDRAIL = 'stop and point to `/opsx:apply`';
18
+ const ARCHIVE_HANDOFF = 'suggest `/opsx:archive`';
2
19
  export function getUpdateChangeSkillTemplate() {
3
20
  return {
4
21
  name: 'openspec-update-change',
@@ -7,9 +24,11 @@ export function getUpdateChangeSkillTemplate() {
7
24
 
8
25
  ${STORE_SELECTION_GUIDANCE}
9
26
 
27
+ ${PROJECT_ROOT_GUARD}
28
+
10
29
  **Input**: Optionally specify a change name. If omitted, check if it can be inferred from conversation context. If vague or ambiguous you MUST prompt for available changes.
11
30
 
12
- \`/opsx:continue\` is an optional workflow and may not be installed. Before suggesting it anywhere below, verify that it is available. If it is unavailable, \`openspec status --change "<name>" --json\` shows the next artifact and \`openspec instructions "<artifact-id>" --change "<name>" --json\` explains how to create it.
31
+ ${CONTINUE_SCOPE_NOTE}
13
32
 
14
33
  **Steps**
15
34
 
@@ -22,7 +41,6 @@ ${STORE_SELECTION_GUIDANCE}
22
41
 
23
42
  When prompting, present the top 3-4 most recently modified changes as options, showing:
24
43
  - Change name
25
- - Schema (from \`schema\` field if present, otherwise "spec-driven")
26
44
  - Status (e.g., "0/5 tasks", "complete", "no tasks")
27
45
  - How recently it was modified (from \`lastModified\` field)
28
46
 
@@ -42,7 +60,7 @@ ${STORE_SELECTION_GUIDANCE}
42
60
 
43
61
  The artifact ids and paths come from the active schema - do NOT assume them, and do NOT branch on hardcoded artifact names. Custom schemas must work unchanged.
44
62
 
45
- The files to edit are \`artifactPaths.<id>.existingOutputPaths\` - the concrete files that exist on disk, already glob-expanded for glob artifacts (e.g. \`specs/**/*.md\`). Do NOT write to \`resolvedOutputPath\`: for a glob artifact it is still the glob pattern, not a real file.
63
+ The files to edit are \`artifactPaths.<id>.existingOutputPaths\` - the concrete files that exist on disk, already glob-expanded for glob artifacts (e.g. \`specs/**/*.md\`), plus any confirmed concrete path allowed under a partly populated glob artifact (step 4). Do NOT write to \`resolvedOutputPath\`: for a glob artifact it is still the glob pattern, not a real file.
46
64
 
47
65
  3. **Understand the request**
48
66
  - If the user asked for a specific revision ("the design now uses X"), that is the starting edit.
@@ -50,13 +68,20 @@ ${STORE_SELECTION_GUIDANCE}
50
68
 
51
69
  4. **Read and reconcile**
52
70
  - Read the artifact(s) the request touches and the change's other existing artifacts.
53
- - Apply the requested edit. Then check every other existing artifact against it - in ANY direction: an edit to a later artifact may require revising an earlier one, not only the other way around. Build order is a useful reading order, not a constraint on which artifacts may be revised.
71
+ - Draft the requested edit in the conversation, not in files. Work out exactly what it changes; step 5 owns every write. Then check every other existing artifact against the drafted edit - in ANY direction: an edit to a later artifact may require revising an earlier one, not only the other way around. Build order is a useful reading order, not a constraint on which artifacts may be revised.
54
72
  - Note everything that is now inconsistent, missing, or contradictory.
55
- - Revise only files that already exist (\`existingOutputPaths\`). Do NOT create artifacts that don't exist yet, and do NOT invent new files under a glob artifact - note them and point the user to \`/opsx:continue\` to create them.
56
- - If the change is already coherent, say so and make no edits.
73
+ - Propose revisions to files that already exist (\`existingOutputPaths\`). If an artifact has no existing output files and status \`ready\` or \`blocked\`, note it and ${CONTINUE_CREATE_THEM}. Leave \`skipped\` artifacts untouched; do not treat them as missing or defer them to the continue workflow.
74
+ - A glob artifact (e.g. \`specs/**/*.md\`) is marked \`done\` after at least one file matches, and the continue workflow only handles \`ready\` artifacts. When reconciliation identifies a missing file for a glob artifact whose \`existingOutputPaths\` is non-empty:
75
+ 1. Run \`openspec instructions "<artifact-id>" --change "<name>" --json\` and use its \`instruction\` and \`template\`. Treat \`context\` and \`rules\` as constraints; do not copy them into the file. If instructions report \`skipped: true\`, do not create the file. Read current dependency files from disk; if a required non-skipped dependency is missing, stop and ask the user to restore it first.
76
+ 2. Choose a concrete path inside \`changeRoot\` that matches \`artifactPaths.<id>.outputPath\` and does not already exist. Verify it remains inside \`changeRoot\` after resolving any symlinked parent directories. The glob \`resolvedOutputPath\` is not a valid target.
77
+ 3. Include the new file in step 5's proposed revisions and create it only after the user confirms.
78
+ 4. After confirmation, immediately before creation, refresh status and instructions. Verify the artifact is still in scope, not skipped, and partially populated; repeat the concrete-path checks above.
79
+ 5. Use a create operation that fails if the target already exists. If \`instruction\` delegates creation to another skill or command, invoke it only if it can honor the confirmed path and these guardrails; otherwise stop. If any check fails or the confirmed draft is no longer valid, stop and reconcile with the user rather than replacing existing content or choosing a different path.
80
+ - If the change is already coherent, say so and propose no revisions.
57
81
 
58
82
  5. **Confirm and apply, one artifact at a time**
59
- - Show each proposed revision and why. Write only after the user confirms.
83
+ - This step performs every artifact write in this workflow; no earlier step edits an artifact.
84
+ - Show each proposed revision and why - including the requested edit drafted in step 4. Write only after the user confirms.
60
85
  - If the user rejects a revision, do not write it - leave that artifact unchanged.
61
86
  - When a substantial rewrite is needed, get that artifact's rules and template first:
62
87
  \`\`\`bash
@@ -64,24 +89,25 @@ ${STORE_SELECTION_GUIDANCE}
64
89
  \`\`\`
65
90
 
66
91
  6. **Point to the next step (guidance only - NEVER act on it)**
67
- - Artifacts still missing -> suggest \`/opsx:continue\` to create them.
68
- - Change already implemented (tasks checked off / already applied) -> the code may no longer match the revised plan; suggest \`/opsx:apply\` to carry the delta into code.
69
- - Everything done and implemented -> suggest \`/opsx:archive\`.
92
+ - Artifacts with empty \`existingOutputPaths\` and status \`ready\` or \`blocked\` -> ${CONTINUE_NEXT_STEP}.
93
+ - Change already implemented (tasks checked off / already applied) -> the code may no longer match the revised plan; ${APPLY_DELTA_HANDOFF}.
94
+ - Everything done and implemented -> ${ARCHIVE_HANDOFF}.
70
95
 
71
96
  **Output**
72
97
 
73
98
  After each invocation, show:
74
99
  - Which artifacts were revised (and which proposed revisions were rejected)
75
- - Anything deferred to \`/opsx:continue\` (not-yet-created artifacts or files)
100
+ - Any file created under a glob artifact that was already partially populated
101
+ - ${CONTINUE_DEFERRED}
76
102
  - Where the change stands and the recommended next command
77
103
 
78
104
  **Guardrails**
79
- - Planning artifacts only - NEVER edit implementation code. If the revised plan implies code changes, stop and point to \`/opsx:apply\`.
105
+ - Planning artifacts only - NEVER edit implementation code. If the revised plan implies code changes, ${APPLY_GUARDRAIL}.
80
106
  - Use the artifact ids and paths reported by \`openspec status\`; never branch on hardcoded artifact names.
81
- - Edit only the concrete files in \`existingOutputPaths\`; never write to a glob \`resolvedOutputPath\`.
82
- - Do not advance the build frontier: no new artifacts, no new files under glob artifacts - that is \`/opsx:continue\`'s job.
107
+ - Edit only the concrete files in \`existingOutputPaths\`, plus any confirmed concrete path allowed under a partly populated glob artifact (step 4); never write to a glob \`resolvedOutputPath\`.
108
+ - Do not advance the build frontier: if an artifact has empty \`existingOutputPaths\` and status \`ready\` or \`blocked\`, ${CONTINUE_FRONTIER}. Leave \`skipped\` artifacts untouched. The only new-file scope is a confirmed concrete path under a glob artifact whose \`existingOutputPaths\` is non-empty.
83
109
  - Confirm every edit with the user before writing.
84
- - If the request changes the change's *intent* rather than refining it, first verify whether the optional \`/opsx:new\` workflow is available. If it is, recommend starting fresh with \`/opsx:new\` (the "Update vs. Start Fresh" heuristic). If it is unavailable, ask for a distinct unused change name and recommend \`openspec new change "<new-change-name>"\` instead.`,
110
+ - If the request changes the change's *intent* rather than refining it, ${INTENT_CHANGE_GUARDRAIL}.`,
85
111
  license: 'MIT',
86
112
  compatibility: 'Requires openspec CLI.',
87
113
  metadata: { author: 'openspec', version: '1.0' },
@@ -97,9 +123,11 @@ export function getOpsxUpdateCommandTemplate() {
97
123
 
98
124
  ${STORE_SELECTION_GUIDANCE}
99
125
 
126
+ ${PROJECT_ROOT_GUARD}
127
+
100
128
  **Input**: Optionally specify a change name after \`/opsx:update\` (e.g., \`/opsx:update add-auth\`). If omitted, check if it can be inferred from conversation context. If vague or ambiguous you MUST prompt for available changes.
101
129
 
102
- \`/opsx:continue\` is an optional workflow and may not be installed. Before suggesting it anywhere below, verify that it is available. If it is unavailable, \`openspec status --change "<name>" --json\` shows the next artifact and \`openspec instructions "<artifact-id>" --change "<name>" --json\` explains how to create it.
130
+ ${CONTINUE_SCOPE_NOTE}
103
131
 
104
132
  **Steps**
105
133
 
@@ -112,7 +140,6 @@ ${STORE_SELECTION_GUIDANCE}
112
140
 
113
141
  When prompting, present the top 3-4 most recently modified changes as options, showing:
114
142
  - Change name
115
- - Schema (from \`schema\` field if present, otherwise "spec-driven")
116
143
  - Status (e.g., "0/5 tasks", "complete", "no tasks")
117
144
  - How recently it was modified (from \`lastModified\` field)
118
145
 
@@ -132,7 +159,7 @@ ${STORE_SELECTION_GUIDANCE}
132
159
 
133
160
  The artifact ids and paths come from the active schema - do NOT assume them, and do NOT branch on hardcoded artifact names. Custom schemas must work unchanged.
134
161
 
135
- The files to edit are \`artifactPaths.<id>.existingOutputPaths\` - the concrete files that exist on disk, already glob-expanded for glob artifacts (e.g. \`specs/**/*.md\`). Do NOT write to \`resolvedOutputPath\`: for a glob artifact it is still the glob pattern, not a real file.
162
+ The files to edit are \`artifactPaths.<id>.existingOutputPaths\` - the concrete files that exist on disk, already glob-expanded for glob artifacts (e.g. \`specs/**/*.md\`), plus any confirmed concrete path allowed under a partly populated glob artifact (step 4). Do NOT write to \`resolvedOutputPath\`: for a glob artifact it is still the glob pattern, not a real file.
136
163
 
137
164
  3. **Understand the request**
138
165
  - If the user asked for a specific revision ("the design now uses X"), that is the starting edit.
@@ -140,13 +167,20 @@ ${STORE_SELECTION_GUIDANCE}
140
167
 
141
168
  4. **Read and reconcile**
142
169
  - Read the artifact(s) the request touches and the change's other existing artifacts.
143
- - Apply the requested edit. Then check every other existing artifact against it - in ANY direction: an edit to a later artifact may require revising an earlier one, not only the other way around. Build order is a useful reading order, not a constraint on which artifacts may be revised.
170
+ - Draft the requested edit in the conversation, not in files. Work out exactly what it changes; step 5 owns every write. Then check every other existing artifact against the drafted edit - in ANY direction: an edit to a later artifact may require revising an earlier one, not only the other way around. Build order is a useful reading order, not a constraint on which artifacts may be revised.
144
171
  - Note everything that is now inconsistent, missing, or contradictory.
145
- - Revise only files that already exist (\`existingOutputPaths\`). Do NOT create artifacts that don't exist yet, and do NOT invent new files under a glob artifact - note them and point the user to \`/opsx:continue\` to create them.
146
- - If the change is already coherent, say so and make no edits.
172
+ - Propose revisions to files that already exist (\`existingOutputPaths\`). If an artifact has no existing output files and status \`ready\` or \`blocked\`, note it and ${CONTINUE_CREATE_THEM}. Leave \`skipped\` artifacts untouched; do not treat them as missing or defer them to the continue workflow.
173
+ - A glob artifact (e.g. \`specs/**/*.md\`) is marked \`done\` after at least one file matches, and the continue workflow only handles \`ready\` artifacts. When reconciliation identifies a missing file for a glob artifact whose \`existingOutputPaths\` is non-empty:
174
+ 1. Run \`openspec instructions "<artifact-id>" --change "<name>" --json\` and use its \`instruction\` and \`template\`. Treat \`context\` and \`rules\` as constraints; do not copy them into the file. If instructions report \`skipped: true\`, do not create the file. Read current dependency files from disk; if a required non-skipped dependency is missing, stop and ask the user to restore it first.
175
+ 2. Choose a concrete path inside \`changeRoot\` that matches \`artifactPaths.<id>.outputPath\` and does not already exist. Verify it remains inside \`changeRoot\` after resolving any symlinked parent directories. The glob \`resolvedOutputPath\` is not a valid target.
176
+ 3. Include the new file in step 5's proposed revisions and create it only after the user confirms.
177
+ 4. After confirmation, immediately before creation, refresh status and instructions. Verify the artifact is still in scope, not skipped, and partially populated; repeat the concrete-path checks above.
178
+ 5. Use a create operation that fails if the target already exists. If \`instruction\` delegates creation to another skill or command, invoke it only if it can honor the confirmed path and these guardrails; otherwise stop. If any check fails or the confirmed draft is no longer valid, stop and reconcile with the user rather than replacing existing content or choosing a different path.
179
+ - If the change is already coherent, say so and propose no revisions.
147
180
 
148
181
  5. **Confirm and apply, one artifact at a time**
149
- - Show each proposed revision and why. Write only after the user confirms.
182
+ - This step performs every artifact write in this workflow; no earlier step edits an artifact.
183
+ - Show each proposed revision and why - including the requested edit drafted in step 4. Write only after the user confirms.
150
184
  - If the user rejects a revision, do not write it - leave that artifact unchanged.
151
185
  - When a substantial rewrite is needed, get that artifact's rules and template first:
152
186
  \`\`\`bash
@@ -154,23 +188,24 @@ ${STORE_SELECTION_GUIDANCE}
154
188
  \`\`\`
155
189
 
156
190
  6. **Point to the next step (guidance only - NEVER act on it)**
157
- - Artifacts still missing -> suggest \`/opsx:continue\` to create them.
158
- - Change already implemented (tasks checked off / already applied) -> the code may no longer match the revised plan; suggest \`/opsx:apply\` to carry the delta into code.
159
- - Everything done and implemented -> suggest \`/opsx:archive\`.
191
+ - Artifacts with empty \`existingOutputPaths\` and status \`ready\` or \`blocked\` -> ${CONTINUE_NEXT_STEP}.
192
+ - Change already implemented (tasks checked off / already applied) -> the code may no longer match the revised plan; ${APPLY_DELTA_HANDOFF}.
193
+ - Everything done and implemented -> ${ARCHIVE_HANDOFF}.
160
194
 
161
195
  **Output**
162
196
 
163
197
  After each invocation, show:
164
198
  - Which artifacts were revised (and which proposed revisions were rejected)
165
- - Anything deferred to \`/opsx:continue\` (not-yet-created artifacts or files)
199
+ - Any file created under a glob artifact that was already partially populated
200
+ - ${CONTINUE_DEFERRED}
166
201
  - Where the change stands and the recommended next command
167
202
 
168
203
  **Guardrails**
169
- - Planning artifacts only - NEVER edit implementation code. If the revised plan implies code changes, stop and point to \`/opsx:apply\`.
204
+ - Planning artifacts only - NEVER edit implementation code. If the revised plan implies code changes, ${APPLY_GUARDRAIL}.
170
205
  - Use the artifact ids and paths reported by \`openspec status\`; never branch on hardcoded artifact names.
171
- - Edit only the concrete files in \`existingOutputPaths\`; never write to a glob \`resolvedOutputPath\`.
172
- - Do not advance the build frontier: no new artifacts, no new files under glob artifacts - that is \`/opsx:continue\`'s job.
206
+ - Edit only the concrete files in \`existingOutputPaths\`, plus any confirmed concrete path allowed under a partly populated glob artifact (step 4); never write to a glob \`resolvedOutputPath\`.
207
+ - Do not advance the build frontier: if an artifact has empty \`existingOutputPaths\` and status \`ready\` or \`blocked\`, ${CONTINUE_FRONTIER}. Leave \`skipped\` artifacts untouched. The only new-file scope is a confirmed concrete path under a glob artifact whose \`existingOutputPaths\` is non-empty.
173
208
  - Confirm every edit with the user before writing.
174
- - If the request changes the change's *intent* rather than refining it, first verify whether the optional \`/opsx:new\` workflow is available. If it is, recommend starting fresh with \`/opsx:new\` (the "Update vs. Start Fresh" heuristic). If it is unavailable, ask for a distinct unused change name and recommend \`openspec new change "<new-change-name>"\` instead.`
209
+ - If the request changes the change's *intent* rather than refining it, ${INTENT_CHANGE_GUARDRAIL}.`
175
210
  };
176
211
  }
@@ -29,7 +29,7 @@ export declare const VALIDATION_MESSAGES: {
29
29
  readonly DELTA_DESCRIPTION_EMPTY: "Delta description cannot be empty";
30
30
  readonly PURPOSE_TOO_BRIEF: "Purpose section is too brief (less than 50 characters)";
31
31
  readonly PURPOSE_IS_PLACEHOLDER: string;
32
- readonly REQUIREMENT_TOO_LONG: "Requirement text is very long (>500 characters). Consider breaking it down.";
32
+ readonly REQUIREMENT_TOO_LONG: "Requirement text is very long (>500 characters). Move examples and edge cases into scenarios, or split it into separate requirements that each state one behavior.";
33
33
  readonly DELTA_DESCRIPTION_TOO_BRIEF: "Delta description is too brief";
34
34
  readonly DELTA_MISSING_REQUIREMENTS: "Delta should include requirements";
35
35
  readonly GUIDE_NO_DELTAS: "No deltas found. Ensure your change has a specs/ directory with capability folders (e.g. specs/http-server/spec.md) containing .md files that use delta headers (## ADDED/MODIFIED/REMOVED/RENAMED Requirements) and that each requirement includes at least one \"#### Scenario:\" block. If this change intentionally modifies no specs (pure refactor, tooling, docs), set \"skip_specs: true\" in the change's .openspec.yaml instead. Tip: run \"openspec change show <change-id> --json --deltas-only\" to inspect parsed deltas.";
@@ -43,7 +43,7 @@ export const VALIDATION_MESSAGES = {
43
43
  'writes for a new capability, or a `TBD`/`TODO` marker left in its place). Replace it with what this ' +
44
44
  'capability is for, editing the main spec directly: a `## Purpose` in a delta is read only when the ' +
45
45
  'capability is created, so it cannot replace this one.',
46
- REQUIREMENT_TOO_LONG: `Requirement text is very long (>${MAX_REQUIREMENT_TEXT_LENGTH} characters). Consider breaking it down.`,
46
+ REQUIREMENT_TOO_LONG: `Requirement text is very long (>${MAX_REQUIREMENT_TEXT_LENGTH} characters). Move examples and edge cases into scenarios, or split it into separate requirements that each state one behavior.`,
47
47
  DELTA_DESCRIPTION_TOO_BRIEF: 'Delta description is too brief',
48
48
  DELTA_MISSING_REQUIREMENTS: 'Delta should include requirements',
49
49
  // Guidance snippets (appended to primary messages for remediation)
@@ -6,22 +6,17 @@ export declare class ChangeParser extends MarkdownParser {
6
6
  parseChangeWithDeltas(name: string): Promise<Change>;
7
7
  private parseDeltaSpecs;
8
8
  /**
9
- * Read requirements from a delta section, ignoring headers that are not
10
- * `### Requirement: <name>`.
11
- *
12
- * A delta section often carries divider headers such as
13
- * `### Documentation Requirements`. The base parser treats every child header
14
- * as a requirement, which invented a scenario-less requirement that does not
15
- * exist (#498): archive warned about a missing scenario, and `show --json`
16
- * reported an extra delta. The delta reader already skips these headers and
17
- * notes them, so this keeps the two readers in agreement.
18
- *
19
- * Overriding here rather than in MarkdownParser keeps main spec parsing —
20
- * `view`, `list`, `spec --json`, spec validation — untouched.
9
+ * Reads requirements from a delta section, ignoring headers that are not
10
+ * `### Requirement: <name>` - a divider like `### Documentation
11
+ * Requirements` would otherwise be read as a scenario-less requirement,
12
+ * which the delta reader already skips and notes. Overriding here rather
13
+ * than in MarkdownParser keeps main spec parsing untouched.
21
14
  */
22
15
  protected parseRequirements(section: Section): Requirement[];
16
+ /** The deltas in one spec file, read by parseDeltaSpec - the same reader archive applies. */
23
17
  private parseSpecDeltas;
24
- private parseRenames;
18
+ /** One Requirement per block, via the same section parser and header filter as before. */
19
+ private toRequirements;
25
20
  private parseSectionsFromContent;
26
21
  private getContentUntilNextHeaderFromLines;
27
22
  }
@@ -1,8 +1,14 @@
1
1
  import { MarkdownParser } from './markdown-parser.js';
2
2
  import { buildCodeFenceMask } from './requirement-text.js';
3
+ import { parseDeltaSpec } from './requirement-blocks.js';
3
4
  import path from 'path';
4
5
  import { promises as fs } from 'fs';
5
6
  import { discoverSpecFiles } from '../spec-discovery.js';
7
+ /** A header-only block for a REMOVED entry written in the bullet form. */
8
+ function removedNameBlock(name) {
9
+ const headerLine = `### Requirement: ${name}`;
10
+ return { headerLine, name, raw: headerLine };
11
+ }
6
12
  export class ChangeParser extends MarkdownParser {
7
13
  changeDir;
8
14
  constructor(content, changeDir) {
@@ -19,13 +25,14 @@ export class ChangeParser extends MarkdownParser {
19
25
  if (!whatChanges) {
20
26
  throw new Error('Change must have a What Changes section');
21
27
  }
22
- // Parse deltas from the What Changes section (simple format)
23
- const simpleDeltas = this.parseDeltas(whatChanges);
24
- // Check if there are spec files with delta format
25
- const specsDir = path.join(this.changeDir, 'specs');
26
- const deltaDeltas = await this.parseDeltaSpecs(specsDir);
27
- // Combine both types of deltas, preferring delta format if available
28
- const deltas = deltaDeltas.length > 0 ? deltaDeltas : simpleDeltas;
28
+ // A spec file with a delta section is the only source of structured
29
+ // deltas, even when the section applies to nothing - else a bullet-form
30
+ // REMOVED fell through to the prose fallback below as an invented
31
+ // MODIFIED. The prose is used only when no spec file has a delta section:
32
+ // no spec files, or a legacy change with full future-state specs.
33
+ const specFiles = await discoverSpecFiles(path.join(this.changeDir, 'specs'));
34
+ const { deltas: specDeltas, hasDeltaSections } = await this.parseDeltaSpecs(specFiles);
35
+ const deltas = hasDeltaSections ? specDeltas : this.parseDeltas(whatChanges);
29
36
  return {
30
37
  name,
31
38
  why: why.trim(),
@@ -37,37 +44,32 @@ export class ChangeParser extends MarkdownParser {
37
44
  },
38
45
  };
39
46
  }
40
- async parseDeltaSpecs(specsDir) {
47
+ // specFiles comes from discoverSpecFiles, which walks specs/ recursively so
48
+ // nested layouts like specs/<area>/<capability>/spec.md are parsed too.
49
+ async parseDeltaSpecs(specFiles) {
41
50
  const deltas = [];
42
- // Discover delta specs recursively so nested layouts like
43
- // specs/<area>/<capability>/spec.md are parsed too (#1353)
44
- const specFiles = await discoverSpecFiles(specsDir);
51
+ let hasDeltaSections = false;
45
52
  for (const { id, specFile } of specFiles) {
46
53
  try {
47
54
  const content = await fs.readFile(specFile, 'utf-8');
48
- const specDeltas = this.parseSpecDeltas(id, content);
49
- deltas.push(...specDeltas);
55
+ const plan = parseDeltaSpec(content);
56
+ if (Object.values(plan.sectionPresence).some(Boolean))
57
+ hasDeltaSections = true;
58
+ deltas.push(...this.parseSpecDeltas(id, plan));
50
59
  }
51
60
  catch (error) {
52
61
  // Spec file might not be readable, which is okay
53
62
  continue;
54
63
  }
55
64
  }
56
- return deltas;
65
+ return { deltas, hasDeltaSections };
57
66
  }
58
67
  /**
59
- * Read requirements from a delta section, ignoring headers that are not
60
- * `### Requirement: <name>`.
61
- *
62
- * A delta section often carries divider headers such as
63
- * `### Documentation Requirements`. The base parser treats every child header
64
- * as a requirement, which invented a scenario-less requirement that does not
65
- * exist (#498): archive warned about a missing scenario, and `show --json`
66
- * reported an extra delta. The delta reader already skips these headers and
67
- * notes them, so this keeps the two readers in agreement.
68
- *
69
- * Overriding here rather than in MarkdownParser keeps main spec parsing —
70
- * `view`, `list`, `spec --json`, spec validation — untouched.
68
+ * Reads requirements from a delta section, ignoring headers that are not
69
+ * `### Requirement: <name>` - a divider like `### Documentation
70
+ * Requirements` would otherwise be read as a scenario-less requirement,
71
+ * which the delta reader already skips and notes. Overriding here rather
72
+ * than in MarkdownParser keeps main spec parsing untouched.
71
73
  */
72
74
  parseRequirements(section) {
73
75
  return super.parseRequirements({
@@ -75,89 +77,64 @@ export class ChangeParser extends MarkdownParser {
75
77
  children: section.children.filter((child) => /^Requirement:\s*\S/i.test(child.title.trim())),
76
78
  });
77
79
  }
78
- parseSpecDeltas(specName, content) {
80
+ /** The deltas in one spec file, read by parseDeltaSpec - the same reader archive applies. */
81
+ parseSpecDeltas(specName, plan) {
79
82
  const deltas = [];
80
- const sections = this.parseSectionsFromContent(content);
81
- // Parse ADDED requirements
82
- const addedSection = this.findSection(sections, 'ADDED Requirements');
83
- if (addedSection) {
84
- const requirements = this.parseRequirements(addedSection);
85
- requirements.forEach(req => {
86
- deltas.push({
87
- spec: specName,
88
- operation: 'ADDED',
89
- description: `Add requirement: ${req.text}`,
90
- // Provide both single and plural forms for compatibility
91
- requirement: req,
92
- requirements: [req],
93
- });
83
+ // Single and plural requirement fields are both filled for compatibility.
84
+ this.toRequirements(plan.added).forEach(req => {
85
+ deltas.push({
86
+ spec: specName,
87
+ operation: 'ADDED',
88
+ description: `Add requirement: ${req.text}`,
89
+ requirement: req,
90
+ requirements: [req],
94
91
  });
95
- }
96
- // Parse MODIFIED requirements
97
- const modifiedSection = this.findSection(sections, 'MODIFIED Requirements');
98
- if (modifiedSection) {
99
- const requirements = this.parseRequirements(modifiedSection);
100
- requirements.forEach(req => {
101
- deltas.push({
102
- spec: specName,
103
- operation: 'MODIFIED',
104
- description: `Modify requirement: ${req.text}`,
105
- requirement: req,
106
- requirements: [req],
107
- });
92
+ });
93
+ this.toRequirements(plan.modified).forEach(req => {
94
+ deltas.push({
95
+ spec: specName,
96
+ operation: 'MODIFIED',
97
+ description: `Modify requirement: ${req.text}`,
98
+ requirement: req,
99
+ requirements: [req],
108
100
  });
109
- }
110
- // Parse REMOVED requirements
111
- const removedSection = this.findSection(sections, 'REMOVED Requirements');
112
- if (removedSection) {
113
- const requirements = this.parseRequirements(removedSection);
114
- requirements.forEach(req => {
115
- deltas.push({
116
- spec: specName,
117
- operation: 'REMOVED',
118
- description: `Remove requirement: ${req.text}`,
119
- requirement: req,
120
- requirements: [req],
121
- });
101
+ });
102
+ // A bullet-form REMOVED entry carries only a name, read here as a
103
+ // header-form removal with no body.
104
+ const removedBlocks = [...plan.removedBlocks];
105
+ const removed = plan.removed.map((name) => {
106
+ const index = removedBlocks.findIndex((block) => block.name === name);
107
+ return index === -1 ? removedNameBlock(name) : removedBlocks.splice(index, 1)[0];
108
+ });
109
+ this.toRequirements(removed).forEach(req => {
110
+ deltas.push({
111
+ spec: specName,
112
+ operation: 'REMOVED',
113
+ description: `Remove requirement: ${req.text}`,
114
+ requirement: req,
115
+ requirements: [req],
122
116
  });
123
- }
124
- // Parse RENAMED requirements
125
- const renamedSection = this.findSection(sections, 'RENAMED Requirements');
126
- if (renamedSection) {
127
- const renames = this.parseRenames(renamedSection.content);
128
- renames.forEach(rename => {
129
- deltas.push({
130
- spec: specName,
131
- operation: 'RENAMED',
132
- description: `Rename requirement from "${rename.from}" to "${rename.to}"`,
133
- rename,
134
- });
117
+ });
118
+ plan.renamed.forEach(rename => {
119
+ deltas.push({
120
+ spec: specName,
121
+ operation: 'RENAMED',
122
+ description: `Rename requirement from "${rename.from}" to "${rename.to}"`,
123
+ rename,
135
124
  });
136
- }
125
+ });
137
126
  return deltas;
138
127
  }
139
- parseRenames(content) {
140
- const renames = [];
141
- const lines = ChangeParser.normalizeContent(content).split('\n');
142
- let currentRename = {};
143
- for (const line of lines) {
144
- const fromMatch = line.match(/^\s*-?\s*FROM:\s*`?###\s*Requirement:\s*(.+?)`?\s*$/);
145
- const toMatch = line.match(/^\s*-?\s*TO:\s*`?###\s*Requirement:\s*(.+?)`?\s*$/);
146
- if (fromMatch) {
147
- currentRename.from = fromMatch[1].trim();
148
- }
149
- else if (toMatch) {
150
- currentRename.to = toMatch[1].trim();
151
- if (currentRename.from && currentRename.to) {
152
- renames.push({
153
- from: currentRename.from,
154
- to: currentRename.to,
155
- });
156
- currentRename = {};
157
- }
158
- }
159
- }
160
- return renames;
128
+ /** One Requirement per block, via the same section parser and header filter as before. */
129
+ toRequirements(blocks) {
130
+ return blocks.flatMap((block) => {
131
+ const [headerLine, ...body] = block.raw.split('\n');
132
+ // The delta reader also accepts `###Requirement:` with no space, which
133
+ // the section parser below would not see as a header.
134
+ const title = headerLine.replace(/^###\s*/, '').trim();
135
+ const [section] = this.parseSectionsFromContent([`### ${title}`, ...body].join('\n'));
136
+ return this.parseRequirements({ level: 2, title: '', content: '', children: [section] });
137
+ });
161
138
  }
162
139
  parseSectionsFromContent(content) {
163
140
  const normalizedContent = ChangeParser.normalizeContent(content);
@@ -1,10 +1,4 @@
1
- import { buildCodeFenceMask, extractRequirementText } from './requirement-text.js';
2
- /**
3
- * EARS scenario title: `Scenario: WHEN <event> THE SYSTEM SHALL <behavior>`
4
- * (also WHILE/WHERE/IF ... SHALL). Case-insensitive; the title is the text
5
- * after `#### ` so it still starts with `Scenario:`.
6
- */
7
- const EARS_SCENARIO_TITLE = /^Scenario:\s*(?:WHEN|WHILE|WHERE|IF)\b[\s\S]*\b(?:SHALL|MUST)\b/i;
1
+ import { buildCodeFenceMask, extractRequirementText, hasScenarioBody, EARS_SCENARIO_TITLE } from './requirement-text.js';
8
2
  export class MarkdownParser {
9
3
  lines;
10
4
  codeFenceLineMask;
@@ -136,8 +130,9 @@ export class MarkdownParser {
136
130
  parseScenarios(requirementSection) {
137
131
  const scenarios = [];
138
132
  for (const scenarioSection of requirementSection.children) {
139
- // Store the raw text content of the scenario section
140
- if (scenarioSection.content.trim()) {
133
+ // Store the raw text content of the scenario section. A header with no
134
+ // body is not a scenario; the delta counter applies the same rule.
135
+ if (hasScenarioBody(scenarioSection.content)) {
141
136
  scenarios.push({
142
137
  rawText: scenarioSection.content
143
138
  });