Skip to content

Commit bc3a8a3

Browse files
Expand Cursor agent rules and resolve workflow contradictions.
Add modular .cursor/rules for requirements gates, tickets, TDD, and verification; tighten plan-first and multi-agent flows; slim AGENTS.md to an index aligned with make lint/mypy/test checks. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 2ad736b commit bc3a8a3

9 files changed

Lines changed: 314 additions & 66 deletions
Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
---
2-
description: Autonomous execution defaults for OpenCRE
2+
description: End-to-end execution policy after plan approval
33
alwaysApply: true
44
---
55

66
# OpenCRE Autonomous Workflow
77

8-
Policy (CI/PR, git, validation order, critical paths): see `AGENTS.md`.
8+
Policy: see `AGENTS.md`. Verification: see `verifiable-goals.mdc`.
99

1010
- For big changes, wait for human plan approval (`multi-agent-workflow.mdc` Phase 1) before editing.
11-
- After plan approval, execute tasks end-to-end unless blocked by auth/secrets, destructive actions, or material plan deviations.
12-
- Prefer small, safe changes and avoid unrelated refactors.
11+
- After approval, execute end-to-end unless blocked by auth/secrets, destructive actions, or material plan deviations.
12+
- Prefer small, safe changes; avoid unrelated refactors.
1313
- Use `Makefile` targets when possible.
14-
- For substantive code changes, run `make lint`, `make mypy`, and `make test` before handoff (skip only when clearly irrelevant and explain why).
15-
- If any check reports failures introduced by your changes, fix them before handoff.
16-
- If commit verification depends on shell initialization, run verification commands in a zsh-compatible shell context so environment-dependent checks are not skipped.
17-
- Run long commands in the background and monitor until completion.
18-
- Do NOT commit or push unless explicitly asked (except when the user explicitly requests CI auto-fix / PR creation; see `AGENTS.md`).
14+
- **Always run lint, mypy, and tests after substantive changes; iterate until green.** Show evidence in handoff.
15+
- If commit verification depends on shell initialization, use a zsh-compatible shell context.
16+
- Run long commands in background; monitor until completion.
17+
- Do NOT commit or push unless explicitly asked.
1918
- In commits do not add "made with cursor" lines.
20-
- At handoff, report: changed files, checks run, and any residual risks.
19+
- On substantive changes, recommend or run judge/subagent review before handoff.

.cursor/rules/complete-ticket.mdc

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
---
2+
description: Requires complete tickets before coding - asks clarifying questions if requirements are missing
3+
globs: "**/*.{md,txt}"
4+
alwaysApply: false
5+
---
6+
7+
# Complete Ticket Requirement
8+
9+
When the user submits a ticket or task via a `.md` or `.txt` file (including `AGENTS.md`):
10+
11+
1. **Check** for: goal, success criteria, context, constraints — same rules as `requirements-gate.mdc`
12+
2. **If missing** → ask clarifying questions; offer the **Requirements template** in `requirements-gate.mdc`; do NOT code
13+
3. **If complete** → follow the decision tree in `multi-agent-workflow.mdc`:
14+
- Trivial (typo, rename, one-liner) → implement directly
15+
- Non-trivial → Plan Mode per `plan-first-workflow.mdc` or Phase 1 per `multi-agent-workflow.mdc` when both apply
16+
- Wait for approval before implementation when planning is required
17+
4. **Never assume** missing details — see `never-assume.mdc`
18+
19+
Verification after implementation: `verifiable-goals.mdc`. Tests for new behavior: `tdd-workflow.mdc`.
20+
21+
## Coding standards (not covered elsewhere)
22+
23+
- **Stack:** Python for backend/application code; TypeScript for new frontend code (`application/frontend/`).
24+
- **Error handling:** Handle expected failure paths explicitly; avoid silent failures; return or raise meaningful errors.
25+
- **Async (frontend):** Prefer `async`/`await` over raw Promise chains or callbacks in new TypeScript.
26+
- **Clean code:** Small functions, clear names, match surrounding module conventions; no drive-by refactors.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
---
2+
description: Keep agent context focused across tasks and stale threads
3+
alwaysApply: true
4+
---
5+
6+
# Context Management
7+
8+
## Do
9+
10+
- Use `/clear` between unrelated tasks or features.
11+
- Reference files with `@path` instead of pasting entire file contents.
12+
- Use `@Past Chats` to pull in prior work instead of copy-pasting old conversations.
13+
- Start fresh after **2 failed corrections** on the same issue: `/clear`, then write a better prompt that incorporates what you learned.
14+
15+
## Don't
16+
17+
- Let context accumulate across unrelated features in one long thread.
18+
- Describe files vaguely when an `@` reference exists.
19+
- Keep correcting the same mistake in a degrading context — reset instead.
20+
21+
## When context is stale
22+
23+
Signs you should `/clear` and re-prompt:
24+
25+
- Repeated fixes on the same bug without progress
26+
- Agent confuses requirements from an earlier, unrelated task
27+
- Plan has drifted significantly from what was approved
28+
29+
After clearing, restate: goal, approved plan (or link to `.cursor/plans/*.md`), relevant `@` files, and acceptance criteria.
Lines changed: 47 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,72 @@
11
---
2-
description: Human plans big changes first; agent executes after explicit approval
2+
description: Two-phase planning for big changes; builder must not be sole judge
33
alwaysApply: true
44
---
55

