konoha-mcp 2.2.23 → 2.2.25
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/NOTICE +14 -8
- package/README.md +20 -5
- package/apps/web/build/adapter-node.js +1 -1
- package/apps/web/build/build-meta.json +2 -2
- package/apps/web/build/client/_app/immutable/entry/{app.TYH87iYy.js → app.DtoBIrs4.js} +2 -2
- package/apps/web/build/client/_app/immutable/entry/app.DtoBIrs4.js.br +0 -0
- package/apps/web/build/client/_app/immutable/entry/app.DtoBIrs4.js.gz +0 -0
- package/apps/web/build/client/_app/immutable/nodes/{0.D7dPIEWA.js → 0.B8Iw7Xl1.js} +1 -1
- package/apps/web/build/client/_app/immutable/nodes/0.B8Iw7Xl1.js.br +0 -0
- package/apps/web/build/client/_app/immutable/nodes/{0.D7dPIEWA.js.gz → 0.B8Iw7Xl1.js.gz} +0 -0
- package/apps/web/build/client/_app/immutable/nodes/{13.TOXVaTBr.js → 13.CQB_Ed6W.js} +1 -1
- package/apps/web/build/client/_app/immutable/nodes/13.CQB_Ed6W.js.br +0 -0
- package/apps/web/build/client/_app/immutable/nodes/{13.TOXVaTBr.js.gz → 13.CQB_Ed6W.js.gz} +0 -0
- package/apps/web/build/client/_app/version.json +1 -1
- package/apps/web/build/client/_app/version.json.br +0 -0
- package/apps/web/build/client/_app/version.json.gz +0 -0
- package/apps/web/build/server/chunks/instance.js +3 -3
- package/apps/web/build/server/chunks/internal.js +1 -1
- package/apps/web/build/server/entries/pages/_layout.svelte.js +1 -1
- package/apps/web/build/server/entries/pages/_layout.svelte.js.map +1 -1
- package/apps/web/build/server/entries/pages/docs/_page.svelte.js +1 -1
- package/apps/web/build/server/entries/pages/docs/_page.svelte.js.map +1 -1
- package/apps/web/build/server/manifest-full.js +1 -1
- package/apps/web/build/server/manifest.js +1 -1
- package/apps/web/build/server/nodes/0.js +1 -1
- package/apps/web/build/server/nodes/13.js +1 -1
- package/apps/web/build/server/server.js +1 -1
- package/apps/web/package.json +1 -1
- package/assets/demo-agy.webp +0 -0
- package/assets/demo-claude.webp +0 -0
- package/assets/demo-codex.webp +0 -0
- package/assets/demo-commandcode.webp +0 -0
- package/assets/demo-cursor.webp +0 -0
- package/assets/demo-opencode.webp +0 -0
- package/assets/demo-pi.webp +0 -0
- package/assets/demo-skill-embed.webp +0 -0
- package/assets/demo-skills.webp +0 -0
- package/assets/demo-web.webp +0 -0
- package/assets/demo.webp +0 -0
- package/assets/konoha-akatsuki-flow.webp +0 -0
- package/assets/konoha-anbu-flow.webp +0 -0
- package/assets/konoha-flow-12-cli-upgrade-progress-engine.webp +0 -0
- package/assets/konoha-jonin-flow.webp +0 -0
- package/assets/konoha-kage-gate.webp +0 -0
- package/assets/konoha-langgraph-flow.webp +0 -0
- package/assets/konoha-orchestration-flow.webp +0 -0
- package/assets/konoha-qa-flow.webp +0 -0
- package/assets/konoha-telegram-flow.webp +0 -0
- package/assets/testing.webp +0 -0
- package/bin/commands/bridge.js +62 -4
- package/bin/commands/doctor.js +2 -0
- package/bin/commands/doctor_services.js +57 -0
- package/bin/commands/init.js +29 -8
- package/bin/commands/init_clients.js +95 -8
- package/bin/commands/init_migration.js +32 -1
- package/bin/lib/config_defaults.js +3 -0
- package/bin/lib/runtime_install.js +147 -54
- package/node_modules/jszip/package.json +2 -2
- package/node_modules/string_decoder/package.json +1 -1
- package/package.json +10 -3
- package/patches/gpt-tokenizer@4.1.0.patch +15 -0
- package/patches/jszip@3.10.2.patch +11 -0
- package/patches/string_decoder@1.3.0.patch +12 -0
- package/src/agent_contract.js +2 -2
- package/src/agent_deployer.js +48 -35
- package/src/agent_file_safety.js +57 -0
- package/src/antigravity_subagent_hook.js +30 -12
- package/src/bridge/gateway.js +2 -0
- package/src/bridge/gateway_adapters.js +155 -29
- package/src/bridge/handlers/anthropic.js +95 -26
- package/src/bridge/handlers/openai.js +18 -5
- package/src/bridge/sidecar/raw.js +10 -2
- package/src/bridge/stream_usage.js +66 -0
- package/src/chunin_knowledge_ddl.js +95 -0
- package/src/client_commands.js +190 -0
- package/src/db_bridges.js +53 -7
- package/src/db_schema.js +14 -2
- package/src/deploy_installer.js +212 -11
- package/src/deploy_utils.js +4 -0
- package/src/file_tools/common.js +65 -3
- package/src/file_tools_mcp.js +17 -9
- package/src/file_tools_router.js +67 -6
- package/src/global_skill_sync.js +3 -1
- package/src/mcp/chunin_knowledge.js +509 -0
- package/src/mcp/langgraph/edges/router.js +3 -0
- package/src/mcp/langgraph/index.js +22 -3
- package/src/mcp/langgraph/nodes/dispatch.js +3 -0
- package/src/mcp/langgraph/nodes/execute.js +87 -13
- package/src/mcp/langgraph/nodes/review.js +13 -1
- package/src/mcp/langgraph/slice_executor_registry.js +22 -0
- package/src/mcp/langgraph/state.js +5 -0
- package/src/mcp/lazy_subagent.js +11 -1
- package/src/mcp/memory_project_context.js +4 -1
- package/src/mcp/memory_subagent_runner.js +2 -1
- package/src/mcp/skills_common.js +1 -0
- package/src/mcp/subagent_spawner.js +7 -0
- package/src/mcp/todo_walkthrough_sync.js +7 -0
- package/src/mcp/tool_dispatch.js +18 -1
- package/src/mcp/web_search.js +27 -3
- package/src/mcp/workflow_completion_helpers.js +6 -1
- package/src/mcp/workflow_gates.js +118 -5
- package/src/mcp/workflow_sannin.js +9 -3
- package/src/mcp_clients/common.js +31 -0
- package/src/mcp_tool_manifest.json +36 -1
- package/src/pi_fs_helpers.js +31 -0
- package/src/pi_manager.js +68 -28
- package/src/provider_usage_logger.js +92 -0
- package/src/schema_ddl.js +17 -1
- package/src/templates/AGENTS.md +1 -1
- package/src/templates/GEMINI.md +1 -1
- package/src/templates/skills/chunin-skill/SKILL.md +34 -0
- package/src/templates/skills/chunin-skill/references/deep-research-analyst.md +27 -10
- package/src/templates/skills/kage-skill/SKILL.md +1 -1
- package/src/templates/skills/konoha/SKILL.md +23 -165
- package/src/templates/skills/konoha/references/contract.md +2 -2
- package/src/templates/skills/konoha/references/peragent-usage.md +1 -1
- package/src/token_usage.js +57 -0
- package/src/tools_savings_logger.js +26 -8
- package/src/url_canonical.js +58 -0
- package/src/vector_pipeline.js +6 -4
- package/src/vector_search.js +4 -2
- package/src/web/controllers/core_controller.js +10 -1
- package/src/workflow/jonin-builder/live_browser_monitor.js +23 -7
- package/apps/web/build/client/_app/immutable/entry/app.TYH87iYy.js.br +0 -0
- package/apps/web/build/client/_app/immutable/entry/app.TYH87iYy.js.gz +0 -0
- package/apps/web/build/client/_app/immutable/nodes/0.D7dPIEWA.js.br +0 -0
- package/apps/web/build/client/_app/immutable/nodes/13.TOXVaTBr.js.br +0 -0
- package/src/templates/skills/konoha/references/architecture.md +0 -99
- package/src/templates/skills/konoha/references/benchmark.md +0 -123
- package/src/templates/skills/konoha/references/docs.md +0 -46
- package/src/templates/skills/konoha/references/test.md +0 -71
- package/src/templates/skills/konoha/references/workflow.md +0 -104
|
@@ -10,6 +10,7 @@ const { normalizeAgentName } = require('../../../canonical_agents');
|
|
|
10
10
|
const { getActiveClient } = require('../../runtime_state');
|
|
11
11
|
const { detectActiveClient, resolveFirstSpawnClient } = require('../../client_detection');
|
|
12
12
|
const { finalizeNodeResult } = require('../budget');
|
|
13
|
+
const { getSliceExecutor } = require('../slice_executor_registry');
|
|
13
14
|
const { syncTodoAndWalkthrough } = require('../../todo_walkthrough_sync');
|
|
14
15
|
const worktree = require('../../worktree_isolation');
|
|
15
16
|
|
|
@@ -21,6 +22,15 @@ function recordCompletedDispatch(status, dispatchId) {
|
|
|
21
22
|
}
|
|
22
23
|
}
|
|
23
24
|
|
|
25
|
+
function _branchFailed(branchResult) {
|
|
26
|
+
if (!branchResult) return false;
|
|
27
|
+
if (branchResult.spawn_state) return branchResult.spawn_state === 'failed';
|
|
28
|
+
return branchResult.status === 'failed'
|
|
29
|
+
|| branchResult.status === 'error'
|
|
30
|
+
|| branchResult.status === 'timeout'
|
|
31
|
+
|| Boolean(branchResult.error_code);
|
|
32
|
+
}
|
|
33
|
+
|
|
24
34
|
async function _executeTaskBranchConcurrently(task, idx, status, state, sliceExecutor) {
|
|
25
35
|
const startedAt = Date.now();
|
|
26
36
|
await new Promise((resolve) => setTimeout(resolve, 2));
|
|
@@ -28,6 +38,13 @@ async function _executeTaskBranchConcurrently(task, idx, status, state, sliceExe
|
|
|
28
38
|
const targetAgent = normalizeAgentName(task.agent || status.assigned_agent || 'anbu');
|
|
29
39
|
if (typeof sliceExecutor === 'function') {
|
|
30
40
|
branchResult = await sliceExecutor(task, idx, status, state);
|
|
41
|
+
// A sliceExecutor is the caller's own trusted executor: it ran the work and
|
|
42
|
+
// reports the outcome. Absent an explicit denial, its documented `completed`
|
|
43
|
+
// status is the completion signal — the MCP runner path below is the one
|
|
44
|
+
// that never spawns anything and therefore never earns that status.
|
|
45
|
+
if (branchResult && branchResult.child_execution_verified === undefined) {
|
|
46
|
+
branchResult.child_execution_verified = branchResult.status === 'completed';
|
|
47
|
+
}
|
|
31
48
|
} else {
|
|
32
49
|
const projectPath = state.projectPath || status.project_path || process.cwd();
|
|
33
50
|
const taskDir = state.taskDir || status.task_dir || '';
|
|
@@ -47,18 +64,27 @@ async function _executeTaskBranchConcurrently(task, idx, status, state, sliceExe
|
|
|
47
64
|
});
|
|
48
65
|
let parsedMcp = {};
|
|
49
66
|
try { parsedMcp = JSON.parse(rawMcp); } catch (_) { parsedMcp = {}; }
|
|
67
|
+
// `runMcpAgentAsync` prepares a prompt and a spawn directive; it never starts
|
|
68
|
+
// a child process. Reporting the slice as completed with "exit 0" made an
|
|
69
|
+
// unspawned slice indistinguishable from a finished one, which is how a run
|
|
70
|
+
// could reach Gate 2 having executed nothing. Without a sliceExecutor there
|
|
71
|
+
// is no exit code to cite, so the slice stays pending and carries the
|
|
72
|
+
// directive the client must actually run.
|
|
50
73
|
branchResult = {
|
|
51
74
|
task_id: task.id,
|
|
52
75
|
agent: parsedMcp.agent || targetAgent,
|
|
53
76
|
model: parsedMcp.model || 'inherit',
|
|
54
77
|
spawn_directive: parsedMcp.spawn_directive || null,
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
78
|
+
spawn_error: parsedMcp.spawn_error || null,
|
|
79
|
+
summary: `Spawn directive prepared for @${targetAgent} slice (${task.id}); no child process was started by the MCP runner`,
|
|
80
|
+
status: 'spawn_pending',
|
|
81
|
+
spawn_state: 'directive_only',
|
|
82
|
+
child_execution_verified: false,
|
|
83
|
+
validation: []
|
|
59
84
|
};
|
|
60
85
|
}
|
|
61
86
|
const completedAt = Date.now();
|
|
87
|
+
const childVerified = branchResult?.child_execution_verified === true;
|
|
62
88
|
const advisorEval = await evaluateWorkerTurnAsync({
|
|
63
89
|
agent: task.agent || status.assigned_agent || 'anbu',
|
|
64
90
|
taskId: task.id,
|
|
@@ -68,8 +94,8 @@ async function _executeTaskBranchConcurrently(task, idx, status, state, sliceExe
|
|
|
68
94
|
ownedFiles: task.owned_files || [],
|
|
69
95
|
filesModified: branchResult?.filesModified || [],
|
|
70
96
|
worktreePath: task.worktree_path || null,
|
|
71
|
-
status: 'completed',
|
|
72
|
-
validation: branchResult?.validation || [
|
|
97
|
+
status: childVerified ? 'completed' : 'spawn_pending',
|
|
98
|
+
validation: branchResult?.validation || []
|
|
73
99
|
});
|
|
74
100
|
return {
|
|
75
101
|
task,
|
|
@@ -82,6 +108,7 @@ async function _executeTaskBranchConcurrently(task, idx, status, state, sliceExe
|
|
|
82
108
|
completed_at: completedAt,
|
|
83
109
|
elapsed_ms: Math.max(1, completedAt - startedAt),
|
|
84
110
|
worktree_path: task.worktree_path || null,
|
|
111
|
+
child_execution_verified: childVerified,
|
|
85
112
|
advisor_status: advisorEval.status,
|
|
86
113
|
advisor_judge_tokens: (advisorEval.judge_usage && advisorEval.judge_usage.total_tokens) || 0
|
|
87
114
|
}
|
|
@@ -91,6 +118,10 @@ async function _executeTaskBranchConcurrently(task, idx, status, state, sliceExe
|
|
|
91
118
|
async function completePendingTasks(status, state, config) {
|
|
92
119
|
const tasks = status.tasks || [];
|
|
93
120
|
const pendingTasks = tasks.filter(t => t.status !== 'completed');
|
|
121
|
+
// The previous turn's directives are stale by definition: a slice that was
|
|
122
|
+
// reported complete is no longer waiting on a child, and leaving the old entry
|
|
123
|
+
// in place made the graph end on a spawn that had already happened.
|
|
124
|
+
status.spawn_pending = [];
|
|
94
125
|
if (pendingTasks.length === 0) return tasks;
|
|
95
126
|
|
|
96
127
|
const sliceResults = state.sliceResults;
|
|
@@ -105,7 +136,9 @@ async function completePendingTasks(status, state, config) {
|
|
|
105
136
|
return tasks;
|
|
106
137
|
}
|
|
107
138
|
|
|
108
|
-
|
|
139
|
+
// `state.sliceExecutor` covers a direct node call; the registry covers a graph run,
|
|
140
|
+
// because LangGraph rebuilds `configurable` and would drop a caller's function.
|
|
141
|
+
const sliceExecutor = state.sliceExecutor || getSliceExecutor(state.threadId || config?.configurable?.thread_id);
|
|
109
142
|
if ((state.requireExplicitDelegation || status.require_explicit_delegation) && !sliceExecutor) {
|
|
110
143
|
return tasks;
|
|
111
144
|
}
|
|
@@ -119,14 +152,43 @@ async function completePendingTasks(status, state, config) {
|
|
|
119
152
|
: [];
|
|
120
153
|
|
|
121
154
|
for (const outcome of branchOutcomes) {
|
|
122
|
-
outcome.
|
|
123
|
-
|
|
155
|
+
const verified = outcome.branchResult && outcome.branchResult.child_execution_verified === true;
|
|
156
|
+
if (verified) {
|
|
157
|
+
outcome.task.status = 'completed';
|
|
158
|
+
outcome.task.spawn_state = 'completed';
|
|
159
|
+
outcome.task.result = outcome.branchResult;
|
|
160
|
+
recordCompletedDispatch(status, outcome.task.dispatch_id);
|
|
161
|
+
} else {
|
|
162
|
+
// No child process produced this slice. Keep it visible as pending work and
|
|
163
|
+
// hand the directive back so the client can actually spawn it; the review
|
|
164
|
+
// node's delegation guard then routes to dispatch instead of Gate 2.
|
|
165
|
+
outcome.task.status = 'spawn_pending';
|
|
166
|
+
// `failed` when the attempt actually ran and lost; `directive_only` when
|
|
167
|
+
// nothing was ever started and the client still owes the spawn.
|
|
168
|
+
outcome.task.spawn_state = _branchFailed(outcome.branchResult) ? 'failed' : 'directive_only';
|
|
169
|
+
outcome.task.spawn_directive = (outcome.branchResult && outcome.branchResult.spawn_directive) || null;
|
|
170
|
+
// The result stays attached so a caller can read the directive it must run;
|
|
171
|
+
// `status` on the task is what marks the slice as unfinished.
|
|
172
|
+
outcome.task.result = outcome.branchResult;
|
|
173
|
+
status.spawn_pending = Array.isArray(status.spawn_pending) ? status.spawn_pending : [];
|
|
174
|
+
status.spawn_pending.push({
|
|
175
|
+
task_id: outcome.task.id,
|
|
176
|
+
agent: outcome.task.agent || null,
|
|
177
|
+
spawn_directive: outcome.task.spawn_directive,
|
|
178
|
+
spawn_error: (outcome.branchResult && outcome.branchResult.spawn_error) || null
|
|
179
|
+
});
|
|
180
|
+
}
|
|
124
181
|
outcome.task.started_at = outcome.telemetry.started_at;
|
|
125
|
-
outcome.task.completed_at = outcome.telemetry.completed_at;
|
|
126
|
-
recordCompletedDispatch(status, outcome.task.dispatch_id);
|
|
182
|
+
outcome.task.completed_at = verified ? outcome.telemetry.completed_at : null;
|
|
127
183
|
status.parallel_execution_telemetry.push(outcome.telemetry);
|
|
128
184
|
}
|
|
129
|
-
|
|
185
|
+
// The status phase is what a resumed call and the delegation guard read; a slice
|
|
186
|
+
// waiting on its client belongs to the execute stage, not to whatever phase the
|
|
187
|
+
// previous node left behind.
|
|
188
|
+
if (status.spawn_pending.length > 0) {
|
|
189
|
+
status.phase = 'execute';
|
|
190
|
+
}
|
|
191
|
+
if (branchOutcomes.length >= 2 && branchOutcomes.every(o => o.branchResult && o.branchResult.child_execution_verified === true)) {
|
|
130
192
|
status.parallel_execution_proof = {
|
|
131
193
|
concurrent_count: branchOutcomes.length,
|
|
132
194
|
branches: status.parallel_execution_telemetry.slice(-branchOutcomes.length),
|
|
@@ -233,6 +295,7 @@ async function executeNode(state, config) {
|
|
|
233
295
|
const breakerStatus = breaker.getStatus();
|
|
234
296
|
const circuitOpen = breakerStatus.state === 'OPEN';
|
|
235
297
|
|
|
298
|
+
const spawnPending = Array.isArray(status.spawn_pending) && status.spawn_pending.length > 0;
|
|
236
299
|
const outputPayload = {
|
|
237
300
|
status,
|
|
238
301
|
phase: status.phase || 'review',
|
|
@@ -243,10 +306,20 @@ async function executeNode(state, config) {
|
|
|
243
306
|
circuitOpen,
|
|
244
307
|
circuitState: breakerStatus.state,
|
|
245
308
|
error: executionError,
|
|
309
|
+
// A slice whose child was never started cannot be reviewed. Returning here
|
|
310
|
+
// hands the directive to the client, which spawns the child and reports back
|
|
311
|
+
// through `report_from_agent`; the next invoke resumes at this node with the
|
|
312
|
+
// tasks completed. Without this the graph bounced execute -> review ->
|
|
313
|
+
// dispatch until the remediation cap opened the circuit breaker.
|
|
314
|
+
spawnPending,
|
|
315
|
+
spawn_pending: spawnPending ? status.spawn_pending : undefined,
|
|
246
316
|
};
|
|
247
317
|
|
|
248
|
-
const nextNode =
|
|
318
|
+
const nextNode = spawnPending
|
|
319
|
+
? '__end__'
|
|
320
|
+
: (outputPayload.phase === 'document' ? 'node_dispatch' : 'node_review');
|
|
249
321
|
return finalizeNodeResult(state, outputPayload, nextNode, {
|
|
322
|
+
resumeNode: spawnPending ? 'node_execute' : undefined,
|
|
250
323
|
source: {
|
|
251
324
|
status,
|
|
252
325
|
phase: outputPayload.phase,
|
|
@@ -254,6 +327,7 @@ async function executeNode(state, config) {
|
|
|
254
327
|
circuitOpen,
|
|
255
328
|
circuitState: breakerStatus.state,
|
|
256
329
|
error: executionError,
|
|
330
|
+
spawnPending,
|
|
257
331
|
}
|
|
258
332
|
});
|
|
259
333
|
}
|
|
@@ -157,6 +157,14 @@ function _delegationGuard(state, status, taskDir) {
|
|
|
157
157
|
status.hitl_gate = null;
|
|
158
158
|
if (taskDir) saveWorkflowStatus(taskDir, status);
|
|
159
159
|
|
|
160
|
+
const pendingSpawns = pendingTasks
|
|
161
|
+
.filter((t) => t.status === 'spawn_pending' && t.spawn_directive)
|
|
162
|
+
.map((t) => ({
|
|
163
|
+
task_id: t.id,
|
|
164
|
+
agent: t.agent || null,
|
|
165
|
+
spawn_state: t.spawn_state || 'directive_only',
|
|
166
|
+
spawn_directive: t.spawn_directive
|
|
167
|
+
}));
|
|
160
168
|
const payload = {
|
|
161
169
|
status,
|
|
162
170
|
phase: 'execute',
|
|
@@ -164,11 +172,15 @@ function _delegationGuard(state, status, taskDir) {
|
|
|
164
172
|
hitlStage: null,
|
|
165
173
|
delegationPending: true,
|
|
166
174
|
pending_task_ids: pendingTasks.map((t) => t.id),
|
|
175
|
+
// A slice the MCP runner only prepared a directive for has to be spawned by
|
|
176
|
+
// the client. Without handing the directive back here the run bounced
|
|
177
|
+
// dispatch -> review with no way to see what was waiting on it.
|
|
178
|
+
spawn_pending: pendingSpawns.length > 0 ? pendingSpawns : undefined,
|
|
167
179
|
error: null,
|
|
168
180
|
};
|
|
169
181
|
return finalizeNodeResult(state, payload, 'node_dispatch', {
|
|
170
182
|
resumeNode: 'node_dispatch',
|
|
171
|
-
source: { delegationPending: true, pending: payload.pending_task_ids },
|
|
183
|
+
source: { delegationPending: true, pending: payload.pending_task_ids, spawnPending: pendingSpawns.length },
|
|
172
184
|
});
|
|
173
185
|
}
|
|
174
186
|
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// LangGraph rebuilds `config.configurable` for its own runtime keys, so a caller's
|
|
4
|
+
// executor cannot ride along there. A function also cannot live in the state
|
|
5
|
+
// schema: the checkpointer serialises state. This registry is the one channel that
|
|
6
|
+
// survives both, keyed by thread so concurrent runs stay isolated.
|
|
7
|
+
const executors = new Map();
|
|
8
|
+
|
|
9
|
+
function setSliceExecutor(threadId, fn) {
|
|
10
|
+
if (!threadId || typeof fn !== 'function') return;
|
|
11
|
+
executors.set(threadId, fn);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function getSliceExecutor(threadId) {
|
|
15
|
+
return threadId ? executors.get(threadId) || null : null;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function clearSliceExecutor(threadId) {
|
|
19
|
+
if (threadId) executors.delete(threadId);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
module.exports = { setSliceExecutor, getSliceExecutor, clearSliceExecutor };
|
|
@@ -100,6 +100,11 @@ const KonohaWorkflowState = Annotation.Root({
|
|
|
100
100
|
hitlRefinement: Annotation({ default: () => null }),
|
|
101
101
|
autoSignoff: Annotation({ default: () => false }),
|
|
102
102
|
|
|
103
|
+
// Declared as channels or LangGraph drops them: the execute node ends the turn
|
|
104
|
+
// here when a slice only has a spawn directive, and the router reads the flag.
|
|
105
|
+
spawnPending: Annotation({ default: () => false }),
|
|
106
|
+
spawn_pending: Annotation({ default: () => null }),
|
|
107
|
+
|
|
103
108
|
result: Annotation({ default: () => null }),
|
|
104
109
|
error: Annotation({ default: () => null }),
|
|
105
110
|
});
|
package/src/mcp/lazy_subagent.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
const { isReadOnlyAgent } = require('../agent_file_safety');
|
|
4
4
|
const { hasPiSubagentSupport } = require('../pi_manager');
|
|
5
|
+
const { normalizeAgentName } = require('../canonical_agents');
|
|
5
6
|
|
|
6
7
|
const SPAWNABLE_SUBAGENTS = Object.freeze([
|
|
7
8
|
'genin',
|
|
@@ -109,6 +110,9 @@ function buildUnsupportedSpawnPayload(client, reason) {
|
|
|
109
110
|
return {
|
|
110
111
|
ok: false,
|
|
111
112
|
supported: false,
|
|
113
|
+
// Nothing was started, so there is no child to report on. This is a
|
|
114
|
+
// capability gap, not a failed run.
|
|
115
|
+
spawn_state: 'directive_only',
|
|
112
116
|
error_code: 'UNSUPPORTED_NATIVE_SPAWN',
|
|
113
117
|
client: client || 'unknown',
|
|
114
118
|
error: reason,
|
|
@@ -192,8 +196,14 @@ function _cliTaskExcerpt(prompt) {
|
|
|
192
196
|
return _shellQuotePosix(truncateSpawnTask(raw).replace(/`/g, ''));
|
|
193
197
|
}
|
|
194
198
|
|
|
199
|
+
// Agent tokens must survive to the deployed profile name verbatim. The previous
|
|
200
|
+
// sanitizer stripped every non `[a-z0-9-]` character, so `tokubetsu_jonin` became
|
|
201
|
+
// `tokubetsujonin` while the profile on disk is `tokubetsu-jonin.md`; the native
|
|
202
|
+
// spawn then named an agent no client could resolve and the CLI fallback failed
|
|
203
|
+
// the same way. normalizeAgentName is the single canonical mapping (`_`/space ->
|
|
204
|
+
// `-`, `@` stripped, lowercase), so every directive and the profile agree.
|
|
195
205
|
function _safeAgentToken(raw) {
|
|
196
|
-
const cleaned = String(raw || 'subagent').replace(/^mcp_/, '')
|
|
206
|
+
const cleaned = normalizeAgentName(String(raw || 'subagent').replace(/^mcp_/, ''));
|
|
197
207
|
return cleaned || 'subagent';
|
|
198
208
|
}
|
|
199
209
|
|
|
@@ -316,7 +316,10 @@ function _reportFromAgent(delivery, rest, useModelJudge) {
|
|
|
316
316
|
// `cleanAgent`, not `opts.agentName`: the dispatch guard below compares against
|
|
317
317
|
// the normalized name, so `mcp_kage` and `Anbu` were rejected as mismatches.
|
|
318
318
|
const { error: wfError, workflowStatus } = _updateWorkflowStatus(safeTaskDir || opts.taskDir, opts.dispatchId, cleanAgent, finalStatus, {
|
|
319
|
-
summary: reportSummary, validation: opts.validation, verified, filesCreated: opts.filesCreated, filesModified: opts.filesModified
|
|
319
|
+
summary: reportSummary, validation: opts.validation, verified, filesCreated: opts.filesCreated, filesModified: opts.filesModified,
|
|
320
|
+
// A report may name the slice it belongs to; without it a parallel workflow
|
|
321
|
+
// attributes every child's result to whichever task happens to be open.
|
|
322
|
+
taskId: opts.taskId
|
|
320
323
|
});
|
|
321
324
|
if (wfError) return JSON.stringify({ status: 'error', message: wfError });
|
|
322
325
|
|
|
@@ -694,5 +694,6 @@ async function runMcpAgentAsync(agentName, task = null, context = null, constrai
|
|
|
694
694
|
module.exports = {
|
|
695
695
|
getMainModel, applyFileEdits, autoloadSkillsFromPrompt, buildSubagentMcpBlock,
|
|
696
696
|
buildResearchFetchRule, truncateAtBoundary, cleanRedundantPersonaText,
|
|
697
|
-
_loadBaseProjectContext, _prepareAgentRun, _finalizeAgentRun, runMcpAgent, runMcpAgentAsync
|
|
697
|
+
_loadBaseProjectContext, _prepareAgentRun, _finalizeAgentRun, runMcpAgent, runMcpAgentAsync,
|
|
698
|
+
PROMPT_CEILING_BYTES, SYSTEM_PROMPT_FLOOR_BYTES, MIN_SKILL_PREVIEW_BYTES
|
|
698
699
|
};
|
package/src/mcp/skills_common.js
CHANGED
|
@@ -363,6 +363,7 @@ function resolveFlowHashFromTask(flowHash, taskId) {
|
|
|
363
363
|
// stays authoritative: the database is an index of them, never a replacement.
|
|
364
364
|
const PROJECT_SKILL_SUBDIRS = [
|
|
365
365
|
['.agents', 'skills'],
|
|
366
|
+
['.agents', 'dev-skills'],
|
|
366
367
|
['.agent', 'skills'],
|
|
367
368
|
['skills'],
|
|
368
369
|
['.skills'],
|
|
@@ -332,6 +332,8 @@ function _prepareSpawnSpec(options) {
|
|
|
332
332
|
aborted: true,
|
|
333
333
|
agent: normalizedAgent,
|
|
334
334
|
client: capability.client,
|
|
335
|
+
// Cancelled before launch: no child ever existed.
|
|
336
|
+
spawn_state: 'directive_only',
|
|
335
337
|
error_code: 'SPAWN_ABORTED',
|
|
336
338
|
error: 'Subagent spawn cancelled before launch.'
|
|
337
339
|
}
|
|
@@ -454,6 +456,9 @@ function _buildFailureExitResult({
|
|
|
454
456
|
return {
|
|
455
457
|
ok: false,
|
|
456
458
|
status: kind.status,
|
|
459
|
+
// Fixed vocabulary: directive_only | completed | failed. A timeout or abort
|
|
460
|
+
// is a failure, not a state of its own.
|
|
461
|
+
spawn_state: 'failed',
|
|
457
462
|
...(kind.flagKey ? { [kind.flagKey]: true } : {}),
|
|
458
463
|
agent: normalizedAgent,
|
|
459
464
|
client,
|
|
@@ -566,6 +571,7 @@ function _executeSpawnSpec(spec, options, childEnv, startedAt) {
|
|
|
566
571
|
client: capability.client,
|
|
567
572
|
child_pid: childPid || null,
|
|
568
573
|
elapsed_ms: Date.now() - startedAt,
|
|
574
|
+
spawn_state: 'failed',
|
|
569
575
|
error_code: err.code === 'ENOENT' ? 'HARNESS_BINARY_NOT_FOUND' : 'SPAWN_PROCESS_ERROR',
|
|
570
576
|
error: err.message
|
|
571
577
|
});
|
|
@@ -609,6 +615,7 @@ function _executeSpawnSpec(spec, options, childEnv, startedAt) {
|
|
|
609
615
|
...parsed,
|
|
610
616
|
ok: true,
|
|
611
617
|
status: parsed.status || 'completed',
|
|
618
|
+
spawn_state: 'completed',
|
|
612
619
|
agent: normalizedAgent,
|
|
613
620
|
client: capability.client,
|
|
614
621
|
child_pid: parsed.child_pid || childPid,
|
|
@@ -47,6 +47,10 @@ function normalizeTodoItems(tasks = [], status = {}) {
|
|
|
47
47
|
if (rawStatus === 'completed' || rawStatus === 'done') mappedStatus = 'completed';
|
|
48
48
|
else if (rawStatus === 'in_progress' || rawStatus === 'running') mappedStatus = 'in_progress';
|
|
49
49
|
else if (['unverified', 'failed', 'rejected', 'blocked'].includes(rawStatus)) mappedStatus = rawStatus;
|
|
50
|
+
// `spawn_pending` is a real state, not a typo: the slice has a directive the
|
|
51
|
+
// client must run and is only completed by `report_from_agent`. Mapping it to
|
|
52
|
+
// `pending` here erased the marker on every sync and hid the waiting spawn.
|
|
53
|
+
else if (rawStatus === 'spawn_pending') mappedStatus = 'spawn_pending';
|
|
50
54
|
const text = base.task || base.content || base.description || `Step ${idx + 1}`;
|
|
51
55
|
return {
|
|
52
56
|
...base,
|
|
@@ -196,6 +200,9 @@ function applyAgentReportToTodos(workflowStatus, cleanAgent, dispatchId, finalSt
|
|
|
196
200
|
|
|
197
201
|
if (finalStatus === 'completed' || finalStatus === 'unverified') {
|
|
198
202
|
task.status = finalStatus;
|
|
203
|
+
// A report without passing validation evidence cannot have produced a
|
|
204
|
+
// finished child: `completed` requires the evidence gate to have passed.
|
|
205
|
+
task.spawn_state = finalStatus === 'completed' ? 'completed' : 'directive_only';
|
|
199
206
|
task.result = updateData.summary || '';
|
|
200
207
|
task.validation = updateData.validation || [];
|
|
201
208
|
task.verified = updateData.verified;
|
package/src/mcp/tool_dispatch.js
CHANGED
|
@@ -326,6 +326,22 @@ function _mergeSanninGraphResponse(parsedSannin, graphInitRes, threadId) {
|
|
|
326
326
|
};
|
|
327
327
|
}
|
|
328
328
|
|
|
329
|
+
// A slice that only has a spawn directive is not routed work: the client has to
|
|
330
|
+
// run the directive and report back. Answering it with the routing envelope made
|
|
331
|
+
// the caller believe a subagent had been dispatched.
|
|
332
|
+
if (graphInitRes.spawnPending) {
|
|
333
|
+
return {
|
|
334
|
+
...parsedSannin,
|
|
335
|
+
status: 'spawn_pending',
|
|
336
|
+
phase: graphInitRes.phase,
|
|
337
|
+
spawn_pending: graphInitRes.spawn_pending || (wfStatus && wfStatus.spawn_pending) || [],
|
|
338
|
+
next_action: 'spawn_and_report',
|
|
339
|
+
resume_node: 'node_execute',
|
|
340
|
+
langgraph_checkpoint: checkpoint,
|
|
341
|
+
workflow_state: typeof graphInitRes.status === 'object' ? graphInitRes.status : undefined
|
|
342
|
+
};
|
|
343
|
+
}
|
|
344
|
+
|
|
329
345
|
if (parsedSannin.status === 'routed') {
|
|
330
346
|
return {
|
|
331
347
|
...graphInitRes,
|
|
@@ -569,7 +585,8 @@ async function _executeHeavyToolAsync(toolName, args, agent) {
|
|
|
569
585
|
const query = args.query;
|
|
570
586
|
const numResults = Math.min(Math.max(parseInt(args.num_results || 5, 10), 1), 50);
|
|
571
587
|
const searchDepth = ['standard', 'deep'].includes(args.search_depth) ? args.search_depth : 'standard';
|
|
572
|
-
|
|
588
|
+
const excludeUrls = Array.isArray(args.exclude_urls) ? args.exclude_urls : undefined;
|
|
589
|
+
return await runWebSearch(query, numResults, searchDepth, agent, { excludeUrls });
|
|
573
590
|
}
|
|
574
591
|
const docEngineMethod = {
|
|
575
592
|
document_create: 'documentCreate',
|
package/src/mcp/web_search.js
CHANGED
|
@@ -12,6 +12,7 @@ const { detectActiveAgent } = require('./client_detection');
|
|
|
12
12
|
const { logToolCall } = require('./skills');
|
|
13
13
|
const { globalCircuitRegistry } = require('../circuit_breaker');
|
|
14
14
|
const { getConfigValue } = require('../config_access');
|
|
15
|
+
const { canonicalizeUrl } = require('../url_canonical');
|
|
15
16
|
|
|
16
17
|
const searxngDir = path.join(KONOHA_DIR, 'searxng');
|
|
17
18
|
const instancesCachePath = path.join(searxngDir, 'instances_cache.json');
|
|
@@ -437,13 +438,29 @@ async function _queryBlendedSearch(q, numResults, isBlended, requestedEngine) {
|
|
|
437
438
|
|
|
438
439
|
function _appendUniqueResults(currentResults, seenUrls, allResults) {
|
|
439
440
|
for (const r of currentResults) {
|
|
440
|
-
|
|
441
|
-
|
|
441
|
+
const key = canonicalizeUrl(r.url) || r.url;
|
|
442
|
+
if (!seenUrls.has(key)) {
|
|
443
|
+
seenUrls.add(key);
|
|
442
444
|
allResults.push(r);
|
|
443
445
|
}
|
|
444
446
|
}
|
|
445
447
|
}
|
|
446
448
|
|
|
449
|
+
/**
|
|
450
|
+
* Normalizes the caller's `exclude_urls` into canonical keys. Accepts raw URLs,
|
|
451
|
+
* bare hosts, and URLs already in canonical form; anything unparseable is
|
|
452
|
+
* dropped rather than throwing, because a bad exclusion must not fail a search.
|
|
453
|
+
*/
|
|
454
|
+
function _normalizeExclusions(excludeUrls) {
|
|
455
|
+
const set = new Set();
|
|
456
|
+
if (!Array.isArray(excludeUrls)) return set;
|
|
457
|
+
for (const entry of excludeUrls) {
|
|
458
|
+
const canonical = canonicalizeUrl(entry);
|
|
459
|
+
if (canonical) set.add(canonical);
|
|
460
|
+
}
|
|
461
|
+
return set;
|
|
462
|
+
}
|
|
463
|
+
|
|
447
464
|
async function runWebSearch(query, numResults = 5, searchDepth = 'standard', agentName = null, options = {}) {
|
|
448
465
|
if (!query || !query.trim()) {
|
|
449
466
|
return JSON.stringify({ status: 'error', message: 'Query is required.' });
|
|
@@ -460,6 +477,7 @@ async function runWebSearch(query, numResults = 5, searchDepth = 'standard', age
|
|
|
460
477
|
|
|
461
478
|
const allResults = [];
|
|
462
479
|
const seenUrls = new Set();
|
|
480
|
+
const excluded = _normalizeExclusions(options && options.excludeUrls);
|
|
463
481
|
const requestedEngine = (options && options.engine) ? String(options.engine).toLowerCase() : 'all';
|
|
464
482
|
const isBlended = options && options.blended !== undefined ? options.blended : (requestedEngine === 'all');
|
|
465
483
|
|
|
@@ -469,11 +487,16 @@ async function runWebSearch(query, numResults = 5, searchDepth = 'standard', age
|
|
|
469
487
|
? specific
|
|
470
488
|
: await _queryBlendedSearch(q, numResults, isBlended, requestedEngine);
|
|
471
489
|
|
|
490
|
+
// Fetch a wider candidate set when exclusions are in play, so filtering out
|
|
491
|
+
// already-known URLs still leaves `numResults` net-new results.
|
|
472
492
|
_appendUniqueResults(currentResults, seenUrls, allResults);
|
|
473
493
|
}
|
|
474
494
|
|
|
475
495
|
allResults.sort((a, b) => rankScore(b) - rankScore(a));
|
|
476
|
-
const
|
|
496
|
+
const fresh = excluded.size
|
|
497
|
+
? allResults.filter((r) => !excluded.has(canonicalizeUrl(r.url) || r.url))
|
|
498
|
+
: allResults;
|
|
499
|
+
const formatted = fresh.slice(0, numResults).map((r, i) => ({
|
|
477
500
|
citation_id: i + 1,
|
|
478
501
|
title: r.title,
|
|
479
502
|
url: r.url,
|
|
@@ -485,6 +508,7 @@ async function runWebSearch(query, numResults = 5, searchDepth = 'standard', age
|
|
|
485
508
|
status: 'success',
|
|
486
509
|
query,
|
|
487
510
|
search_depth: searchDepth,
|
|
511
|
+
excluded_count: excluded.size,
|
|
488
512
|
results_count: formatted.length,
|
|
489
513
|
results: formatted
|
|
490
514
|
});
|
|
@@ -150,7 +150,12 @@ function extractModifiedFiles(tasks) {
|
|
|
150
150
|
function formatTaskSummary(tasks) {
|
|
151
151
|
const list = (tasks || []).slice(0, 5);
|
|
152
152
|
return list.map(t => {
|
|
153
|
-
|
|
153
|
+
// Executor slices report `summary`; agent reports use `result`. Either may
|
|
154
|
+
// arrive as a non-string (object payload), which used to throw here and
|
|
155
|
+
// took the whole review node down.
|
|
156
|
+
const raw = typeof t.result === 'string' ? t.result
|
|
157
|
+
: (typeof t.summary === 'string' ? t.summary : 'Completed');
|
|
158
|
+
const res = raw.replace(/\n+/g, ' ').trim();
|
|
154
159
|
const short = res.length > 60 ? res.slice(0, 57) + '...' : res;
|
|
155
160
|
return `• [${t.agent || 'agent'}] ${t.task}: ${short}`;
|
|
156
161
|
}).join('\n');
|