pantheon-opencode 1.6.1 → 1.6.2-beta.2
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.
- package/AGENTS.global.md +11 -11
- package/AGENTS.md +2 -2
- package/CHANGELOG.md +29 -0
- package/README.md +100 -19
- package/README.pt-BR.md +27 -11
- package/bin/pantheon-init.mjs +106 -19
- package/package.json +3 -2
- package/plugin.json +1 -1
- package/pyproject.toml +1 -1
- package/scripts/build-agents-md.mjs +1 -1
- package/scripts/doctor.mjs +213 -45
- package/scripts/install/agents-md.mjs +2 -1
- package/scripts/install/config-migration.mjs +344 -393
- package/scripts/install/config-paths.mjs +15 -0
- package/scripts/install/mcp-permissions.mjs +164 -0
- package/scripts/install/opencode-version.mjs +31 -13
- package/scripts/install/opencode-wildcard.mjs +106 -0
- package/scripts/install/opencode.mjs +240 -69
- package/scripts/install/plan-artifact.mjs +12 -1
- package/scripts/install/plugin.mjs +17 -1
- package/scripts/install/v2-capabilities.mjs +5 -6
- package/scripts/package-evidence.mjs +1 -0
- package/scripts/sandbox-env.sh +174 -0
- package/scripts/setup-v2-config.mjs +1703 -0
- package/scripts/setup.mjs +415 -0
- package/scripts/sync-tui.mjs +9 -1
- package/scripts/test-opencode-v2-sandbox.sh +438 -151
- package/scripts/update-skills-lock.mjs +30 -0
- package/skills-lock.json +10 -10
- package/src/agents/aphrodite.md +5 -2
- package/src/agents/apollo.md +5 -0
- package/src/agents/athena.md +6 -1
- package/src/agents/demeter.md +5 -1
- package/src/agents/gaia.md +4 -0
- package/src/agents/hephaestus.md +6 -1
- package/src/agents/hermes.md +6 -3
- package/src/agents/iris.md +5 -1
- package/src/agents/mnemosyne.md +20 -50
- package/src/agents/nyx.md +5 -1
- package/src/agents/prometheus.md +4 -0
- package/src/agents/talos.md +4 -0
- package/src/agents/themis.md +4 -0
- package/src/agents/zeus.md +9 -3
- package/src/instructions/agent-return-format.instructions.md +1 -1
- package/src/instructions/memory-protocol.instructions.md +3 -3
- package/src/instructions/test-economy.instructions.md +6 -6
- package/src/mcp/pantheon_vision.py +37 -36
- package/src/pantheon/cost-command.ts +30 -133
- package/src/pantheon/model-pricing.ts +1 -536
- package/src/pantheon/v2-vision.ts +34 -29
- package/src/pantheon/vision.ts +43 -10
- package/src/plugin-v2.ts +30 -53
- package/src/plugins/tui/THIRD_PARTY_NOTICES.md +24 -0
- package/src/plugins/tui/dist/cost-data-CCZUs1aJ.js +749 -0
- package/src/plugins/tui/dist/cost-data-CCZUs1aJ.js.map +1 -0
- package/src/plugins/tui/dist/quota-adapters.d.ts +89 -0
- package/src/plugins/tui/dist/quota-adapters.d.ts.map +1 -0
- package/src/plugins/tui/dist/quota-adapters.js +1142 -0
- package/src/plugins/tui/dist/quota-adapters.js.map +1 -0
- package/src/plugins/tui/dist/quota-cli.d.ts +17 -0
- package/src/plugins/tui/dist/quota-cli.d.ts.map +1 -0
- package/src/plugins/tui/dist/quota-cli.js +184 -0
- package/src/plugins/tui/dist/quota-cli.js.map +1 -0
- package/src/plugins/tui/dist/quota-rpc-DMmXBhBe.js +684 -0
- package/src/plugins/tui/dist/quota-rpc-DMmXBhBe.js.map +1 -0
- package/src/plugins/tui/dist/server-v2.d.ts +14 -0
- package/src/plugins/tui/dist/server-v2.d.ts.map +1 -0
- package/src/plugins/tui/dist/server-v2.js +796 -0
- package/src/plugins/tui/dist/server-v2.js.map +1 -0
- package/src/plugins/tui/dist/tui-v2.d.ts +375 -53
- package/src/plugins/tui/dist/tui-v2.d.ts.map +1 -1
- package/src/plugins/tui/dist/tui-v2.js +5876 -530
- package/src/plugins/tui/dist/tui-v2.js.map +1 -1
- package/src/plugins/tui/dist/tui.js +1 -1
- package/src/plugins/tui/dist/usage-history-contract-nt1rnBPE.js +118 -0
- package/src/plugins/tui/dist/usage-history-contract-nt1rnBPE.js.map +1 -0
- package/src/plugins/tui/dist/usage-history-worker.js +25 -0
- package/src/plugins/tui/dist/usage-history-worker.js.map +1 -0
- package/src/plugins/tui/index-v2.ts +3 -6
- package/src/plugins/tui/package-lock.json +17 -2
- package/src/plugins/tui/package.json +6 -3
- package/src/plugins/tui/src/context-gauge.ts +59 -0
- package/src/plugins/tui/src/cost-data.ts +607 -0
- package/src/plugins/tui/src/go-key-diagnostic-ui.ts +100 -0
- package/src/plugins/tui/src/go-key-diagnostic.ts +125 -0
- package/src/plugins/tui/src/index-v2.tsx +231 -240
- package/src/plugins/tui/src/model-pricing.ts +536 -0
- package/src/plugins/tui/src/model-usage-limits.ts +4 -0
- package/src/plugins/tui/src/quota-adapters.ts +1598 -0
- package/src/plugins/tui/src/quota-cli.ts +237 -0
- package/src/plugins/tui/src/quota-rpc.ts +373 -0
- package/src/plugins/tui/src/quota-v2-model.ts +1032 -0
- package/src/plugins/tui/src/quota-v2.tsx +1238 -0
- package/src/plugins/tui/src/server-v2.ts +985 -0
- package/src/plugins/tui/src/sidebar-width.ts +129 -0
- package/src/plugins/tui/src/usage-history-contract.ts +217 -0
- package/src/plugins/tui/src/usage-history-validation.ts +104 -0
- package/src/plugins/tui/src/usage-history-view.tsx +236 -0
- package/src/plugins/tui/src/usage-history-worker.ts +25 -0
- package/src/plugins/tui/src/usage-view-model.ts +272 -0
- package/src/plugins/tui/tsconfig.typecheck.json +6 -1
- package/src/plugins/tui/tsdown.config.ts +44 -5
- package/src/routing.yml +72 -13
- package/src/skills/README.md +4 -0
- package/src/skills/agent-coordination/SKILL.md +0 -3
- package/src/skills/artifact-management/SKILL.md +0 -3
- package/src/skills/auto-continue/SKILL.md +0 -3
- package/src/skills/code-review-checklist/SKILL.md +0 -3
- package/src/skills/context-compression/SKILL.md +0 -3
- package/src/skills/memory-bank/SKILL.md +6 -28
- package/src/skills/session-goal/SKILL.md +0 -3
- package/src/skills/simplify/SKILL.md +5 -4
- package/src/skills/tdd-with-agents/SKILL.md +0 -3
- package/src/skills/visual-review-pipeline/SKILL.md +0 -1
- package/src/pantheon/memory-context.ts +0 -1017
|
@@ -8,8 +8,116 @@ 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 type { QuotaIconMode, QuotaIconName, QuotaTab } from './quota-v2'
|
|
54
|
+
export {
|
|
55
|
+
activeQuotaModelLabel,
|
|
56
|
+
DEFAULT_QUOTA_TAB,
|
|
57
|
+
financeMetricLines,
|
|
58
|
+
moveQuotaTab,
|
|
59
|
+
openQuotaPanel,
|
|
60
|
+
providerState,
|
|
61
|
+
QUOTA_ICON,
|
|
62
|
+
QUOTA_OPEN_COMMAND_ID,
|
|
63
|
+
QUOTA_PANEL_COMMANDS,
|
|
64
|
+
QUOTA_PANEL_NAME,
|
|
65
|
+
QUOTA_TABS,
|
|
66
|
+
QuotaPanel,
|
|
67
|
+
quotaIcon,
|
|
68
|
+
quotaMetricLines,
|
|
69
|
+
quotaOpenCommand,
|
|
70
|
+
quotaPanelKeymapLayer,
|
|
71
|
+
quotaPanelStatusMessage,
|
|
72
|
+
quotaTabLabel,
|
|
73
|
+
quotaTextLines,
|
|
74
|
+
quotaUsageTone,
|
|
75
|
+
quotaWindowLines,
|
|
76
|
+
runQuotaPanelCommand,
|
|
77
|
+
sidebarFinanceEntries,
|
|
78
|
+
snapshotSummary,
|
|
79
|
+
} from './quota-v2'
|
|
80
|
+
export type { QuotaSidebarEntry } from './quota-v2-model'
|
|
81
|
+
export {
|
|
82
|
+
collectRecentModelUsageRows,
|
|
83
|
+
compactQuotaMetric,
|
|
84
|
+
createQuotaClock,
|
|
85
|
+
createQuotaRuntime,
|
|
86
|
+
DEFAULT_QUOTA_PREFERENCES,
|
|
87
|
+
formatQuotaCountdown,
|
|
88
|
+
formatQuotaMetric,
|
|
89
|
+
normalizeQuotaPreferences,
|
|
90
|
+
QUOTA_CLOCK_INTERVAL_MS,
|
|
91
|
+
quotaClock,
|
|
92
|
+
quotaProgress,
|
|
93
|
+
quotaSidebarEntries,
|
|
94
|
+
quotaSnapshotFromStatus,
|
|
95
|
+
quotaSnapshotStatusLabel,
|
|
96
|
+
} from './quota-v2-model'
|
|
97
|
+
export { cellWidth } from './sidebar-width'
|
|
98
|
+
export { UsageHistorySection } from './usage-history-view'
|
|
99
|
+
export type { ActiveContextCostResult } from './usage-view-model'
|
|
100
|
+
export {
|
|
101
|
+
activeContextEstimateErrorLines,
|
|
102
|
+
activeContextEstimateLines,
|
|
103
|
+
activeContextEstimateMissingLines,
|
|
104
|
+
activeContextEstimatePendingLines,
|
|
105
|
+
activeModelIdentity,
|
|
106
|
+
sessionSpendLabel,
|
|
107
|
+
USAGE_HISTORY_PERIOD_BINDINGS,
|
|
108
|
+
usageHistoryChartLines,
|
|
109
|
+
usageHistoryControlsLines,
|
|
110
|
+
usageHistoryCoverageLabel,
|
|
111
|
+
usageHistoryEmptyMessage,
|
|
112
|
+
usageHistoryPartialWarning,
|
|
113
|
+
usageHistoryPeriodForKey,
|
|
114
|
+
usageHistoryPricingLabel,
|
|
115
|
+
usageHistorySelectorLabel,
|
|
116
|
+
usageHistorySelectorLines,
|
|
117
|
+
usageHistoryTextLines,
|
|
118
|
+
usageHistoryUnavailableMessage,
|
|
119
|
+
} from './usage-view-model'
|
|
120
|
+
export { resolveActiveModelRef, resolveModelContextSnapshot }
|
|
13
121
|
|
|
14
122
|
const SINGLETON = Symbol.for('pantheon.tui.v2.loaded')
|
|
15
123
|
|
|
@@ -320,20 +428,6 @@ export function computeContextUsage(
|
|
|
320
428
|
return null
|
|
321
429
|
}
|
|
322
430
|
|
|
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
431
|
/** Color for one gauge stage. Filled cells and the percent value both come from
|
|
338
432
|
* this one call, so the bar and its number can never disagree. `theme` is the
|
|
339
433
|
* host's resolved theme (loosely typed at runtime); a missing token falls back
|
|
@@ -458,67 +552,6 @@ export function turnTokensPerSecond(
|
|
|
458
552
|
* are optional; the block renders no line when neither is available. */
|
|
459
553
|
export type ContextPerformance = { cacheHit: number | null; tokensPerSecond: number | null }
|
|
460
554
|
|
|
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
555
|
/** One rendered context row. `lead` and `tail` carry the gauge bar when the row
|
|
523
556
|
* has one (`lead` is toned with the value, `tail` is muted), so the 12 cells
|
|
524
557
|
* stay contiguous while the empty half still reads as background. */
|
|
@@ -551,7 +584,7 @@ export function contextBlockRows(
|
|
|
551
584
|
const spent: ContextRow | null =
|
|
552
585
|
spentValue === null
|
|
553
586
|
? null
|
|
554
|
-
: { lead: null, value: spentValue, tail: null, suffix: '
|
|
587
|
+
: { lead: null, value: spentValue, tail: null, suffix: ' gasto na sessão', tone: null }
|
|
555
588
|
if (usage === null) return spent === null ? null : { tokens: null, percent: null, spent }
|
|
556
589
|
|
|
557
590
|
const tokensValue = formatTokenCount(usage.tokens)
|
|
@@ -586,12 +619,6 @@ export function contextBlockRows(
|
|
|
586
619
|
* a message without `cost` contributes 0 and is omitted (never a guessed
|
|
587
620
|
* price). */
|
|
588
621
|
|
|
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
622
|
/** Column widths for one model row (labels are muted, numbers right-aligned). */
|
|
596
623
|
export const MODEL_USAGE_MODEL_WIDTH = 12
|
|
597
624
|
export const MODEL_USAGE_TOKEN_WIDTH = 6
|
|
@@ -697,6 +724,38 @@ export function modelUsageRowText(row: ModelUsageRow): string {
|
|
|
697
724
|
return `${row.model.padEnd(MODEL_USAGE_MODEL_WIDTH)} ${row.tokens.padStart(MODEL_USAGE_TOKEN_WIDTH)} ${row.cost.padStart(MODEL_USAGE_COST_WIDTH)}`
|
|
698
725
|
}
|
|
699
726
|
|
|
727
|
+
/** Wrap sidebar text by terminal cells, preserving the complete values. */
|
|
728
|
+
export function sidebarTextLines(value: string): string[] {
|
|
729
|
+
return quotaTextLines(value, SIDEBAR_CONTENT_WIDTH, 0)
|
|
730
|
+
}
|
|
731
|
+
|
|
732
|
+
/** Align a monetary value when it fits, otherwise preserve it on a new line. */
|
|
733
|
+
export function sidebarMoneyLines(label: string, value: string): string[] {
|
|
734
|
+
const gap = SIDEBAR_CONTENT_WIDTH - cellWidth(label) - cellWidth(value)
|
|
735
|
+
return gap >= 1
|
|
736
|
+
? [`${label}${' '.repeat(gap)}${value}`]
|
|
737
|
+
: [...sidebarTextLines(label), ...sidebarTextLines(value)]
|
|
738
|
+
}
|
|
739
|
+
|
|
740
|
+
/** Keep the existing OpenCode periods together when possible. */
|
|
741
|
+
export function contextSpendLines(value: string): string[] {
|
|
742
|
+
const match = /^(.*\S)\s+(<?\$\S+)$/.exec(value)
|
|
743
|
+
return match?.[1] && match[2] && cellWidth(value) <= SIDEBAR_CONTENT_WIDTH
|
|
744
|
+
? sidebarMoneyLines(match[1], match[2])
|
|
745
|
+
: sidebarTextLines(value)
|
|
746
|
+
}
|
|
747
|
+
|
|
748
|
+
/** Keep ordinary rows aligned; give oversized values their own lines. */
|
|
749
|
+
export function modelUsageRowLines(row: ModelUsageRow): string[] {
|
|
750
|
+
const single = modelUsageRowText(row)
|
|
751
|
+
if (cellWidth(single) <= SIDEBAR_CONTENT_WIDTH) return [single]
|
|
752
|
+
return [
|
|
753
|
+
...sidebarTextLines(row.model),
|
|
754
|
+
...sidebarTextLines(`Tokens ${row.tokens}`),
|
|
755
|
+
...sidebarTextLines(`USD ${row.cost}`),
|
|
756
|
+
]
|
|
757
|
+
}
|
|
758
|
+
|
|
700
759
|
/** Muted aggregate line for the models beyond the cap (`… +2 $0.03`). Null
|
|
701
760
|
* when every model fits. Pure. */
|
|
702
761
|
export function hiddenModelUsageText(hidden: number, hiddenCost: number): string | null {
|
|
@@ -1172,10 +1231,10 @@ export function statsRangeMatches(
|
|
|
1172
1231
|
return sameUnit || asMilliseconds
|
|
1173
1232
|
}
|
|
1174
1233
|
|
|
1175
|
-
/** The `Context` block's last line:
|
|
1176
|
-
* (`hoje $0.42 · 30d $9.80`). A window without a
|
|
1177
|
-
* no usable window at all yields null so the
|
|
1178
|
-
* dropped. Pure. */
|
|
1234
|
+
/** The `Context` block's last line: OpenCode stats source and both spend windows
|
|
1235
|
+
* on one muted row (`OpenCode · hoje $0.42 · 30d $9.80`). A window without a
|
|
1236
|
+
* usable amount is omitted, and no usable window at all yields null so the
|
|
1237
|
+
* line (and not the block) is dropped. Pure. */
|
|
1179
1238
|
export function contextSpendLine(totals: SpendTotals | null): string | null {
|
|
1180
1239
|
if (totals === null) return null
|
|
1181
1240
|
const parts: string[] = []
|
|
@@ -1183,138 +1242,13 @@ export function contextSpendLine(totals: SpendTotals | null): string | null {
|
|
|
1183
1242
|
if (today !== null) parts.push(`${SPEND_TODAY_LABEL} ${today}`)
|
|
1184
1243
|
const thirtyDays = formatSpendUSD(totals.thirtyDays)
|
|
1185
1244
|
if (thirtyDays !== null) parts.push(`${SPEND_30D_LABEL} ${thirtyDays}`)
|
|
1186
|
-
return parts.length === 0
|
|
1245
|
+
return parts.length === 0
|
|
1246
|
+
? null
|
|
1247
|
+
: `OpenCode${SPEND_LINE_SEPARATOR}${parts.join(SPEND_LINE_SEPARATOR)}`
|
|
1187
1248
|
}
|
|
1188
1249
|
|
|
1189
1250
|
/** Grapheme iterator: a cut never splits a surrogate pair, a combining mark
|
|
1190
1251
|
* 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
1252
|
/** Clamp a free-form label to `max` terminal cells without wrapping. The width
|
|
1319
1253
|
* is measured in display cells, never in UTF-16 code units: a CJK or emoji
|
|
1320
1254
|
* label used to overflow the column it was cut for (`計画の移行` is 5 code
|
|
@@ -1347,7 +1281,7 @@ export function padCell(value: string, cells: number): string {
|
|
|
1347
1281
|
}
|
|
1348
1282
|
|
|
1349
1283
|
/** Columns the fixed header may use before it would wrap the sidebar. */
|
|
1350
|
-
export const HEADER_MAX_WIDTH =
|
|
1284
|
+
export const HEADER_MAX_WIDTH = SIDEBAR_CONTENT_WIDTH
|
|
1351
1285
|
|
|
1352
1286
|
/** Preset row of the fixed header: `▸ <preset> · <provider>`. The provider is
|
|
1353
1287
|
* cut first when the row overflows, so the preset name is never the casualty;
|
|
@@ -3595,21 +3529,19 @@ export function createSidebarModel(
|
|
|
3595
3529
|
})
|
|
3596
3530
|
|
|
3597
3531
|
const contextUsage = createMemo(() => {
|
|
3598
|
-
const list = messages()
|
|
3532
|
+
const list = messages().slice(-MODEL_USAGE_MESSAGE_LIMIT)
|
|
3599
3533
|
if (list.length === 0) return null
|
|
3600
3534
|
const refs = modelRefs()
|
|
3601
|
-
const
|
|
3602
|
-
|
|
3603
|
-
|
|
3604
|
-
const ref = lastAssistant?.model ?? refs.sessionRef ?? refs.agentRef ?? refs.override
|
|
3605
|
-
let limit: number | null = null
|
|
3535
|
+
const ref = resolveActiveModelRef(refs.sessionRef, list, refs.agentRef)
|
|
3536
|
+
if (ref === null) return null
|
|
3537
|
+
let models: unknown[] = []
|
|
3606
3538
|
try {
|
|
3607
|
-
const
|
|
3608
|
-
|
|
3539
|
+
const result = context.data.location?.model?.list?.(location)
|
|
3540
|
+
if (Array.isArray(result)) models = result
|
|
3609
3541
|
} catch {
|
|
3610
|
-
|
|
3542
|
+
/* Unknown model limits suppress only the context gauge. */
|
|
3611
3543
|
}
|
|
3612
|
-
return
|
|
3544
|
+
return resolveModelContextSnapshot(list, ref, models, session()?.revert?.messageID)
|
|
3613
3545
|
})
|
|
3614
3546
|
|
|
3615
3547
|
// Telemetry that rides on the messages already in hand — no extra request.
|
|
@@ -3795,13 +3727,41 @@ export function createSidebarModel(
|
|
|
3795
3727
|
* cells), the value, the muted gauge tail (empty cells) and the muted unit
|
|
3796
3728
|
* suffix (`tokens` / `of 200K` / `spent`). */
|
|
3797
3729
|
function ContextRowView(props: { row: ContextRow; fg: string; muted: string }) {
|
|
3730
|
+
const fullWidth = () =>
|
|
3731
|
+
cellWidth(
|
|
3732
|
+
`${props.row.lead ?? ''}${props.row.tail ?? ''}${props.row.value}${props.row.suffix ?? ''}`,
|
|
3733
|
+
)
|
|
3798
3734
|
return (
|
|
3799
|
-
<
|
|
3800
|
-
|
|
3801
|
-
|
|
3802
|
-
|
|
3803
|
-
|
|
3804
|
-
|
|
3735
|
+
<Show
|
|
3736
|
+
when={props.row.suffix !== ' gasto na sessão'}
|
|
3737
|
+
fallback={
|
|
3738
|
+
<box flexDirection="column">
|
|
3739
|
+
<For each={sidebarMoneyLines('gasto na sessão', props.row.value)}>
|
|
3740
|
+
{(line) => <text fg={props.fg}>{line}</text>}
|
|
3741
|
+
</For>
|
|
3742
|
+
</box>
|
|
3743
|
+
}
|
|
3744
|
+
>
|
|
3745
|
+
<Show
|
|
3746
|
+
when={fullWidth() <= SIDEBAR_CONTENT_WIDTH}
|
|
3747
|
+
fallback={
|
|
3748
|
+
<box flexDirection="column">
|
|
3749
|
+
<For each={sidebarTextLines(`${props.row.value.trim()}${props.row.suffix ?? ''}`)}>
|
|
3750
|
+
{(line) => <text fg={props.fg}>{line}</text>}
|
|
3751
|
+
</For>
|
|
3752
|
+
</box>
|
|
3753
|
+
}
|
|
3754
|
+
>
|
|
3755
|
+
<box flexDirection="row">
|
|
3756
|
+
<Show when={props.row.lead}>{(lead) => <text fg={props.fg}>{lead()}</text>}</Show>
|
|
3757
|
+
<Show when={props.row.tail}>{(tail) => <text fg={props.muted}>{tail()}</text>}</Show>
|
|
3758
|
+
<text fg={props.fg}>{props.row.value}</text>
|
|
3759
|
+
<Show when={props.row.suffix}>
|
|
3760
|
+
{(suffix) => <text fg={props.muted}>{suffix()}</text>}
|
|
3761
|
+
</Show>
|
|
3762
|
+
</box>
|
|
3763
|
+
</Show>
|
|
3764
|
+
</Show>
|
|
3805
3765
|
)
|
|
3806
3766
|
}
|
|
3807
3767
|
|
|
@@ -3829,7 +3789,13 @@ function BlockHeader(props: {
|
|
|
3829
3789
|
)
|
|
3830
3790
|
}
|
|
3831
3791
|
|
|
3832
|
-
|
|
3792
|
+
interface SidebarProps {
|
|
3793
|
+
context: Context
|
|
3794
|
+
sessionID?: string
|
|
3795
|
+
quotaRuntime: QuotaRuntime
|
|
3796
|
+
}
|
|
3797
|
+
|
|
3798
|
+
function Sidebar(props: SidebarProps): JSX.Element {
|
|
3833
3799
|
const { context } = props
|
|
3834
3800
|
const model = createSidebarModel(context, () => props.sessionID)
|
|
3835
3801
|
const text = () => context.theme.text?.base
|
|
@@ -3915,16 +3881,30 @@ function Sidebar(props: { context: any; sessionID?: string }) {
|
|
|
3915
3881
|
numbers right-aligned; the gauge above remains the block's
|
|
3916
3882
|
single accent. When no message carries cost this loop is empty
|
|
3917
3883
|
and the block keeps its original token/spend rows. */}
|
|
3884
|
+
<Show when={usageRows().length > 0}>
|
|
3885
|
+
<text fg={muted()}>Sessão · custo reportado</text>
|
|
3886
|
+
<text fg={muted()}>
|
|
3887
|
+
{'Modelo'.padEnd(MODEL_USAGE_MODEL_WIDTH) +
|
|
3888
|
+
' Tokens'.padStart(8) +
|
|
3889
|
+
' USD'.padStart(10)}
|
|
3890
|
+
</text>
|
|
3891
|
+
</Show>
|
|
3918
3892
|
<For each={usageRows()}>
|
|
3919
3893
|
{(row: ModelUsageRow) => (
|
|
3920
|
-
<box flexDirection="
|
|
3921
|
-
<
|
|
3922
|
-
|
|
3923
|
-
|
|
3894
|
+
<box flexDirection="column">
|
|
3895
|
+
<For each={modelUsageRowLines(row)}>
|
|
3896
|
+
{(line) => <text fg={text()}>{line}</text>}
|
|
3897
|
+
</For>
|
|
3924
3898
|
</box>
|
|
3925
3899
|
)}
|
|
3926
3900
|
</For>
|
|
3927
|
-
<Show when={usageHidden()}>
|
|
3901
|
+
<Show when={usageHidden()}>
|
|
3902
|
+
{(line) => (
|
|
3903
|
+
<For each={sidebarTextLines(line())}>
|
|
3904
|
+
{(part) => <text fg={muted()}>{part}</text>}
|
|
3905
|
+
</For>
|
|
3906
|
+
)}
|
|
3907
|
+
</Show>
|
|
3928
3908
|
</box>
|
|
3929
3909
|
)}
|
|
3930
3910
|
</Show>
|
|
@@ -3934,7 +3914,13 @@ function Sidebar(props: { context: any; sessionID?: string }) {
|
|
|
3934
3914
|
<Show when={performanceLine()}>{(line) => <text fg={muted()}>{line()}</text>}</Show>
|
|
3935
3915
|
{/* Spend, not budget: two local windows on one muted line. Absent
|
|
3936
3916
|
whenever stats is missing or the from/to unit probe failed. */}
|
|
3937
|
-
<Show when={spendLine()}>
|
|
3917
|
+
<Show when={spendLine()}>
|
|
3918
|
+
{(line) => (
|
|
3919
|
+
<For each={contextSpendLines(line())}>
|
|
3920
|
+
{(part) => <text fg={muted()}>{part}</text>}
|
|
3921
|
+
</For>
|
|
3922
|
+
)}
|
|
3923
|
+
</Show>
|
|
3938
3924
|
</box>
|
|
3939
3925
|
</Show>
|
|
3940
3926
|
|
|
@@ -4048,6 +4034,8 @@ function Sidebar(props: { context: any; sessionID?: string }) {
|
|
|
4048
4034
|
</Show>
|
|
4049
4035
|
</box>
|
|
4050
4036
|
</Show>
|
|
4037
|
+
{/* Keep quota inside this composition: host slots order claims, not our blocks. */}
|
|
4038
|
+
<QuotaSidebarSummary context={context} runtime={props.quotaRuntime} />
|
|
4051
4039
|
</box>
|
|
4052
4040
|
)
|
|
4053
4041
|
}
|
|
@@ -4322,11 +4310,13 @@ const plugin = Plugin.define({
|
|
|
4322
4310
|
// Eager load/sync at setup so the cache is warm before the slot's first
|
|
4323
4311
|
// render (Known Issue: empty sidebar before the first prompt).
|
|
4324
4312
|
warmUpSidebarData(context, location)
|
|
4313
|
+
const quotaRuntime = createQuotaRuntime(context)
|
|
4314
|
+
const unregisterQuotaTui = registerQuotaTui(context, quotaRuntime)
|
|
4325
4315
|
|
|
4326
4316
|
const unregisterSidebar = context.ui.slot({
|
|
4327
4317
|
append: 'sidebar.content',
|
|
4328
4318
|
render: ({ sessionID }: { sessionID: string }) => (
|
|
4329
|
-
<Sidebar context={context} sessionID={sessionID} />
|
|
4319
|
+
<Sidebar context={context} sessionID={sessionID} quotaRuntime={quotaRuntime} />
|
|
4330
4320
|
),
|
|
4331
4321
|
})
|
|
4332
4322
|
const unregisterHome = context.ui.slot({
|
|
@@ -4364,6 +4354,7 @@ const plugin = Plugin.define({
|
|
|
4364
4354
|
if (typeof unregisterPromptFooter === 'function') unregisterPromptFooter()
|
|
4365
4355
|
if (typeof unregisterPanel === 'function') unregisterPanel()
|
|
4366
4356
|
if (typeof unregisterCommands === 'function') unregisterCommands()
|
|
4357
|
+
unregisterQuotaTui()
|
|
4367
4358
|
delete globalState[SINGLETON]
|
|
4368
4359
|
}
|
|
4369
4360
|
},
|