Skip to content

Commit 43ef3a1

Browse files
t3dotggclaude
andcommitted
feat(server): agents list snoozed threads across all projects in one call
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 1abf368 commit 43ef3a1

5 files changed

Lines changed: 109 additions & 28 deletions

File tree

‎apps/server/src/mcp/OrchestratorMcpService.test.ts‎

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2694,6 +2694,71 @@ describe("OrchestratorMcpService thread lookup", () => {
26942694
);
26952695
});
26962696

2697+
describe("OrchestratorMcpService thread list", () => {
2698+
const client: McpInvocationScope = {
2699+
environmentId: EnvironmentId.make("environment:thread-list"),
2700+
requestNamespace: "client:thread-list",
2701+
thread: undefined,
2702+
client: { sessionId: "thread-list", label: "Claude Code", access: "full-access" },
2703+
capabilities: new Set(["orchestration"]),
2704+
issuedAt: 1,
2705+
};
2706+
const shell = (id: string, projectId: string, snoozed: boolean) => ({
2707+
...liveThreadShell(ThreadId.make(id)),
2708+
projectId: ProjectId.make(projectId),
2709+
status: "completed" as const,
2710+
snoozedUntil: snoozed ? DateTime.makeUnsafe("2099-01-01T00:00:00Z") : null,
2711+
});
2712+
const shells = [
2713+
shell("thread:a-snoozed", "project:a", true),
2714+
shell("thread:a-awake", "project:a", false),
2715+
shell("thread:b-snoozed", "project:b", true),
2716+
];
2717+
const service = layerOrchestratorService.pipe(
2718+
Layer.provide(
2719+
Layer.mergeAll(
2720+
NodeServices.layer,
2721+
Layer.mock(ThreadManagementService.ThreadManagementService)({
2722+
listProjectThreads: (input) =>
2723+
Effect.succeed(
2724+
shells.filter(
2725+
(thread) => input.projectId === undefined || thread.projectId === input.projectId,
2726+
),
2727+
),
2728+
}),
2729+
ServerSettings.layerTest(),
2730+
Layer.mock(ProviderRegistry.ProviderRegistry)({ getProviders: Effect.succeed([]) }),
2731+
Layer.mock(ProviderAdapterRegistry.ProviderAdapterRegistryV2)({
2732+
list: () => Effect.succeed([]),
2733+
}),
2734+
Layer.mock(ProjectService.ProjectService)({}),
2735+
Layer.mock(SecretRequests.SecretRequests)({}),
2736+
Layer.mock(RemoteDelegation.RemoteDelegation)({}),
2737+
Layer.mock(ScheduledTaskService.ScheduledTaskService)({}),
2738+
),
2739+
),
2740+
);
2741+
2742+
it.effect("lists snoozed threads across every project with allProjects", () =>
2743+
Effect.gen(function* () {
2744+
const mcp = yield* OrchestratorMcpService.OrchestratorMcpService;
2745+
const listed = yield* mcp.listThreads(client, {
2746+
allProjects: true,
2747+
projectId: ProjectId.make("project:a"),
2748+
snoozed: true,
2749+
});
2750+
assert.equal(listed.projectId, null);
2751+
assert.deepStrictEqual(
2752+
listed.threads.map((thread) => [thread.threadId, thread.projectId]),
2753+
[
2754+
["thread:a-snoozed", "project:a"],
2755+
["thread:b-snoozed", "project:b"],
2756+
],
2757+
);
2758+
}).pipe(Effect.provide(service)),
2759+
);
2760+
});
2761+
26972762
describe("OrchestratorMcpService thread stop", () => {
26982763
const driver = ProviderDriverKind.make("codex");
26992764
const instanceId = ProviderInstanceId.make("codex");

‎apps/server/src/mcp/OrchestratorMcpService.ts‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -755,6 +755,7 @@ function listItemFromShell(
755755
): OrchestratorMcpThreadListItem {
756756
return {
757757
threadId: shell.id,
758+
projectId: shell.projectId,
758759
title: shell.title,
759760
link: formatThreadLink({ environmentId, threadId: shell.id }),
760761
createdBy: shell.createdBy,
@@ -2764,10 +2765,12 @@ const make = Effect.gen(function* () {
27642765
),
27652766
listThreads: Effect.fn("OrchestratorMcpService.listThreads")(function* (scope, input) {
27662767
const { parent } = yield* loadCaller(scope);
2767-
const projectId = yield* resolveProjectTarget(parent, input.projectId);
2768+
const projectId = input.allProjects
2769+
? null
2770+
: yield* resolveProjectTarget(parent, input.projectId);
27682771
const projectThreads = yield* threadManagement
27692772
.listProjectThreads({
2770-
projectId,
2773+
projectId: projectId ?? undefined,
27712774
includeSubagents: input.includeSubagents !== false,
27722775
})
27732776
.pipe(

‎apps/server/src/mcp/toolkits/orchestrator/tools.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ const CreateThreadsTool = Tool.make("create_threads", {
222222

223223
const ThreadListTool = Tool.make("t3_thread_list", {
224224
description:
225-
"List threads in a project, newest first. Omit `projectId` for yours. Filter by status, title, settled, or snoozed. Page with the cursor.",
225+
"List threads in a project, newest first. Omit `projectId` for yours, or pass `allProjects`. Filter by status, title, settled, or snoozed. Page with the cursor.",
226226
parameters: OrchestratorMcpThreadListInput,
227227
success: OrchestratorMcpThreadListResult,
228228
failure: OrchestratorMcpFailure,

‎apps/server/src/orchestration-v2/ThreadManagementService.ts‎

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -279,12 +279,14 @@ export class ThreadManagementProjectionLoadError extends Schema.TaggedError<Thre
279279
export class ThreadManagementProjectThreadsListError extends Schema.TaggedError<ThreadManagementProjectThreadsListError>()(
280280
"ThreadManagementProjectThreadsListError",
281281
{
282-
projectId: ProjectId,
282+
projectId: Schema.optional(ProjectId),
283283
cause: Schema.Defect(),
284284
},
285285
) {
286286
override get message(): string {
287-
return `Unable to list threads in project ${this.projectId}.`;
287+
return this.projectId === undefined
288+
? "Unable to list threads."
289+
: `Unable to list threads in project ${this.projectId}.`;
288290
}
289291
}
290292

@@ -404,8 +406,9 @@ export interface ThreadManagementServiceShape {
404406
Orchestrator.OrchestratorV2Error
405407
>;
406408
readonly getThreadShell: Orchestrator.OrchestratorV2["Service"]["getThreadShell"];
409+
/** Omit `projectId` to list every project's threads. */
407410
readonly listProjectThreads: (input: {
408-
readonly projectId: ProjectId;
411+
readonly projectId?: ProjectId | undefined;
409412
readonly includeSubagents: boolean;
410413
}) => Effect.Effect<ReadonlyArray<OrchestrationV2ThreadShell>, ThreadManagementError>;
411414
readonly sendToThread: (
@@ -736,27 +739,32 @@ const make = Effect.gen(function* () {
736739
);
737740

738741
const listProjectThreads: ThreadManagementServiceShape["listProjectThreads"] = (input) =>
739-
orchestrator.getShellSnapshot({ projectId: input.projectId, location: "active" }).pipe(
740-
Effect.mapError(
741-
(cause) =>
742-
new ThreadManagementProjectThreadsListError({
743-
projectId: input.projectId,
744-
cause,
745-
}),
746-
),
747-
Effect.map((snapshot) =>
748-
snapshot.threads
749-
.filter(
750-
(thread) =>
751-
input.includeSubagents || thread.lineage.relationshipToParent !== "subagent",
752-
)
753-
.toSorted(
754-
(left, right) =>
755-
DateTime.toEpochMillis(right.updatedAt) - DateTime.toEpochMillis(left.updatedAt) ||
756-
right.id.localeCompare(left.id),
757-
),
758-
),
759-
);
742+
orchestrator
743+
.getShellSnapshot({
744+
location: "active",
745+
...(input.projectId === undefined ? {} : { projectId: input.projectId }),
746+
})
747+
.pipe(
748+
Effect.mapError(
749+
(cause) =>
750+
new ThreadManagementProjectThreadsListError({
751+
projectId: input.projectId,
752+
cause,
753+
}),
754+
),
755+
Effect.map((snapshot) =>
756+
snapshot.threads
757+
.filter(
758+
(thread) =>
759+
input.includeSubagents || thread.lineage.relationshipToParent !== "subagent",
760+
)
761+
.toSorted(
762+
(left, right) =>
763+
DateTime.toEpochMillis(right.updatedAt) - DateTime.toEpochMillis(left.updatedAt) ||
764+
right.id.localeCompare(left.id),
765+
),
766+
),
767+
);
760768

761769
const sendToThread: ThreadManagementServiceShape["sendToThread"] = Effect.fn(
762770
"ThreadManagementService.sendToThread",

‎packages/contracts/src/orchestratorMcp.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,9 @@ export const OrchestratorMcpEnvironmentTarget = Schema.optional(
330330
export const OrchestratorMcpThreadListInput = Schema.Struct({
331331
environmentId: OrchestratorMcpEnvironmentTarget,
332332
projectId: OrchestratorMcpProjectTarget,
333+
allProjects: Schema.optional(
334+
Schema.Boolean.annotate({ description: "List every project's threads. Ignores `projectId`." }),
335+
),
333336
statuses: Schema.optional(
334337
Schema.Array(OrchestratorMcpThreadStatus).check(Schema.isMaxLength(10)),
335338
),
@@ -353,6 +356,7 @@ export type OrchestratorMcpThreadPullRequest = typeof OrchestratorMcpThreadPullR
353356

354357
export const OrchestratorMcpThreadListItem = Schema.Struct({
355358
threadId: ThreadId,
359+
projectId: ProjectId,
356360
title: Schema.String,
357361
link: Schema.optional(Schema.String),
358362
createdBy: OrchestrationV2Actor,
@@ -378,7 +382,8 @@ export const OrchestratorMcpThreadListItem = Schema.Struct({
378382
export type OrchestratorMcpThreadListItem = typeof OrchestratorMcpThreadListItem.Type;
379383

380384
export const OrchestratorMcpThreadListResult = Schema.Struct({
381-
projectId: ProjectId,
385+
/** null with `allProjects`. */
386+
projectId: Schema.NullOr(ProjectId),
382387
currentThreadId: Schema.NullOr(ThreadId),
383388
threads: Schema.Array(OrchestratorMcpThreadListItem),
384389
nextCursor: Schema.NullOr(NonNegativeInt),

0 commit comments

Comments
 (0)