Skip to content

armgit / qm

Public Imported from GitHub
0

Multiplayer agent harness for work.

Simplify stopped-turn presentation (#1352)

Regan Bell852530bb7fad
diff --git a/docs/screenshots/stopped-after.png b/docs/screenshots/stopped-after.png
new file mode 100644
index 000000000..db99630ef
Binary files /dev/null and b/docs/screenshots/stopped-after.png differ
diff --git a/docs/screenshots/stopped-before.png b/docs/screenshots/stopped-before.png
new file mode 100644
index 000000000..dd4e9af7c
Binary files /dev/null and b/docs/screenshots/stopped-before.png differ
diff --git a/plugins/web-ui/src/chat.ts b/plugins/web-ui/src/chat.ts
index d40b65056..df13363dc 100644
--- a/plugins/web-ui/src/chat.ts
+++ b/plugins/web-ui/src/chat.ts
@@ -18,7 +18,6 @@ import { html, nothing, render, type TemplateResult } from "lit";
import { repeat } from "lit/directives/repeat.js";
import {
Activity,
- Ban,
Bot,
Brain,
Check,
@@ -1670,11 +1669,22 @@ export function createChatSurface(
const msg = message as AssistantMessage;
if ((msg as AssistantWork).retryableSend) return nothing;
const work = (msg as AssistantWork).work;
- const text = assistantDisplayText(messageText(msg)).trim();
+ const text = assistantDisplayText(messageText(msg), msg.stopReason).trim();
const hasText = Boolean(text);
const showWork =
shouldShowApprovalWork(msg, work, text) &&
shouldShowWork(work, isStreaming || msg.stopReason === "error" || msg.stopReason === "aborted" ? "" : text);
+ let workView = showWork
+ ? workBlock(
+ work,
+ isStreaming,
+ msg.stopReason === "aborted" || msg.stopReason === "error" ? "" : text,
+ (msg as AssistantWork).streamingBaseline ?? "",
+ )
+ : nothing;
+ if (msg.stopReason === "aborted") {
+ workView = work ? workBlock(work, false, "", "", true) : html`<div class="stopped-head">You stopped</div>`;
+ }
const deliveredFiles = (msg as AssistantWork).deliveredFiles;
const hasVisibleContent =
showWork ||
@@ -1685,10 +1695,8 @@ export function createChatSurface(
return html`
<article class="message-row assistant-row ${isStreaming ? "streaming" : ""}" data-index=${index}>
<div class="assistant-body">
- ${showWork ? workBlock(work, isStreaming, msg.stopReason === "aborted" || msg.stopReason === "error" ? "" : text, (msg as AssistantWork).streamingBaseline ?? "") : nothing}
- ${assistantContent(msg, isStreaming, showWork)} ${assistantFileList(deliveredFiles)}
+ ${workView} ${assistantContent(msg, isStreaming, showWork)} ${assistantFileList(deliveredFiles)}
${msg.stopReason === "error" && msg.errorMessage ? html`<div class="composer-error inline">${msg.errorMessage}</div>` : nothing}
- ${msg.stopReason === "aborted" ? html`<div class="stopped-note">${icon(Ban, 13)}<span>Stopped</span></div>` : nothing}
${isStreaming ? nothing : messageMeta(msg, index)}
</div>
</article>
@@ -1698,7 +1706,10 @@ export function createChatSurface(
}
function copyableText(message: AgentMessage): string {
- const raw = messageText(message);
+ const raw =
+ message.role === "assistant"
+ ? assistantDisplayText(messageText(message), (message as AssistantMessage).stopReason)
+ : messageText(message);
if (!isReadOnlySlackView()) return raw;
const role = (message as { role?: string }).role;
return role === "user" || role === "user-with-attachments" ? slackWireToPlain(raw) : stripSlackDirectives(raw);
@@ -1825,7 +1836,8 @@ export function createChatSurface(
return !chatState.agent && chatState.forkSession !== null && surfaceOf(chatState.forkSession) === "slack";
}
- function assistantDisplayText(text: string): string {
+ function assistantDisplayText(text: string, stopReason?: string): string {
+ if (stopReason === "aborted" && text.trim() === "(stopped)") return "";
return isReadOnlySlackView() ? stripSlackDirectives(text) : text;
}
@@ -1854,7 +1866,7 @@ export function createChatSurface(
const streamingFinal = isStreaming && phase?.phase === "final_answer";
const text = streamingFinal ? chunk.text.slice(phase.streamOffset) : chunk.text;
for (const [partIndex, part] of setupContent(
- assistantDisplayText(isStreaming && hasWork && !streamingFinal ? "" : text),
+ assistantDisplayText(isStreaming && hasWork && !streamingFinal ? "" : text, message.stopReason),
).entries()) {
if (part.type !== "text") {
if (!(message as AssistantWork).persisted) continue;
@@ -2343,7 +2355,13 @@ export function createChatSurface(
return workedLabel(work.status === "working" ? "Working" : "Worked", secs);
}
- function workBlock(work: WorkBlock, isStreaming: boolean, text: string, baseline: string): TemplateResult {
+ function workBlock(
+ work: WorkBlock,
+ isStreaming: boolean,
+ text: string,
+ baseline: string,
+ stopped = false,
+ ): TemplateResult {
const active =
isStreaming &&
currentTextPhase(work)?.phase !== "final_answer" &&
@@ -2357,12 +2375,18 @@ export function createChatSurface(
});
const tail = active ? streamingTextTail(text, work.activity) : "";
const stopping = active && runSlot.stopGeneration === runSlot.generation;
- const label = stopping ? "Stopping…" : workLabel(work);
- const fold =
+ let label = stopping ? "Stopping…" : workLabel(work);
+ if (stopped) label = `You stopped after ${goalElapsedLabel(0, workSeconds(work) * 1000)}`;
+ let fold =
timeline.length || tail.trim() || work.pendingApprovals?.length
- ? html`<details class="work work-fold work-${work.status}" ?open=${active || !!work.pendingApprovals?.length}>
- <summary class="work-head">${sheenLabel(label, active)}${icon(ChevronRight, 14)}</summary>
- <div class="work-divider"></div>
+ ? html`<details
+ class=${stopped ? "stopped-work" : `work work-fold work-${work.status}`}
+ ?open=${active || !!work.pendingApprovals?.length}
+ >
+ <summary class=${stopped ? "stopped-head" : "work-head"}>
+ ${sheenLabel(label, active)}${icon(ChevronRight, 14)}
+ </summary>
+ ${stopped ? nothing : html`<div class="work-divider"></div>`}
<div class="work-rows">
${repeat(
timeline,
@@ -2378,6 +2402,7 @@ export function createChatSurface(
</div>
</details>`
: nothing;
+ if (stopped && fold === nothing) fold = html`<div class="stopped-head">${label}</div>`;
return html`${fold}${replies.map((reply) => html`<div class="streaming-text" dir="auto">${markdown(reply)}</div>`)}`;
}
diff --git a/plugins/web-ui/src/core-bridge.ts b/plugins/web-ui/src/core-bridge.ts
index 49129cfce..313730856 100644
--- a/plugins/web-ui/src/core-bridge.ts
+++ b/plugins/web-ui/src/core-bridge.ts
@@ -1892,7 +1892,7 @@ export function entriesToMessages(entries: SessionEntry[], model?: Model<Api>):
stopReason: stopped ? "aborted" : "stop",
timestamp: at ?? pending[pending.length - 1]?.createdAt,
};
- if (pending.length) {
+ if (pending.length || (stopped && timing?.startedAt !== undefined)) {
const boundary = pending.findLast(
(entry) => typeof (entry.payload as { workStartedAt?: unknown } | null)?.workStartedAt === "number",
)?.payload as { workStartedAt: number } | undefined;
@@ -2014,7 +2014,8 @@ export function entriesToMessages(entries: SessionEntry[], model?: Model<Api>):
...(typeof payload?.workStartedAt === "number" ? { startedAt: payload.workStartedAt } : {}),
...(typeof payload?.workFinishedAt === "number" ? { finishedAt: payload.workFinishedAt } : {}),
};
- if (text || pending.length || heldPosts.size || payload?.stopped) {
+ const stopped = payload?.stopped === true || text.trim() === "(stopped)";
+ if (text || pending.length || heldPosts.size || stopped) {
spillHeldPosts();
if (posted && text) {
pending.push({
@@ -2024,9 +2025,9 @@ export function entriesToMessages(entries: SessionEntry[], model?: Model<Api>):
payload: { text, demoted: true },
createdAt: e.createdAt,
});
- flushWork("", e.createdAt, false, timing, payload?.stopped === true);
+ flushWork("", e.createdAt, false, timing, stopped);
} else {
- flushWork(text, e.createdAt, !posted, timing, payload?.stopped === true);
+ flushWork(text, e.createdAt, !posted, timing, stopped);
}
}
posted = false;
diff --git a/plugins/web-ui/src/shell.css b/plugins/web-ui/src/shell.css
index 11e1c134f..a1b84835a 100644
--- a/plugins/web-ui/src/shell.css
+++ b/plugins/web-ui/src/shell.css
@@ -4248,19 +4248,30 @@ qm-markdown .tok-in {
.composer-error.inline {
margin: 4px 0 0;
}
-.stopped-note {
- display: inline-flex;
+.stopped-head {
+ display: flex;
align-items: center;
- gap: 5px;
- margin-top: 6px;
- padding: 2px 9px;
- border-radius: 999px;
- background: var(--secondary);
+ gap: 6px;
+ padding: 8px 0 10px;
+ margin-bottom: 12px;
+ border-bottom: 1px solid var(--border);
color: var(--muted-foreground);
- font-size: 12px;
+ font-size: 14px;
+ line-height: 1.5;
+ list-style: none;
}
-.stopped-note .icon {
- opacity: 0.8;
+summary.stopped-head {
+ cursor: pointer;
+}
+summary.stopped-head::-webkit-details-marker {
+ display: none;
+}
+summary.stopped-head:focus-visible {
+ outline: 2px solid var(--ring);
+ outline-offset: 3px;
+}
+.stopped-work[open] > .stopped-head .icon {
+ transform: rotate(90deg);
}
.file-note {
display: inline-flex;
diff --git a/plugins/web-ui/test/stopped-history.test.ts b/plugins/web-ui/test/stopped-history.test.ts
new file mode 100644
index 000000000..bde5714a2
--- /dev/null
+++ b/plugins/web-ui/test/stopped-history.test.ts
@@ -0,0 +1,35 @@
+import assert from "node:assert/strict";
+import test from "node:test";
+import { entriesToMessages, type AssistantWork, type SessionEntry } from "../src/core-bridge.ts";
+import { workSeconds } from "../src/work-duration.ts";
+
+for (const text of ["", "Partial answer", "(stopped)"]) {
+ test(`stopped history preserves status, content and timing: ${JSON.stringify(text)}`, () => {
+ const entries: SessionEntry[] = [
+ {
+ type: "assistant",
+ payload: { text, stopped: true, workStartedAt: 1000, workFinishedAt: 4000 },
+ createdAt: 4000,
+ seq: 1,
+ },
+ ];
+ const messages = entriesToMessages(entries);
+ assert.equal(messages.length, 1);
+ const message = messages[0] as AssistantWork;
+ assert.equal(message.stopReason, "aborted");
+ assert.deepEqual(message.content, [{ type: "text", text }]);
+ assert.equal(workSeconds(message.work!), 3);
+ });
+}
+
+test("legacy stopped placeholders are recognized without treating ordinary replies as cancellation", () => {
+ for (const [text, reason] of [
+ ["(stopped)", "aborted"],
+ ["The process stopped.", "stop"],
+ ]) {
+ const message = entriesToMessages([
+ { type: "assistant", payload: { text }, createdAt: 1000, seq: 1 },
+ ])[0] as AssistantWork;
+ assert.equal(message.stopReason, reason);
+ }
+});
diff --git a/plugins/web-ui/test/work-fold-source.test.ts b/plugins/web-ui/test/work-fold-source.test.ts
index 65971642b..72c05571e 100644
--- a/plugins/web-ui/test/work-fold-source.test.ts
+++ b/plugins/web-ui/test/work-fold-source.test.ts
@@ -6,9 +6,9 @@ const chat = readFileSync(new URL("../src/chat.ts", import.meta.url), "utf8");
const css = readFileSync(new URL("../src/shell.css", import.meta.url), "utf8");
test("live and completed work share one chronological duration fold", () => {
- assert.match(chat, /<details class="work work-fold work-/);
+ assert.match(chat, /class=\$\{stopped \? "stopped-work" : `work work-fold work-\$\{work.status\}`\}/);
assert.match(chat, /messageWorkTimeline\(work, active \? "" : text\)/);
- assert.match(chat, /const label = stopping \? "Stopping…" : workLabel\(work\)/);
+ assert.match(chat, /let label = stopping \? "Stopping…" : workLabel\(work\)/);
assert.match(chat, /\?open=\$\{active \|\| !!work.pendingApprovals\?\.length\}/);
assert.doesNotMatch(chat, /function segmentSummaryLabel/);
});
@@ -72,3 +72,12 @@ test("activity previews use the row width before ellipsizing", () => {
assert.match(css, /\.tool-label \{[\s\S]{0,80}?flex: 1 1 auto;/);
assert.match(css, /\.tool-label \{[\s\S]{0,180}?text-overflow: ellipsis;/);
});
+
+test("stopped work shares posted reply rendering and shows one status without activity", () => {
+ assert.match(chat, /workBlock\(work, false, "", "", true\)/);
+ const block = chat.slice(chat.indexOf(" function workBlock("), chat.indexOf(" function approvalSummaryView("));
+ assert.match(block, /postSpeechText\(item.row\)/);
+ assert.match(block, /replies.map\(\(reply\) => html`<div class="streaming-text"/);
+ assert.match(block, /if \(stopped && fold === nothing\) fold = html`<div class="stopped-head">/);
+ assert.doesNotMatch(chat, /stopped-note|function stoppedWork/);
+});