@fission-ai/openspec 0.17.2 → 0.19.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 (89) hide show
  1. package/README.md +52 -0
  2. package/dist/cli/index.js +39 -3
  3. package/dist/commands/artifact-workflow.d.ts +17 -0
  4. package/dist/commands/artifact-workflow.js +823 -0
  5. package/dist/commands/completion.js +42 -6
  6. package/dist/core/archive.d.ts +0 -5
  7. package/dist/core/archive.js +4 -257
  8. package/dist/core/artifact-graph/graph.d.ts +56 -0
  9. package/dist/core/artifact-graph/graph.js +141 -0
  10. package/dist/core/artifact-graph/index.d.ts +7 -0
  11. package/dist/core/artifact-graph/index.js +13 -0
  12. package/dist/core/artifact-graph/instruction-loader.d.ts +130 -0
  13. package/dist/core/artifact-graph/instruction-loader.js +173 -0
  14. package/dist/core/artifact-graph/resolver.d.ts +61 -0
  15. package/dist/core/artifact-graph/resolver.js +187 -0
  16. package/dist/core/artifact-graph/schema.d.ts +13 -0
  17. package/dist/core/artifact-graph/schema.js +108 -0
  18. package/dist/core/artifact-graph/state.d.ts +12 -0
  19. package/dist/core/artifact-graph/state.js +54 -0
  20. package/dist/core/artifact-graph/types.d.ts +45 -0
  21. package/dist/core/artifact-graph/types.js +43 -0
  22. package/dist/core/completions/command-registry.js +7 -1
  23. package/dist/core/completions/factory.d.ts +15 -2
  24. package/dist/core/completions/factory.js +19 -1
  25. package/dist/core/completions/generators/bash-generator.d.ts +32 -0
  26. package/dist/core/completions/generators/bash-generator.js +174 -0
  27. package/dist/core/completions/generators/fish-generator.d.ts +32 -0
  28. package/dist/core/completions/generators/fish-generator.js +157 -0
  29. package/dist/core/completions/generators/powershell-generator.d.ts +32 -0
  30. package/dist/core/completions/generators/powershell-generator.js +198 -0
  31. package/dist/core/completions/generators/zsh-generator.d.ts +0 -14
  32. package/dist/core/completions/generators/zsh-generator.js +55 -124
  33. package/dist/core/completions/installers/bash-installer.d.ts +87 -0
  34. package/dist/core/completions/installers/bash-installer.js +318 -0
  35. package/dist/core/completions/installers/fish-installer.d.ts +43 -0
  36. package/dist/core/completions/installers/fish-installer.js +143 -0
  37. package/dist/core/completions/installers/powershell-installer.d.ts +88 -0
  38. package/dist/core/completions/installers/powershell-installer.js +327 -0
  39. package/dist/core/completions/installers/zsh-installer.d.ts +1 -12
  40. package/dist/core/completions/templates/bash-templates.d.ts +6 -0
  41. package/dist/core/completions/templates/bash-templates.js +24 -0
  42. package/dist/core/completions/templates/fish-templates.d.ts +7 -0
  43. package/dist/core/completions/templates/fish-templates.js +39 -0
  44. package/dist/core/completions/templates/powershell-templates.d.ts +6 -0
  45. package/dist/core/completions/templates/powershell-templates.js +25 -0
  46. package/dist/core/completions/templates/zsh-templates.d.ts +6 -0
  47. package/dist/core/completions/templates/zsh-templates.js +36 -0
  48. package/dist/core/config.js +1 -0
  49. package/dist/core/configurators/slash/codebuddy.js +6 -9
  50. package/dist/core/configurators/slash/continue.d.ts +9 -0
  51. package/dist/core/configurators/slash/continue.js +46 -0
  52. package/dist/core/configurators/slash/registry.js +3 -0
  53. package/dist/core/converters/json-converter.js +2 -1
  54. package/dist/core/global-config.d.ts +10 -0
  55. package/dist/core/global-config.js +28 -0
  56. package/dist/core/index.d.ts +1 -1
  57. package/dist/core/index.js +1 -1
  58. package/dist/core/list.d.ts +6 -1
  59. package/dist/core/list.js +88 -6
  60. package/dist/core/specs-apply.d.ts +73 -0
  61. package/dist/core/specs-apply.js +384 -0
  62. package/dist/core/templates/skill-templates.d.ts +86 -0
  63. package/dist/core/templates/skill-templates.js +1934 -0
  64. package/dist/core/update.js +1 -1
  65. package/dist/core/validation/validator.js +2 -1
  66. package/dist/core/view.js +28 -8
  67. package/dist/telemetry/config.d.ts +32 -0
  68. package/dist/telemetry/config.js +68 -0
  69. package/dist/telemetry/index.d.ts +31 -0
  70. package/dist/telemetry/index.js +145 -0
  71. package/dist/utils/change-metadata.d.ts +47 -0
  72. package/dist/utils/change-metadata.js +130 -0
  73. package/dist/utils/change-utils.d.ts +51 -0
  74. package/dist/utils/change-utils.js +100 -0
  75. package/dist/utils/file-system.d.ts +11 -0
  76. package/dist/utils/file-system.js +50 -2
  77. package/dist/utils/index.d.ts +3 -1
  78. package/dist/utils/index.js +4 -1
  79. package/package.json +5 -1
  80. package/schemas/spec-driven/schema.yaml +148 -0
  81. package/schemas/spec-driven/templates/design.md +19 -0
  82. package/schemas/spec-driven/templates/proposal.md +23 -0
  83. package/schemas/spec-driven/templates/spec.md +8 -0
  84. package/schemas/spec-driven/templates/tasks.md +9 -0
  85. package/schemas/tdd/schema.yaml +213 -0
  86. package/schemas/tdd/templates/docs.md +15 -0
  87. package/schemas/tdd/templates/implementation.md +11 -0
  88. package/schemas/tdd/templates/spec.md +11 -0
  89. package/schemas/tdd/templates/test.md +11 -0
