claude-flow 3.5.70 → 3.5.71

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.
Files changed (87) hide show
  1. package/package.json +1 -1
  2. package/v3/@claude-flow/cli/dist/src/mcp-tools/agent-tools.js +35 -1
  3. package/v3/@claude-flow/cli/dist/src/mcp-tools/agentdb-tools.js +81 -0
  4. package/v3/@claude-flow/cli/dist/src/mcp-tools/analyze-tools.js +29 -0
  5. package/v3/@claude-flow/cli/dist/src/mcp-tools/autopilot-tools.js +4 -0
  6. package/v3/@claude-flow/cli/dist/src/mcp-tools/browser-tools.js +146 -0
  7. package/v3/@claude-flow/cli/dist/src/mcp-tools/claims-tools.js +116 -0
  8. package/v3/@claude-flow/cli/dist/src/mcp-tools/coordination-tools.js +31 -0
  9. package/v3/@claude-flow/cli/dist/src/mcp-tools/daa-tools.js +61 -0
  10. package/v3/@claude-flow/cli/dist/src/mcp-tools/embeddings-tools.js +26 -0
  11. package/v3/@claude-flow/cli/dist/src/mcp-tools/github-tools.js +96 -0
  12. package/v3/@claude-flow/cli/dist/src/mcp-tools/guidance-tools.js +21 -0
  13. package/v3/@claude-flow/cli/dist/src/mcp-tools/hive-mind-tools.js +56 -0
  14. package/v3/@claude-flow/cli/dist/src/mcp-tools/hooks-tools.js +176 -0
  15. package/v3/@claude-flow/cli/dist/src/mcp-tools/memory-tools.js +18 -2
  16. package/v3/@claude-flow/cli/dist/src/mcp-tools/neural-tools.js +51 -0
  17. package/v3/@claude-flow/cli/dist/src/mcp-tools/performance-tools.js +11 -0
  18. package/v3/@claude-flow/cli/dist/src/mcp-tools/ruvllm-tools.js +31 -0
  19. package/v3/@claude-flow/cli/dist/src/mcp-tools/security-tools.js +36 -0
  20. package/v3/@claude-flow/cli/dist/src/mcp-tools/system-tools.js +6 -0
  21. package/v3/@claude-flow/cli/dist/src/mcp-tools/transfer-tools.js +51 -0
  22. package/v3/@claude-flow/cli/dist/src/mcp-tools/wasm-agent-tools.js +61 -0
  23. package/v3/@claude-flow/cli/package.json +1 -1
  24. package/v3/@claude-flow/guidance/dist/adversarial.d.ts +284 -0
  25. package/v3/@claude-flow/guidance/dist/adversarial.js +572 -0
  26. package/v3/@claude-flow/guidance/dist/analyzer.d.ts +530 -0
  27. package/v3/@claude-flow/guidance/dist/analyzer.js +2518 -0
  28. package/v3/@claude-flow/guidance/dist/artifacts.d.ts +283 -0
  29. package/v3/@claude-flow/guidance/dist/artifacts.js +356 -0
  30. package/v3/@claude-flow/guidance/dist/authority.d.ts +290 -0
  31. package/v3/@claude-flow/guidance/dist/authority.js +558 -0
  32. package/v3/@claude-flow/guidance/dist/capabilities.d.ts +209 -0
  33. package/v3/@claude-flow/guidance/dist/capabilities.js +485 -0
  34. package/v3/@claude-flow/guidance/dist/coherence.d.ts +233 -0
  35. package/v3/@claude-flow/guidance/dist/coherence.js +372 -0
  36. package/v3/@claude-flow/guidance/dist/compiler.d.ts +87 -0
  37. package/v3/@claude-flow/guidance/dist/compiler.js +419 -0
  38. package/v3/@claude-flow/guidance/dist/conformance-kit.d.ts +225 -0
  39. package/v3/@claude-flow/guidance/dist/conformance-kit.js +629 -0
  40. package/v3/@claude-flow/guidance/dist/continue-gate.d.ts +214 -0
  41. package/v3/@claude-flow/guidance/dist/continue-gate.js +353 -0
  42. package/v3/@claude-flow/guidance/dist/crypto-utils.d.ts +17 -0
  43. package/v3/@claude-flow/guidance/dist/crypto-utils.js +24 -0
  44. package/v3/@claude-flow/guidance/dist/evolution.d.ts +282 -0
  45. package/v3/@claude-flow/guidance/dist/evolution.js +500 -0
  46. package/v3/@claude-flow/guidance/dist/gates.d.ts +79 -0
  47. package/v3/@claude-flow/guidance/dist/gates.js +302 -0
  48. package/v3/@claude-flow/guidance/dist/gateway.d.ts +206 -0
  49. package/v3/@claude-flow/guidance/dist/gateway.js +452 -0
  50. package/v3/@claude-flow/guidance/dist/generators.d.ts +153 -0
  51. package/v3/@claude-flow/guidance/dist/generators.js +682 -0
  52. package/v3/@claude-flow/guidance/dist/headless.d.ts +177 -0
  53. package/v3/@claude-flow/guidance/dist/headless.js +342 -0
  54. package/v3/@claude-flow/guidance/dist/hooks.d.ts +109 -0
  55. package/v3/@claude-flow/guidance/dist/hooks.js +347 -0
  56. package/v3/@claude-flow/guidance/dist/index.d.ts +205 -0
  57. package/v3/@claude-flow/guidance/dist/index.js +321 -0
  58. package/v3/@claude-flow/guidance/dist/ledger.d.ts +162 -0
  59. package/v3/@claude-flow/guidance/dist/ledger.js +375 -0
  60. package/v3/@claude-flow/guidance/dist/manifest-validator.d.ts +289 -0
  61. package/v3/@claude-flow/guidance/dist/manifest-validator.js +838 -0
  62. package/v3/@claude-flow/guidance/dist/memory-gate.d.ts +222 -0
  63. package/v3/@claude-flow/guidance/dist/memory-gate.js +382 -0
  64. package/v3/@claude-flow/guidance/dist/meta-governance.d.ts +265 -0
  65. package/v3/@claude-flow/guidance/dist/meta-governance.js +348 -0
  66. package/v3/@claude-flow/guidance/dist/optimizer.d.ts +104 -0
  67. package/v3/@claude-flow/guidance/dist/optimizer.js +329 -0
  68. package/v3/@claude-flow/guidance/dist/persistence.d.ts +189 -0
  69. package/v3/@claude-flow/guidance/dist/persistence.js +464 -0
  70. package/v3/@claude-flow/guidance/dist/proof.d.ts +185 -0
  71. package/v3/@claude-flow/guidance/dist/proof.js +238 -0
  72. package/v3/@claude-flow/guidance/dist/retriever.d.ts +116 -0
  73. package/v3/@claude-flow/guidance/dist/retriever.js +394 -0
  74. package/v3/@claude-flow/guidance/dist/ruvbot-integration.d.ts +370 -0
  75. package/v3/@claude-flow/guidance/dist/ruvbot-integration.js +738 -0
  76. package/v3/@claude-flow/guidance/dist/temporal.d.ts +426 -0
  77. package/v3/@claude-flow/guidance/dist/temporal.js +658 -0
  78. package/v3/@claude-flow/guidance/dist/trust.d.ts +283 -0
  79. package/v3/@claude-flow/guidance/dist/trust.js +473 -0
  80. package/v3/@claude-flow/guidance/dist/truth-anchors.d.ts +276 -0
  81. package/v3/@claude-flow/guidance/dist/truth-anchors.js +488 -0
  82. package/v3/@claude-flow/guidance/dist/types.d.ts +378 -0
  83. package/v3/@claude-flow/guidance/dist/types.js +10 -0
  84. package/v3/@claude-flow/guidance/dist/uncertainty.d.ts +372 -0
  85. package/v3/@claude-flow/guidance/dist/uncertainty.js +619 -0
  86. package/v3/@claude-flow/guidance/dist/wasm-kernel.d.ts +48 -0
  87. 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,6 +2795,11 @@ 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';
