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

tools.ts

85 lines4.3 KB

1import {
2 WorktreeMcpFailure,
3 OrchestratorMcpFailure,
4 VcsListRefsInput,
5 VcsListRefsResult,
6 WorktreeMcpHandoffInput,
7 WorktreeMcpHandoffResult,
8 WorktreeMcpStatusResult,
9 ThreadId,
10} from "@t3tools/contracts";
11import * as Schema from "effect/Schema";
12import * as GitWorkflowService from "../../../git/GitWorkflowService.ts";
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 "Needs an agent running inside a T3 thread. Move this agent thread into a new git worktree. To launch a separate agent already bound to a new or existing worktree, use t3_thread_launch with workspaceStrategy instead. Creates the worktree branch (optionally from the base branch's remote), re-points the thread at the worktree, and by default runs the project's setup script there. Changing the workspace detaches the live provider session, so the current turn ends shortly after the handoff is recorded; call this as the last action of the turn. To keep working after the handoff, pass continuationPrompt with the remaining work: it is queued as the thread's next message and starts a new turn inside the worktree with the conversation preserved. Without it the thread stays idle until the next message. The worktree is not removed automatically when the thread is deleted. Fails if the thread is already attached to 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 "Needs an agent running inside a T3 thread. Report this agent thread's worktree binding: whether it is attached to a git worktree, the worktree path and branch, the project's main workspace root, and the server default for t3_worktree_handoff's startFromOrigin. Call this before t3_worktree_handoff to check whether a handoff is possible or has already happened.",
46 // Empty Struct emits object|array, making MCP clients reject the server; use EmptyParams for an object schema.
47 success: WorktreeMcpStatusResult,
48 failure: WorktreeToolFailure,
49 failureMode: "return",
50 dependencies,
51})
52 .annotate(Tool.Title, "Get thread worktree status")
53 .annotate(Tool.Readonly, true)
54 .annotate(Tool.Destructive, false)
55 .annotate(Tool.Idempotent, true)
56 .annotate(Tool.OpenWorld, false);
57​
58const WorktreeListTool = Tool.make("t3_worktree_list", {
59 description:
60 "List branch refs and their associated checkout paths for a thread's workspace (omit threadId for this thread) using the app's ref inventory. Detached worktrees without a branch are not included. Use t3_worktree_status for the thread binding and t3_worktree_handoff to create a new worktree.",
61 parameters: Schema.Struct({
62 threadId: Schema.optional(ThreadId),
63 query: VcsListRefsInput.fields.query,
64 cursor: VcsListRefsInput.fields.cursor,
65 limit: VcsListRefsInput.fields.limit,
66 refKind: VcsListRefsInput.fields.refKind,
67 includeMatchingRemoteRefs: VcsListRefsInput.fields.includeMatchingRemoteRefs,
68 }),
69 success: VcsListRefsResult,
70 failure: OrchestratorMcpFailure,
71 failureMode: "return",
72 dependencies: [
73 McpInvocationContext.McpInvocationContext,
74 ThreadManagementService.ThreadManagementService,
75 ProjectService.ProjectService,
76 GitWorkflowService.GitWorkflowService,
77 ],
78})
79 .annotate(Tool.Readonly, true)
80 .annotate(Tool.Destructive, false);
81export const WorktreeToolkit = Toolkit.make(
82 WorktreeHandoffTool,
83 WorktreeStatusTool,
84 WorktreeListTool,
85);