Skip to content

Commit 1c411dc

Browse files
committed
Fix dashboard history projection and approval followups
1 parent 6a2ec62 commit 1c411dc

4 files changed

Lines changed: 93 additions & 5 deletions

File tree

‎src/agents/bash-tools.exec-approval-followup.test.ts‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ vi.mock("../infra/outbound/message.js", () => ({
1616
import fs from "node:fs";
1717
import os from "node:os";
1818
import path from "node:path";
19-
import { writeSessionStoreForTest } from "../config/sessions/test-helpers.js";
2019
import { clearSessionStoreCacheForTest } from "../config/sessions/store.js";
20+
import { writeSessionStoreForTest } from "../config/sessions/test-helpers.js";
2121
import { sendMessage } from "../infra/outbound/message.js";
2222
import {
2323
buildExecApprovalFollowupPrompt,
@@ -142,6 +142,20 @@ describe("exec approval followup", () => {
142142
expect(sendMessage).not.toHaveBeenCalled();
143143
});
144144

145+
it("suppresses prompt persistence for session-resume followups", async () => {
146+
await sendExecApprovalFollowup({
147+
approvalId: "req-hidden-prompt",
148+
sessionKey: "agent:main:main",
149+
resultText: "Exec finished (gateway id=req-hidden-prompt, code 0)\nok",
150+
});
151+
152+
expectGatewayAgentFollowup({
153+
sessionKey: "agent:main:main",
154+
suppressPromptPersistence: true,
155+
});
156+
expect(sendMessage).not.toHaveBeenCalled();
157+
});
158+
145159
it("forwards the approval-time session id so the gateway can drop stale followups", async () => {
146160
await sendExecApprovalFollowup({
147161
approvalId: "req-pin-59349",

‎src/agents/bash-tools.exec-approval-followup.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,7 @@ function buildAgentFollowupArgs(params: {
268268
return {
269269
sessionKey: params.sessionKey,
270270
message: buildExecApprovalFollowupPrompt(params.resultText),
271+
suppressPromptPersistence: true,
271272
deliver: deliveryTarget.deliver,
272273
...(deliveryTarget.deliver ? { bestEffortDeliver: true as const } : {}),
273274
channel: deliveryTarget.deliver ? deliveryTarget.channel : fallbackChannel,

‎src/gateway/chat-display-projection.ts‎

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1595,6 +1595,44 @@ function projectSessionsSendInterSessionMessages(
15951595
return changed ? projected : messages;
15961596
}
15971597

1598+
function isRecentChatDisplayToolCallOnlyAssistant(message: Record<string, unknown>): boolean {
1599+
if (message.role !== "assistant" || !Array.isArray(message.content)) {
1600+
return false;
1601+
}
1602+
let hasToolCallBlock = false;
1603+
for (const block of message.content) {
1604+
const entry = readRecord(block);
1605+
if (!entry) {
1606+
return false;
1607+
}
1608+
const type = normalizeToolHistoryType(entry.type);
1609+
if (type === "toolcall" || type === "tooluse") {
1610+
hasToolCallBlock = true;
1611+
continue;
1612+
}
1613+
if (type === "text") {
1614+
if (typeof entry.text === "string" && entry.text.trim()) {
1615+
return false;
1616+
}
1617+
continue;
1618+
}
1619+
if (type === "thinking") {
1620+
continue;
1621+
}
1622+
return false;
1623+
}
1624+
return hasToolCallBlock;
1625+
}
1626+
1627+
function filterRecentChatDisplayMessages(
1628+
messages: Array<Record<string, unknown>>,
1629+
): Array<Record<string, unknown>> {
1630+
if (!messages.some(isRecentChatDisplayToolCallOnlyAssistant)) {
1631+
return messages;
1632+
}
1633+
return messages.filter((message) => !isRecentChatDisplayToolCallOnlyAssistant(message));
1634+
}
1635+
15981636
export function projectChatDisplayMessages(
15991637
messages: unknown[],
16001638
options?: { maxChars?: number; stripEnvelope?: boolean },
@@ -1630,10 +1668,12 @@ export function projectRecentChatDisplayMessages(
16301668
messages: unknown[],
16311669
options?: { maxChars?: number; maxMessages?: number; stripEnvelope?: boolean },
16321670
): Array<Record<string, unknown>> {
1633-
return limitChatDisplayMessages(
1634-
projectChatDisplayMessages(messages, options),
1635-
options?.maxMessages,
1636-
);
1671+
const projected = projectChatDisplayMessages(messages, options);
1672+
const recentDisplayMessages =
1673+
typeof options?.maxMessages === "number"
1674+
? filterRecentChatDisplayMessages(projected)
1675+
: projected;
1676+
return limitChatDisplayMessages(recentDisplayMessages, options?.maxMessages);
16371677
}
16381678

16391679
export function projectChatDisplayMessage(

‎src/gateway/server-methods/server-methods.test.ts‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1282,6 +1282,39 @@ describe("projectRecentChatDisplayMessages", () => {
12821282
});
12831283
});
12841284

1285+
it("does not let toolCall-only assistant messages hide recent user context", () => {
1286+
const result = projectRecentChatDisplayMessages(
1287+
[
1288+
{
1289+
role: "user",
1290+
content: [{ type: "text", text: "please keep my last prompt visible" }],
1291+
timestamp: 1,
1292+
},
1293+
{
1294+
role: "assistant",
1295+
content: [
1296+
{
1297+
type: "toolCall",
1298+
id: "call-read-only",
1299+
name: "read",
1300+
arguments: { path: "AGENTS.md" },
1301+
},
1302+
],
1303+
timestamp: 2,
1304+
},
1305+
],
1306+
{ maxMessages: 1 },
1307+
);
1308+
1309+
expect(result).toEqual([
1310+
{
1311+
role: "user",
1312+
content: [{ type: "text", text: "please keep my last prompt visible" }],
1313+
timestamp: 1,
1314+
},
1315+
]);
1316+
});
1317+
12851318
it("keeps pure commentary assistant messages hidden", () => {
12861319
const result = projectRecentChatDisplayMessages([
12871320
{

0 commit comments

Comments
 (0)