Skip to content

Commit 10fee30

Browse files
committed
Update openspec enforcement rules
1 parent 61a820c commit 10fee30

File tree

2 files changed

+100
-41
lines changed

2 files changed

+100
-41
lines changed

.cursor/rules/automatic-openspec-workflow.mdc

Lines changed: 99 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,31 @@ alwaysApply: true
55

66
# Automatic OpenSpec Workflow
77

8-
This rule ensures that all code changes in the specfact-cli codebase are properly tracked through OpenSpec change proposals, following the spec-driven development workflow.
8+
This rule ensures that all code changes in the specfact-cli codebase are properly tracked through OpenSpec change proposals, following the spec-driven development workflow. **No application code may be modified without a corresponding OpenSpec change (new or delta) unless the user explicitly opts out.**
9+
10+
## Critical: Before Any Code Modification
11+
12+
**Do not add, modify, or delete any application code** (in `src/`, `tools/`, tests, or significant docs) until all of the following are done:
13+
14+
1. **Read and apply `openspec/config.yaml`:**
15+
- Use the project context (tech stack, constraints, architecture, SDD+TDD discipline) for all artifact work.
16+
- Apply per-artifact rules (proposal, specs, design, tasks) when creating or updating any change artifact.
17+
18+
2. **Ensure an OpenSpec change exists for the intended modification:**
19+
- **New work:** Create a new change (e.g. via `/opsx:new`, `/opsx:ff`, or `/wf-create-change-from-plan`).
20+
- **Existing change:** Update the existing change (proposal, specs, design, tasks) or create a **delta change** that updates the existing spec (e.g. via openspec archive after implementation).
21+
- There must be no code change without a corresponding change proposal (new or delta) that describes it.
22+
23+
3. **Validate the change before implementing:**
24+
- Run `openspec validate <change-id> --strict`.
25+
- Optionally run `/wf-validate-change <change-id>` for breaking-change and dependency analysis.
26+
- Do not proceed to implementation until validation passes (or the user explicitly overrides).
27+
28+
**Exception:** Only when the user explicitly says "skip openspec", "direct implementation", "simple fix", "just fix it", or similar, may you implement without creating or updating an OpenSpec change.
929

1030
## When This Rule Applies
1131

12-
This rule automatically triggers when the user requests to:
32+
This rule applies to **every** request that would result in:
1333

1434
- **Add** new features, functions, classes, or capabilities
1535
- **Modify** existing code, functions, or behavior
@@ -19,46 +39,50 @@ This rule automatically triggers when the user requests to:
1939
- **Implement** new features or capabilities
2040
- **Enhance** existing functionality
2141
- **Remove** features or code (unless explicitly a simple deletion)
42+
- **Bug fixes** that restore intended behavior (including simple fixes)
43+
- **Tests for existing behavior** (adding tests to existing code)
44+
- **Typos, formatting, or comments** (cosmetic changes)
45+
- **Dependency updates** (breaking and non-breaking)
46+
- **Configuration changes** (including simple config updates)
47+
48+
For any such request, **before** writing or modifying any code, follow the steps below so that a change (new or delta) exists and is validated. If the work relates to an already-implemented change, create an OpenSpec delta change to update the existing spec (e.g. via openspec archive after implementation).
2249

2350
## What This Rule Does NOT Apply To
2451

25-
Skip OpenSpec workflow for:
52+
Skip OpenSpec workflow only when:
2653

27-
- **Bug fixes** that restore intended behavior (simple fixes)
28-
- **Typos, formatting, or comments** (cosmetic changes)
29-
- **Dependency updates** (non-breaking)
30-
- **Configuration changes** (simple config updates)
31-
- **Tests for existing behavior** (adding tests to existing code)
32-
- **User explicitly says "skip openspec"** or "direct implementation"
54+
- **User explicitly says** "skip openspec", "no openspec", "direct implementation", "implement directly", "simple fix", or "just fix it"
3355

3456
## Automatic Workflow Steps
3557

36-
### Step 1: Detect Change Request
58+
### Step 1: Detect Change Request (No Code Modification Yet)
3759

