Skip to content

Commit 3cdcdfc

Browse files
authored
feat(cli): add schema management commands (Fission-AI#525)
Add `openspec schema` command group with subcommands for managing workflow schemas: - `schema which [name]` - Show where a schema resolves from with shadow detection across project/user/package locations - `schema validate [name]` - Validate schema structure, templates, and dependency graph - `schema fork <source> [name]` - Copy an existing schema to project for customization - `schema init <name>` - Create a new project-local schema with interactive or CLI-driven configuration All commands support `--json` output for scripting. The init command supports interactive prompts for description and artifact selection. Implements the schema-management-cli change proposal.
1 parent 32fc19a commit 3cdcdfc

6 files changed

Lines changed: 1594 additions & 48 deletions

File tree

Lines changed: 47 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,67 @@
11
## 1. Setup and Command Structure
22

3-
- [ ] 1.1 Create `src/commands/schema.ts` with `registerSchemaCommand(program: Command)` function
4-
- [ ] 1.2 Register schema command in `src/cli/index.ts` (import and call `registerSchemaCommand`)
5-
- [ ] 1.3 Add schema command group with description: "Manage workflow schemas"
3+
- [x] 1.1 Create `src/commands/schema.ts` with `registerSchemaCommand(program: Command)` function
4+
- [x] 1.2 Register schema command in `src/cli/index.ts` (import and call `registerSchemaCommand`)
5+
- [x] 1.3 Add schema command group with description: "Manage workflow schemas"
66

77
## 2. Schema Which Command
88

9-
- [ ] 2.1 Add `schema which <name>` subcommand with `--json` and `--all` options
10-
- [ ] 2.2 Implement resolution lookup using `getSchemaDir()` with project root
11-
- [ ] 2.3 Implement shadow detection by checking all three locations (project, user, package)
12-
- [ ] 2.4 Add text output: show source, path, and shadowing info
13-
- [ ] 2.5 Add JSON output: `{ name, source, path, shadows: [] }`
14-
- [ ] 2.6 Add `--all` mode to list all schemas with their resolution sources
9+
- [x] 2.1 Add `schema which <name>` subcommand with `--json` and `--all` options
10+
- [x] 2.2 Implement resolution lookup using `getSchemaDir()` with project root
11+
- [x] 2.3 Implement shadow detection by checking all three locations (project, user, package)
12+
- [x] 2.4 Add text output: show source, path, and shadowing info
13+
- [x] 2.5 Add JSON output: `{ name, source, path, shadows: [] }`
14+
- [x] 2.6 Add `--all` mode to list all schemas with their resolution sources
1515

1616
## 3. Schema Validate Command
1717

18-
- [ ] 3.1 Add `schema validate [name]` subcommand with `--json` and `--verbose` options
19-
- [ ] 3.2 Implement single-schema validation using existing `parseSchema()` from `schema.ts`
20-
- [ ] 3.3 Add template existence check for each artifact's template file
21-
- [ ] 3.4 Add dependency graph cycle detection (reuse topological sort logic)
22-
- [ ] 3.5 Add validate-all mode when no name provided (scan `openspec/schemas/`)
23-
- [ ] 3.6 Add text output with pass/fail indicators and error messages
24-
- [ ] 3.7 Add JSON output matching existing `openspec validate` format: `{ valid, issues: [] }`
25-
- [ ] 3.8 Add verbose mode showing each validation step
18+
- [x] 3.1 Add `schema validate [name]` subcommand with `--json` and `--verbose` options
19+
- [x] 3.2 Implement single-schema validation using existing `parseSchema()` from `schema.ts`
20+
- [x] 3.3 Add template existence check for each artifact's template file
21+
- [x] 3.4 Add dependency graph cycle detection (reuse topological sort logic)
22+
- [x] 3.5 Add validate-all mode when no name provided (scan `openspec/schemas/`)
23+
- [x] 3.6 Add text output with pass/fail indicators and error messages
24+
- [x] 3.7 Add JSON output matching existing `openspec validate` format: `{ valid, issues: [] }`
25+
- [x] 3.8 Add verbose mode showing each validation step
2626

2727
## 4. Schema Fork Command
2828

29-
- [ ] 4.1 Add `schema fork <source> [name]` subcommand with `--json` and `--force` options
30-
- [ ] 4.2 Implement source resolution using `getSchemaDir()` with project root
31-
- [ ] 4.3 Implement default destination naming: `<source>-custom`
32-
- [ ] 4.4 Implement directory copy with recursive file copy
33-
- [ ] 4.5 Update `name` field in copied `schema.yaml`
34-
- [ ] 4.6 Add overwrite protection: check destination exists, require `--force` or confirmation
35-
- [ ] 4.7 Add text output with source/destination paths
36-
- [ ] 4.8 Add JSON output: `{ forked, source, destination, sourceLocation }`
29+
- [x] 4.1 Add `schema fork <source> [name]` subcommand with `--json` and `--force` options
30+
- [x] 4.2 Implement source resolution using `getSchemaDir()` with project root
31+
- [x] 4.3 Implement default destination naming: `<source>-custom`
32+
- [x] 4.4 Implement directory copy with recursive file copy
33+
- [x] 4.5 Update `name` field in copied `schema.yaml`
34+
- [x] 4.6 Add overwrite protection: check destination exists, require `--force` or confirmation
35+
- [x] 4.7 Add text output with source/destination paths
36+
- [x] 4.8 Add JSON output: `{ forked, source, destination, sourceLocation }`
3737

3838
## 5. Schema Init Command
3939

40-
- [ ] 5.1 Add `schema init <name>` subcommand with `--json`, `--description`, `--artifacts`, `--default`, `--no-default`, `--force` options
41-
- [ ] 5.2 Implement schema name validation (kebab-case, no spaces)
42-
- [ ] 5.3 Implement interactive prompts for description using `@inquirer/prompts`
43-
- [ ] 5.4 Implement interactive artifact selection with descriptions (multi-select)
44-
- [ ] 5.5 Create schema directory and `schema.yaml` with selected configuration
45-
- [ ] 5.6 Create default template files for selected artifacts
46-
- [ ] 5.7 Add `--default` flag to update `openspec/config.yaml` with new schema as default
47-
- [ ] 5.8 Add overwrite protection: check if schema exists, require `--force`
48-
- [ ] 5.9 Add text output with created path and next steps
49-
- [ ] 5.10 Add JSON output: `{ created, path, schema }`
50-
- [ ] 5.11 Add non-interactive mode with `--description` and `--artifacts` flags
40+
- [x] 5.1 Add `schema init <name>` subcommand with `--json`, `--description`, `--artifacts`, `--default`, `--no-default`, `--force` options
41+
- [x] 5.2 Implement schema name validation (kebab-case, no spaces)
42+
- [x] 5.3 Implement interactive prompts for description using `@inquirer/prompts`
43+
- [x] 5.4 Implement interactive artifact selection with descriptions (multi-select)
44+
- [x] 5.5 Create schema directory and `schema.yaml` with selected configuration
45+
- [x] 5.6 Create default template files for selected artifacts
46+
- [x] 5.7 Add `--default` flag to update `openspec/config.yaml` with new schema as default
47+
- [x] 5.8 Add overwrite protection: check if schema exists, require `--force`
48+
- [x] 5.9 Add text output with created path and next steps
49+
- [x] 5.10 Add JSON output: `{ created, path, schema }`
50+
- [x] 5.11 Add non-interactive mode with `--description` and `--artifacts` flags
5151

5252
## 6. Testing
5353

54-
- [ ] 6.1 Add unit tests for `schema which` command in `test/commands/schema.test.ts`
55-
- [ ] 6.2 Add unit tests for `schema validate` command
56-
- [ ] 6.3 Add unit tests for `schema fork` command
57-
- [ ] 6.4 Add unit tests for `schema init` command
58-
- [ ] 6.5 Test interactive mode mocking with `@inquirer/prompts`
59-
- [ ] 6.6 Test JSON output format for all commands
60-
- [ ] 6.7 Test error cases: invalid name, not found, already exists, cycle detection
54+
- [x] 6.1 Add unit tests for `schema which` command in `test/commands/schema.test.ts`
55+
- [x] 6.2 Add unit tests for `schema validate` command
56+
- [x] 6.3 Add unit tests for `schema fork` command
57+
- [x] 6.4 Add unit tests for `schema init` command
58+
- [x] 6.5 Test interactive mode mocking with `@inquirer/prompts`
59+
- [x] 6.6 Test JSON output format for all commands
60+
- [x] 6.7 Test error cases: invalid name, not found, already exists, cycle detection
6161

6262
## 7. Documentation and Polish
6363

64-
- [ ] 7.1 Add CLI help text for all schema subcommands
65-
- [ ] 7.2 Update shell completion to include schema commands
66-
- [ ] 7.3 Run linting and fix any issues (`npm run lint`)
67-
- [ ] 7.4 Run full test suite (`npm test`)
64+
- [x] 7.1 Add CLI help text for all schema subcommands
65+
- [x] 7.2 Update shell completion to include schema commands
66+
- [x] 7.3 Run linting and fix any issues (`npm run lint`)
67+
- [x] 7.4 Run full test suite (`npm test`)

src/cli/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { CompletionCommand } from '../commands/completion.js';
1616
import { FeedbackCommand } from '../commands/feedback.js';
1717
import { registerConfigCommand } from '../commands/config.js';
1818
import { registerArtifactWorkflowCommands } from '../commands/artifact-workflow.js';
19+
import { registerSchemaCommand } from '../commands/schema.js';
1920
import { maybeShowTelemetryNotice, trackCommand, shutdown } from '../telemetry/index.js';
2021

2122
const program = new Command();
@@ -243,6 +244,7 @@ program
243244

244245
registerSpecCommand(program);
245246
registerConfigCommand(program);
247+
registerSchemaCommand(program);
246248

247249
// Top-level validate command
248250
program

0 commit comments

Comments
 (0)