pantheon-opencode 1.7.0 → 2.0.0-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.
Files changed (173) hide show
  1. package/AGENTS.global.md +2 -2
  2. package/AGENTS.md +3 -3
  3. package/CHANGELOG.md +85 -59
  4. package/README.md +74 -48
  5. package/README.pt-BR.md +19 -19
  6. package/bin/pantheon-init.mjs +11 -48
  7. package/package.json +9 -13
  8. package/plugin.json +2 -2
  9. package/pyproject.toml +1 -1
  10. package/scripts/build-agents-md.mjs +7 -6
  11. package/scripts/{check-plugin-v2-coverage.mjs → check-plugin-coverage.mjs} +7 -7
  12. package/scripts/{decision-router-v2-budget.mjs → decision-router-budget-gates.mjs} +1 -1
  13. package/scripts/{decision-router-v2-egress.mjs → decision-router-egress.mjs} +1 -1
  14. package/scripts/decision-router.mjs +2 -2
  15. package/scripts/docs-media.mjs +1 -1
  16. package/scripts/doctor.mjs +225 -136
  17. package/scripts/install/behavior-overrides.bundle.mjs +123 -0
  18. package/scripts/install/{v2-capabilities.mjs → capabilities.mjs} +7 -7
  19. package/scripts/install/config-migration.mjs +60 -253
  20. package/scripts/install/file-inventory.mjs +6 -4
  21. package/scripts/install/interactive.mjs +1 -1
  22. package/scripts/install/opencode-state.mjs +13 -12
  23. package/scripts/install/opencode-version.mjs +97 -162
  24. package/scripts/install/opencode.mjs +271 -428
  25. package/scripts/install/plan.mjs +1 -9
  26. package/scripts/install/plugin.mjs +19 -35
  27. package/scripts/install/shared.mjs +40 -1
  28. package/scripts/package-evidence.mjs +1 -4
  29. package/scripts/probe-pantheon-cost.mjs +1 -1
  30. package/scripts/reconcile.mjs +5 -7
  31. package/scripts/release-gates.mjs +22 -61
  32. package/scripts/setup-v2-config.mjs +10 -8
  33. package/scripts/setup.mjs +12 -22
  34. package/scripts/sync-tui.mjs +9 -17
  35. package/scripts/{test-opencode-v2-sandbox.sh → test-opencode-sandbox.sh} +9 -9
  36. package/scripts/update-skills-lock.mjs +24 -12
  37. package/scripts/update.mjs +17 -1
  38. package/scripts/validate-routing.mjs +79 -4
  39. package/scripts/validate-sandbox-install.mjs +3 -3
  40. package/skills-lock.json +25 -8
  41. package/src/agents/zeus.md +1 -0
  42. package/src/pantheon/behavior-overrides.ts +191 -0
  43. package/src/pantheon/{v2-bounded-read.ts → bounded-read.ts} +1 -1
  44. package/src/pantheon/cost-command.ts +1 -1
  45. package/src/pantheon/{v2-decision-contracts.ts → decision-contracts.ts} +3 -3
  46. package/src/pantheon/{v2-decision-points → decision-points}/p1-agent.ts +3 -3
  47. package/src/pantheon/{v2-decision-points → decision-points}/p10-claims.ts +2 -2
  48. package/src/pantheon/{v2-decision-points → decision-points}/p11-catalog.ts +2 -2
  49. package/src/pantheon/{v2-decision-points → decision-points}/p2-skill.ts +3 -3
  50. package/src/pantheon/{v2-decision-points → decision-points}/p3-complexity.ts +6 -6
  51. package/src/pantheon/{v2-decision-points → decision-points}/p4-memory.ts +2 -2
  52. package/src/pantheon/{v2-decision-points → decision-points}/p5-themis-verify.ts +2 -2
  53. package/src/pantheon/{v2-decision-points → decision-points}/p6-council.ts +3 -3
  54. package/src/pantheon/{v2-decision-points → decision-points}/p7-loop.ts +5 -5
  55. package/src/pantheon/{v2-decision-points → decision-points}/p8-guardrail.ts +2 -2
  56. package/src/pantheon/{v2-decision-points → decision-points}/p9-memory-compaction.ts +2 -2
  57. package/src/pantheon/{v2-decision-points.ts → decision-points.ts} +5 -5
  58. package/src/pantheon/{v2-decision-policy.ts → decision-policy.ts} +2 -2
  59. package/src/pantheon/{v2-decision-prompt-surface.ts → decision-prompt-surface.ts} +3 -3
  60. package/src/pantheon/{v2-decision-registry.ts → decision-registry.ts} +10 -13
  61. package/src/pantheon/{v2-decision-resource-ids.ts → decision-resource-ids.ts} +1 -1
  62. package/src/pantheon/{v2-decision-shadow.ts → decision-shadow.ts} +1 -1
  63. package/src/pantheon/{v2-decision-telemetry.ts → decision-telemetry.ts} +1 -1
  64. package/src/pantheon/{v2-execute-after.ts → execute-after.ts} +4 -4
  65. package/src/pantheon/goal-store.ts +7 -0
  66. package/src/pantheon/{v2-hook-engine.ts → hook-engine.ts} +3 -3
  67. package/src/pantheon/jev-decision-tool.ts +3 -3
  68. package/src/pantheon/jev-decisions.ts +12 -6
  69. package/src/pantheon/jev-escalation.ts +6 -6
  70. package/src/pantheon/jev-quality-score.ts +2 -2
  71. package/src/pantheon/jev-rank-verify.ts +2 -2
  72. package/src/pantheon/jev-risk-gate.ts +4 -4
  73. package/src/pantheon/local-decision-agents.ts +1 -1
  74. package/src/pantheon/local-decision-router.ts +1 -1
  75. package/src/pantheon/local-decision-tool.ts +2 -2
  76. package/src/pantheon/local-orchestration.ts +1 -1
  77. package/src/pantheon/model-command.ts +1 -1
  78. package/src/pantheon/{v2-vision.ts → native-vision.ts} +12 -15
  79. package/src/pantheon/pantheon-decision-catalog.ts +12 -0
  80. package/src/pantheon/{v2-shell-hooks.ts → shell-hooks.ts} +4 -4
  81. package/src/pantheon/{v2-tools.ts → tools.ts} +4 -4
  82. package/src/pantheon/{v2-unsupported.d.mts → unsupported.d.mts} +3 -3
  83. package/src/pantheon/{v2-unsupported.mjs → unsupported.mjs} +8 -8
  84. package/src/pantheon/update-notifier.ts +101 -0
  85. package/src/pantheon/vision-local.ts +12 -3
  86. package/src/pantheon/vision.ts +120 -2
  87. package/src/{plugin-v2 → plugin}/index.ts +7 -7
  88. package/src/plugin.ts +2870 -500
  89. package/src/plugins/hook-runner.ts +3 -3
  90. package/src/plugins/tui/dist/server.d.ts +23 -9
  91. package/src/plugins/tui/dist/server.d.ts.map +1 -1
  92. package/src/plugins/tui/dist/server.js +25 -12
  93. package/src/plugins/tui/dist/server.js.map +1 -1
  94. package/src/plugins/tui/dist/tui.d.ts +1023 -494
  95. package/src/plugins/tui/dist/tui.d.ts.map +1 -1
  96. package/src/plugins/tui/dist/tui.js +5612 -2086
  97. package/src/plugins/tui/dist/tui.js.map +1 -1
  98. package/src/plugins/tui/{index-v2.ts → index.ts} +1 -1
  99. package/src/plugins/tui/package-lock.json +2 -42
  100. package/src/plugins/tui/package.json +4 -10
  101. package/src/plugins/tui/src/cost-data.ts +1 -1
  102. package/src/plugins/tui/src/decision-router-state.ts +242 -0
  103. package/src/plugins/tui/src/doctor-state.ts +198 -0
  104. package/src/plugins/tui/src/index.tsx +4222 -2822
  105. package/src/plugins/tui/src/j1-gate-status.ts +85 -0
  106. package/src/plugins/tui/src/pantheon-settings-state.ts +245 -0
  107. package/src/plugins/tui/src/pantheon-settings.tsx +442 -0
  108. package/src/plugins/tui/src/preset-state.ts +143 -0
  109. package/src/plugins/tui/src/server.ts +23 -10
  110. package/src/plugins/tui/src/update-notice.ts +90 -0
  111. package/src/plugins/tui/src/update-status.ts +98 -0
  112. package/src/plugins/tui/tsconfig.typecheck.json +9 -2
  113. package/src/plugins/tui/tsdown.config.ts +3 -5
  114. package/src/plugins/tui/tui.ts +1 -2
  115. package/src/routing.yml +36 -0
  116. package/src/skills/README.md +16 -1
  117. package/src/skills/artifact-management/SKILL.md +10 -67
  118. package/src/skills/artifact-management/references/artifact-templates.md +71 -0
  119. package/src/skills/auto-continue/SKILL.md +10 -0
  120. package/src/skills/code-review-checklist/SKILL.md +11 -44
  121. package/src/skills/code-review-checklist/references/review-checklists.md +54 -0
  122. package/src/skills/instruction-forge/SKILL.md +57 -0
  123. package/src/skills/instruction-forge/references/agents-md-doctrine.md +50 -0
  124. package/src/skills/instruction-forge/references/eval-doctrine.md +37 -0
  125. package/src/skills/instruction-forge/references/skill-doctrine.md +62 -0
  126. package/src/skills/memory-bank/SKILL.md +11 -90
  127. package/src/skills/memory-bank/references/anti-patterns.md +33 -0
  128. package/src/skills/memory-bank/references/product-adoption.md +19 -0
  129. package/src/skills/memory-bank/references/storage-model.md +21 -0
  130. package/src/skills/memory-bank/references/structure-and-frequency.md +44 -0
  131. package/src/skills/reflect/SKILL.md +1 -0
  132. package/src/skills/session-goal/SKILL.md +7 -54
  133. package/src/skills/session-goal/references/goal-format.md +26 -0
  134. package/src/skills/session-goal/references/session-reuse.md +44 -0
  135. package/src/skills/tdd-with-agents/SKILL.md +11 -101
  136. package/src/skills/tdd-with-agents/references/advanced-testing-patterns.md +58 -0
  137. package/src/skills/tdd-with-agents/references/testing-by-layer.md +60 -0
  138. package/src/skills/visual-review-pipeline/SKILL.md +11 -120
  139. package/src/skills/visual-review-pipeline/references/findings-schema.md +49 -0
  140. package/src/skills/visual-review-pipeline/references/workflow-steps.md +111 -0
  141. package/scripts/hooks/log-session-start.sh +0 -48
  142. package/scripts/hooks/validate-post-conditions.sh +0 -21
  143. package/scripts/hooks/validate-talos-scope.sh +0 -50
  144. package/scripts/hooks/validate-tool-safety.sh +0 -49
  145. package/src/pantheon/goal-loop.ts +0 -314
  146. package/src/pantheon/idle-continuation.ts +0 -52
  147. package/src/pantheon/todo-preserve.ts +0 -301
  148. package/src/pantheon/tool-ceiling.ts +0 -159
  149. package/src/pantheon/v2-bridge.ts +0 -153
  150. package/src/plugin-v2.ts +0 -2954
  151. package/src/plugins/pantheon-hooks.ts +0 -1433
  152. package/src/plugins/tui/dist/server-v2.d.ts +0 -30
  153. package/src/plugins/tui/dist/server-v2.d.ts.map +0 -1
  154. package/src/plugins/tui/dist/server-v2.js +0 -33
  155. package/src/plugins/tui/dist/server-v2.js.map +0 -1
  156. package/src/plugins/tui/dist/tui-v2.d.ts +0 -1039
  157. package/src/plugins/tui/dist/tui-v2.d.ts.map +0 -1
  158. package/src/plugins/tui/dist/tui-v2.js +0 -4597
  159. package/src/plugins/tui/dist/tui-v2.js.map +0 -1
  160. package/src/plugins/tui/src/index-v2.tsx +0 -4496
  161. package/src/plugins/tui/src/server-v2.ts +0 -28
  162. package/src/plugins/tui/tui-v2.ts +0 -2
  163. /package/src/pantheon/{v2-decision-budget.ts → decision-budget.ts} +0 -0
  164. /package/src/pantheon/{v2-decision-egress.ts → decision-egress.ts} +0 -0
  165. /package/src/pantheon/{v2-decision-events.ts → decision-events.ts} +0 -0
  166. /package/src/pantheon/{v2-decision-heuristic.ts → decision-heuristic.ts} +0 -0
  167. /package/src/pantheon/{v2-decision-premises.ts → decision-premises.ts} +0 -0
  168. /package/src/pantheon/{v2-decision-rank.ts → decision-rank.ts} +0 -0
  169. /package/src/pantheon/{v2-decision-verify.ts → decision-verify.ts} +0 -0
  170. /package/src/pantheon/{v2-delegation-enforce.ts → delegation-policy.ts} +0 -0
  171. /package/src/pantheon/{v2-model-overrides.ts → model-overrides.ts} +0 -0
  172. /package/src/pantheon/{v2-native-decisions.ts → native-decisions.ts} +0 -0
  173. /package/src/plugins/tui/src/{opencode-v2.d.ts → opencode.d.ts} +0 -0
