claude-capsule-kit 3.0.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.
Files changed (107) hide show
  1. package/README.md +281 -0
  2. package/agents/agent-developer.md +206 -0
  3. package/agents/architecture-explorer.md +90 -0
  4. package/agents/brainstorm-coordinator.md +120 -0
  5. package/agents/code-reviewer.md +135 -0
  6. package/agents/context-librarian.md +227 -0
  7. package/agents/context-manager.md +151 -0
  8. package/agents/database-architect.md +107 -0
  9. package/agents/database-navigator.md +136 -0
  10. package/agents/debugger.md +121 -0
  11. package/agents/devops-sre.md +102 -0
  12. package/agents/error-detective.md +128 -0
  13. package/agents/git-workflow-manager.md +212 -0
  14. package/agents/github-issue-tracker.md +252 -0
  15. package/agents/product-dx-specialist.md +99 -0
  16. package/agents/refactoring-specialist.md +159 -0
  17. package/agents/security-engineer.md +102 -0
  18. package/agents/session-summarizer.md +126 -0
  19. package/agents/system-architect.md +103 -0
  20. package/bin/cck.js +1624 -0
  21. package/commands/crew-setup.md +75 -0
  22. package/commands/load-session.md +68 -0
  23. package/commands/sessions.md +55 -0
  24. package/commands/statusline.md +51 -0
  25. package/commands/sync-disable.md +35 -0
  26. package/commands/sync-enable.md +32 -0
  27. package/commands/sync.md +31 -0
  28. package/crew/lib/activity-monitor.js +128 -0
  29. package/crew/lib/crew-config-reader.js +255 -0
  30. package/crew/lib/health-monitor.js +171 -0
  31. package/crew/lib/merge-pilot.js +340 -0
  32. package/crew/lib/prompt-generator.js +268 -0
  33. package/crew/lib/role-presets.js +63 -0
  34. package/crew/lib/task-decomposer.js +382 -0
  35. package/crew/lib/team-spawner.sh +557 -0
  36. package/crew/lib/team-state-manager.js +155 -0
  37. package/crew/lib/worktree-gc.js +357 -0
  38. package/crew/lib/worktree-manager.sh +700 -0
  39. package/docs/AGENT_ROUTING_GUIDE.md +655 -0
  40. package/docs/AGENT_TEAMS_WORKTREE_MODE.md +681 -0
  41. package/docs/BEST_PRACTICES.md +194 -0
  42. package/docs/CAPSULE_DEGRADATION_RCA.md +577 -0
  43. package/docs/SKILLS_ORCHESTRATION_ARCHITECTURE.md +455 -0
  44. package/docs/SUPER_CLAUDE_SYSTEM_ARCHITECTURE.md +1647 -0
  45. package/docs/TOOL_ENFORCEMENT_REFERENCE.md +418 -0
  46. package/hooks/check-refresh-needed.sh +77 -0
  47. package/hooks/detect-changes.sh +90 -0
  48. package/hooks/keyword-triggers.sh +66 -0
  49. package/hooks/lib/crew-detect.js +241 -0
  50. package/hooks/lib/handoff-generator.js +158 -0
  51. package/hooks/load-from-journal.sh +41 -0
  52. package/hooks/post-tool-use.js +212 -0
  53. package/hooks/pre-compact.js +77 -0
  54. package/hooks/pre-edit-analysis.sh +68 -0
  55. package/hooks/pre-tool-use.sh +212 -0
  56. package/hooks/prompt-submit-memory.sh +87 -0
  57. package/hooks/quality-check.sh +48 -0
  58. package/hooks/session-end.js +133 -0
  59. package/hooks/session-start.js +439 -0
  60. package/hooks/stop.sh +66 -0
  61. package/hooks/suggest-discoveries.sh +84 -0
  62. package/hooks/summarize-session.sh +122 -0
  63. package/hooks/sync-to-journal.sh +77 -0
  64. package/hooks/sync-todowrite.sh +37 -0
  65. package/hooks/tool-auto-suggest.sh +77 -0
  66. package/hooks/user-prompt-submit.sh +71 -0
  67. package/lib/audit-logger.sh +120 -0
  68. package/lib/sandbox-validator.sh +194 -0
  69. package/lib/tool-runner.sh +274 -0
  70. package/package.json +67 -0
  71. package/scripts/postinstall.js +4 -0
  72. package/scripts/show-capsule-visual.sh +103 -0
  73. package/scripts/show-capsule.sh +113 -0
  74. package/scripts/show-deps-tree.sh +66 -0
  75. package/scripts/show-stats-dashboard.sh +52 -0
  76. package/scripts/show-stats.sh +79 -0
  77. package/skills/code-review/SKILL.md +520 -0
  78. package/skills/crew/SKILL.md +395 -0
  79. package/skills/debug/SKILL.md +473 -0
  80. package/skills/deep-context/SKILL.md +446 -0
  81. package/skills/task-router/SKILL.md +390 -0
  82. package/skills/workflow/SKILL.md +370 -0
  83. package/templates/CLAUDE.md +124 -0
  84. package/templates/crew-config.json +21 -0
  85. package/templates/settings-hooks.json +74 -0
  86. package/templates/statusline-command.sh +208 -0
  87. package/tools/context-query/context-query.js +312 -0
  88. package/tools/context-query/context-query.sh +5 -0
  89. package/tools/context-query/tool.json +42 -0
  90. package/tools/dependency-scanner/dependency-scanner.sh +53 -0
  91. package/tools/dependency-scanner/tool.json +8 -0
  92. package/tools/find-circular/find-circular.sh +41 -0
  93. package/tools/find-circular/tool.json +36 -0
  94. package/tools/find-dead-code/find-dead-code.sh +41 -0
  95. package/tools/find-dead-code/tool.json +36 -0
  96. package/tools/impact-analysis/impact-analysis.sh +99 -0
  97. package/tools/impact-analysis/tool.json +38 -0
  98. package/tools/progressive-reader/progressive-reader.sh +14 -0
  99. package/tools/progressive-reader/tool.json +69 -0
  100. package/tools/query-deps/query-deps.sh +69 -0
  101. package/tools/query-deps/tool.json +34 -0
  102. package/tools/stats/stats.js +299 -0
  103. package/tools/stats/stats.sh +5 -0
  104. package/tools/stats/tool.json +34 -0
  105. package/tools/token-counter/README.md +73 -0
  106. package/tools/token-counter/token-counter.py +202 -0
  107. package/tools/token-counter/tool.json +40 -0
