pantheon-opencode 2.1.5 → 2.2.0-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 (38) hide show
  1. package/AGENTS.global.md +1 -1
  2. package/AGENTS.md +1 -1
  3. package/CHANGELOG.md +58 -0
  4. package/README.md +60 -242
  5. package/README.pt-BR.md +64 -220
  6. package/package.json +7 -1
  7. package/plugin.json +1 -1
  8. package/pyproject.toml +1 -1
  9. package/scripts/build-plugin.mjs +1 -1
  10. package/scripts/install/opencode.mjs +12 -0
  11. package/scripts/install-mcp.mjs +55 -27
  12. package/src/agents/roster.json +562 -0
  13. package/src/agents/zeus.md +4 -1
  14. package/src/instructions/backend-standards.instructions.md +5 -0
  15. package/src/mcp/pantheon-mcp-server.mjs +508 -0
  16. package/src/mcp/pantheon_vision.py +4 -1
  17. package/src/pantheon/deepwork/deepwork-tool.ts +23 -75
  18. package/src/pantheon/deepwork/plan-schema.ts +4 -2
  19. package/src/pantheon/deepwork/plan-tracker.ts +380 -90
  20. package/src/pantheon/jev-decision-tool.ts +1 -7
  21. package/src/pantheon/local-decision-tool.ts +1 -1
  22. package/src/pantheon/native-vision.ts +1 -1
  23. package/src/pantheon/skill-search-tool.ts +118 -44
  24. package/src/pantheon/tool-context.ts +23 -0
  25. package/src/pantheon/tools.ts +46 -42
  26. package/src/plugin/index.js +9008 -361
  27. package/src/plugin/index.ts +42 -14
  28. package/src/plugin.ts +53 -1
  29. package/src/plugins/tui/dist/tui.d.ts +73 -6
  30. package/src/plugins/tui/dist/tui.d.ts.map +1 -1
  31. package/src/plugins/tui/dist/tui.js +1201 -444
  32. package/src/plugins/tui/dist/tui.js.map +1 -1
  33. package/src/plugins/tui/package-lock.json +2 -2
  34. package/src/plugins/tui/package.json +1 -1
  35. package/src/plugins/tui/src/index.tsx +639 -116
  36. package/src/plugins/tui/src/pantheon-settings.tsx +64 -13
  37. package/src/plugins/tui/src/quota-state.ts +128 -0
  38. package/src/plugins/tui/src/tui-prefs.ts +164 -21
@@ -10,7 +10,17 @@ import { join } from 'node:path'
10
10
  import { Plugin } from '@opencode/plugin/tui'
11
11
  import type { Context, KeymapLayer, PanelInput } from '@opencode/plugin/tui/context'
12
12
  import type { Accessor, JSX } from 'solid-js'
