GeezerVison is showing github.com — feat(server): initialize native task threads (#11) · tomcorke/t3code@3712da5
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: apps/server/src/mcp/McpToolAccess.testkit.ts +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -80,7 +80,7 @@ export const idleThreadProjection = ( | 80 | 80 | ...thread | 81 | 81 | } = shell; | 82 | 82 | return { | 83 | | - thread: { ...thread, lastVisitedAt: lastVisitedAt ?? null }, | | 83 | + thread: { ...thread, taskInitialization: null, lastVisitedAt: lastVisitedAt ?? null }, | 84 | 84 | runs: [], | 85 | 85 | attempts: [], | 86 | 86 | nodes: [], | |
Collapse file Copy file name to clipboardExpand all lines: apps/server/src/mcp/OrchestratorMcpService.ts +3Lines changed: 3 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | import { | | 2 | + taskThreadInitializationSummary, | 2 | 3 | CommandId, | 3 | 4 | type RunId, | 4 | 5 | isProviderAvailable, | @@ -806,6 +807,8 @@ function threadDetail( | 806 | 807 | interactionMode: projection.thread.interactionMode, | 807 | 808 | linkedPullRequest: projection.thread.linkedPullRequest ?? null, | 808 | 809 | pullRequests: threadPullRequests(projection.thread.pullRequests), | | 810 | + taskDocumentId: projection.thread.taskDocumentId ?? null, | | 811 | + taskInitialization: taskThreadInitializationSummary(projection.thread.taskInitialization), | 809 | 812 | titleRegeneration: | 810 | 813 | projection.thread.titleRegeneration === undefined || | 811 | 814 | projection.thread.titleRegeneration === null | |
Collapse file Copy file name to clipboardExpand all lines: apps/server/src/mcp/toolkits/project/handlers.ts +40-2Lines changed: 40 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -75,7 +75,42 @@ const access = Effect.gen(function* () { | 75 | 75 | yield* readCaller(); | 76 | 76 | return yield* Project.ProjectService; | 77 | 77 | }); | | 78 | +// File-system causes stay out of the message; authored reasons are safe to show. | | 79 | +const taskLaunchFailure = (error: ThreadLaunch.ThreadLaunchError) => | | 80 | + error.operation === "resolve-task" | | 81 | + ? new OrchestratorMcpFailure({ | | 82 | + code: "invalid_request", | | 83 | + message: | | 84 | + typeof error.cause === "string" | | 85 | + ? error.cause | | 86 | + : "The task document or update instructions could not be read.", | | 87 | + }) | | 88 | + : unavailable(); | | 89 | + | 78 | 90 | export const layer = McpToolAccess.toLayer(ProjectToolkit, { | | 91 | + task_thread_initialization_result: McpToolAccess.writesThreads( | | 92 | + () => [], | | 93 | + (input) => | | 94 | + Effect.gen(function* () { | | 95 | + const scope = yield* McpInvocationContext.McpInvocationContext; | | 96 | + const { caller } = yield* readCaller(); | | 97 | + if (scope.thread === undefined || scope.thread.subagent === true || caller === undefined) | | 98 | + return yield* new OrchestratorMcpFailure({ | | 99 | + code: "invalid_request", | | 100 | + message: "Only the initializing thread can report its context outcome.", | | 101 | + }); | | 102 | + const launches = yield* ThreadLaunch.ThreadLaunchService; | | 103 | + yield* launches | | 104 | + .reportTaskInitialization({ | | 105 | + threadId: caller.id, | | 106 | + projectId: caller.projectId, | | 107 | + providerInstanceId: scope.thread.providerInstanceId, | | 108 | + outcome: input.outcome, | | 109 | + }) | | 110 | + .pipe(Effect.mapError(taskLaunchFailure)); | | 111 | + return { recorded: true }; | | 112 | + }), | | 113 | + ), | 79 | 114 | t3_thread_launch: McpToolAccess.startsThreads( | 80 | 115 | (input) => input, | 81 | 116 | (input, { runtimeMode, interactionMode, linkOrigin }) => | @@ -209,6 +244,7 @@ export const layer = McpToolAccess.toLayer(ProjectToolkit, { | 209 | 244 | ) | 210 | 245 | : runtimeMode; | 211 | 246 | const result = yield* ThreadMessageIntake.launchThread({ | | 247 | + ...(input.task === undefined ? {} : { task: input.task }), | 212 | 248 | commandId, | 213 | 249 | threadId, | 214 | 250 | projectId, | @@ -246,11 +282,13 @@ export const layer = McpToolAccess.toLayer(ProjectToolkit, { | 246 | 282 | message: error.message, | 247 | 283 | }); | 248 | 284 | } | 249 | | - return unavailable(); | | 285 | + return error._tag === "ThreadLaunchError" ? taskLaunchFailure(error) : unavailable(); | 250 | 286 | }), | 251 | 287 | ); | 252 | 288 | const thread = result.projection.thread; | 253 | | - const run = result.projection.runs.find((run) => run.userMessageId === messageId); | | 289 | + const run = result.projection.runs.find( | | 290 | + (run) => run.userMessageId === (thread.taskInitialization?.messageId ?? messageId), | | 291 | + ); | 254 | 292 | return { | 255 | 293 | threadId: thread.id, | 256 | 294 | link: McpInvocationContext.threadLinkFor(scope, thread.id), | |
Collapse file Copy file name to clipboardExpand all lines: apps/server/src/mcp/toolkits/project/tools.ts +17Lines changed: 17 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 8 | 8 | OrchestrationV2DelegatedFrom, | 9 | 9 | OrchestrationV2RunStatus, | 10 | 10 | OrchestrationV2ThreadLaunchWorkspaceStrategy, | | 11 | + TaskThreadLaunchOptions, | 11 | 12 | RuntimeMode, | 12 | 13 | ProviderInteractionMode, | 13 | 14 | Project, | @@ -123,6 +124,12 @@ const ThreadLaunchTool = Tool.make("t3_thread_launch", { | 123 | 124 | description: | 124 | 125 | "Create one new top-level thread, bound to its workspace before the agent starts. Task in `message`. Omit `projectId`, model and modes to inherit yours (outside a thread, pass `projectId` or `scratch`); modes cannot exceed yours. After an error or lost reply, retry with the same `clientRequestId`. Follow it with `t3_thread_read` or `t3_thread_wait`. Mention it with its `link`.", | 125 | 126 | parameters: Schema.Struct({ | | 127 | + task: Schema.optional( | | 128 | + TaskThreadLaunchOptions.annotate({ | | 129 | + description: | | 130 | + "Optional registered task document and update-discipline path on the destination environment. Runs visible context initialization first. Omit message/attachments; send work after launch. No filesystem permission is added.", | | 131 | + }), | | 132 | + ), | 126 | 133 | environmentId: OrchestratorMcpEnvironmentTarget, | 127 | 134 | projectId: Schema.optional(ProjectId), | 128 | 135 | scratch: Schema.optional( | @@ -174,7 +181,17 @@ const ThreadLaunchTool = Tool.make("t3_thread_launch", { | 174 | 181 | .annotate(Tool.Destructive, true) | 175 | 182 | .annotate(Tool.OpenWorld, true); | 176 | 183 |
| | 184 | +const TaskInitializationResultTool = Tool.make("task_thread_initialization_result", { | | 185 | + ...shared, | | 186 | + description: | | 187 | + "Report this task thread's initialization outcome after reading its required context. Use ready only when the task, relevant parents, update discipline and workspace instructions are readable and the selected workspace matches. Otherwise report failed and explain why. This reports context readiness; it does not start user work or change permissions.", | | 188 | + parameters: Schema.Struct({ outcome: Schema.Literals(["ready", "failed"]) }), | | 189 | + success: Schema.Struct({ recorded: Schema.Boolean }), | | 190 | + dependencies: [...shared.dependencies, ThreadLaunchService.ThreadLaunchService], | | 191 | +}).annotate(Tool.Destructive, true); | | 192 | + | 177 | 193 | export const ProjectToolkit = Toolkit.make( | | 194 | + TaskInitializationResultTool, | 178 | 195 | ThreadLaunchTool, | 179 | 196 | ProjectListTool, | 180 | 197 | ProjectReadTool, | |
|