Skip to content

armgit / qm

Public Imported from GitHub
0

Multiplayer agent harness for work.

Hide finish_silently from silent wake turns in the web transcript (#2395)

Regan Bell349308fa7190
diff --git a/plugins/web-ui/src/core-bridge.ts b/plugins/web-ui/src/core-bridge.ts
index 37c70e24a..655b349d1 100644
--- a/plugins/web-ui/src/core-bridge.ts
+++ b/plugins/web-ui/src/core-bridge.ts
@@ -2044,6 +2044,14 @@ export function appendConsumedSteers(messages: AgentMessage[], work: WorkBlock):
}
}
+const SILENCE_TOOLS = new Set(["finish_silently", "stay_silent"]);
+
+function deliveredSilence(a: ToolActivity): boolean {
+ if (a.type !== "tool_result") return false;
+ const p = a.payload as { tool?: string; silent?: boolean; ok?: boolean } | null;
+ return (p?.tool === "finish_silently" && p?.silent === true) || (p?.tool === "stay_silent" && p?.ok === true);
+}
+
function isFinishedReplyEntry(entry: SessionEntry): boolean {
if (entry.type !== "text") return false;
const step = (entry.payload as { step?: { stopReason?: unknown } } | null)?.step;
@@ -2058,6 +2066,7 @@ export function entriesToMessages(entries: SessionEntry[], model?: Model<Api>):
let deliveryFiles: DeliveredFile[] = [];
let posted = false;
let stoppedShown = false;
+ let hiddenPrompt = false;
const heldPosts = new Map<string, { text: string; activity: ToolActivity }>();
const spillHeldPosts = (): void => {
for (const held of heldPosts.values()) pending.push(held.activity);
@@ -2101,12 +2110,14 @@ export function entriesToMessages(entries: SessionEntry[], model?: Model<Api>):
): void => {
if (!text && !pending.length && !deliveryFiles.length && !stopped) return;
if (stopped) stoppedShown = true;
+ if (hiddenPrompt && !text && !stopped && pending.some(deliveredSilence)) {
+ pending = pending.filter((a) => !SILENCE_TOOLS.has((a.payload as { tool?: string } | null)?.tool ?? ""));
+ if (!pending.some((a) => a.type === "tool_call") && !deliveryFiles.length) {
+ pending = [];
+ return;
+ }
+ }
entrySeqs = [...entrySeqs, ...pending.map((entry) => entry.seq)];
- const deliveredSilence = (a: ToolActivity): boolean => {
- if (a.type !== "tool_result") return false;
- const p = a.payload as { tool?: string; silent?: boolean; ok?: boolean } | null;
- return (p?.tool === "finish_silently" && p?.silent === true) || (p?.tool === "stay_silent" && p?.ok === true);
- };
const lastText = pending.findLastIndex((a) => a.type === "text");
if (lastText >= 0) {
const segment = ((pending[lastText]!.payload as { text?: string } | null)?.text ?? "").trim();
@@ -2225,7 +2236,10 @@ export function entriesToMessages(entries: SessionEntry[], model?: Model<Api>):
continue;
}
if (e.type === "user") {
- if (!payload?.steered) stoppedShown = false;
+ if (!payload?.steered) {
+ stoppedShown = false;
+ hiddenPrompt = payload?.hidden === true;
+ }
if (payload?.hidden) continue;
if (!payload?.steered) {
posted = false;
diff --git a/plugins/web-ui/test/history.test.ts b/plugins/web-ui/test/history.test.ts
index 9bd65c0e2..442b37294 100644
--- a/plugins/web-ui/test/history.test.ts
+++ b/plugins/web-ui/test/history.test.ts
@@ -1198,29 +1198,89 @@ test("a turn that closed empty after narrating surfaces the last narration as th
);
});
-test("a delivered-silence turn (finish_silently → silent:true) stays collapsed — no promotion", () => {
+const wakeEntry = (seq: number, createdAt: number): SessionEntry => ({
+ type: "user",
+ payload: {
+ text: '<wake reason="monitor" surface="monitor" at="1970-01-01T00:00:00.000Z"><why>still running</why></wake>',
+ hidden: true,
+ },
+ createdAt,
+ seq,
+});
+
+const silentFinish = (seq: number, createdAt: number): SessionEntry[] => [
+ {
+ type: "tool_call",
+ payload: { tool: "finish_silently", reason: "nothing new" },
+ createdAt,
+ seq,
+ parentSeq: seq - 1,
+ },
+ {
+ type: "tool_result",
+ payload: { tool: "finish_silently", silent: true },
+ createdAt: createdAt + 1,
+ seq: seq + 1,
+ parentSeq: seq,
+ },
+];
+
+test("a wake that only finishes silently leaves nothing in the transcript", () => {
const entries: SessionEntry[] = [
- {
- type: "user",
- payload: {
- text: '<wake reason="monitor" surface="monitor" at="1970-01-01T00:00:00.000Z"><why>still running</why></wake>',
- hidden: true,
- },
- createdAt: 100,
- seq: 1,
- },
- { type: "text", payload: { text: "Heartbeat check." }, createdAt: 110, seq: 2, parentSeq: 1 },
- {
- type: "tool_call",
- payload: { tool: "finish_silently", reason: "nothing new" },
- createdAt: 120,
- seq: 3,
- parentSeq: 2,
- },
- { type: "tool_result", payload: { tool: "finish_silently", silent: true }, createdAt: 130, seq: 4, parentSeq: 3 },
- { type: "assistant", payload: { text: "" }, createdAt: 140, seq: 5 },
+ { type: "user", payload: { text: "watch the deploy" }, createdAt: 10, seq: 1 },
+ { type: "assistant", payload: { text: "Watching." }, createdAt: 20, seq: 2 },
+ wakeEntry(3, 100),
+ { type: "text", payload: { text: "Heartbeat check." }, createdAt: 110, seq: 4, parentSeq: 3 },
+ ...silentFinish(5, 120),
+ { type: "assistant", payload: { text: "" }, createdAt: 140, seq: 7 },
+ ];
+ const msgs = entriesToMessages(entries, MODEL);
+ assert.deepEqual(
+ msgs.map((m) => (m as { role: string }).role),
+ ["user", "assistant"],
+ );
+ assert.equal(((msgs[1] as AssistantWork).content[0] as { text: string }).text, "Watching.");
+});
+
+test("a silent wake keeps its real tool work but drops the finish_silently call", () => {
+ const entries: SessionEntry[] = [
+ wakeEntry(1, 100),
+ { type: "tool_call", payload: { tool: "background", action: "poll" }, createdAt: 110, seq: 2, parentSeq: 1 },
+ { type: "tool_result", payload: { tool: "background", action: "poll" }, createdAt: 115, seq: 3, parentSeq: 2 },
+ ...silentFinish(4, 120),
+ { type: "assistant", payload: { text: "" }, createdAt: 140, seq: 6 },
+ ];
+ const msgs = entriesToMessages(entries, MODEL);
+ assert.equal(msgs.length, 1);
+ const msg = msgs[0] as AssistantWork;
+ assert.equal((msg.content[0] as { text: string }).text, "", "intentional silence is not turned into a message");
+ assert.deepEqual(
+ msg.work?.activity.map((a) => (a.payload as { tool?: string }).tool),
+ ["background", "background"],
+ );
+});
+
+test("a wake that replies is unchanged", () => {
+ const entries: SessionEntry[] = [
+ wakeEntry(1, 100),
+ { type: "tool_call", payload: { tool: "background", action: "poll" }, createdAt: 110, seq: 2, parentSeq: 1 },
+ { type: "tool_result", payload: { tool: "background", action: "poll" }, createdAt: 115, seq: 3, parentSeq: 2 },
+ { type: "assistant", payload: { text: "Deploy finished." }, createdAt: 140, seq: 4 },
];
const msg = entriesToMessages(entries, MODEL)[0] as AssistantWork;
+ assert.equal((msg.content[0] as { text: string }).text, "Deploy finished.");
+ assert.equal(msg.work?.activity.length, 2);
+});
+
+test("a visible turn that finishes silently still shows the finish_silently call", () => {
+ const entries: SessionEntry[] = [
+ { type: "user", payload: { text: "no reply needed" }, createdAt: 100, seq: 1 },
+ { type: "text", payload: { text: "Nothing to add." }, createdAt: 110, seq: 2, parentSeq: 1 },
+ ...silentFinish(3, 120),
+ { type: "assistant", payload: { text: "" }, createdAt: 140, seq: 5 },
+ ];
+ const msgs = entriesToMessages(entries, MODEL);
+ const msg = msgs[msgs.length - 1] as AssistantWork;
assert.equal((msg.content[0] as { text: string }).text, "", "intentional silence is not turned into a message");
assert.deepEqual(
msg.work?.activity.map((a) => a.type),