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

t3McpToolPresentation.ts

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