Instruction file imported from finalFlick/market-prediction (
.cursor/rules/spec-sessions.mdc). Copyright stays with the author.
Spec sessions
This project follows a Kiro-style spec-driven development (SDD) workflow
for any non-trivial feature, refactor, or bug. A spec session is a
structured, three-phase exchange — Requirements → Design → Tasks —
that produces three durable artifacts under specs/<feature-name>/ before
implementation begins.
You — the AI agent — MUST recognize when a spec session is appropriate, enter it without being asked, and follow the protocol below.
When to enter a spec session (auto-detection)
Enter spec session mode when any of these are true:
- The user asks to build, design, implement, add, create, plan, or architect a feature, module, page, endpoint, pipeline, or system.
- The work will touch more than one file or one module in
data/,research/,strategies/,risk/,execution/,monitoring/,backend/,frontend/,backtests/, orai_evals/. - The user mentions "feature", "spec", "design", "requirements", "tasks.md", "RFC", "ADR", "architecture", "refactor", "migration", or "MVP".
- The user describes a multi-step user journey ("when X, the user should Y, then Z…").
- The user reports a bug whose fix is non-obvious or requires changes in more than one file → enter spec session in bugfix mode.
Do NOT enter a spec session for:
- Single-file edits (typo, comment, rename, doc tweak, lint fix).
- Trivial bug fixes (one obvious wrong line in one file).
- Read-only investigation, exploration, or Q&A.
- New trading-signal hypotheses — those follow the
SIGNALS.mdflow inresearch-workflow.mdc. A spec session is for structural features (a new module, API, dashboard page, ingestion source, risk check, broker adapter, etc.), not new signal ideas. - Light plans for small multi-file work — for plain-English task
decompositions that don't warrant a durable artifact, delegate to
the
plannersubagent (.cursor/agents/planner.md) instead. Spec sessions exist for work big enough to deserve persistedrequirements.md+design.md+tasks.mdfiles.
When in doubt, ask the user once:
"This sounds like a multi-step feature. Want me to run a spec session (requirements → design → tasks) before coding?"
If they decline, proceed normally. If they accept or are silent, enter spec mode.
The three-phase protocol
When you enter a spec session, follow these phases in order. Do not skip ahead. Do not start writing implementation code until Phase 3 is approved.
Phase 0 — Naming and setup
-
Pick a kebab-case feature name (e.g.
binance-orderbook-ingest,risk-kill-switch-api,frontend-equity-curve-page). -
If an
specs/<feature-name>/directory already exists, read its files first and resume from the latest unfinished phase. -
Otherwise, scaffold the directory by running:
node .cursor/scripts/spec-new.js <feature-name>This copies the templates from
.cursor/spec-templates/intospecs/<feature-name>/(requirements.md,design.md,tasks.md, plusbugfix.mdfor bug specs). -
Switch the IDE to plan mode (
SwitchModetoplan) for Phases 1 and 2 — these phases are read-only design work. -
Announce to the user: "Entering spec session for
<feature-name>. Phase 1: Requirements."
Phase 1 — Requirements
Goal: produce a complete specs/<feature-name>/requirements.md that
captures what must be built, in EARS notation, with full user-story
context.
- Read
.cursor/spec-templates/requirements-template.mdend-to-end. - Fill in the template based on the user's prompt and any context you can gather from the codebase. Ask the user clarifying questions if a requirement is ambiguous — but ask all questions in one batch, not one at a time.
- Use EARS syntax for every acceptance criterion:
WHEN <trigger> THE SYSTEM SHALL <response>(event-driven)IF <condition> THEN THE SYSTEM SHALL <behavior>(conditional)WHILE <state> THE SYSTEM SHALL <continuous behavior>(state)WHERE <context> THE SYSTEM SHALL <contextual behavior>THE SYSTEM SHALL <action>(ubiquitous)
- Number every requirement (
Requirement 1,Requirement 2, …) and number every acceptance criterion within it (1.1,1.2, …). These numbers will be referenced fromtasks.md. - Cover non-functional requirements: performance, security, reliability, observability, latency budgets, cost limits.
- Reference the project's existing rules —
architecture.mdc,coding-standards.mdc,security.mdc,research-workflow.mdc— and record any constraints they impose as explicit requirements. - Show the user the finished
requirements.mdand ask: "Approve requirements and proceed to design? (yes / edit)" - Iterate until the user approves. Do NOT start design until they say yes.
Phase 2 — Design
Goal: produce specs/<feature-name>/design.md that turns the approved
requirements into a concrete technical plan.
- Read
.cursor/spec-templates/design-template.mdend-to-end. - Fill in: overview, architecture (with mermaid diagrams when useful), components and interfaces, data models, API contracts, error handling, testing strategy, security considerations, performance budgets, deployment notes.
- Respect the project's hard rules from
architecture.mdc: one-way pipeline, non-bypassable risk engine, no look-ahead, configs over code, determinism. Call out where the design touches these. - List every external dependency, env var, and config key the feature will introduce.
- Cross-reference each component back to a requirement number (e.g. "satisfies Requirement 1.2, 3.1").
- Show the user the finished
design.mdand ask: "Approve design and proceed to tasks? (yes / edit)" - Iterate until approved.
Phase 3 — Tasks
Goal: produce specs/<feature-name>/tasks.md — an ordered, two-level
checkbox list of discrete, executable coding tasks that an AI agent
or developer can pick up one by one.
- Read
.cursor/spec-templates/tasks-template.mdend-to-end. - Decompose the design into at most two levels of nesting
(
1.,1.1, …). Each leaf task must:- Produce working, testable code.
- Be completable in 1–4 hours.
- List the files / functions to create or modify.
- End with a
_Requirements: <ids>_line citing the requirement numbers it fulfills.
- Order tasks so each builds on completed work. Use the
foundation-first sequencing from
.cursor/spec-templates/tasks-template.mdunless a different strategy is justified. - Include test tasks alongside implementation tasks, never as a final afterthought.
- After tasks.md is written, switch back to agent mode (via
SwitchMode) and ask: "Approve tasks and start implementation? You can also ask me to run them one at a time, or all at once."
Phase 4 — Implementation (optional, drives the loop)
When the user approves tasks, execute them one at a time unless they explicitly say "run all":
- Read the task description and its requirement references.
- Mark the task as in-progress (update the checkbox to
- [~]or add a status comment). - Implement only that task. Stay within scope.
- Run the relevant verification commands from
workflow.mdc(pytest -q,ruff check .,mypy --strict .). - On success, mark the task
- [x]. - On failure, leave it unchecked and report what blocked you.
Stop and ask the user before moving to the next task only if the
implementation revealed a gap in requirements.md or design.md that
needs amending.
Bugfix mode
If the user reports a non-trivial bug, enter spec session in bugfix mode:
- Run
node .cursor/scripts/spec-new.js <bug-name> --bugfix. - Use
bugfix.md(from.cursor/spec-templates/bugfix-template.md) instead ofrequirements.md. It captures: current behavior, expected behavior, reproduction steps, root-cause hypothesis, regression risks, behavior that must remain unchanged. - After
bugfix.mdis approved, write a shortdesign.mddescribing the chosen fix and its blast radius. - Then write
tasks.mdas in Phase 3, including a regression test task.
Hard rules
- Never start writing implementation code in a multi-file feature
before
tasks.mdhas been written and approved. - Never skip a phase because it "feels obvious" — Kiro-style SDD derives its value from making the obvious explicit and traceable.
- Never invent EARS-violating acceptance criteria. Every criterion must use one of the four EARS keywords.
- Always record requirement numbers in tasks (
_Requirements: 2.1, 3.4_). Traceability is non-negotiable. - Always save spec files inside
specs/<feature-name>/— never at the project root. - Always update the spec files when implementation reveals a gap; the spec is the source of truth, not the code.
- Never mark a task complete until its tests pass and its acceptance criteria are demonstrably met.
- Additive work vs a sibling spec. If implementation lands
additively while a related spec or epic is paused or
in flight, append a short Implementation addendum to that
spec's ticket, epic, or
tasks.mdinspecs/…describing the merge handoff (e.g. styleguide registration, import paths, fixture deltas). Do not change the paused spec's core scope; record only how the new work plugs in when the other feature merges.
Quick reference
| Phase | Artifact | Mode | Approval before next phase? |
|---|---|---|---|
| 0 | specs/<feature>/ directory |
agent | n/a |
| 1 | requirements.md (EARS) |
plan | yes |
| 2 | design.md |
plan | yes |
| 3 | tasks.md (2-level checklist) |
agent | yes |
| 4 | code + tests, task by task | agent | per-task |
When the user just says "build X" and X is non-trivial, your first response should look like:
Detected spec session candidate:
<feature-name>. Running Phase 0 setup, then Phase 1 (Requirements). Switching to plan mode.
Integration with existing rules and agents
This protocol layers on top of the project's other rules and agents:
workflow.mdc— the dev loop (pytest/ruff/mypy) applies inside Phase 4 task execution. Each leaf task you execute must end with the verification commands green.ai-workflow.mdc— the agent governance rule. Spec sessions satisfy its "plan before multi-file changes" requirement; you do not also need a separate plain-text plan when running a spec session.planneragent (.cursor/agents/planner.md) — use for short multi-file plans that don't justify a full spec. Spec sessions and theplannersubagent serve different scales of work.research-workflow.mdc+SIGNALS.md— owns new trading-signal hypotheses. Don't write a spec for "add EMA-cross signal" — that goes inSIGNALS.md. Do write a spec for "add a new feature pipeline that supports rolling cross-asset features".architecture.mdc/coding-standards.mdc/security.mdc— enumerate constraints that every spec must respect; cite them by filename indesign.md§ Key Design Decisions when the design brushes up against them.- Domain agents under
.cursor/agents/(research,signal,strategy,backtest,risk,evaluation,monitoring,reviewer) — when executing tasks in Phase 4, consider delegating the implementation of a single task to the matching domain subagent rather than doing it inline.