anvil-dev-framework 0.1.7 → 0.1.9

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.
Files changed (143) hide show
  1. package/README.md +71 -22
  2. package/VERSION +1 -1
  3. package/docs/ANV-263-hook-logging-investigation.md +116 -0
  4. package/docs/command-reference.md +398 -17
  5. package/docs/session-workflow.md +62 -9
  6. package/docs/system-architecture.md +584 -0
  7. package/global/api/__pycache__/ralph_api.cpython-314.pyc +0 -0
  8. package/global/api/openapi.yaml +357 -0
  9. package/global/api/ralph_api.py +528 -0
  10. package/global/commands/anvil-settings.md +47 -19
  11. package/global/commands/audit.md +163 -0
  12. package/global/commands/checklist.md +180 -0
  13. package/global/commands/coderabbit-fix.md +282 -0
  14. package/global/commands/efficiency.md +356 -0
  15. package/global/commands/evidence.md +117 -33
  16. package/global/commands/hud.md +24 -0
  17. package/global/commands/insights.md +101 -3
  18. package/global/commands/orient.md +22 -21
  19. package/global/commands/patterns.md +115 -0
  20. package/global/commands/ralph.md +47 -1
  21. package/global/commands/token-budget.md +214 -0
  22. package/global/commands/weekly-review.md +21 -1
  23. package/global/config/notifications.yaml.template +50 -0
  24. package/global/hooks/ralph_stop.sh +33 -1
  25. package/global/hooks/statusline.sh +67 -2
  26. package/global/lib/__pycache__/coderabbit_metrics.cpython-314.pyc +0 -0
  27. package/global/lib/__pycache__/command_tracker.cpython-314.pyc +0 -0
  28. package/global/lib/__pycache__/context_optimizer.cpython-314.pyc +0 -0
  29. package/global/lib/__pycache__/git_utils.cpython-314.pyc +0 -0
  30. package/global/lib/__pycache__/issue_models.cpython-314.pyc +0 -0
  31. package/global/lib/__pycache__/linear_provider.cpython-314.pyc +0 -0
  32. package/global/lib/__pycache__/optimization_applier.cpython-314.pyc +0 -0
  33. package/global/lib/__pycache__/ralph_state.cpython-314.pyc +0 -0
  34. package/global/lib/__pycache__/ralph_webhooks.cpython-314.pyc +0 -0
  35. package/global/lib/__pycache__/state_manager.cpython-314.pyc +0 -0
  36. package/global/lib/__pycache__/token_analyzer.cpython-314.pyc +0 -0
  37. package/global/lib/__pycache__/token_metrics.cpython-314.pyc +0 -0
  38. package/global/lib/coderabbit_metrics.py +647 -0
  39. package/global/lib/command_tracker.py +147 -0
  40. package/global/lib/context_optimizer.py +323 -0
  41. package/global/lib/linear_provider.py +210 -16
  42. package/global/lib/log_rotation.py +287 -0
  43. package/global/lib/optimization_applier.py +582 -0
  44. package/global/lib/ralph_events.py +398 -0
  45. package/global/lib/ralph_notifier.py +366 -0
  46. package/global/lib/ralph_state.py +264 -24
  47. package/global/lib/ralph_webhooks.py +470 -0
  48. package/global/lib/state_manager.py +121 -0
  49. package/global/lib/token_analyzer.py +1383 -0
  50. package/global/lib/token_metrics.py +919 -0
  51. package/global/tests/__pycache__/test_command_tracker.cpython-314-pytest-9.0.2.pyc +0 -0
  52. package/global/tests/__pycache__/test_context_optimizer.cpython-314-pytest-9.0.2.pyc +0 -0
  53. package/global/tests/__pycache__/test_doc_coverage.cpython-314-pytest-9.0.2.pyc +0 -0
  54. package/global/tests/__pycache__/test_git_utils.cpython-314-pytest-9.0.2.pyc +0 -0
  55. package/global/tests/__pycache__/test_issue_models.cpython-314-pytest-9.0.2.pyc +0 -0
  56. package/global/tests/__pycache__/test_linear_filtering.cpython-314-pytest-9.0.2.pyc +0 -0
  57. package/global/tests/__pycache__/test_linear_provider.cpython-314-pytest-9.0.2.pyc +0 -0
  58. package/global/tests/__pycache__/test_local_provider.cpython-314-pytest-9.0.2.pyc +0 -0
  59. package/global/tests/__pycache__/test_optimization_applier.cpython-314-pytest-9.0.2.pyc +0 -0
  60. package/global/tests/__pycache__/test_token_analyzer.cpython-314-pytest-9.0.2.pyc +0 -0
  61. package/global/tests/__pycache__/test_token_analyzer_phase6.cpython-314-pytest-9.0.2.pyc +0 -0
  62. package/global/tests/__pycache__/test_token_metrics.cpython-314-pytest-9.0.2.pyc +0 -0
  63. package/global/tests/test_command_tracker.py +172 -0
  64. package/global/tests/test_context_optimizer.py +321 -0
  65. package/global/tests/test_linear_filtering.py +319 -0
  66. package/global/tests/test_linear_provider.py +40 -1
  67. package/global/tests/test_optimization_applier.py +508 -0
  68. package/global/tests/test_token_analyzer.py +735 -0
  69. package/global/tests/test_token_analyzer_phase6.py +537 -0
  70. package/global/tests/test_token_metrics.py +829 -0
  71. package/global/tools/README.md +153 -0
  72. package/global/tools/__pycache__/anvil-hud.cpython-314.pyc +0 -0
  73. package/global/tools/__pycache__/orient_linear.cpython-314.pyc +0 -0
  74. package/global/tools/__pycache__/ralph-watchcpython-314.pyc +0 -0
  75. package/global/tools/anvil-hud.py +86 -1
  76. package/global/tools/anvil-memory/src/__tests__/ccs/context-monitor.test.ts +472 -0
  77. package/global/tools/anvil-memory/src/__tests__/ccs/fixtures.ts +405 -0
  78. package/global/tools/anvil-memory/src/__tests__/ccs/index.ts +36 -0
  79. package/global/tools/anvil-memory/src/__tests__/ccs/prompt-generator.test.ts +653 -0
  80. package/global/tools/anvil-memory/src/__tests__/ccs/ralph-stop.test.ts +727 -0
  81. package/global/tools/anvil-memory/src/__tests__/ccs/test-utils.ts +340 -0
  82. package/global/tools/anvil-memory/src/__tests__/commands.test.ts +218 -0
  83. package/global/tools/anvil-memory/src/commands/context.ts +322 -0
  84. package/global/tools/anvil-memory/src/db.ts +108 -0
  85. package/global/tools/anvil-memory/src/index.ts +2 -8
  86. package/global/tools/orient_linear.py +159 -0
  87. package/global/tools/ralph-watch +423 -0
  88. package/package.json +2 -1
  89. package/project/.anvil-project.yaml.template +93 -0
  90. package/project/CLAUDE.md.template +343 -0
  91. package/project/agents/README.md +119 -0
  92. package/project/agents/cross-layer-debugger.md +217 -0
  93. package/project/agents/security-code-reviewer.md +162 -0
  94. package/project/constitution.md.template +235 -0
  95. package/project/coordination.md +103 -0
  96. package/project/docs/background-tasks.md +258 -0
  97. package/project/docs/skills-frontmatter.md +243 -0
  98. package/project/examples/README.md +106 -0
  99. package/project/examples/api-route-template.ts +171 -0
  100. package/project/examples/component-template.tsx +110 -0
  101. package/project/examples/hook-template.ts +152 -0
  102. package/project/examples/service-template.ts +207 -0
  103. package/project/examples/test-template.test.tsx +249 -0
  104. package/project/hooks/README.md +491 -0
  105. package/project/hooks/__pycache__/notification.cpython-314.pyc +0 -0
  106. package/project/hooks/__pycache__/post_tool_use.cpython-314.pyc +0 -0
  107. package/project/hooks/__pycache__/pre_tool_use.cpython-314.pyc +0 -0
  108. package/project/hooks/__pycache__/session_start.cpython-314.pyc +0 -0
  109. package/project/hooks/__pycache__/stop.cpython-314.pyc +0 -0
  110. package/project/hooks/notification.py +183 -0
  111. package/project/hooks/permission_request.py +438 -0
  112. package/project/hooks/post_tool_use.py +397 -0
  113. package/project/hooks/pre_compact.py +126 -0
  114. package/project/hooks/pre_tool_use.py +454 -0
  115. package/project/hooks/session_start.py +656 -0
  116. package/project/hooks/stop.py +356 -0
  117. package/project/hooks/subagent_start.py +223 -0
  118. package/project/hooks/subagent_stop.py +215 -0
  119. package/project/hooks/user_prompt_submit.py +110 -0
  120. package/project/hooks/utils/llm/anth.py +114 -0
  121. package/project/hooks/utils/llm/oai.py +114 -0
  122. package/project/hooks/utils/tts/elevenlabs_tts.py +63 -0
  123. package/project/hooks/utils/tts/mlx_audio_tts.py +86 -0
  124. package/project/hooks/utils/tts/openai_tts.py +92 -0
  125. package/project/hooks/utils/tts/pyttsx3_tts.py +75 -0
  126. package/project/linear.yaml.template +23 -0
  127. package/project/product.md.template +238 -0
  128. package/project/retros/README.md +126 -0
  129. package/project/rules/README.md +90 -0
  130. package/project/rules/debugging.md +139 -0
  131. package/project/rules/security-review.md +115 -0
  132. package/project/settings.yaml.template +185 -0
  133. package/project/specs/SPEC-ANV-72-hud-kanban.md +525 -0
  134. package/project/templates/api-python/CLAUDE.md +547 -0
  135. package/project/templates/generic/CLAUDE.md +260 -0
  136. package/project/templates/saas/CLAUDE.md +478 -0
  137. package/project/tests/README.md +140 -0
  138. package/project/tests/__pycache__/test_transcript_parser.cpython-314-pytest-9.0.2.pyc +0 -0
  139. package/project/tests/fixtures/sample-transcript.jsonl +21 -0
  140. package/project/tests/test-hooks.sh +259 -0
  141. package/project/tests/test-lib.sh +248 -0
  142. package/project/tests/test-statusline.sh +165 -0
  143. package/project/tests/test_transcript_parser.py +323 -0
