claude-flow-guidance-implementation 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (275) hide show
  1. package/.agents/README.md +38 -0
  2. package/.agents/config.toml +298 -0
  3. package/.agents/skills/memory-management/SKILL.md +126 -0
  4. package/.agents/skills/memory-management/scripts/memory-backup.sh +16 -0
  5. package/.agents/skills/memory-management/scripts/memory-consolidate.sh +11 -0
  6. package/.agents/skills/security-audit/SKILL.md +135 -0
  7. package/.agents/skills/security-audit/scripts/cve-remediate.sh +16 -0
  8. package/.agents/skills/security-audit/scripts/security-scan.sh +33 -0
  9. package/.agents/skills/sparc-methodology/SKILL.md +118 -0
  10. package/.agents/skills/sparc-methodology/scripts/sparc-init.sh +21 -0
  11. package/.agents/skills/sparc-methodology/scripts/sparc-review.sh +18 -0
  12. package/.agents/skills/swarm-orchestration/SKILL.md +114 -0
  13. package/.agents/skills/swarm-orchestration/scripts/swarm-monitor.sh +8 -0
  14. package/.agents/skills/swarm-orchestration/scripts/swarm-start.sh +14 -0
  15. package/.claude/agents/analysis/analyze-code-quality.md +179 -0
  16. package/.claude/agents/analysis/code-analyzer.md +210 -0
  17. package/.claude/agents/analysis/code-review/analyze-code-quality.md +179 -0
  18. package/.claude/agents/architecture/system-design/arch-system-design.md +155 -0
  19. package/.claude/agents/consensus/README.md +253 -0
  20. package/.claude/agents/consensus/byzantine-coordinator.md +63 -0
  21. package/.claude/agents/consensus/crdt-synchronizer.md +997 -0
  22. package/.claude/agents/consensus/gossip-coordinator.md +63 -0
  23. package/.claude/agents/consensus/performance-benchmarker.md +851 -0
  24. package/.claude/agents/consensus/quorum-manager.md +823 -0
  25. package/.claude/agents/consensus/raft-manager.md +63 -0
  26. package/.claude/agents/consensus/security-manager.md +622 -0
  27. package/.claude/agents/core/coder.md +266 -0
  28. package/.claude/agents/core/planner.md +168 -0
  29. package/.claude/agents/core/researcher.md +190 -0
  30. package/.claude/agents/core/reviewer.md +326 -0
  31. package/.claude/agents/core/tester.md +319 -0
  32. package/.claude/agents/custom/test-long-runner.md +44 -0
  33. package/.claude/agents/data/ml/data-ml-model.md +193 -0
  34. package/.claude/agents/development/backend/dev-backend-api.md +142 -0
  35. package/.claude/agents/development/dev-backend-api.md +345 -0
  36. package/.claude/agents/devops/ci-cd/ops-cicd-github.md +164 -0
  37. package/.claude/agents/documentation/api-docs/docs-api-openapi.md +174 -0
  38. package/.claude/agents/dual-mode/README.md +94 -0
  39. package/.claude/agents/dual-mode/codex-coordinator.md +224 -0
  40. package/.claude/agents/dual-mode/codex-worker.md +211 -0
  41. package/.claude/agents/dual-mode/dual-orchestrator.md +291 -0
  42. package/.claude/agents/flow-nexus/app-store.md +88 -0
  43. package/.claude/agents/flow-nexus/authentication.md +69 -0
  44. package/.claude/agents/flow-nexus/challenges.md +81 -0
  45. package/.claude/agents/flow-nexus/neural-network.md +88 -0
  46. package/.claude/agents/flow-nexus/payments.md +83 -0
  47. package/.claude/agents/flow-nexus/sandbox.md +76 -0
  48. package/.claude/agents/flow-nexus/swarm.md +76 -0
  49. package/.claude/agents/flow-nexus/user-tools.md +96 -0
  50. package/.claude/agents/flow-nexus/workflow.md +84 -0
  51. package/.claude/agents/github/code-review-swarm.md +538 -0
  52. package/.claude/agents/github/github-modes.md +173 -0
  53. package/.claude/agents/github/issue-tracker.md +319 -0
  54. package/.claude/agents/github/multi-repo-swarm.md +553 -0
  55. package/.claude/agents/github/pr-manager.md +191 -0
  56. package/.claude/agents/github/project-board-sync.md +509 -0
  57. package/.claude/agents/github/release-manager.md +367 -0
  58. package/.claude/agents/github/release-swarm.md +583 -0
  59. package/.claude/agents/github/repo-architect.md +398 -0
  60. package/.claude/agents/github/swarm-issue.md +573 -0
  61. package/.claude/agents/github/swarm-pr.md +428 -0
  62. package/.claude/agents/github/sync-coordinator.md +452 -0
  63. package/.claude/agents/github/workflow-automation.md +635 -0
  64. package/.claude/agents/goal/agent.md +816 -0
  65. package/.claude/agents/goal/code-goal-planner.md +446 -0
  66. package/.claude/agents/goal/goal-planner.md +168 -0
  67. package/.claude/agents/hive-mind/collective-intelligence-coordinator.md +130 -0
  68. package/.claude/agents/hive-mind/queen-coordinator.md +203 -0
  69. package/.claude/agents/hive-mind/scout-explorer.md +242 -0
  70. package/.claude/agents/hive-mind/swarm-memory-manager.md +193 -0
  71. package/.claude/agents/hive-mind/worker-specialist.md +217 -0
  72. package/.claude/agents/optimization/README.md +250 -0
  73. package/.claude/agents/optimization/benchmark-suite.md +665 -0
  74. package/.claude/agents/optimization/load-balancer.md +431 -0
  75. package/.claude/agents/optimization/performance-monitor.md +672 -0
  76. package/.claude/agents/optimization/resource-allocator.md +674 -0
  77. package/.claude/agents/optimization/topology-optimizer.md +808 -0
  78. package/.claude/agents/payments/agentic-payments.md +126 -0
  79. package/.claude/agents/sona/sona-learning-optimizer.md +74 -0
  80. package/.claude/agents/sparc/architecture.md +472 -0
  81. package/.claude/agents/sparc/pseudocode.md +318 -0
  82. package/.claude/agents/sparc/refinement.md +525 -0
  83. package/.claude/agents/sparc/specification.md +276 -0
  84. package/.claude/agents/specialized/mobile/spec-mobile-react-native.md +225 -0
  85. package/.claude/agents/sublinear/consensus-coordinator.md +338 -0
  86. package/.claude/agents/sublinear/matrix-optimizer.md +185 -0
  87. package/.claude/agents/sublinear/pagerank-analyzer.md +299 -0
  88. package/.claude/agents/sublinear/performance-optimizer.md +368 -0
  89. package/.claude/agents/sublinear/trading-predictor.md +246 -0
  90. package/.claude/agents/swarm/README.md +190 -0
  91. package/.claude/agents/swarm/adaptive-coordinator.md +396 -0
  92. package/.claude/agents/swarm/hierarchical-coordinator.md +327 -0
  93. package/.claude/agents/swarm/mesh-coordinator.md +392 -0
  94. package/.claude/agents/templates/automation-smart-agent.md +205 -0
  95. package/.claude/agents/templates/coordinator-swarm-init.md +105 -0
  96. package/.claude/agents/templates/github-pr-manager.md +177 -0
  97. package/.claude/agents/templates/implementer-sparc-coder.md +259 -0
  98. package/.claude/agents/templates/memory-coordinator.md +187 -0
  99. package/.claude/agents/templates/migration-plan.md +746 -0
  100. package/.claude/agents/templates/orchestrator-task.md +139 -0
  101. package/.claude/agents/templates/performance-analyzer.md +199 -0
  102. package/.claude/agents/templates/sparc-coordinator.md +183 -0
  103. package/.claude/agents/testing/production-validator.md +395 -0
  104. package/.claude/agents/testing/tdd-london-swarm.md +244 -0
  105. package/.claude/agents/testing/unit/tdd-london-swarm.md +244 -0
  106. package/.claude/agents/testing/validation/production-validator.md +395 -0
  107. package/.claude/agents/v3/database-specialist.yaml +21 -0
  108. package/.claude/agents/v3/index.yaml +17 -0
  109. package/.claude/agents/v3/project-coordinator.yaml +15 -0
  110. package/.claude/agents/v3/python-specialist.yaml +21 -0
  111. package/.claude/agents/v3/test-architect.yaml +20 -0
  112. package/.claude/agents/v3/typescript-specialist.yaml +21 -0
  113. package/.claude/agents/v3/v3-integration-architect.md +346 -0
  114. package/.claude/agents/v3/v3-memory-specialist.md +318 -0
  115. package/.claude/agents/v3/v3-performance-engineer.md +397 -0
  116. package/.claude/agents/v3/v3-queen-coordinator.md +98 -0
  117. package/.claude/agents/v3/v3-security-architect.md +174 -0
  118. package/.claude/commands/analysis/COMMAND_COMPLIANCE_REPORT.md +54 -0
  119. package/.claude/commands/analysis/README.md +9 -0
  120. package/.claude/commands/analysis/bottleneck-detect.md +162 -0
  121. package/.claude/commands/analysis/performance-bottlenecks.md +59 -0
  122. package/.claude/commands/analysis/performance-report.md +25 -0
  123. package/.claude/commands/analysis/token-efficiency.md +45 -0
  124. package/.claude/commands/analysis/token-usage.md +25 -0
  125. package/.claude/commands/automation/README.md +9 -0
  126. package/.claude/commands/automation/auto-agent.md +122 -0
  127. package/.claude/commands/automation/self-healing.md +106 -0
  128. package/.claude/commands/automation/session-memory.md +90 -0
  129. package/.claude/commands/automation/smart-agents.md +73 -0
  130. package/.claude/commands/automation/smart-spawn.md +25 -0
  131. package/.claude/commands/automation/workflow-select.md +25 -0
  132. package/.claude/commands/claude-flow-help.md +103 -0
  133. package/.claude/commands/claude-flow-memory.md +107 -0
  134. package/.claude/commands/claude-flow-swarm.md +205 -0
  135. package/.claude/commands/github/README.md +11 -0
  136. package/.claude/commands/github/code-review-swarm.md +514 -0
  137. package/.claude/commands/github/code-review.md +25 -0
  138. package/.claude/commands/github/github-modes.md +147 -0
  139. package/.claude/commands/github/github-swarm.md +121 -0
  140. package/.claude/commands/github/issue-tracker.md +292 -0
  141. package/.claude/commands/github/issue-triage.md +25 -0
  142. package/.claude/commands/github/multi-repo-swarm.md +519 -0
  143. package/.claude/commands/github/pr-enhance.md +26 -0
  144. package/.claude/commands/github/pr-manager.md +170 -0
  145. package/.claude/commands/github/project-board-sync.md +471 -0
  146. package/.claude/commands/github/release-manager.md +338 -0
  147. package/.claude/commands/github/release-swarm.md +544 -0
  148. package/.claude/commands/github/repo-analyze.md +25 -0
  149. package/.claude/commands/github/repo-architect.md +367 -0
  150. package/.claude/commands/github/swarm-issue.md +482 -0
  151. package/.claude/commands/github/swarm-pr.md +285 -0
  152. package/.claude/commands/github/sync-coordinator.md +301 -0
  153. package/.claude/commands/github/workflow-automation.md +442 -0
  154. package/.claude/commands/hooks/README.md +11 -0
  155. package/.claude/commands/hooks/overview.md +58 -0
  156. package/.claude/commands/hooks/post-edit.md +117 -0
  157. package/.claude/commands/hooks/post-task.md +112 -0
  158. package/.claude/commands/hooks/pre-edit.md +113 -0
  159. package/.claude/commands/hooks/pre-task.md +111 -0
  160. package/.claude/commands/hooks/session-end.md +118 -0
  161. package/.claude/commands/hooks/setup.md +103 -0
  162. package/.claude/commands/monitoring/README.md +9 -0
  163. package/.claude/commands/monitoring/agent-metrics.md +25 -0
  164. package/.claude/commands/monitoring/agents.md +44 -0
  165. package/.claude/commands/monitoring/real-time-view.md +25 -0
  166. package/.claude/commands/monitoring/status.md +46 -0
  167. package/.claude/commands/monitoring/swarm-monitor.md +25 -0
  168. package/.claude/commands/optimization/README.md +9 -0
  169. package/.claude/commands/optimization/auto-topology.md +62 -0
  170. package/.claude/commands/optimization/cache-manage.md +25 -0
  171. package/.claude/commands/optimization/parallel-execute.md +25 -0
  172. package/.claude/commands/optimization/parallel-execution.md +50 -0
  173. package/.claude/commands/optimization/topology-optimize.md +25 -0
  174. package/.claude/commands/sparc/analyzer.md +52 -0
  175. package/.claude/commands/sparc/architect.md +53 -0
  176. package/.claude/commands/sparc/ask.md +97 -0
  177. package/.claude/commands/sparc/batch-executor.md +54 -0
  178. package/.claude/commands/sparc/code.md +89 -0
  179. package/.claude/commands/sparc/coder.md +54 -0
  180. package/.claude/commands/sparc/debug.md +83 -0
  181. package/.claude/commands/sparc/debugger.md +54 -0
  182. package/.claude/commands/sparc/designer.md +53 -0
  183. package/.claude/commands/sparc/devops.md +109 -0
  184. package/.claude/commands/sparc/docs-writer.md +80 -0
  185. package/.claude/commands/sparc/documenter.md +54 -0
  186. package/.claude/commands/sparc/innovator.md +54 -0
  187. package/.claude/commands/sparc/integration.md +83 -0
  188. package/.claude/commands/sparc/mcp.md +117 -0
  189. package/.claude/commands/sparc/memory-manager.md +54 -0
  190. package/.claude/commands/sparc/optimizer.md +54 -0
  191. package/.claude/commands/sparc/orchestrator.md +132 -0
  192. package/.claude/commands/sparc/post-deployment-monitoring-mode.md +83 -0
  193. package/.claude/commands/sparc/refinement-optimization-mode.md +83 -0
  194. package/.claude/commands/sparc/researcher.md +54 -0
  195. package/.claude/commands/sparc/reviewer.md +54 -0
  196. package/.claude/commands/sparc/security-review.md +80 -0
  197. package/.claude/commands/sparc/sparc-modes.md +174 -0
  198. package/.claude/commands/sparc/sparc.md +111 -0
  199. package/.claude/commands/sparc/spec-pseudocode.md +80 -0
  200. package/.claude/commands/sparc/supabase-admin.md +348 -0
  201. package/.claude/commands/sparc/swarm-coordinator.md +54 -0
  202. package/.claude/commands/sparc/tdd.md +54 -0
  203. package/.claude/commands/sparc/tester.md +54 -0
  204. package/.claude/commands/sparc/tutorial.md +79 -0
  205. package/.claude/commands/sparc/workflow-manager.md +54 -0
  206. package/.claude/helpers/hook-handler.cjs +168 -0
  207. package/.claude/helpers/intelligence.cjs +197 -0
  208. package/.claude/helpers/memory.js +83 -0
  209. package/.claude/helpers/post-commit +16 -0
  210. package/.claude/helpers/pre-commit +26 -0
  211. package/.claude/helpers/router.js +66 -0
  212. package/.claude/helpers/session.js +127 -0
  213. package/.claude/settings.json +250 -0
  214. package/.claude/skills/agentdb-advanced/SKILL.md +550 -0
  215. package/.claude/skills/agentdb-learning/SKILL.md +545 -0
  216. package/.claude/skills/agentdb-memory-patterns/SKILL.md +339 -0
  217. package/.claude/skills/agentdb-optimization/SKILL.md +509 -0
  218. package/.claude/skills/agentdb-vector-search/SKILL.md +339 -0
  219. package/.claude/skills/github-code-review/SKILL.md +1140 -0
  220. package/.claude/skills/github-multi-repo/SKILL.md +874 -0
  221. package/.claude/skills/github-project-management/SKILL.md +1277 -0
  222. package/.claude/skills/github-release-management/SKILL.md +1081 -0
  223. package/.claude/skills/github-workflow-automation/SKILL.md +1065 -0
  224. package/.claude/skills/hooks-automation/SKILL.md +1201 -0
  225. package/.claude/skills/pair-programming/SKILL.md +1202 -0
  226. package/.claude/skills/reasoningbank-agentdb/SKILL.md +446 -0
  227. package/.claude/skills/reasoningbank-intelligence/SKILL.md +201 -0
  228. package/.claude/skills/skill-builder/.claude-flow/metrics/agent-metrics.json +1 -0
  229. package/.claude/skills/skill-builder/.claude-flow/metrics/performance.json +87 -0
  230. package/.claude/skills/skill-builder/.claude-flow/metrics/task-metrics.json +10 -0
  231. package/.claude/skills/skill-builder/SKILL.md +910 -0
  232. package/.claude/skills/sparc-methodology/SKILL.md +1115 -0
  233. package/.claude/skills/stream-chain/SKILL.md +563 -0
  234. package/.claude/skills/swarm-advanced/SKILL.md +973 -0
  235. package/.claude/skills/swarm-orchestration/SKILL.md +179 -0
  236. package/.claude/skills/v3-cli-modernization/SKILL.md +872 -0
  237. package/.claude/skills/v3-core-implementation/SKILL.md +797 -0
  238. package/.claude/skills/v3-ddd-architecture/SKILL.md +442 -0
  239. package/.claude/skills/v3-integration-deep/SKILL.md +241 -0
  240. package/.claude/skills/v3-mcp-optimization/SKILL.md +777 -0
  241. package/.claude/skills/v3-memory-unification/SKILL.md +174 -0
  242. package/.claude/skills/v3-performance-optimization/SKILL.md +390 -0
  243. package/.claude/skills/v3-security-overhaul/SKILL.md +82 -0
  244. package/.claude/skills/v3-swarm-coordination/SKILL.md +340 -0
  245. package/.claude/skills/verification-quality/SKILL.md +649 -0
  246. package/.claude/statusline.mjs +109 -0
  247. package/.claude/statusline.sh +375 -0
  248. package/.claude-flow/CAPABILITIES.md +403 -0
  249. package/.claude-flow/config.yaml +43 -0
  250. package/.claude-flow/metrics/learning.json +17 -0
  251. package/.claude-flow/metrics/swarm-activity.json +18 -0
  252. package/.claude-flow/metrics/v3-progress.json +26 -0
  253. package/.claude-flow/security/audit-status.json +8 -0
  254. package/.mcp.json +20 -0
  255. package/AGENTS.md +145 -0
  256. package/CLAUDE.md +188 -0
  257. package/LICENSE +21 -0
  258. package/README.md +115 -0
  259. package/bin/cf-guidance-impl.mjs +74 -0
  260. package/package.json +23 -0
  261. package/scaffold/.claude/helpers/hook-handler.cjs +576 -0
  262. package/scaffold/docs/guidance-control-plane.md +441 -0
  263. package/scaffold/docs/guidance-implementation-guide.md +424 -0
  264. package/scaffold/scripts/analyze-guidance.js +176 -0
  265. package/scaffold/scripts/guidance-ab-benchmark.js +40 -0
  266. package/scaffold/scripts/guidance-autopilot.js +473 -0
  267. package/scaffold/scripts/guidance-codex-bridge.js +337 -0
  268. package/scaffold/scripts/guidance-integrations.js +587 -0
  269. package/scaffold/scripts/guidance-runtime.js +133 -0
  270. package/scaffold/scripts/scaffold-guidance.js +122 -0
  271. package/scaffold/src/guidance/advanced-runtime.js +658 -0
  272. package/scaffold/src/guidance/content-aware-executor.js +70 -0
  273. package/scaffold/src/guidance/phase1-runtime.js +151 -0
  274. package/src/default-settings.mjs +111 -0
  275. package/src/installer.mjs +415 -0
