openspec-cn 0.23.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +22 -0
- package/README.md +153 -0
- package/bin/openspec.js +3 -0
- package/dist/cli/index.d.ts +2 -0
- package/dist/cli/index.js +480 -0
- package/dist/commands/change.d.ts +35 -0
- package/dist/commands/change.js +277 -0
- package/dist/commands/completion.d.ts +72 -0
- package/dist/commands/completion.js +257 -0
- package/dist/commands/config.d.ts +8 -0
- package/dist/commands/config.js +198 -0
- package/dist/commands/feedback.d.ts +9 -0
- package/dist/commands/feedback.js +183 -0
- package/dist/commands/schema.d.ts +6 -0
- package/dist/commands/schema.js +869 -0
- package/dist/commands/show.d.ts +14 -0
- package/dist/commands/show.js +132 -0
- package/dist/commands/spec.d.ts +15 -0
- package/dist/commands/spec.js +225 -0
- package/dist/commands/validate.d.ts +24 -0
- package/dist/commands/validate.js +294 -0
- package/dist/commands/workflow/index.d.ts +17 -0
- package/dist/commands/workflow/index.js +12 -0
- package/dist/commands/workflow/instructions.d.ts +29 -0
- package/dist/commands/workflow/instructions.js +381 -0
- package/dist/commands/workflow/new-change.d.ts +11 -0
- package/dist/commands/workflow/new-change.js +44 -0
- package/dist/commands/workflow/schemas.d.ts +10 -0
- package/dist/commands/workflow/schemas.js +34 -0
- package/dist/commands/workflow/shared.d.ts +52 -0
- package/dist/commands/workflow/shared.js +111 -0
- package/dist/commands/workflow/status.d.ts +14 -0
- package/dist/commands/workflow/status.js +58 -0
- package/dist/commands/workflow/templates.d.ts +16 -0
- package/dist/commands/workflow/templates.js +68 -0
- package/dist/core/archive.d.ts +11 -0
- package/dist/core/archive.js +280 -0
- package/dist/core/artifact-graph/graph.d.ts +56 -0
- package/dist/core/artifact-graph/graph.js +141 -0
- package/dist/core/artifact-graph/index.d.ts +7 -0
- package/dist/core/artifact-graph/index.js +13 -0
- package/dist/core/artifact-graph/instruction-loader.d.ts +143 -0
- package/dist/core/artifact-graph/instruction-loader.js +214 -0
- package/dist/core/artifact-graph/resolver.d.ts +81 -0
- package/dist/core/artifact-graph/resolver.js +257 -0
- package/dist/core/artifact-graph/schema.d.ts +13 -0
- package/dist/core/artifact-graph/schema.js +108 -0
- package/dist/core/artifact-graph/state.d.ts +12 -0
- package/dist/core/artifact-graph/state.js +54 -0
- package/dist/core/artifact-graph/types.d.ts +45 -0
- package/dist/core/artifact-graph/types.js +43 -0
- package/dist/core/command-generation/adapters/amazon-q.d.ts +13 -0
- package/dist/core/command-generation/adapters/amazon-q.js +26 -0
- package/dist/core/command-generation/adapters/antigravity.d.ts +13 -0
- package/dist/core/command-generation/adapters/antigravity.js +26 -0
- package/dist/core/command-generation/adapters/auggie.d.ts +13 -0
- package/dist/core/command-generation/adapters/auggie.js +27 -0
- package/dist/core/command-generation/adapters/claude.d.ts +13 -0
- package/dist/core/command-generation/adapters/claude.js +50 -0
- package/dist/core/command-generation/adapters/cline.d.ts +14 -0
- package/dist/core/command-generation/adapters/cline.js +27 -0
- package/dist/core/command-generation/adapters/codebuddy.d.ts +13 -0
- package/dist/core/command-generation/adapters/codebuddy.js +28 -0
- package/dist/core/command-generation/adapters/codex.d.ts +13 -0
- package/dist/core/command-generation/adapters/codex.js +27 -0
- package/dist/core/command-generation/adapters/continue.d.ts +13 -0
- package/dist/core/command-generation/adapters/continue.js +28 -0
- package/dist/core/command-generation/adapters/costrict.d.ts +13 -0
- package/dist/core/command-generation/adapters/costrict.js +27 -0
- package/dist/core/command-generation/adapters/crush.d.ts +13 -0
- package/dist/core/command-generation/adapters/crush.js +30 -0
- package/dist/core/command-generation/adapters/cursor.d.ts +14 -0
- package/dist/core/command-generation/adapters/cursor.js +44 -0
- package/dist/core/command-generation/adapters/factory.d.ts +13 -0
- package/dist/core/command-generation/adapters/factory.js +27 -0
- package/dist/core/command-generation/adapters/gemini.d.ts +13 -0
- package/dist/core/command-generation/adapters/gemini.js +26 -0
- package/dist/core/command-generation/adapters/github-copilot.d.ts +13 -0
- package/dist/core/command-generation/adapters/github-copilot.js +26 -0
- package/dist/core/command-generation/adapters/iflow.d.ts +13 -0
- package/dist/core/command-generation/adapters/iflow.js +29 -0
- package/dist/core/command-generation/adapters/index.d.ts +27 -0
- package/dist/core/command-generation/adapters/index.js +27 -0
- package/dist/core/command-generation/adapters/kilocode.d.ts +14 -0
- package/dist/core/command-generation/adapters/kilocode.js +23 -0
- package/dist/core/command-generation/adapters/opencode.d.ts +13 -0
- package/dist/core/command-generation/adapters/opencode.js +26 -0
- package/dist/core/command-generation/adapters/qoder.d.ts +13 -0
- package/dist/core/command-generation/adapters/qoder.js +30 -0
- package/dist/core/command-generation/adapters/qwen.d.ts +13 -0
- package/dist/core/command-generation/adapters/qwen.js +26 -0
- package/dist/core/command-generation/adapters/roocode.d.ts +14 -0
- package/dist/core/command-generation/adapters/roocode.js +27 -0
- package/dist/core/command-generation/adapters/windsurf.d.ts +14 -0
- package/dist/core/command-generation/adapters/windsurf.js +51 -0
- package/dist/core/command-generation/generator.d.ts +21 -0
- package/dist/core/command-generation/generator.js +27 -0
- package/dist/core/command-generation/index.d.ts +22 -0
- package/dist/core/command-generation/index.js +24 -0
- package/dist/core/command-generation/registry.d.ts +36 -0
- package/dist/core/command-generation/registry.js +88 -0
- package/dist/core/command-generation/types.d.ts +55 -0
- package/dist/core/command-generation/types.js +8 -0
- package/dist/core/completions/command-registry.d.ts +7 -0
- package/dist/core/completions/command-registry.js +456 -0
- package/dist/core/completions/completion-provider.d.ts +60 -0
- package/dist/core/completions/completion-provider.js +102 -0
- package/dist/core/completions/factory.d.ts +64 -0
- package/dist/core/completions/factory.js +75 -0
- package/dist/core/completions/generators/bash-generator.d.ts +32 -0
- package/dist/core/completions/generators/bash-generator.js +174 -0
- package/dist/core/completions/generators/fish-generator.d.ts +32 -0
- package/dist/core/completions/generators/fish-generator.js +157 -0
- package/dist/core/completions/generators/powershell-generator.d.ts +33 -0
- package/dist/core/completions/generators/powershell-generator.js +207 -0
- package/dist/core/completions/generators/zsh-generator.d.ts +44 -0
- package/dist/core/completions/generators/zsh-generator.js +250 -0
- package/dist/core/completions/installers/bash-installer.d.ts +87 -0
- package/dist/core/completions/installers/bash-installer.js +318 -0
- package/dist/core/completions/installers/fish-installer.d.ts +43 -0
- package/dist/core/completions/installers/fish-installer.js +143 -0
- package/dist/core/completions/installers/powershell-installer.d.ts +88 -0
- package/dist/core/completions/installers/powershell-installer.js +327 -0
- package/dist/core/completions/installers/zsh-installer.d.ts +125 -0
- package/dist/core/completions/installers/zsh-installer.js +449 -0
- package/dist/core/completions/templates/bash-templates.d.ts +6 -0
- package/dist/core/completions/templates/bash-templates.js +24 -0
- package/dist/core/completions/templates/fish-templates.d.ts +7 -0
- package/dist/core/completions/templates/fish-templates.js +39 -0
- package/dist/core/completions/templates/powershell-templates.d.ts +6 -0
- package/dist/core/completions/templates/powershell-templates.js +25 -0
- package/dist/core/completions/templates/zsh-templates.d.ts +6 -0
- package/dist/core/completions/templates/zsh-templates.js +36 -0
- package/dist/core/completions/types.d.ts +79 -0
- package/dist/core/completions/types.js +2 -0
- package/dist/core/config-prompts.d.ts +9 -0
- package/dist/core/config-prompts.js +34 -0
- package/dist/core/config-schema.d.ts +76 -0
- package/dist/core/config-schema.js +200 -0
- package/dist/core/config.d.ts +17 -0
- package/dist/core/config.js +30 -0
- package/dist/core/converters/json-converter.d.ts +6 -0
- package/dist/core/converters/json-converter.js +51 -0
- package/dist/core/global-config.d.ts +39 -0
- package/dist/core/global-config.js +115 -0
- package/dist/core/index.d.ts +2 -0
- package/dist/core/index.js +3 -0
- package/dist/core/init.d.ts +32 -0
- package/dist/core/init.js +433 -0
- package/dist/core/legacy-cleanup.d.ts +162 -0
- package/dist/core/legacy-cleanup.js +501 -0
- package/dist/core/list.d.ts +9 -0
- package/dist/core/list.js +171 -0
- package/dist/core/parsers/change-parser.d.ts +13 -0
- package/dist/core/parsers/change-parser.js +193 -0
- package/dist/core/parsers/markdown-parser.d.ts +22 -0
- package/dist/core/parsers/markdown-parser.js +187 -0
- package/dist/core/parsers/requirement-blocks.d.ts +37 -0
- package/dist/core/parsers/requirement-blocks.js +201 -0
- package/dist/core/project-config.d.ts +64 -0
- package/dist/core/project-config.js +223 -0
- package/dist/core/schemas/base.schema.d.ts +13 -0
- package/dist/core/schemas/base.schema.js +13 -0
- package/dist/core/schemas/change.schema.d.ts +73 -0
- package/dist/core/schemas/change.schema.js +31 -0
- package/dist/core/schemas/index.d.ts +4 -0
- package/dist/core/schemas/index.js +4 -0
- package/dist/core/schemas/spec.schema.d.ts +18 -0
- package/dist/core/schemas/spec.schema.js +15 -0
- package/dist/core/shared/index.d.ts +8 -0
- package/dist/core/shared/index.js +8 -0
- package/dist/core/shared/skill-generation.d.ts +41 -0
- package/dist/core/shared/skill-generation.js +74 -0
- package/dist/core/shared/tool-detection.d.ts +66 -0
- package/dist/core/shared/tool-detection.js +140 -0
- package/dist/core/specs-apply.d.ts +73 -0
- package/dist/core/specs-apply.js +384 -0
- package/dist/core/styles/palette.d.ts +7 -0
- package/dist/core/styles/palette.js +8 -0
- package/dist/core/templates/index.d.ts +8 -0
- package/dist/core/templates/index.js +9 -0
- package/dist/core/templates/skill-templates.d.ts +112 -0
- package/dist/core/templates/skill-templates.js +2893 -0
- package/dist/core/update.d.ts +42 -0
- package/dist/core/update.js +306 -0
- package/dist/core/validation/constants.d.ts +34 -0
- package/dist/core/validation/constants.js +40 -0
- package/dist/core/validation/types.d.ts +18 -0
- package/dist/core/validation/types.js +2 -0
- package/dist/core/validation/validator.d.ts +33 -0
- package/dist/core/validation/validator.js +409 -0
- package/dist/core/view.d.ts +8 -0
- package/dist/core/view.js +168 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/prompts/searchable-multi-select.d.ts +27 -0
- package/dist/prompts/searchable-multi-select.js +149 -0
- package/dist/telemetry/config.d.ts +32 -0
- package/dist/telemetry/config.js +68 -0
- package/dist/telemetry/index.d.ts +31 -0
- package/dist/telemetry/index.js +145 -0
- package/dist/ui/ascii-patterns.d.ts +16 -0
- package/dist/ui/ascii-patterns.js +133 -0
- package/dist/ui/welcome-screen.d.ts +10 -0
- package/dist/ui/welcome-screen.js +146 -0
- package/dist/utils/change-metadata.d.ts +51 -0
- package/dist/utils/change-metadata.js +147 -0
- package/dist/utils/change-utils.d.ts +62 -0
- package/dist/utils/change-utils.js +121 -0
- package/dist/utils/file-system.d.ts +36 -0
- package/dist/utils/file-system.js +281 -0
- package/dist/utils/index.d.ts +5 -0
- package/dist/utils/index.js +7 -0
- package/dist/utils/interactive.d.ts +18 -0
- package/dist/utils/interactive.js +21 -0
- package/dist/utils/item-discovery.d.ts +4 -0
- package/dist/utils/item-discovery.js +72 -0
- package/dist/utils/match.d.ts +3 -0
- package/dist/utils/match.js +22 -0
- package/dist/utils/shell-detection.d.ts +20 -0
- package/dist/utils/shell-detection.js +41 -0
- package/dist/utils/task-progress.d.ts +8 -0
- package/dist/utils/task-progress.js +36 -0
- package/package.json +84 -0
- package/schemas/spec-driven/schema.yaml +148 -0
- package/schemas/spec-driven/templates/design.md +19 -0
- package/schemas/spec-driven/templates/proposal.md +23 -0
- package/schemas/spec-driven/templates/spec.md +8 -0
- package/schemas/spec-driven/templates/tasks.md +9 -0
- package/schemas/tdd/schema.yaml +213 -0
- package/schemas/tdd/templates/docs.md +15 -0
- package/schemas/tdd/templates/implementation.md +11 -0
- package/schemas/tdd/templates/spec.md +11 -0
- package/schemas/tdd/templates/test.md +11 -0
- 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(), 'openspec', '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 "openspec 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(), 'openspec', '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(), 'openspec', '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 "openspec 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: openspec 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 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,257 @@
|
|
|
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 OpenSpec 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: openspec 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
|
+
// Check if any shell config was updated
|
|
111
|
+
const configWasUpdated = result.zshrcConfigured || result.bashrcConfigured || result.profileConfigured;
|
|
112
|
+
if (configWasUpdated) {
|
|
113
|
+
const configPaths = {
|
|
114
|
+
zsh: '~/.zshrc',
|
|
115
|
+
bash: '~/.bashrc',
|
|
116
|
+
fish: '~/.config/fish/config.fish',
|
|
117
|
+
powershell: '$PROFILE',
|
|
118
|
+
};
|
|
119
|
+
const configPath = configPaths[shell] || 'config file';
|
|
120
|
+
console.log(` ${configPath} configured automatically`);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
// Display warnings if present
|
|
124
|
+
if (result.warnings && result.warnings.length > 0) {
|
|
125
|
+
console.log('');
|
|
126
|
+
for (const warning of result.warnings) {
|
|
127
|
+
console.log(warning);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
// Print instructions (only shown if .zshrc wasn't auto-configured)
|
|
131
|
+
if (result.instructions && result.instructions.length > 0) {
|
|
132
|
+
console.log('');
|
|
133
|
+
for (const instruction of result.instructions) {
|
|
134
|
+
console.log(instruction);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
// Check if any shell config was updated (InstallationResult has: zshrcConfigured, bashrcConfigured, profileConfigured)
|
|
139
|
+
const configWasUpdated = result.zshrcConfigured || result.bashrcConfigured || result.profileConfigured;
|
|
140
|
+
if (configWasUpdated) {
|
|
141
|
+
console.log('');
|
|
142
|
+
// Shell-specific reload instructions
|
|
143
|
+
const reloadCommands = {
|
|
144
|
+
zsh: 'exec zsh',
|
|
145
|
+
bash: 'exec bash',
|
|
146
|
+
fish: 'exec fish',
|
|
147
|
+
powershell: '. $PROFILE',
|
|
148
|
+
};
|
|
149
|
+
const reloadCmd = reloadCommands[shell] || `restart your ${shell} shell`;
|
|
150
|
+
console.log(`Restart your shell or run: ${reloadCmd}`);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
else {
|
|
155
|
+
console.error(`✗ ${result.message}`);
|
|
156
|
+
process.exitCode = 1;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
catch (error) {
|
|
160
|
+
spinner.stop();
|
|
161
|
+
console.error(`✗ Failed to install completion script: ${error instanceof Error ? error.message : String(error)}`);
|
|
162
|
+
process.exitCode = 1;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Uninstall completion script for a specific shell
|
|
167
|
+
*/
|
|
168
|
+
async uninstallForShell(shell, skipConfirmation) {
|
|
169
|
+
const installer = CompletionFactory.createInstaller(shell);
|
|
170
|
+
// Prompt for confirmation unless --yes flag is provided
|
|
171
|
+
if (!skipConfirmation) {
|
|
172
|
+
const { confirm } = await import('@inquirer/prompts');
|
|
173
|
+
// Get shell-specific config file path
|
|
174
|
+
const configPaths = {
|
|
175
|
+
zsh: '~/.zshrc',
|
|
176
|
+
bash: '~/.bashrc',
|
|
177
|
+
fish: 'Fish configuration', // Fish doesn't modify profile, just removes script file
|
|
178
|
+
powershell: '$PROFILE',
|
|
179
|
+
};
|
|
180
|
+
const configPath = configPaths[shell] || `${shell} configuration`;
|
|
181
|
+
const confirmed = await confirm({
|
|
182
|
+
message: `Remove OpenSpec configuration from ${configPath}?`,
|
|
183
|
+
default: false,
|
|
184
|
+
});
|
|
185
|
+
if (!confirmed) {
|
|
186
|
+
console.log('Uninstall cancelled.');
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
const spinner = ora(`Uninstalling ${shell} completion script...`).start();
|
|
191
|
+
try {
|
|
192
|
+
const result = await installer.uninstall();
|
|
193
|
+
spinner.stop();
|
|
194
|
+
if (result.success) {
|
|
195
|
+
console.log(`✓ ${result.message}`);
|
|
196
|
+
}
|
|
197
|
+
else {
|
|
198
|
+
console.error(`✗ ${result.message}`);
|
|
199
|
+
process.exitCode = 1;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
catch (error) {
|
|
203
|
+
spinner.stop();
|
|
204
|
+
console.error(`✗ Failed to uninstall completion script: ${error instanceof Error ? error.message : String(error)}`);
|
|
205
|
+
process.exitCode = 1;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Output machine-readable completion data for shell consumption
|
|
210
|
+
* Format: tab-separated "id\tdescription" per line
|
|
211
|
+
*
|
|
212
|
+
* @param options - Options specifying completion type
|
|
213
|
+
*/
|
|
214
|
+
async complete(options) {
|
|
215
|
+
const type = options.type.toLowerCase();
|
|
216
|
+
try {
|
|
217
|
+
switch (type) {
|
|
218
|
+
case 'changes': {
|
|
219
|
+
const changeIds = await this.completionProvider.getChangeIds();
|
|
220
|
+
for (const id of changeIds) {
|
|
221
|
+
console.log(`${id}\tactive change`);
|
|
222
|
+
}
|
|
223
|
+
break;
|
|
224
|
+
}
|
|
225
|
+
case 'specs': {
|
|
226
|
+
const specIds = await this.completionProvider.getSpecIds();
|
|
227
|
+
for (const id of specIds) {
|
|
228
|
+
console.log(`${id}\tspecification`);
|
|
229
|
+
}
|
|
230
|
+
break;
|
|
231
|
+
}
|
|
232
|
+
case 'archived-changes': {
|
|
233
|
+
const archivedIds = await getArchivedChangeIds();
|
|
234
|
+
for (const id of archivedIds) {
|
|
235
|
+
console.log(`${id}\tarchived change`);
|
|
236
|
+
}
|
|
237
|
+
break;
|
|
238
|
+
}
|
|
239
|
+
default:
|
|
240
|
+
// Invalid type - silently exit with no output for graceful shell completion failure
|
|
241
|
+
process.exitCode = 1;
|
|
242
|
+
break;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
catch {
|
|
246
|
+
// Silently fail for graceful shell completion experience
|
|
247
|
+
process.exitCode = 1;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Normalize shell parameter to lowercase
|
|
252
|
+
*/
|
|
253
|
+
normalizeShell(shell) {
|
|
254
|
+
return shell?.toLowerCase();
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
//# 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
|