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.
Files changed (90) hide show
  1. package/package.json +1 -1
  2. package/v3/@claude-flow/cli/dist/src/commands/plugins.js +6 -0
  3. package/v3/@claude-flow/cli/dist/src/commands/security.js +350 -34
  4. package/v3/@claude-flow/cli/dist/src/commands/swarm.js +100 -15
  5. package/v3/@claude-flow/cli/dist/src/mcp-tools/agent-tools.js +35 -1
  6. package/v3/@claude-flow/cli/dist/src/mcp-tools/agentdb-tools.js +81 -0
  7. package/v3/@claude-flow/cli/dist/src/mcp-tools/analyze-tools.js +29 -0
  8. package/v3/@claude-flow/cli/dist/src/mcp-tools/autopilot-tools.js +4 -0
  9. package/v3/@claude-flow/cli/dist/src/mcp-tools/browser-tools.js +146 -0
  10. package/v3/@claude-flow/cli/dist/src/mcp-tools/claims-tools.js +116 -0
  11. package/v3/@claude-flow/cli/dist/src/mcp-tools/coordination-tools.js +31 -0
  12. package/v3/@claude-flow/cli/dist/src/mcp-tools/daa-tools.js +61 -0
  13. package/v3/@claude-flow/cli/dist/src/mcp-tools/embeddings-tools.js +26 -0
  14. package/v3/@claude-flow/cli/dist/src/mcp-tools/github-tools.js +96 -0
  15. package/v3/@claude-flow/cli/dist/src/mcp-tools/guidance-tools.js +21 -0
  16. package/v3/@claude-flow/cli/dist/src/mcp-tools/hive-mind-tools.js +56 -0
  17. package/v3/@claude-flow/cli/dist/src/mcp-tools/hooks-tools.js +231 -13
  18. package/v3/@claude-flow/cli/dist/src/mcp-tools/memory-tools.js +18 -2
  19. package/v3/@claude-flow/cli/dist/src/mcp-tools/neural-tools.js +92 -2
  20. package/v3/@claude-flow/cli/dist/src/mcp-tools/performance-tools.js +18 -5
  21. package/v3/@claude-flow/cli/dist/src/mcp-tools/ruvllm-tools.js +31 -0
  22. package/v3/@claude-flow/cli/dist/src/mcp-tools/security-tools.js +36 -0
  23. package/v3/@claude-flow/cli/dist/src/mcp-tools/system-tools.js +59 -18
  24. package/v3/@claude-flow/cli/dist/src/mcp-tools/transfer-tools.js +51 -0
  25. package/v3/@claude-flow/cli/dist/src/mcp-tools/wasm-agent-tools.js +61 -0
  26. package/v3/@claude-flow/cli/package.json +1 -1
  27. package/v3/@claude-flow/guidance/dist/adversarial.d.ts +284 -0
  28. package/v3/@claude-flow/guidance/dist/adversarial.js +572 -0
  29. package/v3/@claude-flow/guidance/dist/analyzer.d.ts +530 -0
  30. package/v3/@claude-flow/guidance/dist/analyzer.js +2518 -0
  31. package/v3/@claude-flow/guidance/dist/artifacts.d.ts +283 -0
  32. package/v3/@claude-flow/guidance/dist/artifacts.js +356 -0
  33. package/v3/@claude-flow/guidance/dist/authority.d.ts +290 -0
  34. package/v3/@claude-flow/guidance/dist/authority.js +558 -0
  35. package/v3/@claude-flow/guidance/dist/capabilities.d.ts +209 -0
  36. package/v3/@claude-flow/guidance/dist/capabilities.js +485 -0
  37. package/v3/@claude-flow/guidance/dist/coherence.d.ts +233 -0
  38. package/v3/@claude-flow/guidance/dist/coherence.js +372 -0
  39. package/v3/@claude-flow/guidance/dist/compiler.d.ts +87 -0
  40. package/v3/@claude-flow/guidance/dist/compiler.js +419 -0
  41. package/v3/@claude-flow/guidance/dist/conformance-kit.d.ts +225 -0
  42. package/v3/@claude-flow/guidance/dist/conformance-kit.js +629 -0
  43. package/v3/@claude-flow/guidance/dist/continue-gate.d.ts +214 -0
  44. package/v3/@claude-flow/guidance/dist/continue-gate.js +353 -0
  45. package/v3/@claude-flow/guidance/dist/crypto-utils.d.ts +17 -0
  46. package/v3/@claude-flow/guidance/dist/crypto-utils.js +24 -0
  47. package/v3/@claude-flow/guidance/dist/evolution.d.ts +282 -0
  48. package/v3/@claude-flow/guidance/dist/evolution.js +500 -0
  49. package/v3/@claude-flow/guidance/dist/gates.d.ts +79 -0
  50. package/v3/@claude-flow/guidance/dist/gates.js +302 -0
  51. package/v3/@claude-flow/guidance/dist/gateway.d.ts +206 -0
  52. package/v3/@claude-flow/guidance/dist/gateway.js +452 -0
  53. package/v3/@claude-flow/guidance/dist/generators.d.ts +153 -0
  54. package/v3/@claude-flow/guidance/dist/generators.js +682 -0
  55. package/v3/@claude-flow/guidance/dist/headless.d.ts +177 -0
  56. package/v3/@claude-flow/guidance/dist/headless.js +342 -0
  57. package/v3/@claude-flow/guidance/dist/hooks.d.ts +109 -0
  58. package/v3/@claude-flow/guidance/dist/hooks.js +347 -0
  59. package/v3/@claude-flow/guidance/dist/index.d.ts +205 -0
  60. package/v3/@claude-flow/guidance/dist/index.js +321 -0
  61. package/v3/@claude-flow/guidance/dist/ledger.d.ts +162 -0
  62. package/v3/@claude-flow/guidance/dist/ledger.js +375 -0
  63. package/v3/@claude-flow/guidance/dist/manifest-validator.d.ts +289 -0
  64. package/v3/@claude-flow/guidance/dist/manifest-validator.js +838 -0
  65. package/v3/@claude-flow/guidance/dist/memory-gate.d.ts +222 -0
  66. package/v3/@claude-flow/guidance/dist/memory-gate.js +382 -0
  67. package/v3/@claude-flow/guidance/dist/meta-governance.d.ts +265 -0
  68. package/v3/@claude-flow/guidance/dist/meta-governance.js +348 -0
  69. package/v3/@claude-flow/guidance/dist/optimizer.d.ts +104 -0
  70. package/v3/@claude-flow/guidance/dist/optimizer.js +329 -0
  71. package/v3/@claude-flow/guidance/dist/persistence.d.ts +189 -0
  72. package/v3/@claude-flow/guidance/dist/persistence.js +464 -0
  73. package/v3/@claude-flow/guidance/dist/proof.d.ts +185 -0
  74. package/v3/@claude-flow/guidance/dist/proof.js +238 -0
  75. package/v3/@claude-flow/guidance/dist/retriever.d.ts +116 -0
  76. package/v3/@claude-flow/guidance/dist/retriever.js +394 -0
  77. package/v3/@claude-flow/guidance/dist/ruvbot-integration.d.ts +370 -0
  78. package/v3/@claude-flow/guidance/dist/ruvbot-integration.js +738 -0
  79. package/v3/@claude-flow/guidance/dist/temporal.d.ts +426 -0
  80. package/v3/@claude-flow/guidance/dist/temporal.js +658 -0
  81. package/v3/@claude-flow/guidance/dist/trust.d.ts +283 -0
  82. package/v3/@claude-flow/guidance/dist/trust.js +473 -0
  83. package/v3/@claude-flow/guidance/dist/truth-anchors.d.ts +276 -0
  84. package/v3/@claude-flow/guidance/dist/truth-anchors.js +488 -0
  85. package/v3/@claude-flow/guidance/dist/types.d.ts +378 -0
  86. package/v3/@claude-flow/guidance/dist/types.js +10 -0
  87. package/v3/@claude-flow/guidance/dist/uncertainty.d.ts +372 -0
  88. package/v3/@claude-flow/guidance/dist/uncertainty.js +619 -0
  89. package/v3/@claude-flow/guidance/dist/wasm-kernel.d.ts +48 -0
  90. package/v3/@claude-flow/guidance/dist/wasm-kernel.js +158 -0
