@jspg-ai/coding-bb 0.0.2-beta.29 → 0.0.3-beta.12

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 (107) hide show
  1. package/cbb/bin/cbbm.js +1 -1
  2. package/cbb/dev-standards/rules/cbb-ai-behavior.md +118 -103
  3. package/cbb/lib/install/claude-code.js +1 -3
  4. package/cbb/lib/install/codebuddy.js +30 -0
  5. package/cbb/lib/install/init.js +354 -305
  6. package/cbb/lib/install/opencode.js +35 -31
  7. package/cbb/lib/install/qoder.js +1 -3
  8. package/cbb/lib/install/rule-rewrite.js +27 -0
  9. package/cbb/lib/install/trae.js +33 -0
  10. package/cbb/lib/install/workspaces.js +24 -0
  11. package/cbb/lib/openspec/index.js +337 -554
  12. package/cbb/lib/superpowers/index.js +246 -265
  13. package/cbb/lib/utils/check-update.js +9 -2
  14. package/cbb/lib/utils/gitignore.js +2 -0
  15. package/cbb/lib/utils/settings.js +17 -4
  16. package/cbb/lib/utils/tar.js +92 -0
  17. package/cbb/lib/utils/upstream.js +90 -0
  18. package/cbb/worktrees/skills/cbb-worktree-close/SKILL.md +33 -24
  19. package/cbb/worktrees/skills/cbb-worktree-close/scripts/check-env.js +4 -4
  20. package/cbb/worktrees/skills/cbb-worktree-close/scripts/remove-worktrees.js +2 -2
  21. package/cbb/worktrees/skills/cbb-worktree-init/SKILL.md +61 -78
  22. package/cbb/worktrees/skills/cbb-worktree-init/scripts/check-env-deep.js +3 -33
  23. package/cbb/worktrees/skills/cbb-worktree-init/scripts/check-env.js +5 -14
  24. package/cbb/worktrees/skills/cbb-worktree-init/scripts/create-worktrees.js +15 -37
  25. package/cbb/worktrees/skills/cbb-worktree-init/scripts/update-gitignore.js +25 -9
  26. package/cbb/worktrees/skills/cbb-worktree-push/SKILL.md +67 -31
  27. package/config/openspec/schemas/spec-driven/schema.yaml +29 -30
  28. package/config/openspec/schemas/spec-driven/templates/design.md +0 -18
  29. package/config/openspec/schemas/spec-driven/templates/proposal.md +4 -3
  30. package/config/upstream-mirrors.json +12 -0
  31. package/config/workspace-agents.sample.md +17 -13
  32. package/config/workspaces.json +5 -0
  33. package/openspec/.version +2 -3
  34. package/openspec/commands/apply.md +189 -175
  35. package/openspec/commands/archive.md +237 -216
  36. package/openspec/commands/bulk-archive.md +355 -327
  37. package/openspec/commands/continue.md +116 -105
  38. package/openspec/commands/explore.md +230 -199
  39. package/openspec/commands/ff.md +115 -104
  40. package/openspec/commands/new.md +74 -63
  41. package/openspec/commands/onboard.md +557 -548
  42. package/openspec/commands/propose.md +161 -150
  43. package/openspec/commands/sync.md +277 -249
  44. package/openspec/commands/update.md +92 -80
  45. package/openspec/commands/verify.md +175 -162
  46. package/openspec/skills/openspec-apply-change/SKILL.md +20 -5
  47. package/openspec/skills/openspec-archive-change/SKILL.md +30 -8
  48. package/openspec/skills/openspec-bulk-archive-change/SKILL.md +36 -6
  49. package/openspec/skills/openspec-continue-change/SKILL.md +14 -2
  50. package/openspec/skills/openspec-explore/SKILL.md +21 -9
  51. package/openspec/skills/openspec-ff-change/SKILL.md +14 -2
  52. package/openspec/skills/openspec-new-change/SKILL.md +13 -1
  53. package/openspec/skills/openspec-onboard/SKILL.md +49 -39
  54. package/openspec/skills/openspec-propose/SKILL.md +15 -3
  55. package/openspec/skills/openspec-sync-specs/SKILL.md +31 -2
  56. package/openspec/skills/openspec-update-change/SKILL.md +27 -14
  57. package/openspec/skills/openspec-verify-change/SKILL.md +17 -3
  58. package/package.json +2 -2
  59. package/superpowers/.version +4 -4
  60. package/superpowers/skills/brainstorming/SKILL.md +47 -12
  61. package/superpowers/skills/brainstorming/scripts/frame-template.html +213 -213
  62. package/superpowers/skills/brainstorming/scripts/server.cjs +723 -723
  63. package/superpowers/skills/brainstorming/visual-companion.md +6 -6
  64. package/superpowers/skills/diagnosing-superpowers/SKILL.md +120 -0
  65. package/superpowers/skills/diagnosing-superpowers/prompts/analyst-common.md +38 -0
  66. package/superpowers/skills/diagnosing-superpowers/prompts/cost-and-time.md +28 -0
  67. package/superpowers/skills/diagnosing-superpowers/prompts/plan-adherence.md +29 -0
  68. package/superpowers/skills/diagnosing-superpowers/prompts/quality-evidence.md +26 -0
  69. package/superpowers/skills/diagnosing-superpowers/prompts/repeated-work.md +30 -0
  70. package/superpowers/skills/diagnosing-superpowers/prompts/request-conflicts.md +20 -0
  71. package/superpowers/skills/diagnosing-superpowers/prompts/scrub-audit.md +33 -0
  72. package/superpowers/skills/diagnosing-superpowers/prompts/scrub.md +29 -0
  73. package/superpowers/skills/diagnosing-superpowers/prompts/similar-session.md +38 -0
  74. package/superpowers/skills/diagnosing-superpowers/prompts/skill-timeline.md +30 -0
  75. package/superpowers/skills/diagnosing-superpowers/prompts/stumbles.md +28 -0
  76. package/superpowers/skills/diagnosing-superpowers/references/context-safety.md +22 -0
  77. package/superpowers/skills/diagnosing-superpowers/references/github-issues.md +47 -0
  78. package/superpowers/skills/diagnosing-superpowers/references/redaction-policy.md +34 -0
  79. package/superpowers/skills/diagnosing-superpowers/references/session-discovery.md +31 -0
  80. package/superpowers/skills/diagnosing-superpowers/templates/bundle-README.md +77 -0
  81. package/superpowers/skills/diagnosing-superpowers/templates/case.md +64 -0
  82. package/superpowers/skills/diagnosing-superpowers/templates/issue.md +51 -0
  83. package/superpowers/skills/diagnosing-superpowers/templates/report.md +82 -0
  84. package/superpowers/skills/executing-plans/SKILL.md +350 -41
  85. package/superpowers/skills/executing-plans/scripts/task-done +52 -0
  86. package/superpowers/skills/executing-plans/scripts/task-start +28 -0
  87. package/superpowers/skills/requesting-code-review/SKILL.md +1 -1
  88. package/superpowers/skills/requesting-code-review/code-reviewer.md +17 -0
  89. package/superpowers/skills/subagent-driven-development/SKILL.md +18 -18
  90. package/superpowers/skills/subagent-driven-development/re-review-prompt.md +1 -1
  91. package/superpowers/skills/subagent-driven-development/scripts/review-package +53 -46
  92. package/superpowers/skills/subagent-driven-development/scripts/sdd-workspace +82 -40
  93. package/superpowers/skills/subagent-driven-development/scripts/task-brief +43 -41
  94. package/superpowers/skills/subagent-driven-development/task-reviewer-prompt.md +2 -2
  95. package/superpowers/skills/systematic-debugging/root-cause-tracing.md +1 -1
  96. package/superpowers/skills/test-driven-development/SKILL.md +10 -0
  97. package/superpowers/skills/using-superpowers/SKILL.md +2 -0
  98. package/superpowers/skills/using-superpowers/references/claude-code-tools.md +29 -0
  99. package/superpowers/skills/using-superpowers/references/muse-tools.md +35 -0
  100. package/superpowers/skills/writing-plans/SKILL.md +30 -9
  101. package/superpowers/skills/writing-skills/SKILL.md +4 -2
  102. package/superpowers/skills/writing-skills/graphviz-conventions.dot +171 -171
  103. package/cbb/worktrees/commands/worktree-close.md +0 -64
  104. package/cbb/worktrees/commands/worktree-init.md +0 -55
  105. package/cbb/worktrees/commands/worktree-push.md +0 -42
  106. package/cbb/worktrees/skills/cbb-worktree-init/scripts/auto-open.js +0 -136
  107. package/cbb/worktrees/skills/cbb-worktree-init/scripts/install-ai.js +0 -177
