Skip to content

Commit ee83353

Browse files
TabishBStrayDragon
authored andcommitted
feat(config): add project-level configuration via openspec/config.yaml (Fission-AI#499)
* feat(config): add project-level configuration via openspec/config.yaml Adds openspec/config.yaml support for project-level customization without forking schemas. Teams can now: - Set a default schema (used when --schema flag not provided) - Inject project context into all artifact instructions - Add per-artifact rules (e.g., proposal rules, specs rules) Key changes: - New `src/core/project-config.ts` with Zod schema and resilient parsing - New `src/core/config-prompts.ts` for interactive config creation - Updated schema resolution order: CLI → change metadata → config → default - Updated instruction generation to inject <context> and <rules> XML sections - Integrated config creation prompts into `artifact-experimental-setup` Schema resolution precedence: 1. --schema CLI flag (explicit override) 2. .openspec.yaml in change directory (change-specific) 3. openspec/config.yaml schema field (project default) 4. "spec-driven" (hardcoded fallback) * test(config): add e2e tests and performance benchmarks for project config - Add project config integration tests in artifact-workflow.test.ts: - Test new change uses schema from config - Test CLI schema overrides config schema - Test context and rules injection in instructions - Test backwards compatibility without config file - Test immediate reflection of config changes - Add performance benchmark tests in project-config.test.ts: - Typical config (1KB): <20ms target - Large config (50KB): <50ms target - Repeated reads consistency check - Missing config fast-path test - Add project configuration documentation in experimental-workflow.md: - Config fields reference (schema, context, rules) - Schema precedence explanation - Artifact IDs by schema - Troubleshooting guide - Mark all tasks complete in tasks.md * refactor(config): remove benchmark tests, document decision in source Remove performance benchmark tests from project-config.test.ts and document the results directly in the source code instead. Benchmarks showed config reads are fast enough (~0.5ms typical) that caching is unnecessary. * fix(config): resolve three issues in project config feature - Remove nested <template> tags: generateInstructions() no longer wraps template content since printInstructionsText() already handles XML structure - Fix schema message accuracy: newChangeCommand() now uses the resolved schema returned from createChange() instead of hardcoded fallback - Add TTY check: artifact-experimental-setup skips interactive prompts in non-TTY environments (CI, automation) to prevent hangs
1 parent 1f10736 commit ee83353

File tree

21 files changed

+4021
-22
lines changed

21 files changed

+4021
-22
lines changed

docs/experimental-workflow.md

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,98 @@ openspec artifact-experimental-setup
7878

7979
This creates skills in `.claude/skills/` that Claude Code auto-detects.
8080

81+
During setup, you'll be prompted to create a **project config** (`openspec/config.yaml`). This is optional but recommended.
82+
83+
## Project Configuration
84+
85+
Project config lets you set defaults and inject project-specific context into all artifacts.
86+
87+
### Creating Config
88+
89+
Config is created during `artifact-experimental-setup`, or manually:
90+
91+
```yaml
92+
# openspec/config.yaml
93+
schema: spec-driven
94+
95+
context: |
96+
Tech stack: TypeScript, React, Node.js
97+
API conventions: RESTful, JSON responses
98+
Testing: Vitest for unit tests, Playwright for e2e
99+
Style: ESLint with Prettier, strict TypeScript
100+
101+
rules:
102+
proposal:
103+
- Include rollback plan
104+
- Identify affected teams
105+
specs:
106+
- Use Given/When/Then format for scenarios
107+
design:
108+
- Include sequence diagrams for complex flows
109+
```
110+
111+
### Config Fields
112+
113+
| Field | Type | Description |
114+
|-------|------|-------------|
115+
| `schema` | string | Default schema for new changes (e.g., `spec-driven`, `tdd`) |
116+
| `context` | string | Project context injected into all artifact instructions |
117+
| `rules` | object | Per-artifact rules, keyed by artifact ID |
118+
119+
### How It Works
120+
121+
**Schema precedence** (highest to lowest):
122+
1. CLI flag (`--schema tdd`)
123+
2. Change metadata (`.openspec.yaml` in change directory)
124+
3. Project config (`openspec/config.yaml`)
125+
4. Default (`spec-driven`)
126+
127+
**Context injection:**
128+
- Context is prepended to every artifact's instructions
129+
- Wrapped in `<context>...</context>` tags
130+
- Helps AI understand your project's conventions
131+
132+
**Rules injection:**
133+
- Rules are only injected for matching artifacts
134+
- Wrapped in `<rules>...</rules>` tags
135+
- Appear after context, before the template
136+
137+
### Artifact IDs by Schema
138+
139+
**spec-driven** (default):
140+
- `proposal` — Change proposal
141+
- `specs` — Specifications
142+
- `design` — Technical design
143+
- `tasks` — Implementation tasks
144+
145+
**tdd**:
146+
- `spec` — Feature specification
147+
- `tests` — Test file
148+
- `implementation` — Implementation code
149+
- `docs` — Documentation
150+
151+
### Config Validation
152+
153+
- Unknown artifact IDs in `rules` generate warnings
154+
- Schema names are validated against available schemas
155+
- Context has a 50KB size limit
156+
- Invalid YAML is reported with line numbers
157+
158+
### Troubleshooting
159+
160+
**"Unknown artifact ID in rules: X"**
161+
- Check artifact IDs match your schema (see list above)
162+
- Run `openspec schemas --json` to see artifact IDs for each schema
163+
164+
**Config not being applied:**
165+
- Ensure file is at `openspec/config.yaml` (not `.yml`)
166+
- Check YAML syntax with a validator
167+
- Config changes take effect immediately (no restart needed)
168+
169+
**Context too large:**
170+
- Context is limited to 50KB
171+
- Summarize or link to external docs instead
172+
81173
## Commands
82174

83175
| Command | What it does |
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
schema: spec-driven
2+
created: "2025-01-13"

0 commit comments

Comments
 (0)