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

main
ts 1,809 lines 58.5 KB
Raw
1 import { mFallback, msg } from "gt-i18n";
2 import type { MFunctionType } from "gt-i18n/types";
3 import type { T3McpToolSummaryAction } from "@t3tools/shared/t3McpToolPresentation";
4
5 export interface T3ToolSummaryCall {
6 readonly input: unknown;
7 readonly output: unknown;
8 readonly outcome: "completed" | "failed" | "unfinished";
9 }
10
11 function asRecord(value: unknown): Record<string, unknown> | undefined {
12 return value !== null && typeof value === "object" && !Array.isArray(value)
13 ? (value as Record<string, unknown>)
14 : undefined;
15 }
16
17 function id(value: unknown): string | undefined {
18 return typeof value === "string" && value.trim() !== "" ? value : undefined;
19 }
20
21 interface ToolResult {
22 readonly data?: Record<string, unknown>;
23 readonly failed: boolean;
24 }
25
26 function readResult(value: unknown, depth = 0): ToolResult {
27 if (depth > 4) return { failed: false };
28 if (typeof value === "string") {
29 try {
30 return readResult(JSON.parse(value), depth + 1);
31 } catch {
32 return { failed: false };
33 }
34 }
35 if (Array.isArray(value)) {
36 let data: ToolResult["data"];
37 let failed = false;
38 for (const block of value) {
39 const record = asRecord(block);
40 const text = record?.text ?? asRecord(record?.content)?.text;
41 const result = readResult(asRecord(text)?.text ?? text, depth + 1);
42 data ??= result.data;
43 failed ||= result.failed;
44 }
45 return { ...(data ? { data } : {}), failed };
46 }
47 const record = asRecord(value);
48 if (!record) return { failed: false };
49 const failed =
50 record.isError === true ||
51 record.is_error === true ||
52 (typeof record._tag === "string" && /(?:Error|Failure)$/.test(record._tag)) ||
53 record.error != null;
54 const content = record.structuredContent ?? record.content;
55 if (content !== undefined) {
56 const result = readResult(content, depth + 1);
57 return { ...(result.data ? { data: result.data } : {}), failed: failed || result.failed };
58 }
59 return { data: record, failed };
60 }
61
62 function readInput(value: unknown): Record<string, unknown> | undefined {
63 const input = readResult(value).data;
64 // Historical Cursor items retain the MCP args envelope.
65 return input && typeof input.toolName === "string" ? asRecord(input.args) : input;
66 }
67
68 /** MCP errors can be returned as data even when the provider completed the tool call. */
69 export function t3ToolResultIndicatesFailure(output: unknown): boolean {
70 return readResult(output).failed;
71 }
72
73 function countEntities(ids: ReadonlyArray<string | undefined>): number {
74 return (
75 new Set(ids.filter((value) => value !== undefined)).size +
76 ids.filter((value) => value === undefined).length
77 );
78 }
79
80 /** One PR per single call; a batch counts what its result reports. Null when a count was lost. */
81 function pullRequestCount(
82 calls: ReadonlyArray<{
83 readonly input: Record<string, unknown> | undefined;
84 readonly output: Record<string, unknown> | undefined;
85 }>,
86 countKey: "linkedCount" | "unlinkedCount",
87 ): number | null {
88 let count = 0;
89 for (const call of calls) {
90 const reported = call.output?.[countKey];
91 if (typeof reported === "number") count += reported;
92 else if (call.input?.url !== undefined || call.input?.number !== undefined) count += 1;
93 // A batch result too large to compact loses its count, so the label drops the number.
94 else return null;
95 }
96 return count;
97 }
98
99 export function summarizeT3ToolCalls(
100 action: T3McpToolSummaryAction,
101 calls: ReadonlyArray<T3ToolSummaryCall>,
102 resolve: MFunctionType = mFallback,
103 ): { label: string; failedCount: number } {
104 const results = calls.map((call) => {
105 const result = readResult(call.output);
106 return {
107 input: readInput(call.input),
108 output: result.data,
109 outcome: result.failed ? ("failed" as const) : call.outcome,
110 };
111 });
112 const completed = results.filter((call) => call.outcome === "completed");
113 let failedCount = results.filter((call) => call.outcome === "failed").length;
114 const done = completed.length > 0;
115 const selected = done ? completed : results;
116 const entityIds = (key: string) =>
117 selected.map((call) => id(call.output?.[key]) ?? id(call.input?.[key]));
118 const projectIds = selected.map(
119 (call) => id(call.output?.id) ?? id(call.output?.projectId) ?? id(call.input?.projectId),
120 );
121 const threadIds = selected.map(
122 (call) =>
123 id(call.output?.threadId) ??
124 id(asRecord(call.output?.thread)?.threadId) ??
125 id(call.input?.threadId),
126 );
127 let label: string;
128 switch (action) {
129 case "delegate": {
130 const count = countEntities(entityIds("taskId"));
131 label = done
132 ? resolve(
133 msg("{count, plural, one {Delegated {count} task} other {Delegated {count} tasks}}", {
134 count,
135 }),
136 )
137 : resolve(
138 msg(
139 "{count, plural, one {Tried to delegate {count} task} other {Tried to delegate {count} tasks}}",
140 { count },
141 ),
142 );
143 break;
144 }
145 case "thread-interrupt": {
146 const count = countEntities(threadIds);
147 label = done
148 ? resolve(
149 msg(
150 "{count, plural, one {Requested interrupts for {count} thread} other {Requested interrupts for {count} threads}}",
151 { count },
152 ),
153 )
154 : resolve(
155 msg(
156 "{count, plural, one {Tried to interrupt {count} thread} other {Tried to interrupt {count} threads}}",
157 { count },
158 ),
159 );
160 break;
161 }
162 case "workflow-stop": {
163 const count = countEntities(entityIds("subagentId"));
164 label = done
165 ? resolve(
166 msg(
167 "{count, plural, one {Requested stops for {count} workflow} other {Requested stops for {count} workflows}}",
168 { count },
169 ),
170 )
171 : resolve(
172 msg(
173 "{count, plural, one {Tried to stop {count} workflow} other {Tried to stop {count} workflows}}",
174 { count },
175 ),
176 );
177 break;
178 }
179 case "task-cancel": {
180 const count = countEntities(entityIds("taskId"));
181 label = done
182 ? resolve(
183 msg(
184 "{count, plural, one {Requested cancellation of {count} task} other {Requested cancellation of {count} tasks}}",
185 { count },
186 ),
187 )
188 : resolve(
189 msg(
190 "{count, plural, one {Tried to cancel {count} task} other {Tried to cancel {count} tasks}}",
191 { count },
192 ),
193 );
194 break;
195 }
196 case "schedule-create": {
197 const count = countEntities(entityIds("scheduledTaskId"));
198 label = done
199 ? resolve(
200 msg("{count, plural, one {Scheduled {count} task} other {Scheduled {count} tasks}}", {
201 count,
202 }),
203 )
204 : resolve(
205 msg(
206 "{count, plural, one {Tried to schedule {count} task} other {Tried to schedule {count} tasks}}",
207 { count },
208 ),
209 );
210 break;
211 }
212 case "schedule-update": {
213 const count = countEntities(entityIds("scheduledTaskId"));
214 label = done
215 ? resolve(
216 msg(
217 "{count, plural, one {Updated {count} scheduled task} other {Updated {count} scheduled tasks}}",
218 { count },
219 ),
220 )
221 : resolve(
222 msg(
223 "{count, plural, one {Tried to update {count} scheduled task} other {Tried to update {count} scheduled tasks}}",
224 { count },
225 ),
226 );
227 break;
228 }
229 case "schedule-delete": {
230 const count = countEntities(entityIds("scheduledTaskId"));
231 label = done
232 ? resolve(
233 msg(
234 "{count, plural, one {Requested deletion of {count} scheduled task} other {Requested deletion of {count} scheduled tasks}}",
235 { count },
236 ),
237 )
238 : resolve(
239 msg(
240 "{count, plural, one {Tried to delete {count} scheduled task} other {Tried to delete {count} scheduled tasks}}",
241 { count },
242 ),
243 );
244 break;
245 }
246 case "schedule-run": {
247 const count = selected.length;
248 label = done
249 ? resolve(
250 msg(
251 "{count, plural, one {Requested {count} scheduled task run} other {Requested {count} scheduled task runs}}",
252 { count },
253 ),
254 )
255 : resolve(
256 msg(
257 "{count, plural, one {Tried to request {count} scheduled task run} other {Tried to request {count} scheduled task runs}}",
258 { count },
259 ),
260 );
261 break;
262 }
263 case "thread-fork": {
264 const count = selected.length;
265 label = done
266 ? resolve(
267 msg(
268 "{count, plural, one {Requested {count} thread fork} other {Requested {count} thread forks}}",
269 { count },
270 ),
271 )
272 : resolve(
273 msg(
274 "{count, plural, one {Tried to request {count} thread fork} other {Tried to request {count} thread forks}}",
275 { count },
276 ),
277 );
278 break;
279 }
280 case "thread-merge": {
281 const count = selected.length;
282 label = done
283 ? resolve(
284 msg(
285 "{count, plural, one {Requested {count} context merge} other {Requested {count} context merges}}",
286 { count },
287 ),
288 )
289 : resolve(
290 msg(
291 "{count, plural, one {Tried to request {count} context merge} other {Tried to request {count} context merges}}",
292 { count },
293 ),
294 );
295 break;
296 }
297 case "thread-update": {
298 const count = countEntities(threadIds);
299 label = done
300 ? resolve(
301 msg("{count, plural, one {Updated {count} thread} other {Updated {count} threads}}", {
302 count,
303 }),
304 )
305 : resolve(
306 msg(
307 "{count, plural, one {Tried to update {count} thread} other {Tried to update {count} threads}}",
308 { count },
309 ),
310 );
311 break;
312 }
313 case "queue-read": {
314 const count = countEntities(entityIds("queuedRunId"));
315 label = done
316 ? resolve(
317 msg(
318 "{count, plural, one {Read {count} queued message} other {Read {count} queued messages}}",
319 { count },
320 ),
321 )
322 : resolve(
323 msg(
324 "{count, plural, one {Tried to read {count} queued message} other {Tried to read {count} queued messages}}",
325 { count },
326 ),
327 );
328 break;
329 }
330 case "queue-edit": {
331 const count = countEntities(entityIds("queuedRunId"));
332 label = done
333 ? resolve(
334 msg(
335 "{count, plural, one {Edited {count} queued message} other {Edited {count} queued messages}}",
336 { count },
337 ),
338 )
339 : resolve(
340 msg(
341 "{count, plural, one {Tried to edit {count} queued message} other {Tried to edit {count} queued messages}}",
342 { count },
343 ),
344 );
345 break;
346 }
347 case "queue-cancel": {
348 const count = countEntities(entityIds("queuedRunId"));
349 label = done
350 ? resolve(
351 msg(
352 "{count, plural, one {Requested cancellation of {count} queued run} other {Requested cancellation of {count} queued runs}}",
353 { count },
354 ),
355 )
356 : resolve(
357 msg(
358 "{count, plural, one {Tried to cancel {count} queued run} other {Tried to cancel {count} queued runs}}",
359 { count },
360 ),
361 );
362 break;
363 }
364 case "queue-reorder": {
365 const count = countEntities(entityIds("queuedRunId"));
366 label = done
367 ? resolve(
368 msg(
369 "{count, plural, one {Reordered {count} queued run} other {Reordered {count} queued runs}}",
370 { count },
371 ),
372 )
373 : resolve(
374 msg(
375 "{count, plural, one {Tried to reorder {count} queued run} other {Tried to reorder {count} queued runs}}",
376 { count },
377 ),
378 );
379 break;
380 }
381 case "queue-steer": {
382 const count = countEntities(entityIds("queuedRunId"));
383 label = done
384 ? resolve(
385 msg(
386 "{count, plural, one {Requested steering with {count} queued message} other {Requested steering with {count} queued messages}}",
387 { count },
388 ),
389 )
390 : resolve(
391 msg(
392 "{count, plural, one {Tried to steer with {count} queued message} other {Tried to steer with {count} queued messages}}",
393 { count },
394 ),
395 );
396 break;
397 }
398 case "question-read": {
399 const count = countEntities(entityIds("requestId"));
400 label = done
401 ? resolve(
402 msg(
403 "{count, plural, one {Read {count} pending question request} other {Read {count} pending question requests}}",
404 { count },
405 ),
406 )
407 : resolve(
408 msg(
409 "{count, plural, one {Tried to read {count} pending question request} other {Tried to read {count} pending question requests}}",
410 { count },
411 ),
412 );
413 break;
414 }
415 case "question-respond": {
416 const count = countEntities(entityIds("requestId"));
417 label = done
418 ? resolve(
419 msg(
420 "{count, plural, one {Answered {count} pending question request} other {Answered {count} pending question requests}}",
421 { count },
422 ),
423 )
424 : resolve(
425 msg(
426 "{count, plural, one {Tried to answer {count} pending question request} other {Tried to answer {count} pending question requests}}",
427 { count },
428 ),
429 );
430 break;
431 }
432 case "secret-request": {
433 const count = selected.length;
434 label = done
435 ? resolve(
436 msg(
437 "{count, plural, one {Asked for {count} secret} other {Asked for {count} secrets}}",
438 { count },
439 ),
440 )
441 : resolve(
442 msg(
443 "{count, plural, one {Tried to ask for {count} secret} other {Tried to ask for {count} secrets}}",
444 { count },
445 ),
446 );
447 break;
448 }
449 case "worktree-handoff": {
450 const count = countEntities(entityIds("worktreePath"));
451 label = done
452 ? resolve(
453 msg(
454 "{count, plural, one {Handed off to {count} worktree} other {Handed off to {count} worktrees}}",
455 { count },
456 ),
457 )
458 : resolve(
459 msg(
460 "{count, plural, one {Tried to hand off to {count} worktree} other {Tried to hand off to {count} worktrees}}",
461 { count },
462 ),
463 );
464 break;
465 }
466 case "project-read": {
467 const count = countEntities(projectIds);
468 label = done
469 ? resolve(
470 msg("{count, plural, one {Read {count} project} other {Read {count} projects}}", {
471 count,
472 }),
473 )
474 : resolve(
475 msg(
476 "{count, plural, one {Tried to read {count} project} other {Tried to read {count} projects}}",
477 { count },
478 ),
479 );
480 break;
481 }
482 case "project-create": {
483 const count = countEntities(projectIds);
484 label = done
485 ? resolve(
486 msg(
487 "{count, plural, one {Registered {count} project} other {Registered {count} projects}}",
488 { count },
489 ),
490 )
491 : resolve(
492 msg(
493 "{count, plural, one {Tried to register {count} project} other {Tried to register {count} projects}}",
494 { count },
495 ),
496 );
497 break;
498 }
499 case "project-update": {
500 const count = countEntities(projectIds);
501 label = done
502 ? resolve(
503 msg("{count, plural, one {Updated {count} project} other {Updated {count} projects}}", {
504 count,
505 }),
506 )
507 : resolve(
508 msg(
509 "{count, plural, one {Tried to update {count} project} other {Tried to update {count} projects}}",
510 { count },
511 ),
512 );
513 break;
514 }
515 case "project-delete": {
516 const count = countEntities(projectIds);
517 label = done
518 ? resolve(
519 msg("{count, plural, one {Deleted {count} project} other {Deleted {count} projects}}", {
520 count,
521 }),
522 )
523 : resolve(
524 msg(
525 "{count, plural, one {Tried to delete {count} project} other {Tried to delete {count} projects}}",
526 { count },
527 ),
528 );
529 break;
530 }
531 case "project-clone": {
532 const count = countEntities(entityIds("cwd"));
533 label = done
534 ? resolve(
535 msg(
536 "{count, plural, one {Cloned {count} repository} other {Cloned {count} repositories}}",
537 { count },
538 ),
539 )
540 : resolve(
541 msg(
542 "{count, plural, one {Tried to clone {count} repository} other {Tried to clone {count} repositories}}",
543 { count },
544 ),
545 );
546 break;
547 }
548 case "environment-link": {
549 const count = selected.length;
550 label = done
551 ? resolve(
552 msg(
553 "{count, plural, one {Asked to link {count} environment} other {Asked to link {count} environments}}",
554 { count },
555 ),
556 )
557 : resolve(
558 msg(
559 "{count, plural, one {Tried to ask to link {count} environment} other {Tried to ask to link {count} environments}}",
560 { count },
561 ),
562 );
563 break;
564 }
565 case "environment-unlink": {
566 const count = countEntities(entityIds("environmentId"));
567 label = done
568 ? resolve(
569 msg(
570 "{count, plural, one {Forgot {count} linked environment} other {Forgot {count} linked environments}}",
571 { count },
572 ),
573 )
574 : resolve(
575 msg(
576 "{count, plural, one {Tried to forget {count} linked environment} other {Tried to forget {count} linked environments}}",
577 { count },
578 ),
579 );
580 break;
581 }
582 case "attachment-prepare": {
583 const count = countEntities(entityIds("attachmentId"));
584 label = done
585 ? resolve(
586 msg(
587 "{count, plural, one {Prepared {count} attachment upload} other {Prepared {count} attachment uploads}}",
588 { count },
589 ),
590 )
591 : resolve(
592 msg(
593 "{count, plural, one {Tried to prepare {count} attachment upload} other {Tried to prepare {count} attachment uploads}}",
594 { count },
595 ),
596 );
597 break;
598 }
599 case "attachment-discard": {
600 const count = countEntities(entityIds("attachmentId"));
601 label = done
602 ? resolve(
603 msg(
604 "{count, plural, one {Discarded {count} pending attachment} other {Discarded {count} pending attachments}}",
605 { count },
606 ),
607 )
608 : resolve(
609 msg(
610 "{count, plural, one {Tried to discard {count} pending attachment} other {Tried to discard {count} pending attachments}}",
611 { count },
612 ),
613 );
614 break;
615 }
616 case "watch-pr": {
617 const count = selected.length;
618 label = done
619 ? resolve(
620 msg(
621 "{count, plural, one {Watching {count} pull request} other {Watching {count} pull requests}}",
622 { count },
623 ),
624 )
625 : resolve(
626 msg(
627 "{count, plural, one {Tried to watch {count} pull request} other {Tried to watch {count} pull requests}}",
628 { count },
629 ),
630 );
631 break;
632 }
633 case "unwatch-pr": {
634 const count = selected.length;
635 label = done
636 ? resolve(
637 msg(
638 "{count, plural, one {Stopped watching {count} pull request} other {Stopped watching {count} pull requests}}",
639 { count },
640 ),
641 )
642 : resolve(
643 msg(
644 "{count, plural, one {Tried to stop watching {count} pull request} other {Tried to stop watching {count} pull requests}}",
645 { count },
646 ),
647 );
648 break;
649 }
650 case "read-pr-guide": {
651 const count = selected.length;
652 label = done
653 ? resolve(
654 msg(
655 "{count, plural, one {Read {count} review guide} other {Read {count} review guides}}",
656 { count },
657 ),
658 )
659 : resolve(
660 msg(
661 "{count, plural, one {Tried to read {count} review guide} other {Tried to read {count} review guides}}",
662 { count },
663 ),
664 );
665 break;
666 }
667 case "list-issues": {
668 const count = selected.length;
669 label = done
670 ? resolve(
671 msg(
672 "{count, plural, one {Listed issues {count} time} other {Listed issues {count} times}}",
673 { count },
674 ),
675 )
676 : resolve(
677 msg(
678 "{count, plural, one {Tried to list issues {count} time} other {Tried to list issues {count} times}}",
679 { count },
680 ),
681 );
682 break;
683 }
684 case "read-issue": {
685 const count = selected.length;
686 label = done
687 ? resolve(
688 msg("{count, plural, one {Read {count} issue} other {Read {count} issues}}", { count }),
689 )
690 : resolve(
691 msg(
692 "{count, plural, one {Tried to read {count} issue} other {Tried to read {count} issues}}",
693 { count },
694 ),
695 );
696 break;
697 }
698 case "create-issue": {
699 const count = selected.length;
700 label = done
701 ? resolve(
702 msg("{count, plural, one {Filed {count} issue} other {Filed {count} issues}}", {
703 count,
704 }),
705 )
706 : resolve(
707 msg(
708 "{count, plural, one {Tried to file {count} issue} other {Tried to file {count} issues}}",
709 { count },
710 ),
711 );
712 break;
713 }
714 case "comment-issue": {
715 const count = selected.length;
716 label = done
717 ? resolve(
718 msg(
719 "{count, plural, one {Commented on {count} issue} other {Commented on {count} issues}}",
720 { count },
721 ),
722 )
723 : resolve(
724 msg(
725 "{count, plural, one {Tried to comment on {count} issue} other {Tried to comment on {count} issues}}",
726 { count },
727 ),
728 );
729 break;
730 }
731 case "set-issue-state": {
732 const count = selected.length;
733 label = done
734 ? resolve(
735 msg(
736 "{count, plural, one {Changed the state of {count} issue} other {Changed the state of {count} issues}}",
737 { count },
738 ),
739 )
740 : resolve(
741 msg(
742 "{count, plural, one {Tried to change the state of {count} issue} other {Tried to change the state of {count} issues}}",
743 { count },
744 ),
745 );
746 break;
747 }
748 case "link-issue": {
749 const count = selected.length;
750 label = done
751 ? resolve(
752 msg("{count, plural, one {Linked {count} issue} other {Linked {count} issues}}", {
753 count,
754 }),
755 )
756 : resolve(
757 msg(
758 "{count, plural, one {Tried to link {count} issue} other {Tried to link {count} issues}}",
759 { count },
760 ),
761 );
762 break;
763 }
764 case "unlink-issue": {
765 const count = selected.length;
766 label = done
767 ? resolve(
768 msg("{count, plural, one {Unlinked {count} issue} other {Unlinked {count} issues}}", {
769 count,
770 }),
771 )
772 : resolve(
773 msg(
774 "{count, plural, one {Tried to unlink {count} issue} other {Tried to unlink {count} issues}}",
775 { count },
776 ),
777 );
778 break;
779 }
780 case "list-thread-issues": {
781 const count = selected.length;
782 if (count === 1) {
783 label = done
784 ? resolve(msg("Checked linked issues"))
785 : resolve(msg("Tried to check linked issues"));
786 } else {
787 label = done
788 ? resolve(
789 msg(
790 "{count, plural, one {Checked linked issues {count} time} other {Checked linked issues {count} times}}",
791 { count },
792 ),
793 )
794 : resolve(
795 msg(
796 "{count, plural, one {Tried to check linked issues {count} time} other {Tried to check linked issues {count} times}}",
797 { count },
798 ),
799 );
800 }
801 break;
802 }
803 case "html-preview": {
804 const count = selected.length;
805 label = done
806 ? resolve(
807 msg(
808 "{count, plural, one {Previewed {count} HTML page} other {Previewed {count} HTML pages}}",
809 { count },
810 ),
811 )
812 : resolve(
813 msg(
814 "{count, plural, one {Tried to preview {count} HTML page} other {Tried to preview {count} HTML pages}}",
815 { count },
816 ),
817 );
818 break;
819 }
820 case "html-render": {
821 const count = selected.length;
822 label = done
823 ? resolve(
824 msg(
825 "{count, plural, one {Rendered {count} HTML page} other {Rendered {count} HTML pages}}",
826 { count },
827 ),
828 )
829 : resolve(
830 msg(
831 "{count, plural, one {Tried to render {count} HTML page} other {Tried to render {count} HTML pages}}",
832 { count },
833 ),
834 );
835 break;
836 }
837 case "send-to-user": {
838 const count = selected.length;
839 label = done
840 ? resolve(
841 msg("{count, plural, one {Sent {count} message} other {Sent {count} messages}}", {
842 count,
843 }),
844 )
845 : resolve(
846 msg(
847 "{count, plural, one {Tried to send {count} message} other {Tried to send {count} messages}}",
848 { count },
849 ),
850 );
851 break;
852 }
853 case "thread-list": {
854 const count = selected.length;
855 label = done
856 ? resolve(
857 msg(
858 "{count, plural, one {Listed threads {count} time} other {Listed threads {count} times}}",
859 { count },
860 ),
861 )
862 : resolve(
863 msg(
864 "{count, plural, one {Tried to list threads {count} time} other {Tried to list threads {count} times}}",
865 { count },
866 ),
867 );
868 break;
869 }
870 case "task-status": {
871 const count = selected.length;
872 label = done
873 ? resolve(
874 msg(
875 "{count, plural, one {Checked task status {count} time} other {Checked task status {count} times}}",
876 { count },
877 ),
878 )
879 : resolve(
880 msg(
881 "{count, plural, one {Tried to check task status {count} time} other {Tried to check task status {count} times}}",
882 { count },
883 ),
884 );
885 break;
886 }
887 case "background-wait": {
888 const count = selected.length;
889 label = done
890 ? resolve(
891 msg(
892 "{count, plural, one {Updated background waits {count} time} other {Updated background waits {count} times}}",
893 { count },
894 ),
895 )
896 : resolve(
897 msg(
898 "{count, plural, one {Tried to update background waits {count} time} other {Tried to update background waits {count} times}}",
899 { count },
900 ),
901 );
902 break;
903 }
904 case "schedule-list": {
905 const count = selected.length;
906 label = done
907 ? resolve(
908 msg(
909 "{count, plural, one {Listed scheduled tasks {count} time} other {Listed scheduled tasks {count} times}}",
910 { count },
911 ),
912 )
913 : resolve(
914 msg(
915 "{count, plural, one {Tried to list scheduled tasks {count} time} other {Tried to list scheduled tasks {count} times}}",
916 { count },
917 ),
918 );
919 break;
920 }
921 case "thread-configuration": {
922 const count = selected.length;
923 label = done
924 ? resolve(
925 msg(
926 "{count, plural, one {Checked thread configuration {count} time} other {Checked thread configuration {count} times}}",
927 { count },
928 ),
929 )
930 : resolve(
931 msg(
932 "{count, plural, one {Tried to check thread configuration {count} time} other {Tried to check thread configuration {count} times}}",
933 { count },
934 ),
935 );
936 break;
937 }
938 case "thread-configure": {
939 const count = selected.length;
940 label = done
941 ? resolve(
942 msg(
943 "{count, plural, one {Set thread model {count} time} other {Set thread model {count} times}}",
944 { count },
945 ),
946 )
947 : resolve(
948 msg(
949 "{count, plural, one {Tried to set thread model {count} time} other {Tried to set thread model {count} times}}",
950 { count },
951 ),
952 );
953 break;
954 }
955 case "thread-search": {
956 const count = selected.length;
957 label = done
958 ? resolve(
959 msg(
960 "{count, plural, one {Searched threads {count} time} other {Searched threads {count} times}}",
961 { count },
962 ),
963 )
964 : resolve(
965 msg(
966 "{count, plural, one {Tried to search threads {count} time} other {Tried to search threads {count} times}}",
967 { count },
968 ),
969 );
970 break;
971 }
972 case "thread-transfers": {
973 const count = selected.length;
974 label = done
975 ? resolve(
976 msg(
977 "{count, plural, one {Checked thread transfers {count} time} other {Checked thread transfers {count} times}}",
978 { count },
979 ),
980 )
981 : resolve(
982 msg(
983 "{count, plural, one {Tried to check thread transfers {count} time} other {Tried to check thread transfers {count} times}}",
984 { count },
985 ),
986 );
987 break;
988 }
989 case "thread-organize": {
990 const count = selected.length;
991 label = done
992 ? resolve(
993 msg(
994 "{count, plural, one {Organized threads {count} time} other {Organized threads {count} times}}",
995 { count },
996 ),
997 )
998 : resolve(
999 msg(
1000 "{count, plural, one {Tried to organize threads {count} time} other {Tried to organize threads {count} times}}",
1001 { count },
1002 ),
1003 );
1004 break;
1005 }
1006 case "queue-list": {
1007 const count = selected.length;
1008 label = done
1009 ? resolve(
1010 msg(
1011 "{count, plural, one {Listed queued messages {count} time} other {Listed queued messages {count} times}}",
1012 { count },
1013 ),
1014 )
1015 : resolve(
1016 msg(
1017 "{count, plural, one {Tried to list queued messages {count} time} other {Tried to list queued messages {count} times}}",
1018 { count },
1019 ),
1020 );
1021 break;
1022 }
1023 case "question-list": {
1024 const count = selected.length;
1025 label = done
1026 ? resolve(
1027 msg(
1028 "{count, plural, one {Listed pending questions {count} time} other {Listed pending questions {count} times}}",
1029 { count },
1030 ),
1031 )
1032 : resolve(
1033 msg(
1034 "{count, plural, one {Tried to list pending questions {count} time} other {Tried to list pending questions {count} times}}",
1035 { count },
1036 ),
1037 );
1038 break;
1039 }
1040 case "worktree-list": {
1041 const count = selected.length;
1042 label = done
1043 ? resolve(
1044 msg(
1045 "{count, plural, one {Listed workspace branches {count} time} other {Listed workspace branches {count} times}}",
1046 { count },
1047 ),
1048 )
1049 : resolve(
1050 msg(
1051 "{count, plural, one {Tried to list workspace branches {count} time} other {Tried to list workspace branches {count} times}}",
1052 { count },
1053 ),
1054 );
1055 break;
1056 }
1057 case "worktree-status": {
1058 const count = selected.length;
1059 label = done
1060 ? resolve(
1061 msg(
1062 "{count, plural, one {Checked worktree status {count} time} other {Checked worktree status {count} times}}",
1063 { count },
1064 ),
1065 )
1066 : resolve(
1067 msg(
1068 "{count, plural, one {Tried to check worktree status {count} time} other {Tried to check worktree status {count} times}}",
1069 { count },
1070 ),
1071 );
1072 break;
1073 }
1074 case "project-list": {
1075 const count = selected.length;
1076 label = done
1077 ? resolve(
1078 msg(
1079 "{count, plural, one {Listed projects {count} time} other {Listed projects {count} times}}",
1080 { count },
1081 ),
1082 )
1083 : resolve(
1084 msg(
1085 "{count, plural, one {Tried to list projects {count} time} other {Tried to list projects {count} times}}",
1086 { count },
1087 ),
1088 );
1089 break;
1090 }
1091 case "environment-read": {
1092 const count = selected.length;
1093 label = done
1094 ? resolve(
1095 msg(
1096 "{count, plural, one {Checked environment preferences {count} time} other {Checked environment preferences {count} times}}",
1097 { count },
1098 ),
1099 )
1100 : resolve(
1101 msg(
1102 "{count, plural, one {Tried to check environment preferences {count} time} other {Tried to check environment preferences {count} times}}",
1103 { count },
1104 ),
1105 );
1106 break;
1107 }
1108 case "environment-update": {
1109 const count = selected.length;
1110 label = done
1111 ? resolve(
1112 msg(
1113 "{count, plural, one {Updated environment preferences {count} time} other {Updated environment preferences {count} times}}",
1114 { count },
1115 ),
1116 )
1117 : resolve(
1118 msg(
1119 "{count, plural, one {Tried to update environment preferences {count} time} other {Tried to update environment preferences {count} times}}",
1120 { count },
1121 ),
1122 );
1123 break;
1124 }
1125 case "theme-read": {
1126 const count = selected.length;
1127 label = done
1128 ? resolve(
1129 msg(
1130 "{count, plural, one {Checked themes {count} time} other {Checked themes {count} times}}",
1131 { count },
1132 ),
1133 )
1134 : resolve(
1135 msg(
1136 "{count, plural, one {Tried to check themes {count} time} other {Tried to check themes {count} times}}",
1137 { count },
1138 ),
1139 );
1140 break;
1141 }
1142 case "theme-set": {
1143 const count = selected.length;
1144 label = done
1145 ? resolve(
1146 msg(
1147 "{count, plural, one {Set the theme {count} time} other {Set the theme {count} times}}",
1148 { count },
1149 ),
1150 )
1151 : resolve(
1152 msg(
1153 "{count, plural, one {Tried to set the theme {count} time} other {Tried to set the theme {count} times}}",
1154 { count },
1155 ),
1156 );
1157 break;
1158 }
1159 case "environment-links": {
1160 const count = selected.length;
1161 label = done
1162 ? resolve(
1163 msg(
1164 "{count, plural, one {Listed linked environments {count} time} other {Listed linked environments {count} times}}",
1165 { count },
1166 ),
1167 )
1168 : resolve(
1169 msg(
1170 "{count, plural, one {Tried to list linked environments {count} time} other {Tried to list linked environments {count} times}}",
1171 { count },
1172 ),
1173 );
1174 break;
1175 }
1176 case "browser": {
1177 const count = selected.length;
1178 label = done
1179 ? resolve(
1180 msg(
1181 "{count, plural, one {Used browser {count} time} other {Used browser {count} times}}",
1182 { count },
1183 ),
1184 )
1185 : resolve(
1186 msg(
1187 "{count, plural, one {Tried to use browser {count} time} other {Tried to use browser {count} times}}",
1188 { count },
1189 ),
1190 );
1191 break;
1192 }
1193 case "device": {
1194 const count = selected.length;
1195 label = done
1196 ? resolve(
1197 msg(
1198 "{count, plural, one {Used device controls {count} time} other {Used device controls {count} times}}",
1199 { count },
1200 ),
1201 )
1202 : resolve(
1203 msg(
1204 "{count, plural, one {Tried to use device controls {count} time} other {Tried to use device controls {count} times}}",
1205 { count },
1206 ),
1207 );
1208 break;
1209 }
1210 case "capabilities": {
1211 const count = selected.length;
1212 label = done
1213 ? resolve(
1214 msg(
1215 "{count, plural, one {Checked orchestration capabilities {count} time} other {Checked orchestration capabilities {count} times}}",
1216 { count },
1217 ),
1218 )
1219 : resolve(
1220 msg(
1221 "{count, plural, one {Tried to check orchestration capabilities {count} time} other {Tried to check orchestration capabilities {count} times}}",
1222 { count },
1223 ),
1224 );
1225 break;
1226 }
1227 case "thread-read": {
1228 if (threadIds.every((value) => value !== undefined)) {
1229 const count = new Set(threadIds).size;
1230 label = done
1231 ? resolve(
1232 msg("{count, plural, one {Read {count} thread} other {Read {count} threads}}", {
1233 count,
1234 }),
1235 )
1236 : resolve(
1237 msg(
1238 "{count, plural, one {Tried to read {count} thread} other {Tried to read {count} threads}}",
1239 { count },
1240 ),
1241 );
1242 } else {
1243 const count = selected.length;
1244 label = done
1245 ? resolve(
1246 msg(
1247 "{count, plural, one {Read threads {count} time} other {Read threads {count} times}}",
1248 { count },
1249 ),
1250 )
1251 : resolve(
1252 msg(
1253 "{count, plural, one {Tried to read threads {count} time} other {Tried to read threads {count} times}}",
1254 { count },
1255 ),
1256 );
1257 }
1258 break;
1259 }
1260 case "thread-wait": {
1261 if (threadIds.every((value) => value !== undefined)) {
1262 const count = new Set(threadIds).size;
1263 label = done
1264 ? resolve(
1265 msg(
1266 "{count, plural, one {Waited on {count} thread} other {Waited on {count} threads}}",
1267 { count },
1268 ),
1269 )
1270 : resolve(
1271 msg(
1272 "{count, plural, one {Tried to wait on {count} thread} other {Tried to wait on {count} threads}}",
1273 { count },
1274 ),
1275 );
1276 } else {
1277 const count = selected.length;
1278 label = done
1279 ? resolve(
1280 msg(
1281 "{count, plural, one {Waited on threads {count} time} other {Waited on threads {count} times}}",
1282 { count },
1283 ),
1284 )
1285 : resolve(
1286 msg(
1287 "{count, plural, one {Tried to wait on threads {count} time} other {Tried to wait on threads {count} times}}",
1288 { count },
1289 ),
1290 );
1291 }
1292 break;
1293 }
1294 case "thread-send": {
1295 const messages = countEntities(selected.map((call) => id(call.output?.messageId)));
1296 const threads = new Set(threadIds).size;
1297 if (!threadIds.every((value) => value !== undefined)) {
1298 const count = messages;
1299 label = done
1300 ? resolve(
1301 msg("{count, plural, one {Sent {count} message} other {Sent {count} messages}}", {
1302 count,
1303 }),
1304 )
1305 : resolve(
1306 msg(
1307 "{count, plural, one {Tried to send {count} message} other {Tried to send {count} messages}}",
1308 { count },
1309 ),
1310 );
1311 } else if (messages === threads && messages > 1) {
1312 label = done
1313 ? resolve(
1314 msg(
1315 "{threads, plural, one {Sent messages to {threads} thread} other {Sent messages to {threads} threads}}",
1316 { threads },
1317 ),
1318 )
1319 : resolve(
1320 msg(
1321 "{threads, plural, one {Tried to send messages to {threads} thread} other {Tried to send messages to {threads} threads}}",
1322 { threads },
1323 ),
1324 );
1325 } else {
1326 label = done
1327 ? resolve(
1328 msg(
1329 "{messages, plural, one {Sent {messages} message to {threads, plural, one {{threads} thread} other {{threads} threads}}} other {Sent {messages} messages to {threads, plural, one {{threads} thread} other {{threads} threads}}}}",
1330 { messages, threads },
1331 ),
1332 )
1333 : resolve(
1334 msg(
1335 "{messages, plural, one {Tried to send {messages} message to {threads, plural, one {{threads} thread} other {{threads} threads}}} other {Tried to send {messages} messages to {threads, plural, one {{threads} thread} other {{threads} threads}}}}",
1336 { messages, threads },
1337 ),
1338 );
1339 }
1340 break;
1341 }
1342 case "thread-create": {
1343 const createdIds: string[] = [];
1344 const resultsKnown =
1345 completed.length > 0 &&
1346 completed.every((call) => {
1347 const threads = Array.isArray(call.output?.threads) ? call.output.threads : [call.output];
1348 return threads.every((thread) => {
1349 const record = asRecord(thread);
1350 if (record?.status === "rolled_back") return true;
1351 const threadId = id(record?.threadId);
1352 if (!threadId) return false;
1353 createdIds.push(threadId);
1354 return true;
1355 });
1356 });
1357 if (resultsKnown) {
1358 const count = new Set(createdIds).size;
1359 label = resolve(
1360 msg("{count, plural, one {Created {count} thread} other {Created {count} threads}}", {
1361 count,
1362 }),
1363 );
1364 } else {
1365 const count = selected.length;
1366 label = resolve(
1367 msg(
1368 "{count, plural, one {Requested thread creation {count} time} other {Requested thread creation {count} times}}",
1369 { count },
1370 ),
1371 );
1372 }
1373 break;
1374 }
1375 case "attachment-send": {
1376 const messages = new Map<string, (typeof selected)[number]>();
1377 selected.forEach((call, index) =>
1378 messages.set(id(call.output?.messageId) ?? `call-${index}`, call),
1379 );
1380 const attachments = [...messages.values()].reduce(
1381 (count, call) =>
1382 count + (Array.isArray(call.input?.attachments) ? call.input.attachments.length : 0),
1383 0,
1384 );
1385 const countsKnown = [...messages.values()].every(
1386 (call) => Array.isArray(call.input?.attachments) && call.input.attachments.length > 0,
1387 );
1388 const threads = new Set(threadIds).size;
1389 const count = selected.length;
1390 if (threadIds.every((value) => value !== undefined)) {
1391 label = countsKnown
1392 ? done
1393 ? resolve(
1394 msg(
1395 "{attachments, plural, one {Sent {attachments} attachment to {threads, plural, one {{threads} thread} other {{threads} threads}}} other {Sent {attachments} attachments to {threads, plural, one {{threads} thread} other {{threads} threads}}}}",
1396 { attachments, threads },
1397 ),
1398 )
1399 : resolve(
1400 msg(
1401 "{attachments, plural, one {Tried to send {attachments} attachment to {threads, plural, one {{threads} thread} other {{threads} threads}}} other {Tried to send {attachments} attachments to {threads, plural, one {{threads} thread} other {{threads} threads}}}}",
1402 { attachments, threads },
1403 ),
1404 )
1405 : done
1406 ? resolve(
1407 msg(
1408 "{count, plural, one {Sent attachments to {threads, plural, one {{threads} thread} other {{threads} threads}} {count} time} other {Sent attachments to {threads, plural, one {{threads} thread} other {{threads} threads}} {count} times}}",
1409 { threads, count },
1410 ),
1411 )
1412 : resolve(
1413 msg(
1414 "{count, plural, one {Tried to send attachments to {threads, plural, one {{threads} thread} other {{threads} threads}} {count} time} other {Tried to send attachments to {threads, plural, one {{threads} thread} other {{threads} threads}} {count} times}}",
1415 { threads, count },
1416 ),
1417 );
1418 } else {
1419 label = countsKnown
1420 ? done
1421 ? resolve(
1422 msg(
1423 "{attachments, plural, one {Sent {attachments} attachment} other {Sent {attachments} attachments}}",
1424 { attachments },
1425 ),
1426 )
1427 : resolve(
1428 msg(
1429 "{attachments, plural, one {Tried to send {attachments} attachment} other {Tried to send {attachments} attachments}}",
1430 { attachments },
1431 ),
1432 )
1433 : done
1434 ? resolve(
1435 msg(
1436 "{count, plural, one {Sent attachments {count} time} other {Sent attachments {count} times}}",
1437 { count },
1438 ),
1439 )
1440 : resolve(
1441 msg(
1442 "{count, plural, one {Tried to send attachments {count} time} other {Tried to send attachments {count} times}}",
1443 { count },
1444 ),
1445 );
1446 }
1447 break;
1448 }
1449 case "link-pr": {
1450 const count = pullRequestCount(selected, "linkedCount");
1451 if (count === null) {
1452 label = done
1453 ? resolve(msg("Linked pull requests"))
1454 : resolve(msg("Tried to link pull requests"));
1455 } else {
1456 label = done
1457 ? resolve(
1458 msg(
1459 "{count, plural, one {Linked {count} pull request} other {Linked {count} pull requests}}",
1460 { count },
1461 ),
1462 )
1463 : resolve(
1464 msg(
1465 "{count, plural, one {Tried to link {count} pull request} other {Tried to link {count} pull requests}}",
1466 { count },
1467 ),
1468 );
1469 }
1470 break;
1471 }
1472 case "unlink-pr": {
1473 const count = pullRequestCount(selected, "unlinkedCount");
1474 if (count === null) {
1475 label = done
1476 ? resolve(msg("Unlinked pull requests"))
1477 : resolve(msg("Tried to unlink pull requests"));
1478 } else {
1479 label = done
1480 ? resolve(
1481 msg(
1482 "{count, plural, one {Unlinked {count} pull request} other {Unlinked {count} pull requests}}",
1483 { count },
1484 ),
1485 )
1486 : resolve(
1487 msg(
1488 "{count, plural, one {Tried to unlink {count} pull request} other {Tried to unlink {count} pull requests}}",
1489 { count },
1490 ),
1491 );
1492 }
1493 break;
1494 }
1495 case "list-prs": {
1496 const count = selected.length;
1497 if (count === 1) {
1498 label = done
1499 ? resolve(msg("Checked linked pull requests"))
1500 : resolve(msg("Tried to check linked pull requests"));
1501 } else {
1502 label = done
1503 ? resolve(
1504 msg(
1505 "{count, plural, one {Checked linked pull requests {count} time} other {Checked linked pull requests {count} times}}",
1506 { count },
1507 ),
1508 )
1509 : resolve(
1510 msg(
1511 "{count, plural, one {Tried to check linked pull requests {count} time} other {Tried to check linked pull requests {count} times}}",
1512 { count },
1513 ),
1514 );
1515 }
1516 break;
1517 }
1518 case "write-pr-guides": {
1519 // One call writes many guides, and reports a refusal per guide rather than failing.
1520 const outcomes = selected.flatMap((call) =>
1521 Array.isArray(call.output?.guides)
1522 ? call.output.guides.map((guide) => asRecord(guide)?.outcome)
1523 : [],
1524 );
1525 const started = outcomes.filter((outcome) => outcome !== "failed").length;
1526 const failed = outcomes.length - started;
1527 failedCount += failed;
1528 if (outcomes.length === 0) {
1529 const count = selected.length;
1530 label =
1531 count === 1
1532 ? done
1533 ? resolve(msg("Started writing review guides"))
1534 : resolve(msg("Tried to start writing review guides"))
1535 : done
1536 ? resolve(
1537 msg(
1538 "{count, plural, one {Started writing review guides {count} time} other {Started writing review guides {count} times}}",
1539 { count },
1540 ),
1541 )
1542 : resolve(
1543 msg(
1544 "{count, plural, one {Tried to start writing review guides {count} time} other {Tried to start writing review guides {count} times}}",
1545 { count },
1546 ),
1547 );
1548 } else if (started === 0) {
1549 label = resolve(
1550 msg(
1551 "{failed, plural, one {Could not start {failed} review guide} other {Could not start {failed} review guides}}",
1552 { failed },
1553 ),
1554 );
1555 } else if (failed > 0) {
1556 label = done
1557 ? resolve(
1558 msg(
1559 "{started, plural, one {Started {started} review guide, {failed} failed} other {Started {started} review guides, {failed} failed}}",
1560 { started, failed },
1561 ),
1562 )
1563 : resolve(
1564 msg(
1565 "{started, plural, one {Tried to start {started} review guide, {failed} failed} other {Tried to start {started} review guides, {failed} failed}}",
1566 { started, failed },
1567 ),
1568 );
1569 } else {
1570 label = done
1571 ? resolve(
1572 msg(
1573 "{started, plural, one {Started {started} review guide} other {Started {started} review guides}}",
1574 { started },
1575 ),
1576 )
1577 : resolve(
1578 msg(
1579 "{started, plural, one {Tried to start {started} review guide} other {Tried to start {started} review guides}}",
1580 { started },
1581 ),
1582 );
1583 }
1584 break;
1585 }
1586 case "read-pr": {
1587 const count = selected.length;
1588 label = done
1589 ? resolve(
1590 msg(
1591 "{count, plural, one {Read {count} pull request} other {Read {count} pull requests}}",
1592 { count },
1593 ),
1594 )
1595 : resolve(
1596 msg(
1597 "{count, plural, one {Tried to read {count} pull request} other {Tried to read {count} pull requests}}",
1598 { count },
1599 ),
1600 );
1601 break;
1602 }
1603 case "list-repo-prs": {
1604 const count = selected.length;
1605 label = done
1606 ? resolve(
1607 msg(
1608 "{count, plural, one {Listed pull requests {count} time} other {Listed pull requests {count} times}}",
1609 { count },
1610 ),
1611 )
1612 : resolve(
1613 msg(
1614 "{count, plural, one {Tried to list pull requests {count} time} other {Tried to list pull requests {count} times}}",
1615 { count },
1616 ),
1617 );
1618 break;
1619 }
1620 case "create-pr": {
1621 // An open PR for the branch is returned rather than duplicated.
1622 const existing = selected.filter((call) => call.output?.created === false).length;
1623 const opened = selected.length - existing;
1624 label = !done
1625 ? resolve(
1626 msg(
1627 "{count, plural, one {Tried to open {count} pull request} other {Tried to open {count} pull requests}}",
1628 { count: selected.length },
1629 ),
1630 )
1631 : opened === 0
1632 ? resolve(
1633 msg(
1634 "{count, plural, one {Found {count} open pull request} other {Found {count} open pull requests}}",
1635 { count: existing },
1636 ),
1637 )
1638 : existing === 0
1639 ? resolve(
1640 msg(
1641 "{count, plural, one {Opened {count} pull request} other {Opened {count} pull requests}}",
1642 { count: opened },
1643 ),
1644 )
1645 : resolve(
1646 msg(
1647 "{opened, plural, one {Opened {opened} pull request, found {existing} open} other {Opened {opened} pull requests, found {existing} open}}",
1648 { opened, existing },
1649 ),
1650 );
1651 break;
1652 }
1653 case "update-pr": {
1654 const count = selected.length;
1655 label = done
1656 ? resolve(
1657 msg(
1658 "{count, plural, one {Updated {count} pull request} other {Updated {count} pull requests}}",
1659 { count },
1660 ),
1661 )
1662 : resolve(
1663 msg(
1664 "{count, plural, one {Tried to update {count} pull request} other {Tried to update {count} pull requests}}",
1665 { count },
1666 ),
1667 );
1668 break;
1669 }
1670 case "respond-pr": {
1671 const count = selected.length;
1672 label = done
1673 ? resolve(
1674 msg(
1675 "{count, plural, one {Responded on pull requests {count} time} other {Responded on pull requests {count} times}}",
1676 { count },
1677 ),
1678 )
1679 : resolve(
1680 msg(
1681 "{count, plural, one {Tried to respond on pull requests {count} time} other {Tried to respond on pull requests {count} times}}",
1682 { count },
1683 ),
1684 );
1685 break;
1686 }
1687 case "merge-pr": {
1688 // Auto-merge and merge queues leave the PR open until it lands.
1689 const queued = selected.filter((call) =>
1690 call.output?.state === undefined
1691 ? call.input?.auto === true
1692 : call.output.state !== "merged",
1693 ).length;
1694 const merged = selected.length - queued;
1695 label = !done
1696 ? resolve(
1697 msg(
1698 "{count, plural, one {Tried to merge {count} pull request} other {Tried to merge {count} pull requests}}",
1699 { count: selected.length },
1700 ),
1701 )
1702 : merged === 0
1703 ? resolve(
1704 msg(
1705 "{count, plural, one {Queued {count} pull request to merge} other {Queued {count} pull requests to merge}}",
1706 { count: queued },
1707 ),
1708 )
1709 : queued === 0
1710 ? resolve(
1711 msg(
1712 "{count, plural, one {Merged {count} pull request} other {Merged {count} pull requests}}",
1713 { count: merged },
1714 ),
1715 )
1716 : resolve(
1717 msg(
1718 "{merged, plural, one {Merged {merged} pull request, queued {queued}} other {Merged {merged} pull requests, queued {queued}}}",
1719 { merged, queued },
1720 ),
1721 );
1722 break;
1723 }
1724 case "ci-logs": {
1725 const count = selected.length;
1726 label = done
1727 ? resolve(
1728 msg(
1729 "{count, plural, one {Read CI logs {count} time} other {Read CI logs {count} times}}",
1730 { count },
1731 ),
1732 )
1733 : resolve(
1734 msg(
1735 "{count, plural, one {Tried to read CI logs {count} time} other {Tried to read CI logs {count} times}}",
1736 { count },
1737 ),
1738 );
1739 break;
1740 }
1741 case "ci-rerun": {
1742 // A host can refuse a check it cannot re-run, such as one outside its CI.
1743 const outcomes = selected.flatMap((call) =>
1744 Array.isArray(call.output?.checks)
1745 ? call.output.checks.map((check) => asRecord(check)?.rerun === true)
1746 : [],
1747 );
1748 const rerun = outcomes.filter(Boolean).length;
1749 const refused = outcomes.length - rerun;
1750 failedCount += refused;
1751 if (!done) {
1752 label = resolve(
1753 msg(
1754 "{count, plural, one {Tried to re-run CI {count} time} other {Tried to re-run CI {count} times}}",
1755 { count: selected.length },
1756 ),
1757 );
1758 } else if (outcomes.length === 0) {
1759 // An empty list means no check had failed, so nothing was asked of the host.
1760 label = selected.some((call) => Array.isArray(call.output?.checks))
1761 ? resolve(msg("Found no failed checks to re-run"))
1762 : resolve(
1763 msg("{count, plural, one {Re-ran CI {count} time} other {Re-ran CI {count} times}}", {
1764 count: selected.length,
1765 }),
1766 );
1767 } else if (rerun === 0) {
1768 label = resolve(
1769 msg(
1770 "{count, plural, one {Could not re-run {count} check} other {Could not re-run {count} checks}}",
1771 { count: refused },
1772 ),
1773 );
1774 } else if (refused === 0) {
1775 label = resolve(
1776 msg("{count, plural, one {Re-ran {count} check} other {Re-ran {count} checks}}", {
1777 count: rerun,
1778 }),
1779 );
1780 } else {
1781 label = resolve(
1782 msg(
1783 "{rerun, plural, one {Re-ran {rerun} check, {refused} refused} other {Re-ran {rerun} checks, {refused} refused}}",
1784 { rerun, refused },
1785 ),
1786 );
1787 }
1788 break;
1789 }
1790 case "review-pr": {
1791 const count = selected.length;
1792 label = done
1793 ? resolve(
1794 msg(
1795 "{count, plural, one {Reviewed {count} pull request} other {Reviewed {count} pull requests}}",
1796 { count },
1797 ),
1798 )
1799 : resolve(
1800 msg(
1801 "{count, plural, one {Tried to review {count} pull request} other {Tried to review {count} pull requests}}",
1802 { count },
1803 ),
1804 );
1805 break;
1806 }
1807 }
1808 return { label, failedCount };
1809 }