Skip to content

Commit b9afba5

Browse files
Bil0000juliusmarmingeclaudecodexmaria-rcks
authored
feat(web): show Claude workflow phases and members in Lineage (#12598)
Co-authored-by: Julius Marminge <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]> Co-authored-by: GPT-6.1-Sol (Codex) <[email protected]> Co-authored-by: maria-rcks <[email protected]>
1 parent a908a7a commit b9afba5

56 files changed

Lines changed: 7214 additions & 659 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎apps/server/src/auth/RpcAuthorization.test.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
ProviderInstanceId,
99
ThreadId,
1010
AuthOrchestrationOperateScope,
11+
ORCHESTRATION_V2_WS_METHODS,
1112
AuthOrchestrationReadScope,
1213
AuthSourceControlWriteScope,
1314
AuthPreviewOperateScope,
@@ -35,6 +36,12 @@ describe("RPC authorization scopes", () => {
3536
expect(new Set(Object.keys(RPC_REQUIRED_SCOPES))).toEqual(new Set(WsRpcGroup.requests.keys()));
3637
});
3738

39+
it("requires operate access to stop a workflow", () => {
40+
expect(requiredScopeForRpcMethod(ORCHESTRATION_V2_WS_METHODS.stopWorkflow)).toBe(
41+
AuthOrchestrationOperateScope,
42+
);
43+
});
44+
3845
it("authorizes background policy reporting and observation deliberately", () => {
3946
expect(requiredScopeForRpcMethod(WS_METHODS.serverReportClientActivity)).toBe(
4047
AuthOrchestrationReadScope,

‎apps/server/src/auth/RpcAuthorization.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ export const RPC_REQUIRED_SCOPES = {
4646
...CLIENT_GUARDED_RPC_SCOPES,
4747
[ORCHESTRATION_V2_WS_METHODS.dispatchCommand]: AuthOrchestrationOperateScope,
4848
[ORCHESTRATION_V2_WS_METHODS.getWorkflowScript]: AuthOrchestrationReadScope,
49+
[ORCHESTRATION_V2_WS_METHODS.stopWorkflow]: AuthOrchestrationOperateScope,
4950
[ORCHESTRATION_V2_WS_METHODS.getTurnDiff]: AuthOrchestrationReadScope,
5051
[ORCHESTRATION_V2_WS_METHODS.getFullThreadDiff]: AuthOrchestrationReadScope,
5152
[ORCHESTRATION_V2_WS_METHODS.searchThreads]: AuthOrchestrationReadScope,

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -879,6 +879,7 @@ function timelineItem(input: {
879879
visibility: input.row.visibility,
880880
sourceThreadId: input.row.sourceThreadId,
881881
itemId: input.row.sourceItemId,
882+
...(input.row.item.type === "subagent" ? { subagentId: input.row.item.subagentId } : {}),
882883
runId: input.row.item.runId,
883884
messageId,
884885
createdBy: message?.createdBy ?? null,

‎apps/server/src/mcp/toolkits/core.test.ts‎

Lines changed: 132 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,14 @@ import {
88
ChatImageAttachment,
99
CommandId,
1010
EnvironmentId,
11+
NodeId,
12+
OrchestratorMcpThreadReadResult,
13+
ProviderDriverKind,
1114
ProviderInstanceId,
1215
RunId,
1316
ThreadId,
17+
TurnItemId,
18+
type OrchestrationV2ProjectedTurnItem,
1419
type OrchestrationV2ThreadShell,
1520
} from "@t3tools/contracts";
1621
import * as Effect from "effect/Effect";
@@ -69,6 +74,7 @@ import {
6974
import { htmlRenderFromToolItem } from "@t3tools/shared/toolOutput";
7075

7176
const decodeMcpAttachmentInput = Schema.decodeUnknownEffect(McpAttachmentInput);
77+
const decodeThreadReadResult = Schema.decodeUnknownEffect(OrchestratorMcpThreadReadResult);
7278

7379
// Registration asks for every service the thread tools declare; these cases call none that use them.
7480
const layerThreadToolkit = McpHttpServer.layerThreadToolkit.pipe(
@@ -663,37 +669,142 @@ function scheduledTask(id: string, runtimeMode: "auto" | "full-access"): never {
663669
} as never;
664670
}
665671

666-
it.effect("a caller cannot interrupt a thread that runs above its own modes", () =>
667-
Effect.gen(function* () {
672+
it.effect.each(["t3_thread_interrupt", "t3_workflow_stop"])(
673+
"a caller cannot use %s on a thread that runs above its own modes",
674+
(toolName) =>
675+
Effect.gen(function* () {
676+
const server = yield* McpServer.McpServer;
677+
const result = yield* server
678+
.callTool({
679+
name: toolName,
680+
arguments: {
681+
threadId: "full-access-thread",
682+
...(toolName === "t3_workflow_stop" ? { subagentId: "workflow-coordinator" } : {}),
683+
},
684+
})
685+
.pipe(
686+
Effect.provideService(McpInvocationContext.McpInvocationContext, clientScope("auto")),
687+
Effect.provideService(McpSchema.McpServerClient, client),
688+
);
689+
expect(declaredFailure(result)).toMatchObject({ code: "runtime_mode_escalation_denied" });
690+
}).pipe(
691+
Effect.provide(
692+
McpHttpServer.layerOrchestratorToolkit.pipe(
693+
Layer.provideMerge(McpServer.McpServer.layer),
694+
Layer.provide(NodeCrypto.layer),
695+
Layer.provide(
696+
Layer.mock(ThreadManagement.ThreadManagementService)({
697+
getThreadShell: () =>
698+
Effect.succeed({
699+
projectId: "project-a",
700+
deletedAt: null,
701+
runtimeMode: "full-access",
702+
interactionMode: "default",
703+
} as never),
704+
getProjectThreadRecords: () =>
705+
Effect.succeed({
706+
thread: {
707+
id: ThreadId.make("full-access-thread"),
708+
projectId: "project-a",
709+
runtimeMode: "full-access",
710+
interactionMode: "default",
711+
deletedAt: null,
712+
},
713+
runs: [],
714+
} as never),
715+
stopWorkflow: () => Effect.die("workflow stop must not dispatch above the ceiling"),
716+
interruptThread: () => Effect.die("interrupt must not dispatch above the ceiling"),
717+
}),
718+
),
719+
Layer.provide(Layer.mock(ProviderRegistry.ProviderRegistry)({})),
720+
Layer.provide(Layer.mock(ProviderAdapterRegistry.ProviderAdapterRegistryV2)({})),
721+
Layer.provide(Layer.mock(ScheduledTaskService.ScheduledTaskService)({})),
722+
Layer.provide(Layer.mock(ProjectService.ProjectService)({})),
723+
Layer.provide(Layer.mock(SecretRequests.SecretRequests)({})),
724+
),
725+
),
726+
),
727+
);
728+
729+
it.effect("discovers workflow stop targets and requires orchestration capability", () => {
730+
const threadId = ThreadId.make("workflow-parent");
731+
const shell = McpToolAccessTestkit.liveThreadShell(threadId);
732+
const subagentId = NodeId.make("workflow-coordinator");
733+
const itemId = TurnItemId.make("workflow-coordinator-activity");
734+
const row: OrchestrationV2ProjectedTurnItem = {
735+
position: 0,
736+
visibility: "local",
737+
sourceThreadId: threadId,
738+
sourceItemId: itemId,
739+
item: {
740+
id: itemId,
741+
threadId,
742+
runId: shell.activeRunId,
743+
nodeId: subagentId,
744+
providerThreadId: null,
745+
providerTurnId: null,
746+
nativeItemRef: null,
747+
parentItemId: null,
748+
ordinal: 0,
749+
status: "running",
750+
title: "Workflow: checkout review",
751+
startedAt: shell.createdAt,
752+
completedAt: null,
753+
updatedAt: shell.updatedAt,
754+
type: "subagent",
755+
subagentId,
756+
origin: "provider_native",
757+
driver: ProviderDriverKind.make("claudeAgent"),
758+
providerInstanceId: ProviderInstanceId.make("claudeAgent"),
759+
childThreadId: ThreadId.make("workflow-child"),
760+
prompt: "Review checkout",
761+
result: null,
762+
},
763+
};
764+
const stopped: Array<{ readonly threadId: ThreadId; readonly subagentId: string }> = [];
765+
return Effect.gen(function* () {
668766
const server = yield* McpServer.McpServer;
669-
const result = yield* server
670-
.callTool({ name: "t3_thread_interrupt", arguments: { threadId: "full-access-thread" } })
767+
const scope = clientScope("full-access");
768+
const read = yield* server
769+
.callTool({ name: "t3_thread_read", arguments: { threadId, view: "activity" } })
671770
.pipe(
672-
Effect.provideService(McpInvocationContext.McpInvocationContext, clientScope("auto")),
771+
Effect.provideService(McpInvocationContext.McpInvocationContext, scope),
673772
Effect.provideService(McpSchema.McpServerClient, client),
674773
);
675-
expect(declaredFailure(result)).toMatchObject({ code: "runtime_mode_escalation_denied" });
774+
expect(read.isError).toBe(false);
775+
const result = yield* decodeThreadReadResult(read.structuredContent);
776+
expect(result.items[0]?.subagentId).toBe(subagentId);
777+
const call = (invocation: McpInvocationContext.McpInvocationScope) =>
778+
server
779+
.callTool({
780+
name: "t3_workflow_stop",
781+
arguments: { threadId, subagentId: result.items[0]?.subagentId },
782+
})
783+
.pipe(
784+
Effect.provideService(McpInvocationContext.McpInvocationContext, invocation),
785+
Effect.provideService(McpSchema.McpServerClient, client),
786+
);
787+
const denied = yield* call({ ...scope, capabilities: new Set(["worktree"]) });
788+
expect(declaredFailure(denied)).toMatchObject({ code: "capability_denied" });
789+
expect(stopped).toEqual([]);
790+
const allowed = yield* call(scope);
791+
expect(allowed.isError).toBe(false);
792+
expect(stopped).toEqual([{ threadId: "workflow-parent", subagentId: "workflow-coordinator" }]);
676793
}).pipe(
677794
Effect.provide(
678795
McpHttpServer.layerOrchestratorToolkit.pipe(
679796
Layer.provideMerge(McpServer.McpServer.layer),
680797
Layer.provide(NodeCrypto.layer),
681798
Layer.provide(
682799
Layer.mock(ThreadManagement.ThreadManagementService)({
683-
getThreadShell: () =>
684-
Effect.succeed({ projectId: "project-a", deletedAt: null } as never),
800+
getThreadShell: (id) => Effect.succeed(McpToolAccessTestkit.liveThreadShell(id)),
685801
getProjectThreadRecords: () =>
686-
Effect.succeed({
687-
thread: {
688-
id: ThreadId.make("full-access-thread"),
689-
projectId: "project-a",
690-
runtimeMode: "full-access",
691-
interactionMode: "default",
692-
deletedAt: null,
693-
},
694-
runs: [],
695-
} as never),
696-
interruptThread: () => Effect.die("interrupt must not dispatch above the ceiling"),
802+
Effect.succeed(McpToolAccessTestkit.idleThreadProjection(shell)),
803+
getTimelinePage: () => Effect.succeed({ items: [row], totalItems: 1, hasMore: false }),
804+
stopWorkflow: (input) =>
805+
Effect.sync(() => {
806+
stopped.push(input);
807+
}),
697808
}),
698809
),
699810
Layer.provide(Layer.mock(ProviderRegistry.ProviderRegistry)({})),
@@ -703,8 +814,8 @@ it.effect("a caller cannot interrupt a thread that runs above its own modes", ()
703814
Layer.provide(Layer.mock(SecretRequests.SecretRequests)({})),
704815
),
705816
),
706-
),
707-
);
817+
);
818+
});
708819

709820
it.effect("only the caller that prepared a pending upload can discard it", () =>
710821
Effect.gen(function* () {

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
import { OrchestratorMcpFailure } from "@t3tools/contracts";
12
import { OrchestratorToolkit } from "./tools.ts";
23
import * as Effect from "effect/Effect";
34

5+
import { readCaller } from "../../threadAccess.ts";
46
import * as McpInvocationContext from "../../McpInvocationContext.ts";
57
import * as McpToolAccess from "../../McpToolAccess.ts";
68
import * as OrchestratorMcpService from "../../OrchestratorMcpService.ts";
@@ -35,6 +37,26 @@ const handlers = {
3537
return yield* service.cancelTask(scope, input);
3638
}),
3739
),
40+
t3_workflow_stop: McpToolAccess.writesThreads(
41+
(input) => [input.threadId],
42+
(input) =>
43+
Effect.gen(function* () {
44+
const { threads } = yield* readCaller();
45+
return yield* threads.stopWorkflow(input).pipe(
46+
Effect.as({}),
47+
Effect.mapError(
48+
(cause) =>
49+
new OrchestratorMcpFailure({
50+
code:
51+
cause.reason === "unavailable" || cause.reason === "stop-failed"
52+
? "orchestration_error"
53+
: "invalid_request",
54+
message: cause.message,
55+
}),
56+
),
57+
);
58+
}),
59+
),
3860
schedule_task: McpToolAccess.startsThreads(
3961
// A scheduled task runs with the caller's own modes.
4062
() => ({}),

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {
22
OrchestratorMcpCapabilitiesResult,
3+
OrchestrationV2StopWorkflowInput,
34
OrchestratorMcpCreateThreadsInput,
45
OrchestratorMcpCreateThreadsResult,
56
OrchestratorMcpDelegateTaskInput,
@@ -31,6 +32,7 @@ import {
3132
ThreadMetadataMcpUpdateResult,
3233
} from "@t3tools/contracts";
3334
import { Tool, Toolkit } from "effect/ai";
35+
import * as Schema from "effect/Schema";
3436

3537
import * as ThreadManagementService from "../../../orchestration-v2/ThreadManagementService.ts";
3638
import * as McpInvocationContext from "../../McpInvocationContext.ts";
@@ -100,6 +102,18 @@ const TaskCancelTool = Tool.make("task_cancel", {
100102
.annotate(Tool.Title, "Cancel delegated task")
101103
.annotate(Tool.Destructive, true);
102104

105+
const WorkflowStopTool = Tool.make("t3_workflow_stop", {
106+
description:
107+
"Stop one running Claude workflow in a T3 thread. Use the workflow coordinator's subagentId returned by t3_thread_read with view='activity'. Stops the whole workflow, including its phases and agents. Does not stop the parent thread or other workflows. Individual workflow phases and agents cannot be stopped separately.",
108+
parameters: OrchestrationV2StopWorkflowInput,
109+
success: Schema.Struct({}),
110+
failure: OrchestratorMcpFailure,
111+
failureMode: "return",
112+
dependencies,
113+
})
114+
.annotate(Tool.Title, "Stop a workflow")
115+
.annotate(Tool.Destructive, true);
116+
103117
export const ScheduleTaskTool = Tool.make("schedule_task", {
104118
description:
105119
"Create persistent work in the app scheduler that runs even when no turn is active. Pass schedule as a STRUCTURED OBJECT, never JSON text. Timers: {type:'interval', everyMs:3600000} is hourly; {type:'fixed_time', timeOfDay:'09:00', weekdays:[1,2,3,4,5]} is weekday mornings; report the returned nextRunAt. Webhooks: {type:'webhook'} runs once per request to a generated URL. The run sees the request ONLY through prompt placeholders: {{body.path}} (e.g. {{body.action}}, {{body.release.tag_name}}), {{headers.name}}, {{query.name}}, {{body}}, or {{request}} (method, headers with credentials redacted, and body). For a sender that signs requests, first call request_secret so the user enters the secret privately (never ask for it in chat or invent one), then set signature with the returned secretRef, e.g. GitHub: {type:'webhook', signature:{header:'x-hub-signature-256', encoding:'hex', prefix:'sha256=', secretRef}}. The result's webhookUrl is the public URL to give the user; if it is absent, this environment has no T3 Connect managed tunnel, so tell the user to enable T3 Connect remote access rather than sharing a path. Omit projectId for this thread's project. In this thread's project, runs post into THIS thread by default (bindToCurrentThread=true), which suits an orchestrator that sees every trigger, delegates work, and can dedupe against what is in flight; use false only when the user wants a fresh top-level thread per run. Elsewhere each run launches a fresh thread. Provider, model, and runtime settings inherit from this thread, or from the project default when there is no calling thread.",
@@ -261,6 +275,7 @@ export const OrchestratorToolkit = Toolkit.make(
261275
DelegateTaskTool,
262276
TaskStatusTool,
263277
TaskCancelTool,
278+
WorkflowStopTool,
264279
ScheduleTaskTool,
265280
ListScheduledTasksTool,
266281
UpdateScheduledTaskTool,

‎apps/server/src/observability/RpcInstrumentation.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ type WsRpcMethod = RpcGroup.Rpcs<typeof WsRpcGroup>["_tag"];
1717
const RPC_AGGREGATES = {
1818
[ORCHESTRATION_V2_WS_METHODS.dispatchCommand]: "orchestrationV2",
1919
[ORCHESTRATION_V2_WS_METHODS.getWorkflowScript]: "orchestration",
20+
[ORCHESTRATION_V2_WS_METHODS.stopWorkflow]: "orchestration",
2021
[ORCHESTRATION_V2_WS_METHODS.getTurnItem]: "orchestration",
2122
[ORCHESTRATION_V2_WS_METHODS.getTurnDiff]: "orchestration",
2223
[ORCHESTRATION_V2_WS_METHODS.getFullThreadDiff]: "orchestration",

0 commit comments

Comments
 (0)