@bobby_z/openspec 0.0.1

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 (234) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +204 -0
  3. package/bin/openspec.js +3 -0
  4. package/dist/cli/index.d.ts +2 -0
  5. package/dist/cli/index.js +482 -0
  6. package/dist/commands/change.d.ts +35 -0
  7. package/dist/commands/change.js +277 -0
  8. package/dist/commands/completion.d.ts +72 -0
  9. package/dist/commands/completion.js +257 -0
  10. package/dist/commands/config.d.ts +8 -0
  11. package/dist/commands/config.js +198 -0
  12. package/dist/commands/feedback.d.ts +9 -0
  13. package/dist/commands/feedback.js +183 -0
  14. package/dist/commands/schema.d.ts +6 -0
  15. package/dist/commands/schema.js +869 -0
  16. package/dist/commands/show.d.ts +14 -0
  17. package/dist/commands/show.js +132 -0
  18. package/dist/commands/spec.d.ts +15 -0
  19. package/dist/commands/spec.js +225 -0
  20. package/dist/commands/validate.d.ts +24 -0
  21. package/dist/commands/validate.js +294 -0
  22. package/dist/commands/workflow/index.d.ts +17 -0
  23. package/dist/commands/workflow/index.js +12 -0
  24. package/dist/commands/workflow/instructions.d.ts +29 -0
  25. package/dist/commands/workflow/instructions.js +381 -0
  26. package/dist/commands/workflow/new-change.d.ts +11 -0
  27. package/dist/commands/workflow/new-change.js +44 -0
  28. package/dist/commands/workflow/schemas.d.ts +10 -0
  29. package/dist/commands/workflow/schemas.js +34 -0
  30. package/dist/commands/workflow/shared.d.ts +52 -0
  31. package/dist/commands/workflow/shared.js +111 -0
  32. package/dist/commands/workflow/status.d.ts +14 -0
  33. package/dist/commands/workflow/status.js +58 -0
  34. package/dist/commands/workflow/templates.d.ts +16 -0
  35. package/dist/commands/workflow/templates.js +68 -0
  36. package/dist/core/archive.d.ts +11 -0
  37. package/dist/core/archive.js +328 -0
  38. package/dist/core/artifact-graph/graph.d.ts +56 -0
  39. package/dist/core/artifact-graph/graph.js +141 -0
  40. package/dist/core/artifact-graph/index.d.ts +7 -0
  41. package/dist/core/artifact-graph/index.js +13 -0
  42. package/dist/core/artifact-graph/instruction-loader.d.ts +143 -0
  43. package/dist/core/artifact-graph/instruction-loader.js +214 -0
  44. package/dist/core/artifact-graph/resolver.d.ts +81 -0
  45. package/dist/core/artifact-graph/resolver.js +257 -0
  46. package/dist/core/artifact-graph/schema.d.ts +13 -0
  47. package/dist/core/artifact-graph/schema.js +108 -0
  48. package/dist/core/artifact-graph/state.d.ts +12 -0
  49. package/dist/core/artifact-graph/state.js +54 -0
  50. package/dist/core/artifact-graph/types.d.ts +45 -0
  51. package/dist/core/artifact-graph/types.js +43 -0
  52. package/dist/core/command-generation/adapters/amazon-q.d.ts +13 -0
  53. package/dist/core/command-generation/adapters/amazon-q.js +26 -0
  54. package/dist/core/command-generation/adapters/antigravity.d.ts +13 -0
  55. package/dist/core/command-generation/adapters/antigravity.js +26 -0
  56. package/dist/core/command-generation/adapters/auggie.d.ts +13 -0
  57. package/dist/core/command-generation/adapters/auggie.js +27 -0
  58. package/dist/core/command-generation/adapters/claude.d.ts +13 -0
  59. package/dist/core/command-generation/adapters/claude.js +50 -0
  60. package/dist/core/command-generation/adapters/cline.d.ts +14 -0
  61. package/dist/core/command-generation/adapters/cline.js +27 -0
  62. package/dist/core/command-generation/adapters/codebuddy.d.ts +13 -0
  63. package/dist/core/command-generation/adapters/codebuddy.js +28 -0
  64. package/dist/core/command-generation/adapters/codex.d.ts +16 -0
  65. package/dist/core/command-generation/adapters/codex.js +39 -0
  66. package/dist/core/command-generation/adapters/continue.d.ts +13 -0
  67. package/dist/core/command-generation/adapters/continue.js +28 -0
  68. package/dist/core/command-generation/adapters/costrict.d.ts +13 -0
  69. package/dist/core/command-generation/adapters/costrict.js +27 -0
  70. package/dist/core/command-generation/adapters/crush.d.ts +13 -0
  71. package/dist/core/command-generation/adapters/crush.js +30 -0
  72. package/dist/core/command-generation/adapters/cursor.d.ts +14 -0
  73. package/dist/core/command-generation/adapters/cursor.js +44 -0
  74. package/dist/core/command-generation/adapters/devagent.d.ts +15 -0
  75. package/dist/core/command-generation/adapters/devagent.js +28 -0
  76. package/dist/core/command-generation/adapters/factory.d.ts +13 -0
  77. package/dist/core/command-generation/adapters/factory.js +27 -0
  78. package/dist/core/command-generation/adapters/gemini.d.ts +13 -0
  79. package/dist/core/command-generation/adapters/gemini.js +26 -0
  80. package/dist/core/command-generation/adapters/github-copilot.d.ts +13 -0
  81. package/dist/core/command-generation/adapters/github-copilot.js +26 -0
  82. package/dist/core/command-generation/adapters/iflow.d.ts +13 -0
  83. package/dist/core/command-generation/adapters/iflow.js +29 -0
  84. package/dist/core/command-generation/adapters/index.d.ts +28 -0
  85. package/dist/core/command-generation/adapters/index.js +28 -0
  86. package/dist/core/command-generation/adapters/kilocode.d.ts +14 -0
  87. package/dist/core/command-generation/adapters/kilocode.js +23 -0
  88. package/dist/core/command-generation/adapters/opencode.d.ts +13 -0
  89. package/dist/core/command-generation/adapters/opencode.js +29 -0
  90. package/dist/core/command-generation/adapters/qoder.d.ts +13 -0
  91. package/dist/core/command-generation/adapters/qoder.js +30 -0
  92. package/dist/core/command-generation/adapters/qwen.d.ts +13 -0
  93. package/dist/core/command-generation/adapters/qwen.js +26 -0
  94. package/dist/core/command-generation/adapters/roocode.d.ts +14 -0
  95. package/dist/core/command-generation/adapters/roocode.js +27 -0
  96. package/dist/core/command-generation/adapters/windsurf.d.ts +14 -0
  97. package/dist/core/command-generation/adapters/windsurf.js +51 -0
  98. package/dist/core/command-generation/generator.d.ts +21 -0
  99. package/dist/core/command-generation/generator.js +27 -0
  100. package/dist/core/command-generation/index.d.ts +22 -0
  101. package/dist/core/command-generation/index.js +24 -0
  102. package/dist/core/command-generation/registry.d.ts +36 -0
  103. package/dist/core/command-generation/registry.js +90 -0
  104. package/dist/core/command-generation/types.d.ts +56 -0
  105. package/dist/core/command-generation/types.js +8 -0
  106. package/dist/core/completions/command-registry.d.ts +7 -0
  107. package/dist/core/completions/command-registry.js +454 -0
  108. package/dist/core/completions/completion-provider.d.ts +60 -0
  109. package/dist/core/completions/completion-provider.js +102 -0
  110. package/dist/core/completions/factory.d.ts +64 -0
  111. package/dist/core/completions/factory.js +75 -0
  112. package/dist/core/completions/generators/bash-generator.d.ts +32 -0
  113. package/dist/core/completions/generators/bash-generator.js +174 -0
  114. package/dist/core/completions/generators/fish-generator.d.ts +32 -0
  115. package/dist/core/completions/generators/fish-generator.js +157 -0
  116. package/dist/core/completions/generators/powershell-generator.d.ts +33 -0
  117. package/dist/core/completions/generators/powershell-generator.js +207 -0
  118. package/dist/core/completions/generators/zsh-generator.d.ts +44 -0
  119. package/dist/core/completions/generators/zsh-generator.js +250 -0
  120. package/dist/core/completions/installers/bash-installer.d.ts +87 -0
  121. package/dist/core/completions/installers/bash-installer.js +318 -0
  122. package/dist/core/completions/installers/fish-installer.d.ts +43 -0
  123. package/dist/core/completions/installers/fish-installer.js +143 -0
  124. package/dist/core/completions/installers/powershell-installer.d.ts +88 -0
  125. package/dist/core/completions/installers/powershell-installer.js +327 -0
  126. package/dist/core/completions/installers/zsh-installer.d.ts +125 -0
  127. package/dist/core/completions/installers/zsh-installer.js +449 -0
  128. package/dist/core/completions/templates/bash-templates.d.ts +6 -0
  129. package/dist/core/completions/templates/bash-templates.js +24 -0
  130. package/dist/core/completions/templates/fish-templates.d.ts +7 -0
  131. package/dist/core/completions/templates/fish-templates.js +39 -0
  132. package/dist/core/completions/templates/powershell-templates.d.ts +6 -0
  133. package/dist/core/completions/templates/powershell-templates.js +25 -0
  134. package/dist/core/completions/templates/zsh-templates.d.ts +6 -0
  135. package/dist/core/completions/templates/zsh-templates.js +36 -0
  136. package/dist/core/completions/types.d.ts +79 -0
  137. package/dist/core/completions/types.js +2 -0
  138. package/dist/core/config-prompts.d.ts +9 -0
  139. package/dist/core/config-prompts.js +34 -0
  140. package/dist/core/config-schema.d.ts +76 -0
  141. package/dist/core/config-schema.js +200 -0
  142. package/dist/core/config.d.ts +17 -0
  143. package/dist/core/config.js +175 -0
  144. package/dist/core/converters/json-converter.d.ts +6 -0
  145. package/dist/core/converters/json-converter.js +51 -0
  146. package/dist/core/global-config.d.ts +39 -0
  147. package/dist/core/global-config.js +115 -0
  148. package/dist/core/index.d.ts +2 -0
  149. package/dist/core/index.js +3 -0
  150. package/dist/core/init.d.ts +32 -0
  151. package/dist/core/init.js +447 -0
  152. package/dist/core/legacy-cleanup.d.ts +162 -0
  153. package/dist/core/legacy-cleanup.js +520 -0
  154. package/dist/core/list.d.ts +9 -0
  155. package/dist/core/list.js +171 -0
  156. package/dist/core/parsers/change-parser.d.ts +13 -0
  157. package/dist/core/parsers/change-parser.js +193 -0
  158. package/dist/core/parsers/markdown-parser.d.ts +22 -0
  159. package/dist/core/parsers/markdown-parser.js +187 -0
  160. package/dist/core/parsers/requirement-blocks.d.ts +37 -0
  161. package/dist/core/parsers/requirement-blocks.js +201 -0
  162. package/dist/core/project-config.d.ts +64 -0
  163. package/dist/core/project-config.js +223 -0
  164. package/dist/core/schemas/base.schema.d.ts +13 -0
  165. package/dist/core/schemas/base.schema.js +13 -0
  166. package/dist/core/schemas/change.schema.d.ts +73 -0
  167. package/dist/core/schemas/change.schema.js +31 -0
  168. package/dist/core/schemas/index.d.ts +4 -0
  169. package/dist/core/schemas/index.js +4 -0
  170. package/dist/core/schemas/spec.schema.d.ts +18 -0
  171. package/dist/core/schemas/spec.schema.js +15 -0
  172. package/dist/core/shared/index.d.ts +8 -0
  173. package/dist/core/shared/index.js +8 -0
  174. package/dist/core/shared/skill-generation.d.ts +42 -0
  175. package/dist/core/shared/skill-generation.js +80 -0
  176. package/dist/core/shared/tool-detection.d.ts +66 -0
  177. package/dist/core/shared/tool-detection.js +140 -0
  178. package/dist/core/specs-apply.d.ts +73 -0
  179. package/dist/core/specs-apply.js +384 -0
  180. package/dist/core/styles/palette.d.ts +7 -0
  181. package/dist/core/styles/palette.js +8 -0
  182. package/dist/core/templates/index.d.ts +8 -0
  183. package/dist/core/templates/index.js +9 -0
  184. package/dist/core/templates/skill-templates.d.ts +122 -0
  185. package/dist/core/templates/skill-templates.js +3437 -0
  186. package/dist/core/update.d.ts +42 -0
  187. package/dist/core/update.js +311 -0
  188. package/dist/core/validation/constants.d.ts +34 -0
  189. package/dist/core/validation/constants.js +40 -0
  190. package/dist/core/validation/types.d.ts +18 -0
  191. package/dist/core/validation/types.js +2 -0
  192. package/dist/core/validation/validator.d.ts +33 -0
  193. package/dist/core/validation/validator.js +409 -0
  194. package/dist/core/view.d.ts +8 -0
  195. package/dist/core/view.js +168 -0
  196. package/dist/index.d.ts +3 -0
  197. package/dist/index.js +3 -0
  198. package/dist/prompts/searchable-multi-select.d.ts +27 -0
  199. package/dist/prompts/searchable-multi-select.js +149 -0
  200. package/dist/telemetry/config.d.ts +32 -0
  201. package/dist/telemetry/config.js +68 -0
  202. package/dist/telemetry/index.d.ts +31 -0
  203. package/dist/telemetry/index.js +145 -0
  204. package/dist/ui/ascii-patterns.d.ts +16 -0
  205. package/dist/ui/ascii-patterns.js +133 -0
  206. package/dist/ui/welcome-screen.d.ts +10 -0
  207. package/dist/ui/welcome-screen.js +146 -0
  208. package/dist/utils/change-metadata.d.ts +51 -0
  209. package/dist/utils/change-metadata.js +147 -0
  210. package/dist/utils/change-utils.d.ts +62 -0
  211. package/dist/utils/change-utils.js +121 -0
  212. package/dist/utils/command-references.d.ts +18 -0
  213. package/dist/utils/command-references.js +20 -0
  214. package/dist/utils/file-system.d.ts +36 -0
  215. package/dist/utils/file-system.js +281 -0
  216. package/dist/utils/index.d.ts +6 -0
  217. package/dist/utils/index.js +9 -0
  218. package/dist/utils/interactive.d.ts +18 -0
  219. package/dist/utils/interactive.js +21 -0
  220. package/dist/utils/item-discovery.d.ts +4 -0
  221. package/dist/utils/item-discovery.js +72 -0
  222. package/dist/utils/match.d.ts +3 -0
  223. package/dist/utils/match.js +22 -0
  224. package/dist/utils/shell-detection.d.ts +20 -0
  225. package/dist/utils/shell-detection.js +41 -0
  226. package/dist/utils/task-progress.d.ts +8 -0
  227. package/dist/utils/task-progress.js +36 -0
  228. package/package.json +83 -0
  229. package/schemas/spec-driven/schema.yaml +151 -0
  230. package/schemas/spec-driven/templates/design.md +21 -0
  231. package/schemas/spec-driven/templates/proposal.md +25 -0
  232. package/schemas/spec-driven/templates/spec.md +10 -0
  233. package/schemas/spec-driven/templates/tasks.md +9 -0
  234. package/scripts/postinstall.js +147 -0
