pantheon-opencode 1.6.1 → 1.6.2-beta.1

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 (99) hide show
  1. package/AGENTS.global.md +11 -11
  2. package/AGENTS.md +2 -2
  3. package/CHANGELOG.md +16 -0
  4. package/README.md +91 -19
  5. package/README.pt-BR.md +14 -9
  6. package/bin/pantheon-init.mjs +106 -19
  7. package/package.json +3 -2
  8. package/plugin.json +1 -1
  9. package/pyproject.toml +1 -1
  10. package/scripts/build-agents-md.mjs +1 -1
  11. package/scripts/doctor.mjs +213 -45
  12. package/scripts/install/agents-md.mjs +2 -1
  13. package/scripts/install/config-migration.mjs +344 -393
  14. package/scripts/install/config-paths.mjs +15 -0
  15. package/scripts/install/mcp-permissions.mjs +164 -0
  16. package/scripts/install/opencode-version.mjs +31 -13
  17. package/scripts/install/opencode-wildcard.mjs +106 -0
  18. package/scripts/install/opencode.mjs +240 -69
  19. package/scripts/install/plan-artifact.mjs +12 -1
  20. package/scripts/install/plugin.mjs +17 -1
  21. package/scripts/install/v2-capabilities.mjs +5 -6
  22. package/scripts/package-evidence.mjs +1 -0
  23. package/scripts/sandbox-env.sh +174 -0
  24. package/scripts/setup-v2-config.mjs +1703 -0
  25. package/scripts/setup.mjs +415 -0
  26. package/scripts/sync-tui.mjs +9 -1
  27. package/scripts/test-opencode-v2-sandbox.sh +438 -151
  28. package/scripts/update-skills-lock.mjs +30 -0
  29. package/skills-lock.json +10 -10
  30. package/src/agents/aphrodite.md +5 -2
  31. package/src/agents/apollo.md +5 -0
  32. package/src/agents/athena.md +6 -1
  33. package/src/agents/demeter.md +5 -1
  34. package/src/agents/gaia.md +4 -0
  35. package/src/agents/hephaestus.md +6 -1
  36. package/src/agents/hermes.md +6 -3
  37. package/src/agents/iris.md +5 -1
  38. package/src/agents/mnemosyne.md +20 -50
  39. package/src/agents/nyx.md +5 -1
  40. package/src/agents/prometheus.md +4 -0
  41. package/src/agents/talos.md +4 -0
  42. package/src/agents/themis.md +4 -0
  43. package/src/agents/zeus.md +9 -3
  44. package/src/instructions/agent-return-format.instructions.md +1 -1
  45. package/src/instructions/memory-protocol.instructions.md +3 -3
  46. package/src/instructions/test-economy.instructions.md +6 -6
  47. package/src/mcp/pantheon_vision.py +37 -36
  48. package/src/pantheon/v2-vision.ts +34 -29
  49. package/src/pantheon/vision.ts +43 -10
  50. package/src/plugin-v2.ts +30 -53
  51. package/src/plugins/tui/dist/quota-adapters.d.ts +89 -0
  52. package/src/plugins/tui/dist/quota-adapters.d.ts.map +1 -0
  53. package/src/plugins/tui/dist/quota-adapters.js +1142 -0
  54. package/src/plugins/tui/dist/quota-adapters.js.map +1 -0
  55. package/src/plugins/tui/dist/quota-cli.d.ts +17 -0
  56. package/src/plugins/tui/dist/quota-cli.d.ts.map +1 -0
  57. package/src/plugins/tui/dist/quota-cli.js +184 -0
  58. package/src/plugins/tui/dist/quota-cli.js.map +1 -0
  59. package/src/plugins/tui/dist/quota-rpc-UL2HuFRJ.js +390 -0
  60. package/src/plugins/tui/dist/quota-rpc-UL2HuFRJ.js.map +1 -0
  61. package/src/plugins/tui/dist/server-v2.d.ts +14 -0
  62. package/src/plugins/tui/dist/server-v2.d.ts.map +1 -0
  63. package/src/plugins/tui/dist/server-v2.js +673 -0
  64. package/src/plugins/tui/dist/server-v2.js.map +1 -0
  65. package/src/plugins/tui/dist/tui-v2.d.ts +247 -52
  66. package/src/plugins/tui/dist/tui-v2.d.ts.map +1 -1
  67. package/src/plugins/tui/dist/tui-v2.js +2492 -529
  68. package/src/plugins/tui/dist/tui-v2.js.map +1 -1
  69. package/src/plugins/tui/dist/tui.js +1 -1
  70. package/src/plugins/tui/index-v2.ts +3 -6
  71. package/src/plugins/tui/package-lock.json +2 -2
  72. package/src/plugins/tui/package.json +3 -2
  73. package/src/plugins/tui/src/context-gauge.ts +59 -0
  74. package/src/plugins/tui/src/go-key-diagnostic-ui.ts +100 -0
  75. package/src/plugins/tui/src/go-key-diagnostic.ts +125 -0
  76. package/src/plugins/tui/src/index-v2.tsx +199 -240
  77. package/src/plugins/tui/src/model-usage-limits.ts +4 -0
  78. package/src/plugins/tui/src/quota-adapters.ts +1598 -0
  79. package/src/plugins/tui/src/quota-cli.ts +237 -0
  80. package/src/plugins/tui/src/quota-rpc.ts +209 -0
  81. package/src/plugins/tui/src/quota-v2-model.ts +1032 -0
  82. package/src/plugins/tui/src/quota-v2.tsx +986 -0
  83. package/src/plugins/tui/src/server-v2.ts +841 -0
  84. package/src/plugins/tui/src/sidebar-width.ts +129 -0
  85. package/src/plugins/tui/tsconfig.typecheck.json +1 -1
  86. package/src/plugins/tui/tsdown.config.ts +8 -1
  87. package/src/routing.yml +72 -13
  88. package/src/skills/README.md +4 -0
  89. package/src/skills/agent-coordination/SKILL.md +0 -3
  90. package/src/skills/artifact-management/SKILL.md +0 -3
  91. package/src/skills/auto-continue/SKILL.md +0 -3
  92. package/src/skills/code-review-checklist/SKILL.md +0 -3
  93. package/src/skills/context-compression/SKILL.md +0 -3
  94. package/src/skills/memory-bank/SKILL.md +6 -28
  95. package/src/skills/session-goal/SKILL.md +0 -3
  96. package/src/skills/simplify/SKILL.md +5 -4
  97. package/src/skills/tdd-with-agents/SKILL.md +0 -3
  98. package/src/skills/visual-review-pipeline/SKILL.md +0 -1
  99. package/src/pantheon/memory-context.ts +0 -1017
