@fission-ai/openspec 1.6.0 → 1.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (208) hide show
  1. package/README.md +31 -2
  2. package/dist/cli/index.js +79 -8
  3. package/dist/commands/change.d.ts +0 -1
  4. package/dist/commands/change.js +105 -51
  5. package/dist/commands/config.js +14 -8
  6. package/dist/commands/doctor.js +9 -4
  7. package/dist/commands/feedback.js +74 -23
  8. package/dist/commands/schema.js +110 -31
  9. package/dist/commands/show.js +5 -2
  10. package/dist/commands/spec.js +49 -29
  11. package/dist/commands/validate.js +20 -5
  12. package/dist/commands/workflow/index.d.ts +1 -1
  13. package/dist/commands/workflow/index.js +1 -1
  14. package/dist/commands/workflow/instructions.d.ts +7 -1
  15. package/dist/commands/workflow/instructions.js +121 -33
  16. package/dist/commands/workflow/shared.d.ts +13 -2
  17. package/dist/commands/workflow/shared.js +34 -4
  18. package/dist/commands/workflow/status.js +9 -4
  19. package/dist/commands/workflow/templates.js +15 -5
  20. package/dist/core/archive.d.ts +14 -1
  21. package/dist/core/archive.js +1332 -155
  22. package/dist/core/artifact-graph/graph.d.ts +16 -0
  23. package/dist/core/artifact-graph/graph.js +30 -6
  24. package/dist/core/artifact-graph/index.d.ts +1 -1
  25. package/dist/core/artifact-graph/index.js +1 -1
  26. package/dist/core/artifact-graph/instruction-loader.d.ts +30 -3
  27. package/dist/core/artifact-graph/instruction-loader.js +70 -12
  28. package/dist/core/artifact-graph/outputs.d.ts +1 -0
  29. package/dist/core/artifact-graph/outputs.js +67 -5
  30. package/dist/core/artifact-graph/resolver.d.ts +14 -0
  31. package/dist/core/artifact-graph/resolver.js +69 -15
  32. package/dist/core/artifact-graph/types.js +21 -3
  33. package/dist/core/available-tools.d.ts +2 -2
  34. package/dist/core/available-tools.js +14 -3
  35. package/dist/core/change-metadata/schema.d.ts +2 -0
  36. package/dist/core/change-metadata/schema.js +13 -0
  37. package/dist/core/change-status-policy.d.ts +1 -1
  38. package/dist/core/change-status-policy.js +2 -2
  39. package/dist/core/command-generation/adapters/amazon-q.d.ts +4 -0
  40. package/dist/core/command-generation/adapters/amazon-q.js +7 -1
  41. package/dist/core/command-generation/adapters/antigravity.js +2 -1
  42. package/dist/core/command-generation/adapters/auggie.js +2 -1
  43. package/dist/core/command-generation/adapters/bob.d.ts +5 -1
  44. package/dist/core/command-generation/adapters/bob.js +6 -5
  45. package/dist/core/command-generation/adapters/claude.js +1 -8
  46. package/dist/core/command-generation/adapters/codebuddy.js +3 -2
  47. package/dist/core/command-generation/adapters/continue.js +3 -2
  48. package/dist/core/command-generation/adapters/costrict.js +2 -1
  49. package/dist/core/command-generation/adapters/crush.js +5 -5
  50. package/dist/core/command-generation/adapters/cursor.js +2 -2
  51. package/dist/core/command-generation/adapters/devin.d.ts +19 -0
  52. package/dist/core/command-generation/adapters/devin.js +36 -0
  53. package/dist/core/command-generation/adapters/factory.js +2 -1
  54. package/dist/core/command-generation/adapters/gemini.js +37 -2
  55. package/dist/core/command-generation/adapters/github-copilot.js +2 -1
  56. package/dist/core/command-generation/adapters/iflow.js +5 -4
  57. package/dist/core/command-generation/adapters/index.d.ts +2 -2
  58. package/dist/core/command-generation/adapters/index.js +2 -2
  59. package/dist/core/command-generation/adapters/junie.js +2 -1
  60. package/dist/core/command-generation/adapters/kiro.js +2 -1
  61. package/dist/core/command-generation/adapters/lingma.js +5 -5
  62. package/dist/core/command-generation/adapters/oh-my-pi.d.ts +2 -2
  63. package/dist/core/command-generation/adapters/oh-my-pi.js +3 -5
  64. package/dist/core/command-generation/adapters/opencode.js +3 -5
  65. package/dist/core/command-generation/adapters/pi.d.ts +2 -2
  66. package/dist/core/command-generation/adapters/pi.js +3 -6
  67. package/dist/core/command-generation/adapters/qoder.js +5 -5
  68. package/dist/core/command-generation/adapters/qwen.d.ts +7 -3
  69. package/dist/core/command-generation/adapters/qwen.js +12 -7
  70. package/dist/core/command-generation/adapters/roocode.d.ts +4 -4
  71. package/dist/core/command-generation/adapters/roocode.js +4 -4
  72. package/dist/core/command-generation/adapters/trae.js +1 -21
  73. package/dist/core/command-generation/adapters/zcode.d.ts +16 -0
  74. package/dist/core/command-generation/adapters/zcode.js +33 -0
  75. package/dist/core/command-generation/generator.d.ts +8 -0
  76. package/dist/core/command-generation/generator.js +15 -1
  77. package/dist/core/command-generation/index.d.ts +1 -1
  78. package/dist/core/command-generation/index.js +1 -1
  79. package/dist/core/command-generation/invocation.d.ts +73 -0
  80. package/dist/core/command-generation/invocation.js +77 -0
  81. package/dist/core/command-generation/registry.js +4 -4
  82. package/dist/core/command-generation/types.d.ts +9 -2
  83. package/dist/core/command-generation/yaml.d.ts +20 -6
  84. package/dist/core/command-generation/yaml.js +31 -21
  85. package/dist/core/command-surface.d.ts +15 -0
  86. package/dist/core/command-surface.js +33 -0
  87. package/dist/core/completions/command-registry.js +16 -2
  88. package/dist/core/completions/generators/powershell-generator.js +15 -8
  89. package/dist/core/completions/installers/zsh-installer.d.ts +9 -0
  90. package/dist/core/completions/installers/zsh-installer.js +20 -4
  91. package/dist/core/config-prompts.d.ts +1 -1
  92. package/dist/core/config-prompts.js +14 -1
  93. package/dist/core/config-schema.d.ts +10 -1
  94. package/dist/core/config-schema.js +67 -1
  95. package/dist/core/config.d.ts +15 -0
  96. package/dist/core/config.js +45 -5
  97. package/dist/core/file-state.js +56 -24
  98. package/dist/core/github-copilot/cloud-agent.d.ts +95 -0
  99. package/dist/core/github-copilot/cloud-agent.js +497 -0
  100. package/dist/core/global-config.d.ts +16 -0
  101. package/dist/core/init.d.ts +58 -0
  102. package/dist/core/init.js +450 -69
  103. package/dist/core/legacy-cleanup.d.ts +59 -0
  104. package/dist/core/legacy-cleanup.js +253 -24
  105. package/dist/core/list.js +5 -7
  106. package/dist/core/migration.d.ts +73 -1
  107. package/dist/core/migration.js +360 -11
  108. package/dist/core/onboarding-commands.d.ts +30 -0
  109. package/dist/core/onboarding-commands.js +38 -0
  110. package/dist/core/parsers/change-parser.d.ts +17 -2
  111. package/dist/core/parsers/change-parser.js +33 -20
  112. package/dist/core/parsers/code-fence.d.ts +15 -0
  113. package/dist/core/parsers/code-fence.js +49 -0
  114. package/dist/core/parsers/markdown-parser.js +2 -1
  115. package/dist/core/parsers/requirement-blocks.d.ts +18 -0
  116. package/dist/core/parsers/requirement-blocks.js +120 -35
  117. package/dist/core/parsers/requirement-text.d.ts +1 -8
  118. package/dist/core/parsers/requirement-text.js +4 -42
  119. package/dist/core/parsers/spec-structure.d.ts +1 -1
  120. package/dist/core/parsers/spec-structure.js +20 -30
  121. package/dist/core/profile-sync-drift.d.ts +0 -8
  122. package/dist/core/profile-sync-drift.js +48 -49
  123. package/dist/core/project-config.d.ts +28 -6
  124. package/dist/core/project-config.js +108 -8
  125. package/dist/core/references.js +42 -4
  126. package/dist/core/relationship-health.d.ts +8 -0
  127. package/dist/core/relationship-health.js +13 -0
  128. package/dist/core/root-selection.d.ts +9 -6
  129. package/dist/core/root-selection.js +42 -5
  130. package/dist/core/shared/index.d.ts +1 -0
  131. package/dist/core/shared/index.js +1 -0
  132. package/dist/core/shared/skill-content-equivalence.d.ts +7 -0
  133. package/dist/core/shared/skill-content-equivalence.js +41 -0
  134. package/dist/core/shared/skill-paths.d.ts +13 -0
  135. package/dist/core/shared/skill-paths.js +23 -0
  136. package/dist/core/shared/tool-detection.d.ts +25 -5
  137. package/dist/core/shared/tool-detection.js +166 -36
  138. package/dist/core/shared-skill-target.d.ts +16 -0
  139. package/dist/core/shared-skill-target.js +156 -0
  140. package/dist/core/specs-apply.d.ts +80 -33
  141. package/dist/core/specs-apply.js +659 -171
  142. package/dist/core/store/git.d.ts +13 -0
  143. package/dist/core/store/git.js +24 -0
  144. package/dist/core/templates/skill-templates.d.ts +1 -1
  145. package/dist/core/templates/skill-templates.js +1 -1
  146. package/dist/core/templates/workflows/apply-change.d.ts +10 -0
  147. package/dist/core/templates/workflows/apply-change.js +48 -158
  148. package/dist/core/templates/workflows/archive-change.js +170 -42
  149. package/dist/core/templates/workflows/bulk-archive-change.js +256 -75
  150. package/dist/core/templates/workflows/continue-change.js +38 -46
  151. package/dist/core/templates/workflows/explore.js +54 -18
  152. package/dist/core/templates/workflows/ff-change.js +46 -30
  153. package/dist/core/templates/workflows/new-change.js +2 -2
  154. package/dist/core/templates/workflows/onboard.js +13 -7
  155. package/dist/core/templates/workflows/propose.js +116 -46
  156. package/dist/core/templates/workflows/store-selection.d.ts +1 -1
  157. package/dist/core/templates/workflows/store-selection.js +1 -1
  158. package/dist/core/templates/workflows/sync-specs.js +260 -32
  159. package/dist/core/templates/workflows/update-change.js +26 -16
  160. package/dist/core/templates/workflows/verify-change.js +16 -10
  161. package/dist/core/update.d.ts +40 -5
  162. package/dist/core/update.js +389 -93
  163. package/dist/core/validation/constants.d.ts +4 -1
  164. package/dist/core/validation/constants.js +4 -1
  165. package/dist/core/validation/validator.d.ts +22 -8
  166. package/dist/core/validation/validator.js +222 -50
  167. package/dist/core/version-check.d.ts +152 -0
  168. package/dist/core/version-check.js +731 -0
  169. package/dist/core/view.js +12 -17
  170. package/dist/prompts/searchable-multi-select.js +1 -1
  171. package/dist/telemetry/config.d.ts +3 -4
  172. package/dist/telemetry/index.d.ts +10 -5
  173. package/dist/telemetry/index.js +75 -41
  174. package/dist/ui/welcome-screen.d.ts +9 -1
  175. package/dist/ui/welcome-screen.js +91 -38
  176. package/dist/utils/change-metadata.d.ts +43 -0
  177. package/dist/utils/change-metadata.js +123 -7
  178. package/dist/utils/change-utils.d.ts +10 -4
  179. package/dist/utils/change-utils.js +20 -13
  180. package/dist/utils/ci.d.ts +12 -0
  181. package/dist/utils/ci.js +16 -0
  182. package/dist/utils/command-references.d.ts +92 -6
  183. package/dist/utils/command-references.js +180 -7
  184. package/dist/utils/date.d.ts +8 -0
  185. package/dist/utils/date.js +13 -0
  186. package/dist/utils/file-system.d.ts +10 -0
  187. package/dist/utils/file-system.js +70 -0
  188. package/dist/utils/index.d.ts +1 -1
  189. package/dist/utils/index.js +1 -1
  190. package/dist/utils/interactive.d.ts +23 -0
  191. package/dist/utils/interactive.js +32 -0
  192. package/dist/utils/item-discovery.d.ts +19 -0
  193. package/dist/utils/item-discovery.js +30 -48
  194. package/dist/utils/shell-detection.d.ts +1 -1
  195. package/dist/utils/shell-detection.js +64 -11
  196. package/dist/utils/spec-discovery.d.ts +40 -0
  197. package/dist/utils/spec-discovery.js +115 -0
  198. package/dist/utils/task-progress.d.ts +17 -0
  199. package/dist/utils/task-progress.js +41 -13
  200. package/package.json +14 -12
  201. package/schemas/spec-driven/schema.yaml +67 -10
  202. package/schemas/spec-driven/templates/design.md +2 -2
  203. package/schemas/spec-driven/templates/proposal.md +10 -4
  204. package/schemas/spec-driven/templates/spec.md +3 -0
  205. package/dist/core/command-generation/adapters/codex.d.ts +0 -16
  206. package/dist/core/command-generation/adapters/codex.js +0 -39
  207. package/dist/core/command-generation/adapters/windsurf.d.ts +0 -14
  208. package/dist/core/command-generation/adapters/windsurf.js +0 -38
