@causyne/agent 1.20.112 → 1.20.117

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 (169) hide show
  1. package/docs/ARCHITECTURE.md +29 -0
  2. package/package.json +1 -1
  3. package/src/agentLoop.js +153 -68
  4. package/src/agentLoop.ts +152 -71
  5. package/src/browser/browserRuntime.js +13 -8
  6. package/src/browser/browserRuntime.ts +16 -8
  7. package/src/browser/causyneBrowser.js +37 -9
  8. package/src/browser/causyneBrowser.ts +37 -9
  9. package/src/browser/searchProviders.js +18 -7
  10. package/src/browser/searchProviders.ts +17 -5
  11. package/src/browser/snapshotWindow.js +1 -1
  12. package/src/browser/snapshotWindow.ts +1 -1
  13. package/src/browser/urlPolicy.js +21 -10
  14. package/src/browser/urlPolicy.ts +19 -10
  15. package/src/browser/workspacePreview.js +13 -1
  16. package/src/browser/workspacePreview.ts +11 -1
  17. package/src/cliMode.js +5 -1
  18. package/src/computerUse/visionGrounding.js +31 -27
  19. package/src/computerUse/visionGrounding.ts +27 -27
  20. package/src/continuum/ui/continuumPicker.js +14 -6
  21. package/src/continuum/ui/continuumPicker.ts +13 -6
  22. package/src/continuum/ui/continuumPickerView.js +24 -15
  23. package/src/continuum/ui/continuumPickerView.ts +24 -16
  24. package/src/memory/scopedFacts.js +171 -0
  25. package/src/memory/scopedFacts.ts +214 -0
  26. package/src/memory.d.ts +13 -1
  27. package/src/memory.js +9 -12
  28. package/src/observer/advisory.js +32 -22
  29. package/src/observer/advisory.ts +30 -18
  30. package/src/observer/coldObserver.js +21 -33
  31. package/src/observer/coldObserver.ts +20 -33
  32. package/src/observer/evidence.js +20 -13
  33. package/src/observer/evidence.ts +21 -13
  34. package/src/observer.js +47 -12
  35. package/src/observer.ts +50 -18
  36. package/src/perception.js +124 -3
  37. package/src/perception.ts +128 -4
  38. package/src/planCache.js +17 -3
  39. package/src/planCache.ts +17 -3
  40. package/src/pluginsFactory/discovery.js +28 -16
  41. package/src/pluginsFactory/discovery.ts +29 -16
  42. package/src/pluginsFactory/pluginsFactory.js +213 -38
  43. package/src/pluginsFactory/pluginsFactory.ts +218 -39
  44. package/src/pluginsFactory/strategy.js +26 -16
  45. package/src/pluginsFactory/strategy.ts +34 -19
  46. package/src/pluginsFactory/templates.js +183 -62
  47. package/src/pluginsFactory/templates.ts +174 -54
  48. package/src/smartToolsUse.js +4 -5
  49. package/src/smartToolsUse.ts +4 -6
  50. package/src/taskShape.js +49 -7
  51. package/src/taskShape.ts +55 -7
  52. package/src/timeMachine.js +43 -22
  53. package/src/timeMachine.ts +44 -22
  54. package/src/tool-scripts/desktop_act.applescript +1 -0
  55. package/src/toolPacks.js +27 -5
  56. package/src/toolPacks.ts +32 -5
  57. package/src/tools/computerUse.js +23 -10
  58. package/src/tools/computerUse.ts +19 -8
  59. package/src/tools/desktopAct.js +12 -1
  60. package/src/tools/memoryWrite.js +8 -10
  61. package/src/tools/memoryWrite.ts +13 -11
  62. package/src/tools/pluginsFactory.js +108 -5
  63. package/src/tools/pluginsFactory.ts +115 -5
  64. package/src/tui/CausyneRotor.js +24 -10
  65. package/src/tui/CausyneRotor.ts +25 -10
  66. package/src/tui/activityLayout.js +9 -5
  67. package/src/tui/activityLayout.ts +9 -5
  68. package/src/tui/ask.js +34 -14
  69. package/src/tui/banner.js +55 -18
  70. package/src/tui/banner.ts +52 -17
  71. package/src/tui/block.js +47 -20
  72. package/src/tui/block.ts +54 -27
  73. package/src/tui/chatRenderer.js +139 -84
  74. package/src/tui/chatboxClipboard.js +12 -5
  75. package/src/tui/chatboxClipboard.ts +10 -4
  76. package/src/tui/clipboardImage.js +52 -42
  77. package/src/tui/clipboardImage.ts +50 -39
  78. package/src/tui/clipboardSync.js +12 -1
  79. package/src/tui/clipboardSync.ts +9 -1
  80. package/src/tui/codeProgress.js +60 -28
  81. package/src/tui/codeProgress.ts +60 -27
  82. package/src/tui/codeStreamRenderer.js +94 -23
  83. package/src/tui/codeStreamRenderer.ts +92 -23
  84. package/src/tui/commandPresentation.js +9 -2
  85. package/src/tui/commandPresentation.ts +9 -2
  86. package/src/tui/completion.js +45 -23
  87. package/src/tui/composerControls.js +21 -10
  88. package/src/tui/composerControls.ts +18 -10
  89. package/src/tui/composerGeometry.js +6 -4
  90. package/src/tui/composerGeometry.ts +6 -4
  91. package/src/tui/consoleGuard.js +29 -7
  92. package/src/tui/consoleGuard.ts +28 -7
  93. package/src/tui/dialogs.js +134 -71
  94. package/src/tui/diff.js +8 -4
  95. package/src/tui/history.js +6 -5
  96. package/src/tui/home.js +25 -13
  97. package/src/tui/homeView.js +37 -18
  98. package/src/tui/homeView.ts +38 -18
  99. package/src/tui/inlineSlash.js +6 -5
  100. package/src/tui/inlineSlash.ts +6 -5
  101. package/src/tui/keys.js +36 -18
  102. package/src/tui/layout.js +27 -9
  103. package/src/tui/layout.ts +26 -9
  104. package/src/tui/lineEditor.js +49 -23
  105. package/src/tui/markdownMath.js +64 -14
  106. package/src/tui/markdownMath.ts +69 -13
  107. package/src/tui/messageActionPlacement.js +28 -13
  108. package/src/tui/messageActionPlacement.ts +28 -13
  109. package/src/tui/messageInteraction.js +111 -46
  110. package/src/tui/messageInteraction.ts +115 -47
  111. package/src/tui/modelPicker.js +44 -15
  112. package/src/tui/modelPicker.ts +48 -15
  113. package/src/tui/observerPicker.js +56 -13
  114. package/src/tui/observerPicker.ts +73 -30
  115. package/src/tui/overlay.js +79 -35
  116. package/src/tui/overlay.ts +81 -34
  117. package/src/tui/prompt.js +186 -94
  118. package/src/tui/runningLight.js +1 -1
  119. package/src/tui/runningLight.ts +1 -1
  120. package/src/tui/scrollInteraction.js +64 -36
  121. package/src/tui/scrollInteraction.ts +70 -37
  122. package/src/tui/selectList.js +60 -32
  123. package/src/tui/sessionLayout.js +11 -3
  124. package/src/tui/sessionLayout.ts +10 -3
  125. package/src/tui/sessionPicker.js +74 -46
  126. package/src/tui/sessionPicker.ts +73 -48
  127. package/src/tui/sessionPickerView.js +32 -19
  128. package/src/tui/sessionPickerView.ts +31 -18
  129. package/src/tui/sessionSidebar.js +87 -57
  130. package/src/tui/sessionSidebar.ts +90 -54
  131. package/src/tui/setup.js +28 -3
  132. package/src/tui/setup.ts +27 -3
  133. package/src/tui/skillAuthoring.js +11 -5
  134. package/src/tui/skillAuthoring.ts +11 -5
  135. package/src/tui/smartLinkClick.js +75 -23
  136. package/src/tui/smartLinkClick.ts +86 -26
  137. package/src/tui/stage.js +47 -16
  138. package/src/tui/stage.ts +53 -18
  139. package/src/tui/stageSurface.js +232 -51
  140. package/src/tui/statusLine.js +85 -53
  141. package/src/tui/statusLine.ts +82 -46
  142. package/src/tui/terminalInputFramer.js +5 -2
  143. package/src/tui/text.js +117 -46
  144. package/src/tui/text.ts +113 -43
  145. package/src/tui/textLayout.js +6 -4
  146. package/src/tui/textLayout.ts +11 -5
  147. package/src/tui/theme.js +17 -8
  148. package/src/tui/thinkingBox.js +95 -95
  149. package/src/tui/thinkingBox.ts +105 -80
  150. package/src/tui/toolActivityPolicy.js +8 -1
  151. package/src/tui/toolActivityPolicy.ts +7 -1
  152. package/src/tui/toolDisplay.js +15 -6
  153. package/src/tui/toolDisplay.ts +16 -6
  154. package/src/tui/toolOutputNormalizer.js +16 -3
  155. package/src/tui/toolOutputNormalizer.ts +13 -3
  156. package/src/tui/transcript.js +15 -9
  157. package/src/tui/turnRail.js +176 -80
  158. package/src/tui/turnRail.ts +173 -71
  159. package/src/tui/usageCard.js +136 -80
  160. package/src/tui/usageCard.ts +145 -103
  161. package/src/tui/viewport.js +48 -23
  162. package/src/tui/viewport.ts +48 -27
  163. package/src/tui/viewportAnchor.js +2 -2
  164. package/src/tui/viewportAnchor.ts +2 -2
  165. package/src/tui/workspaceFileIndex.js +8 -6
  166. package/src/tui/workspaceFileIndex.ts +8 -6
  167. package/src/tui/workspaceSwitch.js +13 -10
  168. package/src/tui/workspaceSwitch.ts +11 -7
  169. package/src/types/contracts.ts +3 -0
