Multiplayer agent harness for work.
Fix missing latest message in inbox conversation details (#1003)
Regan Bellf189da581b00
diff --git a/docs/screenshots/inbox-latest-message.png b/docs/screenshots/inbox-latest-message.pngnew file mode 100644index 000000000..8db67f635Binary files /dev/null and b/docs/screenshots/inbox-latest-message.png differdiff --git a/plugins/web-ui/src/draft-review.ts b/plugins/web-ui/src/draft-review.tsindex 3102ef715..31d63af04 100644--- a/plugins/web-ui/src/draft-review.ts+++ b/plugins/web-ui/src/draft-review.ts@@ -15,7 +15,6 @@ import {persistDraft,refreshInbox,selectInboxView,- slackTextTpl,type InboxItem,} from "./inbox";import { openSessionInto, refreshSessions, sessionsReady, sessionsState } from "./sessions";@@ -251,10 +250,6 @@ function detailTpl(surface: ReviewSurface, item: InboxItem | null): TemplateResu<span class="rv-detail-title">${gmail ? item.title : (item.slack?.channelLabel ?? item.title)}</span><span class="rv-detail-from">${item.from}${item.fromDetail ? ` · ${item.fromDetail}` : ""}</span></div>- <div class="rv-orig">- <div class="rv-orig-head">${item.from} · ${relTime(item.receivedAt)}</div>- <div class="rv-orig-text">${slackTextTpl(item, item.snippet)}</div>- </div>${contextTpl(item)} ${item.status === "open" ? draftEditorTpl(item) : handledNoteTpl(item)}${item.status === "open" ? steerTpl(surface, item) : nothing}`;diff --git a/plugins/web-ui/src/inbox.ts b/plugins/web-ui/src/inbox.tsindex 00a438a2d..22e7db0fb 100644--- a/plugins/web-ui/src/inbox.ts+++ b/plugins/web-ui/src/inbox.ts@@ -728,10 +728,12 @@ function itemImagesTpl(item: InboxItem, urls: string[] | undefined, ctxIndex: nu}export function contextTpl(item: InboxItem): TemplateResult | typeof nothing {- const rows = item.context ?? [];- if (!rows.length) return nothing;+ const rows = [+ ...(item.context ?? []).map((message, index) => ({ ...message, imageIndex: index })),+ { author: item.from, at: item.receivedAt, text: item.snippet, images: item.images, imageIndex: -1 },+ ];return html`<div class="inbox-context">- ${rows.map((m, i) => {+ ${rows.map((m) => {const name = participantName(m.author) || m.author;return html`<div class="inbox-context-msg">@@ -744,7 +746,7 @@ export function contextTpl(item: InboxItem): TemplateResult | typeof nothing {${m.at ? html`<span class="inbox-context-at">${relTime(m.at)}</span>` : nothing}</div><div class="inbox-context-text">${slackTextTpl(item, m.text)}</div>- ${itemImagesTpl(item, m.images, i)}+ ${itemImagesTpl(item, m.images, m.imageIndex)}</div></div>`;@@ -1024,8 +1026,7 @@ function itemRowTpl(surface: InboxSurface, item: InboxItem): TemplateResult {${expanded? html`<div class="inbox-item-detail">- ${contextTpl(item)} ${itemImagesTpl(item, item.images, -1)}- ${handled ? handledNoteTpl(item) : draftEditorTpl(item)}+ ${contextTpl(item)} ${handled ? handledNoteTpl(item) : draftEditorTpl(item)}</div>`: nothing}@@ -1189,8 +1190,7 @@ function itemPageTpl(item: InboxItem): TemplateResult {</div><div class="inbox-surface inbox-item-surface"><div class="inbox-scroll inbox-item-thread">- ${contextTpl(item)} ${itemImagesTpl(item, item.images, -1)}- ${handled ? handledNoteTpl(item) : draftEditorTpl(item, { chat: false })}+ ${contextTpl(item)} ${handled ? handledNoteTpl(item) : draftEditorTpl(item, { chat: false })}</div></div><aside class="inbox-item-aside">${chatTpl(item)}</aside>diff --git a/plugins/web-ui/src/shell.css b/plugins/web-ui/src/shell.cssindex a56145f30..ea6e12560 100644--- a/plugins/web-ui/src/shell.css+++ b/plugins/web-ui/src/shell.css@@ -8093,9 +8093,6 @@ h3.ambient-field-label {flex: none;}}-.inbox-item-surface .inbox-context {- max-height: none;-}.inbox-item-surface .inbox-draft-body {min-height: 200px;}@@ -8111,10 +8108,9 @@ h3.ambient-field-label {}.inbox-context {display: flex;+ flex: none;flex-direction: column;gap: 14px;- max-height: 240px;- overflow-y: auto;}.inbox-context-msg {display: flex;@@ -8735,23 +8731,6 @@ h3.ambient-field-label {font-size: 11.5px;color: var(--muted-foreground);}-.rv-orig {- border: 1px solid var(--border);- border-radius: 8px;- padding: 8px 11px;- margin-bottom: 10px;- background: color-mix(in srgb, var(--foreground) 2%, transparent);-}-.rv-orig-head {- font-size: 11px;- color: var(--muted-foreground);- margin-bottom: 3px;-}-.rv-orig-text {- font-size: 13px;- line-height: 1.5;- white-space: pre-wrap;-}.draft-review-surface .inbox-draft {margin-top: 10px;}diff --git a/plugins/web-ui/test/inbox-context.test.ts b/plugins/web-ui/test/inbox-context.test.tsnew file mode 100644index 000000000..777a68f9c--- /dev/null+++ b/plugins/web-ui/test/inbox-context.test.ts@@ -0,0 +1,72 @@+import assert from "node:assert/strict";+import { test } from "node:test";+import { JSDOM } from "jsdom";+import { createServer } from "vite";++test("conversation details include the waiting message after prior context with correctly routed attachments", async () => {+ const dom = new JSDOM('<!doctype html><div id="app"></div><main id="main"></main>', {+ url: "http://localhost/web-ui/",+ });+ Object.defineProperty(dom.window, "matchMedia", {+ value: () => ({ matches: false, addEventListener() {}, removeEventListener() {} }),+ });+ for (const key of ["window", "document", "location", "history", "localStorage", "navigator", "HTMLElement", "Node"])+ Object.defineProperty(globalThis, key, {+ configurable: true,+ value: key === "window" ? dom.window : dom.window[key as keyof typeof dom.window],+ });+ const vite = await createServer({ server: { middlewareMode: true, hmr: false }, appType: "custom" });+ try {+ await vite.ssrLoadModule("/src/shell.ts");+ const { contextTpl, toInboxItem } = await vite.ssrLoadModule("/src/inbox.ts");+ const { render } = await vite.ssrLoadModule("lit");+ const host = dom.window.document.getElementById("main")!;+ for (const source of ["slack", "gmail"]) {+ for (const context of [+ undefined,+ [],+ [{ author: "Alex", at: 1000, text: "Earlier message", images: ["https://example.com/old.png"] }],+ ]) {+ const item = toInboxItem({+ id: "item-1",+ loopId: "loop-1",+ dedupeKey: "conversation-1",+ state: "held",+ source,+ sourcePayload: {+ title: "Conversation",+ from: "Sam",+ snippet: "Latest waiting message",+ context,+ images: ["https://example.com/latest.png"],+ },+ sourceAt: 2000,+ updatedAt: 3000,+ thread: [],+ });+ render(contextTpl(item), host);+ assert.deepEqual(+ [...host.querySelectorAll(".inbox-context-text")].map((el) => el.textContent?.trim()),+ context?.length ? ["Earlier message", "Latest waiting message"] : ["Latest waiting message"],+ );+ const messages = host.querySelectorAll(".inbox-context-msg");+ const latest = messages[messages.length - 1]!;+ assert.equal(latest.querySelector(".inbox-context-author")?.textContent, "Sam");+ assert.ok(latest.querySelector(".inbox-context-at"));+ assert.equal(+ latest.querySelector("img")?.getAttribute("src"),+ "/api/loops/loop-1/items/item-1/image?ctx=-1&i=0",+ );+ if (context?.length)+ assert.equal(+ messages[0]!.querySelector("img")?.getAttribute("src"),+ "/api/loops/loop-1/items/item-1/image?ctx=0&i=0",+ );+ assert.equal(item.context, context);+ }+ }+ } finally {+ await vite.close();+ dom.window.close();+ }+});diff --git a/plugins/web-ui/test/inbox-source.test.ts b/plugins/web-ui/test/inbox-source.test.tsindex 42e8c167f..7bd4d3c23 100644--- a/plugins/web-ui/test/inbox-source.test.ts+++ b/plugins/web-ui/test/inbox-source.test.ts@@ -213,3 +213,9 @@ test("suggested draft actions yield to typed instructions without reflow", () =>assert.match(css, /\.inbox-chat-composer\.has-text \.inbox-chat-suggest \{\s*visibility: hidden;/);assert.doesNotMatch(inbox, /inbox-draft-actions|function sendLabel/);});++test("conversation messages use the containing view's scroll instead of clipping the latest message", () => {+ const context = css.match(/\.inbox-context \{[^}]*\}/)?.[0] ?? "";+ assert.match(context, /flex: none;/);+ assert.doesNotMatch(context, /max-height:|overflow-y:/);+});