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