This commit is contained in:
Dave Onkels 2026-01-30 06:56:28 -08:00 committed by GitHub
commit 1628773796
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 74 additions and 3 deletions

View File

@ -113,9 +113,9 @@ export function renderChatControls(state: AppViewState) {
aria-pressed=${showThinking}
title=${disableThinkingToggle
? "Disabled during onboarding"
: "Toggle assistant thinking/working output"}
: "Show/hide debug info (tool calls, heartbeats)"}
>
${icons.brain}
${icons.bug}
</button>
<button
class="btn btn--sm btn--icon ${focusActive ? "active" : ""}"

View File

@ -93,4 +93,44 @@ describe("chat view", () => {
expect(onNewSession).toHaveBeenCalledTimes(1);
expect(container.textContent).not.toContain("Stop");
});
it("filters debug messages when showThinking is false", () => {
const container = document.createElement("div");
render(
renderChat(
createProps({
showThinking: false,
messages: [
{ role: "user", content: "hello", timestamp: 1 },
{ role: "toolresult", content: "debug info", timestamp: 2 },
{ role: "assistant", content: "world", timestamp: 3 },
],
}),
),
container,
);
expect(container.textContent).toContain("hello");
expect(container.textContent).toContain("world");
expect(container.textContent).not.toContain("debug info");
});
it("shows debug messages when showThinking is true", () => {
const container = document.createElement("div");
render(
renderChat(
createProps({
showThinking: true,
messages: [
{ role: "user", content: "hello", timestamp: 1 },
{ role: "toolresult", content: "debug info", timestamp: 2 },
],
}),
),
container,
);
expect(container.textContent).toContain("hello");
expect(container.textContent).toContain("debug info");
});
});

View File

@ -434,7 +434,7 @@ function buildChatItems(props: ChatProps): Array<ChatItem | MessageGroup> {
const msg = history[i];
const normalized = normalizeMessage(msg);
if (!props.showThinking && normalized.role.toLowerCase() === "toolresult") {
if (!props.showThinking && isDebugMessage(msg)) {
continue;
}
@ -484,3 +484,34 @@ function messageKey(message: unknown, index: number): string {
if (timestamp != null) return `msg:${role}:${timestamp}:${index}`;
return `msg:${role}:${index}`;
}
function extractTextContent(m: Record<string, unknown>): string {
if (typeof m.content === "string") return m.content;
if (Array.isArray(m.content)) {
return m.content
.filter((c: unknown) => (c as Record<string, unknown>).type === "text")
.map((c: unknown) => (c as Record<string, string>).text ?? "")
.join(" ");
}
return "";
}
function isDebugMessage(message: unknown): boolean {
const m = message as Record<string, unknown>;
const role = typeof m.role === "string" ? m.role.toLowerCase() : "";
// Filter tool results
if (role === "toolresult" || role === "tool_result" || role === "tool") {
return true;
}
// Filter system debug messages (heartbeats, context compaction, etc.)
if (role === "system") {
const content = extractTextContent(m);
if (/heartbeat|scheduled|context (compacted|trimmed)/i.test(content)) {
return true;
}
}
return false;
}