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

worktreeMcp.ts

112 lines3.9 KB

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