Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

tools.ts

89 lines3.6 KB

1import {
2 WorktreeMcpFailure,
3 OrchestratorMcpEnvironmentTarget,
4 OrchestratorMcpFailure,
5 VcsListRefsInput,
6 VcsListRefsResult,
7 WorktreeMcpHandoffInput,
8 WorktreeMcpHandoffResult,
9 WorktreeMcpStatusResult,
10 ThreadId,
11} from "@t3tools/contracts";
12import * as Schema from "effect/Schema";
13import * as ProjectService from "../../../project/ProjectService.ts";
14import * as ThreadManagementService from "../../../orchestration-v2/ThreadManagementService.ts";
15import { Tool, Toolkit } from "effect/ai";
16​
17import * as McpInvocationContext from "../../McpInvocationContext.ts";
18import * as WorktreeMcpService from "../../WorktreeMcpService.ts";
19​
20const dependencies = [
21 McpInvocationContext.McpInvocationContext,
22 ThreadManagementService.ThreadManagementService,
23 WorktreeMcpService.WorktreeMcpService,
24];
25​
26const WorktreeToolFailure = Schema.Union([WorktreeMcpFailure, OrchestratorMcpFailure]);
27​
28const WorktreeHandoffTool = Tool.make("t3_worktree_handoff", {
29 description:
30 "Move THIS thread into a new git worktree on a new branch. Runs the setup script by default. A separate agent in a worktree: `t3_thread_launch` with `workspaceStrategy`. Call last in your turn. The move ends the live session. `continuationPrompt` resumes work there next turn. Without it, the thread waits. The worktree stays after the thread is deleted. Fails if this thread has a worktree.",
31 parameters: WorktreeMcpHandoffInput,
32 success: WorktreeMcpHandoffResult,
33 failure: WorktreeToolFailure,
34 failureMode: "return",
35 dependencies,
36})
37 .annotate(Tool.Title, "Hand off thread to a git worktree")
38 .annotate(Tool.Readonly, false)
39 .annotate(Tool.Destructive, true)
40 .annotate(Tool.Idempotent, false)
41 .annotate(Tool.OpenWorld, true);
42​
43const WorktreeStatusTool = Tool.make("t3_worktree_status", {
44 description:
45 "Report this thread's worktree: attached or not, path, branch, project root, and the `startFromOrigin` default. Check before `t3_worktree_handoff`.",
46 // No `parameters`: Tool.make defaults to Tool.EmptyParams, which serializes
47 // to a top-level `type: "object"` JSON Schema. An explicit empty
48 // Schema.Struct({}) serializes to `anyOf: [object, array]`, which is not a
49 // valid MCP tool input schema and makes clients reject the whole server.
50 success: WorktreeMcpStatusResult,
51 failure: WorktreeToolFailure,
52 failureMode: "return",
53 dependencies,
54})
55 .annotate(Tool.Title, "Get thread worktree status")
56 .annotate(Tool.Readonly, true)
57 .annotate(Tool.Destructive, false)
58 .annotate(Tool.Idempotent, true)
59 .annotate(Tool.OpenWorld, false);
60​
61const WorktreeListTool = Tool.make("t3_worktree_list", {
62 description:
63 "List branch refs and checkout paths for a thread's workspace. Omit `threadId` for this thread. Detached worktrees with no branch are left out.",
64 parameters: Schema.Struct({
65 environmentId: OrchestratorMcpEnvironmentTarget,
66 threadId: Schema.optional(ThreadId),
67 query: VcsListRefsInput.fields.query,
68 cursor: VcsListRefsInput.fields.cursor,
69 limit: VcsListRefsInput.fields.limit,
70 refKind: VcsListRefsInput.fields.refKind,
71 includeMatchingRemoteRefs: VcsListRefsInput.fields.includeMatchingRemoteRefs,
72 }),
73 success: VcsListRefsResult,
74 failure: OrchestratorMcpFailure,
75 failureMode: "return",
76 dependencies: [
77 McpInvocationContext.McpInvocationContext,
78 ThreadManagementService.ThreadManagementService,
79 ProjectService.ProjectService,
80 WorktreeMcpService.WorktreeMcpService,
81 ],
82})
83 .annotate(Tool.Readonly, true)
84 .annotate(Tool.Destructive, false);
85export const WorktreeToolkit = Toolkit.make(
86 WorktreeHandoffTool,
87 WorktreeStatusTool,
88 WorktreeListTool,
89);