moflo 4.9.19 → 4.9.21

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 (82) hide show
  1. package/.claude/commands/{simplify.md → flo-simplify.md} +4 -4
  2. package/.claude/guidance/shipped/moflo-agent-rules.md +172 -0
  3. package/.claude/guidance/shipped/moflo-claude-swarm-cohesion.md +73 -265
  4. package/.claude/guidance/shipped/moflo-cli-reference.md +6 -6
  5. package/.claude/guidance/shipped/moflo-core-guidance.md +66 -184
  6. package/.claude/guidance/shipped/moflo-cross-platform.md +1 -1
  7. package/.claude/guidance/shipped/moflo-error-handling.md +3 -3
  8. package/.claude/guidance/shipped/moflo-guidance-rules.md +17 -7
  9. package/.claude/guidance/shipped/moflo-memory-strategy.md +76 -182
  10. package/.claude/guidance/shipped/moflo-memorydb-maintenance.md +6 -8
  11. package/.claude/guidance/shipped/moflo-settings-injection.md +7 -9
  12. package/.claude/guidance/shipped/moflo-source-hygiene.md +5 -5
  13. package/.claude/guidance/shipped/moflo-spell-connectors.md +3 -4
  14. package/.claude/guidance/shipped/moflo-spell-custom-steps.md +3 -4
  15. package/.claude/guidance/shipped/moflo-spell-engine.md +40 -162
  16. package/.claude/guidance/shipped/moflo-spell-runner.md +134 -0
  17. package/.claude/guidance/shipped/moflo-spell-sandboxing.md +10 -57
  18. package/.claude/guidance/shipped/moflo-spell-troubleshooting.md +149 -0
  19. package/.claude/guidance/shipped/moflo-subagents.md +43 -114
  20. package/.claude/guidance/shipped/moflo-task-icons.md +4 -4
  21. package/.claude/guidance/shipped/moflo-user-facing-language.md +3 -3
  22. package/.claude/guidance/shipped/moflo-verbose-command-filtering.md +3 -3
  23. package/.claude/guidance/shipped/moflo-yaml-reference.md +4 -5
  24. package/.claude/helpers/gate.cjs +124 -14
  25. package/.claude/helpers/prompt-hook.mjs +4 -38
  26. package/.claude/helpers/simplify-classify.cjs +32 -11
  27. package/.claude/helpers/subagent-bootstrap.json +1 -1
  28. package/.claude/helpers/subagent-start.cjs +1 -1
  29. package/.claude/skills/connector-builder/SKILL.md +42 -429
  30. package/.claude/skills/connector-builder/templates/connector.md +189 -0
  31. package/.claude/skills/connector-builder/templates/step-command.md +176 -0
  32. package/.claude/skills/eldar/SKILL.md +7 -7
  33. package/.claude/skills/fl/SKILL.md +3 -3
  34. package/.claude/skills/fl/execution-modes.md +3 -3
  35. package/.claude/skills/fl/phases.md +3 -3
  36. package/.claude/skills/{simplify → flo-simplify}/SKILL.md +11 -11
  37. package/.claude/skills/guidance/SKILL.md +17 -9
  38. package/.claude/skills/memory-patterns/SKILL.md +1 -1
  39. package/.claude/skills/publish/SKILL.md +121 -36
  40. package/.claude/skills/reset-epic/SKILL.md +2 -2
  41. package/.claude/skills/spell-builder/SKILL.md +39 -226
  42. package/.claude/skills/spell-builder/architecture.md +1 -1
  43. package/.claude/skills/spell-builder/permissions.md +107 -0
  44. package/.claude/skills/spell-builder/preflight.md +101 -0
  45. package/.claude/skills/spell-schedule/SKILL.md +2 -3
  46. package/bin/gate.cjs +124 -14
  47. package/bin/prompt-hook.mjs +4 -38
  48. package/bin/session-start-launcher.mjs +66 -1
  49. package/bin/setup-project.mjs +63 -69
  50. package/bin/simplify-classify.cjs +32 -11
  51. package/dist/src/cli/commands/doctor-checks-deep.js +4 -0
  52. package/dist/src/cli/init/claudemd-generator.js +30 -33
  53. package/dist/src/cli/init/executor.js +28 -16
  54. package/dist/src/cli/init/helpers-generator.js +101 -51
  55. package/dist/src/cli/init/moflo-init.js +41 -114
  56. package/dist/src/cli/init/settings-generator.js +32 -14
  57. package/dist/src/cli/services/hook-block-hash.js +7 -2
  58. package/dist/src/cli/services/hook-wiring.js +86 -3
  59. package/dist/src/cli/services/subagent-bootstrap.js +1 -1
  60. package/dist/src/cli/version.js +1 -1
  61. package/package.json +2 -2
  62. package/scripts/post-install-bootstrap.mjs +19 -0
  63. package/.claude/guidance/shipped/moflo-session-start.md +0 -154
  64. package/.claude/guidance/shipped/moflo-spell-engine-architecture.md +0 -145
  65. package/.claude/skills/browser/SKILL.md +0 -204
  66. package/.claude/skills/github-code-review/SKILL.md +0 -1140
  67. package/.claude/skills/github-multi-repo/SKILL.md +0 -866
  68. package/.claude/skills/github-project-management/SKILL.md +0 -1272
  69. package/.claude/skills/github-release-management/SKILL.md +0 -1074
  70. package/.claude/skills/github-workflow-automation/SKILL.md +0 -1060
  71. package/.claude/skills/hive-mind-advanced/SKILL.md +0 -712
  72. package/.claude/skills/hooks-automation/SKILL.md +0 -1193
  73. package/.claude/skills/pair-programming/SKILL.md +0 -1202
  74. package/.claude/skills/performance-analysis/SKILL.md +0 -563
  75. package/.claude/skills/skill-builder/SKILL.md +0 -910
  76. package/.claude/skills/sparc-methodology/SKILL.md +0 -904
  77. package/.claude/skills/stream-chain/SKILL.md +0 -563
  78. package/.claude/skills/swarm-advanced/SKILL.md +0 -811
  79. package/.claude/skills/swarm-orchestration/SKILL.md +0 -179
  80. package/.claude/skills/verification-quality/SKILL.md +0 -649
  81. package/.claude/skills/worker-benchmarks/skill.md +0 -135
  82. package/.claude/skills/worker-integration/skill.md +0 -154