66
# Multi-Agent Workflow (Human Plan → Agent Execute)
77

88
For **big changes**, split work into two phases. Do not skip Phase 1.
99

10-
## What Counts as a Big Change
11-
12-
Treat the change as **big** when any of these apply:
10+
## What counts as a big change
1311

1412
- New feature, new standard importer, or new user-facing capability
1513
- Expected to touch **3+ files** or **>500 lines** of diff
1614
- Refactor or migration with behavioral risk
1715
- Touches critical paths (auth, secrets, production data, payments)
18-
- Requirements are incomplete or have meaningful product/design choices
16+
- Incomplete requirements or meaningful product/design choices
17+
18+
Small fixes: single-file bugfix, typo, test-only tweak, clear one-liner → `plan-first-workflow.mdc` only.
19+
20+
## Phase 1 — Human-led planning (no code)
21+
22+
**Stop before editing.**
1923

20-
Small fixes (single-file bugfix, typo, test-only tweak, clear one-liner scope) skip this rule; use `plan-first-workflow.mdc` only.
24+
1. Acknowledge this is a big change; planning comes first.
25+
2. Ask minimum questions: goal, data sources, pattern to mirror, acceptance criteria, out of scope.
26+
3. Draft a plan: steps, `@` file paths, similar code, test/validation plan, risks.
27+
4. Wait for explicit approval ("proceed", "approved", or confirmed edited plan).
28+
5. No commits, push, or implementation code in Phase 1. Read-only research is fine.
29+
Tests and production code begin in Phase 2 after approval (see `tdd-workflow.mdc`).
2130

22-
## Phase 1Human-Led Planning (Agent Facilitates, No Code)
31+
## Phase 2 — Agent execution
2332

24-
**Stop before editing.** Your job is to help the human produce and approve a plan.
33+
After approval:
2534

26-
1. **Acknowledge** this is a big change and that planning comes first.
27-
2. **Ask the human** the minimum questions needed to plan well. Prefer a short numbered list over a long questionnaire. Typical prompts:
28-
- What is the goal and definition of done?
29-
- What source format / data / URLs does FOOBAR (or the feature) use?
30-
- Which existing pattern should we mirror (e.g. a similar importer or route)?
31-
- Acceptance criteria and manual checks?
32-
- Out of scope / constraints?
33-
3. **Draft a plan** for the human to edit, including:
34-
- Goal and acceptance criteria
35-
- Steps in execution order
36-
- Files likely touched (with `@`-style paths where helpful)
37-
- Similar code to follow
38-
- Test and validation plan (`make lint`, `make mypy`, `make test`, import smoke if relevant)
39-
- Risks and open questions
40-
4. **Wait for explicit approval** before Phase 2. Approval looks like: "looks good", "proceed", "approved", or an edited plan the human confirms.
41-
5. **Do not** create commits, push, or write implementation code during Phase 1. Research and read-only exploration are fine.
35+
1. Execute per `autonomous-workflow.mdc`.
36+
2. Follow the approved plan; pause if material deviation is needed.
37+
3. Implement incrementally; verify as you go (`verifiable-goals.mdc`).
38+
4. Hand off with checklist including test evidence.
4239

