Skip to content

Commit 6023bdc

Browse files
committed
docs(rules): strengthen context, audit, and review guidance
- Add context engineering rule and handoff bundle template - Anchor audit report paths to GIT_REPO_ROOT and update self-review docs - Enforce Cloudflare naming/Zone terminology guidance - Require concrete performance rewrites during code review - Add Go DI guidance (manual wiring first; when fx/dig/wire is justified)
1 parent e832ae4 commit 6023bdc

9 files changed

Lines changed: 174 additions & 6 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Comprehensive, battle-tested Cursor IDE rules for professional software engineer
1313
### Core Standards
1414

1515
- **[100-core.mdc](rules/100-core.mdc)** - Core coding standards and review guidelines
16+
- **[015-context-engineering.mdc](rules/015-context-engineering.mdc)** - Context engineering (prompt packing, retrieval, compaction)
1617
- **[010-workflow.mdc](rules/010-workflow.mdc)** - Development workflow patterns
1718
- **[020-agent-audit.mdc](rules/020-agent-audit.mdc)** - Agent audit requirements
1819
- **[130-git.mdc](rules/130-git.mdc)** - Git conventions and commit standards

commands/self-review.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ Generate a structured review report:
160160

161161
**Generate Audit Report (per `060-agent-audit.mdc`):**
162162

163-
- Write report to `extras/agent_reports/agent_report_<repo>_<branch>_<yyyymmdd_HHMMSS>.md` (if `extras/` exists and is gitignored) or `/tmp/agent_report_<repo>_<branch>_<yyyymmdd_HHMMSS>.md`
163+
- Ensure `CURSOR_AGENT_CHAT_ID` and `GIT_REPO_ROOT` are set (generate/export if missing), then write report to `<GIT_REPO_ROOT>/extras/agent_reports/agent_report_<repo>_<branch>_<CURSOR_AGENT_CHAT_ID>.md` (if `<GIT_REPO_ROOT>/extras/` exists and is gitignored) or `/tmp/agent_report_<repo>_<branch>_<CURSOR_AGENT_CHAT_ID>.md`
164164
- Include:
165165
- Start/end timestamps (local and UTC)
166166
- Repo name, branch name, `HEAD` SHA

rules/010-workflow.mdc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,9 @@ Treat recurring mistakes as a signal to improve the system, not just the code:
250250