@@ -8,8 +8,84 @@ import { homedir } from 'node:os'
8
8
  import { join } from 'node:path'
9
9
  import { Plugin } from '@opencode/plugin/tui'
10
10
  import type { Context, KeymapLayer, PanelInput } from '@opencode/plugin/tui/context'
11
- import type { Accessor } from 'solid-js'
11
+ import type { Accessor, JSX } from 'solid-js'
12
12
  import { createEffect, createMemo, createSignal, For, on, onCleanup, onMount, Show } from 'solid-js'
13
+ import {
14
+ type ContextProgressTone,
15
+ contextBar,
16
+ contextUsageTone,
17
+ formatContextWindow,
18
+ formatSpent,
19
+ formatTokenCount,
20
+ } from './context-gauge'
21
+ import {
22
+ MODEL_USAGE_MESSAGE_LIMIT,
23
+ MODEL_USAGE_SESSION_LIMIT,
24
+ MODEL_USAGE_VISIBLE_CEILING,
25
+ } from './model-usage-limits'
26
+ import { QuotaSidebarSummary, quotaTextLines, registerQuotaTui } from './quota-v2'
27
+ import {
28
+ createQuotaRuntime,
29
+ type QuotaRuntime,
30
+ resolveActiveModelRef,
31
+ resolveModelContextSnapshot,
32
+ } from './quota-v2-model'
33
+ import { cellWidth, GRAPHEMES, SIDEBAR_CONTENT_WIDTH } from './sidebar-width'
34
+
35
+ export type { ContextProgressTone } from './context-gauge'
36
+ export {
37
+ CONTEXT_BAR_CELLS,
38
+ CONTEXT_BAR_EMPTY_CELL,
39
+ CONTEXT_BAR_FILLED_CELL,
40
+ contextBar,
41
+ contextBarFilled,
42
+ contextUsageTone,
43
+ formatContextWindow,
44
+ formatSpent,
45
+ formatTokenCount,
46
+ } from './context-gauge'
47
+ export { quotaGoCheckCommand } from './go-key-diagnostic-ui'
48
+ export {
49
+ MODEL_USAGE_MESSAGE_LIMIT,
50
+ MODEL_USAGE_SESSION_LIMIT,
51
+ MODEL_USAGE_VISIBLE_CEILING,
52
+ } from './model-usage-limits'
53
+ export {
54
+ financeMetricLines,
55
+ openQuotaPanel,
56
+ QUOTA_ICON,
57
+ QUOTA_OPEN_COMMAND_ID,
58
+ QUOTA_PANEL_COMMANDS,
59
+ QUOTA_PANEL_NAME,
60
+ quotaMetricLines,
61
+ quotaOpenCommand,
62
+ quotaPanelKeymapLayer,
63
+ quotaTextLines,
64
+ quotaUsageTone,
65
+ quotaWindowLines,
66
+ runQuotaPanelCommand,
67
+ sidebarFinanceEntries,
68
+ snapshotSummary,
69
+ } from './quota-v2'
70
+ export type { QuotaSidebarEntry } from './quota-v2-model'
71
+ export {
72
+ collectRecentModelUsageRows,
73
+ compactQuotaMetric,
74
+ createQuotaClock,
75
+ createQuotaRuntime,
76
+ DEFAULT_QUOTA_PREFERENCES,
77
+ formatQuotaCountdown,
78
+ formatQuotaMetric,
79
+ normalizeQuotaPreferences,
80
+ QUOTA_CLOCK_INTERVAL_MS,
81
+ quotaClock,
82
+ quotaProgress,
83
+ quotaSidebarEntries,
84
+ quotaSnapshotFromStatus,
85
+ quotaSnapshotStatusLabel,
86
+ } from './quota-v2-model'
87
+ export { cellWidth } from './sidebar-width'
88
+ export { resolveActiveModelRef, resolveModelContextSnapshot }
13
89
 
