Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

t3McpToolPresentation.ts

369 lines13.3 KB

1export type T3McpToolLogo = "t3-code";
2​
3export interface T3McpToolPresentation {
4 readonly displayName: string;
5 readonly logo: T3McpToolLogo;
6}
7​
8export type T3McpToolSummaryAction =
9 | "capabilities"
10 | "delegate"
11 | "task-status"
12 | "task-cancel"
13 | "schedule-run"
14 | "schedule-create"
15 | "schedule-list"
16 | "schedule-update"
17 | "schedule-delete"
18 | "thread-create"
19 | "thread-list"
20 | "thread-read"
21 | "thread-send"
22 | "thread-wait"
23 | "thread-interrupt"
24 | "thread-configuration"
25 | "thread-configure"
26 | "thread-fork"
27 | "thread-merge"
28 | "thread-search"
29 | "thread-transfers"
30 | "thread-organize"
31 | "thread-update"
32 | "queue-list"
33 | "queue-read"
34 | "queue-edit"
35 | "queue-cancel"
36 | "queue-reorder"
37 | "queue-steer"
38 | "question-list"
39 | "question-read"
40 | "question-respond"
41 | "secret-request"
42 | "worktree-handoff"
43 | "worktree-list"
44 | "worktree-status"
45 | "project-list"
46 | "project-read"
47 | "project-create"
48 | "project-update"
49 | "project-delete"
50 | "project-clone"
51 | "environment-read"
52 | "environment-update"
53 | "attachment-prepare"
54 | "attachment-discard"
55 | "attachment-send"
56 | "link-pr"
57 | "unlink-pr"
58 | "list-prs"
59 | "watch-pr"
60 | "unwatch-pr"
61 | "browser"
62 | "device"
63 | "html-preview"
64 | "html-render";
65​
66export interface T3McpToolDefinition {
67 readonly displayName: string;
68 readonly labels: readonly [action: string, running: string, completed: string, detail: string];
69 readonly icon: "t3-code" | "browser" | "device" | "pull-request";
70 readonly summaryAction: T3McpToolSummaryAction;
72​
73function tool(
74 labels: T3McpToolDefinition["labels"],
75 summaryAction: T3McpToolSummaryAction,
76 icon: T3McpToolDefinition["icon"] = "t3-code",
77 displayName = `${labels[0]} ${labels[3]}`,
78): T3McpToolDefinition {
79 return { displayName, labels, icon, summaryAction };
81​
82const T3_MCP_SERVER_ALIASES = new Set(["t3-code", "t3_code", "t3code"]);
83​
84// Cards, activity rows, summaries, and provider identity recovery share this inventory.
85const T3_MCP_TOOLS: Readonly<Record<string, T3McpToolDefinition>> = {
86 link_pull_request: tool(
87 ["Link", "Linking", "Linked", "a pull request"],
88 "link-pr",
89 "pull-request",
90 ),
91 unlink_pull_request: tool(
92 ["Unlink", "Unlinking", "Unlinked", "a pull request"],
93 "unlink-pr",
94 "pull-request",
95 ),
96 list_thread_pull_requests: tool(
97 ["Check", "Checking", "Checked", "linked pull requests"],
98 "list-prs",
99 "pull-request",
100 ),
101 watch_pull_request: tool(
102 ["Watch", "Watching", "Watching", "a pull request"],
103 "watch-pr",
104 "pull-request",
105 ),
106 unwatch_pull_request: tool(
107 ["Stop watching", "Stopping watching", "Stopped watching", "a pull request"],
108 "unwatch-pr",
109 "pull-request",
110 ),
111 orchestrator_capabilities: tool(
112 ["Get", "Getting", "Got", "orchestration capabilities"],
113 "capabilities",
114 ),
115 delegate_task: tool(["Delegate", "Delegating", "Delegated", "a child task"], "delegate"),
116 task_status: tool(["Get", "Getting", "Got", "delegated task status"], "task-status"),
117 task_cancel: tool(
118 ["Cancel", "Canceling", "Requested cancellation of", "delegated task"],
119 "task-cancel",
120 ),
121 schedule_task: tool(
122 ["Schedule", "Scheduling", "Scheduled", "a recurring task"],
123 "schedule-create",
124 ),
125 list_scheduled_tasks: tool(["List", "Listing", "Listed", "scheduled tasks"], "schedule-list"),
126 update_scheduled_task: tool(
127 ["Update", "Updating", "Updated", "a scheduled task"],
128 "schedule-update",
129 ),
130 delete_scheduled_task: tool(
131 ["Delete", "Deleting", "Requested deletion of", "a scheduled task"],
132 "schedule-delete",
133 ),
134 request_secret: tool(["Ask for", "Asking for", "Asked for", "a secret"], "secret-request"),
135 create_threads: tool(["Create", "Creating", "Created", "T3 threads"], "thread-create"),
136 t3_thread_start: tool(["Start", "Starting", "Started", "a T3 thread"], "thread-create"),
137 t3_thread_list: tool(["List", "Listing", "Listed", "T3 threads"], "thread-list"),
138 t3_thread_read: tool(["Read", "Reading", "Read", "a T3 thread"], "thread-read"),
139 t3_thread_send: tool(["Send", "Sending", "Sent", "to a T3 thread"], "thread-send"),
140 t3_thread_wait: tool(["Wait", "Waiting", "Waited", "for a T3 thread"], "thread-wait"),
141 t3_thread_interrupt: tool(
142 ["Interrupt", "Interrupting", "Requested an interrupt of", "a T3 thread"],
143 "thread-interrupt",
144 ),
145 t3_worktree_handoff: tool(
146 ["Hand off", "Handing off", "Handed off", "thread to a git worktree"],
147 "worktree-handoff",
148 ),
149 t3_worktree_status: tool(["Get", "Getting", "Got", "thread worktree status"], "worktree-status"),
150 preview_status: tool(["Get", "Getting", "Got", "preview browser status"], "browser", "browser"),
151 preview_open: tool(
152 ["Open", "Opening", "Opened", "a page in the preview browser"],
153 "browser",
154 "browser",
155 ),
156 preview_navigate: tool(
157 ["Navigate", "Navigating", "Navigated", "the preview browser"],
158 "browser",
159 "browser",
160 ),
161 preview_snapshot: tool(
162 ["Take a snapshot of", "Taking a snapshot of", "Took a snapshot of", "the preview page"],
163 "browser",
164 "browser",
165 "Snapshot the preview page",
166 ),
167 preview_click: tool(
168 ["Click", "Clicking", "Clicked", "in the preview browser"],
169 "browser",
170 "browser",
171 ),
172 preview_press: tool(
173 ["Press", "Pressing", "Pressed", "a key in the preview browser"],
174 "browser",
175 "browser",
176 ),
177 preview_type: tool(["Type", "Typing", "Typed", "in the preview browser"], "browser", "browser"),
178 preview_scroll: tool(
179 ["Scroll", "Scrolling", "Scrolled", "the preview browser"],
180 "browser",
181 "browser",
182 ),
183 preview_resize: tool(
184 ["Resize", "Resizing", "Resized", "the preview browser"],
185 "browser",
186 "browser",
187 ),
188 preview_evaluate: tool(
189 ["Evaluate", "Evaluating", "Evaluated", "script in the preview browser"],
190 "browser",
191 "browser",
192 ),
193 preview_wait_for: tool(
194 ["Wait", "Waiting", "Waited", "for the preview page"],
195 "browser",
196 "browser",
197 ),
198 preview_set_appearance: tool(
199 ["Set", "Setting", "Set", "preview browser appearance"],
200 "browser",
201 "browser",
202 ),
203 preview_recording_start: tool(
204 ["Start", "Starting", "Started", "recording the preview browser"],
205 "browser",
206 "browser",
207 ),
208 preview_recording_stop: tool(
209 ["Stop", "Stopping", "Stopped", "recording the preview browser"],
210 "browser",
211 "browser",
212 ),
213 device_list: tool(["List", "Listing", "Listed", "simulators and emulators"], "device", "device"),
214 device_open: tool(
215 ["Open", "Opening", "Opened", "a device in the Device panel"],
216 "device",
217 "device",
218 ),
219 device_screenshot: tool(
220 ["Take a screenshot of", "Taking a screenshot of", "Took a screenshot of", "the device"],
221 "device",
222 "device",
223 ),
224 device_close: tool(["Close", "Closing", "Closed", "a device"], "device", "device"),
225 run_scheduled_task_now: tool(
226 ["Run", "Running", "Requested a run of", "a scheduled task"],
227 "schedule-run",
228 ),
229 t3_queue_list: tool(["List", "Listing", "Listed", "queued messages"], "queue-list"),
230 t3_queue_read: tool(["Read", "Reading", "Read", "a queued message"], "queue-read"),
231 t3_queue_edit: tool(["Edit", "Editing", "Edited", "a queued message"], "queue-edit"),
232 t3_queue_cancel: tool(
233 ["Cancel", "Canceling", "Requested cancellation of", "a queued run"],
234 "queue-cancel",
235 ),
236 t3_queue_reorder: tool(["Reorder", "Reordering", "Reordered", "a queued run"], "queue-reorder"),
237 t3_queue_promote_to_steer: tool(
238 ["Steer with", "Steering with", "Requested steering with", "a queued message"],
239 "queue-steer",
240 ),
241 t3_pending_request_list: tool(
242 ["List", "Listing", "Listed", "pending questions"],
243 "question-list",
244 ),
245 t3_pending_request_read: tool(["Read", "Reading", "Read", "pending questions"], "question-read"),
246 t3_pending_request_respond: tool(
247 ["Answer", "Answering", "Answered", "pending questions"],
248 "question-respond",
249 ),
250 t3_thread_configuration: tool(
251 ["Read", "Reading", "Read", "thread configuration"],
252 "thread-configuration",
253 ),
254 t3_thread_configure: tool(["Set", "Setting", "Set", "thread model"], "thread-configure"),
255 t3_thread_fork: tool(["Fork", "Forking", "Requested a fork of", "this thread"], "thread-fork"),
256 t3_thread_merge_back: tool(
257 ["Merge", "Merging", "Requested a merge of", "thread context"],
258 "thread-merge",
259 ),
260 t3_thread_search: tool(["Search", "Searching", "Searched", "thread content"], "thread-search"),
261 t3_thread_transfers: tool(["Read", "Reading", "Read", "thread transfers"], "thread-transfers"),
262 t3_thread_organize: tool(["Organize", "Organizing", "Organized", "a thread"], "thread-organize"),
263 t3_thread_update: tool(["Update", "Updating", "Updated", "T3 thread metadata"], "thread-update"),
264 t3_worktree_list: tool(["List", "Listing", "Listed", "workspace branches"], "worktree-list"),
265 t3_preview_list: tool(["List", "Listing", "Listed", "preview tabs"], "browser", "browser"),
266 t3_preview_close: tool(["Close", "Closing", "Closed", "a preview tab"], "browser", "browser"),
267 t3_environment_read: tool(
268 ["Read", "Reading", "Read", "environment preferences"],
269 "environment-read",
270 ),
271 t3_environment_preferences_update: tool(
272 ["Update", "Updating", "Updated", "environment preferences"],
273 "environment-update",
274 ),
275 t3_thread_launch: tool(["Launch", "Launching", "Launched", "a project thread"], "thread-create"),
276 t3_project_list: tool(["List", "Listing", "Listed", "projects"], "project-list"),
277 t3_project_read: tool(["Read", "Reading", "Read", "a project"], "project-read"),
278 t3_project_create: tool(["Register", "Registering", "Registered", "a project"], "project-create"),
279 t3_project_update: tool(["Update", "Updating", "Updated", "a project"], "project-update"),
280 t3_project_delete: tool(["Delete", "Deleting", "Deleted", "a project"], "project-delete"),
281 t3_project_clone: tool(["Clone", "Cloning", "Cloned", "a repository"], "project-clone"),
282 t3_attachment_prepare_upload: tool(
283 ["Prepare", "Preparing", "Prepared", "an attachment upload"],
284 "attachment-prepare",
285 ),
286 t3_attachment_discard: tool(
287 ["Discard", "Discarding", "Discarded", "a pending attachment"],
288 "attachment-discard",
289 ),
290 t3_thread_send_attachments: tool(["Send", "Sending", "Sent", "attachments"], "attachment-send"),
291 html_preview: tool(["Preview", "Previewing", "Previewed", "an HTML page"], "html-preview"),
292 html_render: tool(["Render", "Rendering", "Rendered", "an HTML page"], "html-render"),
293};
294​
295/**
296 * The T3 orchestration tool inventory, used to gate loose name matching on
297 * both the server (ACP MCP identity recovery) and the client (logo branding).
298 */
299export const T3_MCP_TOOL_NAMES: ReadonlySet<string> = new Set(Object.keys(T3_MCP_TOOLS));
300​
301function normalizeT3McpToolLabel(value: string): string {
302 return value.replace(/\s+(?:complete|completed)\s*$/i, "").trim();
304​
305/**
306 * ACP agents disagree on how the injected T3 server prefixes its tools:
307 * `mcp__t3-code__x` (Claude/Cursor), `t3-code.x` (Codex), plus single
308 * underscore, colon, slash, dash, and space separators seen from registry
309 * agents. The prefix match is deliberately loose because the display-name
310 * inventory is the real gate; unknown tools stay on the generic renderer.
311 */
312function resolveT3McpToolName(value: string): string | null {
313 const label = normalizeT3McpToolLabel(value);
314 const mcpMatch = /^mcp__(?<server>.+?)__(?<tool>.+)$/i.exec(label);
315 if (mcpMatch?.groups) {
316 const { server, tool } = mcpMatch.groups;
317 return server !== undefined &&
318 tool !== undefined &&
319 T3_MCP_SERVER_ALIASES.has(server.toLowerCase())
320 ? tool
321 : null;
322 }
323​
324 const namespaceMatch = /^(?<server>t3-code|t3_code|t3code)(?:[.:/]|\s*·\s*)(?<tool>.+)$/i.exec(
325 label,
326 );
327 if (namespaceMatch?.groups) {
328 return namespaceMatch.groups.tool ?? null;
329 }
330​
331 const prefixed = /^(?:mcp[-_]{1,2})?t3[-_ ]?code(?:__|[-_.:/ ])(?<tool>.+)$/i.exec(label);
332 const candidate = prefixed?.groups?.tool ?? label;
333 if (Object.hasOwn(T3_MCP_TOOLS, candidate)) return candidate;
334 // OpenCode 2 registers one server per thread, `t3-code-<thread>`, and joins
335 // it to the tool with `_`. Thread ids can hold `_` too, so take the longest
336 // known tool name that ends the label.
337 if (!/^t3-code-/i.test(label)) return null;
338 let longest: string | null = null;
339 for (const tool of Object.keys(T3_MCP_TOOLS)) {
340 if (label.endsWith(`_${tool}`) && tool.length > (longest?.length ?? 0)) longest = tool;
341 }
342 return longest;
344​
345/** The bare T3 tool name (`html_render`) for any provider's spelling of it. */
346export function resolveT3McpToolId(toolName: string | null | undefined): string | null {
347 const name = toolName == null ? null : resolveT3McpToolName(toolName);
348 return name !== null && Object.hasOwn(T3_MCP_TOOLS, name) ? name : null;
350​
351export function resolveT3McpToolDefinition(
352 toolName: string | null | undefined,
353): T3McpToolDefinition | null {
354 const name = toolName == null ? null : resolveT3McpToolName(toolName);
355 return name !== null && Object.hasOwn(T3_MCP_TOOLS, name) ? T3_MCP_TOOLS[name]! : null;
357​
358export function resolveT3McpToolPresentation(
359 toolName: string | null | undefined,
360): T3McpToolPresentation | null {
361 const definition = resolveT3McpToolDefinition(toolName);
362 return definition === null ? null : { displayName: definition.displayName, logo: "t3-code" };
364​
365export function resolveT3McpToolSummaryAction(
366 toolName: string | null | undefined,
367): T3McpToolSummaryAction | null {
368 return resolveT3McpToolDefinition(toolName)?.summaryAction ?? null;