@workerdeck/ui 0.16.0 → 0.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/README.md +7 -0
  2. package/build/{SessionPanel-B9CHoq8x.d.mts → SessionPanel-CnU_IJ3-.d.mts} +36 -9
  3. package/build/{SessionPanel-DII9MmQ8.mjs → SessionPanel-DPx8Iz8a.mjs} +1432 -384
  4. package/build/SessionPanel-DPx8Iz8a.mjs.map +1 -0
  5. package/build/{format-DfI_je9S.d.mts → format-ljc3lKpA.d.mts} +1 -1
  6. package/build/format.d.mts +16 -5
  7. package/build/format.mjs +2 -3
  8. package/build/index.d.mts +288 -8
  9. package/build/index.mjs +620 -165
  10. package/build/index.mjs.map +1 -1
  11. package/build/{format-DqR56Y8l.mjs → status-BE-zg88x.mjs} +154 -2
  12. package/build/status-BE-zg88x.mjs.map +1 -0
  13. package/build/workspace.d.mts +4 -1
  14. package/build/workspace.mjs +4 -3
  15. package/build/workspace.mjs.map +1 -1
  16. package/package.json +8 -6
  17. package/src/components/agent/ContextRing.tsx +41 -0
  18. package/src/components/agent/EngineIcon.tsx +40 -0
  19. package/src/components/agent/ProjectIcon.tsx +119 -0
  20. package/src/components/agent/SessionBrowser.tsx +191 -17
  21. package/src/components/agent/SessionPanel.tsx +177 -2
  22. package/src/components/agent/SessionSteps.tsx +233 -0
  23. package/src/components/agent/SessionWorkspace.tsx +4 -0
  24. package/src/components/agent/StatusBar.tsx +4 -2
  25. package/src/components/agent/SubagentStrip.tsx +134 -0
  26. package/src/components/agent/ToolCallCard.tsx +72 -5
  27. package/src/components/agent/Transcript.tsx +212 -23
  28. package/src/components/agent/tool-result-fetch.tsx +36 -0
  29. package/src/components/agent/tool-result-image.tsx +209 -0
  30. package/src/components/agent/transcript-rows.ts +122 -23
  31. package/src/components/terminal/TerminalTranscript.tsx +154 -2
  32. package/src/components/terminal/affordances.tsx +34 -0
  33. package/src/components/terminal/blocks.ts +260 -0
  34. package/src/components/terminal/height.ts +73 -6
  35. package/src/components/terminal/image-box.ts +53 -0
  36. package/src/components/terminal/items.tsx +116 -79
  37. package/src/components/terminal/result-preview.ts +20 -6
  38. package/src/components/terminal/scrubber.tsx +172 -26
  39. package/src/components/terminal/tool-run.ts +177 -0
  40. package/src/index.ts +20 -1
  41. package/src/lib/status.ts +16 -3
  42. package/src/styles/terminal.css +85 -5
  43. package/src/styles/theme.css +42 -0
  44. package/build/SessionPanel-DII9MmQ8.mjs.map +0 -1
  45. package/build/format-DqR56Y8l.mjs.map +0 -1
  46. package/build/status-Ydzi7n6j.mjs +0 -143
  47. package/build/status-Ydzi7n6j.mjs.map +0 -1
