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

t3McpToolPresentation.ts

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