@@ -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
@@ -24,7 +25,7 @@ try {
24
25
  realEmbeddings = { embed: (text) => rb.computeEmbedding(text) };
25
26
  embeddingServiceName = 'agentic-flow/reasoningbank';
26
27
  }
27
- // Tier 2: @claude-flow/embeddings
28
+ // Tier 2: @claude-flow/embeddings with agentic-flow provider
28
29
  if (!realEmbeddings) {
29
30
  const embeddingsModule = await import('@claude-flow/embeddings').catch(() => null);
30
31
  if (embeddingsModule?.createEmbeddingService) {
@@ -39,6 +40,34 @@ try {
39
40
  embeddingServiceName = 'agentic-flow';
40
41
  }
41
42
  catch {
43
+ // agentic-flow provider not available, try ONNX
44
+ }
45
+ }
46
+ }
47
+ // Tier 3: @claude-flow/embeddings with ONNX provider
48
+ if (!realEmbeddings) {
49
+ const embeddingsModule = await import('@claude-flow/embeddings').catch(() => null);
50
+ if (embeddingsModule?.createEmbeddingService) {
51
+ try {
52
+ const service = embeddingsModule.createEmbeddingService({ provider: 'onnx' });
53
+ realEmbeddings = {
54
+ embed: async (text) => {
55
+ const result = await service.embed(text);
56
+ return Array.from(result.embedding);
57
+ },
58
+ };
59
+ embeddingServiceName = 'onnx';
60
+ }
61
+ catch {
62
+ // ONNX provider not available, fall through to mock
63
+ }
64
+ }
65
+ }
66
+ // Tier 4: mock fallback (last resort — embeddings are not semantic)
67
+ if (!realEmbeddings) {
68
+ const embeddingsModule = await import('@claude-flow/embeddings').catch(() => null);
69
+ if (embeddingsModule?.createEmbeddingService) {
70
+ try {
42
71
  const service = embeddingsModule.createEmbeddingService({ provider: 'mock' });
43
72
  realEmbeddings = {
44
73
  embed: async (text) => {
@@ -46,7 +75,10 @@ try {
46
75
  return Array.from(result.embedding);
47
76
  },
48
77
  };
49
- embeddingServiceName = 'mock';
78
+ embeddingServiceName = 'mock-fallback';
79
+ }
80
+ catch {
81
+ // No embedding service available at all
50
82
  }
51
83
  }
52
84
  }
@@ -147,6 +179,11 @@ export const neuralTools = [
147
179
  required: ['modelType'],
148
180
  },
149
181
  handler: async (input) => {
182
+ if (input.modelId) {
183
+ const v = validateIdentifier(input.modelId, 'modelId');
184
+ if (!v.valid)
185
+ return { success: false, error: v.error };
186
+ }
150
187
  const store = loadNeuralStore();
151
188
  const modelId = input.modelId || `model-${Date.now()}-${Math.random().toString(36).slice(2, 6)}`;
152
189
  const modelType = input.modelType;
@@ -201,6 +238,7 @@ export const neuralTools = [
201
238
  return {
202
239
  success: true,
203
240
  _realEmbedding: !!realEmbeddings,
241
+ embeddingProvider: embeddingServiceName,
204
242
  modelId,
205
243
  type: modelType,
206
244
  status: model.status,
@@ -225,6 +263,16 @@ export const neuralTools = [
225
263
  required: ['input'],
226
264
  },
227
265
  handler: async (input) => {
266
+ {
267
+ const v = validateText(input.input, 'input');
268
+ if (!v.valid)
269
+ return { success: false, error: v.error };
270
+ }
271
+ if (input.modelId) {
272
+ const v = validateIdentifier(input.modelId, 'modelId');
273
+ if (!v.valid)
274
+ return { success: false, error: v.error };
275
+ }
228
276
  const store = loadNeuralStore();
229
277
  const modelId = input.modelId;
230
278
  const inputText = input.input;
@@ -259,6 +307,7 @@ export const neuralTools = [
259
307
  return {
260
308
  success: true,
261
309
  _realEmbedding: !!realEmbeddings,
310
+ embeddingProvider: embeddingServiceName,
262
311
  _hasStoredPatterns: storedPatterns.length > 0,
263
312
  modelId: model?.id || 'default',
264
313
  input: inputText,
@@ -285,6 +334,26 @@ export const neuralTools = [
285
334
  },
286
335
  },
287
336
  handler: async (input) => {
337
+ if (input.patternId) {
338
+ const v = validateIdentifier(input.patternId, 'patternId');
339
+ if (!v.valid)
340
+ return { success: false, error: v.error };
341
+ }
342
+ if (input.name) {
343
+ const v = validateText(input.name, 'name');
344
+ if (!v.valid)
345
+ return { success: false, error: v.error };
346
+ }
347
+ if (input.type) {
348
+ const v = validateIdentifier(input.type, 'type');
349
+ if (!v.valid)
350
+ return { success: false, error: v.error };
351
+ }
352
+ if (input.query) {
353
+ const v = validateText(input.query, 'query');
354
+ if (!v.valid)
355
+ return { success: false, error: v.error };
356
+ }
288
357
  const store = loadNeuralStore();
289
358
  const action = input.action || 'list';
290
359
  if (action === 'list') {
@@ -328,6 +397,7 @@ export const neuralTools = [
328
397
  return {
329
398
  success: true,
330
399
  _realEmbedding: !!realEmbeddings,
400
+ embeddingProvider: embeddingServiceName,
331
401
  patternId,
332
402
  name: pattern.name,
333
403
  type: pattern.type,
@@ -350,6 +420,7 @@ export const neuralTools = [
350
420
  return {
351
421
  _realSimilarity: true,
352
422
  _realEmbedding: !!realEmbeddings,
423
+ embeddingProvider: embeddingServiceName,
353
424
  query,
354
425
  results: results.map(r => ({
355
426
  id: r.id,
@@ -385,6 +456,11 @@ export const neuralTools = [
385
456
  },
386
457
  },
387
458
  handler: async (input) => {
459
+ if (input.modelId) {
460
+ const v = validateIdentifier(input.modelId, 'modelId');
461
+ if (!v.valid)
462
+ return { success: false, error: v.error };
463
+ }
388
464
  const store = loadNeuralStore();
389
465
  const method = input.method || 'quantize';
390
466
  const targetReduction = input.targetSize || 0.5;
@@ -414,6 +490,7 @@ export const neuralTools = [
414
490
  saveNeuralStore(store);
415
491
  return {
416
492
  success: true, _real: true, method,
493
+ embeddingProvider: embeddingServiceName,
417
494
  patternsCompressed: totalCompressed,
418
495
  compressionRatio: '3.92x (Int8)',
419
496
  beforeBytes: beforeSize,
@@ -437,6 +514,7 @@ export const neuralTools = [
437
514
  saveNeuralStore(store);
438
515
  return {
439
516
  success: true, _real: true, method,
517
+ embeddingProvider: embeddingServiceName,
440
518
  threshold,
441
519
  patternsRemoved: toRemove.length,
442
520
  patternsBefore: beforeCount,
@@ -470,6 +548,7 @@ export const neuralTools = [
470
548
  saveNeuralStore(store);
471
549
  return {
472
550
  success: true, _real: true, method,
551
+ embeddingProvider: embeddingServiceName,
473
552
  patternsMerged: merged.length,
474
553
  patternsBefore: beforeCount,
475
554
  patternsAfter: Object.keys(store.patterns).length,
@@ -490,6 +569,11 @@ export const neuralTools = [
490
569
  },
491
570
  },
492
571
  handler: async (input) => {
572
+ if (input.modelId) {
573
+ const v = validateIdentifier(input.modelId, 'modelId');
574
+ if (!v.valid)
575
+ return { success: false, error: v.error };
576
+ }
493
577
  const store = loadNeuralStore();
494
578
  if (input.modelId) {
495
579
  const model = store.models[input.modelId];
@@ -540,6 +624,11 @@ export const neuralTools = [
540
624
  },
541
625
  },
542
626
  handler: async (input) => {
627
+ if (input.modelId) {
628
+ const v = validateIdentifier(input.modelId, 'modelId');
629
+ if (!v.valid)
630
+ return { success: false, error: v.error };
631
+ }
543
632
  const store = loadNeuralStore();
544
633
  const target = input.target || 'balanced';
545
634
  const patterns = Object.values(store.patterns);
@@ -619,6 +708,7 @@ export const neuralTools = [
619
708
  const elapsed = Math.round(performance.now() - startTime);
620
709
  return {
621
710
  success: true, _real: true, target,
711
+ embeddingProvider: embeddingServiceName,
622
712
  actions,
623
713
  patternsBefore: beforeCount,
624
714
  patternsAfter: Object.keys(store.patterns).length,
@@ -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);
@@ -227,15 +233,15 @@ export const performanceTools = [
227
233
  const suite = input.suite || 'all';
228
234
  const iterations = input.iterations || 100;
229
235
  const warmup = input.warmup !== false;
230
- // REAL benchmark functions
236
+ // Synthetic data benchmarks — measures actual CPU/memory throughput
231
237
  const benchmarkFunctions = {
232
238
  memory: () => {
233
- // Real memory allocation benchmark
239
+ // Synthetic data benchmark — measures actual allocation + sort throughput
234
240
  const arr = new Array(1000).fill(0).map(() => Math.random());
235
241
  arr.sort();
236
242
  },
237
243
  neural: () => {
238
- // Real computation benchmark (matrix-like operations)
244
+ // Synthetic data benchmark — measures actual matrix multiplication throughput
239
245
  const size = 64;
240
246
  const a = Array.from({ length: size }, () => Array.from({ length: size }, () => Math.random()));
241
247
  const b = Array.from({ length: size }, () => Array.from({ length: size }, () => Math.random()));
@@ -249,14 +255,14 @@ export const performanceTools = [
249
255
  }
250
256
  },
251
257
  swarm: () => {
252
- // Real object creation and manipulation
258
+ // Synthetic data benchmark — measures actual object creation + manipulation throughput
253
259
  const agents = Array.from({ length: 10 }, (_, i) => ({ id: i, status: 'active', tasks: [] }));
254
260
  agents.forEach(a => { for (let i = 0; i < 100; i++)
255
261
  a.tasks.push(i); });
256
262
  agents.sort((a, b) => a.tasks.length - b.tasks.length);
257
263
  },
258
264
  io: () => {
259
- // Real JSON serialization benchmark
265
+ // Synthetic data benchmark — measures actual JSON serialization throughput
260
266
  const data = { agents: Array.from({ length: 50 }, (_, i) => ({ id: i, name: `agent-${i}` })) };
261
267
  const json = JSON.stringify(data);
262
268
  JSON.parse(json);
@@ -307,6 +313,7 @@ export const performanceTools = [
307
313
  avgLatency: `${avgLatencyMs.toFixed(3)}ms`,
308
314
  memoryUsage: `${Math.abs(memoryDelta)}KB`,
309
315
  _real: true,
316
+ _dataSource: 'synthetic',
310
317
  });
311
318
  }
312
319
  }
@@ -324,6 +331,7 @@ export const performanceTools = [
324
331
  : { note: 'First benchmark run - no comparison available', totalBenchmarks: allBenchmarks.length };
325
332
  return {
326
333
  _real: true,
334
+ _note: 'Benchmarks use synthetic workloads to measure throughput. Results reflect actual CPU/memory performance.',
327
335
  suite,
328
336
  iterations,
329
337
  warmup,
@@ -346,6 +354,11 @@ export const performanceTools = [
346
354
  },
347
355
  },
348
356
  handler: async (input) => {
357
+ if (input.target) {
358
+ const v = validateIdentifier(input.target, 'target');
359
+ if (!v.valid)
360
+ return { success: false, error: v.error };
361
+ }
349
362
  const target = input.target || 'all';
350
363
  const durationSec = Math.min(input.duration || 1, 10);
351
364
  const durationMs = durationSec * 1000;
@@ -4,6 +4,7 @@
4
4
  * Exposes @ruvector/ruvllm-wasm operations via MCP protocol.
5
5
  * All tools gracefully degrade when the WASM package is not installed.
6
6
  */
7
+ import { validateIdentifier, validateText } from './validate-input.js';
7
8
  async function loadRuvllmWasm() {
8
9
  return import('../ruvector/ruvllm-wasm.js');
9
10
  }
@@ -67,6 +68,16 @@ export const ruvllmWasmTools = [
67
68
  required: ['routerId', 'name', 'embedding'],
68
69
  },
69
70
  handler: async (args) => {
71
+ {
72
+ const v = validateIdentifier(args.routerId, 'routerId');
73
+ if (!v.valid)
74
+ return { content: [{ type: 'text', text: JSON.stringify({ error: v.error }) }], isError: true };
75
+ }
76
+ {
77
+ const v = validateIdentifier(args.name, 'name');
78
+ if (!v.valid)
79
+ return { content: [{ type: 'text', text: JSON.stringify({ error: v.error }) }], isError: true };
80
+ }
70
81
  try {
71
82
  const router = hnswRouters.get(args.routerId);
72
83
  if (!router)
@@ -97,6 +108,11 @@ export const ruvllmWasmTools = [
97
108
  required: ['routerId', 'query'],
98
109
  },
99
110
  handler: async (args) => {
111
+ {
112
+ const v = validateIdentifier(args.routerId, 'routerId');
113
+ if (!v.valid)
114
+ return { content: [{ type: 'text', text: JSON.stringify({ error: v.error }) }], isError: true };
115
+ }
100
116
  try {
101
117
  const router = hnswRouters.get(args.routerId);
102
118
  if (!router)
@@ -150,6 +166,11 @@ export const ruvllmWasmTools = [
150
166
  required: ['sonaId', 'quality'],
151
167
  },
152
168
  handler: async (args) => {
169
+ {
170
+ const v = validateIdentifier(args.sonaId, 'sonaId');
171
+ if (!v.valid)
172
+ return { content: [{ type: 'text', text: JSON.stringify({ error: v.error }) }], isError: true };
173
+ }
153
174
  try {
154
175
  const sona = sonaInstances.get(args.sonaId);
155
176
  if (!sona)
@@ -207,6 +228,11 @@ export const ruvllmWasmTools = [
207
228
  required: ['loraId', 'quality'],
208
229
  },
209
230
  handler: async (args) => {
231
+ {
232
+ const v = validateIdentifier(args.loraId, 'loraId');
233
+ if (!v.valid)
234
+ return { content: [{ type: 'text', text: JSON.stringify({ error: v.error }) }], isError: true };
235
+ }
210
236
  try {
211
237
  const lora = loraInstances.get(args.loraId);
212
238
  if (!lora)
@@ -235,6 +261,11 @@ export const ruvllmWasmTools = [
235
261
  required: ['messages', 'template'],
236
262
  },
237
263
  handler: async (args) => {
264
+ {
265
+ const v = validateText(args.template, 'template', 256);
266
+ if (!v.valid)
267
+ return { content: [{ type: 'text', text: JSON.stringify({ error: v.error }) }], isError: true };
268
+ }
238
269
  try {
239
270
  const mod = await loadRuvllmWasm();
240
271
  const messages = args.messages;
@@ -9,6 +9,7 @@
9
9
  *
10
10
  * Created with ❤️ by ruv.io
11
11
  */
12
+ import { validateText, validateIdentifier } from './validate-input.js';
12
13
  import { autoInstallPackage } from './auto-install.js';
13
14
  import { createRequire } from 'module';
14
15
  // Create require for resolving module paths
@@ -93,6 +94,11 @@ const aidefenceScanTool = {
93
94
  required: ['input'],
94
95
  },
95
96
  handler: async (args) => {
97
+ {
98
+ const v = validateText(args.input, 'input');
99
+ if (!v.valid)
100
+ return { content: [{ type: 'text', text: JSON.stringify({ error: v.error }) }], isError: true };
101
+ }
96
102
  const input = args.input;
97
103
  const quick = args.quick;
98
104
  try {
@@ -167,6 +173,11 @@ const aidefenceAnalyzeTool = {
167
173
  required: ['input'],
168
174
  },
169
175
  handler: async (args) => {
176
+ {
177
+ const v = validateText(args.input, 'input');
178
+ if (!v.valid)
179
+ return { content: [{ type: 'text', text: JSON.stringify({ error: v.error }) }], isError: true };
180
+ }
170
181
  const input = args.input;
171
182
  const searchSimilar = args.searchSimilar !== false;
172
183
  const k = args.k || 5;
@@ -296,6 +307,21 @@ const aidefenceLearnTool = {
296
307
  required: ['input', 'wasAccurate'],
297
308
  },
298
309
  handler: async (args) => {
310
+ {
311
+ const v = validateText(args.input, 'input');
312
+ if (!v.valid)
313
+ return { content: [{ type: 'text', text: JSON.stringify({ error: v.error }) }], isError: true };
314
+ }
315
+ if (args.verdict) {
316
+ const v = validateText(args.verdict, 'verdict');
317
+ if (!v.valid)
318
+ return { content: [{ type: 'text', text: JSON.stringify({ error: v.error }) }], isError: true };
319
+ }
320
+ if (args.threatType) {
321
+ const v = validateIdentifier(args.threatType, 'threatType');
322
+ if (!v.valid)
323
+ return { content: [{ type: 'text', text: JSON.stringify({ error: v.error }) }], isError: true };
324
+ }
299
325
  const input = args.input;
300
326
  const wasAccurate = args.wasAccurate;
301
327
  const verdict = args.verdict;
@@ -358,6 +384,11 @@ const aidefenceIsSafeTool = {
358
384
  required: ['input'],
359
385
  },
360
386
  handler: async (args) => {
387
+ {
388
+ const v = validateText(args.input, 'input');
389
+ if (!v.valid)
390
+ return { content: [{ type: 'text', text: JSON.stringify({ error: v.error }) }], isError: true };
391
+ }
361
392
  const input = args.input;
362
393
  try {
363
394
  const { isSafe } = await import('@claude-flow/aidefence');
@@ -397,6 +428,11 @@ const aidefenceHasPIITool = {
397
428
  required: ['input'],
398
429
  },
399
430
  handler: async (args) => {
431
+ {
432
+ const v = validateText(args.input, 'input');
433
+ if (!v.valid)
434
+ return { content: [{ type: 'text', text: JSON.stringify({ error: v.error }) }], isError: true };
435
+ }
400
436
  const input = args.input;
401
437
  try {
402
438
  const defender = await getAIDefence();
@@ -9,10 +9,12 @@
9
9
  * - os module for system information
10
10
  */
11
11
  import { getProjectCwd } from './types.js';
12
- import { existsSync, readFileSync, writeFileSync, mkdirSync } from 'node:fs';
12
+ import { validateIdentifier } from './validate-input.js';
13
+ import { existsSync, readFileSync, writeFileSync, mkdirSync, statfsSync } from 'node:fs';
13
14
  import { join, dirname } from 'node:path';
14
15
  import { fileURLToPath } from 'node:url';
15
16
  import * as os from 'node:os';
17
+ import * as dns from 'node:dns';
16
18
  // Read version dynamically from package.json
17
19
  function getPackageVersion() {
18
20
  try {
@@ -331,26 +333,60 @@ export const systemTools = [
331
333
  message: 'Neural network health not monitored',
332
334
  });
333
335
  if (input.deep) {
334
- // Disk check — real free space check via os module
336
+ // Disk check — real free space via statfsSync (Node 18.15+)
335
337
  {
336
338
  const t0 = performance.now();
337
- const freeMem = os.freemem();
338
- const totalMem = os.totalmem();
339
- const elapsed = performance.now() - t0;
340
- // Use memory as a proxy; real disk check would need statvfs
341
- checks.push({
342
- name: 'disk',
343
- status: 'unknown',
344
- latency: Math.round(elapsed * 100) / 100,
345
- message: 'Disk space check not implemented — use os-level tools',
346
- });
339
+ try {
340
+ const stats = statfsSync(projectCwd);
341
+ const totalBytes = stats.blocks * stats.bsize;
342
+ const freeBytes = stats.bfree * stats.bsize;
343
+ const totalGB = Math.round((totalBytes / (1024 ** 3)) * 10) / 10;
344
+ const freeGB = Math.round((freeBytes / (1024 ** 3)) * 10) / 10;
345
+ const freePercent = Math.round((freeBytes / totalBytes) * 100);
346
+ const elapsed = performance.now() - t0;
347
+ checks.push({
348
+ name: 'disk',
349
+ status: freePercent > 10 ? 'healthy' : 'warning',
350
+ latency: Math.round(elapsed * 100) / 100,
351
+ message: `${freeGB}GB free of ${totalGB}GB (${freePercent}%)`,
352
+ });
353
+ }
354
+ catch {
355
+ const elapsed = performance.now() - t0;
356
+ checks.push({
357
+ name: 'disk',
358
+ status: 'unknown',
359
+ latency: Math.round(elapsed * 100) / 100,
360
+ message: 'Disk space check failed — statfsSync unavailable',
361
+ });
362
+ }
363
+ }
364
+ // Network — DNS resolution check with timeout
365
+ {
366
+ const t0 = performance.now();
367
+ try {
368
+ await Promise.race([
369
+ dns.promises.lookup('registry.npmjs.org'),
370
+ new Promise((_, reject) => setTimeout(() => reject(new Error('timeout')), 3000)),
371
+ ]);
372
+ const elapsed = performance.now() - t0;
373
+ checks.push({
374
+ name: 'network',
375
+ status: 'healthy',
376
+ latency: Math.round(elapsed * 100) / 100,
377
+ message: 'DNS resolution working',
378
+ });
379
+ }
380
+ catch {
381
+ const elapsed = performance.now() - t0;
382
+ checks.push({
383
+ name: 'network',
384
+ status: 'warning',
385
+ latency: Math.round(elapsed * 100) / 100,
386
+ message: 'DNS resolution failed — check network',
387
+ });
388
+ }
347
389
  }
348
- // Network — cannot verify without making a request
349
- checks.push({
350
- name: 'network',
351
- status: 'unknown',
352
- message: 'Network connectivity not monitored',
353
- });
354
390
  // Database — check if coordination store exists
355
391
  {
356
392
  const t0 = performance.now();
@@ -437,6 +473,11 @@ export const systemTools = [
437
473
  if (!input.confirm) {
438
474
  return { success: false, error: 'Reset requires confirmation' };
439
475
  }
476
+ if (input.component) {
477
+ const v = validateIdentifier(input.component, 'component');
478
+ if (!v.valid)
479
+ return { success: false, error: v.error };
480
+ }
440
481
  const component = input.component || 'metrics';
441
482
  // Reset metrics to defaults
442
483
  const defaultMetrics = {
@@ -5,6 +5,7 @@
5
5
  * @module @claude-flow/cli/mcp-tools/transfer-tools
6
6
  * @version 3.0.0
7
7
  */
8
+ import { validateIdentifier, validateText } from './validate-input.js';
8
9
  /**
9
10
  * Helper to create MCP tool result
10
11
  */
@@ -42,6 +43,11 @@ export const transferTools = [
42
43
  required: ['content'],
43
44
  },
44
45
  handler: async (input) => {
46
+ {
47
+ const v = validateText(input.content, 'content');
48
+ if (!v.valid)
49
+ return createResult({ error: v.error }, true);
50
+ }
45
51
  try {
46
52
  const { detectPII } = await import('../transfer/anonymization/index.js');
47
53
  const result = detectPII(input.content);
@@ -71,6 +77,11 @@ export const transferTools = [
71
77
  required: ['name'],
72
78
  },
73
79
  handler: async (input) => {
80
+ {
81
+ const v = validateIdentifier(input.name, 'name');
82
+ if (!v.valid)
83
+ return createResult({ error: v.error }, true);
84
+ }
74
85
  try {
75
86
  const { resolveIPNS } = await import('../transfer/ipfs/client.js');
76
87
  const result = await resolveIPNS(input.name);
@@ -115,6 +126,16 @@ export const transferTools = [
115
126
  },
116
127
  },
117
128
  handler: async (input) => {
129
+ if (input.query) {
130
+ const v = validateText(input.query, 'query');
131
+ if (!v.valid)
132
+ return createResult({ error: v.error }, true);
133
+ }
134
+ if (input.category) {
135
+ const v = validateIdentifier(input.category, 'category');
136
+ if (!v.valid)
137
+ return createResult({ error: v.error }, true);
138
+ }
118
139
  try {
119
140
  const { PatternStore } = await import('../transfer/store/index.js');
120
141
  const store = new PatternStore();
@@ -143,6 +164,11 @@ export const transferTools = [
143
164
  required: ['id'],
144
165
  },
145
166
  handler: async (input) => {
167
+ {
168
+ const v = validateIdentifier(input.id, 'id');
169
+ if (!v.valid)
170
+ return createResult({ error: v.error }, true);
171
+ }
146
172
  try {
147
173
  const { PatternStore } = await import('../transfer/store/index.js');
148
174
  const store = new PatternStore();
@@ -178,6 +204,11 @@ export const transferTools = [
178
204
  required: ['id'],
179
205
  },
180
206
  handler: async (input) => {
207
+ {
208
+ const v = validateIdentifier(input.id, 'id');
209
+ if (!v.valid)
210
+ return createResult({ error: v.error }, true);
211
+ }
181
212
  try {
182
213
  const { PatternStore } = await import('../transfer/store/index.js');
183
214
  const store = new PatternStore();
@@ -284,6 +315,21 @@ export const transferTools = [
284
315
  },
285
316
  },
286
317
  handler: async (input) => {
318
+ if (input.query) {
319
+ const v = validateText(input.query, 'query');
320
+ if (!v.valid)
321
+ return createResult({ error: v.error }, true);
322
+ }
323
+ if (input.category) {
324
+ const v = validateIdentifier(input.category, 'category');
325
+ if (!v.valid)
326
+ return createResult({ error: v.error }, true);
327
+ }
328
+ if (input.type) {
329
+ const v = validateIdentifier(input.type, 'type');
330
+ if (!v.valid)
331
+ return createResult({ error: v.error }, true);
332
+ }
287
333
  try {
288
334
  const { createPluginDiscoveryService, searchPlugins } = await import('../plugins/store/index.js');
289
335
  const discovery = createPluginDiscoveryService();
@@ -316,6 +362,11 @@ export const transferTools = [
316
362
  required: ['name'],
317
363
  },
318
364
  handler: async (input) => {
365
+ {
366
+ const v = validateIdentifier(input.name, 'name');
367
+ if (!v.valid)
368
+ return createResult({ error: v.error }, true);
369
+ }
319
370
  try {
320
371
  const { createPluginDiscoveryService } = await import('../plugins/store/index.js');
321
372
  const discovery = createPluginDiscoveryService();