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,140 @@
1
+ /**
2
+ * Tool Detection Utilities
3
+ *
4
+ * Shared utilities for detecting tool configurations and version status.
5
+ */
6
+ import path from 'path';
7
+ import * as fs from 'fs';
8
+ import { AI_TOOLS } from '../config.js';
9
+ /**
10
+ * Names of skill directories created by openspec init.
11
+ */
12
+ export const SKILL_NAMES = [
13
+ 'openspec-explore',
14
+ 'openspec-new-change',
15
+ 'openspec-continue-change',
16
+ 'openspec-apply-change',
17
+ 'openspec-ff-change',
18
+ 'openspec-sync-specs',
19
+ 'openspec-archive-change',
20
+ 'openspec-bulk-archive-change',
21
+ 'openspec-verify-change',
22
+ ];
23
+ /**
24
+ * Gets the list of tools with skillsDir configured.
25
+ */
26
+ export function getToolsWithSkillsDir() {
27
+ return AI_TOOLS.filter((t) => t.skillsDir).map((t) => t.value);
28
+ }
29
+ /**
30
+ * Checks which skill files exist for a tool.
31
+ */
32
+ export function getToolSkillStatus(projectRoot, toolId) {
33
+ const tool = AI_TOOLS.find((t) => t.value === toolId);
34
+ if (!tool?.skillsDir) {
35
+ return { configured: false, fullyConfigured: false, skillCount: 0 };
36
+ }
37
+ const skillsDir = path.join(projectRoot, tool.skillsDir, 'skills');
38
+ let skillCount = 0;
39
+ for (const skillName of SKILL_NAMES) {
40
+ const skillFile = path.join(skillsDir, skillName, 'SKILL.md');
41
+ if (fs.existsSync(skillFile)) {
42
+ skillCount++;
43
+ }
44
+ }
45
+ return {
46
+ configured: skillCount > 0,
47
+ fullyConfigured: skillCount === SKILL_NAMES.length,
48
+ skillCount,
49
+ };
50
+ }
51
+ /**
52
+ * Gets the skill status for all tools with skillsDir configured.
53
+ */
54
+ export function getToolStates(projectRoot) {
55
+ const states = new Map();
56
+ const toolIds = AI_TOOLS.filter((t) => t.skillsDir).map((t) => t.value);
57
+ for (const toolId of toolIds) {
58
+ states.set(toolId, getToolSkillStatus(projectRoot, toolId));
59
+ }
60
+ return states;
61
+ }
62
+ /**
63
+ * Extracts the generatedBy version from a skill file's YAML frontmatter.
64
+ * Returns null if the field is not found or the file doesn't exist.
65
+ */
66
+ export function extractGeneratedByVersion(skillFilePath) {
67
+ try {
68
+ if (!fs.existsSync(skillFilePath)) {
69
+ return null;
70
+ }
71
+ const content = fs.readFileSync(skillFilePath, 'utf-8');
72
+ // Look for generatedBy in the YAML frontmatter
73
+ // The file format is:
74
+ // ---
75
+ // ...
76
+ // metadata:
77
+ // author: openspec
78
+ // version: "1.0"
79
+ // generatedBy: "0.23.0"
80
+ // ---
81
+ const generatedByMatch = content.match(/^\s*generatedBy:\s*["']?([^"'\n]+)["']?\s*$/m);
82
+ if (generatedByMatch && generatedByMatch[1]) {
83
+ return generatedByMatch[1].trim();
84
+ }
85
+ return null;
86
+ }
87
+ catch {
88
+ return null;
89
+ }
90
+ }
91
+ /**
92
+ * Gets version status for a tool by reading the first available skill file.
93
+ */
94
+ export function getToolVersionStatus(projectRoot, toolId, currentVersion) {
95
+ const tool = AI_TOOLS.find((t) => t.value === toolId);
96
+ if (!tool?.skillsDir) {
97
+ return {
98
+ toolId,
99
+ toolName: toolId,
100
+ configured: false,
101
+ generatedByVersion: null,
102
+ needsUpdate: false,
103
+ };
104
+ }
105
+ const skillsDir = path.join(projectRoot, tool.skillsDir, 'skills');
106
+ let generatedByVersion = null;
107
+ // Find the first skill file that exists and read its version
108
+ for (const skillName of SKILL_NAMES) {
109
+ const skillFile = path.join(skillsDir, skillName, 'SKILL.md');
110
+ if (fs.existsSync(skillFile)) {
111
+ generatedByVersion = extractGeneratedByVersion(skillFile);
112
+ break;
113
+ }
114
+ }
115
+ const configured = getToolSkillStatus(projectRoot, toolId).configured;
116
+ const needsUpdate = configured && (generatedByVersion === null || generatedByVersion !== currentVersion);
117
+ return {
118
+ toolId,
119
+ toolName: tool.name,
120
+ configured,
121
+ generatedByVersion,
122
+ needsUpdate,
123
+ };
124
+ }
125
+ /**
126
+ * Gets all configured tools in the project.
127
+ */
128
+ export function getConfiguredTools(projectRoot) {
129
+ return AI_TOOLS
130
+ .filter((t) => t.skillsDir && getToolSkillStatus(projectRoot, t.value).configured)
131
+ .map((t) => t.value);
132
+ }
133
+ /**
134
+ * Gets version status for all configured tools.
135
+ */
136
+ export function getAllToolVersionStatus(projectRoot, currentVersion) {
137
+ const configuredTools = getConfiguredTools(projectRoot);
138
+ return configuredTools.map((toolId) => getToolVersionStatus(projectRoot, toolId, currentVersion));
139
+ }
140
+ //# sourceMappingURL=tool-detection.js.map
@@ -0,0 +1,73 @@
1
+ /**
2
+ * Spec Application Logic
3
+ *
4
+ * Extracted from ArchiveCommand to enable standalone spec application.
5
+ * Applies delta specs from a change to main specs without archiving.
6
+ */
7
+ export interface SpecUpdate {
8
+ source: string;
9
+ target: string;
10
+ exists: boolean;
11
+ }
12
+ export interface ApplyResult {
13
+ capability: string;
14
+ added: number;
15
+ modified: number;
16
+ removed: number;
17
+ renamed: number;
18
+ }
19
+ export interface SpecsApplyOutput {
20
+ changeName: string;
21
+ capabilities: ApplyResult[];
22
+ totals: {
23
+ added: number;
24
+ modified: number;
25
+ removed: number;
26
+ renamed: number;
27
+ };
28
+ noChanges: boolean;
29
+ }
30
+ /**
31
+ * Find all delta spec files that need to be applied from a change.
32
+ */
33
+ export declare function findSpecUpdates(changeDir: string, mainSpecsDir: string): Promise<SpecUpdate[]>;
34
+ /**
35
+ * Build an updated spec by applying delta operations.
36
+ * Returns the rebuilt content and counts of operations.
37
+ */
38
+ export declare function buildUpdatedSpec(update: SpecUpdate, changeName: string): Promise<{
39
+ rebuilt: string;
40
+ counts: {
41
+ added: number;
42
+ modified: number;
43
+ removed: number;
44
+ renamed: number;
45
+ };
46
+ }>;
47
+ /**
48
+ * Write an updated spec to disk.
49
+ */
50
+ export declare function writeUpdatedSpec(update: SpecUpdate, rebuilt: string, counts: {
51
+ added: number;
52
+ modified: number;
53
+ removed: number;
54
+ renamed: number;
55
+ }): Promise<void>;
56
+ /**
57
+ * Build a skeleton spec for new capabilities.
58
+ */
59
+ export declare function buildSpecSkeleton(specFolderName: string, changeName: string): string;
60
+ /**
61
+ * Apply all delta specs from a change to main specs.
62
+ *
63
+ * @param projectRoot - The project root directory
64
+ * @param changeName - The name of the change to apply
65
+ * @param options - Options for the operation
66
+ * @returns Result of the operation with counts
67
+ */
68
+ export declare function applySpecs(projectRoot: string, changeName: string, options?: {
69
+ dryRun?: boolean;
70
+ skipValidation?: boolean;
71
+ silent?: boolean;
72
+ }): Promise<SpecsApplyOutput>;
73
+ //# sourceMappingURL=specs-apply.d.ts.map
@@ -0,0 +1,384 @@
1
+ /**
2
+ * Spec Application Logic
3
+ *
4
+ * Extracted from ArchiveCommand to enable standalone spec application.
5
+ * Applies delta specs from a change to main specs without archiving.
6
+ */
7
+ import { promises as fs } from 'fs';
8
+ import path from 'path';
9
+ import chalk from 'chalk';
10
+ import { extractRequirementsSection, parseDeltaSpec, normalizeRequirementName, } from './parsers/requirement-blocks.js';
11
+ import { Validator } from './validation/validator.js';
12
+ // -----------------------------------------------------------------------------
13
+ // Public API
14
+ // -----------------------------------------------------------------------------
15
+ /**
16
+ * Find all delta spec files that need to be applied from a change.
17
+ */
18
+ export async function findSpecUpdates(changeDir, mainSpecsDir) {
19
+ const updates = [];
20
+ const changeSpecsDir = path.join(changeDir, 'specs');
21
+ try {
22
+ const entries = await fs.readdir(changeSpecsDir, { withFileTypes: true });
23
+ for (const entry of entries) {
24
+ if (entry.isDirectory()) {
25
+ const specFile = path.join(changeSpecsDir, entry.name, 'spec.md');
26
+ const targetFile = path.join(mainSpecsDir, entry.name, 'spec.md');
27
+ try {
28
+ await fs.access(specFile);
29
+ // Check if target exists
30
+ let exists = false;
31
+ try {
32
+ await fs.access(targetFile);
33
+ exists = true;
34
+ }
35
+ catch {
36
+ exists = false;
37
+ }
38
+ updates.push({
39
+ source: specFile,
40
+ target: targetFile,
41
+ exists,
42
+ });
43
+ }
44
+ catch {
45
+ // Source spec doesn't exist, skip
46
+ }
47
+ }
48
+ }
49
+ }
50
+ catch {
51
+ // No specs directory in change
52
+ }
53
+ return updates;
54
+ }
55
+ /**
56
+ * Build an updated spec by applying delta operations.
57
+ * Returns the rebuilt content and counts of operations.
58
+ */
59
+ export async function buildUpdatedSpec(update, changeName) {
60
+ // Read change spec content (delta-format expected)
61
+ const changeContent = await fs.readFile(update.source, 'utf-8');
62
+ // Parse deltas from the change spec file
63
+ const plan = parseDeltaSpec(changeContent);
64
+ const specName = path.basename(path.dirname(update.target));
65
+ // Pre-validate duplicates within sections
66
+ const addedNames = new Set();
67
+ for (const add of plan.added) {
68
+ const name = normalizeRequirementName(add.name);
69
+ if (addedNames.has(name)) {
70
+ throw new Error(`${specName} validation failed - duplicate requirement in ADDED for header "### Requirement: ${add.name}"`);
71
+ }
72
+ addedNames.add(name);
73
+ }
74
+ const modifiedNames = new Set();
75
+ for (const mod of plan.modified) {
76
+ const name = normalizeRequirementName(mod.name);
77
+ if (modifiedNames.has(name)) {
78
+ throw new Error(`${specName} validation failed - duplicate requirement in MODIFIED for header "### Requirement: ${mod.name}"`);
79
+ }
80
+ modifiedNames.add(name);
81
+ }
82
+ const removedNamesSet = new Set();
83
+ for (const rem of plan.removed) {
84
+ const name = normalizeRequirementName(rem);
85
+ if (removedNamesSet.has(name)) {
86
+ throw new Error(`${specName} validation failed - duplicate requirement in REMOVED for header "### Requirement: ${rem}"`);
87
+ }
88
+ removedNamesSet.add(name);
89
+ }
90
+ const renamedFromSet = new Set();
91
+ const renamedToSet = new Set();
92
+ for (const { from, to } of plan.renamed) {
93
+ const fromNorm = normalizeRequirementName(from);
94
+ const toNorm = normalizeRequirementName(to);
95
+ if (renamedFromSet.has(fromNorm)) {
96
+ throw new Error(`${specName} validation failed - duplicate FROM in RENAMED for header "### Requirement: ${from}"`);
97
+ }
98
+ if (renamedToSet.has(toNorm)) {
99
+ throw new Error(`${specName} validation failed - duplicate TO in RENAMED for header "### Requirement: ${to}"`);
100
+ }
101
+ renamedFromSet.add(fromNorm);
102
+ renamedToSet.add(toNorm);
103
+ }
104
+ // Pre-validate cross-section conflicts
105
+ const conflicts = [];
106
+ for (const n of modifiedNames) {
107
+ if (removedNamesSet.has(n))
108
+ conflicts.push({ name: n, a: 'MODIFIED', b: 'REMOVED' });
109
+ if (addedNames.has(n))
110
+ conflicts.push({ name: n, a: 'MODIFIED', b: 'ADDED' });
111
+ }
112
+ for (const n of addedNames) {
113
+ if (removedNamesSet.has(n))
114
+ conflicts.push({ name: n, a: 'ADDED', b: 'REMOVED' });
115
+ }
116
+ // Renamed interplay: MODIFIED must reference the NEW header, not FROM
117
+ for (const { from, to } of plan.renamed) {
118
+ const fromNorm = normalizeRequirementName(from);
119
+ const toNorm = normalizeRequirementName(to);
120
+ if (modifiedNames.has(fromNorm)) {
121
+ throw new Error(`${specName} validation failed - when a rename exists, MODIFIED must reference the NEW header "### Requirement: ${to}"`);
122
+ }
123
+ // Detect ADDED colliding with a RENAMED TO
124
+ if (addedNames.has(toNorm)) {
125
+ throw new Error(`${specName} validation failed - RENAMED TO header collides with ADDED for "### Requirement: ${to}"`);
126
+ }
127
+ }
128
+ if (conflicts.length > 0) {
129
+ const c = conflicts[0];
130
+ throw new Error(`${specName} validation failed - requirement present in multiple sections (${c.a} and ${c.b}) for header "### Requirement: ${c.name}"`);
131
+ }
132
+ const hasAnyDelta = plan.added.length + plan.modified.length + plan.removed.length + plan.renamed.length > 0;
133
+ if (!hasAnyDelta) {
134
+ throw new Error(`Delta parsing found no operations for ${path.basename(path.dirname(update.source))}. ` +
135
+ `Provide ADDED/MODIFIED/REMOVED/RENAMED sections in change spec.`);
136
+ }
137
+ // Load or create base target content
138
+ let targetContent;
139
+ let isNewSpec = false;
140
+ try {
141
+ targetContent = await fs.readFile(update.target, 'utf-8');
142
+ }
143
+ catch {
144
+ // Target spec does not exist; MODIFIED and RENAMED are not allowed for new specs
145
+ // REMOVED will be ignored with a warning since there's nothing to remove
146
+ if (plan.modified.length > 0 || plan.renamed.length > 0) {
147
+ throw new Error(`${specName}: target spec does not exist; only ADDED requirements are allowed for new specs. MODIFIED and RENAMED operations require an existing spec.`);
148
+ }
149
+ // Warn about REMOVED requirements being ignored for new specs
150
+ if (plan.removed.length > 0) {
151
+ console.log(chalk.yellow(`⚠️ Warning: ${specName} - ${plan.removed.length} REMOVED requirement(s) ignored for new spec (nothing to remove).`));
152
+ }
153
+ isNewSpec = true;
154
+ targetContent = buildSpecSkeleton(specName, changeName);
155
+ }
156
+ // Extract requirements section and build name->block map
157
+ const parts = extractRequirementsSection(targetContent);
158
+ const nameToBlock = new Map();
159
+ for (const block of parts.bodyBlocks) {
160
+ nameToBlock.set(normalizeRequirementName(block.name), block);
161
+ }
162
+ // Apply operations in order: RENAMED → REMOVED → MODIFIED → ADDED
163
+ // RENAMED
164
+ for (const r of plan.renamed) {
165
+ const from = normalizeRequirementName(r.from);
166
+ const to = normalizeRequirementName(r.to);
167
+ if (!nameToBlock.has(from)) {
168
+ throw new Error(`${specName} RENAMED failed for header "### Requirement: ${r.from}" - source not found`);
169
+ }
170
+ if (nameToBlock.has(to)) {
171
+ throw new Error(`${specName} RENAMED failed for header "### Requirement: ${r.to}" - target already exists`);
172
+ }
173
+ const block = nameToBlock.get(from);
174
+ const newHeader = `### Requirement: ${to}`;
175
+ const rawLines = block.raw.split('\n');
176
+ rawLines[0] = newHeader;
177
+ const renamedBlock = {
178
+ headerLine: newHeader,
179
+ name: to,
180
+ raw: rawLines.join('\n'),
181
+ };
182
+ nameToBlock.delete(from);
183
+ nameToBlock.set(to, renamedBlock);
184
+ }
185
+ // REMOVED
186
+ for (const name of plan.removed) {
187
+ const key = normalizeRequirementName(name);
188
+ if (!nameToBlock.has(key)) {
189
+ // For new specs, REMOVED requirements are already warned about and ignored
190
+ // For existing specs, missing requirements are an error
191
+ if (!isNewSpec) {
192
+ throw new Error(`${specName} REMOVED failed for header "### Requirement: ${name}" - not found`);
193
+ }
194
+ // Skip removal for new specs (already warned above)
195
+ continue;
196
+ }
197
+ nameToBlock.delete(key);
198
+ }
199
+ // MODIFIED
200
+ for (const mod of plan.modified) {
201
+ const key = normalizeRequirementName(mod.name);
202
+ if (!nameToBlock.has(key)) {
203
+ throw new Error(`${specName} MODIFIED failed for header "### Requirement: ${mod.name}" - not found`);
204
+ }
205
+ // Replace block with provided raw (ensure header line matches key)
206
+ const modHeaderMatch = mod.raw.split('\n')[0].match(/^###\s*Requirement:\s*(.+)\s*$/);
207
+ if (!modHeaderMatch || normalizeRequirementName(modHeaderMatch[1]) !== key) {
208
+ throw new Error(`${specName} MODIFIED failed for header "### Requirement: ${mod.name}" - header mismatch in content`);
209
+ }
210
+ nameToBlock.set(key, mod);
211
+ }
212
+ // ADDED
213
+ for (const add of plan.added) {
214
+ const key = normalizeRequirementName(add.name);
215
+ if (nameToBlock.has(key)) {
216
+ throw new Error(`${specName} ADDED failed for header "### Requirement: ${add.name}" - already exists`);
217
+ }
218
+ nameToBlock.set(key, add);
219
+ }
220
+ // Duplicates within resulting map are implicitly prevented by key uniqueness.
221
+ // Recompose requirements section preserving original ordering where possible
222
+ const keptOrder = [];
223
+ const seen = new Set();
224
+ for (const block of parts.bodyBlocks) {
225
+ const key = normalizeRequirementName(block.name);
226
+ const replacement = nameToBlock.get(key);
227
+ if (replacement) {
228
+ keptOrder.push(replacement);
229
+ seen.add(key);
230
+ }
231
+ }
232
+ // Append any newly added that were not in original order
233
+ for (const [key, block] of nameToBlock.entries()) {
234
+ if (!seen.has(key)) {
235
+ keptOrder.push(block);
236
+ }
237
+ }
238
+ const reqBody = [parts.preamble && parts.preamble.trim() ? parts.preamble.trimEnd() : '']
239
+ .filter(Boolean)
240
+ .concat(keptOrder.map((b) => b.raw))
241
+ .join('\n\n')
242
+ .trimEnd();
243
+ const rebuilt = [parts.before.trimEnd(), parts.headerLine, reqBody, parts.after]
244
+ .filter((s, idx) => !(idx === 0 && s === ''))
245
+ .join('\n')
246
+ .replace(/\n{3,}/g, '\n\n');
247
+ return {
248
+ rebuilt,
249
+ counts: {
250
+ added: plan.added.length,
251
+ modified: plan.modified.length,
252
+ removed: plan.removed.length,
253
+ renamed: plan.renamed.length,
254
+ },
255
+ };
256
+ }
257
+ /**
258
+ * Write an updated spec to disk.
259
+ */
260
+ export async function writeUpdatedSpec(update, rebuilt, counts) {
261
+ // Create target directory if needed
262
+ const targetDir = path.dirname(update.target);
263
+ await fs.mkdir(targetDir, { recursive: true });
264
+ await fs.writeFile(update.target, rebuilt);
265
+ const specName = path.basename(path.dirname(update.target));
266
+ console.log(`Applying changes to openspec/specs/${specName}/spec.md:`);
267
+ if (counts.added)
268
+ console.log(` + ${counts.added} added`);
269
+ if (counts.modified)
270
+ console.log(` ~ ${counts.modified} modified`);
271
+ if (counts.removed)
272
+ console.log(` - ${counts.removed} removed`);
273
+ if (counts.renamed)
274
+ console.log(` → ${counts.renamed} renamed`);
275
+ }
276
+ /**
277
+ * Build a skeleton spec for new capabilities.
278
+ */
279
+ export function buildSpecSkeleton(specFolderName, changeName) {
280
+ const titleBase = specFolderName;
281
+ return `# ${titleBase} Specification\n\n## Purpose\nTBD - created by archiving change ${changeName}. Update Purpose after archive.\n\n## Requirements\n`;
282
+ }
283
+ /**
284
+ * Apply all delta specs from a change to main specs.
285
+ *
286
+ * @param projectRoot - The project root directory
287
+ * @param changeName - The name of the change to apply
288
+ * @param options - Options for the operation
289
+ * @returns Result of the operation with counts
290
+ */
291
+ export async function applySpecs(projectRoot, changeName, options = {}) {
292
+ const changeDir = path.join(projectRoot, 'openspec', 'changes', changeName);
293
+ const mainSpecsDir = path.join(projectRoot, 'openspec', 'specs');
294
+ // Verify change exists
295
+ try {
296
+ const stat = await fs.stat(changeDir);
297
+ if (!stat.isDirectory()) {
298
+ throw new Error(`Change '${changeName}' not found.`);
299
+ }
300
+ }
301
+ catch {
302
+ throw new Error(`Change '${changeName}' not found.`);
303
+ }
304
+ // Find specs to update
305
+ const specUpdates = await findSpecUpdates(changeDir, mainSpecsDir);
306
+ if (specUpdates.length === 0) {
307
+ return {
308
+ changeName,
309
+ capabilities: [],
310
+ totals: { added: 0, modified: 0, removed: 0, renamed: 0 },
311
+ noChanges: true,
312
+ };
313
+ }
314
+ // Prepare all updates first (validation pass, no writes)
315
+ const prepared = [];
316
+ for (const update of specUpdates) {
317
+ const built = await buildUpdatedSpec(update, changeName);
318
+ prepared.push({ update, rebuilt: built.rebuilt, counts: built.counts });
319
+ }
320
+ // Validate rebuilt specs unless validation is skipped
321
+ if (!options.skipValidation) {
322
+ const validator = new Validator();
323
+ for (const p of prepared) {
324
+ const specName = path.basename(path.dirname(p.update.target));
325
+ const report = await validator.validateSpecContent(specName, p.rebuilt);
326
+ if (!report.valid) {
327
+ const errors = report.issues
328
+ .filter((i) => i.level === 'ERROR')
329
+ .map((i) => ` ✗ ${i.message}`)
330
+ .join('\n');
331
+ throw new Error(`Validation errors in rebuilt spec for ${specName}:\n${errors}`);
332
+ }
333
+ }
334
+ }
335
+ // Build results
336
+ const capabilities = [];
337
+ const totals = { added: 0, modified: 0, removed: 0, renamed: 0 };
338
+ for (const p of prepared) {
339
+ const capability = path.basename(path.dirname(p.update.target));
340
+ if (!options.dryRun) {
341
+ // Write the updated spec
342
+ const targetDir = path.dirname(p.update.target);
343
+ await fs.mkdir(targetDir, { recursive: true });
344
+ await fs.writeFile(p.update.target, p.rebuilt);
345
+ if (!options.silent) {
346
+ console.log(`Applying changes to openspec/specs/${capability}/spec.md:`);
347
+ if (p.counts.added)
348
+ console.log(` + ${p.counts.added} added`);
349
+ if (p.counts.modified)
350
+ console.log(` ~ ${p.counts.modified} modified`);
351
+ if (p.counts.removed)
352
+ console.log(` - ${p.counts.removed} removed`);
353
+ if (p.counts.renamed)
354
+ console.log(` → ${p.counts.renamed} renamed`);
355
+ }
356
+ }
357
+ else if (!options.silent) {
358
+ console.log(`Would apply changes to openspec/specs/${capability}/spec.md:`);
359
+ if (p.counts.added)
360
+ console.log(` + ${p.counts.added} added`);
361
+ if (p.counts.modified)
362
+ console.log(` ~ ${p.counts.modified} modified`);
363
+ if (p.counts.removed)
364
+ console.log(` - ${p.counts.removed} removed`);
365
+ if (p.counts.renamed)
366
+ console.log(` → ${p.counts.renamed} renamed`);
367
+ }
368
+ capabilities.push({
369
+ capability,
370
+ ...p.counts,
371
+ });
372
+ totals.added += p.counts.added;
373
+ totals.modified += p.counts.modified;
374
+ totals.removed += p.counts.removed;
375
+ totals.renamed += p.counts.renamed;
376
+ }
377
+ return {
378
+ changeName,
379
+ capabilities,
380
+ totals,
381
+ noChanges: false,
382
+ };
383
+ }
384
+ //# sourceMappingURL=specs-apply.js.map
@@ -0,0 +1,7 @@
1
+ export declare const PALETTE: {
2
+ white: import("chalk").ChalkInstance;
3
+ lightGray: import("chalk").ChalkInstance;
4
+ midGray: import("chalk").ChalkInstance;
5
+ darkGray: import("chalk").ChalkInstance;
6
+ };
7
+ //# sourceMappingURL=palette.d.ts.map
@@ -0,0 +1,8 @@
1
+ import chalk from 'chalk';
2
+ export const PALETTE = {
3
+ white: chalk.hex('#f4f4f4'),
4
+ lightGray: chalk.hex('#c8c8c8'),
5
+ midGray: chalk.hex('#8a8a8a'),
6
+ darkGray: chalk.hex('#4a4a4a')
7
+ };
8
+ //# sourceMappingURL=palette.js.map
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Template exports for OpenSpec.
3
+ *
4
+ * The old config file templates (AGENTS.md, project.md, claude-template, etc.)
5
+ * have been removed. The skill-based workflow uses skill-templates.ts directly.
6
+ */
7
+ export { getExploreSkillTemplate, getNewChangeSkillTemplate, getContinueChangeSkillTemplate, getApplyChangeSkillTemplate, getFfChangeSkillTemplate, getSyncSpecsSkillTemplate, getArchiveChangeSkillTemplate, getBulkArchiveChangeSkillTemplate, getVerifyChangeSkillTemplate, getOpsxExploreCommandTemplate, getOpsxNewCommandTemplate, getOpsxContinueCommandTemplate, getOpsxApplyCommandTemplate, getOpsxFfCommandTemplate, getOpsxSyncCommandTemplate, getOpsxArchiveCommandTemplate, getOpsxBulkArchiveCommandTemplate, getOpsxVerifyCommandTemplate, } from './skill-templates.js';
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Template exports for OpenSpec.
3
+ *
4
+ * The old config file templates (AGENTS.md, project.md, claude-template, etc.)
5
+ * have been removed. The skill-based workflow uses skill-templates.ts directly.
6
+ */
7
+ // Re-export skill templates for convenience
8
+ export { getExploreSkillTemplate, getNewChangeSkillTemplate, getContinueChangeSkillTemplate, getApplyChangeSkillTemplate, getFfChangeSkillTemplate, getSyncSpecsSkillTemplate, getArchiveChangeSkillTemplate, getBulkArchiveChangeSkillTemplate, getVerifyChangeSkillTemplate, getOpsxExploreCommandTemplate, getOpsxNewCommandTemplate, getOpsxContinueCommandTemplate, getOpsxApplyCommandTemplate, getOpsxFfCommandTemplate, getOpsxSyncCommandTemplate, getOpsxArchiveCommandTemplate, getOpsxBulkArchiveCommandTemplate, getOpsxVerifyCommandTemplate, } from './skill-templates.js';
9
+ //# sourceMappingURL=index.js.map