claude-flow 3.5.70 → 3.5.72
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/package.json +1 -1
- package/v3/@claude-flow/cli/dist/src/commands/plugins.js +6 -0
- package/v3/@claude-flow/cli/dist/src/commands/security.js +350 -34
- package/v3/@claude-flow/cli/dist/src/commands/swarm.js +100 -15
- package/v3/@claude-flow/cli/dist/src/mcp-tools/agent-tools.js +35 -1
- package/v3/@claude-flow/cli/dist/src/mcp-tools/agentdb-tools.js +81 -0
- package/v3/@claude-flow/cli/dist/src/mcp-tools/analyze-tools.js +29 -0
- package/v3/@claude-flow/cli/dist/src/mcp-tools/autopilot-tools.js +4 -0
- package/v3/@claude-flow/cli/dist/src/mcp-tools/browser-tools.js +146 -0
- package/v3/@claude-flow/cli/dist/src/mcp-tools/claims-tools.js +116 -0
- package/v3/@claude-flow/cli/dist/src/mcp-tools/coordination-tools.js +31 -0
- package/v3/@claude-flow/cli/dist/src/mcp-tools/daa-tools.js +61 -0
- package/v3/@claude-flow/cli/dist/src/mcp-tools/embeddings-tools.js +26 -0
- package/v3/@claude-flow/cli/dist/src/mcp-tools/github-tools.js +96 -0
- package/v3/@claude-flow/cli/dist/src/mcp-tools/guidance-tools.js +21 -0
- package/v3/@claude-flow/cli/dist/src/mcp-tools/hive-mind-tools.js +56 -0
- package/v3/@claude-flow/cli/dist/src/mcp-tools/hooks-tools.js +231 -13
- package/v3/@claude-flow/cli/dist/src/mcp-tools/memory-tools.js +18 -2
- package/v3/@claude-flow/cli/dist/src/mcp-tools/neural-tools.js +92 -2
- package/v3/@claude-flow/cli/dist/src/mcp-tools/performance-tools.js +18 -5
- package/v3/@claude-flow/cli/dist/src/mcp-tools/ruvllm-tools.js +31 -0
- package/v3/@claude-flow/cli/dist/src/mcp-tools/security-tools.js +36 -0
- package/v3/@claude-flow/cli/dist/src/mcp-tools/system-tools.js +59 -18
- package/v3/@claude-flow/cli/dist/src/mcp-tools/transfer-tools.js +51 -0
- package/v3/@claude-flow/cli/dist/src/mcp-tools/wasm-agent-tools.js +61 -0
- package/v3/@claude-flow/cli/package.json +1 -1
- package/v3/@claude-flow/guidance/dist/adversarial.d.ts +284 -0
- package/v3/@claude-flow/guidance/dist/adversarial.js +572 -0
- package/v3/@claude-flow/guidance/dist/analyzer.d.ts +530 -0
- package/v3/@claude-flow/guidance/dist/analyzer.js +2518 -0
- package/v3/@claude-flow/guidance/dist/artifacts.d.ts +283 -0
- package/v3/@claude-flow/guidance/dist/artifacts.js +356 -0
- package/v3/@claude-flow/guidance/dist/authority.d.ts +290 -0
- package/v3/@claude-flow/guidance/dist/authority.js +558 -0
- package/v3/@claude-flow/guidance/dist/capabilities.d.ts +209 -0
- package/v3/@claude-flow/guidance/dist/capabilities.js +485 -0
- package/v3/@claude-flow/guidance/dist/coherence.d.ts +233 -0
- package/v3/@claude-flow/guidance/dist/coherence.js +372 -0
- package/v3/@claude-flow/guidance/dist/compiler.d.ts +87 -0
- package/v3/@claude-flow/guidance/dist/compiler.js +419 -0
- package/v3/@claude-flow/guidance/dist/conformance-kit.d.ts +225 -0
- package/v3/@claude-flow/guidance/dist/conformance-kit.js +629 -0
- package/v3/@claude-flow/guidance/dist/continue-gate.d.ts +214 -0
- package/v3/@claude-flow/guidance/dist/continue-gate.js +353 -0
- package/v3/@claude-flow/guidance/dist/crypto-utils.d.ts +17 -0
- package/v3/@claude-flow/guidance/dist/crypto-utils.js +24 -0
- package/v3/@claude-flow/guidance/dist/evolution.d.ts +282 -0
- package/v3/@claude-flow/guidance/dist/evolution.js +500 -0
- package/v3/@claude-flow/guidance/dist/gates.d.ts +79 -0
- package/v3/@claude-flow/guidance/dist/gates.js +302 -0
- package/v3/@claude-flow/guidance/dist/gateway.d.ts +206 -0
- package/v3/@claude-flow/guidance/dist/gateway.js +452 -0
- package/v3/@claude-flow/guidance/dist/generators.d.ts +153 -0
- package/v3/@claude-flow/guidance/dist/generators.js +682 -0
- package/v3/@claude-flow/guidance/dist/headless.d.ts +177 -0
- package/v3/@claude-flow/guidance/dist/headless.js +342 -0
- package/v3/@claude-flow/guidance/dist/hooks.d.ts +109 -0
- package/v3/@claude-flow/guidance/dist/hooks.js +347 -0
- package/v3/@claude-flow/guidance/dist/index.d.ts +205 -0
- package/v3/@claude-flow/guidance/dist/index.js +321 -0
- package/v3/@claude-flow/guidance/dist/ledger.d.ts +162 -0
- package/v3/@claude-flow/guidance/dist/ledger.js +375 -0
- package/v3/@claude-flow/guidance/dist/manifest-validator.d.ts +289 -0
- package/v3/@claude-flow/guidance/dist/manifest-validator.js +838 -0
- package/v3/@claude-flow/guidance/dist/memory-gate.d.ts +222 -0
- package/v3/@claude-flow/guidance/dist/memory-gate.js +382 -0
- package/v3/@claude-flow/guidance/dist/meta-governance.d.ts +265 -0
- package/v3/@claude-flow/guidance/dist/meta-governance.js +348 -0
- package/v3/@claude-flow/guidance/dist/optimizer.d.ts +104 -0
- package/v3/@claude-flow/guidance/dist/optimizer.js +329 -0
- package/v3/@claude-flow/guidance/dist/persistence.d.ts +189 -0
- package/v3/@claude-flow/guidance/dist/persistence.js +464 -0
- package/v3/@claude-flow/guidance/dist/proof.d.ts +185 -0
- package/v3/@claude-flow/guidance/dist/proof.js +238 -0
- package/v3/@claude-flow/guidance/dist/retriever.d.ts +116 -0
- package/v3/@claude-flow/guidance/dist/retriever.js +394 -0
- package/v3/@claude-flow/guidance/dist/ruvbot-integration.d.ts +370 -0
- package/v3/@claude-flow/guidance/dist/ruvbot-integration.js +738 -0
- package/v3/@claude-flow/guidance/dist/temporal.d.ts +426 -0
- package/v3/@claude-flow/guidance/dist/temporal.js +658 -0
- package/v3/@claude-flow/guidance/dist/trust.d.ts +283 -0
- package/v3/@claude-flow/guidance/dist/trust.js +473 -0
- package/v3/@claude-flow/guidance/dist/truth-anchors.d.ts +276 -0
- package/v3/@claude-flow/guidance/dist/truth-anchors.js +488 -0
- package/v3/@claude-flow/guidance/dist/types.d.ts +378 -0
- package/v3/@claude-flow/guidance/dist/types.js +10 -0
- package/v3/@claude-flow/guidance/dist/uncertainty.d.ts +372 -0
- package/v3/@claude-flow/guidance/dist/uncertainty.js +619 -0
- package/v3/@claude-flow/guidance/dist/wasm-kernel.d.ts +48 -0
- package/v3/@claude-flow/guidance/dist/wasm-kernel.js +158 -0
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
import { existsSync, readFileSync, writeFileSync, mkdirSync } from 'node:fs';
|
|
7
7
|
import { join } from 'node:path';
|
|
8
8
|
import { getProjectCwd } from './types.js';
|
|
9
|
+
import { validateIdentifier, validateText } from './validate-input.js';
|
|
9
10
|
// Storage paths
|
|
10
11
|
const STORAGE_DIR = '.claude-flow';
|
|
11
12
|
const HIVE_DIR = 'hive-mind';
|
|
@@ -158,6 +159,16 @@ export const hiveMindTools = [
|
|
|
158
159
|
if (!state.initialized) {
|
|
159
160
|
return { success: false, error: 'Hive-mind not initialized. Run hive-mind/init first.' };
|
|
160
161
|
}
|
|
162
|
+
if (input.agentType) {
|
|
163
|
+
const v = validateIdentifier(input.agentType, 'agentType');
|
|
164
|
+
if (!v.valid)
|
|
165
|
+
return { success: false, error: v.error };
|
|
166
|
+
}
|
|
167
|
+
if (input.prefix) {
|
|
168
|
+
const v = validateIdentifier(input.prefix, 'prefix');
|
|
169
|
+
if (!v.valid)
|
|
170
|
+
return { success: false, error: v.error };
|
|
171
|
+
}
|
|
161
172
|
const count = Math.min(Math.max(1, input.count || 1), 20); // Cap at 20
|
|
162
173
|
const role = input.role || 'worker';
|
|
163
174
|
const agentType = input.agentType || 'worker';
|
|
@@ -211,6 +222,11 @@ export const hiveMindTools = [
|
|
|
211
222
|
},
|
|
212
223
|
},
|
|
213
224
|
handler: async (input) => {
|
|
225
|
+
if (input.queenId) {
|
|
226
|
+
const v = validateIdentifier(input.queenId, 'queenId');
|
|
227
|
+
if (!v.valid)
|
|
228
|
+
return { success: false, error: v.error };
|
|
229
|
+
}
|
|
214
230
|
const state = loadHiveState();
|
|
215
231
|
const hiveId = `hive-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
|
|
216
232
|
const queenId = input.queenId || `queen-${Date.now()}`;
|
|
@@ -354,6 +370,11 @@ export const hiveMindTools = [
|
|
|
354
370
|
handler: async (input) => {
|
|
355
371
|
const state = loadHiveState();
|
|
356
372
|
const agentId = input.agentId;
|
|
373
|
+
{
|
|
374
|
+
const v = validateIdentifier(agentId, 'agentId');
|
|
375
|
+
if (!v.valid)
|
|
376
|
+
return { success: false, error: v.error };
|
|
377
|
+
}
|
|
357
378
|
if (!state.initialized) {
|
|
358
379
|
return { success: false, error: 'Hive-mind not initialized' };
|
|
359
380
|
}
|
|
@@ -384,6 +405,11 @@ export const hiveMindTools = [
|
|
|
384
405
|
handler: async (input) => {
|
|
385
406
|
const state = loadHiveState();
|
|
386
407
|
const agentId = input.agentId;
|
|
408
|
+
{
|
|
409
|
+
const v = validateIdentifier(agentId, 'agentId');
|
|
410
|
+
if (!v.valid)
|
|
411
|
+
return { success: false, agentId, error: v.error };
|
|
412
|
+
}
|
|
387
413
|
const index = state.workers.indexOf(agentId);
|
|
388
414
|
if (index > -1) {
|
|
389
415
|
state.workers.splice(index, 1);
|
|
@@ -419,6 +445,21 @@ export const hiveMindTools = [
|
|
|
419
445
|
required: ['action'],
|
|
420
446
|
},
|
|
421
447
|
handler: async (input) => {
|
|
448
|
+
if (input.proposalId) {
|
|
449
|
+
const v = validateIdentifier(input.proposalId, 'proposalId');
|
|
450
|
+
if (!v.valid)
|
|
451
|
+
return { action: input.action, error: v.error };
|
|
452
|
+
}
|
|
453
|
+
if (input.voterId) {
|
|
454
|
+
const v = validateIdentifier(input.voterId, 'voterId');
|
|
455
|
+
if (!v.valid)
|
|
456
|
+
return { action: input.action, error: v.error };
|
|
457
|
+
}
|
|
458
|
+
if (input.type) {
|
|
459
|
+
const v = validateText(input.type, 'type');
|
|
460
|
+
if (!v.valid)
|
|
461
|
+
return { action: input.action, error: v.error };
|
|
462
|
+
}
|
|
422
463
|
const state = loadHiveState();
|
|
423
464
|
const action = input.action;
|
|
424
465
|
const strategy = input.strategy || 'raft';
|
|
@@ -687,6 +728,16 @@ export const hiveMindTools = [
|
|
|
687
728
|
if (!state.initialized) {
|
|
688
729
|
return { success: false, error: 'Hive-mind not initialized' };
|
|
689
730
|
}
|
|
731
|
+
{
|
|
732
|
+
const v = validateText(input.message, 'message');
|
|
733
|
+
if (!v.valid)
|
|
734
|
+
return { success: false, error: v.error };
|
|
735
|
+
}
|
|
736
|
+
if (input.fromId) {
|
|
737
|
+
const v = validateIdentifier(input.fromId, 'fromId');
|
|
738
|
+
if (!v.valid)
|
|
739
|
+
return { success: false, error: v.error };
|
|
740
|
+
}
|
|
690
741
|
const messageId = `msg-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
|
|
691
742
|
// Store in shared memory
|
|
692
743
|
const messages = state.sharedMemory.broadcasts || [];
|
|
@@ -781,6 +832,11 @@ export const hiveMindTools = [
|
|
|
781
832
|
required: ['action'],
|
|
782
833
|
},
|
|
783
834
|
handler: async (input) => {
|
|
835
|
+
if (input.key) {
|
|
836
|
+
const v = validateIdentifier(input.key, 'key');
|
|
837
|
+
if (!v.valid)
|
|
838
|
+
return { action: input.action, error: v.error };
|
|
839
|
+
}
|
|
784
840
|
const state = loadHiveState();
|
|
785
841
|
const action = input.action;
|
|
786
842
|
const key = input.key;
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
import { mkdirSync, writeFileSync, existsSync, readFileSync, statSync, unlinkSync, readdirSync } from 'fs';
|
|
6
6
|
import { dirname, join, resolve } from 'path';
|
|
7
7
|
import { getProjectCwd } from './types.js';
|
|
8
|
+
import { validateIdentifier, validateText, validatePath } from './validate-input.js';
|
|
8
9
|
// Real vector search functions - lazy loaded to avoid circular imports
|
|
9
10
|
let searchEntriesFn = null;
|
|
10
11
|
async function getRealSearchFunction() {
|
|
@@ -578,6 +579,11 @@ export const hooksPreEdit = {
|
|
|
578
579
|
handler: async (params) => {
|
|
579
580
|
const filePath = params.filePath;
|
|
580
581
|
const operation = params.operation || 'update';
|
|
582
|
+
{
|
|
583
|
+
const v = validatePath(filePath, 'filePath');
|
|
584
|
+
if (!v.valid)
|
|
585
|
+
return { success: false, error: v.error };
|
|
586
|
+
}
|
|
581
587
|
const suggestedAgents = suggestAgentsForFile(filePath);
|
|
582
588
|
const ext = getFileExtension(filePath);
|
|
583
589
|
return {
|
|
@@ -616,6 +622,16 @@ export const hooksPostEdit = {
|
|
|
616
622
|
const filePath = params.filePath;
|
|
617
623
|
const success = params.success !== false;
|
|
618
624
|
const agent = params.agent;
|
|
625
|
+
{
|
|
626
|
+
const v = validatePath(filePath, 'filePath');
|
|
627
|
+
if (!v.valid)
|
|
628
|
+
return { success: false, error: v.error };
|
|
629
|
+
}
|
|
630
|
+
if (agent) {
|
|
631
|
+
const v = validateIdentifier(agent, 'agent');
|
|
632
|
+
if (!v.valid)
|
|
633
|
+
return { success: false, error: v.error };
|
|
634
|
+
}
|
|
619
635
|
// Wire recordFeedback through bridge (issue #1209)
|
|
620
636
|
let feedbackResult = null;
|
|
621
637
|
try {
|
|
@@ -656,6 +672,11 @@ export const hooksPreCommand = {
|
|
|
656
672
|
},
|
|
657
673
|
handler: async (params) => {
|
|
658
674
|
const command = params.command;
|
|
675
|
+
{
|
|
676
|
+
const v = validateText(command, 'command');
|
|
677
|
+
if (!v.valid)
|
|
678
|
+
return { success: false, error: v.error };
|
|
679
|
+
}
|
|
659
680
|
const assessment = assessCommandRisk(command);
|
|
660
681
|
const riskLevel = assessment.level >= 0.8 ? 'critical'
|
|
661
682
|
: assessment.level >= 0.6 ? 'high'
|
|
@@ -692,6 +713,11 @@ export const hooksPostCommand = {
|
|
|
692
713
|
const command = params.command;
|
|
693
714
|
const exitCode = params.exitCode || 0;
|
|
694
715
|
const success = exitCode === 0;
|
|
716
|
+
{
|
|
717
|
+
const v = validateText(command, 'command');
|
|
718
|
+
if (!v.valid)
|
|
719
|
+
return { success: false, error: v.error };
|
|
720
|
+
}
|
|
695
721
|
// Persist command outcome via AgentDB
|
|
696
722
|
let _storedIn = 'none';
|
|
697
723
|
try {
|
|
@@ -744,6 +770,16 @@ export const hooksRoute = {
|
|
|
744
770
|
const task = params.task;
|
|
745
771
|
const context = params.context;
|
|
746
772
|
const useSemanticRouter = params.useSemanticRouter !== false;
|
|
773
|
+
{
|
|
774
|
+
const v = validateText(task, 'task');
|
|
775
|
+
if (!v.valid)
|
|
776
|
+
return { success: false, error: v.error };
|
|
777
|
+
}
|
|
778
|
+
if (context) {
|
|
779
|
+
const v = validateText(context, 'context');
|
|
780
|
+
if (!v.valid)
|
|
781
|
+
return { success: false, error: v.error };
|
|
782
|
+
}
|
|
747
783
|
// Phase 5: Try AgentDB's SemanticRouter / LearningSystem first
|
|
748
784
|
if (useSemanticRouter) {
|
|
749
785
|
try {
|
|
@@ -1011,6 +1047,21 @@ export const hooksPreTask = {
|
|
|
1011
1047
|
const taskId = params.taskId;
|
|
1012
1048
|
const description = params.description;
|
|
1013
1049
|
const filePath = params.filePath;
|
|
1050
|
+
{
|
|
1051
|
+
const v = validateIdentifier(taskId, 'taskId');
|
|
1052
|
+
if (!v.valid)
|
|
1053
|
+
return { success: false, error: v.error };
|
|
1054
|
+
}
|
|
1055
|
+
{
|
|
1056
|
+
const v = validateText(description, 'description');
|
|
1057
|
+
if (!v.valid)
|
|
1058
|
+
return { success: false, error: v.error };
|
|
1059
|
+
}
|
|
1060
|
+
if (filePath) {
|
|
1061
|
+
const v = validatePath(filePath, 'filePath');
|
|
1062
|
+
if (!v.valid)
|
|
1063
|
+
return { success: false, error: v.error };
|
|
1064
|
+
}
|
|
1014
1065
|
const suggestion = suggestAgentsForTask(description);
|
|
1015
1066
|
// Determine complexity
|
|
1016
1067
|
const descLower = description.toLowerCase();
|
|
@@ -1099,6 +1150,16 @@ export const hooksPostTask = {
|
|
|
1099
1150
|
const agent = params.agent;
|
|
1100
1151
|
const quality = params.quality || (success ? 0.85 : 0.3);
|
|
1101
1152
|
const startTime = Date.now();
|
|
1153
|
+
{
|
|
1154
|
+
const v = validateIdentifier(taskId, 'taskId');
|
|
1155
|
+
if (!v.valid)
|
|
1156
|
+
return { success: false, error: v.error };
|
|
1157
|
+
}
|
|
1158
|
+
if (agent) {
|
|
1159
|
+
const v = validateIdentifier(agent, 'agent');
|
|
1160
|
+
if (!v.valid)
|
|
1161
|
+
return { success: false, error: v.error };
|
|
1162
|
+
}
|
|
1102
1163
|
// Phase 3: Wire recordFeedback through bridge → LearningSystem + ReasoningBank
|
|
1103
1164
|
let feedbackResult = null;
|
|
1104
1165
|
try {
|
|
@@ -1234,6 +1295,11 @@ export const hooksExplain = {
|
|
|
1234
1295
|
},
|
|
1235
1296
|
handler: async (params) => {
|
|
1236
1297
|
const task = params.task;
|
|
1298
|
+
{
|
|
1299
|
+
const v = validateText(task, 'task');
|
|
1300
|
+
if (!v.valid)
|
|
1301
|
+
return { success: false, error: v.error };
|
|
1302
|
+
}
|
|
1237
1303
|
const suggestion = suggestAgentsForTask(task);
|
|
1238
1304
|
const taskLower = task.toLowerCase();
|
|
1239
1305
|
// Determine matched patterns
|
|
@@ -1469,6 +1535,16 @@ export const hooksTransfer = {
|
|
|
1469
1535
|
const sourcePath = params.sourcePath;
|
|
1470
1536
|
const minConfidence = params.minConfidence || 0.7;
|
|
1471
1537
|
const filter = params.filter;
|
|
1538
|
+
{
|
|
1539
|
+
const v = validatePath(sourcePath, 'sourcePath');
|
|
1540
|
+
if (!v.valid)
|
|
1541
|
+
return { success: false, error: v.error };
|
|
1542
|
+
}
|
|
1543
|
+
if (filter) {
|
|
1544
|
+
const v = validateIdentifier(filter, 'filter');
|
|
1545
|
+
if (!v.valid)
|
|
1546
|
+
return { success: false, error: v.error };
|
|
1547
|
+
}
|
|
1472
1548
|
// Try to load patterns from source project's memory store
|
|
1473
1549
|
const sourceMemoryPath = join(resolve(sourcePath), MEMORY_DIR, MEMORY_FILE);
|
|
1474
1550
|
let sourceStore = { entries: {}, version: '3.0.0' };
|
|
@@ -1540,6 +1616,11 @@ export const hooksSessionStart = {
|
|
|
1540
1616
|
const sessionId = params.sessionId || `session-${Date.now()}`;
|
|
1541
1617
|
const restoreLatest = params.restoreLatest;
|
|
1542
1618
|
const shouldStartDaemon = params.startDaemon === true;
|
|
1619
|
+
if (params.sessionId) {
|
|
1620
|
+
const v = validateIdentifier(params.sessionId, 'sessionId');
|
|
1621
|
+
if (!v.valid)
|
|
1622
|
+
return { success: false, error: v.error };
|
|
1623
|
+
}
|
|
1543
1624
|
// Auto-regenerate statusline if outdated (fixes older installs)
|
|
1544
1625
|
// Checks for the old fake heuristic: "Math.floor(sizeKB / 2)"
|
|
1545
1626
|
try {
|
|
@@ -1765,6 +1846,11 @@ export const hooksSessionRestore = {
|
|
|
1765
1846
|
const requestedId = params.sessionId || 'latest';
|
|
1766
1847
|
const restoreAgents = params.restoreAgents !== false;
|
|
1767
1848
|
const restoreTasks = params.restoreTasks !== false;
|
|
1849
|
+
if (params.sessionId) {
|
|
1850
|
+
const v = validateIdentifier(params.sessionId, 'sessionId');
|
|
1851
|
+
if (!v.valid)
|
|
1852
|
+
return { success: false, error: v.error };
|
|
1853
|
+
}
|
|
1768
1854
|
const originalSessionId = requestedId === 'latest' ? `session-${Date.now() - 86400000}` : requestedId;
|
|
1769
1855
|
const newSessionId = `session-${Date.now()}`;
|
|
1770
1856
|
// Get real memory entry count
|
|
@@ -1804,6 +1890,16 @@ export const hooksNotify = {
|
|
|
1804
1890
|
const message = params.message;
|
|
1805
1891
|
const target = params.target || 'all';
|
|
1806
1892
|
const priority = params.priority || 'normal';
|
|
1893
|
+
{
|
|
1894
|
+
const v = validateText(message, 'message');
|
|
1895
|
+
if (!v.valid)
|
|
1896
|
+
return { success: false, error: v.error };
|
|
1897
|
+
}
|
|
1898
|
+
if (params.target) {
|
|
1899
|
+
const v = validateIdentifier(target, 'target');
|
|
1900
|
+
if (!v.valid)
|
|
1901
|
+
return { success: false, error: v.error };
|
|
1902
|
+
}
|
|
1807
1903
|
return {
|
|
1808
1904
|
notificationId: `notify-${Date.now()}`,
|
|
1809
1905
|
message,
|
|
@@ -2036,6 +2132,16 @@ export const hooksTrajectoryStart = {
|
|
|
2036
2132
|
handler: async (params) => {
|
|
2037
2133
|
const task = params.task;
|
|
2038
2134
|
const agent = params.agent || 'coder';
|
|
2135
|
+
{
|
|
2136
|
+
const v = validateText(task, 'task');
|
|
2137
|
+
if (!v.valid)
|
|
2138
|
+
return { success: false, error: v.error };
|
|
2139
|
+
}
|
|
2140
|
+
if (params.agent) {
|
|
2141
|
+
const v = validateIdentifier(params.agent, 'agent');
|
|
2142
|
+
if (!v.valid)
|
|
2143
|
+
return { success: false, error: v.error };
|
|
2144
|
+
}
|
|
2039
2145
|
const trajectoryId = `traj-${Date.now()}-${Math.random().toString(36).substring(7)}`;
|
|
2040
2146
|
const startedAt = new Date().toISOString();
|
|
2041
2147
|
// Create real trajectory entry in memory
|
|
@@ -2078,6 +2184,16 @@ export const hooksTrajectoryStep = {
|
|
|
2078
2184
|
const quality = params.quality || 0.85;
|
|
2079
2185
|
const timestamp = new Date().toISOString();
|
|
2080
2186
|
const stepId = `step-${Date.now()}`;
|
|
2187
|
+
{
|
|
2188
|
+
const v = validateIdentifier(trajectoryId, 'trajectoryId');
|
|
2189
|
+
if (!v.valid)
|
|
2190
|
+
return { success: false, error: v.error };
|
|
2191
|
+
}
|
|
2192
|
+
{
|
|
2193
|
+
const v = validateText(action, 'action');
|
|
2194
|
+
if (!v.valid)
|
|
2195
|
+
return { success: false, error: v.error };
|
|
2196
|
+
}
|
|
2081
2197
|
// Add step to real trajectory if it exists
|
|
2082
2198
|
const trajectory = activeTrajectories.get(trajectoryId);
|
|
2083
2199
|
if (trajectory) {
|
|
@@ -2115,6 +2231,11 @@ export const hooksTrajectoryEnd = {
|
|
|
2115
2231
|
},
|
|
2116
2232
|
handler: async (params) => {
|
|
2117
2233
|
const trajectoryId = params.trajectoryId;
|
|
2234
|
+
{
|
|
2235
|
+
const v = validateIdentifier(trajectoryId, 'trajectoryId');
|
|
2236
|
+
if (!v.valid)
|
|
2237
|
+
return { success: false, error: v.error };
|
|
2238
|
+
}
|
|
2118
2239
|
const success = params.success !== false;
|
|
2119
2240
|
const feedback = params.feedback;
|
|
2120
2241
|
const endedAt = new Date().toISOString();
|
|
@@ -2253,6 +2374,16 @@ export const hooksPatternStore = {
|
|
|
2253
2374
|
const confidence = params.confidence || 0.8;
|
|
2254
2375
|
const metadata = params.metadata;
|
|
2255
2376
|
const timestamp = new Date().toISOString();
|
|
2377
|
+
{
|
|
2378
|
+
const v = validateText(pattern, 'pattern');
|
|
2379
|
+
if (!v.valid)
|
|
2380
|
+
return { success: false, error: v.error };
|
|
2381
|
+
}
|
|
2382
|
+
if (params.type) {
|
|
2383
|
+
const v = validateIdentifier(params.type, 'type');
|
|
2384
|
+
if (!v.valid)
|
|
2385
|
+
return { success: false, error: v.error };
|
|
2386
|
+
}
|
|
2256
2387
|
const patternId = `pattern-${Date.now()}-${Math.random().toString(36).substring(7)}`;
|
|
2257
2388
|
// Phase 3: Try ReasoningBank via bridge first
|
|
2258
2389
|
let reasoningResult = null;
|
|
@@ -2319,6 +2450,16 @@ export const hooksPatternSearch = {
|
|
|
2319
2450
|
const topK = params.topK || 5;
|
|
2320
2451
|
const minConfidence = params.minConfidence || 0.3;
|
|
2321
2452
|
const namespace = params.namespace || 'pattern';
|
|
2453
|
+
{
|
|
2454
|
+
const v = validateText(query, 'query');
|
|
2455
|
+
if (!v.valid)
|
|
2456
|
+
return { success: false, error: v.error };
|
|
2457
|
+
}
|
|
2458
|
+
if (params.namespace) {
|
|
2459
|
+
const v = validateIdentifier(params.namespace, 'namespace');
|
|
2460
|
+
if (!v.valid)
|
|
2461
|
+
return { success: false, error: v.error };
|
|
2462
|
+
}
|
|
2322
2463
|
// Phase 3: Try ReasoningBank search via bridge first
|
|
2323
2464
|
try {
|
|
2324
2465
|
const bridge = await import('../memory/memory-bridge.js');
|
|
@@ -2654,19 +2795,65 @@ export const hooksIntelligenceAttention = {
|
|
|
2654
2795
|
const mode = params.mode || 'flash';
|
|
2655
2796
|
const topK = params.topK || 5;
|
|
2656
2797
|
const startTime = performance.now();
|
|
2798
|
+
{
|
|
2799
|
+
const v = validateText(query, 'query');
|
|
2800
|
+
if (!v.valid)
|
|
2801
|
+
return { success: false, error: v.error };
|
|
2802
|
+
}
|
|
2657
2803
|
let implementation = 'placeholder';
|
|
2804
|
+
let embeddingSource = 'none';
|
|
2658
2805
|
const results = [];
|
|
2806
|
+
// Helper: generate query embedding, preferring real ONNX embeddings over hash fallback
|
|
2807
|
+
async function getQueryEmbedding(text, dims) {
|
|
2808
|
+
// Try ONNX via @claude-flow/embeddings
|
|
2809
|
+
try {
|
|
2810
|
+
const embeddingsModule = await import('@claude-flow/embeddings').catch(() => null);
|
|
2811
|
+
if (embeddingsModule?.createEmbeddingService) {
|
|
2812
|
+
const service = embeddingsModule.createEmbeddingService({ provider: 'onnx' });
|
|
2813
|
+
const result = await service.embed(text);
|
|
2814
|
+
const arr = new Float32Array(dims);
|
|
2815
|
+
for (let i = 0; i < Math.min(dims, result.embedding.length); i++) {
|
|
2816
|
+
arr[i] = result.embedding[i];
|
|
2817
|
+
}
|
|
2818
|
+
return { embedding: arr, source: 'onnx' };
|
|
2819
|
+
}
|
|
2820
|
+
}
|
|
2821
|
+
catch {
|
|
2822
|
+
// ONNX not available, try agentic-flow
|
|
2823
|
+
}
|
|
2824
|
+
// Try agentic-flow embeddings
|
|
2825
|
+
try {
|
|
2826
|
+
const embeddingsModule = await import('@claude-flow/embeddings').catch(() => null);
|
|
2827
|
+
if (embeddingsModule?.createEmbeddingService) {
|
|
2828
|
+
const service = embeddingsModule.createEmbeddingService({ provider: 'agentic-flow' });
|
|
2829
|
+
const result = await service.embed(text);
|
|
2830
|
+
const arr = new Float32Array(dims);
|
|
2831
|
+
for (let i = 0; i < Math.min(dims, result.embedding.length); i++) {
|
|
2832
|
+
arr[i] = result.embedding[i];
|
|
2833
|
+
}
|
|
2834
|
+
return { embedding: arr, source: 'onnx' };
|
|
2835
|
+
}
|
|
2836
|
+
}
|
|
2837
|
+
catch {
|
|
2838
|
+
// agentic-flow not available
|
|
2839
|
+
}
|
|
2840
|
+
// Hash-based fallback (deterministic but not semantic)
|
|
2841
|
+
const arr = new Float32Array(dims);
|
|
2842
|
+
let seed = text.split('').reduce((acc, char, i) => acc + char.charCodeAt(0) * (i + 1), 0);
|
|
2843
|
+
for (let i = 0; i < dims; i++) {
|
|
2844
|
+
seed = (seed * 1103515245 + 12345) & 0x7fffffff;
|
|
2845
|
+
arr[i] = (seed / 0x7fffffff) * 2 - 1;
|
|
2846
|
+
}
|
|
2847
|
+
return { embedding: arr, source: 'hash-fallback' };
|
|
2848
|
+
}
|
|
2659
2849
|
if (mode === 'moe') {
|
|
2660
2850
|
// Try MoE routing
|
|
2661
2851
|
const moe = await getMoERouter();
|
|
2662
2852
|
if (moe) {
|
|
2663
2853
|
try {
|
|
2664
|
-
|
|
2665
|
-
|
|
2666
|
-
|
|
2667
|
-
embedding[i] = Math.sin(query.charCodeAt(i % query.length) * (i + 1) * 0.01);
|
|
2668
|
-
}
|
|
2669
|
-
const routingResult = moe.route(embedding);
|
|
2854
|
+
const embResult = await getQueryEmbedding(query, 384);
|
|
2855
|
+
embeddingSource = embResult.source;
|
|
2856
|
+
const routingResult = moe.route(embResult.embedding);
|
|
2670
2857
|
for (let i = 0; i < Math.min(topK, routingResult.experts.length); i++) {
|
|
2671
2858
|
const expert = routingResult.experts[i];
|
|
2672
2859
|
results.push({
|
|
@@ -2688,13 +2875,11 @@ export const hooksIntelligenceAttention = {
|
|
|
2688
2875
|
const flash = await getFlashAttention();
|
|
2689
2876
|
if (flash) {
|
|
2690
2877
|
try {
|
|
2691
|
-
|
|
2692
|
-
|
|
2878
|
+
const embResult = await getQueryEmbedding(query, 384);
|
|
2879
|
+
embeddingSource = embResult.source;
|
|
2880
|
+
const q = embResult.embedding;
|
|
2693
2881
|
const keys = [];
|
|
2694
2882
|
const values = [];
|
|
2695
|
-
for (let i = 0; i < 384; i++) {
|
|
2696
|
-
q[i] = Math.sin(query.charCodeAt(i % query.length) * (i + 1) * 0.01);
|
|
2697
|
-
}
|
|
2698
2883
|
// Generate some keys/values
|
|
2699
2884
|
for (let k = 0; k < topK; k++) {
|
|
2700
2885
|
const key = new Float32Array(384);
|
|
@@ -2737,10 +2922,13 @@ export const hooksIntelligenceAttention = {
|
|
|
2737
2922
|
results,
|
|
2738
2923
|
stats: {
|
|
2739
2924
|
computeTimeMs,
|
|
2740
|
-
|
|
2741
|
-
|
|
2925
|
+
implementation,
|
|
2926
|
+
_embeddingSource: embeddingSource,
|
|
2742
2927
|
_stub: implementation === 'none',
|
|
2743
2928
|
_note: implementation === 'none' ? 'No attention backend available. Install @ruvector/attention for real computation.' : undefined,
|
|
2929
|
+
...(embeddingSource === 'hash-fallback' && implementation !== 'none'
|
|
2930
|
+
? { _embeddingNote: 'Query embeddings are hash-based (not semantic). Install @claude-flow/embeddings for real ONNX embeddings.' }
|
|
2931
|
+
: {}),
|
|
2744
2932
|
},
|
|
2745
2933
|
implementation,
|
|
2746
2934
|
};
|
|
@@ -3017,6 +3205,11 @@ export const hooksWorkerDispatch = {
|
|
|
3017
3205
|
const context = params.context || 'default';
|
|
3018
3206
|
const priority = params.priority || WORKER_CONFIGS[trigger]?.priority || 'normal';
|
|
3019
3207
|
const background = params.background !== false;
|
|
3208
|
+
if (params.context) {
|
|
3209
|
+
const v = validateText(params.context, 'context');
|
|
3210
|
+
if (!v.valid)
|
|
3211
|
+
return { success: false, error: v.error };
|
|
3212
|
+
}
|
|
3020
3213
|
if (!WORKER_CONFIGS[trigger]) {
|
|
3021
3214
|
return {
|
|
3022
3215
|
success: false,
|
|
@@ -3092,6 +3285,11 @@ export const hooksWorkerStatus = {
|
|
|
3092
3285
|
handler: async (params) => {
|
|
3093
3286
|
const workerId = params.workerId;
|
|
3094
3287
|
const includeCompleted = params.includeCompleted !== false;
|
|
3288
|
+
if (workerId) {
|
|
3289
|
+
const v = validateIdentifier(workerId, 'workerId');
|
|
3290
|
+
if (!v.valid)
|
|
3291
|
+
return { success: false, error: v.error };
|
|
3292
|
+
}
|
|
3095
3293
|
if (workerId) {
|
|
3096
3294
|
const worker = activeWorkers.get(workerId);
|
|
3097
3295
|
if (!worker) {
|
|
@@ -3147,6 +3345,11 @@ export const hooksWorkerDetect = {
|
|
|
3147
3345
|
const prompt = params.prompt;
|
|
3148
3346
|
const autoDispatch = params.autoDispatch;
|
|
3149
3347
|
const minConfidence = params.minConfidence || 0.5;
|
|
3348
|
+
{
|
|
3349
|
+
const v = validateText(prompt, 'prompt');
|
|
3350
|
+
if (!v.valid)
|
|
3351
|
+
return { success: false, error: v.error };
|
|
3352
|
+
}
|
|
3150
3353
|
const detection = detectWorkerTriggers(prompt);
|
|
3151
3354
|
const result = {
|
|
3152
3355
|
prompt: prompt.slice(0, 200) + (prompt.length > 200 ? '...' : ''),
|
|
@@ -3219,6 +3422,11 @@ export const hooksModelRoute = {
|
|
|
3219
3422
|
},
|
|
3220
3423
|
handler: async (params) => {
|
|
3221
3424
|
const task = params.task;
|
|
3425
|
+
{
|
|
3426
|
+
const v = validateText(task, 'task');
|
|
3427
|
+
if (!v.valid)
|
|
3428
|
+
return { success: false, error: v.error };
|
|
3429
|
+
}
|
|
3222
3430
|
const router = await getModelRouterInstance();
|
|
3223
3431
|
if (!router) {
|
|
3224
3432
|
// Fallback to simple heuristic
|
|
@@ -3262,6 +3470,11 @@ export const hooksModelOutcome = {
|
|
|
3262
3470
|
const task = params.task;
|
|
3263
3471
|
const model = params.model;
|
|
3264
3472
|
const outcome = params.outcome;
|
|
3473
|
+
{
|
|
3474
|
+
const v = validateText(task, 'task');
|
|
3475
|
+
if (!v.valid)
|
|
3476
|
+
return { success: false, error: v.error };
|
|
3477
|
+
}
|
|
3265
3478
|
const router = await getModelRouterInstance();
|
|
3266
3479
|
if (router) {
|
|
3267
3480
|
router.recordOutcome(task, model, outcome);
|
|
@@ -3325,6 +3538,11 @@ export const hooksWorkerCancel = {
|
|
|
3325
3538
|
},
|
|
3326
3539
|
handler: async (params) => {
|
|
3327
3540
|
const workerId = params.workerId;
|
|
3541
|
+
{
|
|
3542
|
+
const v = validateIdentifier(workerId, 'workerId');
|
|
3543
|
+
if (!v.valid)
|
|
3544
|
+
return { success: false, error: v.error };
|
|
3545
|
+
}
|
|
3328
3546
|
const worker = activeWorkers.get(workerId);
|
|
3329
3547
|
if (!worker) {
|
|
3330
3548
|
return {
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
*/
|
|
12
12
|
import { existsSync, mkdirSync, readFileSync, unlinkSync, writeFileSync } from 'fs';
|
|
13
13
|
import { join, resolve } from 'path';
|
|
14
|
+
import { validateIdentifier } from './validate-input.js';
|
|
14
15
|
// Paths
|
|
15
16
|
const MEMORY_DIR = '.claude-flow/memory';
|
|
16
17
|
const LEGACY_MEMORY_FILE = 'store.json';
|
|
@@ -231,7 +232,7 @@ export const memoryTools = [
|
|
|
231
232
|
const { getEntry } = await getMemoryFunctions();
|
|
232
233
|
const key = input.key;
|
|
233
234
|
const namespace = input.namespace || 'default';
|
|
234
|
-
validateMemoryInput(key);
|
|
235
|
+
validateMemoryInput(key, undefined, undefined, namespace);
|
|
235
236
|
try {
|
|
236
237
|
const result = await getEntry({ key, namespace });
|
|
237
238
|
if (result.found && result.entry) {
|
|
@@ -356,7 +357,7 @@ export const memoryTools = [
|
|
|
356
357
|
const { deleteEntry } = await getMemoryFunctions();
|
|
357
358
|
const key = input.key;
|
|
358
359
|
const namespace = input.namespace || 'default';
|
|
359
|
-
validateMemoryInput(key);
|
|
360
|
+
validateMemoryInput(key, undefined, undefined, namespace);
|
|
360
361
|
try {
|
|
361
362
|
const result = await deleteEntry({ key, namespace });
|
|
362
363
|
return {
|
|
@@ -397,6 +398,11 @@ export const memoryTools = [
|
|
|
397
398
|
const namespace = input.namespace;
|
|
398
399
|
const limit = input.limit || 50;
|
|
399
400
|
const offset = input.offset || 0;
|
|
401
|
+
if (namespace) {
|
|
402
|
+
const vNs = validateIdentifier(namespace, 'namespace');
|
|
403
|
+
if (!vNs.valid)
|
|
404
|
+
throw new Error(vNs.error);
|
|
405
|
+
}
|
|
400
406
|
try {
|
|
401
407
|
const result = await listEntries({
|
|
402
408
|
namespace,
|
|
@@ -533,6 +539,11 @@ export const memoryTools = [
|
|
|
533
539
|
const { storeEntry } = await getMemoryFunctions();
|
|
534
540
|
const { homedir } = await import('os');
|
|
535
541
|
const ns = input.namespace || 'claude-memories';
|
|
542
|
+
if (input.namespace) {
|
|
543
|
+
const vNs = validateIdentifier(ns, 'namespace');
|
|
544
|
+
if (!vNs.valid)
|
|
545
|
+
return { success: false, imported: 0, error: vNs.error };
|
|
546
|
+
}
|
|
536
547
|
const allProjects = input.allProjects;
|
|
537
548
|
const claudeProjectsDir = join(homedir(), '.claude', 'projects');
|
|
538
549
|
// Find memory files
|
|
@@ -703,6 +714,11 @@ export const memoryTools = [
|
|
|
703
714
|
const query = input.query;
|
|
704
715
|
const limit = input.limit || 10;
|
|
705
716
|
const ns = input.namespace;
|
|
717
|
+
if (ns) {
|
|
718
|
+
const vNs = validateIdentifier(ns, 'namespace');
|
|
719
|
+
if (!vNs.valid)
|
|
720
|
+
return { success: false, query, results: [], total: 0, error: vNs.error };
|
|
721
|
+
}
|
|
706
722
|
// Search all namespaces unless filtered
|
|
707
723
|
const namespaces = ns ? [ns] : ['default', 'claude-memories', 'auto-memory', 'patterns', 'tasks', 'feedback'];
|
|
708
724
|
const allResults = [];
|