fix: refine tool summaries and scope discord tool

This commit is contained in:
Peter Steinberger
2026-01-03 12:33:42 +01:00
parent 7165c8a7e5
commit 772ada4308
13 changed files with 83 additions and 11 deletions

View File

@@ -105,6 +105,7 @@ type FollowupRun = {
run: {
sessionId: string;
sessionKey?: string;
surface?: string;
sessionFile: string;
workspaceDir: string;
config: ClawdisConfig;
@@ -1871,6 +1872,7 @@ export async function getReplyFromConfig(
run: {
sessionId: sessionIdFinal,
sessionKey,
surface: sessionCtx.Surface?.trim().toLowerCase() || undefined,
sessionFile,
workspaceDir,
config: cfg,
@@ -1942,6 +1944,7 @@ export async function getReplyFromConfig(
runResult = await runEmbeddedPiAgent({
sessionId: queued.run.sessionId,
sessionKey: queued.run.sessionKey,
surface: queued.run.surface,
sessionFile: queued.run.sessionFile,
workspaceDir: queued.run.workspaceDir,
config: queued.run.config,
@@ -2061,6 +2064,7 @@ export async function getReplyFromConfig(
runResult = await runEmbeddedPiAgent({
sessionId: sessionIdFinal,
sessionKey,
surface: sessionCtx.Surface?.trim().toLowerCase() || undefined,
sessionFile,
workspaceDir,
config: cfg,

View File

@@ -35,7 +35,7 @@ describe("tool meta formatting", () => {
"note",
"a→b",
]);
expect(out).toMatch(/^\[🛠️ fs]/);
expect(out).toMatch(/^🛠️ fs/);
expect(out).toContain("~/dir/{a.txt, b.txt}");
expect(out).toContain("note");
expect(out).toContain("a→b");
@@ -43,8 +43,8 @@ describe("tool meta formatting", () => {
it("formats prefixes with default labels", () => {
vi.stubEnv("HOME", "/Users/test");
expect(formatToolPrefix(undefined, undefined)).toBe("[🛠️ tool]");
expect(formatToolPrefix("x", "/Users/test/a.txt")).toBe("[🛠️ x ~/a.txt]");
expect(formatToolPrefix(undefined, undefined)).toBe("🛠️ tool");
expect(formatToolPrefix("x", "/Users/test/a.txt")).toBe("🛠️ x: ~/a.txt");
});
});

View File

@@ -1,6 +1,28 @@
export const TOOL_RESULT_DEBOUNCE_MS = 500;
export const TOOL_RESULT_FLUSH_COUNT = 5;
const TOOL_EMOJI_BY_NAME: Record<string, string> = {
bash: "💻",
process: "🧰",
read: "📖",
write: "✍️",
edit: "📝",
attach: "📎",
clawdis_browser: "🌐",
clawdis_canvas: "🖼️",
clawdis_nodes: "📱",
clawdis_cron: "⏰",
clawdis_gateway: "🔌",
whatsapp_login: "🟢",
discord: "💬",
};
function resolveToolEmoji(toolName?: string): string {
const key = toolName?.trim().toLowerCase();
if (key && TOOL_EMOJI_BY_NAME[key]) return TOOL_EMOJI_BY_NAME[key];
return "🛠️";
}
export function shortenPath(p: string): string {
const home = process.env.HOME;
if (home && (p === home || p.startsWith(`${home}/`)))
@@ -23,7 +45,7 @@ export function formatToolAggregate(
): string {
const filtered = (metas ?? []).filter(Boolean).map(shortenMeta);
const label = toolName?.trim() || "tool";
const prefix = `[🛠️ ${label}]`;
const prefix = `${resolveToolEmoji(label)} ${label}`;
if (!filtered.length) return prefix;
const rawSegments: string[] = [];
@@ -53,13 +75,14 @@ export function formatToolAggregate(
});
const allSegments = [...rawSegments, ...segments];
return `${prefix} ${allSegments.join("; ")}`;
return `${prefix}: ${allSegments.join("; ")}`;
}
export function formatToolPrefix(toolName?: string, meta?: string) {
const label = toolName?.trim() || "tool";
const emoji = resolveToolEmoji(label);
const extra = meta?.trim() ? shortenMeta(meta) : undefined;
return extra ? `[🛠️ ${label} ${extra}]` : `[🛠️ ${label}]`;
return extra ? `${emoji} ${label}: ${extra}` : `${emoji} ${label}`;
}
export function createToolDebouncer(