Skip to content

Commit a364fcf

Browse files
committed
Gate tool-output URI reads on named truncation notices
The prompt always preferred a tool-output URI over re-reading huge blobs, so complete inline wait_agents results were re-read. Only invite that read when a truncation notice named a URI.
1 parent 2a8cf44 commit a364fcf

2 files changed

Lines changed: 24 additions & 2 deletions

File tree

src/agent/prompts.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ export function buildHarnessFacts(
7878
"- Shell file-writes and deletions are blocked; never use echo/heredoc/sed/rm as a substitute for product tools. Path tools are the DIY surface.",
7979
]),
8080
"- Use the provided tools for file reads/searches instead of shelling out as a substitute.",
81-
"- read_file accepts a filesystem path or a tool-output:///{callId} URI from a prior tool result when the harness exposes one; prefer the URI over re-reading huge blobs.",
81+
"- read_file accepts a filesystem path or a tool-output:///{callId} URI from a prior tool result when the harness exposes one. Only read_file a tool-output:// URI if the truncation notice on that result named one; do not re-read a complete inline result.",
8282
"- run_shell has no default timeout; pass timeout for builds, tests, and other long commands. Prefer background:true for builds, test suites, and dev servers: it returns a shell_id at once, the result is delivered when the process finishes (foreground runs hold steers; background runs do not), and shell_collect collects or cancels later. background does not change the retained shell cwd.",
8383
"- Shell find, rg, and grep -r are blocked — they can walk huge trees and OOM the host. Prefer the bounded grep/search_files tools, and do not substitute another unbounded walk (fd, ls -R, scripted os.walk).",
8484
...(subAgent
@@ -226,7 +226,7 @@ export function buildPromptDisciplineBlock(
226226

227227
const TOOL_SUMMARIES: Record<string, string> = {
228228
read_file:
229-
"read a file or tool-output:///{callId} from a prior tool result (prefer over cat/head/tail in the shell)",
229+
"read a file or tool-output:///{callId} from a prior tool result (prefer over cat/head/tail in the shell). Only read_file a tool-output:// URI if the truncation notice named one",
230230
write_file: "create or overwrite a file (never shell redirects or heredocs)",
231231
edit_file:
232232
"make a surgical edit (exact old_string match, or start_line/end_line line-range mode; never include read_file's NNNNNN\\t line prefix; substring failures include nearby file text; prefer over sed/awk in the shell)",

src/prompts.test.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,28 @@ test("harness facts state only the non-derivable tool and safety rules", () => {
8787
expect(facts).not.toContain("Tool results already render richly");
8888
});
8989

90+
test("harness facts gate tool-output URI reads on a named truncation notice", () => {
91+
const facts = buildHarnessFacts();
92+
expect(facts).toContain("read_file");
93+
expect(facts).toMatch(/filesystem path/i);
94+
expect(facts).toMatch(/tool-output:\/\//);
95+
expect(facts).toMatch(/truncat/i);
96+
expect(facts).toMatch(/named/i);
97+
expect(facts).not.toMatch(/prefer the URI/i);
98+
expect(facts).not.toMatch(/re-reading huge blobs/i);
99+
expect(facts).toMatch(/complete inline/i);
100+
});
101+
102+
test("read_file catalog summary gates tool-output URI reads on truncation", () => {
103+
const listed = buildAvailableTools(["read_file"]);
104+
expect(listed).toContain("read_file");
105+
expect(listed).toMatch(/tool-output:\/\//);
106+
expect(listed).toMatch(/truncat/i);
107+
expect(listed).toMatch(/named/i);
108+
expect(listed).toContain("cat/head/tail");
109+
expect(listed).not.toMatch(/prefer the URI/i);
110+
});
111+
90112
test("harness facts name skill_search as a resident catalog tool", () => {
91113
const facts = buildHarnessFacts();
92114
expect(facts).toMatch(

0 commit comments

Comments
 (0)