@@ -4,7 +4,7 @@
4
4
  */
5
5
  // @ts-expect-error theme.js has no TypeScript declaration yet.
6
6
  import { paint, fill, bold, dim, GLYPHS, HAS_COLOR } from './theme.js';
7
- import { visibleWidth, padEnd, truncate } from './text.js';
7
+ import { visibleWidth, padEnd, safeDisplay, truncate } from './text.js';
8
8
  import { FRAME } from './overlay.js';
9
9
  import { TokenTracker } from '../tokenTracker.js';
10
10
  import { loadConfig } from '../config.js';
@@ -12,16 +12,27 @@ import { loadConfig } from '../config.js';
12
12
  import { buildContextReport } from '../reporting.js';
13
13
  import { isAntigravityProvider } from '../providers/antigravity.js';
14
14
  import { isAcpProvider } from '../providers/acp.js';
15
+ import { resolveModelContextTokens } from '../contextManager.js';
16
+ function oneLineText(value) {
17
+ return safeDisplay(value).replace(/\s+/g, ' ').trim();
18
+ }
15
19
  function formatNumber(value) {
16
- return Number(value || 0).toLocaleString('en-US');
20
+ const num = Number(value);
21
+ return (Number.isFinite(num) ? Math.max(0, Math.round(num)) : 0).toLocaleString('en-US');
22
+ }
23
+ function formatCostEstimate(costUsd) {
24
+ const num = Number(costUsd);
25
+ return Number.isFinite(num) && num > 0 ? ` ${dim(`$${num.toFixed(4)} est`)}` : '';
17
26
  }
18
27
  /**
19
28
  * Render a visual progress bar for context capacity or token budget.
20
29
  */
