openspec-cn 0.23.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (235) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +153 -0
  3. package/bin/openspec.js +3 -0
  4. package/dist/cli/index.d.ts +2 -0
  5. package/dist/cli/index.js +480 -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 +280 -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 +13 -0
  65. package/dist/core/command-generation/adapters/codex.js +27 -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/factory.d.ts +13 -0
  75. package/dist/core/command-generation/adapters/factory.js +27 -0
  76. package/dist/core/command-generation/adapters/gemini.d.ts +13 -0
  77. package/dist/core/command-generation/adapters/gemini.js +26 -0
  78. package/dist/core/command-generation/adapters/github-copilot.d.ts +13 -0
  79. package/dist/core/command-generation/adapters/github-copilot.js +26 -0
  80. package/dist/core/command-generation/adapters/iflow.d.ts +13 -0
  81. package/dist/core/command-generation/adapters/iflow.js +29 -0
  82. package/dist/core/command-generation/adapters/index.d.ts +27 -0
  83. package/dist/core/command-generation/adapters/index.js +27 -0
  84. package/dist/core/command-generation/adapters/kilocode.d.ts +14 -0
  85. package/dist/core/command-generation/adapters/kilocode.js +23 -0
  86. package/dist/core/command-generation/adapters/opencode.d.ts +13 -0
  87. package/dist/core/command-generation/adapters/opencode.js +26 -0
  88. package/dist/core/command-generation/adapters/qoder.d.ts +13 -0
  89. package/dist/core/command-generation/adapters/qoder.js +30 -0
  90. package/dist/core/command-generation/adapters/qwen.d.ts +13 -0
  91. package/dist/core/command-generation/adapters/qwen.js +26 -0
  92. package/dist/core/command-generation/adapters/roocode.d.ts +14 -0
  93. package/dist/core/command-generation/adapters/roocode.js +27 -0
  94. package/dist/core/command-generation/adapters/windsurf.d.ts +14 -0
  95. package/dist/core/command-generation/adapters/windsurf.js +51 -0
  96. package/dist/core/command-generation/generator.d.ts +21 -0
  97. package/dist/core/command-generation/generator.js +27 -0
  98. package/dist/core/command-generation/index.d.ts +22 -0
  99. package/dist/core/command-generation/index.js +24 -0
  100. package/dist/core/command-generation/registry.d.ts +36 -0
  101. package/dist/core/command-generation/registry.js +88 -0
  102. package/dist/core/command-generation/types.d.ts +55 -0
  103. package/dist/core/command-generation/types.js +8 -0
  104. package/dist/core/completions/command-registry.d.ts +7 -0
  105. package/dist/core/completions/command-registry.js +456 -0
  106. package/dist/core/completions/completion-provider.d.ts +60 -0
  107. package/dist/core/completions/completion-provider.js +102 -0
  108. package/dist/core/completions/factory.d.ts +64 -0
  109. package/dist/core/completions/factory.js +75 -0
  110. package/dist/core/completions/generators/bash-generator.d.ts +32 -0
  111. package/dist/core/completions/generators/bash-generator.js +174 -0
  112. package/dist/core/completions/generators/fish-generator.d.ts +32 -0
  113. package/dist/core/completions/generators/fish-generator.js +157 -0
  114. package/dist/core/completions/generators/powershell-generator.d.ts +33 -0
  115. package/dist/core/completions/generators/powershell-generator.js +207 -0
  116. package/dist/core/completions/generators/zsh-generator.d.ts +44 -0
  117. package/dist/core/completions/generators/zsh-generator.js +250 -0
  118. package/dist/core/completions/installers/bash-installer.d.ts +87 -0
  119. package/dist/core/completions/installers/bash-installer.js +318 -0
  120. package/dist/core/completions/installers/fish-installer.d.ts +43 -0
  121. package/dist/core/completions/installers/fish-installer.js +143 -0
  122. package/dist/core/completions/installers/powershell-installer.d.ts +88 -0
  123. package/dist/core/completions/installers/powershell-installer.js +327 -0
  124. package/dist/core/completions/installers/zsh-installer.d.ts +125 -0
  125. package/dist/core/completions/installers/zsh-installer.js +449 -0
  126. package/dist/core/completions/templates/bash-templates.d.ts +6 -0
  127. package/dist/core/completions/templates/bash-templates.js +24 -0
  128. package/dist/core/completions/templates/fish-templates.d.ts +7 -0
  129. package/dist/core/completions/templates/fish-templates.js +39 -0
  130. package/dist/core/completions/templates/powershell-templates.d.ts +6 -0
  131. package/dist/core/completions/templates/powershell-templates.js +25 -0
  132. package/dist/core/completions/templates/zsh-templates.d.ts +6 -0
  133. package/dist/core/completions/templates/zsh-templates.js +36 -0
  134. package/dist/core/completions/types.d.ts +79 -0
  135. package/dist/core/completions/types.js +2 -0
  136. package/dist/core/config-prompts.d.ts +9 -0
  137. package/dist/core/config-prompts.js +34 -0
  138. package/dist/core/config-schema.d.ts +76 -0
  139. package/dist/core/config-schema.js +200 -0
  140. package/dist/core/config.d.ts +17 -0
  141. package/dist/core/config.js +30 -0
  142. package/dist/core/converters/json-converter.d.ts +6 -0
  143. package/dist/core/converters/json-converter.js +51 -0
  144. package/dist/core/global-config.d.ts +39 -0
  145. package/dist/core/global-config.js +115 -0
  146. package/dist/core/index.d.ts +2 -0
  147. package/dist/core/index.js +3 -0
  148. package/dist/core/init.d.ts +32 -0
  149. package/dist/core/init.js +433 -0
  150. package/dist/core/legacy-cleanup.d.ts +162 -0
  151. package/dist/core/legacy-cleanup.js +501 -0
  152. package/dist/core/list.d.ts +9 -0
  153. package/dist/core/list.js +171 -0
  154. package/dist/core/parsers/change-parser.d.ts +13 -0
  155. package/dist/core/parsers/change-parser.js +193 -0
  156. package/dist/core/parsers/markdown-parser.d.ts +22 -0
  157. package/dist/core/parsers/markdown-parser.js +187 -0
  158. package/dist/core/parsers/requirement-blocks.d.ts +37 -0
  159. package/dist/core/parsers/requirement-blocks.js +201 -0
  160. package/dist/core/project-config.d.ts +64 -0
  161. package/dist/core/project-config.js +223 -0
  162. package/dist/core/schemas/base.schema.d.ts +13 -0
  163. package/dist/core/schemas/base.schema.js +13 -0
  164. package/dist/core/schemas/change.schema.d.ts +73 -0
  165. package/dist/core/schemas/change.schema.js +31 -0
  166. package/dist/core/schemas/index.d.ts +4 -0
  167. package/dist/core/schemas/index.js +4 -0
  168. package/dist/core/schemas/spec.schema.d.ts +18 -0
  169. package/dist/core/schemas/spec.schema.js +15 -0
  170. package/dist/core/shared/index.d.ts +8 -0
  171. package/dist/core/shared/index.js +8 -0
  172. package/dist/core/shared/skill-generation.d.ts +41 -0
  173. package/dist/core/shared/skill-generation.js +74 -0
  174. package/dist/core/shared/tool-detection.d.ts +66 -0
  175. package/dist/core/shared/tool-detection.js +140 -0
  176. package/dist/core/specs-apply.d.ts +73 -0
  177. package/dist/core/specs-apply.js +384 -0
  178. package/dist/core/styles/palette.d.ts +7 -0
  179. package/dist/core/styles/palette.js +8 -0
  180. package/dist/core/templates/index.d.ts +8 -0
  181. package/dist/core/templates/index.js +9 -0
  182. package/dist/core/templates/skill-templates.d.ts +112 -0
  183. package/dist/core/templates/skill-templates.js +2893 -0
  184. package/dist/core/update.d.ts +42 -0
  185. package/dist/core/update.js +306 -0
  186. package/dist/core/validation/constants.d.ts +34 -0
  187. package/dist/core/validation/constants.js +40 -0
  188. package/dist/core/validation/types.d.ts +18 -0
  189. package/dist/core/validation/types.js +2 -0
  190. package/dist/core/validation/validator.d.ts +33 -0
  191. package/dist/core/validation/validator.js +409 -0
  192. package/dist/core/view.d.ts +8 -0
  193. package/dist/core/view.js +168 -0
  194. package/dist/index.d.ts +3 -0
  195. package/dist/index.js +3 -0
  196. package/dist/prompts/searchable-multi-select.d.ts +27 -0
  197. package/dist/prompts/searchable-multi-select.js +149 -0
  198. package/dist/telemetry/config.d.ts +32 -0
  199. package/dist/telemetry/config.js +68 -0
  200. package/dist/telemetry/index.d.ts +31 -0
  201. package/dist/telemetry/index.js +145 -0
  202. package/dist/ui/ascii-patterns.d.ts +16 -0
  203. package/dist/ui/ascii-patterns.js +133 -0
  204. package/dist/ui/welcome-screen.d.ts +10 -0
  205. package/dist/ui/welcome-screen.js +146 -0
  206. package/dist/utils/change-metadata.d.ts +51 -0
  207. package/dist/utils/change-metadata.js +147 -0
  208. package/dist/utils/change-utils.d.ts +62 -0
  209. package/dist/utils/change-utils.js +121 -0
  210. package/dist/utils/file-system.d.ts +36 -0
  211. package/dist/utils/file-system.js +281 -0
  212. package/dist/utils/index.d.ts +5 -0
  213. package/dist/utils/index.js +7 -0
  214. package/dist/utils/interactive.d.ts +18 -0
  215. package/dist/utils/interactive.js +21 -0
  216. package/dist/utils/item-discovery.d.ts +4 -0
  217. package/dist/utils/item-discovery.js +72 -0
  218. package/dist/utils/match.d.ts +3 -0
  219. package/dist/utils/match.js +22 -0
  220. package/dist/utils/shell-detection.d.ts +20 -0
  221. package/dist/utils/shell-detection.js +41 -0
  222. package/dist/utils/task-progress.d.ts +8 -0
  223. package/dist/utils/task-progress.js +36 -0
  224. package/package.json +84 -0
  225. package/schemas/spec-driven/schema.yaml +148 -0
  226. package/schemas/spec-driven/templates/design.md +19 -0
  227. package/schemas/spec-driven/templates/proposal.md +23 -0
  228. package/schemas/spec-driven/templates/spec.md +8 -0
  229. package/schemas/spec-driven/templates/tasks.md +9 -0
  230. package/schemas/tdd/schema.yaml +213 -0
  231. package/schemas/tdd/templates/docs.md +15 -0
  232. package/schemas/tdd/templates/implementation.md +11 -0
  233. package/schemas/tdd/templates/spec.md +11 -0
  234. package/schemas/tdd/templates/test.md +11 -0
  235. package/scripts/postinstall.js +147 -0
