diff --git a/CHANGELOG.md b/CHANGELOG.md index 22b86b00..7aa84d47 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,7 @@ assigned at release. ## Unreleased -- Fixed: MCP repository-filtered session summaries apply the first 200 characters of a repo-only filter in the session directory before pagination, while still accepting a 512-character repo value and verifying the full returned repository URL. This requires a sessions read API whose session directory list applies `projectContains` as a case-insensitive substring of project ID, catalog project key or recorded repository URL (directory migration `20261105034000` or later). Exact verification can still produce a short or empty page with a cursor. Relay agent listings now link an exact roster agent ID to its already-synced Desktop native session when the agent has no validated Relaycast session declaration. No migration. +- Fixed: MCP repository-filtered session summaries apply the first 200 characters of a repo-only filter in the session directory before pagination, while still accepting a 512-character repo value and verifying the full returned repository URL. This requires a sessions read API whose session directory list applies `projectContains` as a case-insensitive substring of project ID, catalog project key or recorded repository URL (directory migration `20261105034000` or later). Exact verification can still produce a short or empty page with a cursor. Relay agent listings now link an exact roster agent ID to its already-synced Desktop native session when the agent has no validated Relaycast session declaration. The optional session join is failure-open: the roster still returns a null session ID and attribution with `session_unavailable_reason` set to `enrichment_failed` or `ambiguous_sync`; an independently recorded metadata session kind is preserved. No migration. - Changed: MCP `list_amp_threads` now returns `{ threads, truncated }` instead of a bare thread array. Clients that parse the old array must read the `threads` field; `truncated` reports whether Amp returned more than the first 100 threads. - Changed: MCP `list_relay_agents` now returns the first at most 100 matching agents in relay order and adds `total_matching` and `truncated`; it previously returned the whole matching roster. - Changed: MCP `get_session_summary` now returns `summary: { status: "unsupported" }` as a normal result when the selected backend records that status; it previously returned a tool error. diff --git a/src/mcp/relay-messaging.ts b/src/mcp/relay-messaging.ts index 270e51d9..f8064798 100644 --- a/src/mcp/relay-messaging.ts +++ b/src/mcp/relay-messaging.ts @@ -55,7 +55,7 @@ export function registerRelayMessaging(server: McpServer, context: McpContext): }; server.registerTool("list_relay_agents", { - description: "List the first matching agents in relay order across every teammate in your current workspace's relay, with exact machine addresses, presence, descriptions and owners. The page defaults to 100 agents and cannot exceed 100; total_matching and truncated disclose omitted matches, so narrow the filters when truncated. Ownership metadata describes the roster; it does not grant permission to act as an agent.", + description: "List the first matching agents in relay order across every teammate in your current workspace's relay, with exact machine addresses, presence, descriptions and owners. The page defaults to 100 agents and cannot exceed 100; total_matching and truncated disclose omitted matches, so narrow the filters when truncated. A null session with session_unavailable_reason means optional Desktop session enrichment failed or was ambiguous; the roster remains available. Ownership metadata describes the roster; it does not grant permission to act as an agent.", inputSchema: { person: z.string().trim().min(1).max(200).optional().describe("me, a teammate's user ID, or display name"), status: z.enum(["live", "offline", "all"]).default("live"), query: z.string().trim().max(200).optional(), limit: z.number().int().min(1).max(100).default(100).describe("Maximum matching agents returned from the start of relay order. Use person/query/status filters to narrow a truncated result."), diff --git a/src/mcp/relay-participants.ts b/src/mcp/relay-participants.ts index 0689f9a2..72a5f955 100644 --- a/src/mcp/relay-participants.ts +++ b/src/mcp/relay-participants.ts @@ -738,11 +738,15 @@ function createRelayService(context: McpContext) { const syncedSessionKinds = new Set(["codex", "grok", "pi", "opencode", "claude", "copilot", "cursor"]); const syncedSessionId = /^[A-Za-z0-9][A-Za-z0-9._:-]{0,199}$/; + type SyncedDesktopSessions = { + sessions: Map; + ambiguous: Set; + }; async function syncedDesktopSessions(agents: readonly RosterAgent[]) { const targets = agents.map(agent => relayAgentOwnerTarget(agent, Boolean(gate))); const candidates = new Map(targets.map((target, index) => [`${target.lookupId}\0${target.name}`, agents[index]!])); const ids = [...new Set(targets.map(target => target.lookupId))]; - if (!ids.length) return new Map(); + if (!ids.length) return { sessions: new Map(), ambiguous: new Set() } satisfies SyncedDesktopSessions; const rows = await executor.query<{ agent_name: string; agent_remote_id: string; native_session_kind: string; native_session_id: string }>( `SELECT agent_name, agent_remote_id, native_session_kind, native_session_id FROM desktop_relay_identities @@ -753,11 +757,13 @@ function createRelayService(context: McpContext) { ); const sessions = new Map(); const matched = new Set(); + const ambiguous = new Set(); for (const row of rows.rows) { const agent = candidates.get(`${row.agent_remote_id}\0${row.agent_name}`); if (!agent) continue; if (matched.has(agent.id)) { sessions.delete(agent.id); + ambiguous.add(agent.id); continue; } matched.add(agent.id); @@ -766,7 +772,7 @@ function createRelayService(context: McpContext) { sessions.set(agent.id, { sessionId: row.native_session_id, sessionKind: kind }); } } - return sessions; + return { sessions, ambiguous }; } async function roster(status: "live" | "all" | "offline", people: readonly McpMember[], includeStale = false, dir: Directory = directory()) { @@ -774,17 +780,22 @@ function createRelayService(context: McpContext) { const [owners, synced] = await Promise.all([ loadRelayAgentOwners(database, workspaceId, relayWorkspaceId, listed, people, Boolean(gate)) .catch(error => { ownerEnrichmentFailed("list_relay_agents", error); return undefined; }), - syncedDesktopSessions(listed).catch(error => { + syncedDesktopSessions(listed).then(result => ({ ...result, failed: false as const })).catch(error => { sessionEnrichmentFailed(error); - return new Map(); + return { sessions: new Map(), + ambiguous: new Set(), failed: true as const }; }), ]); return listed .map(agent => { const row = rosterAgent(agent, people, userId, workspaceId, owners?.get(agent.id)); - const session = row.session_attribution ? null : synced.get(agent.id); + const session = row.session_attribution ? null : synced.sessions.get(agent.id); + const unavailableReason = row.session_attribution || session ? null + : synced.failed ? "enrichment_failed" as const + : synced.ambiguous.has(agent.id) ? "ambiguous_sync" as const : null; return { ...row, ...(session ? { session_id: session.sessionId, session_kind: session.sessionKind, session_attribution: "synced" as const } : {}), + session_unavailable_reason: unavailableReason, ...cardSummary(agent.metadata, agent) }; }) .filter(agent => status === "all" || (status === "live" ? agent.online : !agent.online)); diff --git a/test/mcp.test.ts b/test/mcp.test.ts index 22cea1f3..d23cf8de 100644 --- a/test/mcp.test.ts +++ b/test/mcp.test.ts @@ -900,16 +900,19 @@ test("list_relay_agents links synced Desktop sessions and keeps validated declar const client = await relayClient(t, env); const agents = structured(await client.callTool({ name: "list_relay_agents", arguments: { status: "all" } })).agents; const syncedRow = agents.find((agent: any) => agent.name === synced.name); - assert.deepEqual([syncedRow.session_id, syncedRow.session_kind, syncedRow.session_attribution], - ["ses_ABCD1234", "opencode", "synced"]); + assert.deepEqual([syncedRow.session_id, syncedRow.session_kind, syncedRow.session_attribution, + syncedRow.session_unavailable_reason], ["ses_ABCD1234", "opencode", "synced", null]); const declaredRow = agents.find((agent: any) => agent.name === declared.name); - assert.deepEqual([declaredRow.session_id, declaredRow.session_kind, declaredRow.session_attribution], - ["declared-session-id", "claude", "declared"]); + assert.deepEqual([declaredRow.session_id, declaredRow.session_kind, declaredRow.session_attribution, + declaredRow.session_unavailable_reason], ["declared-session-id", "claude", "declared", null]); }); test("list_relay_agents session enrichment fails open and refuses ambiguous Desktop rows", async (t) => { const env = await setup(t); - const peer = env.relay.world.addAgent("session-fallback", { source: "relay-desktop" }); + const peer = env.relay.world.addAgent("session-fallback", { source: "relay-desktop", session_kind: "claude" }); + const declared = env.relay.world.addAgent("session-declared-fallback", { + source: "relay-desktop", session_id: "declared-session-id", session_kind: "claude", injectable: "true", + }); const client = await relayClient(t, env); const originalQuery = env.database.query.bind(env.database); let mode: "reject" | "duplicate" = "reject"; @@ -929,7 +932,11 @@ test("list_relay_agents session enrichment fails open and refuses ambiguous Desk const unavailable = structured(await client.callTool({ name: "list_relay_agents", arguments: { status: "all" } })); const unavailableRow = unavailable.agents.find((agent: any) => agent.name === peer.name); - assert.deepEqual([unavailableRow.session_id, unavailableRow.session_attribution], [null, null]); + assert.deepEqual([unavailableRow.session_id, unavailableRow.session_kind, unavailableRow.session_attribution, + unavailableRow.session_unavailable_reason], [null, "claude", null, "enrichment_failed"]); + const declaredRow = unavailable.agents.find((agent: any) => agent.name === declared.name); + assert.deepEqual([declaredRow.session_id, declaredRow.session_kind, declaredRow.session_attribution, + declaredRow.session_unavailable_reason], ["declared-session-id", "claude", "declared", null]); assert.deepEqual(warnings, [["[selfhost-mcp] session enrichment failed", { operation: "list_relay_agents", error: "TypeError" }]]); assert.doesNotMatch(JSON.stringify(warnings), /private session query detail/); @@ -937,7 +944,8 @@ test("list_relay_agents session enrichment fails open and refuses ambiguous Desk mode = "duplicate"; const ambiguous = structured(await client.callTool({ name: "list_relay_agents", arguments: { status: "all" } })); const ambiguousRow = ambiguous.agents.find((agent: any) => agent.name === peer.name); - assert.deepEqual([ambiguousRow.session_id, ambiguousRow.session_attribution], [null, null]); + assert.deepEqual([ambiguousRow.session_id, ambiguousRow.session_kind, ambiguousRow.session_attribution, + ambiguousRow.session_unavailable_reason], [null, "claude", null, "ambiguous_sync"]); }); test("agent card owner enrichment fails open when its journal or membership read fails", async (t) => {