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

t3McpToolPresentation.ts

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