2658
2804
  const results = [];
2659
2805
  if (mode === 'moe') {
@@ -3017,6 +3163,11 @@ export const hooksWorkerDispatch = {
3017
3163
  const context = params.context || 'default';
3018
3164
  const priority = params.priority || WORKER_CONFIGS[trigger]?.priority || 'normal';
3019
3165
  const background = params.background !== false;
3166
+ if (params.context) {
3167
+ const v = validateText(params.context, 'context');
3168
+ if (!v.valid)
3169
+ return { success: false, error: v.error };
3170
+ }
3020
3171
  if (!WORKER_CONFIGS[trigger]) {
3021
3172
  return {
3022
3173
  success: false,
@@ -3092,6 +3243,11 @@ export const hooksWorkerStatus = {
3092
3243
  handler: async (params) => {
3093
3244
  const workerId = params.workerId;
3094
3245
  const includeCompleted = params.includeCompleted !== false;
3246
+ if (workerId) {
3247
+ const v = validateIdentifier(workerId, 'workerId');
3248
+ if (!v.valid)
3249
+ return { success: false, error: v.error };
3250
+ }
3095
3251
  if (workerId) {
3096
3252
  const worker = activeWorkers.get(workerId);
3097
3253
  if (!worker) {
@@ -3147,6 +3303,11 @@ export const hooksWorkerDetect = {
3147
3303
  const prompt = params.prompt;
3148
3304
  const autoDispatch = params.autoDispatch;
3149
3305
  const minConfidence = params.minConfidence || 0.5;
3306
+ {
3307
+ const v = validateText(prompt, 'prompt');
3308
+ if (!v.valid)
3309
+ return { success: false, error: v.error };
3310
+ }
3150
3311
  const detection = detectWorkerTriggers(prompt);
3151
3312
  const result = {
3152
3313
  prompt: prompt.slice(0, 200) + (prompt.length > 200 ? '...' : ''),
@@ -3219,6 +3380,11 @@ export const hooksModelRoute = {
3219
3380
  },
3220
3381
  handler: async (params) => {
3221
3382
  const task = params.task;
3383
+ {
3384
+ const v = validateText(task, 'task');
3385
+ if (!v.valid)
3386
+ return { success: false, error: v.error };
3387
+ }
3222
3388
  const router = await getModelRouterInstance();
3223
3389
  if (!router) {
3224
3390
  // Fallback to simple heuristic
@@ -3262,6 +3428,11 @@ export const hooksModelOutcome = {
3262
3428
  const task = params.task;
3263
3429
  const model = params.model;
3264
3430
  const outcome = params.outcome;
3431
+ {
3432
+ const v = validateText(task, 'task');
3433
+ if (!v.valid)
3434
+ return { success: false, error: v.error };
3435
+ }
3265
3436
  const router = await getModelRouterInstance();
3266
3437
  if (router) {
3267
3438
  router.recordOutcome(task, model, outcome);
@@ -3325,6 +3496,11 @@ export const hooksWorkerCancel = {
3325
3496
  },
3326
3497
  handler: async (params) => {
3327
3498
  const workerId = params.workerId;
3499
+ {
3500
+ const v = validateIdentifier(workerId, 'workerId');
3501
+ if (!v.valid)
3502
+ return { success: false, error: v.error };
3503
+ }
3328
3504
  const worker = activeWorkers.get(workerId);
3329
3505
  if (!worker) {
3330
3506
  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 = [];
@@ -12,6 +12,7 @@
12
12
  * Note: For production neural features, use @claude-flow/neural module
13
13
  */
14
14
  import { getProjectCwd } from './types.js';
15
+ import { validateIdentifier, validateText } from './validate-input.js';
15
16
  import { existsSync, readFileSync, writeFileSync, mkdirSync } from 'node:fs';
16
17
  import { join } from 'node:path';
17
18
  // Try to import real embeddings — prefer agentic-flow v3 ReasoningBank, then @claude-flow/embeddings
@@ -147,6 +148,11 @@ export const neuralTools = [
147
148
  required: ['modelType'],
148
149
  },
149
150
  handler: async (input) => {
151
+ if (input.modelId) {
152
+ const v = validateIdentifier(input.modelId, 'modelId');
153
+ if (!v.valid)
154
+ return { success: false, error: v.error };
155
+ }
150
156
  const store = loadNeuralStore();
151
157
  const modelId = input.modelId || `model-${Date.now()}-${Math.random().toString(36).slice(2, 6)}`;
152
158
  const modelType = input.modelType;
@@ -225,6 +231,16 @@ export const neuralTools = [
225
231
  required: ['input'],
226
232
  },
227
233
  handler: async (input) => {
234
+ {
235
+ const v = validateText(input.input, 'input');
236
+ if (!v.valid)
237
+ return { success: false, error: v.error };
238
+ }
239
+ if (input.modelId) {
240
+ const v = validateIdentifier(input.modelId, 'modelId');
241
+ if (!v.valid)
242
+ return { success: false, error: v.error };
243
+ }
228
244
  const store = loadNeuralStore();
229
245
  const modelId = input.modelId;
230
246
  const inputText = input.input;
@@ -285,6 +301,26 @@ export const neuralTools = [
285
301
  },
286
302
  },
287
303
  handler: async (input) => {
304
+ if (input.patternId) {
305
+ const v = validateIdentifier(input.patternId, 'patternId');
306
+ if (!v.valid)
307
+ return { success: false, error: v.error };
308
+ }
309
+ if (input.name) {
310
+ const v = validateText(input.name, 'name');
311
+ if (!v.valid)
312
+ return { success: false, error: v.error };
313
+ }
314
+ if (input.type) {
315
+ const v = validateIdentifier(input.type, 'type');
316
+ if (!v.valid)
317
+ return { success: false, error: v.error };
318
+ }
319
+ if (input.query) {
320
+ const v = validateText(input.query, 'query');
321
+ if (!v.valid)
322
+ return { success: false, error: v.error };
323
+ }
288
324
  const store = loadNeuralStore();
289
325
  const action = input.action || 'list';
290
326
  if (action === 'list') {
@@ -385,6 +421,11 @@ export const neuralTools = [
385
421
  },
386
422
  },
387
423
  handler: async (input) => {
424
+ if (input.modelId) {
425
+ const v = validateIdentifier(input.modelId, 'modelId');
426
+ if (!v.valid)
427
+ return { success: false, error: v.error };
428
+ }
388
429
  const store = loadNeuralStore();
389
430
  const method = input.method || 'quantize';
390
431
  const targetReduction = input.targetSize || 0.5;
@@ -490,6 +531,11 @@ export const neuralTools = [
490
531
  },
491
532
  },
492
533
  handler: async (input) => {
534
+ if (input.modelId) {
535
+ const v = validateIdentifier(input.modelId, 'modelId');
536
+ if (!v.valid)
537
+ return { success: false, error: v.error };
538
+ }
493
539
  const store = loadNeuralStore();
494
540
  if (input.modelId) {
495
541
  const model = store.models[input.modelId];
@@ -540,6 +586,11 @@ export const neuralTools = [
540
586
  },
541
587
  },
542
588
  handler: async (input) => {
589
+ if (input.modelId) {
590
+ const v = validateIdentifier(input.modelId, 'modelId');
591
+ if (!v.valid)
592
+ return { success: false, error: v.error };
593
+ }
543
594
  const store = loadNeuralStore();
544
595
  const target = input.target || 'balanced';
545
596
  const patterns = Object.values(store.patterns);
@@ -12,6 +12,7 @@
12
12
  * Note: Some optimization suggestions are illustrative
13
13
  */
14
14
  import { getProjectCwd } from './types.js';
15
+ import { validateIdentifier } from './validate-input.js';
15
16
  import { existsSync, readFileSync, writeFileSync, mkdirSync } from 'node:fs';
16
17
  import { join } from 'node:path';
17
18
  import * as os from 'node:os';
@@ -158,6 +159,11 @@ export const performanceTools = [
158
159
  },
159
160
  },
160
161
  handler: async (_input) => {
162
+ if (_input.component) {
163
+ const v = validateIdentifier(_input.component, 'component');
164
+ if (!v.valid)
165
+ return { success: false, error: v.error };
166
+ }
161
167
  const loadAvg = os.loadavg();
162
168
  const cpus = os.cpus();
163
169
  const cpuPercent = Math.min((loadAvg[0] / cpus.length) * 100, 100);
@@ -346,6 +352,11 @@ export const performanceTools = [
346
352
  },
347
353
  },
348
354
  handler: async (input) => {
355
+ if (input.target) {
356
+ const v = validateIdentifier(input.target, 'target');
357
+ if (!v.valid)
358
+ return { success: false, error: v.error };
359
+ }
349
360
  const target = input.target || 'all';
350
361
  const durationSec = Math.min(input.duration || 1, 10);
351
362
  const durationMs = durationSec * 1000;