mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 21:58:26 +00:00
feat(tool-display): add intent-first details and exec summaries
- add human-readable read/write/edit/attach details with path alias support\n- add explicit web_search/web_fetch phrasing (quoted query, mode/limit)\n- make detail text title-first by returning detail-only in formatters\n- add deterministic exec summarizer (wrappers, pipelines, heredoc, git/node/python heuristics, preamble stripping)\n- extend e2e coverage for file/web/exec cases
This commit is contained in:
committed by
Peter Steinberger
parent
b9c45d003d
commit
24f213e7ed
@@ -51,4 +51,80 @@ describe("tool display details", () => {
|
||||
expect(detail).toContain("limit 20");
|
||||
expect(detail).toContain("tools true");
|
||||
});
|
||||
|
||||
it("formats read/write/edit with intent-first file detail", () => {
|
||||
const readDetail = formatToolDetail(
|
||||
resolveToolDisplay({
|
||||
name: "read",
|
||||
args: { file_path: "/tmp/a.txt", offset: 2, limit: 2 },
|
||||
}),
|
||||
);
|
||||
const writeDetail = formatToolDetail(
|
||||
resolveToolDisplay({
|
||||
name: "write",
|
||||
args: { file_path: "/tmp/a.txt", content: "abc" },
|
||||
}),
|
||||
);
|
||||
const editDetail = formatToolDetail(
|
||||
resolveToolDisplay({
|
||||
name: "edit",
|
||||
args: { path: "/tmp/a.txt", newText: "abcd" },
|
||||
}),
|
||||
);
|
||||
|
||||
expect(readDetail).toBe("lines 2-3 from /tmp/a.txt");
|
||||
expect(writeDetail).toBe("to /tmp/a.txt (3 chars)");
|
||||
expect(editDetail).toBe("in /tmp/a.txt (4 chars)");
|
||||
});
|
||||
|
||||
it("formats web_search query with quotes", () => {
|
||||
const detail = formatToolDetail(
|
||||
resolveToolDisplay({
|
||||
name: "web_search",
|
||||
args: { query: "OpenClaw docs", count: 3 },
|
||||
}),
|
||||
);
|
||||
|
||||
expect(detail).toBe('for "OpenClaw docs" (top 3)');
|
||||
});
|
||||
|
||||
it("summarizes exec commands with context", () => {
|
||||
const detail = formatToolDetail(
|
||||
resolveToolDisplay({
|
||||
name: "exec",
|
||||
args: {
|
||||
command:
|
||||
"set -euo pipefail\ngit -C /Users/adityasingh/.openclaw/workspace status --short | head -n 3",
|
||||
workdir: "/Users/adityasingh/.openclaw/workspace",
|
||||
},
|
||||
}),
|
||||
);
|
||||
|
||||
expect(detail).toContain("check git status -> show first 3 lines");
|
||||
expect(detail).toContain(".openclaw/workspace)");
|
||||
});
|
||||
|
||||
it("recognizes heredoc/inline script exec details", () => {
|
||||
const pyDetail = formatToolDetail(
|
||||
resolveToolDisplay({
|
||||
name: "exec",
|
||||
args: {
|
||||
command: "python3 <<PY\nprint('x')\nPY",
|
||||
workdir: "/Users/adityasingh/.openclaw/workspace",
|
||||
},
|
||||
}),
|
||||
);
|
||||
const nodeCheckDetail = formatToolDetail(
|
||||
resolveToolDisplay({
|
||||
name: "exec",
|
||||
args: {
|
||||
command: "node --check /tmp/test.js",
|
||||
workdir: "/Users/adityasingh/.openclaw/workspace",
|
||||
},
|
||||
}),
|
||||
);
|
||||
|
||||
expect(pyDetail).toContain("run python3 inline script (heredoc)");
|
||||
expect(nodeCheckDetail).toContain("check js syntax for /tmp/test.js");
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user