38-
When user requests a change, immediately:
60+
When user requests a change, **do not write or modify any application code yet**. Instead:
3961

4062
1. **Parse the request** to understand:
4163
- What is being changed (feature, function, module, etc.)
4264
- Scope of change (new feature, modification, refactor)
4365
- Affected files or modules (if mentioned)
4466

4567
2. **Determine if OpenSpec workflow is needed:**
46-
- If request matches "What This Rule Applies To" → proceed
68+
- If request matches "When This Rule Applies" → proceed with Steps 2–4 (create/update change, validate), then implement only after change is ready
4769
- If request matches "What This Rule Does NOT Apply To" → skip OpenSpec, implement directly
4870
- If unclear → ask user: "Should this be tracked as an OpenSpec change, or is this a simple fix?"
4971

72+
3. **Read `openspec/config.yaml`** before creating or updating any change artifact. Apply project context and per-artifact rules to all proposal, spec, design, and task content.
73+
5074
### Step 2: Search for Existing OpenSpec Changes
5175

5276
**Before creating a new change, always check for existing work:**
5377

54-
1. **Navigate to specfact-cli-internal workspace:**
55-
- Change directory to `/home/dom/git/nold-ai/specfact-cli-internal`
78+
1. **Navigate to specfact-cli workspace:**
79+
- Change directory to `specfact-cli` inside the project workspace
5680
- Verify `openspec/` directory exists
5781

5882
2. **List active changes:**
5983

6084
```bash
61-
cd /home/dom/git/nold-ai/specfact-cli-internal
85+
cd <project-workspace>/specfact-cli
6286
openspec list
6387
```
6488

@@ -78,6 +102,8 @@ When user requests a change, immediately:
78102

79103
### Step 3: Create or Update OpenSpec Change
80104

105+
**Required:** Use `openspec/config.yaml` (project context and per-artifact rules) for all artifact creation and updates. Do not create or update proposal, specs, design, or tasks without applying config.yaml rules.
106+
81107
**If creating a new change:**
82108

83109
1. **Gather requirements:**
@@ -96,16 +122,16 @@ When user requests a change, immediately:
96122
3. **Execute workflow command:**
97123

98124
**For ad-hoc changes (no plan document):**
99-
- Use: `/openspec-proposal` command directly
125+
- Use: `/opsx-explore` to research codebase for potential conflicts, dependencies, and clarify, then use `/opsx-new` (or `/opsx:ff`) to create the change proposal
100126
- Follow the command steps:
101-
- Review `openspec/config.yaml` (OPSX) or `openspec/project.md` (legacy) and existing specs
127+
- Review `openspec/config.yaml` and existing specs
102128
- Choose unique verb-led `change-id`
103129
- Scaffold `proposal.md`, `tasks.md`, optional `design.md`
104130
- Create spec deltas in `changes/<id>/specs/<capability>/spec.md`
105131
- Validate with `openspec validate <id> --strict`
106132

107133
**For changes from plan documents:**
108-
- Use: `/specfact-cli-internal/wf-create-change-from-plan <plan-path>`
134+
- Use: `/specfact-cli/wf-create-change-from-plan <plan-path>`
109135
- Follow the workflow steps:
110136
- Plan selection and discovery
111137
- Plan review and alignment check
@@ -125,38 +151,47 @@ When user requests a change, immediately:
125151
- Read `openspec/changes/<change-id>/proposal.md`
126152
- Read `openspec/changes/<change-id>/tasks.md`
127153
- Read `openspec/changes/<change-id>/specs/` (if exists)
154+
- Read `openspec/changes/<change-id>/design.md` (if exists)
155+
- Read `openspec/changes/<change-id>/CHANGE_VALIDATION.md` (if exists)
128156

129157
2. **Update change artifacts:**
130158
- Update `proposal.md` if scope changed
131-
- Add new tasks to `tasks.md` if needed
159+
- Add new tasks to `tasks.md` if needed and adhere to config.yaml rules
132160
- Update spec deltas if requirements changed
161+
- Update design.md if architectural decisions changed
133162

134163
3. **Validate updated change:**
135164

