aboutsummaryrefslogtreecommitdiffstats
path: root/.claude/commands/opsx/archive.md
diff options
context:
space:
mode:
Diffstat (limited to '.claude/commands/opsx/archive.md')
-rw-r--r--.claude/commands/opsx/archive.md225
1 files changed, 225 insertions, 0 deletions
diff --git a/.claude/commands/opsx/archive.md b/.claude/commands/opsx/archive.md
new file mode 100644
index 0000000..d93baca
--- /dev/null
+++ b/.claude/commands/opsx/archive.md
@@ -0,0 +1,225 @@
1---
2name: "OPSX: Archive"
3description: "Archive a completed change in the experimental workflow"
4allowed-tools: Bash(openspec:*)
5category: "Workflow"
6tags: ["workflow", "archive", "experimental"]
7---
8
9Archive a completed change in the experimental workflow.
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`<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: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.
16
17**Steps**
18
191. **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 only active changes (not already archived).
27 Include the schema used for each change if available.
28
29 Always announce: "Using change: <name>" and how to override (e.g., `/opsx:archive <other>`).
30
31 **Load current archive inputs before the existing archive checks:**
32
33 After resolving the selected change and planning root, run:
34 ```bash
35 openspec instructions archive --change "<name>" --json
36 ```
37 Keep the same selected-root flags on this command. This lookup is advisory and
38 optional: it only supplies extra prompt inputs, so it must never block archiving.
39 If it exits non-zero or returns invalid JSON — for example on an older CLI that
40 does not support this command yet — continue the archive workflow with no
41 context and no operation guidance. Do not report an error and do not stop.
42
43 A successful response may omit both optional fields. Treat `context` as a
44 required prompt-level input: read and consider it, and apply relevant project
45 facts, conventions, and constraints. Treat `operationGuidance` as optional
46 additive advice: read and consider every entry, and follow entries that are
47 applicable and compatible with the built-in archive workflow.
48
49 Keep both fields separate from built-in steps, explicit user choices, resolved
50 paths, CLI checks, and command contracts. If context conflicts with one of those
51 controlling inputs, report the conflict and preserve the controlling value. If
52 guidance is inapplicable or conflicts with a controlling input, do not follow it
53 and explain why. Do not infer replacement paths, skipped prompts, or flags from
54 either field, and do not copy their text verbatim into specs, change artifacts,
55 or archive summaries unless the user separately asks for it. These are
56 prompt-level behavior contracts, not enforceable checks.
57
582. **Check artifact completion status**
59
60 Run `openspec status --change "<name>" --json` to check artifact completion.
61
62 Parse the JSON to understand:
63 - `schemaName`: The workflow being used
64 - `planningHome`, `changeRoot`, `artifactPaths`, and `actionContext`: path and scope context
65 - `artifacts`: List of artifacts with their status (`done`, `skipped`, or other)
66
67 **If any artifacts are neither `done` nor `skipped`** (skipped artifacts satisfy the requirement - the change declares skip_specs):
68 - Display warning listing incomplete artifacts
69 - Prompt user for confirmation to continue
70 - Proceed if user confirms
71
723. **Check task completion status**
73
74 Read the tasks file (typically `tasks.md`) to check for incomplete tasks.
75
76 Count tasks marked with `- [ ]` (incomplete) vs `- [x]` (complete).
77
78 **If incomplete tasks found:**
79 - Display warning showing count of incomplete tasks
80 - Prompt user for confirmation to continue
81 - Proceed if user confirms
82
83 **If no tasks file exists:** Proceed without task-related warning.
84
854. **Assess delta spec sync state**
86
87 Use `artifactPaths.specs.existingOutputPaths` from status JSON as the only
88 delta-spec source. If the `specs` entry is missing or
89 `existingOutputPaths` is empty, proceed without a sync prompt and do not infer
90 delta specs from other artifacts.
91
92 **If delta specs exist:**
93 - 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)
94 - Determine what changes would be applied (adds, modifications, removals, renames)
95 - Show a combined summary before prompting
96
97 **Prompt options:**
98 - If changes needed: "Sync now (recommended)", "Archive without syncing"
99 - If already synced: "Archive now", "Sync anyway", "Cancel"
100
101 Route on the answer:
102 - "Cancel" — stop, do not archive
103 - "Archive without syncing" or "Archive now" — proceed to archive
104 - "Sync now" or "Sync anyway" — sync, then verify (below)
105 - Anything else — ask again rather than archiving
106
107 Before a selected sync writes any main spec, run
108 `openspec instructions specs --change "<name>" --json` once with the same
109 selected-root flags. Require a zero exit status and valid artifact-instruction
110 JSON. If the lookup fails or returns invalid JSON, report the error and stop
111 before writing any main spec or moving the change. A valid response with omitted
112 `rules` is the no-rules case. Apply returned `rules` only to the content and
113 form of main specs produced by this merge; do not use them as archive guidance,
114 change CLI behavior, or copy the rule text into any output file.
115
116 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.
117
118 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:
119 - ADDED requirements present
120 - MODIFIED requirements carrying the scenario and description changes named in the delta, with their other scenarios intact
121 - 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
122 - RENAMED requirements present under the new name and absent under the old one
123
124 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.
125
1265. **Perform the archive**
127
128 Create an `archive` directory under `planningHome.changesDir` if it doesn't exist:
129 ```bash
130 mkdir -p "<planningHome.changesDir>/archive"
131 ```
132
133 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`).
134
135 **Check if target already exists:**
136 - If yes: Fail with error, suggest renaming existing archive or using different date
137 - If no: Move `changeRoot` to the archive directory
138
139 ```bash
140 mv "<changeRoot>" "<planningHome.changesDir>/archive/<target-name>"
141 ```
142
1436. **Display summary**
144
145 Show archive completion summary including:
146 - Change name
147 - Schema that was used
148 - Archive location
149 - Spec sync status (synced / sync skipped / no delta specs)
150 - Note about any warnings (incomplete artifacts/tasks)
151
152**Output On Success**
153
154```markdown
155## Archive Complete
156
157**Change:** <change-name>
158**Schema:** <schema-name>
159**Archived to:** the archive path derived from `planningHome.changesDir`/<target-name>/
160**Specs:** ✓ Synced to main specs
161
162All artifacts complete. All tasks complete.
163```
164
165**Output On Success (No Delta Specs)**
166
167```markdown
168## Archive Complete
169
170**Change:** <change-name>
171**Schema:** <schema-name>
172**Archived to:** the archive path derived from `planningHome.changesDir`/<target-name>/
173**Specs:** No delta specs
174
175All artifacts complete. All tasks complete.
176```
177
178**Output On Success With Warnings**
179
180```markdown
181## Archive Complete (with warnings)
182
183**Change:** <change-name>
184**Schema:** <schema-name>
185**Archived to:** the archive path derived from `planningHome.changesDir`/<target-name>/
186**Specs:** Sync skipped (user chose to skip)
187
188**Warnings:**
189- Archived with 2 incomplete artifacts
190- Archived with 3 incomplete tasks
191- Delta spec sync was skipped (user chose to skip)
192
193Review the archive if this was not intentional.
194```
195
196**Output On Error (Archive Exists)**
197
198```markdown
199## Archive Failed
200
201**Change:** <change-name>
202**Target:** the archive path derived from `planningHome.changesDir`/<target-name>/
203
204Target archive directory already exists.
205
206**Options:**
2071. Rename the existing archive
2082. Delete the existing archive if it's a duplicate
2093. Wait until a different date to archive
210```
211
212**Guardrails**
213- Announce the selected change; prompt for selection when it is ambiguous
214- Use artifact graph (openspec status --json) for completion checking
215- Don't block archive on warnings - just inform and confirm
216- Preserve .openspec.yaml when moving to archive (it moves with the directory)
217- Show clear summary of what happened
218- If sync is requested, run the `/opsx:sync` workflow inline (agent-driven)
219- Never archive while a spec sync is still in flight — run the sync inline and verify the main specs before moving `changeRoot`
220- If delta specs exist, always run the sync assessment and show the combined summary before prompting
221- Apply relevant runtime context and report conflicts; operation guidance remains advisory
222- Consider every guidance entry and explain any inapplicable or conflicting advice
223- Existing CLI checks, resolved paths, prompts, and command contracts are unchanged
224- Artifact rules constrain only the specs being written and are never operation guidance
225- Never copy runtime context, operation guidance, or artifact-rule text verbatim into output files