43-
If the human already supplied a complete plan, reflect it back briefly and ask them to confirm before executing.
40+
## Builder ≠ Judge (required on substantive work)
4441

45-
## Phase 2 — Agent Execution (Autonomous)
42+
| Role | Responsibility |
43+
|------|----------------|
44+
| **Builder** | Implements approved plan |
45+
| **Judge** | Independent review — edge cases, security, test gaps |
4646

47-
After the human approves the plan:
47+
Invoke judge via subagent, parallel agent, or fresh context:
4848

49-
1. **Execute end-to-end** per `autonomous-workflow.mdc` and `AGENTS.md`.
50-
2. **Follow the approved plan**; if you discover a material deviation, pause and ask before continuing.
51-
3. **Implement in small increments** when possible; run validation as you go.
52-
4. **Evaluate** against acceptance criteria: run tests, note manual spot-checks for the human.
53-
5. **Hand off** with the standard checklist (changes, checks, CI status, risks).
49+
- "Use a subagent to review this change for edge cases and security issues."
5450

55-
## Optional Cursor Agent Window Roles
51+
Do not mark substantive work complete without independent review or documented reason to skip.
5652

57-
When using parallel agents, map roles to phases:
53+
**Re-review:** Required only when judge findings change behavior, tests, or security posture materially. Style-only nits fixed in-place do not require a second judge pass.
5854

59-
| Role | Phase | Responsibility |
60-
|------|-------|----------------|
61-
| Planner | 1 | Expand prompt into spec + acceptance criteria; human approves |
62-
| Builder | 2 | Implement approved plan |
63-
| Evaluator | 2 | Run tests/checks; compare results to acceptance criteria |
55+
## Decision tree
6456

65-
One agent can cover Builder + Evaluator; Phase 1 still requires human approval before Builder starts.
57+
```
58+
User request received
59+
60+
├─ Missing goal / criteria / context / constraints?
61+
│ └─ STOP → ask questions OR offer Requirements template (requirements-gate.mdc)
62+
63+
├─ Typo / rename / one-sentence fix?
64+
│ └─ Implement → quality checks → show evidence
65+
66+
├─ Multi-file / new feature / refactor / critical path?
67+
│ └─ Plan Mode → detailed plan → WAIT for approval → implement
68+
│ → quality checks → subagent review → handoff with evidence
69+
70+
└─ Otherwise
71+
└─ Brief plan → implement → quality checks → handoff with evidence
72+
```

.cursor/rules/never-assume.mdc

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
---
2+
description: Verify or ask — no guessing packages, APIs, patterns, or incomplete code
3+
alwaysApply: true
4+
---
5+
6+
# Never Assume
7+
8+
| Do NOT | Instead |
9+
|--------|---------|
10+
| Assume package names, API endpoints, DB schema, or file locations | Read the codebase; grep; ask |
11+
| Add new dependencies without explanation | State why, alternatives considered, and get approval |
12+
| Use mocks unless explicitly requested | Prefer integration-style tests matching `@application/tests/` patterns |
13+
| Replace code with placeholders, TODOs, or stubs | Ship complete, working code |
14+
| Write incomplete implementations | Finish the feature or stop and explain what's blocked |
15+
| Guess production/staging targets for DB ops | Confirm target app; follow `production-db-ops-safety.mdc` |
16+
| Commit or push unless asked | Wait for explicit user request |
17+
18+
## Scope and diff discipline
19+
20+
- Minimize scope — smallest correct diff; no drive-by refactors.
21+
- Match surrounding naming, types, imports, and documentation level.
22+
- Comments only for non-obvious business logic.
23+
- Do not add markdown/docs files the user did not ask for.
24+
- Do not use "made with cursor" or similar in commits.
25+
26+
## OpenCRE conventions
27+
28+
- Mirror patterns in existing code (importers, tests, web routes).
29+
- Use Makefile targets over ad-hoc commands when available.
30+
- Prefer `scripts/db/` for production DB operations over raw SQL.
Lines changed: 41 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,54 @@
11
---
2-
description: Plan with reasoning before substantive code changes
2+
description: Require Plan Mode and user approval before non-trivial implementation
33
alwaysApply: true
44
---
55

