Skip to content

Commit 9eb9cbb

Browse files
committed
fix(agents): detect extensionless shell scripts
1 parent a4c2e09 commit 9eb9cbb

2 files changed

Lines changed: 27 additions & 1 deletion

File tree

‎src/agents/bash-tools.exec.script-preflight.test.ts‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1072,6 +1072,23 @@ describeNonWin("exec script preflight", () => {
10721072
workdir: tmp,
10731073
}),
10741074
).rejects.toThrow(/exec cannot run OpenClaw message delivery commands/);
1075+
1076+
await fs.writeFile(
1077+
path.join(tmp, "send-message"),
1078+
[
1079+
"#!/usr/bin/env bash",
1080+
'openclaw message send --channel whatsapp --target +1555 --message "hello"',
1081+
].join("\n"),
1082+
"utf-8",
1083+
);
1084+
await fs.chmod(path.join(tmp, "send-message"), 0o755);
1085+
await expect(
1086+
tool.execute("call-direct-extensionless-shell-script-send", {
1087+
command: "./send-message",
1088+
workdir: tmp,
1089+
}),
1090+
).rejects.toThrow(/exec cannot run OpenClaw message delivery commands/);
1091+
10751092
await expect(
10761093
tool.execute("call-source-shell-script-send", {
10771094
command: "source ./send.sh",

‎src/agents/bash-tools.exec.ts‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,16 @@ function extractDirectShellScriptTargetFromArgv(
534534
return null;
535535
}
536536
const commandName = normalizeCommandBaseName(command);
537-
if (!/\.(?:bash|command|fish|ksh|sh|zsh)$/iu.test(commandName)) {
537+
const isAbsoluteShellWrapperPath =
538+
OPENCLAW_CONTROL_SHELL_WRAPPERS.has(commandName) &&
539+
(path.isAbsolute(command) || /^[A-Za-z]:[\\/]/u.test(command) || command.startsWith("\\\\"));
540+
if (isAbsoluteShellWrapperPath) {
541+
return null;
542+
}
543+
const hasShellScriptSuffix = /\.(?:bash|command|fish|ksh|sh|zsh)$/iu.test(commandName);
544+
const isPathLikeExtensionlessCommand =
545+
!commandName.includes(".") && (command.includes("/") || command.includes("\\"));
546+
if (!hasShellScriptSuffix && !isPathLikeExtensionlessCommand) {
538547
return null;
539548
}
540549
return { kind: "shell", relOrAbsPaths: [command] };

0 commit comments

Comments
 (0)