Open History to see the last commit
1import type { OrchestrationV2TurnItemStatus } from "@t3tools/contracts";
2
3/** Summarizes one adjacent group, without changing its member identities or order. */
4export function subagentGroupSummary(
5 members: ReadonlyArray<{ readonly status: OrchestrationV2TurnItemStatus }>,
6) {
7 const active = members.some(
8 ({ status }) => status === "pending" || status === "running" || status === "waiting",
9 );
10 return {
11 label: `${active ? "Kicked off" : "Ran"} ${members.length} ${members.length === 1 ? "subagent" : "subagents"}`,
12 active,
13 failed: members.some(({ status }) => status === "failed"),
14 };
15}
16
17/**
18 * Counts a group's states in the order a reader scans them: what is still
19 * running first, then outcomes, using the agents panel's words.
20 */
21export function summarizeSubagentStatuses(
22 statuses: ReadonlyArray<OrchestrationV2TurnItemStatus>,
23): string {
24 const counts = { working: 0, done: 0, failed: 0, stopped: 0, idle: 0 };
25 for (const status of statuses) {
26 if (status === "pending" || status === "running" || status === "waiting") counts.working += 1;
27 else if (status === "completed") counts.done += 1;
28 else if (status === "failed") counts.failed += 1;
29 else if (status === "idle") counts.idle += 1;
30 else counts.stopped += 1;
31 }
32 return (Object.keys(counts) as Array<keyof typeof counts>)
33 .filter((key) => counts[key] > 0)
34 .map((key) => `${counts[key]} ${key}`)
35 .join(" · ");
36}
37
38/** Formats Codex task paths for display while leaving provider identity untouched. */
39export function formatSubagentDisplayTitle(title: string): string {
40 const displayTitle = title.replace(/^Subagent:\s*/i, "");
41 const path = /^\/root\/(?:[^/]+\/)*([^/]+)\/?$/u.exec(displayTitle);
42 if (path === null) return displayTitle;
43
44 const name = path[1]!.replace(/[_\s]+/gu, " ").trim();
45 return name.replace(/(^|\s)\S/gu, (letter) => letter.toUpperCase()) || displayTitle;
46}