21
30
  export function renderProgressBar(percent, barLength = 24, invertColors = false) {
22
- const clamped = Math.max(0, Math.min(100, Math.round(percent)));
23
- const filledChars = Math.max(0, Math.min(barLength, Math.round((clamped / 100) * barLength)));
24
- const emptyChars = Math.max(0, barLength - filledChars);
31
+ const safePercent = Number.isFinite(percent) ? percent : 0;
32
+ const safeLength = Number.isFinite(barLength) ? Math.max(1, Math.floor(barLength)) : 24;
33
+ const clamped = Math.max(0, Math.min(100, Math.round(safePercent)));
34
+ const filledChars = Math.max(0, Math.min(safeLength, Math.round((clamped / 100) * safeLength)));
35
+ const emptyChars = Math.max(0, safeLength - filledChars);
25
36
  let role;
26
37
  if (!invertColors) {
27
38
  // Standard: higher percentage is good (e.g. % context remaining)
@@ -48,20 +59,51 @@ export async function collectUsageCardData(loop) {
48
59
  const cumulative = await tracker.getCumulativeUsage();
49
60
  const daily = await tracker.getDailyUsage();
50
61
  const config = loadConfig();
51
- const provider = String(config.provider || 'default');
52
- const model = String(config.model || 'default');
62
+ // The running agent can differ from saved settings after a model switch.
63
+ const liveConfig = loop?.config || {};
64
+ const provider = oneLineText(liveConfig.provider || config.provider || 'default') || 'default';
65
+ const model = oneLineText(liveConfig.model || config.model || 'default') || 'default';
53
66
  const isAgy = isAntigravityProvider(provider);
54
67
  const isAcp = isAcpProvider(provider);
55
68
  const billingNote = (isAgy || isAcp)
56
69
  ? 'Local CLI / ACP peer'
57
70
  : 'BYOK (provider billed)';
71
+ const finiteNonNeg = (value, fallback = 0) => {
72
+ const n = Number(value);
73
+ return Number.isFinite(n) && n >= 0 ? n : fallback;
74
+ };
58
75
  // Context accounting
59
76
  const contextReport = buildContextReport();
60
- const poolTokens = Math.max(1, contextReport.approxTokenPool || 250000);
77
+ const override = liveConfig.contextTokens || liveConfig.maxContextTokens
78
+ || config.contextTokens || config.maxContextTokens;
79
+ const explicitLimit = Number.isFinite(Number(override)) && Number(override) > 0;
80
+ // report() uses persisted settings and can describe a *different* model.
81
+ // Resolve against the actual running provider/model; otherwise say inferred.
82
+ const modelLimit = resolveModelContextTokens({
83
+ provider, model, overrideTokens: explicitLimit ? Number(override) : 0
84
+ });
85
+ const liveLimitChars = finiteNonNeg(loop?._contextLimitChars, 0);
86
+ const liveLimitTokens = liveLimitChars > 0 ? Math.round(liveLimitChars / 4) : 0;
87
+ const poolTokens = Math.floor(modelLimit > 0
88
+ ? finiteNonNeg(modelLimit, 0)
89
+ : (liveLimitTokens > 0 ? liveLimitTokens : finiteNonNeg(contextReport?.approxTokenPool, 0)));
61
90
  // Measure active messages tokens
62
91
  let messageChars = 0;
63
92
  let messageCount = 0;
64
- const rawMessages = loop?.messages || (loop?.memoryManager ? loop.memoryManager.loadHistory() : []);
93
+ let rawMessages = [];
94
+ if (Array.isArray(loop?.messages)) {
95
+ rawMessages = loop.messages;
96
+ }
97
+ else if (typeof loop?.memoryManager?.loadHistory === 'function') {
98
+ try {
99
+ const loaded = loop.memoryManager.loadHistory();
100
+ if (Array.isArray(loaded))
101
+ rawMessages = loaded;
102
+ }
103
+ catch {
104
+ rawMessages = [];
105
+ }
106
+ }
65
107
  if (Array.isArray(rawMessages)) {
66
108
  messageCount = rawMessages.length;
67
109
  for (const msg of rawMessages) {
@@ -79,27 +121,38 @@ export async function collectUsageCardData(loop) {
79
121
  }
80
122
  }
81
123
  const messageTokens = Math.round(messageChars / 4);
82
- const coreToolTokens = contextReport.core?.tokens || 5000;
83
- const contextUsed = messageTokens + coreToolTokens;
84
- const contextPctLeft = Math.max(0, Math.min(100, Math.round(((poolTokens - contextUsed) / poolTokens) * 100)));
124
+ const coreToolTokens = Math.floor(finiteNonNeg(contextReport?.core?.tokens, 5000));
125
+ const liveContextChars = finiteNonNeg(loop?._contextChars, 0);
126
+ const liveContextTokens = liveContextChars > 0 ? Math.round(liveContextChars / 4) : 0;
127
+ const contextUsed = liveContextTokens > 0
128
+ ? Math.max(liveContextTokens, messageTokens)
129
+ : (messageTokens + coreToolTokens);
130
+ const contextPctLeft = poolTokens > 0
131
+ ? Math.max(0, Math.min(100, Math.round(((poolTokens - contextUsed) / poolTokens) * 100))) : 0;
85
132
  // Budget
86
133
  const budget = config.tokenBudget || {};
87
134
  const budgetEnabled = Boolean(budget.enabled);
88
- const budgetLimitTokens = Number(budget.maxTokensPerDay) || 0;
135
+ const budgetLimitTokens = Math.floor(finiteNonNeg(budget.maxTokensPerDay, 0));
136
+ const dailyTokens = finiteNonNeg(daily?.totalTokens, 0);
89
137
  const budgetPercentUsed = budgetLimitTokens > 0
90
- ? Math.round((daily.totalTokens / budgetLimitTokens) * 100)
138
+ ? Math.round((dailyTokens / budgetLimitTokens) * 100)
91
139
  : 0;
92
- const sessionId = String(loop?.memoryManager?.sessionId || 'default');
140
+ const rawCostCeiling = finiteNonNeg(budget.maxCostUsd, 0);
141
+ const sessionId = oneLineText(loop?.memoryManager?.sessionId || 'default') || 'default';
142
+ const sessionMetricsAvailable = Boolean(loop?.tokenTracker);
143
+ // These counters are per tracker instance, not persisted across restarts.
144
+ const sessionTokens = finiteNonNeg(tracker.sessionTokens, finiteNonNeg(reported?.sessionTokens, 0));
145
+ const sessionCostUsd = finiteNonNeg(tracker.sessionCostUsd, finiteNonNeg(reported?.sessionCostUsd, 0));
93
146
  return {
94
147
  sessionId,
95
148
  sessionTurns: messageCount,
96
- sessionTokens: tracker.sessionTokens || tracker.taskTokens || 0,
97
- sessionCostUsd: tracker.sessionCostUsd || tracker.taskCostUsd || 0,
98
- dailyTokens: daily.totalTokens,
99
- dailyCostUsd: daily.totalCostUsd || 0,
100
- lifetimeTokens: cumulative.totalTokens,
101
- lifetimeCostUsd: cumulative.totalCostUsd || 0,
102
- lifetimeCalls: cumulative.totalCalls || 0,
149
+ sessionTokens,
150
+ sessionCostUsd,
151
+ dailyTokens,
152
+ dailyCostUsd: finiteNonNeg(daily?.totalCostUsd, 0),
153
+ lifetimeTokens: finiteNonNeg(cumulative?.totalTokens, 0),
154
+ lifetimeCostUsd: finiteNonNeg(cumulative?.totalCostUsd, 0),
155
+ lifetimeCalls: Math.floor(finiteNonNeg(cumulative?.totalCalls, 0)),
103
156
  contextUsedTokens: contextUsed,
104
157
  contextPoolTokens: poolTokens,
105
158
  contextPercentLeft: contextPctLeft,
@@ -108,71 +161,74 @@ export async function collectUsageCardData(loop) {
108
161
  billingNote,
109
162
  budgetEnabled,
110
163
  budgetLimitTokens,
111
- budgetCostCeilingUsd: Number(budget.maxCostUsd) || undefined,
112
- budgetPercentUsed
164
+ budgetCostCeilingUsd: rawCostCeiling > 0 ? rawCostCeiling : undefined,
165
+ budgetPercentUsed,
166
+ sessionMetricsAvailable,
167
+ contextLimitSource: explicitLimit ? 'configured' : 'inferred',
168
+ usageProvenance: 'Local tracker: provider reports, ACP text estimates and media equivalents can be mixed'
113
169
  };
114
170
  }
115
171
  /**
116
172
  * Render the usage card as an array of styled terminal rows, exactly matching `width`.
117
173
  */
118
174
  export function renderUsageCardRows(data, width) {
119
- const frameWidth = Math.max(40, width);
120
- const innerWidth = Math.max(20, frameWidth - 4); // border (1) + pad (1) on each side
121
- const borderRole = 'accent';
122
- const surfaceRole = 'surface';
123
- // Header row
124
- const title = ` ${bold(paint('accent', 'Usage & Context'))} `;
125
- const closeHint = ` ${dim('esc close')} `;
126
- const hLineLength = Math.max(0, frameWidth - 2 - visibleWidth(title) - visibleWidth(closeHint));
127
- const topBorder = paint(borderRole, FRAME.tl + FRAME.h)
128
- + title
129
- + paint(borderRole, FRAME.h.repeat(hLineLength))
130
- + closeHint
131
- + paint(borderRole, FRAME.tr);
132
- // Content lines inside card
133
- const lines = [];
134
- // 1. Session ID & Message count
135
- const shortSession = data.sessionId.length > 24
136
- ? `${data.sessionId.slice(0, 10)}…${data.sessionId.slice(-10)}`
137
- : data.sessionId;
138
- lines.push(`${dim('Session/Chat :')} ${paint('ink', shortSession)} ${dim(`(${data.sessionTurns} messages)`)}`);
139
- // 2. Context Window & Progress bar
140
- const pBar = renderProgressBar(data.contextPercentLeft, 22, false);
141
- lines.push(`${dim('Context :')} ${bold(`${data.contextPercentLeft}% left`)} ${dim(`(${formatNumber(data.contextUsedTokens)} used / ${formatNumber(data.contextPoolTokens)})`)} ${pBar}`);
142
- // 3. This Session Usage
143
- const sessionSpend = data.sessionCostUsd > 0
144
- ? ` ${dim(`$${data.sessionCostUsd.toFixed(4)} est`)}`
145
- : '';
146
- lines.push(`${dim('This Session :')} ${bold(formatNumber(data.sessionTokens))} tokens${sessionSpend}`);
147
- // 4. Daily Usage (Today)
148
- const dailySpend = data.dailyCostUsd > 0
149
- ? ` ${dim(`$${data.dailyCostUsd.toFixed(4)} est`)}`
150
- : '';
151
- lines.push(`${dim('Today (24h) :')} ${bold(formatNumber(data.dailyTokens))} tokens${dailySpend}`);
152
- // 5. All-Time / Lifetime Usage
153
- const lifeSpend = data.lifetimeCostUsd > 0
154
- ? ` ${dim(`$${data.lifetimeCostUsd.toFixed(4)} est`)}`
155
- : '';
156
- lines.push(`${dim('All-Time :')} ${bold(formatNumber(data.lifetimeTokens))} tokens${lifeSpend} ${dim(`(${formatNumber(data.lifetimeCalls)} calls)`)}`);
157
- // 6. Model & Provider
158
- lines.push(`${dim('Active Model :')} ${paint('accent', `${data.provider} / ${data.model}`)} ${dim(`(${data.billingNote})`)}`);
159
- // 7. Optional Budget
160
- if (data.budgetEnabled && data.budgetLimitTokens) {
161
- const bBar = renderProgressBar(data.budgetPercentUsed || 0, 16, true);
162
- lines.push(`${dim('Daily Budget :')} ${formatNumber(data.dailyTokens)} / ${formatNumber(data.budgetLimitTokens)} tokens (${data.budgetPercentUsed}% used) ${bBar}`);
163
- }
164
- // Construct boxed rows
165
- const edge = paint(borderRole, FRAME.v);
166
- const rows = [fill(surfaceRole, topBorder)];
167
- for (const line of lines) {
168
- const clipped = visibleWidth(line) > innerWidth ? truncate(line, innerWidth, GLYPHS.ellipsis) : line;
175
+ const safeWidth = Number.isFinite(width) ? Math.max(4, Math.floor(width)) : 80;
176
+ const frameWidth = safeWidth; // Never paint outside the terminal's actual columns.
177
+ const innerWidth = Math.max(0, frameWidth - 4);
178
+ const edge = paint('accent', FRAME.v);
179
+ const title = frameWidth >= 32 ? ` ${bold(paint('accent', 'Usage & Context'))} `
180
+ : frameWidth >= 13 ? ' Usage ' : '';
181
+ const hint = frameWidth >= 43 ? ` ${dim('esc close')} ` : '';
182
+ const lineRoom = Math.max(0, frameWidth - 3 - visibleWidth(title) - visibleWidth(hint));
183
+ const top = paint('accent', FRAME.tl + FRAME.h)
184
+ + title + paint('accent', FRAME.h.repeat(lineRoom)) + hint + paint('accent', FRAME.tr);
185
+ const rows = [fill('surface', top)];
186
+ const labelWidth = innerWidth >= 60 ? 16 : 13;
187
+ const addRow = (label, value) => {
188
+ const name = dim(String(label).padEnd(labelWidth));
189
+ const text = name + value;
190
+ const clipped = visibleWidth(text) > innerWidth
191
+ ? truncate(text, innerWidth, GLYPHS.ellipsis) : text;
169
192
  const padding = ' '.repeat(Math.max(0, innerWidth - visibleWidth(clipped)));
170
- rows.push(fill(surfaceRole, `${edge} ${clipped}${padding} ${edge}`));
193
+ rows.push(fill('surface', `${edge} ${clipped}${padding} ${edge}`));
194
+ };
195
+ const session = oneLineText(data.sessionId || 'unknown') || 'unknown';
196
+ const sessionName = truncate(session, Math.max(8, Math.floor(innerWidth / 2)), '…');
197
+ addRow('Session/Chat', `${paint('ink', sessionName)} ${dim(`(${formatNumber(data.sessionTurns)} messages)`)}`);
198
+ // Model and provider occupy separate rows, rather than squeezing two long
199
+ // identifiers into a single line where neither is readable.
200
+ addRow('Active Model', paint('accent', oneLineText(data.model || 'unknown')));
201
+ addRow('Provider', `${paint('ink', oneLineText(data.provider || 'unknown'))} ${dim(oneLineText(data.billingNote || ''))}`);
202
+ const pool = Number.isFinite(data.contextPoolTokens) && data.contextPoolTokens > 0
203
+ ? data.contextPoolTokens : 0;
204
+ const estimatedUsed = formatNumber(data.contextUsedTokens);
205
+ if (pool > 0) {
206
+ const percent = Number.isFinite(data.contextPercentLeft)
207
+ ? Math.max(0, Math.min(100, Math.round(data.contextPercentLeft))) : 0;
208
+ const poolSource = data.contextLimitSource === 'configured' ? 'configured cap' : 'inferred cap';
209
+ addRow('Context (est.)', `~${estimatedUsed} / ~${formatNumber(pool)} tokens (~${percent}% left; ${poolSource})`);
210
+ }
211
+ else {
212
+ addRow('Context (est.)', `~${estimatedUsed} tokens; model limit unknown`);
213
+ }
214
+ addRow('This Session', data.sessionMetricsAvailable === false
215
+ ? dim('unavailable (no live tracker)')
216
+ : `${bold(formatNumber(data.sessionTokens))} tracked tokens ${dim('(current process only)')}`);
217
+ addRow('Today (local)', `${bold(formatNumber(data.dailyTokens))} tracked tokens ${dim('(calendar day)')}`);
218
+ addRow('All-Time', `${bold(formatNumber(data.lifetimeTokens))} tracked tokens ${dim(`(${formatNumber(data.lifetimeCalls)} recorded events)`)}`);
219
+ const totalEstimate = formatCostEstimate(data.lifetimeCostUsd).trim();
220
+ const dailyEstimate = formatCostEstimate(data.dailyCostUsd).trim();
221
+ addRow('Cost (estimate)', totalEstimate
222
+ ? `${totalEstimate} all-time${dailyEstimate ? ` · ${dailyEstimate} today` : ''}`
223
+ : dim('no positive local estimate recorded'));
224
+ addRow('Data source', dim('Local tracker; not provider billing or exact token telemetry'));
225
+ if (data.budgetEnabled && typeof data.budgetLimitTokens === 'number' && Number.isFinite(data.budgetLimitTokens) && data.budgetLimitTokens > 0) {
226
+ const pct = typeof data.budgetPercentUsed === 'number' && Number.isFinite(data.budgetPercentUsed)
227
+ ? Math.max(0, Math.round(data.budgetPercentUsed)) : 0;
228
+ addRow('Daily budget', `${formatNumber(data.dailyTokens)} / ${formatNumber(data.budgetLimitTokens)} tracked (${pct}% used)`);
171
229
  }
172
- // Bottom row
173
- const bottomBorder = paint(borderRole, FRAME.bl + FRAME.h.repeat(Math.max(0, frameWidth - 2)) + FRAME.br);
174
- rows.push(fill(surfaceRole, bottomBorder));
175
- // Add 1 blank row gap separating the usage card from the chatbox below
176
- rows.push('');
230
+ const bottom = paint('accent', FRAME.bl + FRAME.h.repeat(Math.max(0, frameWidth - 2)) + FRAME.br);
231
+ rows.push(fill('surface', bottom));
232
+ rows.push(''); // Keep the composer visually separate from the usage panel.
177
233
  return rows;
178
234
  }
@@ -5,7 +5,7 @@
5
5
 
6
6
  // @ts-expect-error theme.js has no TypeScript declaration yet.
7
7
  import { paint, fill, bold, dim, GLYPHS, HAS_COLOR } from './theme.js';
8
- import { visibleWidth, padEnd, truncate } from './text.js';
8
+ import { visibleWidth, padEnd, safeDisplay, truncate } from './text.js';
9
9
  import { FRAME } from './overlay.js';
10
10
  import { TokenTracker } from '../tokenTracker.js';
11
11
  import { loadConfig } from '../config.js';
@@ -13,6 +13,7 @@ import { loadConfig } from '../config.js';
13
13
  import { buildContextReport } from '../reporting.js';
14
14
  import { isAntigravityProvider } from '../providers/antigravity.js';
15
15
  import { isAcpProvider } from '../providers/acp.js';
16
+ import { resolveModelContextTokens } from '../contextManager.js';
16
17
 
17
18
  export interface UsageCardData {
18
19
  sessionId: string;
@@ -34,19 +35,37 @@ export interface UsageCardData {
34
35
  budgetLimitTokens?: number | undefined;
35
36
  budgetCostCeilingUsd?: number | undefined;
36
37
  budgetPercentUsed?: number | undefined;
38
+ /** All accounting is local; session counters require an active loop. */
39
+ sessionMetricsAvailable?: boolean;
40
+ /** A context ratio derived from text length and configured/assumed model window. */
41
+ contextLimitSource?: 'configured' | 'inferred';
42
+ /** Local history mixes provider token telemetry, ACP text estimates and media equivalents. */
43
+ usageProvenance?: string;
44
+ }
45
+
46
+ function oneLineText(value: unknown): string {
47
+ return safeDisplay(value).replace(/\s+/g, ' ').trim();
37
48
  }
38
49
 
39
50
  function formatNumber(value: number | undefined | null): string {
40
- return Number(value || 0).toLocaleString('en-US');
51
+ const num = Number(value);
52
+ return (Number.isFinite(num) ? Math.max(0, Math.round(num)) : 0).toLocaleString('en-US');
53
+ }
54
+
55
+ function formatCostEstimate(costUsd: number): string {
56
+ const num = Number(costUsd);
57
+ return Number.isFinite(num) && num > 0 ? ` ${dim(`$${num.toFixed(4)} est`)}` : '';
41
58
  }
42
59
 
43
60
  /**
44
61
  * Render a visual progress bar for context capacity or token budget.
45
62
  */
46
63
  export function renderProgressBar(percent: number, barLength: number = 24, invertColors: boolean = false): string {
47
- const clamped = Math.max(0, Math.min(100, Math.round(percent)));
48
- const filledChars = Math.max(0, Math.min(barLength, Math.round((clamped / 100) * barLength)));
49
- const emptyChars = Math.max(0, barLength - filledChars);
64
+ const safePercent = Number.isFinite(percent) ? percent : 0;
65
+ const safeLength = Number.isFinite(barLength) ? Math.max(1, Math.floor(barLength)) : 24;
66
+ const clamped = Math.max(0, Math.min(100, Math.round(safePercent)));
67
+ const filledChars = Math.max(0, Math.min(safeLength, Math.round((clamped / 100) * safeLength)));
68
+ const emptyChars = Math.max(0, safeLength - filledChars);
50
69
 
51
70
  let role: string;
52
71
  if (!invertColors) {
@@ -78,25 +97,56 @@ export async function collectUsageCardData(loop?: any): Promise<UsageCardData> {
78
97
  const daily = await tracker.getDailyUsage();
79
98
  const config = loadConfig() as Record<string, any>;
80
99
 
81
- const provider = String(config.provider || 'default');
82
- const model = String(config.model || 'default');
100
+ // The running agent can differ from saved settings after a model switch.
101
+ const liveConfig = loop?.config || {};
102
+ const provider = oneLineText(liveConfig.provider || config.provider || 'default') || 'default';
103
+ const model = oneLineText(liveConfig.model || config.model || 'default') || 'default';
83
104
  const isAgy = isAntigravityProvider(provider);
84
105
  const isAcp = isAcpProvider(provider);
85
106
  const billingNote = (isAgy || isAcp)
86
107
  ? 'Local CLI / ACP peer'
87
108
  : 'BYOK (provider billed)';
88
109
 
110
+ const finiteNonNeg = (value: unknown, fallback = 0): number => {
111
+ const n = Number(value);
112
+ return Number.isFinite(n) && n >= 0 ? n : fallback;
113
+ };
114
+
89
115
  // Context accounting
90
116
  const contextReport = buildContextReport();
91
- const poolTokens = Math.max(1, contextReport.approxTokenPool || 250000);
117
+ const override = liveConfig.contextTokens || liveConfig.maxContextTokens
118
+ || config.contextTokens || config.maxContextTokens;
119
+ const explicitLimit = Number.isFinite(Number(override)) && Number(override) > 0;
120
+ // report() uses persisted settings and can describe a *different* model.
121
+ // Resolve against the actual running provider/model; otherwise say inferred.
122
+ const modelLimit = resolveModelContextTokens({
123
+ provider, model, overrideTokens: explicitLimit ? Number(override) : 0
124
+ });
125
+ const liveLimitChars = finiteNonNeg(loop?._contextLimitChars, 0);
126
+ const liveLimitTokens = liveLimitChars > 0 ? Math.round(liveLimitChars / 4) : 0;
127
+ const poolTokens = Math.floor(
128
+ modelLimit > 0
129
+ ? finiteNonNeg(modelLimit, 0)
130
+ : (liveLimitTokens > 0 ? liveLimitTokens : finiteNonNeg(contextReport?.approxTokenPool, 0))
131
+ );
92
132
 
93
133
  // Measure active messages tokens
94
134
  let messageChars = 0;
95
135
  let messageCount = 0;
96
- const rawMessages = loop?.messages || (loop?.memoryManager ? loop.memoryManager.loadHistory() : []);
136
+ let rawMessages: unknown[] = [];
137
+ if (Array.isArray(loop?.messages)) {
138
+ rawMessages = loop.messages;
139
+ } else if (typeof loop?.memoryManager?.loadHistory === 'function') {
140
+ try {
141
+ const loaded = loop.memoryManager.loadHistory();
142
+ if (Array.isArray(loaded)) rawMessages = loaded;
143
+ } catch {
144
+ rawMessages = [];
145
+ }
146
+ }
97
147
  if (Array.isArray(rawMessages)) {
98
148
  messageCount = rawMessages.length;
99
- for (const msg of rawMessages) {
149
+ for (const msg of rawMessages as Array<Record<string, any>>) {
100
150
  if (typeof msg?.content === 'string') {
101
151
  messageChars += msg.content.length;
102
152
  } else if (Array.isArray(msg?.content)) {
@@ -109,30 +159,41 @@ export async function collectUsageCardData(loop?: any): Promise<UsageCardData> {
109
159
  }
110
160
 
111
161
  const messageTokens = Math.round(messageChars / 4);
112
- const coreToolTokens = contextReport.core?.tokens || 5000;
113
- const contextUsed = messageTokens + coreToolTokens;
114
- const contextPctLeft = Math.max(0, Math.min(100, Math.round(((poolTokens - contextUsed) / poolTokens) * 100)));
162
+ const coreToolTokens = Math.floor(finiteNonNeg(contextReport?.core?.tokens, 5000));
163
+ const liveContextChars = finiteNonNeg(loop?._contextChars, 0);
164
+ const liveContextTokens = liveContextChars > 0 ? Math.round(liveContextChars / 4) : 0;
165
+ const contextUsed = liveContextTokens > 0
166
+ ? Math.max(liveContextTokens, messageTokens)
167
+ : (messageTokens + coreToolTokens);
168
+ const contextPctLeft = poolTokens > 0
169
+ ? Math.max(0, Math.min(100, Math.round(((poolTokens - contextUsed) / poolTokens) * 100))) : 0;
115
170
 
116
171
  // Budget
117
172
  const budget = config.tokenBudget || {};
118
173
  const budgetEnabled = Boolean(budget.enabled);
119
- const budgetLimitTokens = Number(budget.maxTokensPerDay) || 0;
174
+ const budgetLimitTokens = Math.floor(finiteNonNeg(budget.maxTokensPerDay, 0));
175
+ const dailyTokens = finiteNonNeg(daily?.totalTokens, 0);
120
176
  const budgetPercentUsed = budgetLimitTokens > 0
121
- ? Math.round((daily.totalTokens / budgetLimitTokens) * 100)
177
+ ? Math.round((dailyTokens / budgetLimitTokens) * 100)
122
178
  : 0;
179
+ const rawCostCeiling = finiteNonNeg(budget.maxCostUsd, 0);
123
180
 
124
- const sessionId = String(loop?.memoryManager?.sessionId || 'default');
181
+ const sessionId = oneLineText(loop?.memoryManager?.sessionId || 'default') || 'default';
182
+ const sessionMetricsAvailable = Boolean(loop?.tokenTracker);
183
+ // These counters are per tracker instance, not persisted across restarts.
184
+ const sessionTokens = finiteNonNeg(tracker.sessionTokens, finiteNonNeg(reported?.sessionTokens, 0));
185
+ const sessionCostUsd = finiteNonNeg(tracker.sessionCostUsd, finiteNonNeg(reported?.sessionCostUsd, 0));
125
186
 
126
187
  return {
127
188
  sessionId,
128
189
  sessionTurns: messageCount,
129
- sessionTokens: tracker.sessionTokens || tracker.taskTokens || 0,
130
- sessionCostUsd: tracker.sessionCostUsd || tracker.taskCostUsd || 0,
131
- dailyTokens: daily.totalTokens,
132
- dailyCostUsd: daily.totalCostUsd || 0,
133
- lifetimeTokens: cumulative.totalTokens,
134
- lifetimeCostUsd: cumulative.totalCostUsd || 0,
135
- lifetimeCalls: cumulative.totalCalls || 0,
190
+ sessionTokens,
191
+ sessionCostUsd,
192
+ dailyTokens,
193
+ dailyCostUsd: finiteNonNeg(daily?.totalCostUsd, 0),
194
+ lifetimeTokens: finiteNonNeg(cumulative?.totalTokens, 0),
195
+ lifetimeCostUsd: finiteNonNeg(cumulative?.totalCostUsd, 0),
196
+ lifetimeCalls: Math.floor(finiteNonNeg(cumulative?.totalCalls, 0)),
136
197
  contextUsedTokens: contextUsed,
137
198
  contextPoolTokens: poolTokens,
138
199
  contextPercentLeft: contextPctLeft,
@@ -141,8 +202,11 @@ export async function collectUsageCardData(loop?: any): Promise<UsageCardData> {
141
202
  billingNote,
142
203
  budgetEnabled,
143
204
  budgetLimitTokens,
144
- budgetCostCeilingUsd: Number(budget.maxCostUsd) || undefined,
145
- budgetPercentUsed
205
+ budgetCostCeilingUsd: rawCostCeiling > 0 ? rawCostCeiling : undefined,
206
+ budgetPercentUsed,
207
+ sessionMetricsAvailable,
208
+ contextLimitSource: explicitLimit ? 'configured' : 'inferred',
209
+ usageProvenance: 'Local tracker: provider reports, ACP text estimates and media equivalents can be mixed'
146
210
  };
147
211
  }
148
212
 
@@ -150,91 +214,69 @@ export async function collectUsageCardData(loop?: any): Promise<UsageCardData> {
150
214
  * Render the usage card as an array of styled terminal rows, exactly matching `width`.
151
215
  */
152
216
  export function renderUsageCardRows(data: UsageCardData, width: number): string[] {
153
- const frameWidth = Math.max(40, width);
154
- const innerWidth = Math.max(20, frameWidth - 4); // border (1) + pad (1) on each side
155
- const borderRole = 'accent';
156
- const surfaceRole = 'surface';
157
-
158
- // Header row
159
- const title = ` ${bold(paint('accent', 'Usage & Context'))} `;
160
- const closeHint = ` ${dim('esc close')} `;
161
- const hLineLength = Math.max(0, frameWidth - 2 - visibleWidth(title) - visibleWidth(closeHint));
162
- const topBorder = paint(borderRole, FRAME.tl + FRAME.h)
163
- + title
164
- + paint(borderRole, FRAME.h.repeat(hLineLength))
165
- + closeHint
166
- + paint(borderRole, FRAME.tr);
167
-
168
- // Content lines inside card
169
- const lines: string[] = [];
170
-
171
- // 1. Session ID & Message count
172
- const shortSession = data.sessionId.length > 24
173
- ? `${data.sessionId.slice(0, 10)}…${data.sessionId.slice(-10)}`
174
- : data.sessionId;
175
- lines.push(
176
- `${dim('Session/Chat :')} ${paint('ink', shortSession)} ${dim(`(${data.sessionTurns} messages)`)}`
177
- );
217
+ const safeWidth = Number.isFinite(width) ? Math.max(4, Math.floor(width)) : 80;
218
+ const frameWidth = safeWidth; // Never paint outside the terminal's actual columns.
219
+ const innerWidth = Math.max(0, frameWidth - 4);
220
+ const edge = paint('accent', FRAME.v);
221
+ const title = frameWidth >= 32 ? ` ${bold(paint('accent', 'Usage & Context'))} `
222
+ : frameWidth >= 13 ? ' Usage ' : '';
223
+ const hint = frameWidth >= 43 ? ` ${dim('esc close')} ` : '';
224
+ const lineRoom = Math.max(0, frameWidth - 3 - visibleWidth(title) - visibleWidth(hint));
225
+ const top = paint('accent', FRAME.tl + FRAME.h)
226
+ + title + paint('accent', FRAME.h.repeat(lineRoom)) + hint + paint('accent', FRAME.tr);
227
+ const rows = [fill('surface', top)];
178
228
 
179
- // 2. Context Window & Progress bar
180
- const pBar = renderProgressBar(data.contextPercentLeft, 22, false);
181
- lines.push(
182
- `${dim('Context :')} ${bold(`${data.contextPercentLeft}% left`)} ${dim(`(${formatNumber(data.contextUsedTokens)} used / ${formatNumber(data.contextPoolTokens)})`)} ${pBar}`
183
- );
184
-
185
- // 3. This Session Usage
186
- const sessionSpend = data.sessionCostUsd > 0
187
- ? ` ${dim(`$${data.sessionCostUsd.toFixed(4)} est`)}`
188
- : '';
189
- lines.push(
190
- `${dim('This Session :')} ${bold(formatNumber(data.sessionTokens))} tokens${sessionSpend}`
191
- );
192
-
193
- // 4. Daily Usage (Today)
194
- const dailySpend = data.dailyCostUsd > 0
195
- ? ` ${dim(`$${data.dailyCostUsd.toFixed(4)} est`)}`
196
- : '';
197
- lines.push(
198
- `${dim('Today (24h) :')} ${bold(formatNumber(data.dailyTokens))} tokens${dailySpend}`
199
- );
200
-
201
- // 5. All-Time / Lifetime Usage
202
- const lifeSpend = data.lifetimeCostUsd > 0
203
- ? ` ${dim(`$${data.lifetimeCostUsd.toFixed(4)} est`)}`
204
- : '';
205
- lines.push(
206
- `${dim('All-Time :')} ${bold(formatNumber(data.lifetimeTokens))} tokens${lifeSpend} ${dim(`(${formatNumber(data.lifetimeCalls)} calls)`)}`
207
- );
229
+ const labelWidth = innerWidth >= 60 ? 16 : 13;
230
+ const addRow = (label: string, value: string): void => {
231
+ const name = dim(String(label).padEnd(labelWidth));
232
+ const text = name + value;
233
+ const clipped = visibleWidth(text) > innerWidth
234
+ ? truncate(text, innerWidth, GLYPHS.ellipsis) : text;
235
+ const padding = ' '.repeat(Math.max(0, innerWidth - visibleWidth(clipped)));
236
+ rows.push(fill('surface', `${edge} ${clipped}${padding} ${edge}`));
237
+ };
208
238
 
209
- // 6. Model & Provider
210
- lines.push(
211
- `${dim('Active Model :')} ${paint('accent', `${data.provider} / ${data.model}`)} ${dim(`(${data.billingNote})`)}`
212
- );
239
+ const session = oneLineText(data.sessionId || 'unknown') || 'unknown';
240
+ const sessionName = truncate(session, Math.max(8, Math.floor(innerWidth / 2)), '…');
241
+ addRow('Session/Chat', `${paint('ink', sessionName)} ${dim(`(${formatNumber(data.sessionTurns)} messages)`)}`);
242
+ // Model and provider occupy separate rows, rather than squeezing two long
243
+ // identifiers into a single line where neither is readable.
244
+ addRow('Active Model', paint('accent', oneLineText(data.model || 'unknown')));
245
+ addRow('Provider', `${paint('ink', oneLineText(data.provider || 'unknown'))} ${dim(oneLineText(data.billingNote || ''))}`);
213
246
 
214
- // 7. Optional Budget
215
- if (data.budgetEnabled && data.budgetLimitTokens) {
216
- const bBar = renderProgressBar(data.budgetPercentUsed || 0, 16, true);
217
- lines.push(
218
- `${dim('Daily Budget :')} ${formatNumber(data.dailyTokens)} / ${formatNumber(data.budgetLimitTokens)} tokens (${data.budgetPercentUsed}% used) ${bBar}`
219
- );
247
+ const pool = Number.isFinite(data.contextPoolTokens) && data.contextPoolTokens > 0
248
+ ? data.contextPoolTokens : 0;
249
+ const estimatedUsed = formatNumber(data.contextUsedTokens);
250
+ if (pool > 0) {
251
+ const percent = Number.isFinite(data.contextPercentLeft)
252
+ ? Math.max(0, Math.min(100, Math.round(data.contextPercentLeft))) : 0;
253
+ const poolSource = data.contextLimitSource === 'configured' ? 'configured cap' : 'inferred cap';
254
+ addRow('Context (est.)', `~${estimatedUsed} / ~${formatNumber(pool)} tokens (~${percent}% left; ${poolSource})`);
255
+ } else {
256
+ addRow('Context (est.)', `~${estimatedUsed} tokens; model limit unknown`);
220
257
  }
221
258
 
222
- // Construct boxed rows
223
- const edge = paint(borderRole, FRAME.v);
224
- const rows: string[] = [fill(surfaceRole, topBorder)];
225
-
226
- for (const line of lines) {
227
- const clipped = visibleWidth(line) > innerWidth ? truncate(line, innerWidth, GLYPHS.ellipsis) : line;
228
- const padding = ' '.repeat(Math.max(0, innerWidth - visibleWidth(clipped)));
229
- rows.push(fill(surfaceRole, `${edge} ${clipped}${padding} ${edge}`));
230
- }
259
+ addRow('This Session', data.sessionMetricsAvailable === false
260
+ ? dim('unavailable (no live tracker)')
261
+ : `${bold(formatNumber(data.sessionTokens))} tracked tokens ${dim('(current process only)')}`);
262
+ addRow('Today (local)', `${bold(formatNumber(data.dailyTokens))} tracked tokens ${dim('(calendar day)')}`);
263
+ addRow('All-Time', `${bold(formatNumber(data.lifetimeTokens))} tracked tokens ${dim(`(${formatNumber(data.lifetimeCalls)} recorded events)`)}`);
231
264
 
232
- // Bottom row
233
- const bottomBorder = paint(borderRole, FRAME.bl + FRAME.h.repeat(Math.max(0, frameWidth - 2)) + FRAME.br);
234
- rows.push(fill(surfaceRole, bottomBorder));
265
+ const totalEstimate = formatCostEstimate(data.lifetimeCostUsd).trim();
266
+ const dailyEstimate = formatCostEstimate(data.dailyCostUsd).trim();
267
+ addRow('Cost (estimate)', totalEstimate
268
+ ? `${totalEstimate} all-time${dailyEstimate ? ` · ${dailyEstimate} today` : ''}`
269
+ : dim('no positive local estimate recorded'));
235
270
 
236
- // Add 1 blank row gap separating the usage card from the chatbox below
237
- rows.push('');
271
+ addRow('Data source', dim('Local tracker; not provider billing or exact token telemetry'));
272
+ if (data.budgetEnabled && typeof data.budgetLimitTokens === 'number' && Number.isFinite(data.budgetLimitTokens) && data.budgetLimitTokens > 0) {
273
+ const pct = typeof data.budgetPercentUsed === 'number' && Number.isFinite(data.budgetPercentUsed)
274
+ ? Math.max(0, Math.round(data.budgetPercentUsed)) : 0;
275
+ addRow('Daily budget', `${formatNumber(data.dailyTokens)} / ${formatNumber(data.budgetLimitTokens)} tracked (${pct}% used)`);
276
+ }
238
277
 
278
+ const bottom = paint('accent', FRAME.bl + FRAME.h.repeat(Math.max(0, frameWidth - 2)) + FRAME.br);
279
+ rows.push(fill('surface', bottom));
280
+ rows.push(''); // Keep the composer visually separate from the usage panel.
239
281
  return rows;
240
282
  }