251251
**IMPORTANT**: Context files are **workspace-specific** and should be in the **extras/** directory in the project root, NOT in the rules directory. This allows each workspace to have its own context while sharing rules via symlinks.
252252

253+
> [!NOTE]
254+
> For prompt packing, retrieval, and “frequent intentional compaction” patterns, see `015-context-engineering.mdc`.
255+
253256
**Templates:** Copy/paste-ready templates live alongside these rules under `templates/` (e.g., `.cursor/rules/templates/` when installed). In this repo, that path is `rules/templates/`. Copy them into `extras/` when you start a new workspace.
254257

255258
For complex projects, maintain context files in the `extras/` directory:

rules/015-context-engineering.mdc

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
---
2+
title: Context Engineering for Coding Agents
3+
description: Prompt packing, retrieval, and compaction patterns for reliable agent work.
4+
alwaysApply: true
5+
priority: 15
6+
---
7+
8+
# Context Engineering for Coding Agents
9+
10+
This rule strengthens agent performance by making context **intentional**, **minimal**, and **reproducible**.
11+
12+
> [!NOTE]
13+
> This rule complements `010-workflow.mdc` (phases + context files) and `100-core.mdc` (anti-slop guardrails).
14+
15+
---
16+
17+
## Goals
18+
19+
- Keep the agent’s working context small and high-signal
20+
- Make work resumable across sessions without “reloading the world”
21+
- Prefer retrieval over memory: fetch exactly what you need, when you need it
22+
23+
---
24+
25+
## Mental Model: Three Layers of Context
26+
27+
- **Working context (volatile)**: what the model sees right now
28+
- **Repo context (retrievable)**: files, diffs, logs, docs that can be re-read on demand
29+
- **Durable context (portable)**: short summaries + decisions captured in `extras/` context files
30+
31+
> [!IMPORTANT]
32+
> If it’s important and will matter later, it must be captured in **durable context**.
33+
34+
---
35+
36+
## Prompt Packing (What to Carry vs. What to Fetch)
37+
38+
### Always carry (paste/recap)
39+
40+
- **Goal**: one sentence
41+
- **Non-goals**: 1–3 bullets
42+
- **Constraints**: security, tooling, performance, “don’t refactor”, etc.
43+
- **Current plan**: 3–7 steps max
44+
- **Current state**: what’s done / what’s blocked
45+
- **Critical artifacts**: exact file paths, key identifiers, and error messages (verbatim)
46+
47+
### Never carry (fetch instead)
48+
49+
- Entire files or long logs “just in case”
50+
- Repeated restatements of requirements
51+
- Unbounded command output without a reason
52+
53+
---
54+
55+
## Retrieval Strategy (Search → Read Narrow → Cite)
56+
57+
Use a tight loop:
58+
59+
1. **Search** for the smallest set of candidate files (prefer repo-local sources first)
60+
2. **Read** only the minimal sections needed to decide or implement
61+
3. **Cite** exact file paths / relevant snippets in your reasoning and updates
62+
63+
> [!TIP]
64+
> Prefer “retrieve just-in-time” over “load everything up-front”. It is faster and more accurate.
65+
66+
---
67+
68+
## Compaction Strategy (Frequent Intentional Compaction)
69+
70+
After any meaningful milestone (plan approved, a module completed, a bug fixed), compact:
71+
72+
- Update `extras/active-context.md` with:
73+
- **Current focus**
74+
- **Key decisions** (what and why)
75+
- **Blockers** (and next action)
76+
- **Context from previous sessions** (only what must persist)
77+
- Update `extras/progress.md` (if used) with “done/next”
78+
- Add a **Handoff Bundle** (copy/pasteable) for resuming work
79+
80+
### Handoff Bundle (copy/paste)
81+
82+
```text
83+
Goal:
84+
Non-goals:
85+
Constraints:
86+
Current state:
87+
Next 3 actions:
88+
Key files/paths:
89+
Key commands + outputs (verbatim, minimal):
90+
```
91+
92+
---
93+
94+
## Context Reset Triggers (Start Fresh on Purpose)
95+
96+
Prefer a fresh chat/session when:
97+
98+
- Plan is approved and you’re moving into implementation (see `010-workflow.mdc`)
99+
- The conversation has accumulated long tool output or multiple competing threads
100+
- You are switching to a new, independent task
101+
102+
When restarting, bring only:
103+
104+
- The approved plan (or the updated `extras/tasks.md`)
105+
- The Handoff Bundle
106+
- The minimal file/line references needed to continue
107+
108+
---
109+
110+
## Guardrails (Quality + Security)
111+
112+
- Follow `100-core.mdc` anti-slop rules: be minimal, anchored, specific
113+
- Never paste secrets into context; redact tokens/keys/passwords
114+
- Prefer deterministic artifacts: file paths, commands, exit codes, and diffs
115+

rules/020-agent-audit.mdc

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,25 @@ Examples (not exhaustive):
8787

8888
For every non-trivial task, write **one** report file at a deterministic path.
8989

90+
### Chat/session identifier (required)
91+
92+
Agents MUST ensure a stable identifier is available for the current chat/session:
93+
94+
- If `CURSOR_AGENT_CHAT_ID` is already set: reuse it
95+
- Otherwise, generate one and export it once for the session:
96+
- `export CURSOR_AGENT_CHAT_ID="$(uuidgen | tr '[:upper:]' '[:lower:]')"`
97+
98+
### Repo root identifier (required)
99+
100+
Agents MUST resolve the absolute repository root path:
101+
102+
- `export GIT_REPO_ROOT="$(git rev-parse --show-toplevel)"`
103+
90104
### Path rules
91-
- If the repo has an `extras/` folder **and** it is gitignored, write to:
92-
- `extras/agent_reports/agent_report_<repo>_<branch>_<yyyymmdd_HHMMSS>.md`
105+
- If `<GIT_REPO_ROOT>/extras/` exists **and** it is gitignored, write to:
106+
- `<GIT_REPO_ROOT>/extras/agent_reports/agent_report_<repo>_<branch>_<CURSOR_AGENT_CHAT_ID>.md`
93107
- Otherwise write to:
94-
- `/tmp/agent_report_<repo>_<branch>_<yyyymmdd_HHMMSS>.md`
108+
- `/tmp/agent_report_<repo>_<branch>_<CURSOR_AGENT_CHAT_ID>.md`
95109

96110
### Required contents
97111
The report MUST include:
@@ -117,13 +131,13 @@ For complex debugging sessions or demos, agents MAY create terminal recordings u
117131
- When user explicitly requests a recording
118132

119133
**Recording path:**
120-
- Save to: `extras/agent_reports/recordings/<repo>_<branch>_<yyyymmdd_HHMMSS>.cast`
134+
- Save to: `<GIT_REPO_ROOT>/extras/agent_reports/recordings/<repo>_<branch>_<CURSOR_AGENT_CHAT_ID>.cast`
121135
- Reference the recording path in the markdown audit report
122136

123137
**How to record:**
124138
```bash
125139
# Start recording
126-
asciinema rec -q extras/agent_reports/recordings/session.cast
140+
asciinema rec -q "<GIT_REPO_ROOT>/extras/agent_reports/recordings/session.cast"
127141

128142
# ... perform commands ...
129143

rules/100-core.mdc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,19 @@ When providing feedback, organize by impact:
122122

123123
1. **Identify main issues first** before diving into details.
124124
2. **Provide specific, actionable suggestions** with working code examples.
125+
3. **Look for inefficient logic** and propose a more efficient rewrite when it is safe and justified.
125126
3. **Explain the "why"** - what benefit does the change provide?
126127
4. **Suggest incremental refactoring** over big-bang rewrites.
127128
5. **Preserve existing code** - no placeholders like `// ... (existing code)` or incomplete sections.
128129

130+
> [!IMPORTANT]
131+
> **Performance rewrite requirement (when reviewing existing code):**
132+
>
133+
> If you find clearly inefficient logic (e.g., \(O(n^2)\) loops, N+1 queries, repeated expensive work, unnecessary allocations/parsing), you MUST:
134+
> - Provide a **concrete improved implementation** (minimal diff) that preserves behavior
135+
> - State the **expected impact** (time/space/calls) and a **measurement plan** (benchmark/metric)
136+
> - Prefer the **smallest safe change**; do not “optimize everything” without evidence
137+
129138
### Anti-slop guardrails (write less, say more)
130139

131140
**Default behavior:** Prefer the smallest change that solves the stated problem. If a change, paragraph, or abstraction doesn’t clearly earn its keep, don’t add it.

rules/210-go.mdc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,20 @@ import "github.com/lib/timeutils" // When time package works fine
384384
// - It's a well-maintained, stable library
385385
```
386386

387+
### Dependency Injection (DI) & Application Wiring
388+
389+
**Default (Go-idiomatic):** Prefer **manual wiring** at the composition root (`cmd/<app>/main.go`). Pass interfaces/structs explicitly via constructors.
390+
391+
Use a DI framework **only when** it clearly reduces risk/complexity, typically:
392+
- You have a **large dependency graph** changing frequently across teams
393+
- You need consistent **lifecycle orchestration** (start/stop ordering, cleanup) across modules
394+
- You run multiple servers/workers in one binary and need coordinated shutdown
395+
396+
If you adopt a DI framework (e.g., `uber/fx`/`dig`, or compile-time `google/wire`):
397+
- Keep framework usage **at the edges** (composition root); constructors remain plain Go
398+
- Avoid “service locator” patterns (hidden dependencies); make deps visible in constructors
399+
- Prefer the **smallest safe change** when refactoring wiring; don’t churn the graph without need
400+
387401
### Make the Zero Value Useful
388402

389403
**Proverb**: "Make the zero value useful"

rules/400-cloudflare.mdc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ files:
2020

2121
**Guiding Principles:**
2222

23+
- **Naming Consistency**: Never use `CloudFlare` anywhere (code/documentation). If any existing docs contain it, flag and fix to `Cloudflare`
24+
- **Terminology Consistency**: Do not use the word `Domain` for Cloudflare. Always use `Zone`. If any existing docs mention “Cloudflare Domain”, flag and fix to “Cloudflare Zone”
2325
- **Performance First**: Order conditions from fast to slow (IP/host/method → path/headers → body/regex)
2426
- **Security by Default**: Assume hostile intent; validate and sanitize all inputs
2527
- **Fail Securely**: Block by default, allow explicitly; log everything

rules/templates/active-context.md.template

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,13 @@ Not Started
2020

2121
## Context from Previous Sessions
2222
[Any important context that needs to be remembered]
23+
24+
## Handoff Bundle (copy/paste)
25+
26+
Goal:
27+
Non-goals:
28+
Constraints:
29+
Current state:
30+
Next 3 actions:
31+
Key files/paths:
32+
Key commands + outputs (verbatim, minimal):

0 commit comments

Comments
 (0)