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,587 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
3
|
+
import { dirname, resolve } from 'node:path';
|
|
4
|
+
import { fileURLToPath } from 'node:url';
|
|
5
|
+
|
|
6
|
+
import { createGuidanceAdvancedRuntime } from '../src/guidance/advanced-runtime.js';
|
|
7
|
+
|
|
8
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
9
|
+
const rootDir = resolve(__dirname, '..');
|
|
10
|
+
|
|
11
|
+
function usage() {
|
|
12
|
+
console.log(`Usage:
|
|
13
|
+
node scripts/guidance-integrations.js status
|
|
14
|
+
node scripts/guidance-integrations.js hooks [taskDescription]
|
|
15
|
+
node scripts/guidance-integrations.js trust
|
|
16
|
+
node scripts/guidance-integrations.js adversarial
|
|
17
|
+
node scripts/guidance-integrations.js proof
|
|
18
|
+
node scripts/guidance-integrations.js conformance
|
|
19
|
+
node scripts/guidance-integrations.js evolution
|
|
20
|
+
node scripts/guidance-integrations.js all
|
|
21
|
+
node scripts/guidance-integrations.js event <pre-command|pre-edit|pre-task|post-task|post-edit|session-end> [jsonPayload]`);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function printJson(value) {
|
|
25
|
+
console.log(JSON.stringify(value, null, 2));
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function readJson(path, fallback = {}) {
|
|
29
|
+
if (!existsSync(path)) return fallback;
|
|
30
|
+
try {
|
|
31
|
+
return JSON.parse(readFileSync(path, 'utf-8'));
|
|
32
|
+
} catch {
|
|
33
|
+
return fallback;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function writeJson(path, value) {
|
|
38
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
39
|
+
writeFileSync(path, JSON.stringify(value, null, 2));
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function parsePayload(input) {
|
|
43
|
+
if (!input) return {};
|
|
44
|
+
try {
|
|
45
|
+
const parsed = JSON.parse(input);
|
|
46
|
+
return typeof parsed === 'object' && parsed != null ? parsed : {};
|
|
47
|
+
} catch {
|
|
48
|
+
return {};
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function safeArray(input) {
|
|
53
|
+
return Array.isArray(input) ? input : [];
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function safeString(input, fallback = '') {
|
|
57
|
+
if (input == null) return fallback;
|
|
58
|
+
return String(input);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function sanitizeDiffLines(input) {
|
|
62
|
+
const value = Number(input);
|
|
63
|
+
if (!Number.isFinite(value) || value < 0) return 0;
|
|
64
|
+
return Math.round(value);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function taskIdFromPayload(prefix, payload) {
|
|
68
|
+
const fromPayload = safeString(payload.taskId, '').trim();
|
|
69
|
+
if (fromPayload) return fromPayload;
|
|
70
|
+
return `${prefix}-${Date.now()}`;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function outcomeFromHookResult(result) {
|
|
74
|
+
if (!result) return 'warn';
|
|
75
|
+
if (!result.success || result.aborted) return 'deny';
|
|
76
|
+
if ((result.warnings?.length ?? 0) > 0) return 'warn';
|
|
77
|
+
return 'allow';
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function severityFromThreat(threat) {
|
|
81
|
+
if ((threat?.severity ?? 0) >= 0.8) return 'high';
|
|
82
|
+
if ((threat?.severity ?? 0) >= 0.5) return 'medium';
|
|
83
|
+
return 'low';
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function mapHookWarningsToViolations(result, baseRuleId) {
|
|
87
|
+
const warnings = safeArray(result?.warnings);
|
|
88
|
+
return warnings.map((warning, index) => ({
|
|
89
|
+
ruleId: `${baseRuleId}-warning-${index + 1}`,
|
|
90
|
+
description: safeString(warning, 'Guidance warning'),
|
|
91
|
+
severity: 'medium',
|
|
92
|
+
autoCorrected: false,
|
|
93
|
+
}));
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
async function runEvent(runtime, eventName, payload) {
|
|
97
|
+
await runtime.initialize();
|
|
98
|
+
const agentId = safeString(payload.agentId, 'claude-main');
|
|
99
|
+
const sessionId = safeString(payload.sessionId, `session-${Date.now()}`);
|
|
100
|
+
const pendingRunsPath = resolve(runtime.dataDir, 'pending-runs.json');
|
|
101
|
+
const pendingRuns = readJson(pendingRunsPath, {});
|
|
102
|
+
|
|
103
|
+
switch (eventName) {
|
|
104
|
+
case 'pre-command': {
|
|
105
|
+
const command = safeString(payload.command, '');
|
|
106
|
+
const taskId = taskIdFromPayload('pre-command', payload);
|
|
107
|
+
|
|
108
|
+
if (!command.trim()) {
|
|
109
|
+
return {
|
|
110
|
+
event: 'pre-command',
|
|
111
|
+
success: true,
|
|
112
|
+
blocked: false,
|
|
113
|
+
skipped: true,
|
|
114
|
+
reason: 'empty-command',
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const startedAt = Date.now();
|
|
119
|
+
const gateResult = await runtime.phase1.preCommand(command);
|
|
120
|
+
const inputThreats = runtime.threatDetector.analyzeInput(command, {
|
|
121
|
+
agentId,
|
|
122
|
+
toolName: 'bash',
|
|
123
|
+
});
|
|
124
|
+
const severeThreats = inputThreats.filter((threat) => threat.severity >= 0.85);
|
|
125
|
+
|
|
126
|
+
const gateBlocked = !gateResult.success || Boolean(gateResult.aborted);
|
|
127
|
+
const threatBlocked = severeThreats.length > 0;
|
|
128
|
+
const blocked = gateBlocked || threatBlocked;
|
|
129
|
+
const outcome = blocked ? 'deny' : outcomeFromHookResult(gateResult);
|
|
130
|
+
|
|
131
|
+
runtime.recordTrust(agentId, outcome, 'hook pre-command');
|
|
132
|
+
|
|
133
|
+
const violations = [
|
|
134
|
+
...mapHookWarningsToViolations(gateResult, 'pre-command'),
|
|
135
|
+
...inputThreats.map((threat) => ({
|
|
136
|
+
ruleId: `threat-${threat.category}`,
|
|
137
|
+
description: threat.description,
|
|
138
|
+
severity: severityFromThreat(threat),
|
|
139
|
+
autoCorrected: false,
|
|
140
|
+
})),
|
|
141
|
+
];
|
|
142
|
+
|
|
143
|
+
if (blocked) {
|
|
144
|
+
violations.push({
|
|
145
|
+
ruleId: 'pre-command-blocked',
|
|
146
|
+
description: threatBlocked
|
|
147
|
+
? 'Command blocked by adversarial threat detection'
|
|
148
|
+
: 'Command blocked by guidance gates',
|
|
149
|
+
severity: 'high',
|
|
150
|
+
autoCorrected: true,
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
const proofEnvelope = runtime.appendProof({
|
|
155
|
+
taskId,
|
|
156
|
+
agentId,
|
|
157
|
+
toolsUsed: ['PreCommand', 'ThreatDetector'],
|
|
158
|
+
violations,
|
|
159
|
+
outcomeAccepted: !blocked,
|
|
160
|
+
durationMs: Date.now() - startedAt,
|
|
161
|
+
details: {
|
|
162
|
+
sessionId,
|
|
163
|
+
toolParams: {
|
|
164
|
+
PreCommand: { command },
|
|
165
|
+
},
|
|
166
|
+
toolResults: {
|
|
167
|
+
PreCommand: {
|
|
168
|
+
success: gateResult.success,
|
|
169
|
+
aborted: Boolean(gateResult.aborted),
|
|
170
|
+
},
|
|
171
|
+
ThreatDetector: {
|
|
172
|
+
inputThreatCount: inputThreats.length,
|
|
173
|
+
severeThreatCount: severeThreats.length,
|
|
174
|
+
},
|
|
175
|
+
},
|
|
176
|
+
},
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
const summary = {
|
|
180
|
+
event: 'pre-command',
|
|
181
|
+
taskId,
|
|
182
|
+
success: !blocked,
|
|
183
|
+
blocked,
|
|
184
|
+
blockedByGates: gateBlocked,
|
|
185
|
+
blockedByThreat: threatBlocked,
|
|
186
|
+
messages: safeArray(gateResult.messages),
|
|
187
|
+
warnings: safeArray(gateResult.warnings),
|
|
188
|
+
threatCount: inputThreats.length,
|
|
189
|
+
severeThreatCount: severeThreats.length,
|
|
190
|
+
trust: runtime.trustSystem.getSnapshot(agentId),
|
|
191
|
+
proofEnvelope: {
|
|
192
|
+
envelopeId: proofEnvelope.envelopeId,
|
|
193
|
+
contentHash: proofEnvelope.contentHash,
|
|
194
|
+
},
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
await runtime.persistState({ lastHookEvent: summary });
|
|
198
|
+
return summary;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
case 'pre-edit': {
|
|
202
|
+
const filePath = safeString(payload.filePath, '');
|
|
203
|
+
const content = safeString(payload.content, '');
|
|
204
|
+
const operation = safeString(payload.operation, 'modify');
|
|
205
|
+
const diffLines = sanitizeDiffLines(payload.diffLines);
|
|
206
|
+
const taskId = taskIdFromPayload('pre-edit', payload);
|
|
207
|
+
|
|
208
|
+
if (!filePath.trim()) {
|
|
209
|
+
return {
|
|
210
|
+
event: 'pre-edit',
|
|
211
|
+
success: true,
|
|
212
|
+
blocked: false,
|
|
213
|
+
skipped: true,
|
|
214
|
+
reason: 'missing-file-path',
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
const startedAt = Date.now();
|
|
219
|
+
const gateResult = await runtime.phase1.preEdit({
|
|
220
|
+
filePath,
|
|
221
|
+
operation,
|
|
222
|
+
content,
|
|
223
|
+
diffLines,
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
const blocked = !gateResult.success || Boolean(gateResult.aborted);
|
|
227
|
+
const outcome = blocked ? 'deny' : outcomeFromHookResult(gateResult);
|
|
228
|
+
runtime.recordTrust(agentId, outcome, 'hook pre-edit');
|
|
229
|
+
|
|
230
|
+
const violations = mapHookWarningsToViolations(gateResult, 'pre-edit');
|
|
231
|
+
if (blocked) {
|
|
232
|
+
violations.push({
|
|
233
|
+
ruleId: 'pre-edit-blocked',
|
|
234
|
+
description: 'Edit blocked by guidance gates',
|
|
235
|
+
severity: 'high',
|
|
236
|
+
autoCorrected: true,
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
const proofEnvelope = runtime.appendProof({
|
|
241
|
+
taskId,
|
|
242
|
+
agentId,
|
|
243
|
+
toolsUsed: ['PreEdit'],
|
|
244
|
+
violations,
|
|
245
|
+
outcomeAccepted: !blocked,
|
|
246
|
+
durationMs: Date.now() - startedAt,
|
|
247
|
+
details: {
|
|
248
|
+
sessionId,
|
|
249
|
+
filesTouched: [filePath],
|
|
250
|
+
toolParams: {
|
|
251
|
+
PreEdit: { filePath, operation, diffLines },
|
|
252
|
+
},
|
|
253
|
+
toolResults: {
|
|
254
|
+
PreEdit: {
|
|
255
|
+
success: gateResult.success,
|
|
256
|
+
aborted: Boolean(gateResult.aborted),
|
|
257
|
+
},
|
|
258
|
+
},
|
|
259
|
+
},
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
const summary = {
|
|
263
|
+
event: 'pre-edit',
|
|
264
|
+
taskId,
|
|
265
|
+
filePath,
|
|
266
|
+
success: !blocked,
|
|
267
|
+
blocked,
|
|
268
|
+
messages: safeArray(gateResult.messages),
|
|
269
|
+
warnings: safeArray(gateResult.warnings),
|
|
270
|
+
trust: runtime.trustSystem.getSnapshot(agentId),
|
|
271
|
+
proofEnvelope: {
|
|
272
|
+
envelopeId: proofEnvelope.envelopeId,
|
|
273
|
+
contentHash: proofEnvelope.contentHash,
|
|
274
|
+
},
|
|
275
|
+
};
|
|
276
|
+
|
|
277
|
+
await runtime.persistState({ lastHookEvent: summary });
|
|
278
|
+
return summary;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
case 'pre-task': {
|
|
282
|
+
const taskDescription = safeString(payload.taskDescription, '');
|
|
283
|
+
const taskId = taskIdFromPayload('pre-task', payload);
|
|
284
|
+
|
|
285
|
+
if (!taskDescription.trim()) {
|
|
286
|
+
return {
|
|
287
|
+
event: 'pre-task',
|
|
288
|
+
success: true,
|
|
289
|
+
blocked: false,
|
|
290
|
+
skipped: true,
|
|
291
|
+
reason: 'empty-task-description',
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
const startedAt = Date.now();
|
|
296
|
+
const result = await runtime.phase1.preTask({
|
|
297
|
+
taskId,
|
|
298
|
+
taskDescription,
|
|
299
|
+
});
|
|
300
|
+
|
|
301
|
+
const blocked = !result.success || Boolean(result.aborted);
|
|
302
|
+
const outcome = blocked ? 'deny' : outcomeFromHookResult(result);
|
|
303
|
+
runtime.recordTrust(agentId, outcome, 'hook pre-task');
|
|
304
|
+
|
|
305
|
+
const violations = mapHookWarningsToViolations(result, 'pre-task');
|
|
306
|
+
if (blocked) {
|
|
307
|
+
violations.push({
|
|
308
|
+
ruleId: 'pre-task-blocked',
|
|
309
|
+
description: 'Task blocked by guidance gates',
|
|
310
|
+
severity: 'high',
|
|
311
|
+
autoCorrected: true,
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
const policyText = runtime.phase1.extractPolicyText(result) || '';
|
|
316
|
+
const proofEnvelope = runtime.appendProof({
|
|
317
|
+
taskId,
|
|
318
|
+
agentId,
|
|
319
|
+
toolsUsed: ['PreTask'],
|
|
320
|
+
violations,
|
|
321
|
+
outcomeAccepted: !blocked,
|
|
322
|
+
durationMs: Date.now() - startedAt,
|
|
323
|
+
details: {
|
|
324
|
+
sessionId,
|
|
325
|
+
toolParams: {
|
|
326
|
+
PreTask: {
|
|
327
|
+
taskDescription,
|
|
328
|
+
},
|
|
329
|
+
},
|
|
330
|
+
toolResults: {
|
|
331
|
+
PreTask: {
|
|
332
|
+
success: result.success,
|
|
333
|
+
aborted: Boolean(result.aborted),
|
|
334
|
+
policyTextLength: policyText.length,
|
|
335
|
+
},
|
|
336
|
+
},
|
|
337
|
+
},
|
|
338
|
+
});
|
|
339
|
+
|
|
340
|
+
const summary = {
|
|
341
|
+
event: 'pre-task',
|
|
342
|
+
taskId,
|
|
343
|
+
success: !blocked,
|
|
344
|
+
blocked,
|
|
345
|
+
messages: safeArray(result.messages),
|
|
346
|
+
warnings: safeArray(result.warnings),
|
|
347
|
+
policyTextLength: policyText.length,
|
|
348
|
+
hooksExecuted: result.hooksExecuted,
|
|
349
|
+
trust: runtime.trustSystem.getSnapshot(agentId),
|
|
350
|
+
proofEnvelope: {
|
|
351
|
+
envelopeId: proofEnvelope.envelopeId,
|
|
352
|
+
contentHash: proofEnvelope.contentHash,
|
|
353
|
+
},
|
|
354
|
+
};
|
|
355
|
+
|
|
356
|
+
pendingRuns[taskId] = {
|
|
357
|
+
taskDescription,
|
|
358
|
+
updatedAt: Date.now(),
|
|
359
|
+
};
|
|
360
|
+
writeJson(pendingRunsPath, pendingRuns);
|
|
361
|
+
|
|
362
|
+
await runtime.persistState({ lastHookEvent: summary });
|
|
363
|
+
return summary;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
case 'post-task': {
|
|
367
|
+
const taskId = taskIdFromPayload('post-task', payload);
|
|
368
|
+
const status = safeString(payload.status, 'completed');
|
|
369
|
+
const toolsUsed = safeArray(payload.toolsUsed);
|
|
370
|
+
const filesTouched = safeArray(payload.filesTouched);
|
|
371
|
+
const pending = pendingRuns[taskId];
|
|
372
|
+
const restoredTaskDescription = safeString(
|
|
373
|
+
payload.taskDescription || pending?.taskDescription,
|
|
374
|
+
''
|
|
375
|
+
);
|
|
376
|
+
|
|
377
|
+
if (restoredTaskDescription) {
|
|
378
|
+
await runtime.phase1.preTask({
|
|
379
|
+
taskId,
|
|
380
|
+
taskDescription: restoredTaskDescription,
|
|
381
|
+
});
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
const startedAt = Date.now();
|
|
385
|
+
const result = await runtime.phase1.postTask({
|
|
386
|
+
taskId,
|
|
387
|
+
status,
|
|
388
|
+
toolsUsed,
|
|
389
|
+
filesTouched,
|
|
390
|
+
});
|
|
391
|
+
|
|
392
|
+
const outcome = outcomeFromHookResult(result);
|
|
393
|
+
runtime.recordTrust(agentId, outcome, 'hook post-task');
|
|
394
|
+
|
|
395
|
+
const violations = mapHookWarningsToViolations(result, 'post-task');
|
|
396
|
+
const proofEnvelope = runtime.appendProof({
|
|
397
|
+
taskId,
|
|
398
|
+
agentId,
|
|
399
|
+
toolsUsed: ['PostTask'],
|
|
400
|
+
violations,
|
|
401
|
+
outcomeAccepted: result.success && !result.aborted,
|
|
402
|
+
durationMs: Date.now() - startedAt,
|
|
403
|
+
details: {
|
|
404
|
+
sessionId,
|
|
405
|
+
filesTouched,
|
|
406
|
+
toolParams: {
|
|
407
|
+
PostTask: {
|
|
408
|
+
status,
|
|
409
|
+
toolsUsed,
|
|
410
|
+
filesTouched,
|
|
411
|
+
},
|
|
412
|
+
},
|
|
413
|
+
toolResults: {
|
|
414
|
+
PostTask: {
|
|
415
|
+
success: result.success,
|
|
416
|
+
aborted: Boolean(result.aborted),
|
|
417
|
+
},
|
|
418
|
+
},
|
|
419
|
+
},
|
|
420
|
+
});
|
|
421
|
+
|
|
422
|
+
const summary = {
|
|
423
|
+
event: 'post-task',
|
|
424
|
+
taskId,
|
|
425
|
+
restoredRunContext: Boolean(restoredTaskDescription),
|
|
426
|
+
success: result.success && !result.aborted,
|
|
427
|
+
blocked: !result.success || Boolean(result.aborted),
|
|
428
|
+
messages: safeArray(result.messages),
|
|
429
|
+
warnings: safeArray(result.warnings),
|
|
430
|
+
trust: runtime.trustSystem.getSnapshot(agentId),
|
|
431
|
+
proofEnvelope: {
|
|
432
|
+
envelopeId: proofEnvelope.envelopeId,
|
|
433
|
+
contentHash: proofEnvelope.contentHash,
|
|
434
|
+
},
|
|
435
|
+
};
|
|
436
|
+
|
|
437
|
+
delete pendingRuns[taskId];
|
|
438
|
+
writeJson(pendingRunsPath, pendingRuns);
|
|
439
|
+
|
|
440
|
+
await runtime.persistState({ lastHookEvent: summary });
|
|
441
|
+
return summary;
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
case 'post-edit': {
|
|
445
|
+
const filePath = safeString(payload.filePath, '');
|
|
446
|
+
const taskId = taskIdFromPayload('post-edit', payload);
|
|
447
|
+
|
|
448
|
+
const proofEnvelope = runtime.appendProof({
|
|
449
|
+
taskId,
|
|
450
|
+
agentId,
|
|
451
|
+
toolsUsed: ['PostEdit'],
|
|
452
|
+
outcomeAccepted: true,
|
|
453
|
+
details: {
|
|
454
|
+
sessionId,
|
|
455
|
+
filesTouched: filePath ? [filePath] : [],
|
|
456
|
+
toolResults: {
|
|
457
|
+
PostEdit: { filePath: filePath || null },
|
|
458
|
+
},
|
|
459
|
+
},
|
|
460
|
+
});
|
|
461
|
+
|
|
462
|
+
runtime.recordTrust(agentId, 'allow', 'hook post-edit');
|
|
463
|
+
const summary = {
|
|
464
|
+
event: 'post-edit',
|
|
465
|
+
taskId,
|
|
466
|
+
success: true,
|
|
467
|
+
blocked: false,
|
|
468
|
+
trust: runtime.trustSystem.getSnapshot(agentId),
|
|
469
|
+
proofEnvelope: {
|
|
470
|
+
envelopeId: proofEnvelope.envelopeId,
|
|
471
|
+
contentHash: proofEnvelope.contentHash,
|
|
472
|
+
},
|
|
473
|
+
};
|
|
474
|
+
await runtime.persistState({ lastHookEvent: summary });
|
|
475
|
+
return summary;
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
case 'session-end': {
|
|
479
|
+
const conformance = await runtime.runConformanceIntegration();
|
|
480
|
+
const evolution = await runtime.runEvolutionIntegration();
|
|
481
|
+
const summary = {
|
|
482
|
+
event: 'session-end',
|
|
483
|
+
success: true,
|
|
484
|
+
blocked: false,
|
|
485
|
+
conformance: {
|
|
486
|
+
passed: conformance.passed,
|
|
487
|
+
failedChecks: conformance.failedChecks.length,
|
|
488
|
+
durationMs: conformance.durationMs,
|
|
489
|
+
},
|
|
490
|
+
evolution: {
|
|
491
|
+
proposalStatus: evolution.proposalStatus,
|
|
492
|
+
approved: Boolean(evolution.comparison?.approved),
|
|
493
|
+
},
|
|
494
|
+
};
|
|
495
|
+
await runtime.persistState({ lastHookEvent: summary });
|
|
496
|
+
return summary;
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
default:
|
|
500
|
+
throw new Error(`Unknown guidance event: ${eventName}`);
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
async function main() {
|
|
505
|
+
const [, , command, ...args] = process.argv;
|
|
506
|
+
if (!command) {
|
|
507
|
+
usage();
|
|
508
|
+
process.exit(1);
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
const runtime = createGuidanceAdvancedRuntime({ rootDir });
|
|
512
|
+
|
|
513
|
+
switch (command) {
|
|
514
|
+
case 'status': {
|
|
515
|
+
await runtime.initialize();
|
|
516
|
+
printJson(runtime.getStatus());
|
|
517
|
+
return;
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
case 'hooks': {
|
|
521
|
+
const taskDescription = args[0];
|
|
522
|
+
const result = await runtime.runHooksIntegration({
|
|
523
|
+
taskDescription,
|
|
524
|
+
});
|
|
525
|
+
printJson(result);
|
|
526
|
+
return;
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
case 'trust': {
|
|
530
|
+
const result = await runtime.runTrustIntegration();
|
|
531
|
+
printJson(result);
|
|
532
|
+
return;
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
case 'adversarial': {
|
|
536
|
+
const result = await runtime.runAdversarialIntegration();
|
|
537
|
+
printJson(result);
|
|
538
|
+
return;
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
case 'proof': {
|
|
542
|
+
const result = await runtime.runProofIntegration();
|
|
543
|
+
printJson(result);
|
|
544
|
+
return;
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
case 'conformance': {
|
|
548
|
+
const result = await runtime.runConformanceIntegration();
|
|
549
|
+
printJson(result);
|
|
550
|
+
return;
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
case 'evolution': {
|
|
554
|
+
const result = await runtime.runEvolutionIntegration();
|
|
555
|
+
printJson(result);
|
|
556
|
+
return;
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
case 'all': {
|
|
560
|
+
const result = await runtime.runAllIntegrations();
|
|
561
|
+
printJson(result);
|
|
562
|
+
return;
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
case 'event': {
|
|
566
|
+
const eventName = safeString(args[0], '');
|
|
567
|
+
if (!eventName) {
|
|
568
|
+
usage();
|
|
569
|
+
process.exit(1);
|
|
570
|
+
}
|
|
571
|
+
const payload = parsePayload(args[1]);
|
|
572
|
+
const result = await runEvent(runtime, eventName, payload);
|
|
573
|
+
printJson(result);
|
|
574
|
+
return;
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
default:
|
|
578
|
+
usage();
|
|
579
|
+
process.exit(1);
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
main().catch((error) => {
|
|
584
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
585
|
+
console.error(message);
|
|
586
|
+
process.exit(1);
|
|
587
|
+
});
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { resolve, dirname } from 'node:path';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
|
|
5
|
+
import { createGuidancePhase1Runtime } from '../src/guidance/phase1-runtime.js';
|
|
6
|
+
|
|
7
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
8
|
+
const rootDir = resolve(__dirname, '..');
|
|
9
|
+
|
|
10
|
+
function usage() {
|
|
11
|
+
console.log(`Usage:
|
|
12
|
+
node scripts/guidance-runtime.js demo
|
|
13
|
+
node scripts/guidance-runtime.js status
|
|
14
|
+
node scripts/guidance-runtime.js task "<description>" [task-id]
|
|
15
|
+
node scripts/guidance-runtime.js command "<shell command>"
|
|
16
|
+
node scripts/guidance-runtime.js tool "<toolName>" [jsonParameters]
|
|
17
|
+
node scripts/guidance-runtime.js edit "<filePath>" [diffLines] [content]`);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function printResult(label, result) {
|
|
21
|
+
const out = {
|
|
22
|
+
label,
|
|
23
|
+
success: result.success,
|
|
24
|
+
aborted: result.aborted ?? false,
|
|
25
|
+
hooksExecuted: result.hooksExecuted,
|
|
26
|
+
hooksFailed: result.hooksFailed,
|
|
27
|
+
messages: result.messages ?? [],
|
|
28
|
+
warnings: result.warnings ?? [],
|
|
29
|
+
};
|
|
30
|
+
console.log(JSON.stringify(out, null, 2));
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
async function run() {
|
|
34
|
+
const [, , command, ...rest] = process.argv;
|
|
35
|
+
|
|
36
|
+
if (!command) {
|
|
37
|
+
usage();
|
|
38
|
+
process.exit(1);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const runtime = createGuidancePhase1Runtime({ rootDir });
|
|
42
|
+
await runtime.initialize();
|
|
43
|
+
|
|
44
|
+
if (command === 'status') {
|
|
45
|
+
console.log(JSON.stringify(runtime.getStatus(), null, 2));
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (command === 'task') {
|
|
50
|
+
const taskDescription = rest[0] ?? '';
|
|
51
|
+
const taskId = rest[1] ?? `task-${Date.now()}`;
|
|
52
|
+
if (!taskDescription) {
|
|
53
|
+
throw new Error('task description is required');
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const pre = await runtime.preTask({ taskId, taskDescription });
|
|
57
|
+
printResult('pre-task', pre);
|
|
58
|
+
const policyText = runtime.extractPolicyText(pre);
|
|
59
|
+
if (policyText) {
|
|
60
|
+
console.log('\nInjected policy preview:\n');
|
|
61
|
+
console.log(policyText.split('\n').slice(0, 16).join('\n'));
|
|
62
|
+
}
|
|
63
|
+
const post = await runtime.postTask({ taskId, status: 'completed' });
|
|
64
|
+
printResult('post-task', post);
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (command === 'command') {
|
|
69
|
+
const shellCommand = rest[0] ?? '';
|
|
70
|
+
if (!shellCommand) {
|
|
71
|
+
throw new Error('shell command is required');
|
|
72
|
+
}
|
|
73
|
+
const result = await runtime.preCommand(shellCommand);
|
|
74
|
+
printResult('pre-command', result);
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (command === 'tool') {
|
|
79
|
+
const toolName = rest[0] ?? '';
|
|
80
|
+
const paramsInput = rest[1] ?? '{}';
|
|
81
|
+
if (!toolName) {
|
|
82
|
+
throw new Error('tool name is required');
|
|
83
|
+
}
|
|
84
|
+
const params = JSON.parse(paramsInput);
|
|
85
|
+
const result = await runtime.preToolUse(toolName, params);
|
|
86
|
+
printResult('pre-tool-use', result);
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if (command === 'edit') {
|
|
91
|
+
const filePath = rest[0] ?? '';
|
|
92
|
+
const diffLines = Number(rest[1] ?? 0);
|
|
93
|
+
const content = rest[2] ?? '';
|
|
94
|
+
if (!filePath) {
|
|
95
|
+
throw new Error('file path is required');
|
|
96
|
+
}
|
|
97
|
+
const result = await runtime.preEdit({ filePath, diffLines, content });
|
|
98
|
+
printResult('pre-edit', result);
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if (command === 'demo') {
|
|
103
|
+
const taskId = `demo-${Date.now()}`;
|
|
104
|
+
const preTask = await runtime.preTask({
|
|
105
|
+
taskId,
|
|
106
|
+
taskDescription: 'Implement a guidance runtime integration script',
|
|
107
|
+
});
|
|
108
|
+
printResult('pre-task', preTask);
|
|
109
|
+
|
|
110
|
+
const destructive = await runtime.preCommand('git push origin main --force');
|
|
111
|
+
printResult('pre-command destructive', destructive);
|
|
112
|
+
|
|
113
|
+
const safe = await runtime.preCommand('git status');
|
|
114
|
+
printResult('pre-command safe', safe);
|
|
115
|
+
|
|
116
|
+
const postTask = await runtime.postTask({
|
|
117
|
+
taskId,
|
|
118
|
+
status: 'completed',
|
|
119
|
+
toolsUsed: ['Read', 'Edit', 'Bash'],
|
|
120
|
+
filesTouched: ['scripts/guidance-runtime.js'],
|
|
121
|
+
});
|
|
122
|
+
printResult('post-task', postTask);
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
usage();
|
|
127
|
+
process.exit(1);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
run().catch((error) => {
|
|
131
|
+
console.error(error instanceof Error ? error.message : String(error));
|
|
132
|
+
process.exit(1);
|
|
133
|
+
});
|