Open History to see the last commit
1import { McpAttachmentInput } from "../attachment/input.ts";
2import {
3 clampedPositiveInt,
4 NonNegativeInt,
5 ModelSelection,
6 TrimmedNonEmptyString,
7 ThreadId,
8 RunId,
9 OrchestrationV2DelegatedFrom,
10 OrchestrationV2RunStatus,
11 OrchestrationV2ThreadLaunchWorkspaceStrategy,
12 RuntimeMode,
13 ProviderInteractionMode,
14 Project,
15 ProjectCreatePayload,
16 ProjectUpdatePayload,
17 ProjectId,
18 OrchestratorMcpClientRequestId,
19 OrchestratorMcpEnvironmentTarget,
20 OrchestratorMcpFailure,
21 SourceControlCloneRepositoryInput,
22 SourceControlCloneRepositoryResult,
23} from "@t3tools/contracts";
24import * as FileSystem from "effect/FileSystem";
25import * as DocumentText from "../../../provider/DocumentText.ts";
26import * as ServerConfig from "../../../config.ts";
27import * as ProviderRegistry from "../../../provider/ProviderRegistry.ts";
28import * as ServerSettings from "../../../serverSettings.ts";
29import * as ThreadLaunchService from "../../../orchestration-v2/ThreadLaunchService.ts";
30import * as Digest from "effect/crypto/Digest";
31import * as SecureRandom from "effect/crypto/SecureRandom";
32import * as Schema from "effect/Schema";
33import { Tool, Toolkit } from "effect/ai";
34import * as ProjectService from "../../../project/ProjectService.ts";
35import * as ProjectCloneTracker from "../../../project/ProjectCloneTracker.ts";
36import * as ManagedProjectFolders from "../../../project/ManagedProjectFolders.ts";
37import * as ThreadManagementService from "../../../orchestration-v2/ThreadManagementService.ts";
38import * as SourceControlRepositoryService from "../../../sourceControl/SourceControlRepositoryService.ts";
39import * as GitVcsDriver from "../../../vcs/GitVcsDriver.ts";
40import * as McpInvocationContext from "../../McpInvocationContext.ts";
41
42const shared = {
43 success: Project,
44 failure: OrchestratorMcpFailure,
45 failureMode: "return" as const,
46 dependencies: [
47 McpInvocationContext.McpInvocationContext,
48 ThreadManagementService.ThreadManagementService,
49 ProjectService.ProjectService,
50 ServerSettings.ServerSettingsService,
51 SecureRandom.SecureRandom,
52 ],
53};
54const ProjectListTool = Tool.make("t3_project_list", {
55 ...shared,
56 description: "List projects. Pages can shift.",
57 parameters: Schema.Struct({
58 environmentId: OrchestratorMcpEnvironmentTarget,
59 cursor: Schema.optional(NonNegativeInt),
60 limit: Schema.optional(clampedPositiveInt(100)),
61 }),
62 success: Schema.Struct({
63 projects: Schema.Array(Project),
64 nextCursor: Schema.NullOr(NonNegativeInt),
65 }),
66})
67 .annotate(Tool.Readonly, true)
68 .annotate(Tool.Destructive, false);
69const ProjectReadTool = Tool.make("t3_project_read", {
70 ...shared,
71 description: "Read one project: workspace and saved scripts.",
72 parameters: Schema.Struct({
73 environmentId: OrchestratorMcpEnvironmentTarget,
74 projectId: ProjectId,
75 }),
76})
77 .annotate(Tool.Readonly, true)
78 .annotate(Tool.Destructive, false);
79const ProjectCreateTool = Tool.make("t3_project_create", {
80 ...shared,
81 description:
82 "Register a project folder. `createWorkspaceRootIfMissing` creates it; a registered folder is rejected. No `workspaceRoot`: makes a git repo from `title` with README, icon, first commit (`commitError` on failure; project still exists). Clone first with `t3_project_clone` if needed.",
83 parameters: Schema.Struct({
84 environmentId: OrchestratorMcpEnvironmentTarget,
85 ...ProjectCreatePayload.fields,
86 workspaceRoot: Schema.optional(ProjectCreatePayload.fields.workspaceRoot),
87 }),
88 success: Schema.Struct({ ...Project.fields, commitError: Schema.optional(Schema.String) }),
89 dependencies: [...shared.dependencies, ManagedProjectFolders.ManagedProjectFolders],
90}).annotate(Tool.Destructive, true);
91const ProjectUpdateTool = Tool.make("t3_project_update", {
92 ...shared,
93 description: "Update one project's settings. Omitted fields are unchanged.",
94 parameters: Schema.Struct({
95 environmentId: OrchestratorMcpEnvironmentTarget,
96 projectId: ProjectId,
97 ...ProjectUpdatePayload.fields,
98 }),
99}).annotate(Tool.Destructive, true);
100const ProjectDeleteTool = Tool.make("t3_project_delete", {
101 ...shared,
102 description: "Delete one project. Nonempty needs `force: true`. Folder on disk stays.",
103 parameters: Schema.Struct({
104 environmentId: OrchestratorMcpEnvironmentTarget,
105 projectId: ProjectId,
106 force: Schema.optionalKey(Schema.Boolean),
107 }),
108 dependencies: [
109 ...shared.dependencies,
110 ProjectCloneTracker.ProjectCloneTracker,
111 ManagedProjectFolders.ManagedProjectFolders,
112 ],
113}).annotate(Tool.Destructive, true);
114const ProjectCloneTool = Tool.make("t3_project_clone", {
115 ...shared,
116 description:
117 "Clone a repository (`destinationPath` new or empty). Register after with `t3_project_create`, with the same `environmentId`.",
118 parameters: Schema.Struct({
119 environmentId: OrchestratorMcpEnvironmentTarget,
120 ...SourceControlCloneRepositoryInput.fields,
121 }),
122 success: SourceControlCloneRepositoryResult,
123 dependencies: [
124 ...shared.dependencies,
125 SourceControlRepositoryService.SourceControlRepositoryService,
126 ],
127})
128 .annotate(Tool.Destructive, true)
129 .annotate(Tool.OpenWorld, true);
130const ThreadLaunchTool = Tool.make("t3_thread_launch", {
131 ...shared,
132 description:
133 "Create a top-level thread in its workspace before starting. Task in `message`. Omit `projectId`, model and modes to inherit yours (outside a thread, pass `projectId` or `scratch`); modes cannot exceed yours. On error or lost reply, reuse `clientRequestId`. Follow it with `t3_thread_read` or `t3_thread_wait`. Mention it with its `link`.",
134 parameters: Schema.Struct({
135 environmentId: OrchestratorMcpEnvironmentTarget,
136 projectId: Schema.optional(ProjectId),
137 scratch: Schema.optional(
138 Schema.Boolean.annotate({
139 description:
140 "No project: a new Scratch folder. Not with `projectId` or `workspaceStrategy`.",
141 }),
142 ),
143 title: TrimmedNonEmptyString,
144 generateTitle: Schema.optional(Schema.Boolean),
145 modelSelection: Schema.optional(ModelSelection),
146 runtimeMode: Schema.optional(RuntimeMode),
147 interactionMode: Schema.optional(ProviderInteractionMode),
148 workspaceStrategy: Schema.optional(
149 OrchestrationV2ThreadLaunchWorkspaceStrategy.annotate({
150 description:
151 "'worktree': new checkout from `baseRef`. Honor a requested base. Otherwise, independent work uses the default branch as `remote/branch` (e.g. `origin/main`) with `startFromOrigin: true`; with no remote, use the local default branch. Required unpublished commits and dependent or stacked work use their local base with `startFromOrigin: false`. 'existing_worktree': bind `worktreePath`, a project worktree. 'root': project checkout, the default, not your worktree. Uncommitted edits are not copied.",
152 }),
153 ),
154 message: Schema.optional(
155 Schema.String.check(Schema.isMaxLength(120000)).annotate({
156 description: "First prompt. Omit it and `attachments` for idle.",
157 }),
158 ),
159 attachments: Schema.optional(Schema.Array(McpAttachmentInput).check(Schema.isMaxLength(8))),
160 outputSchema: Schema.optional(
161 Schema.Record(Schema.String, Schema.Json).annotate({
162 description: "As in `t3_thread_send`. Needs `message`.",
163 }),
164 ),
165 clientRequestId: Schema.optional(OrchestratorMcpClientRequestId),
166 /** Set by a linked environment launching its agent's delegated task here; ignored otherwise. */
167 delegatedFrom: Schema.optional(OrchestrationV2DelegatedFrom),
168 }),
169 success: Schema.Struct({
170 threadId: ThreadId,
171 link: Schema.optional(Schema.String),
172 projectId: ProjectId,
173 modelSelection: ModelSelection,
174 runId: Schema.NullOr(RunId),
175 status: Schema.NullOr(OrchestrationV2RunStatus),
176 }),
177 dependencies: [
178 ...shared.dependencies,
179 ThreadLaunchService.ThreadLaunchService,
180 ManagedProjectFolders.ManagedProjectFolders,
181 GitVcsDriver.GitVcsDriver,
182 FileSystem.FileSystem,
183 ServerConfig.ServerConfig,
184 ServerSettings.ServerSettingsService,
185 ProviderRegistry.ProviderRegistry,
186 DocumentText.DocumentText,
187 Digest.Digest,
188 ],
189})
190 .annotate(Tool.Destructive, true)
191 .annotate(Tool.OpenWorld, true);
192
193export const ProjectToolkit = Toolkit.make(
194 ThreadLaunchTool,
195 ProjectListTool,
196 ProjectReadTool,
197 ProjectCreateTool,
198 ProjectUpdateTool,
199 ProjectDeleteTool,
200 ProjectCloneTool,
201);