@zhuan-ai/zhuanspec 1.3.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 (210) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +461 -0
  3. package/README.zh.md +434 -0
  4. package/bin/zhuanspec.js +3 -0
  5. package/dist/cli/index.d.ts +2 -0
  6. package/dist/cli/index.js +356 -0
  7. package/dist/commands/artifact-workflow.d.ts +13 -0
  8. package/dist/commands/artifact-workflow.js +916 -0
  9. package/dist/commands/change.d.ts +35 -0
  10. package/dist/commands/change.js +277 -0
  11. package/dist/commands/completion.d.ts +72 -0
  12. package/dist/commands/completion.js +221 -0
  13. package/dist/commands/config.d.ts +8 -0
  14. package/dist/commands/config.js +198 -0
  15. package/dist/commands/show.d.ts +14 -0
  16. package/dist/commands/show.js +132 -0
  17. package/dist/commands/spec.d.ts +15 -0
  18. package/dist/commands/spec.js +225 -0
  19. package/dist/commands/validate.d.ts +24 -0
  20. package/dist/commands/validate.js +294 -0
  21. package/dist/core/archive.d.ts +30 -0
  22. package/dist/core/archive.js +438 -0
  23. package/dist/core/artifact-graph/graph.d.ts +56 -0
  24. package/dist/core/artifact-graph/graph.js +141 -0
  25. package/dist/core/artifact-graph/index.d.ts +7 -0
  26. package/dist/core/artifact-graph/index.js +13 -0
  27. package/dist/core/artifact-graph/instruction-loader.d.ts +134 -0
  28. package/dist/core/artifact-graph/instruction-loader.js +180 -0
  29. package/dist/core/artifact-graph/resolver.d.ts +61 -0
  30. package/dist/core/artifact-graph/resolver.js +187 -0
  31. package/dist/core/artifact-graph/schema.d.ts +13 -0
  32. package/dist/core/artifact-graph/schema.js +108 -0
  33. package/dist/core/artifact-graph/state.d.ts +12 -0
  34. package/dist/core/artifact-graph/state.js +54 -0
  35. package/dist/core/artifact-graph/types.d.ts +45 -0
  36. package/dist/core/artifact-graph/types.js +43 -0
  37. package/dist/core/completions/command-registry.d.ts +7 -0
  38. package/dist/core/completions/command-registry.js +362 -0
  39. package/dist/core/completions/completion-provider.d.ts +60 -0
  40. package/dist/core/completions/completion-provider.js +102 -0
  41. package/dist/core/completions/factory.d.ts +51 -0
  42. package/dist/core/completions/factory.js +57 -0
  43. package/dist/core/completions/generators/zsh-generator.d.ts +58 -0
  44. package/dist/core/completions/generators/zsh-generator.js +319 -0
  45. package/dist/core/completions/installers/zsh-installer.d.ts +136 -0
  46. package/dist/core/completions/installers/zsh-installer.js +449 -0
  47. package/dist/core/completions/types.d.ts +78 -0
  48. package/dist/core/completions/types.js +2 -0
  49. package/dist/core/config-schema.d.ts +76 -0
  50. package/dist/core/config-schema.js +200 -0
  51. package/dist/core/config.d.ts +16 -0
  52. package/dist/core/config.js +29 -0
  53. package/dist/core/configurators/agents.d.ts +8 -0
  54. package/dist/core/configurators/agents.js +15 -0
  55. package/dist/core/configurators/base.d.ts +7 -0
  56. package/dist/core/configurators/base.js +2 -0
  57. package/dist/core/configurators/claude.d.ts +8 -0
  58. package/dist/core/configurators/claude.js +15 -0
  59. package/dist/core/configurators/cline.d.ts +8 -0
  60. package/dist/core/configurators/cline.js +15 -0
  61. package/dist/core/configurators/codebuddy.d.ts +8 -0
  62. package/dist/core/configurators/codebuddy.js +15 -0
  63. package/dist/core/configurators/costrict.d.ts +8 -0
  64. package/dist/core/configurators/costrict.js +15 -0
  65. package/dist/core/configurators/iflow.d.ts +8 -0
  66. package/dist/core/configurators/iflow.js +15 -0
  67. package/dist/core/configurators/qoder.d.ts +30 -0
  68. package/dist/core/configurators/qoder.js +42 -0
  69. package/dist/core/configurators/qwen.d.ts +24 -0
  70. package/dist/core/configurators/qwen.js +37 -0
  71. package/dist/core/configurators/registry.d.ts +9 -0
  72. package/dist/core/configurators/registry.js +43 -0
  73. package/dist/core/configurators/slash/amazon-q.d.ts +9 -0
  74. package/dist/core/configurators/slash/amazon-q.js +46 -0
  75. package/dist/core/configurators/slash/antigravity.d.ts +9 -0
  76. package/dist/core/configurators/slash/antigravity.js +23 -0
  77. package/dist/core/configurators/slash/auggie.d.ts +9 -0
  78. package/dist/core/configurators/slash/auggie.js +31 -0
  79. package/dist/core/configurators/slash/base.d.ts +19 -0
  80. package/dist/core/configurators/slash/base.js +69 -0
  81. package/dist/core/configurators/slash/claude.d.ts +9 -0
  82. package/dist/core/configurators/slash/claude.js +37 -0
  83. package/dist/core/configurators/slash/cline.d.ts +9 -0
  84. package/dist/core/configurators/slash/cline.js +23 -0
  85. package/dist/core/configurators/slash/codebuddy.d.ts +9 -0
  86. package/dist/core/configurators/slash/codebuddy.js +37 -0
  87. package/dist/core/configurators/slash/codex.d.ts +14 -0
  88. package/dist/core/configurators/slash/codex.js +109 -0
  89. package/dist/core/configurators/slash/costrict.d.ts +9 -0
  90. package/dist/core/configurators/slash/costrict.js +31 -0
  91. package/dist/core/configurators/slash/crush.d.ts +9 -0
  92. package/dist/core/configurators/slash/crush.js +37 -0
  93. package/dist/core/configurators/slash/cursor.d.ts +9 -0
  94. package/dist/core/configurators/slash/cursor.js +37 -0
  95. package/dist/core/configurators/slash/factory.d.ts +10 -0
  96. package/dist/core/configurators/slash/factory.js +35 -0
  97. package/dist/core/configurators/slash/gemini.d.ts +9 -0
  98. package/dist/core/configurators/slash/gemini.js +22 -0
  99. package/dist/core/configurators/slash/github-copilot.d.ts +9 -0
  100. package/dist/core/configurators/slash/github-copilot.js +34 -0
  101. package/dist/core/configurators/slash/iflow.d.ts +9 -0
  102. package/dist/core/configurators/slash/iflow.js +37 -0
  103. package/dist/core/configurators/slash/kilocode.d.ts +9 -0
  104. package/dist/core/configurators/slash/kilocode.js +17 -0
  105. package/dist/core/configurators/slash/opencode.d.ts +12 -0
  106. package/dist/core/configurators/slash/opencode.js +72 -0
  107. package/dist/core/configurators/slash/qoder.d.ts +35 -0
  108. package/dist/core/configurators/slash/qoder.js +76 -0
  109. package/dist/core/configurators/slash/qwen.d.ts +32 -0
  110. package/dist/core/configurators/slash/qwen.js +49 -0
  111. package/dist/core/configurators/slash/registry.d.ts +8 -0
  112. package/dist/core/configurators/slash/registry.js +75 -0
  113. package/dist/core/configurators/slash/roocode.d.ts +9 -0
  114. package/dist/core/configurators/slash/roocode.js +23 -0
  115. package/dist/core/configurators/slash/toml-base.d.ts +10 -0
  116. package/dist/core/configurators/slash/toml-base.js +53 -0
  117. package/dist/core/configurators/slash/windsurf.d.ts +9 -0
  118. package/dist/core/configurators/slash/windsurf.js +23 -0
  119. package/dist/core/converters/json-converter.d.ts +6 -0
  120. package/dist/core/converters/json-converter.js +51 -0
  121. package/dist/core/global-config.d.ts +39 -0
  122. package/dist/core/global-config.js +115 -0
  123. package/dist/core/index.d.ts +2 -0
  124. package/dist/core/index.js +3 -0
  125. package/dist/core/init.d.ts +60 -0
  126. package/dist/core/init.js +861 -0
  127. package/dist/core/list.d.ts +9 -0
  128. package/dist/core/list.js +171 -0
  129. package/dist/core/parsers/change-parser.d.ts +13 -0
  130. package/dist/core/parsers/change-parser.js +193 -0
  131. package/dist/core/parsers/markdown-parser.d.ts +22 -0
  132. package/dist/core/parsers/markdown-parser.js +187 -0
  133. package/dist/core/parsers/requirement-blocks.d.ts +37 -0
  134. package/dist/core/parsers/requirement-blocks.js +201 -0
  135. package/dist/core/project-config.d.ts +34 -0
  136. package/dist/core/project-config.js +79 -0
  137. package/dist/core/schemas/base.schema.d.ts +13 -0
  138. package/dist/core/schemas/base.schema.js +13 -0
  139. package/dist/core/schemas/change.schema.d.ts +73 -0
  140. package/dist/core/schemas/change.schema.js +31 -0
  141. package/dist/core/schemas/index.d.ts +4 -0
  142. package/dist/core/schemas/index.js +4 -0
  143. package/dist/core/schemas/spec.schema.d.ts +18 -0
  144. package/dist/core/schemas/spec.schema.js +15 -0
  145. package/dist/core/skill-discovery.d.ts +24 -0
  146. package/dist/core/skill-discovery.js +153 -0
  147. package/dist/core/specs-apply.d.ts +73 -0
  148. package/dist/core/specs-apply.js +384 -0
  149. package/dist/core/styles/palette.d.ts +7 -0
  150. package/dist/core/styles/palette.js +8 -0
  151. package/dist/core/templates/agents-root-stub.d.ts +2 -0
  152. package/dist/core/templates/agents-root-stub.js +17 -0
  153. package/dist/core/templates/agents-template.d.ts +2 -0
  154. package/dist/core/templates/agents-template.js +706 -0
  155. package/dist/core/templates/claude-template.d.ts +2 -0
  156. package/dist/core/templates/claude-template.js +2 -0
  157. package/dist/core/templates/cline-template.d.ts +2 -0
  158. package/dist/core/templates/cline-template.js +2 -0
  159. package/dist/core/templates/costrict-template.d.ts +2 -0
  160. package/dist/core/templates/costrict-template.js +2 -0
  161. package/dist/core/templates/index.d.ts +17 -0
  162. package/dist/core/templates/index.js +37 -0
  163. package/dist/core/templates/project-template.d.ts +8 -0
  164. package/dist/core/templates/project-template.js +32 -0
  165. package/dist/core/templates/skill-templates.d.ts +103 -0
  166. package/dist/core/templates/skill-templates.js +2131 -0
  167. package/dist/core/templates/slash-command-templates.d.ts +4 -0
  168. package/dist/core/templates/slash-command-templates.js +81 -0
  169. package/dist/core/update.d.ts +4 -0
  170. package/dist/core/update.js +88 -0
  171. package/dist/core/validation/constants.d.ts +34 -0
  172. package/dist/core/validation/constants.js +40 -0
  173. package/dist/core/validation/types.d.ts +18 -0
  174. package/dist/core/validation/types.js +2 -0
  175. package/dist/core/validation/validator.d.ts +33 -0
  176. package/dist/core/validation/validator.js +409 -0
  177. package/dist/core/view.d.ts +8 -0
  178. package/dist/core/view.js +168 -0
  179. package/dist/index.d.ts +3 -0
  180. package/dist/index.js +3 -0
  181. package/dist/utils/change-metadata.d.ts +47 -0
  182. package/dist/utils/change-metadata.js +130 -0
  183. package/dist/utils/change-utils.d.ts +51 -0
  184. package/dist/utils/change-utils.js +100 -0
  185. package/dist/utils/file-system.d.ts +19 -0
  186. package/dist/utils/file-system.js +177 -0
  187. package/dist/utils/index.d.ts +4 -0
  188. package/dist/utils/index.js +5 -0
  189. package/dist/utils/interactive.d.ts +18 -0
  190. package/dist/utils/interactive.js +21 -0
  191. package/dist/utils/item-discovery.d.ts +4 -0
  192. package/dist/utils/item-discovery.js +72 -0
  193. package/dist/utils/match.d.ts +3 -0
  194. package/dist/utils/match.js +22 -0
  195. package/dist/utils/shell-detection.d.ts +20 -0
  196. package/dist/utils/shell-detection.js +41 -0
  197. package/dist/utils/task-progress.d.ts +8 -0
  198. package/dist/utils/task-progress.js +36 -0
  199. package/package.json +81 -0
  200. package/schemas/spec-driven/schema.yaml +205 -0
  201. package/schemas/spec-driven/templates/design.md +19 -0
  202. package/schemas/spec-driven/templates/proposal.md +43 -0
  203. package/schemas/spec-driven/templates/spec.md +8 -0
  204. package/schemas/spec-driven/templates/tasks.md +25 -0
  205. package/schemas/tdd/schema.yaml +213 -0
  206. package/schemas/tdd/templates/docs.md +0 -0
  207. package/schemas/tdd/templates/implementation.md +11 -0
  208. package/schemas/tdd/templates/spec.md +11 -0
  209. package/schemas/tdd/templates/test.md +11 -0
  210. package/scripts/postinstall.js +147 -0
