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,337 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { existsSync } from 'node:fs';
|
|
3
|
+
import { spawnSync } from 'node:child_process';
|
|
4
|
+
import { dirname, resolve } from 'node:path';
|
|
5
|
+
import { fileURLToPath } from 'node:url';
|
|
6
|
+
|
|
7
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
8
|
+
const rootDir = resolve(__dirname, '..');
|
|
9
|
+
|
|
10
|
+
const SUPPORTED_EVENTS = new Set([
|
|
11
|
+
'pre-command',
|
|
12
|
+
'pre-edit',
|
|
13
|
+
'pre-task',
|
|
14
|
+
'post-edit',
|
|
15
|
+
'post-task',
|
|
16
|
+
'session-start',
|
|
17
|
+
'session-end',
|
|
18
|
+
'status',
|
|
19
|
+
]);
|
|
20
|
+
|
|
21
|
+
const HOOK_HANDLER_MAP = {
|
|
22
|
+
'pre-command': 'pre-bash',
|
|
23
|
+
'pre-edit': 'pre-edit',
|
|
24
|
+
'pre-task': 'pre-task',
|
|
25
|
+
'post-edit': 'post-edit',
|
|
26
|
+
'post-task': 'post-task',
|
|
27
|
+
'session-start': 'session-restore',
|
|
28
|
+
'session-end': 'session-end',
|
|
29
|
+
status: 'status',
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
function usage() {
|
|
33
|
+
console.log(`Usage:
|
|
34
|
+
node scripts/guidance-codex-bridge.js <event> [options]
|
|
35
|
+
|
|
36
|
+
Events:
|
|
37
|
+
pre-command --command "<bash command>"
|
|
38
|
+
pre-edit --file <path> [--content "..."] [--operation modify] [--diff-lines 10]
|
|
39
|
+
pre-task --description "<task description>"
|
|
40
|
+
post-edit --file <path>
|
|
41
|
+
post-task --task-id <id> [--description "..."] [--status completed]
|
|
42
|
+
session-start [--session-id <id>]
|
|
43
|
+
session-end [--session-id <id>]
|
|
44
|
+
status
|
|
45
|
+
|
|
46
|
+
Common options:
|
|
47
|
+
--task-id <id>
|
|
48
|
+
--session-id <id>
|
|
49
|
+
--agent-id <id>
|
|
50
|
+
--payload-json '<json object>'
|
|
51
|
+
--skip-cf-hooks
|
|
52
|
+
|
|
53
|
+
Examples:
|
|
54
|
+
node scripts/guidance-codex-bridge.js pre-task --description "Implement auth middleware"
|
|
55
|
+
node scripts/guidance-codex-bridge.js pre-command --command "git push --force origin main"
|
|
56
|
+
node scripts/guidance-codex-bridge.js post-task --task-id task-123 --status completed`);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function parseArgs(argv) {
|
|
60
|
+
const positional = [];
|
|
61
|
+
const options = {};
|
|
62
|
+
const flags = new Set();
|
|
63
|
+
|
|
64
|
+
for (let i = 0; i < argv.length; i += 1) {
|
|
65
|
+
const current = argv[i];
|
|
66
|
+
if (!current.startsWith('--')) {
|
|
67
|
+
positional.push(current);
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const key = current.slice(2);
|
|
72
|
+
const next = argv[i + 1];
|
|
73
|
+
if (!next || next.startsWith('--')) {
|
|
74
|
+
flags.add(key);
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
options[key] = next;
|
|
79
|
+
i += 1;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return { positional, options, flags };
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function safeString(value, fallback = '') {
|
|
86
|
+
if (value == null) return fallback;
|
|
87
|
+
return String(value);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function toInteger(value, fallback = 0) {
|
|
91
|
+
const parsed = Number(value);
|
|
92
|
+
if (!Number.isFinite(parsed) || parsed < 0) return fallback;
|
|
93
|
+
return Math.round(parsed);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function parseJson(value, fallback = {}) {
|
|
97
|
+
if (!value) return fallback;
|
|
98
|
+
try {
|
|
99
|
+
const parsed = JSON.parse(value);
|
|
100
|
+
return parsed && typeof parsed === 'object' ? parsed : fallback;
|
|
101
|
+
} catch {
|
|
102
|
+
return fallback;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function parseArray(value) {
|
|
107
|
+
if (!value) return [];
|
|
108
|
+
const parsed = parseJson(value, []);
|
|
109
|
+
return Array.isArray(parsed) ? parsed : [];
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function stableId(prefix) {
|
|
113
|
+
return `${prefix}-${Date.now()}`;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function baseIds(eventName, options, payload) {
|
|
117
|
+
const eventTaskPrefix =
|
|
118
|
+
eventName === 'pre-command' || eventName === 'pre-edit' ? eventName : 'task';
|
|
119
|
+
|
|
120
|
+
const taskId = safeString(
|
|
121
|
+
options['task-id'] || payload.taskId || payload.task_id,
|
|
122
|
+
stableId(eventTaskPrefix)
|
|
123
|
+
);
|
|
124
|
+
const sessionId = safeString(
|
|
125
|
+
options['session-id'] || payload.sessionId || payload.session_id,
|
|
126
|
+
safeString(process.env.CLAUDE_SESSION_ID, `session-${Date.now()}`)
|
|
127
|
+
);
|
|
128
|
+
const agentId = safeString(
|
|
129
|
+
options['agent-id'] || payload.agentId || payload.agent_id,
|
|
130
|
+
'codex-main'
|
|
131
|
+
);
|
|
132
|
+
return { taskId, sessionId, agentId };
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function hookHandlerInput(eventName, options, payload, ids, fallbackText) {
|
|
136
|
+
const toolPayload = payload.tool_input && typeof payload.tool_input === 'object'
|
|
137
|
+
? { ...payload.tool_input }
|
|
138
|
+
: {};
|
|
139
|
+
|
|
140
|
+
if (eventName === 'pre-command') {
|
|
141
|
+
const command = safeString(options.command, fallbackText);
|
|
142
|
+
toolPayload.command = command;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
if (eventName === 'pre-edit' || eventName === 'post-edit') {
|
|
146
|
+
toolPayload.file_path = safeString(options.file, safeString(payload.filePath, ''));
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
if (eventName === 'pre-edit') {
|
|
150
|
+
toolPayload.content = safeString(options.content, safeString(payload.content, ''));
|
|
151
|
+
toolPayload.operation = safeString(options.operation, safeString(payload.operation, 'modify'));
|
|
152
|
+
toolPayload.diff_lines = toInteger(
|
|
153
|
+
options['diff-lines'] || payload.diffLines || payload.diff_lines,
|
|
154
|
+
toolPayload.content ? toolPayload.content.split('\n').length : 0
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
if (eventName === 'pre-task') {
|
|
159
|
+
toolPayload.description = safeString(options.description, fallbackText);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
if (eventName === 'post-task') {
|
|
163
|
+
toolPayload.status = safeString(options.status, safeString(payload.status, 'completed'));
|
|
164
|
+
toolPayload.description = safeString(options.description, fallbackText);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
return {
|
|
168
|
+
task_id: ids.taskId,
|
|
169
|
+
session_id: ids.sessionId,
|
|
170
|
+
agent_id: ids.agentId,
|
|
171
|
+
tool_input: toolPayload,
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
function runHookHandler(mappedCommand, inputJson) {
|
|
176
|
+
const handlerPath = resolve(rootDir, '.claude/helpers/hook-handler.cjs');
|
|
177
|
+
if (!existsSync(handlerPath)) {
|
|
178
|
+
return {
|
|
179
|
+
ok: false,
|
|
180
|
+
exitCode: 2,
|
|
181
|
+
stdout: '',
|
|
182
|
+
stderr: `Missing hook handler: ${handlerPath}`,
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
const result = spawnSync(process.execPath, [handlerPath, mappedCommand], {
|
|
187
|
+
cwd: rootDir,
|
|
188
|
+
env: process.env,
|
|
189
|
+
input: inputJson,
|
|
190
|
+
encoding: 'utf-8',
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
return {
|
|
194
|
+
ok: result.status === 0,
|
|
195
|
+
exitCode: result.status ?? 1,
|
|
196
|
+
stdout: safeString(result.stdout, '').trim(),
|
|
197
|
+
stderr: safeString(result.stderr, '').trim(),
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
function claudeFlowHookArgs(eventName, options, payload, ids) {
|
|
202
|
+
const description = safeString(options.description, safeString(payload.taskDescription, ''));
|
|
203
|
+
switch (eventName) {
|
|
204
|
+
case 'pre-command': {
|
|
205
|
+
const command = safeString(options.command, '');
|
|
206
|
+
if (!command) return null;
|
|
207
|
+
return ['hooks', 'pre-command', '--task-id', ids.taskId, '--command', command];
|
|
208
|
+
}
|
|
209
|
+
case 'pre-edit': {
|
|
210
|
+
const filePath = safeString(options.file, safeString(payload.filePath, ''));
|
|
211
|
+
if (!filePath) return null;
|
|
212
|
+
const operation = safeString(options.operation, safeString(payload.operation, 'modify'));
|
|
213
|
+
return [
|
|
214
|
+
'hooks',
|
|
215
|
+
'pre-edit',
|
|
216
|
+
'--task-id',
|
|
217
|
+
ids.taskId,
|
|
218
|
+
'--file',
|
|
219
|
+
filePath,
|
|
220
|
+
'--operation',
|
|
221
|
+
operation,
|
|
222
|
+
];
|
|
223
|
+
}
|
|
224
|
+
case 'pre-task':
|
|
225
|
+
if (!description) return null;
|
|
226
|
+
return ['hooks', 'pre-task', '--task-id', ids.taskId, '--description', description];
|
|
227
|
+
case 'post-edit': {
|
|
228
|
+
const filePath = safeString(options.file, safeString(payload.filePath, ''));
|
|
229
|
+
if (!filePath) return null;
|
|
230
|
+
return [
|
|
231
|
+
'hooks',
|
|
232
|
+
'post-edit',
|
|
233
|
+
'--task-id',
|
|
234
|
+
ids.taskId,
|
|
235
|
+
'--file',
|
|
236
|
+
filePath,
|
|
237
|
+
'--success',
|
|
238
|
+
'true',
|
|
239
|
+
];
|
|
240
|
+
}
|
|
241
|
+
case 'post-task': {
|
|
242
|
+
const taskId = safeString(options['task-id'], ids.taskId);
|
|
243
|
+
const status = safeString(options.status, safeString(payload.status, 'completed'));
|
|
244
|
+
const success = status !== 'failed' ? 'true' : 'false';
|
|
245
|
+
return ['hooks', 'post-task', '--task-id', taskId, '--success', success];
|
|
246
|
+
}
|
|
247
|
+
case 'session-start':
|
|
248
|
+
return ['hooks', 'session-start', '--task-id', ids.taskId, '--session-id', ids.sessionId];
|
|
249
|
+
case 'session-end':
|
|
250
|
+
return ['hooks', 'session-end', '--task-id', ids.taskId, '--export-metrics', 'true'];
|
|
251
|
+
default:
|
|
252
|
+
return null;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
function runClaudeFlowHook(args) {
|
|
257
|
+
if (!args) return { skipped: true, reason: 'no-compatible-args' };
|
|
258
|
+
|
|
259
|
+
const result = spawnSync('npx', ['@claude-flow/cli@latest', ...args], {
|
|
260
|
+
cwd: rootDir,
|
|
261
|
+
env: process.env,
|
|
262
|
+
encoding: 'utf-8',
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
return {
|
|
266
|
+
skipped: false,
|
|
267
|
+
ok: result.status === 0,
|
|
268
|
+
exitCode: result.status ?? 1,
|
|
269
|
+
stdout: safeString(result.stdout, '').trim(),
|
|
270
|
+
stderr: safeString(result.stderr, '').trim(),
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
function buildSummary(eventName, ids, handlerResult, cfHookResult, metadata) {
|
|
275
|
+
return {
|
|
276
|
+
event: eventName,
|
|
277
|
+
ids,
|
|
278
|
+
handler: handlerResult,
|
|
279
|
+
claudeFlowHook: cfHookResult,
|
|
280
|
+
metadata,
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
async function main() {
|
|
285
|
+
const { positional, options, flags } = parseArgs(process.argv.slice(2));
|
|
286
|
+
const eventName = safeString(positional[0], '');
|
|
287
|
+
|
|
288
|
+
if (!eventName || eventName === 'help' || eventName === '--help' || eventName === '-h') {
|
|
289
|
+
usage();
|
|
290
|
+
process.exit(eventName ? 0 : 1);
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
if (!SUPPORTED_EVENTS.has(eventName)) {
|
|
294
|
+
console.error(`Unsupported event: ${eventName}`);
|
|
295
|
+
usage();
|
|
296
|
+
process.exit(1);
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
const fallbackText = positional.slice(1).join(' ').trim();
|
|
300
|
+
const payload = parseJson(options['payload-json'], {});
|
|
301
|
+
const ids = baseIds(eventName, options, payload);
|
|
302
|
+
const mappedCommand = HOOK_HANDLER_MAP[eventName];
|
|
303
|
+
|
|
304
|
+
const input = hookHandlerInput(eventName, options, payload, ids, fallbackText);
|
|
305
|
+
const handlerResult = runHookHandler(mappedCommand, JSON.stringify(input));
|
|
306
|
+
|
|
307
|
+
const shouldRunCfHooks =
|
|
308
|
+
eventName !== 'status' &&
|
|
309
|
+
!flags.has('skip-cf-hooks') &&
|
|
310
|
+
process.env.GUIDANCE_CODEX_SKIP_CF_HOOKS !== '1';
|
|
311
|
+
|
|
312
|
+
let cfHookResult = { skipped: true, reason: 'disabled' };
|
|
313
|
+
if (shouldRunCfHooks && handlerResult.ok) {
|
|
314
|
+
const args = claudeFlowHookArgs(eventName, options, payload, ids);
|
|
315
|
+
cfHookResult = runClaudeFlowHook(args);
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
const metadata = {
|
|
319
|
+
filePath: safeString(options.file, safeString(payload.filePath, '')),
|
|
320
|
+
status: safeString(options.status, safeString(payload.status, '')),
|
|
321
|
+
toolsUsed: parseArray(options['tools-used']),
|
|
322
|
+
filesTouched: parseArray(options['files-touched']),
|
|
323
|
+
};
|
|
324
|
+
|
|
325
|
+
const summary = buildSummary(eventName, ids, handlerResult, cfHookResult, metadata);
|
|
326
|
+
console.log(JSON.stringify(summary, null, 2));
|
|
327
|
+
|
|
328
|
+
if (!handlerResult.ok) {
|
|
329
|
+
process.exit(handlerResult.exitCode || 1);
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
main().catch((error) => {
|
|
334
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
335
|
+
console.error(message);
|
|
336
|
+
process.exit(1);
|
|
337
|
+
});
|