Skip to content

Commit 1946b09

Browse files
byapparovclaude
andcommitted
fix(tool): render the bash default timeout and insert agent descriptions literally
The bash description now renders the default timeout from AICTRL_EXPERIMENTAL_BASH_DEFAULT_TIMEOUT_MS instead of a hardcoded 120000ms. The task description inserts {agents} with a replacer function, so `$` patterns in agent descriptions are not expanded. Refs #214 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_015nwvfUHdM3bgMgD9Zpz7Mj
1 parent 7d54b7a commit 1946b09

5 files changed

Lines changed: 47 additions & 4 deletions

File tree

‎packages/cli/src/tool/bash.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ export const BashTool = Tool.define("bash", async () => {
9797
// Replacer functions insert values literally, without `$` pattern expansion
9898
description: DESCRIPTION.replaceAll("${directory}", () => Instance.directory)
9999
.replaceAll("${maxLines}", () => String(Truncate.MAX_LINES))
100-
.replaceAll("${maxBytes}", () => String(Truncate.MAX_BYTES)),
100+
.replaceAll("${maxBytes}", () => String(Truncate.MAX_BYTES))
101+
.replaceAll("${timeout}", () => String(DEFAULT_TIMEOUT)),
101102
parameters: z.object({
102103
command: z.string().describe("The command to execute"),
103104
timeout: z.number().describe("Optional timeout in milliseconds").optional(),

‎packages/cli/src/tool/bash.txt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Do not use it for file operations; use the dedicated tools instead: Glob (not fi
44

55
All commands run in ${directory} by default. To run elsewhere, set `workdir` instead of using `cd`.
66

7-
Commands time out after 120000ms (2 minutes) unless `timeout` (milliseconds) is set.
7+
Commands time out after ${timeout}ms unless `timeout` (milliseconds) is set.
88

99
Output over ${maxLines} lines or ${maxBytes} bytes is truncated and the full output is written to a file; read it with Read (offset/limit) or search it with Grep. So do not limit output with `head`, `tail` or other truncation commands; run the command directly.
1010

‎packages/cli/src/tool/task.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ export const TaskTool = Tool.define("task", async (ctx) => {
5454
? agents.filter((a) => PermissionNext.evaluate("task", a.name, caller.permission).action !== "deny")
5555
: agents
5656

57-
const description = DESCRIPTION.replace(
58-
"{agents}",
57+
// A replacer function inserts agent descriptions literally, without `$` pattern expansion
58+
const description = DESCRIPTION.replace("{agents}", () =>
5959
accessibleAgents
6060
.map((a) => `- ${a.name}: ${a.description ?? "This subagent should only be called manually by the user."}`)
6161
.join("\n"),

‎packages/cli/test/tool/bash.test.ts‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,37 @@ describe("tool.bash description", () => {
8585
expect(text).toContain("Do not use it for file operations; use the dedicated tools instead")
8686
expect(text).toContain("separate parallel tool calls")
8787
})
88+
89+
test("states the configured default timeout", async () => {
90+
// The default is read from the environment at module load, so render the description in a child process
91+
await using tmp = await tmpdir({
92+
init: async (dir) => {
93+
const src = path.resolve(import.meta.dir, "../../src")
94+
const script = [
95+
`import { BashTool } from ${JSON.stringify(path.join(src, "tool/bash"))}`,
96+
`import { Instance } from ${JSON.stringify(path.join(src, "project/instance"))}`,
97+
`const text = await Instance.provide({ directory: ${JSON.stringify(dir)}, fn: async () => (await BashTool.init()).description })`,
98+
`process.stdout.write(text)`,
99+
`process.exit(0)`,
100+
].join("\n")
101+
await Bun.write(path.join(dir, "render.ts"), script)
102+
},
103+
})
104+
const proc = Bun.spawn(["bun", "--conditions=browser", path.join(tmp.path, "render.ts")], {
105+
cwd: path.resolve(import.meta.dir, "../.."),
106+
env: { ...process.env, AICTRL_EXPERIMENTAL_BASH_DEFAULT_TIMEOUT_MS: "4321" },
107+
stdout: "pipe",
108+
stderr: "pipe",
109+
})
110+
const [text, stderr, code] = await Promise.all([
111+
new Response(proc.stdout).text(),
112+
new Response(proc.stderr).text(),
113+
proc.exited,
114+
])
115+
expect(stderr).toBe("")
116+
expect(code).toBe(0)
117+
expect(text).toContain("Commands time out after 4321ms")
118+
})
88119
})
89120

90121
describe("tool.bash dangerous git commands", () => {

‎packages/cli/test/tool/task.test.ts‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,17 @@ describe("task tool description", () => {
146146
expect(text).toContain("- explore: ")
147147
expect(text).toContain("`task_id`")
148148
})
149+
150+
test("inserts agent descriptions literally", async () => {
151+
await using tmp = await tmpdir({
152+
config: { agent: { pricey: { mode: "subagent", description: "Costs $& or $$ per run" } } },
153+
})
154+
const text = await Instance.provide({
155+
directory: tmp.path,
156+
fn: async () => (await TaskTool.init()).description,
157+
})
158+
expect(text).toContain("- pricey: Costs $& or $$ per run")
159+
})
149160
})
150161

151162
describe("task tool subagent session", () => {

0 commit comments

Comments
 (0)