66
# Plan-First Workflow
77

8-
Apply before making non-trivial edits that are **not** big enough to trigger `multi-agent-workflow.mdc`.
8+
Apply before non-trivial edits. When criteria overlap with `multi-agent-workflow.mdc` (e.g. new feature, 3+ files), follow **multi-agent** Phase 1 — it is the stricter superset.
99

10-
If the change is big (new feature/importer, 3+ files, >500 lines, critical paths), use the human-plan → agent-execute flow there instead of planning and coding in one step.
10+
## Skip planning only for
1111

12-
## Before Editing
12+
- Typos, renames, obvious single-line fixes
13+
- Tasks fully specified with no design choices
1314

14-
- Provide a brief plan with reasoning: goal, steps, files likely touched, and validation approach.
15-
- Break the problem into smaller steps and think through each separately.
16-
- If intent is ambiguous, ask before implementing.
17-
- Check `docs/runbooks/` when the change touches deploy, DB, imports, or ops workflows.
15+
## MUST plan before implementing when ANY apply
1816

19-
## While Editing
17+
- New feature or new importer
18+
- Multi-file change (3+ files) or >500 lines expected
19+
- Refactor or migration with behavioral risk
20+
- Touches critical paths (auth, secrets, production data, payments, deploy)
21+
- Requirements have meaningful design choices
2022

21-
- Only modify code directly relevant to the request.
22-
- Never replace code with placeholders (e.g. `// ... rest of the processing ...`). Include complete, working code.
23-
- Prefer referencing existing patterns with file paths (e.g. "similar to `application/web/web_main.py` route handlers") over inventing new conventions.
24-
- When debugging, state observations first, then reasoning, then the proposed fix.
23+
## Plan output MUST include
2524

26-
## After Editing
25+
1. **Goal** — restated in one sentence
26+
2. **Files** — exact paths to create/modify/delete
27+
3. **Dependencies** — imports, DB migrations, external APIs, new packages
28+
4. **Steps** — ordered implementation sequence
29+
5. **Tests** — new/updated test files and what they assert
30+
6. **Edge cases** — failure modes, empty input, backwards compatibility
31+
7. **Verification** — exact commands (`make lint`, `make mypy`, `make test`, etc.)
32+
8. **Risks** — what could break and how to detect it
2733