14
90
  const SINGLETON = Symbol.for('pantheon.tui.v2.loaded')
15
91
 
@@ -320,20 +396,6 @@ export function computeContextUsage(
320
396
  return null
321
397
  }
322
398
 
323
- /** Semantic tone for a context percentage, inclusive at the top of each band:
324
- * info (blue) up to 25%, success (green) up to 50%, warning (yellow) up to
325
- * 90%, error (red) above it. Four explicit stages, each backed by a feedback
326
- * token, so the gauge follows the active theme. Pure. */
327
- export function contextUsageTone(percent: number): ContextProgressTone {
328
- if (percent > 90) return 'error'
329
- if (percent > 50) return 'warning'
330
- if (percent > 25) return 'success'
331
- return 'info'
332
- }
333
-
334
- /** The gauge's four stages, one per theme feedback token. */
335
- export type ContextProgressTone = 'info' | 'success' | 'warning' | 'error'
336
-
337
399
  /** Color for one gauge stage. Filled cells and the percent value both come from
338
400
  * this one call, so the bar and its number can never disagree. `theme` is the
339
401
  * host's resolved theme (loosely typed at runtime); a missing token falls back
@@ -458,67 +520,6 @@ export function turnTokensPerSecond(
458
520
  * are optional; the block renders no line when neither is available. */
459
521
  export type ContextPerformance = { cacheHit: number | null; tokensPerSecond: number | null }
460
522
 
461
- /** Thousands-separated token total: `55320` → `55,320` (en-US, matching the
462
- * native block this one replaces). Null for a missing/invalid value. Pure. */
463
- export function formatTokenCount(tokens: number | null | undefined): string | null {
464
- const value = numberOrNull(tokens)
465
- if (value === null || value < 0) return null
466
- return Math.round(value).toLocaleString('en-US')
467
- }
468
-
469
- /** Context-window label: `1_000_000` → `1.0M`, `200_000` → `200K`,
470
- * `128_000` → `128K`, `32_768` → `32K`. Sub-million limits truncate to whole K
471
- * so the printed window never overstates the model's capacity. Pure. */
472
- export function formatContextWindow(limit: number | null | undefined): string | null {
473
- const value = numberOrNull(limit)
474
- if (value === null || value <= 0) return null
475
- if (value >= 1_000_000) return `${(value / 1_000_000).toFixed(1)}M`
476
- if (value >= 1_000) return `${Math.floor(value / 1_000)}K`
477
- return `${Math.floor(value)}`
478
- }
479
-
480
- /** Cells in the Context gauge: always rendered in full, so the bar never
481
- * changes width between refreshes. With the space, the percent and the
482
- * `of <window>` tail (at most 9 columns) the line stays inside 34 columns. */
483
- export const CONTEXT_BAR_CELLS = 12
484
- /** Filled cell (U+25B0) and empty cell (U+25B1), both single-width. */
485
- export const CONTEXT_BAR_FILLED_CELL = '\u25B0'
486
- export const CONTEXT_BAR_EMPTY_CELL = '\u25B1'
487
-
488
- /** Filled cells for a percentage: rounded, clamped to `0..cells`, so 0% is an
489
- * empty bar and anything at or above 100% is a full one. Pure. */
490
- export function contextBarFilled(percent: number, cells = CONTEXT_BAR_CELLS): number {
491
- const total = Math.max(1, Math.floor(cells))
492
- const filled = Math.round((percent / 100) * total)
493
- if (!Number.isFinite(filled)) return 0
494
- return Math.min(total, Math.max(0, filled))
495
- }
496
-
497
- /** The gauge split into its toned half (filled cells) and its muted half (empty
498
- * cells), so the caller colors each side. Null when the percentage is missing:
499
- * the Context block then keeps its tokens + cost rows and renders no bar. Pure. */
500
- export function contextBar(
501
- percent: number | null | undefined,
502
- cells = CONTEXT_BAR_CELLS,
503
- ): { filled: string; empty: string } | null {
504
- const value = numberOrNull(percent)
505
- if (value === null) return null
506
- const total = Math.max(1, Math.floor(cells))
507
- const filled = contextBarFilled(value, total)
508
- return {
509
- filled: CONTEXT_BAR_FILLED_CELL.repeat(filled),
510
- empty: CONTEXT_BAR_EMPTY_CELL.repeat(total - filled),
511
- }
512
- }
513
-
514
- /** USD spent with two decimals (`$0.18`), the native block's format. Null for
515
- * a missing/negative value. Pure. */
516
- export function formatSpent(cost: number | null | undefined): string | null {
517
- const value = numberOrNull(cost)
518
- if (value === null || value < 0) return null
519
- return `$${value.toFixed(2)}`
520
- }
521
-
522
523
  /** One rendered context row. `lead` and `tail` carry the gauge bar when the row
523
524
  * has one (`lead` is toned with the value, `tail` is muted), so the 12 cells
524
525
  * stay contiguous while the empty half still reads as background. */
