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

tools.ts

90 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 GitWorkflowService from "../../../git/GitWorkflowService.ts";
14import * as ProjectService from "../../../project/ProjectService.ts";
15import * as ThreadManagementService from "../../../orchestration-v2/ThreadManagementService.ts";
16import { Tool, Toolkit } from "effect/ai";
17​
18import * as McpInvocationContext from "../../McpInvocationContext.ts";
19import * as WorktreeMcpService from "../../WorktreeMcpService.ts";
20​
21const dependencies = [
22 McpInvocationContext.McpInvocationContext,
23 ThreadManagementService.ThreadManagementService,
24 WorktreeMcpService.WorktreeMcpService,
25];
26​
27const WorktreeToolFailure = Schema.Union([WorktreeMcpFailure, OrchestratorMcpFailure]);
28​
29const WorktreeHandoffTool = Tool.make("t3_worktree_handoff", {
30 description:
31 "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.",
32 parameters: WorktreeMcpHandoffInput,
33 success: WorktreeMcpHandoffResult,
34 failure: WorktreeToolFailure,
35 failureMode: "return",
36 dependencies,
37})
38 .annotate(Tool.Title, "Hand off thread to a git worktree")
39 .annotate(Tool.Readonly, false)
40 .annotate(Tool.Destructive, true)
41 .annotate(Tool.Idempotent, false)
42 .annotate(Tool.OpenWorld, true);
43​
44const WorktreeStatusTool = Tool.make("t3_worktree_status", {
45 description:
46 "Report this thread's worktree: attached or not, path, branch, project root, and the `startFromOrigin` default. Check before `t3_worktree_handoff`.",
47 // No `parameters`: Tool.make defaults to Tool.EmptyParams, which serializes
48 // to a top-level `type: "object"` JSON Schema. An explicit empty
49 // Schema.Struct({}) serializes to `anyOf: [object, array]`, which is not a
50 // valid MCP tool input schema and makes clients reject the whole server.
51 success: WorktreeMcpStatusResult,
52 failure: WorktreeToolFailure,
53 failureMode: "return",
54 dependencies,
55})
56 .annotate(Tool.Title, "Get thread worktree status")
57 .annotate(Tool.Readonly, true)
58 .annotate(Tool.Destructive, false)
59 .annotate(Tool.Idempotent, true)
60 .annotate(Tool.OpenWorld, false);
61​
62const WorktreeListTool = Tool.make("t3_worktree_list", {
63 description:
64 "List branch refs and checkout paths for a thread's workspace. Omit `threadId` for this thread. Detached worktrees with no branch are left out.",
65 parameters: Schema.Struct({
66 environmentId: OrchestratorMcpEnvironmentTarget,
67 threadId: Schema.optional(ThreadId),
68 query: VcsListRefsInput.fields.query,
69 cursor: VcsListRefsInput.fields.cursor,
70 limit: VcsListRefsInput.fields.limit,
71 refKind: VcsListRefsInput.fields.refKind,
72 includeMatchingRemoteRefs: VcsListRefsInput.fields.includeMatchingRemoteRefs,
73 }),
74 success: VcsListRefsResult,
75 failure: OrchestratorMcpFailure,
76 failureMode: "return",
77 dependencies: [
78 McpInvocationContext.McpInvocationContext,
79 ThreadManagementService.ThreadManagementService,
80 ProjectService.ProjectService,
81 GitWorkflowService.GitWorkflowService,
82 ],
83})
84 .annotate(Tool.Readonly, true)
85 .annotate(Tool.Destructive, false);
86export const WorktreeToolkit = Toolkit.make(
87 WorktreeHandoffTool,
88 WorktreeStatusTool,
89 WorktreeListTool,
90);