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

worktreeMcp.ts

117 lines4.1 KB

1import * as Schema from "effect/Schema";
2​
3import { TrimmedNonEmptyString } from "./baseSchemas.ts";
4​
5/**
6 * The server picks the location in its managed worktrees folder.
7 * Changing the thread's workspace detaches the live provider session, so the
8 * current turn ends shortly after the handoff is recorded; the conversation
9 * continues inside the worktree on the thread's next run.
10 */
11export const WorktreeMcpHandoffInput = Schema.Struct({
12 branch: TrimmedNonEmptyString.annotate({
13 description: "Branch name to create for the worktree (e.g. 'feature/my-change').",
14 }),
15 baseRef: Schema.optional(
16 TrimmedNonEmptyString.annotate({
17 description:
18 "Branch or ref the worktree branch starts from. Defaults to the branch currently checked out in the project workspace.",
19 }),
20 ),
21 startFromOrigin: Schema.optional(
22 Schema.Boolean.annotate({
23 description:
24 "Fetch the remote baseRef belongs to and start the worktree branch from its remote-tracking commit instead of the local ref. Defaults to the server's 'new worktrees start from remote' setting.",
25 }),
26 ),
27 runSetupScript: Schema.optional(
28 Schema.Boolean.annotate({
29 description:
30 "Run the project's configured setup script in the new worktree after handoff. Defaults to true.",
31 }),
32 ),
33 continuationPrompt: Schema.optional(
34 TrimmedNonEmptyString.check(Schema.isMaxLength(120_000)).annotate({
35 description:
36 "Message queued as the thread's next turn after the handoff. The handoff detaches the current provider session, so pass the remaining work here to automatically resume inside the worktree; omit it to stop after the handoff and wait for the next message.",
37 }),
38 ),
39});
40export type WorktreeMcpHandoffInput = typeof WorktreeMcpHandoffInput.Type;
41​
42export const WorktreeMcpSetupScriptStatus = Schema.Union([
43 Schema.Struct({
44 status: Schema.Literal("started"),
45 scriptName: TrimmedNonEmptyString,
46 terminalId: TrimmedNonEmptyString,
47 }),
48 Schema.Struct({
49 status: Schema.Literal("no-script"),
50 }),
51 Schema.Struct({
52 status: Schema.Literal("skipped"),
53 }),
54 Schema.Struct({
55 status: Schema.Literal("failed"),
56 detail: Schema.String,
57 }),
58]);
59export type WorktreeMcpSetupScriptStatus = typeof WorktreeMcpSetupScriptStatus.Type;
60​
61export const WorktreeMcpContinuationStatus = Schema.Union([
62 Schema.Struct({
63 status: Schema.Literal("scheduled"),
64 delivery: Schema.Literals(["started", "queued", "steered", "restarted"]),
65 }),
66 Schema.Struct({
67 status: Schema.Literal("skipped"),
68 }),
69 Schema.Struct({
70 status: Schema.Literal("failed"),
71 detail: Schema.String,
72 }),
73]);
74export type WorktreeMcpContinuationStatus = typeof WorktreeMcpContinuationStatus.Type;
75​
76export const WorktreeMcpHandoffResult = Schema.Struct({
77 worktreePath: TrimmedNonEmptyString,
78 branch: TrimmedNonEmptyString,
79 baseRef: TrimmedNonEmptyString,
80 startedFromOrigin: Schema.Boolean,
81 setupScript: WorktreeMcpSetupScriptStatus,
82 continuation: WorktreeMcpContinuationStatus,
83 note: Schema.String,
84});
85export type WorktreeMcpHandoffResult = typeof WorktreeMcpHandoffResult.Type;
86​
87export const WorktreeMcpStatusResult = Schema.Struct({
88 attached: Schema.Boolean.annotate({
89 description: "True when this thread is already attached to a git worktree.",
90 }),
91 worktreePath: Schema.NullOr(TrimmedNonEmptyString),
92 branch: Schema.NullOr(TrimmedNonEmptyString),
93 projectWorkspaceRoot: TrimmedNonEmptyString.annotate({
94 description: "Root of the project's main workspace checkout.",
95 }),
96 defaultStartFromOrigin: Schema.Boolean.annotate({
97 description: "Server default used by t3_worktree_handoff when startFromOrigin is omitted.",
98 }),
99});
100export type WorktreeMcpStatusResult = typeof WorktreeMcpStatusResult.Type;
101​
102export class WorktreeMcpFailure extends Schema.TaggedError<WorktreeMcpFailure>()(
103 "WorktreeMcpFailure",
104 {
105 code: Schema.Literals([
106 "capability_denied",
107 "thread_not_found",
108 "project_not_found",
109 "already_in_worktree",
110 "handoff_in_progress",
111 "invalid_request",
112 "operation_failed",
113 "thread_credential_required",
114 ]),
115 message: Schema.String,
116 },
117) {}