136165
```bash
137-
cd /home/dom/git/nold-ai/specfact-cli-internal
166+
cd <project-workspace>/specfact-cli
138167
openspec validate <change-id> --strict
139168
```
140169

170+
Then run `/specfact-cli/wf-validate-change <change-id>` to validate the updated change
171+
- If validation fails, fix issues in proposal.md, tasks.md, design.md (if exists), or spec deltas
172+
- Re-validate until passing
173+
- Continue until validation passes
174+
- If validation passes, update CHANGE_VALIDATION.md with validation result
175+
141176
4. **Inform user:**
142177
- "Updated existing OpenSpec change: `<change-id>`"
143178

144179
### Step 4: Verify and Apply Change
145180

146-
**After change is created or updated:**
181+
**After change is created or updated (still no code modification until user confirms):**
147182

148183
1. **Review the change:**
149184
- Display summary of the change proposal
150185
- Show key tasks and requirements
151186
- Confirm with user: "OpenSpec change ready. Proceed with implementation?"
152187

153188
2. **If user confirms or if workflow requires immediate application:**
154-
- Execute: `/specfact-cli-internal/wf-apply-change <change-id>`
189+
- Execute: `/opsx:apply <change-id>` (or `/specfact-cli/wf-apply-change <change-id>`)
155190
- Follow workflow steps:
156191
- Change selection
157192
- Read change artifacts
158193
- Execute openspec-apply workflow
159-
- Complete tasks sequentially
194+
- Complete tasks sequentially (TDD: tests first, then code)
160195
- Update task checklist
161196
- Completion and summary
162197

@@ -165,41 +200,62 @@ When user requests a change, immediately:
165200
- Suggest reviewing `proposal.md` and `tasks.md`
166201
- Wait for user confirmation before applying
167202

203+
### Step 5: After Implementation—Verify, Validate, and Sync Backlog
204+
205+
**After each code modification (at the end of implementation):**
206+
207+
1. **Verify:**
208+
- Run quality gates: `hatch run format`, `hatch run type-check`, `hatch run contract-test`, `hatch test` (or `hatch run smart-test`).
209+
- Ensure all tests pass and contracts are satisfied.
210+
211+
2. **Validate the change:**
212+
- Run `openspec validate <change-id> --strict`.
213+
- Optionally run `/wf-validate-change <change-id>` for breaking-change and dependency audit.
214+
- If validation fails, fix proposal/specs/design/tasks and re-validate before considering the change complete.
215+
216+
3. **Sync backlog (GitHub issues and Source Tracking):**
217+
- **If the change targets a public repo** (e.g. specfact-cli, platform-frontend):
218+
- **If no GitHub issue exists yet:** Create the issue per config.yaml (title `[Change] <Brief Description>`, labels `enhancement` and `change-proposal`, body from proposal). Update `proposal.md` Source Tracking section with issue number, URL, repository, and status.
219+
- **If an issue already exists:** Sync the issue with the change (e.g. update issue body/status from proposal, ensure Development link to branch/PR). Update `proposal.md` Source Tracking section with current status (e.g. "Last Synced Status: in-progress" or "done").
220+
- Ensure backlog and code stay in sync: proposal Source Tracking and the GitHub issue reflect the current state of the change.
221+
168222
## Implementation Pattern
169223

170224
**Example workflow:**
171225

172-
```
226+
```text
173227
User: "Add a new command to list all backlog items"
174228

175229
AI (automatically):
176-
1. Detects: "Add" → triggers OpenSpec workflow
177-
2. Searches: `openspec list` → no related changes found
178-
3. Creates: `/openspec-proposal` (for ad-hoc changes)
179-
- Asks for clarifications if needed
180-
- Creates change proposal
181-
- Validates change
182-
4. Verifies: Shows change summary
183-
5. Applies: `/specfact-cli-internal/wf-apply-change <change-id>`
184-
- Implements the change
230+
1. Reads openspec/config.yaml (project context and per-artifact rules). Does not modify code yet.
231+
2. Detects: "Add" → triggers OpenSpec workflow
232+
3. Searches: openspec list → no related changes found
233+
4. Creates: /opsx-explore then /opsx-new (or /opsx:ff) or /wf-create-change-from-plan
234+
- Applies config.yaml rules to all artifacts
235+
- Creates change proposal, spec deltas, tasks
236+
- Validates: openspec validate <id> --strict
237+
5. Verifies: Shows change summary; "Proceed with implementation?"
238+
6. Applies: /opsx:apply <change-id> (or /wf-apply-change <change-id>)
239+
- Implements the change (TDD: tests first, then code)
185240
- Updates tasks
186-
- Completes workflow
241+
7. After implementation: Verify (quality gates), validate (openspec validate), sync backlog
242+
- Create or update GitHub issue if public repo; update proposal Source Tracking
187243
```
188244

189245
## Error Handling
190246

191247
- **If `openspec` command not found:**
192-
- Inform user: "OpenSpec CLI not available. Proceeding with direct implementation."
193-
- Skip OpenSpec workflow, implement directly
248+
- Inform user: "OpenSpec CLI not available. No code modification will be made until an OpenSpec change exists (create one manually or install OpenSpec CLI)."
249+
- Do not modify application code unless the user explicitly confirms: "Proceed without OpenSpec" or similar.
194250

195-
- **If specfact-cli-internal workspace not accessible:**
196-
- Inform user: "Cannot access OpenSpec workspace. Proceeding with direct implementation."
197-
- Skip OpenSpec workflow, implement directly
251+
- **If specfact-cli workspace or openspec/ directory not accessible:**
252+
- Inform user: "Cannot access OpenSpec workspace. No code modification will be made until a change exists."
253+
- Do not modify application code unless the user explicitly confirms to proceed without OpenSpec.
198254

199255
- **If change validation fails:**
200-
- Fix validation errors
256+
- Fix validation errors in proposal, specs, design, or tasks
201257
- Re-validate until passing
202-
- Do not proceed with implementation until validation passes
258+
- Do not proceed with implementation until validation passes (or user explicitly overrides)
203259

204260
- **If user explicitly requests to skip:**
205261
- Respect user request: "Skipping OpenSpec workflow as requested."
@@ -227,6 +283,8 @@ This rule works alongside:
227283
## Notes
228284

229285
- This rule applies to the **specfact-cli** codebase specifically
286+
- **Mandatory before any code modification:** Read and apply `openspec/config.yaml` (project context and per-artifact rules). Ensure an OpenSpec change (new or delta) exists and is validated. No code change without a corresponding change proposal unless the user explicitly opts out.
287+
- **Mandatory after each implementation:** Verify (quality gates), validate (`openspec validate <id> --strict`), and sync backlog (create or update GitHub issue, update proposal Source Tracking) so backlog and code stay in sync.
230288
- For other repositories, this rule may not apply (check repository-specific rules)
231289
- **Important workspace distinction:**
232290
- **OpenSpec changes** are stored in `specfact-cli/openspec/changes/`

.cursorrules

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
- When starting a new chat session, capture the current timestamp from the client system using the `run_terminal_cmd` tool with `date "+%Y-%m-%d %H:%M:%S %z"` to ensure accurate timestamps are used in logs, commits, and other time-sensitive operations.
66
- When starting a new chat session, get familiar with the build and test guide (refer to `.cursor/rules/testing-and-build-guide.mdc`).
77
- When starting a new task, first check the project overview and current status in `README.md` and `AGENTS.md`.
8+
- **OpenSpec (before code)**: Before modifying application code, follow the OpenSpec workflow in `.cursor/rules/automatic-openspec-workflow.mdc`: read and apply `openspec/config.yaml`, ensure an OpenSpec change (new or delta) exists and is validated, then implement. Exception: only when the user explicitly says "skip openspec", "direct implementation", "simple fix", or similar.
89
- **Branch Protection**: This repository has branch protection enabled for `dev` and `main` branches. All changes must be made via Pull Requests:
910
- Create a feature branch: `git checkout -b feature/your-feature-name`
1011
- Create a bugfix branch: `git checkout -b bugfix/your-bugfix-name`

0 commit comments

Comments
 (0)