@@ -1 +0,0 @@
1
- {"version":3,"file":"format-DqR56Y8l.mjs","names":[],"sources":["../src/lib/format.ts"],"sourcesContent":["export function formatCost(usd: number | undefined): string {\n if (usd === undefined || Number.isNaN(usd)) return '—'\n if (usd === 0) return '$0.00'\n if (usd < 0.01) return '<$0.01'\n return `$${usd.toFixed(2)}`\n}\n\nexport function formatDuration(ms: number): string {\n if (ms < 1000) return `${Math.round(ms)}ms`\n const s = ms / 1000\n if (s < 60) return `${s.toFixed(1)}s`\n const m = Math.floor(s / 60)\n return `${m}m ${Math.round(s % 60)}s`\n}\n\n/** Compact token count, Claude Code-style: 850 → \"850\", 359_000 → \"359.0k\", 1_200_000 → \"1.2M\". */\nexport function formatTokens(tokens: number): string {\n if (tokens >= 1_000_000) return `${(tokens / 1_000_000).toFixed(1)}M`\n if (tokens >= 1000) return `${(tokens / 1000).toFixed(1)}k`\n return String(Math.round(tokens))\n}\n\nexport function formatBytes(bytes: number): string {\n if (bytes >= 1024 * 1024) return `${(bytes / (1024 * 1024)).toFixed(1)} MB`\n if (bytes >= 1024) return `${(bytes / 1024).toFixed(1)} KB`\n return `${bytes} B`\n}\n\n/** Countdown to an epoch-ms deadline: \"2h 18m\", \"12m\", \"<1m\"; \"now\" once passed. */\nexport function formatCountdown(untilEpochMs: number, now = Date.now()): string {\n const remaining = untilEpochMs - now\n if (remaining <= 0) return 'now'\n const minutes = Math.ceil(remaining / 60_000)\n if (minutes < 1) return '<1m'\n if (minutes < 60) return `${minutes}m`\n const days = Math.floor(minutes / (60 * 24))\n if (days >= 1) return `${days}d ${Math.floor((minutes % (60 * 24)) / 60)}h`\n return `${Math.floor(minutes / 60)}h ${minutes % 60}m`\n}\n\nexport function formatRelativeTime(epochMs: number | undefined, now = Date.now()): string {\n if (!epochMs) return '—'\n const diff = Math.max(0, now - epochMs)\n const s = Math.floor(diff / 1000)\n if (s < 60) return 'just now'\n const m = Math.floor(s / 60)\n if (m < 60) return `${m}m ago`\n const h = Math.floor(m / 60)\n if (h < 24) return `${h}h ago`\n const d = Math.floor(h / 24)\n return `${d}d ago`\n}\n\n/**\n * Human label for a rate-limit window key, compact: 'five_hour' → \"5h\",\n * 'seven_day_opus' → \"7d opus\". The per-model suffix is an open set — the CLI\n * adds buckets as plans gain them — so it is rewritten rather than enumerated.\n */\nexport function formatRateLimitWindow(key: string): string {\n if (key === 'five_hour') return '5h'\n if (key === 'seven_day') return '7d'\n const spaced = key.replaceAll('_', ' ')\n return key.startsWith('seven_day_') ? `7d ${spaced.slice('seven day '.length)}` : spaced\n}\n\n/** The same key spelled out, where there is room: 'five_hour' → \"5-hour\n * session\", 'seven_day_fable' → \"Weekly · Fable\". */\nexport function formatRateLimitWindowLong(key: string): string {\n if (key === 'five_hour') return '5-hour session'\n if (key === 'seven_day') return 'Weekly'\n if (key === 'seven_day_oauth_apps') return 'Weekly · apps'\n const capitalize = (s: string) => s.replace(/\\b\\w/g, (c) => c.toUpperCase())\n if (!key.startsWith('seven_day_')) return capitalize(key.replaceAll('_', ' '))\n return `Weekly · ${capitalize(key.slice('seven_day_'.length).replaceAll('_', ' '))}`\n}\n\n/**\n * How long a rate-limit window is, in seconds — the denominator behind the pace\n * marker. Derived from the key rather than reported: the CLI sends a reset time\n * and a percentage, never a duration. `undefined` for a window whose key doesn't\n * say, and the marker is then simply not drawn rather than guessed.\n */\nexport function rateLimitWindowSeconds(key: string): number | undefined {\n if (key === 'five_hour') return 5 * 3600\n if (key.startsWith('seven_day')) return 7 * 86_400\n return undefined\n}\n\n/** \"8 secs ago\" / \"3 mins ago\" — a freshness line finer-grained than\n * {@link formatRelativeTime}, because a poll that just landed should say so. */\nexport function formatAgoPrecise(epochMs: number, now = Date.now()): string {\n const seconds = Math.max(0, Math.floor((now - epochMs) / 1000))\n if (seconds < 60) return `${seconds} sec${seconds === 1 ? '' : 's'} ago`\n if (seconds < 3600) {\n const minutes = Math.floor(seconds / 60)\n return `${minutes} min${minutes === 1 ? '' : 's'} ago`\n }\n const hours = Math.floor(seconds / 3600)\n return `${hours} hour${hours === 1 ? '' : 's'} ago`\n}\n\n/** Compact one-line preview of a tool input for card headers. */\nexport function toolInputPreview(input: unknown, max = 80): string {\n if (input === null || input === undefined) return ''\n if (typeof input === 'object') {\n const o = input as Record<string, unknown>\n const primary =\n o.command ?? o.file_path ?? o.path ?? o.url ?? o.pattern ?? o.query ?? o.description\n if (typeof primary === 'string') {\n return primary.length > max ? primary.slice(0, max - 1) + '…' : primary\n }\n }\n const text = JSON.stringify(input) ?? ''\n return text.length > max ? text.slice(0, max - 1) + '…' : text\n}\n\n/** Families whose name isn't just a capitalised first letter, and how the\n * vendor writes the version after it. GPT is `GPT-5.6`; everyone else spaces\n * it. Anything unlisted is title-cased and spaced. */\nconst MODEL_FAMILIES: Record<string, { name: string; joiner?: string }> = {\n gpt: { name: 'GPT', joiner: '-' },\n deepseek: { name: 'DeepSeek' },\n glm: { name: 'GLM' },\n qwen: { name: 'Qwen' },\n kimi: { name: 'Kimi' },\n llama: { name: 'Llama' },\n mistral: { name: 'Mistral' },\n grok: { name: 'Grok' },\n}\n\n/**\n * The name a person says, from a wire model id:\n *\n * - `claude-opus-5[1m]` → \"Opus 5\"\n * - `claude-haiku-4-5-20251001` → \"Haiku 4.5\"\n * - `gpt-5.6-luna` → \"GPT-5.6 Luna\"\n * - `gemini-2.5-pro` → \"Gemini 2.5 Pro\"\n * - `o3-mini` → \"o3 Mini\"\n *\n * Three kinds of token after the family, because vendors mix them freely: a\n * **version** (`5`, `4-5`, `5.6` — joined with dots, since Anthropic splits what\n * OpenAI writes as one token), a **code name or tier** (`luna`, `codex`, `pro`,\n * `mini` — kept and capitalised, since it is often the only thing telling two\n * models apart), and a **snapshot date** (`20251001` — dropped; it is a build,\n * not a version).\n *\n * Anything genuinely unreadable falls back to the id: a wrong name is worse than\n * a raw one, which is at least true.\n *\n * The server has a narrower version of this (`friendlyModelName` in core's\n * `normalize.ts`) that derives Claude catalog names at authoring time. This one\n * is the *render-time* fallback for an id with no catalog row behind it — the\n * sidebar has only `SessionInfo.model` — so it has to cope with every vendor the\n * provider engine can reach, not just the CLI's own.\n */\nexport function friendlyModel(id: string | undefined): string | undefined {\n if (!id) return undefined\n const withoutVariant = id.split('[')[0] ?? id\n const parts = withoutVariant.toLowerCase().split('-').filter(Boolean)\n if (parts[0] === 'claude') parts.shift()\n const familyToken = parts.shift()\n if (!familyToken) return id\n const family = MODEL_FAMILIES[familyToken]\n const name =\n family?.name ??\n // OpenAI's reasoning series is lower-case by its own convention ('o3-mini'),\n // and \"O3\" reads as a different product.\n (/^o\\d+$/.test(familyToken)\n ? familyToken\n : `${familyToken.charAt(0).toUpperCase()}${familyToken.slice(1)}`)\n\n const version: string[] = []\n const words: string[] = []\n for (const part of parts) {\n if (/^\\d{8}$/.test(part)) continue\n if (/^\\d+(\\.\\d+)?$/.test(part)) version.push(part)\n else words.push(`${part.charAt(0).toUpperCase()}${part.slice(1)}`)\n }\n const versioned = version.length > 0 ? `${name}${family?.joiner ?? ' '}${version.join('.')}` : name\n return [versioned, ...words].join(' ')\n}\n"],"mappings":";AAAA,SAAgB,WAAW,KAAiC;AAC1D,KAAI,QAAQ,KAAA,KAAa,OAAO,MAAM,IAAI,CAAE,QAAO;AACnD,KAAI,QAAQ,EAAG,QAAO;AACtB,KAAI,MAAM,IAAM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I,CAAC,YAAa,QAAO;CACzB,MAAM,SAAS,eAAe;CAC9B,MAAM,OACJ,QAAQ,SAGP,SAAS,KAAK,YAAY,GACvB,cACA,GAAG,YAAY,OAAO,EAAE,CAAC,aAAa,GAAG,YAAY,MAAM,EAAE;CAEnE,MAAM,UAAoB,EAAE;CAC5B,MAAM,QAAkB,EAAE;AAC1B,MAAK,MAAM,QAAQ,OAAO;AACxB,MAAI,UAAU,KAAK,KAAK,CAAE;AAC1B,MAAI,gBAAgB,KAAK,KAAK,CAAE,SAAQ,KAAK,KAAK;MAC7C,OAAM,KAAK,GAAG,KAAK,OAAO,EAAE,CAAC,aAAa,GAAG,KAAK,MAAM,EAAE,GAAG;;AAGpE,QAAO,CADW,QAAQ,SAAS,IAAI,GAAG,OAAO,QAAQ,UAAU,MAAM,QAAQ,KAAK,IAAI,KAAK,MAC5E,GAAG,MAAM,CAAC,KAAK,IAAI"}
@@ -1,143 +0,0 @@
1
- //#region src/lib/status.ts
2
- const STATUS_META = {
3
- starting: {
4
- icon: "loading~spin",
5
- label: "Starting",
6
- severity: "none"
7
- },
8
- running: {
9
- icon: "loading~spin",
10
- label: "Running",
11
- severity: "none"
12
- },
13
- awaiting_approval: {
14
- icon: "warning",
15
- label: "Needs approval",
16
- severity: "warning"
17
- },
18
- idle: {
19
- icon: "check",
20
- label: "Idle",
21
- severity: "none"
22
- },
23
- parked: {
24
- icon: "debug-pause",
25
- label: "Parked",
26
- severity: "none"
27
- },
28
- failed: {
29
- icon: "error",
30
- label: "Failed",
31
- severity: "error"
32
- },
33
- closed: {
34
- icon: "circle-slash",
35
- label: "Closed",
36
- severity: "none"
37
- }
38
- };
39
- /**
40
- * The status slot, connection first. A session status held over a dead socket is
41
- * the last thing we heard, not the current state — so a lost link takes the slot
42
- * rather than letting "Running" imply a turn is still streaming.
43
- */
44
- function statusPresentation(vitals) {
45
- if (!vitals) return {
46
- icon: "hubot",
47
- label: "Connecting…",
48
- severity: "none"
49
- };
50
- if (vitals.connection === "offline") return {
51
- icon: "debug-disconnect",
52
- label: "Offline",
53
- severity: "error"
54
- };
55
- if (vitals.connection === "reconnecting") return {
56
- icon: "sync~spin",
57
- label: "Reconnecting…",
58
- severity: "warning"
59
- };
60
- return STATUS_META[vitals.status] ?? {
61
- icon: "hubot",
62
- label: vitals.status,
63
- severity: "none"
64
- };
65
- }
66
- /** 0–100 → the colour a meter wears. One pair of thresholds for every surface. */
67
- function meterSeverity(pct) {
68
- if (pct === void 0) return "none";
69
- if (pct >= 95) return "error";
70
- if (pct >= 80) return "warning";
71
- return "none";
72
- }
73
- /** The window a lane points at, or `undefined` when this account has none. */
74
- function usageWindow(rateLimits, lane) {
75
- if (!rateLimits) return void 0;
76
- if (lane === "session") {
77
- const info = rateLimits.five_hour;
78
- return info ? {
79
- key: "five_hour",
80
- info
81
- } : void 0;
82
- }
83
- if (lane === "weekly") {
84
- const info = rateLimits.seven_day;
85
- return info ? {
86
- key: "seven_day",
87
- info
88
- } : void 0;
89
- }
90
- return tightestWindow(Object.fromEntries(Object.entries(rateLimits).filter(([key]) => key.startsWith("seven_day_") && key !== "seven_day_oauth_apps")));
91
- }
92
- /** The rate-limit window that gets the one visible slot: whichever is fullest,
93
- * since the binding constraint is the one worth glancing at. Still the right
94
- * rule for a surface with exactly one slot; {@link usageWindow} is for one with
95
- * three. */
96
- function tightestWindow(rateLimits) {
97
- const entries = Object.entries(rateLimits ?? {});
98
- if (entries.length === 0) return void 0;
99
- let best;
100
- for (const [key, info] of entries) if ((info.status === "rejected" ? Number.POSITIVE_INFINITY : info.utilization ?? -1) > (best === void 0 ? Number.NEGATIVE_INFINITY : best.info.status === "rejected" ? Number.POSITIVE_INFINITY : best.info.utilization ?? -1)) best = {
101
- key,
102
- info
103
- };
104
- return best;
105
- }
106
- /** A rate-limit window's key, named for a human. A model-scoped bucket is named
107
- * for its model alone (`seven_day_fable` → "Fable"): the lane it sits in
108
- * already says weekly, and "Seven day fable" in a status bar is three words to
109
- * say one. */
110
- function windowLabel(key) {
111
- if (key === "five_hour") return "Session";
112
- if (key === "seven_day") return "Weekly";
113
- const words = (key.startsWith("seven_day_") ? key.slice(10) : key).replaceAll("_", " ");
114
- return words.charAt(0).toUpperCase() + words.slice(1);
115
- }
116
- /**
117
- * The catalog row a session is actually running, or `undefined` for a model the
118
- * list doesn't name. Matched leniently: a session reports the *resolved* id
119
- * (`claude-sonnet-5`) where the row may be keyed on the alias (`sonnet`), and
120
- * either can carry a `[1m]` context-window suffix.
121
- */
122
- function currentModel(vitals) {
123
- const id = vitals?.model;
124
- if (!id) return void 0;
125
- const bare = (value) => value.replace(/\[.*\]$/, "");
126
- const wanted = bare(id);
127
- return vitals.models.find((m) => bare(m.value) === wanted || m.resolvedModel && bare(m.resolvedModel) === wanted);
128
- }
129
- /** A session's model, named the way the picker names it. Falls back to the raw
130
- * id, and to "Default" while the session is on the CLI's own pick. */
131
- function modelLabel(vitals) {
132
- if (!vitals?.model) return "Default";
133
- return currentModel(vitals)?.displayName ?? vitals.model;
134
- }
135
- /** Context percentage as its meter severity — the reading and the colour come
136
- * from one place so a panel and a status bar never disagree. */
137
- function contextSeverity(usage) {
138
- return meterSeverity(usage?.percentage);
139
- }
140
- //#endregion
141
- export { statusPresentation as a, windowLabel as c, modelLabel as i, currentModel as n, tightestWindow as o, meterSeverity as r, usageWindow as s, contextSeverity as t };
142
-
143
- //# sourceMappingURL=status-Ydzi7n6j.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"status-Ydzi7n6j.mjs","names":[],"sources":["../src/lib/status.ts"],"sourcesContent":["import type { ContextUsage, ModelOption, RateLimitInfo, SessionStatus } from '@workerdeck/protocol'\n\n/**\n * How a session's live readings become a status line — the pure half, so every\n * host spells \"Needs approval\", \"80% is a warning\" and \"which window is the\n * binding one\" the same way.\n *\n * Structurally typed against `SessionVitals` rather than importing it: this file\n * ships from the React-free `@workerdeck/ui/format` entry, and a host drawing\n * the readings outside React (the VS Code extension host in the window status\n * bar) must not pull a component graph in to do it. A real `SessionVitals`\n * satisfies every shape here.\n */\nexport type StatusSeverity = 'none' | 'warning' | 'error'\n\n/** What a status slot shows, before any host's icon vocabulary gets involved.\n * `icon` is a VS Code codicon name — the one host-shaped thing left, because the\n * alternative is a second mapping table in the only consumer. */\nexport type StatusPresentation = {\n icon: string\n label: string\n severity: StatusSeverity\n}\n\nexport type StatusReadings = {\n status: SessionStatus\n /** `@workerdeck/react`'s `ConnectionState`, structurally — the link state wins\n * the slot, so it has to be part of the reading. */\n connection?: 'live' | 'reconnecting' | 'offline'\n}\n\nconst STATUS_META: Record<SessionStatus, StatusPresentation> = {\n starting: { icon: 'loading~spin', label: 'Starting', severity: 'none' },\n running: { icon: 'loading~spin', label: 'Running', severity: 'none' },\n awaiting_approval: { icon: 'warning', label: 'Needs approval', severity: 'warning' },\n idle: { icon: 'check', label: 'Idle', severity: 'none' },\n parked: { icon: 'debug-pause', label: 'Parked', severity: 'none' },\n failed: { icon: 'error', label: 'Failed', severity: 'error' },\n closed: { icon: 'circle-slash', label: 'Closed', severity: 'none' },\n}\n\n/**\n * The status slot, connection first. A session status held over a dead socket is\n * the last thing we heard, not the current state — so a lost link takes the slot\n * rather than letting \"Running\" imply a turn is still streaming.\n */\nexport function statusPresentation(vitals: StatusReadings | undefined): StatusPresentation {\n if (!vitals) return { icon: 'hubot', label: 'Connecting…', severity: 'none' }\n if (vitals.connection === 'offline') {\n return { icon: 'debug-disconnect', label: 'Offline', severity: 'error' }\n }\n if (vitals.connection === 'reconnecting') {\n return { icon: 'sync~spin', label: 'Reconnecting…', severity: 'warning' }\n }\n return STATUS_META[vitals.status] ?? { icon: 'hubot', label: vitals.status, severity: 'none' }\n}\n\n/** 0–100 → the colour a meter wears. One pair of thresholds for every surface. */\nexport function meterSeverity(pct: number | undefined): StatusSeverity {\n if (pct === undefined) return 'none'\n if (pct >= 95) return 'error'\n if (pct >= 80) return 'warning'\n return 'none'\n}\n\n/**\n * The three *lanes* a plan-usage reading can occupy, and the whole reason this\n * is a rule rather than a per-client `if`.\n *\n * The CLI reports one window per limit (`five_hour`, `seven_day`, and a\n * `seven_day_<model>` bucket per model-scoped limit — `seven_day_opus`,\n * `seven_day_sonnet`, and whatever `model_scoped` names next). A surface with\n * one slot shows the fullest of them, which is why `tightestWindow` exists —\n * but that answers \"what is closest to blocking me\", not \"how much of *this\n * session's* budget have I spent\", and those are different questions a reader\n * asks at different times. A weekly window at 71% will win the single slot over\n * a five-hour window at 60% every time, so the reading you actually watch while\n * working is the one you can never see.\n *\n * Hence three lanes, each independently showable:\n *\n * - `'session'` — the five-hour window. The one that resets while you work.\n * - `'weekly'` — the plain seven-day window, the account-wide ceiling.\n * - `'model'` — the fullest of the *model-scoped* weekly buckets. Deliberately\n * not a named model: which models have their own bucket is the plan's\n * business and changes without notice, so a client that hardcoded\n * `seven_day_opus` would show nothing the month it becomes something else.\n * The label comes from the key, so this lane names whatever it found.\n */\nexport type UsageLane = 'session' | 'weekly' | 'model'\n\n/** The window a lane points at, or `undefined` when this account has none. */\nexport function usageWindow(\n rateLimits: Record<string, RateLimitInfo> | undefined,\n lane: UsageLane,\n): { key: string; info: RateLimitInfo } | undefined {\n if (!rateLimits) return undefined\n if (lane === 'session') {\n const info = rateLimits.five_hour\n return info ? { key: 'five_hour', info } : undefined\n }\n if (lane === 'weekly') {\n const info = rateLimits.seven_day\n return info ? { key: 'seven_day', info } : undefined\n }\n // Model-scoped: same \"fullest wins\" rule as the single slot, over the subset.\n const scoped = Object.fromEntries(\n Object.entries(rateLimits).filter(\n ([key]) => key.startsWith('seven_day_') && key !== 'seven_day_oauth_apps',\n ),\n )\n return tightestWindow(scoped)\n}\n\n/** The rate-limit window that gets the one visible slot: whichever is fullest,\n * since the binding constraint is the one worth glancing at. Still the right\n * rule for a surface with exactly one slot; {@link usageWindow} is for one with\n * three. */\nexport function tightestWindow(\n rateLimits: Record<string, RateLimitInfo> | undefined,\n): { key: string; info: RateLimitInfo } | undefined {\n const entries = Object.entries(rateLimits ?? {})\n if (entries.length === 0) return undefined\n let best: { key: string; info: RateLimitInfo } | undefined\n for (const [key, info] of entries) {\n // A rejected window outranks any utilization: it is the one actually blocking.\n const rank = info.status === 'rejected' ? Number.POSITIVE_INFINITY : (info.utilization ?? -1)\n const bestRank =\n best === undefined\n ? Number.NEGATIVE_INFINITY\n : best.info.status === 'rejected'\n ? Number.POSITIVE_INFINITY\n : (best.info.utilization ?? -1)\n if (rank > bestRank) best = { key, info }\n }\n return best\n}\n\n/** A rate-limit window's key, named for a human. A model-scoped bucket is named\n * for its model alone (`seven_day_fable` → \"Fable\"): the lane it sits in\n * already says weekly, and \"Seven day fable\" in a status bar is three words to\n * say one. */\nexport function windowLabel(key: string): string {\n if (key === 'five_hour') return 'Session'\n if (key === 'seven_day') return 'Weekly'\n const scoped = key.startsWith('seven_day_') ? key.slice('seven_day_'.length) : key\n const words = scoped.replaceAll('_', ' ')\n return words.charAt(0).toUpperCase() + words.slice(1)\n}\n\nexport type ModelReadings = { model?: string; models: readonly ModelOption[] }\n\n/**\n * The catalog row a session is actually running, or `undefined` for a model the\n * list doesn't name. Matched leniently: a session reports the *resolved* id\n * (`claude-sonnet-5`) where the row may be keyed on the alias (`sonnet`), and\n * either can carry a `[1m]` context-window suffix.\n */\nexport function currentModel(vitals: ModelReadings | undefined): ModelOption | undefined {\n const id = vitals?.model\n if (!id) return undefined\n const bare = (value: string) => value.replace(/\\[.*\\]$/, '')\n const wanted = bare(id)\n return vitals.models.find(\n (m) => bare(m.value) === wanted || (m.resolvedModel && bare(m.resolvedModel) === wanted),\n )\n}\n\n/** A session's model, named the way the picker names it. Falls back to the raw\n * id, and to \"Default\" while the session is on the CLI's own pick. */\nexport function modelLabel(vitals: ModelReadings | undefined): string {\n if (!vitals?.model) return 'Default'\n return currentModel(vitals)?.displayName ?? vitals.model\n}\n\n/** Context percentage as its meter severity — the reading and the colour come\n * from one place so a panel and a status bar never disagree. */\nexport function contextSeverity(usage: ContextUsage | undefined): StatusSeverity {\n return meterSeverity(usage?.percentage)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