@dynamicworks/br-openspec 1.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (291) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +210 -0
  3. package/README.pt-BR.md +212 -0
  4. package/bin/openspec.js +3 -0
  5. package/dist/cli/index.d.ts +2 -0
  6. package/dist/cli/index.js +484 -0
  7. package/dist/commands/change.d.ts +35 -0
  8. package/dist/commands/change.js +278 -0
  9. package/dist/commands/completion.d.ts +72 -0
  10. package/dist/commands/completion.js +258 -0
  11. package/dist/commands/config.d.ts +36 -0
  12. package/dist/commands/config.js +553 -0
  13. package/dist/commands/feedback.d.ts +9 -0
  14. package/dist/commands/feedback.js +184 -0
  15. package/dist/commands/schema.d.ts +6 -0
  16. package/dist/commands/schema.js +869 -0
  17. package/dist/commands/show.d.ts +14 -0
  18. package/dist/commands/show.js +133 -0
  19. package/dist/commands/spec.d.ts +15 -0
  20. package/dist/commands/spec.js +226 -0
  21. package/dist/commands/tools.d.ts +11 -0
  22. package/dist/commands/tools.js +252 -0
  23. package/dist/commands/validate.d.ts +24 -0
  24. package/dist/commands/validate.js +295 -0
  25. package/dist/commands/workflow/index.d.ts +17 -0
  26. package/dist/commands/workflow/index.js +12 -0
  27. package/dist/commands/workflow/instructions.d.ts +29 -0
  28. package/dist/commands/workflow/instructions.js +328 -0
  29. package/dist/commands/workflow/new-change.d.ts +11 -0
  30. package/dist/commands/workflow/new-change.js +44 -0
  31. package/dist/commands/workflow/schemas.d.ts +10 -0
  32. package/dist/commands/workflow/schemas.js +35 -0
  33. package/dist/commands/workflow/shared.d.ts +57 -0
  34. package/dist/commands/workflow/shared.js +117 -0
  35. package/dist/commands/workflow/status.d.ts +14 -0
  36. package/dist/commands/workflow/status.js +76 -0
  37. package/dist/commands/workflow/templates.d.ts +16 -0
  38. package/dist/commands/workflow/templates.js +70 -0
  39. package/dist/core/archive.d.ts +11 -0
  40. package/dist/core/archive.js +322 -0
  41. package/dist/core/artifact-graph/graph.d.ts +56 -0
  42. package/dist/core/artifact-graph/graph.js +141 -0
  43. package/dist/core/artifact-graph/index.d.ts +8 -0
  44. package/dist/core/artifact-graph/index.js +14 -0
  45. package/dist/core/artifact-graph/instruction-loader.d.ts +143 -0
  46. package/dist/core/artifact-graph/instruction-loader.js +217 -0
  47. package/dist/core/artifact-graph/outputs.d.ts +14 -0
  48. package/dist/core/artifact-graph/outputs.js +39 -0
  49. package/dist/core/artifact-graph/resolver.d.ts +81 -0
  50. package/dist/core/artifact-graph/resolver.js +258 -0
  51. package/dist/core/artifact-graph/schema.d.ts +13 -0
  52. package/dist/core/artifact-graph/schema.js +108 -0
  53. package/dist/core/artifact-graph/state.d.ts +12 -0
  54. package/dist/core/artifact-graph/state.js +31 -0
  55. package/dist/core/artifact-graph/types.d.ts +45 -0
  56. package/dist/core/artifact-graph/types.js +43 -0
  57. package/dist/core/available-tools.d.ts +17 -0
  58. package/dist/core/available-tools.js +43 -0
  59. package/dist/core/command-generation/adapters/amazon-q.d.ts +13 -0
  60. package/dist/core/command-generation/adapters/amazon-q.js +26 -0
  61. package/dist/core/command-generation/adapters/antigravity.d.ts +13 -0
  62. package/dist/core/command-generation/adapters/antigravity.js +26 -0
  63. package/dist/core/command-generation/adapters/auggie.d.ts +13 -0
  64. package/dist/core/command-generation/adapters/auggie.js +27 -0
  65. package/dist/core/command-generation/adapters/bob.d.ts +14 -0
  66. package/dist/core/command-generation/adapters/bob.js +45 -0
  67. package/dist/core/command-generation/adapters/claude.d.ts +13 -0
  68. package/dist/core/command-generation/adapters/claude.js +50 -0
  69. package/dist/core/command-generation/adapters/cline.d.ts +14 -0
  70. package/dist/core/command-generation/adapters/cline.js +27 -0
  71. package/dist/core/command-generation/adapters/codebuddy.d.ts +13 -0
  72. package/dist/core/command-generation/adapters/codebuddy.js +28 -0
  73. package/dist/core/command-generation/adapters/codex.d.ts +16 -0
  74. package/dist/core/command-generation/adapters/codex.js +39 -0
  75. package/dist/core/command-generation/adapters/continue.d.ts +13 -0
  76. package/dist/core/command-generation/adapters/continue.js +28 -0
  77. package/dist/core/command-generation/adapters/costrict.d.ts +13 -0
  78. package/dist/core/command-generation/adapters/costrict.js +27 -0
  79. package/dist/core/command-generation/adapters/crush.d.ts +13 -0
  80. package/dist/core/command-generation/adapters/crush.js +30 -0
  81. package/dist/core/command-generation/adapters/cursor.d.ts +14 -0
  82. package/dist/core/command-generation/adapters/cursor.js +44 -0
  83. package/dist/core/command-generation/adapters/factory.d.ts +13 -0
  84. package/dist/core/command-generation/adapters/factory.js +27 -0
  85. package/dist/core/command-generation/adapters/gemini.d.ts +13 -0
  86. package/dist/core/command-generation/adapters/gemini.js +26 -0
  87. package/dist/core/command-generation/adapters/github-copilot.d.ts +13 -0
  88. package/dist/core/command-generation/adapters/github-copilot.js +26 -0
  89. package/dist/core/command-generation/adapters/iflow.d.ts +13 -0
  90. package/dist/core/command-generation/adapters/iflow.js +29 -0
  91. package/dist/core/command-generation/adapters/index.d.ts +32 -0
  92. package/dist/core/command-generation/adapters/index.js +32 -0
  93. package/dist/core/command-generation/adapters/junie.d.ts +13 -0
  94. package/dist/core/command-generation/adapters/junie.js +26 -0
  95. package/dist/core/command-generation/adapters/kilocode.d.ts +14 -0
  96. package/dist/core/command-generation/adapters/kilocode.js +23 -0
  97. package/dist/core/command-generation/adapters/kiro.d.ts +13 -0
  98. package/dist/core/command-generation/adapters/kiro.js +26 -0
  99. package/dist/core/command-generation/adapters/lingma.d.ts +13 -0
  100. package/dist/core/command-generation/adapters/lingma.js +30 -0
  101. package/dist/core/command-generation/adapters/opencode.d.ts +13 -0
  102. package/dist/core/command-generation/adapters/opencode.js +29 -0
  103. package/dist/core/command-generation/adapters/pi.d.ts +18 -0
  104. package/dist/core/command-generation/adapters/pi.js +55 -0
  105. package/dist/core/command-generation/adapters/qoder.d.ts +13 -0
  106. package/dist/core/command-generation/adapters/qoder.js +30 -0
  107. package/dist/core/command-generation/adapters/qwen.d.ts +13 -0
  108. package/dist/core/command-generation/adapters/qwen.js +26 -0
  109. package/dist/core/command-generation/adapters/roocode.d.ts +14 -0
  110. package/dist/core/command-generation/adapters/roocode.js +27 -0
  111. package/dist/core/command-generation/adapters/windsurf.d.ts +14 -0
  112. package/dist/core/command-generation/adapters/windsurf.js +51 -0
  113. package/dist/core/command-generation/generator.d.ts +21 -0
  114. package/dist/core/command-generation/generator.js +27 -0
  115. package/dist/core/command-generation/index.d.ts +22 -0
  116. package/dist/core/command-generation/index.js +24 -0
  117. package/dist/core/command-generation/registry.d.ts +36 -0
  118. package/dist/core/command-generation/registry.js +98 -0
  119. package/dist/core/command-generation/types.d.ts +56 -0
  120. package/dist/core/command-generation/types.js +8 -0
  121. package/dist/core/completions/command-registry.d.ts +7 -0
  122. package/dist/core/completions/command-registry.js +462 -0
  123. package/dist/core/completions/completion-provider.d.ts +60 -0
  124. package/dist/core/completions/completion-provider.js +102 -0
  125. package/dist/core/completions/factory.d.ts +64 -0
  126. package/dist/core/completions/factory.js +75 -0
  127. package/dist/core/completions/generators/bash-generator.d.ts +32 -0
  128. package/dist/core/completions/generators/bash-generator.js +174 -0
  129. package/dist/core/completions/generators/fish-generator.d.ts +32 -0
  130. package/dist/core/completions/generators/fish-generator.js +157 -0
  131. package/dist/core/completions/generators/powershell-generator.d.ts +33 -0
  132. package/dist/core/completions/generators/powershell-generator.js +208 -0
  133. package/dist/core/completions/generators/zsh-generator.d.ts +44 -0
  134. package/dist/core/completions/generators/zsh-generator.js +250 -0
  135. package/dist/core/completions/installers/bash-installer.d.ts +87 -0
  136. package/dist/core/completions/installers/bash-installer.js +319 -0
  137. package/dist/core/completions/installers/fish-installer.d.ts +43 -0
  138. package/dist/core/completions/installers/fish-installer.js +143 -0
  139. package/dist/core/completions/installers/powershell-installer.d.ts +102 -0
  140. package/dist/core/completions/installers/powershell-installer.js +400 -0
  141. package/dist/core/completions/installers/zsh-installer.d.ts +125 -0
  142. package/dist/core/completions/installers/zsh-installer.js +450 -0
  143. package/dist/core/completions/templates/bash-templates.d.ts +6 -0
  144. package/dist/core/completions/templates/bash-templates.js +24 -0
  145. package/dist/core/completions/templates/fish-templates.d.ts +7 -0
  146. package/dist/core/completions/templates/fish-templates.js +39 -0
  147. package/dist/core/completions/templates/powershell-templates.d.ts +6 -0
  148. package/dist/core/completions/templates/powershell-templates.js +25 -0
  149. package/dist/core/completions/templates/zsh-templates.d.ts +6 -0
  150. package/dist/core/completions/templates/zsh-templates.js +36 -0
  151. package/dist/core/completions/types.d.ts +79 -0
  152. package/dist/core/completions/types.js +2 -0
  153. package/dist/core/config-prompts.d.ts +9 -0
  154. package/dist/core/config-prompts.js +34 -0
  155. package/dist/core/config-schema.d.ts +86 -0
  156. package/dist/core/config-schema.js +213 -0
  157. package/dist/core/config.d.ts +18 -0
  158. package/dist/core/config.js +38 -0
  159. package/dist/core/converters/json-converter.d.ts +6 -0
  160. package/dist/core/converters/json-converter.js +51 -0
  161. package/dist/core/global-config.d.ts +44 -0
  162. package/dist/core/global-config.js +125 -0
  163. package/dist/core/index.d.ts +2 -0
  164. package/dist/core/index.js +3 -0
  165. package/dist/core/init.d.ts +37 -0
  166. package/dist/core/init.js +549 -0
  167. package/dist/core/is-project-initialized.d.ts +12 -0
  168. package/dist/core/is-project-initialized.js +18 -0
  169. package/dist/core/legacy-cleanup.d.ts +162 -0
  170. package/dist/core/legacy-cleanup.js +515 -0
  171. package/dist/core/list.d.ts +9 -0
  172. package/dist/core/list.js +172 -0
  173. package/dist/core/migration.d.ts +23 -0
  174. package/dist/core/migration.js +109 -0
  175. package/dist/core/parsers/change-parser.d.ts +13 -0
  176. package/dist/core/parsers/change-parser.js +197 -0
  177. package/dist/core/parsers/markdown-parser.d.ts +26 -0
  178. package/dist/core/parsers/markdown-parser.js +228 -0
  179. package/dist/core/parsers/requirement-blocks.d.ts +37 -0
  180. package/dist/core/parsers/requirement-blocks.js +201 -0
  181. package/dist/core/parsers/spec-structure.d.ts +9 -0
  182. package/dist/core/parsers/spec-structure.js +88 -0
  183. package/dist/core/profile-sync-drift.d.ts +38 -0
  184. package/dist/core/profile-sync-drift.js +200 -0
  185. package/dist/core/profiles.d.ts +26 -0
  186. package/dist/core/profiles.js +40 -0
  187. package/dist/core/project-config.d.ts +64 -0
  188. package/dist/core/project-config.js +224 -0
  189. package/dist/core/schemas/base.schema.d.ts +13 -0
  190. package/dist/core/schemas/base.schema.js +13 -0
  191. package/dist/core/schemas/change.schema.d.ts +73 -0
  192. package/dist/core/schemas/change.schema.js +31 -0
  193. package/dist/core/schemas/index.d.ts +4 -0
  194. package/dist/core/schemas/index.js +4 -0
  195. package/dist/core/schemas/spec.schema.d.ts +18 -0
  196. package/dist/core/schemas/spec.schema.js +15 -0
  197. package/dist/core/shared/index.d.ts +8 -0
  198. package/dist/core/shared/index.js +8 -0
  199. package/dist/core/shared/skill-generation.d.ts +49 -0
  200. package/dist/core/shared/skill-generation.js +96 -0
  201. package/dist/core/shared/tool-detection.d.ts +71 -0
  202. package/dist/core/shared/tool-detection.js +158 -0
  203. package/dist/core/specs-apply.d.ts +73 -0
  204. package/dist/core/specs-apply.js +393 -0
  205. package/dist/core/styles/palette.d.ts +7 -0
  206. package/dist/core/styles/palette.js +8 -0
  207. package/dist/core/templates/index.d.ts +8 -0
  208. package/dist/core/templates/index.js +9 -0
  209. package/dist/core/templates/skill-templates.d.ts +20 -0
  210. package/dist/core/templates/skill-templates.js +19 -0
  211. package/dist/core/templates/types.d.ts +19 -0
  212. package/dist/core/templates/types.js +5 -0
  213. package/dist/core/templates/workflows/apply-change.d.ts +10 -0
  214. package/dist/core/templates/workflows/apply-change.js +308 -0
  215. package/dist/core/templates/workflows/archive-change.d.ts +10 -0
  216. package/dist/core/templates/workflows/archive-change.js +271 -0
  217. package/dist/core/templates/workflows/bulk-archive-change.d.ts +10 -0
  218. package/dist/core/templates/workflows/bulk-archive-change.js +492 -0
  219. package/dist/core/templates/workflows/continue-change.d.ts +10 -0
  220. package/dist/core/templates/workflows/continue-change.js +232 -0
  221. package/dist/core/templates/workflows/explore.d.ts +10 -0
  222. package/dist/core/templates/workflows/explore.js +463 -0
  223. package/dist/core/templates/workflows/feedback.d.ts +9 -0
  224. package/dist/core/templates/workflows/feedback.js +108 -0
  225. package/dist/core/templates/workflows/ff-change.d.ts +10 -0
  226. package/dist/core/templates/workflows/ff-change.js +198 -0
  227. package/dist/core/templates/workflows/new-change.d.ts +10 -0
  228. package/dist/core/templates/workflows/new-change.js +21 -0
  229. package/dist/core/templates/workflows/onboard.d.ts +10 -0
  230. package/dist/core/templates/workflows/onboard.js +21 -0
  231. package/dist/core/templates/workflows/propose.d.ts +10 -0
  232. package/dist/core/templates/workflows/propose.js +216 -0
  233. package/dist/core/templates/workflows/sync-specs.d.ts +10 -0
  234. package/dist/core/templates/workflows/sync-specs.js +272 -0
  235. package/dist/core/templates/workflows/upstream-sync.d.ts +10 -0
  236. package/dist/core/templates/workflows/upstream-sync.js +116 -0
  237. package/dist/core/templates/workflows/verify-change.d.ts +10 -0
  238. package/dist/core/templates/workflows/verify-change.js +21 -0
  239. package/dist/core/tools-manager.d.ts +56 -0
  240. package/dist/core/tools-manager.js +215 -0
  241. package/dist/core/update.d.ts +77 -0
  242. package/dist/core/update.js +538 -0
  243. package/dist/core/validation/constants.d.ts +34 -0
  244. package/dist/core/validation/constants.js +40 -0
  245. package/dist/core/validation/types.d.ts +18 -0
  246. package/dist/core/validation/types.js +2 -0
  247. package/dist/core/validation/validator.d.ts +33 -0
  248. package/dist/core/validation/validator.js +419 -0
  249. package/dist/core/view.d.ts +8 -0
  250. package/dist/core/view.js +169 -0
  251. package/dist/index.d.ts +3 -0
  252. package/dist/index.js +3 -0
  253. package/dist/messages/index.d.ts +867 -0
  254. package/dist/messages/index.js +1960 -0
  255. package/dist/prompts/searchable-multi-select.d.ts +28 -0
  256. package/dist/prompts/searchable-multi-select.js +160 -0
  257. package/dist/telemetry/config.d.ts +38 -0
  258. package/dist/telemetry/config.js +136 -0
  259. package/dist/telemetry/index.d.ts +31 -0
  260. package/dist/telemetry/index.js +165 -0
  261. package/dist/ui/ascii-patterns.d.ts +16 -0
  262. package/dist/ui/ascii-patterns.js +133 -0
  263. package/dist/ui/welcome-screen.d.ts +10 -0
  264. package/dist/ui/welcome-screen.js +147 -0
  265. package/dist/utils/change-metadata.d.ts +51 -0
  266. package/dist/utils/change-metadata.js +147 -0
  267. package/dist/utils/change-utils.d.ts +62 -0
  268. package/dist/utils/change-utils.js +121 -0
  269. package/dist/utils/command-references.d.ts +18 -0
  270. package/dist/utils/command-references.js +20 -0
  271. package/dist/utils/file-system.d.ts +41 -0
  272. package/dist/utils/file-system.js +302 -0
  273. package/dist/utils/index.d.ts +6 -0
  274. package/dist/utils/index.js +9 -0
  275. package/dist/utils/interactive.d.ts +18 -0
  276. package/dist/utils/interactive.js +21 -0
  277. package/dist/utils/item-discovery.d.ts +4 -0
  278. package/dist/utils/item-discovery.js +72 -0
  279. package/dist/utils/match.d.ts +3 -0
  280. package/dist/utils/match.js +22 -0
  281. package/dist/utils/shell-detection.d.ts +20 -0
  282. package/dist/utils/shell-detection.js +41 -0
  283. package/dist/utils/task-progress.d.ts +8 -0
  284. package/dist/utils/task-progress.js +37 -0
  285. package/package.json +84 -0
  286. package/schemas/spec-driven/schema.yaml +153 -0
  287. package/schemas/spec-driven/templates/design.md +19 -0
  288. package/schemas/spec-driven/templates/proposal.md +23 -0
  289. package/schemas/spec-driven/templates/spec.md +8 -0
  290. package/schemas/spec-driven/templates/tasks.md +9 -0
  291. package/scripts/postinstall.js +83 -0
