lightspec 0.1.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 (203) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +435 -0
  3. package/bin/lightspec.js +3 -0
  4. package/dist/cli/index.d.ts +2 -0
  5. package/dist/cli/index.js +361 -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/show.d.ts +14 -0
  15. package/dist/commands/show.js +132 -0
  16. package/dist/commands/spec.d.ts +15 -0
  17. package/dist/commands/spec.js +225 -0
  18. package/dist/commands/validate.d.ts +24 -0
  19. package/dist/commands/validate.js +294 -0
  20. package/dist/core/archive.d.ts +11 -0
  21. package/dist/core/archive.js +280 -0
  22. package/dist/core/completions/command-registry.d.ts +7 -0
  23. package/dist/core/completions/command-registry.js +456 -0
  24. package/dist/core/completions/completion-provider.d.ts +60 -0
  25. package/dist/core/completions/completion-provider.js +102 -0
  26. package/dist/core/completions/factory.d.ts +64 -0
  27. package/dist/core/completions/factory.js +75 -0
  28. package/dist/core/completions/generators/bash-generator.d.ts +32 -0
  29. package/dist/core/completions/generators/bash-generator.js +174 -0
  30. package/dist/core/completions/generators/fish-generator.d.ts +32 -0
  31. package/dist/core/completions/generators/fish-generator.js +157 -0
  32. package/dist/core/completions/generators/powershell-generator.d.ts +33 -0
  33. package/dist/core/completions/generators/powershell-generator.js +207 -0
  34. package/dist/core/completions/generators/zsh-generator.d.ts +44 -0
  35. package/dist/core/completions/generators/zsh-generator.js +250 -0
  36. package/dist/core/completions/installers/bash-installer.d.ts +87 -0
  37. package/dist/core/completions/installers/bash-installer.js +318 -0
  38. package/dist/core/completions/installers/fish-installer.d.ts +43 -0
  39. package/dist/core/completions/installers/fish-installer.js +143 -0
  40. package/dist/core/completions/installers/powershell-installer.d.ts +88 -0
  41. package/dist/core/completions/installers/powershell-installer.js +327 -0
  42. package/dist/core/completions/installers/zsh-installer.d.ts +125 -0
  43. package/dist/core/completions/installers/zsh-installer.js +449 -0
  44. package/dist/core/completions/templates/bash-templates.d.ts +6 -0
  45. package/dist/core/completions/templates/bash-templates.js +24 -0
  46. package/dist/core/completions/templates/fish-templates.d.ts +7 -0
  47. package/dist/core/completions/templates/fish-templates.js +39 -0
  48. package/dist/core/completions/templates/powershell-templates.d.ts +6 -0
  49. package/dist/core/completions/templates/powershell-templates.js +25 -0
  50. package/dist/core/completions/templates/zsh-templates.d.ts +6 -0
  51. package/dist/core/completions/templates/zsh-templates.js +36 -0
  52. package/dist/core/completions/types.d.ts +79 -0
  53. package/dist/core/completions/types.js +2 -0
  54. package/dist/core/config-prompts.d.ts +9 -0
  55. package/dist/core/config-prompts.js +34 -0
  56. package/dist/core/config-schema.d.ts +76 -0
  57. package/dist/core/config-schema.js +200 -0
  58. package/dist/core/config.d.ts +16 -0
  59. package/dist/core/config.js +30 -0
  60. package/dist/core/configurators/agents.d.ts +8 -0
  61. package/dist/core/configurators/agents.js +15 -0
  62. package/dist/core/configurators/base.d.ts +7 -0
  63. package/dist/core/configurators/base.js +2 -0
  64. package/dist/core/configurators/claude.d.ts +8 -0
  65. package/dist/core/configurators/claude.js +15 -0
  66. package/dist/core/configurators/cline.d.ts +8 -0
  67. package/dist/core/configurators/cline.js +15 -0
  68. package/dist/core/configurators/codebuddy.d.ts +8 -0
  69. package/dist/core/configurators/codebuddy.js +15 -0
  70. package/dist/core/configurators/costrict.d.ts +8 -0
  71. package/dist/core/configurators/costrict.js +15 -0
  72. package/dist/core/configurators/iflow.d.ts +8 -0
  73. package/dist/core/configurators/iflow.js +15 -0
  74. package/dist/core/configurators/qoder.d.ts +30 -0
  75. package/dist/core/configurators/qoder.js +42 -0
  76. package/dist/core/configurators/qwen.d.ts +24 -0
  77. package/dist/core/configurators/qwen.js +37 -0
  78. package/dist/core/configurators/registry.d.ts +9 -0
  79. package/dist/core/configurators/registry.js +43 -0
  80. package/dist/core/configurators/slash/amazon-q.d.ts +9 -0
  81. package/dist/core/configurators/slash/amazon-q.js +46 -0
  82. package/dist/core/configurators/slash/antigravity.d.ts +9 -0
  83. package/dist/core/configurators/slash/antigravity.js +23 -0
  84. package/dist/core/configurators/slash/auggie.d.ts +9 -0
  85. package/dist/core/configurators/slash/auggie.js +31 -0
  86. package/dist/core/configurators/slash/base.d.ts +19 -0
  87. package/dist/core/configurators/slash/base.js +69 -0
  88. package/dist/core/configurators/slash/claude.d.ts +9 -0
  89. package/dist/core/configurators/slash/claude.js +37 -0
  90. package/dist/core/configurators/slash/cline.d.ts +9 -0
  91. package/dist/core/configurators/slash/cline.js +23 -0
  92. package/dist/core/configurators/slash/codebuddy.d.ts +9 -0
  93. package/dist/core/configurators/slash/codebuddy.js +34 -0
  94. package/dist/core/configurators/slash/codex.d.ts +14 -0
  95. package/dist/core/configurators/slash/codex.js +109 -0
  96. package/dist/core/configurators/slash/continue.d.ts +9 -0
  97. package/dist/core/configurators/slash/continue.js +46 -0
  98. package/dist/core/configurators/slash/costrict.d.ts +9 -0
  99. package/dist/core/configurators/slash/costrict.js +31 -0
  100. package/dist/core/configurators/slash/crush.d.ts +9 -0
  101. package/dist/core/configurators/slash/crush.js +37 -0
  102. package/dist/core/configurators/slash/cursor.d.ts +9 -0
  103. package/dist/core/configurators/slash/cursor.js +37 -0
  104. package/dist/core/configurators/slash/factory.d.ts +10 -0
  105. package/dist/core/configurators/slash/factory.js +35 -0
  106. package/dist/core/configurators/slash/gemini.d.ts +9 -0
  107. package/dist/core/configurators/slash/gemini.js +22 -0
  108. package/dist/core/configurators/slash/github-copilot.d.ts +9 -0
  109. package/dist/core/configurators/slash/github-copilot.js +34 -0
  110. package/dist/core/configurators/slash/iflow.d.ts +9 -0
  111. package/dist/core/configurators/slash/iflow.js +37 -0
  112. package/dist/core/configurators/slash/kilocode.d.ts +9 -0
  113. package/dist/core/configurators/slash/kilocode.js +17 -0
  114. package/dist/core/configurators/slash/opencode.d.ts +12 -0
  115. package/dist/core/configurators/slash/opencode.js +72 -0
  116. package/dist/core/configurators/slash/qoder.d.ts +35 -0
  117. package/dist/core/configurators/slash/qoder.js +76 -0
  118. package/dist/core/configurators/slash/qwen.d.ts +32 -0
  119. package/dist/core/configurators/slash/qwen.js +49 -0
  120. package/dist/core/configurators/slash/registry.d.ts +8 -0
  121. package/dist/core/configurators/slash/registry.js +78 -0
  122. package/dist/core/configurators/slash/roocode.d.ts +9 -0
  123. package/dist/core/configurators/slash/roocode.js +23 -0
  124. package/dist/core/configurators/slash/toml-base.d.ts +10 -0
  125. package/dist/core/configurators/slash/toml-base.js +53 -0
  126. package/dist/core/configurators/slash/windsurf.d.ts +9 -0
  127. package/dist/core/configurators/slash/windsurf.js +23 -0
  128. package/dist/core/converters/json-converter.d.ts +6 -0
  129. package/dist/core/converters/json-converter.js +51 -0
  130. package/dist/core/global-config.d.ts +39 -0
  131. package/dist/core/global-config.js +115 -0
  132. package/dist/core/index.d.ts +2 -0
  133. package/dist/core/index.js +3 -0
  134. package/dist/core/init.d.ts +52 -0
  135. package/dist/core/init.js +644 -0
  136. package/dist/core/list.d.ts +9 -0
  137. package/dist/core/list.js +171 -0
  138. package/dist/core/parsers/change-parser.d.ts +13 -0
  139. package/dist/core/parsers/change-parser.js +193 -0
  140. package/dist/core/parsers/markdown-parser.d.ts +22 -0
  141. package/dist/core/parsers/markdown-parser.js +187 -0
  142. package/dist/core/parsers/requirement-blocks.d.ts +37 -0
  143. package/dist/core/parsers/requirement-blocks.js +201 -0
  144. package/dist/core/project-config.d.ts +64 -0
  145. package/dist/core/project-config.js +223 -0
  146. package/dist/core/schemas/base.schema.d.ts +13 -0
  147. package/dist/core/schemas/base.schema.js +13 -0
  148. package/dist/core/schemas/change.schema.d.ts +73 -0
  149. package/dist/core/schemas/change.schema.js +31 -0
  150. package/dist/core/schemas/index.d.ts +4 -0
  151. package/dist/core/schemas/index.js +4 -0
  152. package/dist/core/schemas/spec.schema.d.ts +18 -0
  153. package/dist/core/schemas/spec.schema.js +15 -0
  154. package/dist/core/specs-apply.d.ts +73 -0
  155. package/dist/core/specs-apply.js +384 -0
  156. package/dist/core/styles/palette.d.ts +7 -0
  157. package/dist/core/styles/palette.js +8 -0
  158. package/dist/core/templates/agents-root-stub.d.ts +2 -0
  159. package/dist/core/templates/agents-root-stub.js +17 -0
  160. package/dist/core/templates/agents-template.d.ts +2 -0
  161. package/dist/core/templates/agents-template.js +458 -0
  162. package/dist/core/templates/claude-template.d.ts +2 -0
  163. package/dist/core/templates/claude-template.js +2 -0
  164. package/dist/core/templates/cline-template.d.ts +2 -0
  165. package/dist/core/templates/cline-template.js +2 -0
  166. package/dist/core/templates/costrict-template.d.ts +2 -0
  167. package/dist/core/templates/costrict-template.js +2 -0
  168. package/dist/core/templates/index.d.ts +17 -0
  169. package/dist/core/templates/index.js +37 -0
  170. package/dist/core/templates/project-template.d.ts +8 -0
  171. package/dist/core/templates/project-template.js +32 -0
  172. package/dist/core/templates/slash-command-templates.d.ts +4 -0
  173. package/dist/core/templates/slash-command-templates.js +49 -0
  174. package/dist/core/update.d.ts +4 -0
  175. package/dist/core/update.js +88 -0
  176. package/dist/core/validation/constants.d.ts +34 -0
  177. package/dist/core/validation/constants.js +40 -0
  178. package/dist/core/validation/types.d.ts +18 -0
  179. package/dist/core/validation/types.js +2 -0
  180. package/dist/core/validation/validator.d.ts +33 -0
  181. package/dist/core/validation/validator.js +409 -0
  182. package/dist/core/view.d.ts +8 -0
  183. package/dist/core/view.js +168 -0
  184. package/dist/index.d.ts +3 -0
  185. package/dist/index.js +3 -0
  186. package/dist/telemetry/config.d.ts +32 -0
  187. package/dist/telemetry/config.js +68 -0
  188. package/dist/telemetry/index.d.ts +31 -0
  189. package/dist/telemetry/index.js +103 -0
  190. package/dist/utils/file-system.d.ts +25 -0
  191. package/dist/utils/file-system.js +218 -0
  192. package/dist/utils/interactive.d.ts +18 -0
  193. package/dist/utils/interactive.js +21 -0
  194. package/dist/utils/item-discovery.d.ts +4 -0
  195. package/dist/utils/item-discovery.js +72 -0
  196. package/dist/utils/match.d.ts +3 -0
  197. package/dist/utils/match.js +22 -0
  198. package/dist/utils/shell-detection.d.ts +20 -0
  199. package/dist/utils/shell-detection.js +41 -0
  200. package/dist/utils/task-progress.d.ts +8 -0
  201. package/dist/utils/task-progress.js +36 -0
  202. package/package.json +82 -0
  203. package/scripts/postinstall.js +147 -0
