fix: format exec elevated flag first in tool summaries

This commit is contained in:
Peter Steinberger
2026-01-17 21:54:05 +00:00
parent 4b11ebb30e
commit 3200b51160
3 changed files with 47 additions and 2 deletions

View File

@@ -2,11 +2,12 @@
Docs: https://docs.clawd.bot
## 2026.1.17-2 (Unreleased)
## 2026.1.17-2
### Changes
### Fixes
- Tools: show exec elevated flag before the command and keep it outside markdown in tool summaries.
- Memory: split overly long lines to keep embeddings under token limits.
## 2026.1.17-1

View File

@@ -42,6 +42,16 @@ describe("tool meta formatting", () => {
expect(out).toContain("`~/dir/a.txt`");
});
it("keeps exec flags outside markdown and moves them to the front", () => {
vi.stubEnv("HOME", "/Users/test");
const out = formatToolAggregate(
"exec",
["cd /Users/test/dir && gemini 2>&1 · elevated"],
{ markdown: true },
);
expect(out).toBe("🛠️ exec: elevated · `cd ~/dir && gemini 2>&1`");
});
it("formats prefixes with default labels", () => {
vi.stubEnv("HOME", "/Users/test");
expect(formatToolPrefix(undefined, undefined)).toBe("🧩 tool");

View File

@@ -60,7 +60,7 @@ export function formatToolAggregate(
const allSegments = [...rawSegments, ...segments];
const meta = allSegments.join("; ");
return `${prefix}: ${maybeWrapMarkdown(meta, options?.markdown)}`;
return `${prefix}: ${formatMetaForDisplay(toolName, meta, options?.markdown)}`;
}
export function formatToolPrefix(toolName?: string, meta?: string) {
@@ -69,6 +69,40 @@ export function formatToolPrefix(toolName?: string, meta?: string) {
return formatToolSummary(display);
}
function formatMetaForDisplay(
toolName: string | undefined,
meta: string,
markdown?: boolean,
): string {
const normalized = (toolName ?? "").trim().toLowerCase();
if (normalized === "exec" || normalized === "bash") {
const { flags, body } = splitExecFlags(meta);
if (flags.length > 0) {
if (!body) return flags.join(" · ");
return `${flags.join(" · ")} · ${maybeWrapMarkdown(body, markdown)}`;
}
}
return maybeWrapMarkdown(meta, markdown);
}
function splitExecFlags(meta: string): { flags: string[]; body: string } {
const parts = meta
.split(" · ")
.map((part) => part.trim())
.filter(Boolean);
if (parts.length === 0) return { flags: [], body: "" };
const flags: string[] = [];
const bodyParts: string[] = [];
for (const part of parts) {
if (part === "elevated" || part === "pty") {
flags.push(part);
continue;
}
bodyParts.push(part);
}
return { flags, body: bodyParts.join(" · ") };
}
function isPathLike(value: string): boolean {
if (!value) return false;
if (value.includes(" ")) return false;