89 lines · 6.8 KB · TypeScriptRaw
/** * A recording's summary by the person's own assistant (src/mcp/tools/recordings.ts; owner via the coordinator, * 23 Nov 2026: Cotton has no model of its own). Every recording, name and word is invented. */import { describe, expect, it } from "vitest";import { answer, http, personalObject, tool } from "./personal.ts";const RECORDINGS = ["meetings_meeting", "meetings_speaker", "meetings_line", "meetings_action"];type Doc = Record<string, unknown>;async function act(slug: string, credential: string, name: string, args: Doc): Promise<Doc> { const done = await http<Doc>(slug, "POST", "/v1/act", { act: name, args }, { authorization: `Bearer ${credential}` }); expect(done.status, JSON.stringify(done.body)).toBe(200); return done.body;}/** A recording with its words, as a phone that transcribed it leaves it. */async function recorded(slug: string, credential: string, take: string, started: string, words: [string, string][]): Promise<void> { await act(slug, credential, "create", { table: "meetings_meeting", id: take, data: { take, kind: "memo", source: "room", status: "ready", started_at: started, duration_ms: 64_000, lines: words.length, speakers: 2, languages: "en", transcribed_by: "phone:sherpa:test", title: `Walk ${take}` } }); await act(slug, credential, "create", { table: "meetings_speaker", id: `${take}-s1`, data: { meeting: take, label: "S1" } }); await act(slug, credential, "create", { table: "meetings_speaker", id: `${take}-s2`, data: { meeting: take, label: "S2", name: "Chitra Invented" } }); for (const [at, [who, text]] of words.entries()) { await act(slug, credential, "create", { table: "meetings_line", id: `${take}-l${at}`, data: { meeting: take, speaker: `${take}-${who}`, position: at, start_ms: at * 2_000, end_ms: at * 2_000 + 1_900, text, language: "en" } }); }}async function actions(slug: string, owner: string, meeting: string): Promise<Doc[]> { const listed = await answer<{ records: { id: string; data: Doc }[] }>(slug, owner, "list_records", { table: "meetings_action", where: { meeting }, limit: 50 }); return listed.records.map((r): Doc => ({ id: r.id, ...r.data })).sort((a, b) => Number(a.position) - Number(b.position));}/** RULE (owner via the coordinator, 23 Nov 2026): a recording's words are read by his own assistant, which writes the summary and the actions back onto it, laid out as his Mac's are; what he added to his to-dos stays. */describe("an assistant summarises a recording", () => { it("lists what waits, reads the words, writes the summary back, and keeps an action already in his to-dos", async () => { const slug = "recordings-summary"; const { credential, owner } = await personalObject(slug, { open: [...RECORDINGS, "todo"] }); await recorded(slug, credential, "r-old", "2026-11-20T09:00:00.000Z", [["s1", "Shall we walk by the river?"], ["s2", "Yes, on Saturday."]]); await recorded(slug, credential, "r-new", "2026-11-22T09:00:00.000Z", [["s1", "I will bring the flask."], ["s2", "I can book the boat by Friday."], ["s1", "Good."]]); await act(slug, credential, "create", { table: "meetings_meeting", id: "r-wait", data: { take: "r-wait", kind: "memo", status: "waiting", started_at: "2026-11-23T09:00:00.000Z", duration_ms: 1_000 } }); const waiting = await answer<{ recordings: Doc[]; more: boolean }>(slug, owner, "recordings_to_summarise", {}); expect(waiting.recordings.map((r) => r.id), "with words, newest first").toEqual(["r-new", "r-old"]); expect(waiting.recordings[0]).toMatchObject({ title: "Walk r-new", lines: 3, duration_ms: 64_000 }); const read = await answer<{ transcript: string; speakers: Doc[]; lines: Doc[] }>(slug, owner, "recording_read", { id: "r-new" }); expect(read.speakers).toEqual([{ label: "S1", name: null }, { label: "S2", name: "Chitra Invented" }]); expect(read.transcript).toBe("1 [0:00] S1: I will bring the flask.\n2 [0:02] Chitra Invented (S2): I can book the boat by Friday.\n3 [0:04] S1: Good."); const first = await answer<Doc>(slug, owner, "recording_summary_write", { id: "r-new", by: "Claude", points: ["They plan the river walk.", "Chitra books the boat."], actions: [{ words: "Bring the flask", who: "S1" }, { words: "Book the boat", who: "S2", due: "2026-11-27", due_said: "by Friday", at_ms: 2_000 }], }); expect(first).toMatchObject({ summary: "- They plan the river walk.\n- Chitra books the boat.", actions: "Bring the flask — S1\nBook the boat — Chitra Invented (S2), by Fri 27 Nov", made: 2, kept: 0 }); const meeting = await answer<{ recording: Doc }>(slug, owner, "recording_read", { id: "r-new" }); expect(meeting.recording).toMatchObject({ summary: "- They plan the river walk.\n- Chitra books the boat.", summarised_by: "Claude" }); const made = await actions(slug, owner, "r-new"); expect(made.map((a) => [a.words, a.who, a.speaker, a.made_by])).toEqual([["Bring the flask", "S1", "r-new-s1", "Claude"], ["Book the boat", "S2", "r-new-s2", "Claude"]]); expect((await answer<{ recordings: Doc[] }>(slug, owner, "recordings_to_summarise", {})).recordings.map((r) => r.id), "summarised, it waits no more").toEqual(["r-old"]); // He adds the boat to his to-dos; the summary is written again: the boat stays as it was, the flask is made anew. const todo = await act(slug, credential, "create", { table: "todo", data: { title: "Book the boat" } }); await act(slug, credential, "update", { table: "meetings_action", id: made[1]!.id, data: { todo: (todo.made as { id: string }).id } }); const again = await answer<Doc>(slug, owner, "recording_summary_write", { id: "r-new", by: "Claude", points: ["They plan the walk."], actions: [{ words: "Book the boat", who: "S2" }, { words: "Fill the flask", who: "S1" }] }); expect(again).toMatchObject({ made: 1, kept: 1 }); const now = await actions(slug, owner, "r-new"); expect(now.map((a) => a.words)).toEqual(["Book the boat", "Fill the flask"]); expect(now[0]!.id).toBe(made[1]!.id); expect(await refusalOf(slug, owner, "recording_summary_write", { id: "r-wait", points: ["Nothing."] })).toMatch(/no words yet/); expect(await refusalOf(slug, owner, "recording_summary_write", { id: "r-old", points: ["A walk."], by: "mac:llama:x" })).toMatch(/assistant's own name/); }, 180_000); it("reads sealed recordings only inside Your Claude's grant", async () => { const slug = "recordings-sealed"; const { owner } = await personalObject(slug, { windows: true }); const got = await tool(slug, owner, "recordings_to_summarise", {}); expect(JSON.stringify(got)).toMatch(/request_unlock|window/); expect(JSON.stringify(got)).not.toMatch(/"recordings":\[/); });});async function refusalOf(slug: string, token: string, name: string, args: Doc): Promise<string> { const got = await tool(slug, token, name, args); return JSON.stringify(got);}