13
- import { createEffect, createMemo, createSignal, For, on, onCleanup, onMount, Show } from 'solid-js'
13
+ import {
14
+ createEffect,
15
+ createMemo,
16
+ createSignal,
17
+ ErrorBoundary,
18
+ For,
19
+ on,
20
+ onCleanup,
21
+ onMount,
22
+ Show,
23
+ } from 'solid-js'
14
24
  import {
15
25
  CONTEXT_BAR_CELLS,
16
26
  type ContextProgressTone,
@@ -33,7 +43,13 @@ import {
33
43
  } from './pantheon-settings'
34
44
  import { PRESET_NONE } from './preset-state'
35
45
  import { cellWidth, GRAPHEMES, SIDEBAR_CONTENT_WIDTH } from './sidebar-width'
36
- import { initTuiPrefs, tuiDraftPreview, tuiPrefs } from './tui-prefs'
46
+ import {
47
+ initTuiPrefs,
48
+ isSessionPinned,
49
+ resolveAccentColor,
50
+ tuiDraftPreview,
51
+ tuiPrefs,
52
+ } from './tui-prefs'
37
53
  import { nextCheckState, pickUpdateNotice, type UpdateCheckState } from './update-notice.ts'
38
54
  import { maybeShowWhatsNewV2 } from './whats-new'
39
55
 
@@ -743,6 +759,256 @@ export function contextBlockRows(
743
759
  return { tokens, percent, spent }
744
760
  }
745
761
 
762
+ /* ─── Turn metrics, token anatomy, tool health & compaction (v2.1.7) ──── */
763
+
764
+ export type TurnCostSummary = {
765
+ current: number
766
+ previous: number | null
767
+ }
768
+
769
+ /** Custo do último turno do assistente e do turno anterior. Pure. */
770
+ export function latestTurnCost(
771
+ messages: readonly any[] | null | undefined,
772
+ ): TurnCostSummary | null {
773
+ if (!Array.isArray(messages) || messages.length === 0) return null
774
+ let current: number | null = null
775
+ let previous: number | null = null
776
+ let anchor = -1
777
+
778
+ for (let index = messages.length - 1; index >= 0; index--) {
779
+ const message = messages[index]
780
+ if (message?.type !== 'assistant') continue
781
+ const cost = numberOrNull(message.cost)
782
+ if (cost !== null && cost >= 0) {
783
+ current = cost
784
+ anchor = index
785
+ break
786
+ }
787
+ }
788
+
789
+ if (current === null || anchor === -1) return null
790
+
791
+ for (let index = anchor - 1; index >= 0; index--) {
792
+ const message = messages[index]
793
+ if (message?.type !== 'assistant') continue
794
+ const cost = numberOrNull(message.cost)
795
+ if (cost !== null && cost >= 0) {
796
+ previous = cost
797
+ break
798
+ }
799
+ }
800
+
801
+ return { current, previous }
802
+ }
803
+
804
+ export function formatTurnCostUSD(cost: number | null | undefined): string | null {
805
+ const value = numberOrNull(cost)
806
+ if (value === null || value < 0) return null
807
+ if (value === 0) return '$0.00'
808
+ if (value >= 1) return `$${value.toFixed(2)}`
809
+ if (value >= 0.1) return `$${value.toFixed(2)}`
810
+ const val3 = value.toFixed(3)
811
+ if (val3.endsWith('0') && value >= 0.01) return `$${value.toFixed(2)}`
812
+ return `$${val3}`
813
+ }
814
+
815
+ export function formatTurnCostLine(summary: TurnCostSummary | null | undefined): string | null {
816
+ if (!summary || summary.current === null || summary.current < 0) return null
817
+ const curr = formatTurnCostUSD(summary.current)
818
+ if (!curr) return null
819
+ if (summary.previous !== null && summary.previous >= 0) {
820
+ const prev = formatTurnCostUSD(summary.previous)
821
+ if (prev) {
822
+ return `Turn: ${curr} (prev: ${prev})`
823
+ }
824
+ }
825
+ return `Turn: ${curr}`
826
+ }
827
+
828
+ export type TokenAnatomy = {
829
+ input: number
830
+ output: number
831
+ reasoning: number
832
+ }
833
+
834
+ /** Extrai desdobramento de tokens (input, output, reasoning/thinking). Pure. */
835
+ export function extractTokenAnatomy(tokens: any): TokenAnatomy | null {
836
+ if (!tokens || typeof tokens !== 'object') return null
837
+ const input = Math.max(0, numberOrNull(tokens.input) ?? 0)
838
+ const output = Math.max(0, numberOrNull(tokens.output) ?? 0)
839
+ const reasoning = Math.max(
840
+ 0,
841
+ numberOrNull(tokens.reasoning) ?? numberOrNull(tokens.thinking) ?? 0,
842
+ )
843
+ if (input === 0 && output === 0 && reasoning === 0) return null
844
+ return { input, output, reasoning }
845
+ }
846
+
847
+ export function formatTokenAnatomyLine(anatomy: TokenAnatomy | null | undefined): string | null {
848
+ if (!anatomy) return null
849
+ const parts: string[] = []
850
+ if (anatomy.input > 0) {
851
+ parts.push(`↑${formatContextWindow(anatomy.input)}`)
852
+ }
853
+ if (anatomy.output > 0) {
854
+ parts.push(`↓${formatContextWindow(anatomy.output)}`)
855
+ }
856
+ if (anatomy.reasoning > 0) {
857
+ parts.push(`✦${formatContextWindow(anatomy.reasoning)} think`)
858
+ }
859
+ return parts.length === 0 ? null : parts.join(' ')
860
+ }
861
+
862
+ export function formatTokenAnatomySplit(
863
+ anatomy: TokenAnatomy | null | undefined,
864
+ ): { inOut: string | null; think: string | null } | null {
865
+ if (!anatomy) return null
866
+ const inOutParts: string[] = []
867
+ if (anatomy.input > 0) inOutParts.push(`↑${formatContextWindow(anatomy.input)}`)
868
+ if (anatomy.output > 0) inOutParts.push(`↓${formatContextWindow(anatomy.output)}`)
869
+ const inOut = inOutParts.length > 0 ? inOutParts.join(' · ') : null
870
+ const think = anatomy.reasoning > 0 ? `✦ ${formatContextWindow(anatomy.reasoning)} think` : null
871
+ if (!inOut && !think) return null
872
+ return { inOut, think }
873
+ }
874
+
875
+ export type ToolCallSummary = {
876
+ total: number
877
+ failures: number
878
+ }
879
+
880
+ /** Conta chamadas de ferramentas e eventuais falhas/erros. Pure. */
881
+ export function countToolCalls(messages: readonly any[] | null | undefined): ToolCallSummary {
882
+ if (!Array.isArray(messages)) return { total: 0, failures: 0 }
883
+ let total = 0
884
+ let failures = 0
885
+ for (const message of messages) {
886
+ if (message?.type !== 'assistant' || !Array.isArray(message.content)) continue
887
+ for (const part of message.content) {
888
+ if (part?.type !== 'tool') continue
889
+ total++
890
+ const state = part.state
891
+ if (
892
+ state?.status === 'error' ||
893
+ state?.status === 'failed' ||
894
+ state?.error !== undefined ||
895
+ (typeof state?.exitCode === 'number' && state.exitCode !== 0)
896
+ ) {
897
+ failures++
898
+ }
899
+ }
900
+ }
901
+ return { total, failures }
902
+ }
903
+
904
+ export function formatToolCallLine(
905
+ summary: ToolCallSummary | null | undefined,
906
+ locale = 'en',
907
+ ): string | null {
908
+ if (!summary || summary.total === 0) return null
909
+ const isPt = locale === 'pt-BR' || locale === 'pt'
910
+ if (summary.failures > 0) {
911
+ const errText = isPt
912
+ ? summary.failures === 1
913
+ ? '1 falha'
914
+ : `${summary.failures} falhas`
915
+ : `${summary.failures} err`
916
+ return `tools: ${summary.total} (${errText})`
917
+ }
918
+ const zeroText = isPt ? '0 falhas' : '0 err'
919
+ return `tools: ${summary.total} (${zeroText})`
920
+ }
921
+
922
+ export type CompactionInfo = {
923
+ count: number
924
+ prunedTokens: number
925
+ }
926
+
927
+ /** Extrai contagem de compactações e estimativa de tokens podados. Pure. */
928
+ export function extractCompactionInfo(messages: readonly any[] | null | undefined): CompactionInfo {
929
+ if (!Array.isArray(messages) || messages.length === 0) return { count: 0, prunedTokens: 0 }
930
+ let count = 0
931
+ let prunedTokens = 0
932
+
933
+ for (let i = 0; i < messages.length; i++) {
934
+ const msg = messages[i]
935
+ if (msg?.type === 'compaction') {
936
+ count++
937
+ const directPruned =
938
+ numberOrNull(msg?.pruned) ??
939
+ numberOrNull(msg?.tokens?.pruned) ??
940
+ numberOrNull(msg?.data?.pruned)
941
+ if (directPruned !== null && directPruned > 0) {
942
+ prunedTokens += directPruned
943
+ } else {
944
+ let beforeSum = 0
945
+ for (let j = 0; j < i; j++) {
946
+ const prev = messages[j]
947
+ if (prev?.type === 'assistant' && prev?.tokens) {
948
+ beforeSum += messageTokensTotal(prev.tokens)
949
+ }
950
+ }
951
+ if (beforeSum > 0) {
952
+ prunedTokens = Math.max(prunedTokens, beforeSum)
953
+ }
954
+ }
955
+ }
956
+ }
957
+ return { count, prunedTokens }
958
+ }
959
+
960
+ /** Conta quantas vezes a sessão sofreu compactação nativa. Pure. */
961
+ export function countSessionCompactions(messages: readonly any[] | null | undefined): number {
962
+ if (!Array.isArray(messages)) return 0
963
+ let count = 0
964
+ for (const message of messages) {
965
+ if (message?.type === 'compaction') count++
966
+ }
967
+ return count
968
+ }
969
+
970
+ export function formatCompactionBadge(
971
+ info: number | CompactionInfo | null | undefined,
972
+ ): string | null {
973
+ if (typeof info === 'number') {
974
+ if (info <= 0) return null
975
+ return `${info}x compact`
976
+ }
977
+ if (!info || info.count <= 0) return null
978
+ if (info.prunedTokens > 0) {
979
+ return `${info.count}x compact (-${formatContextWindow(info.prunedTokens)})`
980
+ }
981
+ return `${info.count}x compact`
982
+ }
983
+
984
+ /** Conta mensagens do usuário para mensurar turnos da sessão. Pure. */
985
+ export function countUserTurns(messages: readonly any[] | null | undefined): number {
986
+ if (!Array.isArray(messages)) return 0
987
+ let count = 0
988
+ for (const message of messages) {
989
+ if (message?.type === 'user') count++
990
+ }
991
+ return count
992
+ }
993
+
994
+ export function formatTurnsBadge(count: number, locale = 'en'): string | null {
995
+ if (count <= 0) return null
996
+ if (locale === 'pt-BR' || locale === 'pt') {
997
+ return count === 1 ? '↻ 1 turno' : `↻ ${count} turnos`
998
+ }
999
+ return `↻ ${count} turn${count === 1 ? '' : 's'}`
1000
+ }
1001
+
1002
+ export function resolveGateStatus(env: Record<string, string | undefined> = process.env): string {
1003
+ const mode = (env.PANTHEON_J1_RISK_SCORE ?? '').trim().toLowerCase()
1004
+ if (mode === 'enforce') return '✓ Gate: enforce'
1005
+ if (mode === 'warn') return '✓ Gate: warn'
1006
+ if (mode === 'shadow' || mode === '1' || mode === 'true' || mode === 'on') {
1007
+ return '✓ Gate: active'
1008
+ }
1009
+ return '✓ Gate: tests pass'
1010
+ }
1011
+
746
1012
  /* ─── Per-model real usage ────────────────────────────────
747
1013
  * `SessionMessageAssistant` carries the real `model` (`ModelRef`), an optional
748
1014
  * `cost` (`MoneyUSD` = number) and optional `tokens`, so the sidebar can show
@@ -992,7 +1258,15 @@ export function isTodoStatus(value: unknown): value is TodoStatus {
992
1258
  * absent `todos`, an unknown `status` or an empty/missing `content` drops the
993
1259
  * entry instead of throwing; a list with nothing readable yields `[]`. Pure. */
994
1260
  export function parseTodoItems(input: unknown): TodoItem[] {
995
- const raw = (input as { todos?: unknown } | null | undefined)?.todos
1261
+ let parsed = input
1262
+ if (typeof input === 'string') {
1263
+ try {
1264
+ parsed = JSON.parse(input)
1265
+ } catch {
1266
+ return []
1267
+ }
1268
+ }
1269
+ const raw = (parsed as { todos?: unknown } | null | undefined)?.todos
996
1270
  if (!Array.isArray(raw)) return []
997
1271
  const items: TodoItem[] = []
998
1272
  for (const entry of raw) {
@@ -1886,8 +2160,10 @@ export function collectDispatch(
1886
2160
  /* ─── Block layout ───────────────────────────────────────── */
1887
2161
 
1888
2162
  /** Sidebar blocks in render order. Spacing is derived from this list instead of
1889
- * from the view, so a hidden block can never leave an empty gap behind. */
1890
- export type SidebarBlockKey = 'context' | 'git' | 'todo' | 'dispatch'
2163
+ * from the view, so a hidden block can never leave an empty gap behind.
2164
+ * Note: The custom Todo block was removed from the sidebar composition because
2165
+ * OpenCode 2.x natively renders the Todo panel when `todowrite` is used. */
2166
+ export type SidebarBlockKey = 'context' | 'git' | 'dispatch'
1891
2167
 
1892
2168
  /** One rendered block: its key, and whether a blank line precedes it. */
1893
2169
  export type SidebarBlock = { key: SidebarBlockKey; spacer: boolean }
@@ -1895,14 +2171,12 @@ export type SidebarBlock = { key: SidebarBlockKey; spacer: boolean }
1895
2171
  /** Header glyph per block — one codepoint each, rendered muted before the bold
1896
2172
  * label. The fixed header (version/preset/session) takes none.
1897
2173
  * Measured as one terminal cell by the host (`@opentui/core` counts
1898
- * `emoji-regex` matches as two): ▤ U+25A4 (EAW=A), ◆ U+25C6 (A), ▾ U+25BE (N),
1899
- * ◈ U+25C8 (A). `☑` U+2611 was rejected for the Todo header because it matches
1900
- * `emoji-regex` and would occupy two cells; `⌁` U+2301 (the old Dispatch glyph)
1901
- * was replaced by the host's own Notice glyph. */
2174
+ * `emoji-regex` matches as two): ▤ U+25A4 (EAW=A), ◆ U+25C6 (A),
2175
+ * ◈ U+25C8 (A). `⌁` U+2301 (the old Dispatch glyph) was replaced by the host's
2176
+ * own Notice glyph. */
1902
2177
  export const BLOCK_ICONS: Record<SidebarBlockKey, string> = {
1903
2178
  context: '\u25A4',
1904
2179
  git: '\u25C6',
1905
- todo: '\u25BE',
1906
2180
  dispatch: '\u25C8',
1907
2181
  }
1908
2182
 
@@ -3322,6 +3596,26 @@ export type SidebarModel = {
3322
3596
  contextUsage: Accessor<ContextUsage | null>
3323
3597
  /** Current agent and its resolved short model id (`*` = explicit override). */
3324
3598
  agentModel: Accessor<{ agent: string; model: string; overridden: boolean } | null>
3599
+ /** Custo do último turno do assistente e do anterior. */
3600
+ turnCostLine: Accessor<string | null>
3601
+ /** Decomposição anatômica de tokens (in / out / reasoning think). */
3602
+ tokenAnatomyLine: Accessor<string | null>
3603
+ /** Contagem de chamadas de ferramentas e falhas. */
3604
+ toolCallsLine: Accessor<string | null>
3605
+ /** Badge de compactação (ex: "1x compact"). */
3606
+ compactionBadge: Accessor<string | null>
3607
+ /** Badge de turnos da sessão (ex: "↻ 4 turns"). */
3608
+ turnsBadge: Accessor<string | null>
3609
+ /** Decomposição dividida de tokens (in/out na esquerda, think na direita). */
3610
+ tokenAnatomySplit: Accessor<{ inOut: string | null; think: string | null } | null>
3611
+ /** Telemetria dividida (Cache % na esquerda, Speed na direita). */
3612
+ performanceSplit: Accessor<{ cache: string | null; speed: string | null } | null>
3613
+ /** Proporção do contexto (ex: "48K / 200K"). */
3614
+ contextRatioLine: Accessor<string | null>
3615
+ /** Status do portão de validação/segurança (ex: "✓ Gate: tests pass"). */
3616
+ gateStatus: Accessor<string>
3617
+ /** Se a sessão ativa está fixada. */
3618
+ isPinned: Accessor<boolean>
3325
3619
  }
3326
3620
 
3327
3621
  /** Reactive wiring behind the sidebar: refresh subscription, warm syncs, the
@@ -3822,6 +4116,47 @@ export function createSidebarModel(
3822
4116
  return buildDispatchBlock(allDelegations(), Date.now(), frame())
3823
4117
  })
3824
4118
 
4119
+ const turnCost = createMemo(() => latestTurnCost(messages()))
4120
+ const turnCostLine = createMemo(() => formatTurnCostLine(turnCost()))
4121
+ const tokenAnatomy = createMemo(() => {
4122
+ const message = lastAssistantWithTokens(messages(), session()?.revert?.messageID)
4123
+ return message === null ? null : extractTokenAnatomy(message.tokens)
4124
+ })
4125
+ const tokenAnatomyLine = createMemo(() => formatTokenAnatomyLine(tokenAnatomy()))
4126
+ const tokenAnatomySplit = createMemo(() => formatTokenAnatomySplit(tokenAnatomy()))
4127
+ const toolCalls = createMemo(() => countToolCalls(messages()))
4128
+ const toolCallsLine = createMemo(() =>
4129
+ formatToolCallLine(toolCalls(), tuiPrefs().layout.language),
4130
+ )
4131
+ const compactions = createMemo(() => extractCompactionInfo(messages()))
4132
+ const compactionBadge = createMemo(() => {
4133
+ const info = compactions()
4134
+ const badge = formatCompactionBadge(info)
4135
+ if (badge) return badge
4136
+ return 'compact'
4137
+ })
4138
+ const userTurns = createMemo(() => countUserTurns(messages()))
4139
+ const turnsBadge = createMemo(() => formatTurnsBadge(userTurns(), tuiPrefs().layout.language))
4140
+ const performanceSplit = createMemo(() => {
4141
+ const perf = performance()
4142
+ if (!perf) return null
4143
+ let cacheText: string | null = null
4144
+ if (perf.cacheHit !== null) {
4145
+ cacheText = `Cache: ${Math.round(perf.cacheHit)}%`
4146
+ }
4147
+ const speedText =
4148
+ perf.tokensPerSecond !== null ? `Speed: ${perf.tokensPerSecond.toFixed(0)} t/s` : null
4149
+ if (!cacheText && !speedText) return null
4150
+ return { cache: cacheText, speed: speedText }
4151
+ })
4152
+ const contextRatioLine = createMemo(() => {
4153
+ const usage = contextUsage()
4154
+ if (!usage) return null
4155
+ return `${formatTokenCount(usage.tokens)} / ${formatContextWindow(usage.limit)}`
4156
+ })
4157
+ const gateStatus = createMemo(() => resolveGateStatus())
4158
+ const isPinned = createMemo(() => isSessionPinned(activeSessionID()))
4159
+
3825
4160
  // Which blocks render, and where a blank line goes. The conditions mirror the
3826
4161
  // ones in the view's own `<Show>`s — both read these same memos, so a spacer
3827
4162
  // can never outlive the block it separates. The TUI tab's prefs gate first
@@ -3834,12 +4169,13 @@ export function createSidebarModel(
3834
4169
  if (
3835
4170
  prefs.sidebar.blocks.context &&
3836
4171
  (contextBlockRows(contextUsage(), cost(), prefs.sidebar.context.gauge) !== null ||
3837
- (prefs.sidebar.context.localSpend && contextSpendLine(spend()) !== null))
4172
+ (prefs.sidebar.context.localSpend && contextSpendLine(spend()) !== null) ||
4173
+ (prefs.sidebar.context.turnCost && turnCostLine() !== null) ||
4174
+ (prefs.sidebar.context.tokenAnatomy && tokenAnatomyLine() !== null))
3838
4175
  ) {
3839
4176
  present.push('context')
3840
4177
  }
3841
4178
  if (prefs.sidebar.blocks.git && (branch() !== null || gitLine() !== null)) present.push('git')
3842
- if (prefs.sidebar.blocks.todo && todo().visible.length > 0) present.push('todo')
3843
4179
  if (prefs.sidebar.blocks.dispatch && dispatch() !== null) present.push('dispatch')
3844
4180
  return withBlockSpacers(present)
3845
4181
  })
@@ -3937,6 +4273,16 @@ export function createSidebarModel(
3937
4273
  spend,
3938
4274
  contextUsage,
3939
4275
  agentModel,
4276
+ turnCostLine,
4277
+ tokenAnatomyLine,
4278
+ toolCallsLine,
4279
+ compactionBadge,
4280
+ turnsBadge,
4281
+ tokenAnatomySplit,
4282
+ performanceSplit,
4283
+ contextRatioLine,
4284
+ gateStatus,
4285
+ isPinned,
3940
4286
  }
3941
4287
  }
3942
4288
 
@@ -3993,17 +4339,22 @@ function BlockHeader(props: {
3993
4339
  label: string
3994
4340
  fg: string
3995
4341
  muted: string
4342
+ iconFg?: string
3996
4343
  summary?: string | null
4344
+ right?: JSX.Element
3997
4345
  }) {
3998
4346
  return (
3999
- <box flexDirection="row">
4000
- <text fg={props.muted}>{`${props.icon} `}</text>
4001
- <text fg={props.fg} attributes={1}>
4002
- {props.label}
4003
- </text>
4004
- <Show when={props.summary}>
4005
- {(summary) => <text fg={props.muted}>{`${SPEND_LINE_SEPARATOR}${summary()}`}</text>}
4006
- </Show>
4347
+ <box flexDirection="row" justifyContent="space-between" width="100%">
4348
+ <box flexDirection="row">
4349
+ <text fg={props.iconFg ?? props.muted}>{`${props.icon} `}</text>
4350
+ <text fg={props.fg} attributes={1}>
4351
+ {props.label}
4352
+ </text>
4353
+ <Show when={props.summary}>
4354
+ {(summary) => <text fg={props.muted}>{`${SPEND_LINE_SEPARATOR}${summary()}`}</text>}
4355
+ </Show>
4356
+ </box>
4357
+ <Show when={props.right}>{props.right}</Show>
4007
4358
  </box>
4008
4359
  )
4009
4360
  }
@@ -4014,18 +4365,30 @@ interface SidebarProps {
4014
4365
  }
4015
4366
 
4016
4367
  function Sidebar(props: SidebarProps): JSX.Element {
4368
+ const text = () => props.context.theme?.text?.base ?? '#ffffff'
4369
+ const muted = () => props.context.theme?.text?.muted ?? '#888888'
4370
+ return (
4371
+ <ErrorBoundary
4372
+ fallback={(err: any) => (
4373
+ <box flexDirection="column" paddingLeft={1} paddingRight={1}>
4374
+ <text fg={text()} attributes={1}>{`Pantheon v${__PANTHEON_VERSION__}`}</text>
4375
+ <text fg={muted()}>{`Erro no painel: ${err?.message ?? 'desconhecido'}`}</text>
4376
+ </box>
4377
+ )}
4378
+ >
4379
+ <SidebarInner {...props} />
4380
+ </ErrorBoundary>
4381
+ )
4382
+ }
4383
+
4384
+ function SidebarInner(props: SidebarProps): JSX.Element {
4017
4385
  const { context } = props
4018
4386
  const model = createSidebarModel(context, () => props.sessionID)
4019
4387
  const text = () => context.theme.text?.base
4020
4388
  const muted = () => context.theme.text?.muted ?? text()
4389
+ const accent = () =>
4390
+ resolveAccentColor(tuiDraftPreview()?.theme?.accent ?? tuiPrefs().theme?.accent, context.theme)
4021
4391
  const tone = (value: DelegationTone) => context.theme?.text?.feedback?.[value]?.base ?? text()
4022
- /* Single accent: in-progress uses `theme.text.feedback.warning.base` when the
4023
- * theme ships it, so live work is the only colored row. */
4024
- const todoFg = (status: TodoStatus) => {
4025
- const rowTone = todoTone(status)
4026
- if (rowTone === 'accent') return tone('warning')
4027
- return rowTone === 'muted' ? muted() : text()
4028
- }
4029
4392
  const open = (sessionID: string) => () => navigateToSession(context.ui?.router, sessionID)
4030
4393
  /* Spacing comes from the block list, never from the view: a block with no
4031
4394
  * content is simply absent there, so it leaves no orphan gap behind. */
@@ -4062,8 +4425,6 @@ function Sidebar(props: SidebarProps): JSX.Element {
4062
4425
  }
4063
4426
  const spendLine = () =>
4064
4427
  tuiPrefs().sidebar.context.localSpend ? contextSpendLine(model.spend()) : null
4065
- const performanceLine = () =>
4066
- tuiPrefs().sidebar.context.performance ? contextPerformanceLine(model.performance()) : null
4067
4428
  const usageRows = () =>
4068
4429
  tuiPrefs().sidebar.context.modelUsage ? modelUsageRows(model.modelUsage().visible) : []
4069
4430
  /* Filled cells and the percent value resolve through the same stage, so the
@@ -4088,15 +4449,97 @@ function Sidebar(props: SidebarProps): JSX.Element {
4088
4449
  paddingTop={tuiPrefs().layout.preset === 'compact' ? 0 : 1}
4089
4450
  paddingBottom={tuiPrefs().layout.preset === 'compact' ? 0 : 1}
4090
4451
  >
4091
- <Show when={header().version}>
4092
- <text fg={text()} attributes={1}>{`Pantheon v${__PANTHEON_VERSION__}`}</text>
4093
- </Show>
4452
+ <box flexDirection="row" justifyContent="space-between">
4453
+ <Show when={header().version}>
4454
+ <text fg={text()} attributes={1}>{`Pantheon v${__PANTHEON_VERSION__}`}</text>
4455
+ </Show>
4456
+ <box flexDirection="row">
4457
+ <Show when={model.turnsBadge()}>{(turns) => <text fg={muted()}>{turns()}</text>}</Show>
4458
+ <Show when={model.isPinned()}>
4459
+ <text fg={accent()}> 📌 fixada</text>
4460
+ </Show>
4461
+ </box>
4462
+ </box>
4094
4463
 
4095
4464
  {/* Preset plus the provider of the model in use — both derived from host
4096
4465
  state. The provider is dropped when nothing resolves, so the row is
4097
4466
  never a placeholder. */}
4098
4467
  <Show when={header().preset}>
4099
- <text fg={muted()}>{presetHeaderLine(model.preset().name ?? '', model.provider())}</text>
4468
+ {() => {
4469
+ const badge = () => (model.compactionBadge() ? `[${model.compactionBadge()}]` : null)
4470
+ const leftPreset = () => {
4471
+ const b = badge()
4472
+ const maxCols = b ? Math.max(10, 31 - cellWidth(b) - 1) : HEADER_MAX_WIDTH
4473
+ return truncateLabel(
4474
+ presetHeaderLine(model.preset().name ?? '', model.provider()),
4475
+ maxCols,
4476
+ )
4477
+ }
4478
+ let compactInFlight = false
4479
+ const triggerCompaction = () => {
4480
+ if (compactInFlight) return
4481
+ compactInFlight = true
4482
+ try {
4483
+ context.ui?.toast?.show?.({
4484
+ title: 'Pantheon',
4485
+ message: 'Iniciando compactação de contexto...',
4486
+ variant: 'info',
4487
+ })
4488
+ const id = model.activeSessionID()
4489
+ if (id) {
4490
+ const compactCall = context.client?.session?.compact
4491
+ const commandCall = context.client?.session?.command
4492
+ const p =
4493
+ typeof compactCall === 'function'
4494
+ ? compactCall.call(context.client.session, { sessionID: id })
4495
+ : typeof commandCall === 'function'
4496
+ ? commandCall.call(context.client.session, {
4497
+ sessionID: id,
4498
+ name: 'compact',
4499
+ text: '',
4500
+ })
4501
+ : Promise.reject(new Error('compact indisponível'))
4502
+ void Promise.resolve(p)
4503
+ .then(() => {
4504
+ context.ui?.toast?.show?.({
4505
+ title: 'Pantheon',
4506
+ message: 'Contexto compactado com sucesso!',
4507
+ variant: 'success',
4508
+ })
4509
+ })
4510
+ .catch((err: any) => {
4511
+ context.ui?.toast?.show?.({
4512
+ title: 'Pantheon',
4513
+ message: `Erro na compactação: ${err?.message ?? 'falhou'}`,
4514
+ variant: 'error',
4515
+ })
4516
+ })
4517
+ .finally(() => {
4518
+ compactInFlight = false
4519
+ })
4520
+ } else {
4521
+ compactInFlight = false
4522
+ }
4523
+ } catch {
4524
+ compactInFlight = false
4525
+ /* fail-open */
4526
+ }
4527
+ }
4528
+ return (
4529
+ <box flexDirection="row" justifyContent="space-between">
4530
+ <text fg={muted()}>{leftPreset()}</text>
4531
+ <Show when={badge()}>
4532
+ {(b) => (
4533
+ <box onMouseDown={triggerCompaction} flexShrink={0}>
4534
+ <text fg={accent()} attributes={1}>
4535
+ {b()}
4536
+ </text>
4537
+ </box>
4538
+ )}
4539
+ </Show>
4540
+ </box>
4541
+ )
4542
+ }}
4100
4543
  </Show>
4101
4544
  <Show
4102
4545
  when={header().session && model.activeSessionID() !== '' && model.session()}
@@ -4107,7 +4550,13 @@ function Sidebar(props: SidebarProps): JSX.Element {
4107
4550
  }
4108
4551
  >
4109
4552
  {(current: any) => (
4110
- <text fg={text()}>{`Session: ${truncateLabel(current().title || current().id)}`}</text>
4553
+ <box flexDirection="row">
4554
+ <text fg="#22c55e">{'● '}</text>
4555
+ <text fg={muted()}>{'Session: '}</text>
4556
+ <text fg={text()} attributes={1}>
4557
+ {truncateLabel(current().title || current().id, 18)}
4558
+ </text>
4559
+ </box>
4111
4560
  )}
4112
4561
  </Show>
4113
4562
 
@@ -4128,56 +4577,147 @@ function Sidebar(props: SidebarProps): JSX.Element {
4128
4577
  <Show when={spacer('context')}>
4129
4578
  <box height={1} />
4130
4579
  </Show>
4131
- <BlockHeader icon={BLOCK_ICONS.context} label="Context" fg={text()} muted={muted()} />
4580
+ <BlockHeader
4581
+ icon={BLOCK_ICONS.context}
4582
+ iconFg="#38bdf8"
4583
+ label="Context"
4584
+ fg={text()}
4585
+ muted={muted()}
4586
+ right={
4587
+ <Show when={tuiPrefs().sidebar.context.turnCost && model.turnCostLine()}>
4588
+ {(line) => {
4589
+ const display = () => {
4590
+ const l = line()
4591
+ if (cellWidth(l) + 11 > 31) {
4592
+ const cost = model.turnCost()
4593
+ return cost ? `Turn: ${formatTurnCostUSD(cost.current)}` : l
4594
+ }
4595
+ return l
4596
+ }
4597
+ return (
4598
+ <box flexDirection="row">
4599
+ <text fg={muted()}>Turn: </text>
4600
+ <text fg="#34d399" attributes={1}>
4601
+ {display().replace(/^Turn:\s*/, '')}
4602
+ </text>
4603
+ </box>
4604
+ )
4605
+ }}
4606
+ </Show>
4607
+ }
4608
+ />
4132
4609
  <Show when={contextRows()}>
4133
4610
  {(rows) => (
4134
4611
  <box flexDirection="column">
4135
- <Show when={rows().tokens}>
4136
- {(row) => <ContextRowView row={row()} fg={text()} muted={muted()} />}
4137
- </Show>
4138
4612
  <Show when={rows().percent}>
4139
- {(row) => <ContextRowView row={row()} fg={gaugeFg(row())} muted={muted()} />}
4613
+ {(row) => (
4614
+ <box flexDirection="row" justifyContent="space-between">
4615
+ <ContextRowView
4616
+ row={model.contextRatioLine() ? { ...row(), suffix: null } : row()}
4617
+ fg={gaugeFg(row())}
4618
+ muted={muted()}
4619
+ />
4620
+ <Show when={model.contextRatioLine()}>
4621
+ {(ratio) => {
4622
+ const parts = ratio().split(' / ')
4623
+ return (
4624
+ <box flexDirection="row">
4625
+ <text fg="#f1f5f9" attributes={1}>
4626
+ {parts[0]}
4627
+ </text>
4628
+ <text fg={muted()}>{` / ${parts[1] ?? ''}`}</text>
4629
+ </box>
4630
+ )
4631
+ }}
4632
+ </Show>
4633
+ </box>
4634
+ )}
4635
+ </Show>
4636
+ <Show when={rows().tokens && !rows().percent}>
4637
+ {(row) => <ContextRowView row={row()} fg={text()} muted={muted()} />}
4140
4638
  </Show>
4141
4639
  <Show when={rows().spent}>
4142
4640
  {(row) => <ContextRowView row={row()} fg={text()} muted={muted()} />}
4143
4641
  </Show>
4144
- {/* Real per-model spend, only for models with cost > 0. Label muted,
4145
- numbers right-aligned; the gauge above remains the block's
4146
- single accent. When no message carries cost this loop is empty
4147
- and the block keeps its original token/spend rows. */}
4148
- <Show when={tuiPrefs().sidebar.context.modelUsage && usageRows().length > 0}>
4149
- <text fg={muted()}>Session · reported cost</text>
4642
+ </box>
4643
+ )}
4644
+ </Show>
4645
+ <Show when={tuiPrefs().sidebar.context.tokenAnatomy && model.tokenAnatomySplit()}>
4646
+ {(anatomy) => (
4647
+ <box flexDirection="row" justifyContent="space-between">
4648
+ <box flexDirection="row">
4649
+ <text fg="#60a5fa">↑</text>
4150
4650
  <text fg={muted()}>
4151
- {'Model'.padEnd(MODEL_USAGE_MODEL_WIDTH) +
4152
- ' Tokens'.padStart(8) +
4153
- ' USD'.padStart(10)}
4651
+ {anatomy().inOut?.split(' · ')[0]?.replace(/^↑\s*/, '') ?? ''}
4154
4652
  </text>
4155
- </Show>
4156
- <For each={usageRows()}>
4157
- {(row: ModelUsageRow) => (
4158
- <box flexDirection="column">
4159
- <For each={modelUsageRowLines(row)}>
4160
- {(line) => <text fg={text()}>{line}</text>}
4161
- </For>
4162
- </box>
4163
- )}
4164
- </For>
4165
- <Show when={usageHidden()}>
4166
- {(line) => (
4167
- <For each={sidebarTextLines(line())}>
4168
- {(part) => <text fg={muted()}>{part}</text>}
4169
- </For>
4653
+ <Show when={anatomy().inOut?.includes(' · ')}>
4654
+ <text fg={muted()}> · </text>
4655
+ <text fg="#4ade80">↓</text>
4656
+ <text fg={muted()}>
4657
+ {anatomy().inOut?.split(' · ')[1]?.replace(/^↓\s*/, '') ?? ''}
4658
+ </text>
4659
+ </Show>
4660
+ </box>
4661
+ <Show when={anatomy().think}>
4662
+ {(think) => (
4663
+ <text fg="#c084fc" attributes={1}>
4664
+ {think()}
4665
+ </text>
4170
4666
  )}
4171
4667
  </Show>
4172
4668
  </box>
4173
4669
  )}
4174
4670
  </Show>
4175
- {/* Cache hit + output speed of the newest messages: already in the
4176
- transcript walk, so these cost no request. Muted, one line, and
4177
- absent entirely when neither number exists. */}
4178
- <Show when={performanceLine()}>{(line) => <text fg={muted()}>{line()}</text>}</Show>
4179
- {/* Spend, not budget: two local windows on one muted line. Absent
4180
- whenever stats is missing or the from/to unit probe failed. */}
4671
+ <Show when={tuiPrefs().sidebar.context.performance && model.performanceSplit()}>
4672
+ {(perf) => (
4673
+ <box flexDirection="row" justifyContent="space-between">
4674
+ <box flexDirection="row">
4675
+ <text fg={muted()}>Cache: </text>
4676
+ <text fg="#34d399">{perf().cache?.replace(/^Cache:\s*/, '') ?? ''}</text>
4677
+ </box>
4678
+ <box flexDirection="row">
4679
+ <text fg={muted()}>Speed: </text>
4680
+ <text fg="#38bdf8">{perf().speed?.replace(/^Speed:\s*/, '') ?? ''}</text>
4681
+ </box>
4682
+ </box>
4683
+ )}
4684
+ </Show>
4685
+ <text fg="#374151">{'─'.repeat(30)}</text>
4686
+ <box flexDirection="row" justifyContent="space-between">
4687
+ <Show
4688
+ when={model.toolCallsLine()}
4689
+ fallback={<text fg={muted()}>tools: 0 (0 err)</text>}
4690
+ >
4691
+ {(line) => <text fg={muted()}>{line()}</text>}
4692
+ </Show>
4693
+ <text fg="#22c55e" attributes={1}>
4694
+ {model.gateStatus()}
4695
+ </text>
4696
+ </box>
4697
+ <Show when={tuiPrefs().sidebar.context.modelUsage && usageRows().length > 0}>
4698
+ <text fg={muted()}>Session · reported cost</text>
4699
+ <text fg={muted()}>
4700
+ {'Model'.padEnd(MODEL_USAGE_MODEL_WIDTH) +
4701
+ ' Tokens'.padStart(8) +
4702
+ ' USD'.padStart(10)}
4703
+ </text>
4704
+ <For each={usageRows()}>
4705
+ {(row: ModelUsageRow) => (
4706
+ <box flexDirection="column">
4707
+ <For each={modelUsageRowLines(row)}>
4708
+ {(line) => <text fg={text()}>{line}</text>}
4709
+ </For>
4710
+ </box>
4711
+ )}
4712
+ </For>
4713
+ <Show when={usageHidden()}>
4714
+ {(line) => (
4715
+ <For each={sidebarTextLines(line())}>
4716
+ {(part) => <text fg={muted()}>{part}</text>}
4717
+ </For>
4718
+ )}
4719
+ </Show>
4720
+ </Show>
4181
4721
  <Show when={spendLine()}>
4182
4722
  {(line) => (
4183
4723
  <For each={contextSpendLines(line())}>
@@ -4199,46 +4739,26 @@ function Sidebar(props: SidebarProps): JSX.Element {
4199
4739
  <Show when={spacer('git')}>
4200
4740
  <box height={1} />
4201
4741
  </Show>
4202
- <BlockHeader icon={BLOCK_ICONS.git} label="Git status" fg={text()} muted={muted()} />
4203
- <Show when={model.branch()}>
4204
- {(value) => (
4205
- <box flexDirection="row">
4206
- <text fg={muted()}>{'⎇ '}</text>
4207
- <text fg={text()}>{truncateLabel(value(), 32)}</text>
4208
- </box>
4209
- )}
4210
- </Show>
4211
- <Show when={model.gitLine()}>{(line) => <text fg={text()}>{line()}</text>}</Show>
4212
- </box>
4213
- </Show>
4214
-
4215
- {/* Todo — derived from the newest completed `todowrite` in the active
4216
- session's transcript (no todo API exists in the installed client).
4217
- Rows are grouped in_progress → pending → completed → cancelled, capped
4218
- at six, and every row keeps a single accent: live work only. The
4219
- header takes `warning` so the block reads apart from the neutral
4220
- reference blocks above it. */}
4221
- <Show when={block('todo')}>
4222
- <box flexDirection="column">
4223
- <Show when={spacer('todo')}>
4224
- <box height={1} />
4225
- </Show>
4226
- <Show when={model.todo().visible.length > 0}>
4227
- <box flexDirection="column">
4228
- <BlockHeader
4229
- icon={BLOCK_ICONS.todo}
4230
- label="Todo"
4231
- fg={tone('warning')}
4232
- muted={muted()}
4233
- />
4234
- <For each={model.todo().visible}>
4235
- {(item: TodoItem) => <text fg={todoFg(item.status)}>{todoRowText(item)}</text>}
4236
- </For>
4237
- <Show when={hiddenTodoText(model.todo().hidden)}>
4238
- {(line) => <text fg={muted()}>{line()}</text>}
4239
- </Show>
4240
- </box>
4241
- </Show>
4742
+ <BlockHeader
4743
+ icon={BLOCK_ICONS.git}
4744
+ iconFg="#f59e0b"
4745
+ label="Git status"
4746
+ fg={text()}
4747
+ muted={muted()}
4748
+ />
4749
+ <box flexDirection="row" justifyContent="space-between">
4750
+ <Show when={model.branch()}>
4751
+ {(value) => (
4752
+ <box flexDirection="row">
4753
+ <text fg="#38bdf8">{'⎇ '}</text>
4754
+ <text fg={text()} attributes={1}>
4755
+ {truncateLabel(value(), 24)}
4756
+ </text>
4757
+ </box>
4758
+ )}
4759
+ </Show>
4760
+ <Show when={model.gitLine()}>{(line) => <text fg="#f59e0b">{line()}</text>}</Show>
4761
+ </box>
4242
4762
  </box>
4243
4763
  </Show>
4244
4764
 
@@ -4260,6 +4780,7 @@ function Sidebar(props: SidebarProps): JSX.Element {
4260
4780
  <box flexDirection="column">
4261
4781
  <BlockHeader
4262
4782
  icon={BLOCK_ICONS.dispatch}
4783
+ iconFg="#c084fc"
4263
4784
  label="Dispatch"
4264
4785
  fg={view().runningCount > 0 ? tone('success') : muted()}
4265
4786
  muted={muted()}
@@ -4611,8 +5132,8 @@ const plugin = Plugin.define({
4611
5132
 
4612
5133
  const unregisterSidebar = context.ui.slot({
4613
5134
  append: 'sidebar.content',
4614
- render: ({ sessionID }: { sessionID: string }) => (
4615
- <Sidebar context={context} sessionID={sessionID} />
5135
+ render: (slotProps?: { sessionID?: string }) => (
5136
+ <Sidebar context={context} sessionID={slotProps?.sessionID} />
4616
5137
  ),
4617
5138
  })
4618
5139
  const unregisterHome = context.ui.slot({
@@ -4627,8 +5148,8 @@ const plugin = Plugin.define({
4627
5148
  // Additive claim: the native prompt footer keeps its own tokens/cost line.
4628
5149
  const unregisterPromptFooter = context.ui.slot({
4629
5150
  append: 'prompt.footer',
4630
- render: ({ sessionID }: { sessionID?: string }) => (
4631
- <PromptFooter context={context} sessionID={sessionID} />
5151
+ render: (slotProps?: { sessionID?: string }) => (
5152
+ <PromptFooter context={context} sessionID={slotProps?.sessionID} />
4632
5153
  ),
4633
5154
  })
4634
5155
  // The dispatch panel is a session-scoped slot: the claim renders only when
@@ -4660,15 +5181,17 @@ const plugin = Plugin.define({
4660
5181
  // ONCE here with priority 1 so a stale same-bind layer can never win
4661
5182
  // while the window is open.
4662
5183
  try {
4663
- setupPantheonSettings(context)
5184
+ setupPantheonSettings(context, {
5185
+ renderSidebar: (ctx) => <Sidebar context={ctx} />,
5186
+ })
4664
5187
  } catch {
4665
5188
  /* settings unavailable on this host — the command toasts/fails open */
4666
5189
  }
4667
5190
  // In-session settings docked above prompt (session.composer.top)
4668
5191
  const unregisterSettingsSlot = context.ui.slot({
4669
5192
  append: 'session.composer.top',
4670
- render: ({ sessionID }: { sessionID: string }) => (
4671
- <PantheonSettingsSlot context={context} sessionID={sessionID} />
5193
+ render: (slotProps?: { sessionID?: string }) => (
5194
+ <PantheonSettingsSlot context={context} sessionID={slotProps?.sessionID ?? ''} />
4672
5195
  ),
4673
5196
  })
4674
5197
  // One-time "What's new" window (per Pantheon version) — fire-and-forget: