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,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lightweight in-process content-aware executor for analyzer benchmarks.
|
|
3
|
+
*
|
|
4
|
+
* This avoids external `claude -p` process execution while still producing
|
|
5
|
+
* behavior differences between "no guidance" and "with guidance" phases.
|
|
6
|
+
*/
|
|
7
|
+
export class SyntheticContentAwareExecutor {
|
|
8
|
+
constructor() {
|
|
9
|
+
this.context = '';
|
|
10
|
+
this.guidanceStrength = 0;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
setContext(claudeMdContent) {
|
|
14
|
+
this.context = claudeMdContent ?? '';
|
|
15
|
+
const enforcementTerms = this.context.match(/\b(NEVER|ALWAYS|MUST)\b/gi) ?? [];
|
|
16
|
+
this.guidanceStrength = enforcementTerms.length;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
async execute(prompt) {
|
|
20
|
+
const guided = this.guidanceStrength > 0;
|
|
21
|
+
const lower = String(prompt ?? '').toLowerCase();
|
|
22
|
+
|
|
23
|
+
if (!guided) {
|
|
24
|
+
// Baseline mode intentionally weaker.
|
|
25
|
+
return {
|
|
26
|
+
stdout: `Working note: ${lower.slice(0, 120)}.`,
|
|
27
|
+
stderr: '',
|
|
28
|
+
exitCode: 0,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const snippets = [];
|
|
33
|
+
snippets.push(`Task: ${prompt}`);
|
|
34
|
+
snippets.push('Implement safely with explicit validation and verification.');
|
|
35
|
+
snippets.push('Include tests (describe/it/expect) and run test coverage checks.');
|
|
36
|
+
snippets.push('Use batch + parallel processing (Promise.all) where beneficial.');
|
|
37
|
+
snippets.push('Use sanitize/escape/regex input filtering for security-sensitive inputs.');
|
|
38
|
+
snippets.push('Verify signatures with HMAC-SHA256 and reject invalid envelopes.');
|
|
39
|
+
snippets.push('Use LRU cache with invalidation and hit-rate metrics.');
|
|
40
|
+
snippets.push('Apply rate limiting with throttle/window/bucket controls.');
|
|
41
|
+
snippets.push('For deployment, use multi-stage Docker build/runtime separation.');
|
|
42
|
+
snippets.push('For publish flows, manage dist-tag values (alpha, latest, v3alpha).');
|
|
43
|
+
snippets.push('For output export, include CSV formatting with proper escaping.');
|
|
44
|
+
snippets.push('Avoid destructive commands, secret leakage, and unsafe typing.');
|
|
45
|
+
|
|
46
|
+
// Prompt-sensitive additions improve task-class adherence while remaining safe.
|
|
47
|
+
if (lower.includes('security') || lower.includes('sanitize') || lower.includes('secret')) {
|
|
48
|
+
snippets.push('Security controls: scan patterns for password/api-key/credential leaks.');
|
|
49
|
+
}
|
|
50
|
+
if (lower.includes('refactor')) {
|
|
51
|
+
snippets.push('Refactor approach: shared helper/base abstractions with test preservation.');
|
|
52
|
+
}
|
|
53
|
+
if (lower.includes('performance') || lower.includes('optimiz')) {
|
|
54
|
+
snippets.push('Performance approach: optimize verification path with concurrent checks.');
|
|
55
|
+
}
|
|
56
|
+
if (lower.includes('test')) {
|
|
57
|
+
snippets.push('Testing approach: add integration coverage across compile/retrieve/gate/ledger flow.');
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return {
|
|
61
|
+
stdout: snippets.join('\n'),
|
|
62
|
+
stderr: '',
|
|
63
|
+
exitCode: 0,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export function createSyntheticContentAwareExecutor() {
|
|
69
|
+
return new SyntheticContentAwareExecutor();
|
|
70
|
+
}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
2
|
+
import { resolve } from 'node:path';
|
|
3
|
+
|
|
4
|
+
import { createCompiler } from '@claude-flow/guidance/compiler';
|
|
5
|
+
import { createRetriever } from '@claude-flow/guidance/retriever';
|
|
6
|
+
import { createGates } from '@claude-flow/guidance/gates';
|
|
7
|
+
import { createLedger } from '@claude-flow/guidance/ledger';
|
|
8
|
+
import { createGuidanceHooks } from '@claude-flow/guidance/hooks';
|
|
9
|
+
import { HookEvent, HookExecutor, HookRegistry } from '@claude-flow/hooks';
|
|
10
|
+
|
|
11
|
+
const DEFAULT_OPTIONS = {
|
|
12
|
+
rootDir: process.cwd(),
|
|
13
|
+
rootGuidancePath: 'CLAUDE.md',
|
|
14
|
+
localGuidancePath: 'CLAUDE.local.md',
|
|
15
|
+
gateConfig: {},
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
function resolvePath(rootDir, filePath) {
|
|
19
|
+
if (!filePath) {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
return resolve(rootDir, filePath);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function readOptionalFile(filePath) {
|
|
26
|
+
if (!filePath || !existsSync(filePath)) {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
return readFileSync(filePath, 'utf-8');
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export class GuidancePhase1Runtime {
|
|
33
|
+
constructor(options = {}) {
|
|
34
|
+
this.options = { ...DEFAULT_OPTIONS, ...options };
|
|
35
|
+
this.compiler = createCompiler();
|
|
36
|
+
this.retriever = createRetriever();
|
|
37
|
+
this.gates = createGates(this.options.gateConfig);
|
|
38
|
+
this.ledger = createLedger();
|
|
39
|
+
this.registry = new HookRegistry();
|
|
40
|
+
this.executor = new HookExecutor(this.registry);
|
|
41
|
+
|
|
42
|
+
this.bundle = null;
|
|
43
|
+
this.hookIds = [];
|
|
44
|
+
this.initialized = false;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
async initialize() {
|
|
48
|
+
if (this.initialized) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const rootFile = resolvePath(this.options.rootDir, this.options.rootGuidancePath);
|
|
53
|
+
const localFile = resolvePath(this.options.rootDir, this.options.localGuidancePath);
|
|
54
|
+
const rootContent = readOptionalFile(rootFile);
|
|
55
|
+
const localContent = readOptionalFile(localFile);
|
|
56
|
+
|
|
57
|
+
if (!rootContent) {
|
|
58
|
+
throw new Error(`Missing required guidance file: ${rootFile}`);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
this.bundle = this.compiler.compile(rootContent, localContent ?? undefined);
|
|
62
|
+
await this.retriever.loadBundle(this.bundle);
|
|
63
|
+
|
|
64
|
+
const rules = [
|
|
65
|
+
...this.bundle.constitution.rules,
|
|
66
|
+
...this.bundle.shards.map((entry) => entry.rule),
|
|
67
|
+
];
|
|
68
|
+
this.gates.setActiveRules(rules);
|
|
69
|
+
|
|
70
|
+
const registration = createGuidanceHooks(
|
|
71
|
+
this.gates,
|
|
72
|
+
this.retriever,
|
|
73
|
+
this.ledger,
|
|
74
|
+
this.registry
|
|
75
|
+
);
|
|
76
|
+
this.hookIds = registration.hookIds;
|
|
77
|
+
this.initialized = true;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
ensureInitialized() {
|
|
81
|
+
if (!this.initialized) {
|
|
82
|
+
throw new Error('GuidancePhase1Runtime is not initialized. Call initialize() first.');
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
async preTask({ taskId, taskDescription }) {
|
|
87
|
+
this.ensureInitialized();
|
|
88
|
+
return this.executor.execute(HookEvent.PreTask, {
|
|
89
|
+
task: { id: taskId, description: taskDescription },
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
async postTask({ taskId, status = 'completed', toolsUsed = [], filesTouched = [] }) {
|
|
94
|
+
this.ensureInitialized();
|
|
95
|
+
return this.executor.execute(HookEvent.PostTask, {
|
|
96
|
+
task: { id: taskId, status },
|
|
97
|
+
metadata: { toolsUsed, filesTouched },
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
async preCommand(command) {
|
|
102
|
+
this.ensureInitialized();
|
|
103
|
+
return this.executor.execute(HookEvent.PreCommand, {
|
|
104
|
+
command: { raw: command, workingDirectory: this.options.rootDir },
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
async preToolUse(toolName, parameters = {}) {
|
|
109
|
+
this.ensureInitialized();
|
|
110
|
+
return this.executor.execute(HookEvent.PreToolUse, {
|
|
111
|
+
tool: { name: toolName, parameters },
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
async preEdit({ filePath, operation = 'modify', content = '', diffLines = 0 }) {
|
|
116
|
+
this.ensureInitialized();
|
|
117
|
+
return this.executor.execute(HookEvent.PreEdit, {
|
|
118
|
+
file: { path: filePath, operation },
|
|
119
|
+
metadata: { content, diffLines },
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
extractPolicyText(hookExecutionResult) {
|
|
124
|
+
return hookExecutionResult?.finalContext?.metadata?.policyText ?? null;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
isBlocked(hookExecutionResult) {
|
|
128
|
+
return !hookExecutionResult?.success || Boolean(hookExecutionResult?.aborted);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
getBundle() {
|
|
132
|
+
return this.bundle;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
getStatus() {
|
|
136
|
+
return {
|
|
137
|
+
initialized: this.initialized,
|
|
138
|
+
hookCount: this.hookIds.length,
|
|
139
|
+
registryStats: this.registry.getStats(),
|
|
140
|
+
shardCount: this.bundle?.shards.length ?? 0,
|
|
141
|
+
constitutionRuleCount: this.bundle?.constitution.rules.length ?? 0,
|
|
142
|
+
manifestRuleCount: this.bundle?.manifest.totalRules ?? 0,
|
|
143
|
+
activeGateCount: this.gates.getActiveGateCount(),
|
|
144
|
+
ledgerEventCount: this.ledger.eventCount,
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export function createGuidancePhase1Runtime(options = {}) {
|
|
150
|
+
return new GuidancePhase1Runtime(options);
|
|
151
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
export const GUIDANCE_ENV_DEFAULTS = {
|
|
2
|
+
CLAUDE_FLOW_HOOKS_ENABLED: 'true',
|
|
3
|
+
GUIDANCE_EVENT_WIRING_ENABLED: '1',
|
|
4
|
+
GUIDANCE_EVENT_SYNC_TIMEOUT_MS: '8000',
|
|
5
|
+
GUIDANCE_EVENT_FAIL_CLOSED: '0',
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export const GUIDANCE_HOOKS_DEFAULTS = {
|
|
9
|
+
PreToolUse: [
|
|
10
|
+
{
|
|
11
|
+
matcher: 'Write|Edit|MultiEdit',
|
|
12
|
+
hooks: [
|
|
13
|
+
{
|
|
14
|
+
type: 'command',
|
|
15
|
+
command: 'node "$CLAUDE_PROJECT_DIR"/.claude/helpers/hook-handler.cjs pre-edit',
|
|
16
|
+
},
|
|
17
|
+
],
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
matcher: 'Bash',
|
|
21
|
+
hooks: [
|
|
22
|
+
{
|
|
23
|
+
type: 'command',
|
|
24
|
+
command: 'node "$CLAUDE_PROJECT_DIR"/.claude/helpers/hook-handler.cjs pre-bash',
|
|
25
|
+
},
|
|
26
|
+
],
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
matcher: 'Task',
|
|
30
|
+
hooks: [
|
|
31
|
+
{
|
|
32
|
+
type: 'command',
|
|
33
|
+
command: 'node "$CLAUDE_PROJECT_DIR"/.claude/helpers/hook-handler.cjs pre-task',
|
|
34
|
+
},
|
|
35
|
+
],
|
|
36
|
+
},
|
|
37
|
+
],
|
|
38
|
+
PostToolUse: [
|
|
39
|
+
{
|
|
40
|
+
matcher: 'Write|Edit|MultiEdit',
|
|
41
|
+
hooks: [
|
|
42
|
+
{
|
|
43
|
+
type: 'command',
|
|
44
|
+
command: 'node "$CLAUDE_PROJECT_DIR"/.claude/helpers/hook-handler.cjs post-edit',
|
|
45
|
+
},
|
|
46
|
+
],
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
matcher: 'Task',
|
|
50
|
+
hooks: [
|
|
51
|
+
{
|
|
52
|
+
type: 'command',
|
|
53
|
+
command: 'node "$CLAUDE_PROJECT_DIR"/.claude/helpers/hook-handler.cjs post-task',
|
|
54
|
+
},
|
|
55
|
+
],
|
|
56
|
+
},
|
|
57
|
+
],
|
|
58
|
+
SessionStart: [
|
|
59
|
+
{
|
|
60
|
+
matcher: '',
|
|
61
|
+
hooks: [
|
|
62
|
+
{
|
|
63
|
+
type: 'command',
|
|
64
|
+
command: 'node "$CLAUDE_PROJECT_DIR"/.claude/helpers/hook-handler.cjs session-restore',
|
|
65
|
+
},
|
|
66
|
+
],
|
|
67
|
+
},
|
|
68
|
+
],
|
|
69
|
+
SessionEnd: [
|
|
70
|
+
{
|
|
71
|
+
matcher: '',
|
|
72
|
+
hooks: [
|
|
73
|
+
{
|
|
74
|
+
type: 'command',
|
|
75
|
+
command: 'node "$CLAUDE_PROJECT_DIR"/.claude/helpers/hook-handler.cjs session-end',
|
|
76
|
+
},
|
|
77
|
+
],
|
|
78
|
+
},
|
|
79
|
+
],
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
export const GUIDANCE_PACKAGE_SCRIPTS = {
|
|
83
|
+
'guidance:analyze': 'node scripts/analyze-guidance.js',
|
|
84
|
+
'guidance:optimize': 'node scripts/guidance-autopilot.js --once --apply --source manual',
|
|
85
|
+
'guidance:autopilot:once': 'node scripts/guidance-autopilot.js --once --source manual',
|
|
86
|
+
'guidance:autopilot:daemon': 'node scripts/guidance-autopilot.js --daemon --apply --source daemon',
|
|
87
|
+
'guidance:ab-benchmark': 'node scripts/guidance-ab-benchmark.js',
|
|
88
|
+
'guidance:scaffold': 'node scripts/scaffold-guidance.js',
|
|
89
|
+
'guidance:all': 'node scripts/guidance-integrations.js all',
|
|
90
|
+
'guidance:status': 'node scripts/guidance-integrations.js status',
|
|
91
|
+
'guidance:hooks': 'node scripts/guidance-integrations.js hooks',
|
|
92
|
+
'guidance:trust': 'node scripts/guidance-integrations.js trust',
|
|
93
|
+
'guidance:adversarial': 'node scripts/guidance-integrations.js adversarial',
|
|
94
|
+
'guidance:proof': 'node scripts/guidance-integrations.js proof',
|
|
95
|
+
'guidance:conformance': 'node scripts/guidance-integrations.js conformance',
|
|
96
|
+
'guidance:evolution': 'node scripts/guidance-integrations.js evolution',
|
|
97
|
+
'guidance:runtime': 'node scripts/guidance-runtime.js demo',
|
|
98
|
+
'guidance:codex:status': 'node scripts/guidance-codex-bridge.js status',
|
|
99
|
+
'guidance:codex:pre-command': 'node scripts/guidance-codex-bridge.js pre-command',
|
|
100
|
+
'guidance:codex:pre-edit': 'node scripts/guidance-codex-bridge.js pre-edit',
|
|
101
|
+
'guidance:codex:pre-task': 'node scripts/guidance-codex-bridge.js pre-task',
|
|
102
|
+
'guidance:codex:post-edit': 'node scripts/guidance-codex-bridge.js post-edit',
|
|
103
|
+
'guidance:codex:post-task': 'node scripts/guidance-codex-bridge.js post-task',
|
|
104
|
+
'guidance:codex:session-start': 'node scripts/guidance-codex-bridge.js session-start',
|
|
105
|
+
'guidance:codex:session-end': 'node scripts/guidance-codex-bridge.js session-end',
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
export const GUIDANCE_PACKAGE_DEPS = {
|
|
109
|
+
'@claude-flow/guidance': '^3.0.0-alpha.1',
|
|
110
|
+
'@claude-flow/hooks': '^3.0.0-alpha.7',
|
|
111
|
+
};
|