@@ -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(), 'zhuanspec', '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 "zhuanspec 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(), 'zhuanspec', '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(), 'zhuanspec', '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 "zhuanspec 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: zhuanspec 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
@@ -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 ZhuanSpec 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,221 @@
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
+ /**
8
+ * Command for managing shell completions for ZhuanSpec CLI
9
+ */
10
+ export class CompletionCommand {
11
+ completionProvider;
12
+ constructor() {
13
+ this.completionProvider = new CompletionProvider();
14
+ }
15
+ /**
16
+ * Resolve shell parameter or exit with error
17
+ *
18
+ * @param shell - The shell parameter (may be undefined)
19
+ * @param operationName - Name of the operation (for error messages)
20
+ * @returns Resolved shell or null if should exit
21
+ */
22
+ resolveShellOrExit(shell, operationName) {
23
+ const normalizedShell = this.normalizeShell(shell);
24
+ if (!normalizedShell) {
25
+ const detectionResult = detectShell();
26
+ if (detectionResult.shell && CompletionFactory.isSupported(detectionResult.shell)) {
27
+ return detectionResult.shell;
28
+ }
29
+ // Shell was detected but not supported
30
+ if (detectionResult.detected && !detectionResult.shell) {
31
+ console.error(`Error: Shell '${detectionResult.detected}' is not supported yet. Currently supported: ${CompletionFactory.getSupportedShells().join(', ')}`);
32
+ process.exitCode = 1;
33
+ return null;
34
+ }
35
+ // No shell specified and cannot auto-detect
36
+ console.error('Error: Could not auto-detect shell. Please specify shell explicitly.');
37
+ console.error(`Usage: zhuanspec completion ${operationName} [shell]`);
38
+ console.error(`Currently supported: ${CompletionFactory.getSupportedShells().join(', ')}`);
39
+ process.exitCode = 1;
40
+ return null;
41
+ }
42
+ if (!CompletionFactory.isSupported(normalizedShell)) {
43
+ console.error(`Error: Shell '${normalizedShell}' is not supported yet. Currently supported: ${CompletionFactory.getSupportedShells().join(', ')}`);
44
+ process.exitCode = 1;
45
+ return null;
46
+ }
47
+ return normalizedShell;
48
+ }
49
+ /**
50
+ * Generate completion script and output to stdout
51
+ *
52
+ * @param options - Options for generation (shell type)
53
+ */
54
+ async generate(options = {}) {
55
+ const shell = this.resolveShellOrExit(options.shell, 'generate');
56
+ if (!shell)
57
+ return;
58
+ await this.generateForShell(shell);
59
+ }
60
+ /**
61
+ * Install completion script to the appropriate location
62
+ *
63
+ * @param options - Options for installation (shell type, verbose output)
64
+ */
65
+ async install(options = {}) {
66
+ const shell = this.resolveShellOrExit(options.shell, 'install');
67
+ if (!shell)
68
+ return;
69
+ await this.installForShell(shell, options.verbose || false);
70
+ }
71
+ /**
72
+ * Uninstall completion script from the installation location
73
+ *
74
+ * @param options - Options for uninstallation (shell type, yes flag)
75
+ */
76
+ async uninstall(options = {}) {
77
+ const shell = this.resolveShellOrExit(options.shell, 'uninstall');
78
+ if (!shell)
79
+ return;
80
+ await this.uninstallForShell(shell, options.yes || false);
81
+ }
82
+ /**
83
+ * Generate completion script for a specific shell
84
+ */
85
+ async generateForShell(shell) {
86
+ const generator = CompletionFactory.createGenerator(shell);
87
+ const script = generator.generate(COMMAND_REGISTRY);
88
+ console.log(script);
89
+ }
90
+ /**
91
+ * Install completion script for a specific shell
92
+ */
93
+ async installForShell(shell, verbose) {
94
+ const generator = CompletionFactory.createGenerator(shell);
95
+ const installer = CompletionFactory.createInstaller(shell);
96
+ const spinner = ora(`Installing ${shell} completion script...`).start();
97
+ try {
98
+ // Generate the completion script
99
+ const script = generator.generate(COMMAND_REGISTRY);
100
+ // Install it
101
+ const result = await installer.install(script);
102
+ spinner.stop();
103
+ if (result.success) {
104
+ console.log(`✓ ${result.message}`);
105
+ if (verbose && result.installedPath) {
106
+ console.log(` Installed to: ${result.installedPath}`);
107
+ if (result.backupPath) {
108
+ console.log(` Backup created: ${result.backupPath}`);
109
+ }
110
+ if (result.zshrcConfigured) {
111
+ console.log(` ~/.zshrc configured automatically`);
112
+ }
113
+ }
114
+ // Print instructions (only shown if .zshrc wasn't auto-configured)
115
+ if (result.instructions && result.instructions.length > 0) {
116
+ console.log('');
117
+ for (const instruction of result.instructions) {
118
+ console.log(instruction);
119
+ }
120
+ }
121
+ else if (result.zshrcConfigured) {
122
+ console.log('');
123
+ console.log('Restart your shell or run: exec zsh');
124
+ }
125
+ }
126
+ else {
127
+ console.error(`✗ ${result.message}`);
128
+ process.exitCode = 1;
129
+ }
130
+ }
131
+ catch (error) {
132
+ spinner.stop();
133
+ console.error(`✗ Failed to install completion script: ${error instanceof Error ? error.message : String(error)}`);
134
+ process.exitCode = 1;
135
+ }
136
+ }
137
+ /**
138
+ * Uninstall completion script for a specific shell
139
+ */
140
+ async uninstallForShell(shell, skipConfirmation) {
141
+ const installer = CompletionFactory.createInstaller(shell);
142
+ // Prompt for confirmation unless --yes flag is provided
143
+ if (!skipConfirmation) {
144
+ const { confirm } = await import('@inquirer/prompts');
145
+ const confirmed = await confirm({
146
+ message: 'Remove ZhuanSpec configuration from ~/.zshrc?',
147
+ default: false,
148
+ });
149
+ if (!confirmed) {
150
+ console.log('Uninstall cancelled.');
151
+ return;
152
+ }
153
+ }
154
+ const spinner = ora(`Uninstalling ${shell} completion script...`).start();
155
+ try {
156
+ const result = await installer.uninstall();
157
+ spinner.stop();
158
+ if (result.success) {
159
+ console.log(`✓ ${result.message}`);
160
+ }
161
+ else {
162
+ console.error(`✗ ${result.message}`);
163
+ process.exitCode = 1;
164
+ }
165
+ }
166
+ catch (error) {
167
+ spinner.stop();
168
+ console.error(`✗ Failed to uninstall completion script: ${error instanceof Error ? error.message : String(error)}`);
169
+ process.exitCode = 1;
170
+ }
171
+ }
172
+ /**
173
+ * Output machine-readable completion data for shell consumption
174
+ * Format: tab-separated "id\tdescription" per line
175
+ *
176
+ * @param options - Options specifying completion type
177
+ */
178
+ async complete(options) {
179
+ const type = options.type.toLowerCase();
180
+ try {
181
+ switch (type) {
182
+ case 'changes': {
183
+ const changeIds = await this.completionProvider.getChangeIds();
184
+ for (const id of changeIds) {
185
+ console.log(`${id}\tactive change`);
186
+ }
187
+ break;
188
+ }
189
+ case 'specs': {
190
+ const specIds = await this.completionProvider.getSpecIds();
191
+ for (const id of specIds) {
192
+ console.log(`${id}\tspecification`);
193
+ }
194
+ break;
195
+ }
196
+ case 'archived-changes': {
197
+ const archivedIds = await getArchivedChangeIds();
198
+ for (const id of archivedIds) {
199
+ console.log(`${id}\tarchived change`);
200
+ }
201
+ break;
202
+ }
203
+ default:
204
+ // Invalid type - silently exit with no output for graceful shell completion failure
205
+ process.exitCode = 1;
206
+ break;
207
+ }
208
+ }
209
+ catch {
210
+ // Silently fail for graceful shell completion experience
211
+ process.exitCode = 1;
212
+ }
213
+ }
214
+ /**
215
+ * Normalize shell parameter to lowercase
216
+ */
217
+ normalizeShell(shell) {
218
+ return shell?.toLowerCase();
219
+ }
220
+ }
221
+ //# sourceMappingURL=completion.js.map
@@ -0,0 +1,8 @@
1
+ import { Command } from 'commander';
2
+ /**
3
+ * Register the config command and all its subcommands.
4
+ *
5
+ * @param program - The Commander program instance
6
+ */
7
+ export declare function registerConfigCommand(program: Command): void;
8
+ //# sourceMappingURL=config.d.ts.map