Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/quiet-schemas-rollback.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@fission-ai/openspec": patch
---

Make `schema init --default` validate and stage config changes before installing a schema, and roll back both files if either install fails.
4 changes: 0 additions & 4 deletions docs-lab/Notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,6 @@ the agent to consume it. Running `openspec update` should refresh them.

Product issues found while verifying the schema system (all file refs current as of today):

- `schema init --default` writes a `defaultSchema:` key to openspec/config.yaml that nothing
reads (schema.ts:961-978; readProjectConfig parses only schema/context/rules/operations/
references/store). The flag should write `schema:` or be removed. The docs now say to set
`schema:` by hand.
- `schema init` next-steps output prints a command that doesn't exist in that form:
"Use with: openspec new --schema <name>" (schema.ts:999); real syntax is
`openspec new change <name> --schema <name>`.
Expand Down
4 changes: 3 additions & 1 deletion docs-lab/reference/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -1317,11 +1317,13 @@ With no `--description` and no `--artifacts` in an interactive terminal, init pr
|---|---|
| `--description <text>` | Schema description. Default: `Custom workflow schema for <name>`. |
| `--artifacts <list>` | Comma-separated artifact IDs from `proposal`, `specs`, `design`, `tasks`. Default: all four. |
| `--default` | Writes `defaultSchema` to `openspec/config.yaml`. Nothing reads that key. To make the schema the default, set `schema: <name>` there yourself. |
| `--default` | Writes `schema: <name>` to the existing `openspec/config.yaml` or `openspec/config.yml`. Creates `openspec/config.yaml` if neither exists. New changes use this schema. |
| `--no-default` | Skip the prompt about the default. |
| `--force` | Overwrite an existing schema with the same name. |
| `--json` | Print the result as JSON. |

Schema creation and the `--default` config update are one operation. If OpenSpec cannot validate or write the config, it leaves both the config and any existing schema unchanged.

**Output**

```
Expand Down
23 changes: 20 additions & 3 deletions openspec/specs/schema-init-command/spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,34 @@ The CLI SHALL offer to set the newly created schema as the project default.
#### Scenario: Set as default interactively
- **WHEN** user runs `openspec schema init my-workflow` in interactive mode
- **AND** user confirms setting as default
- **THEN** system updates `openspec/config.yaml` with `defaultSchema: my-workflow`
- **THEN** system updates an existing `openspec/config.yaml` or `openspec/config.yml` in place with `schema: my-workflow`
- **AND** removes the legacy `defaultSchema` key when updating an existing configuration
- **AND** creates `openspec/config.yaml` when neither configuration file exists

#### Scenario: Set as default via flag
- **WHEN** user runs `openspec schema init my-workflow --default`
- **THEN** system creates schema and updates `openspec/config.yaml` with `defaultSchema: my-workflow`
- **THEN** system creates the schema and updates an existing `openspec/config.yaml` or `openspec/config.yml` in place with `schema: my-workflow`
- **AND** removes the legacy `defaultSchema` key when updating an existing configuration
- **AND** creates `openspec/config.yaml` when neither configuration file exists
Comment thread
coderabbitai[bot] marked this conversation as resolved.

#### Scenario: Skip setting default
- **WHEN** user runs `openspec schema init my-workflow --no-default`
- **THEN** system creates schema without modifying `openspec/config.yaml`

#### Scenario: Invalid config prevents schema creation
- **GIVEN** `openspec/config.yaml` or `openspec/config.yml` is invalid YAML, is not a YAML object, is not a regular file, or is not writable
- **WHEN** user runs `openspec schema init my-workflow --default`
- **THEN** the command exits with a non-zero status
- **AND** does not create `openspec/schemas/my-workflow/`
- **AND** leaves the config byte-for-byte unchanged

#### Scenario: Config failure preserves a schema during forced replacement
- **GIVEN** `openspec/schemas/my-workflow/` already contains user-authored files
- **AND** the project config cannot be validated or atomically replaced
- **WHEN** user runs `openspec schema init my-workflow --force --default`
- **THEN** the command exits with a non-zero status
- **AND** restores the existing schema and config byte-for-byte

### Requirement: Schema init outputs JSON format
The CLI SHALL support `--json` flag for machine-readable output.

Expand Down Expand Up @@ -92,4 +110,3 @@ The CLI SHALL validate all requested artifact IDs before replacing an existing p
- **WHEN** the user runs `schema init` with `--force` and only valid artifact IDs
- **THEN** the command replaces the existing schema with the newly generated schema
- **AND** reports successful creation

Loading
Loading