mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 10:01:24 +00:00
fix(agents): harden bash tool and reply directive handling
This commit is contained in:
@@ -278,6 +278,18 @@ export function createProcessTool(
|
||||
});
|
||||
};
|
||||
|
||||
const runningSessionResult = (
|
||||
session: ProcessSession,
|
||||
text: string,
|
||||
): AgentToolResult<unknown> => ({
|
||||
content: [{ type: "text", text }],
|
||||
details: {
|
||||
status: "running",
|
||||
sessionId: params.sessionId,
|
||||
name: deriveSessionName(session.command),
|
||||
},
|
||||
});
|
||||
|
||||
switch (params.action) {
|
||||
case "poll": {
|
||||
if (!scopedSession) {
|
||||
@@ -452,21 +464,12 @@ export function createProcessTool(
|
||||
if (params.eof) {
|
||||
resolved.stdin.end();
|
||||
}
|
||||
return {
|
||||
content: [
|
||||
{
|
||||
type: "text",
|
||||
text: `Wrote ${(params.data ?? "").length} bytes to session ${params.sessionId}${
|
||||
params.eof ? " (stdin closed)" : ""
|
||||
}.`,
|
||||
},
|
||||
],
|
||||
details: {
|
||||
status: "running",
|
||||
sessionId: params.sessionId,
|
||||
name: deriveSessionName(resolved.session.command),
|
||||
},
|
||||
};
|
||||
return runningSessionResult(
|
||||
resolved.session,
|
||||
`Wrote ${(params.data ?? "").length} bytes to session ${params.sessionId}${
|
||||
params.eof ? " (stdin closed)" : ""
|
||||
}.`,
|
||||
);
|
||||
}
|
||||
|
||||
case "send-keys": {
|
||||
@@ -491,21 +494,11 @@ export function createProcessTool(
|
||||
};
|
||||
}
|
||||
await writeToStdin(resolved.stdin, data);
|
||||
return {
|
||||
content: [
|
||||
{
|
||||
type: "text",
|
||||
text:
|
||||
`Sent ${data.length} bytes to session ${params.sessionId}.` +
|
||||
(warnings.length ? `\nWarnings:\n- ${warnings.join("\n- ")}` : ""),
|
||||
},
|
||||
],
|
||||
details: {
|
||||
status: "running",
|
||||
sessionId: params.sessionId,
|
||||
name: deriveSessionName(resolved.session.command),
|
||||
},
|
||||
};
|
||||
return runningSessionResult(
|
||||
resolved.session,
|
||||
`Sent ${data.length} bytes to session ${params.sessionId}.` +
|
||||
(warnings.length ? `\nWarnings:\n- ${warnings.join("\n- ")}` : ""),
|
||||
);
|
||||
}
|
||||
|
||||
case "submit": {
|
||||
@@ -514,19 +507,10 @@ export function createProcessTool(
|
||||
return resolved.result;
|
||||
}
|
||||
await writeToStdin(resolved.stdin, "\r");
|
||||
return {
|
||||
content: [
|
||||
{
|
||||
type: "text",
|
||||
text: `Submitted session ${params.sessionId} (sent CR).`,
|
||||
},
|
||||
],
|
||||
details: {
|
||||
status: "running",
|
||||
sessionId: params.sessionId,
|
||||
name: deriveSessionName(resolved.session.command),
|
||||
},
|
||||
};
|
||||
return runningSessionResult(
|
||||
resolved.session,
|
||||
`Submitted session ${params.sessionId} (sent CR).`,
|
||||
);
|
||||
}
|
||||
|
||||
case "paste": {
|
||||
@@ -547,19 +531,10 @@ export function createProcessTool(
|
||||
};
|
||||
}
|
||||
await writeToStdin(resolved.stdin, payload);
|
||||
return {
|
||||
content: [
|
||||
{
|
||||
type: "text",
|
||||
text: `Pasted ${params.text?.length ?? 0} chars to session ${params.sessionId}.`,
|
||||
},
|
||||
],
|
||||
details: {
|
||||
status: "running",
|
||||
sessionId: params.sessionId,
|
||||
name: deriveSessionName(resolved.session.command),
|
||||
},
|
||||
};
|
||||
return runningSessionResult(
|
||||
resolved.session,
|
||||
`Pasted ${params.text?.length ?? 0} chars to session ${params.sessionId}.`,
|
||||
);
|
||||
}
|
||||
|
||||
case "kill": {
|
||||
|
||||
Reference in New Issue
Block a user