Q15: show which messages each agent actually read

Runs record a context manifest once a model turn succeeds; the chat
marks each human message with the agents that read its current version.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
ZacharyZhang-NYandClaude Opus 5.5 committed 2026-10-08 04:21:57 -04:00
1 parent 592ce69219
commit 469f2f2c35
14 files changed
+144 -10

No files matched your search

+10 -3
View File
@@ -182,6 +182,13 @@ describe("chat wake context", () => {
expect(seenFollowUps[0]).toContain("Messages that arrived while you were working");
expect(seenFollowUps[0]).toContain("Stop — use Postgres instead.");
expect(seenFollowUps[0]).not.toContain("Use MySQL.");
const entry = (body: string) => {
const row = connection.db.prepare("select id, created_at from chat_messages where body_md = ?").get(body) as { id: string; created_at: string };
return { id: row.id, version: row.created_at };
};
const manifest = JSON.parse((connection.db.prepare("select context_json from task_runs where id = ?").get(wake.id) as { context_json: string }).context_json);
expect(manifest).toEqual({ threadId, history: [], fresh: [entry("Use MySQL.")], omittedCount: 0, midRun: [entry("Stop — use Postgres instead.")] });
expect(firstId).toBe(entry("Use MySQL.").id);
connection.close();
});
@@ -249,14 +256,14 @@ describe("chat wake context", () => {
const threadId = h.say("Old plan: launch in March.", null);
await h.runWake();
h.remove("Old plan: launch in March.");
h.say("Wrong number, ignore it: 4242.", threadId);
h.remove("Wrong number, ignore it: 4242.");
h.say("Wrong number, ignore it: QZX-WRONG.", threadId);
h.remove("Wrong number, ignore it: QZX-WRONG.");
h.say("What is the launch date now?", threadId);
await h.runWake();
const prompt = h.wakePrompts[1];
expect(prompt).toContain("What is the launch date now?");
expect(prompt).not.toContain("Old plan: launch in March.");
expect(prompt).not.toContain("4242");
expect(prompt).not.toContain("QZX-WRONG");
h.connection.close();
});
+1 -1
View File
@@ -24,7 +24,7 @@ describe("domain services", () => {
const connection = createConnection();
const rows = connection.db.prepare("select version from schema_migrations order by version asc").all() as Array<{ version: number }>;
expect(rows.map((row) => row.version)).toEqual([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60]);
expect(rows.map((row) => row.version)).toEqual([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61]);
connection.close();
});
+40
View File
@@ -0,0 +1,40 @@
import { describe, expect, test } from "vitest";
import { messageReaders } from "../../src/renderer/src/pages/chat/chat-helpers";
import type { AgentRecord, ChatMessageRecord, TaskRunRecord } from "../../src/shared/domain";
function run(agentId: string | null, contextJson: string | null): TaskRunRecord {
return {
id: `run_${Math.random()}`, orgId: "org", taskId: "tsk", agentId, providerId: null, providerRequestId: null,
executionContextId: null, serviceIdentityId: null, workspaceMountJson: "[]", secretScopeJson: "{}",
trigger: "chat_mention", state: "completed", createdAt: "", startedAt: null, completedAt: null, errorMessage: null, contextJson,
};
}
function message(id: string, createdAt: string, editedAt: string | null = null): ChatMessageRecord {
return { id, createdAt, editedAt } as ChatMessageRecord;
}
const agents = [{ id: "a1", name: "CEO" }, { id: "a2", name: "Dana" }] as AgentRecord[];
const entry = (id: string, version: string) => ({ id, version });
const manifest = (history: object[], fresh: object[], midRun: object[]) =>
JSON.stringify({ threadId: "t", history, fresh, omittedCount: 0, midRun });
describe("message readers", () => {
test("collects each agent once per message across history, fresh, and mid-run entries", () => {
const messages = [message("m1", "t1"), message("m2", "t2"), message("m3", "t3")];
const readers = messageReaders([
run("a1", manifest([entry("m1", "t1")], [entry("m2", "t2")], [entry("m3", "t3")])),
run("a1", manifest([entry("m2", "t2")], [], [])),
run("a2", manifest([], [entry("m2", "t2")], [])),
run("a2", null),
run(null, manifest([entry("m1", "t1")], [], [])),
], agents, messages);
expect(Object.fromEntries(readers)).toEqual({ m1: ["CEO"], m2: ["CEO", "Dana"], m3: ["CEO"] });
});
test("a message edited after it was read is unread until a run sees the new version", () => {
const messages = [message("m1", "t1", "t9")];
expect(messageReaders([run("a1", manifest([], [entry("m1", "t1")], []))], agents, messages).size).toBe(0);
expect(Object.fromEntries(messageReaders([run("a1", manifest([], [entry("m1", "t9")], []))], agents, messages))).toEqual({ m1: ["CEO"] });
});
});