Skip to content

armgit / qm

Public Imported from GitHub
0

Multiplayer agent harness for work.

web-ui: show steers in the transcript as soon as they're sent (#2422)

Regan Bell1d90f3be5562
diff --git a/plugins/web-ui/src/chat.ts b/plugins/web-ui/src/chat.ts
index b4cd50031..1988d1465 100644
--- a/plugins/web-ui/src/chat.ts
+++ b/plugins/web-ui/src/chat.ts
@@ -1663,7 +1663,7 @@ export function createChatSurface(
content = assistantSidebar({
context: ctx.inbox.context(),
messages: html`${pinnedStrip()} ${inheritedHeader()} ${chatState.earlierCount > 0 ? earlierNotice() : nothing}
- ${messageContent}
+ ${messageContent} ${waitingSteerRows(agent)}
${showStateError(messages, agent.state.errorMessage) ? html`<div class="composer-error inline">${agent.state.errorMessage}</div>` : nothing}`,
status: liveWorkStatus(agent),
busy: agent.state.isStreaming,
@@ -1706,7 +1706,7 @@ export function createChatSurface(
${pinnedStrip()}
<div class="message-stack ${emptyChat ? "empty-stack" : ""}">
${showWelcome ? welcomeGreeting(!messages.length) : nothing} ${inheritedHeader()}
- ${chatState.earlierCount > 0 ? earlierNotice() : nothing} ${messageContent}
+ ${chatState.earlierCount > 0 ? earlierNotice() : nothing} ${messageContent} ${waitingSteerRows(agent)}
${glanceTier ? nothing : liveWorkStatus(agent)}
${emptyChat && !isNewUser && !editingApp && !showWelcome ? html`<h1 class="chat-cta">${chatCta()}</h1>` : nothing}
${ctx.pane ? suggestions : nothing}
@@ -3101,6 +3101,24 @@ export function createChatSurface(
</div>`;
}
+ function waitingSteerRows(agent: Agent): TemplateResult[] {
+ return ctx.composer.waitingSteers(agent).map(
+ (q) =>
+ html`<div class="inline-steer waiting-steer" aria-busy="true">
+ ${chatMessage(
+ {
+ role: "user",
+ content: q.text || (q.hasAttachments ? "(files)" : ""),
+ steered: true,
+ } as unknown as AgentMessage,
+ -1,
+ false,
+ true,
+ )}
+ </div>`,
+ );
+ }
+
function renderTimelineItem(item: TimelineItem, work: WorkBlock): TemplateResult {
const status = work.status;
const stale = work.stale === true;
diff --git a/plugins/web-ui/src/composer.ts b/plugins/web-ui/src/composer.ts
index 477145a13..e39e67106 100644
--- a/plugins/web-ui/src/composer.ts
+++ b/plugins/web-ui/src/composer.ts
@@ -827,11 +827,10 @@ export function createComposerSurface(ctx: ConvCtx, options: ComposerOptions = {
function queuedStrip(agent: Agent): TemplateResult | typeof nothing {
const threadRef = ctx.chat.state.threadRef;
- const steering = steeringRunsFor(threadRef, agent);
const queued = queuedRunsFor(threadRef).filter((q) => !pendingSteers.has(q.runId));
if (queuedEdit?.threadRef === ctx.chat.state.threadRef && !queued.some((q) => q.runId === queuedEdit?.runId))
queued.push({ runId: queuedEdit.runId, text: queuedEdit.original });
- if (!queued.length && !steering.length) return nothing;
+ if (!queued.length) return nothing;
const steerable = canSteer(agent);
const steerTip = (): string => {
if (steerable) return "Steer the running task with this instead of waiting";
@@ -839,16 +838,6 @@ export function createComposerSurface(ctx: ConvCtx, options: ComposerOptions = {
};
return html`
<div class="queued-strip" role="list" aria-label="Queued messages">
- ${steering.map(
- (q) => html`
- <div class="queued-chip queued-steering" role="listitem" aria-busy="true">
- <span class="queued-tag">Steering</span>
- <span class="queued-text" dir="auto" ${tip(q.text || "Files, no text")}
- >${q.text || (q.hasAttachments ? "(files)" : "")}</span
- >
- </div>
- `,
- )}
${queued.map((q) =>
queuedEdit?.runId === q.runId && queuedEdit.threadRef === ctx.chat.state.threadRef
? html` <div class="queued-chip queued-editing" role="listitem">
@@ -2064,6 +2053,7 @@ export function createComposerSurface(ctx: ConvCtx, options: ComposerOptions = {
composerForm,
composerApprovalPanel,
queuedStrip,
+ waitingSteers: (agent: Agent) => steeringRunsFor(ctx.chat.state.threadRef, agent),
queuedRunsFor,
setQueuedRuns,
resetComposer,
diff --git a/plugins/web-ui/src/conv-types.ts b/plugins/web-ui/src/conv-types.ts
index b707dcc56..9d020b999 100644
--- a/plugins/web-ui/src/conv-types.ts
+++ b/plugins/web-ui/src/conv-types.ts
@@ -138,6 +138,7 @@ export interface ComposerSurface {
state: ComposerState;
composerForm(agent: Agent, header?: TemplateResult | typeof nothing): TemplateResult;
queuedStrip(agent: Agent): TemplateResult | typeof import("lit").nothing;
+ waitingSteers(agent: Agent): QueuedRun[];
queuedRunsFor(threadRef: string | null): QueuedRun[];
setQueuedRuns(threadRef: string, runs: QueuedRun[]): void;
resetComposer(): void;
diff --git a/plugins/web-ui/test/activity-folding.test.ts b/plugins/web-ui/test/activity-folding.test.ts
index 03bb04f7f..16ab469ad 100644
--- a/plugins/web-ui/test/activity-folding.test.ts
+++ b/plugins/web-ui/test/activity-folding.test.ts
@@ -146,3 +146,43 @@ test("stopping a steered run preserves earlier singleton tools and labels only i
await h.close();
}
});
+
+test("a steer the model has not read shows once in the transcript, then once inside the work", async () => {
+ const entries = [
+ { seq: 0, type: "user", createdAt: 0, payload: { text: "Original request" } },
+ { seq: 1, type: "tool_call", createdAt: 1000, payload: { tool: "execute", callId: "a", command: "echo a" } },
+ { seq: 2, type: "tool_result", createdAt: 2000, payload: { tool: "execute", callId: "a", code: 0 } },
+ ];
+ const h = await harness({ path: `/s/${SESSION.id}`, listSessions: [SESSION], entries });
+ try {
+ h.releaseSessions();
+ await h.boot();
+ await h.sessionsReady();
+ const conv = h.visibleConversation();
+ let waiting = [{ runId: "q1", text: "Use the smaller sample" }];
+ conv.composer.waitingSteers = () => waiting;
+ conv.drawActiveChat();
+ const row = document.querySelector(".message-stack > .waiting-steer")!;
+ assert.ok(row);
+ assert.equal(document.querySelectorAll(".inline-steer").length, 1);
+ assert.ok(row.querySelector(".steered-row .user-bubble"));
+ assert.equal(
+ row.querySelector<HTMLElement & { content: string }>("qm-markdown")?.content,
+ "Use the smaller sample",
+ );
+ assert.equal(document.querySelector(".queued-chip"), null);
+ waiting = [];
+ conv.state.agent!.state.messages.push({
+ role: "user",
+ content: "Use the smaller sample",
+ steered: true,
+ entrySeq: 3,
+ timestamp: 3000,
+ } as never);
+ conv.drawActiveChat();
+ assert.equal(document.querySelectorAll(".waiting-steer").length, 0);
+ assert.equal(document.querySelectorAll(".message-stack > .steered-row").length, 0);
+ } finally {
+ await h.close();
+ }
+});
diff --git a/plugins/web-ui/test/always-steer.test.ts b/plugins/web-ui/test/always-steer.test.ts
index 21461d107..fa2803c08 100644
--- a/plugins/web-ui/test/always-steer.test.ts
+++ b/plugins/web-ui/test/always-steer.test.ts
@@ -154,7 +154,11 @@ test("a mid-run send with the steer preference steers at once and queues only wh
assert.equal(turns.at(-1), "second");
assert.deepEqual(signalled, [`q${turnId}`]);
assert.deepEqual(composer!.queuedRunsFor(threadRef), []);
- assert.deepEqual(chips(), ["Steering"]);
+ assert.deepEqual(chips(), []);
+ assert.deepEqual(
+ composer!.waitingSteers(agent).map((q) => q.text),
+ ["second"],
+ );
assert.equal(seenTags.has("Queued"), false);
reset();
});
diff --git a/plugins/web-ui/test/pending-steer-chip.test.ts b/plugins/web-ui/test/pending-steer-chip.test.ts
index 67495abb8..4a54de081 100644
--- a/plugins/web-ui/test/pending-steer-chip.test.ts
+++ b/plugins/web-ui/test/pending-steer-chip.test.ts
@@ -5,7 +5,7 @@ import { JSDOM } from "jsdom";
import { createServer } from "vite";
import type { ComposerSurface, ConvCtx } from "../src/conv-types.ts";
-test("a steered queued message stays visible as Steering until model intake or the run ends", async (t) => {
+test("a steered queued message shows in the transcript as waiting until model intake or the run ends", async (t) => {
const dom = new JSDOM('<!doctype html><div id="app"></div><div id="composer"></div>', {
url: "http://localhost/",
pretendToBeVisual: true,
@@ -91,11 +91,7 @@ test("a steered queued message stays visible as Steering until model intake or t
} as unknown as ConvCtx;
composer = createComposerSurface(ctx);
ctx.composer = composer!;
- const chips = () =>
- [...host.querySelectorAll(".queued-chip")].map((chip) => ({
- tag: chip.querySelector(".queued-tag")?.textContent?.trim(),
- text: chip.querySelector(".queued-text")?.textContent?.trim(),
- }));
+ const waiting = () => composer!.waitingSteers(agent).map((q) => q.text);
const steer = async (runId: string): Promise<void> => {
composer!.setQueuedRuns(threadRef, [{ runId, text: "same text" }]);
draw();
@@ -114,43 +110,41 @@ test("a steered queued message stays visible as Steering until model intake or t
});
};
- await t.test("accepting a steer keeps the chip and fabricates no transcript message", async () => {
+ await t.test("accepting a steer leaves the queue strip and fabricates no transcript entry", async () => {
await steer("q1");
assert.deepEqual(composer!.queuedRunsFor(threadRef), []);
- assert.deepEqual(chips(), [{ tag: "Steering", text: "same text" }]);
+ assert.deepEqual(waiting(), ["same text"]);
+ assert.equal(host.querySelector(".queued-chip"), null);
assert.equal(agentState.messages.length, 0);
});
await t.test("repeated text settles only the steer whose intake ts arrived", async () => {
await steer("q2");
- assert.deepEqual(chips(), [
- { tag: "Steering", text: "same text" },
- { tag: "Steering", text: "same text" },
- ]);
+ assert.deepEqual(waiting(), ["same text", "same text"]);
intake("q2", 4);
draw();
- assert.deepEqual(chips(), [{ tag: "Steering", text: "same text" }]);
+ assert.deepEqual(waiting(), ["same text"]);
intake("q1", 5);
draw();
- assert.deepEqual(chips(), []);
+ assert.deepEqual(waiting(), []);
});
- await t.test("an unrelated steered message with the same text does not settle the chip", async () => {
+ await t.test("an unrelated steered message with the same text does not settle the waiting steer", async () => {
await steer("q3");
agentState.messages.push({ role: "user", content: "same text", steered: true, entrySeq: 6, ts: "other" });
draw();
- assert.deepEqual(chips(), [{ tag: "Steering", text: "same text" }]);
+ assert.deepEqual(waiting(), ["same text"]);
});
- await t.test("the chip goes when the run ends without intake", async () => {
+ await t.test("the waiting steer goes when the run ends without intake", async () => {
agentState.isStreaming = false;
live = false;
draw();
- assert.deepEqual(chips(), []);
+ assert.deepEqual(waiting(), []);
agentState.isStreaming = true;
live = true;
draw();
- assert.deepEqual(chips(), []);
+ assert.deepEqual(waiting(), []);
});
} finally {
composer?.dispose?.();