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 OrchestrationV2WorkflowOrigin,
11 OrchestrationV2RunStatus,
12 OrchestrationV2ThreadLaunchWorkspaceStrategy,
13 RuntimeMode,
14 ProviderInteractionMode,
15 Project,
16 ProjectCreatePayload,
17 ProjectUpdatePayload,
18 ProjectId,
19 OrchestratorMcpClientRequestId,
20 OrchestratorMcpEnvironmentTarget,
21 OrchestratorMcpFailure,
22 SourceControlCloneRepositoryInput,
23 SourceControlCloneRepositoryResult,
24} from "@t3tools/contracts";
25import * as FileSystem from "effect/FileSystem";
26import * as DocumentText from "../../../provider/DocumentText.ts";
27import * as ServerConfig from "../../../config.ts";
28import * as ProviderRegistry from "../../../provider/ProviderRegistry.ts";
29import * as ServerSettings from "../../../serverSettings.ts";
30import * as ThreadLaunchService from "../../../orchestration-v2/ThreadLaunchService.ts";
31import * as Digest from "effect/crypto/Digest";
32import * as SecureRandom from "effect/crypto/SecureRandom";
33import * as Schema from "effect/Schema";
34import { Tool, Toolkit } from "effect/ai";
35import * as ProjectService from "../../../project/ProjectService.ts";
36import * as ProjectCloneTracker from "../../../project/ProjectCloneTracker.ts";
37import * as ManagedProjectFolders from "../../../project/ManagedProjectFolders.ts";
38import * as ThreadManagementService from "../../../orchestration-v2/ThreadManagementService.ts";
39import * as SourceControlRepositoryService from "../../../sourceControl/SourceControlRepositoryService.ts";
40import * as GitVcsDriver from "../../../vcs/GitVcsDriver.ts";
41import * as McpInvocationContext from "../../McpInvocationContext.ts";
42
43const shared = {
44 success: Project,
45 failure: OrchestratorMcpFailure,
46 failureMode: "return" as const,
47 dependencies: [
48 McpInvocationContext.McpInvocationContext,
49 ThreadManagementService.ThreadManagementService,
50 ProjectService.ProjectService,
51 ServerSettings.ServerSettingsService,
52 SecureRandom.SecureRandom,
53 ],
54};
55const ProjectListTool = Tool.make("t3_project_list", {
56 ...shared,
57 description: "List projects. Pages can shift.",
58 parameters: Schema.Struct({
59 environmentId: OrchestratorMcpEnvironmentTarget,
60 cursor: Schema.optional(NonNegativeInt),
61 limit: Schema.optional(clampedPositiveInt(100)),
62 }),
63 success: Schema.Struct({
64 projects: Schema.Array(Project),
65 nextCursor: Schema.NullOr(NonNegativeInt),
66 }),
67})
68 .annotate(Tool.Readonly, true)
69 .annotate(Tool.Destructive, false);
70const ProjectReadTool = Tool.make("t3_project_read", {
71 ...shared,
72 description: "Read one project: workspace and saved scripts.",
73 parameters: Schema.Struct({
74 environmentId: OrchestratorMcpEnvironmentTarget,
75 projectId: ProjectId,
76 }),
77})
78 .annotate(Tool.Readonly, true)
79 .annotate(Tool.Destructive, false);
80const ProjectCreateTool = Tool.make("t3_project_create", {
81 ...shared,
82 description:
83 "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.",
84 parameters: Schema.Struct({
85 environmentId: OrchestratorMcpEnvironmentTarget,
86 ...ProjectCreatePayload.fields,
87 workspaceRoot: Schema.optional(ProjectCreatePayload.fields.workspaceRoot),
88 }),
89 success: Schema.Struct({ ...Project.fields, commitError: Schema.optional(Schema.String) }),
90 dependencies: [...shared.dependencies, ManagedProjectFolders.ManagedProjectFolders],
91}).annotate(Tool.Destructive, true);
92const ProjectUpdateTool = Tool.make("t3_project_update", {
93 ...shared,
94 description: "Update one project's settings. Omitted fields are unchanged.",
95 parameters: Schema.Struct({
96 environmentId: OrchestratorMcpEnvironmentTarget,
97 projectId: ProjectId,
98 ...ProjectUpdatePayload.fields,
99 }),
100}).annotate(Tool.Destructive, true);
101const ProjectDeleteTool = Tool.make("t3_project_delete", {
102 ...shared,
103 description: "Delete one project. Nonempty needs `force: true`. Folder on disk stays.",
104 parameters: Schema.Struct({
105 environmentId: OrchestratorMcpEnvironmentTarget,
106 projectId: ProjectId,
107 force: Schema.optionalKey(Schema.Boolean),
108 }),
109 dependencies: [
110 ...shared.dependencies,
111 ProjectCloneTracker.ProjectCloneTracker,
112 ManagedProjectFolders.ManagedProjectFolders,
113 ],
114}).annotate(Tool.Destructive, true);
115const ProjectCloneTool = Tool.make("t3_project_clone", {
116 ...shared,
117 description:
118 "Clone a repository (`destinationPath` new or empty). Register after with `t3_project_create`, with the same `environmentId`.",
119 parameters: Schema.Struct({
120 environmentId: OrchestratorMcpEnvironmentTarget,
121 ...SourceControlCloneRepositoryInput.fields,
122 }),
123 success: SourceControlCloneRepositoryResult,
124 dependencies: [
125 ...shared.dependencies,
126 SourceControlRepositoryService.SourceControlRepositoryService,
127 ],
128})
129 .annotate(Tool.Destructive, true)
130 .annotate(Tool.OpenWorld, true);
131const ThreadLaunchTool = Tool.make("t3_thread_launch", {
132 ...shared,
133 description:
134 "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`.",
135 parameters: Schema.Struct({
136 environmentId: OrchestratorMcpEnvironmentTarget,
137 projectId: Schema.optional(ProjectId),
138 scratch: Schema.optional(
139 Schema.Boolean.annotate({
140 description:
141 "No project: a new Scratch folder. Not with `projectId` or `workspaceStrategy`.",
142 }),
143 ),
144 title: TrimmedNonEmptyString,
145 generateTitle: Schema.optional(Schema.Boolean),
146 modelSelection: Schema.optional(ModelSelection),
147 runtimeMode: Schema.optional(RuntimeMode),
148 interactionMode: Schema.optional(ProviderInteractionMode),
149 workspaceStrategy: Schema.optional(
150 OrchestrationV2ThreadLaunchWorkspaceStrategy.annotate({
151 description:
152 "'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.",
153 }),
154 ),
155 message: Schema.optional(
156 Schema.String.check(Schema.isMaxLength(120000)).annotate({
157 description: "First prompt. Omit it and `attachments` for idle.",
158 }),
159 ),
160 attachments: Schema.optional(Schema.Array(McpAttachmentInput).check(Schema.isMaxLength(8))),
161 outputSchema: Schema.optional(
162 Schema.Record(Schema.String, Schema.Json).annotate({
163 description: "As in `t3_thread_send`. Needs `message`.",
164 }),
165 ),
166 clientRequestId: Schema.optional(OrchestratorMcpClientRequestId),
167 /** Set by a linked environment launching its agent's delegated task here; ignored otherwise. */
168 delegatedFrom: Schema.optional(OrchestrationV2DelegatedFrom),
169 /** Set by a linked environment whose workflow run this thread is a step of; ignored otherwise. */
170 workflowRun: Schema.optional(OrchestrationV2WorkflowOrigin),
171 }),
172 success: Schema.Struct({
173 threadId: ThreadId,
174 link: Schema.optional(Schema.String),
175 projectId: ProjectId,
176 modelSelection: ModelSelection,
177 runId: Schema.NullOr(RunId),
178 status: Schema.NullOr(OrchestrationV2RunStatus),
179 }),
180 dependencies: [
181 ...shared.dependencies,
182 ThreadLaunchService.ThreadLaunchService,
183 ManagedProjectFolders.ManagedProjectFolders,
184 GitVcsDriver.GitVcsDriver,
185 FileSystem.FileSystem,
186 ServerConfig.ServerConfig,
187 ServerSettings.ServerSettingsService,
188 ProviderRegistry.ProviderRegistry,
189 DocumentText.DocumentText,
190 Digest.Digest,
191 ],
192})
193 .annotate(Tool.Destructive, true)
194 .annotate(Tool.OpenWorld, true);
195
196export const ProjectToolkit = Toolkit.make(
197 ThreadLaunchTool,
198 ProjectListTool,
199 ProjectReadTool,
200 ProjectCreateTool,
201 ProjectUpdateTool,
202 ProjectDeleteTool,
203 ProjectCloneTool,
204);