@@ -0,0 +1,381 @@
1
+ /**
2
+ * Instructions Command
3
+ *
4
+ * Generates enriched instructions for creating artifacts or applying tasks.
5
+ * Includes both artifact instructions and apply instructions.
6
+ */
7
+ import ora from 'ora';
8
+ import path from 'path';
9
+ import * as fs from 'fs';
10
+ import { loadChangeContext, generateInstructions, resolveSchema, } from '../../core/artifact-graph/index.js';
11
+ import { validateChangeExists, validateSchemaExists, } from './shared.js';
12
+ // -----------------------------------------------------------------------------
13
+ // Artifact Instructions Command
14
+ // -----------------------------------------------------------------------------
15
+ export async function instructionsCommand(artifactId, options) {
16
+ const spinner = ora('Generating instructions...').start();
17
+ try {
18
+ const projectRoot = process.cwd();
19
+ const changeName = await validateChangeExists(options.change, projectRoot);
20
+ // Validate schema if explicitly provided
21
+ if (options.schema) {
22
+ validateSchemaExists(options.schema, projectRoot);
23
+ }
24
+ // loadChangeContext will auto-detect schema from metadata if not provided
25
+ const context = loadChangeContext(projectRoot, changeName, options.schema);
26
+ if (!artifactId) {
27
+ spinner.stop();
28
+ const validIds = context.graph.getAllArtifacts().map((a) => a.id);
29
+ throw new Error(`Missing required argument <artifact>. Valid artifacts:\n ${validIds.join('\n ')}`);
30
+ }
31
+ const artifact = context.graph.getArtifact(artifactId);
32
+ if (!artifact) {
33
+ spinner.stop();
34
+ const validIds = context.graph.getAllArtifacts().map((a) => a.id);
35
+ throw new Error(`Artifact '${artifactId}' not found in schema '${context.schemaName}'. Valid artifacts:\n ${validIds.join('\n ')}`);
36
+ }
37
+ const instructions = generateInstructions(context, artifactId, projectRoot);
38
+ const isBlocked = instructions.dependencies.some((d) => !d.done);
39
+ spinner.stop();
40
+ if (options.json) {
41
+ console.log(JSON.stringify(instructions, null, 2));
42
+ return;
43
+ }
44
+ printInstructionsText(instructions, isBlocked);
45
+ }
46
+ catch (error) {
47
+ spinner.stop();
48
+ throw error;
49
+ }
50
+ }
51
+ export function printInstructionsText(instructions, isBlocked) {
52
+ const { artifactId, changeName, schemaName, changeDir, outputPath, description, instruction, context, rules, template, dependencies, unlocks, } = instructions;
53
+ // Opening tag
54
+ console.log(`<artifact id="${artifactId}" change="${changeName}" schema="${schemaName}">`);
55
+ console.log();
56
+ // Warning for blocked artifacts
57
+ if (isBlocked) {
58
+ const missing = dependencies.filter((d) => !d.done).map((d) => d.id);
59
+ console.log('<warning>');
60
+ console.log('This artifact has unmet dependencies. Complete them first or proceed with caution.');
61
+ console.log(`Missing: ${missing.join(', ')}`);
62
+ console.log('</warning>');
63
+ console.log();
64
+ }
65
+ // Task directive
66
+ console.log('<task>');
67
+ console.log(`Create the ${artifactId} artifact for change "${changeName}".`);
68
+ console.log(description);
69
+ console.log('</task>');
70
+ console.log();
71
+ // Project context (AI constraint - do not include in output)
72
+ if (context) {
73
+ console.log('<project_context>');
74
+ console.log('<!-- This is background information for you. Do NOT include this in your output. -->');
75
+ console.log(context);
76
+ console.log('</project_context>');
77
+ console.log();
78
+ }
79
+ // Rules (AI constraint - do not include in output)
80
+ if (rules && rules.length > 0) {
81
+ console.log('<rules>');
82
+ console.log('<!-- These are constraints for you to follow. Do NOT include this in your output. -->');
83
+ for (const rule of rules) {
84
+ console.log(`- ${rule}`);
85
+ }
86
+ console.log('</rules>');
87
+ console.log();
88
+ }
89
+ // Dependencies (files to read for context)
90
+ if (dependencies.length > 0) {
91
+ console.log('<dependencies>');
92
+ console.log('Read these files for context before creating this artifact:');
93
+ console.log();
94
+ for (const dep of dependencies) {
95
+ const status = dep.done ? 'done' : 'missing';
96
+ const fullPath = path.join(changeDir, dep.path);
97
+ console.log(`<dependency id="${dep.id}" status="${status}">`);
98
+ console.log(` <path>${fullPath}</path>`);
99
+ console.log(` <description>${dep.description}</description>`);
100
+ console.log('</dependency>');
101
+ }
102
+ console.log('</dependencies>');
103
+ console.log();
104
+ }
105
+ // Output location
106
+ console.log('<output>');
107
+ console.log(`Write to: ${path.join(changeDir, outputPath)}`);
108
+ console.log('</output>');
109
+ console.log();
110
+ // Instruction (guidance)
111
+ if (instruction) {
112
+ console.log('<instruction>');
113
+ console.log(instruction.trim());
114
+ console.log('</instruction>');
115
+ console.log();
116
+ }
117
+ // Template
118
+ console.log('<template>');
119
+ console.log('<!-- Use this as the structure for your output file. Fill in the sections. -->');
120
+ console.log(template.trim());
121
+ console.log('</template>');
122
+ console.log();
123
+ // Success criteria placeholder
124
+ console.log('<success_criteria>');
125
+ console.log('<!-- To be defined in schema validation rules -->');
126
+ console.log('</success_criteria>');
127
+ console.log();
128
+ // Unlocks
129
+ if (unlocks.length > 0) {
130
+ console.log('<unlocks>');
131
+ console.log(`Completing this artifact enables: ${unlocks.join(', ')}`);
132
+ console.log('</unlocks>');
133
+ console.log();
134
+ }
135
+ // Closing tag
136
+ console.log('</artifact>');
137
+ }
138
+ // -----------------------------------------------------------------------------
139
+ // Apply Instructions Command
140
+ // -----------------------------------------------------------------------------
141
+ /**
142
+ * Parses tasks.md content and extracts task items with their completion status.
143
+ */
144
+ function parseTasksFile(content) {
145
+ const tasks = [];
146
+ const lines = content.split('\n');
147
+ let taskIndex = 0;
148
+ for (const line of lines) {
149
+ // Match checkbox patterns: - [ ] or - [x] or - [X]
150
+ const checkboxMatch = line.match(/^[-*]\s*\[([ xX])\]\s*(.+)$/);
151
+ if (checkboxMatch) {
152
+ taskIndex++;
153
+ const done = checkboxMatch[1].toLowerCase() === 'x';
154
+ const description = checkboxMatch[2].trim();
155
+ tasks.push({
156
+ id: `${taskIndex}`,
157
+ description,
158
+ done,
159
+ });
160
+ }
161
+ }
162
+ return tasks;
163
+ }
164
+ /**
165
+ * Checks if an artifact output exists in the change directory.
166
+ * Supports glob patterns (e.g., "specs/*.md") by verifying at least one matching file exists.
167
+ */
168
+ function artifactOutputExists(changeDir, generates) {
169
+ // Normalize the generates path to use platform-specific separators
170
+ const normalizedGenerates = generates.split('/').join(path.sep);
171
+ const fullPath = path.join(changeDir, normalizedGenerates);
172
+ // If it's a glob pattern (contains ** or *), check for matching files
173
+ if (generates.includes('*')) {
174
+ // Extract the directory part before the glob pattern
175
+ const parts = normalizedGenerates.split(path.sep);
176
+ const dirParts = [];
177
+ let patternPart = '';
178
+ for (const part of parts) {
179
+ if (part.includes('*')) {
180
+ patternPart = part;
181
+ break;
182
+ }
183
+ dirParts.push(part);
184
+ }
185
+ const dirPath = path.join(changeDir, ...dirParts);
186
+ // Check if directory exists
187
+ if (!fs.existsSync(dirPath) || !fs.statSync(dirPath).isDirectory()) {
188
+ return false;
189
+ }
190
+ // Extract expected extension from pattern (e.g., "*.md" -> ".md")
191
+ const extMatch = patternPart.match(/\*(\.[a-zA-Z0-9]+)$/);
192
+ const expectedExt = extMatch ? extMatch[1] : null;
193
+ // Recursively check for matching files
194
+ const hasMatchingFiles = (dir) => {
195
+ try {
196
+ const entries = fs.readdirSync(dir, { withFileTypes: true });
197
+ for (const entry of entries) {
198
+ if (entry.isDirectory()) {
199
+ // For ** patterns, recurse into subdirectories
200
+ if (generates.includes('**') && hasMatchingFiles(path.join(dir, entry.name))) {
201
+ return true;
202
+ }
203
+ }
204
+ else if (entry.isFile()) {
205
+ // Check if file matches expected extension (or any file if no extension specified)
206
+ if (!expectedExt || entry.name.endsWith(expectedExt)) {
207
+ return true;
208
+ }
209
+ }
210
+ }
211
+ }
212
+ catch {
213
+ return false;
214
+ }
215
+ return false;
216
+ };
217
+ return hasMatchingFiles(dirPath);
218
+ }
219
+ return fs.existsSync(fullPath);
220
+ }
221
+ /**
222
+ * Generates apply instructions for implementing tasks from a change.
223
+ * Schema-aware: reads apply phase configuration from schema to determine
224
+ * required artifacts, tracking file, and instruction.
225
+ */
226
+ export async function generateApplyInstructions(projectRoot, changeName, schemaName) {
227
+ // loadChangeContext will auto-detect schema from metadata if not provided
228
+ const context = loadChangeContext(projectRoot, changeName, schemaName);
229
+ const changeDir = path.join(projectRoot, 'openspec', 'changes', changeName);
230
+ // Get the full schema to access the apply phase configuration
231
+ const schema = resolveSchema(context.schemaName);
232
+ const applyConfig = schema.apply;
233
+ // Determine required artifacts and tracking file from schema
234
+ // Fallback: if no apply block, require all artifacts
235
+ const requiredArtifactIds = applyConfig?.requires ?? schema.artifacts.map((a) => a.id);
236
+ const tracksFile = applyConfig?.tracks ?? null;
237
+ const schemaInstruction = applyConfig?.instruction ?? null;
238
+ // Check which required artifacts are missing
239
+ const missingArtifacts = [];
240
+ for (const artifactId of requiredArtifactIds) {
241
+ const artifact = schema.artifacts.find((a) => a.id === artifactId);
242
+ if (artifact && !artifactOutputExists(changeDir, artifact.generates)) {
243
+ missingArtifacts.push(artifactId);
244
+ }
245
+ }
246
+ // Build context files from all existing artifacts in schema
247
+ const contextFiles = {};
248
+ for (const artifact of schema.artifacts) {
249
+ if (artifactOutputExists(changeDir, artifact.generates)) {
250
+ contextFiles[artifact.id] = path.join(changeDir, artifact.generates);
251
+ }
252
+ }
253
+ // Parse tasks if tracking file exists
254
+ let tasks = [];
255
+ let tracksFileExists = false;
256
+ if (tracksFile) {
257
+ const tracksPath = path.join(changeDir, tracksFile);
258
+ tracksFileExists = fs.existsSync(tracksPath);
259
+ if (tracksFileExists) {
260
+ const tasksContent = await fs.promises.readFile(tracksPath, 'utf-8');
261
+ tasks = parseTasksFile(tasksContent);
262
+ }
263
+ }
264
+ // Calculate progress
265
+ const total = tasks.length;
266
+ const complete = tasks.filter((t) => t.done).length;
267
+ const remaining = total - complete;
268
+ // Determine state and instruction
269
+ let state;
270
+ let instruction;
271
+ if (missingArtifacts.length > 0) {
272
+ state = 'blocked';
273
+ instruction = `Cannot apply this change yet. Missing artifacts: ${missingArtifacts.join(', ')}.\nUse the openspec-continue-change skill to create the missing artifacts first.`;
274
+ }
275
+ else if (tracksFile && !tracksFileExists) {
276
+ // Tracking file configured but doesn't exist yet
277
+ const tracksFilename = path.basename(tracksFile);
278
+ state = 'blocked';
279
+ instruction = `The ${tracksFilename} file is missing and must be created.\nUse openspec-continue-change to generate the tracking file.`;
280
+ }
281
+ else if (tracksFile && tracksFileExists && total === 0) {
282
+ // Tracking file exists but contains no tasks
283
+ const tracksFilename = path.basename(tracksFile);
284
+ state = 'blocked';
285
+ instruction = `The ${tracksFilename} file exists but contains no tasks.\nAdd tasks to ${tracksFilename} or regenerate it with openspec-continue-change.`;
286
+ }
287
+ else if (tracksFile && remaining === 0 && total > 0) {
288
+ state = 'all_done';
289
+ instruction = 'All tasks are complete! This change is ready to be archived.\nConsider running tests and reviewing the changes before archiving.';
290
+ }
291
+ else if (!tracksFile) {
292
+ // No tracking file (e.g., TDD schema) - ready to apply
293
+ state = 'ready';
294
+ instruction = schemaInstruction?.trim() ?? 'All required artifacts complete. Proceed with implementation.';
295
+ }
296
+ else {
297
+ state = 'ready';
298
+ instruction = schemaInstruction?.trim() ?? 'Read context files, work through pending tasks, mark complete as you go.\nPause if you hit blockers or need clarification.';
299
+ }
300
+ return {
301
+ changeName,
302
+ changeDir,
303
+ schemaName: context.schemaName,
304
+ contextFiles,
305
+ progress: { total, complete, remaining },
306
+ tasks,
307
+ state,
308
+ missingArtifacts: missingArtifacts.length > 0 ? missingArtifacts : undefined,
309
+ instruction,
310
+ };
311
+ }
312
+ export async function applyInstructionsCommand(options) {
313
+ const spinner = ora('Generating apply instructions...').start();
314
+ try {
315
+ const projectRoot = process.cwd();
316
+ const changeName = await validateChangeExists(options.change, projectRoot);
317
+ // Validate schema if explicitly provided
318
+ if (options.schema) {
319
+ validateSchemaExists(options.schema, projectRoot);
320
+ }
321
+ // generateApplyInstructions uses loadChangeContext which auto-detects schema
322
+ const instructions = await generateApplyInstructions(projectRoot, changeName, options.schema);
323
+ spinner.stop();
324
+ if (options.json) {
325
+ console.log(JSON.stringify(instructions, null, 2));
326
+ return;
327
+ }
328
+ printApplyInstructionsText(instructions);
329
+ }
330
+ catch (error) {
331
+ spinner.stop();
332
+ throw error;
333
+ }
334
+ }
335
+ export function printApplyInstructionsText(instructions) {
336
+ const { changeName, schemaName, contextFiles, progress, tasks, state, missingArtifacts, instruction } = instructions;
337
+ console.log(`## Apply: ${changeName}`);
338
+ console.log(`Schema: ${schemaName}`);
339
+ console.log();
340
+ // Warning for blocked state
341
+ if (state === 'blocked' && missingArtifacts) {
342
+ console.log('### ⚠️ Blocked');
343
+ console.log();
344
+ console.log(`Missing artifacts: ${missingArtifacts.join(', ')}`);
345
+ console.log('Use the openspec-continue-change skill to create these first.');
346
+ console.log();
347
+ }
348
+ // Context files (dynamically from schema)
349
+ const contextFileEntries = Object.entries(contextFiles);
350
+ if (contextFileEntries.length > 0) {
351
+ console.log('### Context Files');
352
+ for (const [artifactId, filePath] of contextFileEntries) {
353
+ console.log(`- ${artifactId}: ${filePath}`);
354
+ }
355
+ console.log();
356
+ }
357
+ // Progress (only show if we have tracking)
358
+ if (progress.total > 0 || tasks.length > 0) {
359
+ console.log('### Progress');
360
+ if (state === 'all_done') {
361
+ console.log(`${progress.complete}/${progress.total} complete ✓`);
362
+ }
363
+ else {
364
+ console.log(`${progress.complete}/${progress.total} complete`);
365
+ }
366
+ console.log();
367
+ }
368
+ // Tasks
369
+ if (tasks.length > 0) {
370
+ console.log('### Tasks');
371
+ for (const task of tasks) {
372
+ const checkbox = task.done ? '[x]' : '[ ]';
373
+ console.log(`- ${checkbox} ${task.description}`);
374
+ }
375
+ console.log();
376
+ }
377
+ // Instruction
378
+ console.log('### Instruction');
379
+ console.log(instruction);
380
+ }
381
+ //# sourceMappingURL=instructions.js.map
@@ -0,0 +1,11 @@
1
+ /**
2
+ * New Change Command
3
+ *
4
+ * Creates a new change directory with optional description and schema.
5
+ */
6
+ export interface NewChangeOptions {
7
+ description?: string;
8
+ schema?: string;
9
+ }
10
+ export declare function newChangeCommand(name: string | undefined, options: NewChangeOptions): Promise<void>;
11
+ //# sourceMappingURL=new-change.d.ts.map
@@ -0,0 +1,44 @@
1
+ /**
2
+ * New Change Command
3
+ *
4
+ * Creates a new change directory with optional description and schema.
5
+ */
6
+ import ora from 'ora';
7
+ import path from 'path';
8
+ import { createChange, validateChangeName } from '../../utils/change-utils.js';
9
+ import { validateSchemaExists } from './shared.js';
10
+ // -----------------------------------------------------------------------------
11
+ // Command Implementation
12
+ // -----------------------------------------------------------------------------
13
+ export async function newChangeCommand(name, options) {
14
+ if (!name) {
15
+ throw new Error('Missing required argument <name>');
16
+ }
17
+ const validation = validateChangeName(name);
18
+ if (!validation.valid) {
19
+ throw new Error(validation.error);
20
+ }
21
+ const projectRoot = process.cwd();
22
+ // Validate schema if provided
23
+ if (options.schema) {
24
+ validateSchemaExists(options.schema, projectRoot);
25
+ }
26
+ const schemaDisplay = options.schema ? ` with schema '${options.schema}'` : '';
27
+ const spinner = ora(`Creating change '${name}'${schemaDisplay}...`).start();
28
+ try {
29
+ const result = await createChange(projectRoot, name, { schema: options.schema });
30
+ // If description provided, create README.md with description
31
+ if (options.description) {
32
+ const { promises: fs } = await import('fs');
33
+ const changeDir = path.join(projectRoot, 'openspec', 'changes', name);
34
+ const readmePath = path.join(changeDir, 'README.md');
35
+ await fs.writeFile(readmePath, `# ${name}\n\n${options.description}\n`, 'utf-8');
36
+ }
37
+ spinner.succeed(`Created change '${name}' at openspec/changes/${name}/ (schema: ${result.schema})`);
38
+ }
39
+ catch (error) {
40
+ spinner.fail(`Failed to create change '${name}'`);
41
+ throw error;
42
+ }
43
+ }
44
+ //# sourceMappingURL=new-change.js.map
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Schemas Command
3
+ *
4
+ * Lists available workflow schemas with descriptions.
5
+ */
6
+ export interface SchemasOptions {
7
+ json?: boolean;
8
+ }
9
+ export declare function schemasCommand(options: SchemasOptions): Promise<void>;
10
+ //# sourceMappingURL=schemas.d.ts.map
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Schemas Command
3
+ *
4
+ * Lists available workflow schemas with descriptions.
5
+ */
6
+ import chalk from 'chalk';
7
+ import { listSchemasWithInfo } from '../../core/artifact-graph/index.js';
8
+ // -----------------------------------------------------------------------------
9
+ // Command Implementation
10
+ // -----------------------------------------------------------------------------
11
+ export async function schemasCommand(options) {
12
+ const projectRoot = process.cwd();
13
+ const schemas = listSchemasWithInfo(projectRoot);
14
+ if (options.json) {
15
+ console.log(JSON.stringify(schemas, null, 2));
16
+ return;
17
+ }
18
+ console.log('Available schemas:');
19
+ console.log();
20
+ for (const schema of schemas) {
21
+ let sourceLabel = '';
22
+ if (schema.source === 'project') {
23
+ sourceLabel = chalk.cyan(' (project)');
24
+ }
25
+ else if (schema.source === 'user') {
26
+ sourceLabel = chalk.dim(' (user override)');
27
+ }
28
+ console.log(` ${chalk.bold(schema.name)}${sourceLabel}`);
29
+ console.log(` ${schema.description}`);
30
+ console.log(` Artifacts: ${schema.artifacts.join(' → ')}`);
31
+ console.log();
32
+ }
33
+ }
34
+ //# sourceMappingURL=schemas.js.map
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Shared Types and Utilities for Artifact Workflow Commands
3
+ *
4
+ * This module contains types, constants, and validation helpers used across
5
+ * multiple artifact workflow commands.
6
+ */
7
+ export interface TaskItem {
8
+ id: string;
9
+ description: string;
10
+ done: boolean;
11
+ }
12
+ export interface ApplyInstructions {
13
+ changeName: string;
14
+ changeDir: string;
15
+ schemaName: string;
16
+ contextFiles: Record<string, string>;
17
+ progress: {
18
+ total: number;
19
+ complete: number;
20
+ remaining: number;
21
+ };
22
+ tasks: TaskItem[];
23
+ state: 'blocked' | 'all_done' | 'ready';
24
+ missingArtifacts?: string[];
25
+ instruction: string;
26
+ }
27
+ export declare const DEFAULT_SCHEMA = "spec-driven";
28
+ /**
29
+ * Checks if color output is disabled via NO_COLOR env or --no-color flag.
30
+ */
31
+ export declare function isColorDisabled(): boolean;
32
+ /**
33
+ * Gets the color function based on status.
34
+ */
35
+ export declare function getStatusColor(status: 'done' | 'ready' | 'blocked'): (text: string) => string;
36
+ /**
37
+ * Gets the status indicator for an artifact.
38
+ */
39
+ export declare function getStatusIndicator(status: 'done' | 'ready' | 'blocked'): string;
40
+ /**
41
+ * Validates that a change exists and returns available changes if not.
42
+ * Checks directory existence directly to support scaffolded changes (without proposal.md).
43
+ */
44
+ export declare function validateChangeExists(changeName: string | undefined, projectRoot: string): Promise<string>;
45
+ /**
46
+ * Validates that a schema exists and returns available schemas if not.
47
+ *
48
+ * @param schemaName - The schema name to validate
49
+ * @param projectRoot - Optional project root for project-local schema resolution
50
+ */
51
+ export declare function validateSchemaExists(schemaName: string, projectRoot?: string): string;
52
+ //# sourceMappingURL=shared.d.ts.map
@@ -0,0 +1,111 @@
1
+ /**
2
+ * Shared Types and Utilities for Artifact Workflow Commands
3
+ *
4
+ * This module contains types, constants, and validation helpers used across
5
+ * multiple artifact workflow commands.
6
+ */
7
+ import chalk from 'chalk';
8
+ import path from 'path';
9
+ import * as fs from 'fs';
10
+ import { getSchemaDir, listSchemas } from '../../core/artifact-graph/index.js';
11
+ import { validateChangeName } from '../../utils/change-utils.js';
12
+ // -----------------------------------------------------------------------------
13
+ // Constants
14
+ // -----------------------------------------------------------------------------
15
+ export const DEFAULT_SCHEMA = 'spec-driven';
16
+ // -----------------------------------------------------------------------------
17
+ // Utility Functions
18
+ // -----------------------------------------------------------------------------
19
+ /**
20
+ * Checks if color output is disabled via NO_COLOR env or --no-color flag.
21
+ */
22
+ export function isColorDisabled() {
23
+ return process.env.NO_COLOR === '1' || process.env.NO_COLOR === 'true';
24
+ }
25
+ /**
26
+ * Gets the color function based on status.
27
+ */
28
+ export function getStatusColor(status) {
29
+ if (isColorDisabled()) {
30
+ return (text) => text;
31
+ }
32
+ switch (status) {
33
+ case 'done':
34
+ return chalk.green;
35
+ case 'ready':
36
+ return chalk.yellow;
37
+ case 'blocked':
38
+ return chalk.red;
39
+ }
40
+ }
41
+ /**
42
+ * Gets the status indicator for an artifact.
43
+ */
44
+ export function getStatusIndicator(status) {
45
+ const color = getStatusColor(status);
46
+ switch (status) {
47
+ case 'done':
48
+ return color('[x]');
49
+ case 'ready':
50
+ return color('[ ]');
51
+ case 'blocked':
52
+ return color('[-]');
53
+ }
54
+ }
55
+ /**
56
+ * Validates that a change exists and returns available changes if not.
57
+ * Checks directory existence directly to support scaffolded changes (without proposal.md).
58
+ */
59
+ export async function validateChangeExists(changeName, projectRoot) {
60
+ const changesPath = path.join(projectRoot, 'openspec', 'changes');
61
+ // Get all change directories (not just those with proposal.md)
62
+ const getAvailableChanges = async () => {
63
+ try {
64
+ const entries = await fs.promises.readdir(changesPath, { withFileTypes: true });
65
+ return entries
66
+ .filter((e) => e.isDirectory() && e.name !== 'archive' && !e.name.startsWith('.'))
67
+ .map((e) => e.name);
68
+ }
69
+ catch {
70
+ return [];
71
+ }
72
+ };
73
+ if (!changeName) {
74
+ const available = await getAvailableChanges();
75
+ if (available.length === 0) {
76
+ throw new Error('No changes found. Create one with: openspec new change <name>');
77
+ }
78
+ throw new Error(`Missing required option --change. Available changes:\n ${available.join('\n ')}`);
79
+ }
80
+ // Validate change name format to prevent path traversal
81
+ const nameValidation = validateChangeName(changeName);
82
+ if (!nameValidation.valid) {
83
+ throw new Error(`Invalid change name '${changeName}': ${nameValidation.error}`);
84
+ }
85
+ // Check directory existence directly
86
+ const changePath = path.join(changesPath, changeName);
87
+ const exists = fs.existsSync(changePath) && fs.statSync(changePath).isDirectory();
88
+ if (!exists) {
89
+ const available = await getAvailableChanges();
90
+ if (available.length === 0) {
91
+ throw new Error(`Change '${changeName}' not found. No changes exist. Create one with: openspec new change <name>`);
92
+ }
93
+ throw new Error(`Change '${changeName}' not found. Available changes:\n ${available.join('\n ')}`);
94
+ }
95
+ return changeName;
96
+ }
97
+ /**
98
+ * Validates that a schema exists and returns available schemas if not.
99
+ *
100
+ * @param schemaName - The schema name to validate
101
+ * @param projectRoot - Optional project root for project-local schema resolution
102
+ */
103
+ export function validateSchemaExists(schemaName, projectRoot) {
104
+ const schemaDir = getSchemaDir(schemaName, projectRoot);
105
+ if (!schemaDir) {
106
+ const availableSchemas = listSchemas(projectRoot);
107
+ throw new Error(`Schema '${schemaName}' not found. Available schemas:\n ${availableSchemas.join('\n ')}`);
108
+ }
109
+ return schemaName;
110
+ }
111
+ //# sourceMappingURL=shared.js.map
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Status Command
3
+ *
4
+ * Displays artifact completion status for a change.
5
+ */
6
+ import { type ChangeStatus } from '../../core/artifact-graph/index.js';
7
+ export interface StatusOptions {
8
+ change?: string;
9
+ schema?: string;
10
+ json?: boolean;
11
+ }
12
+ export declare function statusCommand(options: StatusOptions): Promise<void>;
13
+ export declare function printStatusText(status: ChangeStatus): void;
14
+ //# sourceMappingURL=status.d.ts.map