




















@@ -15,6 +15,8 @@ import {
1515} from "../infra/exec-inline-eval.js";
1616import { buildNodeShellCommand } from "../infra/node-shell.js";
1717import { parsePreparedSystemRunPayload } from "../infra/system-run-approval-context.js";
18+import { formatExecCommand, resolveSystemRunCommandRequest } from "../infra/system-run-command.js";
19+import { normalizeNullableString } from "../shared/string-coerce.js";
1820import type { ExecuteNodeHostCommandParams } from "./bash-tools.exec-host-node.js";
1921import type { ExecToolDetails } from "./bash-tools.exec-types.js";
2022import { callGatewayTool } from "./tools/gateway.js";
@@ -26,6 +28,7 @@ export type NodeExecutionTarget = {
2628argv: string[];
2729env: Record<string, string> | undefined;
2830invokeTimeoutMs: number;
31+supportsSystemRunPrepare: boolean;
2932};
30333134export type PreparedNodeRun = {
@@ -113,9 +116,8 @@ export async function resolveNodeExecutionTarget(
113116throw err;
114117}
115118const nodeInfo = nodes.find((entry) => entry.nodeId === nodeId);
116-const supportsSystemRun = Array.isArray(nodeInfo?.commands)
117- ? nodeInfo?.commands?.includes("system.run")
118- : false;
119+const declaredCommands = Array.isArray(nodeInfo?.commands) ? nodeInfo.commands : [];
120+const supportsSystemRun = declaredCommands.includes("system.run");
119121if (!supportsSystemRun) {
120122throw new Error(
121123"exec host=node requires a node that supports system.run (companion app or node host).",
@@ -133,6 +135,7 @@ export async function resolveNodeExecutionTarget(
1331351000 +
1341365_000,
135137),
138+supportsSystemRunPrepare: declaredCommands.includes("system.run.prepare"),
136139};
137140}
138141@@ -199,6 +202,10 @@ export async function prepareNodeSystemRun(params: {
199202request: ExecuteNodeHostCommandParams;
200203target: NodeExecutionTarget;
201204}): Promise<PreparedNodeRun> {
205+if (!params.target.supportsSystemRunPrepare) {
206+return buildLocalPreparedNodeRun(params);
207+}
208+202209const prepareRaw = await callGatewayTool(
203210"node.invoke",
204211{ timeoutMs: 15_000 },
@@ -229,6 +236,41 @@ export async function prepareNodeSystemRun(params: {
229236};
230237}
231238239+function buildLocalPreparedNodeRun(params: {
240+request: ExecuteNodeHostCommandParams;
241+target: NodeExecutionTarget;
242+}): PreparedNodeRun {
243+const command = resolveSystemRunCommandRequest({
244+command: params.target.argv,
245+rawCommand: params.request.command,
246+});
247+if (!command.ok) {
248+throw new Error(command.message);
249+}
250+if (command.argv.length === 0) {
251+throw new Error("command required");
252+}
253+const commandText = formatExecCommand(command.argv);
254+const previewText = command.previewText?.trim();
255+const commandPreview = previewText && previewText !== commandText ? previewText : null;
256+const plan = {
257+argv: [...command.argv],
258+cwd: normalizeNullableString(params.request.workdir),
259+ commandText,
260+ commandPreview,
261+agentId: normalizeNullableString(params.request.agentId),
262+sessionKey: normalizeNullableString(params.request.sessionKey),
263+} satisfies SystemRunApprovalPlan;
264+return {
265+ plan,
266+argv: plan.argv,
267+rawCommand: plan.commandText,
268+cwd: plan.cwd ?? params.request.workdir,
269+agentId: plan.agentId ?? params.request.agentId,
270+sessionKey: plan.sessionKey ?? params.request.sessionKey,
271+};
272+}
273+232274export async function analyzeNodeApprovalRequirement(params: {
233275request: ExecuteNodeHostCommandParams;
234276target: NodeExecutionTarget;
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。