@@ -551,7 +552,7 @@ export function contextBlockRows(
551
552
  const spent: ContextRow | null =
552
553
  spentValue === null
553
554
  ? null
554
- : { lead: null, value: spentValue, tail: null, suffix: ' spent', tone: null }
555
+ : { lead: null, value: spentValue, tail: null, suffix: ' gasto na sessão', tone: null }
555
556
  if (usage === null) return spent === null ? null : { tokens: null, percent: null, spent }
556
557
 
557
558
  const tokensValue = formatTokenCount(usage.tokens)
@@ -586,12 +587,6 @@ export function contextBlockRows(
586
587
  * a message without `cost` contributes 0 and is omitted (never a guessed
587
588
  * price). */
588
589
 
589
- /** Models rendered in the Context block before the aggregate `… +N` line. */
590
- export const MODEL_USAGE_VISIBLE_CEILING = 3
591
- /** Newest messages read per session — bounds the O(n) walk on long sessions. */
592
- export const MODEL_USAGE_MESSAGE_LIMIT = 400
593
- /** Sessions read per family (root + delegations) for the aggregate. */
594
- export const MODEL_USAGE_SESSION_LIMIT = 8
595
590
  /** Column widths for one model row (labels are muted, numbers right-aligned). */
596
591
  export const MODEL_USAGE_MODEL_WIDTH = 12
597
592
  export const MODEL_USAGE_TOKEN_WIDTH = 6
@@ -697,6 +692,38 @@ export function modelUsageRowText(row: ModelUsageRow): string {
697
692
  return `${row.model.padEnd(MODEL_USAGE_MODEL_WIDTH)} ${row.tokens.padStart(MODEL_USAGE_TOKEN_WIDTH)} ${row.cost.padStart(MODEL_USAGE_COST_WIDTH)}`
698
693
  }
699
694
 
695
+ /** Wrap sidebar text by terminal cells, preserving the complete values. */
696
+ export function sidebarTextLines(value: string): string[] {
697
+ return quotaTextLines(value, SIDEBAR_CONTENT_WIDTH, 0)
698
+ }
699
+
700
+ /** Align a monetary value when it fits, otherwise preserve it on a new line. */
701
+ export function sidebarMoneyLines(label: string, value: string): string[] {
702
+ const gap = SIDEBAR_CONTENT_WIDTH - cellWidth(label) - cellWidth(value)
703
+ return gap >= 1
704
+ ? [`${label}${' '.repeat(gap)}${value}`]
705
+ : [...sidebarTextLines(label), ...sidebarTextLines(value)]
706
+ }
707
+
708
+ /** Keep the existing OpenCode periods together when possible. */
709
+ export function contextSpendLines(value: string): string[] {
710
+ const match = /^(.*\S)\s+(<?\$\S+)$/.exec(value)
711
+ return match?.[1] && match[2] && cellWidth(value) <= SIDEBAR_CONTENT_WIDTH
712
+ ? sidebarMoneyLines(match[1], match[2])
713
+ : sidebarTextLines(value)
714
+ }
715
+
716
+ /** Keep ordinary rows aligned; give oversized values their own lines. */
717
+ export function modelUsageRowLines(row: ModelUsageRow): string[] {
718
+ const single = modelUsageRowText(row)
719
+ if (cellWidth(single) <= SIDEBAR_CONTENT_WIDTH) return [single]
720
+ return [
721
+ ...sidebarTextLines(row.model),
722
+ ...sidebarTextLines(`Tokens ${row.tokens}`),
723
+ ...sidebarTextLines(`USD ${row.cost}`),
724
+ ]
725
+ }
726
+
700
727
  /** Muted aggregate line for the models beyond the cap (`… +2 $0.03`). Null
701
728
  * when every model fits. Pure. */
702
729
  export function hiddenModelUsageText(hidden: number, hiddenCost: number): string | null {
@@ -1172,10 +1199,10 @@ export function statsRangeMatches(
1172
1199
  return sameUnit || asMilliseconds
1173
1200
  }
1174
1201
 
1175
- /** The `Context` block's last line: both spend windows on one muted row
1176
- * (`hoje $0.42 · 30d $9.80`). A window without a usable amount is omitted, and
1177
- * no usable window at all yields null so the line (and not the block) is
1178
- * dropped. Pure. */
1202
+ /** The `Context` block's last line: OpenCode stats source and both spend windows
1203
+ * on one muted row (`OpenCode · hoje $0.42 · 30d $9.80`). A window without a
1204
+ * usable amount is omitted, and no usable window at all yields null so the
1205
+ * line (and not the block) is dropped. Pure. */
1179
1206
  export function contextSpendLine(totals: SpendTotals | null): string | null {
1180
1207
  if (totals === null) return null
1181
1208
  const parts: string[] = []
@@ -1183,138 +1210,13 @@ export function contextSpendLine(totals: SpendTotals | null): string | null {
1183
1210
  if (today !== null) parts.push(`${SPEND_TODAY_LABEL} ${today}`)
1184
1211
  const thirtyDays = formatSpendUSD(totals.thirtyDays)
1185
1212
  if (thirtyDays !== null) parts.push(`${SPEND_30D_LABEL} ${thirtyDays}`)
1186
- return parts.length === 0 ? null : parts.join(SPEND_LINE_SEPARATOR)
1213
+ return parts.length === 0
1214
+ ? null
1215
+ : `OpenCode${SPEND_LINE_SEPARATOR}${parts.join(SPEND_LINE_SEPARATOR)}`
1187
1216
  }
1188
1217
 
1189
1218
  /** Grapheme iterator: a cut never splits a surrogate pair, a combining mark
1190
1219
  * from its base or a ZWJ emoji sequence, so truncation stays cell-exact. */
1191
- const GRAPHEMES = new Intl.Segmenter(undefined, { granularity: 'grapheme' })
1192
-
1193
- /** A grapheme the host draws two cells wide: emoji presentation, an extended
1194
- * pictograph (a bare `❤` counts too, exactly as the host's `emoji-regex`
1195
- * does) and a regional-indicator pair (a flag). */
1196
- const EMOJI_GLYPH = /\p{Emoji_Presentation}|\p{Extended_Pictographic}|\p{Regional_Indicator}/u
1197
- /** VS16 asks for emoji presentation; without it `1` is one cell, with it the
1198
- * keycap sequence is drawn as one two-cell glyph. */
1199
- const EMOJI_PRESENTATION_SELECTOR = '\uFE0F'
1200
- /** Unicode default-ignorable code points carry no width of their own. */
1201
- const IGNORABLE_GLYPH = /^\p{Default_Ignorable_Code_Point}$/u
1202
- /** East Asian Wide/Fullwidth ranges — two cells, never the ambiguous width
1203
- * (the host measures ambiguous as narrow, so `▸`/`✓`/`—` stay one cell).
1204
- * Generated from the host's own measurement (`string-width` over every code
1205
- * point, emoji excluded), so this table can be regenerated verbatim when the
1206
- * host upgrades its Unicode data instead of being hand-edited. */
1207
- const CELL_WIDE_RANGES: readonly (readonly [number, number])[] = [
1208
- [0x1100, 0x115e],
1209
- [0x2329, 0x232a],
1210
- [0x2630, 0x2637],
1211
- [0x268a, 0x268f],
1212
- [0x2e80, 0x2e99],
1213
- [0x2e9b, 0x2ef3],
1214
- [0x2f00, 0x2fd5],
1215
- [0x2ff0, 0x302f],
1216
- [0x3031, 0x303c],
1217
- [0x303e, 0x303e],
1218
- [0x3041, 0x3096],
1219
- [0x3099, 0x30ff],
1220
- [0x3105, 0x312f],
1221
- [0x3131, 0x3163],
1222
- [0x3165, 0x318e],
1223
- [0x3190, 0x31e5],
1224
- [0x31ef, 0x321e],
1225
- [0x3220, 0x3247],
1226
- [0x3250, 0x3296],
1227
- [0x3298, 0x3298],
1228
- [0x329a, 0xa48c],
1229
- [0xa490, 0xa4c6],
1230
- [0xa960, 0xa97c],
1231
- [0xac00, 0xd7a3],
1232
- [0xf900, 0xfaff],
1233
- [0xfe10, 0xfe19],
1234
- [0xfe30, 0xfe52],
1235
- [0xfe54, 0xfe66],
1236
- [0xfe68, 0xfe6b],
1237
- [0xff01, 0xff60],
1238
- [0xffe0, 0xffe6],
1239
- [0x16fe0, 0x16fe4],
1240
- [0x16ff0, 0x16ff6],
1241
- [0x17000, 0x18cda],
1242
- [0x18cff, 0x18d20],
1243
- [0x18d80, 0x18df2],
1244
- [0x18e00, 0x19191],
1245
- [0x191a0, 0x191d2],
1246
- [0x1aff0, 0x1aff3],
1247
- [0x1aff5, 0x1affb],
1248
- [0x1affd, 0x1affe],
1249
- [0x1b000, 0x1b128],
1250
- [0x1b132, 0x1b132],
1251
- [0x1b150, 0x1b152],
1252
- [0x1b155, 0x1b155],
1253
- [0x1b164, 0x1b168],
1254
- [0x1b170, 0x1b2fb],
1255
- [0x1d300, 0x1d356],
1256
- [0x1d360, 0x1d376],
1257
- [0x1f200, 0x1f200],
1258
- [0x1f210, 0x1f219],
1259
- [0x1f21b, 0x1f22e],
1260
- [0x1f230, 0x1f231],
1261
- [0x1f23b, 0x1f23b],
1262
- [0x1f240, 0x1f248],
1263
- [0x1f260, 0x1f265],
1264
- [0x20000, 0x2fffd],
1265
- [0x30000, 0x3fffd],
1266
- ]
1267
-
1268
- /** One code point the terminal draws no cell for: control characters, the
1269
- * zero-width joiners/marks, combining marks and variation selectors. */
1270
- function isZeroWidthCodePoint(code: number, glyph: string): boolean {
1271
- if (code <= 0x1f || (code >= 0x7f && code <= 0x9f)) return true
1272
- if (code >= 0x200b && code <= 0x200f) return true
1273
- if (code === 0xfeff) return true
1274
- if (code >= 0x300 && code <= 0x36f) return true
1275
- if (code >= 0x1ab0 && code <= 0x1aff) return true
1276
- if (code >= 0x1dc0 && code <= 0x1dff) return true
1277
- if (code >= 0x20d0 && code <= 0x20ff) return true
1278
- if (code >= 0xfe00 && code <= 0xfe0f) return true
1279
- if (code >= 0xfe20 && code <= 0xfe2f) return true
1280
- if (code >= 0xe0100 && code <= 0xe01ef) return true
1281
- if (code >= 0xd800 && code <= 0xdfff) return true // a lone surrogate
1282
- return IGNORABLE_GLYPH.test(glyph)
1283
- }
1284
-
1285
- function isWideCodePoint(code: number): boolean {
1286
- for (const [low, high] of CELL_WIDE_RANGES) {
1287
- if (code < low) return false
1288
- if (code <= high) return true
1289
- }
1290
- return false
1291
- }
1292
-
1293
- /** Cells one grapheme occupies. */
1294
- function graphemeWidth(segment: string): number {
1295
- if (EMOJI_GLYPH.test(segment)) return 2
1296
- // A lone VS16 carries no width; after a base it asks for emoji presentation.
1297
- if (segment.length > 1 && segment.includes(EMOJI_PRESENTATION_SELECTOR)) return 2
1298
- let width = 0
1299
- for (const glyph of segment) {
1300
- const code = glyph.codePointAt(0) ?? 0
1301
- if (isZeroWidthCodePoint(code, glyph)) continue
1302
- width += isWideCodePoint(code) ? 2 : 1
1303
- }
1304
- return width
1305
- }
1306
-
1307
- /** Terminal cells `value` occupies — the unit every column in this plugin is
1308
- * measured in. Mirrors the host (that is how `@opentui/core` sizes a text
1309
- * run): emoji count as two cells, East Asian Wide/Fullwidth as two, East
1310
- * Asian Ambiguous as one, combining marks and variation selectors as none.
1311
- * Pure. */
1312
- export function cellWidth(value: string): number {
1313
- let width = 0
1314
- for (const { segment } of GRAPHEMES.segment(value)) width += graphemeWidth(segment)
1315
- return width
1316
- }
1317
-
1318
1220
  /** Clamp a free-form label to `max` terminal cells without wrapping. The width
1319
1221
  * is measured in display cells, never in UTF-16 code units: a CJK or emoji
1320
1222
  * label used to overflow the column it was cut for (`計画の移行` is 5 code
@@ -1347,7 +1249,7 @@ export function padCell(value: string, cells: number): string {
1347
1249
  }
1348
1250
 
1349
1251
  /** Columns the fixed header may use before it would wrap the sidebar. */
1350
- export const HEADER_MAX_WIDTH = 34
1252
+ export const HEADER_MAX_WIDTH = SIDEBAR_CONTENT_WIDTH
1351
1253
 
1352
1254
  /** Preset row of the fixed header: `▸ <preset> · <provider>`. The provider is
1353
1255
  * cut first when the row overflows, so the preset name is never the casualty;
@@ -3595,21 +3497,19 @@ export function createSidebarModel(
3595
3497
  })
3596
3498
 
3597
3499
  const contextUsage = createMemo(() => {
3598
- const list = messages()
3500
+ const list = messages().slice(-MODEL_USAGE_MESSAGE_LIMIT)
3599
3501
  if (list.length === 0) return null
3600
3502
  const refs = modelRefs()
3601
- const lastAssistant = [...list]
3602
- .reverse()
3603
- .find((message) => message?.type === 'assistant' && message?.model)
3604
- const ref = lastAssistant?.model ?? refs.sessionRef ?? refs.agentRef ?? refs.override
3605
- let limit: number | null = null
3503
+ const ref = resolveActiveModelRef(refs.sessionRef, list, refs.agentRef)
3504
+ if (ref === null) return null
3505
+ let models: unknown[] = []
3606
3506
  try {
3607
- const models = context.data.location?.model?.list?.(location)
3608
- limit = resolveContextLimit(Array.isArray(models) ? models : [], ref)
3507
+ const result = context.data.location?.model?.list?.(location)
3508
+ if (Array.isArray(result)) models = result
3609
3509
  } catch {
3610
- limit = null
3510
+ /* Unknown model limits suppress only the context gauge. */
3611
3511
  }
3612
- return computeContextUsage(list, limit, session()?.revert?.messageID)
3512
+ return resolveModelContextSnapshot(list, ref, models, session()?.revert?.messageID)
3613
3513
  })
3614
3514
 
3615
3515
  // Telemetry that rides on the messages already in hand — no extra request.
@@ -3795,13 +3695,41 @@ export function createSidebarModel(
3795
3695
  * cells), the value, the muted gauge tail (empty cells) and the muted unit
3796
3696
  * suffix (`tokens` / `of 200K` / `spent`). */
3797
3697
  function ContextRowView(props: { row: ContextRow; fg: string; muted: string }) {
3698
+ const fullWidth = () =>
3699
+ cellWidth(
3700
+ `${props.row.lead ?? ''}${props.row.tail ?? ''}${props.row.value}${props.row.suffix ?? ''}`,
3701
+ )
3798
3702
  return (
3799
- <box flexDirection="row">
3800
- <Show when={props.row.lead}>{(lead) => <text fg={props.fg}>{lead()}</text>}</Show>
3801
- <Show when={props.row.tail}>{(tail) => <text fg={props.muted}>{tail()}</text>}</Show>
3802
- <text fg={props.fg}>{props.row.value}</text>
3803
- <Show when={props.row.suffix}>{(suffix) => <text fg={props.muted}>{suffix()}</text>}</Show>
3804
- </box>
3703
+ <Show
3704
+ when={props.row.suffix !== ' gasto na sessão'}
3705
+ fallback={
3706
+ <box flexDirection="column">
3707
+ <For each={sidebarMoneyLines('gasto na sessão', props.row.value)}>
3708
+ {(line) => <text fg={props.fg}>{line}</text>}
3709
+ </For>
3710
+ </box>
3711
+ }
3712
+ >
3713
+ <Show
3714
+ when={fullWidth() <= SIDEBAR_CONTENT_WIDTH}
3715
+ fallback={
3716
+ <box flexDirection="column">
3717
+ <For each={sidebarTextLines(`${props.row.value.trim()}${props.row.suffix ?? ''}`)}>
3718
+ {(line) => <text fg={props.fg}>{line}</text>}
3719
+ </For>
3720
+ </box>
3721
+ }
3722
+ >
3723
+ <box flexDirection="row">
3724
+ <Show when={props.row.lead}>{(lead) => <text fg={props.fg}>{lead()}</text>}</Show>
3725
+ <Show when={props.row.tail}>{(tail) => <text fg={props.muted}>{tail()}</text>}</Show>
3726
+ <text fg={props.fg}>{props.row.value}</text>
3727
+ <Show when={props.row.suffix}>
3728
+ {(suffix) => <text fg={props.muted}>{suffix()}</text>}
3729
+ </Show>
3730
+ </box>
3731
+ </Show>
3732
+ </Show>
3805
3733
  )
3806
3734
  }
3807
3735
 
@@ -3829,7 +3757,13 @@ function BlockHeader(props: {
3829
3757
  )
3830
3758
  }
3831
3759
 
3832
- function Sidebar(props: { context: any; sessionID?: string }) {
3760
+ interface SidebarProps {
3761
+ context: Context
3762
+ sessionID?: string
3763
+ quotaRuntime: QuotaRuntime
3764
+ }
3765
+
3766
+ function Sidebar(props: SidebarProps): JSX.Element {
3833
3767
  const { context } = props
3834
3768
  const model = createSidebarModel(context, () => props.sessionID)
3835
3769
  const text = () => context.theme.text?.base
@@ -3915,16 +3849,30 @@ function Sidebar(props: { context: any; sessionID?: string }) {
3915
3849
  numbers right-aligned; the gauge above remains the block's
3916
3850
  single accent. When no message carries cost this loop is empty
3917
3851
  and the block keeps its original token/spend rows. */}
3852
+ <Show when={usageRows().length > 0}>
3853
+ <text fg={muted()}>Sessão · custo reportado</text>
3854
+ <text fg={muted()}>
3855
+ {'Modelo'.padEnd(MODEL_USAGE_MODEL_WIDTH) +
3856
+ ' Tokens'.padStart(8) +
3857
+ ' USD'.padStart(10)}
3858
+ </text>
3859
+ </Show>
3918
3860
  <For each={usageRows()}>
3919
3861
  {(row: ModelUsageRow) => (
3920
- <box flexDirection="row">
3921
- <text fg={muted()}>{row.model.padEnd(MODEL_USAGE_MODEL_WIDTH)}</text>
3922
- <text fg={text()}>{` ${row.tokens.padStart(MODEL_USAGE_TOKEN_WIDTH)}`}</text>
3923
- <text fg={text()}>{` ${row.cost.padStart(MODEL_USAGE_COST_WIDTH)}`}</text>
3862
+ <box flexDirection="column">
3863
+ <For each={modelUsageRowLines(row)}>
3864
+ {(line) => <text fg={text()}>{line}</text>}
3865
+ </For>
3924
3866
  </box>
3925
3867
  )}
3926
3868
  </For>
3927
- <Show when={usageHidden()}>{(line) => <text fg={muted()}>{line()}</text>}</Show>
3869
+ <Show when={usageHidden()}>
3870
+ {(line) => (
3871
+ <For each={sidebarTextLines(line())}>
3872
+ {(part) => <text fg={muted()}>{part}</text>}
3873
+ </For>
3874
+ )}
3875
+ </Show>
3928
3876
  </box>
3929
3877
  )}
3930
3878
  </Show>
@@ -3934,7 +3882,13 @@ function Sidebar(props: { context: any; sessionID?: string }) {
3934
3882
  <Show when={performanceLine()}>{(line) => <text fg={muted()}>{line()}</text>}</Show>
3935
3883
  {/* Spend, not budget: two local windows on one muted line. Absent
3936
3884
  whenever stats is missing or the from/to unit probe failed. */}
3937
- <Show when={spendLine()}>{(line) => <text fg={muted()}>{line()}</text>}</Show>
3885
+ <Show when={spendLine()}>
3886
+ {(line) => (
3887
+ <For each={contextSpendLines(line())}>
3888
+ {(part) => <text fg={muted()}>{part}</text>}
3889
+ </For>
3890
+ )}
3891
+ </Show>
3938
3892
  </box>
3939
3893
  </Show>
3940
3894
 
@@ -4048,6 +4002,8 @@ function Sidebar(props: { context: any; sessionID?: string }) {
4048
4002
  </Show>
4049
4003
  </box>
4050
4004
  </Show>
4005
+ {/* Keep quota inside this composition: host slots order claims, not our blocks. */}
4006
+ <QuotaSidebarSummary context={context} runtime={props.quotaRuntime} />
4051
4007
  </box>
4052
4008
  )
4053
4009
  }
@@ -4322,11 +4278,13 @@ const plugin = Plugin.define({
4322
4278
  // Eager load/sync at setup so the cache is warm before the slot's first
4323
4279
  // render (Known Issue: empty sidebar before the first prompt).
4324
4280
  warmUpSidebarData(context, location)
4281
+ const quotaRuntime = createQuotaRuntime(context)
4282
+ const unregisterQuotaTui = registerQuotaTui(context, quotaRuntime)
4325
4283
 
4326
4284
  const unregisterSidebar = context.ui.slot({
4327
4285
  append: 'sidebar.content',
4328
4286
  render: ({ sessionID }: { sessionID: string }) => (
4329
- <Sidebar context={context} sessionID={sessionID} />
4287
+ <Sidebar context={context} sessionID={sessionID} quotaRuntime={quotaRuntime} />
4330
4288
  ),
4331
4289
  })
4332
4290
  const unregisterHome = context.ui.slot({
@@ -4364,6 +4322,7 @@ const plugin = Plugin.define({
4364
4322
  if (typeof unregisterPromptFooter === 'function') unregisterPromptFooter()
4365
4323
  if (typeof unregisterPanel === 'function') unregisterPanel()
4366
4324
  if (typeof unregisterCommands === 'function') unregisterCommands()
4325
+ unregisterQuotaTui()
4367
4326
  delete globalState[SINGLETON]
4368
4327
  }
4369
4328
  },
@@ -0,0 +1,4 @@
1
+ /** Shared bounds for cached recent model-usage aggregation. */
2
+ export const MODEL_USAGE_VISIBLE_CEILING = 3
3
+ export const MODEL_USAGE_MESSAGE_LIMIT = 400
4
+ export const MODEL_USAGE_SESSION_LIMIT = 8