Open History to see the last commit
1import { McpAttachmentInput } from "../attachment/input.ts";
2import {
3 NonNegativeInt,
4 ModelSelection,
5 TrimmedNonEmptyString,
6 ThreadId,
7 RunId,
8 OrchestrationV2RunStatus,
9 OrchestrationV2ThreadLaunchWorkspaceStrategy,
10 RuntimeMode,
11 ProviderInteractionMode,
12 Project,
13 ProjectCreatePayload,
14 ProjectUpdatePayload,
15 ProjectId,
16 OrchestratorMcpFailure,
17 SourceControlCloneRepositoryInput,
18 SourceControlCloneRepositoryResult,
19} from "@t3tools/contracts";
20import * as FileSystem from "effect/FileSystem";
21import * as ServerConfig from "../../../config.ts";
22import * as ThreadLaunchService from "../../../orchestration-v2/ThreadLaunchService.ts";
23import * as Crypto from "effect/Crypto";
24import * as Schema from "effect/Schema";
25import { Tool, Toolkit } from "effect/unstable/ai";
26import * as ProjectService from "../../../project/ProjectService.ts";
27import * as ManagedProjectFolders from "../../../project/ManagedProjectFolders.ts";
28import * as ThreadManagementService from "../../../orchestration-v2/ThreadManagementService.ts";
29import * as SourceControlRepositoryService from "../../../sourceControl/SourceControlRepositoryService.ts";
30import * as McpInvocationContext from "../../McpInvocationContext.ts";
31
32const shared = {
33 success: Project,
34 failure: OrchestratorMcpFailure,
35 failureMode: "return" as const,
36 dependencies: [
37 McpInvocationContext.McpInvocationContext,
38 ThreadManagementService.ThreadManagementService,
39 ProjectService.ProjectService,
40 Crypto.Crypto,
41 ],
42};
43const ProjectListTool = Tool.make("t3_project_list", {
44 ...shared,
45 description:
46 "List registered projects in this environment. Pages use the current project snapshot and may shift between calls.",
47 parameters: Schema.Struct({
48 cursor: Schema.optional(NonNegativeInt),
49 limit: Schema.optional(Schema.Int.check(Schema.isBetween({ minimum: 1, maximum: 100 }))),
50 }),
51 success: Schema.Struct({
52 projects: Schema.Array(Project),
53 nextCursor: Schema.NullOr(NonNegativeInt),
54 }),
55})
56 .annotate(Tool.Readonly, true)
57 .annotate(Tool.Destructive, false);
58const ProjectReadTool = Tool.make("t3_project_read", {
59 ...shared,
60 description:
61 "Read a registered project in this environment, including its workspace and saved scripts.",
62 parameters: Schema.Struct({ projectId: ProjectId }),
63})
64 .annotate(Tool.Readonly, true)
65 .annotate(Tool.Destructive, false);
66const ProjectCreateTool = Tool.make("t3_project_create", {
67 ...shared,
68 description:
69 "Register a project directory through the existing project service. Set createWorkspaceRootIfMissing to create a directory. Omit workspaceRoot to start a new project from just its title: the app makes a Git repository for it in its own projects folder, with a README, an icon, and a first commit (commitError says why a commit failed; the project exists either way). Each call creates a new request; an existing registered workspace is rejected. Clone separately with t3_project_clone when needed.",
70 parameters: Schema.Struct({
71 ...ProjectCreatePayload.fields,
72 workspaceRoot: Schema.optional(ProjectCreatePayload.fields.workspaceRoot),
73 }),
74 success: Schema.Struct({ ...Project.fields, commitError: Schema.optional(Schema.String) }),
75 dependencies: [...shared.dependencies, ManagedProjectFolders.ManagedProjectFolders],
76}).annotate(Tool.Destructive, true);
77const ProjectUpdateTool = Tool.make("t3_project_update", {
78 ...shared,
79 description:
80 "Update a registered project's settings. Omitted fields are preserved. Uses the same project service as the app.",
81 parameters: Schema.Struct({ projectId: ProjectId, ...ProjectUpdatePayload.fields }),
82}).annotate(Tool.Destructive, true);
83const ProjectDeleteTool = Tool.make("t3_project_delete", {
84 ...shared,
85 description:
86 "Delete a project using the existing project deletion lifecycle. Nonempty projects require force=true. This does not delete the repository directory or promise a deleted-thread count.",
87 parameters: Schema.Struct({ projectId: ProjectId, force: Schema.optionalKey(Schema.Boolean) }),
88}).annotate(Tool.Destructive, true);
89const ProjectCloneTool = Tool.make("t3_project_clone", {
90 ...shared,
91 description:
92 "Clone a repository using the app's source-control service. This only clones; register the returned cwd with t3_project_create. An existing destination is not adopted or removed on failure.",
93 parameters: SourceControlCloneRepositoryInput,
94 success: SourceControlCloneRepositoryResult,
95 dependencies: [
96 ...shared.dependencies,
97 SourceControlRepositoryService.SourceControlRepositoryService,
98 ],
99})
100 .annotate(Tool.Destructive, true)
101 .annotate(Tool.OpenWorld, true);
102const ThreadLaunchTool = Tool.make("t3_thread_launch", {
103 ...shared,
104 description:
105 'Create an ordinary TOP-LEVEL thread with an explicit workspace binding before its agent starts. Use this when the user requests independent work, a new thread, or a PR stack in its own worktree; use delegate_task for child subagents. Set workspaceStrategy to {type:"worktree",baseRef:"parent-branch",branch:"new-branch",startFromOrigin:false} for a new worktree based on local commits, or {type:"existing_worktree",worktreePath:"/absolute/path",branch:"existing-branch"} to use an existing checkout. For upstream commits, set startFromOrigin:true. Omitted workspaceStrategy means the project root, NOT the caller\'s worktree. Omit projectId/modelSelection/modes to inherit those settings. Set scratch:true instead of projectId for a thread without a project: it runs in a fresh folder of its own, outside any repository. Put the task in message. Do not ask the agent to create its own worktree via shell: that does not update the thread binding. Each call creates a new launch with no retry key; retain threadId and use t3_thread_read/t3_thread_wait to follow preparation. After errors or lost responses, inspect t3_thread_list before retrying. Attachments must be pending uploads. Requires a full-access/default caller.',
106 parameters: Schema.Struct({
107 projectId: Schema.optional(ProjectId),
108 scratch: Schema.optional(
109 Schema.Boolean.annotate({
110 description:
111 "Launch without a project, in its own folder under the environment's Scratch project. Not with projectId or workspaceStrategy.",
112 }),
113 ),
114 title: TrimmedNonEmptyString,
115 modelSelection: Schema.optional(ModelSelection),
116 runtimeMode: Schema.optional(RuntimeMode),
117 interactionMode: Schema.optional(ProviderInteractionMode),
118 workspaceStrategy: Schema.optional(
119 OrchestrationV2ThreadLaunchWorkspaceStrategy.annotate({
120 description:
121 "Choose where this thread runs before starting its agent: worktree creates and binds a new checkout from baseRef; existing_worktree binds worktreePath; root uses the project checkout. Omitted means root, not the caller's worktree. For a PR stack use the parent branch as baseRef and startFromOrigin:false. Uncommitted changes are not copied.",
122 }),
123 ),
124 message: Schema.optional(
125 Schema.String.check(Schema.isMaxLength(120000)).annotate({
126 description:
127 "First task prompt, delivered after workspace preparation. Omit message and attachments to create an idle thread.",
128 }),
129 ),
130 attachments: Schema.optional(Schema.Array(McpAttachmentInput).check(Schema.isMaxLength(8))),
131 }),
132 success: Schema.Struct({
133 threadId: ThreadId,
134 projectId: ProjectId,
135 modelSelection: ModelSelection,
136 runId: Schema.NullOr(RunId),
137 status: Schema.NullOr(OrchestrationV2RunStatus),
138 }),
139 dependencies: [
140 ...shared.dependencies,
141 ThreadLaunchService.ThreadLaunchService,
142 ManagedProjectFolders.ManagedProjectFolders,
143 FileSystem.FileSystem,
144 ServerConfig.ServerConfig,
145 ],
146})
147 .annotate(Tool.Destructive, true)
148 .annotate(Tool.OpenWorld, true);
149
150export const ProjectToolkit = Toolkit.make(
151 ThreadLaunchTool,
152 ProjectListTool,
153 ProjectReadTool,
154 ProjectCreateTool,
155 ProjectUpdateTool,
156 ProjectDeleteTool,
157 ProjectCloneTool,
158);