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,58 @@
1
+ /**
2
+ * Status Command
3
+ *
4
+ * Displays artifact completion status for a change.
5
+ */
6
+ import ora from 'ora';
7
+ import chalk from 'chalk';
8
+ import { loadChangeContext, formatChangeStatus, } from '../../core/artifact-graph/index.js';
9
+ import { validateChangeExists, validateSchemaExists, getStatusIndicator, getStatusColor, } from './shared.js';
10
+ // -----------------------------------------------------------------------------
11
+ // Command Implementation
12
+ // -----------------------------------------------------------------------------
13
+ export async function statusCommand(options) {
14
+ const spinner = ora('Loading change status...').start();
15
+ try {
16
+ const projectRoot = process.cwd();
17
+ const changeName = await validateChangeExists(options.change, projectRoot);
18
+ // Validate schema if explicitly provided
19
+ if (options.schema) {
20
+ validateSchemaExists(options.schema, projectRoot);
21
+ }
22
+ // loadChangeContext will auto-detect schema from metadata if not provided
23
+ const context = loadChangeContext(projectRoot, changeName, options.schema);
24
+ const status = formatChangeStatus(context);
25
+ spinner.stop();
26
+ if (options.json) {
27
+ console.log(JSON.stringify(status, null, 2));
28
+ return;
29
+ }
30
+ printStatusText(status);
31
+ }
32
+ catch (error) {
33
+ spinner.stop();
34
+ throw error;
35
+ }
36
+ }
37
+ export function printStatusText(status) {
38
+ const doneCount = status.artifacts.filter((a) => a.status === 'done').length;
39
+ const total = status.artifacts.length;
40
+ console.log(`Change: ${status.changeName}`);
41
+ console.log(`Schema: ${status.schemaName}`);
42
+ console.log(`Progress: ${doneCount}/${total} artifacts complete`);
43
+ console.log();
44
+ for (const artifact of status.artifacts) {
45
+ const indicator = getStatusIndicator(artifact.status);
46
+ const color = getStatusColor(artifact.status);
47
+ let line = `${indicator} ${artifact.id}`;
48
+ if (artifact.status === 'blocked' && artifact.missingDeps && artifact.missingDeps.length > 0) {
49
+ line += color(` (blocked by: ${artifact.missingDeps.join(', ')})`);
50
+ }
51
+ console.log(line);
52
+ }
53
+ if (status.isComplete) {
54
+ console.log();
55
+ console.log(chalk.green('All artifacts complete!'));
56
+ }
57
+ }
58
+ //# sourceMappingURL=status.js.map
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Templates Command
3
+ *
4
+ * Shows resolved template paths for all artifacts in a schema.
5
+ */
6
+ export interface TemplatesOptions {
7
+ schema?: string;
8
+ json?: boolean;
9
+ }
10
+ export interface TemplateInfo {
11
+ artifactId: string;
12
+ templatePath: string;
13
+ source: 'project' | 'user' | 'package';
14
+ }
15
+ export declare function templatesCommand(options: TemplatesOptions): Promise<void>;
16
+ //# sourceMappingURL=templates.d.ts.map
@@ -0,0 +1,68 @@
1
+ /**
2
+ * Templates Command
3
+ *
4
+ * Shows resolved template paths for all artifacts in a schema.
5
+ */
6
+ import ora from 'ora';
7
+ import path from 'path';
8
+ import { resolveSchema, getSchemaDir, ArtifactGraph, } from '../../core/artifact-graph/index.js';
9
+ import { validateSchemaExists, DEFAULT_SCHEMA } from './shared.js';
10
+ // -----------------------------------------------------------------------------
11
+ // Command Implementation
12
+ // -----------------------------------------------------------------------------
13
+ export async function templatesCommand(options) {
14
+ const spinner = ora('Loading templates...').start();
15
+ try {
16
+ const projectRoot = process.cwd();
17
+ const schemaName = validateSchemaExists(options.schema ?? DEFAULT_SCHEMA, projectRoot);
18
+ const schema = resolveSchema(schemaName, projectRoot);
19
+ const graph = ArtifactGraph.fromSchema(schema);
20
+ const schemaDir = getSchemaDir(schemaName, projectRoot);
21
+ // Determine the source (project, user, or package)
22
+ const { getUserSchemasDir, getProjectSchemasDir, } = await import('../../core/artifact-graph/resolver.js');
23
+ const projectSchemasDir = getProjectSchemasDir(projectRoot);
24
+ const userSchemasDir = getUserSchemasDir();
25
+ // Determine source by checking if schemaDir is inside each base directory
26
+ // Using path.relative is more robust than startsWith for path comparisons
27
+ const isInsideDir = (child, parent) => {
28
+ const relative = path.relative(parent, child);
29
+ return !relative.startsWith('..') && !path.isAbsolute(relative);
30
+ };
31
+ let source;
32
+ if (isInsideDir(schemaDir, projectSchemasDir)) {
33
+ source = 'project';
34
+ }
35
+ else if (isInsideDir(schemaDir, userSchemasDir)) {
36
+ source = 'user';
37
+ }
38
+ else {
39
+ source = 'package';
40
+ }
41
+ const templates = graph.getAllArtifacts().map((artifact) => ({
42
+ artifactId: artifact.id,
43
+ templatePath: path.join(schemaDir, 'templates', artifact.template),
44
+ source,
45
+ }));
46
+ spinner.stop();
47
+ if (options.json) {
48
+ const output = {};
49
+ for (const t of templates) {
50
+ output[t.artifactId] = { path: t.templatePath, source: t.source };
51
+ }
52
+ console.log(JSON.stringify(output, null, 2));
53
+ return;
54
+ }
55
+ console.log(`Schema: ${schemaName}`);
56
+ console.log(`Source: ${source}`);
57
+ console.log();
58
+ for (const t of templates) {
59
+ console.log(`${t.artifactId}:`);
60
+ console.log(` ${t.templatePath}`);
61
+ }
62
+ }
63
+ catch (error) {
64
+ spinner.stop();
65
+ throw error;
66
+ }
67
+ }
68
+ //# sourceMappingURL=templates.js.map
@@ -0,0 +1,11 @@
1
+ export declare class ArchiveCommand {
2
+ execute(changeName?: string, options?: {
3
+ yes?: boolean;
4
+ skipSpecs?: boolean;
5
+ noValidate?: boolean;
6
+ validate?: boolean;
7
+ }): Promise<void>;
8
+ private selectChange;
9
+ private getArchiveDate;
10
+ }
11
+ //# sourceMappingURL=archive.d.ts.map
@@ -0,0 +1,280 @@
1
+ import { promises as fs } from 'fs';
2
+ import path from 'path';
3
+ import { getTaskProgressForChange, formatTaskStatus } from '../utils/task-progress.js';
4
+ import { Validator } from './validation/validator.js';
5
+ import chalk from 'chalk';
6
+ import { findSpecUpdates, buildUpdatedSpec, writeUpdatedSpec, } from './specs-apply.js';
7
+ export class ArchiveCommand {
8
+ async execute(changeName, options = {}) {
9
+ const targetPath = '.';
10
+ const changesDir = path.join(targetPath, 'openspec', 'changes');
11
+ const archiveDir = path.join(changesDir, 'archive');
12
+ const mainSpecsDir = path.join(targetPath, 'openspec', 'specs');
13
+ // Check if changes directory exists
14
+ try {
15
+ await fs.access(changesDir);
16
+ }
17
+ catch {
18
+ throw new Error("No OpenSpec changes directory found. Run 'openspec init' first.");
19
+ }
20
+ // Get change name interactively if not provided
21
+ if (!changeName) {
22
+ const selectedChange = await this.selectChange(changesDir);
23
+ if (!selectedChange) {
24
+ console.log('No change selected. Aborting.');
25
+ return;
26
+ }
27
+ changeName = selectedChange;
28
+ }
29
+ const changeDir = path.join(changesDir, changeName);
30
+ // Verify change exists
31
+ try {
32
+ const stat = await fs.stat(changeDir);
33
+ if (!stat.isDirectory()) {
34
+ throw new Error(`Change '${changeName}' not found.`);
35
+ }
36
+ }
37
+ catch {
38
+ throw new Error(`Change '${changeName}' not found.`);
39
+ }
40
+ const skipValidation = options.validate === false || options.noValidate === true;
41
+ // Validate specs and change before archiving
42
+ if (!skipValidation) {
43
+ const validator = new Validator();
44
+ let hasValidationErrors = false;
45
+ // Validate proposal.md (non-blocking unless strict mode desired in future)
46
+ const changeFile = path.join(changeDir, 'proposal.md');
47
+ try {
48
+ await fs.access(changeFile);
49
+ const changeReport = await validator.validateChange(changeFile);
50
+ // Proposal validation is informative only (do not block archive)
51
+ if (!changeReport.valid) {
52
+ console.log(chalk.yellow(`\nProposal warnings in proposal.md (non-blocking):`));
53
+ for (const issue of changeReport.issues) {
54
+ const symbol = issue.level === 'ERROR' ? '⚠' : (issue.level === 'WARNING' ? '⚠' : 'ℹ');
55
+ console.log(chalk.yellow(` ${symbol} ${issue.message}`));
56
+ }
57
+ }
58
+ }
59
+ catch {
60
+ // Change file doesn't exist, skip validation
61
+ }
62
+ // Validate delta-formatted spec files under the change directory if present
63
+ const changeSpecsDir = path.join(changeDir, 'specs');
64
+ let hasDeltaSpecs = false;
65
+ try {
66
+ const candidates = await fs.readdir(changeSpecsDir, { withFileTypes: true });
67
+ for (const c of candidates) {
68
+ if (c.isDirectory()) {
69
+ try {
70
+ const candidatePath = path.join(changeSpecsDir, c.name, 'spec.md');
71
+ await fs.access(candidatePath);
72
+ const content = await fs.readFile(candidatePath, 'utf-8');
73
+ if (/^##\s+(ADDED|MODIFIED|REMOVED|RENAMED)\s+Requirements/m.test(content)) {
74
+ hasDeltaSpecs = true;
75
+ break;
76
+ }
77
+ }
78
+ catch { }
79
+ }
80
+ }
81
+ }
82
+ catch { }
83
+ if (hasDeltaSpecs) {
84
+ const deltaReport = await validator.validateChangeDeltaSpecs(changeDir);
85
+ if (!deltaReport.valid) {
86
+ hasValidationErrors = true;
87
+ console.log(chalk.red(`\nValidation errors in change delta specs:`));
88
+ for (const issue of deltaReport.issues) {
89
+ if (issue.level === 'ERROR') {
90
+ console.log(chalk.red(` ✗ ${issue.message}`));
91
+ }
92
+ else if (issue.level === 'WARNING') {
93
+ console.log(chalk.yellow(` ⚠ ${issue.message}`));
94
+ }
95
+ }
96
+ }
97
+ }
98
+ if (hasValidationErrors) {
99
+ console.log(chalk.red('\nValidation failed. Please fix the errors before archiving.'));
100
+ console.log(chalk.yellow('To skip validation (not recommended), use --no-validate flag.'));
101
+ return;
102
+ }
103
+ }
104
+ else {
105
+ // Log warning when validation is skipped
106
+ const timestamp = new Date().toISOString();
107
+ if (!options.yes) {
108
+ const { confirm } = await import('@inquirer/prompts');
109
+ const proceed = await confirm({
110
+ message: chalk.yellow('⚠️ WARNING: Skipping validation may archive invalid specs. Continue? (y/N)'),
111
+ default: false
112
+ });
113
+ if (!proceed) {
114
+ console.log('Archive cancelled.');
115
+ return;
116
+ }
117
+ }
118
+ else {
119
+ console.log(chalk.yellow(`\n⚠️ WARNING: Skipping validation may archive invalid specs.`));
120
+ }
121
+ console.log(chalk.yellow(`[${timestamp}] Validation skipped for change: ${changeName}`));
122
+ console.log(chalk.yellow(`Affected files: ${changeDir}`));
123
+ }
124
+ // Show progress and check for incomplete tasks
125
+ const progress = await getTaskProgressForChange(changesDir, changeName);
126
+ const status = formatTaskStatus(progress);
127
+ console.log(`Task status: ${status}`);
128
+ const incompleteTasks = Math.max(progress.total - progress.completed, 0);
129
+ if (incompleteTasks > 0) {
130
+ if (!options.yes) {
131
+ const { confirm } = await import('@inquirer/prompts');
132
+ const proceed = await confirm({
133
+ message: `Warning: ${incompleteTasks} incomplete task(s) found. Continue?`,
134
+ default: false
135
+ });
136
+ if (!proceed) {
137
+ console.log('Archive cancelled.');
138
+ return;
139
+ }
140
+ }
141
+ else {
142
+ console.log(`Warning: ${incompleteTasks} incomplete task(s) found. Continuing due to --yes flag.`);
143
+ }
144
+ }
145
+ // Handle spec updates unless skipSpecs flag is set
146
+ if (options.skipSpecs) {
147
+ console.log('Skipping spec updates (--skip-specs flag provided).');
148
+ }
149
+ else {
150
+ // Find specs to update
151
+ const specUpdates = await findSpecUpdates(changeDir, mainSpecsDir);
152
+ if (specUpdates.length > 0) {
153
+ console.log('\nSpecs to update:');
154
+ for (const update of specUpdates) {
155
+ const status = update.exists ? 'update' : 'create';
156
+ const capability = path.basename(path.dirname(update.target));
157
+ console.log(` ${capability}: ${status}`);
158
+ }
159
+ let shouldUpdateSpecs = true;
160
+ if (!options.yes) {
161
+ const { confirm } = await import('@inquirer/prompts');
162
+ shouldUpdateSpecs = await confirm({
163
+ message: 'Proceed with spec updates?',
164
+ default: true
165
+ });
166
+ if (!shouldUpdateSpecs) {
167
+ console.log('Skipping spec updates. Proceeding with archive.');
168
+ }
169
+ }
170
+ if (shouldUpdateSpecs) {
171
+ // Prepare all updates first (validation pass, no writes)
172
+ const prepared = [];
173
+ try {
174
+ for (const update of specUpdates) {
175
+ const built = await buildUpdatedSpec(update, changeName);
176
+ prepared.push({ update, rebuilt: built.rebuilt, counts: built.counts });
177
+ }
178
+ }
179
+ catch (err) {
180
+ console.log(String(err.message || err));
181
+ console.log('Aborted. No files were changed.');
182
+ return;
183
+ }
184
+ // All validations passed; pre-validate rebuilt full spec and then write files and display counts
185
+ let totals = { added: 0, modified: 0, removed: 0, renamed: 0 };
186
+ for (const p of prepared) {
187
+ const specName = path.basename(path.dirname(p.update.target));
188
+ if (!skipValidation) {
189
+ const report = await new Validator().validateSpecContent(specName, p.rebuilt);
190
+ if (!report.valid) {
191
+ console.log(chalk.red(`\nValidation errors in rebuilt spec for ${specName} (will not write changes):`));
192
+ for (const issue of report.issues) {
193
+ if (issue.level === 'ERROR')
194
+ console.log(chalk.red(` ✗ ${issue.message}`));
195
+ else if (issue.level === 'WARNING')
196
+ console.log(chalk.yellow(` ⚠ ${issue.message}`));
197
+ }
198
+ console.log('Aborted. No files were changed.');
199
+ return;
200
+ }
201
+ }
202
+ await writeUpdatedSpec(p.update, p.rebuilt, p.counts);
203
+ totals.added += p.counts.added;
204
+ totals.modified += p.counts.modified;
205
+ totals.removed += p.counts.removed;
206
+ totals.renamed += p.counts.renamed;
207
+ }
208
+ console.log(`Totals: + ${totals.added}, ~ ${totals.modified}, - ${totals.removed}, → ${totals.renamed}`);
209
+ console.log('Specs updated successfully.');
210
+ }
211
+ }
212
+ }
213
+ // Create archive directory with date prefix
214
+ const archiveName = `${this.getArchiveDate()}-${changeName}`;
215
+ const archivePath = path.join(archiveDir, archiveName);
216
+ // Check if archive already exists
217
+ try {
218
+ await fs.access(archivePath);
219
+ throw new Error(`Archive '${archiveName}' already exists.`);
220
+ }
221
+ catch (error) {
222
+ if (error.code !== 'ENOENT') {
223
+ throw error;
224
+ }
225
+ }
226
+ // Create archive directory if needed
227
+ await fs.mkdir(archiveDir, { recursive: true });
228
+ // Move change to archive
229
+ await fs.rename(changeDir, archivePath);
230
+ console.log(`Change '${changeName}' archived as '${archiveName}'.`);
231
+ }
232
+ async selectChange(changesDir) {
233
+ const { select } = await import('@inquirer/prompts');
234
+ // Get all directories in changes (excluding archive)
235
+ const entries = await fs.readdir(changesDir, { withFileTypes: true });
236
+ const changeDirs = entries
237
+ .filter(entry => entry.isDirectory() && entry.name !== 'archive')
238
+ .map(entry => entry.name)
239
+ .sort();
240
+ if (changeDirs.length === 0) {
241
+ console.log('No active changes found.');
242
+ return null;
243
+ }
244
+ // Build choices with progress inline to avoid duplicate lists
245
+ let choices = changeDirs.map(name => ({ name, value: name }));
246
+ try {
247
+ const progressList = [];
248
+ for (const id of changeDirs) {
249
+ const progress = await getTaskProgressForChange(changesDir, id);
250
+ const status = formatTaskStatus(progress);
251
+ progressList.push({ id, status });
252
+ }
253
+ const nameWidth = Math.max(...progressList.map(p => p.id.length));
254
+ choices = progressList.map(p => ({
255
+ name: `${p.id.padEnd(nameWidth)} ${p.status}`,
256
+ value: p.id
257
+ }));
258
+ }
259
+ catch {
260
+ // If anything fails, fall back to simple names
261
+ choices = changeDirs.map(name => ({ name, value: name }));
262
+ }
263
+ try {
264
+ const answer = await select({
265
+ message: 'Select a change to archive',
266
+ choices
267
+ });
268
+ return answer;
269
+ }
270
+ catch (error) {
271
+ // User cancelled (Ctrl+C)
272
+ return null;
273
+ }
274
+ }
275
+ getArchiveDate() {
276
+ // Returns date in YYYY-MM-DD format
277
+ return new Date().toISOString().split('T')[0];
278
+ }
279
+ }
280
+ //# sourceMappingURL=archive.js.map
@@ -0,0 +1,56 @@
1
+ import type { Artifact, SchemaYaml, CompletedSet, BlockedArtifacts } from './types.js';
2
+ /**
3
+ * Represents an artifact dependency graph.
4
+ * Provides methods for querying build order, ready artifacts, and completion status.
5
+ */
6
+ export declare class ArtifactGraph {
7
+ private artifacts;
8
+ private schema;
9
+ private constructor();
10
+ /**
11
+ * Creates an ArtifactGraph from a YAML file path.
12
+ */
13
+ static fromYaml(filePath: string): ArtifactGraph;
14
+ /**
15
+ * Creates an ArtifactGraph from YAML content string.
16
+ */
17
+ static fromYamlContent(yamlContent: string): ArtifactGraph;
18
+ /**
19
+ * Creates an ArtifactGraph from a pre-validated schema object.
20
+ */
21
+ static fromSchema(schema: SchemaYaml): ArtifactGraph;
22
+ /**
23
+ * Gets a single artifact by ID.
24
+ */
25
+ getArtifact(id: string): Artifact | undefined;
26
+ /**
27
+ * Gets all artifacts in the graph.
28
+ */
29
+ getAllArtifacts(): Artifact[];
30
+ /**
31
+ * Gets the schema name.
32
+ */
33
+ getName(): string;
34
+ /**
35
+ * Gets the schema version.
36
+ */
37
+ getVersion(): number;
38
+ /**
39
+ * Computes the topological build order using Kahn's algorithm.
40
+ * Returns artifact IDs in the order they should be built.
41
+ */
42
+ getBuildOrder(): string[];
43
+ /**
44
+ * Gets artifacts that are ready to be created (all dependencies completed).
45
+ */
46
+ getNextArtifacts(completed: CompletedSet): string[];
47
+ /**
48
+ * Checks if all artifacts in the graph are completed.
49
+ */
50
+ isComplete(completed: CompletedSet): boolean;
51
+ /**
52
+ * Gets blocked artifacts and their unmet dependencies.
53
+ */
54
+ getBlocked(completed: CompletedSet): BlockedArtifacts;
55
+ }
56
+ //# sourceMappingURL=graph.d.ts.map
@@ -0,0 +1,141 @@
1
+ import { loadSchema, parseSchema } from './schema.js';
2
+ /**
3
+ * Represents an artifact dependency graph.
4
+ * Provides methods for querying build order, ready artifacts, and completion status.
5
+ */
6
+ export class ArtifactGraph {
7
+ artifacts;
8
+ schema;
9
+ constructor(schema) {
10
+ this.schema = schema;
11
+ this.artifacts = new Map(schema.artifacts.map(a => [a.id, a]));
12
+ }
13
+ /**
14
+ * Creates an ArtifactGraph from a YAML file path.
15
+ */
16
+ static fromYaml(filePath) {
17
+ const schema = loadSchema(filePath);
18
+ return new ArtifactGraph(schema);
19
+ }
20
+ /**
21
+ * Creates an ArtifactGraph from YAML content string.
22
+ */
23
+ static fromYamlContent(yamlContent) {
24
+ const schema = parseSchema(yamlContent);
25
+ return new ArtifactGraph(schema);
26
+ }
27
+ /**
28
+ * Creates an ArtifactGraph from a pre-validated schema object.
29
+ */
30
+ static fromSchema(schema) {
31
+ return new ArtifactGraph(schema);
32
+ }
33
+ /**
34
+ * Gets a single artifact by ID.
35
+ */
36
+ getArtifact(id) {
37
+ return this.artifacts.get(id);
38
+ }
39
+ /**
40
+ * Gets all artifacts in the graph.
41
+ */
42
+ getAllArtifacts() {
43
+ return Array.from(this.artifacts.values());
44
+ }
45
+ /**
46
+ * Gets the schema name.
47
+ */
48
+ getName() {
49
+ return this.schema.name;
50
+ }
51
+ /**
52
+ * Gets the schema version.
53
+ */
54
+ getVersion() {
55
+ return this.schema.version;
56
+ }
57
+ /**
58
+ * Computes the topological build order using Kahn's algorithm.
59
+ * Returns artifact IDs in the order they should be built.
60
+ */
61
+ getBuildOrder() {
62
+ const inDegree = new Map();
63
+ const dependents = new Map();
64
+ // Initialize all artifacts
65
+ for (const artifact of this.artifacts.values()) {
66
+ inDegree.set(artifact.id, artifact.requires.length);
67
+ dependents.set(artifact.id, []);
68
+ }
69
+ // Build reverse adjacency (who depends on whom)
70
+ for (const artifact of this.artifacts.values()) {
71
+ for (const req of artifact.requires) {
72
+ dependents.get(req).push(artifact.id);
73
+ }
74
+ }
75
+ // Start with roots (in-degree 0), sorted for determinism
76
+ const queue = [...this.artifacts.keys()]
77
+ .filter(id => inDegree.get(id) === 0)
78
+ .sort();
79
+ const result = [];
80
+ while (queue.length > 0) {
81
+ const current = queue.shift();
82
+ result.push(current);
83
+ // Collect newly ready artifacts, then sort before adding
84
+ const newlyReady = [];
85
+ for (const dep of dependents.get(current)) {
86
+ const newDegree = inDegree.get(dep) - 1;
87
+ inDegree.set(dep, newDegree);
88
+ if (newDegree === 0) {
89
+ newlyReady.push(dep);
90
+ }
91
+ }
92
+ queue.push(...newlyReady.sort());
93
+ }
94
+ return result;
95
+ }
96
+ /**
97
+ * Gets artifacts that are ready to be created (all dependencies completed).
98
+ */
99
+ getNextArtifacts(completed) {
100
+ const ready = [];
101
+ for (const artifact of this.artifacts.values()) {
102
+ if (completed.has(artifact.id)) {
103
+ continue; // Already completed
104
+ }
105
+ const allDepsCompleted = artifact.requires.every(req => completed.has(req));
106
+ if (allDepsCompleted) {
107
+ ready.push(artifact.id);
108
+ }
109
+ }
110
+ // Sort for deterministic ordering
111
+ return ready.sort();
112
+ }
113
+ /**
114
+ * Checks if all artifacts in the graph are completed.
115
+ */
116
+ isComplete(completed) {
117
+ for (const artifact of this.artifacts.values()) {
118
+ if (!completed.has(artifact.id)) {
119
+ return false;
120
+ }
121
+ }
122
+ return true;
123
+ }
124
+ /**
125
+ * Gets blocked artifacts and their unmet dependencies.
126
+ */
127
+ getBlocked(completed) {
128
+ const blocked = {};
129
+ for (const artifact of this.artifacts.values()) {
130
+ if (completed.has(artifact.id)) {
131
+ continue; // Already completed
132
+ }
133
+ const unmetDeps = artifact.requires.filter(req => !completed.has(req));
134
+ if (unmetDeps.length > 0) {
135
+ blocked[artifact.id] = unmetDeps.sort();
136
+ }
137
+ }
138
+ return blocked;
139
+ }
140
+ }
141
+ //# sourceMappingURL=graph.js.map
@@ -0,0 +1,7 @@
1
+ export { ArtifactSchema, SchemaYamlSchema, type Artifact, type SchemaYaml, type CompletedSet, type BlockedArtifacts, } from './types.js';
2
+ export { loadSchema, parseSchema, SchemaValidationError } from './schema.js';
3
+ export { ArtifactGraph } from './graph.js';
4
+ export { detectCompleted } from './state.js';
5
+ export { resolveSchema, listSchemas, listSchemasWithInfo, getSchemaDir, getPackageSchemasDir, getUserSchemasDir, SchemaLoadError, type SchemaInfo, } from './resolver.js';
6
+ export { loadTemplate, loadChangeContext, generateInstructions, formatChangeStatus, TemplateLoadError, type ChangeContext, type ArtifactInstructions, type DependencyInfo, type ArtifactStatus, type ChangeStatus, } from './instruction-loader.js';
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,13 @@
1
+ // Types
2
+ export { ArtifactSchema, SchemaYamlSchema, } from './types.js';
3
+ // Schema loading and validation
4
+ export { loadSchema, parseSchema, SchemaValidationError } from './schema.js';
5
+ // Graph operations
6
+ export { ArtifactGraph } from './graph.js';
7
+ // State detection
8
+ export { detectCompleted } from './state.js';
9
+ // Schema resolution
10
+ export { resolveSchema, listSchemas, listSchemasWithInfo, getSchemaDir, getPackageSchemasDir, getUserSchemasDir, SchemaLoadError, } from './resolver.js';
11
+ // Instruction loading
12
+ export { loadTemplate, loadChangeContext, generateInstructions, formatChangeStatus, TemplateLoadError, } from './instruction-loader.js';
13
+ //# sourceMappingURL=index.js.map