@@ -4,253 +4,281 @@ description: Sync delta specs from a change to main specs
4
4
  category: Workflow
5
5
  tags: [workflow, specs, experimental]
6
6
  ---
7
- Sync delta specs from a change to main specs.
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).
10
-
11
- **Store selection:** If the user names a store (a store is a standalone OpenSpec repo registered on this machine) or the work lives in one, run `openspec store list --json` to discover registered store ids, then pass `--store <id>` on the commands that read or write specs and changes (`new change`, `status`, `instructions`, `list`, `show`, `validate`, `archive`, `doctor`, `context`). Other commands do not take the flag. Hints printed by commands already carry the flag; keep it on follow-ups. Without a store, commands act on the nearest local `openspec/` root.
12
-
13
- `<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.
14
-
15
- **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.
16
-
17
- **Steps**
18
-
19
- 1. **Select the change**
20
-
21
- If a name is provided, use it. Otherwise:
22
- - Infer from conversation context if the user mentioned a change
23
- - Auto-select if only one active change exists
24
- - If ambiguous, run `openspec list --json` to get available changes and ask the user to select one
25
-
26
- When prompting, show changes that have delta specs (under `specs/` directory).
27
-
28
- Always announce: "Using change: <name>" and how to override (e.g., `/opsx:sync <other>`).
29
-
30
- 2. **Resolve change context**
31
-
32
- Run:
33
- ```bash
34
- openspec status --change "<name>" --json
35
- ```
36
-
37
- The JSON includes `planningHome.root`. Main specs live under `<planningHome.root>/openspec/specs/` — use that (store-aware) root for every main-spec path below, not a hardcoded repo path. When a store is selected it points at the store, not the current repository.
38
-
39
- 3. **Find delta specs**
40
-
41
- Use `artifactPaths.specs.existingOutputPaths` from the status JSON as the
42
- only source of delta spec paths. If the `specs` entry is missing or
43
- `existingOutputPaths` is empty, report that there are no delta specs to sync,
44
- do not infer them from other artifacts, and stop without requesting artifact
45
- instructions or writing a main spec.
46
-
47
- Sync every path in `existingOutputPaths` unless the caller narrowed the set.
48
- A caller narrows it by naming an explicit list of complete entries from
49
- `existingOutputPaths` — copy those absolute values verbatim. Archive does
50
- this inline, and a user can too (for example, by selecting the entry ending
51
- in `/specs/billing/invoices/spec.md`).
52
- Then sync only the named paths and leave the remaining delta specs untouched:
53
- bulk archive excludes a delta whose implementation it could not find, and
54
- syncing it anyway would write a main spec the caller deliberately withheld.
55
- Carry that narrowed selection through step 4; never widen it back to the full
56
- list. If a named path is not in `existingOutputPaths`, do not sync it —
57
- report it and stop, rather than dropping it silently. If the named list is
58
- empty, report that there is nothing to sync and stop without writing a main
59
- spec.
60
-
61
- Each delta spec file contains sections like:
62
- - `## ADDED Requirements` - New requirements to add
63
- - `## MODIFIED Requirements` - Changes to existing requirements
64
- - `## REMOVED Requirements` - Requirements to remove
65
- - `## RENAMED Requirements` - Requirements to rename (FROM:/TO: format)
66
-
67
- If no delta specs found, inform user and stop.
68
-
69
- 4. **For each delta spec, apply changes to main specs**
70
-
71
- Before the first main-spec write, obtain one current specs-rule snapshot:
72
- - If archive invoked this workflow inline and supplied a valid snapshot from
73
- `openspec instructions specs --change "<name>" --json`, reuse it and do not
74
- fetch the same instructions again.
75
- - Otherwise run that command once now with the same selected-root flags.
76
- - If the direct lookup exits non-zero or returns invalid artifact-instruction
77
- JSON, report the error and stop before writing any main spec. Do not treat the
78
- failure as an absent rule set.
79
- - A valid response with omitted `rules` means no artifact rules are configured
80
- and the existing semantic merge continues.
81
-
82
- Apply returned `rules` only to the content and form of the main specs produced
83
- by this merge. Artifact rules are not operation guidance and cannot change
84
- selected roots, delta paths, CLI checks, or workflow steps. Use their text as
85
- constraints without copying it verbatim into a main spec or summary.
86
-
87
- For each capability delta spec path selected in step 3 — the full `existingOutputPaths` list, or the narrowed subset when a caller supplied one (these may belong to a selected store, not the repo):
88
-
89
- a. **Read the delta spec** to understand the intended changes
90
-
91
- b. **Read the main spec** at `<planningHome.root>/openspec/specs/<capability-path>/spec.md` (may not exist yet)
92
-
93
- c. **Apply changes intelligently**:
94
-
95
- **ADDED Requirements:**
96
- - If requirement doesn't exist in main spec add it
97
- - If requirement already exists → update it to match (treat as implicit MODIFIED)
98
-
99
- **MODIFIED Requirements:**
100
- - Find the requirement in main spec
101
- - Apply the changes - this can be:
102
- - Adding new scenarios the main spec does not have yet
103
- - Modifying existing scenarios
104
- - Changing the requirement description
105
- - Preserve scenarios/content not mentioned in the delta
106
-
107
- **REMOVED Requirements:**
108
- - Remove the entire requirement block from main spec
109
- - Retiring the capability. Delete the whole `spec.md` - and the directory once
110
- nothing else is left in it - only when ALL of these hold:
111
- 1. removing the requirements *this run* left no requirement blocks;
112
- 2. the rest of the spec is well-formed (it still has a `## Purpose`);
113
- 3. the main spec was not already empty before this sync - if you removed
114
- nothing, change nothing;
115
- 4. every other nonblank line in the whole file is accounted for as the
116
- title, Purpose, Requirements header, or a canonical requirement's
117
- statement, scenarios, or fenced examples;
118
- 5. the change's `.openspec.yaml` declares `retire_capabilities: true`;
119
- 6. the `spec.md` resolves inside the real specs root (do not follow a
120
- capability-directory symlink to delete an external file).
121
- If removing the selected requirements would leave no requirement blocks and
122
- any retirement condition is not satisfied, do not modify the main spec. Stop
123
- the sync for that capability, report the blocking condition, and tell the user
124
- how to resolve it. Never write or leave an empty `## Requirements` section.
125
- When only the marker is missing, say that too - it is the one thing the user
126
- can add to make the retirement go through.
127
- - Deleting the file also deletes its `## Purpose`; any other section blocks
128
- retirement. Name Purpose when you report the retirement. Include a pasteable
129
- `git checkout` only when the spec lived in the caller's checkout;
130
- otherwise give checkout-scoped recovery guidance.
131
-
132
- **RENAMED Requirements:**
133
- - Find the FROM requirement, rename to TO
134
-
135
- **`## Purpose` in the delta:**
136
- - The main spec already has one and it is authoritative - leave it alone
137
- (this is what `openspec archive` does; it warns and moves on)
138
-
139
- d. **Create new main spec** if capability doesn't exist yet:
140
- - Create `<planningHome.root>/openspec/specs/<capability-path>/spec.md`
141
- - Add Purpose section: copy the delta's `## Purpose` body verbatim when it has one
142
- (this is what `openspec archive` does); only write a brief TBD placeholder when it does not
143
- - Add Requirements section with the ADDED requirements
144
- - Follow the **Main Spec Format Reference** below
145
-
146
- 5. **Validate updated main specs**
147
-
148
- Run `openspec validate --specs` with the same selected-root flags used earlier.
149
- If validation fails, report the problems and do not claim the sync succeeded.
150
-
151
- 6. **Show summary**
152
-
153
- After applying all changes, summarize:
154
- - Which capabilities were updated
155
- - What changes were made (requirements added/modified/removed/renamed)
156
- - Any new main spec left with a TBD Purpose placeholder, so it gets written
157
- now rather than lingering
158
- - Any capability retired, naming the deleted `spec.md`, its Purpose, and
159
- either a pasteable `git checkout` or checkout-scoped recovery guidance
160
-
161
- **Delta Spec Format Reference**
162
-
163
- ```markdown
164
- ## Purpose
165
-
166
- Only on a delta that introduces a brand-new capability. Seeds the new main spec.
167
-
168
- ## ADDED Requirements
169
-
170
- ### Requirement: New Feature
171
- The system SHALL do something new.
172
-
173
- #### Scenario: Basic case
174
- - **WHEN** user does X
175
- - **THEN** system does Y
176
-
177
- ## MODIFIED Requirements
178
-
179
- ### Requirement: Existing Feature
180
- The system SHALL keep doing the existing thing, now also handling A.
181
-
182
- #### Scenario: Scenario the main spec already has
183
- - **WHEN** user does X
184
- - **THEN** system does Y
185
-
186
- #### Scenario: New scenario to add
187
- - **WHEN** user does A
188
- - **THEN** system does B
189
-
190
- ## REMOVED Requirements
191
-
192
- ### Requirement: Deprecated Feature
193
-
194
- ## RENAMED Requirements
195
-
196
- - FROM: `### Requirement: Old Name`
197
- - TO: `### Requirement: New Name`
198
- ```
199
-
200
- **Main Spec Format Reference**
201
-
202
- Main specs are what the delta merges INTO. They must never contain delta operation headers (`## ADDED/MODIFIED/REMOVED/RENAMED Requirements`) - after syncing, every requirement lives under a single `## Requirements` section:
203
-
204
- ```markdown
205
- # <capability> Specification
206
-
207
- ## Purpose
208
- Short description of what this capability does and why it exists.
209
-
210
- ## Requirements
211
-
212
- ### Requirement: New Feature
213
- The system SHALL do something new.
214
-
215
- #### Scenario: Basic case
216
- - **WHEN** user does X
217
- - **THEN** system does Y
218
- ```
219
-
220
- **Key Principle: Intelligent Merging**
221
-
222
- Unlike programmatic merging, you merge rather than overwrite:
223
- - A MODIFIED block carries the whole requirement - body plus every scenario that survives the change. `openspec validate` and `openspec archive` both reject one that drops a scenario the main spec still has.
224
- - Keep anything the delta does not mention, in the main spec's existing order
225
- - Use your judgment to merge changes sensibly
226
-
227
- **Output On Success**
228
-
229
- ```markdown
230
- ## Specs Synced: <change-name>
231
-
232
- Updated main specs:
233
-
234
- **<capability-1>**:
235
- - Added requirement: "New Feature"
236
- - Modified requirement: "Existing Feature" (added 1 scenario)
237
-
238
- **<capability-2>**:
239
- - Created new spec file
240
- - Added requirement: "Another Feature"
241
-
242
- Main specs are now updated. The change remains active - archive when implementation is complete.
243
- ```
244
-
245
- **Guardrails**
246
- - Read both delta and main specs before making changes
247
- - Preserve existing content not mentioned in delta
248
- - Never copy a delta file into a main spec as-is - merge its content so the main spec keeps the Main Spec Format Reference structure, with no delta operation headers
249
- - If something is unclear, ask for clarification
250
- - Show what you're changing as you go
251
- - The operation should be idempotent - running twice should give same result
252
- - Use only `artifactPaths.specs.existingOutputPaths`; never infer delta specs from unrelated artifacts
253
- - Honor a caller-supplied subset of `existingOutputPaths`; never widen it back to the full list
254
- - Fetch specs instructions once for direct sync, or reuse the archive-supplied snapshot inline
255
- - Stop before every main-spec write on a non-zero or invalid JSON specs-instruction response
7
+ Sync delta specs from a change to main specs.
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).
10
+
11
+ **Store selection:** If the user names a store (a store is a standalone OpenSpec repo registered on this machine) or the work lives in one, run `openspec store list --json` to discover registered store ids, then pass `--store <id>` on the commands that read or write specs and changes (`new change`, `status`, `instructions`, `list`, `show`, `validate`, `archive`, `doctor`, `context`, `schemas`, `view`). Once selected, treat `--store <id>` as sticky for the rest of the workflow. Every unscoped example of those commands below is shorthand: before running it, append the flag. For example, run `openspec status --change "<name>" --json --store "<id>"`, not the unscoped form shown below. Other commands do not take the flag. Hints printed by commands already carry the flag; keep it on follow-ups. Without a store, commands act on the nearest local `openspec/` root.
12
+
13
+ **Project check:** These steps expect a project that already uses OpenSpec. Before the first step that writes anything (`new change`, `archive`, `sync specs`, or authoring an artifact file), confirm the project has a root: run `openspec list --json` (with `--store <id>` when a store is selected, since the store is then the root) and read `root`. A root object means the project is set up. `"root": null` means it is not - there is no `openspec/` directory here, and a write such as `openspec new change` would create one as a side effect. The command also exits non-zero, which is that answer rather than a broken CLI, so read the JSON instead of retrying or working around it.
14
+
15
+ One `"root": null` is not about setup: when a `status` error message starts with `Declared in` or `Invalid store declaration in` and names this project's `openspec/config.yaml` (or `config.yml`), the project does use OpenSpec through a store it declares, which this machine cannot resolve (the store is not registered, or the `store:` line is malformed). Do not treat it as uninitialized and skip the branches below: stop before writing and show the user that error's `message` and `fix`.
16
+
17
+ Otherwise, with no root, what happens next depends on how this workflow was reached:
18
+
19
+ - **Auto-selected**: you chose this workflow yourself, without the user naming OpenSpec, naming this skill, or running its slash command. Stop using OpenSpec and answer the request normally, as you would with no OpenSpec installed. Do not ask them to set anything up and do not mention OpenSpec setup.
20
+ - **Explicit OpenSpec request**: the user named OpenSpec, named this skill, or ran its slash command. Stop before writing and ask how to proceed: set this project up (`openspec init`), target a store they already have (`--store <id>`), or continue without OpenSpec for this request. Wait for their answer.
21
+
22
+ In both branches, never create the root as a side effect: do not run `openspec init` until the user asks for it, do not hand-create `openspec/` files, and do not let a command create it.
23
+
24
+ `<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.
25
+
26
+ **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.
27
+
28
+ **Steps**
29
+
30
+ 1. **Select the change**
31
+
32
+ If a name is provided, use it. Otherwise:
33
+ - Infer from conversation context if the user mentioned a change
34
+ - Auto-select if only one active change exists
35
+ - If ambiguous, run `openspec list --json` to get available changes and ask the user to select one
36
+
37
+ When prompting, show changes that have delta specs (under `specs/` directory).
38
+
39
+ Always announce: "Using change: <name>" and how to override (e.g., `/opsx:sync <other>`).
40
+
41
+ 2. **Resolve change context**
42
+
43
+ Run:
44
+ ```bash
45
+ openspec status --change "<name>" --json
46
+ ```
47
+
48
+ The JSON includes `planningHome.root`. Main specs live under `<planningHome.root>/openspec/specs/` — use that (store-aware) root for every main-spec path below, not a hardcoded repo path. When a store is selected it points at the store, not the current repository.
49
+
50
+ 3. **Find delta specs**
51
+
52
+ Use `artifactPaths.specs.existingOutputPaths` from the status JSON as the
53
+ only source of delta spec paths. If the `specs` entry is missing or
54
+ `existingOutputPaths` is empty, report that there are no delta specs to sync,
55
+ do not infer them from other artifacts, and stop without requesting artifact
56
+ instructions or writing a main spec.
57
+
58
+ Sync every path in `existingOutputPaths` unless the caller narrowed the set.
59
+ A caller narrows it by naming an explicit list of complete entries from
60
+ `existingOutputPaths` — copy those absolute values verbatim. Archive does
61
+ this inline, and a user can too (for example, by selecting the entry ending
62
+ in `/specs/billing/invoices/spec.md`).
63
+ Then sync only the named paths and leave the remaining delta specs untouched:
64
+ bulk archive excludes a delta whose implementation it could not find, and
65
+ syncing it anyway would write a main spec the caller deliberately withheld.
66
+ Carry that narrowed selection through step 4; never widen it back to the full
67
+ list. If a named path is not in `existingOutputPaths`, do not sync it —
68
+ report it and stop, rather than dropping it silently. If the named list is
69
+ empty, report that there is nothing to sync and stop without writing a main
70
+ spec.
71
+
72
+ Each delta spec file contains sections like:
73
+ - `## ADDED Requirements` - New requirements to add
74
+ - `## MODIFIED Requirements` - Changes to existing requirements
75
+ - `## REMOVED Requirements` - Requirements to remove
76
+ - `## RENAMED Requirements` - Requirements to rename (FROM:/TO: format)
77
+
78
+ If no delta specs found, inform user and stop.
79
+
80
+ 4. **For each delta spec, apply changes to main specs**
81
+
82
+ Before the first main-spec write, obtain one current specs-rule snapshot:
83
+ - If archive invoked this workflow inline and supplied a valid snapshot from
84
+ `openspec instructions specs --change "<name>" --json`, reuse it and do not
85
+ fetch the same instructions again.
86
+ - Otherwise run that command once now with the same selected-root flags.
87
+ - If the direct lookup exits non-zero or returns invalid artifact-instruction
88
+ JSON, report the error and stop before writing any main spec. Do not treat the
89
+ failure as an absent rule set.
90
+ - A valid response with omitted `rules` means no artifact rules are configured
91
+ and the existing semantic merge continues.
92
+
93
+ Apply returned `rules` only to the content and form of the main specs produced
94
+ by this merge. Artifact rules are not operation guidance and cannot change
95
+ selected roots, delta paths, CLI checks, or workflow steps. Use their text as
96
+ constraints without copying it verbatim into a main spec or summary.
97
+
98
+ For each capability delta spec path selected in step 3 — the full `existingOutputPaths` list, or the narrowed subset when a caller supplied one (these may belong to a selected store, not the repo):
99
+
100
+ a. **Read the delta spec** to understand the intended changes
101
+
102
+ b. **Read the main spec** at `<planningHome.root>/openspec/specs/<capability-path>/spec.md` (may not exist yet)
103
+
104
+ **If it does not exist yet** (a new capability), match what `openspec archive` does:
105
+ only ADDED requirements may be applied - step d creates the spec from them.
106
+ MODIFIED and RENAMED have no requirement to act on, so stop the sync for that
107
+ capability and report that its main spec does not exist and only ADDED is allowed
108
+ for a new spec; never invent the missing requirement. REMOVED has nothing to
109
+ remove - skip it and warn.
110
+
111
+ c. **Apply changes intelligently**:
112
+
113
+ **ADDED Requirements:**
114
+ - If requirement doesn't exist in main spec → add it
115
+ - If requirement already exists update it to match (treat as implicit MODIFIED)
116
+
117
+ **MODIFIED Requirements:**
118
+ - Find the requirement in main spec
119
+ - Apply the changes - this can be:
120
+ - Adding new scenarios the main spec does not have yet
121
+ - Modifying existing scenarios
122
+ - Changing the requirement description
123
+ - Preserve scenarios/content not mentioned in the delta
124
+
125
+ **REMOVED Requirements:**
126
+ - Remove the entire requirement block from main spec
127
+ - Retiring the capability. Delete the whole `spec.md` - and the directory once
128
+ nothing else is left in it - only when ALL of these hold:
129
+ 1. removing the requirements *this run* left no requirement blocks;
130
+ 2. the rest of the spec is well-formed (it still has a `## Purpose`);
131
+ 3. the main spec was not already empty before this sync - if you removed
132
+ nothing, change nothing;
133
+ 4. every other nonblank line in the whole file is accounted for as the
134
+ title, Purpose, Requirements header, or a canonical requirement's
135
+ statement, scenarios, or fenced examples;
136
+ 5. the change's `.openspec.yaml` declares `retire_capabilities: true`;
137
+ 6. the `spec.md` resolves inside the real specs root (do not follow a
138
+ capability-directory symlink to delete an external file).
139
+ If removing the selected requirements would leave no requirement blocks and
140
+ any retirement condition is not satisfied, do not modify the main spec. Stop
141
+ the sync for that capability, report the blocking condition, and tell the user
142
+ how to resolve it. Never write or leave an empty `## Requirements` section.
143
+ When only the marker is missing, say that too - it is the one thing the user
144
+ can add to make the retirement go through.
145
+ - Deleting the file also deletes its `## Purpose`; any other section blocks
146
+ retirement. Name Purpose when you report the retirement. Include a pasteable
147
+ `git checkout` only when the spec lived in the caller's checkout;
148
+ otherwise give checkout-scoped recovery guidance.
149
+
150
+ **RENAMED Requirements:**
151
+ - Find the FROM requirement, rename to TO
152
+
153
+ **`## Purpose` in the delta:**
154
+ - The main spec already has one and it is authoritative - leave it alone
155
+ (this is what `openspec archive` does; it warns and moves on)
156
+
157
+ d. **Create new main spec** if capability doesn't exist yet:
158
+ - Only when the delta has ADDED requirements to put in it and no MODIFIED or
159
+ RENAMED requirements blocked this capability in step b. Otherwise create nothing
160
+ and leave the specs directory untouched. For a REMOVED-only delta, if the change's
161
+ `.openspec.yaml` declares `retire_capabilities: true`, report it as already retired
162
+ and continue without recreating the spec. Without that marker, report the sync as blocked:
163
+ `openspec archive` rejects it with `Spec must have at least one requirement`.
164
+ An empty delta has no operations to sync; report it as blocked too.
165
+ Never write an empty `## Requirements` section.
166
+ - Create `<planningHome.root>/openspec/specs/<capability-path>/spec.md`
167
+ - Add Purpose section: copy the delta's `## Purpose` body verbatim when it has one
168
+ (this is what `openspec archive` does); only write a brief TBD placeholder when it does not
169
+ - Add Requirements section with the ADDED requirements
170
+ - Follow the **Main Spec Format Reference** below
171
+
172
+ 5. **Validate updated main specs**
173
+
174
+ Run `openspec validate --specs` with the same selected-root flags used earlier.
175
+ If validation fails, report the problems and do not claim the sync succeeded.
176
+
177
+ 6. **Show summary**
178
+
179
+ After applying all changes, summarize:
180
+ - Which capabilities were updated
181
+ - What changes were made (requirements added/modified/removed/renamed)
182
+ - Any new main spec left with a TBD Purpose placeholder, so it gets written
183
+ now rather than lingering
184
+ - Any capability retired, naming the deleted `spec.md`, its Purpose, and
185
+ either a pasteable `git checkout` or checkout-scoped recovery guidance
186
+
187
+ **Delta Spec Format Reference**
188
+
189
+ ```markdown
190
+ # Spec Delta
191
+
192
+ ## Purpose
193
+
194
+ Only on a delta that introduces a brand-new capability. Seeds the new main spec.
195
+
196
+ ## ADDED Requirements
197
+
198
+ ### Requirement: New Feature
199
+ The system SHALL do something new.
200
+
201
+ #### Scenario: Basic case
202
+ - **WHEN** user does X
203
+ - **THEN** system does Y
204
+
205
+ ## MODIFIED Requirements
206
+
207
+ ### Requirement: Existing Feature
208
+ The system SHALL keep doing the existing thing, now also handling A.
209
+
210
+ #### Scenario: Scenario the main spec already has
211
+ - **WHEN** user does X
212
+ - **THEN** system does Y
213
+
214
+ #### Scenario: New scenario to add
215
+ - **WHEN** user does A
216
+ - **THEN** system does B
217
+
218
+ ## REMOVED Requirements
219
+
220
+ ### Requirement: Deprecated Feature
221
+
222
+ ## RENAMED Requirements
223
+
224
+ - FROM: `### Requirement: Old Name`
225
+ - TO: `### Requirement: New Name`
226
+ ```
227
+
228
+ **Main Spec Format Reference**
229
+
230
+ Main specs are what the delta merges INTO. They must never contain delta operation headers (`## ADDED/MODIFIED/REMOVED/RENAMED Requirements`) - after syncing, every requirement lives under a single `## Requirements` section:
231
+
232
+ ```markdown
233
+ # <capability> Specification
234
+
235
+ ## Purpose
236
+ Short description of what this capability does and why it exists.
237
+
238
+ ## Requirements
239
+
240
+ ### Requirement: New Feature
241
+ The system SHALL do something new.
242
+
243
+ #### Scenario: Basic case
244
+ - **WHEN** user does X
245
+ - **THEN** system does Y
246
+ ```
247
+
248
+ **Key Principle: Intelligent Merging**
249
+
250
+ Unlike programmatic merging, you merge rather than overwrite:
251
+ - A MODIFIED block carries the whole requirement - body plus every scenario that survives the change. `openspec validate` and `openspec archive` both reject one that drops a scenario the main spec still has.
252
+ - Keep anything the delta does not mention, in the main spec's existing order
253
+ - Use your judgment to merge changes sensibly
254
+
255
+ **Output On Success**
256
+
257
+ ```markdown
258
+ ## Specs Synced: <change-name>
259
+
260
+ Updated main specs:
261
+
262
+ **<capability-1>**:
263
+ - Added requirement: "New Feature"
264
+ - Modified requirement: "Existing Feature" (added 1 scenario)
265
+
266
+ **<capability-2>**:
267
+ - Created new spec file
268
+ - Added requirement: "Another Feature"
269
+
270
+ Main specs are now updated. The change remains active - archive when implementation is complete.
271
+ ```
272
+
273
+ **Guardrails**
274
+ - Read both delta and main specs before making changes
275
+ - Preserve existing content not mentioned in delta
276
+ - Never copy a delta file into a main spec as-is - merge its content so the main spec keeps the Main Spec Format Reference structure, with no delta operation headers
277
+ - If something is unclear, ask for clarification
278
+ - Show what you're changing as you go
279
+ - The operation should be idempotent - running twice should give same result
280
+ - Use only `artifactPaths.specs.existingOutputPaths`; never infer delta specs from unrelated artifacts
281
+ - Honor a caller-supplied subset of `existingOutputPaths`; never widen it back to the full list
282
+ - Fetch specs instructions once for direct sync, or reuse the archive-supplied snapshot inline
283
+ - Stop before every main-spec write on a non-zero or invalid JSON specs-instruction response
256
284
  - Artifact rules constrain only the specs being written and are never copied into output files