fix: format verbose tool output by channel
This commit is contained in:
@@ -20,6 +20,10 @@ import {
|
||||
import { logVerbose } from "../../globals.js";
|
||||
import { emitAgentEvent, registerAgentRunContext } from "../../infra/agent-events.js";
|
||||
import { defaultRuntime } from "../../runtime.js";
|
||||
import {
|
||||
isMarkdownCapableMessageChannel,
|
||||
resolveMessageChannel,
|
||||
} from "../../utils/message-channel.js";
|
||||
import { stripHeartbeatToken } from "../heartbeat.js";
|
||||
import type { TemplateContext } from "../templating.js";
|
||||
import type { VerboseLevel } from "../thinking.js";
|
||||
@@ -222,6 +226,14 @@ export async function runAgentTurnWithFallback(params: {
|
||||
thinkLevel: params.followupRun.run.thinkLevel,
|
||||
verboseLevel: params.followupRun.run.verboseLevel,
|
||||
reasoningLevel: params.followupRun.run.reasoningLevel,
|
||||
toolResultFormat: (() => {
|
||||
const channel = resolveMessageChannel(
|
||||
params.sessionCtx.Surface,
|
||||
params.sessionCtx.Provider,
|
||||
);
|
||||
if (!channel) return "markdown";
|
||||
return isMarkdownCapableMessageChannel(channel) ? "markdown" : "plain";
|
||||
})(),
|
||||
bashElevated: params.followupRun.run.bashElevated,
|
||||
timeoutMs: params.followupRun.run.timeoutMs,
|
||||
runId,
|
||||
|
||||
@@ -36,6 +36,12 @@ describe("tool meta formatting", () => {
|
||||
expect(out).toContain("a→b");
|
||||
});
|
||||
|
||||
it("wraps aggregate meta in backticks when markdown is enabled", () => {
|
||||
vi.stubEnv("HOME", "/Users/test");
|
||||
const out = formatToolAggregate("fs", ["/Users/test/dir/a.txt"], { markdown: true });
|
||||
expect(out).toContain("`~/dir/a.txt`");
|
||||
});
|
||||
|
||||
it("formats prefixes with default labels", () => {
|
||||
vi.stubEnv("HOME", "/Users/test");
|
||||
expect(formatToolPrefix(undefined, undefined)).toBe("🧩 tool");
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
import { formatToolSummary, resolveToolDisplay } from "../agents/tool-display.js";
|
||||
import { shortenHomeInString, shortenHomePath } from "../utils.js";
|
||||
|
||||
type ToolAggregateOptions = {
|
||||
markdown?: boolean;
|
||||
};
|
||||
|
||||
export function shortenPath(p: string): string {
|
||||
return shortenHomePath(p);
|
||||
}
|
||||
@@ -14,7 +18,11 @@ export function shortenMeta(meta: string): string {
|
||||
return `${shortenHomeInString(base)}${rest}`;
|
||||
}
|
||||
|
||||
export function formatToolAggregate(toolName?: string, metas?: string[]): string {
|
||||
export function formatToolAggregate(
|
||||
toolName?: string,
|
||||
metas?: string[],
|
||||
options?: ToolAggregateOptions,
|
||||
): string {
|
||||
const filtered = (metas ?? []).filter(Boolean).map(shortenMeta);
|
||||
const display = resolveToolDisplay({ name: toolName });
|
||||
const prefix = `${display.emoji} ${display.label}`;
|
||||
@@ -51,7 +59,8 @@ export function formatToolAggregate(toolName?: string, metas?: string[]): string
|
||||
});
|
||||
|
||||
const allSegments = [...rawSegments, ...segments];
|
||||
return `${prefix}: ${allSegments.join("; ")}`;
|
||||
const meta = allSegments.join("; ");
|
||||
return `${prefix}: ${maybeWrapMarkdown(meta, options?.markdown)}`;
|
||||
}
|
||||
|
||||
export function formatToolPrefix(toolName?: string, meta?: string) {
|
||||
@@ -68,3 +77,9 @@ function isPathLike(value: string): boolean {
|
||||
if (value.includes("&&") || value.includes("||")) return false;
|
||||
return /^~?(\/[^\s]+)+$/.test(value);
|
||||
}
|
||||
|
||||
function maybeWrapMarkdown(value: string, markdown?: boolean): string {
|
||||
if (!markdown) return value;
|
||||
if (value.includes("`")) return value;
|
||||
return `\`${value}\``;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user