mirror of
https://github.com/binaricat/Netcatty.git
synced 2026-11-26 02:31:40 +00:00
* feat(capabilities): add terminal_execute_bulk to run one command on many sessions
Add a terminal_execute_bulk MCP tool that runs the same short command on
2-20 open terminal sessions and groups identical results.
- All-or-nothing preflight: scope, closing, busy, connected, transport
and the per-shell command safety policy are checked for every target
before anything is sent. Any bad target cancels the whole call and all
bad targets are reported at once.
- One approval listing every host. Remembered grants and external-client
session approval never satisfy it (policy.requiresFreshApproval), and a
pending fan-out is not swept up by another request's session approval.
- Targets are claimed before the prompt and re-checked after it; all
targets then start in the same synchronous turn under a single per-chat
exec lock, each with its own wall-clock timeout.
- Results are grouped only when status, exit code, stdout, stderr and
error are identical on the full output, then truncated (tailLines and
size caps). JSON output matches the other tools.
- Loaded on demand through the terminal_bulk toolset.
* fix(capabilities): harden terminal_execute_bulk after review
- Only trust the metadata "connected" flag for worker-hosted sessions; a
live main-process session with a stale snapshot is no longer refused.
- Keep targets protected from idle auto-close from the claim through the
approval wait to completion, and release on every path.
- Classify blocklist refusals before status keywords so a pattern such as
"cancel-job" is reported as not_sent, not cancelled.
- List the terminal_bulk toolset in the MCP server instructions and the
netcatty-mcp skill so clients can discover it.
- Test that the bulk RPC gets the same timeout budget as terminal_execute.
* fix(capabilities): validate worker sessions up front and cancel them at the deadline
An independent review found that the default (terminal worker) sessions
could receive a partial send, and that the backstop deadline never
reached the worker.
- Add a no-send precheck mode to the worker exec handler. The bulk
preflight now runs every deterministic check for worker sessions
(transport, shell kind, shell-specific safety patterns, unsupported
local shell, busy job) so a refusal cancels the whole call before any
host receives the command.
- Add netcatty:ai:exec:cancel and call it at the deadline, so a stuck
worker command is cancelled before the per-chat lock is released
instead of overlapping the next command. Background jobs are left
alone.
- Make the deadline grace 3s and give the bulk RPC extra timeout budget
for its preflight, so the backstop fires before the client gives up.
- Do not group hosts whose exec layer already dropped different amounts
of output, and share one size budget between stdout and stderr.
- Restrict the capability to the sidebar agent; the global agent runs
delegated, which bulk refuses.
- Document that live terminal readiness is a send-time state.
* test(capabilities): cover terminal_execute_bulk over the real MCP wire and close mutation gaps
- Drive the tool through the real stdio MCP server: hidden until the
terminal_bulk toolset is loaded, schema shape, JSON result, Error text
with isError, schema rejection of a native array, and privacy masking
of the grouped result with token restoration in the command.
- Mutation testing (18 deliberate breakages of the safety-critical
lines) left three survivors; add tests that kill two of them: hosts
differing only in exit code, status, stderr or error never share a
group, and a session-scoped answer to a fan-out approval does not
approve later writes from that client.
- Assert that delegated agents cannot reach the fan-out at the gate.
* fix(capabilities): address review findings on terminal_execute_bulk
- Keep the tool MCP-only for now. The in-app agent has no completed-write
replay for it after a context-compaction retry, and its SDK approval
gate would stack a second prompt on the bridge's fresh approval. Both
can follow in a separate change.
- Re-run the transport preflight for every claimed target after the
approval and before the synchronous start, so a worker session that
changed while the user was deciding cancels the whole call instead of
being refused after other hosts have started.
- Never group hosts whose exec layer already dropped part of the output:
equal retained tails do not prove equal full results.
* fix(capabilities): only report not_sent on explicit evidence and flag capped output
- Classify a host as not_sent only when the exec layer says so (a known
pre-send code or refusal text). An error with no output and no exit
code, such as a terminal worker exiting after it typed the command,
is now reported as error, so a mutating command is never presented as
safe to retry blindly. SHELL_NOT_READY and EXECUTION_NOT_AUTHORIZED
are now recognised, so a call where every host refuses fails as
not sent instead of returning ok.
- Have execViaRawPty and execViaChannel set outputTruncated when they
stop collecting at their size cap, so hosts that differ only in the
discarded output are never grouped.
* test(capabilities): run terminal_execute_bulk against the real worker exec handler
Wire the bridge to the production terminal-worker exec handler with fake
shells that speak the wrapper protocol, and cover the grouped result,
Stop while every host is running, and real per-host timeouts.
* fix(capabilities): do not probe hosts before the bulk approval
In confirm mode the preflight ran the shell-kind probe, which opens an
SSH exec channel and runs a remote command, before the approval prompt.
Denying the call (or another target failing) still executed something on
the host, and on an account with a forced command that could trigger it.
- The preflight before the prompt is now read-only: no channel is opened,
and the safety check uses the shell kind only if it is already known,
otherwise the shell-independent patterns.
- The full check, including the probe and the shell-aware patterns, runs
right after approval and before any command is sent, so the call is
still all-or-nothing. Without a prompt the full check runs first.
- The worker precheck honours the same distinction.
* fix(capabilities): recheck local guards before probing hosts after approval
After the approval the bulk call ran the probing transport pass first and
rechecked cancellation, scope and the privacy policy afterwards. A call
that was no longer authorized (Stop pressed, session out of scope,
privacy settings changed while the prompt was open) was rejected only
after the hosts had already been probed.
Run the local, read-only guards first, then the probing pass, then the
guards again because the pass awaits, and only then take the chat lock
and start. A refusal by the privacy hook now happens before the lock is
taken.
* fix(capabilities): re-read the permission mode and classify exec refusals precisely
- Re-evaluate the live permission mode with the other local guards, both
before the probing pass and again before the start. Switching to
observer while a prompt is open (or while hosts are being checked) now
refuses the call, and a call that needed no approval is refused if the
mode turns into confirm before it starts.
- Keep the code of an error the exec layer throws, so SHELL_PROMPT_PENDING
(thrown before anything is written) is reported as not_sent and an
all-refused call fails as not sent.
- Recognise the executors' real closed-stream messages ("Stream closed
unexpectedly", "Serial port closed unexpectedly") as connection_lost.
504 lines
21 KiB
JavaScript
504 lines
21 KiB
JavaScript
"use strict";
|
|
|
|
const test = require("node:test");
|
|
const assert = require("node:assert/strict");
|
|
const { CAPABILITY_STATUS } = require("../constants.cjs");
|
|
const { ALL_CAPABILITIES } = require("../catalog/index.cjs");
|
|
const { TOOL_INPUT_FIELDS } = require("../schemas/toolInputs.cjs");
|
|
const {
|
|
listMcpTools,
|
|
listCattyToolSpecs,
|
|
CATTY_CAPABILITY_DENYLIST,
|
|
isCattyEligible,
|
|
} = require("./toolSurfaces.cjs");
|
|
const { registerMcpTools, buildZodShapeObject, isEmptyMcpInputShape } = require("./mcpToolRegistry.cjs");
|
|
|
|
function mcpToolHandler(schemaOrHandler, maybeHandler) {
|
|
return typeof schemaOrHandler === "function" ? schemaOrHandler : maybeHandler;
|
|
}
|
|
|
|
test("listCattyToolSpecs includes terminal long-running tools", () => {
|
|
const specs = listCattyToolSpecs();
|
|
const names = specs.map((spec) => spec.toolName);
|
|
assert.ok(names.includes("terminal_execute"));
|
|
assert.ok(names.includes("terminal_start"));
|
|
assert.ok(names.includes("terminal_poll"));
|
|
assert.ok(names.includes("terminal_stop"));
|
|
});
|
|
|
|
test("listCattyToolSpecs includes SFTP write tools and attachments", () => {
|
|
const capabilityIds = listCattyToolSpecs().map((spec) => spec.capabilityId);
|
|
assert.ok(capabilityIds.includes("attachment.list"));
|
|
assert.ok(capabilityIds.includes("attachment.read"));
|
|
assert.ok(capabilityIds.includes("sftp.write"));
|
|
assert.ok(capabilityIds.includes("sftp.mkdir"));
|
|
assert.ok(capabilityIds.includes("sftp.delete"));
|
|
assert.ok(capabilityIds.includes("sftp.rename"));
|
|
assert.ok(capabilityIds.includes("sftp.chmod"));
|
|
assert.ok(!capabilityIds.includes("meta.status"));
|
|
assert.ok(!capabilityIds.includes("session.cancel"));
|
|
});
|
|
|
|
test("listCattyToolSpecs includes vault host tools and SFTP transfer", () => {
|
|
const capabilityIds = listCattyToolSpecs().map((spec) => spec.capabilityId);
|
|
assert.ok(capabilityIds.includes("vault.host.get"));
|
|
assert.ok(capabilityIds.includes("vault.host.list"));
|
|
// Sidebar Catty must not open hosts; that expands scope mid-turn.
|
|
assert.ok(!capabilityIds.includes("vault.host.open"));
|
|
assert.ok(capabilityIds.includes("vault.hosts.create"));
|
|
assert.ok(capabilityIds.includes("vault.host.update"));
|
|
assert.ok(capabilityIds.includes("vault.host.delete"));
|
|
assert.ok(capabilityIds.includes("vault.host.import"));
|
|
assert.ok(capabilityIds.includes("vault.note.create"));
|
|
assert.ok(capabilityIds.includes("vault.note.list"));
|
|
assert.ok(capabilityIds.includes("sftp.download"));
|
|
assert.ok(capabilityIds.includes("sftp.upload"));
|
|
});
|
|
|
|
test("host_open stays on MCP and global agent, not sidebar Catty", () => {
|
|
const { AGENT_KINDS, listAgentToolSpecs } = require("./toolSurfaces.cjs");
|
|
const sidebarIds = listAgentToolSpecs(AGENT_KINDS.SIDEBAR).map((spec) => spec.capabilityId);
|
|
const globalIds = listAgentToolSpecs(AGENT_KINDS.GLOBAL).map((spec) => spec.capabilityId);
|
|
const mcpHostOpen = listMcpTools().find((tool) => tool.mcpTool === "host_open");
|
|
|
|
assert.ok(!sidebarIds.includes("vault.host.open"));
|
|
assert.ok(globalIds.includes("vault.host.open"));
|
|
assert.ok(mcpHostOpen);
|
|
assert.equal(mcpHostOpen.capabilityId, "vault.host.open");
|
|
});
|
|
|
|
test("listMcpTools includes vault host update and delete for external MCP clients", () => {
|
|
const tools = listMcpTools();
|
|
const create = tools.find((tool) => tool.mcpTool === "vault_hosts_create");
|
|
const update = tools.find((tool) => tool.mcpTool === "vault_hosts_update");
|
|
const remove = tools.find((tool) => tool.mcpTool === "vault_hosts_delete");
|
|
assert.match(create?.inputShape.hosts?.description ?? "", /passphrase/i);
|
|
assert.equal(update?.capabilityId, "vault.host.update");
|
|
assert.equal(update?.publicRpcMethod, "public/vault/hosts/update");
|
|
assert.ok(update?.inputShape.keyPath);
|
|
assert.ok(update?.inputShape.keypath);
|
|
assert.ok(update?.inputShape.savePassword);
|
|
assert.ok(update?.inputShape.passphrase);
|
|
assert.equal(remove?.capabilityId, "vault.host.delete");
|
|
assert.equal(remove?.publicRpcMethod, "public/vault/hosts/delete");
|
|
});
|
|
|
|
test("listMcpTools includes host_open for external MCP clients", () => {
|
|
const tools = listMcpTools();
|
|
const hostOpen = tools.find((tool) => tool.mcpTool === "host_open");
|
|
assert.ok(hostOpen);
|
|
assert.equal(hostOpen.capabilityId, "vault.host.open");
|
|
assert.equal(hostOpen.publicRpcMethod, "public/vault/hosts/open");
|
|
});
|
|
|
|
test("core MCP descriptions strongly route live terminal work through Netcatty", () => {
|
|
const tools = listMcpTools();
|
|
const environment = tools.find((tool) => tool.mcpTool === "get_environment");
|
|
const execute = tools.find((tool) => tool.mcpTool === "terminal_execute");
|
|
const start = tools.find((tool) => tool.mcpTool === "terminal_start");
|
|
const vaultHosts = tools.find((tool) => tool.mcpTool === "vault_hosts_list");
|
|
|
|
assert.match(environment?.description || "", /Call this first/i);
|
|
assert.match(environment?.description || "", /label or hostname/i);
|
|
assert.match(execute?.description || "", /instead of the local shell/i);
|
|
assert.match(execute?.description || "", /get_environment first/i);
|
|
assert.match(start?.description || "", /instead of the local shell/i);
|
|
assert.match(vaultHosts?.description || "", /host_open/i);
|
|
});
|
|
|
|
test("vault_hosts_list exposes optional query and group filters", () => {
|
|
const vaultHosts = listMcpTools().find((tool) => tool.mcpTool === "vault_hosts_list");
|
|
assert.ok(vaultHosts);
|
|
assert.deepEqual(Object.keys(vaultHosts.inputShape).sort(), ["group", "query"]);
|
|
assert.equal(vaultHosts.inputShape.query.optional, true);
|
|
assert.equal(vaultHosts.inputShape.group.optional, true);
|
|
});
|
|
|
|
test("session_close is exposed to agents and external MCP clients", () => {
|
|
const mcpTool = listMcpTools().find((tool) => tool.mcpTool === "session_close");
|
|
assert.ok(mcpTool);
|
|
assert.equal(mcpTool.capabilityId, "session.close");
|
|
assert.equal(mcpTool.publicRpcMethod, "public/session/close");
|
|
|
|
const cattyTool = listCattyToolSpecs().find((tool) => tool.toolName === "session_close");
|
|
assert.ok(cattyTool);
|
|
assert.equal(cattyTool.rpcMethod, "session/close");
|
|
});
|
|
|
|
test('session reconnect is exposed to both agents without cleanup permission bypasses', () => {
|
|
const spec = listCattyToolSpecs().find(tool => tool.toolName === 'session_reconnect');
|
|
assert.equal(spec?.rpcMethod, 'session/reconnect');
|
|
const mcp = listMcpTools().find(tool => tool.mcpTool === 'session_reconnect');
|
|
assert.equal(mcp?.publicRpcMethod, 'public/session/reconnect');
|
|
assert.equal(mcp?.policy.bypassesApproval, false);
|
|
assert.equal(mcp?.policy.bypassesObserverBlock, false);
|
|
assert.equal(mcp?.policy.bypassesChatCancel, false);
|
|
const recover = listCattyToolSpecs().find(tool => tool.toolName === 'session_recover');
|
|
assert.equal(recover?.rpcMethod, 'session/recover');
|
|
const recoverMcp = listMcpTools().find(tool => tool.mcpTool === 'session_recover');
|
|
assert.equal(recoverMcp?.policy.bypassesApproval, false);
|
|
});
|
|
|
|
test("host_open tells agents to close sessions after use", () => {
|
|
const hostOpen = listMcpTools().find((tool) => tool.mcpTool === "host_open");
|
|
assert.match(hostOpen?.description || "", /session_close/i);
|
|
});
|
|
|
|
test("vault host import tool description routes unknown attached host text to host creation", () => {
|
|
const importSpec = listCattyToolSpecs().find((spec) => spec.capabilityId === "vault.host.import");
|
|
assert.ok(importSpec);
|
|
assert.match(importSpec.description, /known export formats/i);
|
|
assert.match(importSpec.description, /FinalShell/);
|
|
assert.match(importSpec.description, /unknown/i);
|
|
assert.match(importSpec.description, /read_attachment/i);
|
|
assert.match(importSpec.description, /vault_hosts_create/i);
|
|
});
|
|
|
|
test("listCattyToolSpecs binds vault note tools to global RPC methods", () => {
|
|
const specs = listCattyToolSpecs();
|
|
const noteCreate = specs.find((spec) => spec.capabilityId === "vault.note.create");
|
|
assert.equal(noteCreate?.rpcMethod, "vault/notes/create");
|
|
const noteList = specs.find((spec) => spec.capabilityId === "vault.note.list");
|
|
assert.equal(noteList?.rpcMethod, "vault/notes/list");
|
|
});
|
|
|
|
test("listCattyToolSpecs binds vault and portforward tools to global RPC methods", () => {
|
|
const specs = listCattyToolSpecs();
|
|
const hostNotesSet = specs.find((spec) => spec.capabilityId === "vault.host.notes.set");
|
|
assert.equal(hostNotesSet?.rpcMethod, "vault/host/notes/set");
|
|
const portforwardStart = specs.find((spec) => spec.capabilityId === "portforward.start");
|
|
assert.equal(portforwardStart?.rpcMethod, "portforward/start");
|
|
});
|
|
|
|
test("generic snippet agent tools expose dynamic group targets", () => {
|
|
const { AGENT_KINDS, listAgentToolSpecs } = require("./toolSurfaces.cjs");
|
|
for (const kind of [AGENT_KINDS.SIDEBAR, AGENT_KINDS.GLOBAL]) {
|
|
const specs = listAgentToolSpecs(kind);
|
|
for (const capabilityId of ["vault.snippets.create", "vault.snippets.update"]) {
|
|
const spec = specs.find((entry) => entry.capabilityId === capabilityId);
|
|
assert.ok(spec, `${capabilityId} should be exposed to ${kind}`);
|
|
assert.match(spec.inputShape.targetGroups?.description ?? "", /group paths/i);
|
|
}
|
|
}
|
|
});
|
|
|
|
test("listAgentToolSpecs splits sidebar harness tools from shared RPC tools", () => {
|
|
const { AGENT_KINDS, listAgentToolSpecs } = require("./toolSurfaces.cjs");
|
|
const sidebarIds = listAgentToolSpecs(AGENT_KINDS.SIDEBAR).map((spec) => spec.capabilityId);
|
|
const globalIds = listAgentToolSpecs(AGENT_KINDS.GLOBAL).map((spec) => spec.capabilityId);
|
|
|
|
assert.ok(sidebarIds.includes("harness.workspace.get_info"));
|
|
assert.ok(!globalIds.includes("harness.workspace.get_info"));
|
|
|
|
assert.ok(sidebarIds.includes("terminal.execute"));
|
|
assert.ok(globalIds.includes("terminal.execute"));
|
|
assert.ok(globalIds.includes("vault.note.create"));
|
|
|
|
assert.ok(globalIds.every((id) => sidebarIds.includes(id) || id.startsWith("harness.") === false));
|
|
});
|
|
|
|
test("listCattyToolSpecs includes renderer harness tools and the shared terminal read entry", () => {
|
|
const specs = listCattyToolSpecs();
|
|
assert.ok(specs.length >= 40);
|
|
const harness = specs.filter((spec) => spec.capabilityId.startsWith("harness."));
|
|
assert.equal(harness.length, 6);
|
|
for (const spec of harness) {
|
|
const screenRead = spec.capabilityId === "harness.terminal.read_context";
|
|
assert.equal(spec.localExecution, !screenRead);
|
|
assert.equal(spec.rpcMethod, screenRead ? "netcatty/readContext" : null);
|
|
}
|
|
const harnessIds = harness.map((spec) => spec.capabilityId);
|
|
assert.ok(harnessIds.includes("harness.tool_output.read"));
|
|
assert.ok(harnessIds.includes("harness.workspace.get_info"));
|
|
assert.ok(harnessIds.includes("harness.terminal.read_context"));
|
|
});
|
|
|
|
test("only terminal reading is exposed from harness on MCP", () => {
|
|
const mcpCapabilityIds = listMcpTools().map((tool) => tool.capabilityId);
|
|
assert.ok(mcpCapabilityIds.includes("harness.terminal.read_context"));
|
|
for (const capabilityId of mcpCapabilityIds) {
|
|
assert.ok(!capabilityId.startsWith("harness.") || capabilityId === "harness.terminal.read_context");
|
|
}
|
|
});
|
|
|
|
test("listMcpTools descriptions stay aligned with catalog capability ids", () => {
|
|
const mcpTools = listMcpTools();
|
|
assert.ok(mcpTools.length >= 35);
|
|
for (const tool of mcpTools) {
|
|
assert.ok(tool.capabilityId);
|
|
assert.ok(tool.mcpTool);
|
|
assert.ok(tool.description.length > 0);
|
|
assert.ok(tool.rpcMethod);
|
|
}
|
|
});
|
|
|
|
test("catty and mcp terminal tools share capability ids", () => {
|
|
const catty = listCattyToolSpecs().find((spec) => spec.toolName === "terminal_execute");
|
|
const mcp = listMcpTools().find((tool) => tool.mcpTool === "terminal_execute");
|
|
assert.equal(catty?.capabilityId, "terminal.execute");
|
|
assert.equal(mcp?.capabilityId, "terminal.execute");
|
|
});
|
|
|
|
test("implemented catalog tools with inputs are catty-eligible unless denylisted or agentKinds-restricted", () => {
|
|
const implemented = ALL_CAPABILITIES.filter((cap) => cap.status === CAPABILITY_STATUS.IMPLEMENTED);
|
|
for (const capability of implemented) {
|
|
const hasInputs = Object.prototype.hasOwnProperty.call(TOOL_INPUT_FIELDS, capability.id);
|
|
if (!hasInputs) continue;
|
|
if (CATTY_CAPABILITY_DENYLIST.has(capability.id)) {
|
|
assert.equal(isCattyEligible(capability), false);
|
|
continue;
|
|
}
|
|
if (Array.isArray(capability.agentKinds) && capability.agentKinds.length > 0
|
|
&& !capability.agentKinds.includes("sidebar")) {
|
|
assert.equal(isCattyEligible(capability), false);
|
|
continue;
|
|
}
|
|
const hasRpc = Boolean(
|
|
capability.surfaces?.builtin?.rpcMethod
|
|
|| capability.surfaces?.public?.mcpTool,
|
|
);
|
|
if (hasRpc) {
|
|
assert.equal(isCattyEligible(capability), true);
|
|
}
|
|
}
|
|
});
|
|
|
|
test("mcp registry builds zod shapes for every MCP tool", () => {
|
|
for (const tool of listMcpTools()) {
|
|
const shape = buildZodShapeObject(tool.inputShape);
|
|
assert.equal(typeof shape, "object");
|
|
}
|
|
});
|
|
|
|
test("registerMcpTools registers one handler per catalog MCP tool", () => {
|
|
const registered = [];
|
|
const fakeServer = {
|
|
tool(name, _description, schemaOrHandler, maybeHandler) {
|
|
registered.push({ name, handler: typeof mcpToolHandler(schemaOrHandler, maybeHandler) });
|
|
},
|
|
};
|
|
const count = registerMcpTools(fakeServer, {
|
|
rpcCall: async () => ({ ok: true }),
|
|
scopeParams: {},
|
|
guardWriteOperation: () => null,
|
|
catalogDescription: (_name, fallback) => fallback,
|
|
});
|
|
assert.equal(count, listMcpTools().length);
|
|
assert.equal(registered.length, listMcpTools().length);
|
|
});
|
|
|
|
test("no-arg MCP tools register without a params schema so omitted arguments are valid (#3049)", () => {
|
|
const registrations = [];
|
|
const fakeServer = {
|
|
tool(name, _description, schemaOrHandler, maybeHandler) {
|
|
registrations.push({
|
|
name,
|
|
hasSchema: typeof schemaOrHandler !== "function",
|
|
handler: mcpToolHandler(schemaOrHandler, maybeHandler),
|
|
});
|
|
},
|
|
};
|
|
registerMcpTools(fakeServer, {
|
|
rpcCall: async () => ({ ok: true }),
|
|
scopeParams: {},
|
|
guardWriteOperation: () => null,
|
|
catalogDescription: (_name, fallback) => fallback,
|
|
});
|
|
|
|
const noArgNames = listMcpTools()
|
|
.filter((tool) => isEmptyMcpInputShape(tool.inputShape))
|
|
.map((tool) => tool.mcpTool);
|
|
assert.ok(noArgNames.includes("get_environment"));
|
|
assert.ok(noArgNames.includes("list_attachments"));
|
|
|
|
for (const name of noArgNames) {
|
|
const registration = registrations.find((entry) => entry.name === name);
|
|
assert.equal(registration?.hasSchema, false, `${name} should omit the params schema`);
|
|
}
|
|
|
|
const execute = registrations.find((entry) => entry.name === "terminal_execute");
|
|
assert.equal(execute?.hasSchema, true);
|
|
});
|
|
|
|
test("get_environment handler runs when MCP arguments are omitted (#3049)", async () => {
|
|
let handler = null;
|
|
const fakeServer = {
|
|
tool(name, _description, schemaOrHandler, maybeHandler) {
|
|
if (name === "get_environment") handler = mcpToolHandler(schemaOrHandler, maybeHandler);
|
|
},
|
|
};
|
|
let rpcMethod = null;
|
|
registerMcpTools(fakeServer, {
|
|
rpcCall: async (method) => {
|
|
rpcMethod = method;
|
|
return { sessions: [] };
|
|
},
|
|
scopeParams: { chatSessionId: "chat-1" },
|
|
guardWriteOperation: () => null,
|
|
catalogDescription: (_name, fallback) => fallback,
|
|
});
|
|
|
|
assert.ok(handler, "get_environment handler registered");
|
|
const result = await handler();
|
|
assert.equal(result.isError, undefined);
|
|
assert.equal(rpcMethod, "netcatty/getContext");
|
|
assert.match(result.content?.[0]?.text || "", /sessions/);
|
|
});
|
|
|
|
test("session_close remains available as a cleanup action in observer mode", async () => {
|
|
let handler = null;
|
|
let guardCalls = 0;
|
|
const fakeServer = {
|
|
tool(name, _description, schemaOrHandler, maybeHandler) {
|
|
if (name === "session_close") handler = mcpToolHandler(schemaOrHandler, maybeHandler);
|
|
},
|
|
};
|
|
registerMcpTools(fakeServer, {
|
|
rpcCall: async (_method, params) => ({ ok: true, sessionId: params.sessionId, status: "closed" }),
|
|
scopeParams: { chatSessionId: "chat-1" },
|
|
guardWriteOperation: () => {
|
|
guardCalls += 1;
|
|
return "Observer mode";
|
|
},
|
|
catalogDescription: (_name, fallback) => fallback,
|
|
});
|
|
|
|
const result = await handler({ sessionId: "session-1" });
|
|
assert.equal(result.isError, undefined);
|
|
assert.equal(guardCalls, 0);
|
|
});
|
|
|
|
test("terminal_execute MCP response preserves stdout/exitCode on non-zero exit (#2718)", async () => {
|
|
let handler = null;
|
|
const fakeServer = {
|
|
tool(name, _description, schemaOrHandler, maybeHandler) {
|
|
if (name === "terminal_execute") handler = mcpToolHandler(schemaOrHandler, maybeHandler);
|
|
},
|
|
};
|
|
registerMcpTools(fakeServer, {
|
|
rpcCall: async () => ({
|
|
ok: false,
|
|
stdout: "du: cannot access '/missing': No such file or directory",
|
|
stderr: "",
|
|
exitCode: 1,
|
|
}),
|
|
scopeParams: { chatSessionId: "chat-1" },
|
|
guardWriteOperation: () => null,
|
|
catalogDescription: (_name, fallback) => fallback,
|
|
});
|
|
|
|
assert.ok(handler, "terminal_execute handler registered");
|
|
const result = await handler({ sessionId: "sess-1", command: "du /missing" });
|
|
assert.equal(result.isError, undefined);
|
|
const text = result.content?.[0]?.text || "";
|
|
assert.match(text, /cannot access '\/missing'/);
|
|
assert.match(text, /\[exit code: 1\]/);
|
|
assert.doesNotMatch(text, /Operation failed/);
|
|
});
|
|
|
|
test("terminal_execute MCP response keeps operational failures as isError", async () => {
|
|
let handler = null;
|
|
const fakeServer = {
|
|
tool(name, _description, schemaOrHandler, maybeHandler) {
|
|
if (name === "terminal_execute") handler = mcpToolHandler(schemaOrHandler, maybeHandler);
|
|
},
|
|
};
|
|
registerMcpTools(fakeServer, {
|
|
rpcCall: async () => ({ ok: false, error: "Session not found" }),
|
|
scopeParams: { chatSessionId: "chat-1" },
|
|
guardWriteOperation: () => null,
|
|
catalogDescription: (_name, fallback) => fallback,
|
|
});
|
|
|
|
const result = await handler({ sessionId: "gone", command: "uptime" });
|
|
assert.equal(result.isError, true);
|
|
assert.equal(result.content?.[0]?.text, "Error: Session not found");
|
|
});
|
|
|
|
test("terminal_execute MCP response includes partial output on timeout", async () => {
|
|
let handler = null;
|
|
const fakeServer = {
|
|
tool(name, _description, schemaOrHandler, maybeHandler) {
|
|
if (name === "terminal_execute") handler = mcpToolHandler(schemaOrHandler, maybeHandler);
|
|
},
|
|
};
|
|
registerMcpTools(fakeServer, {
|
|
rpcCall: async () => ({
|
|
ok: false,
|
|
stdout: "partial lines",
|
|
stderr: "",
|
|
exitCode: -1,
|
|
error: "Command timed out (60s)",
|
|
}),
|
|
scopeParams: { chatSessionId: "chat-1" },
|
|
guardWriteOperation: () => null,
|
|
catalogDescription: (_name, fallback) => fallback,
|
|
});
|
|
|
|
const result = await handler({ sessionId: "sess-1", command: "sleep 999" });
|
|
assert.equal(result.isError, true);
|
|
const text = result.content?.[0]?.text || "";
|
|
assert.match(text, /partial lines/);
|
|
assert.match(text, /\[exit code: -1\]/);
|
|
assert.match(text, /\[error\] Command timed out \(60s\)/);
|
|
});
|
|
|
|
test("terminal_execute MCP response uses neutral text for successful empty output (#2724)", async () => {
|
|
let handler = null;
|
|
const fakeServer = {
|
|
tool(name, _description, schemaOrHandler, maybeHandler) {
|
|
if (name === "terminal_execute") handler = mcpToolHandler(schemaOrHandler, maybeHandler);
|
|
},
|
|
};
|
|
// Serial/network-device raw PTY success: ok true, empty streams, exitCode null.
|
|
registerMcpTools(fakeServer, {
|
|
rpcCall: async () => ({
|
|
ok: true,
|
|
stdout: "",
|
|
stderr: "",
|
|
exitCode: null,
|
|
}),
|
|
scopeParams: { chatSessionId: "chat-1" },
|
|
guardWriteOperation: () => null,
|
|
catalogDescription: (_name, fallback) => fallback,
|
|
});
|
|
|
|
const result = await handler({ sessionId: "sess-1", command: "configure terminal" });
|
|
assert.equal(result.isError, undefined);
|
|
assert.equal(result.content?.[0]?.text, "Command completed (no output)");
|
|
assert.doesNotMatch(result.content?.[0]?.text || "", /Operation failed/);
|
|
});
|
|
|
|
test("terminal_execute MCP response keeps exit-only non-zero without isError", async () => {
|
|
let handler = null;
|
|
const fakeServer = {
|
|
tool(name, _description, schemaOrHandler, maybeHandler) {
|
|
if (name === "terminal_execute") handler = mcpToolHandler(schemaOrHandler, maybeHandler);
|
|
},
|
|
};
|
|
registerMcpTools(fakeServer, {
|
|
rpcCall: async () => ({
|
|
ok: false,
|
|
stdout: "",
|
|
stderr: "",
|
|
exitCode: 1,
|
|
}),
|
|
scopeParams: { chatSessionId: "chat-1" },
|
|
guardWriteOperation: () => null,
|
|
catalogDescription: (_name, fallback) => fallback,
|
|
});
|
|
|
|
const result = await handler({ sessionId: "sess-1", command: "false" });
|
|
assert.equal(result.isError, undefined);
|
|
assert.equal(result.content?.[0]?.text, "[exit code: 1]");
|
|
assert.doesNotMatch(result.content?.[0]?.text || "", /Operation failed/);
|
|
});
|
|
|
|
test("terminal_execute_bulk is MCP-only: no sidebar or global agent exposure", () => {
|
|
const { listMcpTools, listCattyToolSpecs, listAgentToolSpecs } = require("./toolSurfaces.cjs");
|
|
const { AGENT_KINDS } = require("../constants.cjs");
|
|
assert.ok(listMcpTools().some((tool) => tool.mcpTool === "terminal_execute_bulk"));
|
|
assert.equal(listCattyToolSpecs().some((spec) => spec.capabilityId === "terminal.executeBulk"), false);
|
|
assert.equal(listAgentToolSpecs(AGENT_KINDS.GLOBAL).some((spec) => spec.capabilityId === "terminal.executeBulk"), false);
|
|
});
|