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.
- package/.agents/README.md +38 -0
- package/.agents/config.toml +298 -0
- package/.agents/skills/memory-management/SKILL.md +126 -0
- package/.agents/skills/memory-management/scripts/memory-backup.sh +16 -0
- package/.agents/skills/memory-management/scripts/memory-consolidate.sh +11 -0
- package/.agents/skills/security-audit/SKILL.md +135 -0
- package/.agents/skills/security-audit/scripts/cve-remediate.sh +16 -0
- package/.agents/skills/security-audit/scripts/security-scan.sh +33 -0
- package/.agents/skills/sparc-methodology/SKILL.md +118 -0
- package/.agents/skills/sparc-methodology/scripts/sparc-init.sh +21 -0
- package/.agents/skills/sparc-methodology/scripts/sparc-review.sh +18 -0
- package/.agents/skills/swarm-orchestration/SKILL.md +114 -0
- package/.agents/skills/swarm-orchestration/scripts/swarm-monitor.sh +8 -0
- package/.agents/skills/swarm-orchestration/scripts/swarm-start.sh +14 -0
- package/.claude/agents/analysis/analyze-code-quality.md +179 -0
- package/.claude/agents/analysis/code-analyzer.md +210 -0
- package/.claude/agents/analysis/code-review/analyze-code-quality.md +179 -0
- package/.claude/agents/architecture/system-design/arch-system-design.md +155 -0
- package/.claude/agents/consensus/README.md +253 -0
- package/.claude/agents/consensus/byzantine-coordinator.md +63 -0
- package/.claude/agents/consensus/crdt-synchronizer.md +997 -0
- package/.claude/agents/consensus/gossip-coordinator.md +63 -0
- package/.claude/agents/consensus/performance-benchmarker.md +851 -0
- package/.claude/agents/consensus/quorum-manager.md +823 -0
- package/.claude/agents/consensus/raft-manager.md +63 -0
- package/.claude/agents/consensus/security-manager.md +622 -0
- package/.claude/agents/core/coder.md +266 -0
- package/.claude/agents/core/planner.md +168 -0
- package/.claude/agents/core/researcher.md +190 -0
- package/.claude/agents/core/reviewer.md +326 -0
- package/.claude/agents/core/tester.md +319 -0
- package/.claude/agents/custom/test-long-runner.md +44 -0
- package/.claude/agents/data/ml/data-ml-model.md +193 -0
- package/.claude/agents/development/backend/dev-backend-api.md +142 -0
- package/.claude/agents/development/dev-backend-api.md +345 -0
- package/.claude/agents/devops/ci-cd/ops-cicd-github.md +164 -0
- package/.claude/agents/documentation/api-docs/docs-api-openapi.md +174 -0
- package/.claude/agents/dual-mode/README.md +94 -0
- package/.claude/agents/dual-mode/codex-coordinator.md +224 -0
- package/.claude/agents/dual-mode/codex-worker.md +211 -0
- package/.claude/agents/dual-mode/dual-orchestrator.md +291 -0
- package/.claude/agents/flow-nexus/app-store.md +88 -0
- package/.claude/agents/flow-nexus/authentication.md +69 -0
- package/.claude/agents/flow-nexus/challenges.md +81 -0
- package/.claude/agents/flow-nexus/neural-network.md +88 -0
- package/.claude/agents/flow-nexus/payments.md +83 -0
- package/.claude/agents/flow-nexus/sandbox.md +76 -0
- package/.claude/agents/flow-nexus/swarm.md +76 -0
- package/.claude/agents/flow-nexus/user-tools.md +96 -0
- package/.claude/agents/flow-nexus/workflow.md +84 -0
- package/.claude/agents/github/code-review-swarm.md +538 -0
- package/.claude/agents/github/github-modes.md +173 -0
- package/.claude/agents/github/issue-tracker.md +319 -0
- package/.claude/agents/github/multi-repo-swarm.md +553 -0
- package/.claude/agents/github/pr-manager.md +191 -0
- package/.claude/agents/github/project-board-sync.md +509 -0
- package/.claude/agents/github/release-manager.md +367 -0
- package/.claude/agents/github/release-swarm.md +583 -0
- package/.claude/agents/github/repo-architect.md +398 -0
- package/.claude/agents/github/swarm-issue.md +573 -0
- package/.claude/agents/github/swarm-pr.md +428 -0
- package/.claude/agents/github/sync-coordinator.md +452 -0
- package/.claude/agents/github/workflow-automation.md +635 -0
- package/.claude/agents/goal/agent.md +816 -0
- package/.claude/agents/goal/code-goal-planner.md +446 -0
- package/.claude/agents/goal/goal-planner.md +168 -0
- package/.claude/agents/hive-mind/collective-intelligence-coordinator.md +130 -0
- package/.claude/agents/hive-mind/queen-coordinator.md +203 -0
- package/.claude/agents/hive-mind/scout-explorer.md +242 -0
- package/.claude/agents/hive-mind/swarm-memory-manager.md +193 -0
- package/.claude/agents/hive-mind/worker-specialist.md +217 -0
- package/.claude/agents/optimization/README.md +250 -0
- package/.claude/agents/optimization/benchmark-suite.md +665 -0
- package/.claude/agents/optimization/load-balancer.md +431 -0
- package/.claude/agents/optimization/performance-monitor.md +672 -0
- package/.claude/agents/optimization/resource-allocator.md +674 -0
- package/.claude/agents/optimization/topology-optimizer.md +808 -0
- package/.claude/agents/payments/agentic-payments.md +126 -0
- package/.claude/agents/sona/sona-learning-optimizer.md +74 -0
- package/.claude/agents/sparc/architecture.md +472 -0
- package/.claude/agents/sparc/pseudocode.md +318 -0
- package/.claude/agents/sparc/refinement.md +525 -0
- package/.claude/agents/sparc/specification.md +276 -0
- package/.claude/agents/specialized/mobile/spec-mobile-react-native.md +225 -0
- package/.claude/agents/sublinear/consensus-coordinator.md +338 -0
- package/.claude/agents/sublinear/matrix-optimizer.md +185 -0
- package/.claude/agents/sublinear/pagerank-analyzer.md +299 -0
- package/.claude/agents/sublinear/performance-optimizer.md +368 -0
- package/.claude/agents/sublinear/trading-predictor.md +246 -0
- package/.claude/agents/swarm/README.md +190 -0
- package/.claude/agents/swarm/adaptive-coordinator.md +396 -0
- package/.claude/agents/swarm/hierarchical-coordinator.md +327 -0
- package/.claude/agents/swarm/mesh-coordinator.md +392 -0
- package/.claude/agents/templates/automation-smart-agent.md +205 -0
- package/.claude/agents/templates/coordinator-swarm-init.md +105 -0
- package/.claude/agents/templates/github-pr-manager.md +177 -0
- package/.claude/agents/templates/implementer-sparc-coder.md +259 -0
- package/.claude/agents/templates/memory-coordinator.md +187 -0
- package/.claude/agents/templates/migration-plan.md +746 -0
- package/.claude/agents/templates/orchestrator-task.md +139 -0
- package/.claude/agents/templates/performance-analyzer.md +199 -0
- package/.claude/agents/templates/sparc-coordinator.md +183 -0
- package/.claude/agents/testing/production-validator.md +395 -0
- package/.claude/agents/testing/tdd-london-swarm.md +244 -0
- package/.claude/agents/testing/unit/tdd-london-swarm.md +244 -0
- package/.claude/agents/testing/validation/production-validator.md +395 -0
- package/.claude/agents/v3/database-specialist.yaml +21 -0
- package/.claude/agents/v3/index.yaml +17 -0
- package/.claude/agents/v3/project-coordinator.yaml +15 -0
- package/.claude/agents/v3/python-specialist.yaml +21 -0
- package/.claude/agents/v3/test-architect.yaml +20 -0
- package/.claude/agents/v3/typescript-specialist.yaml +21 -0
- package/.claude/agents/v3/v3-integration-architect.md +346 -0
- package/.claude/agents/v3/v3-memory-specialist.md +318 -0
- package/.claude/agents/v3/v3-performance-engineer.md +397 -0
- package/.claude/agents/v3/v3-queen-coordinator.md +98 -0
- package/.claude/agents/v3/v3-security-architect.md +174 -0
- package/.claude/commands/analysis/COMMAND_COMPLIANCE_REPORT.md +54 -0
- package/.claude/commands/analysis/README.md +9 -0
- package/.claude/commands/analysis/bottleneck-detect.md +162 -0
- package/.claude/commands/analysis/performance-bottlenecks.md +59 -0
- package/.claude/commands/analysis/performance-report.md +25 -0
- package/.claude/commands/analysis/token-efficiency.md +45 -0
- package/.claude/commands/analysis/token-usage.md +25 -0
- package/.claude/commands/automation/README.md +9 -0
- package/.claude/commands/automation/auto-agent.md +122 -0
- package/.claude/commands/automation/self-healing.md +106 -0
- package/.claude/commands/automation/session-memory.md +90 -0
- package/.claude/commands/automation/smart-agents.md +73 -0
- package/.claude/commands/automation/smart-spawn.md +25 -0
- package/.claude/commands/automation/workflow-select.md +25 -0
- package/.claude/commands/claude-flow-help.md +103 -0
- package/.claude/commands/claude-flow-memory.md +107 -0
- package/.claude/commands/claude-flow-swarm.md +205 -0
- package/.claude/commands/github/README.md +11 -0
- package/.claude/commands/github/code-review-swarm.md +514 -0
- package/.claude/commands/github/code-review.md +25 -0
- package/.claude/commands/github/github-modes.md +147 -0
- package/.claude/commands/github/github-swarm.md +121 -0
- package/.claude/commands/github/issue-tracker.md +292 -0
- package/.claude/commands/github/issue-triage.md +25 -0
- package/.claude/commands/github/multi-repo-swarm.md +519 -0
- package/.claude/commands/github/pr-enhance.md +26 -0
- package/.claude/commands/github/pr-manager.md +170 -0
- package/.claude/commands/github/project-board-sync.md +471 -0
- package/.claude/commands/github/release-manager.md +338 -0
- package/.claude/commands/github/release-swarm.md +544 -0
- package/.claude/commands/github/repo-analyze.md +25 -0
- package/.claude/commands/github/repo-architect.md +367 -0
- package/.claude/commands/github/swarm-issue.md +482 -0
- package/.claude/commands/github/swarm-pr.md +285 -0
- package/.claude/commands/github/sync-coordinator.md +301 -0
- package/.claude/commands/github/workflow-automation.md +442 -0
- package/.claude/commands/hooks/README.md +11 -0
- package/.claude/commands/hooks/overview.md +58 -0
- package/.claude/commands/hooks/post-edit.md +117 -0
- package/.claude/commands/hooks/post-task.md +112 -0
- package/.claude/commands/hooks/pre-edit.md +113 -0
- package/.claude/commands/hooks/pre-task.md +111 -0
- package/.claude/commands/hooks/session-end.md +118 -0
- package/.claude/commands/hooks/setup.md +103 -0
- package/.claude/commands/monitoring/README.md +9 -0
- package/.claude/commands/monitoring/agent-metrics.md +25 -0
- package/.claude/commands/monitoring/agents.md +44 -0
- package/.claude/commands/monitoring/real-time-view.md +25 -0
- package/.claude/commands/monitoring/status.md +46 -0
- package/.claude/commands/monitoring/swarm-monitor.md +25 -0
- package/.claude/commands/optimization/README.md +9 -0
- package/.claude/commands/optimization/auto-topology.md +62 -0
- package/.claude/commands/optimization/cache-manage.md +25 -0
- package/.claude/commands/optimization/parallel-execute.md +25 -0
- package/.claude/commands/optimization/parallel-execution.md +50 -0
- package/.claude/commands/optimization/topology-optimize.md +25 -0
- package/.claude/commands/sparc/analyzer.md +52 -0
- package/.claude/commands/sparc/architect.md +53 -0
- package/.claude/commands/sparc/ask.md +97 -0
- package/.claude/commands/sparc/batch-executor.md +54 -0
- package/.claude/commands/sparc/code.md +89 -0
- package/.claude/commands/sparc/coder.md +54 -0
- package/.claude/commands/sparc/debug.md +83 -0
- package/.claude/commands/sparc/debugger.md +54 -0
- package/.claude/commands/sparc/designer.md +53 -0
- package/.claude/commands/sparc/devops.md +109 -0
- package/.claude/commands/sparc/docs-writer.md +80 -0
- package/.claude/commands/sparc/documenter.md +54 -0
- package/.claude/commands/sparc/innovator.md +54 -0
- package/.claude/commands/sparc/integration.md +83 -0
- package/.claude/commands/sparc/mcp.md +117 -0
- package/.claude/commands/sparc/memory-manager.md +54 -0
- package/.claude/commands/sparc/optimizer.md +54 -0
- package/.claude/commands/sparc/orchestrator.md +132 -0
- package/.claude/commands/sparc/post-deployment-monitoring-mode.md +83 -0
- package/.claude/commands/sparc/refinement-optimization-mode.md +83 -0
- package/.claude/commands/sparc/researcher.md +54 -0
- package/.claude/commands/sparc/reviewer.md +54 -0
- package/.claude/commands/sparc/security-review.md +80 -0
- package/.claude/commands/sparc/sparc-modes.md +174 -0
- package/.claude/commands/sparc/sparc.md +111 -0
- package/.claude/commands/sparc/spec-pseudocode.md +80 -0
- package/.claude/commands/sparc/supabase-admin.md +348 -0
- package/.claude/commands/sparc/swarm-coordinator.md +54 -0
- package/.claude/commands/sparc/tdd.md +54 -0
- package/.claude/commands/sparc/tester.md +54 -0
- package/.claude/commands/sparc/tutorial.md +79 -0
- package/.claude/commands/sparc/workflow-manager.md +54 -0
- package/.claude/helpers/hook-handler.cjs +168 -0
- package/.claude/helpers/intelligence.cjs +197 -0
- package/.claude/helpers/memory.js +83 -0
- package/.claude/helpers/post-commit +16 -0
- package/.claude/helpers/pre-commit +26 -0
- package/.claude/helpers/router.js +66 -0
- package/.claude/helpers/session.js +127 -0
- package/.claude/settings.json +250 -0
- package/.claude/skills/agentdb-advanced/SKILL.md +550 -0
- package/.claude/skills/agentdb-learning/SKILL.md +545 -0
- package/.claude/skills/agentdb-memory-patterns/SKILL.md +339 -0
- package/.claude/skills/agentdb-optimization/SKILL.md +509 -0
- package/.claude/skills/agentdb-vector-search/SKILL.md +339 -0
- package/.claude/skills/github-code-review/SKILL.md +1140 -0
- package/.claude/skills/github-multi-repo/SKILL.md +874 -0
- package/.claude/skills/github-project-management/SKILL.md +1277 -0
- package/.claude/skills/github-release-management/SKILL.md +1081 -0
- package/.claude/skills/github-workflow-automation/SKILL.md +1065 -0
- package/.claude/skills/hooks-automation/SKILL.md +1201 -0
- package/.claude/skills/pair-programming/SKILL.md +1202 -0
- package/.claude/skills/reasoningbank-agentdb/SKILL.md +446 -0
- package/.claude/skills/reasoningbank-intelligence/SKILL.md +201 -0
- package/.claude/skills/skill-builder/.claude-flow/metrics/agent-metrics.json +1 -0
- package/.claude/skills/skill-builder/.claude-flow/metrics/performance.json +87 -0
- package/.claude/skills/skill-builder/.claude-flow/metrics/task-metrics.json +10 -0
- package/.claude/skills/skill-builder/SKILL.md +910 -0
- package/.claude/skills/sparc-methodology/SKILL.md +1115 -0
- package/.claude/skills/stream-chain/SKILL.md +563 -0
- package/.claude/skills/swarm-advanced/SKILL.md +973 -0
- package/.claude/skills/swarm-orchestration/SKILL.md +179 -0
- package/.claude/skills/v3-cli-modernization/SKILL.md +872 -0
- package/.claude/skills/v3-core-implementation/SKILL.md +797 -0
- package/.claude/skills/v3-ddd-architecture/SKILL.md +442 -0
- package/.claude/skills/v3-integration-deep/SKILL.md +241 -0
- package/.claude/skills/v3-mcp-optimization/SKILL.md +777 -0
- package/.claude/skills/v3-memory-unification/SKILL.md +174 -0
- package/.claude/skills/v3-performance-optimization/SKILL.md +390 -0
- package/.claude/skills/v3-security-overhaul/SKILL.md +82 -0
- package/.claude/skills/v3-swarm-coordination/SKILL.md +340 -0
- package/.claude/skills/verification-quality/SKILL.md +649 -0
- package/.claude/statusline.mjs +109 -0
- package/.claude/statusline.sh +375 -0
- package/.claude-flow/CAPABILITIES.md +403 -0
- package/.claude-flow/config.yaml +43 -0
- package/.claude-flow/metrics/learning.json +17 -0
- package/.claude-flow/metrics/swarm-activity.json +18 -0
- package/.claude-flow/metrics/v3-progress.json +26 -0
- package/.claude-flow/security/audit-status.json +8 -0
- package/.mcp.json +20 -0
- package/AGENTS.md +145 -0
- package/CLAUDE.md +188 -0
- package/LICENSE +21 -0
- package/README.md +115 -0
- package/bin/cf-guidance-impl.mjs +74 -0
- package/package.json +23 -0
- package/scaffold/.claude/helpers/hook-handler.cjs +576 -0
- package/scaffold/docs/guidance-control-plane.md +441 -0
- package/scaffold/docs/guidance-implementation-guide.md +424 -0
- package/scaffold/scripts/analyze-guidance.js +176 -0
- package/scaffold/scripts/guidance-ab-benchmark.js +40 -0
- package/scaffold/scripts/guidance-autopilot.js +473 -0
- package/scaffold/scripts/guidance-codex-bridge.js +337 -0
- package/scaffold/scripts/guidance-integrations.js +587 -0
- package/scaffold/scripts/guidance-runtime.js +133 -0
- package/scaffold/scripts/scaffold-guidance.js +122 -0
- package/scaffold/src/guidance/advanced-runtime.js +658 -0
- package/scaffold/src/guidance/content-aware-executor.js +70 -0
- package/scaffold/src/guidance/phase1-runtime.js +151 -0
- package/src/default-settings.mjs +111 -0
- package/src/installer.mjs +415 -0
|
@@ -0,0 +1,424 @@
|
|
|
1
|
+
# Guidance Implementation Guide (Authoritative)
|
|
2
|
+
|
|
3
|
+
Status date: 2026-02-17
|
|
4
|
+
|
|
5
|
+
This is the authoritative implementation guide for using `@claude-flow/guidance` in this repo.
|
|
6
|
+
|
|
7
|
+
It answers four things precisely:
|
|
8
|
+
- What the upstream package/README actually provides
|
|
9
|
+
- What we implemented in this repo
|
|
10
|
+
- How hooks and background automation are wired
|
|
11
|
+
- What is automated vs what still needs manual input
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
## 1) Quick Reality Check
|
|
16
|
+
|
|
17
|
+
`@claude-flow/guidance` is a library + CLI surface, not a single turnkey mode.
|
|
18
|
+
|
|
19
|
+
To get the full behavior described in the post/README, you need:
|
|
20
|
+
1. Guidance runtime APIs (compile/retrieve/gates/ledger)
|
|
21
|
+
2. Continuous event wiring (pre/post hooks)
|
|
22
|
+
3. Ongoing optimization/promotion loop (`CLAUDE.local.md` -> `CLAUDE.md`)
|
|
23
|
+
|
|
24
|
+
All three are now present in this repo.
|
|
25
|
+
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
## 2) What Quickstart and "Tutorials" Mean
|
|
29
|
+
|
|
30
|
+
## Quickstart section purpose
|
|
31
|
+
The README Quickstart shows the control-plane API sequence:
|
|
32
|
+
- initialize control plane
|
|
33
|
+
- retrieve task-scoped guidance
|
|
34
|
+
- evaluate gates
|
|
35
|
+
- finalize run
|
|
36
|
+
|
|
37
|
+
It is an embedding example, not "run this one script and everything is wired automatically."
|
|
38
|
+
|
|
39
|
+
## Tutorial sections purpose
|
|
40
|
+
The README "Tutorial: Wiring into Claude Code hooks", "Trust", "Adversarial", etc. are integration recipes.
|
|
41
|
+
|
|
42
|
+
They are examples of how to wire modules into your runtime/hook system. They are not separate built-in CLI commands you must run one-by-one as setup.
|
|
43
|
+
|
|
44
|
+
---
|
|
45
|
+
|
|
46
|
+
## 3) Post Claims -> Concrete Implementation Mapping
|
|
47
|
+
|
|
48
|
+
The post language maps to concrete components as follows:
|
|
49
|
+
|
|
50
|
+
| Post claim | Concrete mechanism |
|
|
51
|
+
|---|---|
|
|
52
|
+
| "CLAUDE.md compiled into typed constitution + shards" | `createCompiler()` + `createRetriever()` in `src/guidance/phase1-runtime.js` |
|
|
53
|
+
| "CLAUDE.local.md overlays private context" | `compiler.compile(root, local)` in phase-1 runtime and autopilot |
|
|
54
|
+
| "Local wins can be promoted with ADR" | `scripts/guidance-autopilot.js` promotion flow + ADR generation in `docs/adr/` |
|
|
55
|
+
| "Rules enforced, loops reduce" | pre-event gates + runtime gating in hook wiring |
|
|
56
|
+
| "Replayable/auditable decisions" | proof chain + advanced state in `.claude-flow/guidance/advanced/` |
|
|
57
|
+
|
|
58
|
+
Important: those outcomes only happen continuously when runtime/hook wiring exists. The library alone does not enforce itself.
|
|
59
|
+
|
|
60
|
+
---
|
|
61
|
+
|
|
62
|
+
## 4) What Is Implemented in This Repo
|
|
63
|
+
|
|
64
|
+
This repo now has manual command-bridge wiring from Claude hooks into guidance runtime:
|
|
65
|
+
|
|
66
|
+
| Area | File(s) | Status |
|
|
67
|
+
|---|---|---|
|
|
68
|
+
| Phase-1 runtime (compiler/retriever/gates/ledger/hooks provider) | `src/guidance/phase1-runtime.js` | Implemented |
|
|
69
|
+
| Advanced runtime (trust/adversarial/proof/conformance/evolution) | `src/guidance/advanced-runtime.js` | Implemented |
|
|
70
|
+
| Event bridge entrypoint | `scripts/guidance-integrations.js` | Implemented |
|
|
71
|
+
| Hook bridge and event dispatch | `.claude/helpers/hook-handler.cjs` | Implemented |
|
|
72
|
+
| Codex lifecycle bridge | `scripts/guidance-codex-bridge.js` | Implemented |
|
|
73
|
+
| Claude hook config | `.claude/settings.json` | Wired |
|
|
74
|
+
| Codex lifecycle command map | `.agents/config.toml`, `AGENTS.md` | Wired |
|
|
75
|
+
| Analysis / benchmark / autopilot scripts | `scripts/analyze-guidance.js`, `scripts/guidance-ab-benchmark.js`, `scripts/guidance-autopilot.js` | Implemented |
|
|
76
|
+
| Implementation docs | `docs/guidance-control-plane.md`, this document | Updated |
|
|
77
|
+
|
|
78
|
+
---
|
|
79
|
+
|
|
80
|
+
## 5) Hook Wiring Architecture (Current)
|
|
81
|
+
|
|
82
|
+
Execution chain:
|
|
83
|
+
|
|
84
|
+
1. Claude hook triggers command in `.claude/settings.json`
|
|
85
|
+
2. `.claude/helpers/hook-handler.cjs` parses hook payload
|
|
86
|
+
3. Hook handler calls `node scripts/guidance-integrations.js event <event> <json>`
|
|
87
|
+
4. `scripts/guidance-integrations.js` runs phase-1/advanced logic
|
|
88
|
+
5. Pre-events can block, post-events persist governance state
|
|
89
|
+
|
|
90
|
+
This is used because Claude Code hooks here are command-based, not direct in-process `HookRegistry` injection.
|
|
91
|
+
|
|
92
|
+
Codex path in this repo:
|
|
93
|
+
1. Run lifecycle command via `scripts/guidance-codex-bridge.js`
|
|
94
|
+
2. Bridge forwards to `.claude/helpers/hook-handler.cjs` with normalized payload
|
|
95
|
+
3. Hook handler dispatches into `scripts/guidance-integrations.js event ...`
|
|
96
|
+
4. Optional best-effort `npx @claude-flow/cli@latest hooks ...` telemetry runs
|
|
97
|
+
|
|
98
|
+
## Event mapping
|
|
99
|
+
|
|
100
|
+
| Claude hook path | Guidance event | Sync/Async | Can block |
|
|
101
|
+
|---|---|---|---|
|
|
102
|
+
| `PreToolUse Bash` -> `pre-bash` | `pre-command` | Sync | Yes |
|
|
103
|
+
| `PreToolUse Write|Edit|MultiEdit` -> `pre-edit` | `pre-edit` | Sync | Yes |
|
|
104
|
+
| `PreToolUse Task` -> `pre-task` | `pre-task` | Sync | Yes |
|
|
105
|
+
| `PostToolUse Write|Edit|MultiEdit` -> `post-edit` | `post-edit` | Async | No |
|
|
106
|
+
| `PostToolUse Task` -> `post-task` | `post-task` | Async | No |
|
|
107
|
+
| `SessionEnd` -> `session-end` | `session-end` | Async | No |
|
|
108
|
+
|
|
109
|
+
## Block semantics
|
|
110
|
+
- `blocked: true` from sync event causes hook failure (non-zero exit)
|
|
111
|
+
- Fail-open/fail-closed on event execution errors is controlled by env:
|
|
112
|
+
- `GUIDANCE_EVENT_FAIL_CLOSED=0` (current default): fail open
|
|
113
|
+
- `GUIDANCE_EVENT_FAIL_CLOSED=1`: fail closed
|
|
114
|
+
|
|
115
|
+
## Codex lifecycle runbook
|
|
116
|
+
|
|
117
|
+
Codex integration is command-driven in this repo. Run bridge commands in this order:
|
|
118
|
+
|
|
119
|
+
1. Session start:
|
|
120
|
+
```bash
|
|
121
|
+
npm run guidance:codex:session-start
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
2. Before task execution:
|
|
125
|
+
```bash
|
|
126
|
+
npm run guidance:codex:pre-task -- --task-id task-123 --description "Implement feature X"
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
3. Before risky command/edit operations:
|
|
130
|
+
```bash
|
|
131
|
+
npm run guidance:codex:pre-command -- --task-id task-123 --command "git status"
|
|
132
|
+
npm run guidance:codex:pre-edit -- --task-id task-123 --file src/example.ts --operation modify
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
4. After edits/task completion:
|
|
136
|
+
```bash
|
|
137
|
+
npm run guidance:codex:post-edit -- --task-id task-123 --file src/example.ts
|
|
138
|
+
npm run guidance:codex:post-task -- --task-id task-123 --status completed --description "Implement feature X"
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
5. Session end:
|
|
142
|
+
```bash
|
|
143
|
+
npm run guidance:codex:session-end -- --task-id task-123
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
Verification expectations:
|
|
147
|
+
- Bridge output is JSON with `handler.ok: true` when local enforcement path succeeds.
|
|
148
|
+
- `claudeFlowHook.ok: true` indicates secondary `@claude-flow/cli` hook telemetry succeeded.
|
|
149
|
+
- Use `--skip-cf-hooks` for local smoke tests if you only want bridge/handler validation.
|
|
150
|
+
|
|
151
|
+
---
|
|
152
|
+
|
|
153
|
+
## 6) Command Surface You Should Use
|
|
154
|
+
|
|
155
|
+
## Upstream CLI (verified in this repo)
|
|
156
|
+
|
|
157
|
+
```bash
|
|
158
|
+
npx claude-flow guidance compile
|
|
159
|
+
npx claude-flow guidance retrieve -t "Fix auth bug"
|
|
160
|
+
npx claude-flow guidance gates -c "git push --force origin main"
|
|
161
|
+
npx claude-flow guidance status
|
|
162
|
+
npx claude-flow guidance optimize
|
|
163
|
+
npx claude-flow guidance ab-test
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
Notes:
|
|
167
|
+
- `claude-flow analyze` is a different command family (code/diff analysis), not guidance scoring.
|
|
168
|
+
- Post/marketing snippets using `ab-benchmark` map to `guidance ab-test` in current CLI.
|
|
169
|
+
|
|
170
|
+
## Repo npm wrappers
|
|
171
|
+
|
|
172
|
+
```bash
|
|
173
|
+
npm run guidance:status
|
|
174
|
+
npm run guidance:analyze
|
|
175
|
+
npm run guidance:runtime
|
|
176
|
+
npm run guidance:hooks
|
|
177
|
+
npm run guidance:trust
|
|
178
|
+
npm run guidance:adversarial
|
|
179
|
+
npm run guidance:proof
|
|
180
|
+
npm run guidance:conformance
|
|
181
|
+
npm run guidance:evolution
|
|
182
|
+
npm run guidance:all
|
|
183
|
+
npm run guidance:ab-benchmark
|
|
184
|
+
npm run guidance:optimize
|
|
185
|
+
npm run guidance:autopilot:once
|
|
186
|
+
npm run guidance:autopilot:daemon
|
|
187
|
+
npm run guidance:codex:status
|
|
188
|
+
npm run guidance:codex:pre-command -- --command "git status"
|
|
189
|
+
npm run guidance:codex:pre-edit -- --file src/example.ts
|
|
190
|
+
npm run guidance:codex:pre-task -- --description "Implement feature X"
|
|
191
|
+
npm run guidance:codex:post-edit -- --file src/example.ts
|
|
192
|
+
npm run guidance:codex:post-task -- --task-id task-123 --status completed
|
|
193
|
+
npm run guidance:codex:session-start
|
|
194
|
+
npm run guidance:codex:session-end
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
Use upstream CLI for baseline guidance operations.
|
|
198
|
+
Use repo wrappers for wired runtime checks, advanced module exercises, autopilot promotion flow, and Codex lifecycle dispatch.
|
|
199
|
+
|
|
200
|
+
---
|
|
201
|
+
|
|
202
|
+
## 7) `createGuidanceHooks` API Clarification
|
|
203
|
+
|
|
204
|
+
README tutorial snippet shows object-style usage:
|
|
205
|
+
|
|
206
|
+
```ts
|
|
207
|
+
createGuidanceHooks({ gates, retriever, ledger })
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
Installed API type signature is positional:
|
|
211
|
+
|
|
212
|
+
```ts
|
|
213
|
+
createGuidanceHooks(gates, retriever, ledger, registry?)
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
Example:
|
|
217
|
+
|
|
218
|
+
```ts
|
|
219
|
+
import { createGuidanceHooks } from '@claude-flow/guidance';
|
|
220
|
+
|
|
221
|
+
const { provider, hookIds } = createGuidanceHooks(gates, retriever, ledger, hookRegistry);
|
|
222
|
+
// or:
|
|
223
|
+
// const { provider } = createGuidanceHooks(gates, retriever, ledger);
|
|
224
|
+
// provider.registerAll(hookRegistry);
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
In this repo, this is already used inside `src/guidance/phase1-runtime.js`. External Claude hook wiring is done through shell commands, not direct provider registry injection.
|
|
228
|
+
|
|
229
|
+
---
|
|
230
|
+
|
|
231
|
+
## 8) Advanced Modules: What They Do and How They Run Here
|
|
232
|
+
|
|
233
|
+
| Module | Purpose | Live in hook path? | Trigger in this repo |
|
|
234
|
+
|---|---|---|---|
|
|
235
|
+
| Hooks integration | Phase-1 pre/post task and command flow exercise | Partially | `event` pre/post paths + `npm run guidance:hooks` |
|
|
236
|
+
| Trust | Agent trust score/tier/rate logic | Yes | Recorded on pre/post events |
|
|
237
|
+
| Adversarial | Injection/exfil/poisoning/collusion/quorum detection | Partially | Threat detection active on `pre-command`; full suite via `npm run guidance:adversarial` |
|
|
238
|
+
| Proof | Hash-chained proof envelopes | Yes | Appended on hook events |
|
|
239
|
+
| Conformance | Replay/integrity checks | Yes | `session-end` event |
|
|
240
|
+
| Evolution | Propose/simulate/stage governance changes | Yes | `session-end` event |
|
|
241
|
+
|
|
242
|
+
Key nuance:
|
|
243
|
+
- Full adversarial collusion/quorum workflow is exercised in module runs.
|
|
244
|
+
- Live hook path currently applies adversarial threat detection primarily on command input.
|
|
245
|
+
|
|
246
|
+
---
|
|
247
|
+
|
|
248
|
+
## 9) Background Automation and Autopilot
|
|
249
|
+
|
|
250
|
+
## What runs automatically
|
|
251
|
+
- Pre-command/edit/task guidance checks on matching hooks
|
|
252
|
+
- Post-edit/post-task governance writes (async)
|
|
253
|
+
- Session-end conformance/evolution event (async)
|
|
254
|
+
- Session-end autopilot launch (detached process) unless disabled
|
|
255
|
+
|
|
256
|
+
## Where autopilot is launched
|
|
257
|
+
- `.claude/helpers/hook-handler.cjs` -> `launchGuidanceAutopilot('session-end')`
|
|
258
|
+
|
|
259
|
+
## Autopilot controls
|
|
260
|
+
- `GUIDANCE_AUTOPILOT_ENABLED=0` disables launch
|
|
261
|
+
- `GUIDANCE_AUTOPILOT_MIN_DELTA` sets promotion threshold
|
|
262
|
+
- `GUIDANCE_AUTOPILOT_AB=1` enables AB gate
|
|
263
|
+
- `GUIDANCE_AUTOPILOT_MIN_AB_GAIN` sets AB minimum gain
|
|
264
|
+
|
|
265
|
+
Current `.claude/settings.json` includes guidance event controls by default:
|
|
266
|
+
- `GUIDANCE_EVENT_WIRING_ENABLED=1`
|
|
267
|
+
- `GUIDANCE_EVENT_SYNC_TIMEOUT_MS=8000`
|
|
268
|
+
- `GUIDANCE_EVENT_FAIL_CLOSED=0`
|
|
269
|
+
|
|
270
|
+
---
|
|
271
|
+
|
|
272
|
+
## 10) CLAUDE.local.md: Manual vs Automated Responsibilities
|
|
273
|
+
|
|
274
|
+
## Manual (you still do this)
|
|
275
|
+
- Add local experimental rules to `CLAUDE.local.md` in parseable guidance style.
|
|
276
|
+
- Keep purely personal notes there as needed.
|
|
277
|
+
|
|
278
|
+
## Automated (system does this)
|
|
279
|
+
- Detect promotable local rules
|
|
280
|
+
- Build candidate promotion section in `CLAUDE.md`
|
|
281
|
+
- Score/benchmark candidate
|
|
282
|
+
- Apply if thresholds pass (`--apply`) and generate ADR
|
|
283
|
+
- Otherwise write proposal only
|
|
284
|
+
|
|
285
|
+
Important:
|
|
286
|
+
- If `CLAUDE.local.md` has no parseable local rules, autopilot reports `no-promotable-local-rules`.
|
|
287
|
+
- It does not invent good rules from free-form notes automatically.
|
|
288
|
+
|
|
289
|
+
---
|
|
290
|
+
|
|
291
|
+
## 11) From Clean Clone: Recommended Setup
|
|
292
|
+
|
|
293
|
+
1. Install deps.
|
|
294
|
+
```bash
|
|
295
|
+
npm install
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
2. Initialize Claude Flow base config if needed.
|
|
299
|
+
```bash
|
|
300
|
+
npx claude-flow init
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
3. Verify guidance command surface.
|
|
304
|
+
```bash
|
|
305
|
+
npx claude-flow guidance --help
|
|
306
|
+
```
|
|
307
|
+
|
|
308
|
+
4. Verify repo wiring files exist and are referenced.
|
|
309
|
+
- `.claude/settings.json`
|
|
310
|
+
- `.claude/helpers/hook-handler.cjs`
|
|
311
|
+
- `scripts/guidance-integrations.js`
|
|
312
|
+
- `scripts/guidance-codex-bridge.js`
|
|
313
|
+
|
|
314
|
+
5. Run baseline checks.
|
|
315
|
+
```bash
|
|
316
|
+
npm run guidance:status
|
|
317
|
+
npm run guidance:analyze
|
|
318
|
+
npm run guidance:ab-benchmark
|
|
319
|
+
```
|
|
320
|
+
|
|
321
|
+
6. Run advanced suite.
|
|
322
|
+
```bash
|
|
323
|
+
npm run guidance:all
|
|
324
|
+
```
|
|
325
|
+
|
|
326
|
+
7. Run autopilot manually.
|
|
327
|
+
```bash
|
|
328
|
+
npm run guidance:autopilot:once
|
|
329
|
+
```
|
|
330
|
+
|
|
331
|
+
8. Optional continuous autopilot loop.
|
|
332
|
+
```bash
|
|
333
|
+
npm run guidance:autopilot:daemon
|
|
334
|
+
```
|
|
335
|
+
|
|
336
|
+
---
|
|
337
|
+
|
|
338
|
+
## 12) Verification Runbook (Hook Path)
|
|
339
|
+
|
|
340
|
+
## Pre-command allow
|
|
341
|
+
```bash
|
|
342
|
+
printf '%s' '{"tool_input":{"command":"git status"}}' \
|
|
343
|
+
| node .claude/helpers/hook-handler.cjs pre-bash
|
|
344
|
+
```
|
|
345
|
+
|
|
346
|
+
## Pre-command block
|
|
347
|
+
```bash
|
|
348
|
+
printf '%s' '{"tool_input":{"command":"git push --force origin main"}}' \
|
|
349
|
+
| node .claude/helpers/hook-handler.cjs pre-bash
|
|
350
|
+
```
|
|
351
|
+
|
|
352
|
+
## Pre-task + post-task correlation
|
|
353
|
+
```bash
|
|
354
|
+
printf '%s' '{"tool_input":{"description":"Implement x"}}' \
|
|
355
|
+
| node .claude/helpers/hook-handler.cjs pre-task
|
|
356
|
+
|
|
357
|
+
printf '%s' '{"tool_input":{"status":"completed"}}' \
|
|
358
|
+
| node .claude/helpers/hook-handler.cjs post-task
|
|
359
|
+
```
|
|
360
|
+
|
|
361
|
+
Inspect:
|
|
362
|
+
- `.claude-flow/guidance/advanced/advanced-state.json`
|
|
363
|
+
- `.claude-flow/guidance/advanced/pending-runs.json`
|
|
364
|
+
- `.claude-flow/guidance/hook-task-cache.json`
|
|
365
|
+
|
|
366
|
+
---
|
|
367
|
+
|
|
368
|
+
## 13) What `init` Does vs What It Does Not Do
|
|
369
|
+
|
|
370
|
+
`npx claude-flow init` sets up Claude Flow baseline scaffolding and hook framework.
|
|
371
|
+
|
|
372
|
+
It does not guarantee your repo-specific guidance bridge scripts are wired exactly the way this repo now uses them.
|
|
373
|
+
|
|
374
|
+
This repo's authoritative wiring is the combination of:
|
|
375
|
+
- `.claude/settings.json` hook commands
|
|
376
|
+
- `.claude/helpers/hook-handler.cjs` bridge logic
|
|
377
|
+
- `scripts/guidance-integrations.js event ...` handlers
|
|
378
|
+
|
|
379
|
+
---
|
|
380
|
+
|
|
381
|
+
## 14) FAQ (Most Common Confusions)
|
|
382
|
+
|
|
383
|
+
## "Do I need to manually add content to CLAUDE.local.md?"
|
|
384
|
+
Yes, for local experimental rules you want considered for promotion. Automation evaluates and promotes; it does not create high-quality local policy out of nothing.
|
|
385
|
+
|
|
386
|
+
## "Does this run in the background to improve CLAUDE.md?"
|
|
387
|
+
Yes, session-end can launch autopilot in background. You can also run continuous daemon mode with `npm run guidance:autopilot:daemon`.
|
|
388
|
+
|
|
389
|
+
## "Do tutorials mean extra setup scripts are required?"
|
|
390
|
+
No. Tutorials are implementation recipes. We already implemented the wiring here.
|
|
391
|
+
|
|
392
|
+
## "Are hooks/daemon/automation configured?"
|
|
393
|
+
Yes in this repo. Guidance event wiring is enabled and session-end autopilot launch is present.
|
|
394
|
+
|
|
395
|
+
---
|
|
396
|
+
|
|
397
|
+
## 15) Known Limitations
|
|
398
|
+
|
|
399
|
+
- Hook payload metadata can be sparse, so some event details may default.
|
|
400
|
+
- `post-task` currently supplies empty `toolsUsed/filesTouched` unless provided.
|
|
401
|
+
- Live adversarial path is strongest on command input; collusion/quorum are mainly exercised in advanced module runs.
|
|
402
|
+
- Default sync error policy is fail-open (`GUIDANCE_EVENT_FAIL_CLOSED=0`).
|
|
403
|
+
|
|
404
|
+
---
|
|
405
|
+
|
|
406
|
+
## 16) Source References
|
|
407
|
+
|
|
408
|
+
Repository implementation:
|
|
409
|
+
- `src/guidance/phase1-runtime.js`
|
|
410
|
+
- `src/guidance/advanced-runtime.js`
|
|
411
|
+
- `scripts/guidance-integrations.js`
|
|
412
|
+
- `scripts/guidance-runtime.js`
|
|
413
|
+
- `scripts/guidance-autopilot.js`
|
|
414
|
+
- `scripts/guidance-ab-benchmark.js`
|
|
415
|
+
- `scripts/analyze-guidance.js`
|
|
416
|
+
- `.claude/helpers/hook-handler.cjs`
|
|
417
|
+
- `.claude/settings.json`
|
|
418
|
+
- `package.json`
|
|
419
|
+
|
|
420
|
+
Upstream/package docs and API:
|
|
421
|
+
- `node_modules/@claude-flow/guidance/README.md`
|
|
422
|
+
- `node_modules/@claude-flow/guidance/dist/hooks.d.ts`
|
|
423
|
+
- `https://github.com/ruvnet/claude-flow/blob/main/v3/%40claude-flow/guidance/README.md`
|
|
424
|
+
- `https://github.com/ruvnet/claude-flow/blob/main/v3/%40claude-flow/guidance/docs/reference/api-quick-reference.md`
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Analyze CLAUDE.md files with @claude-flow/guidance
|
|
4
|
+
*
|
|
5
|
+
* Compiles the project's CLAUDE.md into a policy bundle,
|
|
6
|
+
* scores it across 6 dimensions, and reports the results.
|
|
7
|
+
*
|
|
8
|
+
* Usage: node scripts/analyze-guidance.js [--optimize]
|
|
9
|
+
*/
|
|
10
|
+
import { readFileSync, writeFileSync, mkdirSync } from 'node:fs';
|
|
11
|
+
import { resolve, dirname } from 'node:path';
|
|
12
|
+
import { fileURLToPath } from 'node:url';
|
|
13
|
+
|
|
14
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
15
|
+
const root = resolve(__dirname, '..');
|
|
16
|
+
|
|
17
|
+
// Import guidance modules
|
|
18
|
+
const { analyze, autoOptimize, formatReport, formatBenchmark } = await import('@claude-flow/guidance/analyzer');
|
|
19
|
+
const { createGuidanceControlPlane } = await import('@claude-flow/guidance');
|
|
20
|
+
const { createGuidancePhase1Runtime } = await import('../src/guidance/phase1-runtime.js');
|
|
21
|
+
|
|
22
|
+
const DATA_DIR = resolve(root, '.claude-flow/guidance');
|
|
23
|
+
const CLAUDE_MD = resolve(root, 'CLAUDE.md');
|
|
24
|
+
const PARENT_CLAUDE_MD = resolve(root, '..', 'CLAUDE.md');
|
|
25
|
+
const CLAUDE_LOCAL_MD = resolve(root, 'CLAUDE.local.md');
|
|
26
|
+
|
|
27
|
+
// Ensure data dir exists
|
|
28
|
+
mkdirSync(DATA_DIR, { recursive: true });
|
|
29
|
+
|
|
30
|
+
// --- 1. Read CLAUDE.md files ---
|
|
31
|
+
console.log('=== @claude-flow/guidance - CLAUDE.md Analysis ===\n');
|
|
32
|
+
|
|
33
|
+
let content;
|
|
34
|
+
try {
|
|
35
|
+
content = readFileSync(CLAUDE_MD, 'utf-8');
|
|
36
|
+
console.log(`Loaded: ${CLAUDE_MD} (${content.split('\n').length} lines)`);
|
|
37
|
+
} catch {
|
|
38
|
+
console.error(`ERROR: Cannot read ${CLAUDE_MD}`);
|
|
39
|
+
process.exit(1);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
let parentContent = null;
|
|
43
|
+
try {
|
|
44
|
+
parentContent = readFileSync(PARENT_CLAUDE_MD, 'utf-8');
|
|
45
|
+
console.log(`Loaded: ${PARENT_CLAUDE_MD} (${parentContent.split('\n').length} lines)`);
|
|
46
|
+
} catch {
|
|
47
|
+
// Parent CLAUDE.md is optional
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
let localContent = null;
|
|
51
|
+
try {
|
|
52
|
+
localContent = readFileSync(CLAUDE_LOCAL_MD, 'utf-8');
|
|
53
|
+
console.log(`Loaded: ${CLAUDE_LOCAL_MD} (${localContent.split('\n').length} lines)`);
|
|
54
|
+
} catch {
|
|
55
|
+
// Local CLAUDE.local.md is optional
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// --- 2. Analyze ---
|
|
59
|
+
console.log('\n--- Analysis Results ---\n');
|
|
60
|
+
const result = analyze(content, localContent ?? undefined);
|
|
61
|
+
|
|
62
|
+
console.log(formatReport(result));
|
|
63
|
+
|
|
64
|
+
// --- 3. Initialize Control Plane ---
|
|
65
|
+
console.log('\n--- Policy Bundle Compilation ---\n');
|
|
66
|
+
|
|
67
|
+
try {
|
|
68
|
+
const plane = createGuidanceControlPlane({
|
|
69
|
+
rootGuidancePath: CLAUDE_MD,
|
|
70
|
+
localGuidancePath: localContent ? CLAUDE_LOCAL_MD : undefined,
|
|
71
|
+
dataDir: DATA_DIR,
|
|
72
|
+
});
|
|
73
|
+
await plane.initialize();
|
|
74
|
+
|
|
75
|
+
const status = plane.getStatus();
|
|
76
|
+
console.log(`Constitution loaded: ${status.constitutionLoaded}`);
|
|
77
|
+
console.log(`Shards compiled: ${status.shardCount}`);
|
|
78
|
+
console.log(`Active gates: ${status.activeGates}`);
|
|
79
|
+
console.log(`Initialized: ${status.initialized}`);
|
|
80
|
+
|
|
81
|
+
// Save bundle for inspection
|
|
82
|
+
const bundle = plane.getBundle();
|
|
83
|
+
if (bundle) {
|
|
84
|
+
const bundleSummary = {
|
|
85
|
+
constitutionHash: bundle.constitution.hash,
|
|
86
|
+
constitutionRuleCount: bundle.constitution.rules.length,
|
|
87
|
+
shardCount: bundle.shards.length,
|
|
88
|
+
shards: bundle.shards.map(s => ({
|
|
89
|
+
id: s.rule.id,
|
|
90
|
+
riskClass: s.rule.riskClass,
|
|
91
|
+
intents: s.rule.intents,
|
|
92
|
+
domains: s.rule.domains,
|
|
93
|
+
text: s.rule.text.slice(0, 120) + (s.rule.text.length > 120 ? '...' : ''),
|
|
94
|
+
})),
|
|
95
|
+
compiledAt: new Date().toISOString(),
|
|
96
|
+
};
|
|
97
|
+
writeFileSync(
|
|
98
|
+
resolve(DATA_DIR, 'bundle-summary.json'),
|
|
99
|
+
JSON.stringify(bundleSummary, null, 2)
|
|
100
|
+
);
|
|
101
|
+
console.log(`\nBundle saved to: .claude-flow/guidance/bundle-summary.json`);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// Test retrieval for a sample task
|
|
105
|
+
console.log('\n--- Sample Shard Retrieval ---\n');
|
|
106
|
+
const tasks = [
|
|
107
|
+
'Apply for a graph database specialist role',
|
|
108
|
+
'Update LinkedIn profile with HSBC experience',
|
|
109
|
+
'Build consulting website with portfolio',
|
|
110
|
+
'Fix a bug in the automation scripts',
|
|
111
|
+
];
|
|
112
|
+
|
|
113
|
+
for (const task of tasks) {
|
|
114
|
+
try {
|
|
115
|
+
const guidance = await plane.retrieveForTask({ taskDescription: task, maxShards: 3 });
|
|
116
|
+
console.log(`Task: "${task}"`);
|
|
117
|
+
console.log(` Intent: ${guidance.detectedIntent}, Shards: ${guidance.shards.length}, Latency: ${guidance.latencyMs.toFixed(2)}ms`);
|
|
118
|
+
console.log(` Policy text: ${guidance.policyText.length} chars`);
|
|
119
|
+
if (guidance.shards.length > 0) {
|
|
120
|
+
for (const s of guidance.shards.slice(0, 2)) {
|
|
121
|
+
const similarity = typeof s.similarity === 'number' ? s.similarity.toFixed(2) : '?';
|
|
122
|
+
const text = s.shard?.rule?.text ?? JSON.stringify(s).slice(0, 80);
|
|
123
|
+
console.log(` - [${similarity}] ${String(text).slice(0, 90)}`);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
console.log();
|
|
127
|
+
} catch (e) {
|
|
128
|
+
const message = e instanceof Error ? e.message : String(e);
|
|
129
|
+
console.log(`Task: "${task}" -> retrieval error: ${message}\n`);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// Hook pipeline smoke-check
|
|
134
|
+
console.log('--- Phase-1 Hook Runtime Smoke Check ---\n');
|
|
135
|
+
const runtime = createGuidancePhase1Runtime({
|
|
136
|
+
rootDir: root,
|
|
137
|
+
rootGuidancePath: 'CLAUDE.md',
|
|
138
|
+
localGuidancePath: localContent ? 'CLAUDE.local.md' : null,
|
|
139
|
+
});
|
|
140
|
+
await runtime.initialize();
|
|
141
|
+
|
|
142
|
+
const hookTaskId = `analysis-${Date.now()}`;
|
|
143
|
+
const preTask = await runtime.preTask({
|
|
144
|
+
taskId: hookTaskId,
|
|
145
|
+
taskDescription: 'Analyze guidance and wire runtime hooks',
|
|
146
|
+
});
|
|
147
|
+
console.log(`PreTask: success=${preTask.success}, aborted=${Boolean(preTask.aborted)}`);
|
|
148
|
+
|
|
149
|
+
const destructive = await runtime.preCommand('git push origin main --force');
|
|
150
|
+
console.log(`PreCommand(destructive): success=${destructive.success}, aborted=${Boolean(destructive.aborted)}`);
|
|
151
|
+
|
|
152
|
+
const safe = await runtime.preCommand('git status');
|
|
153
|
+
console.log(`PreCommand(safe): success=${safe.success}, aborted=${Boolean(safe.aborted)}`);
|
|
154
|
+
|
|
155
|
+
await runtime.postTask({ taskId: hookTaskId, status: 'completed' });
|
|
156
|
+
|
|
157
|
+
} catch (e) {
|
|
158
|
+
const message = e instanceof Error ? e.message : String(e);
|
|
159
|
+
console.error(`Control plane error: ${message}`);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// --- 4. Optimize (optional) ---
|
|
163
|
+
if (process.argv.includes('--optimize')) {
|
|
164
|
+
console.log('\n--- Auto-Optimization ---\n');
|
|
165
|
+
const optimized = autoOptimize(content, localContent ?? undefined);
|
|
166
|
+
console.log(`Applied ${optimized.appliedSuggestions.length} suggestions`);
|
|
167
|
+
console.log(formatBenchmark(optimized.benchmark));
|
|
168
|
+
|
|
169
|
+
writeFileSync(
|
|
170
|
+
resolve(DATA_DIR, 'CLAUDE.optimized.md'),
|
|
171
|
+
optimized.optimized
|
|
172
|
+
);
|
|
173
|
+
console.log(`\nOptimized version saved to: .claude-flow/guidance/CLAUDE.optimized.md`);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
console.log('\n=== Guidance analysis complete ===');
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
3
|
+
import { dirname, resolve } from 'node:path';
|
|
4
|
+
import { fileURLToPath } from 'node:url';
|
|
5
|
+
|
|
6
|
+
import { abBenchmark } from '@claude-flow/guidance/analyzer';
|
|
7
|
+
import { createSyntheticContentAwareExecutor } from '../src/guidance/content-aware-executor.js';
|
|
8
|
+
|
|
9
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
10
|
+
const rootDir = resolve(__dirname, '..');
|
|
11
|
+
const guidanceDir = resolve(rootDir, '.claude-flow', 'guidance');
|
|
12
|
+
const reportPath = resolve(guidanceDir, 'ab-benchmark-report.json');
|
|
13
|
+
|
|
14
|
+
async function main() {
|
|
15
|
+
const claudePath = resolve(rootDir, 'CLAUDE.md');
|
|
16
|
+
const content = readFileSync(claudePath, 'utf-8');
|
|
17
|
+
const proofKey = process.env.GUIDANCE_PROOF_KEY;
|
|
18
|
+
const executor = createSyntheticContentAwareExecutor();
|
|
19
|
+
|
|
20
|
+
const report = await abBenchmark(content, {
|
|
21
|
+
proofKey,
|
|
22
|
+
executor,
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
mkdirSync(guidanceDir, { recursive: true });
|
|
26
|
+
writeFileSync(reportPath, JSON.stringify(report, null, 2));
|
|
27
|
+
|
|
28
|
+
console.log('A/B benchmark complete.');
|
|
29
|
+
console.log(`Composite delta: ${report.compositeDelta}`);
|
|
30
|
+
console.log(`Category shift: ${report.categoryShift}`);
|
|
31
|
+
console.log(`Baseline score: ${report.configA.metrics.compositeScore}`);
|
|
32
|
+
console.log(`Guided score: ${report.configB.metrics.compositeScore}`);
|
|
33
|
+
console.log(`Report saved: ${reportPath}`);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
main().catch((error) => {
|
|
37
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
38
|
+
console.error(message);
|
|
39
|
+
process.exit(1);
|
|
40
|
+
});
|