codingbuddy-rules 4.2.0 → 4.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,259 @@
1
+ ---
2
+ name: code-explanation
3
+ description: Use when explaining complex code to new team members, conducting code reviews, onboarding, or understanding unfamiliar codebases. Provides structured analysis from high-level overview to implementation details.
4
+ ---
5
+
6
+ # Code Explanation
7
+
8
+ ## Overview
9
+
10
+ Understanding code is a prerequisite to improving it. Rushed explanations create misunderstanding that compounds over time.
11
+
12
+ **Core principle:** Explain at the right level of abstraction. Start high, drill down only when needed.
13
+
14
+ **Iron Law:**
15
+ ```
16
+ READ BEFORE EXPLAINING. UNDERSTAND BEFORE SIMPLIFYING.
17
+ ```
18
+
19
+ Never explain code you haven't fully read. Never simplify what you haven't fully understood.
20
+
21
+ ## When to Use
22
+
23
+ - Onboarding new team members to a codebase
24
+ - Code review: explaining design decisions
25
+ - Understanding legacy code before modifying it
26
+ - Explaining an AI agent's recommendations
27
+ - Documenting complex algorithms or patterns
28
+ - Understanding error stack traces
29
+
30
+ ## The Five Levels of Explanation
31
+
32
+ Choose the level based on your audience and purpose:
33
+
34
+ | Level | Audience | Goal | Depth |
35
+ |-------|----------|------|-------|
36
+ | **L1: Bird's Eye** | Non-technical stakeholders | What does this system do? | Architecture diagram |
37
+ | **L2: Module** | New developers | How is this organized? | Module/file structure |
38
+ | **L3: Function** | Developers onboarding | What does this code do? | Function by function |
39
+ | **L4: Line** | Debugging partners | Why is this written this way? | Line by line |
40
+ | **L5: Algorithm** | Algorithm review | How does this work mathematically? | Proof-level |
41
+
42
+ ## The Explanation Process
43
+
44
+ ### Phase 1: Read First
45
+
46
+ ```
47
+ 1. Read the entire file/function before explaining anything
48
+ 2. Identify the core purpose (what problem does this solve?)
49
+ 3. Note dependencies (what does this require?)
50
+ 4. Note side effects (what does this change?)
51
+ 5. Note error handling (what can go wrong?)
52
+ ```
53
+
54
+ ### Phase 2: Bird's Eye View (Always Start Here)
55
+
56
+ ```markdown
57
+ **What this is:** One sentence describing purpose
58
+ **What problem it solves:** The business/technical need
59
+ **How it fits:** Where it sits in the larger system
60
+ **Key dependencies:** What it relies on
61
+ **Key outputs:** What it produces or modifies
62
+ ```
63
+
64
+ **Example:**
65
+ ```markdown
66
+ **What this is:** RulesService — file system reader for AI coding rules
67
+ **What problem it solves:** Provides a unified interface for reading and searching
68
+ .ai-rules files regardless of directory structure
69
+ **How it fits:** Used by McpModule to serve rules via MCP protocol
70
+ **Key dependencies:** Node.js fs/promises, glob patterns
71
+ **Key outputs:** Array of Rule objects with name, content, and metadata
72
+ ```
73
+
74
+ ### Phase 3: Structure Walk-Through
75
+
76
+ Walk through the code structure before implementation details:
77
+
78
+ ```typescript
79
+ // Before explaining each function, show the structure:
80
+
81
+ class RulesService {
82
+ // 1. Constructor — sets up file paths
83
+ constructor() { ... }
84
+
85
+ // 2. getRules() — entry point, returns all rules
86
+ async getRules(): Promise<Rule[]> { ... }
87
+
88
+ // 3. searchRules() — filters rules by query
89
+ async searchRules(query: string): Promise<Rule[]> { ... }
90
+
91
+ // 4. Private: readRuleFile() — reads individual file
92
+ private async readRuleFile(path: string): Promise<Rule> { ... }
93
+ }
94
+ ```
95
+
96
+ ### Phase 4: Deep Dive (Only When Requested)
97
+
98
+ Explain non-obvious implementation choices:
99
+
100
+ ```typescript
101
+ // ❓ "Why is this using glob instead of fs.readdir?"
102
+ // ✅ "glob allows pattern matching across nested directories
103
+ // (.ai-rules/**/*.md) without manual recursion. readdir
104
+ // only lists one directory level."
105
+
106
+ const files = await glob('**/*.md', { cwd: this.rulesDir });
107
+ ```
108
+
109
+ ```typescript
110
+ // ❓ "Why is this async even though it looks synchronous?"
111
+ // ✅ "File I/O is always async in Node.js to avoid blocking
112
+ // the event loop. Even a small file read blocks for ~1-5ms
113
+ // which multiplies badly under load."
114
+
115
+ const content = await fs.readFile(filePath, 'utf-8');
116
+ ```
117
+
118
+ ### Phase 5: Mental Model
119
+
120
+ Finish with a mental model the reader can hold in their head:
121
+
122
+ ```
123
+ RulesService mental model:
124
+ ─────────────────────────
125
+ .ai-rules/ ← Root directory
126
+ └── rules/core.md ← Each .md file becomes a Rule
127
+ └── agents/planner.json ← Each .json becomes an Agent
128
+
129
+ getRules() = "read all files, return as array"
130
+ searchRules() = "filter that array by content match"
131
+ getAgent() = "read specific JSON file, parse it"
132
+ ```
133
+
134
+ ## Explanation Templates
135
+
136
+ ### For Functions
137
+
138
+ ```markdown
139
+ ### `functionName(params): returnType`
140
+
141
+ **Purpose:** [One sentence — what does it do?]
142
+
143
+ **Parameters:**
144
+ - `param1` — [What it represents, valid range/values]
145
+ - `param2` — [What it represents, valid range/values]
146
+
147
+ **Returns:** [What is returned, in what shape]
148
+
149
+ **Side effects:** [What does it change outside itself?]
150
+
151
+ **Error cases:** [What errors can it throw and when?]
152
+
153
+ **Example:**
154
+ \`\`\`typescript
155
+ const result = functionName('input', { option: true });
156
+ // result === { expected: 'output' }
157
+ \`\`\`
158
+ ```
159
+
160
+ ### For Classes
161
+
162
+ ```markdown
163
+ ### `ClassName`
164
+
165
+ **Responsibility:** [Single responsibility in one sentence]
166
+
167
+ **Lifecycle:**
168
+ 1. Construction — [What happens when created]
169
+ 2. Usage — [How it's used]
170
+ 3. Cleanup — [Any teardown needed]
171
+
172
+ **Key methods:**
173
+ - `method1()` — [Purpose]
174
+ - `method2()` — [Purpose]
175
+
176
+ **Dependencies injected:**
177
+ - `Dependency1` — [Why it needs this]
178
+ ```
179
+
180
+ ### For Complex Algorithms
181
+
182
+ ```markdown
183
+ ### Algorithm: [Name]
184
+
185
+ **Problem:** [What problem does this solve?]
186
+
187
+ **Approach:** [High-level strategy]
188
+
189
+ **Complexity:** O([time]) time, O([space]) space
190
+
191
+ **Step-by-step walkthrough:**
192
+
193
+ Given input `[example input]`:
194
+ 1. Step 1 → intermediate result
195
+ 2. Step 2 → intermediate result
196
+ 3. Final step → `[expected output]`
197
+
198
+ **Edge cases handled:**
199
+ - Empty input: [behavior]
200
+ - Single element: [behavior]
201
+ - Duplicate values: [behavior]
202
+ ```
203
+
204
+ ## Onboarding Guide Format
205
+
206
+ When explaining a whole codebase to a new team member:
207
+
208
+ ```markdown
209
+ # [Project Name] Codebase Guide
210
+
211
+ ## In 30 Seconds
212
+
213
+ [What this system does, who uses it, why it exists]
214
+
215
+ ## Mental Model
216
+
217
+ [ASCII diagram of key components and data flow]
218
+
219
+ ## Start Here
220
+
221
+ 1. Read `src/main.ts` — entry point
222
+ 2. Read `src/app.module.ts` — understand module structure
223
+ 3. Read `src/mcp/mcp.service.ts` — core business logic
224
+
225
+ ## Key Concepts
226
+
227
+ **[Concept 1]:** [Explanation with code example]
228
+ **[Concept 2]:** [Explanation with code example]
229
+
230
+ ## Common Tasks
231
+
232
+ - "How do I add a new rule?" → See `packages/rules/.ai-rules/`
233
+ - "How do I add a new agent?" → See `packages/rules/.ai-rules/agents/`
234
+ - "How do I run tests?" → `yarn test`
235
+
236
+ ## What to Avoid
237
+
238
+ - [Common mistake 1 and why]
239
+ - [Common mistake 2 and why]
240
+ ```
241
+
242
+ ## Red Flags — STOP
243
+
244
+ | Thought | Reality |
245
+ |---------|---------|
246
+ | "I'll explain as I read" | Read first, explain second |
247
+ | "The code is self-explanatory" | It's never self-explanatory to someone new |
248
+ | "Just look at the tests" | Tests explain behavior, not intent |
249
+ | "I'll summarize without reading" | Summaries from unread code spread misinformation |
250
+
251
+ ## Quick Reference
252
+
253
+ | Situation | Explanation Level |
254
+ |-----------|------------------|
255
+ | New to project | L1 → L2 → L3 on request |
256
+ | Code review | L3 — function by function |
257
+ | Debugging together | L4 — line by line |
258
+ | Algorithm discussion | L5 — mathematical |
259
+ | Stakeholder demo | L1 only |
@@ -0,0 +1,244 @@
1
+ ---
2
+ name: context-management
3
+ description: Use when working on long tasks that span multiple sessions, when context compaction is a concern, or when decisions from PLAN mode need to persist through ACT and EVAL modes.
4
+ ---
5
+
6
+ # Context Management
7
+
8
+ ## Overview
9
+
10
+ AI assistant context windows are finite. Long tasks get compacted, earlier decisions are forgotten, and continuity breaks. Context management is the practice of preserving critical information so work survives compaction.
11
+
12
+ **Core principle:** If it matters after the current conversation, write it down. Memory is the enemy of continuity.
13
+
14
+ **Iron Law:**
15
+ ```
16
+ EXTERNAL STATE > INTERNAL MEMORY
17
+ Write decisions to files. Files survive compaction; conversation memory does not.
18
+ ```
19
+
20
+ ## When to Use
21
+
22
+ - Starting a task that will span multiple sessions
23
+ - Beginning PLAN mode (decisions must survive to ACT)
24
+ - Completing ACT mode (progress must survive to EVAL)
25
+ - When conversation is approaching context limits
26
+ - Before any context compaction event
27
+ - When resuming work after a break
28
+
29
+ ## The Context Document (codingbuddy)
30
+
31
+ The primary context persistence mechanism is `docs/codingbuddy/context.md`.
32
+
33
+ ```
34
+ docs/codingbuddy/context.md
35
+ ─────────────────────────────
36
+ This file is:
37
+ - Created/reset by PLAN mode
38
+ - Appended by ACT mode
39
+ - Appended by EVAL mode
40
+ - Always at a fixed, predictable path
41
+ - Safe to read at any point
42
+ ```
43
+
44
+ ### What Goes in Context
45
+
46
+ **PLAN mode writes:**
47
+ - Task description
48
+ - Key design decisions and their rationale
49
+ - Architecture choices
50
+ - Dependencies and constraints
51
+ - Recommended ACT agent
52
+
53
+ **ACT mode writes:**
54
+ - Progress milestones completed
55
+ - Files created/modified
56
+ - Implementation decisions made
57
+ - Issues encountered and resolved
58
+ - Next steps
59
+
60
+ **EVAL mode writes:**
61
+ - Quality findings (with severity)
62
+ - Security issues found
63
+ - Performance observations
64
+ - Recommendations for next iteration
65
+
66
+ ### Context Document Format
67
+
68
+ ```markdown
69
+ # Context: [Task Title]
70
+
71
+ ## PLAN — [timestamp]
72
+ **Task:** [Original task description]
73
+ **Primary Agent:** solution-architect
74
+ **Recommended ACT Agent:** agent-architect
75
+
76
+ ### Decisions
77
+ - Decision 1: [What was decided and why]
78
+ - Decision 2: [What was decided and why]
79
+
80
+ ### Notes
81
+ - Implementation note 1
82
+ - Constraint or dependency to remember
83
+
84
+ ---
85
+
86
+ ## ACT — [timestamp]
87
+ **Primary Agent:** agent-architect
88
+
89
+ ### Progress
90
+ - [x] Created RulesService with search capability
91
+ - [x] Added Tests: 12 passing
92
+ - [ ] SSE transport implementation pending
93
+
94
+ ### Notes
95
+ - Used glob for file discovery (faster than readdir recursion)
96
+ - NestJS module structure: McpModule → RulesModule
97
+
98
+ ---
99
+
100
+ ## EVAL — [timestamp]
101
+
102
+ ### Findings
103
+ - [HIGH] Missing rate limiting on /sse endpoint
104
+ - [MEDIUM] Test coverage at 72%, below 80% target
105
+
106
+ ### Recommendations
107
+ - Add rate limiting middleware
108
+ - Add tests for error cases in RulesService
109
+ ```
110
+
111
+ ## Context Strategy by Task Duration
112
+
113
+ ### Short Tasks (< 1 hour, single session)
114
+
115
+ No special context management needed. Conversation memory is sufficient.
116
+
117
+ ### Medium Tasks (1-4 hours, 1-2 sessions)
118
+
119
+ ```
120
+ 1. Write task summary to context.md at start
121
+ 2. Update progress at each major milestone
122
+ 3. Write completion summary before ending session
123
+ ```
124
+
125
+ ### Long Tasks (multi-day, multiple sessions)
126
+
127
+ ```
128
+ 1. Create context.md with full plan (PLAN mode)
129
+ 2. Create task breakdown in docs/codingbuddy/plan/
130
+ 3. Update context.md after each working session
131
+ 4. Begin each session by reading context.md
132
+ 5. Use git commits as progress markers
133
+ ```
134
+
135
+ ## Session Start Protocol
136
+
137
+ When resuming a task:
138
+
139
+ ```markdown
140
+ ## Session Resume Checklist
141
+
142
+ 1. Read context document:
143
+ - docs/codingbuddy/context.md
144
+
145
+ 2. Check git status:
146
+ - What was last committed?
147
+ - Any uncommitted changes?
148
+
149
+ 3. Check task list:
150
+ - What was pending at last session?
151
+
152
+ 4. Verify environment:
153
+ - Tests still passing?
154
+ - Build still working?
155
+
156
+ 5. Update context with session start note
157
+ ```
158
+
159
+ ## Session End Protocol
160
+
161
+ Before ending a session:
162
+
163
+ ```markdown
164
+ ## Session End Checklist
165
+
166
+ 1. Commit all completed work with descriptive message
167
+
168
+ 2. Update context document:
169
+ - Mark completed items
170
+ - Note pending items
171
+ - Capture any decisions made
172
+
173
+ 3. Note exact stopping point:
174
+ - What file/function was being edited?
175
+ - What was the next intended step?
176
+
177
+ 4. If blocked: note the blocker clearly
178
+
179
+ 5. Push to remote if collaborating
180
+ ```
181
+
182
+ ## Information Priority
183
+
184
+ When deciding what to preserve, use this priority:
185
+
186
+ ```
187
+ MUST preserve:
188
+ - Architecture decisions (hard to reconstruct)
189
+ - Why (not what) was done — rationale survives code changes
190
+ - Open questions and blockers
191
+ - External dependencies and constraints
192
+
193
+ SHOULD preserve:
194
+ - Files created and their purpose
195
+ - Test coverage status
196
+ - Performance baseline numbers
197
+
198
+ CAN skip:
199
+ - Step-by-step implementation details (read the code)
200
+ - Obvious decisions (no need to record "used async/await")
201
+ - Information available in git history
202
+ ```
203
+
204
+ ## Context Anti-Patterns
205
+
206
+ | Anti-Pattern | Problem | Fix |
207
+ |-------------|---------|-----|
208
+ | Relying on conversation memory | Compaction erases it | Write to file |
209
+ | Writing everything verbatim | Context file becomes noise | Summarize decisions, not steps |
210
+ | Never reading context file | Repeating work already done | Read at session start |
211
+ | Single monolithic context file | Hard to navigate | Split by phase (PLAN/ACT/EVAL) |
212
+ | Context file not in git | Lost if repo changes machines | Always commit context docs |
213
+
214
+ ## notepad.md (OMC Alternative)
215
+
216
+ For sessions not using codingbuddy's parse_mode, use OMC's notepad:
217
+
218
+ ```
219
+ notepad_write_priority: Critical info always loaded at session start
220
+ notepad_write_working: Session-specific notes (auto-pruned after 7 days)
221
+ notepad_write_manual: Permanent notes that must survive
222
+ ```
223
+
224
+ **When to use notepad vs context.md:**
225
+ - `context.md` → For codingbuddy PLAN/ACT/EVAL workflow
226
+ - notepad → For ad-hoc sessions without formal workflow
227
+
228
+ ## Quick Reference
229
+
230
+ ```
231
+ Context File Locations:
232
+ ──────────────────────
233
+ docs/codingbuddy/context.md → Primary context (PLAN/ACT/EVAL)
234
+ docs/codingbuddy/plan/ → Detailed plan documents
235
+ ~/.claude/notepad.md → Global session notes (OMC)
236
+
237
+ Update Context via MCP:
238
+ ──────────────────────
239
+ update_context(mode, decisions[], notes[], progress[], status)
240
+
241
+ Read Context via MCP:
242
+ ──────────────────────
243
+ read_context(verbosity: minimal|standard|full)
244
+ ```