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,418 @@
1
+ # Tool Enforcement Reference
2
+
3
+ Complete guide for tool selection and enforcement rules in Claude Capsule Kit.
4
+
5
+ ---
6
+
7
+ ## Overview
8
+
9
+ Claude Capsule Kit provides specialized tools that are **FASTER and MORE ACCURATE** than generic exploration. These rules are **MANDATORY** and enforced by the PreToolUse hook.
10
+
11
+ **Principle**: Use the right tool for the job—specialized tools beat Task/Explore agents for simple queries.
12
+
13
+ ---
14
+
15
+ ## Dependency Analysis Tools
16
+
17
+ ### Always Use Specialized Tools (NEVER Task/Explore)
18
+
19
+ #### 1. query-deps - "What imports this file?"
20
+
21
+ **Command**:
22
+ ```bash
23
+ bash $HOME/.claude/cck/tools/query-deps/query-deps.sh <file-path>
24
+ ```
25
+
26
+ **Use cases**:
27
+ - Finding files that import/depend on a specific file
28
+ - Checking if a function/export is used before deleting
29
+ - Understanding dependency relationships
30
+
31
+ **Example**:
32
+ ```bash
33
+ bash $HOME/.claude/cck/tools/query-deps/query-deps.sh src/auth/auth.service.ts
34
+
35
+ # Output:
36
+ Imported by 12 files:
37
+ - src/controllers/auth.controller.ts
38
+ - src/middleware/auth.middleware.ts
39
+ - src/guards/jwt.guard.ts
40
+ ...
41
+ ```
42
+
43
+ ---
44
+
45
+ #### 2. impact-analysis - "What would break if I change this?"
46
+
47
+ **Command**:
48
+ ```bash
49
+ bash $HOME/.claude/cck/tools/impact-analysis/impact-analysis.sh <file-path>
50
+ ```
51
+
52
+ **Use cases**:
53
+ - Impact analysis before refactoring
54
+ - Understanding blast radius of changes
55
+ - Risk assessment for modifications
56
+
57
+ **Returns**:
58
+ - Direct dependents
59
+ - Transitive dependents
60
+ - Risk assessment (LOW/MEDIUM/HIGH/CRITICAL)
61
+
62
+ **Example**:
63
+ ```bash
64
+ bash $HOME/.claude/cck/tools/impact-analysis/impact-analysis.sh src/auth/auth.service.ts
65
+
66
+ # Output:
67
+ DIRECT DEPENDENTS (5 files):
68
+ - src/controllers/auth.controller.ts
69
+ - src/middleware/auth.middleware.ts
70
+ ...
71
+
72
+ TRANSITIVE DEPENDENTS (18 files):
73
+ [Files that depend on the direct dependents]
74
+
75
+ RISK: MEDIUM
76
+ Recommendation: Update tests after changes
77
+ ```
78
+
79
+ ---
80
+
81
+ #### 3. find-circular - "Any circular dependencies?"
82
+
83
+ **Command**:
84
+ ```bash
85
+ bash $HOME/.claude/cck/tools/find-circular/find-circular.sh
86
+ ```
87
+
88
+ **Use cases**:
89
+ - Finding import cycles
90
+ - Debugging module resolution errors
91
+ - Code cleanup and refactoring prep
92
+
93
+ **Returns**:
94
+ - All circular dependency chains with fix suggestions
95
+
96
+ **Example**:
97
+ ```bash
98
+ bash $HOME/.claude/cck/tools/find-circular/find-circular.sh
99
+
100
+ # Output:
101
+ CIRCULAR DEPENDENCY FOUND:
102
+ A.ts → B.ts → C.ts → A.ts
103
+
104
+ Suggestion: Break cycle by extracting shared code to D.ts
105
+ ```
106
+
107
+ ---
108
+
109
+ #### 4. find-dead-code - "What files are unused?"
110
+
111
+ **Command**:
112
+ ```bash
113
+ bash $HOME/.claude/cck/tools/find-dead-code/find-dead-code.sh
114
+ ```
115
+
116
+ **Use cases**:
117
+ - Finding unused/unreferenced files
118
+ - Code cleanup
119
+ - Identifying candidates for deletion
120
+
121
+ **Returns**:
122
+ - List of potentially unused files
123
+
124
+ **Example**:
125
+ ```bash
126
+ bash $HOME/.claude/cck/tools/find-dead-code/find-dead-code.sh
127
+
128
+ # Output:
129
+ Potentially unused files (5):
130
+ - src/utils/legacy-helper.ts (not imported anywhere)
131
+ - src/models/old-user.model.ts (not imported)
132
+ ...
133
+ ```
134
+
135
+ ---
136
+
137
+ ### Why NOT Task/Explore for Dependencies?
138
+
139
+ | Issue | Reason |
140
+ |-------|--------|
141
+ | **Slower** | Must read and parse files sequentially |
142
+ | **Incomplete** | May miss indirect dependencies |
143
+ | **Expensive** | High token usage for simple queries |
144
+ | **Cannot detect cycles** | Needs graph analysis (pre-computed) |
145
+
146
+ **Use dependency tools instead** - they read the pre-built dependency graph (instant, complete, accurate).
147
+
148
+ ---
149
+
150
+ ## File Search: Glob Tool
151
+
152
+ ### Always Use Glob (NOT Task/Explore)
153
+
154
+ **Tool**: Glob
155
+ **Reason**: Direct file pattern matching
156
+
157
+ **Examples**:
158
+
159
+ **Find file by name**:
160
+ ```
161
+ Glob(pattern="**/*auth*")
162
+ # Finds: auth.service.ts, auth.controller.ts, auth.middleware.ts
163
+ ```
164
+
165
+ **Find files by extension**:
166
+ ```
167
+ Glob(pattern="**/*.ts")
168
+ # Finds: All TypeScript files
169
+ ```
170
+
171
+ **Find files in specific directory**:
172
+ ```
173
+ Glob(pattern="src/controllers/**/*.ts")
174
+ # Finds: All controllers
175
+ ```
176
+
177
+ **Why NOT Task/Explore?**
178
+ - Slower (agent must search iteratively)
179
+ - Glob is instant (built-in file system query)
180
+
181
+ ---
182
+
183
+ ## Code Search: Grep Tool
184
+
185
+ ### Always Use Grep (NOT Task/Explore)
186
+
187
+ **Tool**: Grep
188
+ **Reason**: Fast pattern matching
189
+
190
+ **Examples**:
191
+
192
+ **Find by keyword**:
193
+ ```
194
+ Grep(pattern="TODO", output_mode="files_with_matches")
195
+ # Finds: All files with TODO comments
196
+ ```
197
+
198
+ **Find definition**:
199
+ ```
200
+ Grep(pattern="function authenticateUser", output_mode="content")
201
+ # Finds: Function definition with line numbers
202
+ ```
203
+
204
+ **Find with context**:
205
+ ```
206
+ Grep(pattern="error", output_mode="content", -A=3, -B=3)
207
+ # Shows 3 lines before/after each match
208
+ ```
209
+
210
+ **Why NOT Task/Explore?**
211
+ - Grep is instant (ripgrep is extremely fast)
212
+ - Task/Explore must read files sequentially
213
+
214
+ ---
215
+
216
+ ## Progressive Reader (Large Files >50KB)
217
+
218
+ ### Navigation Tool for Large Files
219
+
220
+ **Tool**: `progressive-reader`
221
+ **Reason**: File navigation and structure discovery
222
+
223
+ **Purpose**:
224
+ Progressive-reader is a NAVIGATION TOOL for large files. Use it to understand file structure BEFORE reading, then read only what you need.
225
+
226
+ ### Primary Value: `--list` Command
227
+
228
+ The `--list` command shows file structure WITHOUT reading content:
229
+
230
+ **Benefits**:
231
+ - Shows all functions/classes with their chunk numbers
232
+ - Each chunk has a summary of what it contains
233
+ - ~500 tokens to see entire file structure (vs ~48,000 for full read)
234
+ - BETTER THAN GREP for understanding "what's in this file?"
235
+
236
+ ### Workflow
237
+
238
+ **Step 1**: Discover structure
239
+ ```bash
240
+ $HOME/.claude/bin/progressive-reader --path <file> --list
241
+ ```
242
+
243
+ **Output**:
244
+ ```
245
+ File: src/services/large-service.ts
246
+ Total Chunks: 8
247
+
248
+ Chunk 0 (lines 1-200): Imports, type definitions, class declaration
249
+ Chunk 1 (lines 201-400): Constructor and initialization methods
250
+ Chunk 2 (lines 401-600): Core business logic (create, update, delete)
251
+ Chunk 3 (lines 601-800): Validation and helper methods
252
+ ...
253
+ ```
254
+
255
+ **Step 2**: Find relevant chunks from function/class names in the list
256
+
257
+ **Step 3**: Read specific chunk
258
+ ```bash
259
+ $HOME/.claude/bin/progressive-reader --path <file> --chunk N
260
+ ```
261
+
262
+ **Step 4**: Continue if needed
263
+ ```bash
264
+ $HOME/.claude/bin/progressive-reader --continue-file /tmp/continue.toon
265
+ ```
266
+
267
+ ### When to Use Progressive Reader
268
+
269
+ - **Understanding file structure**: "What functions are in this file?"
270
+ - **Finding specific functionality**: "Which part handles authentication?"
271
+ - **Adding new code**: "Show me similar functions so I can follow the pattern"
272
+ - **Targeted reading**: "I need to understand just the login function"
273
+ - **Context-limited sessions**: Nearing token limits, need efficient reading
274
+
275
+ ### When Grep is Fine
276
+
277
+ - Finding specific keyword occurrences
278
+ - Searching for error messages or strings
279
+ - Quick lookups where you know what you're searching for
280
+
281
+ ### Language Support
282
+
283
+ **Full AST parsing** (intelligent chunking):
284
+ - TypeScript
285
+ - JavaScript
286
+ - Python
287
+ - Go
288
+
289
+ **Fallback** (line-based chunking):
290
+ - Other languages (still useful, less intelligent)
291
+
292
+ **Token Savings**: 75-97% vs full file read
293
+
294
+ ---
295
+
296
+ ## File Size Check (MANDATORY)
297
+
298
+ ### BEFORE using Read tool, ALWAYS check file size first
299
+
300
+ **Check command**:
301
+ ```bash
302
+ wc -c <file> | awk '{print int($1/1024)"KB"}'
303
+ ```
304
+
305
+ **Decision**:
306
+ - **If under 50KB**: Use Read tool normally
307
+ - **If over 50KB**: STOP. Use progressive-reader instead
308
+
309
+ **Why this matters**:
310
+ - Files over 50KB (~12,500+ tokens) cause `MaxFileReadTokenExceededError`
311
+ - Each failed Read attempt wastes tokens
312
+ - Check size FIRST to avoid errors
313
+
314
+ **Progressive reader command** (for large files):
315
+ ```bash
316
+ $HOME/.claude/bin/progressive-reader --path <file> --list
317
+ $HOME/.claude/bin/progressive-reader --path <file> --chunk N
318
+ ```
319
+
320
+ ---
321
+
322
+ ## Error Recovery
323
+
324
+ ### MaxFileReadTokenExceededError
325
+
326
+ **Trigger**: Attempted to read file >50KB with Read tool
327
+
328
+ **Action**: IMMEDIATELY stop using Read tool on this file
329
+
330
+ **Solution**: Switch to progressive-reader
331
+ ```bash
332
+ $HOME/.claude/bin/progressive-reader --path <file> --list
333
+ ```
334
+
335
+ **Do NOT**: Retry Read with offset/limit—use progressive-reader instead
336
+
337
+ **Note**: PreToolUse hook will warn/block large file reads automatically
338
+
339
+ ---
340
+
341
+ ## Task Tool - Allowed Uses
342
+
343
+ ### When Task Tool IS Allowed
344
+
345
+ **Allowed Use Cases**:
346
+
347
+ 1. **Complex architectural questions** requiring analysis
348
+ - Example: "How does the authentication system work?"
349
+
350
+ 2. **Implementation understanding**
351
+ - Example: "How does X work internally?"
352
+
353
+ 3. **Multi-file refactoring planning**
354
+ - Example: "Plan refactoring of auth module across files"
355
+
356
+ 4. **Design pattern identification**
357
+ - Example: "What patterns are used in this codebase?"
358
+
359
+ ### When Task Tool is NOT Allowed
360
+
361
+ **Forbidden**:
362
+ - Dependency lookups → Use `query-deps` instead
363
+ - File searches → Use `Glob` instead
364
+ - Code searches → Use `Grep` instead
365
+
366
+ **Why**: Specialized tools are instant and accurate. Task/Explore agents are slow and may miss results.
367
+
368
+ ---
369
+
370
+ ## Enforcement Mechanism
371
+
372
+ **PreToolUse Hook**: Intercepts tool calls and displays enforcement warnings
373
+
374
+ **How it works**:
375
+ 1. Hook detects dependency query keywords in Task/Explore prompts
376
+ 2. Outputs enforcement warning to stderr
377
+ 3. Suggests correct tool with example command
378
+ 4. Task still executes (warning only, not blocking)
379
+
380
+ **You must**: HEED THESE WARNINGS—they indicate you are using the wrong tool.
381
+
382
+ **Example warning**:
383
+ ```json
384
+ {
385
+ "type": "tool-enforcement",
386
+ "category": "dependency-analysis",
387
+ "warning": "Query appears to be about code dependencies",
388
+ "dontUse": {
389
+ "tool": "Task",
390
+ "reason": "inefficient"
391
+ },
392
+ "useInstead": [
393
+ {
394
+ "name": "query-deps",
395
+ "command": "bash $HOME/.claude/cck/tools/query-deps/query-deps.sh <file-path>"
396
+ }
397
+ ]
398
+ }
399
+ ```
400
+
401
+ ---
402
+
403
+ ## Quick Reference Card
404
+
405
+ | Need | Use | NOT |
406
+ |------|-----|-----|
407
+ | What imports X? | `query-deps` | Task/Explore |
408
+ | What breaks if I change X? | `impact-analysis` | Task/Explore |
409
+ | Circular deps? | `find-circular` | Task/Explore |
410
+ | Dead code? | `find-dead-code` | Task/Explore |
411
+ | Find files by name | Glob | Task/Explore |
412
+ | Find code patterns | Grep | Task/Explore |
413
+ | Read large files (>50KB) | `progressive-reader` | Read |
414
+ | Understand architecture | Task/architecture-explorer | Read files |
415
+
416
+ ---
417
+
418
+ **These tools exist to make you FASTER. Use them.**
@@ -0,0 +1,77 @@
1
+ #!/bin/bash
2
+ # Smart Refresh Heuristics
3
+ # Determines if capsule needs updating based on state changes
4
+ # Returns: 0 if refresh needed, 1 if can skip
5
+
6
+ set -euo pipefail
7
+
8
+ REFRESH_STATE_FILE=".claude/last_refresh_state.txt"
9
+ TIMESTAMP=$(date +%s)
10
+
11
+ # Helper: Calculate hash of current state
12
+ calculate_state_hash() {
13
+ local state_string=""
14
+
15
+ # Git state (if available)
16
+ if git rev-parse --git-dir > /dev/null 2>&1; then
17
+ state_string+=$(git status --porcelain 2>/dev/null | md5 -q 2>/dev/null || echo "")
18
+ else
19
+ # Fallback: use timestamp of last modified file
20
+ state_string+=$(find . -type f -not -path "./.claude/*" -not -path "./.git/*" -not -path "./node_modules/*" -printf "%T@\n" 2>/dev/null | sort -n | tail -1 || echo "0")
21
+ fi
22
+
23
+ # File log size (number of lines)
24
+ if [ -f ".claude/session_files.log" ]; then
25
+ state_string+=$(wc -l < .claude/session_files.log 2>/dev/null || echo "0")
26
+ fi
27
+
28
+ # Task log size
29
+ if [ -f ".claude/current_tasks.log" ]; then
30
+ state_string+=$(wc -l < .claude/current_tasks.log 2>/dev/null || echo "0")
31
+ fi
32
+
33
+ # Sub-agent log size
34
+ if [ -f ".claude/subagent_results.log" ]; then
35
+ state_string+=$(wc -l < .claude/subagent_results.log 2>/dev/null || echo "0")
36
+ fi
37
+
38
+ # Discovery log size
39
+ if [ -f ".claude/session_discoveries.log" ]; then
40
+ state_string+=$(wc -l < .claude/session_discoveries.log 2>/dev/null || echo "0")
41
+ fi
42
+
43
+ # Return hash of combined state
44
+ echo "$state_string" | md5 -q 2>/dev/null || echo "$state_string" | md5sum 2>/dev/null | cut -d' ' -f1 || echo "$state_string"
45
+ }
46
+
47
+ # Get current state hash
48
+ CURRENT_HASH=$(calculate_state_hash)
49
+
50
+ # Check if we have previous state
51
+ if [ -f "$REFRESH_STATE_FILE" ]; then
52
+ # Read previous state
53
+ LAST_HASH=$(cut -d',' -f1 "$REFRESH_STATE_FILE" 2>/dev/null || echo "")
54
+ LAST_REFRESH=$(cut -d',' -f2 "$REFRESH_STATE_FILE" 2>/dev/null || echo "0")
55
+ TIME_SINCE_REFRESH=$((TIMESTAMP - LAST_REFRESH))
56
+
57
+ # Compare hashes
58
+ if [ "$CURRENT_HASH" = "$LAST_HASH" ]; then
59
+ # State unchanged - check if too much time passed
60
+ if [ $TIME_SINCE_REFRESH -lt 300 ]; then
61
+ # Less than 5 minutes - safe to skip
62
+ exit 1 # Skip refresh
63
+ else
64
+ # Over 5 minutes - force refresh for freshness
65
+ echo "$CURRENT_HASH,$TIMESTAMP" > "$REFRESH_STATE_FILE"
66
+ exit 0 # Need refresh
67
+ fi
68
+ else
69
+ # State changed - need refresh
70
+ echo "$CURRENT_HASH,$TIMESTAMP" > "$REFRESH_STATE_FILE"
71
+ exit 0 # Need refresh
72
+ fi
73
+ else
74
+ # First run - need refresh
75
+ echo "$CURRENT_HASH,$TIMESTAMP" > "$REFRESH_STATE_FILE"
76
+ exit 0 # Need refresh
77
+ fi
@@ -0,0 +1,90 @@
1
+ #!/bin/bash
2
+ # Automatic Change Detection Script
3
+ # Detects file changes, tool usage, and discoveries since last prompt
4
+ # Called by pre-task-analysis hook
5
+
6
+ set -euo pipefail
7
+
8
+ SNAPSHOT_FILE=".claude/last_snapshot.txt"
9
+ FILE_LOG=".claude/session_files.log"
10
+ TIMESTAMP=$(date +%s)
11
+
12
+ # Create snapshot file if doesn't exist
13
+ mkdir -p .claude
14
+ touch "$SNAPSHOT_FILE"
15
+
16
+ # ============================================
17
+ # GIT-BASED FILE DETECTION (if available)
18
+ # ============================================
19
+ # Detect files that changed since last snapshot
20
+ if git rev-parse --git-dir > /dev/null 2>&1 && [ -f "$SNAPSHOT_FILE" ]; then
21
+ # Get current git status
22
+ CURRENT_STATUS=$(git status --porcelain 2>/dev/null || echo "")
23
+ LAST_STATUS=$(cat "$SNAPSHOT_FILE" 2>/dev/null || echo "")
24
+
25
+ # Compare and find new/modified files
26
+ while IFS= read -r line; do
27
+ if [ -z "$line" ]; then continue; fi
28
+
29
+ # Parse git status line (e.g., " M file.txt", "A file.txt")
30
+ STATUS_CODE="${line:0:2}"
31
+ FILE_PATH="${line:3}"
32
+
33
+ # Skip if this file was already in last snapshot
34
+ if echo "$LAST_STATUS" | grep -qF "$FILE_PATH"; then
35
+ # File was already modified, check if it changed further
36
+ continue
37
+ fi
38
+
39
+ # New change detected, log it
40
+ case "$STATUS_CODE" in
41
+ *M*|" M")
42
+ echo "$FILE_PATH,edit,$TIMESTAMP" >> "$FILE_LOG"
43
+ ;;
44
+ A*|"A ")
45
+ echo "$FILE_PATH,write,$TIMESTAMP" >> "$FILE_LOG"
46
+ ;;
47
+ D*|"D ")
48
+ echo "$FILE_PATH,delete,$TIMESTAMP" >> "$FILE_LOG"
49
+ ;;
50
+ esac
51
+ done <<< "$CURRENT_STATUS"
52
+
53
+ # Save current status as snapshot
54
+ echo "$CURRENT_STATUS" > "$SNAPSHOT_FILE"
55
+ elif git rev-parse --git-dir > /dev/null 2>&1; then
56
+ # First run with git, save snapshot
57
+ git status --porcelain 2>/dev/null > "$SNAPSHOT_FILE" || touch "$SNAPSHOT_FILE"
58
+ else
59
+ # No git available, mark as initialized
60
+ touch "$SNAPSHOT_FILE"
61
+ fi
62
+
63
+ # ============================================
64
+ # FILE MODIFICATION TIME TRACKING
65
+ # ============================================
66
+ # Track recently modified files in project (last 60 seconds)
67
+ if command -v find >/dev/null 2>&1; then
68
+ # Find files modified in last 60 seconds
69
+ find . -type f \
70
+ -not -path "./.git/*" \
71
+ -not -path "./node_modules/*" \
72
+ -not -path "./.claude/*" \
73
+ -not -path "./build/*" \
74
+ -not -path "./dist/*" \
75
+ -mtime -60s 2>/dev/null | while read -r file; do
76
+
77
+ # Check if already logged recently
78
+ if grep -qF "$file" "$FILE_LOG" 2>/dev/null; then
79
+ LAST_LOG=$(grep -F "$file" "$FILE_LOG" | tail -1 | cut -d',' -f3)
80
+ # Only log if more than 30 seconds since last log
81
+ if [ $((TIMESTAMP - LAST_LOG)) -gt 30 ]; then
82
+ echo "$file,edit,$TIMESTAMP" >> "$FILE_LOG"
83
+ fi
84
+ else
85
+ echo "$file,read,$TIMESTAMP" >> "$FILE_LOG"
86
+ fi
87
+ done
88
+ fi
89
+
90
+ exit 0
@@ -0,0 +1,66 @@
1
+ #!/usr/bin/env bash
2
+ # Keyword triggers - auto-suggests tools based on user prompt keywords
3
+ # Can be called standalone or integrated into other hooks
4
+
5
+ set -euo pipefail
6
+
7
+ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
8
+ TOOL_RUNNER_PATH="$HOME/.claude/cck/lib/tool-runner.sh"
9
+
10
+ if [ ! -f "$TOOL_RUNNER_PATH" ]; then
11
+ exit 0
12
+ fi
13
+
14
+ source "$TOOL_RUNNER_PATH"
15
+
16
+ USER_PROMPT="${1:-}"
17
+
18
+ if [ -z "$USER_PROMPT" ]; then
19
+ exit 0
20
+ fi
21
+
22
+ PROMPT_LOWER=$(echo "$USER_PROMPT" | tr '[:upper:]' '[:lower:]')
23
+
24
+ SUGGESTIONS_MADE=false
25
+
26
+ suggest_tool() {
27
+ local tool_name="$1"
28
+ local reason="$2"
29
+
30
+ if ! $SUGGESTIONS_MADE; then
31
+ echo ""
32
+ echo "Claude Capsule Kit - Available Tools:"
33
+ SUGGESTIONS_MADE=true
34
+ fi
35
+
36
+ echo " $tool_name - $reason"
37
+ }
38
+
39
+ if echo "$PROMPT_LOWER" | grep -qE '(depend|import|require|reference)'; then
40
+ suggest_tool "query-deps" "Query dependency relationships"
41
+ fi
42
+
43
+ if echo "$PROMPT_LOWER" | grep -qE '(circular|cycle|loop)'; then
44
+ suggest_tool "find-circular" "Find circular dependency cycles"
45
+ fi
46
+
47
+ if echo "$PROMPT_LOWER" | grep -qE '(unused|dead code|orphan|unreferenced)'; then
48
+ suggest_tool "find-dead-code" "Find potentially unused files"
49
+ fi
50
+
51
+ if echo "$PROMPT_LOWER" | grep -qE '(impact|affect|break|change.*will)'; then
52
+ suggest_tool "impact-analysis" "Analyze impact of file changes"
53
+ fi
54
+
55
+ if echo "$PROMPT_LOWER" | grep -qE '(refactor|restructure|reorganize)'; then
56
+ suggest_tool "query-deps" "Check dependencies before refactoring"
57
+ suggest_tool "impact-analysis" "Analyze refactoring impact"
58
+ fi
59
+
60
+ if $SUGGESTIONS_MADE; then
61
+ echo ""
62
+ echo " Usage: run_tool <tool-name> [args...]"
63
+ echo ""
64
+ fi
65
+
66
+ exit 0