claude-flow-novice 1.3.0 → 1.3.2

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 (305) hide show
  1. package/.claude-flow-novice/preferences/generation.json +147 -0
  2. package/.claude-flow-novice/preferences/language-configs/javascript.json +51 -0
  3. package/.claude-flow-novice/preferences/language-configs/python.json +50 -0
  4. package/.claude-flow-novice/preferences/language-configs/rust.json +237 -0
  5. package/.claude-flow-novice/preferences/language-configs/typescript.json +54 -0
  6. package/.claude-flow-novice/preferences/project-local.json +91 -0
  7. package/.claude-flow-novice/preferences/resource-delegation.json +120 -0
  8. package/.claude-flow-novice/preferences/team-shared.json +195 -0
  9. package/.claude-flow-novice/preferences/user-global.json +247 -0
  10. package/.claude-flow-novice/templates/claude-md-templates/CLAUDE-JAVASCRIPT.md +769 -0
  11. package/.claude-flow-novice/templates/claude-md-templates/CLAUDE-PYTHON.md +1214 -0
  12. package/.claude-flow-novice/templates/claude-md-templates/CLAUDE-RUST.md +475 -0
  13. package/.claude-flow-novice/templates/claude-md-templates/CLAUDE-TYPESCRIPT.md +851 -0
  14. package/.claude-flow-novice/templates/claude-md-templates/README.md +263 -0
  15. package/CLAUDE.md +81 -0
  16. package/README-NPM.md +0 -0
  17. package/package.json +11 -7
  18. package/scripts/build/README.md +167 -0
  19. package/scripts/build/build-config.js +27 -0
  20. package/scripts/build/build-prompt-copier.sh +30 -0
  21. package/scripts/build/performance-monitor.js +869 -0
  22. package/scripts/build/prepare-publish.js +150 -0
  23. package/scripts/build/typescript-fixer.js +621 -0
  24. package/scripts/build/unified-builder.sh +428 -0
  25. package/scripts/build/update-bin-version.js +32 -0
  26. package/scripts/dev/README.md +264 -0
  27. package/scripts/dev/claude-flow-wrapper.sh +35 -0
  28. package/scripts/dev/claude-monitor.py +419 -0
  29. package/scripts/dev/claude-sparc.sh +562 -0
  30. package/scripts/dev/claude-wrapper.sh +17 -0
  31. package/scripts/dev/demo-phase3-compliance.js +172 -0
  32. package/scripts/dev/demo-task-system.ts +224 -0
  33. package/scripts/dev/deployment-validator.js +315 -0
  34. package/scripts/dev/spawn-claude-terminal.sh +32 -0
  35. package/scripts/dev/start-portal.sh +506 -0
  36. package/scripts/dev/start-web-ui.js +15 -0
  37. package/scripts/dev/stop-portal.sh +311 -0
  38. package/scripts/dev/validate-examples.ts +288 -0
  39. package/scripts/dev/validate-phase2.cjs +451 -0
  40. package/scripts/dev/validate-phase2.js +785 -0
  41. package/scripts/dev/validate-phase3.cjs +208 -0
  42. package/scripts/dev/validate-security-remediation.js +1 -0
  43. package/scripts/legacy/README.md +272 -0
  44. package/scripts/legacy/batch-fix-ts.sh +54 -0
  45. package/scripts/legacy/build-migration.sh +105 -0
  46. package/scripts/legacy/build-monitor.js +209 -0
  47. package/scripts/legacy/build-with-filter.sh +84 -0
  48. package/scripts/legacy/build-workaround.sh +71 -0
  49. package/scripts/legacy/fix-ts-advanced.js +358 -0
  50. package/scripts/legacy/fix-ts-final.sh +50 -0
  51. package/scripts/legacy/fix-ts-targeted.sh +49 -0
  52. package/scripts/legacy/fix-typescript-errors.js +305 -0
  53. package/scripts/legacy/force-build.sh +63 -0
  54. package/scripts/legacy/optimize-performance.js +400 -0
  55. package/scripts/legacy/performance-monitor.js +263 -0
  56. package/scripts/legacy/performance-monitoring.js +532 -0
  57. package/scripts/legacy/performance-test-runner.js +645 -0
  58. package/scripts/legacy/quick-fix-ts.js +281 -0
  59. package/scripts/legacy/safe-build.sh +63 -0
  60. package/scripts/migration/README.md +434 -0
  61. package/scripts/migration/install-arm64.js +78 -0
  62. package/scripts/migration/install.js +83 -0
  63. package/scripts/migration/migrate-hooks.js +173 -0
  64. package/scripts/migration/migration-examples.ts +318 -0
  65. package/scripts/optimization/build-optimizer.js +438 -0
  66. package/scripts/optimization/config-validator.js +761 -0
  67. package/scripts/optimization/test-optimization.js +432 -0
  68. package/scripts/optimization/unified-activation.js +839 -0
  69. package/scripts/performance/ACTIVATION_COMMANDS.md +292 -0
  70. package/scripts/performance/sqlite-enhanced-activation.sh +583 -0
  71. package/scripts/performance/test-enhanced-backend.sh +504 -0
  72. package/scripts/performance-test-runner.js +698 -0
  73. package/scripts/security/README.md +339 -0
  74. package/scripts/security/install-git-hooks.sh +132 -0
  75. package/scripts/security/ruv-swarm-safe.js +74 -0
  76. package/scripts/test/README.md +236 -0
  77. package/scripts/test/check-links.ts +274 -0
  78. package/scripts/test/check-performance-regression.ts +168 -0
  79. package/scripts/test/coverage-report.ts +692 -0
  80. package/scripts/test/generate-swarm-tests.js +633 -0
  81. package/scripts/test/integration-test-validation.cjs +253 -0
  82. package/scripts/test/load-test-swarm.js +576 -0
  83. package/scripts/test/run-phase3-compliance-tests.js +427 -0
  84. package/scripts/test/test-batch-tasks.ts +29 -0
  85. package/scripts/test/test-byzantine-resolution.js +246 -0
  86. package/scripts/test/test-claude-spawn-options.sh +63 -0
  87. package/scripts/test/test-cli-wizard.js +331 -0
  88. package/scripts/test/test-comprehensive.js +401 -0
  89. package/scripts/test/test-coordination-features.ts +238 -0
  90. package/scripts/test/test-fallback-systems.js +276 -0
  91. package/scripts/test/test-init-command.ts +302 -0
  92. package/scripts/test/test-mcp.ts +251 -0
  93. package/scripts/test/test-runner.ts +568 -0
  94. package/scripts/test/test-swarm-integration.sh +92 -0
  95. package/scripts/test/test-swarm.ts +142 -0
  96. package/scripts/test/validation-summary.ts +408 -0
  97. package/scripts/utils/README.md +261 -0
  98. package/scripts/utils/clean-build-artifacts.sh +94 -0
  99. package/scripts/utils/cleanup-root.sh +69 -0
  100. package/scripts/utils/fix-cliffy-imports.js +307 -0
  101. package/scripts/utils/fix-duplicate-imports.js +114 -0
  102. package/scripts/utils/fix-error-handling.cjs +70 -0
  103. package/scripts/utils/fix-import-paths.js +104 -0
  104. package/scripts/utils/fix-imports.js +116 -0
  105. package/scripts/utils/fix-shebang.js +78 -0
  106. package/scripts/utils/fix-test-modules.js +27 -0
  107. package/scripts/utils/fix-timezone-issue-246.js +200 -0
  108. package/scripts/utils/fix-ts-comprehensive.py +182 -0
  109. package/scripts/utils/fix-ts-targeted-batch.js +250 -0
  110. package/scripts/utils/remove-benchmark-conflicts.sh +140 -0
  111. package/scripts/utils/simple-test-fixer.js +190 -0
  112. package/scripts/utils/validate-metrics-structure.cjs +144 -0
  113. package/scripts/verify-mcp-server.js +86 -0
  114. package/src/cli/simple-commands/__tests__/agent.test.js +291 -0
  115. package/src/cli/simple-commands/__tests__/memory.test.js +8 -0
  116. package/src/cli/simple-commands/__tests__/swarm.test.js +371 -0
  117. package/src/cli/simple-commands/__tests__/task.test.js +8 -0
  118. package/src/cli/simple-commands/agent.js +216 -0
  119. package/src/cli/simple-commands/analysis.js +570 -0
  120. package/src/cli/simple-commands/automation-executor.js +1603 -0
  121. package/src/cli/simple-commands/automation.js +627 -0
  122. package/src/cli/simple-commands/batch-manager.js +338 -0
  123. package/src/cli/simple-commands/claude-telemetry.js +311 -0
  124. package/src/cli/simple-commands/claude-track.js +102 -0
  125. package/src/cli/simple-commands/concurrent-display.js +348 -0
  126. package/src/cli/simple-commands/config.js +319 -0
  127. package/src/cli/simple-commands/coordination.js +307 -0
  128. package/src/cli/simple-commands/enhanced-ui-views.js +654 -0
  129. package/src/cli/simple-commands/enhanced-webui-complete.js +1038 -0
  130. package/src/cli/simple-commands/fix-hook-variables.js +363 -0
  131. package/src/cli/simple-commands/github/gh-coordinator.js +605 -0
  132. package/src/cli/simple-commands/github/github-api.js +624 -0
  133. package/src/cli/simple-commands/github/init.js +543 -0
  134. package/src/cli/simple-commands/github.js +377 -0
  135. package/src/cli/simple-commands/goal.js +145 -0
  136. package/src/cli/simple-commands/hive-mind/auto-save-middleware.js +311 -0
  137. package/src/cli/simple-commands/hive-mind/communication.js +740 -0
  138. package/src/cli/simple-commands/hive-mind/core.js +1031 -0
  139. package/src/cli/simple-commands/hive-mind/db-optimizer.js +872 -0
  140. package/src/cli/simple-commands/hive-mind/mcp-wrapper.js +1364 -0
  141. package/src/cli/simple-commands/hive-mind/memory.js +1292 -0
  142. package/src/cli/simple-commands/hive-mind/performance-optimizer.js +618 -0
  143. package/src/cli/simple-commands/hive-mind/performance-test.js +373 -0
  144. package/src/cli/simple-commands/hive-mind/queen.js +809 -0
  145. package/src/cli/simple-commands/hive-mind/session-manager.js +1223 -0
  146. package/src/cli/simple-commands/hive-mind-optimize.js +361 -0
  147. package/src/cli/simple-commands/hive-mind-wizard.js +281 -0
  148. package/src/cli/simple-commands/hive-mind.js +3112 -0
  149. package/src/cli/simple-commands/hive.js +140 -0
  150. package/src/cli/simple-commands/hook-safety.js +671 -0
  151. package/src/cli/simple-commands/hooks.js +1268 -0
  152. package/src/cli/simple-commands/init/.claude/checkpoints/1756224542.json +7 -0
  153. package/src/cli/simple-commands/init/.claude/checkpoints/1756224544.json +8 -0
  154. package/src/cli/simple-commands/init/README.md +106 -0
  155. package/src/cli/simple-commands/init/VALIDATION_ROLLBACK.md +488 -0
  156. package/src/cli/simple-commands/init/agent-copier.js +347 -0
  157. package/src/cli/simple-commands/init/batch-init.js +663 -0
  158. package/src/cli/simple-commands/init/claude-commands/claude-flow-commands.js +438 -0
  159. package/src/cli/simple-commands/init/claude-commands/optimized-claude-flow-commands.js +876 -0
  160. package/src/cli/simple-commands/init/claude-commands/optimized-slash-commands.js +356 -0
  161. package/src/cli/simple-commands/init/claude-commands/optimized-sparc-commands.js +501 -0
  162. package/src/cli/simple-commands/init/claude-commands/slash-commands.js +57 -0
  163. package/src/cli/simple-commands/init/claude-commands/sparc-commands.js +296 -0
  164. package/src/cli/simple-commands/init/copy-revised-templates.js +175 -0
  165. package/src/cli/simple-commands/init/executable-wrapper.js +122 -0
  166. package/src/cli/simple-commands/init/gitignore-updater.js +137 -0
  167. package/src/cli/simple-commands/init/help.js +110 -0
  168. package/src/cli/simple-commands/init/hive-mind-init.js +749 -0
  169. package/src/cli/simple-commands/init/index.js +1953 -0
  170. package/src/cli/simple-commands/init/performance-monitor.js +344 -0
  171. package/src/cli/simple-commands/init/rollback/backup-manager.js +542 -0
  172. package/src/cli/simple-commands/init/rollback/index.js +399 -0
  173. package/src/cli/simple-commands/init/rollback/recovery-manager.js +778 -0
  174. package/src/cli/simple-commands/init/rollback/rollback-executor.js +521 -0
  175. package/src/cli/simple-commands/init/rollback/state-tracker.js +486 -0
  176. package/src/cli/simple-commands/init/sparc/roo-readme.js +61 -0
  177. package/src/cli/simple-commands/init/sparc/roomodes-config.js +102 -0
  178. package/src/cli/simple-commands/init/sparc/workflows.js +40 -0
  179. package/src/cli/simple-commands/init/sparc-structure.js +68 -0
  180. package/src/cli/simple-commands/init/template-copier.js +640 -0
  181. package/src/cli/simple-commands/init/templates/CLAUDE.md +1185 -0
  182. package/src/cli/simple-commands/init/templates/CLAUDE.md.optimized +265 -0
  183. package/src/cli/simple-commands/init/templates/claude-flow-universal +81 -0
  184. package/src/cli/simple-commands/init/templates/claude-flow.bat +18 -0
  185. package/src/cli/simple-commands/init/templates/claude-flow.ps1 +24 -0
  186. package/src/cli/simple-commands/init/templates/claude-md.js +1101 -0
  187. package/src/cli/simple-commands/init/templates/commands/analysis/bottleneck-detect.md +162 -0
  188. package/src/cli/simple-commands/init/templates/commands/automation/auto-agent.md +122 -0
  189. package/src/cli/simple-commands/init/templates/commands/coordination/swarm-init.md +85 -0
  190. package/src/cli/simple-commands/init/templates/commands/github/github-swarm.md +121 -0
  191. package/src/cli/simple-commands/init/templates/commands/helpers/standard-checkpoint-hooks.sh +179 -0
  192. package/src/cli/simple-commands/init/templates/commands/hooks/notification.md +113 -0
  193. package/src/cli/simple-commands/init/templates/commands/hooks/post-command.md +116 -0
  194. package/src/cli/simple-commands/init/templates/commands/hooks/post-edit.md +117 -0
  195. package/src/cli/simple-commands/init/templates/commands/hooks/post-task.md +112 -0
  196. package/src/cli/simple-commands/init/templates/commands/hooks/pre-command.md +113 -0
  197. package/src/cli/simple-commands/init/templates/commands/hooks/pre-edit.md +113 -0
  198. package/src/cli/simple-commands/init/templates/commands/hooks/pre-search.md +112 -0
  199. package/src/cli/simple-commands/init/templates/commands/hooks/pre-task.md +111 -0
  200. package/src/cli/simple-commands/init/templates/commands/hooks/session-end.md +118 -0
  201. package/src/cli/simple-commands/init/templates/commands/hooks/session-restore.md +118 -0
  202. package/src/cli/simple-commands/init/templates/commands/hooks/session-start.md +117 -0
  203. package/src/cli/simple-commands/init/templates/coordination-md.js +340 -0
  204. package/src/cli/simple-commands/init/templates/coordination.md +16 -0
  205. package/src/cli/simple-commands/init/templates/enhanced-templates.js +2347 -0
  206. package/src/cli/simple-commands/init/templates/github-safe-enhanced.js +331 -0
  207. package/src/cli/simple-commands/init/templates/github-safe.js +106 -0
  208. package/src/cli/simple-commands/init/templates/memory-bank-md.js +259 -0
  209. package/src/cli/simple-commands/init/templates/memory-bank.md +16 -0
  210. package/src/cli/simple-commands/init/templates/readme-files.js +72 -0
  211. package/src/cli/simple-commands/init/templates/safe-hook-patterns.js +430 -0
  212. package/src/cli/simple-commands/init/templates/settings.json +109 -0
  213. package/src/cli/simple-commands/init/templates/settings.json.enhanced +35 -0
  214. package/src/cli/simple-commands/init/templates/sparc-modes.js +1401 -0
  215. package/src/cli/simple-commands/init/templates/verification-claude-md.js +432 -0
  216. package/src/cli/simple-commands/init/validation/config-validator.js +354 -0
  217. package/src/cli/simple-commands/init/validation/health-checker.js +599 -0
  218. package/src/cli/simple-commands/init/validation/index.js +388 -0
  219. package/src/cli/simple-commands/init/validation/mode-validator.js +387 -0
  220. package/src/cli/simple-commands/init/validation/post-init-validator.js +390 -0
  221. package/src/cli/simple-commands/init/validation/pre-init-validator.js +290 -0
  222. package/src/cli/simple-commands/init/validation/test-runner.js +488 -0
  223. package/src/cli/simple-commands/init.js +4 -0
  224. package/src/cli/simple-commands/mcp-health.js +163 -0
  225. package/src/cli/simple-commands/mcp-integration-layer.js +689 -0
  226. package/src/cli/simple-commands/mcp.js +420 -0
  227. package/src/cli/simple-commands/memory-consolidation.js +631 -0
  228. package/src/cli/simple-commands/memory.js +345 -0
  229. package/src/cli/simple-commands/migrate-hooks.js +63 -0
  230. package/src/cli/simple-commands/monitor.js +417 -0
  231. package/src/cli/simple-commands/neural.js +148 -0
  232. package/src/cli/simple-commands/pair-autofix-only.js +755 -0
  233. package/src/cli/simple-commands/pair-basic.js +751 -0
  234. package/src/cli/simple-commands/pair-old.js +623 -0
  235. package/src/cli/simple-commands/pair-working.js +849 -0
  236. package/src/cli/simple-commands/pair.js +849 -0
  237. package/src/cli/simple-commands/performance-hooks.js +149 -0
  238. package/src/cli/simple-commands/performance-metrics.js +601 -0
  239. package/src/cli/simple-commands/process-ui-enhanced.js +821 -0
  240. package/src/cli/simple-commands/process-ui.js +274 -0
  241. package/src/cli/simple-commands/realtime-update-system.js +659 -0
  242. package/src/cli/simple-commands/sparc/architecture.js +1750 -0
  243. package/src/cli/simple-commands/sparc/commands.js +575 -0
  244. package/src/cli/simple-commands/sparc/completion.js +1831 -0
  245. package/src/cli/simple-commands/sparc/coordinator.js +1045 -0
  246. package/src/cli/simple-commands/sparc/index.js +321 -0
  247. package/src/cli/simple-commands/sparc/phase-base.js +430 -0
  248. package/src/cli/simple-commands/sparc/pseudocode.js +984 -0
  249. package/src/cli/simple-commands/sparc/refinement.js +1856 -0
  250. package/src/cli/simple-commands/sparc/specification.js +736 -0
  251. package/src/cli/simple-commands/sparc-modes/architect.js +125 -0
  252. package/src/cli/simple-commands/sparc-modes/ask.js +126 -0
  253. package/src/cli/simple-commands/sparc-modes/code.js +148 -0
  254. package/src/cli/simple-commands/sparc-modes/debug.js +112 -0
  255. package/src/cli/simple-commands/sparc-modes/devops.js +137 -0
  256. package/src/cli/simple-commands/sparc-modes/docs-writer.js +38 -0
  257. package/src/cli/simple-commands/sparc-modes/generic.js +34 -0
  258. package/src/cli/simple-commands/sparc-modes/index.js +201 -0
  259. package/src/cli/simple-commands/sparc-modes/integration.js +55 -0
  260. package/src/cli/simple-commands/sparc-modes/mcp.js +38 -0
  261. package/src/cli/simple-commands/sparc-modes/monitoring.js +38 -0
  262. package/src/cli/simple-commands/sparc-modes/optimization.js +38 -0
  263. package/src/cli/simple-commands/sparc-modes/security-review.js +130 -0
  264. package/src/cli/simple-commands/sparc-modes/sparc-orchestrator.js +167 -0
  265. package/src/cli/simple-commands/sparc-modes/spec-pseudocode.js +38 -0
  266. package/src/cli/simple-commands/sparc-modes/supabase-admin.js +149 -0
  267. package/src/cli/simple-commands/sparc-modes/swarm.js +436 -0
  268. package/src/cli/simple-commands/sparc-modes/tdd.js +112 -0
  269. package/src/cli/simple-commands/sparc-modes/tutorial.js +277 -0
  270. package/src/cli/simple-commands/sparc.js +530 -0
  271. package/src/cli/simple-commands/start-ui.js +147 -0
  272. package/src/cli/simple-commands/start-wrapper.js +285 -0
  273. package/src/cli/simple-commands/start.js +2 -0
  274. package/src/cli/simple-commands/status.js +303 -0
  275. package/src/cli/simple-commands/stream-chain-clean.js +221 -0
  276. package/src/cli/simple-commands/stream-chain-fixed.js +89 -0
  277. package/src/cli/simple-commands/stream-chain-real.js +408 -0
  278. package/src/cli/simple-commands/stream-chain-working.js +323 -0
  279. package/src/cli/simple-commands/stream-chain.js +491 -0
  280. package/src/cli/simple-commands/stream-processor.js +340 -0
  281. package/src/cli/simple-commands/swarm-executor.js +253 -0
  282. package/src/cli/simple-commands/swarm-metrics-integration.js +371 -0
  283. package/src/cli/simple-commands/swarm-ui.js +741 -0
  284. package/src/cli/simple-commands/swarm-webui-integration.js +311 -0
  285. package/src/cli/simple-commands/swarm.js +2277 -0
  286. package/src/cli/simple-commands/task.js +228 -0
  287. package/src/cli/simple-commands/templates/mle-star-workflow.json +294 -0
  288. package/src/cli/simple-commands/timestamp-fix.js +104 -0
  289. package/src/cli/simple-commands/token-tracker.js +372 -0
  290. package/src/cli/simple-commands/tool-execution-framework.js +555 -0
  291. package/src/cli/simple-commands/train-and-stream.js +354 -0
  292. package/src/cli/simple-commands/training-pipeline.js +874 -0
  293. package/src/cli/simple-commands/training.js +288 -0
  294. package/src/cli/simple-commands/verification-hooks.js +336 -0
  295. package/src/cli/simple-commands/verification-integration.js +464 -0
  296. package/src/cli/simple-commands/verification-training-integration.js +646 -0
  297. package/src/cli/simple-commands/verification.js +551 -0
  298. package/src/cli/simple-commands/web-server.js +929 -0
  299. package/src/cli/simple-commands/webui-validator.js +136 -0
  300. package/src/language/README.md +503 -0
  301. package/src/language/claude-md-generator.js +618 -0
  302. package/src/language/cli.js +422 -0
  303. package/src/language/example.js +347 -0
  304. package/src/language/integration-system.js +619 -0
  305. package/src/language/language-detector.js +581 -0