@@ -0,0 +1,361 @@
1
+ import { Command } from 'commander';
2
+ import { createRequire } from 'module';
3
+ import ora from 'ora';
4
+ import path from 'path';
5
+ import { promises as fs } from 'fs';
6
+ import { AI_TOOLS } from '../core/config.js';
7
+ import { UpdateCommand } from '../core/update.js';
8
+ import { ListCommand } from '../core/list.js';
9
+ import { ArchiveCommand } from '../core/archive.js';
10
+ import { ViewCommand } from '../core/view.js';
11
+ import { registerSpecCommand } from '../commands/spec.js';
12
+ import { ChangeCommand } from '../commands/change.js';
13
+ import { ValidateCommand } from '../commands/validate.js';
14
+ import { ShowCommand } from '../commands/show.js';
15
+ import { CompletionCommand } from '../commands/completion.js';
16
+ import { FeedbackCommand } from '../commands/feedback.js';
17
+ import { registerConfigCommand } from '../commands/config.js';
18
+ import { maybeShowTelemetryNotice, trackCommand, shutdown } from '../telemetry/index.js';
19
+ const program = new Command();
20
+ const require = createRequire(import.meta.url);
21
+ const { version } = require('../../package.json');
22
+ /**
23
+ * Get the full command path for nested commands.
24
+ * For example: 'change show' -> 'change:show'
25
+ */
26
+ function getCommandPath(command) {
27
+ const names = [];
28
+ let current = command;
29
+ while (current) {
30
+ const name = current.name();
31
+ // Skip the root 'lightspec' command
32
+ if (name && name !== 'lightspec') {
33
+ names.unshift(name);
34
+ }
35
+ current = current.parent;
36
+ }
37
+ return names.join(':') || 'lightspec';
38
+ }
39
+ program
40
+ .name('lightspec')
41
+ .description('AI-native system for spec-driven development')
42
+ .version(version);
43
+ // Global options
44
+ program.option('--no-color', 'Disable color output');
45
+ // Apply global flags and telemetry before any command runs
46
+ // Note: preAction receives (thisCommand, actionCommand) where:
47
+ // - thisCommand: the command where hook was added (root program)
48
+ // - actionCommand: the command actually being executed (subcommand)
49
+ program.hook('preAction', async (thisCommand, actionCommand) => {
50
+ const opts = thisCommand.opts();
51
+ if (opts.color === false) {
52
+ process.env.NO_COLOR = '1';
53
+ }
54
+ // Show first-run telemetry notice (if not seen)
55
+ await maybeShowTelemetryNotice();
56
+ // Track command execution (use actionCommand to get the actual subcommand)
57
+ const commandPath = getCommandPath(actionCommand);
58
+ await trackCommand(commandPath, version);
59
+ });
60
+ // Shutdown telemetry after command completes
61
+ program.hook('postAction', async () => {
62
+ await shutdown();
63
+ });
64
+ const availableToolIds = AI_TOOLS.filter((tool) => tool.available).map((tool) => tool.value);
65
+ const toolsOptionDescription = `Configure AI tools non-interactively. Use "all", "none", or a comma-separated list of: ${availableToolIds.join(', ')}`;
66
+ program
67
+ .command('init [path]')
68
+ .description('Initialize LightSpec in your project')
69
+ .option('--tools <tools>', toolsOptionDescription)
70
+ .action(async (targetPath = '.', options) => {
71
+ try {
72
+ // Validate that the path is a valid directory
73
+ const resolvedPath = path.resolve(targetPath);
74
+ try {
75
+ const stats = await fs.stat(resolvedPath);
76
+ if (!stats.isDirectory()) {
77
+ throw new Error(`Path "${targetPath}" is not a directory`);
78
+ }
79
+ }
80
+ catch (error) {
81
+ if (error.code === 'ENOENT') {
82
+ // Directory doesn't exist, but we can create it
83
+ console.log(`Directory "${targetPath}" doesn't exist, it will be created.`);
84
+ }
85
+ else if (error.message && error.message.includes('not a directory')) {
86
+ throw error;
87
+ }
88
+ else {
89
+ throw new Error(`Cannot access path "${targetPath}": ${error.message}`);
90
+ }
91
+ }
92
+ const { InitCommand } = await import('../core/init.js');
93
+ const initCommand = new InitCommand({
94
+ tools: options?.tools,
95
+ });
96
+ await initCommand.execute(targetPath);
97
+ }
98
+ catch (error) {
99
+ console.log(); // Empty line for spacing
100
+ ora().fail(`Error: ${error.message}`);
101
+ process.exit(1);
102
+ }
103
+ });
104
+ program
105
+ .command('update [path]')
106
+ .description('Update LightSpec instruction files')
107
+ .action(async (targetPath = '.') => {
108
+ try {
109
+ const resolvedPath = path.resolve(targetPath);
110
+ const updateCommand = new UpdateCommand();
111
+ await updateCommand.execute(resolvedPath);
112
+ }
113
+ catch (error) {
114
+ console.log(); // Empty line for spacing
115
+ ora().fail(`Error: ${error.message}`);
116
+ process.exit(1);
117
+ }
118
+ });
119
+ program
120
+ .command('list')
121
+ .description('List items (changes by default). Use --specs to list specs.')
122
+ .option('--specs', 'List specs instead of changes')
123
+ .option('--changes', 'List changes explicitly (default)')
124
+ .option('--sort <order>', 'Sort order: "recent" (default) or "name"', 'recent')
125
+ .option('--json', 'Output as JSON (for programmatic use)')
126
+ .action(async (options) => {
127
+ try {
128
+ const listCommand = new ListCommand();
129
+ const mode = options?.specs ? 'specs' : 'changes';
130
+ const sort = options?.sort === 'name' ? 'name' : 'recent';
131
+ await listCommand.execute('.', mode, { sort, json: options?.json });
132
+ }
133
+ catch (error) {
134
+ console.log(); // Empty line for spacing
135
+ ora().fail(`Error: ${error.message}`);
136
+ process.exit(1);
137
+ }
138
+ });
139
+ program
140
+ .command('view')
141
+ .description('Display an interactive dashboard of specs and changes')
142
+ .action(async () => {
143
+ try {
144
+ const viewCommand = new ViewCommand();
145
+ await viewCommand.execute('.');
146
+ }
147
+ catch (error) {
148
+ console.log(); // Empty line for spacing
149
+ ora().fail(`Error: ${error.message}`);
150
+ process.exit(1);
151
+ }
152
+ });
153
+ // Change command with subcommands
154
+ const changeCmd = program
155
+ .command('change')
156
+ .description('Manage LightSpec change proposals');
157
+ // Deprecation notice for noun-based commands
158
+ changeCmd.hook('preAction', () => {
159
+ console.error('Warning: The "lightspec change ..." commands are deprecated. Prefer verb-first commands (e.g., "lightspec list", "lightspec validate --changes").');
160
+ });
161
+ changeCmd
162
+ .command('show [change-name]')
163
+ .description('Show a change proposal in JSON or markdown format')
164
+ .option('--json', 'Output as JSON')
165
+ .option('--deltas-only', 'Show only deltas (JSON only)')
166
+ .option('--requirements-only', 'Alias for --deltas-only (deprecated)')
167
+ .option('--no-interactive', 'Disable interactive prompts')
168
+ .action(async (changeName, options) => {
169
+ try {
170
+ const changeCommand = new ChangeCommand();
171
+ await changeCommand.show(changeName, options);
172
+ }
173
+ catch (error) {
174
+ console.error(`Error: ${error.message}`);
175
+ process.exitCode = 1;
176
+ }
177
+ });
178
+ changeCmd
179
+ .command('list')
180
+ .description('List all active changes (DEPRECATED: use "lightspec list" instead)')
181
+ .option('--json', 'Output as JSON')
182
+ .option('--long', 'Show id and title with counts')
183
+ .action(async (options) => {
184
+ try {
185
+ console.error('Warning: "lightspec change list" is deprecated. Use "lightspec list".');
186
+ const changeCommand = new ChangeCommand();
187
+ await changeCommand.list(options);
188
+ }
189
+ catch (error) {
190
+ console.error(`Error: ${error.message}`);
191
+ process.exitCode = 1;
192
+ }
193
+ });
194
+ changeCmd
195
+ .command('validate [change-name]')
196
+ .description('Validate a change proposal')
197
+ .option('--strict', 'Enable strict validation mode')
198
+ .option('--json', 'Output validation report as JSON')
199
+ .option('--no-interactive', 'Disable interactive prompts')
200
+ .action(async (changeName, options) => {
201
+ try {
202
+ const changeCommand = new ChangeCommand();
203
+ await changeCommand.validate(changeName, options);
204
+ if (typeof process.exitCode === 'number' && process.exitCode !== 0) {
205
+ process.exit(process.exitCode);
206
+ }
207
+ }
208
+ catch (error) {
209
+ console.error(`Error: ${error.message}`);
210
+ process.exitCode = 1;
211
+ }
212
+ });
213
+ program
214
+ .command('archive [change-name]')
215
+ .description('Archive a completed change and update main specs')
216
+ .option('-y, --yes', 'Skip confirmation prompts')
217
+ .option('--skip-specs', 'Skip spec update operations (useful for infrastructure, tooling, or doc-only changes)')
218
+ .option('--no-validate', 'Skip validation (not recommended, requires confirmation)')
219
+ .action(async (changeName, options) => {
220
+ try {
221
+ const archiveCommand = new ArchiveCommand();
222
+ await archiveCommand.execute(changeName, options);
223
+ }
224
+ catch (error) {
225
+ console.log(); // Empty line for spacing
226
+ ora().fail(`Error: ${error.message}`);
227
+ process.exit(1);
228
+ }
229
+ });
230
+ registerSpecCommand(program);
231
+ registerConfigCommand(program);
232
+ // Top-level validate command
233
+ program
234
+ .command('validate [item-name]')
235
+ .description('Validate changes and specs')
236
+ .option('--all', 'Validate all changes and specs')
237
+ .option('--changes', 'Validate all changes')
238
+ .option('--specs', 'Validate all specs')
239
+ .option('--type <type>', 'Specify item type when ambiguous: change|spec')
240
+ .option('--strict', 'Enable strict validation mode')
241
+ .option('--json', 'Output validation results as JSON')
242
+ .option('--concurrency <n>', 'Max concurrent validations (defaults to env LIGHTSPEC_CONCURRENCY or 6)')
243
+ .option('--no-interactive', 'Disable interactive prompts')
244
+ .action(async (itemName, options) => {
245
+ try {
246
+ const validateCommand = new ValidateCommand();
247
+ await validateCommand.execute(itemName, options);
248
+ }
249
+ catch (error) {
250
+ console.log();
251
+ ora().fail(`Error: ${error.message}`);
252
+ process.exit(1);
253
+ }
254
+ });
255
+ // Top-level show command
256
+ program
257
+ .command('show [item-name]')
258
+ .description('Show a change or spec')
259
+ .option('--json', 'Output as JSON')
260
+ .option('--type <type>', 'Specify item type when ambiguous: change|spec')
261
+ .option('--no-interactive', 'Disable interactive prompts')
262
+ // change-only flags
263
+ .option('--deltas-only', 'Show only deltas (JSON only, change)')
264
+ .option('--requirements-only', 'Alias for --deltas-only (deprecated, change)')
265
+ // spec-only flags
266
+ .option('--requirements', 'JSON only: Show only requirements (exclude scenarios)')
267
+ .option('--no-scenarios', 'JSON only: Exclude scenario content')
268
+ .option('-r, --requirement <id>', 'JSON only: Show specific requirement by ID (1-based)')
269
+ // allow unknown options to pass-through to underlying command implementation
270
+ .allowUnknownOption(true)
271
+ .action(async (itemName, options) => {
272
+ try {
273
+ const showCommand = new ShowCommand();
274
+ await showCommand.execute(itemName, options ?? {});
275
+ }
276
+ catch (error) {
277
+ console.log();
278
+ ora().fail(`Error: ${error.message}`);
279
+ process.exit(1);
280
+ }
281
+ });
282
+ // Feedback command
283
+ program
284
+ .command('feedback <message>')
285
+ .description('Submit feedback about LightSpec')
286
+ .option('--body <text>', 'Detailed description for the feedback')
287
+ .action(async (message, options) => {
288
+ try {
289
+ const feedbackCommand = new FeedbackCommand();
290
+ await feedbackCommand.execute(message, options);
291
+ }
292
+ catch (error) {
293
+ console.log();
294
+ ora().fail(`Error: ${error.message}`);
295
+ process.exit(1);
296
+ }
297
+ });
298
+ // Completion command with subcommands
299
+ const completionCmd = program
300
+ .command('completion')
301
+ .description('Manage shell completions for LightSpec CLI');
302
+ completionCmd
303
+ .command('generate [shell]')
304
+ .description('Generate completion script for a shell (outputs to stdout)')
305
+ .action(async (shell) => {
306
+ try {
307
+ const completionCommand = new CompletionCommand();
308
+ await completionCommand.generate({ shell });
309
+ }
310
+ catch (error) {
311
+ console.log();
312
+ ora().fail(`Error: ${error.message}`);
313
+ process.exit(1);
314
+ }
315
+ });
316
+ completionCmd
317
+ .command('install [shell]')
318
+ .description('Install completion script for a shell')
319
+ .option('--verbose', 'Show detailed installation output')
320
+ .action(async (shell, options) => {
321
+ try {
322
+ const completionCommand = new CompletionCommand();
323
+ await completionCommand.install({ shell, verbose: options?.verbose });
324
+ }
325
+ catch (error) {
326
+ console.log();
327
+ ora().fail(`Error: ${error.message}`);
328
+ process.exit(1);
329
+ }
330
+ });
331
+ completionCmd
332
+ .command('uninstall [shell]')
333
+ .description('Uninstall completion script for a shell')
334
+ .option('-y, --yes', 'Skip confirmation prompts')
335
+ .action(async (shell, options) => {
336
+ try {
337
+ const completionCommand = new CompletionCommand();
338
+ await completionCommand.uninstall({ shell, yes: options?.yes });
339
+ }
340
+ catch (error) {
341
+ console.log();
342
+ ora().fail(`Error: ${error.message}`);
343
+ process.exit(1);
344
+ }
345
+ });
346
+ // Hidden command for machine-readable completion data
347
+ program
348
+ .command('__complete <type>', { hidden: true })
349
+ .description('Output completion data in machine-readable format (internal use)')
350
+ .action(async (type) => {
351
+ try {
352
+ const completionCommand = new CompletionCommand();
353
+ await completionCommand.complete({ type });
354
+ }
355
+ catch (error) {
356
+ // Silently fail for graceful shell completion experience
357
+ process.exitCode = 1;
358
+ }
359
+ });
360
+ program.parse();
361
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,35 @@
1
+ export declare class ChangeCommand {
2
+ private converter;
3
+ constructor();
4
+ /**
5
+ * Show a change proposal.
6
+ * - Text mode: raw markdown passthrough (no filters)
7
+ * - JSON mode: minimal object with deltas; --deltas-only returns same object with filtered deltas
8
+ * Note: --requirements-only is deprecated alias for --deltas-only
9
+ */
10
+ show(changeName?: string, options?: {
11
+ json?: boolean;
12
+ requirementsOnly?: boolean;
13
+ deltasOnly?: boolean;
14
+ noInteractive?: boolean;
15
+ }): Promise<void>;
16
+ /**
17
+ * List active changes.
18
+ * - Text default: IDs only; --long prints minimal details (title, counts)
19
+ * - JSON: array of { id, title, deltaCount, taskStatus }, sorted by id
20
+ */
21
+ list(options?: {
22
+ json?: boolean;
23
+ long?: boolean;
24
+ }): Promise<void>;
25
+ validate(changeName?: string, options?: {
26
+ strict?: boolean;
27
+ json?: boolean;
28
+ noInteractive?: boolean;
29
+ }): Promise<void>;
30
+ private getActiveChanges;
31
+ private extractTitle;
32
+ private countTasks;
33
+ private printNextSteps;
34
+ }
35
+ //# sourceMappingURL=change.d.ts.map
@@ -0,0 +1,277 @@
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
+ // Constants for better maintainability
9
+ const ARCHIVE_DIR = 'archive';
10
+ const TASK_PATTERN = /^[-*]\s+\[[\sx]\]/i;
11
+ const COMPLETED_TASK_PATTERN = /^[-*]\s+\[x\]/i;
12
+ export class ChangeCommand {
13
+ converter;
14
+ constructor() {
15
+ this.converter = new JsonConverter();
16
+ }
17
+ /**
18
+ * Show a change proposal.
19
+ * - Text mode: raw markdown passthrough (no filters)
20
+ * - JSON mode: minimal object with deltas; --deltas-only returns same object with filtered deltas
21
+ * Note: --requirements-only is deprecated alias for --deltas-only
22
+ */
23
+ async show(changeName, options) {
24
+ const changesPath = path.join(process.cwd(), 'lightspec', 'changes');
25
+ if (!changeName) {
26
+ const canPrompt = isInteractive(options);
27
+ const changes = await this.getActiveChanges(changesPath);
28
+ if (canPrompt && changes.length > 0) {
29
+ const { select } = await import('@inquirer/prompts');
30
+ const selected = await select({
31
+ message: 'Select a change to show',
32
+ choices: changes.map(id => ({ name: id, value: id })),
33
+ });
34
+ changeName = selected;
35
+ }
36
+ else {
37
+ if (changes.length === 0) {
38
+ console.error('No change specified. No active changes found.');
39
+ }
40
+ else {
41
+ console.error(`No change specified. Available IDs: ${changes.join(', ')}`);
42
+ }
43
+ console.error('Hint: use "lightspec change list" to view available changes.');
44
+ process.exitCode = 1;
45
+ return;
46
+ }
47
+ }
48
+ const proposalPath = path.join(changesPath, changeName, 'proposal.md');
49
+ try {
50
+ await fs.access(proposalPath);
51
+ }
52
+ catch {
53
+ throw new Error(`Change "${changeName}" not found at ${proposalPath}`);
54
+ }
55
+ if (options?.json) {
56
+ const jsonOutput = await this.converter.convertChangeToJson(proposalPath);
57
+ if (options.requirementsOnly) {
58
+ console.error('Flag --requirements-only is deprecated; use --deltas-only instead.');
59
+ }
60
+ const parsed = JSON.parse(jsonOutput);
61
+ const contentForTitle = await fs.readFile(proposalPath, 'utf-8');
62
+ const title = this.extractTitle(contentForTitle, changeName);
63
+ const id = parsed.name;
64
+ const deltas = parsed.deltas || [];
65
+ if (options.requirementsOnly || options.deltasOnly) {
66
+ const output = { id, title, deltaCount: deltas.length, deltas };
67
+ console.log(JSON.stringify(output, null, 2));
68
+ }
69
+ else {
70
+ const output = {
71
+ id,
72
+ title,
73
+ deltaCount: deltas.length,
74
+ deltas,
75
+ };
76
+ console.log(JSON.stringify(output, null, 2));
77
+ }
78
+ }
79
+ else {
80
+ const content = await fs.readFile(proposalPath, 'utf-8');
81
+ console.log(content);
82
+ }
83
+ }
84
+ /**
85
+ * List active changes.
86
+ * - Text default: IDs only; --long prints minimal details (title, counts)
87
+ * - JSON: array of { id, title, deltaCount, taskStatus }, sorted by id
88
+ */
89
+ async list(options) {
90
+ const changesPath = path.join(process.cwd(), 'lightspec', 'changes');
91
+ const changes = await this.getActiveChanges(changesPath);
92
+ if (options?.json) {
93
+ const changeDetails = await Promise.all(changes.map(async (changeName) => {
94
+ const proposalPath = path.join(changesPath, changeName, 'proposal.md');
95
+ const tasksPath = path.join(changesPath, changeName, 'tasks.md');
96
+ try {
97
+ const content = await fs.readFile(proposalPath, 'utf-8');
98
+ const changeDir = path.join(changesPath, changeName);
99
+ const parser = new ChangeParser(content, changeDir);
100
+ const change = await parser.parseChangeWithDeltas(changeName);
101
+ let taskStatus = { total: 0, completed: 0 };
102
+ try {
103
+ const tasksContent = await fs.readFile(tasksPath, 'utf-8');
104
+ taskStatus = this.countTasks(tasksContent);
105
+ }
106
+ catch (error) {
107
+ // Tasks file may not exist, which is okay
108
+ if (process.env.DEBUG) {
109
+ console.error(`Failed to read tasks file at ${tasksPath}:`, error);
110
+ }
111
+ }
112
+ return {
113
+ id: changeName,
114
+ title: this.extractTitle(content, changeName),
115
+ deltaCount: change.deltas.length,
116
+ taskStatus,
117
+ };
118
+ }
119
+ catch (error) {
120
+ return {
121
+ id: changeName,
122
+ title: 'Unknown',
123
+ deltaCount: 0,
124
+ taskStatus: { total: 0, completed: 0 },
125
+ };
126
+ }
127
+ }));
128
+ const sorted = changeDetails.sort((a, b) => a.id.localeCompare(b.id));
129
+ console.log(JSON.stringify(sorted, null, 2));
130
+ }
131
+ else {
132
+ if (changes.length === 0) {
133
+ console.log('No items found');
134
+ return;
135
+ }
136
+ const sorted = [...changes].sort();
137
+ if (!options?.long) {
138
+ // IDs only
139
+ sorted.forEach(id => console.log(id));
140
+ return;
141
+ }
142
+ // Long format: id: title and minimal counts
143
+ for (const changeName of sorted) {
144
+ const proposalPath = path.join(changesPath, changeName, 'proposal.md');
145
+ const tasksPath = path.join(changesPath, changeName, 'tasks.md');
146
+ try {
147
+ const content = await fs.readFile(proposalPath, 'utf-8');
148
+ const title = this.extractTitle(content, changeName);
149
+ let taskStatusText = '';
150
+ try {
151
+ const tasksContent = await fs.readFile(tasksPath, 'utf-8');
152
+ const { total, completed } = this.countTasks(tasksContent);
153
+ taskStatusText = ` [tasks ${completed}/${total}]`;
154
+ }
155
+ catch (error) {
156
+ if (process.env.DEBUG) {
157
+ console.error(`Failed to read tasks file at ${tasksPath}:`, error);
158
+ }
159
+ }
160
+ const changeDir = path.join(changesPath, changeName);
161
+ const parser = new ChangeParser(await fs.readFile(proposalPath, 'utf-8'), changeDir);
162
+ const change = await parser.parseChangeWithDeltas(changeName);
163
+ const deltaCountText = ` [deltas ${change.deltas.length}]`;
164
+ console.log(`${changeName}: ${title}${deltaCountText}${taskStatusText}`);
165
+ }
166
+ catch {
167
+ console.log(`${changeName}: (unable to read)`);
168
+ }
169
+ }
170
+ }
171
+ }
172
+ async validate(changeName, options) {
173
+ const changesPath = path.join(process.cwd(), 'lightspec', 'changes');
174
+ if (!changeName) {
175
+ const canPrompt = isInteractive(options);
176
+ const changes = await getActiveChangeIds();
177
+ if (canPrompt && changes.length > 0) {
178
+ const { select } = await import('@inquirer/prompts');
179
+ const selected = await select({
180
+ message: 'Select a change to validate',
181
+ choices: changes.map(id => ({ name: id, value: id })),
182
+ });
183
+ changeName = selected;
184
+ }
185
+ else {
186
+ if (changes.length === 0) {
187
+ console.error('No change specified. No active changes found.');
188
+ }
189
+ else {
190
+ console.error(`No change specified. Available IDs: ${changes.join(', ')}`);
191
+ }
192
+ console.error('Hint: use "lightspec change list" to view available changes.');
193
+ process.exitCode = 1;
194
+ return;
195
+ }
196
+ }
197
+ const changeDir = path.join(changesPath, changeName);
198
+ try {
199
+ await fs.access(changeDir);
200
+ }
201
+ catch {
202
+ throw new Error(`Change "${changeName}" not found at ${changeDir}`);
203
+ }
204
+ const validator = new Validator(options?.strict || false);
205
+ const report = await validator.validateChangeDeltaSpecs(changeDir);
206
+ if (options?.json) {
207
+ console.log(JSON.stringify(report, null, 2));
208
+ }
209
+ else {
210
+ if (report.valid) {
211
+ console.log(`Change "${changeName}" is valid`);
212
+ }
213
+ else {
214
+ console.error(`Change "${changeName}" has issues`);
215
+ report.issues.forEach(issue => {
216
+ const label = issue.level === 'ERROR' ? 'ERROR' : 'WARNING';
217
+ const prefix = issue.level === 'ERROR' ? '✗' : '⚠';
218
+ console.error(`${prefix} [${label}] ${issue.path}: ${issue.message}`);
219
+ });
220
+ // Next steps footer to guide fixing issues
221
+ this.printNextSteps();
222
+ if (!options?.json) {
223
+ process.exitCode = 1;
224
+ }
225
+ }
226
+ }
227
+ }
228
+ async getActiveChanges(changesPath) {
229
+ try {
230
+ const entries = await fs.readdir(changesPath, { withFileTypes: true });
231
+ const result = [];
232
+ for (const entry of entries) {
233
+ if (!entry.isDirectory() || entry.name.startsWith('.') || entry.name === ARCHIVE_DIR)
234
+ continue;
235
+ const proposalPath = path.join(changesPath, entry.name, 'proposal.md');
236
+ try {
237
+ await fs.access(proposalPath);
238
+ result.push(entry.name);
239
+ }
240
+ catch {
241
+ // skip directories without proposal.md
242
+ }
243
+ }
244
+ return result.sort();
245
+ }
246
+ catch {
247
+ return [];
248
+ }
249
+ }
250
+ extractTitle(content, changeName) {
251
+ const match = content.match(/^#\s+(?:Change:\s+)?(.+)$/im);
252
+ return match ? match[1].trim() : changeName;
253
+ }
254
+ countTasks(content) {
255
+ const lines = content.split('\n');
256
+ let total = 0;
257
+ let completed = 0;
258
+ for (const line of lines) {
259
+ if (line.match(TASK_PATTERN)) {
260
+ total++;
261
+ if (line.match(COMPLETED_TASK_PATTERN)) {
262
+ completed++;
263
+ }
264
+ }
265
+ }
266
+ return { total, completed };
267
+ }
268
+ printNextSteps() {
269
+ const bullets = [];
270
+ bullets.push('- Ensure change has deltas in specs/: use headers ## ADDED/MODIFIED/REMOVED/RENAMED Requirements');
271
+ bullets.push('- Each requirement MUST include at least one #### Scenario: block');
272
+ bullets.push('- Debug parsed deltas: lightspec change show <id> --json --deltas-only');
273
+ console.error('Next steps:');
274
+ bullets.forEach(b => console.error(` ${b}`));
275
+ }
276
+ }
277
+ //# sourceMappingURL=change.js.map