@@ -0,0 +1,3437 @@
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: "进入探索模式:作为思考伙伴梳理想法、排查问题、澄清需求。适用于用户在确定或进行变更前先理清思路时。",
18
+ instructions: `Enter explore mode. Think deeply. Visualize freely. Follow the conversation wherever it goes.
19
+
20
+ **IMPORTANT: Explore mode is for thinking, not implementing.** You may read files, search code, and investigate the codebase, but you must NEVER write code or implement features. If the user asks you to implement something, remind them to exit explore mode first (e.g., start a change with \`/opsx:new\` or \`/opsx:ff\`). You MAY create OpenSpec artifacts (proposals, designs, specs) if the user asks—that's capturing thinking, not implementing.
21
+
22
+ **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.
23
+
24
+ ---
25
+
26
+ ## The Stance
27
+
28
+ - **Curious, not prescriptive** - Ask questions that emerge naturally, don't follow a script
29
+ - **Open threads, not interrogations** - Surface multiple interesting directions and let the user follow what resonates. Don't funnel them through a single path of questions.
30
+ - **Visual** - Use ASCII diagrams liberally when they'd help clarify thinking
31
+ - **Adaptive** - Follow interesting threads, pivot when new information emerges
32
+ - **Patient** - Don't rush to conclusions, let the shape of the problem emerge
33
+ - **Grounded** - Explore the actual codebase when relevant, don't just theorize
34
+
35
+ ---
36
+
37
+ ## What You Might Do
38
+
39
+ Depending on what the user brings, you might:
40
+
41
+ **Explore the problem space**
42
+ - Ask clarifying questions that emerge from what they said
43
+ - Challenge assumptions
44
+ - Reframe the problem
45
+ - Find analogies
46
+
47
+ **Investigate the codebase**
48
+ - Map existing architecture relevant to the discussion
49
+ - Find integration points
50
+ - Identify patterns already in use
51
+ - Surface hidden complexity
52
+
53
+ **Compare options**
54
+ - Brainstorm multiple approaches
55
+ - Build comparison tables
56
+ - Sketch tradeoffs
57
+ - Recommend a path (if asked)
58
+
59
+ **Visualize**
60
+ \`\`\`
61
+ ┌─────────────────────────────────────────┐
62
+ │ Use ASCII diagrams liberally │
63
+ ├─────────────────────────────────────────┤
64
+ │ │
65
+ │ ┌────────┐ ┌────────┐ │
66
+ │ │ State │────────▶│ State │ │
67
+ │ │ A │ │ B │ │
68
+ │ └────────┘ └────────┘ │
69
+ │ │
70
+ │ System diagrams, state machines, │
71
+ │ data flows, architecture sketches, │
72
+ │ dependency graphs, comparison tables │
73
+ │ │
74
+ └─────────────────────────────────────────┘
75
+ \`\`\`
76
+
77
+ **Surface risks and unknowns**
78
+ - Identify what could go wrong
79
+ - Find gaps in understanding
80
+ - Suggest spikes or investigations
81
+
82
+ ---
83
+
84
+ ## OpenSpec Awareness
85
+
86
+ You have full context of the OpenSpec system. Use it naturally, don't force it.
87
+
88
+ ### Check for context
89
+
90
+ At the start, quickly check what exists:
91
+ \`\`\`bash
92
+ openspec list --json
93
+ \`\`\`
94
+
95
+ This tells you:
96
+ - If there are active changes
97
+ - Their names, schemas, and status
98
+ - What the user might be working on
99
+
100
+ ### When no change exists
101
+
102
+ Think freely. When insights crystallize, you might offer:
103
+
104
+ - "This feels solid enough to start a change. Want me to create one?"
105
+ → Can transition to \`/opsx:new\` or \`/opsx:ff\`
106
+ - Or keep exploring - no pressure to formalize
107
+
108
+ ### When a change exists
109
+
110
+ If the user mentions a change or you detect one is relevant:
111
+
112
+ 1. **Read existing artifacts for context**
113
+ - \`openspec/changes/<name>/proposal.md\`
114
+ - \`openspec/changes/<name>/design.md\`
115
+ - \`openspec/changes/<name>/tasks.md\`
116
+ - etc.
117
+
118
+ 2. **Reference them naturally in conversation**
119
+ - "Your design mentions using Redis, but we just realized SQLite fits better..."
120
+ - "The proposal scopes this to premium users, but we're now thinking everyone..."
121
+
122
+ 3. **Offer to capture when decisions are made**
123
+
124
+ | Insight Type | Where to Capture |
125
+ |--------------|------------------|
126
+ | New requirement discovered | \`specs/<capability>/spec.md\` |
127
+ | Requirement changed | \`specs/<capability>/spec.md\` |
128
+ | Design decision made | \`design.md\` |
129
+ | Scope changed | \`proposal.md\` |
130
+ | New work identified | \`tasks.md\` |
131
+ | Assumption invalidated | Relevant artifact |
132
+
133
+ Example offers:
134
+ - "That's a design decision. Capture it in design.md?"
135
+ - "This is a new requirement. Add it to specs?"
136
+ - "This changes scope. Update the proposal?"
137
+
138
+ 4. **The user decides** - Offer and move on. Don't pressure. Don't auto-capture.
139
+
140
+ ---
141
+
142
+ ## What You Don't Have To Do
143
+
144
+ - Follow a script
145
+ - Ask the same questions every time
146
+ - Produce a specific artifact
147
+ - Reach a conclusion
148
+ - Stay on topic if a tangent is valuable
149
+ - Be brief (this is thinking time)
150
+
151
+ ---
152
+
153
+ ## Handling Different Entry Points
154
+
155
+ **User brings a vague idea:**
156
+ \`\`\`
157
+ User: I'm thinking about adding real-time collaboration
158
+
159
+ You: Real-time collab is a big space. Let me think about this...
160
+
161
+ COLLABORATION SPECTRUM
162
+ ════════════════════════════════════════════
163
+
164
+ Awareness Coordination Sync
165
+ │ │ │
166
+ ▼ ▼ ▼
167
+ ┌────────┐ ┌────────┐ ┌────────┐
168
+ │Presence│ │Cursors │ │ CRDT │
169
+ │ "3 │ │ Multi │ │Conflict│
170
+ │online" │ │ select │ │ free │
171
+ └────────┘ └────────┘ └────────┘
172
+ │ │ │
173
+ trivial moderate complex
174
+
175
+ Where's your head at?
176
+ \`\`\`
177
+
178
+ **User brings a specific problem:**
179
+ \`\`\`
180
+ User: The auth system is a mess
181
+
182
+ You: [reads codebase]
183
+
184
+ ┌─────────────────────────────────────────────┐
185
+ │ CURRENT AUTH FLOW │
186
+ └─────────────────────────────────────────────┘
187
+
188
+ ┌─────────────┼─────────────┐
189
+ ▼ ▼ ▼
190
+ ┌─────────┐ ┌─────────┐ ┌─────────┐
191
+ │ Google │ │ GitHub │ │ Email │
192
+ │ OAuth │ │ OAuth │ │ Magic │
193
+ └────┬────┘ └────┬────┘ └────┬────┘
194
+ │ │ │
195
+ └─────────────┼─────────────┘
196
+
197
+ ┌───────────┐
198
+ │ Session │
199
+ └─────┬─────┘
200
+
201
+
202
+ ┌───────────┐
203
+ │ Perms │
204
+ └───────────┘
205
+
206
+ I see three tangles. Which one's burning?
207
+ \`\`\`
208
+
209
+ **User is stuck mid-implementation:**
210
+ \`\`\`
211
+ User: /opsx:explore add-auth-system
212
+ The OAuth integration is more complex than expected
213
+
214
+ You: [reads change artifacts]
215
+
216
+ You're on task 4: "Implement OAuth flow"
217
+
218
+ Let me trace what's involved...
219
+
220
+ [draws diagram, explores options, suggests paths]
221
+
222
+ Want to update the design to reflect this?
223
+ Or add a spike task to investigate?
224
+ \`\`\`
225
+
226
+ **User wants to compare options:**
227
+ \`\`\`
228
+ User: Should we use Postgres or SQLite?
229
+
230
+ You: Generic answer is boring. What's the context?
231
+
232
+ User: A CLI tool that tracks local dev environments
233
+
234
+ You: That changes everything.
235
+
236
+ ┌─────────────────────────────────────────────────┐
237
+ │ CLI TOOL DATA STORAGE │
238
+ └─────────────────────────────────────────────────┘
239
+
240
+ Key constraints:
241
+ • No daemon running
242
+ • Must work offline
243
+ • Single user
244
+
245
+ SQLite Postgres
246
+ Deployment embedded ✓ needs server ✗
247
+ Offline yes ✓ no ✗
248
+ Single file yes ✓ no ✗
249
+
250
+ SQLite. Not even close.
251
+
252
+ Unless... is there a sync component?
253
+ \`\`\`
254
+
255
+ ---
256
+
257
+ ## Ending Discovery
258
+
259
+ There's no required ending. Discovery might:
260
+
261
+ - **Flow into action**: "Ready to start? /opsx:new or /opsx:ff"
262
+ - **Result in artifact updates**: "Updated design.md with these decisions"
263
+ - **Just provide clarity**: User has what they need, moves on
264
+ - **Continue later**: "We can pick this up anytime"
265
+
266
+ When it feels like things are crystallizing, you might summarize:
267
+
268
+ \`\`\`
269
+ ## What We Figured Out
270
+
271
+ **The problem**: [crystallized understanding]
272
+
273
+ **The approach**: [if one emerged]
274
+
275
+ **Open questions**: [if any remain]
276
+
277
+ **Next steps** (if ready):
278
+ - Create a change: /opsx:new <name>
279
+ - Fast-forward to tasks: /opsx:ff <name>
280
+ - Keep exploring: just keep talking
281
+ \`\`\`
282
+
283
+ But this summary is optional. Sometimes the thinking IS the value.
284
+
285
+ ---
286
+
287
+ ## Guardrails
288
+
289
+ - **Don't implement** - Never write code or implement features. Creating OpenSpec artifacts is fine, writing application code is not.
290
+ - **Don't fake understanding** - If something is unclear, dig deeper
291
+ - **Don't rush** - Discovery is thinking time, not task time
292
+ - **Don't force structure** - Let patterns emerge naturally
293
+ - **Don't auto-capture** - Offer to save insights, don't just do it
294
+ - **Do visualize** - A good diagram is worth many paragraphs
295
+ - **Do explore the codebase** - Ground discussions in reality
296
+ - **Do question assumptions** - Including the user's and your own`,
297
+ license: "MIT",
298
+ compatibility: "Requires openspec CLI.",
299
+ metadata: { author: "openspec", version: "1.0" },
300
+ };
301
+ }
302
+ /**
303
+ * Template for openspec-new-change skill
304
+ * Based on /opsx:new command
305
+ */
306
+ export function getNewChangeSkillTemplate() {
307
+ return {
308
+ name: "openspec-new-change",
309
+ description: "新建 OpenSpec 变更(制品工作流)。适用于用户想按步骤创建新功能、修复或改动时。",
310
+ instructions: `Start a new change using the experimental artifact-driven approach.
311
+
312
+ **Input**: The user's request should include a change name (kebab-case) OR a description of what they want to build.
313
+
314
+ **Steps**
315
+
316
+ 1. **If no clear input provided, ask what they want to build**
317
+
318
+ Use the **AskUserQuestion tool** (open-ended, no preset options) to ask:
319
+ > "What change do you want to work on? Describe what you want to build or fix."
320
+
321
+ From their description, derive a kebab-case name (e.g., "add user authentication" → \`add-user-auth\`).
322
+
323
+ **IMPORTANT**: Do NOT proceed without understanding what the user wants to build.
324
+
325
+ 2. **Determine the workflow schema**
326
+
327
+ Use the default schema (omit \`--schema\`) unless the user explicitly requests a different workflow.
328
+
329
+ **Use a different schema only if the user mentions:**
330
+ - A specific schema name → use \`--schema <name>\`
331
+ - "show workflows" or "what workflows" → run \`openspec schemas --json\` and let them choose
332
+
333
+ **Otherwise**: Omit \`--schema\` to use the default.
334
+
335
+ 3. **Create the change directory**
336
+ \`\`\`bash
337
+ openspec new change "<name>"
338
+ \`\`\`
339
+ Add \`--schema <name>\` only if the user requested a specific workflow.
340
+ This creates a scaffolded change at \`openspec/changes/<name>/\` with the selected schema.
341
+
342
+ 4. **Show the artifact status**
343
+ \`\`\`bash
344
+ openspec status --change "<name>"
345
+ \`\`\`
346
+ This shows which artifacts need to be created and which are ready (dependencies satisfied).
347
+
348
+ 5. **Get instructions for the first artifact**
349
+ The first artifact depends on the schema (e.g., \`proposal\` for spec-driven).
350
+ Check the status output to find the first artifact with status "ready".
351
+ \`\`\`bash
352
+ openspec instructions <first-artifact-id> --change "<name>"
353
+ \`\`\`
354
+ This outputs the template and context for creating the first artifact.
355
+
356
+ 6. **STOP and wait for user direction**
357
+
358
+ **Output**
359
+
360
+ After completing the steps, summarize:
361
+ - Change name and location
362
+ - Schema/workflow being used and its artifact sequence
363
+ - Current status (0/N artifacts complete)
364
+ - The template for the first artifact
365
+ - Prompt: "Ready to create the first artifact? Just describe what this change is about and I'll draft it, or ask me to continue."
366
+
367
+ **Guardrails**
368
+ - Do NOT create any artifacts yet - just show the instructions
369
+ - Do NOT advance beyond showing the first artifact template
370
+ - If the name is invalid (not kebab-case), ask for a valid name
371
+ - If a change with that name already exists, suggest continuing that change instead
372
+ - Pass --schema if using a non-default workflow`,
373
+ license: "MIT",
374
+ compatibility: "Requires openspec CLI.",
375
+ metadata: { author: "openspec", version: "1.0" },
376
+ };
377
+ }
378
+ /**
379
+ * Template for openspec-continue-change skill
380
+ * Based on /opsx:continue command
381
+ */
382
+ export function getContinueChangeSkillTemplate() {
383
+ return {
384
+ name: "openspec-continue-change",
385
+ description: "继续当前变更:创建下一个制品。适用于用户想推进变更、创建下一份制品或继续工作流时。",
386
+ instructions: `Continue working on a change by creating the next artifact.
387
+
388
+ **Input**: Optionally specify a change name. If omitted, check if it can be inferred from conversation context. If vague or ambiguous you MUST prompt for available changes.
389
+
390
+ **Steps**
391
+
392
+ 1. **If no change name provided, prompt for selection**
393
+
394
+ 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.
395
+
396
+ Present the top 3-4 most recently modified changes as options, showing:
397
+ - Change name
398
+ - Schema (from \`schema\` field if present, otherwise "spec-driven")
399
+ - Status (e.g., "0/5 tasks", "complete", "no tasks")
400
+ - How recently it was modified (from \`lastModified\` field)
401
+
402
+ Mark the most recently modified change as "(Recommended)" since it's likely what the user wants to continue.
403
+
404
+ **IMPORTANT**: Do NOT guess or auto-select a change. Always let the user choose.
405
+
406
+ 2. **Check current status**
407
+ \`\`\`bash
408
+ openspec status --change "<name>" --json
409
+ \`\`\`
410
+ Parse the JSON to understand current state. The response includes:
411
+ - \`schemaName\`: The workflow schema being used (e.g., "spec-driven")
412
+ - \`artifacts\`: Array of artifacts with their status ("done", "ready", "blocked")
413
+ - \`isComplete\`: Boolean indicating if all artifacts are complete
414
+
415
+ 3. **Act based on status**:
416
+
417
+ ---
418
+
419
+ **If all artifacts are complete (\`isComplete: true\`)**:
420
+ - Congratulate the user
421
+ - Show final status including the schema used
422
+ - Suggest: "All artifacts created! You can now implement this change or archive it."
423
+ - STOP
424
+
425
+ ---
426
+
427
+ **If artifacts are ready to create** (status shows artifacts with \`status: "ready"\`):
428
+ - Pick the FIRST artifact with \`status: "ready"\` from the status output
429
+ - Get its instructions:
430
+ \`\`\`bash
431
+ openspec instructions <artifact-id> --change "<name>" --json
432
+ \`\`\`
433
+ - Parse the JSON. The key fields are:
434
+ - \`context\`: Project background (constraints for you - do NOT include in output)
435
+ - \`rules\`: Artifact-specific rules (constraints for you - do NOT include in output)
436
+ - \`template\`: The structure to use for your output file
437
+ - \`instruction\`: Schema-specific guidance
438
+ - \`outputPath\`: Where to write the artifact
439
+ - \`dependencies\`: Completed artifacts to read for context
440
+ - **Create the artifact file**:
441
+ - Read any completed dependency files for context
442
+ - Use \`template\` as the structure - fill in its sections
443
+ - Apply \`context\` and \`rules\` as constraints when writing - but do NOT copy them into the file
444
+ - Write to the output path specified in instructions
445
+ - Show what was created and what's now unlocked
446
+ - STOP after creating ONE artifact
447
+
448
+ ---
449
+
450
+ **If no artifacts are ready (all blocked)**:
451
+ - This shouldn't happen with a valid schema
452
+ - Show status and suggest checking for issues
453
+
454
+ 4. **After creating an artifact, show progress**
455
+ \`\`\`bash
456
+ openspec status --change "<name>"
457
+ \`\`\`
458
+
459
+ **Output**
460
+
461
+ After each invocation, show:
462
+ - Which artifact was created
463
+ - Schema workflow being used
464
+ - Current progress (N/M complete)
465
+ - What artifacts are now unlocked
466
+ - Prompt: "Want to continue? Just ask me to continue or tell me what to do next."
467
+
468
+ **Artifact Creation Guidelines**
469
+
470
+ The artifact types and their purpose depend on the schema. Use the \`instruction\` field from the instructions output to understand what to create.
471
+
472
+ Common artifact patterns:
473
+
474
+ **spec-driven schema** (proposal → specs → design → tasks):
475
+ - **proposal.md**: Ask user about the change if not clear. Fill in Why, What Changes, Capabilities, Impact.
476
+ - The Capabilities section is critical - each capability listed will need a spec file.
477
+ - **specs/<capability>/spec.md**: Create one spec per capability listed in the proposal's Capabilities section (use the capability name, not the change name).
478
+ - **design.md**: Document technical decisions, architecture, and implementation approach.
479
+ - **tasks.md**: Break down implementation into checkboxed tasks.
480
+
481
+ For other schemas, follow the \`instruction\` field from the CLI output.
482
+
483
+ **Guardrails**
484
+ - Create ONE artifact per invocation
485
+ - Always read dependency artifacts before creating a new one
486
+ - Never skip artifacts or create out of order
487
+ - If context is unclear, ask the user before creating
488
+ - Verify the artifact file exists after writing before marking progress
489
+ - Use the schema's artifact sequence, don't assume specific artifact names
490
+ - **IMPORTANT**: \`context\` and \`rules\` are constraints for YOU, not content for the file
491
+ - Do NOT copy \`<context>\`, \`<rules>\`, \`<project_context>\` blocks into the artifact
492
+ - These guide what you write, but should never appear in the output`,
493
+ license: "MIT",
494
+ compatibility: "Requires openspec CLI.",
495
+ metadata: { author: "openspec", version: "1.0" },
496
+ };
497
+ }
498
+ /**
499
+ * Template for openspec-apply-change skill
500
+ * For implementing tasks from a completed (or in-progress) change
501
+ */
502
+ export function getApplyChangeSkillTemplate() {
503
+ return {
504
+ name: "openspec-apply-change",
505
+ description: "按变更实施任务。适用于用户要开始实现、继续实现或逐项完成任务时。",
506
+ instructions: `Implement tasks from an OpenSpec change.
507
+
508
+ **Input**: Optionally specify a change name. If omitted, check if it can be inferred from conversation context. If vague or ambiguous you MUST prompt for available changes.
509
+
510
+ **Steps**
511
+
512
+ 1. **Select the change**
513
+
514
+ If a name is provided, use it. Otherwise:
515
+ - Infer from conversation context if the user mentioned a change
516
+ - Auto-select if only one active change exists
517
+ - If ambiguous, run \`openspec list --json\` to get available changes and use the **AskUserQuestion tool** to let the user select
518
+
519
+ Always announce: "Using change: <name>" and how to override (e.g., \`/opsx:apply <other>\`).
520
+
521
+ 2. **Check status to understand the schema**
522
+ \`\`\`bash
523
+ openspec status --change "<name>" --json
524
+ \`\`\`
525
+ Parse the JSON to understand:
526
+ - \`schemaName\`: The workflow being used (e.g., "spec-driven")
527
+ - Which artifact contains the tasks (typically "tasks" for spec-driven, check status for others)
528
+
529
+ 3. **Get apply instructions**
530
+
531
+ \`\`\`bash
532
+ openspec instructions apply --change "<name>" --json
533
+ \`\`\`
534
+
535
+ This returns:
536
+ - Context file paths (varies by schema - could be proposal/specs/design/tasks or spec/tests/implementation/docs)
537
+ - Progress (total, complete, remaining)
538
+ - Task list with status
539
+ - Dynamic instruction based on current state
540
+
541
+ **Handle states:**
542
+ - If \`state: "blocked"\` (missing artifacts): show message, suggest using openspec-continue-change
543
+ - If \`state: "all_done"\`: congratulate, suggest archive
544
+ - Otherwise: proceed to implementation
545
+
546
+ 4. **Read context files**
547
+
548
+ Read the files listed in \`contextFiles\` from the apply instructions output.
549
+ The files depend on the schema being used:
550
+ - **spec-driven**: proposal, specs, design, tasks
551
+ - Other schemas: follow the contextFiles from CLI output
552
+
553
+ 5. **Show current progress**
554
+
555
+ Display:
556
+ - Schema being used
557
+ - Progress: "N/M tasks complete"
558
+ - Remaining tasks overview
559
+ - Dynamic instruction from CLI
560
+
561
+ 6. **Implement tasks (loop until done or blocked)**
562
+
563
+ For each pending task:
564
+ - Show which task is being worked on
565
+ - Make the code changes required
566
+ - Keep changes minimal and focused
567
+ - Mark task complete in the tasks file: \`- [ ]\` → \`- [x]\`
568
+ - Continue to next task
569
+
570
+ **Pause if:**
571
+ - Task is unclear → ask for clarification
572
+ - Implementation reveals a design issue → suggest updating artifacts
573
+ - Error or blocker encountered → report and wait for guidance
574
+ - User interrupts
575
+
576
+ 7. **On completion or pause, show status**
577
+
578
+ Display:
579
+ - Tasks completed this session
580
+ - Overall progress: "N/M tasks complete"
581
+ - If all done: suggest archive
582
+ - If paused: explain why and wait for guidance
583
+
584
+ **Output During Implementation**
585
+
586
+ \`\`\`
587
+ ## Implementing: <change-name> (schema: <schema-name>)
588
+
589
+ Working on task 3/7: <task description>
590
+ [...implementation happening...]
591
+ ✓ Task complete
592
+
593
+ Working on task 4/7: <task description>
594
+ [...implementation happening...]
595
+ ✓ Task complete
596
+ \`\`\`
597
+
598
+ **Output On Completion**
599
+
600
+ \`\`\`
601
+ ## Implementation Complete
602
+
603
+ **Change:** <change-name>
604
+ **Schema:** <schema-name>
605
+ **Progress:** 7/7 tasks complete ✓
606
+
607
+ ### Completed This Session
608
+ - [x] Task 1
609
+ - [x] Task 2
610
+ ...
611
+
612
+ All tasks complete! Ready to archive this change.
613
+ \`\`\`
614
+
615
+ **Output On Pause (Issue Encountered)**
616
+
617
+ \`\`\`
618
+ ## Implementation Paused
619
+
620
+ **Change:** <change-name>
621
+ **Schema:** <schema-name>
622
+ **Progress:** 4/7 tasks complete
623
+
624
+ ### Issue Encountered
625
+ <description of the issue>
626
+
627
+ **Options:**
628
+ 1. <option 1>
629
+ 2. <option 2>
630
+ 3. Other approach
631
+
632
+ What would you like to do?
633
+ \`\`\`
634
+
635
+ **Guardrails**
636
+ - Keep going through tasks until done or blocked
637
+ - Always read context files before starting (from the apply instructions output)
638
+ - If task is ambiguous, pause and ask before implementing
639
+ - If implementation reveals issues, pause and suggest artifact updates
640
+ - Keep code changes minimal and scoped to each task
641
+ - Update task checkbox immediately after completing each task
642
+ - Pause on errors, blockers, or unclear requirements - don't guess
643
+ - Use contextFiles from CLI output, don't assume specific file names
644
+
645
+ **Fluid Workflow Integration**
646
+
647
+ This skill supports the "actions on a change" model:
648
+
649
+ - **Can be invoked anytime**: Before all artifacts are done (if tasks exist), after partial implementation, interleaved with other actions
650
+ - **Allows artifact updates**: If implementation reveals design issues, suggest updating artifacts - not phase-locked, work fluidly`,
651
+ license: "MIT",
652
+ compatibility: "Requires openspec CLI.",
653
+ metadata: { author: "openspec", version: "1.0" },
654
+ };
655
+ }
656
+ /**
657
+ * Template for openspec-ff-change skill
658
+ * Fast-forward through artifact creation
659
+ */
660
+ export function getFfChangeSkillTemplate() {
661
+ return {
662
+ name: "openspec-ff-change",
663
+ description: "快进式创建 OpenSpec 制品。适用于用户想一次性生成实施所需全部制品时。",
664
+ instructions: `Fast-forward through artifact creation - generate everything needed to start implementation in one go.
665
+
666
+ **Input**: The user's request should include a change name (kebab-case) OR a description of what they want to build.
667
+
668
+ **Steps**
669
+
670
+ 1. **If no clear input provided, ask what they want to build**
671
+
672
+ Use the **AskUserQuestion tool** (open-ended, no preset options) to ask:
673
+ > "What change do you want to work on? Describe what you want to build or fix."
674
+
675
+ From their description, derive a kebab-case name (e.g., "add user authentication" → \`add-user-auth\`).
676
+
677
+ **IMPORTANT**: Do NOT proceed without understanding what the user wants to build.
678
+
679
+ 2. **Create the change directory**
680
+ \`\`\`bash
681
+ openspec new change "<name>"
682
+ \`\`\`
683
+ This creates a scaffolded change at \`openspec/changes/<name>/\`.
684
+
685
+ 3. **Get the artifact build order**
686
+ \`\`\`bash
687
+ openspec status --change "<name>" --json
688
+ \`\`\`
689
+ Parse the JSON to get:
690
+ - \`applyRequires\`: array of artifact IDs needed before implementation (e.g., \`["tasks"]\`)
691
+ - \`artifacts\`: list of all artifacts with their status and dependencies
692
+
693
+ 4. **Create artifacts in sequence until apply-ready**
694
+
695
+ Use the **TodoWrite tool** to track progress through the artifacts.
696
+
697
+ Loop through artifacts in dependency order (artifacts with no pending dependencies first):
698
+
699
+ a. **For each artifact that is \`ready\` (dependencies satisfied)**:
700
+ - Get instructions:
701
+ \`\`\`bash
702
+ openspec instructions <artifact-id> --change "<name>" --json
703
+ \`\`\`
704
+ - The instructions JSON includes:
705
+ - \`context\`: Project background (constraints for you - do NOT include in output)
706
+ - \`rules\`: Artifact-specific rules (constraints for you - do NOT include in output)
707
+ - \`template\`: The structure to use for your output file
708
+ - \`instruction\`: Schema-specific guidance for this artifact type
709
+ - \`outputPath\`: Where to write the artifact
710
+ - \`dependencies\`: Completed artifacts to read for context
711
+ - Read any completed dependency files for context
712
+ - Create the artifact file using \`template\` as the structure
713
+ - Apply \`context\` and \`rules\` as constraints - but do NOT copy them into the file
714
+ - Show brief progress: "✓ Created <artifact-id>"
715
+
716
+ b. **Continue until all \`applyRequires\` artifacts are complete**
717
+ - After creating each artifact, re-run \`openspec status --change "<name>" --json\`
718
+ - Check if every artifact ID in \`applyRequires\` has \`status: "done"\` in the artifacts array
719
+ - Stop when all \`applyRequires\` artifacts are done
720
+
721
+ c. **If an artifact requires user input** (unclear context):
722
+ - Use **AskUserQuestion tool** to clarify
723
+ - Then continue with creation
724
+
725
+ 5. **Show final status**
726
+ \`\`\`bash
727
+ openspec status --change "<name>"
728
+ \`\`\`
729
+
730
+ **Output**
731
+
732
+ After completing all artifacts, summarize:
733
+ - Change name and location
734
+ - List of artifacts created with brief descriptions
735
+ - What's ready: "All artifacts created! Ready for implementation."
736
+ - Prompt: "Run \`/opsx:apply\` or ask me to implement to start working on the tasks."
737
+
738
+ **Artifact Creation Guidelines**
739
+
740
+ - Follow the \`instruction\` field from \`openspec instructions\` for each artifact type
741
+ - The schema defines what each artifact should contain - follow it
742
+ - Read dependency artifacts for context before creating new ones
743
+ - Use \`template\` as the structure for your output file - fill in its sections
744
+ - **IMPORTANT**: \`context\` and \`rules\` are constraints for YOU, not content for the file
745
+ - Do NOT copy \`<context>\`, \`<rules>\`, \`<project_context>\` blocks into the artifact
746
+ - These guide what you write, but should never appear in the output
747
+
748
+ **Guardrails**
749
+ - Create ALL artifacts needed for implementation (as defined by schema's \`apply.requires\`)
750
+ - Always read dependency artifacts before creating a new one
751
+ - If context is critically unclear, ask the user - but prefer making reasonable decisions to keep momentum
752
+ - If a change with that name already exists, suggest continuing that change instead
753
+ - Verify each artifact file exists after writing before proceeding to next`,
754
+ license: "MIT",
755
+ compatibility: "Requires openspec CLI.",
756
+ metadata: { author: "openspec", version: "1.0" },
757
+ };
758
+ }
759
+ /**
760
+ * Template for openspec-sync-specs skill
761
+ * For syncing delta specs from a change to main specs (agent-driven)
762
+ */
763
+ export function getSyncSpecsSkillTemplate() {
764
+ return {
765
+ name: "openspec-sync-specs",
766
+ description: "将变更中的增量规范同步到主规范。适用于用户想更新主规范但暂不归档变更时。",
767
+ instructions: `Sync delta specs from a change to main specs.
768
+
769
+ 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).
770
+
771
+ **Input**: Optionally specify a change name. If omitted, check if it can be inferred from conversation context. If vague or ambiguous you MUST prompt for available changes.
772
+
773
+ **Steps**
774
+
775
+ 1. **If no change name provided, prompt for selection**
776
+
777
+ Run \`openspec list --json\` to get available changes. Use the **AskUserQuestion tool** to let the user select.
778
+
779
+ Show changes that have delta specs (under \`specs/\` directory).
780
+
781
+ **IMPORTANT**: Do NOT guess or auto-select a change. Always let the user choose.
782
+
783
+ 2. **Find delta specs**
784
+
785
+ Look for delta spec files in \`openspec/changes/<name>/specs/*/spec.md\`.
786
+
787
+ Each delta spec file contains sections like:
788
+ - \`## ADDED Requirements\` - New requirements to add
789
+ - \`## MODIFIED Requirements\` - Changes to existing requirements
790
+ - \`## REMOVED Requirements\` - Requirements to remove
791
+ - \`## RENAMED Requirements\` - Requirements to rename (FROM:/TO: format)
792
+
793
+ If no delta specs found, inform user and stop.
794
+
795
+ 3. **For each delta spec, apply changes to main specs**
796
+
797
+ For each capability with a delta spec at \`openspec/changes/<name>/specs/<capability>/spec.md\`:
798
+
799
+ a. **Read the delta spec** to understand the intended changes
800
+
801
+ b. **Read the main spec** at \`openspec/specs/<capability>/spec.md\` (may not exist yet)
802
+
803
+ c. **Apply changes intelligently**:
804
+
805
+ **ADDED Requirements:**
806
+ - If requirement doesn't exist in main spec → add it
807
+ - If requirement already exists → update it to match (treat as implicit MODIFIED)
808
+
809
+ **MODIFIED Requirements:**
810
+ - Find the requirement in main spec
811
+ - Apply the changes - this can be:
812
+ - Adding new scenarios (don't need to copy existing ones)
813
+ - Modifying existing scenarios
814
+ - Changing the requirement description
815
+ - Preserve scenarios/content not mentioned in the delta
816
+
817
+ **REMOVED Requirements:**
818
+ - Remove the entire requirement block from main spec
819
+
820
+ **RENAMED Requirements:**
821
+ - Find the FROM requirement, rename to TO
822
+
823
+ d. **Create new main spec** if capability doesn't exist yet:
824
+ - Create \`openspec/specs/<capability>/spec.md\`
825
+ - Add Purpose section (can be brief, mark as TBD)
826
+ - Add Requirements section with the ADDED requirements
827
+
828
+ 4. **Show summary**
829
+
830
+ After applying all changes, summarize:
831
+ - Which capabilities were updated
832
+ - What changes were made (requirements added/modified/removed/renamed)
833
+
834
+ **Delta Spec Format Reference**
835
+
836
+ \`\`\`markdown
837
+ ## ADDED Requirements
838
+
839
+ ### Requirement: New Feature
840
+ The system SHALL do something new.
841
+
842
+ #### Scenario: Basic case
843
+ - **WHEN** user does X
844
+ - **THEN** system does Y
845
+
846
+ ## MODIFIED Requirements
847
+
848
+ ### Requirement: Existing Feature
849
+ #### Scenario: New scenario to add
850
+ - **WHEN** user does A
851
+ - **THEN** system does B
852
+
853
+ ## REMOVED Requirements
854
+
855
+ ### Requirement: Deprecated Feature
856
+
857
+ ## RENAMED Requirements
858
+
859
+ - FROM: \`### Requirement: Old Name\`
860
+ - TO: \`### Requirement: New Name\`
861
+ \`\`\`
862
+
863
+ **Key Principle: Intelligent Merging**
864
+
865
+ Unlike programmatic merging, you can apply **partial updates**:
866
+ - To add a scenario, just include that scenario under MODIFIED - don't copy existing scenarios
867
+ - The delta represents *intent*, not a wholesale replacement
868
+ - Use your judgment to merge changes sensibly
869
+
870
+ **Output On Success**
871
+
872
+ \`\`\`
873
+ ## Specs Synced: <change-name>
874
+
875
+ Updated main specs:
876
+
877
+ **<capability-1>**:
878
+ - Added requirement: "New Feature"
879
+ - Modified requirement: "Existing Feature" (added 1 scenario)
880
+
881
+ **<capability-2>**:
882
+ - Created new spec file
883
+ - Added requirement: "Another Feature"
884
+
885
+ Main specs are now updated. The change remains active - archive when implementation is complete.
886
+ \`\`\`
887
+
888
+ **Guardrails**
889
+ - Read both delta and main specs before making changes
890
+ - Preserve existing content not mentioned in delta
891
+ - If something is unclear, ask for clarification
892
+ - Show what you're changing as you go
893
+ - The operation should be idempotent - running twice should give same result`,
894
+ license: "MIT",
895
+ compatibility: "Requires openspec CLI.",
896
+ metadata: { author: "openspec", version: "1.0" },
897
+ };
898
+ }
899
+ /**
900
+ * Template for openspec-onboard skill
901
+ * Guided onboarding through the complete OpenSpec workflow
902
+ */
903
+ export function getOnboardSkillTemplate() {
904
+ return {
905
+ name: "openspec-onboard",
906
+ description: "OpenSpec 引导入门:带讲解走完一整轮工作流,并基于真实代码库操作。",
907
+ instructions: getOnboardInstructions(),
908
+ license: "MIT",
909
+ compatibility: "Requires openspec CLI.",
910
+ metadata: { author: "openspec", version: "1.0" },
911
+ };
912
+ }
913
+ /**
914
+ * Shared onboarding instructions used by both skill and command templates.
915
+ */
916
+ function getOnboardInstructions() {
917
+ return `Guide the user through their first complete OpenSpec workflow cycle. This is a teaching experience—you'll do real work in their codebase while explaining each step.
918
+
919
+ ---
920
+
921
+ ## Preflight
922
+
923
+ Before starting, check if the OpenSpec CLI is installed:
924
+
925
+ \`\`\`bash
926
+ # Unix/macOS
927
+ openspec --version 2>&1 || echo "CLI_NOT_INSTALLED"
928
+ # Windows (PowerShell)
929
+ # if (Get-Command openspec -ErrorAction SilentlyContinue) { openspec --version } else { echo "CLI_NOT_INSTALLED" }
930
+ \`\`\`
931
+
932
+ **If CLI not installed:**
933
+ > OpenSpec CLI is not installed. Install it first, then come back to \`/opsx:onboard\`.
934
+
935
+ Stop here if not installed.
936
+
937
+ ---
938
+
939
+ ## Phase 1: Welcome
940
+
941
+ Display:
942
+
943
+ \`\`\`
944
+ ## Welcome to OpenSpec!
945
+
946
+ I'll walk you through a complete change cycle—from idea to implementation—using a real task in your codebase. Along the way, you'll learn the workflow by doing it.
947
+
948
+ **What we'll do:**
949
+ 1. Pick a small, real task in your codebase
950
+ 2. Explore the problem briefly
951
+ 3. Create a change (the container for our work)
952
+ 4. Build the artifacts: proposal → specs → design → tasks
953
+ 5. Implement the tasks
954
+ 6. Archive the completed change
955
+
956
+ **Time:** ~15-20 minutes
957
+
958
+ Let's start by finding something to work on.
959
+ \`\`\`
960
+
961
+ ---
962
+
963
+ ## Phase 2: Task Selection
964
+
965
+ ### Codebase Analysis
966
+
967
+ Scan the codebase for small improvement opportunities. Look for:
968
+
969
+ 1. **TODO/FIXME comments** - Search for \`TODO\`, \`FIXME\`, \`HACK\`, \`XXX\` in code files
970
+ 2. **Missing error handling** - \`catch\` blocks that swallow errors, risky operations without try-catch
971
+ 3. **Functions without tests** - Cross-reference \`src/\` with test directories
972
+ 4. **Type issues** - \`any\` types in TypeScript files (\`: any\`, \`as any\`)
973
+ 5. **Debug artifacts** - \`console.log\`, \`console.debug\`, \`debugger\` statements in non-debug code
974
+ 6. **Missing validation** - User input handlers without validation
975
+
976
+ Also check recent git activity:
977
+ \`\`\`bash
978
+ # Unix/macOS
979
+ git log --oneline -10 2>/dev/null || echo "No git history"
980
+ # Windows (PowerShell)
981
+ # git log --oneline -10 2>$null; if ($LASTEXITCODE -ne 0) { echo "No git history" }
982
+ \`\`\`
983
+
984
+ ### Present Suggestions
985
+
986
+ From your analysis, present 3-4 specific suggestions:
987
+
988
+ \`\`\`
989
+ ## Task Suggestions
990
+
991
+ Based on scanning your codebase, here are some good starter tasks:
992
+
993
+ **1. [Most promising task]**
994
+ Location: \`src/path/to/file.ts:42\`
995
+ Scope: ~1-2 files, ~20-30 lines
996
+ Why it's good: [brief reason]
997
+
998
+ **2. [Second task]**
999
+ Location: \`src/another/file.ts\`
1000
+ Scope: ~1 file, ~15 lines
1001
+ Why it's good: [brief reason]
1002
+
1003
+ **3. [Third task]**
1004
+ Location: [location]
1005
+ Scope: [estimate]
1006
+ Why it's good: [brief reason]
1007
+
1008
+ **4. Something else?**
1009
+ Tell me what you'd like to work on.
1010
+
1011
+ Which task interests you? (Pick a number or describe your own)
1012
+ \`\`\`
1013
+
1014
+ **If nothing found:** Fall back to asking what the user wants to build:
1015
+ > I didn't find obvious quick wins in your codebase. What's something small you've been meaning to add or fix?
1016
+
1017
+ ### Scope Guardrail
1018
+
1019
+ If the user picks or describes something too large (major feature, multi-day work):
1020
+
1021
+ \`\`\`
1022
+ That's a valuable task, but it's probably larger than ideal for your first OpenSpec run-through.
1023
+
1024
+ For learning the workflow, smaller is better—it lets you see the full cycle without getting stuck in implementation details.
1025
+
1026
+ **Options:**
1027
+ 1. **Slice it smaller** - What's the smallest useful piece of [their task]? Maybe just [specific slice]?
1028
+ 2. **Pick something else** - One of the other suggestions, or a different small task?
1029
+ 3. **Do it anyway** - If you really want to tackle this, we can. Just know it'll take longer.
1030
+
1031
+ What would you prefer?
1032
+ \`\`\`
1033
+
1034
+ Let the user override if they insist—this is a soft guardrail.
1035
+
1036
+ ---
1037
+
1038
+ ## Phase 3: Explore Demo
1039
+
1040
+ Once a task is selected, briefly demonstrate explore mode:
1041
+
1042
+ \`\`\`
1043
+ Before we create a change, let me quickly show you **explore mode**—it's how you think through problems before committing to a direction.
1044
+ \`\`\`
1045
+
1046
+ Spend 1-2 minutes investigating the relevant code:
1047
+ - Read the file(s) involved
1048
+ - Draw a quick ASCII diagram if it helps
1049
+ - Note any considerations
1050
+
1051
+ \`\`\`
1052
+ ## Quick Exploration
1053
+
1054
+ [Your brief analysis—what you found, any considerations]
1055
+
1056
+ ┌─────────────────────────────────────────┐
1057
+ │ [Optional: ASCII diagram if helpful] │
1058
+ └─────────────────────────────────────────┘
1059
+
1060
+ Explore mode (\`/opsx:explore\`) is for this kind of thinking—investigating before implementing. You can use it anytime you need to think through a problem.
1061
+
1062
+ Now let's create a change to hold our work.
1063
+ \`\`\`
1064
+
1065
+ **PAUSE** - Wait for user acknowledgment before proceeding.
1066
+
1067
+ ---
1068
+
1069
+ ## Phase 4: Create the Change
1070
+
1071
+ **EXPLAIN:**
1072
+ \`\`\`
1073
+ ## Creating a Change
1074
+
1075
+ A "change" in OpenSpec is a container for all the thinking and planning around a piece of work. It lives in \`openspec/changes/<name>/\` and holds your artifacts—proposal, specs, design, tasks.
1076
+
1077
+ Let me create one for our task.
1078
+ \`\`\`
1079
+
1080
+ **DO:** Create the change with a derived kebab-case name:
1081
+ \`\`\`bash
1082
+ openspec new change "<derived-name>"
1083
+ \`\`\`
1084
+
1085
+ **SHOW:**
1086
+ \`\`\`
1087
+ Created: \`openspec/changes/<name>/\`
1088
+
1089
+ The folder structure:
1090
+ \`\`\`
1091
+ openspec/changes/<name>/
1092
+ ├── proposal.md ← Why we're doing this (empty, we'll fill it)
1093
+ ├── design.md ← How we'll build it (empty)
1094
+ ├── specs/ ← Detailed requirements (empty)
1095
+ └── tasks.md ← Implementation checklist (empty)
1096
+ \`\`\`
1097
+
1098
+ Now let's fill in the first artifact—the proposal.
1099
+ \`\`\`
1100
+
1101
+ ---
1102
+
1103
+ ## Phase 5: Proposal
1104
+
1105
+ **EXPLAIN:**
1106
+ \`\`\`
1107
+ ## The Proposal
1108
+
1109
+ The proposal captures **why** we're making this change and **what** it involves at a high level. It's the "elevator pitch" for the work.
1110
+
1111
+ I'll draft one based on our task.
1112
+ \`\`\`
1113
+
1114
+ **DO:** Draft the proposal content (don't save yet):
1115
+
1116
+ \`\`\`
1117
+ Here's a draft proposal:
1118
+
1119
+ ---
1120
+
1121
+ ## Why
1122
+
1123
+ [1-2 sentences explaining the problem/opportunity]
1124
+
1125
+ ## What Changes
1126
+
1127
+ [Bullet points of what will be different]
1128
+
1129
+ ## Capabilities
1130
+
1131
+ ### New Capabilities
1132
+ - \`<capability-name>\`: [brief description]
1133
+
1134
+ ### Modified Capabilities
1135
+ <!-- If modifying existing behavior -->
1136
+
1137
+ ## Impact
1138
+
1139
+ - \`src/path/to/file.ts\`: [what changes]
1140
+ - [other files if applicable]
1141
+
1142
+ ---
1143
+
1144
+ Does this capture the intent? I can adjust before we save it.
1145
+ \`\`\`
1146
+
1147
+ **PAUSE** - Wait for user approval/feedback.
1148
+
1149
+ After approval, save the proposal:
1150
+ \`\`\`bash
1151
+ openspec instructions proposal --change "<name>" --json
1152
+ \`\`\`
1153
+ Then write the content to \`openspec/changes/<name>/proposal.md\`.
1154
+
1155
+ \`\`\`
1156
+ Proposal saved. This is your "why" document—you can always come back and refine it as understanding evolves.
1157
+
1158
+ Next up: specs.
1159
+ \`\`\`
1160
+
1161
+ ---
1162
+
1163
+ ## Phase 6: Specs
1164
+
1165
+ **EXPLAIN:**
1166
+ \`\`\`
1167
+ ## Specs
1168
+
1169
+ Specs define **what** we're building in precise, testable terms. They use a requirement/scenario format that makes expected behavior crystal clear.
1170
+
1171
+ For a small task like this, we might only need one spec file.
1172
+ \`\`\`
1173
+
1174
+ **DO:** Create the spec file:
1175
+ \`\`\`bash
1176
+ # Unix/macOS
1177
+ mkdir -p openspec/changes/<name>/specs/<capability-name>
1178
+ # Windows (PowerShell)
1179
+ # New-Item -ItemType Directory -Force -Path "openspec/changes/<name>/specs/<capability-name>"
1180
+ \`\`\`
1181
+
1182
+ Draft the spec content:
1183
+
1184
+ \`\`\`
1185
+ Here's the spec:
1186
+
1187
+ ---
1188
+
1189
+ ## ADDED Requirements
1190
+
1191
+ ### Requirement: <Name>
1192
+
1193
+ <Description of what the system should do>
1194
+
1195
+ #### Scenario: <Scenario name>
1196
+
1197
+ - **WHEN** <trigger condition>
1198
+ - **THEN** <expected outcome>
1199
+ - **AND** <additional outcome if needed>
1200
+
1201
+ ---
1202
+
1203
+ This format—WHEN/THEN/AND—makes requirements testable. You can literally read them as test cases.
1204
+ \`\`\`
1205
+
1206
+ Save to \`openspec/changes/<name>/specs/<capability>/spec.md\`.
1207
+
1208
+ ---
1209
+
1210
+ ## Phase 7: Design
1211
+
1212
+ **EXPLAIN:**
1213
+ \`\`\`
1214
+ ## Design
1215
+
1216
+ The design captures **how** we'll build it—technical decisions, tradeoffs, approach.
1217
+
1218
+ For small changes, this might be brief. That's fine—not every change needs deep design discussion.
1219
+ \`\`\`
1220
+
1221
+ **DO:** Draft design.md:
1222
+
1223
+ \`\`\`
1224
+ Here's the design:
1225
+
1226
+ ---
1227
+
1228
+ ## Context
1229
+
1230
+ [Brief context about the current state]
1231
+
1232
+ ## Goals / Non-Goals
1233
+
1234
+ **Goals:**
1235
+ - [What we're trying to achieve]
1236
+
1237
+ **Non-Goals:**
1238
+ - [What's explicitly out of scope]
1239
+
1240
+ ## Decisions
1241
+
1242
+ ### Decision 1: [Key decision]
1243
+
1244
+ [Explanation of approach and rationale]
1245
+
1246
+ ---
1247
+
1248
+ For a small task, this captures the key decisions without over-engineering.
1249
+ \`\`\`
1250
+
1251
+ Save to \`openspec/changes/<name>/design.md\`.
1252
+
1253
+ ---
1254
+
1255
+ ## Phase 8: Tasks
1256
+
1257
+ **EXPLAIN:**
1258
+ \`\`\`
1259
+ ## Tasks
1260
+
1261
+ Finally, we break the work into implementation tasks—checkboxes that drive the apply phase.
1262
+
1263
+ These should be small, clear, and in logical order.
1264
+ \`\`\`
1265
+
1266
+ **DO:** Generate tasks based on specs and design:
1267
+
1268
+ \`\`\`
1269
+ Here are the implementation tasks:
1270
+
1271
+ ---
1272
+
1273
+ ## 1. [Category or file]
1274
+
1275
+ - [ ] 1.1 [Specific task]
1276
+ - [ ] 1.2 [Specific task]
1277
+
1278
+ ## 2. Verify
1279
+
1280
+ - [ ] 2.1 [Verification step]
1281
+
1282
+ ---
1283
+
1284
+ Each checkbox becomes a unit of work in the apply phase. Ready to implement?
1285
+ \`\`\`
1286
+
1287
+ **PAUSE** - Wait for user to confirm they're ready to implement.
1288
+
1289
+ Save to \`openspec/changes/<name>/tasks.md\`.
1290
+
1291
+ ---
1292
+
1293
+ ## Phase 9: Apply (Implementation)
1294
+
1295
+ **EXPLAIN:**
1296
+ \`\`\`
1297
+ ## Implementation
1298
+
1299
+ Now we implement each task, checking them off as we go. I'll announce each one and occasionally note how the specs/design informed the approach.
1300
+ \`\`\`
1301
+
1302
+ **DO:** For each task:
1303
+
1304
+ 1. Announce: "Working on task N: [description]"
1305
+ 2. Implement the change in the codebase
1306
+ 3. Reference specs/design naturally: "The spec says X, so I'm doing Y"
1307
+ 4. Mark complete in tasks.md: \`- [ ]\` → \`- [x]\`
1308
+ 5. Brief status: "✓ Task N complete"
1309
+
1310
+ Keep narration light—don't over-explain every line of code.
1311
+
1312
+ After all tasks:
1313
+
1314
+ \`\`\`
1315
+ ## Implementation Complete
1316
+
1317
+ All tasks done:
1318
+ - [x] Task 1
1319
+ - [x] Task 2
1320
+ - [x] ...
1321
+
1322
+ The change is implemented! One more step—let's archive it.
1323
+ \`\`\`
1324
+
1325
+ ---
1326
+
1327
+ ## Phase 10: Archive
1328
+
1329
+ **EXPLAIN:**
1330
+ \`\`\`
1331
+ ## Archiving
1332
+
1333
+ When a change is complete, we archive it. This moves it from \`openspec/changes/\` to \`openspec/changes/archive/YYYY-MM-DD-<name>/\`.
1334
+
1335
+ Archived changes become your project's decision history—you can always find them later to understand why something was built a certain way.
1336
+ \`\`\`
1337
+
1338
+ **DO:**
1339
+ \`\`\`bash
1340
+ openspec archive "<name>"
1341
+ \`\`\`
1342
+
1343
+ **SHOW:**
1344
+ \`\`\`
1345
+ Archived to: \`openspec/changes/archive/YYYY-MM-DD-<name>/\`
1346
+
1347
+ The change is now part of your project's history. The code is in your codebase, the decision record is preserved.
1348
+ \`\`\`
1349
+
1350
+ ---
1351
+
1352
+ ## Phase 11: Recap & Next Steps
1353
+
1354
+ \`\`\`
1355
+ ## Congratulations!
1356
+
1357
+ You just completed a full OpenSpec cycle:
1358
+
1359
+ 1. **Explore** - Thought through the problem
1360
+ 2. **New** - Created a change container
1361
+ 3. **Proposal** - Captured WHY
1362
+ 4. **Specs** - Defined WHAT in detail
1363
+ 5. **Design** - Decided HOW
1364
+ 6. **Tasks** - Broke it into steps
1365
+ 7. **Apply** - Implemented the work
1366
+ 8. **Archive** - Preserved the record
1367
+
1368
+ This same rhythm works for any size change—a small fix or a major feature.
1369
+
1370
+ ---
1371
+
1372
+ ## Command Reference
1373
+
1374
+ | Command | What it does |
1375
+ |---------|--------------|
1376
+ | \`/opsx:explore\` | Think through problems before/during work |
1377
+ | \`/opsx:new\` | Start a new change, step through artifacts |
1378
+ | \`/opsx:ff\` | Fast-forward: create all artifacts at once |
1379
+ | \`/opsx:continue\` | Continue working on an existing change |
1380
+ | \`/opsx:apply\` | Implement tasks from a change |
1381
+ | \`/opsx:verify\` | Verify implementation matches artifacts |
1382
+ | \`/opsx:archive\` | Archive a completed change |
1383
+
1384
+ ---
1385
+
1386
+ ## What's Next?
1387
+
1388
+ Try \`/opsx:new\` or \`/opsx:ff\` on something you actually want to build. You've got the rhythm now!
1389
+ \`\`\`
1390
+
1391
+ ---
1392
+
1393
+ ## Graceful Exit Handling
1394
+
1395
+ ### User wants to stop mid-way
1396
+
1397
+ If the user says they need to stop, want to pause, or seem disengaged:
1398
+
1399
+ \`\`\`
1400
+ No problem! Your change is saved at \`openspec/changes/<name>/\`.
1401
+
1402
+ To pick up where we left off later:
1403
+ - \`/opsx:continue <name>\` - Resume artifact creation
1404
+ - \`/opsx:apply <name>\` - Jump to implementation (if tasks exist)
1405
+
1406
+ The work won't be lost. Come back whenever you're ready.
1407
+ \`\`\`
1408
+
1409
+ Exit gracefully without pressure.
1410
+
1411
+ ### User just wants command reference
1412
+
1413
+ If the user says they just want to see the commands or skip the tutorial:
1414
+
1415
+ \`\`\`
1416
+ ## OpenSpec Quick Reference
1417
+
1418
+ | Command | What it does |
1419
+ |---------|--------------|
1420
+ | \`/opsx:explore\` | Think through problems (no code changes) |
1421
+ | \`/opsx:new <name>\` | Start a new change, step by step |
1422
+ | \`/opsx:ff <name>\` | Fast-forward: all artifacts at once |
1423
+ | \`/opsx:continue <name>\` | Continue an existing change |
1424
+ | \`/opsx:apply <name>\` | Implement tasks |
1425
+ | \`/opsx:verify <name>\` | Verify implementation |
1426
+ | \`/opsx:archive <name>\` | Archive when done |
1427
+
1428
+ Try \`/opsx:new\` to start your first change, or \`/opsx:ff\` if you want to move fast.
1429
+ \`\`\`
1430
+
1431
+ Exit gracefully.
1432
+
1433
+ ---
1434
+
1435
+ ## Guardrails
1436
+
1437
+ - **Follow the EXPLAIN → DO → SHOW → PAUSE pattern** at key transitions (after explore, after proposal draft, after tasks, after archive)
1438
+ - **Keep narration light** during implementation—teach without lecturing
1439
+ - **Don't skip phases** even if the change is small—the goal is teaching the workflow
1440
+ - **Pause for acknowledgment** at marked points, but don't over-pause
1441
+ - **Handle exits gracefully**—never pressure the user to continue
1442
+ - **Use real codebase tasks**—don't simulate or use fake examples
1443
+ - **Adjust scope gently**—guide toward smaller tasks but respect user choice`;
1444
+ }
1445
+ /**
1446
+ * Template for /opsx:explore slash command
1447
+ * Explore mode - adaptive thinking partner
1448
+ */
1449
+ export function getOpsxExploreCommandTemplate() {
1450
+ return {
1451
+ name: "OPSX: Explore",
1452
+ description: "进入探索模式:梳理想法、排查问题、澄清需求",
1453
+ category: "Workflow",
1454
+ tags: ["workflow", "explore", "experimental", "thinking"],
1455
+ content: `Enter explore mode. Think deeply. Visualize freely. Follow the conversation wherever it goes.
1456
+
1457
+ **IMPORTANT: Explore mode is for thinking, not implementing.** You may read files, search code, and investigate the codebase, but you must NEVER write code or implement features. If the user asks you to implement something, remind them to exit explore mode first (e.g., start a change with \`/opsx:new\` or \`/opsx:ff\`). You MAY create OpenSpec artifacts (proposals, designs, specs) if the user asks—that's capturing thinking, not implementing.
1458
+
1459
+ **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.
1460
+
1461
+ **Input**: The argument after \`/opsx:explore\` is whatever the user wants to think about. Could be:
1462
+ - A vague idea: "real-time collaboration"
1463
+ - A specific problem: "the auth system is getting unwieldy"
1464
+ - A change name: "add-dark-mode" (to explore in context of that change)
1465
+ - A comparison: "postgres vs sqlite for this"
1466
+ - Nothing (just enter explore mode)
1467
+
1468
+ ---
1469
+
1470
+ ## The Stance
1471
+
1472
+ - **Curious, not prescriptive** - Ask questions that emerge naturally, don't follow a script
1473
+ - **Open threads, not interrogations** - Surface multiple interesting directions and let the user follow what resonates. Don't funnel them through a single path of questions.
1474
+ - **Visual** - Use ASCII diagrams liberally when they'd help clarify thinking
1475
+ - **Adaptive** - Follow interesting threads, pivot when new information emerges
1476
+ - **Patient** - Don't rush to conclusions, let the shape of the problem emerge
1477
+ - **Grounded** - Explore the actual codebase when relevant, don't just theorize
1478
+
1479
+ ---
1480
+
1481
+ ## What You Might Do
1482
+
1483
+ Depending on what the user brings, you might:
1484
+
1485
+ **Explore the problem space**
1486
+ - Ask clarifying questions that emerge from what they said
1487
+ - Challenge assumptions
1488
+ - Reframe the problem
1489
+ - Find analogies
1490
+
1491
+ **Investigate the codebase**
1492
+ - Map existing architecture relevant to the discussion
1493
+ - Find integration points
1494
+ - Identify patterns already in use
1495
+ - Surface hidden complexity
1496
+
1497
+ **Compare options**
1498
+ - Brainstorm multiple approaches
1499
+ - Build comparison tables
1500
+ - Sketch tradeoffs
1501
+ - Recommend a path (if asked)
1502
+
1503
+ **Visualize**
1504
+ \`\`\`
1505
+ ┌─────────────────────────────────────────┐
1506
+ │ Use ASCII diagrams liberally │
1507
+ ├─────────────────────────────────────────┤
1508
+ │ │
1509
+ │ ┌────────┐ ┌────────┐ │
1510
+ │ │ State │────────▶│ State │ │
1511
+ │ │ A │ │ B │ │
1512
+ │ └────────┘ └────────┘ │
1513
+ │ │
1514
+ │ System diagrams, state machines, │
1515
+ │ data flows, architecture sketches, │
1516
+ │ dependency graphs, comparison tables │
1517
+ │ │
1518
+ └─────────────────────────────────────────┘
1519
+ \`\`\`
1520
+
1521
+ **Surface risks and unknowns**
1522
+ - Identify what could go wrong
1523
+ - Find gaps in understanding
1524
+ - Suggest spikes or investigations
1525
+
1526
+ ---
1527
+
1528
+ ## OpenSpec Awareness
1529
+
1530
+ You have full context of the OpenSpec system. Use it naturally, don't force it.
1531
+
1532
+ ### Check for context
1533
+
1534
+ At the start, quickly check what exists:
1535
+ \`\`\`bash
1536
+ openspec list --json
1537
+ \`\`\`
1538
+
1539
+ This tells you:
1540
+ - If there are active changes
1541
+ - Their names, schemas, and status
1542
+ - What the user might be working on
1543
+
1544
+ If the user mentioned a specific change name, read its artifacts for context.
1545
+
1546
+ ### When no change exists
1547
+
1548
+ Think freely. When insights crystallize, you might offer:
1549
+
1550
+ - "This feels solid enough to start a change. Want me to create one?"
1551
+ → Can transition to \`/opsx:new\` or \`/opsx:ff\`
1552
+ - Or keep exploring - no pressure to formalize
1553
+
1554
+ ### When a change exists
1555
+
1556
+ If the user mentions a change or you detect one is relevant:
1557
+
1558
+ 1. **Read existing artifacts for context**
1559
+ - \`openspec/changes/<name>/proposal.md\`
1560
+ - \`openspec/changes/<name>/design.md\`
1561
+ - \`openspec/changes/<name>/tasks.md\`
1562
+ - etc.
1563
+
1564
+ 2. **Reference them naturally in conversation**
1565
+ - "Your design mentions using Redis, but we just realized SQLite fits better..."
1566
+ - "The proposal scopes this to premium users, but we're now thinking everyone..."
1567
+
1568
+ 3. **Offer to capture when decisions are made**
1569
+
1570
+ | Insight Type | Where to Capture |
1571
+ |--------------|------------------|
1572
+ | New requirement discovered | \`specs/<capability>/spec.md\` |
1573
+ | Requirement changed | \`specs/<capability>/spec.md\` |
1574
+ | Design decision made | \`design.md\` |
1575
+ | Scope changed | \`proposal.md\` |
1576
+ | New work identified | \`tasks.md\` |
1577
+ | Assumption invalidated | Relevant artifact |
1578
+
1579
+ Example offers:
1580
+ - "That's a design decision. Capture it in design.md?"
1581
+ - "This is a new requirement. Add it to specs?"
1582
+ - "This changes scope. Update the proposal?"
1583
+
1584
+ 4. **The user decides** - Offer and move on. Don't pressure. Don't auto-capture.
1585
+
1586
+ ---
1587
+
1588
+ ## What You Don't Have To Do
1589
+
1590
+ - Follow a script
1591
+ - Ask the same questions every time
1592
+ - Produce a specific artifact
1593
+ - Reach a conclusion
1594
+ - Stay on topic if a tangent is valuable
1595
+ - Be brief (this is thinking time)
1596
+
1597
+ ---
1598
+
1599
+ ## Ending Discovery
1600
+
1601
+ There's no required ending. Discovery might:
1602
+
1603
+ - **Flow into action**: "Ready to start? \`/opsx:new\` or \`/opsx:ff\`"
1604
+ - **Result in artifact updates**: "Updated design.md with these decisions"
1605
+ - **Just provide clarity**: User has what they need, moves on
1606
+ - **Continue later**: "We can pick this up anytime"
1607
+
1608
+ When things crystallize, you might offer a summary - but it's optional. Sometimes the thinking IS the value.
1609
+
1610
+ ---
1611
+
1612
+ ## Guardrails
1613
+
1614
+ - **Don't implement** - Never write code or implement features. Creating OpenSpec artifacts is fine, writing application code is not.
1615
+ - **Don't fake understanding** - If something is unclear, dig deeper
1616
+ - **Don't rush** - Discovery is thinking time, not task time
1617
+ - **Don't force structure** - Let patterns emerge naturally
1618
+ - **Don't auto-capture** - Offer to save insights, don't just do it
1619
+ - **Do visualize** - A good diagram is worth many paragraphs
1620
+ - **Do explore the codebase** - Ground discussions in reality
1621
+ - **Do question assumptions** - Including the user's and your own`,
1622
+ };
1623
+ }
1624
+ /**
1625
+ * Template for /opsx:new slash command
1626
+ */
1627
+ export function getOpsxNewCommandTemplate() {
1628
+ return {
1629
+ name: "OPSX: New",
1630
+ description: "新建变更(OPSX 制品工作流)",
1631
+ category: "Workflow",
1632
+ tags: ["workflow", "artifacts", "experimental"],
1633
+ content: `Start a new change using the experimental artifact-driven approach.
1634
+
1635
+ **Input**: The argument after \`/opsx:new\` is the change name (kebab-case), OR a description of what the user wants to build.
1636
+
1637
+ **Steps**
1638
+
1639
+ 1. **If no input provided, ask what they want to build**
1640
+
1641
+ Use the **AskUserQuestion tool** (open-ended, no preset options) to ask:
1642
+ > "What change do you want to work on? Describe what you want to build or fix."
1643
+
1644
+ From their description, derive a kebab-case name (e.g., "add user authentication" → \`add-user-auth\`).
1645
+
1646
+ **IMPORTANT**: Do NOT proceed without understanding what the user wants to build.
1647
+
1648
+ 2. **Determine the workflow schema**
1649
+
1650
+ Use the default schema (omit \`--schema\`) unless the user explicitly requests a different workflow.
1651
+
1652
+ **Use a different schema only if the user mentions:**
1653
+ - A specific schema name → use \`--schema <name>\`
1654
+ - "show workflows" or "what workflows" → run \`openspec schemas --json\` and let them choose
1655
+
1656
+ **Otherwise**: Omit \`--schema\` to use the default.
1657
+
1658
+ 3. **Create the change directory**
1659
+ \`\`\`bash
1660
+ openspec new change "<name>"
1661
+ \`\`\`
1662
+ Add \`--schema <name>\` only if the user requested a specific workflow.
1663
+ This creates a scaffolded change at \`openspec/changes/<name>/\` with the selected schema.
1664
+
1665
+ 4. **Show the artifact status**
1666
+ \`\`\`bash
1667
+ openspec status --change "<name>"
1668
+ \`\`\`
1669
+ This shows which artifacts need to be created and which are ready (dependencies satisfied).
1670
+
1671
+ 5. **Get instructions for the first artifact**
1672
+ The first artifact depends on the schema. Check the status output to find the first artifact with status "ready".
1673
+ \`\`\`bash
1674
+ openspec instructions <first-artifact-id> --change "<name>"
1675
+ \`\`\`
1676
+ This outputs the template and context for creating the first artifact.
1677
+
1678
+ 6. **STOP and wait for user direction**
1679
+
1680
+ **Output**
1681
+
1682
+ After completing the steps, summarize:
1683
+ - Change name and location
1684
+ - Schema/workflow being used and its artifact sequence
1685
+ - Current status (0/N artifacts complete)
1686
+ - The template for the first artifact
1687
+ - Prompt: "Ready to create the first artifact? Run \`/opsx:continue\` or just describe what this change is about and I'll draft it."
1688
+
1689
+ **Guardrails**
1690
+ - Do NOT create any artifacts yet - just show the instructions
1691
+ - Do NOT advance beyond showing the first artifact template
1692
+ - If the name is invalid (not kebab-case), ask for a valid name
1693
+ - If a change with that name already exists, suggest using \`/opsx:continue\` instead
1694
+ - Pass --schema if using a non-default workflow`,
1695
+ };
1696
+ }
1697
+ /**
1698
+ * Template for /opsx:continue slash command
1699
+ */
1700
+ export function getOpsxContinueCommandTemplate() {
1701
+ return {
1702
+ name: "OPSX: Continue",
1703
+ description: "继续变更:创建下一个制品",
1704
+ category: "Workflow",
1705
+ tags: ["workflow", "artifacts", "experimental"],
1706
+ content: `Continue working on a change by creating the next artifact.
1707
+
1708
+ **Input**: Optionally specify a change name after \`/opsx:continue\` (e.g., \`/opsx:continue add-auth\`). If omitted, check if it can be inferred from conversation context. If vague or ambiguous you MUST prompt for available changes.
1709
+
1710
+ **Steps**
1711
+
1712
+ 1. **If no change name provided, prompt for selection**
1713
+
1714
+ 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.
1715
+
1716
+ Present the top 3-4 most recently modified changes as options, showing:
1717
+ - Change name
1718
+ - Schema (from \`schema\` field if present, otherwise "spec-driven")
1719
+ - Status (e.g., "0/5 tasks", "complete", "no tasks")
1720
+ - How recently it was modified (from \`lastModified\` field)
1721
+
1722
+ Mark the most recently modified change as "(Recommended)" since it's likely what the user wants to continue.
1723
+
1724
+ **IMPORTANT**: Do NOT guess or auto-select a change. Always let the user choose.
1725
+
1726
+ 2. **Check current status**
1727
+ \`\`\`bash
1728
+ openspec status --change "<name>" --json
1729
+ \`\`\`
1730
+ Parse the JSON to understand current state. The response includes:
1731
+ - \`schemaName\`: The workflow schema being used (e.g., "spec-driven")
1732
+ - \`artifacts\`: Array of artifacts with their status ("done", "ready", "blocked")
1733
+ - \`isComplete\`: Boolean indicating if all artifacts are complete
1734
+
1735
+ 3. **Act based on status**:
1736
+
1737
+ ---
1738
+
1739
+ **If all artifacts are complete (\`isComplete: true\`)**:
1740
+ - Congratulate the user
1741
+ - Show final status including the schema used
1742
+ - Suggest: "All artifacts created! You can now implement this change with \`/opsx:apply\` or archive it with \`/opsx:archive\`."
1743
+ - STOP
1744
+
1745
+ ---
1746
+
1747
+ **If artifacts are ready to create** (status shows artifacts with \`status: "ready"\`):
1748
+ - Pick the FIRST artifact with \`status: "ready"\` from the status output
1749
+ - Get its instructions:
1750
+ \`\`\`bash
1751
+ openspec instructions <artifact-id> --change "<name>" --json
1752
+ \`\`\`
1753
+ - Parse the JSON. The key fields are:
1754
+ - \`context\`: Project background (constraints for you - do NOT include in output)
1755
+ - \`rules\`: Artifact-specific rules (constraints for you - do NOT include in output)
1756
+ - \`template\`: The structure to use for your output file
1757
+ - \`instruction\`: Schema-specific guidance
1758
+ - \`outputPath\`: Where to write the artifact
1759
+ - \`dependencies\`: Completed artifacts to read for context
1760
+ - **Create the artifact file**:
1761
+ - Read any completed dependency files for context
1762
+ - Use \`template\` as the structure - fill in its sections
1763
+ - Apply \`context\` and \`rules\` as constraints when writing - but do NOT copy them into the file
1764
+ - Write to the output path specified in instructions
1765
+ - Show what was created and what's now unlocked
1766
+ - STOP after creating ONE artifact
1767
+
1768
+ ---
1769
+
1770
+ **If no artifacts are ready (all blocked)**:
1771
+ - This shouldn't happen with a valid schema
1772
+ - Show status and suggest checking for issues
1773
+
1774
+ 4. **After creating an artifact, show progress**
1775
+ \`\`\`bash
1776
+ openspec status --change "<name>"
1777
+ \`\`\`
1778
+
1779
+ **Output**
1780
+
1781
+ After each invocation, show:
1782
+ - Which artifact was created
1783
+ - Schema workflow being used
1784
+ - Current progress (N/M complete)
1785
+ - What artifacts are now unlocked
1786
+ - Prompt: "Run \`/opsx:continue\` to create the next artifact"
1787
+
1788
+ **Artifact Creation Guidelines**
1789
+
1790
+ The artifact types and their purpose depend on the schema. Use the \`instruction\` field from the instructions output to understand what to create.
1791
+
1792
+ Common artifact patterns:
1793
+
1794
+ **spec-driven schema** (proposal → specs → design → tasks):
1795
+ - **proposal.md**: Ask user about the change if not clear. Fill in Why, What Changes, Capabilities, Impact.
1796
+ - The Capabilities section is critical - each capability listed will need a spec file.
1797
+ - **specs/<capability>/spec.md**: Create one spec per capability listed in the proposal's Capabilities section (use the capability name, not the change name).
1798
+ - **design.md**: Document technical decisions, architecture, and implementation approach.
1799
+ - **tasks.md**: Break down implementation into checkboxed tasks.
1800
+
1801
+ For other schemas, follow the \`instruction\` field from the CLI output.
1802
+
1803
+ **Guardrails**
1804
+ - Create ONE artifact per invocation
1805
+ - Always read dependency artifacts before creating a new one
1806
+ - Never skip artifacts or create out of order
1807
+ - If context is unclear, ask the user before creating
1808
+ - Verify the artifact file exists after writing before marking progress
1809
+ - Use the schema's artifact sequence, don't assume specific artifact names
1810
+ - **IMPORTANT**: \`context\` and \`rules\` are constraints for YOU, not content for the file
1811
+ - Do NOT copy \`<context>\`, \`<rules>\`, \`<project_context>\` blocks into the artifact
1812
+ - These guide what you write, but should never appear in the output`,
1813
+ };
1814
+ }
1815
+ /**
1816
+ * Template for /opsx:apply slash command
1817
+ */
1818
+ export function getOpsxApplyCommandTemplate() {
1819
+ return {
1820
+ name: "OPSX: Apply",
1821
+ description: "按 OpenSpec 变更实施任务",
1822
+ category: "Workflow",
1823
+ tags: ["workflow", "artifacts", "experimental"],
1824
+ content: `Implement tasks from an OpenSpec change.
1825
+
1826
+ **Input**: Optionally specify a change name (e.g., \`/opsx:apply add-auth\`). If omitted, check if it can be inferred from conversation context. If vague or ambiguous you MUST prompt for available changes.
1827
+
1828
+ **Steps**
1829
+
1830
+ 1. **Select the change**
1831
+
1832
+ If a name is provided, use it. Otherwise:
1833
+ - Infer from conversation context if the user mentioned a change
1834
+ - Auto-select if only one active change exists
1835
+ - If ambiguous, run \`openspec list --json\` to get available changes and use the **AskUserQuestion tool** to let the user select
1836
+
1837
+ Always announce: "Using change: <name>" and how to override (e.g., \`/opsx:apply <other>\`).
1838
+
1839
+ 2. **Check status to understand the schema**
1840
+ \`\`\`bash
1841
+ openspec status --change "<name>" --json
1842
+ \`\`\`
1843
+ Parse the JSON to understand:
1844
+ - \`schemaName\`: The workflow being used (e.g., "spec-driven")
1845
+ - Which artifact contains the tasks (typically "tasks" for spec-driven, check status for others)
1846
+
1847
+ 3. **Get apply instructions**
1848
+
1849
+ \`\`\`bash
1850
+ openspec instructions apply --change "<name>" --json
1851
+ \`\`\`
1852
+
1853
+ This returns:
1854
+ - Context file paths (varies by schema)
1855
+ - Progress (total, complete, remaining)
1856
+ - Task list with status
1857
+ - Dynamic instruction based on current state
1858
+
1859
+ **Handle states:**
1860
+ - If \`state: "blocked"\` (missing artifacts): show message, suggest using \`/opsx:continue\`
1861
+ - If \`state: "all_done"\`: congratulate, suggest archive
1862
+ - Otherwise: proceed to implementation
1863
+
1864
+ 4. **Read context files**
1865
+
1866
+ Read the files listed in \`contextFiles\` from the apply instructions output.
1867
+ The files depend on the schema being used:
1868
+ - **spec-driven**: proposal, specs, design, tasks
1869
+ - Other schemas: follow the contextFiles from CLI output
1870
+
1871
+ 5. **Show current progress**
1872
+
1873
+ Display:
1874
+ - Schema being used
1875
+ - Progress: "N/M tasks complete"
1876
+ - Remaining tasks overview
1877
+ - Dynamic instruction from CLI
1878
+
1879
+ 6. **Implement tasks (loop until done or blocked)**
1880
+
1881
+ For each pending task:
1882
+ - Show which task is being worked on
1883
+ - Make the code changes required
1884
+ - Keep changes minimal and focused
1885
+ - Mark task complete in the tasks file: \`- [ ]\` → \`- [x]\`
1886
+ - Continue to next task
1887
+
1888
+ **Pause if:**
1889
+ - Task is unclear → ask for clarification
1890
+ - Implementation reveals a design issue → suggest updating artifacts
1891
+ - Error or blocker encountered → report and wait for guidance
1892
+ - User interrupts
1893
+
1894
+ 7. **On completion or pause, show status**
1895
+
1896
+ Display:
1897
+ - Tasks completed this session
1898
+ - Overall progress: "N/M tasks complete"
1899
+ - If all done: suggest archive
1900
+ - If paused: explain why and wait for guidance
1901
+
1902
+ **Output During Implementation**
1903
+
1904
+ \`\`\`
1905
+ ## Implementing: <change-name> (schema: <schema-name>)
1906
+
1907
+ Working on task 3/7: <task description>
1908
+ [...implementation happening...]
1909
+ ✓ Task complete
1910
+
1911
+ Working on task 4/7: <task description>
1912
+ [...implementation happening...]
1913
+ ✓ Task complete
1914
+ \`\`\`
1915
+
1916
+ **Output On Completion**
1917
+
1918
+ \`\`\`
1919
+ ## Implementation Complete
1920
+
1921
+ **Change:** <change-name>
1922
+ **Schema:** <schema-name>
1923
+ **Progress:** 7/7 tasks complete ✓
1924
+
1925
+ ### Completed This Session
1926
+ - [x] Task 1
1927
+ - [x] Task 2
1928
+ ...
1929
+
1930
+ All tasks complete! You can archive this change with \`/opsx:archive\`.
1931
+ \`\`\`
1932
+
1933
+ **Output On Pause (Issue Encountered)**
1934
+
1935
+ \`\`\`
1936
+ ## Implementation Paused
1937
+
1938
+ **Change:** <change-name>
1939
+ **Schema:** <schema-name>
1940
+ **Progress:** 4/7 tasks complete
1941
+
1942
+ ### Issue Encountered
1943
+ <description of the issue>
1944
+
1945
+ **Options:**
1946
+ 1. <option 1>
1947
+ 2. <option 2>
1948
+ 3. Other approach
1949
+
1950
+ What would you like to do?
1951
+ \`\`\`
1952
+
1953
+ **Guardrails**
1954
+ - Keep going through tasks until done or blocked
1955
+ - Always read context files before starting (from the apply instructions output)
1956
+ - If task is ambiguous, pause and ask before implementing
1957
+ - If implementation reveals issues, pause and suggest artifact updates
1958
+ - Keep code changes minimal and scoped to each task
1959
+ - Update task checkbox immediately after completing each task
1960
+ - Pause on errors, blockers, or unclear requirements - don't guess
1961
+ - Use contextFiles from CLI output, don't assume specific file names
1962
+
1963
+ **Fluid Workflow Integration**
1964
+
1965
+ This skill supports the "actions on a change" model:
1966
+
1967
+ - **Can be invoked anytime**: Before all artifacts are done (if tasks exist), after partial implementation, interleaved with other actions
1968
+ - **Allows artifact updates**: If implementation reveals design issues, suggest updating artifacts - not phase-locked, work fluidly`,
1969
+ };
1970
+ }
1971
+ /**
1972
+ * Template for /opsx:ff slash command
1973
+ */
1974
+ export function getOpsxFfCommandTemplate() {
1975
+ return {
1976
+ name: "OPSX: Fast Forward",
1977
+ description: "创建变更并一次性生成实施所需全部制品",
1978
+ category: "Workflow",
1979
+ tags: ["workflow", "artifacts", "experimental"],
1980
+ content: `Fast-forward through artifact creation - generate everything needed to start implementation.
1981
+
1982
+ **Input**: The argument after \`/opsx:ff\` is the change name (kebab-case), OR a description of what the user wants to build.
1983
+
1984
+ **Steps**
1985
+
1986
+ 1. **If no input provided, ask what they want to build**
1987
+
1988
+ Use the **AskUserQuestion tool** (open-ended, no preset options) to ask:
1989
+ > "What change do you want to work on? Describe what you want to build or fix."
1990
+
1991
+ From their description, derive a kebab-case name (e.g., "add user authentication" → \`add-user-auth\`).
1992
+
1993
+ **IMPORTANT**: Do NOT proceed without understanding what the user wants to build.
1994
+
1995
+ 2. **Create the change directory**
1996
+ \`\`\`bash
1997
+ openspec new change "<name>"
1998
+ \`\`\`
1999
+ This creates a scaffolded change at \`openspec/changes/<name>/\`.
2000
+
2001
+ 3. **Get the artifact build order**
2002
+ \`\`\`bash
2003
+ openspec status --change "<name>" --json
2004
+ \`\`\`
2005
+ Parse the JSON to get:
2006
+ - \`applyRequires\`: array of artifact IDs needed before implementation (e.g., \`["tasks"]\`)
2007
+ - \`artifacts\`: list of all artifacts with their status and dependencies
2008
+
2009
+ 4. **Create artifacts in sequence until apply-ready**
2010
+
2011
+ Use the **TodoWrite tool** to track progress through the artifacts.
2012
+
2013
+ Loop through artifacts in dependency order (artifacts with no pending dependencies first):
2014
+
2015
+ a. **For each artifact that is \`ready\` (dependencies satisfied)**:
2016
+ - Get instructions:
2017
+ \`\`\`bash
2018
+ openspec instructions <artifact-id> --change "<name>" --json
2019
+ \`\`\`
2020
+ - The instructions JSON includes:
2021
+ - \`context\`: Project background (constraints for you - do NOT include in output)
2022
+ - \`rules\`: Artifact-specific rules (constraints for you - do NOT include in output)
2023
+ - \`template\`: The structure to use for your output file
2024
+ - \`instruction\`: Schema-specific guidance for this artifact type
2025
+ - \`outputPath\`: Where to write the artifact
2026
+ - \`dependencies\`: Completed artifacts to read for context
2027
+ - Read any completed dependency files for context
2028
+ - Create the artifact file using \`template\` as the structure
2029
+ - Apply \`context\` and \`rules\` as constraints - but do NOT copy them into the file
2030
+ - Show brief progress: "✓ Created <artifact-id>"
2031
+
2032
+ b. **Continue until all \`applyRequires\` artifacts are complete**
2033
+ - After creating each artifact, re-run \`openspec status --change "<name>" --json\`
2034
+ - Check if every artifact ID in \`applyRequires\` has \`status: "done"\` in the artifacts array
2035
+ - Stop when all \`applyRequires\` artifacts are done
2036
+
2037
+ c. **If an artifact requires user input** (unclear context):
2038
+ - Use **AskUserQuestion tool** to clarify
2039
+ - Then continue with creation
2040
+
2041
+ 5. **Show final status**
2042
+ \`\`\`bash
2043
+ openspec status --change "<name>"
2044
+ \`\`\`
2045
+
2046
+ **Output**
2047
+
2048
+ After completing all artifacts, summarize:
2049
+ - Change name and location
2050
+ - List of artifacts created with brief descriptions
2051
+ - What's ready: "All artifacts created! Ready for implementation."
2052
+ - Prompt: "Run \`/opsx:apply\` to start implementing."
2053
+
2054
+ **Artifact Creation Guidelines**
2055
+
2056
+ - Follow the \`instruction\` field from \`openspec instructions\` for each artifact type
2057
+ - The schema defines what each artifact should contain - follow it
2058
+ - Read dependency artifacts for context before creating new ones
2059
+ - Use the \`template\` as a starting point, filling in based on context
2060
+
2061
+ **Guardrails**
2062
+ - Create ALL artifacts needed for implementation (as defined by schema's \`apply.requires\`)
2063
+ - Always read dependency artifacts before creating a new one
2064
+ - If context is critically unclear, ask the user - but prefer making reasonable decisions to keep momentum
2065
+ - If a change with that name already exists, ask if user wants to continue it or create a new one
2066
+ - Verify each artifact file exists after writing before proceeding to next`,
2067
+ };
2068
+ }
2069
+ /**
2070
+ * Template for openspec-archive-change skill
2071
+ * For archiving completed changes in the experimental workflow
2072
+ */
2073
+ export function getArchiveChangeSkillTemplate() {
2074
+ return {
2075
+ name: "openspec-archive-change",
2076
+ description: "归档已完成的变更。适用于实施完成后要收尾并归档变更时。",
2077
+ instructions: `Archive a completed change in the experimental workflow.
2078
+
2079
+ **Input**: Optionally specify a change name. If omitted, check if it can be inferred from conversation context. If vague or ambiguous you MUST prompt for available changes.
2080
+
2081
+ **Steps**
2082
+
2083
+ 1. **If no change name provided, prompt for selection**
2084
+
2085
+ Run \`openspec list --json\` to get available changes. Use the **AskUserQuestion tool** to let the user select.
2086
+
2087
+ Show only active changes (not already archived).
2088
+ Include the schema used for each change if available.
2089
+
2090
+ **IMPORTANT**: Do NOT guess or auto-select a change. Always let the user choose.
2091
+
2092
+ 2. **Check artifact completion status**
2093
+
2094
+ Run \`openspec status --change "<name>" --json\` to check artifact completion.
2095
+
2096
+ Parse the JSON to understand:
2097
+ - \`schemaName\`: The workflow being used
2098
+ - \`artifacts\`: List of artifacts with their status (\`done\` or other)
2099
+
2100
+ **If any artifacts are not \`done\`:**
2101
+ - Display warning listing incomplete artifacts
2102
+ - Use **AskUserQuestion tool** to confirm user wants to proceed
2103
+ - Proceed if user confirms
2104
+
2105
+ 3. **Check task completion status**
2106
+
2107
+ Read the tasks file (typically \`tasks.md\`) to check for incomplete tasks.
2108
+
2109
+ Count tasks marked with \`- [ ]\` (incomplete) vs \`- [x]\` (complete).
2110
+
2111
+ **If incomplete tasks found:**
2112
+ - Display warning showing count of incomplete tasks
2113
+ - Use **AskUserQuestion tool** to confirm user wants to proceed
2114
+ - Proceed if user confirms
2115
+
2116
+ **If no tasks file exists:** Proceed without task-related warning.
2117
+
2118
+ 4. **Assess delta spec sync state**
2119
+
2120
+ Check for delta specs at \`openspec/changes/<name>/specs/\`. If none exist, proceed without sync prompt.
2121
+
2122
+ **If delta specs exist:**
2123
+ - Compare each delta spec with its corresponding main spec at \`openspec/specs/<capability>/spec.md\`
2124
+ - Determine what changes would be applied (adds, modifications, removals, renames)
2125
+ - Show a combined summary before prompting
2126
+
2127
+ **Prompt options:**
2128
+ - If changes needed: "Sync now (recommended)", "Archive without syncing"
2129
+ - If already synced: "Archive now", "Sync anyway", "Cancel"
2130
+
2131
+ If user chooses sync, use Task tool (subagent_type: "general-purpose", prompt: "Use Skill tool to invoke openspec-sync-specs for change '<name>'. Delta spec analysis: <include the analyzed delta spec summary>"). Proceed to archive regardless of choice.
2132
+
2133
+ 5. **Perform the archive**
2134
+
2135
+ Create the archive directory if it doesn't exist:
2136
+ \`\`\`bash
2137
+ mkdir -p openspec/changes/archive
2138
+ \`\`\`
2139
+
2140
+ Generate target name using current date: \`YYYY-MM-DD-<change-name>\`
2141
+
2142
+ **Check if target already exists:**
2143
+ - If yes: Fail with error, suggest renaming existing archive or using different date
2144
+ - If no: Move the change directory to archive
2145
+
2146
+ \`\`\`bash
2147
+ mv openspec/changes/<name> openspec/changes/archive/YYYY-MM-DD-<name>
2148
+ \`\`\`
2149
+
2150
+ 6. **Display summary**
2151
+
2152
+ Show archive completion summary including:
2153
+ - Change name
2154
+ - Schema that was used
2155
+ - Archive location
2156
+ - Whether specs were synced (if applicable)
2157
+ - Note about any warnings (incomplete artifacts/tasks)
2158
+
2159
+ **Output On Success**
2160
+
2161
+ \`\`\`
2162
+ ## Archive Complete
2163
+
2164
+ **Change:** <change-name>
2165
+ **Schema:** <schema-name>
2166
+ **Archived to:** openspec/changes/archive/YYYY-MM-DD-<name>/
2167
+ **Specs:** ✓ Synced to main specs (or "No delta specs" or "Sync skipped")
2168
+
2169
+ All artifacts complete. All tasks complete.
2170
+ \`\`\`
2171
+
2172
+ **Guardrails**
2173
+ - Always prompt for change selection if not provided
2174
+ - Use artifact graph (openspec status --json) for completion checking
2175
+ - Don't block archive on warnings - just inform and confirm
2176
+ - Preserve .openspec.yaml when moving to archive (it moves with the directory)
2177
+ - Show clear summary of what happened
2178
+ - If sync is requested, use openspec-sync-specs approach (agent-driven)
2179
+ - If delta specs exist, always run the sync assessment and show the combined summary before prompting`,
2180
+ license: "MIT",
2181
+ compatibility: "Requires openspec CLI.",
2182
+ metadata: { author: "openspec", version: "1.0" },
2183
+ };
2184
+ }
2185
+ /**
2186
+ * Template for openspec-bulk-archive-change skill
2187
+ * For archiving multiple completed changes at once
2188
+ */
2189
+ export function getBulkArchiveChangeSkillTemplate() {
2190
+ return {
2191
+ name: "openspec-bulk-archive-change",
2192
+ description: "一次性归档多个已完成的变更。适用于并行多个变更一起收尾时。",
2193
+ instructions: `Archive multiple completed changes in a single operation.
2194
+
2195
+ This skill allows you to batch-archive changes, handling spec conflicts intelligently by checking the codebase to determine what's actually implemented.
2196
+
2197
+ **Input**: None required (prompts for selection)
2198
+
2199
+ **Steps**
2200
+
2201
+ 1. **Get active changes**
2202
+
2203
+ Run \`openspec list --json\` to get all active changes.
2204
+
2205
+ If no active changes exist, inform user and stop.
2206
+
2207
+ 2. **Prompt for change selection**
2208
+
2209
+ Use **AskUserQuestion tool** with multi-select to let user choose changes:
2210
+ - Show each change with its schema
2211
+ - Include an option for "All changes"
2212
+ - Allow any number of selections (1+ works, 2+ is the typical use case)
2213
+
2214
+ **IMPORTANT**: Do NOT auto-select. Always let the user choose.
2215
+
2216
+ 3. **Batch validation - gather status for all selected changes**
2217
+
2218
+ For each selected change, collect:
2219
+
2220
+ a. **Artifact status** - Run \`openspec status --change "<name>" --json\`
2221
+ - Parse \`schemaName\` and \`artifacts\` list
2222
+ - Note which artifacts are \`done\` vs other states
2223
+
2224
+ b. **Task completion** - Read \`openspec/changes/<name>/tasks.md\`
2225
+ - Count \`- [ ]\` (incomplete) vs \`- [x]\` (complete)
2226
+ - If no tasks file exists, note as "No tasks"
2227
+
2228
+ c. **Delta specs** - Check \`openspec/changes/<name>/specs/\` directory
2229
+ - List which capability specs exist
2230
+ - For each, extract requirement names (lines matching \`### Requirement: <name>\`)
2231
+
2232
+ 4. **Detect spec conflicts**
2233
+
2234
+ Build a map of \`capability -> [changes that touch it]\`:
2235
+
2236
+ \`\`\`
2237
+ auth -> [change-a, change-b] <- CONFLICT (2+ changes)
2238
+ api -> [change-c] <- OK (only 1 change)
2239
+ \`\`\`
2240
+
2241
+ A conflict exists when 2+ selected changes have delta specs for the same capability.
2242
+
2243
+ 5. **Resolve conflicts agentically**
2244
+
2245
+ **For each conflict**, investigate the codebase:
2246
+
2247
+ a. **Read the delta specs** from each conflicting change to understand what each claims to add/modify
2248
+
2249
+ b. **Search the codebase** for implementation evidence:
2250
+ - Look for code implementing requirements from each delta spec
2251
+ - Check for related files, functions, or tests
2252
+
2253
+ c. **Determine resolution**:
2254
+ - If only one change is actually implemented -> sync that one's specs
2255
+ - If both implemented -> apply in chronological order (older first, newer overwrites)
2256
+ - If neither implemented -> skip spec sync, warn user
2257
+
2258
+ d. **Record resolution** for each conflict:
2259
+ - Which change's specs to apply
2260
+ - In what order (if both)
2261
+ - Rationale (what was found in codebase)
2262
+
2263
+ 6. **Show consolidated status table**
2264
+
2265
+ Display a table summarizing all changes:
2266
+
2267
+ \`\`\`
2268
+ | Change | Artifacts | Tasks | Specs | Conflicts | Status |
2269
+ |---------------------|-----------|-------|---------|-----------|--------|
2270
+ | schema-management | Done | 5/5 | 2 delta | None | Ready |
2271
+ | project-config | Done | 3/3 | 1 delta | None | Ready |
2272
+ | add-oauth | Done | 4/4 | 1 delta | auth (!) | Ready* |
2273
+ | add-verify-skill | 1 left | 2/5 | None | None | Warn |
2274
+ \`\`\`
2275
+
2276
+ For conflicts, show the resolution:
2277
+ \`\`\`
2278
+ * Conflict resolution:
2279
+ - auth spec: Will apply add-oauth then add-jwt (both implemented, chronological order)
2280
+ \`\`\`
2281
+
2282
+ For incomplete changes, show warnings:
2283
+ \`\`\`
2284
+ Warnings:
2285
+ - add-verify-skill: 1 incomplete artifact, 3 incomplete tasks
2286
+ \`\`\`
2287
+
2288
+ 7. **Confirm batch operation**
2289
+
2290
+ Use **AskUserQuestion tool** with a single confirmation:
2291
+
2292
+ - "Archive N changes?" with options based on status
2293
+ - Options might include:
2294
+ - "Archive all N changes"
2295
+ - "Archive only N ready changes (skip incomplete)"
2296
+ - "Cancel"
2297
+
2298
+ If there are incomplete changes, make clear they'll be archived with warnings.
2299
+
2300
+ 8. **Execute archive for each confirmed change**
2301
+
2302
+ Process changes in the determined order (respecting conflict resolution):
2303
+
2304
+ a. **Sync specs** if delta specs exist:
2305
+ - Use the openspec-sync-specs approach (agent-driven intelligent merge)
2306
+ - For conflicts, apply in resolved order
2307
+ - Track if sync was done
2308
+
2309
+ b. **Perform the archive**:
2310
+ \`\`\`bash
2311
+ mkdir -p openspec/changes/archive
2312
+ mv openspec/changes/<name> openspec/changes/archive/YYYY-MM-DD-<name>
2313
+ \`\`\`
2314
+
2315
+ c. **Track outcome** for each change:
2316
+ - Success: archived successfully
2317
+ - Failed: error during archive (record error)
2318
+ - Skipped: user chose not to archive (if applicable)
2319
+
2320
+ 9. **Display summary**
2321
+
2322
+ Show final results:
2323
+
2324
+ \`\`\`
2325
+ ## Bulk Archive Complete
2326
+
2327
+ Archived 3 changes:
2328
+ - schema-management-cli -> archive/2026-01-19-schema-management-cli/
2329
+ - project-config -> archive/2026-01-19-project-config/
2330
+ - add-oauth -> archive/2026-01-19-add-oauth/
2331
+
2332
+ Skipped 1 change:
2333
+ - add-verify-skill (user chose not to archive incomplete)
2334
+
2335
+ Spec sync summary:
2336
+ - 4 delta specs synced to main specs
2337
+ - 1 conflict resolved (auth: applied both in chronological order)
2338
+ \`\`\`
2339
+
2340
+ If any failures:
2341
+ \`\`\`
2342
+ Failed 1 change:
2343
+ - some-change: Archive directory already exists
2344
+ \`\`\`
2345
+
2346
+ **Conflict Resolution Examples**
2347
+
2348
+ Example 1: Only one implemented
2349
+ \`\`\`
2350
+ Conflict: specs/auth/spec.md touched by [add-oauth, add-jwt]
2351
+
2352
+ Checking add-oauth:
2353
+ - Delta adds "OAuth Provider Integration" requirement
2354
+ - Searching codebase... found src/auth/oauth.ts implementing OAuth flow
2355
+
2356
+ Checking add-jwt:
2357
+ - Delta adds "JWT Token Handling" requirement
2358
+ - Searching codebase... no JWT implementation found
2359
+
2360
+ Resolution: Only add-oauth is implemented. Will sync add-oauth specs only.
2361
+ \`\`\`
2362
+
2363
+ Example 2: Both implemented
2364
+ \`\`\`
2365
+ Conflict: specs/api/spec.md touched by [add-rest-api, add-graphql]
2366
+
2367
+ Checking add-rest-api (created 2026-01-10):
2368
+ - Delta adds "REST Endpoints" requirement
2369
+ - Searching codebase... found src/api/rest.ts
2370
+
2371
+ Checking add-graphql (created 2026-01-15):
2372
+ - Delta adds "GraphQL Schema" requirement
2373
+ - Searching codebase... found src/api/graphql.ts
2374
+
2375
+ Resolution: Both implemented. Will apply add-rest-api specs first,
2376
+ then add-graphql specs (chronological order, newer takes precedence).
2377
+ \`\`\`
2378
+
2379
+ **Output On Success**
2380
+
2381
+ \`\`\`
2382
+ ## Bulk Archive Complete
2383
+
2384
+ Archived N changes:
2385
+ - <change-1> -> archive/YYYY-MM-DD-<change-1>/
2386
+ - <change-2> -> archive/YYYY-MM-DD-<change-2>/
2387
+
2388
+ Spec sync summary:
2389
+ - N delta specs synced to main specs
2390
+ - No conflicts (or: M conflicts resolved)
2391
+ \`\`\`
2392
+
2393
+ **Output On Partial Success**
2394
+
2395
+ \`\`\`
2396
+ ## Bulk Archive Complete (partial)
2397
+
2398
+ Archived N changes:
2399
+ - <change-1> -> archive/YYYY-MM-DD-<change-1>/
2400
+
2401
+ Skipped M changes:
2402
+ - <change-2> (user chose not to archive incomplete)
2403
+
2404
+ Failed K changes:
2405
+ - <change-3>: Archive directory already exists
2406
+ \`\`\`
2407
+
2408
+ **Output When No Changes**
2409
+
2410
+ \`\`\`
2411
+ ## No Changes to Archive
2412
+
2413
+ No active changes found. Use \`/opsx:new\` to create a new change.
2414
+ \`\`\`
2415
+
2416
+ **Guardrails**
2417
+ - Allow any number of changes (1+ is fine, 2+ is the typical use case)
2418
+ - Always prompt for selection, never auto-select
2419
+ - Detect spec conflicts early and resolve by checking codebase
2420
+ - When both changes are implemented, apply specs in chronological order
2421
+ - Skip spec sync only when implementation is missing (warn user)
2422
+ - Show clear per-change status before confirming
2423
+ - Use single confirmation for entire batch
2424
+ - Track and report all outcomes (success/skip/fail)
2425
+ - Preserve .openspec.yaml when moving to archive
2426
+ - Archive directory target uses current date: YYYY-MM-DD-<name>
2427
+ - If archive target exists, fail that change but continue with others`,
2428
+ license: "MIT",
2429
+ compatibility: "Requires openspec CLI.",
2430
+ metadata: { author: "openspec", version: "1.0" },
2431
+ };
2432
+ }
2433
+ /**
2434
+ * Template for /opsx:sync slash command
2435
+ */
2436
+ export function getOpsxSyncCommandTemplate() {
2437
+ return {
2438
+ name: "OPSX: Sync",
2439
+ description: "将变更的增量规范同步到主规范",
2440
+ category: "Workflow",
2441
+ tags: ["workflow", "specs", "experimental"],
2442
+ content: `Sync delta specs from a change to main specs.
2443
+
2444
+ 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).
2445
+
2446
+ **Input**: Optionally specify a change name after \`/opsx:sync\` (e.g., \`/opsx:sync add-auth\`). If omitted, check if it can be inferred from conversation context. If vague or ambiguous you MUST prompt for available changes.
2447
+
2448
+ **Steps**
2449
+
2450
+ 1. **If no change name provided, prompt for selection**
2451
+
2452
+ Run \`openspec list --json\` to get available changes. Use the **AskUserQuestion tool** to let the user select.
2453
+
2454
+ Show changes that have delta specs (under \`specs/\` directory).
2455
+
2456
+ **IMPORTANT**: Do NOT guess or auto-select a change. Always let the user choose.
2457
+
2458
+ 2. **Find delta specs**
2459
+
2460
+ Look for delta spec files in \`openspec/changes/<name>/specs/*/spec.md\`.
2461
+
2462
+ Each delta spec file contains sections like:
2463
+ - \`## ADDED Requirements\` - New requirements to add
2464
+ - \`## MODIFIED Requirements\` - Changes to existing requirements
2465
+ - \`## REMOVED Requirements\` - Requirements to remove
2466
+ - \`## RENAMED Requirements\` - Requirements to rename (FROM:/TO: format)
2467
+
2468
+ If no delta specs found, inform user and stop.
2469
+
2470
+ 3. **For each delta spec, apply changes to main specs**
2471
+
2472
+ For each capability with a delta spec at \`openspec/changes/<name>/specs/<capability>/spec.md\`:
2473
+
2474
+ a. **Read the delta spec** to understand the intended changes
2475
+
2476
+ b. **Read the main spec** at \`openspec/specs/<capability>/spec.md\` (may not exist yet)
2477
+
2478
+ c. **Apply changes intelligently**:
2479
+
2480
+ **ADDED Requirements:**
2481
+ - If requirement doesn't exist in main spec → add it
2482
+ - If requirement already exists → update it to match (treat as implicit MODIFIED)
2483
+
2484
+ **MODIFIED Requirements:**
2485
+ - Find the requirement in main spec
2486
+ - Apply the changes - this can be:
2487
+ - Adding new scenarios (don't need to copy existing ones)
2488
+ - Modifying existing scenarios
2489
+ - Changing the requirement description
2490
+ - Preserve scenarios/content not mentioned in the delta
2491
+
2492
+ **REMOVED Requirements:**
2493
+ - Remove the entire requirement block from main spec
2494
+
2495
+ **RENAMED Requirements:**
2496
+ - Find the FROM requirement, rename to TO
2497
+
2498
+ d. **Create new main spec** if capability doesn't exist yet:
2499
+ - Create \`openspec/specs/<capability>/spec.md\`
2500
+ - Add Purpose section (can be brief, mark as TBD)
2501
+ - Add Requirements section with the ADDED requirements
2502
+
2503
+ 4. **Show summary**
2504
+
2505
+ After applying all changes, summarize:
2506
+ - Which capabilities were updated
2507
+ - What changes were made (requirements added/modified/removed/renamed)
2508
+
2509
+ **Delta Spec Format Reference**
2510
+
2511
+ \`\`\`markdown
2512
+ ## ADDED Requirements
2513
+
2514
+ ### Requirement: New Feature
2515
+ The system SHALL do something new.
2516
+
2517
+ #### Scenario: Basic case
2518
+ - **WHEN** user does X
2519
+ - **THEN** system does Y
2520
+
2521
+ ## MODIFIED Requirements
2522
+
2523
+ ### Requirement: Existing Feature
2524
+ #### Scenario: New scenario to add
2525
+ - **WHEN** user does A
2526
+ - **THEN** system does B
2527
+
2528
+ ## REMOVED Requirements
2529
+
2530
+ ### Requirement: Deprecated Feature
2531
+
2532
+ ## RENAMED Requirements
2533
+
2534
+ - FROM: \`### Requirement: Old Name\`
2535
+ - TO: \`### Requirement: New Name\`
2536
+ \`\`\`
2537
+
2538
+ **Key Principle: Intelligent Merging**
2539
+
2540
+ Unlike programmatic merging, you can apply **partial updates**:
2541
+ - To add a scenario, just include that scenario under MODIFIED - don't copy existing scenarios
2542
+ - The delta represents *intent*, not a wholesale replacement
2543
+ - Use your judgment to merge changes sensibly
2544
+
2545
+ **Output On Success**
2546
+
2547
+ \`\`\`
2548
+ ## Specs Synced: <change-name>
2549
+
2550
+ Updated main specs:
2551
+
2552
+ **<capability-1>**:
2553
+ - Added requirement: "New Feature"
2554
+ - Modified requirement: "Existing Feature" (added 1 scenario)
2555
+
2556
+ **<capability-2>**:
2557
+ - Created new spec file
2558
+ - Added requirement: "Another Feature"
2559
+
2560
+ Main specs are now updated. The change remains active - archive when implementation is complete.
2561
+ \`\`\`
2562
+
2563
+ **Guardrails**
2564
+ - Read both delta and main specs before making changes
2565
+ - Preserve existing content not mentioned in delta
2566
+ - If something is unclear, ask for clarification
2567
+ - Show what you're changing as you go
2568
+ - The operation should be idempotent - running twice should give same result`,
2569
+ };
2570
+ }
2571
+ /**
2572
+ * Template for openspec-verify-change skill
2573
+ * For verifying implementation matches change artifacts before archiving
2574
+ */
2575
+ export function getVerifyChangeSkillTemplate() {
2576
+ return {
2577
+ name: "openspec-verify-change",
2578
+ description: "校验实现与变更制品是否一致。适用于归档前确认实现完整、正确且一致时。",
2579
+ instructions: `Verify that an implementation matches the change artifacts (specs, tasks, design).
2580
+
2581
+ **Input**: Optionally specify a change name. If omitted, check if it can be inferred from conversation context. If vague or ambiguous you MUST prompt for available changes.
2582
+
2583
+ **Steps**
2584
+
2585
+ 1. **If no change name provided, prompt for selection**
2586
+
2587
+ Run \`openspec list --json\` to get available changes. Use the **AskUserQuestion tool** to let the user select.
2588
+
2589
+ Show changes that have implementation tasks (tasks artifact exists).
2590
+ Include the schema used for each change if available.
2591
+ Mark changes with incomplete tasks as "(In Progress)".
2592
+
2593
+ **IMPORTANT**: Do NOT guess or auto-select a change. Always let the user choose.
2594
+
2595
+ 2. **Check status to understand the schema**
2596
+ \`\`\`bash
2597
+ openspec status --change "<name>" --json
2598
+ \`\`\`
2599
+ Parse the JSON to understand:
2600
+ - \`schemaName\`: The workflow being used (e.g., "spec-driven")
2601
+ - Which artifacts exist for this change
2602
+
2603
+ 3. **Get the change directory and load artifacts**
2604
+
2605
+ \`\`\`bash
2606
+ openspec instructions apply --change "<name>" --json
2607
+ \`\`\`
2608
+
2609
+ This returns the change directory and context files. Read all available artifacts from \`contextFiles\`.
2610
+
2611
+ 4. **Initialize verification report structure**
2612
+
2613
+ Create a report structure with three dimensions:
2614
+ - **Completeness**: Track tasks and spec coverage
2615
+ - **Correctness**: Track requirement implementation and scenario coverage
2616
+ - **Coherence**: Track design adherence and pattern consistency
2617
+
2618
+ Each dimension can have CRITICAL, WARNING, or SUGGESTION issues.
2619
+
2620
+ 5. **Verify Completeness**
2621
+
2622
+ **Task Completion**:
2623
+ - If tasks.md exists in contextFiles, read it
2624
+ - Parse checkboxes: \`- [ ]\` (incomplete) vs \`- [x]\` (complete)
2625
+ - Count complete vs total tasks
2626
+ - If incomplete tasks exist:
2627
+ - Add CRITICAL issue for each incomplete task
2628
+ - Recommendation: "Complete task: <description>" or "Mark as done if already implemented"
2629
+
2630
+ **Spec Coverage**:
2631
+ - If delta specs exist in \`openspec/changes/<name>/specs/\`:
2632
+ - Extract all requirements (marked with "### Requirement:")
2633
+ - For each requirement:
2634
+ - Search codebase for keywords related to the requirement
2635
+ - Assess if implementation likely exists
2636
+ - If requirements appear unimplemented:
2637
+ - Add CRITICAL issue: "Requirement not found: <requirement name>"
2638
+ - Recommendation: "Implement requirement X: <description>"
2639
+
2640
+ 6. **Verify Correctness**
2641
+
2642
+ **Requirement Implementation Mapping**:
2643
+ - For each requirement from delta specs:
2644
+ - Search codebase for implementation evidence
2645
+ - If found, note file paths and line ranges
2646
+ - Assess if implementation matches requirement intent
2647
+ - If divergence detected:
2648
+ - Add WARNING: "Implementation may diverge from spec: <details>"
2649
+ - Recommendation: "Review <file>:<lines> against requirement X"
2650
+
2651
+ **Scenario Coverage**:
2652
+ - For each scenario in delta specs (marked with "#### Scenario:"):
2653
+ - Check if conditions are handled in code
2654
+ - Check if tests exist covering the scenario
2655
+ - If scenario appears uncovered:
2656
+ - Add WARNING: "Scenario not covered: <scenario name>"
2657
+ - Recommendation: "Add test or implementation for scenario: <description>"
2658
+
2659
+ 7. **Verify Coherence**
2660
+
2661
+ **Design Adherence**:
2662
+ - If design.md exists in contextFiles:
2663
+ - Extract key decisions (look for sections like "Decision:", "Approach:", "Architecture:")
2664
+ - Verify implementation follows those decisions
2665
+ - If contradiction detected:
2666
+ - Add WARNING: "Design decision not followed: <decision>"
2667
+ - Recommendation: "Update implementation or revise design.md to match reality"
2668
+ - If no design.md: Skip design adherence check, note "No design.md to verify against"
2669
+
2670
+ **Code Pattern Consistency**:
2671
+ - Review new code for consistency with project patterns
2672
+ - Check file naming, directory structure, coding style
2673
+ - If significant deviations found:
2674
+ - Add SUGGESTION: "Code pattern deviation: <details>"
2675
+ - Recommendation: "Consider following project pattern: <example>"
2676
+
2677
+ 8. **Generate Verification Report**
2678
+
2679
+ **Summary Scorecard**:
2680
+ \`\`\`
2681
+ ## Verification Report: <change-name>
2682
+
2683
+ ### Summary
2684
+ | Dimension | Status |
2685
+ |--------------|------------------|
2686
+ | Completeness | X/Y tasks, N reqs|
2687
+ | Correctness | M/N reqs covered |
2688
+ | Coherence | Followed/Issues |
2689
+ \`\`\`
2690
+
2691
+ **Issues by Priority**:
2692
+
2693
+ 1. **CRITICAL** (Must fix before archive):
2694
+ - Incomplete tasks
2695
+ - Missing requirement implementations
2696
+ - Each with specific, actionable recommendation
2697
+
2698
+ 2. **WARNING** (Should fix):
2699
+ - Spec/design divergences
2700
+ - Missing scenario coverage
2701
+ - Each with specific recommendation
2702
+
2703
+ 3. **SUGGESTION** (Nice to fix):
2704
+ - Pattern inconsistencies
2705
+ - Minor improvements
2706
+ - Each with specific recommendation
2707
+
2708
+ **Final Assessment**:
2709
+ - If CRITICAL issues: "X critical issue(s) found. Fix before archiving."
2710
+ - If only warnings: "No critical issues. Y warning(s) to consider. Ready for archive (with noted improvements)."
2711
+ - If all clear: "All checks passed. Ready for archive."
2712
+
2713
+ **Verification Heuristics**
2714
+
2715
+ - **Completeness**: Focus on objective checklist items (checkboxes, requirements list)
2716
+ - **Correctness**: Use keyword search, file path analysis, reasonable inference - don't require perfect certainty
2717
+ - **Coherence**: Look for glaring inconsistencies, don't nitpick style
2718
+ - **False Positives**: When uncertain, prefer SUGGESTION over WARNING, WARNING over CRITICAL
2719
+ - **Actionability**: Every issue must have a specific recommendation with file/line references where applicable
2720
+
2721
+ **Graceful Degradation**
2722
+
2723
+ - If only tasks.md exists: verify task completion only, skip spec/design checks
2724
+ - If tasks + specs exist: verify completeness and correctness, skip design
2725
+ - If full artifacts: verify all three dimensions
2726
+ - Always note which checks were skipped and why
2727
+
2728
+ **Output Format**
2729
+
2730
+ Use clear markdown with:
2731
+ - Table for summary scorecard
2732
+ - Grouped lists for issues (CRITICAL/WARNING/SUGGESTION)
2733
+ - Code references in format: \`file.ts:123\`
2734
+ - Specific, actionable recommendations
2735
+ - No vague suggestions like "consider reviewing"`,
2736
+ license: "MIT",
2737
+ compatibility: "Requires openspec CLI.",
2738
+ metadata: { author: "openspec", version: "1.0" },
2739
+ };
2740
+ }
2741
+ /**
2742
+ * Template for /opsx:archive slash command
2743
+ */
2744
+ export function getOpsxArchiveCommandTemplate() {
2745
+ return {
2746
+ name: "OPSX: Archive",
2747
+ description: "归档已完成的变更",
2748
+ category: "Workflow",
2749
+ tags: ["workflow", "archive", "experimental"],
2750
+ content: `Archive a completed change in the experimental workflow.
2751
+
2752
+ **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.
2753
+
2754
+ **Steps**
2755
+
2756
+ 1. **If no change name provided, prompt for selection**
2757
+
2758
+ Run \`openspec list --json\` to get available changes. Use the **AskUserQuestion tool** to let the user select.
2759
+
2760
+ Show only active changes (not already archived).
2761
+ Include the schema used for each change if available.
2762
+
2763
+ **IMPORTANT**: Do NOT guess or auto-select a change. Always let the user choose.
2764
+
2765
+ 2. **Check artifact completion status**
2766
+
2767
+ Run \`openspec status --change "<name>" --json\` to check artifact completion.
2768
+
2769
+ Parse the JSON to understand:
2770
+ - \`schemaName\`: The workflow being used
2771
+ - \`artifacts\`: List of artifacts with their status (\`done\` or other)
2772
+
2773
+ **If any artifacts are not \`done\`:**
2774
+ - Display warning listing incomplete artifacts
2775
+ - Prompt user for confirmation to continue
2776
+ - Proceed if user confirms
2777
+
2778
+ 3. **Check task completion status**
2779
+
2780
+ Read the tasks file (typically \`tasks.md\`) to check for incomplete tasks.
2781
+
2782
+ Count tasks marked with \`- [ ]\` (incomplete) vs \`- [x]\` (complete).
2783
+
2784
+ **If incomplete tasks found:**
2785
+ - Display warning showing count of incomplete tasks
2786
+ - Prompt user for confirmation to continue
2787
+ - Proceed if user confirms
2788
+
2789
+ **If no tasks file exists:** Proceed without task-related warning.
2790
+
2791
+ 4. **Assess delta spec sync state**
2792
+
2793
+ Check for delta specs at \`openspec/changes/<name>/specs/\`. If none exist, proceed without sync prompt.
2794
+
2795
+ **If delta specs exist:**
2796
+ - Compare each delta spec with its corresponding main spec at \`openspec/specs/<capability>/spec.md\`
2797
+ - Determine what changes would be applied (adds, modifications, removals, renames)
2798
+ - Show a combined summary before prompting
2799
+
2800
+ **Prompt options:**
2801
+ - If changes needed: "Sync now (recommended)", "Archive without syncing"
2802
+ - If already synced: "Archive now", "Sync anyway", "Cancel"
2803
+
2804
+ If user chooses sync, use Task tool (subagent_type: "general-purpose", prompt: "Use Skill tool to invoke openspec-sync-specs for change '<name>'. Delta spec analysis: <include the analyzed delta spec summary>"). Proceed to archive regardless of choice.
2805
+
2806
+ 5. **Perform the archive**
2807
+
2808
+ Create the archive directory if it doesn't exist:
2809
+ \`\`\`bash
2810
+ mkdir -p openspec/changes/archive
2811
+ \`\`\`
2812
+
2813
+ Generate target name using current date: \`YYYY-MM-DD-<change-name>\`
2814
+
2815
+ **Check if target already exists:**
2816
+ - If yes: Fail with error, suggest renaming existing archive or using different date
2817
+ - If no: Move the change directory to archive
2818
+
2819
+ \`\`\`bash
2820
+ mv openspec/changes/<name> openspec/changes/archive/YYYY-MM-DD-<name>
2821
+ \`\`\`
2822
+
2823
+ 6. **Display summary**
2824
+
2825
+ Show archive completion summary including:
2826
+ - Change name
2827
+ - Schema that was used
2828
+ - Archive location
2829
+ - Spec sync status (synced / sync skipped / no delta specs)
2830
+ - Note about any warnings (incomplete artifacts/tasks)
2831
+
2832
+ **Output On Success**
2833
+
2834
+ \`\`\`
2835
+ ## Archive Complete
2836
+
2837
+ **Change:** <change-name>
2838
+ **Schema:** <schema-name>
2839
+ **Archived to:** openspec/changes/archive/YYYY-MM-DD-<name>/
2840
+ **Specs:** ✓ Synced to main specs
2841
+
2842
+ All artifacts complete. All tasks complete.
2843
+ \`\`\`
2844
+
2845
+ **Output On Success (No Delta Specs)**
2846
+
2847
+ \`\`\`
2848
+ ## Archive Complete
2849
+
2850
+ **Change:** <change-name>
2851
+ **Schema:** <schema-name>
2852
+ **Archived to:** openspec/changes/archive/YYYY-MM-DD-<name>/
2853
+ **Specs:** No delta specs
2854
+
2855
+ All artifacts complete. All tasks complete.
2856
+ \`\`\`
2857
+
2858
+ **Output On Success With Warnings**
2859
+
2860
+ \`\`\`
2861
+ ## Archive Complete (with warnings)
2862
+
2863
+ **Change:** <change-name>
2864
+ **Schema:** <schema-name>
2865
+ **Archived to:** openspec/changes/archive/YYYY-MM-DD-<name>/
2866
+ **Specs:** Sync skipped (user chose to skip)
2867
+
2868
+ **Warnings:**
2869
+ - Archived with 2 incomplete artifacts
2870
+ - Archived with 3 incomplete tasks
2871
+ - Delta spec sync was skipped (user chose to skip)
2872
+
2873
+ Review the archive if this was not intentional.
2874
+ \`\`\`
2875
+
2876
+ **Output On Error (Archive Exists)**
2877
+
2878
+ \`\`\`
2879
+ ## Archive Failed
2880
+
2881
+ **Change:** <change-name>
2882
+ **Target:** openspec/changes/archive/YYYY-MM-DD-<name>/
2883
+
2884
+ Target archive directory already exists.
2885
+
2886
+ **Options:**
2887
+ 1. Rename the existing archive
2888
+ 2. Delete the existing archive if it's a duplicate
2889
+ 3. Wait until a different date to archive
2890
+ \`\`\`
2891
+
2892
+ **Guardrails**
2893
+ - Always prompt for change selection if not provided
2894
+ - Use artifact graph (openspec status --json) for completion checking
2895
+ - Don't block archive on warnings - just inform and confirm
2896
+ - Preserve .openspec.yaml when moving to archive (it moves with the directory)
2897
+ - Show clear summary of what happened
2898
+ - If sync is requested, use the Skill tool to invoke \`openspec-sync-specs\` (agent-driven)
2899
+ - If delta specs exist, always run the sync assessment and show the combined summary before prompting`,
2900
+ };
2901
+ }
2902
+ /**
2903
+ * Template for /opsx:onboard slash command
2904
+ * Guided onboarding through the complete OpenSpec workflow
2905
+ */
2906
+ export function getOpsxOnboardCommandTemplate() {
2907
+ return {
2908
+ name: "OPSX: Onboard",
2909
+ description: "引导入门:带讲解走完完整 OpenSpec 工作流",
2910
+ category: "Workflow",
2911
+ tags: ["workflow", "onboarding", "tutorial", "learning"],
2912
+ content: getOnboardInstructions(),
2913
+ };
2914
+ }
2915
+ /**
2916
+ * Template for /opsx:bulk-archive slash command
2917
+ */
2918
+ export function getOpsxBulkArchiveCommandTemplate() {
2919
+ return {
2920
+ name: "OPSX: Bulk Archive",
2921
+ description: "一次性归档多个已完成的变更",
2922
+ category: "Workflow",
2923
+ tags: ["workflow", "archive", "experimental", "bulk"],
2924
+ content: `Archive multiple completed changes in a single operation.
2925
+
2926
+ This skill allows you to batch-archive changes, handling spec conflicts intelligently by checking the codebase to determine what's actually implemented.
2927
+
2928
+ **Input**: None required (prompts for selection)
2929
+
2930
+ **Steps**
2931
+
2932
+ 1. **Get active changes**
2933
+
2934
+ Run \`openspec list --json\` to get all active changes.
2935
+
2936
+ If no active changes exist, inform user and stop.
2937
+
2938
+ 2. **Prompt for change selection**
2939
+
2940
+ Use **AskUserQuestion tool** with multi-select to let user choose changes:
2941
+ - Show each change with its schema
2942
+ - Include an option for "All changes"
2943
+ - Allow any number of selections (1+ works, 2+ is the typical use case)
2944
+
2945
+ **IMPORTANT**: Do NOT auto-select. Always let the user choose.
2946
+
2947
+ 3. **Batch validation - gather status for all selected changes**
2948
+
2949
+ For each selected change, collect:
2950
+
2951
+ a. **Artifact status** - Run \`openspec status --change "<name>" --json\`
2952
+ - Parse \`schemaName\` and \`artifacts\` list
2953
+ - Note which artifacts are \`done\` vs other states
2954
+
2955
+ b. **Task completion** - Read \`openspec/changes/<name>/tasks.md\`
2956
+ - Count \`- [ ]\` (incomplete) vs \`- [x]\` (complete)
2957
+ - If no tasks file exists, note as "No tasks"
2958
+
2959
+ c. **Delta specs** - Check \`openspec/changes/<name>/specs/\` directory
2960
+ - List which capability specs exist
2961
+ - For each, extract requirement names (lines matching \`### Requirement: <name>\`)
2962
+
2963
+ 4. **Detect spec conflicts**
2964
+
2965
+ Build a map of \`capability -> [changes that touch it]\`:
2966
+
2967
+ \`\`\`
2968
+ auth -> [change-a, change-b] <- CONFLICT (2+ changes)
2969
+ api -> [change-c] <- OK (only 1 change)
2970
+ \`\`\`
2971
+
2972
+ A conflict exists when 2+ selected changes have delta specs for the same capability.
2973
+
2974
+ 5. **Resolve conflicts agentically**
2975
+
2976
+ **For each conflict**, investigate the codebase:
2977
+
2978
+ a. **Read the delta specs** from each conflicting change to understand what each claims to add/modify
2979
+
2980
+ b. **Search the codebase** for implementation evidence:
2981
+ - Look for code implementing requirements from each delta spec
2982
+ - Check for related files, functions, or tests
2983
+
2984
+ c. **Determine resolution**:
2985
+ - If only one change is actually implemented -> sync that one's specs
2986
+ - If both implemented -> apply in chronological order (older first, newer overwrites)
2987
+ - If neither implemented -> skip spec sync, warn user
2988
+
2989
+ d. **Record resolution** for each conflict:
2990
+ - Which change's specs to apply
2991
+ - In what order (if both)
2992
+ - Rationale (what was found in codebase)
2993
+
2994
+ 6. **Show consolidated status table**
2995
+
2996
+ Display a table summarizing all changes:
2997
+
2998
+ \`\`\`
2999
+ | Change | Artifacts | Tasks | Specs | Conflicts | Status |
3000
+ |---------------------|-----------|-------|---------|-----------|--------|
3001
+ | schema-management | Done | 5/5 | 2 delta | None | Ready |
3002
+ | project-config | Done | 3/3 | 1 delta | None | Ready |
3003
+ | add-oauth | Done | 4/4 | 1 delta | auth (!) | Ready* |
3004
+ | add-verify-skill | 1 left | 2/5 | None | None | Warn |
3005
+ \`\`\`
3006
+
3007
+ For conflicts, show the resolution:
3008
+ \`\`\`
3009
+ * Conflict resolution:
3010
+ - auth spec: Will apply add-oauth then add-jwt (both implemented, chronological order)
3011
+ \`\`\`
3012
+
3013
+ For incomplete changes, show warnings:
3014
+ \`\`\`
3015
+ Warnings:
3016
+ - add-verify-skill: 1 incomplete artifact, 3 incomplete tasks
3017
+ \`\`\`
3018
+
3019
+ 7. **Confirm batch operation**
3020
+
3021
+ Use **AskUserQuestion tool** with a single confirmation:
3022
+
3023
+ - "Archive N changes?" with options based on status
3024
+ - Options might include:
3025
+ - "Archive all N changes"
3026
+ - "Archive only N ready changes (skip incomplete)"
3027
+ - "Cancel"
3028
+
3029
+ If there are incomplete changes, make clear they'll be archived with warnings.
3030
+
3031
+ 8. **Execute archive for each confirmed change**
3032
+
3033
+ Process changes in the determined order (respecting conflict resolution):
3034
+
3035
+ a. **Sync specs** if delta specs exist:
3036
+ - Use the openspec-sync-specs approach (agent-driven intelligent merge)
3037
+ - For conflicts, apply in resolved order
3038
+ - Track if sync was done
3039
+
3040
+ b. **Perform the archive**:
3041
+ \`\`\`bash
3042
+ mkdir -p openspec/changes/archive
3043
+ mv openspec/changes/<name> openspec/changes/archive/YYYY-MM-DD-<name>
3044
+ \`\`\`
3045
+
3046
+ c. **Track outcome** for each change:
3047
+ - Success: archived successfully
3048
+ - Failed: error during archive (record error)
3049
+ - Skipped: user chose not to archive (if applicable)
3050
+
3051
+ 9. **Display summary**
3052
+
3053
+ Show final results:
3054
+
3055
+ \`\`\`
3056
+ ## Bulk Archive Complete
3057
+
3058
+ Archived 3 changes:
3059
+ - schema-management-cli -> archive/2026-01-19-schema-management-cli/
3060
+ - project-config -> archive/2026-01-19-project-config/
3061
+ - add-oauth -> archive/2026-01-19-add-oauth/
3062
+
3063
+ Skipped 1 change:
3064
+ - add-verify-skill (user chose not to archive incomplete)
3065
+
3066
+ Spec sync summary:
3067
+ - 4 delta specs synced to main specs
3068
+ - 1 conflict resolved (auth: applied both in chronological order)
3069
+ \`\`\`
3070
+
3071
+ If any failures:
3072
+ \`\`\`
3073
+ Failed 1 change:
3074
+ - some-change: Archive directory already exists
3075
+ \`\`\`
3076
+
3077
+ **Conflict Resolution Examples**
3078
+
3079
+ Example 1: Only one implemented
3080
+ \`\`\`
3081
+ Conflict: specs/auth/spec.md touched by [add-oauth, add-jwt]
3082
+
3083
+ Checking add-oauth:
3084
+ - Delta adds "OAuth Provider Integration" requirement
3085
+ - Searching codebase... found src/auth/oauth.ts implementing OAuth flow
3086
+
3087
+ Checking add-jwt:
3088
+ - Delta adds "JWT Token Handling" requirement
3089
+ - Searching codebase... no JWT implementation found
3090
+
3091
+ Resolution: Only add-oauth is implemented. Will sync add-oauth specs only.
3092
+ \`\`\`
3093
+
3094
+ Example 2: Both implemented
3095
+ \`\`\`
3096
+ Conflict: specs/api/spec.md touched by [add-rest-api, add-graphql]
3097
+
3098
+ Checking add-rest-api (created 2026-01-10):
3099
+ - Delta adds "REST Endpoints" requirement
3100
+ - Searching codebase... found src/api/rest.ts
3101
+
3102
+ Checking add-graphql (created 2026-01-15):
3103
+ - Delta adds "GraphQL Schema" requirement
3104
+ - Searching codebase... found src/api/graphql.ts
3105
+
3106
+ Resolution: Both implemented. Will apply add-rest-api specs first,
3107
+ then add-graphql specs (chronological order, newer takes precedence).
3108
+ \`\`\`
3109
+
3110
+ **Output On Success**
3111
+
3112
+ \`\`\`
3113
+ ## Bulk Archive Complete
3114
+
3115
+ Archived N changes:
3116
+ - <change-1> -> archive/YYYY-MM-DD-<change-1>/
3117
+ - <change-2> -> archive/YYYY-MM-DD-<change-2>/
3118
+
3119
+ Spec sync summary:
3120
+ - N delta specs synced to main specs
3121
+ - No conflicts (or: M conflicts resolved)
3122
+ \`\`\`
3123
+
3124
+ **Output On Partial Success**
3125
+
3126
+ \`\`\`
3127
+ ## Bulk Archive Complete (partial)
3128
+
3129
+ Archived N changes:
3130
+ - <change-1> -> archive/YYYY-MM-DD-<change-1>/
3131
+
3132
+ Skipped M changes:
3133
+ - <change-2> (user chose not to archive incomplete)
3134
+
3135
+ Failed K changes:
3136
+ - <change-3>: Archive directory already exists
3137
+ \`\`\`
3138
+
3139
+ **Output When No Changes**
3140
+
3141
+ \`\`\`
3142
+ ## No Changes to Archive
3143
+
3144
+ No active changes found. Use \`/opsx:new\` to create a new change.
3145
+ \`\`\`
3146
+
3147
+ **Guardrails**
3148
+ - Allow any number of changes (1+ is fine, 2+ is the typical use case)
3149
+ - Always prompt for selection, never auto-select
3150
+ - Detect spec conflicts early and resolve by checking codebase
3151
+ - When both changes are implemented, apply specs in chronological order
3152
+ - Skip spec sync only when implementation is missing (warn user)
3153
+ - Show clear per-change status before confirming
3154
+ - Use single confirmation for entire batch
3155
+ - Track and report all outcomes (success/skip/fail)
3156
+ - Preserve .openspec.yaml when moving to archive
3157
+ - Archive directory target uses current date: YYYY-MM-DD-<name>
3158
+ - If archive target exists, fail that change but continue with others`,
3159
+ };
3160
+ }
3161
+ /**
3162
+ * Template for /opsx:verify slash command
3163
+ */
3164
+ export function getOpsxVerifyCommandTemplate() {
3165
+ return {
3166
+ name: "OPSX: Verify",
3167
+ description: "归档前校验实现是否与变更制品一致",
3168
+ category: "Workflow",
3169
+ tags: ["workflow", "verify", "experimental"],
3170
+ content: `Verify that an implementation matches the change artifacts (specs, tasks, design).
3171
+
3172
+ **Input**: Optionally specify a change name after \`/opsx:verify\` (e.g., \`/opsx:verify add-auth\`). If omitted, check if it can be inferred from conversation context. If vague or ambiguous you MUST prompt for available changes.
3173
+
3174
+ **Steps**
3175
+
3176
+ 1. **If no change name provided, prompt for selection**
3177
+
3178
+ Run \`openspec list --json\` to get available changes. Use the **AskUserQuestion tool** to let the user select.
3179
+
3180
+ Show changes that have implementation tasks (tasks artifact exists).
3181
+ Include the schema used for each change if available.
3182
+ Mark changes with incomplete tasks as "(In Progress)".
3183
+
3184
+ **IMPORTANT**: Do NOT guess or auto-select a change. Always let the user choose.
3185
+
3186
+ 2. **Check status to understand the schema**
3187
+ \`\`\`bash
3188
+ openspec status --change "<name>" --json
3189
+ \`\`\`
3190
+ Parse the JSON to understand:
3191
+ - \`schemaName\`: The workflow being used (e.g., "spec-driven")
3192
+ - Which artifacts exist for this change
3193
+
3194
+ 3. **Get the change directory and load artifacts**
3195
+
3196
+ \`\`\`bash
3197
+ openspec instructions apply --change "<name>" --json
3198
+ \`\`\`
3199
+
3200
+ This returns the change directory and context files. Read all available artifacts from \`contextFiles\`.
3201
+
3202
+ 4. **Initialize verification report structure**
3203
+
3204
+ Create a report structure with three dimensions:
3205
+ - **Completeness**: Track tasks and spec coverage
3206
+ - **Correctness**: Track requirement implementation and scenario coverage
3207
+ - **Coherence**: Track design adherence and pattern consistency
3208
+
3209
+ Each dimension can have CRITICAL, WARNING, or SUGGESTION issues.
3210
+
3211
+ 5. **Verify Completeness**
3212
+
3213
+ **Task Completion**:
3214
+ - If tasks.md exists in contextFiles, read it
3215
+ - Parse checkboxes: \`- [ ]\` (incomplete) vs \`- [x]\` (complete)
3216
+ - Count complete vs total tasks
3217
+ - If incomplete tasks exist:
3218
+ - Add CRITICAL issue for each incomplete task
3219
+ - Recommendation: "Complete task: <description>" or "Mark as done if already implemented"
3220
+
3221
+ **Spec Coverage**:
3222
+ - If delta specs exist in \`openspec/changes/<name>/specs/\`:
3223
+ - Extract all requirements (marked with "### Requirement:")
3224
+ - For each requirement:
3225
+ - Search codebase for keywords related to the requirement
3226
+ - Assess if implementation likely exists
3227
+ - If requirements appear unimplemented:
3228
+ - Add CRITICAL issue: "Requirement not found: <requirement name>"
3229
+ - Recommendation: "Implement requirement X: <description>"
3230
+
3231
+ 6. **Verify Correctness**
3232
+
3233
+ **Requirement Implementation Mapping**:
3234
+ - For each requirement from delta specs:
3235
+ - Search codebase for implementation evidence
3236
+ - If found, note file paths and line ranges
3237
+ - Assess if implementation matches requirement intent
3238
+ - If divergence detected:
3239
+ - Add WARNING: "Implementation may diverge from spec: <details>"
3240
+ - Recommendation: "Review <file>:<lines> against requirement X"
3241
+
3242
+ **Scenario Coverage**:
3243
+ - For each scenario in delta specs (marked with "#### Scenario:"):
3244
+ - Check if conditions are handled in code
3245
+ - Check if tests exist covering the scenario
3246
+ - If scenario appears uncovered:
3247
+ - Add WARNING: "Scenario not covered: <scenario name>"
3248
+ - Recommendation: "Add test or implementation for scenario: <description>"
3249
+
3250
+ 7. **Verify Coherence**
3251
+
3252
+ **Design Adherence**:
3253
+ - If design.md exists in contextFiles:
3254
+ - Extract key decisions (look for sections like "Decision:", "Approach:", "Architecture:")
3255
+ - Verify implementation follows those decisions
3256
+ - If contradiction detected:
3257
+ - Add WARNING: "Design decision not followed: <decision>"
3258
+ - Recommendation: "Update implementation or revise design.md to match reality"
3259
+ - If no design.md: Skip design adherence check, note "No design.md to verify against"
3260
+
3261
+ **Code Pattern Consistency**:
3262
+ - Review new code for consistency with project patterns
3263
+ - Check file naming, directory structure, coding style
3264
+ - If significant deviations found:
3265
+ - Add SUGGESTION: "Code pattern deviation: <details>"
3266
+ - Recommendation: "Consider following project pattern: <example>"
3267
+
3268
+ 8. **Generate Verification Report**
3269
+
3270
+ **Summary Scorecard**:
3271
+ \`\`\`
3272
+ ## Verification Report: <change-name>
3273
+
3274
+ ### Summary
3275
+ | Dimension | Status |
3276
+ |--------------|------------------|
3277
+ | Completeness | X/Y tasks, N reqs|
3278
+ | Correctness | M/N reqs covered |
3279
+ | Coherence | Followed/Issues |
3280
+ \`\`\`
3281
+
3282
+ **Issues by Priority**:
3283
+
3284
+ 1. **CRITICAL** (Must fix before archive):
3285
+ - Incomplete tasks
3286
+ - Missing requirement implementations
3287
+ - Each with specific, actionable recommendation
3288
+
3289
+ 2. **WARNING** (Should fix):
3290
+ - Spec/design divergences
3291
+ - Missing scenario coverage
3292
+ - Each with specific recommendation
3293
+
3294
+ 3. **SUGGESTION** (Nice to fix):
3295
+ - Pattern inconsistencies
3296
+ - Minor improvements
3297
+ - Each with specific recommendation
3298
+
3299
+ **Final Assessment**:
3300
+ - If CRITICAL issues: "X critical issue(s) found. Fix before archiving."
3301
+ - If only warnings: "No critical issues. Y warning(s) to consider. Ready for archive (with noted improvements)."
3302
+ - If all clear: "All checks passed. Ready for archive."
3303
+
3304
+ **Verification Heuristics**
3305
+
3306
+ - **Completeness**: Focus on objective checklist items (checkboxes, requirements list)
3307
+ - **Correctness**: Use keyword search, file path analysis, reasonable inference - don't require perfect certainty
3308
+ - **Coherence**: Look for glaring inconsistencies, don't nitpick style
3309
+ - **False Positives**: When uncertain, prefer SUGGESTION over WARNING, WARNING over CRITICAL
3310
+ - **Actionability**: Every issue must have a specific recommendation with file/line references where applicable
3311
+
3312
+ **Graceful Degradation**
3313
+
3314
+ - If only tasks.md exists: verify task completion only, skip spec/design checks
3315
+ - If tasks + specs exist: verify completeness and correctness, skip design
3316
+ - If full artifacts: verify all three dimensions
3317
+ - Always note which checks were skipped and why
3318
+
3319
+ **Output Format**
3320
+
3321
+ Use clear markdown with:
3322
+ - Table for summary scorecard
3323
+ - Grouped lists for issues (CRITICAL/WARNING/SUGGESTION)
3324
+ - Code references in format: \`file.ts:123\`
3325
+ - Specific, actionable recommendations
3326
+ - No vague suggestions like "consider reviewing"`,
3327
+ };
3328
+ }
3329
+ /**
3330
+ * Template for feedback skill
3331
+ * For collecting and submitting user feedback with context enrichment
3332
+ */
3333
+ export function getFeedbackSkillTemplate() {
3334
+ return {
3335
+ name: "feedback",
3336
+ description: "收集并提交 OpenSpec 相关用户反馈(含上下文补充与匿名处理)。",
3337
+ instructions: `Help the user submit feedback about OpenSpec.
3338
+
3339
+ **Goal**: Guide the user through collecting, enriching, and submitting feedback while ensuring privacy through anonymization.
3340
+
3341
+ **Process**
3342
+
3343
+ 1. **Gather context from the conversation**
3344
+ - Review recent conversation history for context
3345
+ - Identify what task was being performed
3346
+ - Note what worked well or poorly
3347
+ - Capture specific friction points or praise
3348
+
3349
+ 2. **Draft enriched feedback**
3350
+ - Create a clear, descriptive title (single sentence, no "Feedback:" prefix needed)
3351
+ - Write a body that includes:
3352
+ - What the user was trying to do
3353
+ - What happened (good or bad)
3354
+ - Relevant context from the conversation
3355
+ - Any specific suggestions or requests
3356
+
3357
+ 3. **Anonymize sensitive information**
3358
+ - Replace file paths with \`<path>\` or generic descriptions
3359
+ - Replace API keys, tokens, secrets with \`<redacted>\`
3360
+ - Replace company/organization names with \`<company>\`
3361
+ - Replace personal names with \`<user>\`
3362
+ - Replace specific URLs with \`<url>\` unless public/relevant
3363
+ - Keep technical details that help understand the issue
3364
+
3365
+ 4. **Present draft for approval**
3366
+ - Show the complete draft to the user
3367
+ - Display both title and body clearly
3368
+ - Ask for explicit approval before submitting
3369
+ - Allow the user to request modifications
3370
+
3371
+ 5. **Submit on confirmation**
3372
+ - Use the \`openspec feedback\` command to submit
3373
+ - Format: \`openspec feedback "title" --body "body content"\`
3374
+ - The command will automatically add metadata (version, platform, timestamp)
3375
+
3376
+ **Example Draft**
3377
+
3378
+ \`\`\`
3379
+ Title: Error handling in artifact workflow needs improvement
3380
+
3381
+ Body:
3382
+ I was working on creating a new change and encountered an issue with
3383
+ the artifact workflow. When I tried to continue after creating the
3384
+ proposal, the system didn't clearly indicate that I needed to complete
3385
+ the specs first.
3386
+
3387
+ Suggestion: Add clearer error messages that explain dependency chains
3388
+ in the artifact workflow. Something like "Cannot create design.md
3389
+ because specs are not complete (0/2 done)."
3390
+
3391
+ Context: Using the spec-driven schema with <path>/my-project
3392
+ \`\`\`
3393
+
3394
+ **Anonymization Examples**
3395
+
3396
+ Before:
3397
+ \`\`\`
3398
+ Working on /Users/john/mycompany/auth-service/src/oauth.ts
3399
+ Failed with API key: sk_live_abc123xyz
3400
+ Working at Acme Corp
3401
+ \`\`\`
3402
+
3403
+ After:
3404
+ \`\`\`
3405
+ Working on <path>/oauth.ts
3406
+ Failed with API key: <redacted>
3407
+ Working at <company>
3408
+ \`\`\`
3409
+
3410
+ **Guardrails**
3411
+
3412
+ - MUST show complete draft before submitting
3413
+ - MUST ask for explicit approval
3414
+ - MUST anonymize sensitive information
3415
+ - ALLOW user to modify draft before submitting
3416
+ - DO NOT submit without user confirmation
3417
+ - DO include relevant technical context
3418
+ - DO keep conversation-specific insights
3419
+
3420
+ **User Confirmation Required**
3421
+
3422
+ Always ask:
3423
+ \`\`\`
3424
+ Here's the feedback I've drafted:
3425
+
3426
+ Title: [title]
3427
+
3428
+ Body:
3429
+ [body]
3430
+
3431
+ Does this look good? I can modify it if you'd like, or submit it as-is.
3432
+ \`\`\`
3433
+
3434
+ Only proceed with submission after user confirms.`,
3435
+ };
3436
+ }
3437
+ //# sourceMappingURL=skill-templates.js.map