28-
- Before handoff, briefly explain key design choices so a reviewer can ask "why this way?" without re-reading the whole diff.
29-
- Prefer small, reviewable diffs; validate incrementally when possible.
34+
## Approval gate
35+
36+
After presenting the plan, **wait for explicit user approval** ("proceed", "approved",
37+
or an edited plan confirmed by the user) before writing implementation code.
38+
39+
After approval, **tests may be written first** per `tdd-workflow.mdc` — failing tests are not "implementation code" for Phase 1 purposes.
40+
41+
Read-only research (grep, read files, explore codebase) is allowed during planning.
42+
43+
Save approved plans to `.cursor/plans/<feature>.md` when scope is substantial.
44+
45+
## Before editing (Agent Mode)
46+
47+
- Brief plan with reasoning: goal, steps, files touched, validation approach.
48+
- Break into smaller steps; check `scripts/db/` and `scripts/` for deploy/DB/import ops.
49+
50+
## While editing
51+
52+
- Only modify code relevant to the request.
53+
- Never use placeholders — include complete, working code.
54+
- **Reference patterns specifically:** e.g. mirror `@application/utils/external_project_parsers/parsers/pci_dss.py`, tests like `@application/tests/pci_dss_parser_test.py`.
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
---
2+
description: Stop and ask clarifying questions before coding when requirements are incomplete
3+
alwaysApply: true
4+
---
5+
6+
# Requirements Gate
7+
8+
If ANY of the following is missing or ambiguous, **STOP and ask clarifying questions**.
9+
Do NOT write, edit, or delete code until the gaps are filled.
10+
11+
| Required | What to ask |
12+
|----------|-------------|
13+
| **Clear goal** | What outcome does the user want? What problem are we solving? |
14+
| **Verifiable success criteria** | Which checks must pass? (tests, typecheck, linter, CI, manual steps) |
15+
| **Context references** | Which files, modules, or prior chats apply? Prefer `@path/to/file` refs when ambiguous. |
16+
| **Constraints** | Out of scope, performance, compatibility, no new deps, prod DB safety, etc. |
17+
18+
## Context references — when `@` refs are required
19+
20+
- **Satisfied without `@`** when the message names specific paths, modules, or patterns clearly (e.g. "add tests for `application/utils/gap_analysis.py`").
21+
- **Ask for `@` refs** when multiple files could apply, the pattern to mirror is unclear, or prior chat/issue context is needed.
22+
23+
## Skip the gate only when
24+
25+
The request is fully specified in one sentence with obvious success criteria and unambiguous context, e.g.
26+
"Fix typo in README line 42" or "Rename `foo` to `bar` in `application/utils/gap_analysis.py`."
27+
28+
## Requirements template (offer when info is missing)
29+
30+
```
31+
## Task
32+
<One-sentence goal>
33+
34+
## Success criteria (all must pass)
35+
- [ ] `make lint`
36+
- [ ] `make mypy`
37+
- [ ] `make test` (or targeted: `python -m unittest application/tests/<module>_test.py`)
38+
- [ ] `make frontend` / `yarn build` (if frontend touched)
39+
- [ ] CI green (`gh pr checks` or Actions UI)
40+
- [ ] Other: ___
41+
42+
## Context
43+
- Files: @path/to/relevant/file.py
44+
- Pattern to mirror: @path/to/similar/implementation.py
45+
- Prior work: @Past Chats / issue # / PR #
46+
47+
## Constraints
48+
- In scope: ___
49+
- Out of scope: ___
50+
- Dependencies: none / explain before adding
51+
- Mocks: allowed / not allowed
52+
- Production DB: N/A / read-only / destructive (requires explicit confirmation)
53+
```

.cursor/rules/tdd-workflow.mdc

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
---
2+
description: Test-first workflow for new behavior, importers, and API changes
3+
alwaysApply: true
4+
---
5+
6+
# TDD Workflow
7+
8+
Use for new behavior, bug fixes with clear reproduction, and importers/API changes where expected I/O is known.
9+
10+
Skip for: typos, pure refactors with existing test coverage, config-only changes.
11+
12+
## Timing relative to planning
13+
14+
- **After plan approval** (or immediately for trivial fixes that skip planning): write failing tests, then implementation.
15+
- Do not write production code before plan approval when planning is required.
16+
17+
## Loop
18+
19+
1. **Write tests first** from expected input/output or acceptance criteria.
20+
2. **Run tests and confirm they fail** for the right reason. Do not write implementation yet.
21+
3. **Commit tests** only when the user explicitly asks to commit mid-flow.
22+
4. **Implement** the minimum code to pass tests. Do not modify tests to make them pass unless requirements changed (say so explicitly).
23+
5. **Iterate** until `make test` (and lint/mypy) pass.
24+
6. **Commit implementation** when the user asks.
25+
26+
## OpenCRE conventions
27+
28+
- Follow patterns in `@application/tests/` (e.g. `@application/tests/pci_dss_parser_test.py` for importers).
29+
- Use test DB setup from existing parser/web tests; avoid unnecessary mocks when integration-style tests match the codebase.
30+
- Prefer one focused test class per behavior area.

0 commit comments

Comments
 (0)