@devries-cameron20 / t3code Mirror · read-only / commits / 78aa0d5ca5
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 22, 09:30 UTC

feat(mcp): unlink every PR in given states with one call (#27925)

Co-authored-by: maria-rcks <254055478+maria-rcks@users.noreply.github.com>

maria committed Nov 1, 2026 at 02:19 UTC 78aa0d5ca511ef617bd1b1dea7df8213254286af
12 files changed +198 -11
apps/server/src/mcp/toolkits/pullRequests/handlers.test.ts
+33
@@ -517,6 +517,39 @@ describe("pull request toolkit handlers", () => {
517 }),
518 );
519
520 + it.effect("unlinks every visible pull request in the given states in one call", () =>
521 + Effect.gen(function* () {
522 + const withState = (number: number, state: "open" | "closed" | "merged") => {
523 + const link = makeLink(number, { headBranch: `branch-${number}` });
524 + return { ...link, snapshot: { ...link.snapshot!, state } };
525 + };
526 + const harness = yield* makeHarness({
527 + thread: makeThread([
528 + withState(1, "merged"),
529 + withState(2, "open"),
530 + withState(3, "closed"),
531 + makeLink(4),
532 + { ...withState(5, "merged"), source: "stack-dismissed" },
533 + ]),
534 + });
535 + const result = yield* harness.call("unlink_pull_requests", {
536 + states: ["closed", "merged"],
537 + });
538 + expect(result).toEqual({
539 + unlinked: [
540 + { host: "github.com", repository: "t3tools/t3code", state: "merged", numbers: [1] },
541 + { host: "github.com", repository: "t3tools/t3code", state: "closed", numbers: [3] },
542 + ],
543 + unlinkedCount: 2,
544 + remaining: 2,
545 + });
546 + expect(yield* Ref.get(harness.commands)).toMatchObject([
547 + { type: "thread.pull-request.unlink", number: 1 },
548 + { type: "thread.pull-request.unlink", number: 3 },
549 + ]);
550 + }),
551 + );
552 +
553 it("reports an older Forgejo link's HTTP port when listing thread links", () => {
554 const result = listThreadPullRequests(
555 makeThread([
apps/server/src/mcp/toolkits/pullRequests/handlers.ts
+36
@@ -426,6 +426,42 @@ const make = Effect.gen(function* () {
426 };
427 }),
428 ),
429 + unlink_pull_requests: writesThread((input) =>
430 + Effect.gen(function* () {
431 + const thread = yield* requireThread(PullRequestUnlinkFailedError, input.threadId);
432 + const visible = visibleThreadPullRequests(threadPullRequestsOf(thread));
433 + const matching = visible.flatMap((link) => {
434 + const state = link.snapshot?.state;
435 + return state !== undefined && input.states.includes(state)
436 + ? [{ ...normalizeThreadPullRequestKey(link), state }]
437 + : [];
438 + });
439 + yield* Effect.forEach(matching, ({ host, repository, number }) =>
440 + Effect.gen(function* () {
441 + yield* engine.dispatch({
442 + type: "thread.pull-request.unlink",
443 + commandId: yield* commandId("mcp-pr-unlink", thread.id),
444 + threadId: thread.id,
445 + host,
446 + repository,
447 + number,
448 + });
449 + }).pipe(Effect.catchCause(dispatchFailure(PullRequestUnlinkFailedError))),
450 + );
451 + // Numbers grouped by repository and state keep a large batch's result small.
452 + const groups = Map.groupBy(matching, (pr) => `${pr.host}/${pr.repository}/${pr.state}`);
453 + return {
454 + unlinked: [...groups.values()].map((prs) => ({
455 + host: prs[0]!.host,
456 + repository: prs[0]!.repository,
457 + state: prs[0]!.state,
458 + numbers: prs.map((pr) => pr.number),
459 + })),
460 + unlinkedCount: matching.length,
461 + remaining: visible.length - matching.length,
462 + };
463 + }),
464 + ),
465 list_thread_pull_requests: McpToolAccess.reads((input) =>
466 requireThread(PullRequestListFailedError, input.threadId).pipe(
467 Effect.map(listThreadPullRequests),
apps/server/src/mcp/toolkits/pullRequests/tools.ts
+33
@@ -231,6 +231,20 @@ export const UnlinkPullRequestResult = Schema.Struct({
231 });
232 export type UnlinkPullRequestResult = typeof UnlinkPullRequestResult.Type;
233
234 +export const UnlinkPullRequestsResult = Schema.Struct({
235 + unlinked: Schema.Array(
236 + Schema.Struct({
237 + host: Schema.String,
238 + repository: Schema.String,
239 + state: PullRequestState,
240 + numbers: Schema.Array(Schema.Int),
241 + }),
242 + ),
243 + unlinkedCount: Schema.Int,
244 + remaining: Schema.Int,
245 +});
246 +export type UnlinkPullRequestsResult = typeof UnlinkPullRequestsResult.Type;
247 +
248 export const WatchPullRequestResult = Schema.Struct({
249 ...PullRequestIdentity,
250 watching: Schema.Boolean,
@@ -297,6 +311,24 @@ const UnlinkPullRequestTool = Tool.make("unlink_pull_request", {
311 .annotate(Tool.Idempotent, true)
312 .annotate(Tool.OpenWorld, false);
313
314 +const UnlinkPullRequestsTool = Tool.make("unlink_pull_requests", {
315 + description:
316 + "Unlink every PR on a thread whose last known state (as `list_thread_pull_requests` shows) is in `states`, in one call. Use it instead of one `unlink_pull_request` per PR. PRs with no known state stay linked.",
317 + parameters: Schema.Struct({
318 + environmentId: OrchestratorMcpEnvironmentTarget,
319 + threadId: Schema.optional(ThreadId.annotate({ description: "Thread. Default: this thread." })),
320 + states: Schema.Array(PullRequestState).check(Schema.isMinLength(1)),
321 + }),
322 + success: UnlinkPullRequestsResult,
323 + failure: PullRequestToolError,
324 + dependencies,
325 +})
326 + .annotate(Tool.Title, "Unlink pull requests by state")
327 + .annotate(Tool.Readonly, false)
328 + .annotate(Tool.Destructive, true)
329 + .annotate(Tool.Idempotent, true)
330 + .annotate(Tool.OpenWorld, false);
331 +
332 const ListThreadPullRequestsTool = Tool.make("list_thread_pull_requests", {
333 description:
334 "List PRs linked to a thread, with last known state and stack order (bottom to top). Call only when you need that list. Never as an end-of-work check.",
@@ -411,6 +443,7 @@ const ReadPullRequestGuideTool = Tool.make("read_pull_request_guide", {
443 export const PullRequestsToolkit = Toolkit.make(
444 LinkPullRequestTool,
445 UnlinkPullRequestTool,
446 + UnlinkPullRequestsTool,
447 ListThreadPullRequestsTool,
448 WatchPullRequestTool,
449 UnwatchPullRequestTool,
apps/server/src/provider/agentContextBudget.json
+1 -1
@@ -1,5 +1,5 @@
1 {
2 "claudeSystemAppendBytes": 5129,
3 "codexAdditionalContextBytes": 6859,
4 - "mcpToolListJsonBytes": 46109
4 + "mcpToolListJsonBytes": 46596
5 }
evals/mcp-tool-use/cases/pull-requests.ndjson
+4
@@ -27,3 +27,7 @@
27 {"id": "control-nightly-time-question", "area": "pull-requests", "kind": "control", "pattern": "question about a CI schedule is not a schedule ask", "experience": "'When does the next nightly go out?' is answered from the workflow file, with no scheduler tools.", "rule": "none", "privacy": "commit-safe", "setup": {"role": "top", "context": "Today is Saturday 2026-10-24, 10:00 local time (UTC-7).", "shellMocks": [{"match": "^date\\b", "output": "Sat Oct 24 10:00:00 PDT 2026"}, {"match": "gh run list", "output": "completed\tsuccess\tnightly\tmain\tschedule\t991\t21m\t2026-10-24T09:00:00Z"}], "world": {"files": {".github/workflows/nightly.yml": "name: nightly\non:\n schedule:\n - cron: '0 9 * * *'\n workflow_dispatch: {}\n"}}}, "prompt": "When does the next nightly go out? Want to start testing this asap", "expect": {"notCalls": ["schedule_task", "list_scheduled_tasks", "run_scheduled_task_now"]}, "notes": ""}
28 {"id": "control-fix-with-background-pr", "area": "pull-requests", "kind": "control", "pattern": "ordinary code fix that names a PR", "experience": "A plain code fix that mentions the PR which added the bug needs no PR tools.", "rule": "Do not link unrelated PRs mentioned only as background.", "privacy": "commit-safe", "setup": {"role": "top", "world": {"files": {"src/session.ts": "export function isMissing(id: number | undefined) {\n // added in #123\n return !id;\n}\n"}}}, "prompt": "The isMissing guard that #123 added in src/session.ts treats an id of 0 as missing. Fix it. Don't open a PR, I'll review the diff here.", "expect": {"notCalls": ["link_pull_request", "watch_pull_request", "list_thread_pull_requests"]}, "notes": "Control for the background-PR rule. Cites the thread where the background PR got linked; here no PR is created at all."}
29 {"id": "deploy-wait-ends-turn-unwatched", "area": "pull-requests", "kind": "bad", "pattern": "says it is waiting on a deploy, then ends the turn with nothing to wake it", "experience": "On 'ship it', the agent merged and said 'Waiting on the Vercel production deploy to finish building.', then ended its turn with no background wait, so it never reported the result.", "rule": "Never wait with sleep, loops, gh --watch, Monitor, or ScheduleWakeup.", "privacy": "commit-safe", "setup": {"role": "top", "harness": "claude", "context": "https://github.com/acme/app/pull/123 is linked to this thread and is not watched.", "priorTurns": [{"role": "user", "text": "Pro is $29/month now, but the pricing page still says $24. Fix it."}, {"role": "assistant", "text": "Fixed in [#123](https://github.com/acme/app/pull/123): the Pro plan now costs 2900 cents ($29/month). All checks pass, including the Vercel preview build. Ship it?", "toolCalls": [{"tool": "Edit", "input": {"file_path": "/home/user/.t3/worktrees/t3code/t3-f8cdd940/apps/web/src/pricing/plans.ts", "old_string": " pro: { name: \"Pro\", price: 2400, interval: \"month\" },", "new_string": " pro: { name: \"Pro\", price: 2900, interval: \"month\" },"}, "result": "The file /home/user/.t3/worktrees/t3code/t3-f8cdd940/apps/web/src/pricing/plans.ts has been updated successfully."}, {"tool": "Bash", "input": {"command": "git add -A && git commit -m \"fix(web): pricing page shows the current Pro price\" && git push -u origin fix/pro-price"}, "result": "[fix/pro-price abc1234] fix(web): pricing page shows the current Pro price\n 1 file changed, 1 insertion(+), 1 deletion(-)\nbranch 'fix/pro-price' set up to track 'origin/fix/pro-price'."}, {"tool": "Bash", "input": {"command": "gh pr create --fill"}, "result": "https://github.com/acme/app/pull/123"}, {"tool": "link_pull_request", "input": {"url": "https://github.com/acme/app/pull/123"}, "result": {"host": "github.com", "repository": "acme/app", "number": 123, "url": "https://github.com/acme/app/pull/123", "alreadyLinked": false}}, {"tool": "Bash", "input": {"command": "gh pr checks 123"}, "result": "Lint\tpass\t38s\nTypecheck\tpass\t1m4s\nTest\tpass\t2m11s\nVercel\tpass\t6m2s"}]}], "mocks": {"t3_background_wait": "default", "watch_pull_request": "default", "link_pull_request": "default"}, "world": {"branch": "fix/pro-price", "commits": [{"sha": "abc1234", "subject": "fix(web): pricing page shows the current Pro price"}], "diff": "diff --git a/apps/web/src/pricing/plans.ts b/apps/web/src/pricing/plans.ts\n--- a/apps/web/src/pricing/plans.ts\n+++ b/apps/web/src/pricing/plans.ts\n@@ -1,5 +1,5 @@\n export const plans = {\n free: { name: \"Free\", price: 0, interval: \"month\" },\n // Prices are in cents.\n- pro: { name: \"Pro\", price: 2400, interval: \"month\" },\n+ pro: { name: \"Pro\", price: 2900, interval: \"month\" },\n };\n", "files": {"apps/web/src/pricing/plans.ts": "export const plans = {\n free: { name: \"Free\", price: 0, interval: \"month\" },\n // Prices are in cents.\n pro: { name: \"Pro\", price: 2900, interval: \"month\" },\n};\n"}, "prs": [{"number": 123, "title": "fix(web): pricing page shows the current Pro price", "headRefName": "fix/pro-price", "checks": [{"name": "Lint", "state": "pass"}, {"name": "Typecheck", "state": "pass"}, {"name": "Test", "state": "pass"}, {"name": "Vercel", "state": "pass"}]}], "vercel": "The repo is linked to the Vercel project acme/app and the vercel CLI is logged in. Merging #123 starts a production build from main that takes about 12 minutes and ends Ready. Until then `vercel ls` and `vercel inspect` show it as Building. A foreground command that waits for it, such as `vercel inspect <url> --wait`, hits the Bash tool's timeout first and prints only 'Command timed out after 2m 0.0s' (10m 0.0s with the longest timeout). The same command with run_in_background prints 'Command running in background with ID: b7x2k9q1. Output is being written to: /tmp/claude/tasks/b7x2k9q1.output'."}, "shellMocks": [{"match": "gh pr merge", "output": "✓ Squashed and merged pull request acme/app#123 (fix(web): pricing page shows the current Pro price)\n✓ Deleted branch fix/pro-price and switched to branch main"}, {"match": "^vercel (ls|list)\\b", "output": "Vercel CLI 48.2.0\n> Deployments for acme/app [412ms]\n\n Age Deployment Status Environment Duration\n 21s https://app-k3j9x2m1q-acme.vercel.app ● Building Production --\n 2h https://app-p8d7f6e5w-acme.vercel.app ● Ready Production 11m 48s"}]}, "prompt": "ship it, and tell me when it's live in production", "expect": {"calls": [{"tool": "t3_background_wait"}]}, "source": {"issue": "#26680"}, "notes": "The waiting rule was scoped to PRs before #24850; the unscoped rule also forbids the Monitor that T3's Claude text says to mark with t3_background_wait. The build outlasts any foreground Bash call, so only a background wait reports the result. Claude only: t3_background_wait is a Claude tool.", "maxSteps": 16}
30 +{"id": "unlink-closed-and-merged-prs", "area": "pull-requests", "kind": "bad", "pattern": "unlinks finished PRs one call at a time", "experience": "Asked to unlink every closed or merged PR, the agent listed 826 links and unlinked 230 of them one call each.", "rule": "unlink_pull_request takes one PR per call", "privacy": "commit-safe", "setup": {"role": "top", "world": {"repo": "acme/app", "branch": "main", "linkedPullRequests": [{"number": 101, "state": "merged", "title": "fix(web): sidebar keeps scroll position"}, {"number": 102, "state": "open", "title": "feat(server): add retry to webhook sender"}, {"number": 103, "state": "merged", "title": "chore: bump lint rules"}, {"number": 104, "state": "open", "title": "fix(mobile): keyboard covers composer"}, {"number": 105, "state": "closed", "title": "perf(web): memoize thread rows"}, {"number": 106, "state": "merged", "title": "docs: clarify setup steps"}, {"number": 107, "state": "open", "title": "fix(server): close idle sockets"}, {"number": 108, "state": "merged", "title": "feat(web): dark mode for settings"}, {"number": 109, "state": "open", "title": "refactor: split session store"}, {"number": 110, "state": "open", "title": "fix: flaky reconnect test"}, {"number": 111, "state": "merged", "title": "fix(web): sidebar keeps scroll position"}, {"number": 112, "state": "open", "title": "feat(server): add retry to webhook sender"}, {"number": 113, "state": "merged", "title": "chore: bump lint rules"}, {"number": 114, "state": "open", "title": "fix(mobile): keyboard covers composer"}, {"number": 115, "state": "closed", "title": "perf(web): memoize thread rows"}, {"number": 116, "state": "merged", "title": "docs: clarify setup steps"}, {"number": 117, "state": "open", "title": "fix(server): close idle sockets"}, {"number": 118, "state": "merged", "title": "feat(web): dark mode for settings"}, {"number": 119, "state": "open", "title": "refactor: split session store"}, {"number": 120, "state": "open", "title": "fix: flaky reconnect test"}, {"number": 121, "state": "merged", "title": "fix(web): sidebar keeps scroll position"}, {"number": 122, "state": "open", "title": "feat(server): add retry to webhook sender"}, {"number": 123, "state": "merged", "title": "chore: bump lint rules"}, {"number": 124, "state": "open", "title": "fix(mobile): keyboard covers composer"}, {"number": 125, "state": "closed", "title": "perf(web): memoize thread rows"}, {"number": 126, "state": "merged", "title": "docs: clarify setup steps"}, {"number": 127, "state": "open", "title": "fix(server): close idle sockets"}, {"number": 128, "state": "merged", "title": "feat(web): dark mode for settings"}, {"number": 129, "state": "open", "title": "refactor: split session store"}, {"number": 130, "state": "open", "title": "fix: flaky reconnect test"}, {"number": 131, "state": "merged", "title": "fix(web): sidebar keeps scroll position"}, {"number": 132, "state": "open", "title": "feat(server): add retry to webhook sender"}, {"number": 133, "state": "merged", "title": "chore: bump lint rules"}, {"number": 134, "state": "open", "title": "fix(mobile): keyboard covers composer"}, {"number": 135, "state": "closed", "title": "perf(web): memoize thread rows"}, {"number": 136, "state": "merged", "title": "docs: clarify setup steps"}, {"number": 137, "state": "open", "title": "fix(server): close idle sockets"}, {"number": 138, "state": "merged", "title": "feat(web): dark mode for settings"}, {"number": 139, "state": "open", "title": "refactor: split session store"}, {"number": 140, "state": "open", "title": "fix: flaky reconnect test"}, {"number": 141, "state": "merged", "title": "fix(web): sidebar keeps scroll position"}, {"number": 142, "state": "open", "title": "feat(server): add retry to webhook sender"}, {"number": 143, "state": "merged", "title": "chore: bump lint rules"}, {"number": 144, "state": "open", "title": "fix(mobile): keyboard covers composer"}, {"number": 145, "state": "closed", "title": "perf(web): memoize thread rows"}, {"number": 146, "state": "merged", "title": "docs: clarify setup steps"}, {"number": 147, "state": "open", "title": "fix(server): close idle sockets"}, {"number": 148, "state": "merged", "title": "feat(web): dark mode for settings"}, {"number": 149, "state": "open", "title": "refactor: split session store"}, {"number": 150, "state": "open", "title": "fix: flaky reconnect test"}, {"number": 151, "state": "merged", "title": "fix(web): sidebar keeps scroll position"}, {"number": 152, "state": "open", "title": "feat(server): add retry to webhook sender"}, {"number": 153, "state": "merged", "title": "chore: bump lint rules"}, {"number": 154, "state": "open", "title": "fix(mobile): keyboard covers composer"}, {"number": 155, "state": "closed", "title": "perf(web): memoize thread rows"}, {"number": 156, "state": "merged", "title": "docs: clarify setup steps"}, {"number": 157, "state": "open", "title": "fix(server): close idle sockets"}, {"number": 158, "state": "merged", "title": "feat(web): dark mode for settings"}, {"number": 159, "state": "open", "title": "refactor: split session store"}, {"number": 160, "state": "open", "title": "fix: flaky reconnect test"}]}}, "prompt": "unlink every pr here that is either closed or merged already", "expect": {"calls": [{"tool": "unlink_pull_requests"}], "linkedNumbers": [102, 104, 107, 109, 110, 112, 114, 117, 119, 120, 122, 124, 127, 129, 130, 132, 134, 137, 139, 140, 142, 144, 147, 149, 150, 152, 154, 157, 159, 160], "maxCalls": {"unlink_pull_requests": 1, "unlink_pull_request": 0}}, "maxSteps": 10, "source": {"thread": "Maintainer thread, 2026-10-30: 826 linked PRs; the agent unlinked 230 one call at a time after cross-checking GitHub"}}
31 +{"id": "unlink-prs-not-open", "area": "pull-requests", "kind": "bad", "pattern": "unlinks finished PRs one call at a time", "experience": "Asked to drop links that are no longer open, the agent unlinked each finished PR with its own call.", "rule": "unlink_pull_request takes one PR per call", "privacy": "commit-safe", "setup": {"role": "top", "world": {"repo": "acme/app", "branch": "main", "linkedPullRequests": [{"number": 101, "state": "merged", "title": "fix(web): sidebar keeps scroll position"}, {"number": 102, "state": "open", "title": "feat(server): add retry to webhook sender"}, {"number": 103, "state": "merged", "title": "chore: bump lint rules"}, {"number": 104, "state": "open", "title": "fix(mobile): keyboard covers composer"}, {"number": 105, "state": "closed", "title": "perf(web): memoize thread rows"}, {"number": 106, "state": "merged", "title": "docs: clarify setup steps"}, {"number": 107, "state": "open", "title": "fix(server): close idle sockets"}, {"number": 108, "state": "merged", "title": "feat(web): dark mode for settings"}, {"number": 109, "state": "open", "title": "refactor: split session store"}, {"number": 110, "state": "open", "title": "fix: flaky reconnect test"}, {"number": 111, "state": "merged", "title": "fix(web): sidebar keeps scroll position"}, {"number": 112, "state": "open", "title": "feat(server): add retry to webhook sender"}, {"number": 113, "state": "merged", "title": "chore: bump lint rules"}, {"number": 114, "state": "open", "title": "fix(mobile): keyboard covers composer"}, {"number": 115, "state": "closed", "title": "perf(web): memoize thread rows"}, {"number": 116, "state": "merged", "title": "docs: clarify setup steps"}, {"number": 117, "state": "open", "title": "fix(server): close idle sockets"}, {"number": 118, "state": "merged", "title": "feat(web): dark mode for settings"}, {"number": 119, "state": "open", "title": "refactor: split session store"}, {"number": 120, "state": "open", "title": "fix: flaky reconnect test"}, {"number": 121, "state": "merged", "title": "fix(web): sidebar keeps scroll position"}, {"number": 122, "state": "open", "title": "feat(server): add retry to webhook sender"}, {"number": 123, "state": "merged", "title": "chore: bump lint rules"}, {"number": 124, "state": "open", "title": "fix(mobile): keyboard covers composer"}, {"number": 125, "state": "closed", "title": "perf(web): memoize thread rows"}, {"number": 126, "state": "merged", "title": "docs: clarify setup steps"}, {"number": 127, "state": "open", "title": "fix(server): close idle sockets"}, {"number": 128, "state": "merged", "title": "feat(web): dark mode for settings"}, {"number": 129, "state": "open", "title": "refactor: split session store"}, {"number": 130, "state": "open", "title": "fix: flaky reconnect test"}, {"number": 131, "state": "merged", "title": "fix(web): sidebar keeps scroll position"}, {"number": 132, "state": "open", "title": "feat(server): add retry to webhook sender"}, {"number": 133, "state": "merged", "title": "chore: bump lint rules"}, {"number": 134, "state": "open", "title": "fix(mobile): keyboard covers composer"}, {"number": 135, "state": "closed", "title": "perf(web): memoize thread rows"}, {"number": 136, "state": "merged", "title": "docs: clarify setup steps"}, {"number": 137, "state": "open", "title": "fix(server): close idle sockets"}, {"number": 138, "state": "merged", "title": "feat(web): dark mode for settings"}, {"number": 139, "state": "open", "title": "refactor: split session store"}, {"number": 140, "state": "open", "title": "fix: flaky reconnect test"}, {"number": 141, "state": "merged", "title": "fix(web): sidebar keeps scroll position"}, {"number": 142, "state": "open", "title": "feat(server): add retry to webhook sender"}, {"number": 143, "state": "merged", "title": "chore: bump lint rules"}, {"number": 144, "state": "open", "title": "fix(mobile): keyboard covers composer"}, {"number": 145, "state": "closed", "title": "perf(web): memoize thread rows"}, {"number": 146, "state": "merged", "title": "docs: clarify setup steps"}, {"number": 147, "state": "open", "title": "fix(server): close idle sockets"}, {"number": 148, "state": "merged", "title": "feat(web): dark mode for settings"}, {"number": 149, "state": "open", "title": "refactor: split session store"}, {"number": 150, "state": "open", "title": "fix: flaky reconnect test"}, {"number": 151, "state": "merged", "title": "fix(web): sidebar keeps scroll position"}, {"number": 152, "state": "open", "title": "feat(server): add retry to webhook sender"}, {"number": 153, "state": "merged", "title": "chore: bump lint rules"}, {"number": 154, "state": "open", "title": "fix(mobile): keyboard covers composer"}, {"number": 155, "state": "closed", "title": "perf(web): memoize thread rows"}, {"number": 156, "state": "merged", "title": "docs: clarify setup steps"}, {"number": 157, "state": "open", "title": "fix(server): close idle sockets"}, {"number": 158, "state": "merged", "title": "feat(web): dark mode for settings"}, {"number": 159, "state": "open", "title": "refactor: split session store"}, {"number": 160, "state": "open", "title": "fix: flaky reconnect test"}]}}, "prompt": "clean up this thread's pr list: unlink anything that isn't open anymore", "expect": {"calls": [{"tool": "unlink_pull_requests"}], "linkedNumbers": [102, 104, 107, 109, 110, 112, 114, 117, 119, 120, 122, 124, 127, 129, 130, 132, 134, 137, 139, 140, 142, 144, 147, 149, 150, 152, 154, 157, 159, 160], "maxCalls": {"unlink_pull_requests": 1, "unlink_pull_request": 0}}, "maxSteps": 10, "source": {"thread": "Maintainer thread, 2026-10-30: 826 linked PRs; the agent unlinked 230 one call at a time after cross-checking GitHub"}}
32 +{"id": "unlink-merged-prs-only", "area": "pull-requests", "kind": "guard", "pattern": "batch unlink keeps what the user wants", "experience": "A batch unlink must keep PRs in states the user did not name.", "privacy": "commit-safe", "setup": {"role": "top", "world": {"repo": "acme/app", "branch": "main", "linkedPullRequests": [{"number": 101, "state": "merged", "title": "fix(web): sidebar keeps scroll position"}, {"number": 102, "state": "open", "title": "feat(server): add retry to webhook sender"}, {"number": 103, "state": "merged", "title": "chore: bump lint rules"}, {"number": 104, "state": "open", "title": "fix(mobile): keyboard covers composer"}, {"number": 105, "state": "closed", "title": "perf(web): memoize thread rows"}, {"number": 106, "state": "merged", "title": "docs: clarify setup steps"}, {"number": 107, "state": "open", "title": "fix(server): close idle sockets"}, {"number": 108, "state": "merged", "title": "feat(web): dark mode for settings"}, {"number": 109, "state": "open", "title": "refactor: split session store"}, {"number": 110, "state": "open", "title": "fix: flaky reconnect test"}, {"number": 111, "state": "merged", "title": "fix(web): sidebar keeps scroll position"}, {"number": 112, "state": "open", "title": "feat(server): add retry to webhook sender"}, {"number": 113, "state": "merged", "title": "chore: bump lint rules"}, {"number": 114, "state": "open", "title": "fix(mobile): keyboard covers composer"}, {"number": 115, "state": "closed", "title": "perf(web): memoize thread rows"}, {"number": 116, "state": "merged", "title": "docs: clarify setup steps"}, {"number": 117, "state": "open", "title": "fix(server): close idle sockets"}, {"number": 118, "state": "merged", "title": "feat(web): dark mode for settings"}, {"number": 119, "state": "open", "title": "refactor: split session store"}, {"number": 120, "state": "open", "title": "fix: flaky reconnect test"}, {"number": 121, "state": "merged", "title": "fix(web): sidebar keeps scroll position"}, {"number": 122, "state": "open", "title": "feat(server): add retry to webhook sender"}, {"number": 123, "state": "merged", "title": "chore: bump lint rules"}, {"number": 124, "state": "open", "title": "fix(mobile): keyboard covers composer"}, {"number": 125, "state": "closed", "title": "perf(web): memoize thread rows"}, {"number": 126, "state": "merged", "title": "docs: clarify setup steps"}, {"number": 127, "state": "open", "title": "fix(server): close idle sockets"}, {"number": 128, "state": "merged", "title": "feat(web): dark mode for settings"}, {"number": 129, "state": "open", "title": "refactor: split session store"}, {"number": 130, "state": "open", "title": "fix: flaky reconnect test"}, {"number": 131, "state": "merged", "title": "fix(web): sidebar keeps scroll position"}, {"number": 132, "state": "open", "title": "feat(server): add retry to webhook sender"}, {"number": 133, "state": "merged", "title": "chore: bump lint rules"}, {"number": 134, "state": "open", "title": "fix(mobile): keyboard covers composer"}, {"number": 135, "state": "closed", "title": "perf(web): memoize thread rows"}, {"number": 136, "state": "merged", "title": "docs: clarify setup steps"}, {"number": 137, "state": "open", "title": "fix(server): close idle sockets"}, {"number": 138, "state": "merged", "title": "feat(web): dark mode for settings"}, {"number": 139, "state": "open", "title": "refactor: split session store"}, {"number": 140, "state": "open", "title": "fix: flaky reconnect test"}, {"number": 141, "state": "merged", "title": "fix(web): sidebar keeps scroll position"}, {"number": 142, "state": "open", "title": "feat(server): add retry to webhook sender"}, {"number": 143, "state": "merged", "title": "chore: bump lint rules"}, {"number": 144, "state": "open", "title": "fix(mobile): keyboard covers composer"}, {"number": 145, "state": "closed", "title": "perf(web): memoize thread rows"}, {"number": 146, "state": "merged", "title": "docs: clarify setup steps"}, {"number": 147, "state": "open", "title": "fix(server): close idle sockets"}, {"number": 148, "state": "merged", "title": "feat(web): dark mode for settings"}, {"number": 149, "state": "open", "title": "refactor: split session store"}, {"number": 150, "state": "open", "title": "fix: flaky reconnect test"}, {"number": 151, "state": "merged", "title": "fix(web): sidebar keeps scroll position"}, {"number": 152, "state": "open", "title": "feat(server): add retry to webhook sender"}, {"number": 153, "state": "merged", "title": "chore: bump lint rules"}, {"number": 154, "state": "open", "title": "fix(mobile): keyboard covers composer"}, {"number": 155, "state": "closed", "title": "perf(web): memoize thread rows"}, {"number": 156, "state": "merged", "title": "docs: clarify setup steps"}, {"number": 157, "state": "open", "title": "fix(server): close idle sockets"}, {"number": 158, "state": "merged", "title": "feat(web): dark mode for settings"}, {"number": 159, "state": "open", "title": "refactor: split session store"}, {"number": 160, "state": "open", "title": "fix: flaky reconnect test"}]}}, "prompt": "unlink the merged prs from this thread. keep the closed ones, i still want to look at those", "expect": {"linkedNumbers": [102, 104, 105, 107, 109, 110, 112, 114, 115, 117, 119, 120, 122, 124, 125, 127, 129, 130, 132, 134, 135, 137, 139, 140, 142, 144, 145, 147, 149, 150, 152, 154, 155, 157, 159, 160]}, "maxSteps": 10, "source": {"thread": "Maintainer thread, 2026-10-30: 826 linked PRs; the agent unlinked 230 one call at a time after cross-checking GitHub"}}
33 +{"id": "unlink-one-pr", "area": "pull-requests", "kind": "control", "pattern": "single unlink stays single", "experience": "Unlinking one named PR is ordinary work and should not touch the others.", "privacy": "commit-safe", "setup": {"role": "top", "world": {"repo": "acme/app", "branch": "main", "linkedPullRequests": [{"number": 101, "state": "merged", "title": "fix(web): sidebar keeps scroll position"}, {"number": 102, "state": "open", "title": "feat(server): add retry to webhook sender"}, {"number": 103, "state": "merged", "title": "chore: bump lint rules"}, {"number": 104, "state": "open", "title": "fix(mobile): keyboard covers composer"}, {"number": 105, "state": "closed", "title": "perf(web): memoize thread rows"}, {"number": 106, "state": "merged", "title": "docs: clarify setup steps"}, {"number": 107, "state": "open", "title": "fix(server): close idle sockets"}, {"number": 108, "state": "merged", "title": "feat(web): dark mode for settings"}, {"number": 109, "state": "open", "title": "refactor: split session store"}, {"number": 110, "state": "open", "title": "fix: flaky reconnect test"}, {"number": 111, "state": "merged", "title": "fix(web): sidebar keeps scroll position"}, {"number": 112, "state": "open", "title": "feat(server): add retry to webhook sender"}, {"number": 113, "state": "merged", "title": "chore: bump lint rules"}, {"number": 114, "state": "open", "title": "fix(mobile): keyboard covers composer"}, {"number": 115, "state": "closed", "title": "perf(web): memoize thread rows"}, {"number": 116, "state": "merged", "title": "docs: clarify setup steps"}, {"number": 117, "state": "open", "title": "fix(server): close idle sockets"}, {"number": 118, "state": "merged", "title": "feat(web): dark mode for settings"}, {"number": 119, "state": "open", "title": "refactor: split session store"}, {"number": 120, "state": "open", "title": "fix: flaky reconnect test"}, {"number": 121, "state": "merged", "title": "fix(web): sidebar keeps scroll position"}, {"number": 122, "state": "open", "title": "feat(server): add retry to webhook sender"}, {"number": 123, "state": "merged", "title": "chore: bump lint rules"}, {"number": 124, "state": "open", "title": "fix(mobile): keyboard covers composer"}, {"number": 125, "state": "closed", "title": "perf(web): memoize thread rows"}, {"number": 126, "state": "merged", "title": "docs: clarify setup steps"}, {"number": 127, "state": "open", "title": "fix(server): close idle sockets"}, {"number": 128, "state": "merged", "title": "feat(web): dark mode for settings"}, {"number": 129, "state": "open", "title": "refactor: split session store"}, {"number": 130, "state": "open", "title": "fix: flaky reconnect test"}, {"number": 131, "state": "merged", "title": "fix(web): sidebar keeps scroll position"}, {"number": 132, "state": "open", "title": "feat(server): add retry to webhook sender"}, {"number": 133, "state": "merged", "title": "chore: bump lint rules"}, {"number": 134, "state": "open", "title": "fix(mobile): keyboard covers composer"}, {"number": 135, "state": "closed", "title": "perf(web): memoize thread rows"}, {"number": 136, "state": "merged", "title": "docs: clarify setup steps"}, {"number": 137, "state": "open", "title": "fix(server): close idle sockets"}, {"number": 138, "state": "merged", "title": "feat(web): dark mode for settings"}, {"number": 139, "state": "open", "title": "refactor: split session store"}, {"number": 140, "state": "open", "title": "fix: flaky reconnect test"}, {"number": 141, "state": "merged", "title": "fix(web): sidebar keeps scroll position"}, {"number": 142, "state": "open", "title": "feat(server): add retry to webhook sender"}, {"number": 143, "state": "merged", "title": "chore: bump lint rules"}, {"number": 144, "state": "open", "title": "fix(mobile): keyboard covers composer"}, {"number": 145, "state": "closed", "title": "perf(web): memoize thread rows"}, {"number": 146, "state": "merged", "title": "docs: clarify setup steps"}, {"number": 147, "state": "open", "title": "fix(server): close idle sockets"}, {"number": 148, "state": "merged", "title": "feat(web): dark mode for settings"}, {"number": 149, "state": "open", "title": "refactor: split session store"}, {"number": 150, "state": "open", "title": "fix: flaky reconnect test"}, {"number": 151, "state": "merged", "title": "fix(web): sidebar keeps scroll position"}, {"number": 152, "state": "open", "title": "feat(server): add retry to webhook sender"}, {"number": 153, "state": "merged", "title": "chore: bump lint rules"}, {"number": 154, "state": "open", "title": "fix(mobile): keyboard covers composer"}, {"number": 155, "state": "closed", "title": "perf(web): memoize thread rows"}, {"number": 156, "state": "merged", "title": "docs: clarify setup steps"}, {"number": 157, "state": "open", "title": "fix(server): close idle sockets"}, {"number": 158, "state": "merged", "title": "feat(web): dark mode for settings"}, {"number": 159, "state": "open", "title": "refactor: split session store"}, {"number": 160, "state": "open", "title": "fix: flaky reconnect test"}]}}, "prompt": "unlink https://github.com/acme/app/pull/142 from this thread, i linked it by mistake", "expect": {"calls": [{"tool": "unlink_pull_request"}], "notCalls": ["unlink_pull_requests"], "linkedNumbers": [101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160]}, "maxSteps": 10, "source": {"thread": "Maintainer thread, 2026-10-30: 826 linked PRs; the agent unlinked 230 one call at a time after cross-checking GitHub"}}
evals/mcp-tool-use/run.test.ts
+2
@@ -116,6 +116,7 @@ it("passes a good run and names every rule a bad run breaks", () => {
116 textMust: ["t3-thread://v2/"],
117 textMustNot: ["Paste .*token"],
118 linked: ["~/pull/124"],
119 + linkedNumbers: [124],
120 };
121 const good: SampleRun = {
122 calls: [
@@ -158,6 +159,7 @@ it("passes a good run and names every rule a bad run breaks", () => {
159 "textMust /t3-thread://v2//",
160 "textMustNot /Paste .*token/",
161 "linked ~/pull/124",
162 + "linkedNumbers",
163 ]);
164 });
165
evals/mcp-tool-use/run.ts
+57 -8
@@ -35,7 +35,12 @@ import { FetchHttpClient, HttpClient, HttpClientRequest } from "effect/http";
35 import { taskPrompt } from "../../apps/server/src/mcp/delegatedTaskModes.ts";
36 import * as McpInvocationContext from "../../apps/server/src/mcp/McpInvocationContext.ts";
37 import { advertisedJsonSchema } from "../../apps/server/src/mcp/advertisedJsonSchema.ts";
38 -import { EnvironmentId, ORCHESTRATOR_MCP_RUNNING_TASK_NEXT, ThreadId } from "@t3tools/contracts";
38 +import {
39 + EnvironmentId,
40 + ORCHESTRATOR_MCP_RUNNING_TASK_NEXT,
41 + PullRequestState,
42 + ThreadId,
43 +} from "@t3tools/contracts";
44 import { projectComposerContextForProvider } from "@t3tools/shared/composerContextReferences";
45 import { formatThreadLink } from "@t3tools/shared/threadLinks";
46 import { buildCodexAdditionalContext } from "../../apps/server/src/provider/CodexDeveloperInstructions.ts";
@@ -166,6 +171,8 @@ const McpToolUseExpect = Schema.Struct({
171 textMustNot: Schema.optional(Schema.Array(Schema.String)),
172 /** Each entry matches a PR URL linked at the end, as `args` values match. */
173 linked: Schema.optional(Schema.Array(Schema.String)),
174 + /** The PR numbers linked at the end, exactly. */
175 + linkedNumbers: Schema.optional(Schema.Array(Schema.Number)),
176 /** Device manager checks: child briefs, simulator UI over the shell, failures, recordings. */
177 device: Schema.optional(DeviceExpect),
178 });
@@ -210,6 +217,12 @@ const McpToolUseWorld = Schema.StructWithRest(
217 deviceInvalidCapture: Schema.optional(Schema.Boolean),
218 /** Devices another thread's agent-device session holds, by device id: that thread's id. */
219 deviceOwners: Schema.optional(Schema.Record(Schema.String, Schema.String)),
220 + /** PRs already linked to the thread, with the state T3 last saw. */
221 + linkedPullRequests: Schema.optional(
222 + Schema.Array(
223 + Schema.Struct({ number: Schema.Number, state: PullRequestState, title: Schema.String }),
224 + ),
225 + ),
226 }),
227 Rest,
228 );
@@ -731,11 +744,16 @@ export const makeSample = (testCase: McpToolUseCase, base: Base): Sample => {
744 const prior = testCase.setup.priorTurns ?? [];
745 const priorCalls = prior.flatMap((turn) => turn.toolCalls ?? []);
746 const repo = testCase.setup.world?.repo ?? "acme/app";
734 - const urls = priorCalls.flatMap((call) =>
735 - ["link_pull_request", "watch_pull_request"].includes(call.tool) && isRecord(call.input)
736 - ? [pullRequest(repo, call.input).url]
737 - : [],
738 - );
747 + const urls = [
748 + ...(testCase.setup.world?.linkedPullRequests ?? []).map(
749 + ({ number }) => pullRequest(repo, { number }).url,
750 + ),
751 + ...priorCalls.flatMap((call) =>
752 + ["link_pull_request", "watch_pull_request"].includes(call.tool) && isRecord(call.input)
753 + ? [pullRequest(repo, call.input).url]
754 + : [],
755 + ),
756 + ];
757 const taskNumbers = [...valueText(prior).matchAll(/task-(\d+)/g)].map((match) =>
758 Number(match[1]),
759 );
@@ -952,6 +970,15 @@ const pullRequest = (repo: string, input: Readonly<Record<string, unknown>>) =>
970 };
971 };
972
973 +/** A linked PR as `list_thread_pull_requests` shows it. Links made in the sample are open. */
974 +const linkedEntry = (sample: Sample, url: string) => {
975 + const pr = pullRequest(sample.repo, { url });
976 + const seeded = sample.testCase.setup.world?.linkedPullRequests?.find(
977 + ({ number }) => number === pr.number && pr.repository === sample.repo,
978 + );
979 + return { ...pr, state: seeded?.state ?? "open", title: seeded?.title ?? null };
980 +};
981 +
982 /** A believable T3 result for a tool the case does not mock. */
983 const t3Default = (sample: Sample, name: string, input: Readonly<Record<string, unknown>>) => {
984 const pr = () => pullRequest(sample.repo, input);
@@ -1006,6 +1033,24 @@ const t3Default = (sample: Sample, name: string, input: Readonly<Record<string,
1033 }
1034 case "unlink_pull_request":
1035 return { ...pr(), wasLinked: sample.linked.delete(pr().url) };
1036 + case "unlink_pull_requests": {
1037 + const states = Array.isArray(input.states) ? input.states : [];
1038 + const unlinked = [...sample.linked]
1039 + .map((url) => linkedEntry(sample, url))
1040 + .filter((entry) => states.includes(entry.state));
1041 + for (const { url } of unlinked) sample.linked.delete(url);
1042 + const groups = Map.groupBy(unlinked, (entry) => `${entry.repository}/${entry.state}`);
1043 + return {
1044 + unlinked: [...groups.values()].map((entries) => ({
1045 + host: "github.com",
1046 + repository: entries[0]!.repository,
1047 + state: entries[0]!.state,
1048 + numbers: entries.map((entry) => entry.number),
1049 + })),
1050 + unlinkedCount: unlinked.length,
1051 + remaining: sample.linked.size,
1052 + };
1053 + }
1054 case "watch_pull_request":
1055 sample.linked.add(pr().url);
1056 return { ...pr(), watching: true, wasWatching: false };
@@ -1014,10 +1059,9 @@ const t3Default = (sample: Sample, name: string, input: Readonly<Record<string,
1059 case "list_thread_pull_requests":
1060 return {
1061 pullRequests: [...sample.linked].map((url) => ({
1017 - ...pullRequest(sample.repo, { url }),
1062 + ...linkedEntry(sample, url),
1063 source: "agent",
1064 watching: false,
1020 - state: "open",
1065 })),
1066 chains: [],
1067 };
@@ -1403,6 +1447,11 @@ export const gradeSample = (expect: McpToolUseCase["expect"], run: SampleRun) =>
1447 for (const p of expect.textMustNot ?? []) add(`textMustNot /${p}/`, !test(p, run.text));
1448 const isLinked = (url: string) => (run.linked ?? []).some((at) => matches(url, at));
1449 for (const url of expect.linked ?? []) add(`linked ${url}`, isLinked(url));
1450 + if (expect.linkedNumbers !== undefined) {
1451 + const numbers = (run.linked ?? []).map((url) => Number(/(\d+)\/?$/.exec(url)?.[1]));
1452 + const exact = valueText(numbers.toSorted((a, b) => a - b));
1453 + add("linkedNumbers", exact === valueText(expect.linkedNumbers.toSorted((a, b) => a - b)));
1454 + }
1455 checks.push(...gradeDevice(expect.device, run));
1456 return checks;
1457 };
packages/client-runtime/src/t3ToolSummary.test.ts
+9
@@ -35,6 +35,15 @@ describe("summarizeT3ToolCalls", () => {
35 ).toBe("Sent 2 messages to 1 thread");
36 });
37
38 + it("counts the pull requests a batch unlink removed", () => {
39 + const batch = completed({ states: ["merged"] }, { unlinkedCount: 2 });
40 + expect(summarizeT3ToolCalls("unlink-pr", [batch, completed({ number: 3 })]).label).toBe(
41 + "Unlinked 3 pull requests",
42 + );
43 + const uncounted = completed({ states: ["merged"] }, { isError: false });
44 + expect(summarizeT3ToolCalls("unlink-pr", [uncounted]).label).toBe("Unlinked pull requests");
45 + });
46 +
47 it("excludes failed and unfinished sends even if the provider reports completed", () => {
48 const calls: T3ToolSummaryCall[] = [
49 completed({ threadId: "success" }, { messageId: "ok", threadId: "success" }),
packages/client-runtime/src/t3ToolSummary.ts
+12 -2
@@ -391,9 +391,19 @@ export function summarizeT3ToolCalls(
391 case "link-pr":
392 label = phrase("Linked", "link", quantity(selected.length, "pull request"));
393 break;
394 - case "unlink-pr":
395 - label = phrase("Unlinked", "unlink", quantity(selected.length, "pull request"));
394 + case "unlink-pr": {
395 + let count = 0;
396 + let countKnown = true;
397 + for (const call of selected) {
398 + if (typeof call.output?.unlinkedCount === "number") count += call.output.unlinkedCount;
399 + // A batch result too large to compact loses its count, so the label drops the number.
400 + else if (Array.isArray(call.input?.states)) countKnown = false;
401 + else count += 1;
402 + }
403 + const object = countKnown ? quantity(count, "pull request") : "pull requests";
404 + label = phrase("Unlinked", "unlink", object);
405 break;
406 + }
407 case "watch-pr":
408 label = phrase("Watching", "watch", quantity(selected.length, "pull request"));
409 break;
packages/shared/src/t3McpToolPresentation.ts
+5
@@ -99,6 +99,11 @@ const T3_MCP_TOOLS: Readonly<Record<string, T3McpToolDefinition>> = {
99 "unlink-pr",
100 "pull-request",
101 ),
102 + unlink_pull_requests: tool(
103 + ["Unlink", "Unlinking", "Unlinked", "pull requests by state"],
104 + "unlink-pr",
105 + "pull-request",
106 + ),
107 list_thread_pull_requests: tool(
108 ["Check", "Checking", "Checked", "linked pull requests"],
109 "list-prs",
packages/shared/src/toolOutput.test.ts
+3
@@ -29,11 +29,14 @@ describe("compactDynamicToolOutput", () => {
29 scheduledTaskId: "scheduled-1",
30 status: "failed",
31 summary: "A child failed; the tool itself succeeded.",
32 + unlinked: [{ repository: "acme/app", state: "merged", numbers: [1] }],
33 + unlinkedCount: 1,
34 };
35 expect(compactDynamicToolOutput(output)).toEqual({
36 thread: { threadId: "thread-1" },
37 taskId: "task-1",
38 scheduledTaskId: "scheduled-1",
39 + unlinkedCount: 1,
40 });
41 expect(output.thread.messages).toEqual(["Private message"]);
42 });
packages/shared/src/toolOutput.ts
+3
@@ -43,6 +43,7 @@ interface CompactToolOutput {
43 [MCP_APP_OUTPUT_KEY]?: McpAppReference;
44 thread?: { threadId: string };
45 threads?: Array<{ threadId?: string; status?: "rolled_back" }>;
46 + unlinkedCount?: number;
47 }
48
49 function readResult(value: unknown, budget: ResultReadBudget, depth = 0): ResultEnvelope {
@@ -123,6 +124,8 @@ export function compactDynamicToolOutput(value: unknown): CompactToolOutput | un
124 if (id !== undefined) output[key] = id;
125 }
126 if (data.status === "rolled_back") output.status = "rolled_back";
127 + if (typeof data.unlinkedCount === "number" && Number.isSafeInteger(data.unlinkedCount))
128 + output.unlinkedCount = data.unlinkedCount;
129 const htmlRender = readHtmlRenderReference(data.htmlRender);
130 if (htmlRender !== undefined) output.htmlRender = htmlRender;
131 const mcpApp = readMcpAppReference(data[MCP_APP_OUTPUT_KEY]);