@fission-ai/openspec 0.1.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/README.md +119 -0
- package/bin/openspec.js +3 -0
- package/dist/cli/index.d.ts +2 -0
- package/dist/cli/index.js +240 -0
- package/dist/commands/change.d.ts +35 -0
- package/dist/commands/change.js +276 -0
- package/dist/commands/show.d.ts +14 -0
- package/dist/commands/show.js +131 -0
- package/dist/commands/spec.d.ts +15 -0
- package/dist/commands/spec.js +224 -0
- package/dist/commands/validate.d.ts +23 -0
- package/dist/commands/validate.js +275 -0
- package/dist/core/archive.d.ts +15 -0
- package/dist/core/archive.js +529 -0
- package/dist/core/config.d.ts +14 -0
- package/dist/core/config.js +12 -0
- package/dist/core/configurators/base.d.ts +7 -0
- package/dist/core/configurators/base.js +2 -0
- package/dist/core/configurators/claude.d.ts +8 -0
- package/dist/core/configurators/claude.js +15 -0
- package/dist/core/configurators/registry.d.ts +9 -0
- package/dist/core/configurators/registry.js +22 -0
- package/dist/core/converters/json-converter.d.ts +6 -0
- package/dist/core/converters/json-converter.js +48 -0
- package/dist/core/diff.d.ts +11 -0
- package/dist/core/diff.js +193 -0
- package/dist/core/index.d.ts +2 -0
- package/dist/core/index.js +2 -0
- package/dist/core/init.d.ts +10 -0
- package/dist/core/init.js +109 -0
- package/dist/core/list.d.ts +4 -0
- package/dist/core/list.js +89 -0
- package/dist/core/parsers/change-parser.d.ts +13 -0
- package/dist/core/parsers/change-parser.js +192 -0
- package/dist/core/parsers/markdown-parser.d.ts +21 -0
- package/dist/core/parsers/markdown-parser.js +183 -0
- package/dist/core/parsers/requirement-blocks.d.ts +31 -0
- package/dist/core/parsers/requirement-blocks.js +173 -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/templates/claude-template.d.ts +2 -0
- package/dist/core/templates/claude-template.js +96 -0
- package/dist/core/templates/index.d.ts +11 -0
- package/dist/core/templates/index.js +21 -0
- package/dist/core/templates/project-template.d.ts +8 -0
- package/dist/core/templates/project-template.js +32 -0
- package/dist/core/templates/readme-template.d.ts +2 -0
- package/dist/core/templates/readme-template.js +519 -0
- package/dist/core/update.d.ts +4 -0
- package/dist/core/update.js +47 -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 +32 -0
- package/dist/core/validation/validator.js +355 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/utils/file-system.d.ts +10 -0
- package/dist/utils/file-system.js +83 -0
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.js +2 -0
- package/dist/utils/interactive.d.ts +2 -0
- package/dist/utils/interactive.js +8 -0
- package/dist/utils/item-discovery.d.ts +3 -0
- package/dist/utils/item-discovery.js +49 -0
- package/dist/utils/match.d.ts +3 -0
- package/dist/utils/match.js +22 -0
- package/dist/utils/task-progress.d.ts +8 -0
- package/dist/utils/task-progress.js +36 -0
- package/package.json +68 -0
package/README.md
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
# OpenSpec
|
|
2
|
+
|
|
3
|
+
A specification-driven development system for maintaining living documentation alongside your code.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install -g openspec
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
# Initialize OpenSpec in your project
|
|
15
|
+
openspec init
|
|
16
|
+
|
|
17
|
+
# Update existing OpenSpec instructions (team-friendly)
|
|
18
|
+
openspec update
|
|
19
|
+
|
|
20
|
+
# List specs or changes
|
|
21
|
+
openspec spec list # specs (IDs by default; use --long for details)
|
|
22
|
+
openspec change list # changes (IDs by default; use --long for details)
|
|
23
|
+
|
|
24
|
+
# Show differences between specs and proposed changes
|
|
25
|
+
openspec diff [change-name]
|
|
26
|
+
|
|
27
|
+
# Archive completed changes
|
|
28
|
+
openspec archive [change-name]
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Commands
|
|
32
|
+
|
|
33
|
+
### `openspec init`
|
|
34
|
+
|
|
35
|
+
Initializes OpenSpec in your project by creating:
|
|
36
|
+
- `openspec/` directory structure
|
|
37
|
+
- `openspec/README.md` with OpenSpec instructions
|
|
38
|
+
- AI tool configuration files (based on your selection)
|
|
39
|
+
|
|
40
|
+
### `openspec update`
|
|
41
|
+
|
|
42
|
+
Updates OpenSpec instructions to the latest version. This command is **team-friendly** and only updates files that already exist:
|
|
43
|
+
|
|
44
|
+
- Always updates `openspec/README.md` with the latest OpenSpec instructions
|
|
45
|
+
- **Only updates existing AI tool configuration files** (e.g., CLAUDE.md, CURSOR.md)
|
|
46
|
+
- **Never creates new AI tool configuration files**
|
|
47
|
+
- Preserves content outside of OpenSpec markers in AI tool files
|
|
48
|
+
|
|
49
|
+
This allows team members to use different AI tools without conflicts. Each developer can maintain their preferred AI tool configuration file, and `openspec update` will respect their choice.
|
|
50
|
+
|
|
51
|
+
### `openspec spec`
|
|
52
|
+
|
|
53
|
+
Manage and view specifications.
|
|
54
|
+
|
|
55
|
+
Examples:
|
|
56
|
+
- `openspec spec show <spec-id>`
|
|
57
|
+
- Text mode: prints raw `spec.md` content
|
|
58
|
+
- JSON mode (`--json`): returns minimal, stable shape
|
|
59
|
+
- Filters are JSON-only: `--requirements`, `--no-scenarios`, `-r/--requirement <1-based>`
|
|
60
|
+
- `openspec spec list`
|
|
61
|
+
- Prints IDs only by default
|
|
62
|
+
- Use `--long` to include `title` and `[requirements N]`
|
|
63
|
+
- `openspec spec validate <spec-id>`
|
|
64
|
+
- Text: human-readable summary to stdout/stderr
|
|
65
|
+
- `--json` for structured report
|
|
66
|
+
|
|
67
|
+
### `openspec change`
|
|
68
|
+
|
|
69
|
+
Manage and view change proposals.
|
|
70
|
+
|
|
71
|
+
Examples:
|
|
72
|
+
- `openspec change show <change-id>`
|
|
73
|
+
- Text mode: prints raw `proposal.md` content
|
|
74
|
+
- JSON mode (`--json`): `{ id, title, deltaCount, deltas }`
|
|
75
|
+
- Filtering is JSON-only: `--deltas-only` (alias: `--requirements-only`, deprecated)
|
|
76
|
+
- `openspec change list`
|
|
77
|
+
- Prints IDs only by default
|
|
78
|
+
- Use `--long` to include `title` and counts `[deltas N] [tasks x/y]`
|
|
79
|
+
- `openspec change validate <change-id>`
|
|
80
|
+
- Text: human-readable result
|
|
81
|
+
- `--json` for structured report
|
|
82
|
+
|
|
83
|
+
### `openspec diff [change-name]`
|
|
84
|
+
|
|
85
|
+
Shows the differences between current specs and proposed changes:
|
|
86
|
+
- Displays a unified diff format
|
|
87
|
+
- Helps review what will change before implementation
|
|
88
|
+
- Useful for pull request reviews
|
|
89
|
+
|
|
90
|
+
### `openspec archive [change-name]`
|
|
91
|
+
|
|
92
|
+
Archives a completed change:
|
|
93
|
+
- Moves change from `openspec/changes/` to `openspec/changes/archive/`
|
|
94
|
+
- Adds a date prefix to the archived change
|
|
95
|
+
- Updates specs to reflect the new state
|
|
96
|
+
- Use `--skip-specs` to archive without updating specs (for abandoned changes)
|
|
97
|
+
|
|
98
|
+
## Team Collaboration
|
|
99
|
+
|
|
100
|
+
OpenSpec is designed for team collaboration:
|
|
101
|
+
|
|
102
|
+
1. **AI Tool Flexibility**: Each team member can use their preferred AI assistant (Claude, Cursor, etc.)
|
|
103
|
+
2. **Non-Invasive Updates**: The `update` command only modifies existing files, never forcing tools on team members
|
|
104
|
+
3. **Specification Sharing**: The `openspec/` directory contains shared specifications that all team members work from
|
|
105
|
+
4. **Change Tracking**: Proposed changes are visible to all team members for review before implementation
|
|
106
|
+
|
|
107
|
+
## Contributing
|
|
108
|
+
|
|
109
|
+
See `openspec/specs/` for the current system specifications and `openspec/changes/` for pending improvements.
|
|
110
|
+
|
|
111
|
+
## Notes
|
|
112
|
+
|
|
113
|
+
- The legacy `openspec list` command is deprecated. Use `openspec spec list` and `openspec change list`.
|
|
114
|
+
- Text output is raw-first (no formatting or filtering). Prefer `--json` for tooling-friendly output.
|
|
115
|
+
- Global `--no-color` disables ANSI colors and respects `NO_COLOR`.
|
|
116
|
+
|
|
117
|
+
## License
|
|
118
|
+
|
|
119
|
+
MIT
|
package/bin/openspec.js
ADDED
|
@@ -0,0 +1,240 @@
|
|
|
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 { InitCommand } from '../core/init.js';
|
|
7
|
+
import { UpdateCommand } from '../core/update.js';
|
|
8
|
+
import { DiffCommand } from '../core/diff.js';
|
|
9
|
+
import { ListCommand } from '../core/list.js';
|
|
10
|
+
import { ArchiveCommand } from '../core/archive.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
|
+
const program = new Command();
|
|
16
|
+
const require = createRequire(import.meta.url);
|
|
17
|
+
const { version } = require('../../package.json');
|
|
18
|
+
program
|
|
19
|
+
.name('openspec')
|
|
20
|
+
.description('AI-native system for spec-driven development')
|
|
21
|
+
.version(version);
|
|
22
|
+
// Global options
|
|
23
|
+
program.option('--no-color', 'Disable color output');
|
|
24
|
+
// Apply global flags before any command runs
|
|
25
|
+
program.hook('preAction', (thisCommand) => {
|
|
26
|
+
const opts = thisCommand.opts();
|
|
27
|
+
if (opts.noColor) {
|
|
28
|
+
process.env.NO_COLOR = '1';
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
program
|
|
32
|
+
.command('init [path]')
|
|
33
|
+
.description('Initialize OpenSpec in your project')
|
|
34
|
+
.action(async (targetPath = '.') => {
|
|
35
|
+
try {
|
|
36
|
+
// Validate that the path is a valid directory
|
|
37
|
+
const resolvedPath = path.resolve(targetPath);
|
|
38
|
+
try {
|
|
39
|
+
const stats = await fs.stat(resolvedPath);
|
|
40
|
+
if (!stats.isDirectory()) {
|
|
41
|
+
throw new Error(`Path "${targetPath}" is not a directory`);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
if (error.code === 'ENOENT') {
|
|
46
|
+
// Directory doesn't exist, but we can create it
|
|
47
|
+
console.log(`Directory "${targetPath}" doesn't exist, it will be created.`);
|
|
48
|
+
}
|
|
49
|
+
else if (error.message && error.message.includes('not a directory')) {
|
|
50
|
+
throw error;
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
throw new Error(`Cannot access path "${targetPath}": ${error.message}`);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
const initCommand = new InitCommand();
|
|
57
|
+
await initCommand.execute(targetPath);
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
console.log(); // Empty line for spacing
|
|
61
|
+
ora().fail(`Error: ${error.message}`);
|
|
62
|
+
process.exit(1);
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
program
|
|
66
|
+
.command('update [path]')
|
|
67
|
+
.description('Update OpenSpec instruction files')
|
|
68
|
+
.action(async (targetPath = '.') => {
|
|
69
|
+
try {
|
|
70
|
+
const resolvedPath = path.resolve(targetPath);
|
|
71
|
+
const updateCommand = new UpdateCommand();
|
|
72
|
+
await updateCommand.execute(resolvedPath);
|
|
73
|
+
}
|
|
74
|
+
catch (error) {
|
|
75
|
+
console.log(); // Empty line for spacing
|
|
76
|
+
ora().fail(`Error: ${error.message}`);
|
|
77
|
+
process.exit(1);
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
program
|
|
81
|
+
.command('diff [change-name]')
|
|
82
|
+
.description('Show differences between proposed spec changes and current specs (includes validation warnings)')
|
|
83
|
+
.action(async (changeName) => {
|
|
84
|
+
try {
|
|
85
|
+
const diffCommand = new DiffCommand();
|
|
86
|
+
await diffCommand.execute(changeName);
|
|
87
|
+
}
|
|
88
|
+
catch (error) {
|
|
89
|
+
console.log(); // Empty line for spacing
|
|
90
|
+
ora().fail(`Error: ${error.message}`);
|
|
91
|
+
process.exit(1);
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
program
|
|
95
|
+
.command('list')
|
|
96
|
+
.description('List items (changes by default). Use --specs to list specs.')
|
|
97
|
+
.option('--specs', 'List specs instead of changes')
|
|
98
|
+
.option('--changes', 'List changes explicitly (default)')
|
|
99
|
+
.action(async (options) => {
|
|
100
|
+
try {
|
|
101
|
+
const listCommand = new ListCommand();
|
|
102
|
+
const mode = options?.specs ? 'specs' : 'changes';
|
|
103
|
+
await listCommand.execute('.', mode);
|
|
104
|
+
}
|
|
105
|
+
catch (error) {
|
|
106
|
+
console.log(); // Empty line for spacing
|
|
107
|
+
ora().fail(`Error: ${error.message}`);
|
|
108
|
+
process.exit(1);
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
// Change command with subcommands
|
|
112
|
+
const changeCmd = program
|
|
113
|
+
.command('change')
|
|
114
|
+
.description('Manage OpenSpec change proposals');
|
|
115
|
+
// Deprecation notice for noun-based commands
|
|
116
|
+
changeCmd.hook('preAction', () => {
|
|
117
|
+
console.error('Warning: The "openspec change ..." commands are deprecated. Prefer verb-first commands (e.g., "openspec list", "openspec validate --changes").');
|
|
118
|
+
});
|
|
119
|
+
changeCmd
|
|
120
|
+
.command('show [change-name]')
|
|
121
|
+
.description('Show a change proposal in JSON or markdown format')
|
|
122
|
+
.option('--json', 'Output as JSON')
|
|
123
|
+
.option('--deltas-only', 'Show only deltas (JSON only)')
|
|
124
|
+
.option('--requirements-only', 'Alias for --deltas-only (deprecated)')
|
|
125
|
+
.option('--no-interactive', 'Disable interactive prompts')
|
|
126
|
+
.action(async (changeName, options) => {
|
|
127
|
+
try {
|
|
128
|
+
const changeCommand = new ChangeCommand();
|
|
129
|
+
await changeCommand.show(changeName, options);
|
|
130
|
+
}
|
|
131
|
+
catch (error) {
|
|
132
|
+
console.error(`Error: ${error.message}`);
|
|
133
|
+
process.exitCode = 1;
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
changeCmd
|
|
137
|
+
.command('list')
|
|
138
|
+
.description('List all active changes (DEPRECATED: use "openspec list" instead)')
|
|
139
|
+
.option('--json', 'Output as JSON')
|
|
140
|
+
.option('--long', 'Show id and title with counts')
|
|
141
|
+
.action(async (options) => {
|
|
142
|
+
try {
|
|
143
|
+
console.error('Warning: "openspec change list" is deprecated. Use "openspec list".');
|
|
144
|
+
const changeCommand = new ChangeCommand();
|
|
145
|
+
await changeCommand.list(options);
|
|
146
|
+
}
|
|
147
|
+
catch (error) {
|
|
148
|
+
console.error(`Error: ${error.message}`);
|
|
149
|
+
process.exitCode = 1;
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
changeCmd
|
|
153
|
+
.command('validate [change-name]')
|
|
154
|
+
.description('Validate a change proposal')
|
|
155
|
+
.option('--strict', 'Enable strict validation mode')
|
|
156
|
+
.option('--json', 'Output validation report as JSON')
|
|
157
|
+
.option('--no-interactive', 'Disable interactive prompts')
|
|
158
|
+
.action(async (changeName, options) => {
|
|
159
|
+
try {
|
|
160
|
+
const changeCommand = new ChangeCommand();
|
|
161
|
+
await changeCommand.validate(changeName, options);
|
|
162
|
+
if (typeof process.exitCode === 'number' && process.exitCode !== 0) {
|
|
163
|
+
process.exit(process.exitCode);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
catch (error) {
|
|
167
|
+
console.error(`Error: ${error.message}`);
|
|
168
|
+
process.exitCode = 1;
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
program
|
|
172
|
+
.command('archive [change-name]')
|
|
173
|
+
.description('Archive a completed change and update main specs')
|
|
174
|
+
.option('-y, --yes', 'Skip confirmation prompts')
|
|
175
|
+
.option('--skip-specs', 'Skip spec update operations (useful for infrastructure, tooling, or doc-only changes)')
|
|
176
|
+
.option('--no-validate', 'Skip validation (not recommended, requires confirmation)')
|
|
177
|
+
.action(async (changeName, options) => {
|
|
178
|
+
try {
|
|
179
|
+
const archiveCommand = new ArchiveCommand();
|
|
180
|
+
await archiveCommand.execute(changeName, options);
|
|
181
|
+
}
|
|
182
|
+
catch (error) {
|
|
183
|
+
console.log(); // Empty line for spacing
|
|
184
|
+
ora().fail(`Error: ${error.message}`);
|
|
185
|
+
process.exit(1);
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
registerSpecCommand(program);
|
|
189
|
+
// Top-level validate command
|
|
190
|
+
program
|
|
191
|
+
.command('validate [item-name]')
|
|
192
|
+
.description('Validate changes and specs')
|
|
193
|
+
.option('--all', 'Validate all changes and specs')
|
|
194
|
+
.option('--changes', 'Validate all changes')
|
|
195
|
+
.option('--specs', 'Validate all specs')
|
|
196
|
+
.option('--type <type>', 'Specify item type when ambiguous: change|spec')
|
|
197
|
+
.option('--strict', 'Enable strict validation mode')
|
|
198
|
+
.option('--json', 'Output validation results as JSON')
|
|
199
|
+
.option('--concurrency <n>', 'Max concurrent validations (defaults to env OPENSPEC_CONCURRENCY or 6)')
|
|
200
|
+
.option('--no-interactive', 'Disable interactive prompts')
|
|
201
|
+
.action(async (itemName, options) => {
|
|
202
|
+
try {
|
|
203
|
+
const validateCommand = new ValidateCommand();
|
|
204
|
+
await validateCommand.execute(itemName, options);
|
|
205
|
+
}
|
|
206
|
+
catch (error) {
|
|
207
|
+
console.log();
|
|
208
|
+
ora().fail(`Error: ${error.message}`);
|
|
209
|
+
process.exit(1);
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
// Top-level show command
|
|
213
|
+
program
|
|
214
|
+
.command('show [item-name]')
|
|
215
|
+
.description('Show a change or spec')
|
|
216
|
+
.option('--json', 'Output as JSON')
|
|
217
|
+
.option('--type <type>', 'Specify item type when ambiguous: change|spec')
|
|
218
|
+
.option('--no-interactive', 'Disable interactive prompts')
|
|
219
|
+
// change-only flags
|
|
220
|
+
.option('--deltas-only', 'Show only deltas (JSON only, change)')
|
|
221
|
+
.option('--requirements-only', 'Alias for --deltas-only (deprecated, change)')
|
|
222
|
+
// spec-only flags
|
|
223
|
+
.option('--requirements', 'JSON only: Show only requirements (exclude scenarios)')
|
|
224
|
+
.option('--no-scenarios', 'JSON only: Exclude scenario content')
|
|
225
|
+
.option('-r, --requirement <id>', 'JSON only: Show specific requirement by ID (1-based)')
|
|
226
|
+
// allow unknown options to pass-through to underlying command implementation
|
|
227
|
+
.allowUnknownOption(true)
|
|
228
|
+
.action(async (itemName, options) => {
|
|
229
|
+
try {
|
|
230
|
+
const showCommand = new ShowCommand();
|
|
231
|
+
await showCommand.execute(itemName, options ?? {});
|
|
232
|
+
}
|
|
233
|
+
catch (error) {
|
|
234
|
+
console.log();
|
|
235
|
+
ora().fail(`Error: ${error.message}`);
|
|
236
|
+
process.exit(1);
|
|
237
|
+
}
|
|
238
|
+
});
|
|
239
|
+
program.parse();
|
|
240
|
+
//# 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,276 @@
|
|
|
1
|
+
import { promises as fs } from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import { select } from '@inquirer/prompts';
|
|
4
|
+
import { JsonConverter } from '../core/converters/json-converter.js';
|
|
5
|
+
import { Validator } from '../core/validation/validator.js';
|
|
6
|
+
import { ChangeParser } from '../core/parsers/change-parser.js';
|
|
7
|
+
import { isInteractive } from '../utils/interactive.js';
|
|
8
|
+
import { getActiveChangeIds } from '../utils/item-discovery.js';
|
|
9
|
+
// Constants for better maintainability
|
|
10
|
+
const ARCHIVE_DIR = 'archive';
|
|
11
|
+
const TASK_PATTERN = /^[-*]\s+\[[\sx]\]/i;
|
|
12
|
+
const COMPLETED_TASK_PATTERN = /^[-*]\s+\[x\]/i;
|
|
13
|
+
export class ChangeCommand {
|
|
14
|
+
converter;
|
|
15
|
+
constructor() {
|
|
16
|
+
this.converter = new JsonConverter();
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Show a change proposal.
|
|
20
|
+
* - Text mode: raw markdown passthrough (no filters)
|
|
21
|
+
* - JSON mode: minimal object with deltas; --deltas-only returns same object with filtered deltas
|
|
22
|
+
* Note: --requirements-only is deprecated alias for --deltas-only
|
|
23
|
+
*/
|
|
24
|
+
async show(changeName, options) {
|
|
25
|
+
const changesPath = path.join(process.cwd(), 'openspec', 'changes');
|
|
26
|
+
if (!changeName) {
|
|
27
|
+
const canPrompt = isInteractive(options?.noInteractive);
|
|
28
|
+
const changes = await this.getActiveChanges(changesPath);
|
|
29
|
+
if (canPrompt && changes.length > 0) {
|
|
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);
|
|
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),
|
|
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);
|
|
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?.noInteractive);
|
|
176
|
+
const changes = await getActiveChangeIds();
|
|
177
|
+
if (canPrompt && changes.length > 0) {
|
|
178
|
+
const selected = await select({
|
|
179
|
+
message: 'Select a change to validate',
|
|
180
|
+
choices: changes.map(id => ({ name: id, value: id })),
|
|
181
|
+
});
|
|
182
|
+
changeName = selected;
|
|
183
|
+
}
|
|
184
|
+
else {
|
|
185
|
+
if (changes.length === 0) {
|
|
186
|
+
console.error('No change specified. No active changes found.');
|
|
187
|
+
}
|
|
188
|
+
else {
|
|
189
|
+
console.error(`No change specified. Available IDs: ${changes.join(', ')}`);
|
|
190
|
+
}
|
|
191
|
+
console.error('Hint: use "openspec change list" to view available changes.');
|
|
192
|
+
process.exitCode = 1;
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
const changeDir = path.join(changesPath, changeName);
|
|
197
|
+
try {
|
|
198
|
+
await fs.access(changeDir);
|
|
199
|
+
}
|
|
200
|
+
catch {
|
|
201
|
+
throw new Error(`Change "${changeName}" not found at ${changeDir}`);
|
|
202
|
+
}
|
|
203
|
+
const validator = new Validator(options?.strict || false);
|
|
204
|
+
const report = await validator.validateChangeDeltaSpecs(changeDir);
|
|
205
|
+
if (options?.json) {
|
|
206
|
+
console.log(JSON.stringify(report, null, 2));
|
|
207
|
+
}
|
|
208
|
+
else {
|
|
209
|
+
if (report.valid) {
|
|
210
|
+
console.log(`Change "${changeName}" is valid`);
|
|
211
|
+
}
|
|
212
|
+
else {
|
|
213
|
+
console.error(`Change "${changeName}" has issues`);
|
|
214
|
+
report.issues.forEach(issue => {
|
|
215
|
+
const label = issue.level === 'ERROR' ? 'ERROR' : 'WARNING';
|
|
216
|
+
const prefix = issue.level === 'ERROR' ? '✗' : '⚠';
|
|
217
|
+
console.error(`${prefix} [${label}] ${issue.path}: ${issue.message}`);
|
|
218
|
+
});
|
|
219
|
+
// Next steps footer to guide fixing issues
|
|
220
|
+
this.printNextSteps();
|
|
221
|
+
if (!options?.json) {
|
|
222
|
+
process.exitCode = 1;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
async getActiveChanges(changesPath) {
|
|
228
|
+
try {
|
|
229
|
+
const entries = await fs.readdir(changesPath, { withFileTypes: true });
|
|
230
|
+
const result = [];
|
|
231
|
+
for (const entry of entries) {
|
|
232
|
+
if (!entry.isDirectory() || entry.name.startsWith('.') || entry.name === ARCHIVE_DIR)
|
|
233
|
+
continue;
|
|
234
|
+
const proposalPath = path.join(changesPath, entry.name, 'proposal.md');
|
|
235
|
+
try {
|
|
236
|
+
await fs.access(proposalPath);
|
|
237
|
+
result.push(entry.name);
|
|
238
|
+
}
|
|
239
|
+
catch {
|
|
240
|
+
// skip directories without proposal.md
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
return result.sort();
|
|
244
|
+
}
|
|
245
|
+
catch {
|
|
246
|
+
return [];
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
extractTitle(content) {
|
|
250
|
+
const match = content.match(/^#\s+(?:Change:\s+)?(.+)$/m);
|
|
251
|
+
return match ? match[1].trim() : 'Untitled Change';
|
|
252
|
+
}
|
|
253
|
+
countTasks(content) {
|
|
254
|
+
const lines = content.split('\n');
|
|
255
|
+
let total = 0;
|
|
256
|
+
let completed = 0;
|
|
257
|
+
for (const line of lines) {
|
|
258
|
+
if (line.match(TASK_PATTERN)) {
|
|
259
|
+
total++;
|
|
260
|
+
if (line.match(COMPLETED_TASK_PATTERN)) {
|
|
261
|
+
completed++;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
return { total, completed };
|
|
266
|
+
}
|
|
267
|
+
printNextSteps() {
|
|
268
|
+
const bullets = [];
|
|
269
|
+
bullets.push('- Ensure change has deltas in specs/: use headers ## ADDED/MODIFIED/REMOVED/RENAMED Requirements');
|
|
270
|
+
bullets.push('- Each requirement MUST include at least one #### Scenario: block');
|
|
271
|
+
bullets.push('- Debug parsed deltas: openspec change show <id> --json --deltas-only');
|
|
272
|
+
console.error('Next steps:');
|
|
273
|
+
bullets.forEach(b => console.error(` ${b}`));
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
//# sourceMappingURL=change.js.map
|