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