1import {
2 BackgroundActivityProfile,
3 BackgroundActivityProfileSelection,
4 ExecutionEnvironmentDescriptor,
5 OrchestratorMcpFailure,
6 ServerSettings,
7 ServerSettingsPatch,
8} from "@t3tools/contracts";
9import * as Schema from "effect/Schema";
10import { Tool, Toolkit } from "effect/ai";
11import * as ServerEnvironment from "../../../environment/ServerEnvironment.ts";
12import * as ThreadCommandExecutor from "../../../orchestration-v2/ThreadCommandExecutor.ts";
13import * as ThreadManagementService from "../../../orchestration-v2/ThreadManagementService.ts";
14import * as Settings from "../../../serverSettings.ts";
15import * as McpInvocationContext from "../../McpInvocationContext.ts";
16
17const PreferenceFields = {
18 defaultThreadEnvMode: ServerSettings.fields.defaultThreadEnvMode,
19 newWorktreesStartFromOrigin: ServerSettings.fields.newWorktreesStartFromOrigin,
20 enableProviderUpdateChecks: ServerSettings.fields.enableProviderUpdateChecks,
21 backgroundActivity: Schema.Struct({ profile: BackgroundActivityProfileSelection }),
22 sourceControlWritingStyle: Schema.Struct({
23 mode: Schema.String,
24 followChangeRequestTemplates: Schema.Boolean,
25 customInstructions: Schema.String,
26 truncated: Schema.Boolean,
27 }),
28};
29const shared = {
30 failure: OrchestratorMcpFailure,
31 failureMode: "return" as const,
32 dependencies: [
33 McpInvocationContext.McpInvocationContext,
34 ThreadManagementService.ThreadManagementService,
35 ServerEnvironment.ServerEnvironment,
36 Settings.ServerSettingsService,
37 ThreadCommandExecutor.ThreadCommandExecutor,
38 ],
39};
40const EnvironmentReadTool = Tool.make("t3_environment_read", {
41 ...shared,
42 description:
43 "Read this server's identity and selected environment preferences. Provider/model availability is exposed by orchestrator_capabilities. Writing instructions are limited to 4,000 characters.",
44 success: Schema.Struct({
45 environmentId: ExecutionEnvironmentDescriptor.fields.environmentId,
46 label: Schema.String,
47 serverVersion: Schema.String,
48 platform: ExecutionEnvironmentDescriptor.fields.platform,
49 preferences: Schema.Struct(PreferenceFields),
50 }),
51})
52 .annotate(Tool.Readonly, true)
53 .annotate(Tool.Destructive, false);
54const EnvironmentPreferencesTool = Tool.make("t3_environment_preferences_update", {
55 ...shared,
56 description:
57 "Update selected environment-wide preferences through normal settings persistence and notifications. Requires a live full-access/default calling thread. Omitted fields are preserved; empty customInstructions clears them.",
58 parameters: Schema.Struct({
59 defaultThreadEnvMode: ServerSettingsPatch.fields.defaultThreadEnvMode,
60 newWorktreesStartFromOrigin: ServerSettingsPatch.fields.newWorktreesStartFromOrigin,
61 enableProviderUpdateChecks: ServerSettingsPatch.fields.enableProviderUpdateChecks,
62 backgroundActivity: Schema.optionalKey(Schema.Struct({ profile: BackgroundActivityProfile })),
63 sourceControlWritingStyle: ServerSettingsPatch.fields.sourceControlWritingStyle,
64 }),
65 success: Schema.Struct(PreferenceFields),
66}).annotate(Tool.Destructive, true);
67export const EnvironmentToolkit = Toolkit.make(EnvironmentReadTool, EnvironmentPreferencesTool);