@@ -7,18 +7,50 @@ export function getArchiveChangeSkillTemplate() {
7
7
 
8
8
  ${STORE_SELECTION_GUIDANCE}
9
9
 
10
+ \`<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.
11
+
10
12
  **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
13
 
12
14
  **Steps**
13
15
 
14
- 1. **If no change name provided, prompt for selection**
16
+ 1. **Select the change**
15
17
 
16
- Run \`openspec list --json\` to get available changes. Use the **AskUserQuestion tool** to let the user select.
18
+ If a name is provided, use it. Otherwise:
19
+ - Infer from conversation context if the user mentioned a change
20
+ - Auto-select if only one active change exists
21
+ - If ambiguous, run \`openspec list --json\` to get available changes and ask the user to select one
17
22
 
18
- Show only active changes (not already archived).
23
+ When prompting, show only active changes (not already archived).
19
24
  Include the schema used for each change if available.
20
25
 
21
- **IMPORTANT**: Do NOT guess or auto-select a change. Always let the user choose.
26
+ Always announce: "Using change: <name>" and how to override (e.g., \`/opsx:archive <other>\`).
27
+
28
+ **Load current archive inputs before the existing archive checks:**
29
+
30
+ After resolving the selected change and planning root, run:
31
+ \`\`\`bash
32
+ openspec instructions archive --change "<name>" --json
33
+ \`\`\`
34
+ Keep the same selected-root flags on this command. This lookup is advisory and
35
+ optional: it only supplies extra prompt inputs, so it must never block archiving.
36
+ If it exits non-zero or returns invalid JSON — for example on an older CLI that
37
+ does not support this command yet — continue the archive workflow with no
38
+ context and no operation guidance. Do not report an error and do not stop.
39
+
40
+ A successful response may omit both optional fields. Treat \`context\` as a
41
+ required prompt-level input: read and consider it, and apply relevant project
42
+ facts, conventions, and constraints. Treat \`operationGuidance\` as optional
43
+ additive advice: read and consider every entry, and follow entries that are
44
+ applicable and compatible with the built-in archive workflow.
45
+
46
+ Keep both fields separate from built-in steps, explicit user choices, resolved
47
+ paths, CLI checks, and command contracts. If context conflicts with one of those
48
+ controlling inputs, report the conflict and preserve the controlling value. If
49
+ guidance is inapplicable or conflicts with a controlling input, do not follow it
50
+ and explain why. Do not infer replacement paths, skipped prompts, or flags from
51
+ either field, and do not copy their text verbatim into specs, change artifacts,
52
+ or archive summaries unless the user separately asks for it. These are
53
+ prompt-level behavior contracts, not enforceable checks.
22
54
 
23
55
  2. **Check artifact completion status**
24
56
 
@@ -27,11 +59,11 @@ ${STORE_SELECTION_GUIDANCE}
27
59
  Parse the JSON to understand:
28
60
  - \`schemaName\`: The workflow being used
29
61
  - \`planningHome\`, \`changeRoot\`, \`artifactPaths\`, and \`actionContext\`: path and scope context
30
- - \`artifacts\`: List of artifacts with their status (\`done\` or other)
62
+ - \`artifacts\`: List of artifacts with their status (\`done\`, \`skipped\`, or other)
31
63
 
32
- **If any artifacts are not \`done\`:**
64
+ **If any artifacts are neither \`done\` nor \`skipped\`** (skipped artifacts satisfy the requirement - the change declares skip_specs):
33
65
  - Display warning listing incomplete artifacts
34
- - Use **AskUserQuestion tool** to confirm user wants to proceed
66
+ - Ask the user to confirm they want to proceed
35
67
  - Proceed if user confirms
36
68
 
37
69
  3. **Check task completion status**
@@ -42,17 +74,20 @@ ${STORE_SELECTION_GUIDANCE}
42
74
 
43
75
  **If incomplete tasks found:**
44
76
  - Display warning showing count of incomplete tasks
45
- - Use **AskUserQuestion tool** to confirm user wants to proceed
77
+ - Ask the user to confirm they want to proceed
46
78
  - Proceed if user confirms
47
79
 
48
80
  **If no tasks file exists:** Proceed without task-related warning.
49
81
 
50
82
  4. **Assess delta spec sync state**
51
83
 
52
- Use \`artifactPaths.specs.existingOutputPaths\` from status JSON to check for delta specs. If none exist, proceed without sync prompt.
84
+ Use \`artifactPaths.specs.existingOutputPaths\` from status JSON as the only
85
+ delta-spec source. If the \`specs\` entry is missing or
86
+ \`existingOutputPaths\` is empty, proceed without a sync prompt and do not infer
87
+ delta specs from other artifacts.
53
88
 
54
89
  **If delta specs exist:**
55
- - Compare each delta spec with its corresponding main spec at \`openspec/specs/<capability>/spec.md\`
90
+ - Compare each delta spec with its corresponding main spec at \`<planningHome.root>/openspec/specs/<capability-path>/spec.md\` (use the store-aware \`planningHome.root\` from step 2, not a hardcoded repo path)
56
91
  - Determine what changes would be applied (adds, modifications, removals, renames)
57
92
  - Show a combined summary before prompting
58
93
 
@@ -60,7 +95,30 @@ ${STORE_SELECTION_GUIDANCE}
60
95
  - If changes needed: "Sync now (recommended)", "Archive without syncing"
61
96
  - If already synced: "Archive now", "Sync anyway", "Cancel"
62
97
 
63
- If user chooses sync, use Task tool (subagent_type: "general-purpose", prompt: "Use Skill tool to invoke openspec-sync-specs for change '<name>'. Delta spec analysis: <include the analyzed delta spec summary>"). Proceed to archive regardless of choice.
98
+ Route on the answer:
99
+ - "Cancel" — stop, do not archive
100
+ - "Archive without syncing" or "Archive now" — proceed to archive
101
+ - "Sync now" or "Sync anyway" — sync, then verify (below)
102
+ - Anything else — ask again rather than archiving
103
+
104
+ Before a selected sync writes any main spec, run
105
+ \`openspec instructions specs --change "<name>" --json\` once with the same
106
+ selected-root flags. Require a zero exit status and valid artifact-instruction
107
+ JSON. If the lookup fails or returns invalid JSON, report the error and stop
108
+ before writing any main spec or moving the change. A valid response with omitted
109
+ \`rules\` is the no-rules case. Apply returned \`rules\` only to the content and
110
+ form of main specs produced by this merge; do not use them as archive guidance,
111
+ change CLI behavior, or copy the rule text into any output file.
112
+
113
+ Then run the \`openspec-sync-specs\` workflow inline (agent-driven intelligent merge) for change '<name>', passing the delta spec analysis and the fetched specs-rule snapshot from above, and wait for it to finish. The inline sync must reuse that snapshot without fetching \`specs\` instructions again. Do not delegate it to a background task — step 5 would move \`changeRoot\` out from under a sync that is still reading it, leaving the change archived and the main specs never updated. If your agent can only run it by delegation, delegate synchronously and wait for the result.
114
+
115
+ Then re-run the comparison from the top of this step against every capability that has a delta spec in \`artifactPaths.specs.existingOutputPaths\` — not only the ones the sync reports it touched. A successful sync leaves nothing left to apply, so each capability must now read as already synced:
116
+ - ADDED requirements present
117
+ - MODIFIED requirements carrying the scenario and description changes named in the delta, with their other scenarios intact
118
+ - REMOVED requirements gone — and where this sync retired a capability (removed its last requirement, leaving \`## Requirements\` empty), its main spec deleted rather than left empty; a spec the sync deliberately kept and reported is also a match
119
+ - RENAMED requirements present under the new name and absent under the old one
120
+
121
+ If the sync failed, or any capability does not match, report what differs and stop — do not archive. Nothing has moved and \`changeRoot\` is intact, so the user can fix the mismatch or re-run the sync and start the archive again.
64
122
 
65
123
  5. **Perform the archive**
66
124
 
@@ -69,14 +127,14 @@ ${STORE_SELECTION_GUIDANCE}
69
127
  mkdir -p "<planningHome.changesDir>/archive"
70
128
  \`\`\`
71
129
 
72
- Generate target name using current date: \`YYYY-MM-DD-<change-name>\`
130
+ Generate the target name: use the change name as-is when it already starts with a \`YYYY-MM-DD-\` prefix; otherwise prepend the current date as \`YYYY-MM-DD-<change-name>\`. Never stack a second date (same rule as \`openspec archive\`).
73
131
 
74
132
  **Check if target already exists:**
75
133
  - If yes: Fail with error, suggest renaming existing archive or using different date
76
134
  - If no: Move \`changeRoot\` to the archive directory
77
135
 
78
136
  \`\`\`bash
79
- mv "<changeRoot>" "<planningHome.changesDir>/archive/YYYY-MM-DD-<name>"
137
+ mv "<changeRoot>" "<planningHome.changesDir>/archive/<target-name>"
80
138
  \`\`\`
81
139
 
82
140
  6. **Display summary**
@@ -90,25 +148,31 @@ ${STORE_SELECTION_GUIDANCE}
90
148
 
91
149
  **Output On Success**
92
150
 
93
- \`\`\`
151
+ \`\`\`markdown
94
152
  ## Archive Complete
95
153
 
96
154
  **Change:** <change-name>
97
155
  **Schema:** <schema-name>
98
- **Archived to:** the archive path derived from \`planningHome.changesDir\`/YYYY-MM-DD-<name>/
99
- **Specs:** ✓ Synced to main specs (or "No delta specs" or "Sync skipped")
156
+ **Archived to:** the archive path derived from \`planningHome.changesDir\`/<target-name>/
157
+ **Specs:** <"✓ Synced to main specs" only if the step 4 verification passed; otherwise "No delta specs" or "Sync skipped">
100
158
 
101
- All artifacts complete. All tasks complete.
159
+ <"All artifacts complete. All tasks complete." — or, if archived with warnings, list them instead (e.g. "Archived with 2 incomplete tasks")>
102
160
  \`\`\`
103
161
 
104
162
  **Guardrails**
105
- - Always prompt for change selection if not provided
163
+ - Announce the selected change; prompt for selection when it is ambiguous
106
164
  - Use artifact graph (openspec status --json) for completion checking
107
165
  - Don't block archive on warnings - just inform and confirm
108
166
  - Preserve .openspec.yaml when moving to archive (it moves with the directory)
109
167
  - Show clear summary of what happened
110
- - If sync is requested, use openspec-sync-specs approach (agent-driven)
111
- - If delta specs exist, always run the sync assessment and show the combined summary before prompting`,
168
+ - If sync is requested, run the \`openspec-sync-specs\` workflow inline (agent-driven)
169
+ - Never archive while a spec sync is still in flight — run the sync inline and verify the main specs before moving \`changeRoot\`
170
+ - If delta specs exist, always run the sync assessment and show the combined summary before prompting
171
+ - Apply relevant runtime context and report conflicts; operation guidance remains advisory
172
+ - Consider every guidance entry and explain any inapplicable or conflicting advice
173
+ - Existing CLI checks, resolved paths, prompts, and command contracts are unchanged
174
+ - Artifact rules constrain only the specs being written and are never operation guidance
175
+ - Never copy runtime context, operation guidance, or artifact-rule text verbatim into output files`,
112
176
  license: 'MIT',
113
177
  compatibility: 'Requires openspec CLI.',
114
178
  metadata: { author: 'openspec', version: '1.0' },
@@ -124,18 +188,50 @@ export function getOpsxArchiveCommandTemplate() {
124
188
 
125
189
  ${STORE_SELECTION_GUIDANCE}
126
190
 
191
+ \`<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.
192
+
127
193
  **Input**: Optionally specify a change name after \`/opsx:archive\` (e.g., \`/opsx:archive add-auth\`). If omitted, check if it can be inferred from conversation context. If vague or ambiguous you MUST prompt for available changes.
128
194
 
129
195
  **Steps**
130
196
 
131
- 1. **If no change name provided, prompt for selection**
197
+ 1. **Select the change**
132
198
 
133
- Run \`openspec list --json\` to get available changes. Use the **AskUserQuestion tool** to let the user select.
199
+ If a name is provided, use it. Otherwise:
200
+ - Infer from conversation context if the user mentioned a change
201
+ - Auto-select if only one active change exists
202
+ - If ambiguous, run \`openspec list --json\` to get available changes and ask the user to select one
134
203
 
135
- Show only active changes (not already archived).
204
+ When prompting, show only active changes (not already archived).
136
205
  Include the schema used for each change if available.
137
206
 
138
- **IMPORTANT**: Do NOT guess or auto-select a change. Always let the user choose.
207
+ Always announce: "Using change: <name>" and how to override (e.g., \`/opsx:archive <other>\`).
208
+
209
+ **Load current archive inputs before the existing archive checks:**
210
+
211
+ After resolving the selected change and planning root, run:
212
+ \`\`\`bash
213
+ openspec instructions archive --change "<name>" --json
214
+ \`\`\`
215
+ Keep the same selected-root flags on this command. This lookup is advisory and
216
+ optional: it only supplies extra prompt inputs, so it must never block archiving.
217
+ If it exits non-zero or returns invalid JSON — for example on an older CLI that
218
+ does not support this command yet — continue the archive workflow with no
219
+ context and no operation guidance. Do not report an error and do not stop.
220
+
221
+ A successful response may omit both optional fields. Treat \`context\` as a
222
+ required prompt-level input: read and consider it, and apply relevant project
223
+ facts, conventions, and constraints. Treat \`operationGuidance\` as optional
224
+ additive advice: read and consider every entry, and follow entries that are
225
+ applicable and compatible with the built-in archive workflow.
226
+
227
+ Keep both fields separate from built-in steps, explicit user choices, resolved
228
+ paths, CLI checks, and command contracts. If context conflicts with one of those
229
+ controlling inputs, report the conflict and preserve the controlling value. If
230
+ guidance is inapplicable or conflicts with a controlling input, do not follow it
231
+ and explain why. Do not infer replacement paths, skipped prompts, or flags from
232
+ either field, and do not copy their text verbatim into specs, change artifacts,
233
+ or archive summaries unless the user separately asks for it. These are
234
+ prompt-level behavior contracts, not enforceable checks.
139
235
 
140
236
  2. **Check artifact completion status**
141
237
 
@@ -144,9 +240,9 @@ ${STORE_SELECTION_GUIDANCE}
144
240
  Parse the JSON to understand:
145
241
  - \`schemaName\`: The workflow being used
146
242
  - \`planningHome\`, \`changeRoot\`, \`artifactPaths\`, and \`actionContext\`: path and scope context
147
- - \`artifacts\`: List of artifacts with their status (\`done\` or other)
243
+ - \`artifacts\`: List of artifacts with their status (\`done\`, \`skipped\`, or other)
148
244
 
149
- **If any artifacts are not \`done\`:**
245
+ **If any artifacts are neither \`done\` nor \`skipped\`** (skipped artifacts satisfy the requirement - the change declares skip_specs):
150
246
  - Display warning listing incomplete artifacts
151
247
  - Prompt user for confirmation to continue
152
248
  - Proceed if user confirms
@@ -166,10 +262,13 @@ ${STORE_SELECTION_GUIDANCE}
166
262
 
167
263
  4. **Assess delta spec sync state**
168
264
 
169
- Use \`artifactPaths.specs.existingOutputPaths\` from status JSON to check for delta specs. If none exist, proceed without sync prompt.
265
+ Use \`artifactPaths.specs.existingOutputPaths\` from status JSON as the only
266
+ delta-spec source. If the \`specs\` entry is missing or
267
+ \`existingOutputPaths\` is empty, proceed without a sync prompt and do not infer
268
+ delta specs from other artifacts.
170
269
 
171
270
  **If delta specs exist:**
172
- - Compare each delta spec with its corresponding main spec at \`openspec/specs/<capability>/spec.md\`
271
+ - Compare each delta spec with its corresponding main spec at \`<planningHome.root>/openspec/specs/<capability-path>/spec.md\` (use the store-aware \`planningHome.root\` from step 2, not a hardcoded repo path)
173
272
  - Determine what changes would be applied (adds, modifications, removals, renames)
174
273
  - Show a combined summary before prompting
175
274
 
@@ -177,7 +276,30 @@ ${STORE_SELECTION_GUIDANCE}
177
276
  - If changes needed: "Sync now (recommended)", "Archive without syncing"
178
277
  - If already synced: "Archive now", "Sync anyway", "Cancel"
179
278
 
180
- If user chooses sync, use Task tool (subagent_type: "general-purpose", prompt: "Use Skill tool to invoke openspec-sync-specs for change '<name>'. Delta spec analysis: <include the analyzed delta spec summary>"). Proceed to archive regardless of choice.
279
+ Route on the answer:
280
+ - "Cancel" — stop, do not archive
281
+ - "Archive without syncing" or "Archive now" — proceed to archive
282
+ - "Sync now" or "Sync anyway" — sync, then verify (below)
283
+ - Anything else — ask again rather than archiving
284
+
285
+ Before a selected sync writes any main spec, run
286
+ \`openspec instructions specs --change "<name>" --json\` once with the same
287
+ selected-root flags. Require a zero exit status and valid artifact-instruction
288
+ JSON. If the lookup fails or returns invalid JSON, report the error and stop
289
+ before writing any main spec or moving the change. A valid response with omitted
290
+ \`rules\` is the no-rules case. Apply returned \`rules\` only to the content and
291
+ form of main specs produced by this merge; do not use them as archive guidance,
292
+ change CLI behavior, or copy the rule text into any output file.
293
+
294
+ Then run the \`/opsx:sync\` workflow inline (agent-driven intelligent merge) for change '<name>', passing the delta spec analysis and the fetched specs-rule snapshot from above, and wait for it to finish. The inline sync must reuse that snapshot without fetching \`specs\` instructions again. Do not delegate it to a background task — step 5 would move \`changeRoot\` out from under a sync that is still reading it, leaving the change archived and the main specs never updated. If your agent can only run it by delegation, delegate synchronously and wait for the result.
295
+
296
+ Then re-run the comparison from the top of this step against every capability that has a delta spec in \`artifactPaths.specs.existingOutputPaths\` — not only the ones the sync reports it touched. A successful sync leaves nothing left to apply, so each capability must now read as already synced:
297
+ - ADDED requirements present
298
+ - MODIFIED requirements carrying the scenario and description changes named in the delta, with their other scenarios intact
299
+ - REMOVED requirements gone — and where this sync retired a capability (removed its last requirement, leaving \`## Requirements\` empty), its main spec deleted rather than left empty; a spec the sync deliberately kept and reported is also a match
300
+ - RENAMED requirements present under the new name and absent under the old one
301
+
302
+ If the sync failed, or any capability does not match, report what differs and stop — do not archive. Nothing has moved and \`changeRoot\` is intact, so the user can fix the mismatch or re-run the sync and start the archive again.
181
303
 
182
304
  5. **Perform the archive**
183
305
 
@@ -186,14 +308,14 @@ ${STORE_SELECTION_GUIDANCE}
186
308
  mkdir -p "<planningHome.changesDir>/archive"
187
309
  \`\`\`
188
310
 
189
- Generate target name using current date: \`YYYY-MM-DD-<change-name>\`
311
+ Generate the target name: use the change name as-is when it already starts with a \`YYYY-MM-DD-\` prefix; otherwise prepend the current date as \`YYYY-MM-DD-<change-name>\`. Never stack a second date (same rule as \`openspec archive\`).
190
312
 
191
313
  **Check if target already exists:**
192
314
  - If yes: Fail with error, suggest renaming existing archive or using different date
193
315
  - If no: Move \`changeRoot\` to the archive directory
194
316
 
195
317
  \`\`\`bash
196
- mv "<changeRoot>" "<planningHome.changesDir>/archive/YYYY-MM-DD-<name>"
318
+ mv "<changeRoot>" "<planningHome.changesDir>/archive/<target-name>"
197
319
  \`\`\`
198
320
 
199
321
  6. **Display summary**
@@ -207,12 +329,12 @@ ${STORE_SELECTION_GUIDANCE}
207
329
 
208
330
  **Output On Success**
209
331
 
210
- \`\`\`
332
+ \`\`\`markdown
211
333
  ## Archive Complete
212
334
 
213
335
  **Change:** <change-name>
214
336
  **Schema:** <schema-name>
215
- **Archived to:** the archive path derived from \`planningHome.changesDir\`/YYYY-MM-DD-<name>/
337
+ **Archived to:** the archive path derived from \`planningHome.changesDir\`/<target-name>/
216
338
  **Specs:** ✓ Synced to main specs
217
339
 
218
340
  All artifacts complete. All tasks complete.
@@ -220,12 +342,12 @@ All artifacts complete. All tasks complete.
220
342
 
221
343
  **Output On Success (No Delta Specs)**
222
344
 
223
- \`\`\`
345
+ \`\`\`markdown
224
346
  ## Archive Complete
225
347
 
226
348
  **Change:** <change-name>
227
349
  **Schema:** <schema-name>
228
- **Archived to:** the archive path derived from \`planningHome.changesDir\`/YYYY-MM-DD-<name>/
350
+ **Archived to:** the archive path derived from \`planningHome.changesDir\`/<target-name>/
229
351
  **Specs:** No delta specs
230
352
 
231
353
  All artifacts complete. All tasks complete.
@@ -233,12 +355,12 @@ All artifacts complete. All tasks complete.
233
355
 
234
356
  **Output On Success With Warnings**
235
357
 
236
- \`\`\`
358
+ \`\`\`markdown
237
359
  ## Archive Complete (with warnings)
238
360
 
239
361
  **Change:** <change-name>
240
362
  **Schema:** <schema-name>
241
- **Archived to:** the archive path derived from \`planningHome.changesDir\`/YYYY-MM-DD-<name>/
363
+ **Archived to:** the archive path derived from \`planningHome.changesDir\`/<target-name>/
242
364
  **Specs:** Sync skipped (user chose to skip)
243
365
 
244
366
  **Warnings:**
@@ -251,11 +373,11 @@ Review the archive if this was not intentional.
251
373
 
252
374
  **Output On Error (Archive Exists)**
253
375
 
254
- \`\`\`
376
+ \`\`\`markdown
255
377
  ## Archive Failed
256
378
 
257
379
  **Change:** <change-name>
258
- **Target:** the archive path derived from \`planningHome.changesDir\`/YYYY-MM-DD-<name>/
380
+ **Target:** the archive path derived from \`planningHome.changesDir\`/<target-name>/
259
381
 
260
382
  Target archive directory already exists.
261
383
 
@@ -266,13 +388,19 @@ Target archive directory already exists.
266
388
  \`\`\`
267
389
 
268
390
  **Guardrails**
269
- - Always prompt for change selection if not provided
391
+ - Announce the selected change; prompt for selection when it is ambiguous
270
392
  - Use artifact graph (openspec status --json) for completion checking
271
393
  - Don't block archive on warnings - just inform and confirm
272
394
  - Preserve .openspec.yaml when moving to archive (it moves with the directory)
273
395
  - Show clear summary of what happened
274
- - If sync is requested, use the Skill tool to invoke \`openspec-sync-specs\` (agent-driven)
275
- - If delta specs exist, always run the sync assessment and show the combined summary before prompting`
396
+ - If sync is requested, run the \`/opsx:sync\` workflow inline (agent-driven)
397
+ - Never archive while a spec sync is still in flight — run the sync inline and verify the main specs before moving \`changeRoot\`
398
+ - If delta specs exist, always run the sync assessment and show the combined summary before prompting
399
+ - Apply relevant runtime context and report conflicts; operation guidance remains advisory
400
+ - Consider every guidance entry and explain any inapplicable or conflicting advice
401
+ - Existing CLI checks, resolved paths, prompts, and command contracts are unchanged
402
+ - Artifact rules constrain only the specs being written and are never operation guidance
403
+ - Never copy runtime context, operation guidance, or artifact-rule text verbatim into output files`
276
404
  };
277
405
  }
278
406
  //# sourceMappingURL=archive-change.js.map