@@ -0,0 +1,1934 @@
1
+ /**
2
+ * Agent Skill Templates
3
+ *
4
+ * Templates for generating Agent Skills compatible with:
5
+ * - Claude Code
6
+ * - Cursor (Settings → Rules → Import Settings)
7
+ * - Windsurf
8
+ * - Other Agent Skills-compatible editors
9
+ */
10
+ /**
11
+ * Template for openspec-explore skill
12
+ * Explore mode - adaptive thinking partner for exploring ideas and problems
13
+ */
14
+ export function getExploreSkillTemplate() {
15
+ return {
16
+ name: 'openspec-explore',
17
+ description: 'Enter explore mode - a thinking partner for exploring ideas, investigating problems, and clarifying requirements. Use when the user wants to think through something before or during a change.',
18
+ instructions: `Enter explore mode. Think deeply. Visualize freely. Follow the conversation wherever it goes.
19
+
20
+ **This is a stance, not a workflow.** There are no fixed steps, no required sequence, no mandatory outputs. You're a thinking partner helping the user explore.
21
+
22
+ ---
23
+
24
+ ## The Stance
25
+
26
+ - **Curious, not prescriptive** - Ask questions that emerge naturally, don't follow a script
27
+ - **Visual** - Use ASCII diagrams liberally when they'd help clarify thinking
28
+ - **Adaptive** - Follow interesting threads, pivot when new information emerges
29
+ - **Patient** - Don't rush to conclusions, let the shape of the problem emerge
30
+ - **Grounded** - Explore the actual codebase when relevant, don't just theorize
31
+
32
+ ---
33
+
34
+ ## What You Might Do
35
+
36
+ Depending on what the user brings, you might:
37
+
38
+ **Explore the problem space**
39
+ - Ask clarifying questions that emerge from what they said
40
+ - Challenge assumptions
41
+ - Reframe the problem
42
+ - Find analogies
43
+
44
+ **Investigate the codebase**
45
+ - Map existing architecture relevant to the discussion
46
+ - Find integration points
47
+ - Identify patterns already in use
48
+ - Surface hidden complexity
49
+
50
+ **Compare options**
51
+ - Brainstorm multiple approaches
52
+ - Build comparison tables
53
+ - Sketch tradeoffs
54
+ - Recommend a path (if asked)
55
+
56
+ **Visualize**
57
+ \`\`\`
58
+ ┌─────────────────────────────────────────┐
59
+ │ Use ASCII diagrams liberally │
60
+ ├─────────────────────────────────────────┤
61
+ │ │
62
+ │ ┌────────┐ ┌────────┐ │
63
+ │ │ State │────────▶│ State │ │
64
+ │ │ A │ │ B │ │
65
+ │ └────────┘ └────────┘ │
66
+ │ │
67
+ │ System diagrams, state machines, │
68
+ │ data flows, architecture sketches, │
69
+ │ dependency graphs, comparison tables │
70
+ │ │
71
+ └─────────────────────────────────────────┘
72
+ \`\`\`
73
+
74
+ **Surface risks and unknowns**
75
+ - Identify what could go wrong
76
+ - Find gaps in understanding
77
+ - Suggest spikes or investigations
78
+
79
+ ---
80
+
81
+ ## OpenSpec Awareness
82
+
83
+ You have full context of the OpenSpec system. Use it naturally, don't force it.
84
+
85
+ ### Check for context
86
+
87
+ At the start, quickly check what exists:
88
+ \`\`\`bash
89
+ openspec list --json
90
+ \`\`\`
91
+
92
+ This tells you:
93
+ - If there are active changes
94
+ - Their names, schemas, and status
95
+ - What the user might be working on
96
+
97
+ ### When no change exists
98
+
99
+ Think freely. When insights crystallize, you might offer:
100
+
101
+ - "This feels solid enough to start a change. Want me to create one?"
102
+ → Can transition to \`/opsx:new\` or \`/opsx:ff\`
103
+ - Or keep exploring - no pressure to formalize
104
+
105
+ ### When a change exists
106
+
107
+ If the user mentions a change or you detect one is relevant:
108
+
109
+ 1. **Read existing artifacts for context**
110
+ - \`openspec/changes/<name>/proposal.md\`
111
+ - \`openspec/changes/<name>/design.md\`
112
+ - \`openspec/changes/<name>/tasks.md\`
113
+ - etc.
114
+
115
+ 2. **Reference them naturally in conversation**
116
+ - "Your design mentions using Redis, but we just realized SQLite fits better..."
117
+ - "The proposal scopes this to premium users, but we're now thinking everyone..."
118
+
119
+ 3. **Offer to capture when decisions are made**
120
+
121
+ | Insight Type | Where to Capture |
122
+ |--------------|------------------|
123
+ | New requirement discovered | \`specs/<capability>/spec.md\` |
124
+ | Requirement changed | \`specs/<capability>/spec.md\` |
125
+ | Design decision made | \`design.md\` |
126
+ | Scope changed | \`proposal.md\` |
127
+ | New work identified | \`tasks.md\` |
128
+ | Assumption invalidated | Relevant artifact |
129
+
130
+ Example offers:
131
+ - "That's a design decision. Capture it in design.md?"
132
+ - "This is a new requirement. Add it to specs?"
133
+ - "This changes scope. Update the proposal?"
134
+
135
+ 4. **The user decides** - Offer and move on. Don't pressure. Don't auto-capture.
136
+
137
+ ---
138
+
139
+ ## What You Don't Have To Do
140
+
141
+ - Follow a script
142
+ - Ask the same questions every time
143
+ - Produce a specific artifact
144
+ - Reach a conclusion
145
+ - Stay on topic if a tangent is valuable
146
+ - Be brief (this is thinking time)
147
+
148
+ ---
149
+
150
+ ## Handling Different Entry Points
151
+
152
+ **User brings a vague idea:**
153
+ \`\`\`
154
+ User: I'm thinking about adding real-time collaboration
155
+
156
+ You: Real-time collab is a big space. Let me think about this...
157
+
158
+ COLLABORATION SPECTRUM
159
+ ════════════════════════════════════════════
160
+
161
+ Awareness Coordination Sync
162
+ │ │ │
163
+ ▼ ▼ ▼
164
+ ┌────────┐ ┌────────┐ ┌────────┐
165
+ │Presence│ │Cursors │ │ CRDT │
166
+ │ "3 │ │ Multi │ │Conflict│
167
+ │online" │ │ select │ │ free │
168
+ └────────┘ └────────┘ └────────┘
169
+ │ │ │
170
+ trivial moderate complex
171
+
172
+ Where's your head at?
173
+ \`\`\`
174
+
175
+ **User brings a specific problem:**
176
+ \`\`\`
177
+ User: The auth system is a mess
178
+
179
+ You: [reads codebase]
180
+
181
+ ┌─────────────────────────────────────────────┐
182
+ │ CURRENT AUTH FLOW │
183
+ └─────────────────────────────────────────────┘
184
+
185
+ ┌─────────────┼─────────────┐
186
+ ▼ ▼ ▼
187
+ ┌─────────┐ ┌─────────┐ ┌─────────┐
188
+ │ Google │ │ GitHub │ │ Email │
189
+ │ OAuth │ │ OAuth │ │ Magic │
190
+ └────┬────┘ └────┬────┘ └────┬────┘
191
+ │ │ │
192
+ └─────────────┼─────────────┘
193
+
194
+ ┌───────────┐
195
+ │ Session │
196
+ └─────┬─────┘
197
+
198
+
199
+ ┌───────────┐
200
+ │ Perms │
201
+ └───────────┘
202
+
203
+ I see three tangles. Which one's burning?
204
+ \`\`\`
205
+
206
+ **User is stuck mid-implementation:**
207
+ \`\`\`
208
+ User: /opsx:explore add-auth-system
209
+ The OAuth integration is more complex than expected
210
+
211
+ You: [reads change artifacts]
212
+
213
+ You're on task 4: "Implement OAuth flow"
214
+
215
+ Let me trace what's involved...
216
+
217
+ [draws diagram, explores options, suggests paths]
218
+
219
+ Want to update the design to reflect this?
220
+ Or add a spike task to investigate?
221
+ \`\`\`
222
+
223
+ **User wants to compare options:**
224
+ \`\`\`
225
+ User: Should we use Postgres or SQLite?
226
+
227
+ You: Generic answer is boring. What's the context?
228
+
229
+ User: A CLI tool that tracks local dev environments
230
+
231
+ You: That changes everything.
232
+
233
+ ┌─────────────────────────────────────────────────┐
234
+ │ CLI TOOL DATA STORAGE │
235
+ └─────────────────────────────────────────────────┘
236
+
237
+ Key constraints:
238
+ • No daemon running
239
+ • Must work offline
240
+ • Single user
241
+
242
+ SQLite Postgres
243
+ Deployment embedded ✓ needs server ✗
244
+ Offline yes ✓ no ✗
245
+ Single file yes ✓ no ✗
246
+
247
+ SQLite. Not even close.
248
+
249
+ Unless... is there a sync component?
250
+ \`\`\`
251
+
252
+ ---
253
+
254
+ ## Ending Discovery
255
+
256
+ There's no required ending. Discovery might:
257
+
258
+ - **Flow into action**: "Ready to start? /opsx:new or /opsx:ff"
259
+ - **Result in artifact updates**: "Updated design.md with these decisions"
260
+ - **Just provide clarity**: User has what they need, moves on
261
+ - **Continue later**: "We can pick this up anytime"
262
+
263
+ When it feels like things are crystallizing, you might summarize:
264
+
265
+ \`\`\`
266
+ ## What We Figured Out
267
+
268
+ **The problem**: [crystallized understanding]
269
+
270
+ **The approach**: [if one emerged]
271
+
272
+ **Open questions**: [if any remain]
273
+
274
+ **Next steps** (if ready):
275
+ - Create a change: /opsx:new <name>
276
+ - Fast-forward to tasks: /opsx:ff <name>
277
+ - Keep exploring: just keep talking
278
+ \`\`\`
279
+
280
+ But this summary is optional. Sometimes the thinking IS the value.
281
+
282
+ ---
283
+
284
+ ## Guardrails
285
+
286
+ - **Don't fake understanding** - If something is unclear, dig deeper
287
+ - **Don't rush** - Discovery is thinking time, not task time
288
+ - **Don't force structure** - Let patterns emerge naturally
289
+ - **Don't auto-capture** - Offer to save insights, don't just do it
290
+ - **Do visualize** - A good diagram is worth many paragraphs
291
+ - **Do explore the codebase** - Ground discussions in reality
292
+ - **Do question assumptions** - Including the user's and your own`
293
+ };
294
+ }
295
+ /**
296
+ * Template for openspec-new-change skill
297
+ * Based on /opsx:new command
298
+ */
299
+ export function getNewChangeSkillTemplate() {
300
+ return {
301
+ name: 'openspec-new-change',
302
+ description: 'Start a new OpenSpec change using the experimental artifact workflow. Use when the user wants to create a new feature, fix, or modification with a structured step-by-step approach.',
303
+ instructions: `Start a new change using the experimental artifact-driven approach.
304
+
305
+ **Input**: The user's request should include a change name (kebab-case) OR a description of what they want to build.
306
+
307
+ **Steps**
308
+
309
+ 1. **If no clear input provided, ask what they want to build**
310
+
311
+ Use the **AskUserQuestion tool** (open-ended, no preset options) to ask:
312
+ > "What change do you want to work on? Describe what you want to build or fix."
313
+
314
+ From their description, derive a kebab-case name (e.g., "add user authentication" → \`add-user-auth\`).
315
+
316
+ **IMPORTANT**: Do NOT proceed without understanding what the user wants to build.
317
+
318
+ 2. **Determine the workflow schema**
319
+
320
+ Use the default schema (omit \`--schema\`) unless the user explicitly requests a different workflow.
321
+
322
+ **Use a different schema only if the user mentions:**
323
+ - "tdd" or "test-driven" → use \`--schema tdd\`
324
+ - A specific schema name → use \`--schema <name>\`
325
+ - "show workflows" or "what workflows" → run \`openspec schemas --json\` and let them choose
326
+
327
+ **Otherwise**: Omit \`--schema\` to use the default.
328
+
329
+ 3. **Create the change directory**
330
+ \`\`\`bash
331
+ openspec new change "<name>"
332
+ \`\`\`
333
+ Add \`--schema <name>\` only if the user requested a specific workflow.
334
+ This creates a scaffolded change at \`openspec/changes/<name>/\` with the selected schema.
335
+
336
+ 4. **Show the artifact status**
337
+ \`\`\`bash
338
+ openspec status --change "<name>"
339
+ \`\`\`
340
+ This shows which artifacts need to be created and which are ready (dependencies satisfied).
341
+
342
+ 5. **Get instructions for the first artifact**
343
+ The first artifact depends on the schema (e.g., \`proposal\` for spec-driven, \`spec\` for tdd).
344
+ Check the status output to find the first artifact with status "ready".
345
+ \`\`\`bash
346
+ openspec instructions <first-artifact-id> --change "<name>"
347
+ \`\`\`
348
+ This outputs the template and context for creating the first artifact.
349
+
350
+ 6. **STOP and wait for user direction**
351
+
352
+ **Output**
353
+
354
+ After completing the steps, summarize:
355
+ - Change name and location
356
+ - Schema/workflow being used and its artifact sequence
357
+ - Current status (0/N artifacts complete)
358
+ - The template for the first artifact
359
+ - Prompt: "Ready to create the first artifact? Just describe what this change is about and I'll draft it, or ask me to continue."
360
+
361
+ **Guardrails**
362
+ - Do NOT create any artifacts yet - just show the instructions
363
+ - Do NOT advance beyond showing the first artifact template
364
+ - If the name is invalid (not kebab-case), ask for a valid name
365
+ - If a change with that name already exists, suggest continuing that change instead
366
+ - Pass --schema if using a non-default workflow`
367
+ };
368
+ }
369
+ /**
370
+ * Template for openspec-continue-change skill
371
+ * Based on /opsx:continue command
372
+ */
373
+ export function getContinueChangeSkillTemplate() {
374
+ return {
375
+ name: 'openspec-continue-change',
376
+ description: 'Continue working on an OpenSpec change by creating the next artifact. Use when the user wants to progress their change, create the next artifact, or continue their workflow.',
377
+ instructions: `Continue working on a change by creating the next artifact.
378
+
379
+ **Input**: Optionally specify a change name. If omitted, MUST prompt for available changes.
380
+
381
+ **Steps**
382
+
383
+ 1. **If no change name provided, prompt for selection**
384
+
385
+ Run \`openspec list --json\` to get available changes sorted by most recently modified. Then use the **AskUserQuestion tool** to let the user select which change to work on.
386
+
387
+ Present the top 3-4 most recently modified changes as options, showing:
388
+ - Change name
389
+ - Schema (from \`schema\` field if present, otherwise "spec-driven")
390
+ - Status (e.g., "0/5 tasks", "complete", "no tasks")
391
+ - How recently it was modified (from \`lastModified\` field)
392
+
393
+ Mark the most recently modified change as "(Recommended)" since it's likely what the user wants to continue.
394
+
395
+ **IMPORTANT**: Do NOT guess or auto-select a change. Always let the user choose.
396
+
397
+ 2. **Check current status**
398
+ \`\`\`bash
399
+ openspec status --change "<name>" --json
400
+ \`\`\`
401
+ Parse the JSON to understand current state. The response includes:
402
+ - \`schemaName\`: The workflow schema being used (e.g., "spec-driven", "tdd")
403
+ - \`artifacts\`: Array of artifacts with their status ("done", "ready", "blocked")
404
+ - \`isComplete\`: Boolean indicating if all artifacts are complete
405
+
406
+ 3. **Act based on status**:
407
+
408
+ ---
409
+
410
+ **If all artifacts are complete (\`isComplete: true\`)**:
411
+ - Congratulate the user
412
+ - Show final status including the schema used
413
+ - Suggest: "All artifacts created! You can now implement this change or archive it."
414
+ - STOP
415
+
416
+ ---
417
+
418
+ **If artifacts are ready to create** (status shows artifacts with \`status: "ready"\`):
419
+ - Pick the FIRST artifact with \`status: "ready"\` from the status output
420
+ - Get its instructions:
421
+ \`\`\`bash
422
+ openspec instructions <artifact-id> --change "<name>" --json
423
+ \`\`\`
424
+ - Parse the JSON to get template, dependencies, and what it unlocks
425
+ - **Create the artifact file** using the template as a starting point:
426
+ - Read any completed dependency files for context
427
+ - Fill in the template based on context and user's goals
428
+ - Write to the output path specified in instructions
429
+ - Show what was created and what's now unlocked
430
+ - STOP after creating ONE artifact
431
+
432
+ ---
433
+
434
+ **If no artifacts are ready (all blocked)**:
435
+ - This shouldn't happen with a valid schema
436
+ - Show status and suggest checking for issues
437
+
438
+ 4. **After creating an artifact, show progress**
439
+ \`\`\`bash
440
+ openspec status --change "<name>"
441
+ \`\`\`
442
+
443
+ **Output**
444
+
445
+ After each invocation, show:
446
+ - Which artifact was created
447
+ - Schema workflow being used
448
+ - Current progress (N/M complete)
449
+ - What artifacts are now unlocked
450
+ - Prompt: "Want to continue? Just ask me to continue or tell me what to do next."
451
+
452
+ **Artifact Creation Guidelines**
453
+
454
+ The artifact types and their purpose depend on the schema. Use the \`instruction\` field from the instructions output to understand what to create.
455
+
456
+ Common artifact patterns:
457
+
458
+ **spec-driven schema** (proposal → specs → design → tasks):
459
+ - **proposal.md**: Ask user about the change if not clear. Fill in Why, What Changes, Capabilities, Impact.
460
+ - The Capabilities section is critical - each capability listed will need a spec file.
461
+ - **specs/*.md**: Create one spec per capability listed in the proposal.
462
+ - **design.md**: Document technical decisions, architecture, and implementation approach.
463
+ - **tasks.md**: Break down implementation into checkboxed tasks.
464
+
465
+ **tdd schema** (spec → tests → implementation → docs):
466
+ - **spec.md**: Feature specification defining what to build.
467
+ - **tests/*.test.ts**: Write tests BEFORE implementation (TDD red phase).
468
+ - **src/*.ts**: Implement to make tests pass (TDD green phase).
469
+ - **docs/*.md**: Document the implemented feature.
470
+
471
+ For other schemas, follow the \`instruction\` field from the CLI output.
472
+
473
+ **Guardrails**
474
+ - Create ONE artifact per invocation
475
+ - Always read dependency artifacts before creating a new one
476
+ - Never skip artifacts or create out of order
477
+ - If context is unclear, ask the user before creating
478
+ - Verify the artifact file exists after writing before marking progress
479
+ - Use the schema's artifact sequence, don't assume specific artifact names`
480
+ };
481
+ }
482
+ /**
483
+ * Template for openspec-apply-change skill
484
+ * For implementing tasks from a completed (or in-progress) change
485
+ */
486
+ export function getApplyChangeSkillTemplate() {
487
+ return {
488
+ name: 'openspec-apply-change',
489
+ description: 'Implement tasks from an OpenSpec change. Use when the user wants to start implementing, continue implementation, or work through tasks.',
490
+ instructions: `Implement tasks from an OpenSpec change.
491
+
492
+ **Input**: Optionally specify a change name. If omitted, MUST prompt for available changes.
493
+
494
+ **Steps**
495
+
496
+ 1. **If no change name provided, prompt for selection**
497
+
498
+ Run \`openspec list --json\` to get available changes. Use the **AskUserQuestion tool** to let the user select.
499
+
500
+ Show changes that are implementation-ready (have tasks artifact).
501
+ Include the schema used for each change if available.
502
+ Mark changes with incomplete tasks as "(In Progress)".
503
+
504
+ **IMPORTANT**: Do NOT guess or auto-select a change. Always let the user choose.
505
+
506
+ 2. **Check status to understand the schema**
507
+ \`\`\`bash
508
+ openspec status --change "<name>" --json
509
+ \`\`\`
510
+ Parse the JSON to understand:
511
+ - \`schemaName\`: The workflow being used (e.g., "spec-driven", "tdd")
512
+ - Which artifact contains the tasks (typically "tasks" for spec-driven, check status for others)
513
+
514
+ 3. **Get apply instructions**
515
+
516
+ \`\`\`bash
517
+ openspec instructions apply --change "<name>" --json
518
+ \`\`\`
519
+
520
+ This returns:
521
+ - Context file paths (varies by schema - could be proposal/specs/design/tasks or spec/tests/implementation/docs)
522
+ - Progress (total, complete, remaining)
523
+ - Task list with status
524
+ - Dynamic instruction based on current state
525
+
526
+ **Handle states:**
527
+ - If \`state: "blocked"\` (missing artifacts): show message, suggest using openspec-continue-change
528
+ - If \`state: "all_done"\`: congratulate, suggest archive
529
+ - Otherwise: proceed to implementation
530
+
531
+ 4. **Read context files**
532
+
533
+ Read the files listed in \`contextFiles\` from the apply instructions output.
534
+ The files depend on the schema being used:
535
+ - **spec-driven**: proposal, specs, design, tasks
536
+ - **tdd**: spec, tests, implementation, docs
537
+ - Other schemas: follow the contextFiles from CLI output
538
+
539
+ 5. **Show current progress**
540
+
541
+ Display:
542
+ - Schema being used
543
+ - Progress: "N/M tasks complete"
544
+ - Remaining tasks overview
545
+ - Dynamic instruction from CLI
546
+
547
+ 6. **Implement tasks (loop until done or blocked)**
548
+
549
+ For each pending task:
550
+ - Show which task is being worked on
551
+ - Make the code changes required
552
+ - Keep changes minimal and focused
553
+ - Mark task complete in the tasks file: \`- [ ]\` → \`- [x]\`
554
+ - Continue to next task
555
+
556
+ **Pause if:**
557
+ - Task is unclear → ask for clarification
558
+ - Implementation reveals a design issue → suggest updating artifacts
559
+ - Error or blocker encountered → report and wait for guidance
560
+ - User interrupts
561
+
562
+ 7. **On completion or pause, show status**
563
+
564
+ Display:
565
+ - Tasks completed this session
566
+ - Overall progress: "N/M tasks complete"
567
+ - If all done: suggest archive
568
+ - If paused: explain why and wait for guidance
569
+
570
+ **Output During Implementation**
571
+
572
+ \`\`\`
573
+ ## Implementing: <change-name> (schema: <schema-name>)
574
+
575
+ Working on task 3/7: <task description>
576
+ [...implementation happening...]
577
+ ✓ Task complete
578
+
579
+ Working on task 4/7: <task description>
580
+ [...implementation happening...]
581
+ ✓ Task complete
582
+ \`\`\`
583
+
584
+ **Output On Completion**
585
+
586
+ \`\`\`
587
+ ## Implementation Complete
588
+
589
+ **Change:** <change-name>
590
+ **Schema:** <schema-name>
591
+ **Progress:** 7/7 tasks complete ✓
592
+
593
+ ### Completed This Session
594
+ - [x] Task 1
595
+ - [x] Task 2
596
+ ...
597
+
598
+ All tasks complete! Ready to archive this change.
599
+ \`\`\`
600
+
601
+ **Output On Pause (Issue Encountered)**
602
+
603
+ \`\`\`
604
+ ## Implementation Paused
605
+
606
+ **Change:** <change-name>
607
+ **Schema:** <schema-name>
608
+ **Progress:** 4/7 tasks complete
609
+
610
+ ### Issue Encountered
611
+ <description of the issue>
612
+
613
+ **Options:**
614
+ 1. <option 1>
615
+ 2. <option 2>
616
+ 3. Other approach
617
+
618
+ What would you like to do?
619
+ \`\`\`
620
+
621
+ **Guardrails**
622
+ - Keep going through tasks until done or blocked
623
+ - Always read context files before starting (from the apply instructions output)
624
+ - If task is ambiguous, pause and ask before implementing
625
+ - If implementation reveals issues, pause and suggest artifact updates
626
+ - Keep code changes minimal and scoped to each task
627
+ - Update task checkbox immediately after completing each task
628
+ - Pause on errors, blockers, or unclear requirements - don't guess
629
+ - Use contextFiles from CLI output, don't assume specific file names
630
+
631
+ **Fluid Workflow Integration**
632
+
633
+ This skill supports the "actions on a change" model:
634
+
635
+ - **Can be invoked anytime**: Before all artifacts are done (if tasks exist), after partial implementation, interleaved with other actions
636
+ - **Allows artifact updates**: If implementation reveals design issues, suggest updating artifacts - not phase-locked, work fluidly`
637
+ };
638
+ }
639
+ /**
640
+ * Template for openspec-ff-change skill
641
+ * Fast-forward through artifact creation
642
+ */
643
+ export function getFfChangeSkillTemplate() {
644
+ return {
645
+ name: 'openspec-ff-change',
646
+ description: 'Fast-forward through OpenSpec artifact creation. Use when the user wants to quickly create all artifacts needed for implementation without stepping through each one individually.',
647
+ instructions: `Fast-forward through artifact creation - generate everything needed to start implementation in one go.
648
+
649
+ **Input**: The user's request should include a change name (kebab-case) OR a description of what they want to build.
650
+
651
+ **Steps**
652
+
653
+ 1. **If no clear input provided, ask what they want to build**
654
+
655
+ Use the **AskUserQuestion tool** (open-ended, no preset options) to ask:
656
+ > "What change do you want to work on? Describe what you want to build or fix."
657
+
658
+ From their description, derive a kebab-case name (e.g., "add user authentication" → \`add-user-auth\`).
659
+
660
+ **IMPORTANT**: Do NOT proceed without understanding what the user wants to build.
661
+
662
+ 2. **Create the change directory**
663
+ \`\`\`bash
664
+ openspec new change "<name>"
665
+ \`\`\`
666
+ This creates a scaffolded change at \`openspec/changes/<name>/\`.
667
+
668
+ 3. **Get the artifact build order**
669
+ \`\`\`bash
670
+ openspec status --change "<name>" --json
671
+ \`\`\`
672
+ Parse the JSON to get:
673
+ - \`applyRequires\`: array of artifact IDs needed before implementation (e.g., \`["tasks"]\`)
674
+ - \`artifacts\`: list of all artifacts with their status and dependencies
675
+
676
+ 4. **Create artifacts in sequence until apply-ready**
677
+
678
+ Use the **TodoWrite tool** to track progress through the artifacts.
679
+
680
+ Loop through artifacts in dependency order (artifacts with no pending dependencies first):
681
+
682
+ a. **For each artifact that is \`ready\` (dependencies satisfied)**:
683
+ - Get instructions:
684
+ \`\`\`bash
685
+ openspec instructions <artifact-id> --change "<name>" --json
686
+ \`\`\`
687
+ - The instructions JSON includes:
688
+ - \`template\`: The template content to use
689
+ - \`instruction\`: Schema-specific guidance for this artifact type
690
+ - \`outputPath\`: Where to write the artifact
691
+ - \`dependencies\`: Completed artifacts to read for context
692
+ - Read any completed dependency files for context
693
+ - Create the artifact file following the schema's \`instruction\`
694
+ - Show brief progress: "✓ Created <artifact-id>"
695
+
696
+ b. **Continue until all \`applyRequires\` artifacts are complete**
697
+ - After creating each artifact, re-run \`openspec status --change "<name>" --json\`
698
+ - Check if every artifact ID in \`applyRequires\` has \`status: "done"\` in the artifacts array
699
+ - Stop when all \`applyRequires\` artifacts are done
700
+
701
+ c. **If an artifact requires user input** (unclear context):
702
+ - Use **AskUserQuestion tool** to clarify
703
+ - Then continue with creation
704
+
705
+ 5. **Show final status**
706
+ \`\`\`bash
707
+ openspec status --change "<name>"
708
+ \`\`\`
709
+
710
+ **Output**
711
+
712
+ After completing all artifacts, summarize:
713
+ - Change name and location
714
+ - List of artifacts created with brief descriptions
715
+ - What's ready: "All artifacts created! Ready for implementation."
716
+ - Prompt: "Run \`/opsx:apply\` or ask me to implement to start working on the tasks."
717
+
718
+ **Artifact Creation Guidelines**
719
+
720
+ - Follow the \`instruction\` field from \`openspec instructions\` for each artifact type
721
+ - The schema defines what each artifact should contain - follow it
722
+ - Read dependency artifacts for context before creating new ones
723
+ - Use the \`template\` as a starting point, filling in based on context
724
+
725
+ **Guardrails**
726
+ - Create ALL artifacts needed for implementation (as defined by schema's \`apply.requires\`)
727
+ - Always read dependency artifacts before creating a new one
728
+ - If context is critically unclear, ask the user - but prefer making reasonable decisions to keep momentum
729
+ - If a change with that name already exists, suggest continuing that change instead
730
+ - Verify each artifact file exists after writing before proceeding to next`
731
+ };
732
+ }
733
+ /**
734
+ * Template for openspec-sync-specs skill
735
+ * For syncing delta specs from a change to main specs (agent-driven)
736
+ */
737
+ export function getSyncSpecsSkillTemplate() {
738
+ return {
739
+ name: 'openspec-sync-specs',
740
+ 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.',
741
+ instructions: `Sync delta specs from a change to main specs.
742
+
743
+ 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).
744
+
745
+ **Input**: Optionally specify a change name. If omitted, MUST prompt for available changes.
746
+
747
+ **Steps**
748
+
749
+ 1. **If no change name provided, prompt for selection**
750
+
751
+ Run \`openspec list --json\` to get available changes. Use the **AskUserQuestion tool** to let the user select.
752
+
753
+ Show changes that have delta specs (under \`specs/\` directory).
754
+
755
+ **IMPORTANT**: Do NOT guess or auto-select a change. Always let the user choose.
756
+
757
+ 2. **Find delta specs**
758
+
759
+ Look for delta spec files in \`openspec/changes/<name>/specs/*/spec.md\`.
760
+
761
+ Each delta spec file contains sections like:
762
+ - \`## ADDED Requirements\` - New requirements to add
763
+ - \`## MODIFIED Requirements\` - Changes to existing requirements
764
+ - \`## REMOVED Requirements\` - Requirements to remove
765
+ - \`## RENAMED Requirements\` - Requirements to rename (FROM:/TO: format)
766
+
767
+ If no delta specs found, inform user and stop.
768
+
769
+ 3. **For each delta spec, apply changes to main specs**
770
+
771
+ For each capability with a delta spec at \`openspec/changes/<name>/specs/<capability>/spec.md\`:
772
+
773
+ a. **Read the delta spec** to understand the intended changes
774
+
775
+ b. **Read the main spec** at \`openspec/specs/<capability>/spec.md\` (may not exist yet)
776
+
777
+ c. **Apply changes intelligently**:
778
+
779
+ **ADDED Requirements:**
780
+ - If requirement doesn't exist in main spec → add it
781
+ - If requirement already exists → update it to match (treat as implicit MODIFIED)
782
+
783
+ **MODIFIED Requirements:**
784
+ - Find the requirement in main spec
785
+ - Apply the changes - this can be:
786
+ - Adding new scenarios (don't need to copy existing ones)
787
+ - Modifying existing scenarios
788
+ - Changing the requirement description
789
+ - Preserve scenarios/content not mentioned in the delta
790
+
791
+ **REMOVED Requirements:**
792
+ - Remove the entire requirement block from main spec
793
+
794
+ **RENAMED Requirements:**
795
+ - Find the FROM requirement, rename to TO
796
+
797
+ d. **Create new main spec** if capability doesn't exist yet:
798
+ - Create \`openspec/specs/<capability>/spec.md\`
799
+ - Add Purpose section (can be brief, mark as TBD)
800
+ - Add Requirements section with the ADDED requirements
801
+
802
+ 4. **Show summary**
803
+
804
+ After applying all changes, summarize:
805
+ - Which capabilities were updated
806
+ - What changes were made (requirements added/modified/removed/renamed)
807
+
808
+ **Delta Spec Format Reference**
809
+
810
+ \`\`\`markdown
811
+ ## ADDED Requirements
812
+
813
+ ### Requirement: New Feature
814
+ The system SHALL do something new.
815
+
816
+ #### Scenario: Basic case
817
+ - **WHEN** user does X
818
+ - **THEN** system does Y
819
+
820
+ ## MODIFIED Requirements
821
+
822
+ ### Requirement: Existing Feature
823
+ #### Scenario: New scenario to add
824
+ - **WHEN** user does A
825
+ - **THEN** system does B
826
+
827
+ ## REMOVED Requirements
828
+
829
+ ### Requirement: Deprecated Feature
830
+
831
+ ## RENAMED Requirements
832
+
833
+ - FROM: \`### Requirement: Old Name\`
834
+ - TO: \`### Requirement: New Name\`
835
+ \`\`\`
836
+
837
+ **Key Principle: Intelligent Merging**
838
+
839
+ Unlike programmatic merging, you can apply **partial updates**:
840
+ - To add a scenario, just include that scenario under MODIFIED - don't copy existing scenarios
841
+ - The delta represents *intent*, not a wholesale replacement
842
+ - Use your judgment to merge changes sensibly
843
+
844
+ **Output On Success**
845
+
846
+ \`\`\`
847
+ ## Specs Synced: <change-name>
848
+
849
+ Updated main specs:
850
+
851
+ **<capability-1>**:
852
+ - Added requirement: "New Feature"
853
+ - Modified requirement: "Existing Feature" (added 1 scenario)
854
+
855
+ **<capability-2>**:
856
+ - Created new spec file
857
+ - Added requirement: "Another Feature"
858
+
859
+ Main specs are now updated. The change remains active - archive when implementation is complete.
860
+ \`\`\`
861
+
862
+ **Guardrails**
863
+ - Read both delta and main specs before making changes
864
+ - Preserve existing content not mentioned in delta
865
+ - If something is unclear, ask for clarification
866
+ - Show what you're changing as you go
867
+ - The operation should be idempotent - running twice should give same result`
868
+ };
869
+ }
870
+ /**
871
+ * Template for /opsx:explore slash command
872
+ * Explore mode - adaptive thinking partner
873
+ */
874
+ export function getOpsxExploreCommandTemplate() {
875
+ return {
876
+ name: 'OPSX: Explore',
877
+ description: 'Enter explore mode - think through ideas, investigate problems, clarify requirements',
878
+ category: 'Workflow',
879
+ tags: ['workflow', 'explore', 'experimental', 'thinking'],
880
+ content: `Enter explore mode. Think deeply. Visualize freely. Follow the conversation wherever it goes.
881
+
882
+ **This is a stance, not a workflow.** There are no fixed steps, no required sequence, no mandatory outputs. You're a thinking partner helping the user explore.
883
+
884
+ **Input**: The argument after \`/opsx:explore\` is whatever the user wants to think about. Could be:
885
+ - A vague idea: "real-time collaboration"
886
+ - A specific problem: "the auth system is getting unwieldy"
887
+ - A change name: "add-dark-mode" (to explore in context of that change)
888
+ - A comparison: "postgres vs sqlite for this"
889
+ - Nothing (just enter explore mode)
890
+
891
+ ---
892
+
893
+ ## The Stance
894
+
895
+ - **Curious, not prescriptive** - Ask questions that emerge naturally, don't follow a script
896
+ - **Visual** - Use ASCII diagrams liberally when they'd help clarify thinking
897
+ - **Adaptive** - Follow interesting threads, pivot when new information emerges
898
+ - **Patient** - Don't rush to conclusions, let the shape of the problem emerge
899
+ - **Grounded** - Explore the actual codebase when relevant, don't just theorize
900
+
901
+ ---
902
+
903
+ ## What You Might Do
904
+
905
+ Depending on what the user brings, you might:
906
+
907
+ **Explore the problem space**
908
+ - Ask clarifying questions that emerge from what they said
909
+ - Challenge assumptions
910
+ - Reframe the problem
911
+ - Find analogies
912
+
913
+ **Investigate the codebase**
914
+ - Map existing architecture relevant to the discussion
915
+ - Find integration points
916
+ - Identify patterns already in use
917
+ - Surface hidden complexity
918
+
919
+ **Compare options**
920
+ - Brainstorm multiple approaches
921
+ - Build comparison tables
922
+ - Sketch tradeoffs
923
+ - Recommend a path (if asked)
924
+
925
+ **Visualize**
926
+ \`\`\`
927
+ ┌─────────────────────────────────────────┐
928
+ │ Use ASCII diagrams liberally │
929
+ ├─────────────────────────────────────────┤
930
+ │ │
931
+ │ ┌────────┐ ┌────────┐ │
932
+ │ │ State │────────▶│ State │ │
933
+ │ │ A │ │ B │ │
934
+ │ └────────┘ └────────┘ │
935
+ │ │
936
+ │ System diagrams, state machines, │
937
+ │ data flows, architecture sketches, │
938
+ │ dependency graphs, comparison tables │
939
+ │ │
940
+ └─────────────────────────────────────────┘
941
+ \`\`\`
942
+
943
+ **Surface risks and unknowns**
944
+ - Identify what could go wrong
945
+ - Find gaps in understanding
946
+ - Suggest spikes or investigations
947
+
948
+ ---
949
+
950
+ ## OpenSpec Awareness
951
+
952
+ You have full context of the OpenSpec system. Use it naturally, don't force it.
953
+
954
+ ### Check for context
955
+
956
+ At the start, quickly check what exists:
957
+ \`\`\`bash
958
+ openspec list --json
959
+ \`\`\`
960
+
961
+ This tells you:
962
+ - If there are active changes
963
+ - Their names, schemas, and status
964
+ - What the user might be working on
965
+
966
+ If the user mentioned a specific change name, read its artifacts for context.
967
+
968
+ ### When no change exists
969
+
970
+ Think freely. When insights crystallize, you might offer:
971
+
972
+ - "This feels solid enough to start a change. Want me to create one?"
973
+ → Can transition to \`/opsx:new\` or \`/opsx:ff\`
974
+ - Or keep exploring - no pressure to formalize
975
+
976
+ ### When a change exists
977
+
978
+ If the user mentions a change or you detect one is relevant:
979
+
980
+ 1. **Read existing artifacts for context**
981
+ - \`openspec/changes/<name>/proposal.md\`
982
+ - \`openspec/changes/<name>/design.md\`
983
+ - \`openspec/changes/<name>/tasks.md\`
984
+ - etc.
985
+
986
+ 2. **Reference them naturally in conversation**
987
+ - "Your design mentions using Redis, but we just realized SQLite fits better..."
988
+ - "The proposal scopes this to premium users, but we're now thinking everyone..."
989
+
990
+ 3. **Offer to capture when decisions are made**
991
+
992
+ | Insight Type | Where to Capture |
993
+ |--------------|------------------|
994
+ | New requirement discovered | \`specs/<capability>/spec.md\` |
995
+ | Requirement changed | \`specs/<capability>/spec.md\` |
996
+ | Design decision made | \`design.md\` |
997
+ | Scope changed | \`proposal.md\` |
998
+ | New work identified | \`tasks.md\` |
999
+ | Assumption invalidated | Relevant artifact |
1000
+
1001
+ Example offers:
1002
+ - "That's a design decision. Capture it in design.md?"
1003
+ - "This is a new requirement. Add it to specs?"
1004
+ - "This changes scope. Update the proposal?"
1005
+
1006
+ 4. **The user decides** - Offer and move on. Don't pressure. Don't auto-capture.
1007
+
1008
+ ---
1009
+
1010
+ ## What You Don't Have To Do
1011
+
1012
+ - Follow a script
1013
+ - Ask the same questions every time
1014
+ - Produce a specific artifact
1015
+ - Reach a conclusion
1016
+ - Stay on topic if a tangent is valuable
1017
+ - Be brief (this is thinking time)
1018
+
1019
+ ---
1020
+
1021
+ ## Ending Discovery
1022
+
1023
+ There's no required ending. Discovery might:
1024
+
1025
+ - **Flow into action**: "Ready to start? \`/opsx:new\` or \`/opsx:ff\`"
1026
+ - **Result in artifact updates**: "Updated design.md with these decisions"
1027
+ - **Just provide clarity**: User has what they need, moves on
1028
+ - **Continue later**: "We can pick this up anytime"
1029
+
1030
+ When things crystallize, you might offer a summary - but it's optional. Sometimes the thinking IS the value.
1031
+
1032
+ ---
1033
+
1034
+ ## Guardrails
1035
+
1036
+ - **Don't fake understanding** - If something is unclear, dig deeper
1037
+ - **Don't rush** - Discovery is thinking time, not task time
1038
+ - **Don't force structure** - Let patterns emerge naturally
1039
+ - **Don't auto-capture** - Offer to save insights, don't just do it
1040
+ - **Do visualize** - A good diagram is worth many paragraphs
1041
+ - **Do explore the codebase** - Ground discussions in reality
1042
+ - **Do question assumptions** - Including the user's and your own`
1043
+ };
1044
+ }
1045
+ /**
1046
+ * Template for /opsx:new slash command
1047
+ */
1048
+ export function getOpsxNewCommandTemplate() {
1049
+ return {
1050
+ name: 'OPSX: New',
1051
+ description: 'Start a new change using the experimental artifact workflow (OPSX)',
1052
+ category: 'Workflow',
1053
+ tags: ['workflow', 'artifacts', 'experimental'],
1054
+ content: `Start a new change using the experimental artifact-driven approach.
1055
+
1056
+ **Input**: The argument after \`/opsx:new\` is the change name (kebab-case), OR a description of what the user wants to build.
1057
+
1058
+ **Steps**
1059
+
1060
+ 1. **If no input provided, ask what they want to build**
1061
+
1062
+ Use the **AskUserQuestion tool** (open-ended, no preset options) to ask:
1063
+ > "What change do you want to work on? Describe what you want to build or fix."
1064
+
1065
+ From their description, derive a kebab-case name (e.g., "add user authentication" → \`add-user-auth\`).
1066
+
1067
+ **IMPORTANT**: Do NOT proceed without understanding what the user wants to build.
1068
+
1069
+ 2. **Determine the workflow schema**
1070
+
1071
+ Use the default schema (omit \`--schema\`) unless the user explicitly requests a different workflow.
1072
+
1073
+ **Use a different schema only if the user mentions:**
1074
+ - "tdd" or "test-driven" → use \`--schema tdd\`
1075
+ - A specific schema name → use \`--schema <name>\`
1076
+ - "show workflows" or "what workflows" → run \`openspec schemas --json\` and let them choose
1077
+
1078
+ **Otherwise**: Omit \`--schema\` to use the default.
1079
+
1080
+ 3. **Create the change directory**
1081
+ \`\`\`bash
1082
+ openspec new change "<name>"
1083
+ \`\`\`
1084
+ Add \`--schema <name>\` only if the user requested a specific workflow.
1085
+ This creates a scaffolded change at \`openspec/changes/<name>/\` with the selected schema.
1086
+
1087
+ 4. **Show the artifact status**
1088
+ \`\`\`bash
1089
+ openspec status --change "<name>"
1090
+ \`\`\`
1091
+ This shows which artifacts need to be created and which are ready (dependencies satisfied).
1092
+
1093
+ 5. **Get instructions for the first artifact**
1094
+ The first artifact depends on the schema. Check the status output to find the first artifact with status "ready".
1095
+ \`\`\`bash
1096
+ openspec instructions <first-artifact-id> --change "<name>"
1097
+ \`\`\`
1098
+ This outputs the template and context for creating the first artifact.
1099
+
1100
+ 6. **STOP and wait for user direction**
1101
+
1102
+ **Output**
1103
+
1104
+ After completing the steps, summarize:
1105
+ - Change name and location
1106
+ - Schema/workflow being used and its artifact sequence
1107
+ - Current status (0/N artifacts complete)
1108
+ - The template for the first artifact
1109
+ - Prompt: "Ready to create the first artifact? Run \`/opsx:continue\` or just describe what this change is about and I'll draft it."
1110
+
1111
+ **Guardrails**
1112
+ - Do NOT create any artifacts yet - just show the instructions
1113
+ - Do NOT advance beyond showing the first artifact template
1114
+ - If the name is invalid (not kebab-case), ask for a valid name
1115
+ - If a change with that name already exists, suggest using \`/opsx:continue\` instead
1116
+ - Pass --schema if using a non-default workflow`
1117
+ };
1118
+ }
1119
+ /**
1120
+ * Template for /opsx:continue slash command
1121
+ */
1122
+ export function getOpsxContinueCommandTemplate() {
1123
+ return {
1124
+ name: 'OPSX: Continue',
1125
+ description: 'Continue working on a change - create the next artifact (Experimental)',
1126
+ category: 'Workflow',
1127
+ tags: ['workflow', 'artifacts', 'experimental'],
1128
+ content: `Continue working on a change by creating the next artifact.
1129
+
1130
+ **Input**: Optionally specify \`--change <name>\` after \`/opsx:continue\`. If omitted, MUST prompt for available changes.
1131
+
1132
+ **Steps**
1133
+
1134
+ 1. **If no change name provided, prompt for selection**
1135
+
1136
+ Run \`openspec list --json\` to get available changes sorted by most recently modified. Then use the **AskUserQuestion tool** to let the user select which change to work on.
1137
+
1138
+ Present the top 3-4 most recently modified changes as options, showing:
1139
+ - Change name
1140
+ - Schema (from \`schema\` field if present, otherwise "spec-driven")
1141
+ - Status (e.g., "0/5 tasks", "complete", "no tasks")
1142
+ - How recently it was modified (from \`lastModified\` field)
1143
+
1144
+ Mark the most recently modified change as "(Recommended)" since it's likely what the user wants to continue.
1145
+
1146
+ **IMPORTANT**: Do NOT guess or auto-select a change. Always let the user choose.
1147
+
1148
+ 2. **Check current status**
1149
+ \`\`\`bash
1150
+ openspec status --change "<name>" --json
1151
+ \`\`\`
1152
+ Parse the JSON to understand current state. The response includes:
1153
+ - \`schemaName\`: The workflow schema being used (e.g., "spec-driven", "tdd")
1154
+ - \`artifacts\`: Array of artifacts with their status ("done", "ready", "blocked")
1155
+ - \`isComplete\`: Boolean indicating if all artifacts are complete
1156
+
1157
+ 3. **Act based on status**:
1158
+
1159
+ ---
1160
+
1161
+ **If all artifacts are complete (\`isComplete: true\`)**:
1162
+ - Congratulate the user
1163
+ - Show final status including the schema used
1164
+ - Suggest: "All artifacts created! You can now implement this change or archive it."
1165
+ - STOP
1166
+
1167
+ ---
1168
+
1169
+ **If artifacts are ready to create** (status shows artifacts with \`status: "ready"\`):
1170
+ - Pick the FIRST artifact with \`status: "ready"\` from the status output
1171
+ - Get its instructions:
1172
+ \`\`\`bash
1173
+ openspec instructions <artifact-id> --change "<name>" --json
1174
+ \`\`\`
1175
+ - Parse the JSON to get template, dependencies, and what it unlocks
1176
+ - **Create the artifact file** using the template as a starting point:
1177
+ - Read any completed dependency files for context
1178
+ - Fill in the template based on context and user's goals
1179
+ - Write to the output path specified in instructions
1180
+ - Show what was created and what's now unlocked
1181
+ - STOP after creating ONE artifact
1182
+
1183
+ ---
1184
+
1185
+ **If no artifacts are ready (all blocked)**:
1186
+ - This shouldn't happen with a valid schema
1187
+ - Show status and suggest checking for issues
1188
+
1189
+ 4. **After creating an artifact, show progress**
1190
+ \`\`\`bash
1191
+ openspec status --change "<name>"
1192
+ \`\`\`
1193
+
1194
+ **Output**
1195
+
1196
+ After each invocation, show:
1197
+ - Which artifact was created
1198
+ - Schema workflow being used
1199
+ - Current progress (N/M complete)
1200
+ - What artifacts are now unlocked
1201
+ - Prompt: "Run \`/opsx:continue\` to create the next artifact"
1202
+
1203
+ **Artifact Creation Guidelines**
1204
+
1205
+ The artifact types and their purpose depend on the schema. Use the \`instruction\` field from the instructions output to understand what to create.
1206
+
1207
+ Common artifact patterns:
1208
+
1209
+ **spec-driven schema** (proposal → specs → design → tasks):
1210
+ - **proposal.md**: Ask user about the change if not clear. Fill in Why, What Changes, Capabilities, Impact.
1211
+ - The Capabilities section is critical - each capability listed will need a spec file.
1212
+ - **specs/*.md**: Create one spec per capability listed in the proposal.
1213
+ - **design.md**: Document technical decisions, architecture, and implementation approach.
1214
+ - **tasks.md**: Break down implementation into checkboxed tasks.
1215
+
1216
+ **tdd schema** (spec → tests → implementation → docs):
1217
+ - **spec.md**: Feature specification defining what to build.
1218
+ - **tests/*.test.ts**: Write tests BEFORE implementation (TDD red phase).
1219
+ - **src/*.ts**: Implement to make tests pass (TDD green phase).
1220
+ - **docs/*.md**: Document the implemented feature.
1221
+
1222
+ For other schemas, follow the \`instruction\` field from the CLI output.
1223
+
1224
+ **Guardrails**
1225
+ - Create ONE artifact per invocation
1226
+ - Always read dependency artifacts before creating a new one
1227
+ - Never skip artifacts or create out of order
1228
+ - If context is unclear, ask the user before creating
1229
+ - Verify the artifact file exists after writing before marking progress
1230
+ - Use the schema's artifact sequence, don't assume specific artifact names`
1231
+ };
1232
+ }
1233
+ /**
1234
+ * Template for /opsx:apply slash command
1235
+ */
1236
+ export function getOpsxApplyCommandTemplate() {
1237
+ return {
1238
+ name: 'OPSX: Apply',
1239
+ description: 'Implement tasks from an OpenSpec change (Experimental)',
1240
+ category: 'Workflow',
1241
+ tags: ['workflow', 'artifacts', 'experimental'],
1242
+ content: `Implement tasks from an OpenSpec change.
1243
+
1244
+ **Input**: Optionally specify \`--change <name>\` after \`/opsx:apply\`. If omitted, MUST prompt for available changes.
1245
+
1246
+ **Steps**
1247
+
1248
+ 1. **If no change name provided, prompt for selection**
1249
+
1250
+ Run \`openspec list --json\` to get available changes. Use the **AskUserQuestion tool** to let the user select.
1251
+
1252
+ Show changes that are implementation-ready (have tasks artifact).
1253
+ Include the schema used for each change if available.
1254
+ Mark changes with incomplete tasks as "(In Progress)".
1255
+
1256
+ **IMPORTANT**: Do NOT guess or auto-select a change. Always let the user choose.
1257
+
1258
+ 2. **Check status to understand the schema**
1259
+ \`\`\`bash
1260
+ openspec status --change "<name>" --json
1261
+ \`\`\`
1262
+ Parse the JSON to understand:
1263
+ - \`schemaName\`: The workflow being used (e.g., "spec-driven", "tdd")
1264
+ - Which artifact contains the tasks (typically "tasks" for spec-driven, check status for others)
1265
+
1266
+ 3. **Get apply instructions**
1267
+
1268
+ \`\`\`bash
1269
+ openspec instructions apply --change "<name>" --json
1270
+ \`\`\`
1271
+
1272
+ This returns:
1273
+ - Context file paths (varies by schema)
1274
+ - Progress (total, complete, remaining)
1275
+ - Task list with status
1276
+ - Dynamic instruction based on current state
1277
+
1278
+ **Handle states:**
1279
+ - If \`state: "blocked"\` (missing artifacts): show message, suggest using \`/opsx:continue\`
1280
+ - If \`state: "all_done"\`: congratulate, suggest archive
1281
+ - Otherwise: proceed to implementation
1282
+
1283
+ 4. **Read context files**
1284
+
1285
+ Read the files listed in \`contextFiles\` from the apply instructions output.
1286
+ The files depend on the schema being used:
1287
+ - **spec-driven**: proposal, specs, design, tasks
1288
+ - **tdd**: spec, tests, implementation, docs
1289
+ - Other schemas: follow the contextFiles from CLI output
1290
+
1291
+ 5. **Show current progress**
1292
+
1293
+ Display:
1294
+ - Schema being used
1295
+ - Progress: "N/M tasks complete"
1296
+ - Remaining tasks overview
1297
+ - Dynamic instruction from CLI
1298
+
1299
+ 6. **Implement tasks (loop until done or blocked)**
1300
+
1301
+ For each pending task:
1302
+ - Show which task is being worked on
1303
+ - Make the code changes required
1304
+ - Keep changes minimal and focused
1305
+ - Mark task complete in the tasks file: \`- [ ]\` → \`- [x]\`
1306
+ - Continue to next task
1307
+
1308
+ **Pause if:**
1309
+ - Task is unclear → ask for clarification
1310
+ - Implementation reveals a design issue → suggest updating artifacts
1311
+ - Error or blocker encountered → report and wait for guidance
1312
+ - User interrupts
1313
+
1314
+ 7. **On completion or pause, show status**
1315
+
1316
+ Display:
1317
+ - Tasks completed this session
1318
+ - Overall progress: "N/M tasks complete"
1319
+ - If all done: suggest archive
1320
+ - If paused: explain why and wait for guidance
1321
+
1322
+ **Output During Implementation**
1323
+
1324
+ \`\`\`
1325
+ ## Implementing: <change-name> (schema: <schema-name>)
1326
+
1327
+ Working on task 3/7: <task description>
1328
+ [...implementation happening...]
1329
+ ✓ Task complete
1330
+
1331
+ Working on task 4/7: <task description>
1332
+ [...implementation happening...]
1333
+ ✓ Task complete
1334
+ \`\`\`
1335
+
1336
+ **Output On Completion**
1337
+
1338
+ \`\`\`
1339
+ ## Implementation Complete
1340
+
1341
+ **Change:** <change-name>
1342
+ **Schema:** <schema-name>
1343
+ **Progress:** 7/7 tasks complete ✓
1344
+
1345
+ ### Completed This Session
1346
+ - [x] Task 1
1347
+ - [x] Task 2
1348
+ ...
1349
+
1350
+ All tasks complete! Ready to archive this change.
1351
+ \`\`\`
1352
+
1353
+ **Output On Pause (Issue Encountered)**
1354
+
1355
+ \`\`\`
1356
+ ## Implementation Paused
1357
+
1358
+ **Change:** <change-name>
1359
+ **Schema:** <schema-name>
1360
+ **Progress:** 4/7 tasks complete
1361
+
1362
+ ### Issue Encountered
1363
+ <description of the issue>
1364
+
1365
+ **Options:**
1366
+ 1. <option 1>
1367
+ 2. <option 2>
1368
+ 3. Other approach
1369
+
1370
+ What would you like to do?
1371
+ \`\`\`
1372
+
1373
+ **Guardrails**
1374
+ - Keep going through tasks until done or blocked
1375
+ - Always read context files before starting (from the apply instructions output)
1376
+ - If task is ambiguous, pause and ask before implementing
1377
+ - If implementation reveals issues, pause and suggest artifact updates
1378
+ - Keep code changes minimal and scoped to each task
1379
+ - Update task checkbox immediately after completing each task
1380
+ - Pause on errors, blockers, or unclear requirements - don't guess
1381
+ - Use contextFiles from CLI output, don't assume specific file names
1382
+
1383
+ **Fluid Workflow Integration**
1384
+
1385
+ This skill supports the "actions on a change" model:
1386
+
1387
+ - **Can be invoked anytime**: Before all artifacts are done (if tasks exist), after partial implementation, interleaved with other actions
1388
+ - **Allows artifact updates**: If implementation reveals design issues, suggest updating artifacts - not phase-locked, work fluidly`
1389
+ };
1390
+ }
1391
+ /**
1392
+ * Template for /opsx:ff slash command
1393
+ */
1394
+ export function getOpsxFfCommandTemplate() {
1395
+ return {
1396
+ name: 'OPSX: Fast Forward',
1397
+ description: 'Create a change and generate all artifacts needed for implementation in one go',
1398
+ category: 'Workflow',
1399
+ tags: ['workflow', 'artifacts', 'experimental'],
1400
+ content: `Fast-forward through artifact creation - generate everything needed to start implementation.
1401
+
1402
+ **Input**: The argument after \`/opsx:ff\` is the change name (kebab-case), OR a description of what the user wants to build.
1403
+
1404
+ **Steps**
1405
+
1406
+ 1. **If no input provided, ask what they want to build**
1407
+
1408
+ Use the **AskUserQuestion tool** (open-ended, no preset options) to ask:
1409
+ > "What change do you want to work on? Describe what you want to build or fix."
1410
+
1411
+ From their description, derive a kebab-case name (e.g., "add user authentication" → \`add-user-auth\`).
1412
+
1413
+ **IMPORTANT**: Do NOT proceed without understanding what the user wants to build.
1414
+
1415
+ 2. **Create the change directory**
1416
+ \`\`\`bash
1417
+ openspec new change "<name>"
1418
+ \`\`\`
1419
+ This creates a scaffolded change at \`openspec/changes/<name>/\`.
1420
+
1421
+ 3. **Get the artifact build order**
1422
+ \`\`\`bash
1423
+ openspec status --change "<name>" --json
1424
+ \`\`\`
1425
+ Parse the JSON to get:
1426
+ - \`applyRequires\`: array of artifact IDs needed before implementation (e.g., \`["tasks"]\`)
1427
+ - \`artifacts\`: list of all artifacts with their status and dependencies
1428
+
1429
+ 4. **Create artifacts in sequence until apply-ready**
1430
+
1431
+ Use the **TodoWrite tool** to track progress through the artifacts.
1432
+
1433
+ Loop through artifacts in dependency order (artifacts with no pending dependencies first):
1434
+
1435
+ a. **For each artifact that is \`ready\` (dependencies satisfied)**:
1436
+ - Get instructions:
1437
+ \`\`\`bash
1438
+ openspec instructions <artifact-id> --change "<name>" --json
1439
+ \`\`\`
1440
+ - The instructions JSON includes:
1441
+ - \`template\`: The template content to use
1442
+ - \`instruction\`: Schema-specific guidance for this artifact type
1443
+ - \`outputPath\`: Where to write the artifact
1444
+ - \`dependencies\`: Completed artifacts to read for context
1445
+ - Read any completed dependency files for context
1446
+ - Create the artifact file following the schema's \`instruction\`
1447
+ - Show brief progress: "✓ Created <artifact-id>"
1448
+
1449
+ b. **Continue until all \`applyRequires\` artifacts are complete**
1450
+ - After creating each artifact, re-run \`openspec status --change "<name>" --json\`
1451
+ - Check if every artifact ID in \`applyRequires\` has \`status: "done"\` in the artifacts array
1452
+ - Stop when all \`applyRequires\` artifacts are done
1453
+
1454
+ c. **If an artifact requires user input** (unclear context):
1455
+ - Use **AskUserQuestion tool** to clarify
1456
+ - Then continue with creation
1457
+
1458
+ 5. **Show final status**
1459
+ \`\`\`bash
1460
+ openspec status --change "<name>"
1461
+ \`\`\`
1462
+
1463
+ **Output**
1464
+
1465
+ After completing all artifacts, summarize:
1466
+ - Change name and location
1467
+ - List of artifacts created with brief descriptions
1468
+ - What's ready: "All artifacts created! Ready for implementation."
1469
+ - Prompt: "Run \`/opsx:apply\` to start implementing."
1470
+
1471
+ **Artifact Creation Guidelines**
1472
+
1473
+ - Follow the \`instruction\` field from \`openspec instructions\` for each artifact type
1474
+ - The schema defines what each artifact should contain - follow it
1475
+ - Read dependency artifacts for context before creating new ones
1476
+ - Use the \`template\` as a starting point, filling in based on context
1477
+
1478
+ **Guardrails**
1479
+ - Create ALL artifacts needed for implementation (as defined by schema's \`apply.requires\`)
1480
+ - Always read dependency artifacts before creating a new one
1481
+ - If context is critically unclear, ask the user - but prefer making reasonable decisions to keep momentum
1482
+ - If a change with that name already exists, ask if user wants to continue it or create a new one
1483
+ - Verify each artifact file exists after writing before proceeding to next`
1484
+ };
1485
+ }
1486
+ /**
1487
+ * Template for openspec-archive-change skill
1488
+ * For archiving completed changes in the experimental workflow
1489
+ */
1490
+ export function getArchiveChangeSkillTemplate() {
1491
+ return {
1492
+ name: 'openspec-archive-change',
1493
+ description: 'Archive a completed change in the experimental workflow. Use when the user wants to finalize and archive a change after implementation is complete.',
1494
+ instructions: `Archive a completed change in the experimental workflow.
1495
+
1496
+ **Input**: Optionally specify a change name. If omitted, MUST prompt for available changes.
1497
+
1498
+ **Steps**
1499
+
1500
+ 1. **If no change name provided, prompt for selection**
1501
+
1502
+ Run \`openspec list --json\` to get available changes. Use the **AskUserQuestion tool** to let the user select.
1503
+
1504
+ Show only active changes (not already archived).
1505
+ Include the schema used for each change if available.
1506
+
1507
+ **IMPORTANT**: Do NOT guess or auto-select a change. Always let the user choose.
1508
+
1509
+ 2. **Check artifact completion status**
1510
+
1511
+ Run \`openspec status --change "<name>" --json\` to check artifact completion.
1512
+
1513
+ Parse the JSON to understand:
1514
+ - \`schemaName\`: The workflow being used
1515
+ - \`artifacts\`: List of artifacts with their status (\`done\` or other)
1516
+
1517
+ **If any artifacts are not \`done\`:**
1518
+ - Display warning listing incomplete artifacts
1519
+ - Use **AskUserQuestion tool** to confirm user wants to proceed
1520
+ - Proceed if user confirms
1521
+
1522
+ 3. **Check task completion status**
1523
+
1524
+ Read the tasks file (typically \`tasks.md\`) to check for incomplete tasks.
1525
+
1526
+ Count tasks marked with \`- [ ]\` (incomplete) vs \`- [x]\` (complete).
1527
+
1528
+ **If incomplete tasks found:**
1529
+ - Display warning showing count of incomplete tasks
1530
+ - Use **AskUserQuestion tool** to confirm user wants to proceed
1531
+ - Proceed if user confirms
1532
+
1533
+ **If no tasks file exists:** Proceed without task-related warning.
1534
+
1535
+ 4. **Check if delta specs need syncing**
1536
+
1537
+ Check if \`specs/\` directory exists in the change with spec files.
1538
+
1539
+ **If delta specs exist, perform a quick sync check:**
1540
+
1541
+ a. **For each delta spec** at \`openspec/changes/<name>/specs/<capability>/spec.md\`:
1542
+ - Extract requirement names (lines matching \`### Requirement: <name>\`)
1543
+ - Note which sections exist (ADDED, MODIFIED, REMOVED)
1544
+
1545
+ b. **Check corresponding main spec** at \`openspec/specs/<capability>/spec.md\`:
1546
+ - If main spec doesn't exist → needs sync
1547
+ - If main spec exists, check if ADDED requirement names appear in it
1548
+ - If any ADDED requirements are missing from main spec → needs sync
1549
+
1550
+ c. **Report findings:**
1551
+
1552
+ **If sync needed:**
1553
+ \`\`\`
1554
+ ⚠️ Delta specs may not be synced:
1555
+ - specs/auth/spec.md → Main spec missing requirement "Token Refresh"
1556
+ - specs/api/spec.md → Main spec doesn't exist yet
1557
+
1558
+ Would you like to sync now before archiving?
1559
+ \`\`\`
1560
+ - Use **AskUserQuestion tool** with options: "Sync now", "Archive without syncing"
1561
+ - If user chooses sync, execute /opsx:sync logic (use the openspec-sync-specs skill)
1562
+
1563
+ **If already synced (all requirements found):**
1564
+ - Proceed without prompting (specs appear to be in sync)
1565
+
1566
+ **If no delta specs exist:** Proceed without sync-related checks.
1567
+
1568
+ 5. **Perform the archive**
1569
+
1570
+ Create the archive directory if it doesn't exist:
1571
+ \`\`\`bash
1572
+ mkdir -p openspec/changes/archive
1573
+ \`\`\`
1574
+
1575
+ Generate target name using current date: \`YYYY-MM-DD-<change-name>\`
1576
+
1577
+ **Check if target already exists:**
1578
+ - If yes: Fail with error, suggest renaming existing archive or using different date
1579
+ - If no: Move the change directory to archive
1580
+
1581
+ \`\`\`bash
1582
+ mv openspec/changes/<name> openspec/changes/archive/YYYY-MM-DD-<name>
1583
+ \`\`\`
1584
+
1585
+ 6. **Display summary**
1586
+
1587
+ Show archive completion summary including:
1588
+ - Change name
1589
+ - Schema that was used
1590
+ - Archive location
1591
+ - Whether specs were synced (if applicable)
1592
+ - Note about any warnings (incomplete artifacts/tasks)
1593
+
1594
+ **Output On Success**
1595
+
1596
+ \`\`\`
1597
+ ## Archive Complete
1598
+
1599
+ **Change:** <change-name>
1600
+ **Schema:** <schema-name>
1601
+ **Archived to:** openspec/changes/archive/YYYY-MM-DD-<name>/
1602
+ **Specs:** ✓ Synced to main specs (or "No delta specs" or "⚠️ Not synced")
1603
+
1604
+ All artifacts complete. All tasks complete.
1605
+ \`\`\`
1606
+
1607
+ **Guardrails**
1608
+ - Always prompt for change selection if not provided
1609
+ - Use artifact graph (openspec status --json) for completion checking
1610
+ - Don't block archive on warnings - just inform and confirm
1611
+ - Preserve .openspec.yaml when moving to archive (it moves with the directory)
1612
+ - Show clear summary of what happened
1613
+ - If sync is requested, use openspec-sync-specs approach (agent-driven)
1614
+ - Quick sync check: look for requirement names in delta specs, verify they exist in main specs`
1615
+ };
1616
+ }
1617
+ /**
1618
+ * Template for /opsx:sync slash command
1619
+ */
1620
+ export function getOpsxSyncCommandTemplate() {
1621
+ return {
1622
+ name: 'OPSX: Sync',
1623
+ description: 'Sync delta specs from a change to main specs',
1624
+ category: 'Workflow',
1625
+ tags: ['workflow', 'specs', 'experimental'],
1626
+ content: `Sync delta specs from a change to main specs.
1627
+
1628
+ 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).
1629
+
1630
+ **Input**: Optionally specify \`--change <name>\` after \`/opsx:sync\`. If omitted, MUST prompt for available changes.
1631
+
1632
+ **Steps**
1633
+
1634
+ 1. **If no change name provided, prompt for selection**
1635
+
1636
+ Run \`openspec list --json\` to get available changes. Use the **AskUserQuestion tool** to let the user select.
1637
+
1638
+ Show changes that have delta specs (under \`specs/\` directory).
1639
+
1640
+ **IMPORTANT**: Do NOT guess or auto-select a change. Always let the user choose.
1641
+
1642
+ 2. **Find delta specs**
1643
+
1644
+ Look for delta spec files in \`openspec/changes/<name>/specs/*/spec.md\`.
1645
+
1646
+ Each delta spec file contains sections like:
1647
+ - \`## ADDED Requirements\` - New requirements to add
1648
+ - \`## MODIFIED Requirements\` - Changes to existing requirements
1649
+ - \`## REMOVED Requirements\` - Requirements to remove
1650
+ - \`## RENAMED Requirements\` - Requirements to rename (FROM:/TO: format)
1651
+
1652
+ If no delta specs found, inform user and stop.
1653
+
1654
+ 3. **For each delta spec, apply changes to main specs**
1655
+
1656
+ For each capability with a delta spec at \`openspec/changes/<name>/specs/<capability>/spec.md\`:
1657
+
1658
+ a. **Read the delta spec** to understand the intended changes
1659
+
1660
+ b. **Read the main spec** at \`openspec/specs/<capability>/spec.md\` (may not exist yet)
1661
+
1662
+ c. **Apply changes intelligently**:
1663
+
1664
+ **ADDED Requirements:**
1665
+ - If requirement doesn't exist in main spec → add it
1666
+ - If requirement already exists → update it to match (treat as implicit MODIFIED)
1667
+
1668
+ **MODIFIED Requirements:**
1669
+ - Find the requirement in main spec
1670
+ - Apply the changes - this can be:
1671
+ - Adding new scenarios (don't need to copy existing ones)
1672
+ - Modifying existing scenarios
1673
+ - Changing the requirement description
1674
+ - Preserve scenarios/content not mentioned in the delta
1675
+
1676
+ **REMOVED Requirements:**
1677
+ - Remove the entire requirement block from main spec
1678
+
1679
+ **RENAMED Requirements:**
1680
+ - Find the FROM requirement, rename to TO
1681
+
1682
+ d. **Create new main spec** if capability doesn't exist yet:
1683
+ - Create \`openspec/specs/<capability>/spec.md\`
1684
+ - Add Purpose section (can be brief, mark as TBD)
1685
+ - Add Requirements section with the ADDED requirements
1686
+
1687
+ 4. **Show summary**
1688
+
1689
+ After applying all changes, summarize:
1690
+ - Which capabilities were updated
1691
+ - What changes were made (requirements added/modified/removed/renamed)
1692
+
1693
+ **Delta Spec Format Reference**
1694
+
1695
+ \`\`\`markdown
1696
+ ## ADDED Requirements
1697
+
1698
+ ### Requirement: New Feature
1699
+ The system SHALL do something new.
1700
+
1701
+ #### Scenario: Basic case
1702
+ - **WHEN** user does X
1703
+ - **THEN** system does Y
1704
+
1705
+ ## MODIFIED Requirements
1706
+
1707
+ ### Requirement: Existing Feature
1708
+ #### Scenario: New scenario to add
1709
+ - **WHEN** user does A
1710
+ - **THEN** system does B
1711
+
1712
+ ## REMOVED Requirements
1713
+
1714
+ ### Requirement: Deprecated Feature
1715
+
1716
+ ## RENAMED Requirements
1717
+
1718
+ - FROM: \`### Requirement: Old Name\`
1719
+ - TO: \`### Requirement: New Name\`
1720
+ \`\`\`
1721
+
1722
+ **Key Principle: Intelligent Merging**
1723
+
1724
+ Unlike programmatic merging, you can apply **partial updates**:
1725
+ - To add a scenario, just include that scenario under MODIFIED - don't copy existing scenarios
1726
+ - The delta represents *intent*, not a wholesale replacement
1727
+ - Use your judgment to merge changes sensibly
1728
+
1729
+ **Output On Success**
1730
+
1731
+ \`\`\`
1732
+ ## Specs Synced: <change-name>
1733
+
1734
+ Updated main specs:
1735
+
1736
+ **<capability-1>**:
1737
+ - Added requirement: "New Feature"
1738
+ - Modified requirement: "Existing Feature" (added 1 scenario)
1739
+
1740
+ **<capability-2>**:
1741
+ - Created new spec file
1742
+ - Added requirement: "Another Feature"
1743
+
1744
+ Main specs are now updated. The change remains active - archive when implementation is complete.
1745
+ \`\`\`
1746
+
1747
+ **Guardrails**
1748
+ - Read both delta and main specs before making changes
1749
+ - Preserve existing content not mentioned in delta
1750
+ - If something is unclear, ask for clarification
1751
+ - Show what you're changing as you go
1752
+ - The operation should be idempotent - running twice should give same result`
1753
+ };
1754
+ }
1755
+ /**
1756
+ * Template for /opsx:archive slash command
1757
+ */
1758
+ export function getOpsxArchiveCommandTemplate() {
1759
+ return {
1760
+ name: 'OPSX: Archive',
1761
+ description: 'Archive a completed change in the experimental workflow',
1762
+ category: 'Workflow',
1763
+ tags: ['workflow', 'archive', 'experimental'],
1764
+ content: `Archive a completed change in the experimental workflow.
1765
+
1766
+ **Input**: Optionally specify \`--change <name>\` after \`/opsx:archive\`. If omitted, MUST prompt for available changes.
1767
+
1768
+ **Steps**
1769
+
1770
+ 1. **If no change name provided, prompt for selection**
1771
+
1772
+ Run \`openspec list --json\` to get available changes. Use the **AskUserQuestion tool** to let the user select.
1773
+
1774
+ Show only active changes (not already archived).
1775
+ Include the schema used for each change if available.
1776
+
1777
+ **IMPORTANT**: Do NOT guess or auto-select a change. Always let the user choose.
1778
+
1779
+ 2. **Check artifact completion status**
1780
+
1781
+ Run \`openspec status --change "<name>" --json\` to check artifact completion.
1782
+
1783
+ Parse the JSON to understand:
1784
+ - \`schemaName\`: The workflow being used
1785
+ - \`artifacts\`: List of artifacts with their status (\`done\` or other)
1786
+
1787
+ **If any artifacts are not \`done\`:**
1788
+ - Display warning listing incomplete artifacts
1789
+ - Prompt user for confirmation to continue
1790
+ - Proceed if user confirms
1791
+
1792
+ 3. **Check task completion status**
1793
+
1794
+ Read the tasks file (typically \`tasks.md\`) to check for incomplete tasks.
1795
+
1796
+ Count tasks marked with \`- [ ]\` (incomplete) vs \`- [x]\` (complete).
1797
+
1798
+ **If incomplete tasks found:**
1799
+ - Display warning showing count of incomplete tasks
1800
+ - Prompt user for confirmation to continue
1801
+ - Proceed if user confirms
1802
+
1803
+ **If no tasks file exists:** Proceed without task-related warning.
1804
+
1805
+ 4. **Check if delta specs need syncing**
1806
+
1807
+ Check if \`specs/\` directory exists in the change with spec files.
1808
+
1809
+ **If delta specs exist, perform a quick sync check:**
1810
+
1811
+ a. **For each delta spec** at \`openspec/changes/<name>/specs/<capability>/spec.md\`:
1812
+ - Extract requirement names (lines matching \`### Requirement: <name>\`)
1813
+ - Note which sections exist (ADDED, MODIFIED, REMOVED)
1814
+
1815
+ b. **Check corresponding main spec** at \`openspec/specs/<capability>/spec.md\`:
1816
+ - If main spec doesn't exist → needs sync
1817
+ - If main spec exists, check if ADDED requirement names appear in it
1818
+ - If any ADDED requirements are missing from main spec → needs sync
1819
+
1820
+ c. **Report findings:**
1821
+
1822
+ **If sync needed:**
1823
+ \`\`\`
1824
+ ⚠️ Delta specs may not be synced:
1825
+ - specs/auth/spec.md → Main spec missing requirement "Token Refresh"
1826
+ - specs/api/spec.md → Main spec doesn't exist yet
1827
+
1828
+ Would you like to sync now before archiving?
1829
+ \`\`\`
1830
+ - Use **AskUserQuestion tool** with options: "Sync now", "Archive without syncing"
1831
+ - If user chooses sync, execute \`/opsx:sync\` logic
1832
+
1833
+ **If already synced (all requirements found):**
1834
+ - Proceed without prompting (specs appear to be in sync)
1835
+
1836
+ **If no delta specs exist:** Proceed without sync-related checks.
1837
+
1838
+ 5. **Perform the archive**
1839
+
1840
+ Create the archive directory if it doesn't exist:
1841
+ \`\`\`bash
1842
+ mkdir -p openspec/changes/archive
1843
+ \`\`\`
1844
+
1845
+ Generate target name using current date: \`YYYY-MM-DD-<change-name>\`
1846
+
1847
+ **Check if target already exists:**
1848
+ - If yes: Fail with error, suggest renaming existing archive or using different date
1849
+ - If no: Move the change directory to archive
1850
+
1851
+ \`\`\`bash
1852
+ mv openspec/changes/<name> openspec/changes/archive/YYYY-MM-DD-<name>
1853
+ \`\`\`
1854
+
1855
+ 6. **Display summary**
1856
+
1857
+ Show archive completion summary including:
1858
+ - Change name
1859
+ - Schema that was used
1860
+ - Archive location
1861
+ - Spec sync status (synced / not synced / no delta specs)
1862
+ - Note about any warnings (incomplete artifacts/tasks)
1863
+
1864
+ **Output On Success**
1865
+
1866
+ \`\`\`
1867
+ ## Archive Complete
1868
+
1869
+ **Change:** <change-name>
1870
+ **Schema:** <schema-name>
1871
+ **Archived to:** openspec/changes/archive/YYYY-MM-DD-<name>/
1872
+ **Specs:** ✓ Synced to main specs
1873
+
1874
+ All artifacts complete. All tasks complete.
1875
+ \`\`\`
1876
+
1877
+ **Output On Success (No Delta Specs)**
1878
+
1879
+ \`\`\`
1880
+ ## Archive Complete
1881
+
1882
+ **Change:** <change-name>
1883
+ **Schema:** <schema-name>
1884
+ **Archived to:** openspec/changes/archive/YYYY-MM-DD-<name>/
1885
+ **Specs:** No delta specs
1886
+
1887
+ All artifacts complete. All tasks complete.
1888
+ \`\`\`
1889
+
1890
+ **Output On Success With Warnings**
1891
+
1892
+ \`\`\`
1893
+ ## Archive Complete (with warnings)
1894
+
1895
+ **Change:** <change-name>
1896
+ **Schema:** <schema-name>
1897
+ **Archived to:** openspec/changes/archive/YYYY-MM-DD-<name>/
1898
+ **Specs:** ⚠️ Not synced
1899
+
1900
+ **Warnings:**
1901
+ - Archived with 2 incomplete artifacts
1902
+ - Archived with 3 incomplete tasks
1903
+ - Delta specs were not synced (user chose to skip)
1904
+
1905
+ Review the archive if this was not intentional.
1906
+ \`\`\`
1907
+
1908
+ **Output On Error (Archive Exists)**
1909
+
1910
+ \`\`\`
1911
+ ## Archive Failed
1912
+
1913
+ **Change:** <change-name>
1914
+ **Target:** openspec/changes/archive/YYYY-MM-DD-<name>/
1915
+
1916
+ Target archive directory already exists.
1917
+
1918
+ **Options:**
1919
+ 1. Rename the existing archive
1920
+ 2. Delete the existing archive if it's a duplicate
1921
+ 3. Wait until a different date to archive
1922
+ \`\`\`
1923
+
1924
+ **Guardrails**
1925
+ - Always prompt for change selection if not provided
1926
+ - Use artifact graph (openspec status --json) for completion checking
1927
+ - Don't block archive on warnings - just inform and confirm
1928
+ - Preserve .openspec.yaml when moving to archive (it moves with the directory)
1929
+ - Quick sync check: look for requirement names in delta specs, verify they exist in main specs
1930
+ - Show clear summary of what happened
1931
+ - If sync is requested, use /opsx:sync approach (agent-driven)`
1932
+ };
1933
+ }
1934
+ //# sourceMappingURL=skill-templates.js.map