agentic-flow 2.0.1-alpha.4 ā 2.0.1-alpha.8
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/CHANGELOG.md +26 -0
- package/dist/.tsbuildinfo +1 -1
- package/dist/agentdb/controllers/EmbeddingService.d.ts +37 -0
- package/dist/agentdb/controllers/EmbeddingService.d.ts.map +1 -0
- package/dist/agentdb/controllers/EmbeddingService.js +1 -0
- package/dist/agentdb/controllers/EmbeddingService.js.map +1 -0
- package/dist/billing/mcp/tools.d.ts.map +1 -1
- package/dist/billing/mcp/tools.js +2 -0
- package/dist/billing/mcp/tools.js.map +1 -1
- package/dist/cli/commands/hooks.d.ts +18 -0
- package/dist/cli/commands/hooks.d.ts.map +1 -0
- package/dist/cli/commands/hooks.js +750 -0
- package/dist/cli/commands/hooks.js.map +1 -0
- package/dist/cli-proxy.js +26 -1
- package/dist/cli-proxy.js.map +1 -1
- package/dist/core/agentdb-fast.js +3 -3
- package/dist/core/agentdb-fast.js.map +1 -1
- package/dist/core/agentdb-wrapper-enhanced.d.ts.map +1 -1
- package/dist/core/agentdb-wrapper-enhanced.js +32 -17
- package/dist/core/agentdb-wrapper-enhanced.js.map +1 -1
- package/dist/core/attention-native.d.ts +1 -0
- package/dist/core/attention-native.d.ts.map +1 -1
- package/dist/core/attention-native.js +6 -1
- package/dist/core/attention-native.js.map +1 -1
- package/dist/federation/integrations/supabase-adapter-debug.js +3 -3
- package/dist/federation/integrations/supabase-adapter-debug.js.map +1 -1
- package/dist/intelligence/RuVectorIntelligence.d.ts +362 -0
- package/dist/intelligence/RuVectorIntelligence.d.ts.map +1 -0
- package/dist/intelligence/RuVectorIntelligence.js +852 -0
- package/dist/intelligence/RuVectorIntelligence.js.map +1 -0
- package/dist/intelligence/index.d.ts +14 -0
- package/dist/intelligence/index.d.ts.map +1 -0
- package/dist/intelligence/index.js +14 -0
- package/dist/intelligence/index.js.map +1 -0
- package/dist/llm/RuvLLMOrchestrator.d.ts +184 -0
- package/dist/llm/RuvLLMOrchestrator.d.ts.map +1 -0
- package/dist/llm/RuvLLMOrchestrator.js +442 -0
- package/dist/llm/RuvLLMOrchestrator.js.map +1 -0
- package/dist/llm/index.d.ts +9 -0
- package/dist/llm/index.d.ts.map +1 -0
- package/dist/llm/index.js +8 -0
- package/dist/llm/index.js.map +1 -0
- package/dist/mcp/claudeFlowSdkServer.d.ts.map +1 -1
- package/dist/mcp/claudeFlowSdkServer.js +86 -21
- package/dist/mcp/claudeFlowSdkServer.js.map +1 -1
- package/dist/mcp/fastmcp/servers/hooks-server.d.ts +15 -0
- package/dist/mcp/fastmcp/servers/hooks-server.d.ts.map +1 -0
- package/dist/mcp/fastmcp/servers/hooks-server.js +63 -0
- package/dist/mcp/fastmcp/servers/hooks-server.js.map +1 -0
- package/dist/mcp/fastmcp/tools/hooks/benchmark.d.ts +20 -0
- package/dist/mcp/fastmcp/tools/hooks/benchmark.d.ts.map +1 -0
- package/dist/mcp/fastmcp/tools/hooks/benchmark.js +110 -0
- package/dist/mcp/fastmcp/tools/hooks/benchmark.js.map +1 -0
- package/dist/mcp/fastmcp/tools/hooks/build-agents.d.ts +7 -0
- package/dist/mcp/fastmcp/tools/hooks/build-agents.d.ts.map +1 -0
- package/dist/mcp/fastmcp/tools/hooks/build-agents.js +276 -0
- package/dist/mcp/fastmcp/tools/hooks/build-agents.js.map +1 -0
- package/dist/mcp/fastmcp/tools/hooks/explain.d.ts +6 -0
- package/dist/mcp/fastmcp/tools/hooks/explain.d.ts.map +1 -0
- package/dist/mcp/fastmcp/tools/hooks/explain.js +164 -0
- package/dist/mcp/fastmcp/tools/hooks/explain.js.map +1 -0
- package/dist/mcp/fastmcp/tools/hooks/index.d.ts +28 -0
- package/dist/mcp/fastmcp/tools/hooks/index.d.ts.map +1 -0
- package/dist/mcp/fastmcp/tools/hooks/index.js +59 -0
- package/dist/mcp/fastmcp/tools/hooks/index.js.map +1 -0
- package/dist/mcp/fastmcp/tools/hooks/intelligence-bridge.d.ts +91 -0
- package/dist/mcp/fastmcp/tools/hooks/intelligence-bridge.d.ts.map +1 -0
- package/dist/mcp/fastmcp/tools/hooks/intelligence-bridge.js +269 -0
- package/dist/mcp/fastmcp/tools/hooks/intelligence-bridge.js.map +1 -0
- package/dist/mcp/fastmcp/tools/hooks/intelligence-tools.d.ts +58 -0
- package/dist/mcp/fastmcp/tools/hooks/intelligence-tools.d.ts.map +1 -0
- package/dist/mcp/fastmcp/tools/hooks/intelligence-tools.js +416 -0
- package/dist/mcp/fastmcp/tools/hooks/intelligence-tools.js.map +1 -0
- package/dist/mcp/fastmcp/tools/hooks/metrics.d.ts +6 -0
- package/dist/mcp/fastmcp/tools/hooks/metrics.d.ts.map +1 -0
- package/dist/mcp/fastmcp/tools/hooks/metrics.js +137 -0
- package/dist/mcp/fastmcp/tools/hooks/metrics.js.map +1 -0
- package/dist/mcp/fastmcp/tools/hooks/post-command.d.ts +7 -0
- package/dist/mcp/fastmcp/tools/hooks/post-command.d.ts.map +1 -0
- package/dist/mcp/fastmcp/tools/hooks/post-command.js +91 -0
- package/dist/mcp/fastmcp/tools/hooks/post-command.js.map +1 -0
- package/dist/mcp/fastmcp/tools/hooks/post-edit.d.ts +12 -0
- package/dist/mcp/fastmcp/tools/hooks/post-edit.d.ts.map +1 -0
- package/dist/mcp/fastmcp/tools/hooks/post-edit.js +146 -0
- package/dist/mcp/fastmcp/tools/hooks/post-edit.js.map +1 -0
- package/dist/mcp/fastmcp/tools/hooks/pre-command.d.ts +7 -0
- package/dist/mcp/fastmcp/tools/hooks/pre-command.d.ts.map +1 -0
- package/dist/mcp/fastmcp/tools/hooks/pre-command.js +70 -0
- package/dist/mcp/fastmcp/tools/hooks/pre-command.js.map +1 -0
- package/dist/mcp/fastmcp/tools/hooks/pre-edit.d.ts +14 -0
- package/dist/mcp/fastmcp/tools/hooks/pre-edit.d.ts.map +1 -0
- package/dist/mcp/fastmcp/tools/hooks/pre-edit.js +121 -0
- package/dist/mcp/fastmcp/tools/hooks/pre-edit.js.map +1 -0
- package/dist/mcp/fastmcp/tools/hooks/pretrain.d.ts +7 -0
- package/dist/mcp/fastmcp/tools/hooks/pretrain.d.ts.map +1 -0
- package/dist/mcp/fastmcp/tools/hooks/pretrain.js +171 -0
- package/dist/mcp/fastmcp/tools/hooks/pretrain.js.map +1 -0
- package/dist/mcp/fastmcp/tools/hooks/route.d.ts +12 -0
- package/dist/mcp/fastmcp/tools/hooks/route.d.ts.map +1 -0
- package/dist/mcp/fastmcp/tools/hooks/route.js +267 -0
- package/dist/mcp/fastmcp/tools/hooks/route.js.map +1 -0
- package/dist/mcp/fastmcp/tools/hooks/shared.d.ts +46 -0
- package/dist/mcp/fastmcp/tools/hooks/shared.d.ts.map +1 -0
- package/dist/mcp/fastmcp/tools/hooks/shared.js +159 -0
- package/dist/mcp/fastmcp/tools/hooks/shared.js.map +1 -0
- package/dist/mcp/fastmcp/tools/hooks/transfer.d.ts +7 -0
- package/dist/mcp/fastmcp/tools/hooks/transfer.d.ts.map +1 -0
- package/dist/mcp/fastmcp/tools/hooks/transfer.js +151 -0
- package/dist/mcp/fastmcp/tools/hooks/transfer.js.map +1 -0
- package/dist/mcp/tools/agent-booster-tools.d.ts +10 -1
- package/dist/mcp/tools/agent-booster-tools.d.ts.map +1 -1
- package/dist/mcp/tools/agent-booster-tools.js.map +1 -1
- package/dist/mcp/tools/sona-tools.d.ts.map +1 -1
- package/dist/mcp/tools/sona-tools.js +15 -3
- package/dist/mcp/tools/sona-tools.js.map +1 -1
- package/dist/memory/SharedMemoryPool.d.ts +16 -3
- package/dist/memory/SharedMemoryPool.d.ts.map +1 -1
- package/dist/memory/SharedMemoryPool.js +33 -1
- package/dist/memory/SharedMemoryPool.js.map +1 -1
- package/dist/middleware/auth.middleware.d.ts +114 -0
- package/dist/middleware/auth.middleware.d.ts.map +1 -0
- package/dist/middleware/auth.middleware.js +222 -0
- package/dist/middleware/auth.middleware.js.map +1 -0
- package/dist/optimizations/agent-booster-migration.d.ts.map +1 -1
- package/dist/optimizations/agent-booster-migration.js.map +1 -1
- package/dist/proxy/anthropic-to-gemini.d.ts.map +1 -1
- package/dist/proxy/anthropic-to-gemini.js.map +1 -1
- package/dist/proxy/anthropic-to-openrouter.d.ts.map +1 -1
- package/dist/proxy/anthropic-to-openrouter.js.map +1 -1
- package/dist/proxy/anthropic-to-requesty.d.ts.map +1 -1
- package/dist/proxy/anthropic-to-requesty.js.map +1 -1
- package/dist/proxy/quic-proxy.d.ts +0 -1
- package/dist/proxy/quic-proxy.d.ts.map +1 -1
- package/dist/proxy/quic-proxy.js +2 -1
- package/dist/proxy/quic-proxy.js.map +1 -1
- package/dist/reasoningbank/AdvancedMemory.d.ts.map +1 -1
- package/dist/reasoningbank/AdvancedMemory.js +12 -1
- package/dist/reasoningbank/AdvancedMemory.js.map +1 -1
- package/dist/reasoningbank/HybridBackend.d.ts +9 -0
- package/dist/reasoningbank/HybridBackend.d.ts.map +1 -1
- package/dist/reasoningbank/HybridBackend.js +48 -4
- package/dist/reasoningbank/HybridBackend.js.map +1 -1
- package/dist/reasoningbank/backend-selector.d.ts +1 -1
- package/dist/reasoningbank/backend-selector.d.ts.map +1 -1
- package/dist/reasoningbank/backend-selector.js.map +1 -1
- package/dist/reasoningbank/index-new.d.ts +0 -6
- package/dist/reasoningbank/index-new.d.ts.map +1 -1
- package/dist/reasoningbank/index-new.js +9 -7
- package/dist/reasoningbank/index-new.js.map +1 -1
- package/dist/reasoningbank/index.d.ts +1 -6
- package/dist/reasoningbank/index.d.ts.map +1 -1
- package/dist/reasoningbank/index.js +10 -7
- package/dist/reasoningbank/index.js.map +1 -1
- package/dist/router/providers/onnx-local.d.ts.map +1 -1
- package/dist/router/providers/onnx-local.js +3 -1
- package/dist/router/providers/onnx-local.js.map +1 -1
- package/dist/routing/CircuitBreakerRouter.d.ts +187 -0
- package/dist/routing/CircuitBreakerRouter.d.ts.map +1 -0
- package/dist/routing/CircuitBreakerRouter.js +460 -0
- package/dist/routing/CircuitBreakerRouter.js.map +1 -0
- package/dist/routing/SemanticRouter.d.ts +164 -0
- package/dist/routing/SemanticRouter.d.ts.map +1 -0
- package/dist/routing/SemanticRouter.js +291 -0
- package/dist/routing/SemanticRouter.js.map +1 -0
- package/dist/routing/index.d.ts +12 -0
- package/dist/routing/index.d.ts.map +1 -0
- package/dist/routing/index.js +10 -0
- package/dist/routing/index.js.map +1 -0
- package/dist/services/embedding-service.d.ts.map +1 -1
- package/dist/services/embedding-service.js +5 -2
- package/dist/services/embedding-service.js.map +1 -1
- package/dist/services/sona-agent-training.js +1 -1
- package/dist/services/sona-agent-training.js.map +1 -1
- package/dist/services/sona-agentdb-integration.d.ts.map +1 -1
- package/dist/services/sona-agentdb-integration.js +10 -5
- package/dist/services/sona-agentdb-integration.js.map +1 -1
- package/dist/services/sona-service.d.ts +6 -6
- package/dist/services/sona-service.d.ts.map +1 -1
- package/dist/services/sona-service.js +3 -1
- package/dist/services/sona-service.js.map +1 -1
- package/dist/utils/audit-logger.d.ts +115 -0
- package/dist/utils/audit-logger.d.ts.map +1 -0
- package/dist/utils/audit-logger.js +228 -0
- package/dist/utils/audit-logger.js.map +1 -0
- package/dist/utils/cli.d.ts +1 -1
- package/dist/utils/cli.d.ts.map +1 -1
- package/dist/utils/cli.js +5 -0
- package/dist/utils/cli.js.map +1 -1
- package/dist/utils/input-validator.d.ts +116 -0
- package/dist/utils/input-validator.d.ts.map +1 -0
- package/dist/utils/input-validator.js +299 -0
- package/dist/utils/input-validator.js.map +1 -0
- package/dist/utils/rate-limiter.js +2 -2
- package/dist/utils/rate-limiter.js.map +1 -1
- package/package.json +5 -2
- package/wasm/reasoningbank/reasoningbank_wasm_bg.js +2 -2
- package/wasm/reasoningbank/reasoningbank_wasm_bg.wasm +0 -0
|
@@ -0,0 +1,750 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* CLI Hooks Commands
|
|
4
|
+
* Provides CLI interface for agentic-flow hook tools
|
|
5
|
+
*
|
|
6
|
+
* NOW WITH FULL RUVECTOR INTELLIGENCE:
|
|
7
|
+
* - @ruvector/sona: Micro-LoRA (~0.05ms), EWC++, Trajectory tracking
|
|
8
|
+
* - @ruvector/attention: MoE, Flash, Hyperbolic, Graph attention
|
|
9
|
+
* - ruvector core: HNSW indexing (150x faster)
|
|
10
|
+
*
|
|
11
|
+
* Available as BOTH:
|
|
12
|
+
* 1. CLI Commands (agentic-flow hooks ...)
|
|
13
|
+
* 2. MCP Tools (via hooks-server.ts)
|
|
14
|
+
*/
|
|
15
|
+
import { Command } from 'commander';
|
|
16
|
+
import * as path from 'path';
|
|
17
|
+
// Import hook tools
|
|
18
|
+
import { hookPreEditTool } from '../../mcp/fastmcp/tools/hooks/pre-edit.js';
|
|
19
|
+
import { hookPostEditTool } from '../../mcp/fastmcp/tools/hooks/post-edit.js';
|
|
20
|
+
import { hookPreCommandTool } from '../../mcp/fastmcp/tools/hooks/pre-command.js';
|
|
21
|
+
import { hookPostCommandTool } from '../../mcp/fastmcp/tools/hooks/post-command.js';
|
|
22
|
+
import { hookRouteTool } from '../../mcp/fastmcp/tools/hooks/route.js';
|
|
23
|
+
import { hookExplainTool } from '../../mcp/fastmcp/tools/hooks/explain.js';
|
|
24
|
+
import { hookPretrainTool } from '../../mcp/fastmcp/tools/hooks/pretrain.js';
|
|
25
|
+
import { hookBuildAgentsTool } from '../../mcp/fastmcp/tools/hooks/build-agents.js';
|
|
26
|
+
import { hookMetricsTool } from '../../mcp/fastmcp/tools/hooks/metrics.js';
|
|
27
|
+
import { hookTransferTool } from '../../mcp/fastmcp/tools/hooks/transfer.js';
|
|
28
|
+
// Import intelligence tools (RuVector SONA + Attention + HNSW)
|
|
29
|
+
import { intelligenceRouteTool, intelligenceTrajectoryStartTool, intelligenceTrajectoryStepTool, intelligenceTrajectoryEndTool, intelligencePatternStoreTool, intelligencePatternSearchTool, intelligenceStatsTool, intelligenceLearnTool, intelligenceAttentionTool } from '../../mcp/fastmcp/tools/hooks/intelligence-tools.js';
|
|
30
|
+
const mockContext = {
|
|
31
|
+
onProgress: (update) => {
|
|
32
|
+
if (process.env.VERBOSE) {
|
|
33
|
+
console.log(`[${Math.round(update.progress * 100)}%] ${update.message}`);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
export function createHooksCommand() {
|
|
38
|
+
const hooks = new Command('hooks')
|
|
39
|
+
.description('Self-learning intelligence hooks for agent routing and optimization');
|
|
40
|
+
// Pre-edit hook
|
|
41
|
+
hooks
|
|
42
|
+
.command('pre-edit <filePath>')
|
|
43
|
+
.description('Get context and agent suggestion before editing a file')
|
|
44
|
+
.option('-t, --task <task>', 'Task description')
|
|
45
|
+
.option('-j, --json', 'Output as JSON')
|
|
46
|
+
.action(async (filePath, options) => {
|
|
47
|
+
try {
|
|
48
|
+
const result = await hookPreEditTool.execute({ filePath, task: options.task }, mockContext);
|
|
49
|
+
if (options.json) {
|
|
50
|
+
console.log(JSON.stringify(result, null, 2));
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
console.log(`\nšÆ Suggested Agent: ${result.suggestedAgent}`);
|
|
54
|
+
console.log(`š Confidence: ${(result.confidence * 100).toFixed(1)}%`);
|
|
55
|
+
if (result.relatedFiles?.length > 0) {
|
|
56
|
+
console.log(`š Related Files:`);
|
|
57
|
+
result.relatedFiles.forEach((f) => console.log(` - ${f}`));
|
|
58
|
+
}
|
|
59
|
+
console.log(`ā±ļø Latency: ${result.latencyMs}ms`);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
console.error('Error:', error instanceof Error ? error.message : error);
|
|
64
|
+
process.exit(1);
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
// Post-edit hook
|
|
68
|
+
hooks
|
|
69
|
+
.command('post-edit <filePath>')
|
|
70
|
+
.description('Record edit outcome for learning')
|
|
71
|
+
.option('-s, --success', 'Mark as successful edit')
|
|
72
|
+
.option('-f, --fail', 'Mark as failed edit')
|
|
73
|
+
.option('-a, --agent <agent>', 'Agent that performed the edit')
|
|
74
|
+
.option('-d, --duration <ms>', 'Edit duration in milliseconds', parseInt)
|
|
75
|
+
.option('-e, --error <message>', 'Error message if failed')
|
|
76
|
+
.option('-j, --json', 'Output as JSON')
|
|
77
|
+
.action(async (filePath, options) => {
|
|
78
|
+
try {
|
|
79
|
+
const success = options.success || !options.fail;
|
|
80
|
+
const result = await hookPostEditTool.execute({
|
|
81
|
+
filePath,
|
|
82
|
+
success,
|
|
83
|
+
agent: options.agent,
|
|
84
|
+
duration: options.duration,
|
|
85
|
+
errorMessage: options.error
|
|
86
|
+
}, mockContext);
|
|
87
|
+
if (options.json) {
|
|
88
|
+
console.log(JSON.stringify(result, null, 2));
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
console.log(`\n${success ? 'ā
' : 'ā'} Edit recorded: ${filePath}`);
|
|
92
|
+
console.log(`š Pattern updated: ${result.newPatternValue?.toFixed(2) || 'N/A'}`);
|
|
93
|
+
console.log(`š Routing accuracy: ${(result.routingAccuracy * 100).toFixed(1)}%`);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
catch (error) {
|
|
97
|
+
console.error('Error:', error instanceof Error ? error.message : error);
|
|
98
|
+
process.exit(1);
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
// Pre-command hook
|
|
102
|
+
hooks
|
|
103
|
+
.command('pre-command <command>')
|
|
104
|
+
.description('Assess command risk before execution')
|
|
105
|
+
.option('-j, --json', 'Output as JSON')
|
|
106
|
+
.action(async (command, options) => {
|
|
107
|
+
try {
|
|
108
|
+
const result = await hookPreCommandTool.execute({ command }, mockContext);
|
|
109
|
+
if (options.json) {
|
|
110
|
+
console.log(JSON.stringify(result, null, 2));
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
const riskIcon = result.blocked ? 'š«' :
|
|
114
|
+
result.riskCategory === 'safe' ? 'ā
' :
|
|
115
|
+
result.riskCategory === 'caution' ? 'ā ļø' : 'ā';
|
|
116
|
+
console.log(`\n${riskIcon} Risk Level: ${result.riskCategory.toUpperCase()} (${(result.riskLevel * 100).toFixed(0)}%)`);
|
|
117
|
+
if (result.blocked) {
|
|
118
|
+
console.log(`š« Command BLOCKED - dangerous operation detected`);
|
|
119
|
+
}
|
|
120
|
+
else if (result.approved) {
|
|
121
|
+
console.log(`ā
Command APPROVED`);
|
|
122
|
+
}
|
|
123
|
+
if (result.suggestions?.length > 0) {
|
|
124
|
+
console.log(`š” Suggestions:`);
|
|
125
|
+
result.suggestions.forEach((s) => console.log(` - ${s}`));
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
catch (error) {
|
|
130
|
+
console.error('Error:', error instanceof Error ? error.message : error);
|
|
131
|
+
process.exit(1);
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
// Post-command hook
|
|
135
|
+
hooks
|
|
136
|
+
.command('post-command <command>')
|
|
137
|
+
.description('Record command outcome for learning')
|
|
138
|
+
.option('-c, --exit-code <code>', 'Exit code', parseInt, 0)
|
|
139
|
+
.option('-o, --stdout <output>', 'Command stdout')
|
|
140
|
+
.option('-e, --stderr <error>', 'Command stderr')
|
|
141
|
+
.option('-j, --json', 'Output as JSON')
|
|
142
|
+
.action(async (command, options) => {
|
|
143
|
+
try {
|
|
144
|
+
const result = await hookPostCommandTool.execute({
|
|
145
|
+
command,
|
|
146
|
+
exitCode: options.exitCode ?? 0,
|
|
147
|
+
stdout: options.stdout,
|
|
148
|
+
stderr: options.stderr
|
|
149
|
+
}, mockContext);
|
|
150
|
+
if (options.json) {
|
|
151
|
+
console.log(JSON.stringify(result, null, 2));
|
|
152
|
+
}
|
|
153
|
+
else {
|
|
154
|
+
console.log(`\n${result.commandSuccess ? 'ā
' : 'ā'} Command outcome recorded`);
|
|
155
|
+
console.log(`š Learned: ${result.learned ? 'Yes' : 'No'}`);
|
|
156
|
+
if (result.errorType) {
|
|
157
|
+
console.log(`š Error type: ${result.errorType}`);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
catch (error) {
|
|
162
|
+
console.error('Error:', error instanceof Error ? error.message : error);
|
|
163
|
+
process.exit(1);
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
// Route hook
|
|
167
|
+
hooks
|
|
168
|
+
.command('route <task>')
|
|
169
|
+
.description('Route task to optimal agent using learned patterns')
|
|
170
|
+
.option('-f, --file <filePath>', 'Context file path')
|
|
171
|
+
.option('-e, --explore', 'Enable exploration mode')
|
|
172
|
+
.option('-j, --json', 'Output as JSON')
|
|
173
|
+
.action(async (task, options) => {
|
|
174
|
+
try {
|
|
175
|
+
const result = await hookRouteTool.execute({
|
|
176
|
+
task,
|
|
177
|
+
context: options.file ? { file: options.file } : undefined,
|
|
178
|
+
explore: options.explore
|
|
179
|
+
}, mockContext);
|
|
180
|
+
if (options.json) {
|
|
181
|
+
console.log(JSON.stringify(result, null, 2));
|
|
182
|
+
}
|
|
183
|
+
else {
|
|
184
|
+
console.log(`\nšÆ Recommended Agent: ${result.agent}`);
|
|
185
|
+
console.log(`š Confidence: ${(result.confidence * 100).toFixed(1)}%`);
|
|
186
|
+
if (result.explored) {
|
|
187
|
+
console.log(`š Exploration mode: Active`);
|
|
188
|
+
}
|
|
189
|
+
console.log(`\nš Routing Factors:`);
|
|
190
|
+
result.factors.forEach((f) => {
|
|
191
|
+
console.log(` ⢠${f.name}: ${(f.score * 100).toFixed(0)}%`);
|
|
192
|
+
});
|
|
193
|
+
if (result.alternatives?.length > 0) {
|
|
194
|
+
console.log(`\nš Alternatives:`);
|
|
195
|
+
result.alternatives.forEach((a) => {
|
|
196
|
+
console.log(` - ${a.agent} (${(a.score * 100).toFixed(0)}%)`);
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
console.log(`\nā±ļø Latency: ${result.latencyMs}ms`);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
catch (error) {
|
|
203
|
+
console.error('Error:', error instanceof Error ? error.message : error);
|
|
204
|
+
process.exit(1);
|
|
205
|
+
}
|
|
206
|
+
});
|
|
207
|
+
// Explain hook
|
|
208
|
+
hooks
|
|
209
|
+
.command('explain <task>')
|
|
210
|
+
.description('Explain routing decision with full transparency')
|
|
211
|
+
.option('-f, --file <filePath>', 'Context file path')
|
|
212
|
+
.option('-j, --json', 'Output as JSON')
|
|
213
|
+
.action(async (task, options) => {
|
|
214
|
+
try {
|
|
215
|
+
const result = await hookExplainTool.execute({ task, file: options.file }, mockContext);
|
|
216
|
+
if (options.json) {
|
|
217
|
+
console.log(JSON.stringify(result, null, 2));
|
|
218
|
+
}
|
|
219
|
+
else {
|
|
220
|
+
console.log(`\nš Summary: ${result.summary}`);
|
|
221
|
+
console.log(`\nšÆ Recommended: ${result.recommendedAgent}`);
|
|
222
|
+
console.log(`\nš” Reasons:`);
|
|
223
|
+
result.reasons.forEach((r) => console.log(` ⢠${r}`));
|
|
224
|
+
console.log(`\nš Agent Ranking:`);
|
|
225
|
+
result.ranking.forEach((r) => {
|
|
226
|
+
console.log(` ${r.rank}. ${r.agent} - ${(r.score * 100).toFixed(1)}%`);
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
catch (error) {
|
|
231
|
+
console.error('Error:', error instanceof Error ? error.message : error);
|
|
232
|
+
process.exit(1);
|
|
233
|
+
}
|
|
234
|
+
});
|
|
235
|
+
// Pretrain hook
|
|
236
|
+
hooks
|
|
237
|
+
.command('pretrain')
|
|
238
|
+
.description('Analyze repository to bootstrap intelligence')
|
|
239
|
+
.option('-d, --depth <n>', 'Git history depth', parseInt, 50)
|
|
240
|
+
.option('--skip-git', 'Skip git history analysis')
|
|
241
|
+
.option('--skip-files', 'Skip file structure analysis')
|
|
242
|
+
.option('-j, --json', 'Output as JSON')
|
|
243
|
+
.action(async (options) => {
|
|
244
|
+
try {
|
|
245
|
+
console.log('š§ Analyzing repository...\n');
|
|
246
|
+
const result = await hookPretrainTool.execute({
|
|
247
|
+
depth: options.depth ?? 50,
|
|
248
|
+
skipGit: options.skipGit ?? false,
|
|
249
|
+
skipFiles: options.skipFiles ?? false
|
|
250
|
+
}, mockContext);
|
|
251
|
+
if (options.json) {
|
|
252
|
+
console.log(JSON.stringify(result, null, 2));
|
|
253
|
+
}
|
|
254
|
+
else {
|
|
255
|
+
console.log(`\nš Pretrain Complete!`);
|
|
256
|
+
console.log(` š Files analyzed: ${result.filesAnalyzed}`);
|
|
257
|
+
console.log(` š§© Patterns created: ${result.patternsCreated}`);
|
|
258
|
+
console.log(` š¾ Memories stored: ${result.memoriesStored}`);
|
|
259
|
+
console.log(` š Co-edits found: ${result.coEditsFound || 0}`);
|
|
260
|
+
if (result.languages?.length > 0) {
|
|
261
|
+
console.log(` š Languages: ${result.languages.join(', ')}`);
|
|
262
|
+
}
|
|
263
|
+
console.log(` ā±ļø Duration: ${result.durationMs}ms`);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
catch (error) {
|
|
267
|
+
console.error('Error:', error instanceof Error ? error.message : error);
|
|
268
|
+
process.exit(1);
|
|
269
|
+
}
|
|
270
|
+
});
|
|
271
|
+
// Build-agents hook
|
|
272
|
+
hooks
|
|
273
|
+
.command('build-agents')
|
|
274
|
+
.description('Generate optimized agent configurations from pretrain data')
|
|
275
|
+
.option('-f, --focus <mode>', 'Focus mode: quality|speed|security|testing|fullstack', 'quality')
|
|
276
|
+
.option('-o, --output <dir>', 'Output directory', '.claude/agents')
|
|
277
|
+
.option('--format <fmt>', 'Output format: yaml|json', 'yaml')
|
|
278
|
+
.option('--no-prompts', 'Exclude system prompts')
|
|
279
|
+
.option('-j, --json', 'Output as JSON')
|
|
280
|
+
.action(async (options) => {
|
|
281
|
+
try {
|
|
282
|
+
console.log(`šļø Building agents with focus: ${options.focus}...\n`);
|
|
283
|
+
const result = await hookBuildAgentsTool.execute({
|
|
284
|
+
focus: options.focus,
|
|
285
|
+
output: options.output,
|
|
286
|
+
format: options.format,
|
|
287
|
+
includePrompts: options.prompts !== false
|
|
288
|
+
}, mockContext);
|
|
289
|
+
if (options.json) {
|
|
290
|
+
console.log(JSON.stringify(result, null, 2));
|
|
291
|
+
}
|
|
292
|
+
else {
|
|
293
|
+
console.log(`\nā
Agents Generated!`);
|
|
294
|
+
console.log(` š¦ Total: ${result.agentsGenerated}`);
|
|
295
|
+
console.log(` š Output: ${result.outputDir}`);
|
|
296
|
+
console.log(` šÆ Focus: ${result.focus}`);
|
|
297
|
+
console.log(`\n Agents created:`);
|
|
298
|
+
result.agents.forEach((a) => console.log(` ⢠${a}`));
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
catch (error) {
|
|
302
|
+
console.error('Error:', error instanceof Error ? error.message : error);
|
|
303
|
+
process.exit(1);
|
|
304
|
+
}
|
|
305
|
+
});
|
|
306
|
+
// Metrics hook
|
|
307
|
+
hooks
|
|
308
|
+
.command('metrics')
|
|
309
|
+
.alias('stats')
|
|
310
|
+
.description('View learning metrics and performance dashboard')
|
|
311
|
+
.option('-t, --timeframe <period>', 'Timeframe: 1h|24h|7d|30d', '24h')
|
|
312
|
+
.option('-d, --detailed', 'Show detailed metrics')
|
|
313
|
+
.option('-j, --json', 'Output as JSON')
|
|
314
|
+
.action(async (options) => {
|
|
315
|
+
try {
|
|
316
|
+
const result = await hookMetricsTool.execute({
|
|
317
|
+
timeframe: options.timeframe,
|
|
318
|
+
detailed: options.detailed
|
|
319
|
+
}, mockContext);
|
|
320
|
+
if (options.json) {
|
|
321
|
+
console.log(JSON.stringify(result, null, 2));
|
|
322
|
+
}
|
|
323
|
+
else {
|
|
324
|
+
console.log(`\nš Learning Metrics (${options.timeframe || '24h'})\n`);
|
|
325
|
+
console.log(`šÆ Routing:`);
|
|
326
|
+
console.log(` Total routes: ${result.routing.total}`);
|
|
327
|
+
console.log(` Successful: ${result.routing.successful}`);
|
|
328
|
+
console.log(` Accuracy: ${(result.routing.accuracy * 100).toFixed(1)}%`);
|
|
329
|
+
console.log(`\nš Learning:`);
|
|
330
|
+
console.log(` Patterns: ${result.learning.patterns}`);
|
|
331
|
+
console.log(` Memories: ${result.learning.memories}`);
|
|
332
|
+
console.log(` Error patterns: ${result.learning.errorPatterns}`);
|
|
333
|
+
console.log(`\nš Health: ${result.health.status.toUpperCase()}`);
|
|
334
|
+
if (result.health.issues?.length > 0) {
|
|
335
|
+
console.log(` Issues:`);
|
|
336
|
+
result.health.issues.forEach((i) => console.log(` ā ļø ${i}`));
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
catch (error) {
|
|
341
|
+
console.error('Error:', error instanceof Error ? error.message : error);
|
|
342
|
+
process.exit(1);
|
|
343
|
+
}
|
|
344
|
+
});
|
|
345
|
+
// Transfer hook
|
|
346
|
+
hooks
|
|
347
|
+
.command('transfer <sourceProject>')
|
|
348
|
+
.description('Transfer learned patterns from another project')
|
|
349
|
+
.option('-c, --min-confidence <n>', 'Minimum confidence threshold', parseFloat, 0.7)
|
|
350
|
+
.option('-m, --max-patterns <n>', 'Maximum patterns to transfer', parseInt, 50)
|
|
351
|
+
.option('--mode <mode>', 'Transfer mode: merge|replace|additive', 'merge')
|
|
352
|
+
.option('-j, --json', 'Output as JSON')
|
|
353
|
+
.action(async (sourceProject, options) => {
|
|
354
|
+
try {
|
|
355
|
+
console.log(`š¤ Transferring patterns from: ${sourceProject}...\n`);
|
|
356
|
+
const result = await hookTransferTool.execute({
|
|
357
|
+
sourceProject,
|
|
358
|
+
minConfidence: options.minConfidence,
|
|
359
|
+
maxPatterns: options.maxPatterns,
|
|
360
|
+
mode: options.mode
|
|
361
|
+
}, mockContext);
|
|
362
|
+
if (options.json) {
|
|
363
|
+
console.log(JSON.stringify(result, null, 2));
|
|
364
|
+
}
|
|
365
|
+
else {
|
|
366
|
+
console.log(`\nā
Transfer Complete!`);
|
|
367
|
+
console.log(` š„ Patterns transferred: ${result.transferred}`);
|
|
368
|
+
console.log(` š Patterns adapted: ${result.adapted}`);
|
|
369
|
+
console.log(` šÆ Mode: ${result.mode}`);
|
|
370
|
+
if (result.targetStack?.length > 0) {
|
|
371
|
+
console.log(` š ļø Target stack: ${result.targetStack.join(', ')}`);
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
catch (error) {
|
|
376
|
+
console.error('Error:', error instanceof Error ? error.message : error);
|
|
377
|
+
process.exit(1);
|
|
378
|
+
}
|
|
379
|
+
});
|
|
380
|
+
// Init command (creates .claude/settings.json with hooks)
|
|
381
|
+
hooks
|
|
382
|
+
.command('init')
|
|
383
|
+
.description('Initialize hooks in project with .claude/settings.json')
|
|
384
|
+
.option('--minimal', 'Minimal configuration')
|
|
385
|
+
.option('--force', 'Overwrite existing configuration')
|
|
386
|
+
.action(async (options) => {
|
|
387
|
+
try {
|
|
388
|
+
const fs = await import('fs');
|
|
389
|
+
const settingsPath = path.join(process.cwd(), '.claude', 'settings.json');
|
|
390
|
+
const claudeDir = path.dirname(settingsPath);
|
|
391
|
+
// Check if exists
|
|
392
|
+
if (fs.existsSync(settingsPath) && !options.force) {
|
|
393
|
+
console.log('ā ļø Settings file already exists. Use --force to overwrite.');
|
|
394
|
+
return;
|
|
395
|
+
}
|
|
396
|
+
// Create .claude directory
|
|
397
|
+
if (!fs.existsSync(claudeDir)) {
|
|
398
|
+
fs.mkdirSync(claudeDir, { recursive: true });
|
|
399
|
+
}
|
|
400
|
+
// Create settings
|
|
401
|
+
const settings = {
|
|
402
|
+
hooks: {
|
|
403
|
+
PreToolUse: [
|
|
404
|
+
{
|
|
405
|
+
matcher: 'Edit|Write',
|
|
406
|
+
hooks: [
|
|
407
|
+
{
|
|
408
|
+
type: 'command',
|
|
409
|
+
command: 'agentic-flow hooks pre-edit "$TOOL_INPUT_file_path"'
|
|
410
|
+
}
|
|
411
|
+
]
|
|
412
|
+
},
|
|
413
|
+
{
|
|
414
|
+
matcher: 'Bash',
|
|
415
|
+
hooks: [
|
|
416
|
+
{
|
|
417
|
+
type: 'command',
|
|
418
|
+
command: 'agentic-flow hooks pre-command "$TOOL_INPUT_command"'
|
|
419
|
+
}
|
|
420
|
+
]
|
|
421
|
+
}
|
|
422
|
+
],
|
|
423
|
+
PostToolUse: [
|
|
424
|
+
{
|
|
425
|
+
matcher: 'Edit|Write',
|
|
426
|
+
hooks: [
|
|
427
|
+
{
|
|
428
|
+
type: 'command',
|
|
429
|
+
command: 'agentic-flow hooks post-edit "$TOOL_INPUT_file_path" --success'
|
|
430
|
+
}
|
|
431
|
+
]
|
|
432
|
+
}
|
|
433
|
+
],
|
|
434
|
+
SessionStart: [
|
|
435
|
+
{
|
|
436
|
+
type: 'command',
|
|
437
|
+
command: 'agentic-flow hooks metrics --json'
|
|
438
|
+
}
|
|
439
|
+
]
|
|
440
|
+
},
|
|
441
|
+
permissions: {
|
|
442
|
+
allow: [
|
|
443
|
+
'Bash(agentic-flow:*)',
|
|
444
|
+
'mcp__agentic-flow'
|
|
445
|
+
]
|
|
446
|
+
}
|
|
447
|
+
};
|
|
448
|
+
fs.writeFileSync(settingsPath, JSON.stringify(settings, null, 2));
|
|
449
|
+
console.log('ā
Hooks initialized!');
|
|
450
|
+
console.log(` š Created: ${settingsPath}`);
|
|
451
|
+
console.log('\nš” Next steps:');
|
|
452
|
+
console.log(' 1. Run: agentic-flow hooks pretrain');
|
|
453
|
+
console.log(' 2. Run: agentic-flow hooks build-agents');
|
|
454
|
+
console.log(' 3. Start using Claude Code with intelligent routing!');
|
|
455
|
+
}
|
|
456
|
+
catch (error) {
|
|
457
|
+
console.error('Error:', error instanceof Error ? error.message : error);
|
|
458
|
+
process.exit(1);
|
|
459
|
+
}
|
|
460
|
+
});
|
|
461
|
+
// ============================================
|
|
462
|
+
// RUVECTOR INTELLIGENCE COMMANDS
|
|
463
|
+
// SONA Micro-LoRA + MoE Attention + HNSW
|
|
464
|
+
// ============================================
|
|
465
|
+
// Create intelligence subcommand group
|
|
466
|
+
const intelligence = new Command('intelligence')
|
|
467
|
+
.alias('intel')
|
|
468
|
+
.description('RuVector intelligence: SONA Micro-LoRA (~0.05ms) + MoE attention + HNSW (150x faster)');
|
|
469
|
+
// Intelligence route command
|
|
470
|
+
intelligence
|
|
471
|
+
.command('route <task>')
|
|
472
|
+
.description('Route task using SONA + MoE + HNSW (150x faster than brute force)')
|
|
473
|
+
.option('-f, --file <path>', 'File context')
|
|
474
|
+
.option('-e, --error <context>', 'Error context for debugging')
|
|
475
|
+
.option('-k, --top-k <n>', 'Number of candidates', parseInt, 5)
|
|
476
|
+
.option('-j, --json', 'Output as JSON')
|
|
477
|
+
.action(async (task, options) => {
|
|
478
|
+
try {
|
|
479
|
+
const result = await intelligenceRouteTool.execute({ task, file: options.file, errorContext: options.error, topK: options.topK }, mockContext);
|
|
480
|
+
if (options.json) {
|
|
481
|
+
console.log(JSON.stringify(result, null, 2));
|
|
482
|
+
}
|
|
483
|
+
else {
|
|
484
|
+
console.log(`\nā” RuVector Intelligence Route`);
|
|
485
|
+
console.log(`šÆ Agent: ${result.agent}`);
|
|
486
|
+
console.log(`š Confidence: ${((result.confidence || 0) * 100).toFixed(1)}%`);
|
|
487
|
+
console.log(`š§ Engine: ${result.engine}`);
|
|
488
|
+
console.log(`ā±ļø Latency: ${result.latencyMs?.toFixed(2)}ms`);
|
|
489
|
+
if (result.features?.length > 0) {
|
|
490
|
+
console.log(`š§ Features: ${result.features.join(', ')}`);
|
|
491
|
+
}
|
|
492
|
+
if (result.alternatives?.length > 0) {
|
|
493
|
+
console.log(`\nš Alternatives:`);
|
|
494
|
+
result.alternatives.forEach((a) => {
|
|
495
|
+
console.log(` - ${a.agent} (${((a.confidence || 0) * 100).toFixed(1)}%)`);
|
|
496
|
+
});
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
catch (error) {
|
|
501
|
+
console.error('Error:', error instanceof Error ? error.message : error);
|
|
502
|
+
process.exit(1);
|
|
503
|
+
}
|
|
504
|
+
});
|
|
505
|
+
// Trajectory start command
|
|
506
|
+
intelligence
|
|
507
|
+
.command('trajectory-start <task>')
|
|
508
|
+
.description('Begin SONA trajectory for reinforcement learning')
|
|
509
|
+
.requiredOption('-a, --agent <name>', 'Agent executing the task')
|
|
510
|
+
.option('-c, --context <text>', 'Additional context')
|
|
511
|
+
.option('-j, --json', 'Output as JSON')
|
|
512
|
+
.action(async (task, options) => {
|
|
513
|
+
try {
|
|
514
|
+
const result = await intelligenceTrajectoryStartTool.execute({ task, agent: options.agent, context: options.context }, mockContext);
|
|
515
|
+
if (options.json) {
|
|
516
|
+
console.log(JSON.stringify(result, null, 2));
|
|
517
|
+
}
|
|
518
|
+
else {
|
|
519
|
+
console.log(`\nš¬ Trajectory Started`);
|
|
520
|
+
console.log(`š ID: ${result.trajectoryId}`);
|
|
521
|
+
console.log(`š¤ Agent: ${options.agent}`);
|
|
522
|
+
console.log(`š§ Features: ${result.features?.join(', ')}`);
|
|
523
|
+
console.log(`\nš” Use this ID with trajectory-step and trajectory-end commands`);
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
catch (error) {
|
|
527
|
+
console.error('Error:', error instanceof Error ? error.message : error);
|
|
528
|
+
process.exit(1);
|
|
529
|
+
}
|
|
530
|
+
});
|
|
531
|
+
// Trajectory step command
|
|
532
|
+
intelligence
|
|
533
|
+
.command('trajectory-step <trajectoryId>')
|
|
534
|
+
.description('Record step in trajectory for reinforcement learning')
|
|
535
|
+
.requiredOption('-a, --action <action>', 'Action taken')
|
|
536
|
+
.requiredOption('-r, --reward <n>', 'Reward signal (-1 to 1)', parseFloat)
|
|
537
|
+
.option('-f, --file <path>', 'File involved')
|
|
538
|
+
.option('--error-fixed', 'Mark as error fix')
|
|
539
|
+
.option('--test-passed', 'Mark as test passed')
|
|
540
|
+
.option('-j, --json', 'Output as JSON')
|
|
541
|
+
.action(async (trajectoryId, options) => {
|
|
542
|
+
try {
|
|
543
|
+
const result = await intelligenceTrajectoryStepTool.execute({
|
|
544
|
+
trajectoryId: parseInt(trajectoryId),
|
|
545
|
+
action: options.action,
|
|
546
|
+
reward: options.reward,
|
|
547
|
+
file: options.file,
|
|
548
|
+
errorFixed: options.errorFixed,
|
|
549
|
+
testPassed: options.testPassed
|
|
550
|
+
}, mockContext);
|
|
551
|
+
if (options.json) {
|
|
552
|
+
console.log(JSON.stringify(result, null, 2));
|
|
553
|
+
}
|
|
554
|
+
else {
|
|
555
|
+
console.log(`\nš Step Recorded`);
|
|
556
|
+
console.log(` Action: ${options.action}`);
|
|
557
|
+
console.log(` Reward: ${options.reward}`);
|
|
558
|
+
console.log(` Trajectory: ${trajectoryId}`);
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
catch (error) {
|
|
562
|
+
console.error('Error:', error instanceof Error ? error.message : error);
|
|
563
|
+
process.exit(1);
|
|
564
|
+
}
|
|
565
|
+
});
|
|
566
|
+
// Trajectory end command
|
|
567
|
+
intelligence
|
|
568
|
+
.command('trajectory-end <trajectoryId>')
|
|
569
|
+
.description('End trajectory and trigger SONA learning with EWC++')
|
|
570
|
+
.option('-s, --success', 'Mark as successful')
|
|
571
|
+
.option('-f, --fail', 'Mark as failed')
|
|
572
|
+
.option('-q, --quality <n>', 'Quality score (0-1)', parseFloat, 0.8)
|
|
573
|
+
.option('-j, --json', 'Output as JSON')
|
|
574
|
+
.action(async (trajectoryId, options) => {
|
|
575
|
+
try {
|
|
576
|
+
const success = options.success || !options.fail;
|
|
577
|
+
const result = await intelligenceTrajectoryEndTool.execute({ trajectoryId: parseInt(trajectoryId), success, quality: options.quality }, mockContext);
|
|
578
|
+
if (options.json) {
|
|
579
|
+
console.log(JSON.stringify(result, null, 2));
|
|
580
|
+
}
|
|
581
|
+
else {
|
|
582
|
+
console.log(`\nš Trajectory Completed`);
|
|
583
|
+
console.log(` ${success ? 'ā
Success' : 'ā Failed'}`);
|
|
584
|
+
console.log(` Quality: ${(options.quality || 0.8) * 100}%`);
|
|
585
|
+
console.log(` Learning: EWC++ consolidation applied`);
|
|
586
|
+
if (result.learningOutcome) {
|
|
587
|
+
console.log(` Outcome: ${JSON.stringify(result.learningOutcome)}`);
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
catch (error) {
|
|
592
|
+
console.error('Error:', error instanceof Error ? error.message : error);
|
|
593
|
+
process.exit(1);
|
|
594
|
+
}
|
|
595
|
+
});
|
|
596
|
+
// Pattern store command
|
|
597
|
+
intelligence
|
|
598
|
+
.command('pattern-store')
|
|
599
|
+
.description('Store pattern in ReasoningBank (HNSW-indexed)')
|
|
600
|
+
.requiredOption('-t, --task <task>', 'Task description')
|
|
601
|
+
.requiredOption('-r, --resolution <text>', 'How it was resolved')
|
|
602
|
+
.option('-s, --score <n>', 'Success score (0-1)', parseFloat, 0.9)
|
|
603
|
+
.option('-j, --json', 'Output as JSON')
|
|
604
|
+
.action(async (options) => {
|
|
605
|
+
try {
|
|
606
|
+
const result = await intelligencePatternStoreTool.execute({ task: options.task, resolution: options.resolution, reward: options.score || 0.9 }, mockContext);
|
|
607
|
+
if (options.json) {
|
|
608
|
+
console.log(JSON.stringify(result, null, 2));
|
|
609
|
+
}
|
|
610
|
+
else {
|
|
611
|
+
console.log(`\nš¾ Pattern Stored`);
|
|
612
|
+
console.log(` Task: ${options.task.slice(0, 50)}...`);
|
|
613
|
+
console.log(` Score: ${((options.score || 0.9) * 100).toFixed(0)}%`);
|
|
614
|
+
console.log(` Index: HNSW (150x faster retrieval)`);
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
catch (error) {
|
|
618
|
+
console.error('Error:', error instanceof Error ? error.message : error);
|
|
619
|
+
process.exit(1);
|
|
620
|
+
}
|
|
621
|
+
});
|
|
622
|
+
// Pattern search command
|
|
623
|
+
intelligence
|
|
624
|
+
.command('pattern-search <query>')
|
|
625
|
+
.description('Search ReasoningBank using HNSW (150x faster)')
|
|
626
|
+
.option('-k, --top-k <n>', 'Number of results', parseInt, 5)
|
|
627
|
+
.option('-m, --min-reward <n>', 'Minimum reward filter', parseFloat)
|
|
628
|
+
.option('-j, --json', 'Output as JSON')
|
|
629
|
+
.action(async (query, options) => {
|
|
630
|
+
try {
|
|
631
|
+
const result = await intelligencePatternSearchTool.execute({ query, topK: options.topK, minReward: options.minReward }, mockContext);
|
|
632
|
+
if (options.json) {
|
|
633
|
+
console.log(JSON.stringify(result, null, 2));
|
|
634
|
+
}
|
|
635
|
+
else {
|
|
636
|
+
console.log(`\nš Pattern Search Results`);
|
|
637
|
+
console.log(` Query: "${query.slice(0, 50)}"`);
|
|
638
|
+
console.log(` Engine: ${result.searchEngine}`);
|
|
639
|
+
console.log(` Found: ${result.count} patterns`);
|
|
640
|
+
if (result.patterns?.length > 0) {
|
|
641
|
+
console.log(`\n š Results:`);
|
|
642
|
+
result.patterns.forEach((p, i) => {
|
|
643
|
+
console.log(` ${i + 1}. [${((p.similarity || 0) * 100).toFixed(0)}%] ${p.resolution?.slice(0, 40)}...`);
|
|
644
|
+
});
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
catch (error) {
|
|
649
|
+
console.error('Error:', error instanceof Error ? error.message : error);
|
|
650
|
+
process.exit(1);
|
|
651
|
+
}
|
|
652
|
+
});
|
|
653
|
+
// Intelligence stats command
|
|
654
|
+
intelligence
|
|
655
|
+
.command('stats')
|
|
656
|
+
.description('Get RuVector intelligence layer statistics')
|
|
657
|
+
.option('-j, --json', 'Output as JSON')
|
|
658
|
+
.action(async (options) => {
|
|
659
|
+
try {
|
|
660
|
+
const result = await intelligenceStatsTool.execute({}, mockContext);
|
|
661
|
+
if (options.json) {
|
|
662
|
+
console.log(JSON.stringify(result, null, 2));
|
|
663
|
+
}
|
|
664
|
+
else {
|
|
665
|
+
console.log(`\nš RuVector Intelligence Stats`);
|
|
666
|
+
console.log(`\nš§ SONA Engine:`);
|
|
667
|
+
console.log(` Micro-LoRA: ${result.features?.sona?.microLora || 'rank-1 (~0.05ms)'}`);
|
|
668
|
+
console.log(` Base-LoRA: ${result.features?.sona?.baseLora || 'rank-8'}`);
|
|
669
|
+
console.log(` EWC Lambda: ${result.features?.sona?.ewcLambda || 1000.0}`);
|
|
670
|
+
console.log(`\nā” Attention:`);
|
|
671
|
+
console.log(` Type: ${result.features?.attention?.type || 'moe'}`);
|
|
672
|
+
console.log(` Experts: ${result.features?.attention?.experts || 4}`);
|
|
673
|
+
console.log(` Top-K: ${result.features?.attention?.topK || 2}`);
|
|
674
|
+
console.log(`\nš HNSW:`);
|
|
675
|
+
console.log(` Enabled: ${result.features?.hnsw?.enabled ?? true}`);
|
|
676
|
+
console.log(` Speedup: ${result.features?.hnsw?.speedup || '150x vs brute-force'}`);
|
|
677
|
+
console.log(`\nš Learning:`);
|
|
678
|
+
console.log(` Trajectories: ${result.stats?.trajectoryCount || 0}`);
|
|
679
|
+
console.log(` Active: ${result.stats?.activeTrajectories || 0}`);
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
catch (error) {
|
|
683
|
+
console.error('Error:', error instanceof Error ? error.message : error);
|
|
684
|
+
process.exit(1);
|
|
685
|
+
}
|
|
686
|
+
});
|
|
687
|
+
// Force learning command
|
|
688
|
+
intelligence
|
|
689
|
+
.command('learn')
|
|
690
|
+
.description('Force immediate SONA learning cycle with EWC++ consolidation')
|
|
691
|
+
.option('-r, --reason <text>', 'Reason for forcing learning')
|
|
692
|
+
.option('-j, --json', 'Output as JSON')
|
|
693
|
+
.action(async (options) => {
|
|
694
|
+
try {
|
|
695
|
+
const result = await intelligenceLearnTool.execute({ reason: options.reason }, mockContext);
|
|
696
|
+
if (options.json) {
|
|
697
|
+
console.log(JSON.stringify(result, null, 2));
|
|
698
|
+
}
|
|
699
|
+
else {
|
|
700
|
+
console.log(`\nš Learning Cycle Complete`);
|
|
701
|
+
console.log(` ${result.success ? 'ā
' : 'ā'} ${result.message}`);
|
|
702
|
+
console.log(` Reason: ${result.reason || 'manual trigger'}`);
|
|
703
|
+
console.log(` Features: ${result.features?.join(', ')}`);
|
|
704
|
+
console.log(` Latency: ${result.latencyMs?.toFixed(2)}ms`);
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
catch (error) {
|
|
708
|
+
console.error('Error:', error instanceof Error ? error.message : error);
|
|
709
|
+
process.exit(1);
|
|
710
|
+
}
|
|
711
|
+
});
|
|
712
|
+
// Attention compute command
|
|
713
|
+
intelligence
|
|
714
|
+
.command('attention <query>')
|
|
715
|
+
.description('Compute attention-weighted similarity using MoE/Flash/Hyperbolic')
|
|
716
|
+
.requiredOption('-c, --candidates <texts...>', 'Candidate texts to score')
|
|
717
|
+
.option('-t, --type <type>', 'Attention type: moe|flash|hyperbolic|graph|dual', 'moe')
|
|
718
|
+
.option('-j, --json', 'Output as JSON')
|
|
719
|
+
.action(async (query, options) => {
|
|
720
|
+
try {
|
|
721
|
+
const result = await intelligenceAttentionTool.execute({
|
|
722
|
+
query,
|
|
723
|
+
candidates: options.candidates,
|
|
724
|
+
attentionType: options.type
|
|
725
|
+
}, mockContext);
|
|
726
|
+
if (options.json) {
|
|
727
|
+
console.log(JSON.stringify(result, null, 2));
|
|
728
|
+
}
|
|
729
|
+
else {
|
|
730
|
+
console.log(`\nš§ Attention Scores (${options.type || 'moe'})`);
|
|
731
|
+
console.log(` Query: "${query.slice(0, 40)}..."`);
|
|
732
|
+
console.log(`\n š Results:`);
|
|
733
|
+
result.results?.forEach((r, i) => {
|
|
734
|
+
const bar = 'ā'.repeat(Math.round(r.score * 20));
|
|
735
|
+
console.log(` ${i + 1}. ${bar} ${(r.score * 100).toFixed(1)}% "${r.text}"`);
|
|
736
|
+
});
|
|
737
|
+
console.log(`\n ā±ļø Latency: ${result.latencyMs?.toFixed(2)}ms`);
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
catch (error) {
|
|
741
|
+
console.error('Error:', error instanceof Error ? error.message : error);
|
|
742
|
+
process.exit(1);
|
|
743
|
+
}
|
|
744
|
+
});
|
|
745
|
+
// Add intelligence subcommand to hooks
|
|
746
|
+
hooks.addCommand(intelligence);
|
|
747
|
+
return hooks;
|
|
748
|
+
}
|
|
749
|
+
export default createHooksCommand;
|
|
750
|
+
//# sourceMappingURL=hooks.js.map
|