@@ -0,0 +1,343 @@
1
+ # [Project Name]
2
+
3
+ > [One-line description of the project]
4
+
5
+ ---
6
+
7
+ ## Project Overview
8
+
9
+ [2-3 sentences describing what this project is and who it's for]
10
+
11
+ **Status**: [Active Development / Maintenance / Beta / etc.]
12
+ **Repository**: [URL]
13
+ **Live URL**: [URL if applicable]
14
+
15
+ ---
16
+
17
+ ## Tech Stack
18
+
19
+ | Layer | Technology | Version |
20
+ |-------|------------|---------|
21
+ | Framework | Next.js | 14.x |
22
+ | Language | TypeScript | 5.x |
23
+ | Database | Supabase (PostgreSQL) | — |
24
+ | Auth | Supabase Auth | — |
25
+ | Styling | Tailwind CSS | 3.x |
26
+ | Testing | Vitest | 1.x |
27
+ | Deployment | Vercel | — |
28
+
29
+ ---
30
+
31
+ ## Architecture
32
+
33
+ ### Directory Structure
34
+ ```
35
+ src/
36
+ ├── app/ # Next.js App Router pages
37
+ │ ├── api/ # API routes
38
+ │ └── (routes)/ # Page routes
39
+ ├── components/ # React components
40
+ │ ├── ui/ # Base UI components
41
+ │ └── [feature]/ # Feature-specific components
42
+ ├── lib/ # Shared utilities
43
+ ├── services/ # Business logic
44
+ ├── hooks/ # Custom React hooks
45
+ └── types/ # TypeScript types
46
+ ```
47
+
48
+ ### Key Patterns
49
+ - **API Routes**: Next.js App Router with route handlers
50
+ - **Database**: Supabase client with RLS policies
51
+ - **Auth**: Supabase Auth with middleware protection
52
+ - **State**: React Query for server state, Zustand for client state
53
+ - **Error Handling**: Custom AppError class with error boundaries
54
+
55
+ ---
56
+
57
+ ## Agent Approach
58
+
59
+ ### Session Startup
60
+ ```
61
+ 1. /orient → Check handoffs, understand context
62
+ 2. /ready → See unblocked work
63
+ 3. /validate → Ensure clean environment
64
+ 4. Await direction → Don't start work without confirmation
65
+ ```
66
+
67
+ ### Implementation Flow
68
+ ```
69
+ 1. /explore → Discovery before any new feature
70
+ 2. /spec → Formal specification (if needed)
71
+ 3. /plan → Implementation plan
72
+ 4. /tasks → Linear issues from plan
73
+ 5. [implement] → Do the work
74
+ 6. /evidence → Capture quality proof
75
+ 7. /handoff → Session continuity
76
+ ```
77
+
78
+ ### During Work
79
+ - Read existing code before writing new code
80
+ - Cite file paths and line numbers as evidence
81
+ - File discovered work immediately with `/discover`
82
+ - Update Linear status at phase transitions
83
+ - Stop and report if stuck >5 minutes
84
+
85
+ ### Anti-Patterns to Avoid
86
+
87
+ Before implementing, verify you're NOT doing:
88
+
89
+ | Anti-Pattern | Check |
90
+ |--------------|-------|
91
+ | Premature abstraction | Is this the 3rd instance? (Rule of Three) |
92
+ | Adding files without need | Can this be added to existing file? |
93
+ | Over-engineering | Is this the simplest solution? |
94
+ | Ignoring existing patterns | Did I check examples first? |
95
+ | Large PRs | Can I break this into smaller chunks? |
96
+ | Skipping exploration | Did I run `/explore` first? |
97
+ | Editing gitignored files | Is this path in `.gitignore`? (check `project/` vs `.claude/`) |
98
+ | Uncommitted work before compaction | Did I commit a WIP checkpoint? |
99
+ | Reading files on wrong branch | Did I run `git branch --show-current` first? |
100
+ | Post-edit without git diff | Did I run `git diff` to verify edits persisted? |
101
+ | Starting exploration without WIP | Is current work committed before `/explore`? |
102
+ | Stash operation without verification | Did I run `git diff --name-only main..HEAD` after stash pop? |
103
+ | Importing from `global.*` in Python | Use `sys.path.insert(0, project_root)` first - `global` is reserved |
104
+ | Guessing object attributes | Read class definition or use `dir(obj)` first |
105
+
106
+ ### Code Patterns
107
+
108
+ Patterns for specific coding scenarios:
109
+
110
+ | Pattern | When to Use | Example |
111
+ |---------|-------------|---------|
112
+ | Python Null Handling | JSON with possible null values | `dict.get(key) or default` not `dict.get(key, default)` for falsy values |
113
+ | Try-Finally for Resources | File handles, DB connections, temp files | `try: conn = open() ... finally: conn.close()` |
114
+ | Fast-Path Scripts | 3+ independent queries >100ms each | Create `_fast.py` companion with ThreadPoolExecutor |
115
+ | Script Existence Check | New script added in PR | `[ -f script.py ] && python3 script.py` in commands |
116
+
117
+ ### Code Patterns
118
+
119
+ Patterns for specific coding scenarios (Evidence: ANV-135, ANV-203, ANV-250, coderabbit-fixes):
120
+
121
+ | Pattern | When to Use | Example |
122
+ |---------|-------------|---------|
123
+ | Python Null Handling | JSON with possible null/falsy values | Use `dict.get(key) or default` when None means missing; use `dict.get(key, default)` when 0 or "" are valid values |
124
+ | Try-Finally for Resources | File handles, DB connections, temp files | `try: conn = open() ... finally: conn.close()` |
125
+ | Fast-Path Scripts | 3+ independent queries >100ms each | Create `_fast.py` companion with ThreadPoolExecutor |
126
+ | Script Existence Check | New script added in PR | `[ -f script.py ] && python3 script.py` in commands |
127
+
128
+ ### Confidence Checkpoints
129
+
130
+ Rate your confidence at each stage (1-10):
131
+
132
+ | Confidence | Action |
133
+ |------------|--------|
134
+ | 8-10 | Proceed normally |
135
+ | 5-7 | Document uncertainty, proceed cautiously, note assumptions |
136
+ | 1-4 | **STOP**. Explain the uncertainty. Ask for guidance. |
137
+
138
+ **Escalation rule**: After 2 failed attempts at the same task → Stop. Reassess. Ask for help.
139
+
140
+ ---
141
+
142
+ ## Interactive Questions (AskUserQuestion)
143
+
144
+ When requirements are ambiguous, use the AskUserQuestion tool to gather explicit decisions interactively.
145
+
146
+ ### When to Use
147
+ - Requirements contain alternatives ("X or Y")
148
+ - Multiple valid approaches exist
149
+ - Scope is negotiable
150
+ - Technical choices need user input
151
+
152
+ ### Best Practices
153
+
154
+ | Guideline | Example |
155
+ |-----------|---------|
156
+ | **header**: Max 12 chars, noun-like | "Provider", "Scope", "Priority" |
157
+ | **question**: Full sentence with "?" | "Which auth provider should we use?" |
158
+ | **multiSelect**: true if multiple valid | Scope selections, feature toggles |
159
+ | **options**: 2-4 choices, best first | Add "(Recommended)" to suggested option |
160
+ | **descriptions**: Explain implications | "Fastest setup, widest adoption" |
161
+
162
+ ### Pattern: Interview-Then-Execute
163
+ ```
164
+ 1. /clarify [topic] → Gather decisions via AskUserQuestion
165
+ 2. /spec [feature] → Write spec with decisions captured
166
+ 3. /plan [spec] → Plan implementation
167
+ 4. [implement] → Execute with clarity
168
+ ```
169
+
170
+ ### Example
171
+ ```typescript
172
+ AskUserQuestion({
173
+ questions: [{
174
+ header: "Provider",
175
+ question: "Which authentication provider should we implement?",
176
+ multiSelect: false,
177
+ options: [
178
+ { label: "Google OAuth (Recommended)", description: "Widest adoption" },
179
+ { label: "GitHub OAuth", description: "Developer-focused" },
180
+ { label: "Email/Password", description: "No external dependency" }
181
+ ]
182
+ }]
183
+ })
184
+ ```
185
+
186
+ **Note**: User can always select "Other" to provide custom input.
187
+
188
+ ---
189
+
190
+ ## Slash Commands
191
+
192
+ ### Session Commands
193
+ | Command | Purpose |
194
+ |---------|---------|
195
+ | `/orient` | Session startup orientation (with interactive task picker) |
196
+ | `/ready` | Calculate ready work |
197
+ | `/sprint` | Quick session prioritization |
198
+ | `/handoff` | Generate session continuity doc |
199
+
200
+ ### Workflow Commands
201
+ | Command | Purpose |
202
+ |---------|---------|
203
+ | `/explore` | Discovery phase |
204
+ | `/clarify` | Interactive requirement disambiguation |
205
+ | `/spec` | Generate specification |
206
+ | `/plan` | Create implementation plan |
207
+ | `/tasks` | Create Linear issues |
208
+ | `/change` | Brownfield change proposal |
209
+ | `/discover` | File discovered work |
210
+
211
+ ### Quality Commands
212
+ | Command | Purpose |
213
+ |---------|---------|
214
+ | `/validate` | Environment validation |
215
+ | `/evidence` | Capture quality proof |
216
+
217
+ ### Maintenance Commands
218
+ | Command | Purpose |
219
+ |---------|---------|
220
+ | `/retro` | Write retrospective |
221
+ | `/insights` | Synthesize learnings |
222
+
223
+ ---
224
+
225
+ ## Linear Workflow
226
+
227
+ ### Issue States
228
+ | State | Meaning |
229
+ |-------|---------|
230
+ | Backlog | Not yet prioritized |
231
+ | Todo | Prioritized, ready to start |
232
+ | In Progress | Actively being worked on |
233
+ | In Review | PR created, awaiting review |
234
+ | Done | Merged and deployed |
235
+
236
+ ### Labels
237
+ - `bug` — Something isn't working
238
+ - `feature` — New functionality
239
+ - `chore` — Maintenance task
240
+ - `discovered` — Found during other work
241
+ - `blocked` — Cannot proceed
242
+
243
+ ### Priorities
244
+ - **P0 (Urgent)**: Drop everything, fix now
245
+ - **P1 (High)**: Next up after current task
246
+ - **P2 (Medium)**: This sprint
247
+ - **P3 (Low)**: Backlog
248
+
249
+ ---
250
+
251
+ ## File Conventions
252
+
253
+ ### Naming
254
+ - **Components**: PascalCase (`UserProfile.tsx`)
255
+ - **Hooks**: camelCase with `use` prefix (`useAuth.ts`)
256
+ - **Utilities**: camelCase (`formatDate.ts`)
257
+ - **Types**: PascalCase (`User.ts`)
258
+ - **API Routes**: lowercase (`route.ts`)
259
+
260
+ ### Component Structure
261
+ ```typescript
262
+ // Imports (external, then internal)
263
+ import { useState } from 'react'
264
+ import { Button } from '@/components/ui'
265
+
266
+ // Types
267
+ interface Props {
268
+ // ...
269
+ }
270
+
271
+ // Component
272
+ export function ComponentName({ prop }: Props) {
273
+ // Hooks first
274
+ // State second
275
+ // Effects third
276
+ // Handlers fourth
277
+ // Render last
278
+ }
279
+ ```
280
+
281
+ ---
282
+
283
+ ## Error Handling
284
+
285
+ ### Pattern
286
+ ```typescript
287
+ import { AppError } from '@/lib/errors'
288
+
289
+ try {
290
+ // operation
291
+ } catch (error) {
292
+ if (error instanceof AppError) {
293
+ // Handle known errors
294
+ }
295
+ throw new AppError('OPERATION_FAILED', 'Description', { cause: error })
296
+ }
297
+ ```
298
+
299
+ ### Error Codes
300
+ | Code | Meaning |
301
+ |------|---------|
302
+ | `AUTH_REQUIRED` | User must be logged in |
303
+ | `NOT_FOUND` | Resource doesn't exist |
304
+ | `VALIDATION_ERROR` | Invalid input |
305
+ | `PERMISSION_DENIED` | User lacks permission |
306
+
307
+ ---
308
+
309
+ ## Key Files Reference
310
+
311
+ | Purpose | Location |
312
+ |---------|----------|
313
+ | Project config | `CLAUDE.md` (this file) |
314
+ | Non-negotiables | `.claude/constitution.md` |
315
+ | Product definition | `.claude/product.md` |
316
+ | Active specs | `.claude/specs/current/` |
317
+ | Handoffs | `.claude/handoffs/` |
318
+ | Convention examples | `.claude/examples/` |
319
+
320
+ ---
321
+
322
+ ## Environment Setup
323
+
324
+ ### Required Environment Variables
325
+ ```bash
326
+ # .env.local
327
+ NEXT_PUBLIC_SUPABASE_URL=
328
+ NEXT_PUBLIC_SUPABASE_ANON_KEY=
329
+ SUPABASE_SERVICE_ROLE_KEY=
330
+ ```
331
+
332
+ ### Local Development
333
+ ```bash
334
+ npm install # Install dependencies
335
+ npm run dev # Start dev server
336
+ npm run test # Run tests
337
+ npm run typecheck # Check types
338
+ npm run lint # Run linter
339
+ ```
340
+
341
+ ---
342
+
343
+ *Update this file as the project evolves. This is your project's source of truth for AI assistance.*
@@ -0,0 +1,119 @@
1
+ # Sub-Agents
2
+
3
+ > Focused task executors for specific bounded workflows. Use sparingly.
4
+
5
+ ---
6
+
7
+ ## Philosophy
8
+
9
+ **Single agent with skills beats multi-agent coordination.**
10
+
11
+ Research shows multi-agent architectures degrade sequential task performance by 39-70%. Coding is inherently sequential. Therefore, Anvil uses a single generalist agent enhanced with on-demand skills.
12
+
13
+ Sub-agents are the **exception**, not the rule.
14
+
15
+ ---
16
+
17
+ ## When to Use Sub-Agents
18
+
19
+ Sub-agents are appropriate when:
20
+
21
+ 1. **Adversarial perspective helps** — Task benefits from "fresh eyes" that haven't seen the code being reviewed
22
+ 2. **Bounded scope** — Task has clear start/end with specific methodology
23
+ 3. **Context isolation valuable** — Separate context prevents bias from implementation work
24
+
25
+ ### Recommended Sub-Agents (2)
26
+
27
+ | Sub-Agent | Purpose | Why It's Needed |
28
+ |-----------|---------|-----------------|
29
+ | `security-code-reviewer` | Adversarial security review | Fresh perspective catches what implementer missed |
30
+ | `cross-layer-debugger` | Debug issues spanning layers | Bounded methodology, isolation prevents tunnel vision |
31
+
32
+ ---
33
+
34
+ ## When NOT to Use Sub-Agents
35
+
36
+ **Use skills instead when:**
37
+
38
+ - It's mainly a checklist or methodology → Skill
39
+ - Same context as main work is fine → Skill
40
+ - Doesn't need "fresh eyes" → Skill
41
+ - One-off task → Do manually
42
+
43
+ **Common anti-patterns:**
44
+
45
+ | Anti-Pattern | Better Alternative |
46
+ |--------------|-------------------|
47
+ | api-designer sub-agent | API design patterns skill |
48
+ | test-writer sub-agent | Testing strategies skill |
49
+ | docs-writer sub-agent | Documentation standards skill |
50
+ | component-designer sub-agent | Component architecture skill |
51
+
52
+ ---
53
+
54
+ ## Sub-Agent Structure
55
+
56
+ Each sub-agent file uses YAML frontmatter followed by the agent definition:
57
+
58
+ ```yaml
59
+ ---
60
+ name: <agent-name>
61
+ description: <brief description>
62
+ tools: [Read, Grep, Glob] # Available tools
63
+ skills: [skill-1, skill-2] # Auto-loaded skills (optional)
64
+ permissionMode: default # default|inherit|strict (optional)
65
+ ---
66
+
67
+ # [Sub-Agent Name]
68
+
69
+ > One-line description
70
+
71
+ ## Purpose
72
+ Why this sub-agent exists (not a skill)
73
+
74
+ ## Trigger Conditions
75
+ When to invoke this sub-agent
76
+
77
+ ## Process
78
+ Step-by-step methodology
79
+
80
+ ## Output Format
81
+ What the sub-agent produces
82
+
83
+ ## Escalation
84
+ When to stop and escalate to human
85
+ ```
86
+
87
+ ### Frontmatter Fields
88
+
89
+ | Field | Required | Description |
90
+ |-------|----------|-------------|
91
+ | `name` | Yes | Agent identifier |
92
+ | `description` | Yes | Brief purpose description |
93
+ | `tools` | Yes | List of available tools |
94
+ | `skills` | No | Skills to auto-load at start |
95
+ | `permissionMode` | No | Permission handling: `default`, `inherit`, `strict` |
96
+
97
+ See [Skills Frontmatter](../docs/skills-frontmatter.md) for detailed documentation.
98
+
99
+ ---
100
+
101
+ ## Available Sub-Agents
102
+
103
+ - [security-code-reviewer.md](security-code-reviewer.md) — Adversarial security review
104
+ - [cross-layer-debugger.md](cross-layer-debugger.md) — Cross-layer debugging methodology
105
+
106
+ ---
107
+
108
+ ## Adding New Sub-Agents
109
+
110
+ Before adding a sub-agent, ask:
111
+
112
+ 1. Could this be a skill instead? (Usually yes)
113
+ 2. Does it genuinely benefit from fresh context?
114
+ 3. Is the scope bounded with clear methodology?
115
+ 4. Will it be used regularly? (If not, do manually)
116
+
117
+ If all answers support a sub-agent, use the template structure above.
118
+
119
+ **Default answer: Use a skill instead.**
@@ -0,0 +1,217 @@
1
+ ---
2
+ name: cross-layer-debugger
3
+ description: Systematic debugging for issues spanning multiple system layers
4
+ ---
5
+
6
+ # Cross-Layer Debugger
7
+
8
+ > Systematic debugging for issues spanning multiple system layers.
9
+
10
+ ---
11
+
12
+ ## Purpose
13
+
14
+ Debug issues that cross boundaries between frontend, API, database, and external services. Uses structured methodology to isolate which layer contains the bug.
15
+
16
+ **Why sub-agent (not skill):** Debugging benefits from fresh context without preconceptions about where the bug "should" be. Isolation prevents tunnel vision from implementation work.
17
+
18
+ ---
19
+
20
+ ## Trigger Conditions
21
+
22
+ Invoke this sub-agent when:
23
+
24
+ - Bug symptoms appear in one layer but cause may be elsewhere
25
+ - Issue involves data flow across multiple boundaries
26
+ - Previous debugging attempts haven't isolated the problem
27
+ - "It works locally but not in production" scenarios
28
+ - Intermittent failures that are hard to reproduce
29
+
30
+ ---
31
+
32
+ ## Process
33
+
34
+ ### Step 1: Symptom Documentation
35
+
36
+ Before investigating, document exactly what's observed:
37
+
38
+ ```markdown
39
+ ## Symptom Report
40
+ - **What happens**: [Exact error/behavior]
41
+ - **What should happen**: [Expected behavior]
42
+ - **Where observed**: [UI/console/logs/etc.]
43
+ - **Reproducible**: [Always/Sometimes/Rarely]
44
+ - **Steps to reproduce**: [Minimal steps]
45
+ ```
46
+
47
+ ### Step 2: Layer Identification
48
+
49
+ Identify all layers involved in the data flow:
50
+
51
+ ```
52
+ ┌─────────────┐
53
+ │ Frontend │ ← UI components, state, event handlers
54
+ ├─────────────┤
55
+ │ API Layer │ ← Routes, controllers, middleware
56
+ ├─────────────┤
57
+ │ Services │ ← Business logic, validation
58
+ ├─────────────┤
59
+ │ Database │ ← Queries, RLS, triggers
60
+ ├─────────────┤
61
+ │ External │ ← Third-party APIs, services
62
+ └─────────────┘
63
+ ```
64
+
65
+ For the bug, trace which layers are involved in the operation.
66
+
67
+ ### Step 3: Boundary Testing
68
+
69
+ Test at each layer boundary systematically:
70
+
71
+ **Frontend → API**
72
+ ```bash
73
+ # Verify request is correct
74
+ curl -X POST http://localhost:3000/api/endpoint \
75
+ -H "Content-Type: application/json" \
76
+ -d '{"test": "data"}'
77
+ ```
78
+ - Is the request payload correct?
79
+ - Are headers correct (auth, content-type)?
80
+ - Does the API receive what frontend sends?
81
+
82
+ **API → Service**
83
+ - Add logging at service entry point
84
+ - Verify parameters passed correctly
85
+ - Check for transformation errors
86
+
87
+ **Service → Database**
88
+ - Log the actual query being executed
89
+ - Run query directly in database client
90
+ - Check RLS policies if applicable
91
+
92
+ **Database → External**
93
+ - Verify external service is reachable
94
+ - Check credentials/tokens
95
+ - Test external API independently
96
+
97
+ ### Step 4: Isolation
98
+
99
+ Use binary search to isolate:
100
+
101
+ 1. Find the middle boundary
102
+ 2. Verify data is correct at that point
103
+ 3. If correct: bug is downstream
104
+ 4. If incorrect: bug is upstream
105
+ 5. Repeat until layer identified
106
+
107
+ ### Step 5: Root Cause Analysis
108
+
109
+ Once layer is identified:
110
+
111
+ - What's the exact line/function?
112
+ - Why does it fail?
113
+ - What assumption was wrong?
114
+ - Is this the only occurrence?
115
+
116
+ ---
117
+
118
+ ## Debugging Toolkit
119
+
120
+ ### Logging Strategy
121
+
122
+ ```typescript
123
+ // Boundary logging pattern
124
+ console.log('[LAYER:BOUNDARY] input:', JSON.stringify(input));
125
+ // ... operation ...
126
+ console.log('[LAYER:BOUNDARY] output:', JSON.stringify(output));
127
+ ```
128
+
129
+ ### Database Debugging
130
+
131
+ ```sql
132
+ -- Check RLS is the issue
133
+ SET LOCAL row_level_security = off;
134
+ SELECT * FROM table WHERE id = 'xxx';
135
+
136
+ -- Check what policies exist
137
+ SELECT * FROM pg_policies WHERE tablename = 'table_name';
138
+ ```
139
+
140
+ ### Network Debugging
141
+
142
+ ```bash
143
+ # See actual request/response
144
+ curl -v -X POST url -d 'data'
145
+
146
+ # Check if service is reachable
147
+ nc -zv hostname port
148
+ ```
149
+
150
+ ### State Debugging
151
+
152
+ ```typescript
153
+ // React state debugging
154
+ useEffect(() => {
155
+ console.log('[STATE] value changed:', value);
156
+ }, [value]);
157
+ ```
158
+
159
+ ---
160
+
161
+ ## Output Format
162
+
163
+ ```markdown
164
+ # Debug Report: [Issue Description]
165
+
166
+ ## Symptom
167
+ [What was observed]
168
+
169
+ ## Layers Investigated
170
+ - [ ] Frontend
171
+ - [ ] API
172
+ - [ ] Services
173
+ - [ ] Database
174
+ - [ ] External
175
+
176
+ ## Boundary Test Results
177
+
178
+ | Boundary | Input Correct? | Output Correct? | Notes |
179
+ |----------|---------------|-----------------|-------|
180
+ | FE → API | ✅/❌ | ✅/❌ | [notes] |
181
+ | API → Service | ✅/❌ | ✅/❌ | [notes] |
182
+ | Service → DB | ✅/❌ | ✅/❌ | [notes] |
183
+
184
+ ## Root Cause
185
+ **Layer**: [Where bug exists]
186
+ **Component**: [Specific file/function]
187
+ **Issue**: [What's wrong]
188
+ **Why**: [Root cause explanation]
189
+
190
+ ## Fix Recommendation
191
+ [Suggested fix with code snippet if applicable]
192
+
193
+ ## Verification
194
+ [How to verify the fix works]
195
+ ```
196
+
197
+ ---
198
+
199
+ ## Escalation
200
+
201
+ Stop and escalate to human when:
202
+
203
+ - Issue requires production access you don't have
204
+ - Bug appears to be in third-party code
205
+ - Multiple possible root causes, unclear which
206
+ - Fix requires architectural decision
207
+ - Unable to reproduce after 3 attempts
208
+ - Debugging has taken >30 minutes without progress
209
+
210
+ ---
211
+
212
+ ## What This Sub-Agent Does NOT Do
213
+
214
+ - Implement fixes (report findings, main agent fixes)
215
+ - Make architectural decisions
216
+ - Debug without systematic approach (no random changes)
217
+ - Continue indefinitely (escalate if stuck)