feat(queue): queue a message with everything the composer had attached

Queueing captured only the text and files. Context chips (inline comments,
terminal selections, browser annotations, PR comments and checks, quotes,
linked issue/PR/Linear references, pending synthetic parts) stayed in the
composer and only left with the next manual send, so a queued message the
server delivered went out without them and the chips rode an unrelated
message later.

A queued message now carries what the composer would have sent: the text
with its agent mention stripped and file mentions resolved into
attachments, the attached context as structured parts, and the skill
instruction derived from the text. The server delivers those parts in the
composer's order, the VS Code auto-send does the same, and editing a queued
message puts the chips and linked references back. A failed queue restores
the composer completely. Snapshots and broadcasts omit the captured
context like attachment payloads; a take returns it.

Claude-Session: https://claude.ai/code/session_01HB9wdLQoZX2vfyDjwv6Rso
This commit is contained in:
Bohdan Triapitsyn
2026-09-04 22:56:27 +03:00
parent ce5c0c068e
commit 34bf631157
17 changed files with 823 additions and 285 deletions
@@ -49,11 +49,14 @@ const serverItem = (id: string, content: string, extra: Partial<ServerItem> = {}
id,
createdAt: 1,
content,
text: content,
attachments: [],
sendConfig: { providerID: "p", modelID: "m" },
...extra,
})
const issueMetadata = { openchamberContext: { kind: "github-issue" as const, number: 3, title: "Bug", url: "https://x/issues/3" } }
const session = (items: ServerItem[], sendingId: string | null = null): ServerSession => ({
sessionId: "session-1",
directory: "/repo",
@@ -90,7 +93,7 @@ describe("server-owned message queue", () => {
test("hydrate uploads messages queued by an older build before reading the server", async () => {
useMessageQueueStore.setState({
queuedMessages: {
[key]: [{ id: "local-1", content: "from before", createdAt: 1, sendConfig: { providerID: "p", modelID: "m" } }],
[key]: [{ id: "local-1", content: "from before", text: "from before", createdAt: 1, sendConfig: { providerID: "p", modelID: "m" } }],
},
})
respond = (call) => (call.method === "POST"
@@ -101,7 +104,7 @@ describe("server-owned message queue", () => {
expect(calls[0]).toEqual({
method: "POST",
path: "/api/message-queue/sessions/session-1/items",
body: { directory: "/repo", item: { content: "from before", text: "from before", attachments: [], sendConfig: { providerID: "p", modelID: "m" } } },
body: { directory: "/repo", item: { content: "from before", text: "from before", attachments: [], context: [], sendConfig: { providerID: "p", modelID: "m" } } },
})
expect(calls[1]?.path).toBe("/api/message-queue")
expect(useMessageQueueStore.getState().queuedMessages[key]?.map((m) => m.id)).toEqual(["q1"])
@@ -138,6 +141,7 @@ describe("server-owned message queue", () => {
text: "hi",
agentMention: "reviewer",
attachments: [{ id: "att-1", filename: "note.txt", mimeType: "text/plain", size: 2, source: "local", dataUrl: attachment.dataUrl }],
context: [],
sendConfig: { providerID: "p", modelID: "m", agent: "build" },
},
},
@@ -145,6 +149,36 @@ describe("server-owned message queue", () => {
expect(useMessageQueueStore.getState().queuedMessages[key]?.map((m) => m.id)).toEqual(["srv-1"])
})
test("addToQueue hands the captured context to the server, and a take brings it back", async () => {
const context = [
{ kind: "context" as const, text: "issue body", metadata: issueMetadata },
{ kind: "synthetic" as const, text: "conflict payload" },
]
respond = () => json({ revision: 6, session: session([serverItem("srv-1", "with context")]) })
await useMessageQueueStore.getState().addToQueue(target, {
content: "with context",
context,
sendConfig: { providerID: "p", modelID: "m" },
})
expect(calls[0]?.body.item.context).toEqual(context)
// The projection carries no context; the server strips payloads from snapshots.
expect(useMessageQueueStore.getState().queuedMessages[key]?.[0]?.context).toBe(undefined)
respond = () => json({ revision: 7, session: session([]), item: serverItem("srv-1", "with context", { context }) })
const [taken] = await useMessageQueueStore.getState().takeForSend(target, "srv-1")
expect(taken?.context).toEqual(context)
expect(taken?.text).toBe("with context")
})
test("a server item with malformed context is rejected at the boundary", async () => {
respond = () => new Response(JSON.stringify({
revision: 8,
session: session([]),
item: { ...serverItem("srv-1", "x"), context: [{ kind: "context", text: "x", metadata: { openchamberContext: { kind: "nope" } } }] },
}), { status: 200 })
await expect(useMessageQueueStore.getState().takeForSend(target, "srv-1")).rejects.toThrow()
})
test("addToQueue rolls the optimistic entry back when the server refuses", async () => {
respond = () => new Response("nope", { status: 500 })
await expect(useMessageQueueStore.getState().addToQueue(target, {
@@ -200,7 +234,7 @@ describe("server-owned message queue", () => {
})
test("removeFromQueue and clearQueue update locally and tell the server", async () => {
useMessageQueueStore.setState({ queuedMessages: { [key]: [{ id: "q1", content: "a", createdAt: 1 }, { id: "q2", content: "b", createdAt: 2 }] } })
useMessageQueueStore.setState({ queuedMessages: { [key]: [{ id: "q1", content: "a", text: "a", createdAt: 1 }, { id: "q2", content: "b", text: "b", createdAt: 2 }] } })
respond = () => json({ revision: 10, session: session([serverItem("q2", "b")]) })
useMessageQueueStore.getState().removeFromQueue(target, "q1")
expect(useMessageQueueStore.getState().queuedMessages[key]?.map((m) => m.id)).toEqual(["q2"])
@@ -216,7 +250,7 @@ describe("server-owned message queue", () => {
})
test("reorderQueue sends the complete new order", async () => {
useMessageQueueStore.setState({ queuedMessages: { [key]: [{ id: "q1", content: "a", createdAt: 1 }, { id: "q2", content: "b", createdAt: 2 }] } })
useMessageQueueStore.setState({ queuedMessages: { [key]: [{ id: "q1", content: "a", text: "a", createdAt: 1 }, { id: "q2", content: "b", text: "b", createdAt: 2 }] } })
respond = () => json({ revision: 12, session: session([serverItem("q2", "b"), serverItem("q1", "a")]) })
useMessageQueueStore.getState().reorderQueue(target, "q2", "q1")
await Promise.resolve()