codingbuddy-rules 4.3.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,269 @@
1
+ ---
2
+ name: agent-design
3
+ description: Use when creating new specialist agent definitions for codingbuddy. Covers JSON schema design, expertise definition, system prompt authoring, and differentiation from existing agents.
4
+ ---
5
+
6
+ # Agent Design
7
+
8
+ ## Overview
9
+
10
+ Agents are specialist personas that AI assistants embody to provide focused, domain-specific guidance. A well-designed agent has a clear identity, distinct expertise, and precise activation triggers.
11
+
12
+ **Core principle:** Each agent does ONE thing exceptionally well. Overlap is a design flaw.
13
+
14
+ **Iron Law:**
15
+ ```
16
+ DEFINE THE AGENT'S "NO" BEFORE DEFINING ITS "YES"
17
+ What this agent explicitly does NOT handle is as important as what it does.
18
+ ```
19
+
20
+ ## When to Use
21
+
22
+ - Adding a new specialist domain to codingbuddy
23
+ - Improving an existing agent's focus and expertise
24
+ - Designing agent activation trigger patterns
25
+ - Reviewing agent differentiation before adding to the registry
26
+
27
+ ## Agent Schema Reference
28
+
29
+ Agents are defined in `packages/rules/.ai-rules/agents/<name>.json` (filename is kebab-case):
30
+
31
+ ```json
32
+ {
33
+ "name": "My Specialist",
34
+ "description": "One-sentence description of what this agent specializes in",
35
+ "role": {
36
+ "title": "Specialist Role Title",
37
+ "type": "specialist",
38
+ "expertise": [
39
+ "Domain Expertise Area 1",
40
+ "Domain Expertise Area 2",
41
+ "Domain Expertise Area 3"
42
+ ],
43
+ "responsibilities": [
44
+ "Key responsibility 1",
45
+ "Key responsibility 2"
46
+ ]
47
+ },
48
+ "context_files": [
49
+ ".ai-rules/rules/core.md",
50
+ ".ai-rules/rules/project.md"
51
+ ],
52
+ "modes": {
53
+ "planning": {
54
+ "activation": { "trigger": "When planning..." }
55
+ },
56
+ "evaluation": {
57
+ "activation": { "trigger": "When evaluating..." }
58
+ }
59
+ }
60
+ }
61
+ ```
62
+
63
+ ### Required Fields
64
+
65
+ | Field | Type | Rules |
66
+ |-------|------|-------|
67
+ | `name` | string | Display name, Title Case (e.g., "Migration Specialist") |
68
+ | `description` | string | 10+ chars, one sentence |
69
+ | `role` | object | Must include `title` at minimum |
70
+ | `role.title` | string | Official role title |
71
+ | `role.expertise` | string[] | 3-7 items, specific domains |
72
+ | `context_files` | string[] | Paths starting with `.ai-rules/` |
73
+
74
+ > **Note:** The JSON filename uses kebab-case (e.g., `migration-specialist.json`), while `name` is Title Case.
75
+
76
+ ### Optional Fields
77
+
78
+ | Field | Type | Description |
79
+ |-------|------|-------------|
80
+ | `role.type` | string | `primary` (main agent in a mode) / `specialist` (domain reviews) |
81
+ | `role.responsibilities` | string[] | Key responsibilities |
82
+ | `modes.planning` | object | Planning mode activation config |
83
+ | `modes.implementation` | object | Implementation mode activation config |
84
+ | `modes.evaluation` | object | Evaluation mode activation config |
85
+ | `activation` | object | Activation triggers, workflow integration |
86
+ | `model` | object | Preferred AI model config (`preferred`, `reason`) |
87
+
88
+ ## Design Process
89
+
90
+ ### Phase 1: Define the Domain
91
+
92
+ Answer these questions before writing any JSON:
93
+
94
+ ```
95
+ 1. What SPECIFIC problem domain does this agent own?
96
+ Example: "Database schema migrations with zero downtime"
97
+ NOT: "Databases" (too broad)
98
+
99
+ 2. What does this agent explicitly NOT handle?
100
+ Example: "Does not handle query optimization (→ performance-specialist)"
101
+
102
+ 3. What 3 things is this agent the BEST at?
103
+ (These become expertise items)
104
+
105
+ 4. Who calls this agent? (Which modes, which tasks)
106
+
107
+ 5. Name 3 existing agents. Is there overlap? If yes, redesign.
108
+ ```
109
+
110
+ ### Phase 2: Differentiation Check
111
+
112
+ Before finalizing, compare against all existing agents:
113
+
114
+ ```bash
115
+ # List all existing agents
116
+ ls packages/rules/.ai-rules/agents/*.json | \
117
+ xargs -I{} jq -r '.name + ": " + .description' {}
118
+ ```
119
+
120
+ **Overlap detection:**
121
+ - If two agents share > 2 expertise items → merge or split differently
122
+ - If trigger keywords match another agent → tighten the triggers
123
+ - If the description could apply to another agent → rewrite
124
+
125
+ ### Phase 3: Write the System Prompt
126
+
127
+ The system prompt is the agent's constitution. It must:
128
+
129
+ ```markdown
130
+ # [DisplayName]
131
+
132
+ You are a [Role] specialist agent focused on [narrow domain].
133
+
134
+ ## Your Expertise
135
+
136
+ You excel at:
137
+ - [Specific skill 1]
138
+ - [Specific skill 2]
139
+ - [Specific skill 3]
140
+
141
+ ## Your Approach
142
+
143
+ When activated, you:
144
+ 1. [First thing you always do]
145
+ 2. [Second thing you always do]
146
+ 3. [How you structure your output]
147
+
148
+ ## What You DO NOT Handle
149
+
150
+ Redirect to appropriate specialists for:
151
+ - [Out-of-scope concern 1] → [other-agent]
152
+ - [Out-of-scope concern 2] → [other-agent]
153
+
154
+ ## Output Format
155
+
156
+ Always structure your responses as:
157
+ - [Output element 1]
158
+ - [Output element 2]
159
+ ```
160
+
161
+ ### Phase 4: Write the JSON
162
+
163
+ Save as `packages/rules/.ai-rules/agents/migration-specialist.json`:
164
+
165
+ ```json
166
+ {
167
+ "name": "Migration Specialist",
168
+ "description": "Zero-downtime database schema migration planning and execution specialist",
169
+ "role": {
170
+ "title": "Database Migration Engineer",
171
+ "type": "specialist",
172
+ "expertise": [
173
+ "Zero-Downtime Schema Changes",
174
+ "Expand-Contract Migration Pattern",
175
+ "Rollback Strategy Design",
176
+ "Large Data Migration Batching",
177
+ "Migration Validation Procedures"
178
+ ],
179
+ "responsibilities": [
180
+ "Plan and verify zero-downtime schema migrations",
181
+ "Design rollback strategies for all migration scenarios",
182
+ "Validate data integrity pre and post migration"
183
+ ]
184
+ },
185
+ "context_files": [
186
+ ".ai-rules/rules/core.md",
187
+ ".ai-rules/rules/project.md"
188
+ ],
189
+ "modes": {
190
+ "planning": {
191
+ "activation": {
192
+ "trigger": "When planning database schema migrations",
193
+ "auto_activate_conditions": ["Schema change planning", "Migration strategy design"]
194
+ }
195
+ },
196
+ "evaluation": {
197
+ "activation": {
198
+ "trigger": "When evaluating migration safety and rollback readiness"
199
+ }
200
+ }
201
+ }
202
+ }
203
+ ```
204
+
205
+ ### Phase 5: Validate
206
+
207
+ ```bash
208
+ # Validate JSON syntax
209
+ cat packages/rules/.ai-rules/agents/my-agent.json | jq .
210
+
211
+ # Check filename uniqueness (filenames are kebab-case)
212
+ ls packages/rules/.ai-rules/agents/ | grep "my-agent"
213
+
214
+ # Validate against schema (required: name, description, role, context_files)
215
+ npx ajv validate \
216
+ -s packages/rules/.ai-rules/schemas/agent.schema.json \
217
+ -d packages/rules/.ai-rules/agents/my-agent.json
218
+ ```
219
+
220
+ ## Naming Conventions
221
+
222
+ | Pattern | Example | Use for |
223
+ |---------|---------|---------|
224
+ | `<domain>-specialist` | `security-specialist` | Narrow domain expert |
225
+ | `<role>-engineer` | `devops-engineer` | Engineering role |
226
+ | `<role>-developer` | `frontend-developer` | Developer persona |
227
+ | `<role>-architect` | `solution-architect` | Architecture role |
228
+ | `<domain>-mode` | `plan-mode` | Workflow mode agent |
229
+
230
+ ## Common Mistakes
231
+
232
+ | Mistake | Fix |
233
+ |---------|-----|
234
+ | Too broad ("backend developer") | Narrow to specific domain (e.g., "api-designer") |
235
+ | Expertise overlaps with existing agent | Merge or redefine scope |
236
+ | System prompt has no "you do NOT handle" | Every agent needs explicit boundaries |
237
+ | Expertise items are vague ("databases") | Make specific ("PostgreSQL Query Optimization") |
238
+ | No mode specified | Always define which PLAN/ACT/EVAL modes apply |
239
+ | Filename uses camelCase | Use kebab-case for filenames (e.g., `my-agent.json`) |
240
+
241
+ ## Quick Reference
242
+
243
+ ```
244
+ Agent Tier Definitions:
245
+ ─────────────────────────────
246
+ primary → Used as main agent in a mode (solution-architect, plan-mode)
247
+ specialist → Called in parallel for domain reviews (security-specialist)
248
+
249
+ Mode Usage:
250
+ ─────────────────────────────
251
+ PLAN → Design, architecture, planning agents
252
+ ACT → Implementation, development agents
253
+ EVAL → Review, quality, security agents
254
+ ALL → Cross-cutting agents (code-reviewer)
255
+ ```
256
+
257
+ ## Checklist Before Adding Agent
258
+
259
+ ```
260
+ - [ ] Domain is specific, not broad
261
+ - [ ] No significant overlap with existing agents (< 2 shared expertise items)
262
+ - [ ] System prompt includes "what this agent does NOT handle"
263
+ - [ ] 3-7 expertise items, all specific
264
+ - [ ] JSON validates against agent.schema.json
265
+ - [ ] Filename follows kebab-case convention
266
+ - [ ] Modes reflect actual usage patterns
267
+ - [ ] README.md updated with new agent
268
+ - [ ] Added to relevant adapter configurations
269
+ ```
@@ -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 |