Skip to content

Commit 48b9b8a

Browse files
authored
Merge branch 'main' into feature/structured-extraction-b3
2 parents c5edfea + bc3a8a3 commit 48b9b8a

26 files changed

Lines changed: 1519 additions & 262 deletions
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
description: Enforce Alembic DB-revision guardrail before deploy/migration operations
3+
alwaysApply: true
4+
---
5+
6+
# Alembic Deploy Guardrail
7+
8+
- Before any production/staging deploy or migration operation, run the Alembic guardrail check:
9+
- `python scripts/check_alembic_revision_guardrail.py`
10+
- or `make alembic-guardrail`
11+
- If the guardrail reports unknown DB revision(s), stop immediately and do not run migrations until lineage is reconciled.
12+
- For Heroku deploys, keep `Procfile` `release:` wired to the guardrail so incompatible slugs fail before web/worker rollout.
13+
- After backup restore operations, re-run the guardrail before any `flask db upgrade`.
14+
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
description: End-to-end execution policy after plan approval
3+
alwaysApply: true
4+
---
5+
6+
# OpenCRE Autonomous Workflow
7+
8+
Policy: see `AGENTS.md`. Verification: see `verifiable-goals.mdc`.
9+
10+
- For big changes, wait for human plan approval (`multi-agent-workflow.mdc` Phase 1) before editing.
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.
13+
- Use `Makefile` targets when possible.
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.
18+
- In commits do not add "made with cursor" lines.
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: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
---
2+
description: Two-phase planning for big changes; builder must not be sole judge
3+
alwaysApply: true
4+
---
5+
6+
# Multi-Agent Workflow (Human Plan → Agent Execute)
7+
8+
For **big changes**, split work into two phases. Do not skip Phase 1.
9+
10+
## What counts as a big change
11+
12+
- New feature, new standard importer, or new user-facing capability
13+
- Expected to touch **3+ files** or **>500 lines** of diff
14+
- Refactor or migration with behavioral risk
15+
- Touches critical paths (auth, secrets, production data, payments)
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.**
23+
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`).
30+
31+
## Phase 2 — Agent execution
32+
33+
After approval:
34+
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.
39+
40+
## Builder ≠ Judge (required on substantive work)
41+
42+
| Role | Responsibility |
43+
|------|----------------|
44+
| **Builder** | Implements approved plan |
45+
| **Judge** | Independent review — edge cases, security, test gaps |
46+
47+
Invoke judge via subagent, parallel agent, or fresh context:
48+
49+
- "Use a subagent to review this change for edge cases and security issues."
50+
51+
Do not mark substantive work complete without independent review or documented reason to skip.
52+
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.
54+
55+
## Decision tree
56+
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: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
---
2+
description: Require Plan Mode and user approval before non-trivial implementation
3+
alwaysApply: true
4+
---
5+
6+
# Plan-First Workflow
7+
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.
9+
10+
## Skip planning only for
11+
12+
- Typos, renames, obvious single-line fixes
13+
- Tasks fully specified with no design choices
14+
15+
## MUST plan before implementing when ANY apply
16+
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
22+
23+
## Plan output MUST include
24+
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
33+
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: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
description: Require all-caps confirmation for destructive production DB operations and prefer pre-op backups
3+
alwaysApply: true
4+
---
5+
6+
# Production DB Operations Safety
7+
8+
- For production database operations, treat destructive actions (`DELETE`, `DROP`, `TRUNCATE`, irreversible `ALTER`) as high risk.
9+
- Prefer using `scripts/db/` operations instead of ad-hoc production DB commands whenever those scripts cover the use case.
10+
- Before proposing or executing destructive production DB actions, require explicit all-caps confirmation from the user.
11+
- Confirmation should be exact and unambiguous (for OpenCRE scripts: `I_UNDERSTAND_OPENCREORG_PROD_DB_DESTRUCTIVE_ACTION`).
12+
- Prefer capturing a fresh backup before destructive production DB actions; if a backup is skipped, clearly explain risk and ask for confirmation again.
13+
- If app/environment target is ambiguous, stop and ask to confirm target app first.
14+
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)