@@ -0,0 +1,278 @@
1
+ import { promises as fs } from 'fs';
2
+ import path from 'path';
3
+ import { JsonConverter } from '../core/converters/json-converter.js';
4
+ import { Validator } from '../core/validation/validator.js';
5
+ import { ChangeParser } from '../core/parsers/change-parser.js';
6
+ import { isInteractive } from '../utils/interactive.js';
7
+ import { getActiveChangeIds } from '../utils/item-discovery.js';
8
+ import { CHANGE_MESSAGES, UTILS_MESSAGES } from '../messages/index.js';
9
+ // Constants for better maintainability
10
+ const ARCHIVE_DIR = 'archive';
11
+ const TASK_PATTERN = /^[-*]\s+\[[\sx]\]/i;
12
+ const COMPLETED_TASK_PATTERN = /^[-*]\s+\[x\]/i;
13
+ export class ChangeCommand {
14
+ converter;
15
+ constructor() {
16
+ this.converter = new JsonConverter();
17
+ }
18
+ /**
19
+ * Show a change proposal.
20
+ * - Text mode: raw markdown passthrough (no filters)
21
+ * - JSON mode: minimal object with deltas; --deltas-only returns same object with filtered deltas
22
+ * Note: --requirements-only is deprecated alias for --deltas-only
23
+ */
24
+ async show(changeName, options) {
25
+ const changesPath = path.join(process.cwd(), 'openspec', 'changes');
26
+ if (!changeName) {
27
+ const canPrompt = isInteractive(options);
28
+ const changes = await this.getActiveChanges(changesPath);
29
+ if (canPrompt && changes.length > 0) {
30
+ const { select } = await import('@inquirer/prompts');
31
+ const selected = await select({
32
+ message: CHANGE_MESSAGES.selectChangeToShow,
33
+ choices: changes.map(id => ({ name: id, value: id })),
34
+ });
35
+ changeName = selected;
36
+ }
37
+ else {
38
+ if (changes.length === 0) {
39
+ console.error(CHANGE_MESSAGES.noChangeSpecifiedNoActive);
40
+ }
41
+ else {
42
+ console.error(CHANGE_MESSAGES.noChangeSpecifiedAvailable(changes.join(', ')));
43
+ }
44
+ console.error(CHANGE_MESSAGES.hintViewChanges);
45
+ process.exitCode = 1;
46
+ return;
47
+ }
48
+ }
49
+ const proposalPath = path.join(changesPath, changeName, 'proposal.md');
50
+ try {
51
+ await fs.access(proposalPath);
52
+ }
53
+ catch {
54
+ throw new Error(CHANGE_MESSAGES.changeNotFound(changeName, proposalPath));
55
+ }
56
+ if (options?.json) {
57
+ const jsonOutput = await this.converter.convertChangeToJson(proposalPath);
58
+ if (options.requirementsOnly) {
59
+ console.error(CHANGE_MESSAGES.requirementsOnlyDeprecated);
60
+ }
61
+ const parsed = JSON.parse(jsonOutput);
62
+ const contentForTitle = await fs.readFile(proposalPath, 'utf-8');
63
+ const title = this.extractTitle(contentForTitle, changeName);
64
+ const id = parsed.name;
65
+ const deltas = parsed.deltas || [];
66
+ if (options.requirementsOnly || options.deltasOnly) {
67
+ const output = { id, title, deltaCount: deltas.length, deltas };
68
+ console.log(JSON.stringify(output, null, 2));
69
+ }
70
+ else {
71
+ const output = {
72
+ id,
73
+ title,
74
+ deltaCount: deltas.length,
75
+ deltas,
76
+ };
77
+ console.log(JSON.stringify(output, null, 2));
78
+ }
79
+ }
80
+ else {
81
+ const content = await fs.readFile(proposalPath, 'utf-8');
82
+ console.log(content);
83
+ }
84
+ }
85
+ /**
86
+ * List active changes.
87
+ * - Text default: IDs only; --long prints minimal details (title, counts)
88
+ * - JSON: array of { id, title, deltaCount, taskStatus }, sorted by id
89
+ */
90
+ async list(options) {
91
+ const changesPath = path.join(process.cwd(), 'openspec', 'changes');
92
+ const changes = await this.getActiveChanges(changesPath);
93
+ if (options?.json) {
94
+ const changeDetails = await Promise.all(changes.map(async (changeName) => {
95
+ const proposalPath = path.join(changesPath, changeName, 'proposal.md');
96
+ const tasksPath = path.join(changesPath, changeName, 'tasks.md');
97
+ try {
98
+ const content = await fs.readFile(proposalPath, 'utf-8');
99
+ const changeDir = path.join(changesPath, changeName);
100
+ const parser = new ChangeParser(content, changeDir);
101
+ const change = await parser.parseChangeWithDeltas(changeName);
102
+ let taskStatus = { total: 0, completed: 0 };
103
+ try {
104
+ const tasksContent = await fs.readFile(tasksPath, 'utf-8');
105
+ taskStatus = this.countTasks(tasksContent);
106
+ }
107
+ catch (error) {
108
+ // Tasks file may not exist, which is okay
109
+ if (process.env.DEBUG) {
110
+ console.error(UTILS_MESSAGES.failedToReadTasks(tasksPath, error));
111
+ }
112
+ }
113
+ return {
114
+ id: changeName,
115
+ title: this.extractTitle(content, changeName),
116
+ deltaCount: change.deltas.length,
117
+ taskStatus,
118
+ };
119
+ }
120
+ catch (error) {
121
+ return {
122
+ id: changeName,
123
+ title: 'Unknown',
124
+ deltaCount: 0,
125
+ taskStatus: { total: 0, completed: 0 },
126
+ };
127
+ }
128
+ }));
129
+ const sorted = changeDetails.sort((a, b) => a.id.localeCompare(b.id));
130
+ console.log(JSON.stringify(sorted, null, 2));
131
+ }
132
+ else {
133
+ if (changes.length === 0) {
134
+ console.log(CHANGE_MESSAGES.noItemsFound);
135
+ return;
136
+ }
137
+ const sorted = [...changes].sort();
138
+ if (!options?.long) {
139
+ // IDs only
140
+ sorted.forEach(id => console.log(id));
141
+ return;
142
+ }
143
+ // Long format: id: title and minimal counts
144
+ for (const changeName of sorted) {
145
+ const proposalPath = path.join(changesPath, changeName, 'proposal.md');
146
+ const tasksPath = path.join(changesPath, changeName, 'tasks.md');
147
+ try {
148
+ const content = await fs.readFile(proposalPath, 'utf-8');
149
+ const title = this.extractTitle(content, changeName);
150
+ let taskStatusText = '';
151
+ try {
152
+ const tasksContent = await fs.readFile(tasksPath, 'utf-8');
153
+ const { total, completed } = this.countTasks(tasksContent);
154
+ taskStatusText = ` ${CHANGE_MESSAGES.tasks(completed, total)}`;
155
+ }
156
+ catch (error) {
157
+ if (process.env.DEBUG) {
158
+ console.error(UTILS_MESSAGES.failedToReadTasks(tasksPath, error));
159
+ }
160
+ }
161
+ const changeDir = path.join(changesPath, changeName);
162
+ const parser = new ChangeParser(await fs.readFile(proposalPath, 'utf-8'), changeDir);
163
+ const change = await parser.parseChangeWithDeltas(changeName);
164
+ const deltaCountText = CHANGE_MESSAGES.deltas(change.deltas.length);
165
+ console.log(`${changeName}: ${title}${deltaCountText}${taskStatusText}`);
166
+ }
167
+ catch {
168
+ console.log(`${changeName}: ${CHANGE_MESSAGES.unableToRead}`);
169
+ }
170
+ }
171
+ }
172
+ }
173
+ async validate(changeName, options) {
174
+ const changesPath = path.join(process.cwd(), 'openspec', 'changes');
175
+ if (!changeName) {
176
+ const canPrompt = isInteractive(options);
177
+ const changes = await getActiveChangeIds();
178
+ if (canPrompt && changes.length > 0) {
179
+ const { select } = await import('@inquirer/prompts');
180
+ const selected = await select({
181
+ message: CHANGE_MESSAGES.selectChangeToValidate,
182
+ choices: changes.map(id => ({ name: id, value: id })),
183
+ });
184
+ changeName = selected;
185
+ }
186
+ else {
187
+ if (changes.length === 0) {
188
+ console.error(CHANGE_MESSAGES.noChangeSpecifiedNoActive);
189
+ }
190
+ else {
191
+ console.error(CHANGE_MESSAGES.noChangeSpecifiedAvailable(changes.join(', ')));
192
+ }
193
+ console.error(CHANGE_MESSAGES.hintViewChanges);
194
+ process.exitCode = 1;
195
+ return;
196
+ }
197
+ }
198
+ const changeDir = path.join(changesPath, changeName);
199
+ try {
200
+ await fs.access(changeDir);
201
+ }
202
+ catch {
203
+ throw new Error(CHANGE_MESSAGES.changeNotFound(changeName, changeDir));
204
+ }
205
+ const validator = new Validator(options?.strict || false);
206
+ const report = await validator.validateChangeDeltaSpecs(changeDir);
207
+ if (options?.json) {
208
+ console.log(JSON.stringify(report, null, 2));
209
+ }
210
+ else {
211
+ if (report.valid) {
212
+ console.log(CHANGE_MESSAGES.changeIsValid(changeName));
213
+ }
214
+ else {
215
+ console.error(CHANGE_MESSAGES.changeHasIssues(changeName));
216
+ report.issues.forEach(issue => {
217
+ const label = issue.level === 'ERROR' ? 'ERROR' : 'WARNING';
218
+ const prefix = issue.level === 'ERROR' ? '✗' : '⚠';
219
+ console.error(`${prefix} [${label}] ${issue.path}: ${issue.message}`);
220
+ });
221
+ // Next steps footer to guide fixing issues
222
+ this.printNextSteps();
223
+ if (!options?.json) {
224
+ process.exitCode = 1;
225
+ }
226
+ }
227
+ }
228
+ }
229
+ async getActiveChanges(changesPath) {
230
+ try {
231
+ const entries = await fs.readdir(changesPath, { withFileTypes: true });
232
+ const result = [];
233
+ for (const entry of entries) {
234
+ if (!entry.isDirectory() || entry.name.startsWith('.') || entry.name === ARCHIVE_DIR)
235
+ continue;
236
+ const proposalPath = path.join(changesPath, entry.name, 'proposal.md');
237
+ try {
238
+ await fs.access(proposalPath);
239
+ result.push(entry.name);
240
+ }
241
+ catch {
242
+ // skip directories without proposal.md
243
+ }
244
+ }
245
+ return result.sort();
246
+ }
247
+ catch {
248
+ return [];
249
+ }
250
+ }
251
+ extractTitle(content, changeName) {
252
+ const match = content.match(/^#\s+(?:Change:\s+)?(.+)$/im);
253
+ return match ? match[1].trim() : changeName;
254
+ }
255
+ countTasks(content) {
256
+ const lines = content.split('\n');
257
+ let total = 0;
258
+ let completed = 0;
259
+ for (const line of lines) {
260
+ if (line.match(TASK_PATTERN)) {
261
+ total++;
262
+ if (line.match(COMPLETED_TASK_PATTERN)) {
263
+ completed++;
264
+ }
265
+ }
266
+ }
267
+ return { total, completed };
268
+ }
269
+ printNextSteps() {
270
+ const bullets = [];
271
+ bullets.push(CHANGE_MESSAGES.ensureDeltasInSpecs);
272
+ bullets.push(CHANGE_MESSAGES.eachRequirementNeedsScenario);
273
+ bullets.push(CHANGE_MESSAGES.debugParsedDeltas);
274
+ console.error(CHANGE_MESSAGES.nextSteps);
275
+ bullets.forEach(b => console.error(` ${b}`));
276
+ }
277
+ }
278
+ //# sourceMappingURL=change.js.map
@@ -0,0 +1,72 @@
1
+ interface GenerateOptions {
2
+ shell?: string;
3
+ }
4
+ interface InstallOptions {
5
+ shell?: string;
6
+ verbose?: boolean;
7
+ }
8
+ interface UninstallOptions {
9
+ shell?: string;
10
+ yes?: boolean;
11
+ }
12
+ interface CompleteOptions {
13
+ type: string;
14
+ }
15
+ /**
16
+ * Command for managing shell completions for BR-OpenSpec CLI
17
+ */
18
+ export declare class CompletionCommand {
19
+ private completionProvider;
20
+ constructor();
21
+ /**
22
+ * Resolve shell parameter or exit with error
23
+ *
24
+ * @param shell - The shell parameter (may be undefined)
25
+ * @param operationName - Name of the operation (for error messages)
26
+ * @returns Resolved shell or null if should exit
27
+ */
28
+ private resolveShellOrExit;
29
+ /**
30
+ * Generate completion script and output to stdout
31
+ *
32
+ * @param options - Options for generation (shell type)
33
+ */
34
+ generate(options?: GenerateOptions): Promise<void>;
35
+ /**
36
+ * Install completion script to the appropriate location
37
+ *
38
+ * @param options - Options for installation (shell type, verbose output)
39
+ */
40
+ install(options?: InstallOptions): Promise<void>;
41
+ /**
42
+ * Uninstall completion script from the installation location
43
+ *
44
+ * @param options - Options for uninstallation (shell type, yes flag)
45
+ */
46
+ uninstall(options?: UninstallOptions): Promise<void>;
47
+ /**
48
+ * Generate completion script for a specific shell
49
+ */
50
+ private generateForShell;
51
+ /**
52
+ * Install completion script for a specific shell
53
+ */
54
+ private installForShell;
55
+ /**
56
+ * Uninstall completion script for a specific shell
57
+ */
58
+ private uninstallForShell;
59
+ /**
60
+ * Output machine-readable completion data for shell consumption
61
+ * Format: tab-separated "id\tdescription" per line
62
+ *
63
+ * @param options - Options specifying completion type
64
+ */
65
+ complete(options: CompleteOptions): Promise<void>;
66
+ /**
67
+ * Normalize shell parameter to lowercase
68
+ */
69
+ private normalizeShell;
70
+ }
71
+ export {};
72
+ //# sourceMappingURL=completion.d.ts.map
@@ -0,0 +1,258 @@
1
+ import ora from 'ora';
2
+ import { CompletionFactory } from '../core/completions/factory.js';
3
+ import { COMMAND_REGISTRY } from '../core/completions/command-registry.js';
4
+ import { detectShell } from '../utils/shell-detection.js';
5
+ import { CompletionProvider } from '../core/completions/completion-provider.js';
6
+ import { getArchivedChangeIds } from '../utils/item-discovery.js';
7
+ import { COMPLETION_MESSAGES } from '../messages/index.js';
8
+ /**
9
+ * Command for managing shell completions for BR-OpenSpec CLI
10
+ */
11
+ export class CompletionCommand {
12
+ completionProvider;
13
+ constructor() {
14
+ this.completionProvider = new CompletionProvider();
15
+ }
16
+ /**
17
+ * Resolve shell parameter or exit with error
18
+ *
19
+ * @param shell - The shell parameter (may be undefined)
20
+ * @param operationName - Name of the operation (for error messages)
21
+ * @returns Resolved shell or null if should exit
22
+ */
23
+ resolveShellOrExit(shell, operationName) {
24
+ const normalizedShell = this.normalizeShell(shell);
25
+ if (!normalizedShell) {
26
+ const detectionResult = detectShell();
27
+ if (detectionResult.shell && CompletionFactory.isSupported(detectionResult.shell)) {
28
+ return detectionResult.shell;
29
+ }
30
+ // Shell was detected but not supported
31
+ if (detectionResult.detected && !detectionResult.shell) {
32
+ console.error(COMPLETION_MESSAGES.shellNotSupported(detectionResult.detected, CompletionFactory.getSupportedShells().join(', ')));
33
+ process.exitCode = 1;
34
+ return null;
35
+ }
36
+ // No shell specified and cannot auto-detect
37
+ console.error(COMPLETION_MESSAGES.couldNotDetectShell);
38
+ console.error(COMPLETION_MESSAGES.usageCompletion(operationName));
39
+ console.error(COMPLETION_MESSAGES.currentlySupported(CompletionFactory.getSupportedShells().join(', ')));
40
+ process.exitCode = 1;
41
+ return null;
42
+ }
43
+ if (!CompletionFactory.isSupported(normalizedShell)) {
44
+ console.error(COMPLETION_MESSAGES.shellNotSupported(normalizedShell, CompletionFactory.getSupportedShells().join(', ')));
45
+ process.exitCode = 1;
46
+ return null;
47
+ }
48
+ return normalizedShell;
49
+ }
50
+ /**
51
+ * Generate completion script and output to stdout
52
+ *
53
+ * @param options - Options for generation (shell type)
54
+ */
55
+ async generate(options = {}) {
56
+ const shell = this.resolveShellOrExit(options.shell, 'generate');
57
+ if (!shell)
58
+ return;
59
+ await this.generateForShell(shell);
60
+ }
61
+ /**
62
+ * Install completion script to the appropriate location
63
+ *
64
+ * @param options - Options for installation (shell type, verbose output)
65
+ */
66
+ async install(options = {}) {
67
+ const shell = this.resolveShellOrExit(options.shell, 'install');
68
+ if (!shell)
69
+ return;
70
+ await this.installForShell(shell, options.verbose || false);
71
+ }
72
+ /**
73
+ * Uninstall completion script from the installation location
74
+ *
75
+ * @param options - Options for uninstallation (shell type, yes flag)
76
+ */
77
+ async uninstall(options = {}) {
78
+ const shell = this.resolveShellOrExit(options.shell, 'uninstall');
79
+ if (!shell)
80
+ return;
81
+ await this.uninstallForShell(shell, options.yes || false);
82
+ }
83
+ /**
84
+ * Generate completion script for a specific shell
85
+ */
86
+ async generateForShell(shell) {
87
+ const generator = CompletionFactory.createGenerator(shell);
88
+ const script = generator.generate(COMMAND_REGISTRY);
89
+ console.log(script);
90
+ }
91
+ /**
92
+ * Install completion script for a specific shell
93
+ */
94
+ async installForShell(shell, verbose) {
95
+ const generator = CompletionFactory.createGenerator(shell);
96
+ const installer = CompletionFactory.createInstaller(shell);
97
+ const spinner = ora(COMPLETION_MESSAGES.installingCompletion(shell)).start();
98
+ try {
99
+ // Generate the completion script
100
+ const script = generator.generate(COMMAND_REGISTRY);
101
+ // Install it
102
+ const result = await installer.install(script);
103
+ spinner.stop();
104
+ if (result.success) {
105
+ console.log(COMPLETION_MESSAGES.installSuccess(result.message));
106
+ if (verbose && result.installedPath) {
107
+ console.log(COMPLETION_MESSAGES.installedTo(result.installedPath));
108
+ if (result.backupPath) {
109
+ console.log(COMPLETION_MESSAGES.backupCreated(result.backupPath));
110
+ }
111
+ // Check if any shell config was updated
112
+ const configWasUpdated = result.zshrcConfigured || result.bashrcConfigured || result.profileConfigured;
113
+ if (configWasUpdated) {
114
+ const configPaths = {
115
+ zsh: '~/.zshrc',
116
+ bash: '~/.bashrc',
117
+ fish: '~/.config/fish/config.fish',
118
+ powershell: '$PROFILE',
119
+ };
120
+ const configPath = configPaths[shell] || 'config file';
121
+ console.log(COMPLETION_MESSAGES.configFileConfigured(configPath));
122
+ }
123
+ }
124
+ // Display warnings if present
125
+ if (result.warnings && result.warnings.length > 0) {
126
+ console.log('');
127
+ for (const warning of result.warnings) {
128
+ console.log(warning);
129
+ }
130
+ }
131
+ // Print instructions (only shown if .zshrc wasn't auto-configured)
132
+ if (result.instructions && result.instructions.length > 0) {
133
+ console.log('');
134
+ for (const instruction of result.instructions) {
135
+ console.log(instruction);
136
+ }
137
+ }
138
+ else {
139
+ // Check if any shell config was updated (InstallationResult has: zshrcConfigured, bashrcConfigured, profileConfigured)
140
+ const configWasUpdated = result.zshrcConfigured || result.bashrcConfigured || result.profileConfigured;
141
+ if (configWasUpdated) {
142
+ console.log('');
143
+ // Shell-specific reload instructions
144
+ const reloadCommands = {
145
+ zsh: 'exec zsh',
146
+ bash: 'exec bash',
147
+ fish: 'exec fish',
148
+ powershell: '. $PROFILE',
149
+ };
150
+ const reloadCmd = reloadCommands[shell] || `restart your ${shell} shell`;
151
+ console.log(COMPLETION_MESSAGES.restartShell(reloadCmd));
152
+ }
153
+ }
154
+ }
155
+ else {
156
+ console.error(COMPLETION_MESSAGES.installFailed(result.message));
157
+ process.exitCode = 1;
158
+ }
159
+ }
160
+ catch (error) {
161
+ spinner.stop();
162
+ console.error(COMPLETION_MESSAGES.failedToInstall(error instanceof Error ? error.message : String(error)));
163
+ process.exitCode = 1;
164
+ }
165
+ }
166
+ /**
167
+ * Uninstall completion script for a specific shell
168
+ */
169
+ async uninstallForShell(shell, skipConfirmation) {
170
+ const installer = CompletionFactory.createInstaller(shell);
171
+ // Prompt for confirmation unless --yes flag is provided
172
+ if (!skipConfirmation) {
173
+ const { confirm } = await import('@inquirer/prompts');
174
+ // Get shell-specific config file path
175
+ const configPaths = {
176
+ zsh: '~/.zshrc',
177
+ bash: '~/.bashrc',
178
+ fish: 'Fish configuration', // Fish doesn't modify profile, just removes script file
179
+ powershell: '$PROFILE',
180
+ };
181
+ const configPath = configPaths[shell] || `${shell} configuration`;
182
+ const confirmed = await confirm({
183
+ message: COMPLETION_MESSAGES.removeConfigConfirm(configPath),
184
+ default: false,
185
+ });
186
+ if (!confirmed) {
187
+ console.log(COMPLETION_MESSAGES.uninstallCancelled);
188
+ return;
189
+ }
190
+ }
191
+ const spinner = ora(COMPLETION_MESSAGES.uninstallingCompletion(shell)).start();
192
+ try {
193
+ const result = await installer.uninstall();
194
+ spinner.stop();
195
+ if (result.success) {
196
+ console.log(COMPLETION_MESSAGES.uninstallSuccess(result.message));
197
+ }
198
+ else {
199
+ console.error(COMPLETION_MESSAGES.uninstallFailed(result.message));
200
+ process.exitCode = 1;
201
+ }
202
+ }
203
+ catch (error) {
204
+ spinner.stop();
205
+ console.error(COMPLETION_MESSAGES.failedToUninstall(error instanceof Error ? error.message : String(error)));
206
+ process.exitCode = 1;
207
+ }
208
+ }
209
+ /**
210
+ * Output machine-readable completion data for shell consumption
211
+ * Format: tab-separated "id\tdescription" per line
212
+ *
213
+ * @param options - Options specifying completion type
214
+ */
215
+ async complete(options) {
216
+ const type = options.type.toLowerCase();
217
+ try {
218
+ switch (type) {
219
+ case 'changes': {
220
+ const changeIds = await this.completionProvider.getChangeIds();
221
+ for (const id of changeIds) {
222
+ console.log(`${id}\t${COMPLETION_MESSAGES.activeChange}`);
223
+ }
224
+ break;
225
+ }
226
+ case 'specs': {
227
+ const specIds = await this.completionProvider.getSpecIds();
228
+ for (const id of specIds) {
229
+ console.log(`${id}\t${COMPLETION_MESSAGES.specification}`);
230
+ }
231
+ break;
232
+ }
233
+ case 'archived-changes': {
234
+ const archivedIds = await getArchivedChangeIds();
235
+ for (const id of archivedIds) {
236
+ console.log(`${id}\t${COMPLETION_MESSAGES.archivedChange}`);
237
+ }
238
+ break;
239
+ }
240
+ default:
241
+ // Invalid type - silently exit with no output for graceful shell completion failure
242
+ process.exitCode = 1;
243
+ break;
244
+ }
245
+ }
246
+ catch {
247
+ // Silently fail for graceful shell completion experience
248
+ process.exitCode = 1;
249
+ }
250
+ }
251
+ /**
252
+ * Normalize shell parameter to lowercase
253
+ */
254
+ normalizeShell(shell) {
255
+ return shell?.toLowerCase();
256
+ }
257
+ }
258
+ //# sourceMappingURL=completion.js.map
@@ -0,0 +1,36 @@
1
+ import { Command } from 'commander';
2
+ import { GlobalConfig } from '../core/global-config.js';
3
+ import type { Profile, Delivery } from '../core/global-config.js';
4
+ interface ProfileState {
5
+ profile: Profile;
6
+ delivery: Delivery;
7
+ workflows: string[];
8
+ }
9
+ interface ProfileStateDiff {
10
+ hasChanges: boolean;
11
+ lines: string[];
12
+ }
13
+ /**
14
+ * Resolve the effective current profile state from global config defaults.
15
+ */
16
+ export declare function resolveCurrentProfileState(config: GlobalConfig): ProfileState;
17
+ /**
18
+ * Derive profile type from selected workflows.
19
+ */
20
+ export declare function deriveProfileFromWorkflowSelection(selectedWorkflows: string[]): Profile;
21
+ /**
22
+ * Format a compact workflow summary for the profile header.
23
+ */
24
+ export declare function formatWorkflowSummary(workflows: readonly string[], profile: Profile): string;
25
+ /**
26
+ * Build a user-facing diff summary between two profile states.
27
+ */
28
+ export declare function diffProfileState(before: ProfileState, after: ProfileState): ProfileStateDiff;
29
+ /**
30
+ * Register the config command and all its subcommands.
31
+ *
32
+ * @param program - The Commander program instance
33
+ */
34
+ export declare function registerConfigCommand(program: Command): void;
35
+ export {};
36
+ //# sourceMappingURL=config.d.ts.map