@@ -0,0 +1,442 @@
1
+ // biome-ignore-all lint/suspicious/noExplicitAny: OpenCode exposes its TUI API at runtime.
2
+ // biome-ignore-all lint/a11y/noStaticElementInteractions: TUI elements, not DOM
3
+ /** @jsxImportSource @opentui/solid */
4
+
5
+ /**
6
+ * pantheon-settings.tsx — the /pantheon-settings window.
7
+ *
8
+ * One section per page, keyboard-first: `tab` cycles sections, `up`/`down`
9
+ * select, `enter`/`space` dispatches the selected row (the Gates section
10
+ * writes the GLOBAL overrides file — the same one the installer and doctor
11
+ * consume; Updates runs a registry check). `escape`/`q` closes. The
12
+ * gated-layer pattern mirrors the dispatch panel and whats-new windows.
13
+ * Every failure path is silent (fail-open).
14
+ */
15
+ import { mkdirSync, readFileSync, writeFileSync } from 'node:fs'
16
+ import { join } from 'node:path'
17
+ import type { Context } from '@opencode/plugin/tui/context'
18
+ import { createSignal, For, Show } from 'solid-js'
19
+ import {
20
+ buildDecisionSection,
21
+ readDecisionRouterConfig,
22
+ setDecisionEnabled,
23
+ writeDecisionRouterConfig,
24
+ } from './decision-router-state.ts'
25
+ import { buildDoctorSection } from './doctor-state.ts'
26
+ import { buildJ1Section } from './j1-gate-status.ts'
27
+ import {
28
+ buildAboutSection,
29
+ buildGatesSection,
30
+ canWriteOverrides,
31
+ type EffectiveOverrides,
32
+ firstSelectableId,
33
+ flatSelectableRows,
34
+ isBehaviorDisabled,
35
+ mergedOverrides,
36
+ type OverridesLoad,
37
+ type SettingsRow,
38
+ type SettingsSection,
39
+ serializeOverrides,
40
+ toggledOverrides,
41
+ } from './pantheon-settings-state.ts'
42
+ import {
43
+ buildPresetSection,
44
+ clearActivePreset,
45
+ globalActivePresetPath,
46
+ projectActivePresetPath,
47
+ readActivePresetMarker,
48
+ writeActivePreset,
49
+ } from './preset-state.ts'
50
+ import { nextCheckState, type UpdateCheckState } from './update-notice.ts'
51
+ import {
52
+ buildUpdatesSection,
53
+ registryUrlForChannel,
54
+ type UpdatesSectionInput,
55
+ updateChannelFor,
56
+ } from './update-status.ts'
57
+
58
+ function globalOverridesPath(): string {
59
+ const xdgConfig = process.env.XDG_CONFIG_HOME ?? join(process.env.HOME ?? '', '.config')
60
+ return join(xdgConfig, 'opencode', 'pantheon-overrides.json')
61
+ }
62
+
63
+ function projectOverridesPath(): string {
64
+ return join(process.cwd(), '.pantheon', 'overrides.json')
65
+ }
66
+
67
+ /** Read one overrides file; a missing file is empty, an unreadable one is corrupt. */
68
+ function readOneOverrides(path: string): { value: EffectiveOverrides; corrupt: boolean } {
69
+ try {
70
+ const parsed: unknown = JSON.parse(readFileSync(path, 'utf8'))
71
+ if (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed)) {
72
+ return { value: {}, corrupt: true }
73
+ }
74
+ return { value: parsed as EffectiveOverrides, corrupt: false }
75
+ } catch (error) {
76
+ return { value: {}, corrupt: (error as NodeJS.ErrnoException)?.code !== 'ENOENT' }
77
+ }
78
+ }
79
+
80
+ function readOverridesLoad(): OverridesLoad {
81
+ const globalRead = readOneOverrides(globalOverridesPath())
82
+ const projectRead = readOneOverrides(projectOverridesPath())
83
+ return {
84
+ global: globalRead.value,
85
+ project: projectRead.value,
86
+ corruptGlobal: globalRead.corrupt,
87
+ }
88
+ }
89
+
90
+ function writeOverridesToDisk(load: OverridesLoad): void {
91
+ writeFileSync(globalOverridesPath(), serializeOverrides(load.global), 'utf8')
92
+ }
93
+
94
+ function updateCheckStatePath(): string {
95
+ const stateDir = process.env.XDG_STATE_HOME ?? join(process.env.HOME ?? '', '.local', 'state')
96
+ return join(stateDir, 'pantheon', 'update-check.json')
97
+ }
98
+
99
+ function readUpdateCheckState(): UpdateCheckState {
100
+ try {
101
+ return JSON.parse(readFileSync(updateCheckStatePath(), 'utf8')) as UpdateCheckState
102
+ } catch {
103
+ return {}
104
+ }
105
+ }
106
+
107
+ /**
108
+ * Registry check for the RUNNING version's channel (beta installs ask the
109
+ * beta dist-tag). Resolves with the latest version seen, or null offline.
110
+ */
111
+ async function fetchLatestForChannel(currentVersion: string): Promise<string | null> {
112
+ try {
113
+ const response = await fetch(registryUrlForChannel(updateChannelFor(currentVersion)), {
114
+ signal: AbortSignal.timeout(5000),
115
+ })
116
+ const latest = String(((await response.json()) as { version?: unknown })?.version ?? '')
117
+ return latest || null
118
+ } catch {
119
+ return null
120
+ }
121
+ }
122
+
123
+ function persistUpdateCheckState(previous: UpdateCheckState, latest: string | null): void {
124
+ try {
125
+ const path = updateCheckStatePath()
126
+ mkdirSync(join(path, '..'), { recursive: true })
127
+ writeFileSync(
128
+ path,
129
+ `${JSON.stringify(nextCheckState(previous, latest ? { version: latest, message: '' } : null, Date.now()), null, 2)}\n`,
130
+ )
131
+ } catch {
132
+ /* state is a cache — never block on it */
133
+ }
134
+ }
135
+
136
+ function resolveRunningVersion(): string {
137
+ try {
138
+ const manifest = JSON.parse(
139
+ readFileSync(new URL('../../package.json', import.meta.url), 'utf8'),
140
+ ) as { version?: string }
141
+ return manifest.version ?? 'unknown'
142
+ } catch {
143
+ return 'unknown'
144
+ }
145
+ }
146
+
147
+ export function SettingsContent(props: {
148
+ sections: () => SettingsSection[]
149
+ page: () => number
150
+ selectedId: () => string | undefined
151
+ fg?: any
152
+ muted?: any
153
+ }) {
154
+ const section = () =>
155
+ props.sections()[props.page()] ?? {
156
+ id: 'empty',
157
+ title: '',
158
+ rows: [],
159
+ }
160
+ return (
161
+ <box flexDirection="column" paddingLeft={1} paddingRight={1} paddingTop={1}>
162
+ <text attributes={1} fg={props.fg}>
163
+ {section().title}
164
+ </text>
165
+ <text fg={props.muted}>{'─'.repeat(38)}</text>
166
+ <For each={section().rows}>
167
+ {(row: SettingsRow) => {
168
+ const isSelected = () => row.selectable !== false && row.id === props.selectedId()
169
+ const marker = () => row.marker ?? (row.disabled ? '[x]' : '[ ]')
170
+ return (
171
+ <box flexDirection="column">
172
+ <text
173
+ fg={isSelected() ? props.fg : props.muted}
174
+ {...(isSelected() ? { attributes: 1 } : {})}
175
+ >
176
+ {`${marker()} ${row.title}${isSelected() ? ' <-' : ''}`}
177
+ </text>
178
+ <Show when={row.description !== ''}>
179
+ <text fg={props.muted}>{` ${row.description}`}</text>
180
+ </Show>
181
+ </box>
182
+ )
183
+ }}
184
+ </For>
185
+ <box height={1} />
186
+ <Show when={section().hint !== undefined}>
187
+ <text fg={props.muted}>{section().hint}</text>
188
+ </Show>
189
+ <text fg={props.muted}>
190
+ {`${props.page() + 1}/${props.sections().length} · `}tab: section · up/down: select · enter:
191
+ apply · esc/q: close
192
+ </text>
193
+ </box>
194
+ )
195
+ }
196
+
197
+ /**
198
+ * Entry glue: read both overrides files, then show the window through the
199
+ * host dialog stack once. The gated keymap layer is inert while the window
200
+ * is closed. Never throws.
201
+ */
202
+ export async function maybeShowPantheonSettings(context: Context): Promise<void> {
203
+ try {
204
+ const [open, setOpen] = createSignal(false)
205
+ const [page, setPage] = createSignal(0)
206
+ const [load, setLoad] = createSignal<OverridesLoad>(readOverridesLoad())
207
+ const [lastChecked, setLastChecked] = createSignal<string | undefined>(undefined)
208
+ const [checking, setChecking] = createSignal(false)
209
+ const [decision, setDecision] = createSignal(readDecisionRouterConfig())
210
+ const [presetTick, setPresetTick] = createSignal(0)
211
+
212
+ const currentVersion = resolveRunningVersion()
213
+
214
+ const updatesInput = (): UpdatesSectionInput => {
215
+ const input: UpdatesSectionInput = {
216
+ currentVersion,
217
+ state: readUpdateCheckState(),
218
+ checking: checking(),
219
+ nowMs: Date.now(),
220
+ }
221
+ const seen = lastChecked()
222
+ if (seen !== undefined) input.lastCheckedVersion = seen
223
+ return input
224
+ }
225
+
226
+ const presetInput = () => {
227
+ void presetTick()
228
+ return {
229
+ globalName: readActivePresetMarker(globalActivePresetPath())?.name ?? null,
230
+ projectName: readActivePresetMarker(projectActivePresetPath())?.name ?? null,
231
+ }
232
+ }
233
+
234
+ const sections = (): SettingsSection[] => [
235
+ buildGatesSection(load()),
236
+ buildDecisionSection(decision()),
237
+ buildPresetSection(presetInput()),
238
+ buildJ1Section(process.env, isBehaviorDisabled(mergedOverrides(load()), 'gate-j1-risk-gate')),
239
+ buildUpdatesSection(updatesInput()),
240
+ buildDoctorSection({
241
+ runningVersion: currentVersion,
242
+ nodeVersion: process.versions.node,
243
+ load: load(),
244
+ }),
245
+ buildAboutSection(currentVersion),
246
+ ]
247
+ const [selectedId, setSelectedId] = createSignal<string | undefined>(
248
+ firstSelectableId(sections()),
249
+ )
250
+
251
+ const move = (delta: number) => {
252
+ const list = flatSelectableRows(sections())
253
+ if (list.length === 0) return
254
+ const current = list.findIndex((row) => row.id === selectedId())
255
+ const nextIndex = current === -1 ? 0 : Math.min(Math.max(current + delta, 0), list.length - 1)
256
+ setSelectedId(list[nextIndex]?.id)
257
+ }
258
+
259
+ const flipSection = () => {
260
+ const count = sections().length
261
+ const next = (page() + 1) % count
262
+ setPage(next)
263
+ const target = sections()[next]
264
+ if (target === undefined) return
265
+ const within = flatSelectableRows([target])[0]
266
+ if (within) setSelectedId(within.id)
267
+ }
268
+
269
+ const toggleSelectedGate = () => {
270
+ const id = selectedId()
271
+ if (id === undefined || !id.startsWith('gate.')) return false
272
+ if (!canWriteOverrides(load())) return undefined // corrupt file — writes refused
273
+ const behaviorId = id.slice('gate.'.length)
274
+ const next: OverridesLoad = {
275
+ ...load(),
276
+ global: toggledOverrides(load().global, behaviorId),
277
+ }
278
+ try {
279
+ writeOverridesToDisk(next)
280
+ setLoad(next)
281
+ } catch {
282
+ /* disk write failed — keep the in-memory state, stay open */
283
+ }
284
+ return undefined
285
+ }
286
+
287
+ const checkUpdatesNow = () => {
288
+ if (checking()) return undefined
289
+ setChecking(true)
290
+ void fetchLatestForChannel(currentVersion)
291
+ .then((latest) => {
292
+ if (latest) setLastChecked(latest)
293
+ persistUpdateCheckState(readUpdateCheckState(), latest)
294
+ })
295
+ .catch(() => {
296
+ /* offline — the row keeps the last known state */
297
+ })
298
+ .finally(() => setChecking(false))
299
+ return undefined
300
+ }
301
+
302
+ const toggleDecisionEnabled = () => {
303
+ const current = decision()
304
+ if (current.corrupt) return undefined // invalid file — writes refused
305
+ const next = setDecisionEnabled(current.config, !current.config.enabled)
306
+ if (!next.ok) return undefined // guard refused (egress consent missing)
307
+ try {
308
+ writeDecisionRouterConfig(next.config)
309
+ setDecision({ config: next.config, corrupt: false })
310
+ } catch {
311
+ /* disk write failed — keep the in-memory state */
312
+ }
313
+ return undefined
314
+ }
315
+
316
+ const applySelectedPreset = () => {
317
+ const id = selectedId()
318
+ if (id === undefined) return undefined
319
+ const name = id.startsWith('preset.') ? id.slice('preset.'.length) : null
320
+ if (name === null || name === 'project') return undefined
321
+ const path = globalActivePresetPath()
322
+ try {
323
+ if (name === 'none') clearActivePreset(path)
324
+ else writeActivePreset(path, name)
325
+ setPresetTick((tick) => tick + 1)
326
+ } catch {
327
+ /* disk write failed — the section keeps showing the last read state */
328
+ }
329
+ return undefined
330
+ }
331
+
332
+ let dismiss: () => void = () => {}
333
+ try {
334
+ context.keymap.layer(() => ({
335
+ mode: 'global',
336
+ enabled: () => open(),
337
+ commands: [
338
+ {
339
+ id: 'pantheon.settings.close',
340
+ title: 'Close settings',
341
+ bind: 'escape,q',
342
+ run: () => {
343
+ if (!open()) return false
344
+ dismiss()
345
+ return undefined
346
+ },
347
+ },
348
+ {
349
+ id: 'pantheon.settings.down',
350
+ title: 'Select next',
351
+ bind: 'down,j',
352
+ run: () => {
353
+ if (!open()) return false
354
+ move(1)
355
+ return undefined
356
+ },
357
+ },
358
+ {
359
+ id: 'pantheon.settings.up',
360
+ title: 'Select previous',
361
+ bind: 'up,k',
362
+ run: () => {
363
+ if (!open()) return false
364
+ move(-1)
365
+ return undefined
366
+ },
367
+ },
368
+ {
369
+ id: 'pantheon.settings.toggle',
370
+ title: 'Apply the selected row',
371
+ bind: 'enter,space',
372
+ run: () => {
373
+ if (!open()) return false
374
+ const id = selectedId()
375
+ if (id?.startsWith('gate.')) return toggleSelectedGate()
376
+ if (id === 'decision.enabled') return toggleDecisionEnabled()
377
+ if (id?.startsWith('preset.')) return applySelectedPreset()
378
+ if (id === 'update.check') return checkUpdatesNow()
379
+ return undefined
380
+ },
381
+ },
382
+ {
383
+ id: 'pantheon.settings.section',
384
+ title: 'Next section',
385
+ bind: 'tab',
386
+ run: () => {
387
+ if (!open()) return false
388
+ flipSection()
389
+ return undefined
390
+ },
391
+ },
392
+ ],
393
+ }))
394
+ } catch {
395
+ /* keymap API unavailable — the host dialog chrome still dismisses (ESC) */
396
+ }
397
+
398
+ // The host may dismiss the dialog on its own and call this callback from
399
+ // inside its dismissal; mutating the dialog stack there re-enters the host
400
+ // mid-close and the swallowed failure leaves the window unclosable (the
401
+ // whats-new split: clear() lives only in dismiss, never in close).
402
+ const close = () => {
403
+ setOpen(false)
404
+ }
405
+ dismiss = () => {
406
+ try {
407
+ context.ui.dialog.clear()
408
+ } catch {
409
+ /* already closed */
410
+ }
411
+ close()
412
+ }
413
+ setOpen(true)
414
+ setPage(0)
415
+ try {
416
+ const theme = context.theme?.text ?? {}
417
+ context.ui.dialog.show(
418
+ () => (
419
+ <SettingsContent
420
+ sections={sections}
421
+ page={page}
422
+ selectedId={selectedId}
423
+ fg={theme.base}
424
+ muted={theme.muted}
425
+ />
426
+ ),
427
+ close,
428
+ )
429
+ // Roomier chrome for the sectioned window; older hosts without `set`
430
+ // keep the default size (fail-open).
431
+ try {
432
+ context.ui.dialog.set?.({ size: 'xlarge' })
433
+ } catch {
434
+ /* size control unavailable */
435
+ }
436
+ } catch {
437
+ /* dialog stack unavailable — fail-open */
438
+ }
439
+ } catch {
440
+ /* fail-open — the window must never block or break TUI startup */
441
+ }
442
+ }
@@ -0,0 +1,143 @@
1
+ /**
2
+ * preset-state.ts — the Model Preset section of the settings window.
3
+ *
4
+ * TUI-local replica (the bundle must stay self-contained). The preset NAMES
5
+ * mirror routing.yml's `presets:` and are drift-pinned by
6
+ * tests/tui-preset-state.test.mjs against `loadPresetDefs()`. The marker file
7
+ * shape mirrors scripts/install/model-picker.mjs's `buildActivePresetFile`
8
+ * (version 1), and the readers (`resolveActivePreset`, vision.ts candidates)
9
+ * only consult `.preset`, so the window writes `source: 'tui-settings'`.
10
+ *
11
+ * Scope note: the window writes the GLOBAL marker only
12
+ * (`<config-dir>/opencode/.pantheon/active-preset.json`). A project marker
13
+ * wins (it precedes the global path in every runtime candidate list), so it
14
+ * is displayed read-only. `none` DELETES the marker with a .bak backup — the
15
+ * same contract as the CLI's `set-tier none`.
16
+ */
17
+ import {
18
+ copyFileSync,
19
+ existsSync,
20
+ mkdirSync,
21
+ readFileSync,
22
+ renameSync,
23
+ rmSync,
24
+ writeFileSync,
25
+ } from 'node:fs'
26
+ import { dirname, join } from 'node:path'
27
+ import type { SettingsRow, SettingsSection } from './pantheon-settings-state.ts'
28
+
29
+ /** Mirrors routing.yml `presets:` — drift-pinned against loadPresetDefs(). */
30
+ export const PRESET_NAMES: readonly string[] = Object.freeze([
31
+ 'go-free',
32
+ 'go-fast',
33
+ 'go-premium',
34
+ 'go-hybrid',
35
+ 'anthropic',
36
+ 'openai',
37
+ ])
38
+
39
+ export interface ActivePresetMarker {
40
+ version: number
41
+ preset: string
42
+ source: string
43
+ updated_at: string
44
+ }
45
+
46
+ export function globalActivePresetPath(env: Record<string, string | undefined> = process.env) {
47
+ const xdg = env.XDG_CONFIG_HOME
48
+ const home = env.HOME ?? ''
49
+ const root = xdg ?? join(home, '.config')
50
+ return join(root, 'opencode', '.pantheon', 'active-preset.json')
51
+ }
52
+
53
+ export function projectActivePresetPath() {
54
+ return join(process.cwd(), '.pantheon', 'active-preset.json')
55
+ }
56
+
57
+ /** Fail-open read: missing/corrupt marker = no active preset. */
58
+ export function readActivePresetMarker(path: string): { name: string; updatedAt: string } | null {
59
+ try {
60
+ const raw = JSON.parse(readFileSync(path, 'utf8')) as { preset?: unknown; updated_at?: unknown }
61
+ if (typeof raw?.preset !== 'string' || raw.preset === '' || raw.preset === 'none') return null
62
+ return {
63
+ name: raw.preset,
64
+ updatedAt: typeof raw.updated_at === 'string' ? raw.updated_at : '',
65
+ }
66
+ } catch {
67
+ return null
68
+ }
69
+ }
70
+
71
+ function writeMarkerAtomically(path: string, content: string): void {
72
+ mkdirSync(dirname(path), { recursive: true })
73
+ const temp = `${path}.tui.tmp`
74
+ writeFileSync(temp, content)
75
+ renameSync(temp, path)
76
+ }
77
+
78
+ /** Select a preset globally: .bak backup, atomic write, version-1 marker. */
79
+ export function writeActivePreset(
80
+ path: string,
81
+ name: string,
82
+ nowIso = new Date().toISOString(),
83
+ ): void {
84
+ if (!PRESET_NAMES.includes(name)) {
85
+ throw new TypeError(`Refusing to persist unknown preset "${name}"`)
86
+ }
87
+ backupMarker(path)
88
+ const marker: ActivePresetMarker = {
89
+ version: 1,
90
+ preset: name,
91
+ source: 'tui-settings',
92
+ updated_at: nowIso,
93
+ }
94
+ writeMarkerAtomically(path, `${JSON.stringify(marker, null, 2)}\n`)
95
+ }
96
+
97
+ /** Clear the global marker (the `none` contract): .bak backup, then remove. */
98
+ export function clearActivePreset(path: string): void {
99
+ backupMarker(path)
100
+ rmSync(path, { force: true })
101
+ }
102
+
103
+ function backupMarker(path: string): void {
104
+ if (!existsSync(path)) return
105
+ mkdirSync(dirname(path), { recursive: true })
106
+ copyFileSync(path, `${path}.bak`)
107
+ }
108
+
109
+ export interface PresetSectionInput {
110
+ globalName: string | null
111
+ projectName: string | null
112
+ }
113
+
114
+ export function buildPresetSection(input: PresetSectionInput): SettingsSection {
115
+ const rows: SettingsRow[] = PRESET_NAMES.map((name) => ({
116
+ id: `preset.${name}`,
117
+ title: name,
118
+ description: input.globalName === name ? 'active (global)' : 'enter: activate globally',
119
+ disabled: input.globalName === name,
120
+ }))
121
+ rows.push({
122
+ id: 'preset.none',
123
+ title: 'none',
124
+ description: 'clear the global marker — opencode defaults',
125
+ disabled: input.globalName === null,
126
+ marker: input.globalName === null ? '[x]' : '[ ]',
127
+ })
128
+ if (input.projectName !== null) {
129
+ rows.push({
130
+ id: 'preset.project',
131
+ title: `${input.projectName} (project)`,
132
+ description: `${projectActivePresetPath()} wins over the global marker`,
133
+ marker: '[!]',
134
+ selectable: false,
135
+ })
136
+ }
137
+ return {
138
+ id: 'preset',
139
+ title: 'Model Preset',
140
+ rows,
141
+ hint: 'enter: activate globally · writes <config>/opencode/.pantheon/active-preset.json',
142
+ }
143
+ }
@@ -1,15 +1,28 @@
1
1
  /**
2
- * No-op server stub for the opencode plugin loader.
2
+ * No-op server stub for the OpenCode V2 plugin loader.
3
3
  *
4
- * The opencode plugin host requires every plugin (TUI included) to expose a
5
- * `server()` entry via `exports["./server"]` (or package.json `main`). When
6
- * that entry is missing the host fails to attach the plugin's server half and
7
- * the TUI runtime never wires the reactive channel — the initial JSX mounts
8
- * but effects/refresh/events stay dead (the "mudo panel" symptom).
4
+ * The OpenCode plugin host requires every plugin (TUI included) to expose a
5
+ * `server()` entry via `exports["./server"]` (or package.json `main`) — for the
6
+ * V2 copy this root `index-v2.ts` re-export resolves to this compiled entry —
7
+ * and it loads that server half only from a `config.plugins` entry (see
8
+ * `scripts/install/opencode.mjs`). When the entry is missing the host fails to
9
+ * attach the plugin's server half and the TUI runtime never wires the reactive
10
+ * channel — the initial JSX mounts but effects/refresh/events stay dead (the
11
+ * "mudo panel" symptom; same contract as the V1 `server.ts` stub).
9
12
  *
10
- * This stub satisfies the loader contract; pantheon-tui is TUI-only and has
11
- * no background server work of its own.
13
+ * This stub satisfies the loader contract. Field report (beta.13): host 2.2.5
14
+ * validates the default export as a DEFINITION OBJECT — "Plugin must export a
15
+ * default definition with an id and an effect or setup function
16
+ * (SchemaError(Expected object at ["default"]))" — the bare `server()`
17
+ * function form failed that schema on every boot (~3.4k load failures in the
18
+ * host log). The native quota RPC that used to live here was removed in 1.6.2
19
+ * — provider quota/usage visibility is now the community plugin's job
20
+ * (`@slkiser/opencode-quota`, docs/tui-quota-providers.md) — and
21
+ * pantheon-tui has no other background server work of its own.
12
22
  */
13
- export default function server() {
14
- return {}
23
+ export default {
24
+ id: 'pantheon.tui.server',
25
+ setup() {
26
+ return {}
27
+ },
15
28
  }