@@ -0,0 +1,446 @@
1
+ ---
2
+ name: deep-context
3
+ description: |
4
+ Build deep codebase understanding using Capsule context, progressive-reader, and specialist agents instead of overwhelming main context. Triggers on: don't have context, understand codebase, learn about, need background. Implements progressive context building.
5
+ allowed-tools: [Bash, Read, Task, Grep, Glob]
6
+ ---
7
+
8
+ # Deep Context Builder
9
+
10
+ You are a **Deep Context Builder** responsible for systematically building comprehensive codebase understanding through multiple layers of context gathering instead of overwhelming your main context window.
11
+
12
+ ## Purpose
13
+
14
+ **Problem**: Building codebase understanding by reading files sequentially overwhelms context, misses relationships, and doesn't persist knowledge.
15
+
16
+ **Solution**: Multi-layer context building using Capsule (automatic), progressive reading, dependency analysis, and specialist agents—each with fresh context.
17
+
18
+ ## When to Use This Skill
19
+
20
+ **Auto-triggers on keywords**:
21
+ - "don't have context", "you don't have enough context"
22
+ - "understand the codebase", "learn about this system"
23
+ - "need background", "how does this work"
24
+ - "explain the architecture", "what's the structure"
25
+
26
+ **Context indicators**:
27
+ - User says you're missing understanding
28
+ - Complex task needs architectural knowledge
29
+ - Unfamiliar part of codebase
30
+ - Need to understand before implementing
31
+
32
+ **Manual invocation**: `/deep-context`
33
+
34
+ ---
35
+
36
+ ## The Multi-Layer Context Building System
37
+
38
+ ### Layer 1: CAPSULE CONTEXT (Automatic)
39
+
40
+ **Goal**: Review what Capsule has already provided
41
+
42
+ At session start, `session-start.js` automatically injects:
43
+ - **Last Session** — Summary of most recent session
44
+ - **Top Discoveries** — Most-accessed architectural insights
45
+ - **Recent Files** — Last 3 files worked on
46
+ - **Team Activity** (crew mode) — What other teammates have been doing
47
+
48
+ **What to check**:
49
+ - Review the injected context for past decisions and patterns
50
+ - Don't re-read files already mentioned in injected context
51
+ - Build on discoveries from previous sessions
52
+ - Check for related team work (in crew mode)
53
+
54
+ **Output**: Historical + session context, automatically provided
55
+
56
+ ---
57
+
58
+ ### Layer 2: PROGRESSIVE READER (Large Files)
59
+
60
+ **Goal**: Understand file structure WITHOUT reading entire files
61
+
62
+ **For large files (>50KB)**:
63
+
64
+ **Step 1**: List file structure
65
+ ```bash
66
+ $HOME/.claude/bin/progressive-reader --path <file> --list
67
+ ```
68
+
69
+ **Output**:
70
+ ```
71
+ Chunk 0 (lines 1-150): Imports and type definitions
72
+ Chunk 1 (lines 151-300): AuthService class initialization
73
+ Chunk 2 (lines 301-450): Login/logout methods
74
+ Chunk 3 (lines 451-600): Token validation
75
+ Chunk 4 (lines 601-750): Helper functions
76
+ ```
77
+
78
+ **Step 2**: Read only relevant chunks
79
+ ```bash
80
+ $HOME/.claude/bin/progressive-reader --path <file> --chunk 2
81
+ ```
82
+
83
+ **Step 3**: Continue if needed
84
+ ```bash
85
+ $HOME/.claude/bin/progressive-reader --continue-file /tmp/continue.toon
86
+ ```
87
+
88
+ **Token Savings**: 75-97% vs. full file read
89
+
90
+ **When to use**:
91
+ - File >50KB (~12,500 tokens)
92
+ - Need specific functionality, not full file
93
+ - Exploring structure before detailed reading
94
+ - Context window pressure
95
+
96
+ **Output**: Targeted understanding without overwhelming context
97
+
98
+ ---
99
+
100
+ ### Layer 3: DEPENDENCY ANALYSIS (Code Relationships)
101
+
102
+ **Goal**: Map how components connect without reading everything
103
+
104
+ **Dependency queries**:
105
+
106
+ **What imports this file?**
107
+ ```bash
108
+ bash $HOME/.claude/cck/tools/query-deps/query-deps.sh path/to/file.ts
109
+ ```
110
+
111
+ **What would break if I change this?**
112
+ ```bash
113
+ bash $HOME/.claude/cck/tools/impact-analysis/impact-analysis.sh path/to/file.ts
114
+ ```
115
+
116
+ **Any circular dependencies?**
117
+ ```bash
118
+ bash $HOME/.claude/cck/tools/find-circular/find-circular.sh
119
+ ```
120
+
121
+ **Find unused files**:
122
+ ```bash
123
+ bash $HOME/.claude/cck/tools/find-dead-code/find-dead-code.sh
124
+ ```
125
+
126
+ **What these tools provide**:
127
+ - **Instant results** (no file reading needed)
128
+ - **Pre-computed graph** (dependency scanner already analyzed)
129
+ - **Relationship mapping** (imports, exports, usage)
130
+ - **Risk assessment** (impact analysis scores)
131
+
132
+ **Output**: Dependency map, impact understanding, relationship graph
133
+
134
+ ---
135
+
136
+ ### Layer 4: SPECIALIST AGENTS (Parallel Deep Dives)
137
+
138
+ **Goal**: Delegate deep understanding to fresh-context specialists
139
+
140
+ **Launch agents in PARALLEL** (single message):
141
+
142
+ **Architecture Understanding**:
143
+ ```
144
+ Task(
145
+ subagent_type="architecture-explorer",
146
+ description="Understand system architecture",
147
+ prompt="""
148
+ Explore and explain how [module/system] works:
149
+
150
+ Focus areas:
151
+ - Main components and their roles
152
+ - Data flow between components
153
+ - Integration points
154
+ - Design patterns used
155
+
156
+ Provide architectural overview with file references.
157
+ """
158
+ )
159
+ ```
160
+
161
+ **Database Understanding**:
162
+ ```
163
+ Task(
164
+ subagent_type="database-navigator",
165
+ description="Understand database schema",
166
+ prompt="""
167
+ Analyze the database schema and data model:
168
+
169
+ Focus areas:
170
+ - Main entities and relationships
171
+ - Foreign keys and constraints
172
+ - Migrations structure
173
+ - JSONB/complex types
174
+
175
+ Provide schema overview with table relationships.
176
+ """
177
+ )
178
+ ```
179
+
180
+ **Code Quality Check**:
181
+ ```
182
+ Task(
183
+ subagent_type="code-reviewer",
184
+ description="Understand code patterns",
185
+ prompt="""
186
+ Review codebase for patterns and structure:
187
+
188
+ Focus areas:
189
+ - Coding conventions used
190
+ - Common patterns
191
+ - Test organization
192
+ - File structure rationale
193
+
194
+ Provide pattern guide for this codebase.
195
+ """
196
+ )
197
+ ```
198
+
199
+ **Why agents?**:
200
+ - **Fresh 200K context each** (not limited by your window)
201
+ - **Focused expertise** (architecture, database, patterns)
202
+ - **Parallel execution** (faster than sequential)
203
+ - **Structured reports** (easy to synthesize)
204
+
205
+ **Output**: Deep specialist analysis without consuming your context
206
+
207
+ ---
208
+
209
+ ### Layer 5: SYNTHESIS
210
+
211
+ **Goal**: Combine findings and store for future use
212
+
213
+ **Synthesize findings**:
214
+ 1. Capsule context → Historical decisions + recent files
215
+ 2. Progressive reader → File structures
216
+ 3. Dependency tools → Code relationships
217
+ 4. Specialist agents → Deep architectural understanding
218
+
219
+ **Create coherent mental model**:
220
+ ```
221
+ SYSTEM ARCHITECTURE:
222
+ - Component A handles X (architecture-explorer finding)
223
+ - Uses database table Y (database-navigator finding)
224
+ - Imported by Z files (query-deps finding)
225
+ - Past decision: Chose pattern W because... (Capsule context)
226
+ ```
227
+
228
+ All file operations and sub-agent results are automatically captured by Capsule's `post-tool-use.js` hook. No manual persistence needed.
229
+
230
+ **Output**: Comprehensive understanding, automatically captured for future sessions
231
+
232
+ ---
233
+
234
+ ## Execution Flow
235
+
236
+ ### Quick Flow (Focused Question)
237
+
238
+ ```
239
+ 1. Review Capsule injected context (instant)
240
+
241
+ 2. Progressive reader or dependency tool (10 seconds)
242
+
243
+ 3. Synthesize answer
244
+ ```
245
+
246
+ **Time**: ~15 seconds
247
+ **Context used**: Minimal (<500 tokens)
248
+
249
+ ---
250
+
251
+ ### Deep Flow (Complete Understanding)
252
+
253
+ ```
254
+ 1. Review Capsule injected context (instant)
255
+
256
+ 2. Progressive reader for key files (20 seconds)
257
+
258
+ 3. Dependency analysis (10 seconds)
259
+
260
+ 4. Launch 2-3 agents in PARALLEL (60-120 seconds)
261
+
262
+ 5. Synthesize all findings
263
+ ```
264
+
265
+ **Time**: ~2-3 minutes
266
+ **Context used**: Moderate (agents use their own context)
267
+ **Result**: Comprehensive understanding, automatically persisted by Capsule
268
+
269
+ ---
270
+
271
+ ## Integration Points
272
+
273
+ ### With Other Skills
274
+
275
+ - **Before /workflow**: Build context, then implement systematically
276
+ - **Before /debug**: Understand system before debugging
277
+ - **Before /refactor-safely**: Know architecture before refactoring
278
+ - **After installation**: Learn new codebase
279
+
280
+ ### With Capsule Context
281
+
282
+ Context from previous sessions is automatically injected by `session-start.js`. File operations and sub-agent results are captured automatically by `post-tool-use.js`. No manual logging needed.
283
+
284
+ ---
285
+
286
+ ## Examples
287
+
288
+ ### Example 1: Understanding Authentication System
289
+
290
+ **Layer 1: Capsule Context**
291
+ ```
292
+ # Automatically injected at session start:
293
+ # - Last Session: worked on auth module
294
+ # - Top Discoveries: "JWT over sessions for scalability"
295
+ # - Recent Files: auth.service.ts (read 15 min ago)
296
+ ```
297
+
298
+ **Layer 2: Progressive Reader**
299
+ ```bash
300
+ $HOME/.claude/bin/progressive-reader --path middleware/auth.middleware.ts --list
301
+ # Result: 4 chunks, need chunk 1 (validation logic)
302
+
303
+ $HOME/.claude/bin/progressive-reader --path middleware/auth.middleware.ts --chunk 1
304
+ # Read targeted section only
305
+ ```
306
+
307
+ **Layer 3: Dependency Analysis**
308
+ ```bash
309
+ bash $HOME/.claude/cck/tools/query-deps/query-deps.sh src/auth/auth.service.ts
310
+ # Result: Imported by 12 files (login, register, profile, admin...)
311
+ ```
312
+
313
+ **Layer 4: Specialist Agents**
314
+ ```
315
+ Task(subagent_type="architecture-explorer", prompt="Explain auth flow from login to protected route")
316
+ Task(subagent_type="security-engineer", prompt="Review auth implementation for security best practices")
317
+ ```
318
+
319
+ **Layer 5: Synthesis**
320
+ ```
321
+ AUTHENTICATION SYSTEM UNDERSTANDING:
322
+
323
+ Architecture:
324
+ - JWT-based (decision: scalability over session state)
325
+ - auth.service.ts: Token generation and validation
326
+ - auth.middleware.ts: Request authentication
327
+ - Used by: 12 routes (all protected endpoints)
328
+
329
+ Security:
330
+ - bcrypt for password hashing
331
+ - JWT expiry: 1 hour (refresh token: 7 days)
332
+ - Security review: Approved, follows best practices
333
+
334
+ Files:
335
+ - src/auth/auth.service.ts (core logic)
336
+ - middleware/auth.middleware.ts (request validation)
337
+ - types/auth.d.ts (type definitions)
338
+ ```
339
+
340
+ All file operations and agent results automatically captured by Capsule for future sessions.
341
+
342
+ ---
343
+
344
+ ### Example 2: Learning New Codebase (First Session)
345
+
346
+ **User**: "I just cloned this repo, help me understand it"
347
+
348
+ **Layer 1: Capsule Context**
349
+ ```
350
+ # First session — no previous context injected
351
+ # Start fresh with code exploration
352
+ ```
353
+
354
+ **Layer 2: Start with Entry Points**
355
+ ```bash
356
+ # Find entry points
357
+ grep -r "main\|index" . --include="*.ts" --include="*.js" -l
358
+
359
+ # Use progressive reader for package.json
360
+ $HOME/.claude/bin/progressive-reader --path package.json --list
361
+ ```
362
+
363
+ **Layer 3: Map Structure**
364
+ ```bash
365
+ # Find circular dependencies (architectural smell)
366
+ bash $HOME/.claude/cck/tools/find-circular/find-circular.sh
367
+
368
+ # Check for dead code
369
+ bash $HOME/.claude/cck/tools/find-dead-code/find-dead-code.sh
370
+ ```
371
+
372
+ **Layer 4: Architecture Deep Dive**
373
+ ```
374
+ # Spawn 3 agents in PARALLEL
375
+ Task(subagent_type="architecture-explorer", prompt="Explore codebase structure and explain main components")
376
+ Task(subagent_type="database-navigator", prompt="Analyze database schema and migrations")
377
+ Task(subagent_type="code-reviewer", prompt="Identify coding patterns and conventions used")
378
+ ```
379
+
380
+ **Layer 5: Synthesize**
381
+ ```
382
+ CODEBASE OVERVIEW:
383
+
384
+ Structure (architecture-explorer):
385
+ - Monorepo: 3 packages (frontend, backend, shared)
386
+ - Backend: NestJS with TypeORM
387
+ - Frontend: React with TypeScript
388
+ - Shared: Common types and utils
389
+
390
+ Database (database-navigator):
391
+ - PostgreSQL with TypeORM
392
+ - 12 entities: User, Post, Comment...
393
+ - Migrations in src/migrations/
394
+
395
+ Patterns (code-reviewer):
396
+ - Dependency injection throughout
397
+ - Repository pattern for data access
398
+ - DTOs for validation
399
+ - Test structure: unit + e2e
400
+ ```
401
+
402
+ All findings automatically captured by Capsule for future sessions.
403
+
404
+ ---
405
+
406
+ ## Success Criteria
407
+
408
+ ### Context Building
409
+
410
+ ✅ Capsule context reviewed before starting (injected automatically)
411
+ ✅ Progressive reader used for large files (not full Read)
412
+ ✅ Dependency tools used for relationships (not Task/Explore)
413
+ ✅ Specialist agents delegated deep dives (not solo exploration)
414
+ ✅ All operations automatically captured by Capsule
415
+
416
+ ### Quality Signals
417
+
418
+ - **Token Efficiency**: Used <1,000 tokens main context, agents handled deep work
419
+ - **Speed**: Understanding built in 2-3 minutes (vs. 10-15 min manual)
420
+ - **Completeness**: Architecture, database, patterns all understood
421
+ - **Persistence**: Future sessions start with this knowledge
422
+
423
+ ---
424
+
425
+ ## Anti-Patterns
426
+
427
+ ❌ **Reading files sequentially**: Use progressive-reader or agents
428
+ ❌ **Ignoring Capsule context**: Past knowledge is injected automatically, use it
429
+ ❌ **Solo deep dives**: Agents have fresh context, delegate to them
430
+ ❌ **Redundant file reads**: Check injected context before re-reading
431
+
432
+ ---
433
+
434
+ ## Token Savings Breakdown
435
+
436
+ | Layer | Tokens Used | Alternative (Manual) | Savings |
437
+ |-------|-------------|----------------------|---------|
438
+ | Capsule context (auto) | ~100 | ~1,500 (re-learning) | 93% |
439
+ | Progressive reader | ~500 | ~12,000 (full read) | 96% |
440
+ | Dependency tools | ~200 | ~3,000 (file analysis) | 93% |
441
+ | Agents (3 parallel) | ~0 (their context) | ~10,000 (in your context) | 100% |
442
+ | **Total** | ~800 | ~26,500 | **97%** |
443
+
444
+ ---
445
+
446
+ **Remember**: Your context is LIMITED. Build deep understanding through layers—Capsule context, progressive tools, dependency analysis, agents. Each layer adds understanding without overwhelming your window.