Multiplayer agent harness for work.
Keep conversation status out of Slack turns (#1754)
Regan Bell632d3f427a09
diff --git a/src/api/agent-api-catalog.ts b/src/api/agent-api-catalog.tsindex 83936c101..f4c36fda3 100644--- a/src/api/agent-api-catalog.ts+++ b/src/api/agent-api-catalog.ts@@ -22,6 +22,9 @@ interface AgentApiFamily {const onPath = (m: string, p: string) => (method: string, pathname: string) => method === m && pathname === p;+const CONVERSATION_UPDATE =+ "update one of the asking person's conversations — body {archived?, pinned?, title?, color?}; archive/unarchive, pin/unpin, rename (null title clears), or set the sidebar color (#rrggbb; null clears). These are per-person.";+const FAMILIES: AgentApiFamily[] = [{match: (method, path) =>@@ -398,12 +401,6 @@ const FAMILIES: AgentApiFamily[] = [summary:"list the asking person's own conversations (id, title, status, archived, pinned, lastActivityAt) — the same list their web sidebar shows",},- {- method: "POST",- path: "/v1/conversations/:id",- summary:- "update one of the asking person's conversations — body {archived?, pinned?, title?, color?, status?}; archive/unarchive, pin/unpin, rename (null title clears), or set the sidebar color (#rrggbb; null clears). Title, archive, pin, and color are per-person. Status is shared by everyone in the session: {emoji: one Unicode emoji, text: 1–200 characters}, or null to clear. Use it for verified milestones, e.g. ✅ PR merged or 🚀 Live in production, and replace it as work progresses. 404 for a conversation not on their list",- },{method: "GET",path: "/v1/conversations/:id?tailTurns=20",@@ -424,6 +421,28 @@ const FAMILIES: AgentApiFamily[] = [},],},+ {+ match: () => false,+ when: (v) => v.claims.surface === "slack",+ routes: [+ {+ method: "POST",+ path: "/v1/conversations/:id",+ summary: `${CONVERSATION_UPDATE} 404 for a conversation not on their list`,+ },+ ],+ },+ {+ match: () => false,+ when: (v) => v.claims.surface !== "slack",+ routes: [+ {+ method: "POST",+ path: "/v1/conversations/:id",+ summary: `${CONVERSATION_UPDATE} Body status sets the web UI sidebar status shared by everyone in the session: {emoji: one Unicode emoji, text: 1–200 characters}, or null to clear. Use it for verified milestones, e.g. ✅ PR merged or 🚀 Live in production, and replace it as work progresses. 404 for a conversation not on their list`,+ },+ ],+ },{match: (m, p) => m === "GET" && (p === "/v1/files" || /^\/v1\/files\/[^/]+\/content$/.test(p)),guidance:diff --git a/src/api/routes/surface.ts b/src/api/routes/surface.tsindex 6dac2a282..6c28dd583 100644--- a/src/api/routes/surface.ts+++ b/src/api/routes/surface.ts@@ -525,6 +525,12 @@ async function patchAgentConversation(ctx: ApiCtx): Promise<void> {patch.color = typeof b.color === "string" ? b.color.toLowerCase() : null;}if ("status" in b) {+ if (capability.surface === "slack") {+ return sendJson(res, 403, {+ error: "forbidden",+ message: "conversation status is a web UI feature and is not available on Slack turns",+ });+ }if (!isSessionStatus(b.status)) {return sendJson(res, 400, {error: "bad_request",diff --git a/src/auth/capability-token.ts b/src/auth/capability-token.tsindex e4b308a6a..2b4c9256e 100644--- a/src/auth/capability-token.ts+++ b/src/auth/capability-token.ts@@ -70,6 +70,7 @@ export interface CapabilityClaims {triggered?: boolean;grants?: string[];threadRef?: string;+ surface?: string;exp: number;}diff --git a/src/core/orchestrator.ts b/src/core/orchestrator.tsindex 1ff2f1bb8..cd881bba4 100644--- a/src/core/orchestrator.ts+++ b/src/core/orchestrator.ts@@ -1673,6 +1673,7 @@ export function createOrchestrator(deps: OrchestratorDeps): Orchestrator {const memoryClaim = memoryAccess? { ...memoryAccess, read: baseRecallScopes, ...(orgMemoryWrite ? { orgWrite: orgMemoryWrite } : {}) }: undefined;+ const turnSurface = input.surface === "web" ? "web" : (session.surface ?? input.surface);controlClaims = {...scopeAttestation,aud: CONTROL_PLANE_AUD,@@ -1706,6 +1707,7 @@ export function createOrchestrator(deps: OrchestratorDeps): Orchestrator {runAttempt: input.attempt,runLeaseToken: input.runLeaseToken,threadRef: conversation.threadRef,+ ...(turnSurface ? { surface: turnSurface } : {}),};connectorEnv.AGENT_API_TOKEN = await mintCapabilityToken(controlClaims,diff --git a/test/agent-api-discovery.test.ts b/test/agent-api-discovery.test.tsindex 4184d6ca2..e17391e54 100644--- a/test/agent-api-discovery.test.ts+++ b/test/agent-api-discovery.test.ts@@ -272,3 +272,24 @@ test("disabled swarms are absent from discovery and reject direct API calls", asawait close();}});++test("conversation status is advertised on web turns and omitted on Slack turns", async () => {+ const s = await start();+ try {+ const update = (body: any) =>+ body.endpoints.filter((e: any) => e.path === "/v1/conversations/:id" && e.method === "POST");+ const cap = (surface: string) =>+ mintCapabilityToken(+ { actorId: "U1", scopeId: scopeId("personal", "U1"), exp: Date.now() + CAPABILITY_TTL_MS, surface },+ SECRET,+ );+ const web = update((await listApis(s.base, await cap("web"))).body);+ assert.equal(web.length, 1);+ assert.match(web[0].summary, /sidebar status/);+ const slack = update((await listApis(s.base, await cap("slack"))).body);+ assert.equal(slack.length, 1);+ assert.doesNotMatch(JSON.stringify(slack), /status/i);+ } finally {+ await s.close();+ }+});diff --git a/test/agent-conversations-route.test.ts b/test/agent-conversations-route.test.tsindex e9fae8102..b5bc69524 100644--- a/test/agent-conversations-route.test.ts+++ b/test/agent-conversations-route.test.ts@@ -114,6 +114,27 @@ describe("agent conversations self-API", async () => {assert.equal((await post(`/v1/conversations/${mineId}`, { status: null })).status, 401);});+ it("refuses conversation status from Slack turns while other updates still apply", async () => {+ const slack = await mintCapabilityToken(+ {+ actorId: "U1",+ scopeId: scopeId("personal", "U1"),+ aud: CONTROL_PLANE_AUD,+ exp: Date.now() + CAPABILITY_TTL_MS,+ liveActor: true,+ surface: "slack",+ },+ SECRET,+ );+ const before = (await built.app.getSessionForViewer(mineId, "U1"))?.session.status ?? null;+ const refused = await post(`/v1/conversations/${mineId}`, { status: { emoji: "👍", text: "Cleared" } }, slack);+ assert.equal(refused.status, 403);+ assert.deepEqual((await built.app.getSessionForViewer(mineId, "U1"))?.session.status ?? null, before);+ const renamed = await post(`/v1/conversations/${mineId}`, { title: "Launch plan" }, slack);+ assert.equal(renamed.status, 200);+ assert.equal(((await renamed.json()) as { conversation: { title: string } }).conversation.title, "Launch plan");+ });+it("spawns a fresh conversation with only the seed text", async () => {const token = await capFor("U1");const res = await post(diff --git a/test/orchestrator.test.ts b/test/orchestrator.test.tsindex 363210060..bb7cdd9db 100644--- a/test/orchestrator.test.ts+++ b/test/orchestrator.test.ts@@ -1124,6 +1124,18 @@ test("turn timezone rides the prompt and control-plane capability token", asyncassert.equal(res.status, "ok");const claims = await verifyCapabilityToken(captured!.env!.AGENT_API_TOKEN!, TEST_CAPABILITY_SECRET);assert.equal(claims!.timezone, "America/New_York");+ assert.equal(claims!.surface, "test");++ const slackThread = { kind: "dm" as const, threadRef: "dm:U1:slack-wake" };+ await app.turn(dm("!run echo slack", { surface: "slack", conversation: slackThread }));+ captured = undefined;+ await app.turn(dm("!run echo wake", { surface: "monitor", conversation: slackThread }));+ const wake = await verifyCapabilityToken(captured!.env!.AGENT_API_TOKEN!, TEST_CAPABILITY_SECRET);+ assert.equal(wake!.surface, "slack", "a wake in a Slack thread keeps the conversation's surface");+ captured = undefined;+ await app.turn(dm("!run echo web", { surface: "web", conversation: slackThread }));+ const web = await verifyCapabilityToken(captured!.env!.AGENT_API_TOKEN!, TEST_CAPABILITY_SECRET);+ assert.equal(web!.surface, "web", "a live web UI turn is a web turn even in a Slack-labelled conversation");const prompt = await app.turn(dm("!sysprompt", { conversation: { kind: "dm", threadRef: "dm:U1:tz-prompt" }, timezone: "America/New_York" }),