@@ -0,0 +1,2347 @@
1
+ // enhanced-templates.js - Generate Claude Flow v2.0.0 enhanced templates
2
+ import { readFileSync } from 'fs';
3
+ import { dirname, join } from 'path';
4
+ import { fileURLToPath } from 'url';
5
+
6
+ const __dirname = dirname(fileURLToPath(import.meta.url));
7
+
8
+ // Load template files
9
+ const loadTemplate = (filename) => {
10
+ try {
11
+ return readFileSync(join(__dirname, filename), 'utf8');
12
+ } catch (error) {
13
+ // Silently fall back to hardcoded templates if files not found
14
+ // This handles npm packaging scenarios where template files may not be included
15
+ return null;
16
+ }
17
+ };
18
+
19
+ export function createEnhancedClaudeMd() {
20
+ const template = loadTemplate('CLAUDE.md');
21
+ if (!template) {
22
+ // Fallback to hardcoded if template file not found
23
+ return createEnhancedClaudeMdFallback();
24
+ }
25
+ return template;
26
+ }
27
+
28
+ export function createEnhancedSettingsJson() {
29
+ const template = loadTemplate('settings.json');
30
+ if (!template) {
31
+ return createEnhancedSettingsJsonFallback();
32
+ }
33
+ return template;
34
+ }
35
+
36
+ export function createWrapperScript(type = 'unix') {
37
+ // For unix, use the universal wrapper that works in both CommonJS and ES modules
38
+ if (type === 'unix') {
39
+ const universalTemplate = loadTemplate('claude-flow-universal');
40
+ if (universalTemplate) {
41
+ return universalTemplate;
42
+ }
43
+ }
44
+
45
+ const filename =
46
+ type === 'unix' ? 'claude-flow' : type === 'windows' ? 'claude-flow.bat' : 'claude-flow.ps1';
47
+
48
+ const template = loadTemplate(filename);
49
+ if (!template) {
50
+ return createWrapperScriptFallback(type);
51
+ }
52
+ return template;
53
+ }
54
+
55
+ export function createCommandDoc(category, command) {
56
+ const template = loadTemplate(`commands/${category}/${command}.md`);
57
+ if (!template) {
58
+ // Silently fall back to generated documentation
59
+ return createCommandDocFallback(category, command);
60
+ }
61
+ return template;
62
+ }
63
+
64
+ // Generate command documentation fallbacks
65
+ function createCommandDocFallback(category, command) {
66
+ const docs = {
67
+ analysis: {
68
+ 'bottleneck-detect': `# bottleneck-detect
69
+
70
+ Automatically detect performance bottlenecks in your swarm operations.
71
+
72
+ ## Usage
73
+ \`\`\`bash
74
+ npx claude-flow analysis bottleneck-detect [options]
75
+ \`\`\`
76
+
77
+ ## Options
78
+ - \`--swarm-id <id>\` - Target specific swarm
79
+ - \`--threshold <ms>\` - Performance threshold (default: 1000ms)
80
+ - \`--export <file>\` - Export results to file
81
+
82
+ ## Examples
83
+ \`\`\`bash
84
+ # Detect bottlenecks in current swarm
85
+ npx claude-flow analysis bottleneck-detect
86
+
87
+ # Set custom threshold
88
+ npx claude-flow analysis bottleneck-detect --threshold 500
89
+
90
+ # Export results
91
+ npx claude-flow analysis bottleneck-detect --export bottlenecks.json
92
+ \`\`\`
93
+ `,
94
+ 'token-usage': `# token-usage
95
+
96
+ Analyze token usage patterns and optimize for efficiency.
97
+
98
+ ## Usage
99
+ \`\`\`bash
100
+ npx claude-flow analysis token-usage [options]
101
+ \`\`\`
102
+
103
+ ## Options
104
+ - \`--period <time>\` - Analysis period (1h, 24h, 7d, 30d)
105
+ - \`--by-agent\` - Break down by agent
106
+ - \`--by-operation\` - Break down by operation type
107
+
108
+ ## Examples
109
+ \`\`\`bash
110
+ # Last 24 hours token usage
111
+ npx claude-flow analysis token-usage --period 24h
112
+
113
+ # By agent breakdown
114
+ npx claude-flow analysis token-usage --by-agent
115
+
116
+ # Export detailed report
117
+ npx claude-flow analysis token-usage --period 7d --export tokens.csv
118
+ \`\`\`
119
+ `,
120
+ 'performance-report': `# performance-report
121
+
122
+ Generate comprehensive performance reports for swarm operations.
123
+
124
+ ## Usage
125
+ \`\`\`bash
126
+ npx claude-flow analysis performance-report [options]
127
+ \`\`\`
128
+
129
+ ## Options
130
+ - \`--format <type>\` - Report format (json, html, markdown)
131
+ - \`--include-metrics\` - Include detailed metrics
132
+ - \`--compare <id>\` - Compare with previous swarm
133
+
134
+ ## Examples
135
+ \`\`\`bash
136
+ # Generate HTML report
137
+ npx claude-flow analysis performance-report --format html
138
+
139
+ # Compare swarms
140
+ npx claude-flow analysis performance-report --compare swarm-123
141
+
142
+ # Full metrics report
143
+ npx claude-flow analysis performance-report --include-metrics --format markdown
144
+ \`\`\`
145
+ `,
146
+ },
147
+ automation: {
148
+ 'auto-agent': `# auto-agent
149
+
150
+ Automatically assign agents based on task analysis.
151
+
152
+ ## Usage
153
+ \`\`\`bash
154
+ npx claude-flow automation auto-agent [options]
155
+ \`\`\`
156
+
157
+ ## Options
158
+ - \`--task <description>\` - Task to analyze
159
+ - \`--max-agents <n>\` - Maximum agents to spawn
160
+ - \`--strategy <type>\` - Assignment strategy
161
+
162
+ ## Examples
163
+ \`\`\`bash
164
+ # Auto-assign for task
165
+ npx claude-flow automation auto-agent --task "Build REST API"
166
+
167
+ # Limit agents
168
+ npx claude-flow automation auto-agent --task "Fix bugs" --max-agents 3
169
+
170
+ # Use specific strategy
171
+ npx claude-flow automation auto-agent --strategy specialized
172
+ \`\`\`
173
+ `,
174
+ 'smart-spawn': `# smart-spawn
175
+
176
+ Intelligently spawn agents based on workload analysis.
177
+
178
+ ## Usage
179
+ \`\`\`bash
180
+ npx claude-flow automation smart-spawn [options]
181
+ \`\`\`
182
+
183
+ ## Options
184
+ - \`--analyze\` - Analyze before spawning
185
+ - \`--threshold <n>\` - Spawn threshold
186
+ - \`--topology <type>\` - Preferred topology
187
+
188
+ ## Examples
189
+ \`\`\`bash
190
+ # Smart spawn with analysis
191
+ npx claude-flow automation smart-spawn --analyze
192
+
193
+ # Set spawn threshold
194
+ npx claude-flow automation smart-spawn --threshold 5
195
+
196
+ # Force topology
197
+ npx claude-flow automation smart-spawn --topology hierarchical
198
+ \`\`\`
199
+ `,
200
+ 'workflow-select': `# workflow-select
201
+
202
+ Automatically select optimal workflow based on task type.
203
+
204
+ ## Usage
205
+ \`\`\`bash
206
+ npx claude-flow automation workflow-select [options]
207
+ \`\`\`
208
+
209
+ ## Options
210
+ - \`--task <description>\` - Task description
211
+ - \`--constraints <list>\` - Workflow constraints
212
+ - \`--preview\` - Preview without executing
213
+
214
+ ## Examples
215
+ \`\`\`bash
216
+ # Select workflow for task
217
+ npx claude-flow automation workflow-select --task "Deploy to production"
218
+
219
+ # With constraints
220
+ npx claude-flow automation workflow-select --constraints "no-downtime,rollback"
221
+
222
+ # Preview mode
223
+ npx claude-flow automation workflow-select --task "Database migration" --preview
224
+ \`\`\`
225
+ `,
226
+ },
227
+ coordination: {
228
+ 'swarm-init': `# swarm-init
229
+
230
+ Initialize a new agent swarm with specified topology.
231
+
232
+ ## Usage
233
+ \`\`\`bash
234
+ npx claude-flow swarm init [options]
235
+ \`\`\`
236
+
237
+ ## Options
238
+ - \`--topology <type>\` - Swarm topology (mesh, hierarchical, ring, star)
239
+ - \`--max-agents <n>\` - Maximum number of agents
240
+ - \`--strategy <type>\` - Execution strategy (parallel, sequential, adaptive)
241
+
242
+ ## Examples
243
+ \`\`\`bash
244
+ # Initialize hierarchical swarm
245
+ npx claude-flow swarm init --topology hierarchical
246
+
247
+ # With agent limit
248
+ npx claude-flow swarm init --topology mesh --max-agents 8
249
+
250
+ # Parallel execution
251
+ npx claude-flow swarm init --strategy parallel
252
+ \`\`\`
253
+ `,
254
+ 'agent-spawn': `# agent-spawn
255
+
256
+ Spawn a new agent in the current swarm.
257
+
258
+ ## Usage
259
+ \`\`\`bash
260
+ npx claude-flow agent spawn [options]
261
+ \`\`\`
262
+
263
+ ## Options
264
+ - \`--type <type>\` - Agent type (coder, researcher, analyst, tester, coordinator)
265
+ - \`--name <name>\` - Custom agent name
266
+ - \`--skills <list>\` - Specific skills (comma-separated)
267
+
268
+ ## Examples
269
+ \`\`\`bash
270
+ # Spawn coder agent
271
+ npx claude-flow agent spawn --type coder
272
+
273
+ # With custom name
274
+ npx claude-flow agent spawn --type researcher --name "API Expert"
275
+
276
+ # With specific skills
277
+ npx claude-flow agent spawn --type coder --skills "python,fastapi,testing"
278
+ \`\`\`
279
+ `,
280
+ 'task-orchestrate': `# task-orchestrate
281
+
282
+ Orchestrate complex tasks across the swarm.
283
+
284
+ ## Usage
285
+ \`\`\`bash
286
+ npx claude-flow task orchestrate [options]
287
+ \`\`\`
288
+
289
+ ## Options
290
+ - \`--task <description>\` - Task description
291
+ - \`--strategy <type>\` - Orchestration strategy
292
+ - \`--priority <level>\` - Task priority (low, medium, high, critical)
293
+
294
+ ## Examples
295
+ \`\`\`bash
296
+ # Orchestrate development task
297
+ npx claude-flow task orchestrate --task "Implement user authentication"
298
+
299
+ # High priority task
300
+ npx claude-flow task orchestrate --task "Fix production bug" --priority critical
301
+
302
+ # With specific strategy
303
+ npx claude-flow task orchestrate --task "Refactor codebase" --strategy parallel
304
+ \`\`\`
305
+ `,
306
+ },
307
+ github: {
308
+ 'github-swarm': `# github-swarm
309
+
310
+ Create a specialized swarm for GitHub repository management.
311
+
312
+ ## Usage
313
+ \`\`\`bash
314
+ npx claude-flow github swarm [options]
315
+ \`\`\`
316
+
317
+ ## Options
318
+ - \`--repository <owner/repo>\` - Target repository
319
+ - \`--agents <n>\` - Number of specialized agents
320
+ - \`--focus <area>\` - Focus area (maintenance, features, security)
321
+
322
+ ## Examples
323
+ \`\`\`bash
324
+ # Create GitHub swarm
325
+ npx claude-flow github swarm --repository myorg/myrepo
326
+
327
+ # With specific focus
328
+ npx claude-flow github swarm --repository myorg/myrepo --focus security
329
+
330
+ # Custom agent count
331
+ npx claude-flow github swarm --repository myorg/myrepo --agents 6
332
+ \`\`\`
333
+ `,
334
+ 'repo-analyze': `# repo-analyze
335
+
336
+ Deep analysis of GitHub repository with AI insights.
337
+
338
+ ## Usage
339
+ \`\`\`bash
340
+ npx claude-flow github repo-analyze [options]
341
+ \`\`\`
342
+
343
+ ## Options
344
+ - \`--repository <owner/repo>\` - Repository to analyze
345
+ - \`--deep\` - Enable deep analysis
346
+ - \`--include <areas>\` - Include specific areas (issues, prs, code, commits)
347
+
348
+ ## Examples
349
+ \`\`\`bash
350
+ # Basic analysis
351
+ npx claude-flow github repo-analyze --repository myorg/myrepo
352
+
353
+ # Deep analysis
354
+ npx claude-flow github repo-analyze --repository myorg/myrepo --deep
355
+
356
+ # Specific areas
357
+ npx claude-flow github repo-analyze --repository myorg/myrepo --include issues,prs
358
+ \`\`\`
359
+ `,
360
+ 'pr-enhance': `# pr-enhance
361
+
362
+ AI-powered pull request enhancements.
363
+
364
+ ## Usage
365
+ \`\`\`bash
366
+ npx claude-flow github pr-enhance [options]
367
+ \`\`\`
368
+
369
+ ## Options
370
+ - \`--pr-number <n>\` - Pull request number
371
+ - \`--add-tests\` - Add missing tests
372
+ - \`--improve-docs\` - Improve documentation
373
+ - \`--check-security\` - Security review
374
+
375
+ ## Examples
376
+ \`\`\`bash
377
+ # Enhance PR
378
+ npx claude-flow github pr-enhance --pr-number 123
379
+
380
+ # Add tests
381
+ npx claude-flow github pr-enhance --pr-number 123 --add-tests
382
+
383
+ # Full enhancement
384
+ npx claude-flow github pr-enhance --pr-number 123 --add-tests --improve-docs
385
+ \`\`\`
386
+ `,
387
+ 'issue-triage': `# issue-triage
388
+
389
+ Intelligent issue classification and triage.
390
+
391
+ ## Usage
392
+ \`\`\`bash
393
+ npx claude-flow github issue-triage [options]
394
+ \`\`\`
395
+
396
+ ## Options
397
+ - \`--repository <owner/repo>\` - Target repository
398
+ - \`--auto-label\` - Automatically apply labels
399
+ - \`--assign\` - Auto-assign to team members
400
+
401
+ ## Examples
402
+ \`\`\`bash
403
+ # Triage issues
404
+ npx claude-flow github issue-triage --repository myorg/myrepo
405
+
406
+ # With auto-labeling
407
+ npx claude-flow github issue-triage --repository myorg/myrepo --auto-label
408
+
409
+ # Full automation
410
+ npx claude-flow github issue-triage --repository myorg/myrepo --auto-label --assign
411
+ \`\`\`
412
+ `,
413
+ 'code-review': `# code-review
414
+
415
+ Automated code review with swarm intelligence.
416
+
417
+ ## Usage
418
+ \`\`\`bash
419
+ npx claude-flow github code-review [options]
420
+ \`\`\`
421
+
422
+ ## Options
423
+ - \`--pr-number <n>\` - Pull request to review
424
+ - \`--focus <areas>\` - Review focus (security, performance, style)
425
+ - \`--suggest-fixes\` - Suggest code fixes
426
+
427
+ ## Examples
428
+ \`\`\`bash
429
+ # Review PR
430
+ npx claude-flow github code-review --pr-number 456
431
+
432
+ # Security focus
433
+ npx claude-flow github code-review --pr-number 456 --focus security
434
+
435
+ # With fix suggestions
436
+ npx claude-flow github code-review --pr-number 456 --suggest-fixes
437
+ \`\`\`
438
+ `,
439
+ },
440
+ hooks: {
441
+ 'pre-task': `# pre-task
442
+
443
+ Hook executed before task execution.
444
+
445
+ ## Usage
446
+ \`\`\`bash
447
+ npx claude-flow hook pre-task [options]
448
+ \`\`\`
449
+
450
+ ## Options
451
+ - \`--description <text>\` - Task description
452
+ - \`--auto-spawn-agents\` - Automatically spawn required agents
453
+ - \`--load-context\` - Load previous context
454
+
455
+ ## Examples
456
+ \`\`\`bash
457
+ # Basic pre-task hook
458
+ npx claude-flow hook pre-task --description "Building API endpoints"
459
+
460
+ # With auto-spawn
461
+ npx claude-flow hook pre-task --description "Complex refactoring" --auto-spawn-agents
462
+
463
+ # Load context
464
+ npx claude-flow hook pre-task --description "Continue feature" --load-context
465
+ \`\`\`
466
+ `,
467
+ 'post-task': `# post-task
468
+
469
+ Hook executed after task completion.
470
+
471
+ ## Usage
472
+ \`\`\`bash
473
+ npx claude-flow hook post-task [options]
474
+ \`\`\`
475
+
476
+ ## Options
477
+ - \`--task-id <id>\` - Task identifier
478
+ - \`--analyze-performance\` - Analyze task performance
479
+ - \`--update-memory\` - Update swarm memory
480
+
481
+ ## Examples
482
+ \`\`\`bash
483
+ # Basic post-task
484
+ npx claude-flow hook post-task --task-id task-123
485
+
486
+ # With performance analysis
487
+ npx claude-flow hook post-task --task-id task-123 --analyze-performance
488
+
489
+ # Update memory
490
+ npx claude-flow hook post-task --task-id task-123 --update-memory
491
+ \`\`\`
492
+ `,
493
+ 'pre-edit': `# pre-edit
494
+
495
+ Hook executed before file edits.
496
+
497
+ ## Usage
498
+ \`\`\`bash
499
+ npx claude-flow hook pre-edit [options]
500
+ \`\`\`
501
+
502
+ ## Options
503
+ - \`--file <path>\` - File to be edited
504
+ - \`--validate-syntax\` - Validate syntax before edit
505
+ - \`--backup\` - Create backup
506
+
507
+ ## Examples
508
+ \`\`\`bash
509
+ # Pre-edit hook
510
+ npx claude-flow hook pre-edit --file src/api.js
511
+
512
+ # With validation
513
+ npx claude-flow hook pre-edit --file src/api.js --validate-syntax
514
+
515
+ # Create backup
516
+ npx claude-flow hook pre-edit --file src/api.js --backup
517
+ \`\`\`
518
+ `,
519
+ 'post-edit': `# post-edit
520
+
521
+ Hook executed after file edits.
522
+
523
+ ## Usage
524
+ \`\`\`bash
525
+ npx claude-flow hook post-edit [options]
526
+ \`\`\`
527
+
528
+ ## Options
529
+ - \`--file <path>\` - Edited file
530
+ - \`--memory-key <key>\` - Memory storage key
531
+ - \`--format\` - Auto-format code
532
+
533
+ ## Examples
534
+ \`\`\`bash
535
+ # Post-edit hook
536
+ npx claude-flow hook post-edit --file src/api.js
537
+
538
+ # Store in memory
539
+ npx claude-flow hook post-edit --file src/api.js --memory-key "api-changes"
540
+
541
+ # With formatting
542
+ npx claude-flow hook post-edit --file src/api.js --format
543
+ \`\`\`
544
+ `,
545
+ 'session-end': `# session-end
546
+
547
+ Hook executed at session end.
548
+
549
+ ## Usage
550
+ \`\`\`bash
551
+ npx claude-flow hook session-end [options]
552
+ \`\`\`
553
+
554
+ ## Options
555
+ - \`--export-metrics\` - Export session metrics
556
+ - \`--generate-summary\` - Generate session summary
557
+ - \`--persist-state\` - Save session state
558
+
559
+ ## Examples
560
+ \`\`\`bash
561
+ # End session
562
+ npx claude-flow hook session-end
563
+
564
+ # Export metrics
565
+ npx claude-flow hook session-end --export-metrics
566
+
567
+ # Full closure
568
+ npx claude-flow hook session-end --export-metrics --generate-summary --persist-state
569
+ \`\`\`
570
+ `,
571
+ },
572
+ memory: {
573
+ 'memory-usage': `# memory-usage
574
+
575
+ Manage persistent memory storage.
576
+
577
+ ## Usage
578
+ \`\`\`bash
579
+ npx claude-flow memory usage [options]
580
+ \`\`\`
581
+
582
+ ## Options
583
+ - \`--action <type>\` - Action (store, retrieve, list, clear)
584
+ - \`--key <key>\` - Memory key
585
+ - \`--value <data>\` - Data to store (JSON)
586
+
587
+ ## Examples
588
+ \`\`\`bash
589
+ # Store memory
590
+ npx claude-flow memory usage --action store --key "project-config" --value '{"api": "v2"}'
591
+
592
+ # Retrieve memory
593
+ npx claude-flow memory usage --action retrieve --key "project-config"
594
+
595
+ # List all keys
596
+ npx claude-flow memory usage --action list
597
+ \`\`\`
598
+ `,
599
+ 'memory-persist': `# memory-persist
600
+
601
+ Persist memory across sessions.
602
+
603
+ ## Usage
604
+ \`\`\`bash
605
+ npx claude-flow memory persist [options]
606
+ \`\`\`
607
+
608
+ ## Options
609
+ - \`--export <file>\` - Export to file
610
+ - \`--import <file>\` - Import from file
611
+ - \`--compress\` - Compress memory data
612
+
613
+ ## Examples
614
+ \`\`\`bash
615
+ # Export memory
616
+ npx claude-flow memory persist --export memory-backup.json
617
+
618
+ # Import memory
619
+ npx claude-flow memory persist --import memory-backup.json
620
+
621
+ # Compressed export
622
+ npx claude-flow memory persist --export memory.gz --compress
623
+ \`\`\`
624
+ `,
625
+ 'memory-search': `# memory-search
626
+
627
+ Search through stored memory.
628
+
629
+ ## Usage
630
+ \`\`\`bash
631
+ npx claude-flow memory search [options]
632
+ \`\`\`
633
+
634
+ ## Options
635
+ - \`--query <text>\` - Search query
636
+ - \`--pattern <regex>\` - Pattern matching
637
+ - \`--limit <n>\` - Result limit
638
+
639
+ ## Examples
640
+ \`\`\`bash
641
+ # Search memory
642
+ npx claude-flow memory search --query "authentication"
643
+
644
+ # Pattern search
645
+ npx claude-flow memory search --pattern "api-.*"
646
+
647
+ # Limited results
648
+ npx claude-flow memory search --query "config" --limit 10
649
+ \`\`\`
650
+ `,
651
+ },
652
+ monitoring: {
653
+ 'swarm-monitor': `# swarm-monitor
654
+
655
+ Real-time swarm monitoring.
656
+
657
+ ## Usage
658
+ \`\`\`bash
659
+ npx claude-flow swarm monitor [options]
660
+ \`\`\`
661
+
662
+ ## Options
663
+ - \`--interval <ms>\` - Update interval
664
+ - \`--metrics\` - Show detailed metrics
665
+ - \`--export\` - Export monitoring data
666
+
667
+ ## Examples
668
+ \`\`\`bash
669
+ # Start monitoring
670
+ npx claude-flow swarm monitor
671
+
672
+ # Custom interval
673
+ npx claude-flow swarm monitor --interval 5000
674
+
675
+ # With metrics
676
+ npx claude-flow swarm monitor --metrics
677
+ \`\`\`
678
+ `,
679
+ 'agent-metrics': `# agent-metrics
680
+
681
+ View agent performance metrics.
682
+
683
+ ## Usage
684
+ \`\`\`bash
685
+ npx claude-flow agent metrics [options]
686
+ \`\`\`
687
+
688
+ ## Options
689
+ - \`--agent-id <id>\` - Specific agent
690
+ - \`--period <time>\` - Time period
691
+ - \`--format <type>\` - Output format
692
+
693
+ ## Examples
694
+ \`\`\`bash
695
+ # All agents metrics
696
+ npx claude-flow agent metrics
697
+
698
+ # Specific agent
699
+ npx claude-flow agent metrics --agent-id agent-001
700
+
701
+ # Last hour
702
+ npx claude-flow agent metrics --period 1h
703
+ \`\`\`
704
+ `,
705
+ 'real-time-view': `# real-time-view
706
+
707
+ Real-time view of swarm activity.
708
+
709
+ ## Usage
710
+ \`\`\`bash
711
+ npx claude-flow monitoring real-time-view [options]
712
+ \`\`\`
713
+
714
+ ## Options
715
+ - \`--filter <type>\` - Filter view
716
+ - \`--highlight <pattern>\` - Highlight pattern
717
+ - \`--tail <n>\` - Show last N events
718
+
719
+ ## Examples
720
+ \`\`\`bash
721
+ # Start real-time view
722
+ npx claude-flow monitoring real-time-view
723
+
724
+ # Filter errors
725
+ npx claude-flow monitoring real-time-view --filter errors
726
+
727
+ # Highlight pattern
728
+ npx claude-flow monitoring real-time-view --highlight "API"
729
+ \`\`\`
730
+ `,
731
+ },
732
+ optimization: {
733
+ 'topology-optimize': `# topology-optimize
734
+
735
+ Optimize swarm topology for current workload.
736
+
737
+ ## Usage
738
+ \`\`\`bash
739
+ npx claude-flow optimization topology-optimize [options]
740
+ \`\`\`
741
+
742
+ ## Options
743
+ - \`--analyze-first\` - Analyze before optimizing
744
+ - \`--target <metric>\` - Optimization target
745
+ - \`--apply\` - Apply optimizations
746
+
747
+ ## Examples
748
+ \`\`\`bash
749
+ # Analyze and suggest
750
+ npx claude-flow optimization topology-optimize --analyze-first
751
+
752
+ # Optimize for speed
753
+ npx claude-flow optimization topology-optimize --target speed
754
+
755
+ # Apply changes
756
+ npx claude-flow optimization topology-optimize --target efficiency --apply
757
+ \`\`\`
758
+ `,
759
+ 'parallel-execute': `# parallel-execute
760
+
761
+ Execute tasks in parallel for maximum efficiency.
762
+
763
+ ## Usage
764
+ \`\`\`bash
765
+ npx claude-flow optimization parallel-execute [options]
766
+ \`\`\`
767
+
768
+ ## Options
769
+ - \`--tasks <file>\` - Task list file
770
+ - \`--max-parallel <n>\` - Maximum parallel tasks
771
+ - \`--strategy <type>\` - Execution strategy
772
+
773
+ ## Examples
774
+ \`\`\`bash
775
+ # Execute task list
776
+ npx claude-flow optimization parallel-execute --tasks tasks.json
777
+
778
+ # Limit parallelism
779
+ npx claude-flow optimization parallel-execute --tasks tasks.json --max-parallel 5
780
+
781
+ # Custom strategy
782
+ npx claude-flow optimization parallel-execute --strategy adaptive
783
+ \`\`\`
784
+ `,
785
+ 'cache-manage': `# cache-manage
786
+
787
+ Manage operation cache for performance.
788
+
789
+ ## Usage
790
+ \`\`\`bash
791
+ npx claude-flow optimization cache-manage [options]
792
+ \`\`\`
793
+
794
+ ## Options
795
+ - \`--action <type>\` - Action (view, clear, optimize)
796
+ - \`--max-size <mb>\` - Maximum cache size
797
+ - \`--ttl <seconds>\` - Time to live
798
+
799
+ ## Examples
800
+ \`\`\`bash
801
+ # View cache stats
802
+ npx claude-flow optimization cache-manage --action view
803
+
804
+ # Clear cache
805
+ npx claude-flow optimization cache-manage --action clear
806
+
807
+ # Set limits
808
+ npx claude-flow optimization cache-manage --max-size 100 --ttl 3600
809
+ \`\`\`
810
+ `,
811
+ },
812
+ training: {
813
+ 'neural-train': `# neural-train
814
+
815
+ Train neural patterns from operations.
816
+
817
+ ## Usage
818
+ \`\`\`bash
819
+ npx claude-flow training neural-train [options]
820
+ \`\`\`
821
+
822
+ ## Options
823
+ - \`--data <source>\` - Training data source
824
+ - \`--model <name>\` - Target model
825
+ - \`--epochs <n>\` - Training epochs
826
+
827
+ ## Examples
828
+ \`\`\`bash
829
+ # Train from recent ops
830
+ npx claude-flow training neural-train --data recent
831
+
832
+ # Specific model
833
+ npx claude-flow training neural-train --model task-predictor
834
+
835
+ # Custom epochs
836
+ npx claude-flow training neural-train --epochs 100
837
+ \`\`\`
838
+ `,
839
+ 'pattern-learn': `# pattern-learn
840
+
841
+ Learn patterns from successful operations.
842
+
843
+ ## Usage
844
+ \`\`\`bash
845
+ npx claude-flow training pattern-learn [options]
846
+ \`\`\`
847
+
848
+ ## Options
849
+ - \`--source <type>\` - Pattern source
850
+ - \`--threshold <score>\` - Success threshold
851
+ - \`--save <name>\` - Save pattern set
852
+
853
+ ## Examples
854
+ \`\`\`bash
855
+ # Learn from all ops
856
+ npx claude-flow training pattern-learn
857
+
858
+ # High success only
859
+ npx claude-flow training pattern-learn --threshold 0.9
860
+
861
+ # Save patterns
862
+ npx claude-flow training pattern-learn --save optimal-patterns
863
+ \`\`\`
864
+ `,
865
+ 'model-update': `# model-update
866
+
867
+ Update neural models with new data.
868
+
869
+ ## Usage
870
+ \`\`\`bash
871
+ npx claude-flow training model-update [options]
872
+ \`\`\`
873
+
874
+ ## Options
875
+ - \`--model <name>\` - Model to update
876
+ - \`--incremental\` - Incremental update
877
+ - \`--validate\` - Validate after update
878
+
879
+ ## Examples
880
+ \`\`\`bash
881
+ # Update all models
882
+ npx claude-flow training model-update
883
+
884
+ # Specific model
885
+ npx claude-flow training model-update --model agent-selector
886
+
887
+ # Incremental with validation
888
+ npx claude-flow training model-update --incremental --validate
889
+ \`\`\`
890
+ `,
891
+ },
892
+ workflows: {
893
+ 'workflow-create': `# workflow-create
894
+
895
+ Create reusable workflow templates.
896
+
897
+ ## Usage
898
+ \`\`\`bash
899
+ npx claude-flow workflow create [options]
900
+ \`\`\`
901
+
902
+ ## Options
903
+ - \`--name <name>\` - Workflow name
904
+ - \`--from-history\` - Create from history
905
+ - \`--interactive\` - Interactive creation
906
+
907
+ ## Examples
908
+ \`\`\`bash
909
+ # Create workflow
910
+ npx claude-flow workflow create --name "deploy-api"
911
+
912
+ # From history
913
+ npx claude-flow workflow create --name "test-suite" --from-history
914
+
915
+ # Interactive mode
916
+ npx claude-flow workflow create --interactive
917
+ \`\`\`
918
+ `,
919
+ 'workflow-execute': `# workflow-execute
920
+
921
+ Execute saved workflows.
922
+
923
+ ## Usage
924
+ \`\`\`bash
925
+ npx claude-flow workflow execute [options]
926
+ \`\`\`
927
+
928
+ ## Options
929
+ - \`--name <name>\` - Workflow name
930
+ - \`--params <json>\` - Workflow parameters
931
+ - \`--dry-run\` - Preview execution
932
+
933
+ ## Examples
934
+ \`\`\`bash
935
+ # Execute workflow
936
+ npx claude-flow workflow execute --name "deploy-api"
937
+
938
+ # With parameters
939
+ npx claude-flow workflow execute --name "test-suite" --params '{"env": "staging"}'
940
+
941
+ # Dry run
942
+ npx claude-flow workflow execute --name "deploy-api" --dry-run
943
+ \`\`\`
944
+ `,
945
+ 'workflow-export': `# workflow-export
946
+
947
+ Export workflows for sharing.
948
+
949
+ ## Usage
950
+ \`\`\`bash
951
+ npx claude-flow workflow export [options]
952
+ \`\`\`
953
+
954
+ ## Options
955
+ - \`--name <name>\` - Workflow to export
956
+ - \`--format <type>\` - Export format
957
+ - \`--include-history\` - Include execution history
958
+
959
+ ## Examples
960
+ \`\`\`bash
961
+ # Export workflow
962
+ npx claude-flow workflow export --name "deploy-api"
963
+
964
+ # As YAML
965
+ npx claude-flow workflow export --name "test-suite" --format yaml
966
+
967
+ # With history
968
+ npx claude-flow workflow export --name "deploy-api" --include-history
969
+ \`\`\`
970
+ `,
971
+ },
972
+ swarm: {
973
+ swarm: `# swarm
974
+
975
+ Main swarm orchestration command for Claude Flow.
976
+
977
+ ## Usage
978
+ \`\`\`bash
979
+ npx claude-flow swarm <objective> [options]
980
+ \`\`\`
981
+
982
+ ## Options
983
+ - \`--strategy <type>\` - Execution strategy (research, development, analysis, testing)
984
+ - \`--mode <type>\` - Coordination mode (centralized, distributed, hierarchical, mesh)
985
+ - \`--max-agents <n>\` - Maximum number of agents (default: 5)
986
+ - \`--claude\` - Open Claude Code CLI with swarm prompt
987
+ - \`--parallel\` - Enable parallel execution
988
+
989
+ ## Examples
990
+ \`\`\`bash
991
+ # Basic swarm
992
+ npx claude-flow swarm "Build REST API"
993
+
994
+ # With strategy
995
+ npx claude-flow swarm "Research AI patterns" --strategy research
996
+
997
+ # Open in Claude Code
998
+ npx claude-flow swarm "Build API" --claude
999
+ \`\`\`
1000
+ `,
1001
+ 'swarm-init': `# swarm-init
1002
+
1003
+ Initialize a new swarm with specified topology.
1004
+
1005
+ ## Usage
1006
+ \`\`\`bash
1007
+ npx claude-flow swarm init [options]
1008
+ \`\`\`
1009
+
1010
+ ## Options
1011
+ - \`--topology <type>\` - Swarm topology (mesh, hierarchical, ring, star)
1012
+ - \`--max-agents <n>\` - Maximum agents
1013
+ - \`--strategy <type>\` - Distribution strategy
1014
+
1015
+ ## Examples
1016
+ \`\`\`bash
1017
+ npx claude-flow swarm init --topology mesh
1018
+ npx claude-flow swarm init --topology hierarchical --max-agents 8
1019
+ \`\`\`
1020
+ `,
1021
+ 'swarm-spawn': `# swarm-spawn
1022
+
1023
+ Spawn agents in the swarm.
1024
+
1025
+ ## Usage
1026
+ \`\`\`bash
1027
+ npx claude-flow swarm spawn [options]
1028
+ \`\`\`
1029
+
1030
+ ## Options
1031
+ - \`--type <type>\` - Agent type
1032
+ - \`--count <n>\` - Number to spawn
1033
+ - \`--capabilities <list>\` - Agent capabilities
1034
+
1035
+ ## Examples
1036
+ \`\`\`bash
1037
+ npx claude-flow swarm spawn --type coder --count 3
1038
+ npx claude-flow swarm spawn --type researcher --capabilities "web-search,analysis"
1039
+ \`\`\`
1040
+ `,
1041
+ },
1042
+ 'hive-mind': {
1043
+ 'hive-mind': `# hive-mind
1044
+
1045
+ Hive Mind collective intelligence system for advanced swarm coordination.
1046
+
1047
+ ## Usage
1048
+ \`\`\`bash
1049
+ npx claude-flow hive-mind [subcommand] [options]
1050
+ \`\`\`
1051
+
1052
+ ## Subcommands
1053
+ - \`init\` - Initialize hive mind system
1054
+ - \`spawn\` - Spawn hive mind swarm
1055
+ - \`status\` - Show hive mind status
1056
+ - \`resume\` - Resume paused session
1057
+ - \`stop\` - Stop running session
1058
+
1059
+ ## Examples
1060
+ \`\`\`bash
1061
+ # Initialize hive mind
1062
+ npx claude-flow hive-mind init
1063
+
1064
+ # Spawn swarm
1065
+ npx claude-flow hive-mind spawn "Build microservices"
1066
+
1067
+ # Check status
1068
+ npx claude-flow hive-mind status
1069
+ \`\`\`
1070
+ `,
1071
+ 'hive-mind-init': `# hive-mind-init
1072
+
1073
+ Initialize the Hive Mind collective intelligence system.
1074
+
1075
+ ## Usage
1076
+ \`\`\`bash
1077
+ npx claude-flow hive-mind init [options]
1078
+ \`\`\`
1079
+
1080
+ ## Options
1081
+ - \`--force\` - Force reinitialize
1082
+ - \`--config <file>\` - Configuration file
1083
+
1084
+ ## Examples
1085
+ \`\`\`bash
1086
+ npx claude-flow hive-mind init
1087
+ npx claude-flow hive-mind init --force
1088
+ \`\`\`
1089
+ `,
1090
+ 'hive-mind-spawn': `# hive-mind-spawn
1091
+
1092
+ Spawn a Hive Mind swarm with queen-led coordination.
1093
+
1094
+ ## Usage
1095
+ \`\`\`bash
1096
+ npx claude-flow hive-mind spawn <objective> [options]
1097
+ \`\`\`
1098
+
1099
+ ## Options
1100
+ - \`--queen-type <type>\` - Queen type (strategic, tactical, adaptive)
1101
+ - \`--max-workers <n>\` - Maximum worker agents
1102
+ - \`--consensus <type>\` - Consensus algorithm
1103
+ - \`--claude\` - Generate Claude Code spawn commands
1104
+
1105
+ ## Examples
1106
+ \`\`\`bash
1107
+ npx claude-flow hive-mind spawn "Build API"
1108
+ npx claude-flow hive-mind spawn "Research patterns" --queen-type adaptive
1109
+ npx claude-flow hive-mind spawn "Build service" --claude
1110
+ \`\`\`
1111
+ `,
1112
+ },
1113
+ agents: {
1114
+ 'agent-types': `# agent-types
1115
+
1116
+ Complete guide to all 54 available agent types in Claude Flow.
1117
+
1118
+ ## Core Development Agents
1119
+ - \`coder\` - Implementation specialist
1120
+ - \`reviewer\` - Code quality assurance
1121
+ - \`tester\` - Test creation and validation
1122
+ - \`planner\` - Strategic planning
1123
+ - \`researcher\` - Information gathering
1124
+
1125
+ ## Swarm Coordination Agents
1126
+ - \`hierarchical-coordinator\` - Queen-led coordination
1127
+ - \`mesh-coordinator\` - Peer-to-peer networks
1128
+ - \`adaptive-coordinator\` - Dynamic topology
1129
+
1130
+ ## Specialized Agents
1131
+ - \`backend-dev\` - API development
1132
+ - \`mobile-dev\` - React Native development
1133
+ - \`ml-developer\` - Machine learning
1134
+ - \`system-architect\` - High-level design
1135
+
1136
+ For full list and details:
1137
+ \`\`\`bash
1138
+ npx claude-flow agents list
1139
+ \`\`\`
1140
+ `,
1141
+ 'agent-capabilities': `# agent-capabilities
1142
+
1143
+ Matrix of agent capabilities and their specializations.
1144
+
1145
+ ## Capability Matrix
1146
+
1147
+ | Agent Type | Primary Skills | Best For |
1148
+ |------------|---------------|----------|
1149
+ | coder | Implementation, debugging | Feature development |
1150
+ | researcher | Analysis, synthesis | Requirements gathering |
1151
+ | tester | Testing, validation | Quality assurance |
1152
+ | architect | Design, planning | System architecture |
1153
+
1154
+ ## Querying Capabilities
1155
+ \`\`\`bash
1156
+ # List all capabilities
1157
+ npx claude-flow agents capabilities
1158
+
1159
+ # For specific agent
1160
+ npx claude-flow agents capabilities --type coder
1161
+ \`\`\`
1162
+ `,
1163
+ 'agent-coordination': `# agent-coordination
1164
+
1165
+ Coordination patterns for multi-agent collaboration.
1166
+
1167
+ ## Coordination Patterns
1168
+
1169
+ ### Hierarchical
1170
+ Queen-led with worker specialization
1171
+ \`\`\`bash
1172
+ npx claude-flow swarm init --topology hierarchical
1173
+ \`\`\`
1174
+
1175
+ ### Mesh
1176
+ Peer-to-peer collaboration
1177
+ \`\`\`bash
1178
+ npx claude-flow swarm init --topology mesh
1179
+ \`\`\`
1180
+
1181
+ ### Adaptive
1182
+ Dynamic topology based on workload
1183
+ \`\`\`bash
1184
+ npx claude-flow swarm init --topology adaptive
1185
+ \`\`\`
1186
+
1187
+ ## Best Practices
1188
+ - Use hierarchical for complex projects
1189
+ - Use mesh for research tasks
1190
+ - Use adaptive for unknown workloads
1191
+ `,
1192
+ 'agent-spawning': `# agent-spawning
1193
+
1194
+ Guide to spawning agents with Claude Code's Task tool.
1195
+
1196
+ ## Using Claude Code's Task Tool
1197
+
1198
+ **CRITICAL**: Always use Claude Code's Task tool for actual agent execution:
1199
+
1200
+ \`\`\`javascript
1201
+ // Spawn ALL agents in ONE message
1202
+ Task("Researcher", "Analyze requirements...", "researcher")
1203
+ Task("Coder", "Implement features...", "coder")
1204
+ Task("Tester", "Create tests...", "tester")
1205
+ \`\`\`
1206
+
1207
+ ## MCP Coordination Setup (Optional)
1208
+
1209
+ MCP tools are ONLY for coordination:
1210
+ \`\`\`javascript
1211
+ mcp__claude-flow__swarm_init { topology: "mesh" }
1212
+ mcp__claude-flow__agent_spawn { type: "researcher" }
1213
+ \`\`\`
1214
+
1215
+ ## Best Practices
1216
+ 1. Always spawn agents concurrently
1217
+ 2. Use Task tool for execution
1218
+ 3. MCP only for coordination
1219
+ 4. Batch all operations
1220
+ `,
1221
+ },
1222
+ };
1223
+
1224
+ return (
1225
+ docs[category]?.[command] ||
1226
+ `# ${command}\n\nCommand documentation for ${command} in category ${category}.\n\nUsage:\n\`\`\`bash\nnpx claude-flow ${category} ${command} [options]\n\`\`\`\n`
1227
+ );
1228
+ }
1229
+
1230
+ // Command categories and their commands
1231
+ export const COMMAND_STRUCTURE = {
1232
+ analysis: ['bottleneck-detect', 'token-usage', 'performance-report'],
1233
+ automation: ['auto-agent', 'smart-spawn', 'workflow-select'],
1234
+ coordination: ['swarm-init', 'agent-spawn', 'task-orchestrate'],
1235
+ github: ['github-swarm', 'repo-analyze', 'pr-enhance', 'issue-triage', 'code-review'],
1236
+ hooks: ['pre-task', 'post-task', 'pre-edit', 'post-edit', 'session-end'],
1237
+ memory: ['memory-usage', 'memory-persist', 'memory-search'],
1238
+ monitoring: ['swarm-monitor', 'agent-metrics', 'real-time-view'],
1239
+ optimization: ['topology-optimize', 'parallel-execute', 'cache-manage'],
1240
+ training: ['neural-train', 'pattern-learn', 'model-update'],
1241
+ workflows: ['workflow-create', 'workflow-execute', 'workflow-export'],
1242
+ swarm: [
1243
+ 'swarm',
1244
+ 'swarm-init',
1245
+ 'swarm-spawn',
1246
+ 'swarm-status',
1247
+ 'swarm-monitor',
1248
+ 'swarm-strategies',
1249
+ 'swarm-modes',
1250
+ 'swarm-background',
1251
+ 'swarm-analysis',
1252
+ ],
1253
+ 'hive-mind': [
1254
+ 'hive-mind',
1255
+ 'hive-mind-init',
1256
+ 'hive-mind-spawn',
1257
+ 'hive-mind-status',
1258
+ 'hive-mind-resume',
1259
+ 'hive-mind-stop',
1260
+ 'hive-mind-sessions',
1261
+ 'hive-mind-consensus',
1262
+ 'hive-mind-memory',
1263
+ 'hive-mind-metrics',
1264
+ 'hive-mind-wizard',
1265
+ ],
1266
+ agents: ['agent-types', 'agent-capabilities', 'agent-coordination', 'agent-spawning'],
1267
+ };
1268
+
1269
+ // Helper script content
1270
+ export function createHelperScript(name) {
1271
+ const scripts = {
1272
+ 'setup-mcp.sh': `#!/bin/bash
1273
+ # Setup MCP server for Claude Flow
1274
+
1275
+ echo "🚀 Setting up Claude Flow MCP server..."
1276
+
1277
+ # Check if claude command exists
1278
+ if ! command -v claude &> /dev/null; then
1279
+ echo "❌ Error: Claude Code CLI not found"
1280
+ echo "Please install Claude Code first"
1281
+ exit 1
1282
+ fi
1283
+
1284
+ # Add MCP server
1285
+ echo "📦 Adding Claude Flow MCP server..."
1286
+ claude mcp add claude-flow npx claude-flow mcp start
1287
+
1288
+ echo "✅ MCP server setup complete!"
1289
+ echo "🎯 You can now use mcp__claude-flow__ tools in Claude Code"
1290
+ `,
1291
+ 'quick-start.sh': `#!/bin/bash
1292
+ # Quick start guide for Claude Flow
1293
+
1294
+ echo "🚀 Claude Flow Quick Start"
1295
+ echo "=========================="
1296
+ echo ""
1297
+ echo "1. Initialize a swarm:"
1298
+ echo " npx claude-flow swarm init --topology hierarchical"
1299
+ echo ""
1300
+ echo "2. Spawn agents:"
1301
+ echo " npx claude-flow agent spawn --type coder --name \"API Developer\""
1302
+ echo ""
1303
+ echo "3. Orchestrate tasks:"
1304
+ echo " npx claude-flow task orchestrate --task \"Build REST API\""
1305
+ echo ""
1306
+ echo "4. Monitor progress:"
1307
+ echo " npx claude-flow swarm monitor"
1308
+ echo ""
1309
+ echo "📚 For more examples, see .claude/commands/"
1310
+ `,
1311
+ 'github-setup.sh': `#!/bin/bash
1312
+ # Setup GitHub integration for Claude Flow
1313
+
1314
+ echo "🔗 Setting up GitHub integration..."
1315
+
1316
+ # Check for gh CLI
1317
+ if ! command -v gh &> /dev/null; then
1318
+ echo "⚠️ GitHub CLI (gh) not found"
1319
+ echo "Install from: https://cli.github.com/"
1320
+ echo "Continuing without GitHub features..."
1321
+ else
1322
+ echo "✅ GitHub CLI found"
1323
+
1324
+ # Check auth status
1325
+ if gh auth status &> /dev/null; then
1326
+ echo "✅ GitHub authentication active"
1327
+ else
1328
+ echo "⚠️ Not authenticated with GitHub"
1329
+ echo "Run: gh auth login"
1330
+ fi
1331
+ fi
1332
+
1333
+ echo ""
1334
+ echo "📦 GitHub swarm commands available:"
1335
+ echo " - npx claude-flow github swarm"
1336
+ echo " - npx claude-flow repo analyze"
1337
+ echo " - npx claude-flow pr enhance"
1338
+ echo " - npx claude-flow issue triage"
1339
+ `,
1340
+ 'github-safe.js': `#!/usr/bin/env node
1341
+
1342
+ /**
1343
+ * Safe GitHub CLI Helper
1344
+ * Prevents timeout issues when using gh commands with special characters
1345
+ *
1346
+ * Usage:
1347
+ * ./github-safe.js issue comment 123 "Message with \`backticks\`"
1348
+ * ./github-safe.js pr create --title "Title" --body "Complex body"
1349
+ */
1350
+
1351
+ import { execSync } from 'child_process';
1352
+ import { writeFileSync, unlinkSync } from 'fs';
1353
+ import { tmpdir } from 'os';
1354
+ import { join } from 'path';
1355
+ import { randomBytes } from 'crypto';
1356
+
1357
+ const args = process.argv.slice(2);
1358
+
1359
+ if (args.length < 2) {
1360
+ console.log(\`
1361
+ Safe GitHub CLI Helper
1362
+
1363
+ Usage:
1364
+ ./github-safe.js issue comment <number> <body>
1365
+ ./github-safe.js pr comment <number> <body>
1366
+ ./github-safe.js issue create --title <title> --body <body>
1367
+ ./github-safe.js pr create --title <title> --body <body>
1368
+
1369
+ This helper prevents timeout issues with special characters like:
1370
+ - Backticks in code examples
1371
+ - Command substitution \\$(...)
1372
+ - Directory paths
1373
+ - Special shell characters
1374
+ \`);
1375
+ process.exit(1);
1376
+ }
1377
+
1378
+ const [command, subcommand, ...restArgs] = args;
1379
+
1380
+ // Handle commands that need body content
1381
+ if ((command === 'issue' || command === 'pr') &&
1382
+ (subcommand === 'comment' || subcommand === 'create')) {
1383
+
1384
+ let bodyIndex = -1;
1385
+ let body = '';
1386
+
1387
+ if (subcommand === 'comment' && restArgs.length >= 2) {
1388
+ // Simple format: github-safe.js issue comment 123 "body"
1389
+ body = restArgs[1];
1390
+ bodyIndex = 1;
1391
+ } else {
1392
+ // Flag format: --body "content"
1393
+ bodyIndex = restArgs.indexOf('--body');
1394
+ if (bodyIndex !== -1 && bodyIndex < restArgs.length - 1) {
1395
+ body = restArgs[bodyIndex + 1];
1396
+ }
1397
+ }
1398
+
1399
+ if (body) {
1400
+ // Use temporary file for body content
1401
+ const tmpFile = join(tmpdir(), \`gh-body-\${randomBytes(8).toString('hex')}.tmp\`);
1402
+
1403
+ try {
1404
+ writeFileSync(tmpFile, body, 'utf8');
1405
+
1406
+ // Build new command with --body-file
1407
+ const newArgs = [...restArgs];
1408
+ if (subcommand === 'comment' && bodyIndex === 1) {
1409
+ // Replace body with --body-file
1410
+ newArgs[1] = '--body-file';
1411
+ newArgs.push(tmpFile);
1412
+ } else if (bodyIndex !== -1) {
1413
+ // Replace --body with --body-file
1414
+ newArgs[bodyIndex] = '--body-file';
1415
+ newArgs[bodyIndex + 1] = tmpFile;
1416
+ }
1417
+
1418
+ // Execute safely
1419
+ const ghCommand = \`gh \${command} \${subcommand} \${newArgs.join(' ')}\`;
1420
+ console.log(\`Executing: \${ghCommand}\`);
1421
+
1422
+ const result = execSync(ghCommand, {
1423
+ stdio: 'inherit',
1424
+ timeout: 30000 // 30 second timeout
1425
+ });
1426
+
1427
+ } catch (error) {
1428
+ console.error('Error:', error.message);
1429
+ process.exit(1);
1430
+ } finally {
1431
+ // Clean up
1432
+ try {
1433
+ unlinkSync(tmpFile);
1434
+ } catch (e) {
1435
+ // Ignore cleanup errors
1436
+ }
1437
+ }
1438
+ } else {
1439
+ // No body content, execute normally
1440
+ execSync(\`gh \${args.join(' ')}\`, { stdio: 'inherit' });
1441
+ }
1442
+ } else {
1443
+ // Other commands, execute normally
1444
+ execSync(\`gh \${args.join(' ')}\`, { stdio: 'inherit' });
1445
+ }
1446
+ `,
1447
+ 'checkpoint-hooks.sh': `#!/bin/bash
1448
+ # Checkpoint hook functions for Claude settings.json
1449
+
1450
+ # Function to handle pre-edit checkpoints
1451
+ pre_edit_checkpoint() {
1452
+ local tool_input="$1"
1453
+ local file=$(echo "$tool_input" | jq -r '.file_path // empty')
1454
+
1455
+ if [ -n "$file" ]; then
1456
+ local checkpoint_branch="checkpoint/pre-edit-$(date +%Y%m%d-%H%M%S)"
1457
+ local current_branch=$(git branch --show-current)
1458
+
1459
+ # Create checkpoint
1460
+ git add -A
1461
+ git stash push -m "Pre-edit checkpoint for $file" >/dev/null 2>&1
1462
+ git branch "$checkpoint_branch"
1463
+
1464
+ # Store metadata
1465
+ mkdir -p .claude/checkpoints
1466
+ cat > ".claude/checkpoints/$(date +%s).json" <<EOF
1467
+ {
1468
+ "branch": "$checkpoint_branch",
1469
+ "file": "$file",
1470
+ "timestamp": "$(date -u +%Y-%m-%dT%H:%M:%SZ)",
1471
+ "type": "pre-edit",
1472
+ "original_branch": "$current_branch"
1473
+ }
1474
+ EOF
1475
+
1476
+ # Restore working directory
1477
+ git stash pop --quiet >/dev/null 2>&1 || true
1478
+
1479
+ echo "✅ Created checkpoint: $checkpoint_branch for $file"
1480
+ fi
1481
+ }
1482
+
1483
+ # Function to handle post-edit checkpoints
1484
+ post_edit_checkpoint() {
1485
+ local tool_input="$1"
1486
+ local file=$(echo "$tool_input" | jq -r '.file_path // empty')
1487
+
1488
+ if [ -n "$file" ] && [ -f "$file" ]; then
1489
+ # Check if file was modified - first check if file is tracked
1490
+ if ! git ls-files --error-unmatch "$file" >/dev/null 2>&1; then
1491
+ # File is not tracked, add it first
1492
+ git add "$file"
1493
+ fi
1494
+
1495
+ # Now check if there are changes
1496
+ if git diff --cached --quiet "$file" 2>/dev/null && git diff --quiet "$file" 2>/dev/null; then
1497
+ echo "ℹ️ No changes to checkpoint for $file"
1498
+ else
1499
+ local tag_name="checkpoint-$(date +%Y%m%d-%H%M%S)"
1500
+ local current_branch=$(git branch --show-current)
1501
+
1502
+ # Create commit
1503
+ git add "$file"
1504
+ if git commit -m "🔖 Checkpoint: Edit $file
1505
+
1506
+ Automatic checkpoint created by Claude
1507
+ - File: $file
1508
+ - Branch: $current_branch
1509
+ - Timestamp: $(date -u +%Y-%m-%dT%H:%M:%SZ)
1510
+
1511
+ [Auto-checkpoint]" --quiet; then
1512
+ # Create tag only if commit succeeded
1513
+ git tag -a "$tag_name" -m "Checkpoint after editing $file"
1514
+
1515
+ # Store metadata
1516
+ mkdir -p .claude/checkpoints
1517
+ local diff_stats=$(git diff HEAD~1 --stat | tr '\\n' ' ' | sed 's/"/\\\\"/g')
1518
+ cat > ".claude/checkpoints/$(date +%s).json" <<EOF
1519
+ {
1520
+ "tag": "$tag_name",
1521
+ "file": "$file",
1522
+ "timestamp": "$(date -u +%Y-%m-%dT%H:%M:%SZ)",
1523
+ "type": "post-edit",
1524
+ "branch": "$current_branch",
1525
+ "diff_summary": "$diff_stats"
1526
+ }
1527
+ EOF
1528
+
1529
+ echo "✅ Created checkpoint: $tag_name for $file"
1530
+ else
1531
+ echo "ℹ️ No commit created (no changes or commit failed)"
1532
+ fi
1533
+ fi
1534
+ fi
1535
+ }
1536
+
1537
+ # Function to handle task checkpoints
1538
+ task_checkpoint() {
1539
+ local user_prompt="$1"
1540
+ local task=$(echo "$user_prompt" | head -c 100 | tr '\\n' ' ')
1541
+
1542
+ if [ -n "$task" ]; then
1543
+ local checkpoint_name="task-$(date +%Y%m%d-%H%M%S)"
1544
+
1545
+ # Commit current state
1546
+ git add -A
1547
+ git commit -m "🔖 Task checkpoint: $task..." --quiet || true
1548
+
1549
+ # No GitHub release in standard version
1550
+
1551
+ # Store metadata
1552
+ mkdir -p .claude/checkpoints
1553
+ cat > ".claude/checkpoints/task-$(date +%s).json" <<EOF
1554
+ {
1555
+ "checkpoint": "$checkpoint_name",
1556
+ "task": "$task",
1557
+ "timestamp": "$(date -u +%Y-%m-%dT%H:%M:%SZ)",
1558
+ "commit": "$(git rev-parse HEAD)"
1559
+ }
1560
+ EOF
1561
+
1562
+ echo "✅ Created task checkpoint: $checkpoint_name"
1563
+ fi
1564
+ }
1565
+
1566
+ # Function to handle session end
1567
+ session_end_checkpoint() {
1568
+ local session_id="session-$(date +%Y%m%d-%H%M%S)"
1569
+ local summary_file=".claude/checkpoints/summary-$session_id.md"
1570
+
1571
+ mkdir -p .claude/checkpoints
1572
+
1573
+ # Create summary
1574
+ cat > "$summary_file" <<EOF
1575
+ # Session Summary - $(date +'%Y-%m-%d %H:%M:%S')
1576
+
1577
+ ## Checkpoints Created
1578
+ $(find .claude/checkpoints -name '*.json' -mtime -1 -exec basename {} \\; | sort)
1579
+
1580
+ ## Files Modified
1581
+ $(git diff --name-only $(git log --format=%H -n 1 --before="1 hour ago" 2>/dev/null) 2>/dev/null || echo "No files tracked")
1582
+
1583
+ ## Recent Commits
1584
+ $(git log --oneline -10 --grep="Checkpoint" || echo "No checkpoint commits")
1585
+
1586
+ ## Rollback Instructions
1587
+ To rollback to a specific checkpoint:
1588
+ \\\`\\\`\\\`bash
1589
+ # List all checkpoints
1590
+ git tag -l 'checkpoint-*' | sort -r
1591
+
1592
+ # Rollback to a checkpoint
1593
+ git checkout checkpoint-YYYYMMDD-HHMMSS
1594
+
1595
+ # Or reset to a checkpoint (destructive)
1596
+ git reset --hard checkpoint-YYYYMMDD-HHMMSS
1597
+ \\\`\\\`\\\`
1598
+ EOF
1599
+
1600
+ # Create final checkpoint
1601
+ git add -A
1602
+ git commit -m "🏁 Session end checkpoint: $session_id" --quiet || true
1603
+ git tag -a "session-end-$session_id" -m "End of Claude session"
1604
+
1605
+ echo "✅ Session summary saved to: $summary_file"
1606
+ echo "📌 Final checkpoint: session-end-$session_id"
1607
+ }
1608
+
1609
+ # Main entry point
1610
+ case "$1" in
1611
+ pre-edit)
1612
+ pre_edit_checkpoint "$2"
1613
+ ;;
1614
+ post-edit)
1615
+ post_edit_checkpoint "$2"
1616
+ ;;
1617
+ task)
1618
+ task_checkpoint "$2"
1619
+ ;;
1620
+ session-end)
1621
+ session_end_checkpoint
1622
+ ;;
1623
+ *)
1624
+ echo "Usage: $0 {pre-edit|post-edit|task|session-end} [input]"
1625
+ exit 1
1626
+ ;;
1627
+ esac
1628
+ `,
1629
+ 'checkpoint-manager.sh': `#!/bin/bash
1630
+ # Claude Checkpoint Manager
1631
+ # Provides easy rollback and management of Claude Code checkpoints
1632
+
1633
+ set -e
1634
+
1635
+ # Colors
1636
+ RED='\\033[0;31m'
1637
+ GREEN='\\033[0;32m'
1638
+ YELLOW='\\033[1;33m'
1639
+ BLUE='\\033[0;34m'
1640
+ NC='\\033[0m' # No Color
1641
+
1642
+ # Configuration
1643
+ CHECKPOINT_DIR=".claude/checkpoints"
1644
+ BACKUP_DIR=".claude/backups"
1645
+
1646
+ # Help function
1647
+ show_help() {
1648
+ cat << EOF
1649
+ Claude Checkpoint Manager
1650
+ ========================
1651
+
1652
+ Usage: $0 <command> [options]
1653
+
1654
+ Commands:
1655
+ list List all checkpoints
1656
+ show <id> Show details of a specific checkpoint
1657
+ rollback <id> Rollback to a specific checkpoint
1658
+ diff <id> Show diff since checkpoint
1659
+ clean Clean old checkpoints (older than 7 days)
1660
+ summary Show session summary
1661
+
1662
+ Options:
1663
+ --hard For rollback: use git reset --hard (destructive)
1664
+ --soft For rollback: use git reset --soft (default)
1665
+ --branch For rollback: create new branch from checkpoint
1666
+
1667
+ Examples:
1668
+ $0 list
1669
+ $0 show checkpoint-20240130-143022
1670
+ $0 rollback checkpoint-20240130-143022 --branch
1671
+ $0 diff session-end-session-20240130-150000
1672
+ EOF
1673
+ }
1674
+
1675
+ # List all checkpoints
1676
+ function list_checkpoints() {
1677
+ echo -e "\${BLUE}📋 Available Checkpoints:\${NC}"
1678
+ echo ""
1679
+
1680
+ # List checkpoint tags
1681
+ echo -e "\${YELLOW}Git Tags:\${NC}"
1682
+ local tags=$(git tag -l 'checkpoint-*' -l 'session-end-*' -l 'task-*' --sort=-creatordate | head -20)
1683
+ if [ -n "$tags" ]; then
1684
+ echo "$tags"
1685
+ else
1686
+ echo "No checkpoint tags found"
1687
+ fi
1688
+
1689
+ echo ""
1690
+
1691
+ # List checkpoint branches
1692
+ echo -e "\${YELLOW}Checkpoint Branches:\${NC}"
1693
+ local branches=$(git branch -a | grep "checkpoint/" | sed 's/^[ *]*//')
1694
+ if [ -n "$branches" ]; then
1695
+ echo "$branches"
1696
+ else
1697
+ echo "No checkpoint branches found"
1698
+ fi
1699
+
1700
+ echo ""
1701
+
1702
+ # List checkpoint files
1703
+ if [ -d "$CHECKPOINT_DIR" ]; then
1704
+ echo -e "\${YELLOW}Recent Checkpoint Files:\${NC}"
1705
+ find "$CHECKPOINT_DIR" -name "*.json" -type f -printf "%T@ %p\\n" | \\
1706
+ sort -rn | head -10 | cut -d' ' -f2- | xargs -I {} basename {}
1707
+ fi
1708
+ }
1709
+
1710
+ # Show checkpoint details
1711
+ function show_checkpoint() {
1712
+ local checkpoint_id="$1"
1713
+
1714
+ echo -e "\${BLUE}📍 Checkpoint Details: $checkpoint_id\${NC}"
1715
+ echo ""
1716
+
1717
+ # Check if it's a tag
1718
+ if git tag -l "$checkpoint_id" | grep -q "$checkpoint_id"; then
1719
+ echo -e "\${YELLOW}Type:\${NC} Git Tag"
1720
+ echo -e "\${YELLOW}Commit:\${NC} $(git rev-list -n 1 "$checkpoint_id")"
1721
+ echo -e "\${YELLOW}Date:\${NC} $(git log -1 --format=%ai "$checkpoint_id")"
1722
+ echo -e "\${YELLOW}Message:\${NC}"
1723
+ git log -1 --format=%B "$checkpoint_id" | sed 's/^/ /'
1724
+ echo ""
1725
+ echo -e "\${YELLOW}Files changed:\${NC}"
1726
+ git diff-tree --no-commit-id --name-status -r "$checkpoint_id" | sed 's/^/ /'
1727
+ # Check if it's a branch
1728
+ elif git branch -a | grep -q "$checkpoint_id"; then
1729
+ echo -e "\${YELLOW}Type:\${NC} Git Branch"
1730
+ echo -e "\${YELLOW}Latest commit:\${NC}"
1731
+ git log -1 --oneline "$checkpoint_id"
1732
+ else
1733
+ echo -e "\${RED}❌ Checkpoint not found: $checkpoint_id\${NC}"
1734
+ exit 1
1735
+ fi
1736
+ }
1737
+
1738
+ # Rollback to checkpoint
1739
+ function rollback_checkpoint() {
1740
+ local checkpoint_id="$1"
1741
+ local mode="$2"
1742
+
1743
+ echo -e "\${YELLOW}🔄 Rolling back to checkpoint: $checkpoint_id\${NC}"
1744
+ echo ""
1745
+
1746
+ # Verify checkpoint exists
1747
+ if ! git tag -l "$checkpoint_id" | grep -q "$checkpoint_id" && \\
1748
+ ! git branch -a | grep -q "$checkpoint_id"; then
1749
+ echo -e "\${RED}❌ Checkpoint not found: $checkpoint_id\${NC}"
1750
+ exit 1
1751
+ fi
1752
+
1753
+ # Create backup before rollback
1754
+ local backup_name="backup-$(date +%Y%m%d-%H%M%S)"
1755
+ echo "Creating backup: $backup_name"
1756
+ git tag "$backup_name" -m "Backup before rollback to $checkpoint_id"
1757
+
1758
+ case "$mode" in
1759
+ "--hard")
1760
+ echo -e "\${RED}⚠️ Performing hard reset (destructive)\${NC}"
1761
+ git reset --hard "$checkpoint_id"
1762
+ echo -e "\${GREEN}✅ Rolled back to $checkpoint_id (hard reset)\${NC}"
1763
+ ;;
1764
+ "--branch")
1765
+ local branch_name="rollback-$checkpoint_id-$(date +%Y%m%d-%H%M%S)"
1766
+ echo "Creating new branch: $branch_name"
1767
+ git checkout -b "$branch_name" "$checkpoint_id"
1768
+ echo -e "\${GREEN}✅ Created branch $branch_name from $checkpoint_id\${NC}"
1769
+ ;;
1770
+ "--stash"|*)
1771
+ echo "Stashing current changes..."
1772
+ git stash push -m "Stash before rollback to $checkpoint_id"
1773
+ git reset --soft "$checkpoint_id"
1774
+ echo -e "\${GREEN}✅ Rolled back to $checkpoint_id (soft reset)\${NC}"
1775
+ echo "Your changes are stashed. Use 'git stash pop' to restore them."
1776
+ ;;
1777
+ esac
1778
+ }
1779
+
1780
+ # Show diff since checkpoint
1781
+ function diff_checkpoint() {
1782
+ local checkpoint_id="$1"
1783
+
1784
+ echo -e "\${BLUE}📊 Changes since checkpoint: $checkpoint_id\${NC}"
1785
+ echo ""
1786
+
1787
+ if git tag -l "$checkpoint_id" | grep -q "$checkpoint_id"; then
1788
+ git diff "$checkpoint_id"
1789
+ elif git branch -a | grep -q "$checkpoint_id"; then
1790
+ git diff "$checkpoint_id"
1791
+ else
1792
+ echo -e "\${RED}❌ Checkpoint not found: $checkpoint_id\${NC}"
1793
+ exit 1
1794
+ fi
1795
+ }
1796
+
1797
+ # Clean old checkpoints
1798
+ function clean_checkpoints() {
1799
+ local days=\${1:-7}
1800
+
1801
+ echo -e "\${YELLOW}🧹 Cleaning checkpoints older than $days days...\${NC}"
1802
+ echo ""
1803
+
1804
+ # Clean old checkpoint files
1805
+ if [ -d "$CHECKPOINT_DIR" ]; then
1806
+ find "$CHECKPOINT_DIR" -name "*.json" -type f -mtime +$days -delete
1807
+ echo "✅ Cleaned old checkpoint files"
1808
+ fi
1809
+
1810
+ # List old tags (but don't delete automatically)
1811
+ echo ""
1812
+ echo "Old checkpoint tags (manual deletion required):"
1813
+ git tag -l 'checkpoint-*' --sort=-creatordate | tail -n +50 || echo "No old tags found"
1814
+ }
1815
+
1816
+ # Show session summary
1817
+ function show_summary() {
1818
+ echo -e "\${BLUE}📊 Session Summary\${NC}"
1819
+ echo ""
1820
+
1821
+ # Find most recent session summary
1822
+ if [ -d "$CHECKPOINT_DIR" ]; then
1823
+ local latest_summary=$(find "$CHECKPOINT_DIR" -name "summary-*.md" -type f -printf "%T@ %p\\n" | \\
1824
+ sort -rn | head -1 | cut -d' ' -f2-)
1825
+
1826
+ if [ -n "$latest_summary" ]; then
1827
+ echo -e "\${YELLOW}Latest session summary:\${NC}"
1828
+ cat "$latest_summary"
1829
+ else
1830
+ echo "No session summaries found"
1831
+ fi
1832
+ fi
1833
+ }
1834
+
1835
+ # Main command handling
1836
+ case "$1" in
1837
+ list)
1838
+ list_checkpoints
1839
+ ;;
1840
+ show)
1841
+ if [ -z "$2" ]; then
1842
+ echo -e "\${RED}Error: Please specify a checkpoint ID\${NC}"
1843
+ show_help
1844
+ exit 1
1845
+ fi
1846
+ show_checkpoint "$2"
1847
+ ;;
1848
+ rollback)
1849
+ if [ -z "$2" ]; then
1850
+ echo -e "\${RED}Error: Please specify a checkpoint ID\${NC}"
1851
+ show_help
1852
+ exit 1
1853
+ fi
1854
+ rollback_checkpoint "$2" "$3"
1855
+ ;;
1856
+ diff)
1857
+ if [ -z "$2" ]; then
1858
+ echo -e "\${RED}Error: Please specify a checkpoint ID\${NC}"
1859
+ show_help
1860
+ exit 1
1861
+ fi
1862
+ diff_checkpoint "$2"
1863
+ ;;
1864
+ clean)
1865
+ clean_checkpoints "$2"
1866
+ ;;
1867
+ summary)
1868
+ show_summary
1869
+ ;;
1870
+ help|--help|-h)
1871
+ show_help
1872
+ ;;
1873
+ *)
1874
+ echo -e "\${RED}Error: Unknown command: $1\${NC}"
1875
+ echo ""
1876
+ show_help
1877
+ exit 1
1878
+ ;;
1879
+ esac
1880
+ `,
1881
+ 'standard-checkpoint-hooks.sh': `#!/bin/bash
1882
+ # Standard checkpoint hook functions for Claude settings.json (without GitHub features)
1883
+
1884
+ # Function to handle pre-edit checkpoints
1885
+ pre_edit_checkpoint() {
1886
+ local tool_input="$1"
1887
+ local file=$(echo "$tool_input" | jq -r '.file_path // empty')
1888
+
1889
+ if [ -n "$file" ]; then
1890
+ local checkpoint_branch="checkpoint/pre-edit-$(date +%Y%m%d-%H%M%S)"
1891
+ local current_branch=$(git branch --show-current)
1892
+
1893
+ # Create checkpoint
1894
+ git add -A
1895
+ git stash push -m "Pre-edit checkpoint for $file" >/dev/null 2>&1
1896
+ git branch "$checkpoint_branch"
1897
+
1898
+ # Store metadata
1899
+ mkdir -p .claude/checkpoints
1900
+ cat > ".claude/checkpoints/$(date +%s).json" <<EOF
1901
+ {
1902
+ "branch": "$checkpoint_branch",
1903
+ "file": "$file",
1904
+ "timestamp": "$(date -u +%Y-%m-%dT%H:%M:%SZ)",
1905
+ "type": "pre-edit",
1906
+ "original_branch": "$current_branch"
1907
+ }
1908
+ EOF
1909
+
1910
+ # Restore working directory
1911
+ git stash pop --quiet >/dev/null 2>&1 || true
1912
+
1913
+ echo "✅ Created checkpoint: $checkpoint_branch for $file"
1914
+ fi
1915
+ }
1916
+
1917
+ # Function to handle post-edit checkpoints
1918
+ post_edit_checkpoint() {
1919
+ local tool_input="$1"
1920
+ local file=$(echo "$tool_input" | jq -r '.file_path // empty')
1921
+
1922
+ if [ -n "$file" ] && [ -f "$file" ]; then
1923
+ # Check if file was modified - first check if file is tracked
1924
+ if ! git ls-files --error-unmatch "$file" >/dev/null 2>&1; then
1925
+ # File is not tracked, add it first
1926
+ git add "$file"
1927
+ fi
1928
+
1929
+ # Now check if there are changes
1930
+ if git diff --cached --quiet "$file" 2>/dev/null && git diff --quiet "$file" 2>/dev/null; then
1931
+ echo "ℹ️ No changes to checkpoint for $file"
1932
+ else
1933
+ local tag_name="checkpoint-$(date +%Y%m%d-%H%M%S)"
1934
+ local current_branch=$(git branch --show-current)
1935
+
1936
+ # Create commit
1937
+ git add "$file"
1938
+ if git commit -m "🔖 Checkpoint: Edit $file
1939
+
1940
+ Automatic checkpoint created by Claude
1941
+ - File: $file
1942
+ - Branch: $current_branch
1943
+ - Timestamp: $(date -u +%Y-%m-%dT%H:%M:%SZ)
1944
+
1945
+ [Auto-checkpoint]" --quiet; then
1946
+ # Create tag only if commit succeeded
1947
+ git tag -a "$tag_name" -m "Checkpoint after editing $file"
1948
+
1949
+ # Store metadata
1950
+ mkdir -p .claude/checkpoints
1951
+ local diff_stats=$(git diff HEAD~1 --stat | tr '\\n' ' ' | sed 's/"/\\"/g')
1952
+ cat > ".claude/checkpoints/$(date +%s).json" <<EOF
1953
+ {
1954
+ "tag": "$tag_name",
1955
+ "file": "$file",
1956
+ "timestamp": "$(date -u +%Y-%m-%dT%H:%M:%SZ)",
1957
+ "type": "post-edit",
1958
+ "branch": "$current_branch",
1959
+ "diff_summary": "$diff_stats"
1960
+ }
1961
+ EOF
1962
+
1963
+ echo "✅ Created checkpoint: $tag_name for $file"
1964
+ else
1965
+ echo "ℹ️ No commit created (no changes or commit failed)"
1966
+ fi
1967
+ fi
1968
+ fi
1969
+ }
1970
+
1971
+ # Function to handle task checkpoints
1972
+ task_checkpoint() {
1973
+ local user_prompt="$1"
1974
+ local task=$(echo "$user_prompt" | head -c 100 | tr '\\n' ' ')
1975
+
1976
+ if [ -n "$task" ]; then
1977
+ local checkpoint_name="task-$(date +%Y%m%d-%H%M%S)"
1978
+
1979
+ # Commit current state
1980
+ git add -A
1981
+ git commit -m "🔖 Task checkpoint: $task..." --quiet || true
1982
+
1983
+ # Store metadata
1984
+ mkdir -p .claude/checkpoints
1985
+ cat > ".claude/checkpoints/task-$(date +%s).json" <<EOF
1986
+ {
1987
+ "checkpoint": "$checkpoint_name",
1988
+ "task": "$task",
1989
+ "timestamp": "$(date -u +%Y-%m-%dT%H:%M:%SZ)",
1990
+ "commit": "$(git rev-parse HEAD)"
1991
+ }
1992
+ EOF
1993
+
1994
+ echo "✅ Created task checkpoint: $checkpoint_name"
1995
+ fi
1996
+ }
1997
+
1998
+ # Function to handle session end
1999
+ session_end_checkpoint() {
2000
+ local session_id="session-$(date +%Y%m%d-%H%M%S)"
2001
+ local summary_file=".claude/checkpoints/summary-$session_id.md"
2002
+
2003
+ mkdir -p .claude/checkpoints
2004
+
2005
+ # Create summary
2006
+ cat > "$summary_file" <<EOF
2007
+ # Session Summary - $(date +'%Y-%m-%d %H:%M:%S')
2008
+
2009
+ ## Checkpoints Created
2010
+ $(find .claude/checkpoints -name '*.json' -mtime -1 -exec basename {} \\; | sort)
2011
+
2012
+ ## Files Modified
2013
+ $(git diff --name-only $(git log --format=%H -n 1 --before="1 hour ago" 2>/dev/null) 2>/dev/null || echo "No files tracked")
2014
+
2015
+ ## Recent Commits
2016
+ $(git log --oneline -10 --grep="Checkpoint" || echo "No checkpoint commits")
2017
+
2018
+ ## Rollback Instructions
2019
+ To rollback to a specific checkpoint:
2020
+ \\\`\\\`\\\`bash
2021
+ # List all checkpoints
2022
+ git tag -l 'checkpoint-*' | sort -r
2023
+
2024
+ # Rollback to a checkpoint
2025
+ git checkout checkpoint-YYYYMMDD-HHMMSS
2026
+
2027
+ # Or reset to a checkpoint (destructive)
2028
+ git reset --hard checkpoint-YYYYMMDD-HHMMSS
2029
+ \\\`\\\`\\\`
2030
+ EOF
2031
+
2032
+ # Create final checkpoint
2033
+ git add -A
2034
+ git commit -m "🏁 Session end checkpoint: $session_id" --quiet || true
2035
+ git tag -a "session-end-$session_id" -m "End of Claude session"
2036
+
2037
+ echo "✅ Session summary saved to: $summary_file"
2038
+ echo "📌 Final checkpoint: session-end-$session_id"
2039
+ }
2040
+
2041
+ # Main entry point
2042
+ case "$1" in
2043
+ pre-edit)
2044
+ pre_edit_checkpoint "$2"
2045
+ ;;
2046
+ post-edit)
2047
+ post_edit_checkpoint "$2"
2048
+ ;;
2049
+ task)
2050
+ task_checkpoint "$2"
2051
+ ;;
2052
+ session-end)
2053
+ session_end_checkpoint
2054
+ ;;
2055
+ *)
2056
+ echo "Usage: $0 {pre-edit|post-edit|task|session-end} [input]"
2057
+ exit 1
2058
+ ;;
2059
+ esac
2060
+ `,
2061
+ };
2062
+
2063
+ return scripts[name] || '';
2064
+ }
2065
+
2066
+ // Wrapper script fallbacks
2067
+ function createWrapperScriptFallback(type) {
2068
+ if (type === 'unix') {
2069
+ // Return the universal ES module compatible wrapper
2070
+ return `#!/usr/bin/env node
2071
+
2072
+ /**
2073
+ * Claude Flow CLI - Universal Wrapper
2074
+ * Works in both CommonJS and ES Module projects
2075
+ */
2076
+
2077
+ // Use dynamic import to work in both CommonJS and ES modules
2078
+ (async () => {
2079
+ const { spawn } = await import('child_process');
2080
+ const { resolve } = await import('path');
2081
+ const { fileURLToPath } = await import('url');
2082
+
2083
+ try {
2084
+ // Try to use import.meta.url (ES modules)
2085
+ const __filename = fileURLToPath(import.meta.url);
2086
+ const __dirname = resolve(__filename, '..');
2087
+ } catch {
2088
+ // Fallback for CommonJS
2089
+ }
2090
+
2091
+ // Try multiple strategies to find claude-flow
2092
+ const strategies = [
2093
+ // 1. Local node_modules
2094
+ async () => {
2095
+ try {
2096
+ const localPath = resolve(process.cwd(), 'node_modules/.bin/claude-flow');
2097
+ const { existsSync } = await import('fs');
2098
+ if (existsSync(localPath)) {
2099
+ return spawn(localPath, process.argv.slice(2), { stdio: 'inherit' });
2100
+ }
2101
+ } catch {}
2102
+ },
2103
+
2104
+ // 2. Parent node_modules (monorepo)
2105
+ async () => {
2106
+ try {
2107
+ const parentPath = resolve(process.cwd(), '../node_modules/.bin/claude-flow');
2108
+ const { existsSync } = await import('fs');
2109
+ if (existsSync(parentPath)) {
2110
+ return spawn(parentPath, process.argv.slice(2), { stdio: 'inherit' });
2111
+ }
2112
+ } catch {}
2113
+ },
2114
+
2115
+ // 3. NPX with latest alpha version (prioritized over global)
2116
+ async () => {
2117
+ return spawn('npx', ['claude-flow@2.0.0-alpha.25', ...process.argv.slice(2)], { stdio: 'inherit' });
2118
+ }
2119
+ ];
2120
+
2121
+ // Try each strategy
2122
+ for (const strategy of strategies) {
2123
+ try {
2124
+ const child = await strategy();
2125
+ if (child) {
2126
+ child.on('exit', (code) => process.exit(code || 0));
2127
+ child.on('error', (err) => {
2128
+ if (err.code !== 'ENOENT') {
2129
+ console.error('Error:', err);
2130
+ process.exit(1);
2131
+ }
2132
+ });
2133
+ return;
2134
+ }
2135
+ } catch {}
2136
+ }
2137
+
2138
+ console.error('Could not find claude-flow. Please install it with: npm install claude-flow');
2139
+ process.exit(1);
2140
+ })();`;
2141
+ } else if (type === 'windows') {
2142
+ return `@echo off
2143
+ rem Claude Flow wrapper script for Windows
2144
+
2145
+ rem Check if package.json exists in current directory
2146
+ if exist "%~dp0package.json" (
2147
+ rem Local development mode
2148
+ if exist "%~dp0src\\cli\\simple-cli.js" (
2149
+ node "%~dp0src\\cli\\simple-cli.js" %*
2150
+ ) else if exist "%~dp0dist\\cli.js" (
2151
+ node "%~dp0dist\\cli.js" %*
2152
+ ) else (
2153
+ echo Error: Could not find Claude Flow CLI files
2154
+ exit /b 1
2155
+ )
2156
+ ) else (
2157
+ rem Production mode - use npx alpha
2158
+ npx claude-flow@alpha %*
2159
+ )`;
2160
+ } else if (type === 'powershell') {
2161
+ return `# Claude Flow wrapper script for PowerShell
2162
+
2163
+ $scriptPath = Split-Path -Parent $MyInvocation.MyCommand.Path
2164
+
2165
+ if (Test-Path "$scriptPath\\package.json") {
2166
+ # Local development mode
2167
+ if (Test-Path "$scriptPath\\src\\cli\\simple-cli.js") {
2168
+ & node "$scriptPath\\src\\cli\\simple-cli.js" $args
2169
+ } elseif (Test-Path "$scriptPath\\dist\\cli.js") {
2170
+ & node "$scriptPath\\dist\\cli.js" $args
2171
+ } else {
2172
+ Write-Error "Could not find Claude Flow CLI files"
2173
+ exit 1
2174
+ }
2175
+ } else {
2176
+ # Production mode - use npx alpha
2177
+ & npx claude-flow@alpha $args
2178
+ }`;
2179
+ }
2180
+ return '';
2181
+ }
2182
+
2183
+ // Fallback functions for when templates can't be loaded
2184
+ function createEnhancedClaudeMdFallback() {
2185
+ // Read from the actual template file we created
2186
+ try {
2187
+ return readFileSync(join(__dirname, 'CLAUDE.md'), 'utf8');
2188
+ } catch (error) {
2189
+ // If that fails, return a minimal version
2190
+ return `# Claude Code Configuration for Claude Flow
2191
+
2192
+ ## 🚀 IMPORTANT: Claude Flow AI-Driven Development
2193
+
2194
+ ### Claude Code Handles:
2195
+ - ✅ **ALL file operations** (Read, Write, Edit, MultiEdit)
2196
+ - ✅ **ALL code generation** and development tasks
2197
+ - ✅ **ALL bash commands** and system operations
2198
+ - ✅ **ALL actual implementation** work
2199
+ - ✅ **Project navigation** and code analysis
2200
+
2201
+ ### Claude Flow MCP Tools Handle:
2202
+ - 🧠 **Coordination only** - Orchestrating Claude Code's actions
2203
+ - 💾 **Memory management** - Persistent state across sessions
2204
+ - 🤖 **Neural features** - Cognitive patterns and learning
2205
+ - 📊 **Performance tracking** - Monitoring and metrics
2206
+ - 🐝 **Swarm orchestration** - Multi-agent coordination
2207
+ - 🔗 **GitHub integration** - Advanced repository management
2208
+
2209
+ ### ⚠️ Key Principle:
2210
+ **MCP tools DO NOT create content or write code.** They coordinate and enhance Claude Code's native capabilities.
2211
+
2212
+ ## Quick Start
2213
+
2214
+ 1. Add MCP server: \`claude mcp add claude-flow npx claude-flow mcp start\`
2215
+ 2. Initialize swarm: \`mcp__claude-flow__swarm_init { topology: "hierarchical" }\`
2216
+ 3. Spawn agents: \`mcp__claude-flow__agent_spawn { type: "coder" }\`
2217
+ 4. Orchestrate: \`mcp__claude-flow__task_orchestrate { task: "Build feature" }\`
2218
+
2219
+ See full documentation in \`.claude/commands/\`
2220
+ `;
2221
+ }
2222
+ }
2223
+
2224
+ function createEnhancedSettingsJsonFallback() {
2225
+ return JSON.stringify(
2226
+ {
2227
+ env: {
2228
+ CLAUDE_FLOW_AUTO_COMMIT: 'false',
2229
+ CLAUDE_FLOW_AUTO_PUSH: 'false',
2230
+ CLAUDE_FLOW_HOOKS_ENABLED: 'true',
2231
+ CLAUDE_FLOW_TELEMETRY_ENABLED: 'true',
2232
+ CLAUDE_FLOW_REMOTE_EXECUTION: 'true',
2233
+ CLAUDE_FLOW_CHECKPOINTS_ENABLED: 'true',
2234
+ },
2235
+ permissions: {
2236
+ allow: [
2237
+ 'Bash(npx claude-flow *)',
2238
+ 'Bash(npm run lint)',
2239
+ 'Bash(npm run test:*)',
2240
+ 'Bash(npm test *)',
2241
+ 'Bash(git status)',
2242
+ 'Bash(git diff *)',
2243
+ 'Bash(git log *)',
2244
+ 'Bash(git add *)',
2245
+ 'Bash(git commit *)',
2246
+ 'Bash(git push)',
2247
+ 'Bash(git config *)',
2248
+ 'Bash(git tag *)',
2249
+ 'Bash(git branch *)',
2250
+ 'Bash(git checkout *)',
2251
+ 'Bash(git stash *)',
2252
+ 'Bash(node *)',
2253
+ 'Bash(which *)',
2254
+ 'Bash(pwd)',
2255
+ 'Bash(ls *)',
2256
+ 'Bash(jq *)',
2257
+ ],
2258
+ deny: ['Bash(rm -rf /)', 'Bash(curl * | bash)', 'Bash(wget * | sh)', 'Bash(eval *)'],
2259
+ },
2260
+ enabledMcpjsonServers: ['claude-flow', 'ruv-swarm'],
2261
+ hooks: {
2262
+ PreToolUse: [
2263
+ {
2264
+ matcher: 'Bash',
2265
+ hooks: [
2266
+ {
2267
+ type: 'command',
2268
+ command:
2269
+ 'cat | jq -r \'.tool_input.command // ""\' | xargs -I {} npx claude-flow@alpha hooks pre-command --command "{}" --validate-safety true --prepare-resources true',
2270
+ },
2271
+ ],
2272
+ },
2273
+ {
2274
+ matcher: 'Write|Edit|MultiEdit',
2275
+ hooks: [
2276
+ {
2277
+ type: 'command',
2278
+ command:
2279
+ 'cat | jq -r \'.tool_input.file_path // .tool_input.path // ""\' | xargs -I {} npx claude-flow@alpha hooks pre-edit --file "{}" --auto-assign-agents true --load-context true',
2280
+ },
2281
+ {
2282
+ type: 'command',
2283
+ command: './.claude/helpers/standard-checkpoint-hooks.sh pre-edit "{{tool_input}}"',
2284
+ },
2285
+ ],
2286
+ },
2287
+ ],
2288
+ PostToolUse: [
2289
+ {
2290
+ matcher: 'Bash',
2291
+ hooks: [
2292
+ {
2293
+ type: 'command',
2294
+ command:
2295
+ 'cat | jq -r \'.tool_input.command // ""\' | xargs -I {} npx claude-flow@alpha hooks post-command --command "{}" --track-metrics true --store-results true',
2296
+ },
2297
+ ],
2298
+ },
2299
+ {
2300
+ matcher: 'Write|Edit|MultiEdit',
2301
+ hooks: [
2302
+ {
2303
+ type: 'command',
2304
+ command:
2305
+ 'cat | jq -r \'.tool_input.file_path // .tool_input.path // ""\' | xargs -I {} npx claude-flow@alpha hooks post-edit --file "{}" --format true --update-memory true --train-neural true',
2306
+ },
2307
+ {
2308
+ type: 'command',
2309
+ command:
2310
+ './.claude/helpers/standard-checkpoint-hooks.sh post-edit "{{tool_input}}"',
2311
+ },
2312
+ ],
2313
+ },
2314
+ ],
2315
+ UserPromptSubmit: [
2316
+ {
2317
+ hooks: [
2318
+ {
2319
+ type: 'command',
2320
+ command: './.claude/helpers/standard-checkpoint-hooks.sh task "{{user_prompt}}"',
2321
+ },
2322
+ ],
2323
+ },
2324
+ ],
2325
+ Stop: [
2326
+ {
2327
+ hooks: [
2328
+ {
2329
+ type: 'command',
2330
+ command:
2331
+ '/usr/bin/env bash -c \'if command -v npx >/dev/null 2>&1; then npx claude-flow@alpha hooks session-end --generate-summary true --persist-state true --export-metrics true; else echo "⚠️ npx not available, skipping Claude Flow session-end hook"; fi\'',
2332
+ },
2333
+ {
2334
+ type: 'command',
2335
+ command:
2336
+ '/usr/bin/env bash -c \'if [ -f ./.claude/helpers/standard-checkpoint-hooks.sh ]; then ./.claude/helpers/standard-checkpoint-hooks.sh session-end; else echo "⚠️ Checkpoint hooks not found"; fi\'',
2337
+ },
2338
+ ],
2339
+ },
2340
+ ],
2341
+ },
2342
+ includeCoAuthoredBy: true,
2343
+ },
2344
+ null,
2345
+ 2,
2346
+ );
2347
+ }