@@ -1,1193 +0,0 @@
1
- ---
2
- name: Hooks Automation
3
- description: Automated coordination, formatting, and learning from Claude Code operations using intelligent hooks with MCP integration. Includes pre/post task hooks, session management, Git integration, memory coordination, and neural pattern training for enhanced development workflows.
4
- ---
5
-
6
- # Hooks Automation
7
-
8
- Intelligent automation system that coordinates, validates, and learns from Claude Code operations through hooks integrated with MCP tools and neural pattern training.
9
-
10
- ## What This Skill Does
11
-
12
- This skill provides a comprehensive hook system that automatically manages development operations, coordinates swarm agents, maintains session state, and continuously learns from coding patterns. It enables automated agent assignment, code formatting, performance tracking, and cross-session memory persistence.
13
-
14
- **Key Capabilities:**
15
- - **Pre-Operation Hooks**: Validate, prepare, and auto-assign agents before operations
16
- - **Post-Operation Hooks**: Format, analyze, and train patterns after operations
17
- - **Session Management**: Persist state, restore context, generate summaries
18
- - **Memory Coordination**: Synchronize knowledge across swarm agents
19
- - **Git Integration**: Automated commit hooks with quality verification
20
- - **Neural Training**: Continuous learning from successful patterns
21
- - **MCP Integration**: Seamless coordination with swarm tools
22
-
23
- ## Prerequisites
24
-
25
- **Required:**
26
- - Claude Flow CLI installed (`npm install -g claude-flow@alpha`)
27
- - Claude Code with hooks enabled
28
- - `.claude/settings.json` with hook configurations
29
-
30
- **Optional:**
31
- - MCP servers configured (claude-flow, ruv-swarm, flow-nexus)
32
- - Git repository for version control
33
- - Testing framework for quality verification
34
-
35
- ## Quick Start
36
-
37
- ### Initialize Hooks System
38
-
39
- ```bash
40
- # Initialize with default hooks configuration
41
- npx claude-flow init --hooks
42
- ```
43
-
44
- This creates:
45
- - `.claude/settings.json` with pre-configured hooks
46
- - Hook command documentation in `.claude/commands/hooks/`
47
- - Default hook handlers for common operations
48
-
49
- ### Basic Hook Usage
50
-
51
- ```bash
52
- # Pre-task hook (auto-spawns agents)
53
- npx claude-flow hook pre-task --description "Implement authentication"
54
-
55
- # Post-edit hook (auto-formats and stores in memory)
56
- npx claude-flow hook post-edit --file "src/auth.js" --memory-key "auth/login"
57
-
58
- # Session end hook (saves state and metrics)
59
- npx claude-flow hook session-end --session-id "dev-session" --export-metrics
60
- ```
61
-
62
- ---
63
-
64
- ## Complete Guide
65
-
66
- ### Available Hooks
67
-
68
- #### Pre-Operation Hooks
69
-
70
- Hooks that execute BEFORE operations to prepare and validate:
71
-
72
- **pre-edit** - Validate and assign agents before file modifications
73
- ```bash
74
- npx claude-flow hook pre-edit [options]
75
-
76
- Options:
77
- --file, -f <path> File path to be edited
78
- --auto-assign-agent Automatically assign best agent (default: true)
79
- --validate-syntax Pre-validate syntax before edit
80
- --check-conflicts Check for merge conflicts
81
- --backup-file Create backup before editing
82
-
83
- Examples:
84
- npx claude-flow hook pre-edit --file "src/auth/login.js"
85
- npx claude-flow hook pre-edit -f "config/db.js" --validate-syntax
86
- npx claude-flow hook pre-edit -f "production.env" --backup-file --check-conflicts
87
- ```
88
-
89
- **Features:**
90
- - Auto agent assignment based on file type
91
- - Syntax validation to prevent broken code
92
- - Conflict detection for concurrent edits
93
- - Automatic file backups for safety
94
-
95
- **pre-bash** - Check command safety and resource requirements
96
- ```bash
97
- npx claude-flow hook pre-bash --command <cmd>
98
-
99
- Options:
100
- --command, -c <cmd> Command to validate
101
- --check-safety Verify command safety (default: true)
102
- --estimate-resources Estimate resource usage
103
- --require-confirmation Request user confirmation for risky commands
104
-
105
- Examples:
106
- npx claude-flow hook pre-bash -c "rm -rf /tmp/cache"
107
- npx claude-flow hook pre-bash --command "docker build ." --estimate-resources
108
- ```
109
-
110
- **Features:**
111
- - Command safety validation
112
- - Resource requirement estimation
113
- - Destructive command confirmation
114
- - Permission checks
115
-
116
- **pre-task** - Auto-spawn agents and prepare for complex tasks
117
- ```bash
118
- npx claude-flow hook pre-task [options]
119
-
120
- Options:
121
- --description, -d <text> Task description for context
122
- --auto-spawn-agents Automatically spawn required agents (default: true)
123
- --load-memory Load relevant memory from previous sessions
124
- --optimize-topology Select optimal swarm topology
125
- --estimate-complexity Analyze task complexity
126
-
127
- Examples:
128
- npx claude-flow hook pre-task --description "Implement user authentication"
129
- npx claude-flow hook pre-task -d "Continue API dev" --load-memory
130
- npx claude-flow hook pre-task -d "Refactor codebase" --optimize-topology
131
- ```
132
-
133
- **Features:**
134
- - Automatic agent spawning based on task analysis
135
- - Memory loading for context continuity
136
- - Topology optimization for task structure
137
- - Complexity estimation and time prediction
138
-
139
- **pre-search** - Prepare and optimize search operations
140
- ```bash
141
- npx claude-flow hook pre-search --query <query>
142
-
143
- Options:
144
- --query, -q <text> Search query
145
- --check-cache Check cache first (default: true)
146
- --optimize-query Optimize search pattern
147
-
148
- Examples:
149
- npx claude-flow hook pre-search -q "authentication middleware"
150
- ```
151
-
152
- **Features:**
153
- - Cache checking for faster results
154
- - Query optimization
155
- - Search pattern improvement
156
-
157
- #### Post-Operation Hooks
158
-
159
- Hooks that execute AFTER operations to process and learn:
160
-
161
- **post-edit** - Auto-format, validate, and update memory
162
- ```bash
163
- npx claude-flow hook post-edit [options]
164
-
165
- Options:
166
- --file, -f <path> File path that was edited
167
- --auto-format Automatically format code (default: true)
168
- --memory-key, -m <key> Store edit context in memory
169
- --train-patterns Train neural patterns from edit
170
- --validate-output Validate edited file
171
-
172
- Examples:
173
- npx claude-flow hook post-edit --file "src/components/Button.jsx"
174
- npx claude-flow hook post-edit -f "api/auth.js" --memory-key "auth/login"
175
- npx claude-flow hook post-edit -f "utils/helpers.ts" --train-patterns
176
- ```
177
-
178
- **Features:**
179
- - Language-specific auto-formatting (Prettier, Black, gofmt)
180
- - Memory storage for edit context and decisions
181
- - Neural pattern training for continuous improvement
182
- - Output validation with linting
183
-
184
- **post-bash** - Log execution and update metrics
185
- ```bash
186
- npx claude-flow hook post-bash --command <cmd>
187
-
188
- Options:
189
- --command, -c <cmd> Command that was executed
190
- --log-output Log command output (default: true)
191
- --update-metrics Update performance metrics
192
- --store-result Store result in memory
193
-
194
- Examples:
195
- npx claude-flow hook post-bash -c "npm test" --update-metrics
196
- ```
197
-
198
- **Features:**
199
- - Command execution logging
200
- - Performance metric tracking
201
- - Result storage for analysis
202
- - Error pattern detection
203
-
204
- **post-task** - Performance analysis and decision storage
205
- ```bash
206
- npx claude-flow hook post-task [options]
207
-
208
- Options:
209
- --task-id, -t <id> Task identifier for tracking
210
- --analyze-performance Generate performance metrics (default: true)
211
- --store-decisions Save task decisions to memory
212
- --export-learnings Export neural pattern learnings
213
- --generate-report Create task completion report
214
-
215
- Examples:
216
- npx claude-flow hook post-task --task-id "auth-implementation"
217
- npx claude-flow hook post-task -t "api-refactor" --analyze-performance
218
- npx claude-flow hook post-task -t "bug-fix-123" --store-decisions
219
- ```
220
-
221
- **Features:**
222
- - Execution time and token usage measurement
223
- - Decision and implementation choice recording
224
- - Neural learning pattern export
225
- - Completion report generation
226
-
227
- **post-search** - Cache results and improve patterns
228
- ```bash
229
- npx claude-flow hook post-search --query <query> --results <path>
230
-
231
- Options:
232
- --query, -q <text> Original search query
233
- --results, -r <path> Results file path
234
- --cache-results Cache for future use (default: true)
235
- --train-patterns Improve search patterns
236
-
237
- Examples:
238
- npx claude-flow hook post-search -q "auth" -r "results.json" --train-patterns
239
- ```
240
-
241
- **Features:**
242
- - Result caching for faster subsequent searches
243
- - Search pattern improvement
244
- - Relevance scoring
245
-
246
- #### MCP Integration Hooks
247
-
248
- Hooks that coordinate with MCP swarm tools:
249
-
250
- **mcp-initialized** - Persist swarm configuration
251
- ```bash
252
- npx claude-flow hook mcp-initialized --swarm-id <id>
253
-
254
- Features:
255
- - Save swarm topology and configuration
256
- - Store agent roster in memory
257
- - Initialize coordination namespace
258
- ```
259
-
260
- **agent-spawned** - Update agent roster and memory
261
- ```bash
262
- npx claude-flow hook agent-spawned --agent-id <id> --type <type>
263
-
264
- Features:
265
- - Register agent in coordination memory
266
- - Update agent roster
267
- - Initialize agent-specific memory namespace
268
- ```
269
-
270
- **task-orchestrated** - Monitor task progress
271
- ```bash
272
- npx claude-flow hook task-orchestrated --task-id <id>
273
-
274
- Features:
275
- - Track task progress through memory
276
- - Monitor agent assignments
277
- - Update coordination state
278
- ```
279
-
280
- **neural-trained** - Save pattern improvements
281
- ```bash
282
- npx claude-flow hook neural-trained --pattern <name>
283
-
284
- Features:
285
- - Export trained neural patterns
286
- - Update coordination models
287
- - Share learning across agents
288
- ```
289
-
290
- #### Memory Coordination Hooks
291
-
292
- **memory-write** - Triggered when agents write to coordination memory
293
- ```bash
294
- Features:
295
- - Validate memory key format
296
- - Update cross-agent indexes
297
- - Trigger dependent hooks
298
- - Notify subscribed agents
299
- ```
300
-
301
- **memory-read** - Triggered when agents read from coordination memory
302
- ```bash
303
- Features:
304
- - Log access patterns
305
- - Update popularity metrics
306
- - Preload related data
307
- - Track usage statistics
308
- ```
309
-
310
- **memory-sync** - Synchronize memory across swarm agents
311
- ```bash
312
- npx claude-flow hook memory-sync --namespace <ns>
313
-
314
- Features:
315
- - Sync memory state across agents
316
- - Resolve conflicts
317
- - Propagate updates
318
- - Maintain consistency
319
- ```
320
-
321
- #### Session Hooks
322
-
323
- **session-start** - Initialize new session
324
- ```bash
325
- npx claude-flow hook session-start --session-id <id>
326
-
327
- Options:
328
- --session-id, -s <id> Session identifier
329
- --load-context Load context from previous session
330
- --init-agents Initialize required agents
331
-
332
- Features:
333
- - Create session directory
334
- - Initialize metrics tracking
335
- - Load previous context
336
- - Set up coordination namespace
337
- ```
338
-
339
- **session-restore** - Load previous session state
340
- ```bash
341
- npx claude-flow hook session-restore --session-id <id>
342
-
343
- Options:
344
- --session-id, -s <id> Session to restore
345
- --restore-memory Restore memory state (default: true)
346
- --restore-agents Restore agent configurations
347
-
348
- Examples:
349
- npx claude-flow hook session-restore --session-id "swarm-20241019"
350
- npx claude-flow hook session-restore -s "feature-auth" --restore-memory
351
- ```
352
-
353
- **Features:**
354
- - Load previous session context
355
- - Restore memory state and decisions
356
- - Reconfigure agents to previous state
357
- - Resume in-progress tasks
358
-
359
- **session-end** - Cleanup and persist session state
360
- ```bash
361
- npx claude-flow hook session-end [options]
362
-
363
- Options:
364
- --session-id, -s <id> Session identifier to end
365
- --save-state Save current session state (default: true)
366
- --export-metrics Export session metrics
367
- --generate-summary Create session summary
368
- --cleanup-temp Remove temporary files
369
-
370
- Examples:
371
- npx claude-flow hook session-end --session-id "dev-session-2024"
372
- npx claude-flow hook session-end -s "feature-auth" --export-metrics --generate-summary
373
- npx claude-flow hook session-end -s "quick-fix" --cleanup-temp
374
- ```
375
-
376
- **Features:**
377
- - Save current context and progress
378
- - Export session metrics (duration, commands, tokens, files)
379
- - Generate work summary with decisions and next steps
380
- - Cleanup temporary files and optimize storage
381
-
382
- **notify** - Custom notifications with swarm status
383
- ```bash
384
- npx claude-flow hook notify --message <msg>
385
-
386
- Options:
387
- --message, -m <text> Notification message
388
- --level <level> Notification level (info|warning|error)
389
- --swarm-status Include swarm status (default: true)
390
- --broadcast Send to all agents
391
-
392
- Examples:
393
- npx claude-flow hook notify -m "Task completed" --level info
394
- npx claude-flow hook notify -m "Critical error" --level error --broadcast
395
- ```
396
-
397
- **Features:**
398
- - Send notifications to coordination system
399
- - Include swarm status and metrics
400
- - Broadcast to all agents
401
- - Log important events
402
-
403
- ### Configuration
404
-
405
- #### Basic Configuration
406
-
407
- Edit `.claude/settings.json` to configure hooks:
408
-
409
- ```json
410
- {
411
- "hooks": {
412
- "PreToolUse": [
413
- {
414
- "matcher": "^(Write|Edit|MultiEdit)$",
415
- "hooks": [{
416
- "type": "command",
417
- "command": "npx claude-flow hook pre-edit --file '${tool.params.file_path}' --memory-key 'swarm/editor/current'"
418
- }]
419
- },
420
- {
421
- "matcher": "^Bash$",
422
- "hooks": [{
423
- "type": "command",
424
- "command": "npx claude-flow hook pre-bash --command '${tool.params.command}'"
425
- }]
426
- }
427
- ],
428
- "PostToolUse": [
429
- {
430
- "matcher": "^(Write|Edit|MultiEdit)$",
431
- "hooks": [{
432
- "type": "command",
433
- "command": "npx claude-flow hook post-edit --file '${tool.params.file_path}' --memory-key 'swarm/editor/complete' --auto-format --train-patterns"
434
- }]
435
- },
436
- {
437
- "matcher": "^Bash$",
438
- "hooks": [{
439
- "type": "command",
440
- "command": "npx claude-flow hook post-bash --command '${tool.params.command}' --update-metrics"
441
- }]
442
- }
443
- ]
444
- }
445
- }
446
- ```
447
-
448
- #### Advanced Configuration
449
-
450
- Complete hook configuration with all features:
451
-
452
- ```json
453
- {
454
- "hooks": {
455
- "enabled": true,
456
- "debug": false,
457
- "timeout": 5000,
458
-
459
- "PreToolUse": [
460
- {
461
- "matcher": "^(Write|Edit|MultiEdit)$",
462
- "hooks": [
463
- {
464
- "type": "command",
465
- "command": "npx claude-flow hook pre-edit --file '${tool.params.file_path}' --auto-assign-agent --validate-syntax",
466
- "timeout": 3000,
467
- "continueOnError": true
468
- }
469
- ]
470
- },
471
- {
472
- "matcher": "^Task$",
473
- "hooks": [
474
- {
475
- "type": "command",
476
- "command": "npx claude-flow hook pre-task --description '${tool.params.task}' --auto-spawn-agents --load-memory",
477
- "async": true
478
- }
479
- ]
480
- },
481
- {
482
- "matcher": "^Grep$",
483
- "hooks": [
484
- {
485
- "type": "command",
486
- "command": "npx claude-flow hook pre-search --query '${tool.params.pattern}' --check-cache"
487
- }
488
- ]
489
- }
490
- ],
491
-
492
- "PostToolUse": [
493
- {
494
- "matcher": "^(Write|Edit|MultiEdit)$",
495
- "hooks": [
496
- {
497
- "type": "command",
498
- "command": "npx claude-flow hook post-edit --file '${tool.params.file_path}' --memory-key 'edits/${tool.params.file_path}' --auto-format --train-patterns",
499
- "async": true
500
- }
501
- ]
502
- },
503
- {
504
- "matcher": "^Task$",
505
- "hooks": [
506
- {
507
- "type": "command",
508
- "command": "npx claude-flow hook post-task --task-id '${result.task_id}' --analyze-performance --store-decisions --export-learnings",
509
- "async": true
510
- }
511
- ]
512
- },
513
- {
514
- "matcher": "^Grep$",
515
- "hooks": [
516
- {
517
- "type": "command",
518
- "command": "npx claude-flow hook post-search --query '${tool.params.pattern}' --cache-results --train-patterns"
519
- }
520
- ]
521
- }
522
- ],
523
-
524
- "SessionStart": [
525
- {
526
- "hooks": [
527
- {
528
- "type": "command",
529
- "command": "npx claude-flow hook session-start --session-id '${session.id}' --load-context"
530
- }
531
- ]
532
- }
533
- ],
534
-
535
- "SessionEnd": [
536
- {
537
- "hooks": [
538
- {
539
- "type": "command",
540
- "command": "npx claude-flow hook session-end --session-id '${session.id}' --export-metrics --generate-summary --cleanup-temp"
541
- }
542
- ]
543
- }
544
- ]
545
- }
546
- }
547
- ```
548
-
549
- #### Protected File Patterns
550
-
551
- Add protection for sensitive files:
552
-
553
- ```json
554
- {
555
- "hooks": {
556
- "PreToolUse": [
557
- {
558
- "matcher": "^(Write|Edit|MultiEdit)$",
559
- "hooks": [
560
- {
561
- "type": "command",
562
- "command": "npx claude-flow hook check-protected --file '${tool.params.file_path}'"
563
- }
564
- ]
565
- }
566
- ]
567
- }
568
- }
569
- ```
570
-
571
- #### Automatic Testing
572
-
573
- Run tests after file modifications:
574
-
575
- ```json
576
- {
577
- "hooks": {
578
- "PostToolUse": [
579
- {
580
- "matcher": "^Write$",
581
- "hooks": [
582
- {
583
- "type": "command",
584
- "command": "test -f '${tool.params.file_path%.js}.test.js' && npm test '${tool.params.file_path%.js}.test.js'",
585
- "continueOnError": true
586
- }
587
- ]
588
- }
589
- ]
590
- }
591
- }
592
- ```
593
-
594
- ### MCP Tool Integration
595
-
596
- Hooks automatically integrate with MCP tools for coordination:
597
-
598
- #### Pre-Task Hook with Agent Spawning
599
-
600
- ```javascript
601
- // Hook command
602
- npx claude-flow hook pre-task --description "Build REST API"
603
-
604
- // Internally calls MCP tools:
605
- mcp__moflo__agent_spawn {
606
- type: "backend-dev",
607
- capabilities: ["api", "database", "testing"]
608
- }
609
-
610
- mcp__moflo__memory_store {
611
- key: "swarm/task/api-build/context",
612
- namespace: "coordination",
613
- value: JSON.stringify({
614
- description: "Build REST API",
615
- agents: ["backend-dev"],
616
- started: Date.now()
617
- })
618
- }
619
- ```
620
-
621
- #### Post-Edit Hook with Memory Storage
622
-
623
- ```javascript
624
- // Hook command
625
- npx claude-flow hook post-edit --file "api/auth.js"
626
-
627
- // Internally calls MCP tools:
628
- mcp__moflo__memory_store {
629
- key: "swarm/edits/api/auth.js",
630
- namespace: "coordination",
631
- value: JSON.stringify({
632
- file: "api/auth.js",
633
- timestamp: Date.now(),
634
- changes: { added: 45, removed: 12 },
635
- formatted: true,
636
- linted: true
637
- })
638
- }
639
-
640
- mcp__moflo__neural_train {
641
- pattern_type: "coordination",
642
- training_data: { /* edit patterns */ }
643
- }
644
- ```
645
-
646
- #### Session End Hook with State Persistence
647
-
648
- ```javascript
649
- // Hook command
650
- npx claude-flow hook session-end --session-id "dev-2024"
651
-
652
- // Internally calls MCP tools:
653
-
654
- mcp__moflo__swarm_status {
655
- swarmId: "current"
656
- }
657
-
658
- // Generates metrics and summary
659
- ```
660
-
661
- ### Memory Coordination Protocol
662
-
663
- All hooks follow a standardized memory coordination pattern:
664
-
665
- #### Three-Phase Memory Protocol
666
-
667
- **Phase 1: STATUS** - Hook starts
668
- ```javascript
669
- mcp__moflo__memory_store {
670
- key: "swarm/hooks/pre-edit/status",
671
- namespace: "coordination",
672
- value: JSON.stringify({
673
- status: "running",
674
- hook: "pre-edit",
675
- file: "src/auth.js",
676
- timestamp: Date.now()
677
- })
678
- }
679
- ```
680
-
681
- **Phase 2: PROGRESS** - Hook processes
682
- ```javascript
683
- mcp__moflo__memory_store {
684
- key: "swarm/hooks/pre-edit/progress",
685
- namespace: "coordination",
686
- value: JSON.stringify({
687
- progress: 50,
688
- action: "validating syntax",
689
- file: "src/auth.js"
690
- })
691
- }
692
- ```
693
-
694
- **Phase 3: COMPLETE** - Hook finishes
695
- ```javascript
696
- mcp__moflo__memory_store {
697
- key: "swarm/hooks/pre-edit/complete",
698
- namespace: "coordination",
699
- value: JSON.stringify({
700
- status: "complete",
701
- result: "success",
702
- agent_assigned: "backend-dev",
703
- syntax_valid: true,
704
- backup_created: true
705
- })
706
- }
707
- ```
708
-
709
- ### Hook Response Format
710
-
711
- Hooks return JSON responses to control operation flow:
712
-
713
- #### Continue Response
714
- ```json
715
- {
716
- "continue": true,
717
- "reason": "All validations passed",
718
- "metadata": {
719
- "agent_assigned": "backend-dev",
720
- "syntax_valid": true,
721
- "file": "src/auth.js"
722
- }
723
- }
724
- ```
725
-
726
- #### Block Response
727
- ```json
728
- {
729
- "continue": false,
730
- "reason": "Protected file - manual review required",
731
- "metadata": {
732
- "file": ".env.production",
733
- "protection_level": "high",
734
- "requires": "manual_approval"
735
- }
736
- }
737
- ```
738
-
739
- #### Warning Response
740
- ```json
741
- {
742
- "continue": true,
743
- "reason": "Syntax valid but complexity high",
744
- "warnings": [
745
- "Cyclomatic complexity: 15 (threshold: 10)",
746
- "Consider refactoring for better maintainability"
747
- ],
748
- "metadata": {
749
- "complexity": 15,
750
- "threshold": 10
751
- }
752
- }
753
- ```
754
-
755
- ### Git Integration
756
-
757
- Hooks can integrate with Git operations for quality control:
758
-
759
- #### Pre-Commit Hook
760
- ```bash
761
- # Add to .git/hooks/pre-commit or use husky
762
-
763
- #!/bin/bash
764
- # Run quality checks before commit
765
-
766
- # Get staged files
767
- FILES=$(git diff --cached --name-only --diff-filter=ACM)
768
-
769
- for FILE in $FILES; do
770
- # Run pre-edit hook for validation
771
- npx claude-flow hook pre-edit --file "$FILE" --validate-syntax
772
-
773
- if [ $? -ne 0 ]; then
774
- echo "Validation failed for $FILE"
775
- exit 1
776
- fi
777
-
778
- # Run post-edit hook for formatting
779
- npx claude-flow hook post-edit --file "$FILE" --auto-format
780
- done
781
-
782
- # Run tests
783
- npm test
784
-
785
- exit $?
786
- ```
787
-
788
- #### Post-Commit Hook
789
- ```bash
790
- # Add to .git/hooks/post-commit
791
-
792
- #!/bin/bash
793
- # Track commit metrics
794
-
795
- COMMIT_HASH=$(git rev-parse HEAD)
796
- COMMIT_MSG=$(git log -1 --pretty=%B)
797
-
798
- npx claude-flow hook notify \
799
- --message "Commit completed: $COMMIT_MSG" \
800
- --level info \
801
- --swarm-status
802
- ```
803
-
804
- #### Pre-Push Hook
805
- ```bash
806
- # Add to .git/hooks/pre-push
807
-
808
- #!/bin/bash
809
- # Quality gate before push
810
-
811
- # Run full test suite
812
- npm run test:all
813
-
814
- # Run quality checks
815
- npx claude-flow hook session-end \
816
- --generate-report \
817
- --export-metrics
818
-
819
- # Verify quality thresholds
820
- TRUTH_SCORE=$(npx claude-flow metrics score --format json | jq -r '.truth_score')
821
-
822
- if (( $(echo "$TRUTH_SCORE < 0.95" | bc -l) )); then
823
- echo "Truth score below threshold: $TRUTH_SCORE < 0.95"
824
- exit 1
825
- fi
826
-
827
- exit 0
828
- ```
829
-
830
- ### Agent Coordination Workflow
831
-
832
- How agents use hooks for coordination:
833
-
834
- #### Agent Workflow Example
835
-
836
- ```bash
837
- # Agent 1: Backend Developer
838
- # STEP 1: Pre-task preparation
839
- npx claude-flow hook pre-task \
840
- --description "Implement user authentication API" \
841
- --auto-spawn-agents \
842
- --load-memory
843
-
844
- # STEP 2: Work begins - pre-edit validation
845
- npx claude-flow hook pre-edit \
846
- --file "api/auth.js" \
847
- --auto-assign-agent \
848
- --validate-syntax
849
-
850
- # STEP 3: Edit file (via Claude Code Edit tool)
851
- # ... code changes ...
852
-
853
- # STEP 4: Post-edit processing
854
- npx claude-flow hook post-edit \
855
- --file "api/auth.js" \
856
- --memory-key "swarm/backend/auth-api" \
857
- --auto-format \
858
- --train-patterns
859
-
860
- # STEP 5: Notify coordination system
861
- npx claude-flow hook notify \
862
- --message "Auth API implementation complete" \
863
- --swarm-status \
864
- --broadcast
865
-
866
- # STEP 6: Task completion
867
- npx claude-flow hook post-task \
868
- --task-id "auth-api" \
869
- --analyze-performance \
870
- --store-decisions \
871
- --export-learnings
872
- ```
873
-
874
- ```bash
875
- # Agent 2: Test Engineer (receives notification)
876
- # STEP 1: Check memory for API details
877
- npx claude-flow hook session-restore \
878
- --session-id "swarm-current" \
879
- --restore-memory
880
-
881
- # Memory contains: swarm/backend/auth-api with implementation details
882
-
883
- # STEP 2: Generate tests
884
- npx claude-flow hook pre-task \
885
- --description "Write tests for auth API" \
886
- --load-memory
887
-
888
- # STEP 3: Create test file
889
- npx claude-flow hook post-edit \
890
- --file "api/auth.test.js" \
891
- --memory-key "swarm/testing/auth-api-tests" \
892
- --train-patterns
893
-
894
- # STEP 4: Share test results
895
- npx claude-flow hook notify \
896
- --message "Auth API tests complete - 100% coverage" \
897
- --broadcast
898
- ```
899
-
900
- ### Custom Hook Creation
901
-
902
- Create custom hooks for specific workflows:
903
-
904
- #### Custom Hook Template
905
-
906
- ```javascript
907
- // .claude/hooks/custom-quality-check.js
908
-
909
- module.exports = {
910
- name: 'custom-quality-check',
911
- type: 'pre',
912
- matcher: /\.(ts|js)$/,
913
-
914
- async execute(context) {
915
- const { file, content } = context;
916
-
917
- // Custom validation logic
918
- const complexity = await analyzeComplexity(content);
919
- const securityIssues = await scanSecurity(content);
920
-
921
- // Store in memory
922
- await storeInMemory({
923
- key: `quality/${file}`,
924
- value: { complexity, securityIssues }
925
- });
926
-
927
- // Return decision
928
- if (complexity > 15 || securityIssues.length > 0) {
929
- return {
930
- continue: false,
931
- reason: 'Quality checks failed',
932
- warnings: [
933
- `Complexity: ${complexity} (max: 15)`,
934
- `Security issues: ${securityIssues.length}`
935
- ]
936
- };
937
- }
938
-
939
- return {
940
- continue: true,
941
- reason: 'Quality checks passed',
942
- metadata: { complexity, securityIssues: 0 }
943
- };
944
- }
945
- };
946
- ```
947
-
948
- #### Register Custom Hook
949
-
950
- ```json
951
- {
952
- "hooks": {
953
- "PreToolUse": [
954
- {
955
- "matcher": "^(Write|Edit)$",
956
- "hooks": [
957
- {
958
- "type": "script",
959
- "script": ".claude/hooks/custom-quality-check.js"
960
- }
961
- ]
962
- }
963
- ]
964
- }
965
- }
966
- ```
967
-
968
- ### Real-World Examples
969
-
970
- #### Example 1: Full-Stack Development Workflow
971
-
972
- ```bash
973
- # Session start - initialize coordination
974
- npx claude-flow hook session-start --session-id "fullstack-feature"
975
-
976
- # Pre-task planning
977
- npx claude-flow hook pre-task \
978
- --description "Build user profile feature - frontend + backend + tests" \
979
- --auto-spawn-agents \
980
- --optimize-topology
981
-
982
- # Backend work
983
- npx claude-flow hook pre-edit --file "api/profile.js"
984
- # ... implement backend ...
985
- npx claude-flow hook post-edit \
986
- --file "api/profile.js" \
987
- --memory-key "profile/backend" \
988
- --train-patterns
989
-
990
- # Frontend work (reads backend details from memory)
991
- npx claude-flow hook pre-edit --file "components/Profile.jsx"
992
- # ... implement frontend ...
993
- npx claude-flow hook post-edit \
994
- --file "components/Profile.jsx" \
995
- --memory-key "profile/frontend" \
996
- --train-patterns
997
-
998
- # Testing (reads both backend and frontend from memory)
999
- npx claude-flow hook pre-task \
1000
- --description "Test profile feature" \
1001
- --load-memory
1002
-
1003
- # Session end - export everything
1004
- npx claude-flow hook session-end \
1005
- --session-id "fullstack-feature" \
1006
- --export-metrics \
1007
- --generate-summary
1008
- ```
1009
-
1010
- #### Example 2: Debugging with Hooks
1011
-
1012
- ```bash
1013
- # Start debugging session
1014
- npx claude-flow hook session-start --session-id "debug-memory-leak"
1015
-
1016
- # Pre-task: analyze issue
1017
- npx claude-flow hook pre-task \
1018
- --description "Debug memory leak in event handlers" \
1019
- --load-memory \
1020
- --estimate-complexity
1021
-
1022
- # Search for event emitters
1023
- npx claude-flow hook pre-search --query "EventEmitter"
1024
- # ... search executes ...
1025
- npx claude-flow hook post-search \
1026
- --query "EventEmitter" \
1027
- --cache-results
1028
-
1029
- # Fix the issue
1030
- npx claude-flow hook pre-edit \
1031
- --file "services/events.js" \
1032
- --backup-file
1033
- # ... fix code ...
1034
- npx claude-flow hook post-edit \
1035
- --file "services/events.js" \
1036
- --memory-key "debug/memory-leak-fix" \
1037
- --validate-output
1038
-
1039
- # Verify fix
1040
- npx claude-flow hook post-task \
1041
- --task-id "memory-leak-fix" \
1042
- --analyze-performance \
1043
- --generate-report
1044
-
1045
- # End session
1046
- npx claude-flow hook session-end \
1047
- --session-id "debug-memory-leak" \
1048
- --export-metrics
1049
- ```
1050
-
1051
- #### Example 3: Multi-Agent Refactoring
1052
-
1053
- ```bash
1054
- # Initialize swarm for refactoring
1055
- npx claude-flow hook pre-task \
1056
- --description "Refactor legacy codebase to modern patterns" \
1057
- --auto-spawn-agents \
1058
- --optimize-topology
1059
-
1060
- # Agent 1: Code Analyzer
1061
- npx claude-flow hook pre-task --description "Analyze code complexity"
1062
- # ... analysis ...
1063
- npx claude-flow hook post-task \
1064
- --task-id "analysis" \
1065
- --store-decisions
1066
-
1067
- # Agent 2: Refactoring (reads analysis from memory)
1068
- npx claude-flow hook session-restore \
1069
- --session-id "swarm-refactor" \
1070
- --restore-memory
1071
-
1072
- for file in src/**/*.js; do
1073
- npx claude-flow hook pre-edit --file "$file" --backup-file
1074
- # ... refactor ...
1075
- npx claude-flow hook post-edit \
1076
- --file "$file" \
1077
- --memory-key "refactor/$file" \
1078
- --auto-format \
1079
- --train-patterns
1080
- done
1081
-
1082
- # Agent 3: Testing (reads refactored code from memory)
1083
- npx claude-flow hook pre-task \
1084
- --description "Generate tests for refactored code" \
1085
- --load-memory
1086
-
1087
- # Broadcast completion
1088
- npx claude-flow hook notify \
1089
- --message "Refactoring complete - all tests passing" \
1090
- --broadcast
1091
- ```
1092
-
1093
- ### Performance Tips
1094
-
1095
- 1. **Keep Hooks Lightweight** - Target < 100ms execution time
1096
- 2. **Use Async for Heavy Operations** - Don't block the main flow
1097
- 3. **Cache Aggressively** - Store frequently accessed data
1098
- 4. **Batch Related Operations** - Combine multiple actions
1099
- 5. **Use Memory Wisely** - Set appropriate TTLs
1100
- 6. **Monitor Hook Performance** - Track execution times
1101
- 7. **Parallelize When Possible** - Run independent hooks concurrently
1102
-
1103
- ### Debugging Hooks
1104
-
1105
- Enable debug mode for troubleshooting:
1106
-
1107
- ```bash
1108
- # Enable debug output
1109
- export CLAUDE_FLOW_DEBUG=true
1110
-
1111
- # Test specific hook with verbose output
1112
- npx claude-flow hook pre-edit --file "test.js" --debug
1113
-
1114
- # Check hook execution logs
1115
- cat .moflo/logs/hooks-$(date +%Y-%m-%d).log
1116
-
1117
- # Validate configuration
1118
- npx claude-flow hook validate-config
1119
- ```
1120
-
1121
- ### Benefits
1122
-
1123
- - **Automatic Agent Assignment**: Right agent for every file type
1124
- - **Consistent Code Formatting**: Language-specific formatters
1125
- - **Continuous Learning**: Neural patterns improve over time
1126
- - **Cross-Session Memory**: Context persists between sessions
1127
- - **Performance Tracking**: Comprehensive metrics and analytics
1128
- - **Automatic Coordination**: Agents sync via memory
1129
- - **Smart Agent Spawning**: Task-based agent selection
1130
- - **Quality Gates**: Pre-commit validation and verification
1131
- - **Error Prevention**: Syntax validation before edits
1132
- - **Knowledge Sharing**: Decisions stored and shared
1133
- - **Reduced Manual Work**: Automation of repetitive tasks
1134
- - **Better Collaboration**: Seamless multi-agent coordination
1135
-
1136
- ### Best Practices
1137
-
1138
- 1. **Configure Hooks Early** - Set up during project initialization
1139
- 2. **Use Memory Keys Strategically** - Organize with clear namespaces
1140
- 3. **Enable Auto-Formatting** - Maintain code consistency
1141
- 4. **Train Patterns Continuously** - Learn from successful operations
1142
- 5. **Monitor Performance** - Track hook execution times
1143
- 6. **Validate Configuration** - Test hooks before production use
1144
- 7. **Document Custom Hooks** - Maintain hook documentation
1145
- 8. **Set Appropriate Timeouts** - Prevent hanging operations
1146
- 9. **Handle Errors Gracefully** - Use continueOnError when appropriate
1147
- 10. **Review Metrics Regularly** - Optimize based on usage patterns
1148
-
1149
- ### Troubleshooting
1150
-
1151
- #### Hooks Not Executing
1152
- - Verify `.claude/settings.json` syntax
1153
- - Check hook matcher patterns
1154
- - Enable debug mode
1155
- - Review permission settings
1156
- - Ensure claude-flow CLI is in PATH
1157
-
1158
- #### Hook Timeouts
1159
- - Increase timeout values in configuration
1160
- - Make hooks asynchronous for heavy operations
1161
- - Optimize hook logic
1162
- - Check network connectivity for MCP tools
1163
-
1164
- #### Memory Issues
1165
- - Set appropriate TTLs for memory keys
1166
- - Clean up old memory entries
1167
- - Use memory namespaces effectively
1168
- - Monitor memory usage
1169
-
1170
- #### Performance Problems
1171
- - Profile hook execution times
1172
- - Use caching for repeated operations
1173
- - Batch operations when possible
1174
- - Reduce hook complexity
1175
-
1176
- ### Related Commands
1177
-
1178
- - `npx claude-flow init --hooks` - Initialize hooks system
1179
- - `npx claude-flow hook --list` - List available hooks
1180
- - `npx claude-flow hook --test <hook>` - Test specific hook
1181
- - `npx claude-flow memory usage` - Manage memory
1182
- - `npx claude-flow agent spawn` - Spawn agents
1183
- - `npx claude-flow swarm init` - Initialize swarm
1184
-
1185
- ### Integration with Other Skills
1186
-
1187
- This skill works seamlessly with:
1188
- - **SPARC Methodology** - Hooks enhance SPARC workflows
1189
- - **Pair Programming** - Automated quality in pairing sessions
1190
- - **Verification Quality** - Truth-score validation in hooks
1191
- - **GitHub Workflows** - Git integration for commits/PRs
1192
- - **Performance Analysis** - Metrics collection in hooks
1193
- - **Swarm Advanced** - Multi-agent coordination via hooks