@@ -0,0 +1,441 @@
1
+ # Guidance Control Plane: How It Works in This Repo
2
+
3
+ ## Purpose
4
+ This document explains the `@claude-flow/guidance` setup in this repository, including:
5
+ - What upstream `claude-flow guidance` provides
6
+ - What custom repo scripts add on top
7
+ - How hook/background automation is wired
8
+ - Which commands to run for analysis, optimization, and A/B checks
9
+ - Where outputs/logs are written
10
+
11
+ It also clarifies command-name differences between promo snippets and the current CLI.
12
+
13
+ ## Version and Command Compatibility
14
+ The currently installed CLI reports:
15
+ - `claude-flow v3.1.0-alpha.41`
16
+
17
+ Promo snippets often show:
18
+ - `npx claude-flow analyze CLAUDE.md`
19
+ - `npx claude-flow optimize CLAUDE.md`
20
+ - `npx claude-flow ab-benchmark`
21
+
22
+ In this CLI version, the guidance commands are namespaced:
23
+ - `npx @claude-flow/cli@latest guidance optimize`
24
+ - `npx @claude-flow/cli@latest guidance ab-test`
25
+
26
+ `claude-flow analyze` exists, but it is code/diff analysis, not guidance scoring.
27
+
28
+ ## High-Level Architecture
29
+ Guidance is implemented as a control plane around `CLAUDE.md` + `CLAUDE.local.md`:
30
+
31
+ 1. Compile:
32
+ - Parse root and local guidance into a typed policy bundle
33
+ - Split into constitution rules plus task-scoped shards
34
+
35
+ 2. Retrieve:
36
+ - Detect task intent
37
+ - Retrieve relevant shards + constitution into policy text
38
+
39
+ 3. Enforce:
40
+ - Evaluate gates (destructive commands, secrets, tool checks, etc.)
41
+ - Allow, require confirmation, warn, or block
42
+
43
+ 4. Record and evolve:
44
+ - Ledger/proof outputs from guidance pipeline
45
+ - Optimization and A/B evaluation
46
+ - Optional local-rule promotion to root guidance (repo custom autopilot)
47
+
48
+ ## Upstream CLI Commands
49
+ Primary command:
50
+ - `npx @claude-flow/cli@latest guidance <subcommand> ...`
51
+
52
+ Available subcommands:
53
+ - `compile`
54
+ - `retrieve`
55
+ - `gates`
56
+ - `status`
57
+ - `optimize`
58
+ - `ab-test`
59
+
60
+ Aliases:
61
+ - `guide`
62
+ - `policy`
63
+
64
+ ### `guidance compile`
65
+ Compiles `CLAUDE.md` into constitution + shards + manifest.
66
+
67
+ Flags:
68
+ - `--root, -r <path>` root guidance file (default `./CLAUDE.md`)
69
+ - `--local, -l <path>` local overlay file
70
+ - `--output, -o <dir>` output directory (declared by CLI)
71
+ - `--json` machine-readable output
72
+
73
+ Examples:
74
+ ```bash
75
+ npx @claude-flow/cli@latest guidance compile
76
+ npx @claude-flow/cli@latest guidance compile -r ./CLAUDE.md -l ./CLAUDE.local.md
77
+ npx @claude-flow/cli@latest guidance compile --json
78
+ ```
79
+
80
+ ### `guidance retrieve`
81
+ Retrieves task-relevant shards by intent.
82
+
83
+ Flags:
84
+ - `--task, -t <text>` required task description
85
+ - `--root, -r <path>` root guidance file
86
+ - `--local, -l <path>` local overlay
87
+ - `--max-shards, -n <number>` max shard count (default `5`)
88
+ - `--intent, -i <intent>` override detected intent
89
+ - `--json` machine-readable output
90
+
91
+ Examples:
92
+ ```bash
93
+ npx @claude-flow/cli@latest guidance retrieve --task "Fix auth bug"
94
+ npx @claude-flow/cli@latest guidance retrieve -t "Add tests" -n 3
95
+ npx @claude-flow/cli@latest guidance retrieve -t "Refactor API" --intent refactor
96
+ ```
97
+
98
+ ### `guidance gates`
99
+ Runs enforcement gates against command/content/tool inputs.
100
+
101
+ Flags:
102
+ - `--command, -c <cmd>` evaluate command risk
103
+ - `--content <text>` evaluate content (secret scans)
104
+ - `--tool, -t <name>` tool allowlist check
105
+ - `--json` machine-readable output
106
+
107
+ Examples:
108
+ ```bash
109
+ npx @claude-flow/cli@latest guidance gates -c "git push --force origin main"
110
+ npx @claude-flow/cli@latest guidance gates --content "api_key=sk-test..."
111
+ npx @claude-flow/cli@latest guidance gates -t Bash
112
+ ```
113
+
114
+ ### `guidance status`
115
+ Reports guidance files and compiled bundle stats.
116
+
117
+ Flags:
118
+ - `--json`
119
+
120
+ Example:
121
+ ```bash
122
+ npx @claude-flow/cli@latest guidance status
123
+ ```
124
+
125
+ ### `guidance optimize`
126
+ Analyzes and optimizes guidance content.
127
+
128
+ Flags:
129
+ - `--root, -r <path>` root guidance file
130
+ - `--local, -l <path>` local overlay
131
+ - `--apply, -a` write optimized output back to root file
132
+ - `--context-size, -s <compact|standard|full>` optimization target size
133
+ - `--target-score <0-100>` composite score target (default `90`)
134
+ - `--max-iterations <n>` optimization iterations (default `5`)
135
+ - `--json` machine-readable output
136
+
137
+ Examples:
138
+ ```bash
139
+ npx @claude-flow/cli@latest guidance optimize
140
+ npx @claude-flow/cli@latest guidance optimize --apply
141
+ npx @claude-flow/cli@latest guidance optimize -s compact --target-score 95 --apply
142
+ ```
143
+
144
+ ### `guidance ab-test`
145
+ Runs baseline vs candidate behavioral comparison.
146
+
147
+ Flags:
148
+ - `--config-a, -a <path>` baseline guidance path (optional; default baseline mode)
149
+ - `--config-b, -b <path>` candidate guidance path (default `./CLAUDE.md`)
150
+ - `--tasks, -t <json-file>` custom AB tasks
151
+ - `--work-dir, -w <path>` working directory
152
+ - `--json` machine-readable output
153
+
154
+ Examples:
155
+ ```bash
156
+ npx @claude-flow/cli@latest guidance ab-test
157
+ npx @claude-flow/cli@latest guidance ab-test -a old.md -b CLAUDE.md
158
+ npx @claude-flow/cli@latest guidance ab-test --tasks custom-ab-tasks.json
159
+ ```
160
+
161
+ ## Repo-Level Command Wrappers
162
+ This repo adds npm scripts that wrap guidance workflows:
163
+
164
+ From `package.json`:
165
+ - `npm run guidance:analyze`
166
+ - `npm run guidance:optimize`
167
+ - `npm run guidance:autopilot:once`
168
+ - `npm run guidance:autopilot:daemon`
169
+ - `npm run guidance:ab-benchmark`
170
+ - `npm run guidance:all`
171
+ - `npm run guidance:status`
172
+ - `npm run guidance:hooks`
173
+ - `npm run guidance:trust`
174
+ - `npm run guidance:adversarial`
175
+ - `npm run guidance:proof`
176
+ - `npm run guidance:conformance`
177
+ - `npm run guidance:evolution`
178
+ - `npm run guidance:scaffold`
179
+ - `npm run guidance:runtime`
180
+ - `npm run guidance:codex:status`
181
+ - `npm run guidance:codex:pre-command -- --command "git status"`
182
+ - `npm run guidance:codex:pre-edit -- --file src/example.ts`
183
+ - `npm run guidance:codex:pre-task -- --description "Implement feature X"`
184
+ - `npm run guidance:codex:post-edit -- --file src/example.ts`
185
+ - `npm run guidance:codex:post-task -- --task-id task-123 --status completed`
186
+ - `npm run guidance:codex:session-start`
187
+ - `npm run guidance:codex:session-end`
188
+
189
+ ### What each wrapper does
190
+
191
+ `guidance:analyze`
192
+ - Runs `scripts/analyze-guidance.js`
193
+ - Uses `@claude-flow/guidance/analyzer` score reporting
194
+ - Initializes guidance control plane
195
+ - Performs shard retrieval smoke checks
196
+ - Performs phase-1 hook runtime smoke checks
197
+ - Writes bundle summary to `.claude-flow/guidance/bundle-summary.json`
198
+
199
+ `guidance:optimize`
200
+ - Runs `scripts/guidance-autopilot.js --once --apply --source manual`
201
+ - Executes repo custom promotion loop (see next section)
202
+
203
+ `guidance:autopilot:once`
204
+ - Runs one dry-ish autopilot cycle (`--once`, no `--apply`)
205
+
206
+ `guidance:autopilot:daemon`
207
+ - Runs recurring autopilot cycles in foreground process (`--daemon --apply`)
208
+
209
+ `guidance:ab-benchmark`
210
+ - Runs `scripts/guidance-ab-benchmark.js`
211
+ - Uses `abBenchmark()` with a local synthetic executor
212
+ - Writes `.claude-flow/guidance/ab-benchmark-report.json`
213
+
214
+ `guidance:all` and the module-specific `guidance:*` wrappers
215
+ - Runs `scripts/guidance-integrations.js` (backed by `src/guidance/advanced-runtime.js`)
216
+ - Implements executable versions of README integration modules:
217
+ - hook wiring flow
218
+ - trust accumulation
219
+ - adversarial detection + quorum
220
+ - proof chain generation/verification
221
+ - conformance test + replay
222
+ - evolution propose/simulate/stage/promote
223
+ - Writes advanced runtime state and proof chain to `.claude-flow/guidance/advanced/`
224
+
225
+ `guidance:runtime`
226
+ - Runs `scripts/guidance-runtime.js demo`
227
+ - Demonstrates pre-task / pre-command / post-task flow
228
+
229
+ `guidance:scaffold`
230
+ - Runs `scripts/scaffold-guidance.js`
231
+ - Scaffolds guidance templates into `.claude-flow/guidance/scaffold/`
232
+
233
+ `guidance:codex:*`
234
+ - Runs `scripts/guidance-codex-bridge.js` lifecycle events
235
+ - Reuses `.claude/helpers/hook-handler.cjs` enforcement path
236
+ - Optionally executes best-effort `npx @claude-flow/cli@latest hooks ...` telemetry
237
+
238
+ ## Repo Custom Autopilot (Promotion + ADR)
239
+ This repo includes a custom autopilot that is not a built-in CLI command.
240
+
241
+ File:
242
+ - `scripts/guidance-autopilot.js`
243
+
244
+ Behavior:
245
+ 1. Read `CLAUDE.md` and optional `CLAUDE.local.md`
246
+ 2. Compile both and detect promotable local rules (`source === local` + new/changed vs root)
247
+ 3. Build candidate root content with an auto-promotion section:
248
+ - `## Guidance Auto-Promotions`
249
+ - `<!-- guidance-autopilot:start --> ... <!-- guidance-autopilot:end -->`
250
+ 4. Score before/after via `analyze()` and `benchmark()`
251
+ 5. Optional A/B gate via `abBenchmark()`
252
+ 6. If thresholds pass and `--apply` is set:
253
+ - Backup current `CLAUDE.md`
254
+ - Write updated `CLAUDE.md`
255
+ - Generate ADR in `docs/adr/`
256
+ 7. Otherwise write proposal file only
257
+
258
+ CLI flags (custom script):
259
+ - `--once`
260
+ - `--daemon`
261
+ - `--apply`
262
+ - `--ab`
263
+ - `--no-ab`
264
+ - `--min-delta <number>`
265
+ - `--max-promotions <number>`
266
+ - `--interval-ms <number>`
267
+ - `--min-ab-gain <number>`
268
+ - `--source <text>`
269
+
270
+ Generated files:
271
+ - `.claude-flow/guidance/autopilot-report.json`
272
+ - `.claude-flow/guidance/autopilot-state.json`
273
+ - `.claude-flow/guidance/autopilot.log`
274
+ - `.claude-flow/guidance/autopilot.lock`
275
+ - `.claude-flow/guidance/proposals/*.md`
276
+ - `.claude-flow/guidance/backups/CLAUDE.md.*.bak`
277
+ - `docs/adr/ADR-XXX-guidance-local-rule-promotion.md`
278
+
279
+ ### Important practical point
280
+ Current repo autopilot promotes only rules already present in `CLAUDE.local.md` as local guidance rules. It does not yet auto-invent new rules from scratch. You can treat `CLAUDE.local.md` as the experimental staging area.
281
+
282
+ ## Hook Integration and Background Automation
283
+ Hook launcher file:
284
+ - `.claude/helpers/hook-handler.cjs`
285
+ - `scripts/guidance-codex-bridge.js` (Codex lifecycle dispatcher)
286
+
287
+ Claude hook configuration file:
288
+ - `.claude/settings.json`
289
+ - `.agents/config.toml` (Codex command map metadata)
290
+
291
+ Key integration:
292
+ - On `SessionEnd`, `hook-handler.cjs` launches autopilot as a detached background process.
293
+ - This is non-blocking (`detached: true`, `stdio: ignore`, `child.unref()`).
294
+ - Hook handler now dispatches guidance event wiring through `scripts/guidance-integrations.js event ...`:
295
+ - sync blocking checks for `pre-command`, `pre-edit`, `pre-task`
296
+ - async governance updates for `post-edit`, `post-task`, `session-end`
297
+
298
+ Hook paths currently wired in settings:
299
+ - `SessionStart`: `session-restore`
300
+ - `SessionEnd`: `session-end`
301
+ - `PreToolUse Bash`: `pre-bash`
302
+ - `PreToolUse Write/Edit/MultiEdit`: `pre-edit`
303
+ - `PreToolUse Task`: `pre-task`
304
+ - `PostToolUse Task`: `post-task`
305
+ - `PostToolUse Write/Edit`: `post-edit`
306
+ - plus related `entire hooks ...` commands
307
+
308
+ Codex lifecycle wiring in this repo:
309
+ - `guidance:codex:session-start` -> `session-restore`
310
+ - `guidance:codex:pre-command` -> `pre-bash`
311
+ - `guidance:codex:pre-edit` -> `pre-edit`
312
+ - `guidance:codex:pre-task` -> `pre-task`
313
+ - `guidance:codex:post-edit` -> `post-edit`
314
+ - `guidance:codex:post-task` -> `post-task`
315
+ - `guidance:codex:session-end` -> `session-end`
316
+
317
+ Each bridge call sends normalized payload to `hook-handler.cjs` and may also run best-effort `npx @claude-flow/cli@latest hooks ...` telemetry unless disabled with `--skip-cf-hooks` or `GUIDANCE_CODEX_SKIP_CF_HOOKS=1`.
318
+
319
+ ### Autopilot environment toggles
320
+ Recognized by `hook-handler.cjs`:
321
+ - `GUIDANCE_AUTOPILOT_ENABLED=0` disable session-end autopilot
322
+ - `GUIDANCE_AUTOPILOT_MIN_DELTA=<float>` override promotion threshold (default `0.5`)
323
+ - `GUIDANCE_AUTOPILOT_AB=1` enable A/B gate during hook-triggered autopilot
324
+ - `GUIDANCE_AUTOPILOT_MIN_AB_GAIN=<float>` minimum A/B gain when AB gate is enabled (default `0.05`)
325
+ - `GUIDANCE_EVENT_WIRING_ENABLED=0` disable guidance event wiring in hook-handler
326
+ - `GUIDANCE_EVENT_SYNC_TIMEOUT_MS=<ms>` timeout for sync pre-event checks
327
+ - `GUIDANCE_EVENT_FAIL_CLOSED=1` block when sync guidance check errors
328
+
329
+ Recognized by benchmark script:
330
+ - `GUIDANCE_PROOF_KEY=<string>` optional proof key for A/B benchmark report generation
331
+
332
+ ## Daemon and Runtime Modes
333
+ There are two separate concepts:
334
+
335
+ 1. Claude Flow CLI daemon:
336
+ - `npx @claude-flow/cli@latest daemon start`
337
+ - Supports broader orchestration/runtime internals
338
+ - Optional start during init (`--start-daemon`, `--start-all`)
339
+
340
+ 2. Repo autopilot daemon loop:
341
+ - `npm run guidance:autopilot:daemon`
342
+ - Runs recurring local promotion checks from `scripts/guidance-autopilot.js`
343
+ - Independent of whether CLI daemon is running
344
+
345
+ ## Recommended Operational Flows
346
+
347
+ ### Baseline (upstream only)
348
+ ```bash
349
+ npx @claude-flow/cli@latest init
350
+ npx @claude-flow/cli@latest guidance status
351
+ npx @claude-flow/cli@latest guidance optimize
352
+ npx @claude-flow/cli@latest guidance ab-test
353
+ ```
354
+
355
+ ### Repo workflow (with wrappers)
356
+ ```bash
357
+ npm run guidance:analyze
358
+ npm run guidance:ab-benchmark
359
+ npm run guidance:optimize
360
+ npm run guidance:all
361
+ ```
362
+
363
+ ### Codex lifecycle workflow (bridge)
364
+ ```bash
365
+ # start/restore lifecycle context
366
+ npm run guidance:codex:session-start
367
+
368
+ # gate task and operations
369
+ npm run guidance:codex:pre-task -- --task-id task-123 --description "Implement feature X"
370
+ npm run guidance:codex:pre-command -- --task-id task-123 --command "git status"
371
+ npm run guidance:codex:pre-edit -- --task-id task-123 --file src/example.ts --operation modify
372
+
373
+ # finalize learning/ledger
374
+ npm run guidance:codex:post-edit -- --task-id task-123 --file src/example.ts
375
+ npm run guidance:codex:post-task -- --task-id task-123 --status completed --description "Implement feature X"
376
+ npm run guidance:codex:session-end -- --task-id task-123
377
+ ```
378
+
379
+ Quick verification:
380
+ ```bash
381
+ npm run guidance:codex:status
382
+ npm run guidance:codex:pre-task -- --task-id smoke-1 --description "smoke" --skip-cf-hooks
383
+ ```
384
+ Expected result: JSON output with `handler.ok: true`; when not skipping, expect `claudeFlowHook.ok: true`.
385
+
386
+ ### Continuous repo workflow
387
+ ```bash
388
+ npm run guidance:autopilot:daemon
389
+ ```
390
+
391
+ ### Enable stricter session-end promotion gate
392
+ ```bash
393
+ export GUIDANCE_AUTOPILOT_AB=1
394
+ export GUIDANCE_AUTOPILOT_MIN_AB_GAIN=0.05
395
+ ```
396
+
397
+ ## Troubleshooting
398
+
399
+ `Unknown command: optimize` or `Unknown command: ab-benchmark`:
400
+ - Use namespaced commands:
401
+ - `guidance optimize`
402
+ - `guidance ab-test`
403
+
404
+ `guidance retrieve` says missing `--task`:
405
+ - Provide `--task "..."` or `-t "..."`.
406
+
407
+ Autopilot reports `no-promotable-local-rules`:
408
+ - Expected when `CLAUDE.local.md` has no local rule candidates.
409
+ - Add explicit experimental rules in `CLAUDE.local.md`.
410
+
411
+ No background autopilot activity on session end:
412
+ - Confirm hook wiring in `.claude/settings.json`
413
+ - Confirm script exists at `scripts/guidance-autopilot.js`
414
+ - Ensure `GUIDANCE_AUTOPILOT_ENABLED` is not set to `0`
415
+
416
+ A/B benchmark hangs in environments without `claude -p`:
417
+ - Use repo wrapper `npm run guidance:ab-benchmark` (synthetic local executor).
418
+
419
+ Need to validate full README integration implementations:
420
+ - Run `npm run guidance:all` for full suite.
421
+ - Run `npm run guidance:status` to inspect advanced runtime state.
422
+
423
+ ## Source Files in This Repo
424
+ Core docs and implementation:
425
+ - `CLAUDE.md`
426
+ - `CLAUDE.local.md`
427
+ - `.claude/settings.json`
428
+ - `.claude/helpers/hook-handler.cjs`
429
+ - `scripts/analyze-guidance.js`
430
+ - `scripts/guidance-autopilot.js`
431
+ - `scripts/guidance-ab-benchmark.js`
432
+ - `scripts/guidance-integrations.js`
433
+ - `scripts/guidance-runtime.js`
434
+ - `scripts/scaffold-guidance.js`
435
+ - `src/guidance/phase1-runtime.js`
436
+ - `src/guidance/advanced-runtime.js`
437
+ - `src/guidance/content-aware-executor.js`
438
+
439
+ Upstream package references:
440
+ - `node_modules/@claude-flow/guidance/README.md`
441
+ - `@claude-flow/cli` guidance command implementation (`dist/src/commands/guidance.js`)