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

worktreeMcp.ts

122 lines4.3 KB

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