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