@claude-flow/cli 3.7.0 → 3.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -1
- package/dist/src/mcp-tools/agentdb-tools.d.ts +2 -0
- package/dist/src/mcp-tools/agentdb-tools.d.ts.map +1 -1
- package/dist/src/mcp-tools/agentdb-tools.js +492 -2
- package/dist/src/mcp-tools/agentdb-tools.js.map +1 -1
- package/dist/src/mcp-tools/hooks-tools.d.ts.map +1 -1
- package/dist/src/mcp-tools/hooks-tools.js +39 -0
- package/dist/src/mcp-tools/hooks-tools.js.map +1 -1
- package/dist/src/mcp-tools/wasm-agent-tools.d.ts +4 -0
- package/dist/src/mcp-tools/wasm-agent-tools.d.ts.map +1 -1
- package/dist/src/mcp-tools/wasm-agent-tools.js +549 -0
- package/dist/src/mcp-tools/wasm-agent-tools.js.map +1 -1
- package/dist/src/memory/embedding-quantization.d.ts +62 -0
- package/dist/src/memory/embedding-quantization.d.ts.map +1 -0
- package/dist/src/memory/embedding-quantization.js +147 -0
- package/dist/src/memory/embedding-quantization.js.map +1 -0
- package/dist/src/memory/graph-edge-writer.d.ts +61 -0
- package/dist/src/memory/graph-edge-writer.d.ts.map +1 -0
- package/dist/src/memory/graph-edge-writer.js +183 -0
- package/dist/src/memory/graph-edge-writer.js.map +1 -0
- package/dist/src/memory/memory-initializer.d.ts +1 -1
- package/dist/src/memory/memory-initializer.d.ts.map +1 -1
- package/dist/src/memory/memory-initializer.js +37 -0
- package/dist/src/memory/memory-initializer.js.map +1 -1
- package/dist/src/ruvector/agent-wasm.d.ts +46 -11
- package/dist/src/ruvector/agent-wasm.d.ts.map +1 -1
- package/dist/src/ruvector/agent-wasm.js +134 -25
- package/dist/src/ruvector/agent-wasm.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/scripts/bench-rvagent.mjs +312 -0
- package/dist/src/__probe.d.ts +0 -2
- package/dist/src/__probe.d.ts.map +0 -1
- package/dist/src/__probe.js +0 -5
- package/dist/src/__probe.js.map +0 -1
- package/dist/src/commands/benchmark-cosign.d.ts +0 -29
- package/dist/src/commands/benchmark-cosign.d.ts.map +0 -1
- package/dist/src/commands/benchmark-cosign.js +0 -222
- package/dist/src/commands/benchmark-cosign.js.map +0 -1
- package/dist/src/commands/benchmark-verify.d.ts +0 -21
- package/dist/src/commands/benchmark-verify.d.ts.map +0 -1
- package/dist/src/commands/benchmark-verify.js +0 -202
- package/dist/src/commands/benchmark-verify.js.map +0 -1
- package/dist/src/mcp-tools/hive-consensus-runtime.d.ts +0 -149
- package/dist/src/mcp-tools/hive-consensus-runtime.d.ts.map +0 -1
- package/dist/src/mcp-tools/hive-consensus-runtime.js +0 -296
- package/dist/src/mcp-tools/hive-consensus-runtime.js.map +0 -1
- package/dist/src/memory/ann-router-registry.d.ts +0 -61
- package/dist/src/memory/ann-router-registry.d.ts.map +0 -1
- package/dist/src/memory/ann-router-registry.js +0 -72
- package/dist/src/memory/ann-router-registry.js.map +0 -1
- package/dist/src/memory/diskann-registry.d.ts +0 -56
- package/dist/src/memory/diskann-registry.d.ts.map +0 -1
- package/dist/src/memory/diskann-registry.js +0 -88
- package/dist/src/memory/diskann-registry.js.map +0 -1
|
@@ -3,6 +3,10 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Exposes @ruvector/rvagent-wasm operations via MCP protocol.
|
|
5
5
|
* All tools gracefully degrade when the WASM package is not installed.
|
|
6
|
+
*
|
|
7
|
+
* ADR-129: Phase 2 adds wasm_agent_compose + addMcpTools bridge.
|
|
8
|
+
* Phase 3 adds 10 gallery CRUD + 6 agent introspection tools.
|
|
9
|
+
* Phase 4 adds includePlugins to wasm_agent_compose.
|
|
6
10
|
*/
|
|
7
11
|
import type { MCPTool } from './types.js';
|
|
8
12
|
export declare const wasmAgentTools: MCPTool[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wasm-agent-tools.d.ts","sourceRoot":"","sources":["../../../src/mcp-tools/wasm-agent-tools.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"wasm-agent-tools.d.ts","sourceRoot":"","sources":["../../../src/mcp-tools/wasm-agent-tools.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAIH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAsF1C,eAAO,MAAM,cAAc,EAAE,OAAO,EA+oBnC,CAAC"}
|
|
@@ -3,12 +3,82 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Exposes @ruvector/rvagent-wasm operations via MCP protocol.
|
|
5
5
|
* All tools gracefully degrade when the WASM package is not installed.
|
|
6
|
+
*
|
|
7
|
+
* ADR-129: Phase 2 adds wasm_agent_compose + addMcpTools bridge.
|
|
8
|
+
* Phase 3 adds 10 gallery CRUD + 6 agent introspection tools.
|
|
9
|
+
* Phase 4 adds includePlugins to wasm_agent_compose.
|
|
6
10
|
*/
|
|
11
|
+
import { readFileSync, existsSync } from 'node:fs';
|
|
12
|
+
import { resolve } from 'node:path';
|
|
7
13
|
import { validateIdentifier, validateText } from './validate-input.js';
|
|
8
14
|
async function loadAgentWasm() {
|
|
9
15
|
const mod = await import('../ruvector/agent-wasm.js');
|
|
10
16
|
return mod;
|
|
11
17
|
}
|
|
18
|
+
// ── ADR-129 P2 — Destructive-tool gate ──────────────────────────────────────
|
|
19
|
+
/** Tools that can cause data loss or system disruption — require explicit opt-in. */
|
|
20
|
+
const DESTRUCTIVE_TOOL_PATTERNS = [
|
|
21
|
+
/^memory_delete$/,
|
|
22
|
+
/^federation_/,
|
|
23
|
+
/^swarm_shutdown$/,
|
|
24
|
+
/^agent_terminate$/,
|
|
25
|
+
/_delete$/,
|
|
26
|
+
/_remove$/,
|
|
27
|
+
/_drop$/,
|
|
28
|
+
/_shutdown$/,
|
|
29
|
+
];
|
|
30
|
+
function isDestructiveTool(name) {
|
|
31
|
+
return DESTRUCTIVE_TOOL_PATTERNS.some(p => p.test(name));
|
|
32
|
+
}
|
|
33
|
+
/** Safe-by-default MCP tool allowlist for wasm_agent_compose. */
|
|
34
|
+
const SAFE_MCP_TOOLS = new Set([
|
|
35
|
+
'memory_search', 'memory_retrieve', 'memory_list', 'memory_stats',
|
|
36
|
+
'memory_store', 'memory_compress', 'memory_export',
|
|
37
|
+
'embeddings_search', 'embeddings_search_text', 'embeddings_generate',
|
|
38
|
+
'embeddings_status', 'embeddings_compare',
|
|
39
|
+
'hooks_post_task', 'hooks_pre_task', 'hooks_route', 'hooks_metrics',
|
|
40
|
+
'wasm_agent_list', 'wasm_agent_status', 'wasm_agent_files',
|
|
41
|
+
'wasm_gallery_list', 'wasm_gallery_search', 'wasm_gallery_categories',
|
|
42
|
+
'agentdb_pattern_search', 'agentdb_hierarchical_recall',
|
|
43
|
+
'neural_predict', 'neural_patterns', 'neural_status',
|
|
44
|
+
'task_list', 'task_status', 'task_summary',
|
|
45
|
+
]);
|
|
46
|
+
/**
|
|
47
|
+
* Load and parse a plugin's plugin.json, extracting the optional rvagent field.
|
|
48
|
+
* Returns null silently if the plugin or its manifest is missing.
|
|
49
|
+
*/
|
|
50
|
+
function loadPluginManifest(pluginName) {
|
|
51
|
+
const candidateDirs = [
|
|
52
|
+
resolve(process.cwd(), 'plugins', pluginName, '.claude-plugin', 'plugin.json'),
|
|
53
|
+
resolve(process.cwd(), 'plugins', `ruflo-${pluginName}`, '.claude-plugin', 'plugin.json'),
|
|
54
|
+
resolve(process.cwd(), 'v3', 'plugins', pluginName, '.claude-plugin', 'plugin.json'),
|
|
55
|
+
];
|
|
56
|
+
for (const p of candidateDirs) {
|
|
57
|
+
if (existsSync(p)) {
|
|
58
|
+
try {
|
|
59
|
+
return JSON.parse(readFileSync(p, 'utf8'));
|
|
60
|
+
}
|
|
61
|
+
catch { /* skip */ }
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Extract skills declared for WASM agent exposure from a plugin manifest.
|
|
68
|
+
* Handles both string[] and boolean forms of exposeSkillsAsTools.
|
|
69
|
+
*/
|
|
70
|
+
function extractPluginSkills(manifest, pluginName) {
|
|
71
|
+
const rv = manifest.rvagent;
|
|
72
|
+
if (!rv)
|
|
73
|
+
return [];
|
|
74
|
+
const skillNames = Array.isArray(rv.exposeSkillsAsTools) ? rv.exposeSkillsAsTools : [];
|
|
75
|
+
return skillNames.map(skillName => ({
|
|
76
|
+
name: skillName,
|
|
77
|
+
description: `Plugin skill: ${skillName} from ${pluginName}`,
|
|
78
|
+
trigger: skillName,
|
|
79
|
+
content: `Plugin-provided skill: ${skillName}`,
|
|
80
|
+
}));
|
|
81
|
+
}
|
|
12
82
|
export const wasmAgentTools = [
|
|
13
83
|
{
|
|
14
84
|
name: 'wasm_agent_create',
|
|
@@ -287,5 +357,484 @@ export const wasmAgentTools = [
|
|
|
287
357
|
}
|
|
288
358
|
},
|
|
289
359
|
},
|
|
360
|
+
// ── ADR-129 P2 — wasm_agent_compose ────────────────────────────────────────
|
|
361
|
+
{
|
|
362
|
+
name: 'wasm_agent_compose',
|
|
363
|
+
description: [
|
|
364
|
+
'Compose an RVF container with explicit skills, MCP tool descriptors, prompts, and tools.',
|
|
365
|
+
'Returns base64-encoded RVF bytes + a manifest of what was packed.',
|
|
366
|
+
'SECURITY: mcpTools accepts only an explicit allowlist — never pass "*".',
|
|
367
|
+
'Destructive tools (memory_delete, *_shutdown, federation_*, etc.) require',
|
|
368
|
+
'mcpToolsAllowDestructive: true.',
|
|
369
|
+
'Use includePlugins to auto-wire skills from plugins that declare rvagent.exposeSkillsAsTools.',
|
|
370
|
+
].join(' '),
|
|
371
|
+
inputSchema: {
|
|
372
|
+
type: 'object',
|
|
373
|
+
properties: {
|
|
374
|
+
name: { type: 'string', description: 'Optional name for the composed agent' },
|
|
375
|
+
model: { type: 'string', description: 'Model identifier (default: anthropic:claude-sonnet-4-6)' },
|
|
376
|
+
skills: { type: 'array', items: { type: 'string' }, description: 'Skill names to include' },
|
|
377
|
+
mcpTools: {
|
|
378
|
+
type: 'array',
|
|
379
|
+
items: { type: 'string' },
|
|
380
|
+
description: 'Explicit allowlist of MCP tool names to embed (principle of least privilege)',
|
|
381
|
+
},
|
|
382
|
+
mcpToolsAllowDestructive: {
|
|
383
|
+
type: 'boolean',
|
|
384
|
+
description: 'Set true to allow destructive tools (*_delete, *_shutdown, federation_*, etc.)',
|
|
385
|
+
},
|
|
386
|
+
prompts: { type: 'array', items: { type: 'object' }, description: 'Prompt objects to embed' },
|
|
387
|
+
tools: { type: 'array', items: { type: 'object' }, description: 'Tool definitions to embed' },
|
|
388
|
+
includePlugins: {
|
|
389
|
+
type: 'array',
|
|
390
|
+
items: { type: 'string' },
|
|
391
|
+
description: 'Plugin names whose rvagent.exposeSkillsAsTools skills should be included',
|
|
392
|
+
},
|
|
393
|
+
},
|
|
394
|
+
},
|
|
395
|
+
handler: async (args) => {
|
|
396
|
+
try {
|
|
397
|
+
const wasm = await loadAgentWasm();
|
|
398
|
+
const allowDestructive = args.mcpToolsAllowDestructive === true;
|
|
399
|
+
const requestedTools = args.mcpTools ?? [];
|
|
400
|
+
// Validate: reject destructive tools unless explicitly opted in
|
|
401
|
+
const blockedTools = requestedTools.filter(n => isDestructiveTool(n) && !allowDestructive);
|
|
402
|
+
if (blockedTools.length > 0) {
|
|
403
|
+
return {
|
|
404
|
+
content: [{ type: 'text', text: JSON.stringify({
|
|
405
|
+
error: `Destructive tools blocked: ${blockedTools.join(', ')}. Set mcpToolsAllowDestructive: true to allow.`,
|
|
406
|
+
blockedTools,
|
|
407
|
+
}) }],
|
|
408
|
+
isError: true,
|
|
409
|
+
};
|
|
410
|
+
}
|
|
411
|
+
// Build MCP tool descriptors from the allowlist
|
|
412
|
+
const mcpToolDescriptors = requestedTools.map(name => ({
|
|
413
|
+
name,
|
|
414
|
+
description: SAFE_MCP_TOOLS.has(name) ? `Ruflo MCP tool: ${name}` : `MCP tool: ${name}`,
|
|
415
|
+
input_schema: {},
|
|
416
|
+
group: 'ruflo',
|
|
417
|
+
}));
|
|
418
|
+
// ADR-129 P4: auto-wire plugin skills
|
|
419
|
+
const pluginSkills = [];
|
|
420
|
+
const pluginWarnings = [];
|
|
421
|
+
const includePlugins = args.includePlugins ?? [];
|
|
422
|
+
for (const pluginName of includePlugins) {
|
|
423
|
+
const manifest = loadPluginManifest(pluginName);
|
|
424
|
+
if (!manifest) {
|
|
425
|
+
pluginWarnings.push(`Plugin not found: ${pluginName} (skipped)`);
|
|
426
|
+
continue;
|
|
427
|
+
}
|
|
428
|
+
const skills = extractPluginSkills(manifest, pluginName);
|
|
429
|
+
pluginSkills.push(...skills);
|
|
430
|
+
}
|
|
431
|
+
// Merge explicit skills with plugin skills
|
|
432
|
+
const explicitSkillNames = args.skills ?? [];
|
|
433
|
+
const explicitSkills = explicitSkillNames.map(name => ({
|
|
434
|
+
name,
|
|
435
|
+
description: `Skill: ${name}`,
|
|
436
|
+
trigger: name,
|
|
437
|
+
content: name,
|
|
438
|
+
}));
|
|
439
|
+
const allSkills = [...explicitSkills, ...pluginSkills];
|
|
440
|
+
const rvfBytes = await wasm.buildRvfContainer({
|
|
441
|
+
prompts: args.prompts ?? [],
|
|
442
|
+
tools: args.tools ?? [],
|
|
443
|
+
skills: allSkills,
|
|
444
|
+
mcpTools: mcpToolDescriptors,
|
|
445
|
+
});
|
|
446
|
+
const { Buffer } = await import('node:buffer');
|
|
447
|
+
const rvfBase64 = Buffer.from(rvfBytes).toString('base64');
|
|
448
|
+
const manifest = {
|
|
449
|
+
skills: allSkills.map(s => s.name),
|
|
450
|
+
mcpTools: requestedTools,
|
|
451
|
+
prompts: (args.prompts ?? []).length,
|
|
452
|
+
tools: (args.tools ?? []).length,
|
|
453
|
+
rvfSizeBytes: rvfBytes.length,
|
|
454
|
+
pluginWarnings: pluginWarnings.length > 0 ? pluginWarnings : undefined,
|
|
455
|
+
};
|
|
456
|
+
return { content: [{ type: 'text', text: JSON.stringify({ success: true, rvfBase64, manifest }, null, 2) }] };
|
|
457
|
+
}
|
|
458
|
+
catch (err) {
|
|
459
|
+
return { content: [{ type: 'text', text: JSON.stringify({ error: String(err) }) }], isError: true };
|
|
460
|
+
}
|
|
461
|
+
},
|
|
462
|
+
},
|
|
463
|
+
// ── ADR-129 P3 — Agent introspection tools ──────────────────────────────────
|
|
464
|
+
{
|
|
465
|
+
name: 'wasm_agent_state',
|
|
466
|
+
description: 'Read the full internal state of a WASM agent (messages, turn count, config, stop status). Use when native Task is wrong because the agent runs in a sandboxed WASM runtime whose internal conversation history is not directly accessible from the host process.',
|
|
467
|
+
inputSchema: {
|
|
468
|
+
type: 'object',
|
|
469
|
+
properties: { agentId: { type: 'string', description: 'WASM agent ID' } },
|
|
470
|
+
required: ['agentId'],
|
|
471
|
+
},
|
|
472
|
+
handler: async (args) => {
|
|
473
|
+
{
|
|
474
|
+
const v = validateIdentifier(args.agentId, 'agentId');
|
|
475
|
+
if (!v.valid)
|
|
476
|
+
return { content: [{ type: 'text', text: JSON.stringify({ error: v.error }) }], isError: true };
|
|
477
|
+
}
|
|
478
|
+
try {
|
|
479
|
+
const wasm = await loadAgentWasm();
|
|
480
|
+
const state = wasm.getWasmAgentState(args.agentId);
|
|
481
|
+
return { content: [{ type: 'text', text: JSON.stringify({ agentId: args.agentId, state }, null, 2) }] };
|
|
482
|
+
}
|
|
483
|
+
catch (err) {
|
|
484
|
+
return { content: [{ type: 'text', text: JSON.stringify({ error: String(err) }) }], isError: true };
|
|
485
|
+
}
|
|
486
|
+
},
|
|
487
|
+
},
|
|
488
|
+
{
|
|
489
|
+
name: 'wasm_agent_todos',
|
|
490
|
+
description: 'Get the structured todo list of a WASM agent as JSON. Use when native Task is wrong because the todo state lives inside the sandboxed WASM runtime and is not visible to the host process.',
|
|
491
|
+
inputSchema: {
|
|
492
|
+
type: 'object',
|
|
493
|
+
properties: { agentId: { type: 'string', description: 'WASM agent ID' } },
|
|
494
|
+
required: ['agentId'],
|
|
495
|
+
},
|
|
496
|
+
handler: async (args) => {
|
|
497
|
+
{
|
|
498
|
+
const v = validateIdentifier(args.agentId, 'agentId');
|
|
499
|
+
if (!v.valid)
|
|
500
|
+
return { content: [{ type: 'text', text: JSON.stringify({ error: v.error }) }], isError: true };
|
|
501
|
+
}
|
|
502
|
+
try {
|
|
503
|
+
const wasm = await loadAgentWasm();
|
|
504
|
+
const todos = wasm.getWasmAgentTodos(args.agentId);
|
|
505
|
+
return { content: [{ type: 'text', text: JSON.stringify({ agentId: args.agentId, todos }, null, 2) }] };
|
|
506
|
+
}
|
|
507
|
+
catch (err) {
|
|
508
|
+
return { content: [{ type: 'text', text: JSON.stringify({ error: String(err) }) }], isError: true };
|
|
509
|
+
}
|
|
510
|
+
},
|
|
511
|
+
},
|
|
512
|
+
{
|
|
513
|
+
name: 'wasm_agent_tools',
|
|
514
|
+
description: 'List the tools registered on a WASM agent sandbox. Use when native Task is wrong because the tool registry lives inside the WASM runtime and cannot be inspected from the host via standard reflection.',
|
|
515
|
+
inputSchema: {
|
|
516
|
+
type: 'object',
|
|
517
|
+
properties: { agentId: { type: 'string', description: 'WASM agent ID' } },
|
|
518
|
+
required: ['agentId'],
|
|
519
|
+
},
|
|
520
|
+
handler: async (args) => {
|
|
521
|
+
{
|
|
522
|
+
const v = validateIdentifier(args.agentId, 'agentId');
|
|
523
|
+
if (!v.valid)
|
|
524
|
+
return { content: [{ type: 'text', text: JSON.stringify({ error: v.error }) }], isError: true };
|
|
525
|
+
}
|
|
526
|
+
try {
|
|
527
|
+
const wasm = await loadAgentWasm();
|
|
528
|
+
const tools = wasm.getWasmAgentTools(args.agentId);
|
|
529
|
+
return { content: [{ type: 'text', text: JSON.stringify({ agentId: args.agentId, tools }, null, 2) }] };
|
|
530
|
+
}
|
|
531
|
+
catch (err) {
|
|
532
|
+
return { content: [{ type: 'text', text: JSON.stringify({ error: String(err) }) }], isError: true };
|
|
533
|
+
}
|
|
534
|
+
},
|
|
535
|
+
},
|
|
536
|
+
{
|
|
537
|
+
name: 'wasm_agent_turn_count',
|
|
538
|
+
description: 'Return the current turn count of a WASM agent. Use when native Task is wrong because turn-limit enforcement and progress tracking must be polled from inside the sandboxed WASM runtime rather than inferred externally.',
|
|
539
|
+
inputSchema: {
|
|
540
|
+
type: 'object',
|
|
541
|
+
properties: { agentId: { type: 'string', description: 'WASM agent ID' } },
|
|
542
|
+
required: ['agentId'],
|
|
543
|
+
},
|
|
544
|
+
handler: async (args) => {
|
|
545
|
+
{
|
|
546
|
+
const v = validateIdentifier(args.agentId, 'agentId');
|
|
547
|
+
if (!v.valid)
|
|
548
|
+
return { content: [{ type: 'text', text: JSON.stringify({ error: v.error }) }], isError: true };
|
|
549
|
+
}
|
|
550
|
+
try {
|
|
551
|
+
const wasm = await loadAgentWasm();
|
|
552
|
+
const info = wasm.getWasmAgent(args.agentId);
|
|
553
|
+
if (!info)
|
|
554
|
+
return { content: [{ type: 'text', text: JSON.stringify({ error: `Agent not found: ${args.agentId}` }) }], isError: true };
|
|
555
|
+
return { content: [{ type: 'text', text: JSON.stringify({ agentId: args.agentId, turnCount: info.turnCount }, null, 2) }] };
|
|
556
|
+
}
|
|
557
|
+
catch (err) {
|
|
558
|
+
return { content: [{ type: 'text', text: JSON.stringify({ error: String(err) }) }], isError: true };
|
|
559
|
+
}
|
|
560
|
+
},
|
|
561
|
+
},
|
|
562
|
+
{
|
|
563
|
+
name: 'wasm_agent_is_stopped',
|
|
564
|
+
description: 'Check whether a WASM agent has reached its stop condition (max turns or explicit stop). Use when native Task is wrong because the stop condition is evaluated inside the WASM runtime and not observable from the host without an explicit query.',
|
|
565
|
+
inputSchema: {
|
|
566
|
+
type: 'object',
|
|
567
|
+
properties: { agentId: { type: 'string', description: 'WASM agent ID' } },
|
|
568
|
+
required: ['agentId'],
|
|
569
|
+
},
|
|
570
|
+
handler: async (args) => {
|
|
571
|
+
{
|
|
572
|
+
const v = validateIdentifier(args.agentId, 'agentId');
|
|
573
|
+
if (!v.valid)
|
|
574
|
+
return { content: [{ type: 'text', text: JSON.stringify({ error: v.error }) }], isError: true };
|
|
575
|
+
}
|
|
576
|
+
try {
|
|
577
|
+
const wasm = await loadAgentWasm();
|
|
578
|
+
const info = wasm.getWasmAgent(args.agentId);
|
|
579
|
+
if (!info)
|
|
580
|
+
return { content: [{ type: 'text', text: JSON.stringify({ error: `Agent not found: ${args.agentId}` }) }], isError: true };
|
|
581
|
+
return { content: [{ type: 'text', text: JSON.stringify({ agentId: args.agentId, isStopped: info.isStopped }, null, 2) }] };
|
|
582
|
+
}
|
|
583
|
+
catch (err) {
|
|
584
|
+
return { content: [{ type: 'text', text: JSON.stringify({ error: String(err) }) }], isError: true };
|
|
585
|
+
}
|
|
586
|
+
},
|
|
587
|
+
},
|
|
588
|
+
{
|
|
589
|
+
name: 'wasm_agent_reset',
|
|
590
|
+
description: 'Reset a WASM agent — clears messages and turn count so it can be reused across tasks. Use when native Task is wrong because the agent lives in a sandboxed WASM runtime that must be explicitly reset rather than simply re-spawned.',
|
|
591
|
+
inputSchema: {
|
|
592
|
+
type: 'object',
|
|
593
|
+
properties: { agentId: { type: 'string', description: 'WASM agent ID' } },
|
|
594
|
+
required: ['agentId'],
|
|
595
|
+
},
|
|
596
|
+
handler: async (args) => {
|
|
597
|
+
{
|
|
598
|
+
const v = validateIdentifier(args.agentId, 'agentId');
|
|
599
|
+
if (!v.valid)
|
|
600
|
+
return { content: [{ type: 'text', text: JSON.stringify({ error: v.error }) }], isError: true };
|
|
601
|
+
}
|
|
602
|
+
try {
|
|
603
|
+
const wasm = await loadAgentWasm();
|
|
604
|
+
const ok = wasm.resetWasmAgent(args.agentId);
|
|
605
|
+
return { content: [{ type: 'text', text: JSON.stringify({ success: ok, agentId: args.agentId }) }] };
|
|
606
|
+
}
|
|
607
|
+
catch (err) {
|
|
608
|
+
return { content: [{ type: 'text', text: JSON.stringify({ error: String(err) }) }], isError: true };
|
|
609
|
+
}
|
|
610
|
+
},
|
|
611
|
+
},
|
|
612
|
+
// ── ADR-129 P3 — Gallery CRUD tools ─────────────────────────────────────────
|
|
613
|
+
{
|
|
614
|
+
name: 'wasm_gallery_load_rvf',
|
|
615
|
+
description: 'Load a named gallery template as a base64-encoded RVF container. Use when native Read is wrong because RVF containers are packed inside the WASM gallery store and are not accessible as plain filesystem files.',
|
|
616
|
+
inputSchema: {
|
|
617
|
+
type: 'object',
|
|
618
|
+
properties: { id: { type: 'string', description: 'Gallery template ID' } },
|
|
619
|
+
required: ['id'],
|
|
620
|
+
},
|
|
621
|
+
handler: async (args) => {
|
|
622
|
+
{
|
|
623
|
+
const v = validateIdentifier(args.id, 'id');
|
|
624
|
+
if (!v.valid)
|
|
625
|
+
return { content: [{ type: 'text', text: JSON.stringify({ error: v.error }) }], isError: true };
|
|
626
|
+
}
|
|
627
|
+
try {
|
|
628
|
+
const wasm = await loadAgentWasm();
|
|
629
|
+
const bytes = await wasm.galleryLoadRvf(args.id);
|
|
630
|
+
const { Buffer } = await import('node:buffer');
|
|
631
|
+
return { content: [{ type: 'text', text: JSON.stringify({ id: args.id, rvfBase64: Buffer.from(bytes).toString('base64'), sizeBytes: bytes.length }, null, 2) }] };
|
|
632
|
+
}
|
|
633
|
+
catch (err) {
|
|
634
|
+
return { content: [{ type: 'text', text: JSON.stringify({ error: String(err) }) }], isError: true };
|
|
635
|
+
}
|
|
636
|
+
},
|
|
637
|
+
},
|
|
638
|
+
{
|
|
639
|
+
name: 'wasm_gallery_configure',
|
|
640
|
+
description: 'Apply runtime configuration overrides (e.g. maxTurns, model) to the active WASM gallery template. Use when native Edit is wrong because gallery configuration lives inside the WASM runtime state and cannot be changed via filesystem writes.',
|
|
641
|
+
inputSchema: {
|
|
642
|
+
type: 'object',
|
|
643
|
+
properties: { config: { type: 'object', description: 'Configuration overrides (e.g. {maxTurns: 100})' } },
|
|
644
|
+
required: ['config'],
|
|
645
|
+
},
|
|
646
|
+
handler: async (args) => {
|
|
647
|
+
try {
|
|
648
|
+
const wasm = await loadAgentWasm();
|
|
649
|
+
await wasm.galleryConfigure(JSON.stringify(args.config));
|
|
650
|
+
return { content: [{ type: 'text', text: JSON.stringify({ success: true }) }] };
|
|
651
|
+
}
|
|
652
|
+
catch (err) {
|
|
653
|
+
return { content: [{ type: 'text', text: JSON.stringify({ error: String(err) }) }], isError: true };
|
|
654
|
+
}
|
|
655
|
+
},
|
|
656
|
+
},
|
|
657
|
+
{
|
|
658
|
+
name: 'wasm_gallery_categories',
|
|
659
|
+
description: 'Return all WASM gallery template categories with per-category template counts. Use when native Bash/ls is wrong because gallery category metadata is indexed inside the WASM runtime, not on the filesystem.',
|
|
660
|
+
inputSchema: { type: 'object', properties: {} },
|
|
661
|
+
handler: async () => {
|
|
662
|
+
try {
|
|
663
|
+
const wasm = await loadAgentWasm();
|
|
664
|
+
const categories = await wasm.getGalleryCategories();
|
|
665
|
+
return { content: [{ type: 'text', text: JSON.stringify({ categories }, null, 2) }] };
|
|
666
|
+
}
|
|
667
|
+
catch (err) {
|
|
668
|
+
return { content: [{ type: 'text', text: JSON.stringify({ error: String(err) }) }], isError: true };
|
|
669
|
+
}
|
|
670
|
+
},
|
|
671
|
+
},
|
|
672
|
+
{
|
|
673
|
+
name: 'wasm_gallery_list_by_category',
|
|
674
|
+
description: 'List WASM gallery templates filtered to a specific category. Use when native Glob is wrong because gallery templates are stored in the WASM runtime registry, not as individual filesystem files.',
|
|
675
|
+
inputSchema: {
|
|
676
|
+
type: 'object',
|
|
677
|
+
properties: { category: { type: 'string', description: 'Category name' } },
|
|
678
|
+
required: ['category'],
|
|
679
|
+
},
|
|
680
|
+
handler: async (args) => {
|
|
681
|
+
{
|
|
682
|
+
const v = validateIdentifier(args.category, 'category');
|
|
683
|
+
if (!v.valid)
|
|
684
|
+
return { content: [{ type: 'text', text: JSON.stringify({ error: v.error }) }], isError: true };
|
|
685
|
+
}
|
|
686
|
+
try {
|
|
687
|
+
const wasm = await loadAgentWasm();
|
|
688
|
+
const templates = await wasm.galleryListByCategory(args.category);
|
|
689
|
+
return { content: [{ type: 'text', text: JSON.stringify({ category: args.category, templates }, null, 2) }] };
|
|
690
|
+
}
|
|
691
|
+
catch (err) {
|
|
692
|
+
return { content: [{ type: 'text', text: JSON.stringify({ error: String(err) }) }], isError: true };
|
|
693
|
+
}
|
|
694
|
+
},
|
|
695
|
+
},
|
|
696
|
+
{
|
|
697
|
+
name: 'wasm_gallery_add_custom',
|
|
698
|
+
description: 'Add a custom agent template to the WASM gallery registry. Use when native Write is wrong because custom templates must be registered inside the WASM runtime store, not written as plain files.',
|
|
699
|
+
inputSchema: {
|
|
700
|
+
type: 'object',
|
|
701
|
+
properties: { template: { type: 'object', description: 'Template object to add' } },
|
|
702
|
+
required: ['template'],
|
|
703
|
+
},
|
|
704
|
+
handler: async (args) => {
|
|
705
|
+
try {
|
|
706
|
+
const wasm = await loadAgentWasm();
|
|
707
|
+
await wasm.galleryAddCustom(JSON.stringify(args.template));
|
|
708
|
+
return { content: [{ type: 'text', text: JSON.stringify({ success: true }) }] };
|
|
709
|
+
}
|
|
710
|
+
catch (err) {
|
|
711
|
+
return { content: [{ type: 'text', text: JSON.stringify({ error: String(err) }) }], isError: true };
|
|
712
|
+
}
|
|
713
|
+
},
|
|
714
|
+
},
|
|
715
|
+
{
|
|
716
|
+
name: 'wasm_gallery_remove_custom',
|
|
717
|
+
description: 'Remove a custom template from the WASM gallery by ID. Use when native Bash rm is wrong because custom templates exist only inside the WASM runtime registry and cannot be deleted via filesystem operations.',
|
|
718
|
+
inputSchema: {
|
|
719
|
+
type: 'object',
|
|
720
|
+
properties: { id: { type: 'string', description: 'Custom template ID to remove' } },
|
|
721
|
+
required: ['id'],
|
|
722
|
+
},
|
|
723
|
+
handler: async (args) => {
|
|
724
|
+
{
|
|
725
|
+
const v = validateIdentifier(args.id, 'id');
|
|
726
|
+
if (!v.valid)
|
|
727
|
+
return { content: [{ type: 'text', text: JSON.stringify({ error: v.error }) }], isError: true };
|
|
728
|
+
}
|
|
729
|
+
try {
|
|
730
|
+
const wasm = await loadAgentWasm();
|
|
731
|
+
await wasm.galleryRemoveCustom(args.id);
|
|
732
|
+
return { content: [{ type: 'text', text: JSON.stringify({ success: true, id: args.id }) }] };
|
|
733
|
+
}
|
|
734
|
+
catch (err) {
|
|
735
|
+
return { content: [{ type: 'text', text: JSON.stringify({ error: String(err) }) }], isError: true };
|
|
736
|
+
}
|
|
737
|
+
},
|
|
738
|
+
},
|
|
739
|
+
{
|
|
740
|
+
name: 'wasm_gallery_import',
|
|
741
|
+
description: [
|
|
742
|
+
'HIGH RISK: Import custom templates from JSON into the gallery.',
|
|
743
|
+
'The payload is deserialized inside the WASM runtime — a malicious system_prompt',
|
|
744
|
+
'in an imported template can direct agents toward harmful behavior.',
|
|
745
|
+
'Input is scanned by AIDefence when available.',
|
|
746
|
+
'Requires explicit confirmation of the source before use.',
|
|
747
|
+
].join(' '),
|
|
748
|
+
inputSchema: {
|
|
749
|
+
type: 'object',
|
|
750
|
+
properties: {
|
|
751
|
+
templatesJson: { type: 'string', description: 'JSON string of template array to import' },
|
|
752
|
+
},
|
|
753
|
+
required: ['templatesJson'],
|
|
754
|
+
},
|
|
755
|
+
handler: async (args) => {
|
|
756
|
+
{
|
|
757
|
+
const v = validateText(args.templatesJson, 'templatesJson');
|
|
758
|
+
if (!v.valid)
|
|
759
|
+
return { content: [{ type: 'text', text: JSON.stringify({ error: v.error }) }], isError: true };
|
|
760
|
+
}
|
|
761
|
+
try {
|
|
762
|
+
// ADR-129 P3 AIDefence gate — scan for prompt injection before WASM deserialization.
|
|
763
|
+
// ADR-118 pattern: lazy import @claude-flow/aidefence; warn and continue if unavailable.
|
|
764
|
+
let aiDefenceWarning;
|
|
765
|
+
try {
|
|
766
|
+
const aidefenceMod = await import('@claude-flow/aidefence');
|
|
767
|
+
const defence = aidefenceMod.createAIDefence({ enableLearning: false });
|
|
768
|
+
if (defence) {
|
|
769
|
+
const scanResult = await defence.scan(args.templatesJson);
|
|
770
|
+
if (scanResult && scanResult.isThreat) {
|
|
771
|
+
return {
|
|
772
|
+
content: [{ type: 'text', text: JSON.stringify({
|
|
773
|
+
error: 'AIDefence blocked import: potential prompt injection detected in template payload',
|
|
774
|
+
HIGH_RISK: true,
|
|
775
|
+
}) }],
|
|
776
|
+
isError: true,
|
|
777
|
+
};
|
|
778
|
+
}
|
|
779
|
+
}
|
|
780
|
+
}
|
|
781
|
+
catch {
|
|
782
|
+
aiDefenceWarning = 'AIDefence not available — import proceeded without prompt-injection scan';
|
|
783
|
+
console.warn(`[wasm_gallery_import] HIGH_RISK: ${aiDefenceWarning}`);
|
|
784
|
+
}
|
|
785
|
+
const wasm = await loadAgentWasm();
|
|
786
|
+
const count = await wasm.galleryImportCustom(args.templatesJson);
|
|
787
|
+
return { content: [{ type: 'text', text: JSON.stringify({ success: true, importedCount: count, warning: aiDefenceWarning }, null, 2) }] };
|
|
788
|
+
}
|
|
789
|
+
catch (err) {
|
|
790
|
+
return { content: [{ type: 'text', text: JSON.stringify({ error: String(err) }) }], isError: true };
|
|
791
|
+
}
|
|
792
|
+
},
|
|
793
|
+
},
|
|
794
|
+
{
|
|
795
|
+
name: 'wasm_gallery_export',
|
|
796
|
+
description: 'Export all custom WASM gallery templates as a JSON snapshot. Use when native Read/cat is wrong because custom templates live inside the WASM runtime store and are not persisted as individual files on disk.',
|
|
797
|
+
inputSchema: { type: 'object', properties: {} },
|
|
798
|
+
handler: async () => {
|
|
799
|
+
try {
|
|
800
|
+
const wasm = await loadAgentWasm();
|
|
801
|
+
const exported = await wasm.galleryExportCustom();
|
|
802
|
+
return { content: [{ type: 'text', text: JSON.stringify({ exported }, null, 2) }] };
|
|
803
|
+
}
|
|
804
|
+
catch (err) {
|
|
805
|
+
return { content: [{ type: 'text', text: JSON.stringify({ error: String(err) }) }], isError: true };
|
|
806
|
+
}
|
|
807
|
+
},
|
|
808
|
+
},
|
|
809
|
+
{
|
|
810
|
+
name: 'wasm_gallery_active',
|
|
811
|
+
description: 'Return the ID of the currently active WASM gallery template. Use when native Bash is wrong because the active-template cursor is tracked inside the WASM runtime state, not in a file you can read directly.',
|
|
812
|
+
inputSchema: { type: 'object', properties: {} },
|
|
813
|
+
handler: async () => {
|
|
814
|
+
try {
|
|
815
|
+
const wasm = await loadAgentWasm();
|
|
816
|
+
const activeId = await wasm.galleryGetActive();
|
|
817
|
+
return { content: [{ type: 'text', text: JSON.stringify({ activeId: activeId ?? null }, null, 2) }] };
|
|
818
|
+
}
|
|
819
|
+
catch (err) {
|
|
820
|
+
return { content: [{ type: 'text', text: JSON.stringify({ error: String(err) }) }], isError: true };
|
|
821
|
+
}
|
|
822
|
+
},
|
|
823
|
+
},
|
|
824
|
+
{
|
|
825
|
+
name: 'wasm_gallery_config',
|
|
826
|
+
description: 'Get the runtime configuration overrides applied to the active WASM gallery template. Use when native Read is wrong because gallery config overrides are stored in the WASM runtime state rather than as an editable config file.',
|
|
827
|
+
inputSchema: { type: 'object', properties: {} },
|
|
828
|
+
handler: async () => {
|
|
829
|
+
try {
|
|
830
|
+
const wasm = await loadAgentWasm();
|
|
831
|
+
const config = await wasm.galleryGetConfig();
|
|
832
|
+
return { content: [{ type: 'text', text: JSON.stringify({ config }, null, 2) }] };
|
|
833
|
+
}
|
|
834
|
+
catch (err) {
|
|
835
|
+
return { content: [{ type: 'text', text: JSON.stringify({ error: String(err) }) }], isError: true };
|
|
836
|
+
}
|
|
837
|
+
},
|
|
838
|
+
},
|
|
290
839
|
];
|
|
291
840
|
//# sourceMappingURL=wasm-agent-tools.js.map
|