pantheon-opencode 2.0.0-beta.5 → 2.0.0-rc.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 (63) hide show
  1. package/AGENTS.global.md +6 -1
  2. package/AGENTS.md +1 -1
  3. package/CHANGELOG.md +67 -0
  4. package/README.md +169 -510
  5. package/README.pt-BR.md +177 -149
  6. package/bin/pantheon-init.mjs +1 -1
  7. package/commands/pantheon-deepwork.md +6 -1
  8. package/commands/pantheon.md +10 -5
  9. package/package.json +1 -1
  10. package/plugin.json +2 -2
  11. package/prompts/orchestrate-with-zeus.prompt.md +82 -290
  12. package/prompts/subtask.prompt.md +1 -1
  13. package/pyproject.toml +1 -1
  14. package/scripts/doctor.mjs +27 -11
  15. package/scripts/hooks/format-multi-language.sh +30 -48
  16. package/scripts/install/opencode.mjs +13 -1
  17. package/scripts/jev-live-probe.mjs +1 -1
  18. package/scripts/release-gates.mjs +19 -5
  19. package/scripts/skill-search.mjs +66 -7
  20. package/scripts/test-opencode-sandbox.sh +44 -15
  21. package/scripts/update.mjs +9 -2
  22. package/skills-lock.json +5 -3
  23. package/src/agents/aphrodite.md +2 -0
  24. package/src/agents/apollo.md +8 -206
  25. package/src/agents/athena.md +25 -29
  26. package/src/agents/hermes.md +3 -1
  27. package/src/agents/mnemosyne.md +1 -1
  28. package/src/agents/nyx.md +1 -1
  29. package/src/agents/prometheus.md +0 -203
  30. package/src/agents/talos.md +2 -0
  31. package/src/agents/themis.md +8 -3
  32. package/src/agents/zeus.md +18 -12
  33. package/src/instructions/memory-protocol.instructions.md +4 -0
  34. package/src/instructions/test-economy.instructions.md +1 -0
  35. package/src/instructions/zeus-council-synthesis.instructions.md +13 -1
  36. package/src/pantheon/goal-loop-config.ts +55 -0
  37. package/src/pantheon/native-vision.ts +9 -5
  38. package/src/pantheon/pantheon-decision-catalog.ts +8 -0
  39. package/src/pantheon/skill-search-tool.ts +193 -0
  40. package/src/pantheon/tools.ts +2 -0
  41. package/src/pantheon/vision.ts +14 -1
  42. package/src/plugin.ts +39 -7
  43. package/src/plugins/tui/dist/tui.d.ts +12 -2
  44. package/src/plugins/tui/dist/tui.d.ts.map +1 -1
  45. package/src/plugins/tui/dist/tui.js +1399 -365
  46. package/src/plugins/tui/dist/tui.js.map +1 -1
  47. package/src/plugins/tui/package-lock.json +2 -2
  48. package/src/plugins/tui/package.json +1 -1
  49. package/src/plugins/tui/src/autonomy-state.ts +149 -0
  50. package/src/plugins/tui/src/context-gauge.ts +64 -5
  51. package/src/plugins/tui/src/decision-router-state.ts +175 -6
  52. package/src/plugins/tui/src/index.tsx +25 -3
  53. package/src/plugins/tui/src/pantheon-settings-state.ts +99 -0
  54. package/src/plugins/tui/src/pantheon-settings.tsx +647 -103
  55. package/src/plugins/tui/src/tui-prefs.ts +161 -9
  56. package/src/plugins/tui/src/update-status.ts +27 -8
  57. package/src/routing.yml +9 -0
  58. package/src/skills/README.md +35 -25
  59. package/src/skills/fast-path-execution/SKILL.md +54 -0
  60. package/src/skills/prompt-refinery/SKILL.md +53 -37
  61. package/src/skills/tdd-with-agents/SKILL.md +22 -10
  62. package/src/skills/test-slicing/SKILL.md +56 -0
  63. package/src/skills/verification-planning/SKILL.md +4 -3
@@ -11,6 +11,38 @@ import { fileURLToPath } from "node:url";
11
11
  const CONTEXT_BAR_CELLS = 12;
12
12
  const CONTEXT_BAR_FILLED_CELL = "▰";
13
13
  const CONTEXT_BAR_EMPTY_CELL = "▱";
14
+ const BAR_SHAPES = {
15
+ block: {
16
+ filled: "▰",
17
+ empty: "▱",
18
+ mark: "│"
19
+ },
20
+ line: {
21
+ filled: "━",
22
+ empty: "─",
23
+ mark: "┼"
24
+ },
25
+ smooth: {
26
+ filled: "█",
27
+ empty: "░",
28
+ mark: "┆"
29
+ },
30
+ ascii: {
31
+ filled: "=",
32
+ empty: "-",
33
+ mark: "|"
34
+ },
35
+ dots: {
36
+ filled: "●",
37
+ empty: "○",
38
+ mark: "│"
39
+ },
40
+ braille: {
41
+ filled: "⣿",
42
+ empty: "⣀",
43
+ mark: "⡇"
44
+ }
45
+ };
14
46
  function numberOrNull$1(value) {
15
47
  return typeof value === "number" && Number.isFinite(value) ? value : null;
16
48
  }
@@ -38,14 +70,34 @@ function contextBarFilled(percent, cells = 12) {
38
70
  if (!Number.isFinite(filled)) return 0;
39
71
  return Math.min(total, Math.max(0, filled));
40
72
  }
41
- function contextBar(percent, cells = 12) {
73
+ function contextBar(percent, options = 12) {
42
74
  const value = numberOrNull$1(percent);
43
75
  if (value === null) return null;
44
- const total = Math.max(1, Math.floor(cells));
45
- const filled = contextBarFilled(value, total);
76
+ const total = Math.max(1, Math.floor(typeof options === "number" ? options : options?.cells ?? 12));
77
+ const shapeKey = typeof options === "object" && options?.shape && options.shape in BAR_SHAPES ? options.shape : "block";
78
+ const glyphs = BAR_SHAPES[shapeKey] ?? BAR_SHAPES.block;
79
+ const evenMark = typeof options === "object" ? Boolean(options?.evenMark) : false;
80
+ const filledCount = contextBarFilled(value, total);
81
+ const emptyCount = total - filledCount;
82
+ if (!evenMark || total < 4) return {
83
+ filled: glyphs.filled.repeat(filledCount),
84
+ empty: glyphs.empty.repeat(emptyCount)
85
+ };
86
+ const mid = Math.floor(total / 2);
87
+ const mark = glyphs.mark ?? "|";
88
+ if (filledCount <= mid) {
89
+ const emptyBefore = mid - filledCount;
90
+ const emptyAfter = Math.max(0, emptyCount - emptyBefore - 1);
91
+ return {
92
+ filled: glyphs.filled.repeat(filledCount),
93
+ empty: `${glyphs.empty.repeat(emptyBefore)}${mark}${glyphs.empty.repeat(emptyAfter)}`
94
+ };
95
+ }
96
+ const filledBefore = mid;
97
+ const filledAfter = Math.max(0, filledCount - filledBefore - 1);
46
98
  return {
47
- filled: "▰".repeat(filled),
48
- empty: "▱".repeat(total - filled)
99
+ filled: `${glyphs.filled.repeat(filledBefore)}${mark}${glyphs.filled.repeat(filledAfter)}`,
100
+ empty: glyphs.empty.repeat(emptyCount)
49
101
  };
50
102
  }
51
103
  function formatSpent(cost) {
@@ -60,6 +112,117 @@ const MODEL_USAGE_VISIBLE_CEILING = 3;
60
112
  const MODEL_USAGE_MESSAGE_LIMIT = 400;
61
113
  const MODEL_USAGE_SESSION_LIMIT = 8;
62
114
  //#endregion
115
+ //#region src/autonomy-state.ts
116
+ const DEFAULT_GOAL_LOOP_PREFS = {
117
+ enabled: false,
118
+ cooldownMs: 5e3,
119
+ maxContinuations: 25
120
+ };
121
+ const GOAL_LOOP_ENABLED_CYCLE = Object.freeze(["enabled", "disabled"]);
122
+ const DEFAULT_DECISION_BUDGETS = {
123
+ monthlyUsd: 5,
124
+ perDecisionUsd: .1
125
+ };
126
+ /** Format USD compactly for a cycler cell ("$5", "$0.10"). */
127
+ function formatUsd(value) {
128
+ return `$${value < 1 ? value.toFixed(2) : String(Math.round(value))}`;
129
+ }
130
+ /** Build the USD step ladder used by the budget cyclers. */
131
+ const MONTHLY_USD_CYCLE = Object.freeze([
132
+ 1,
133
+ 2,
134
+ 5,
135
+ 10,
136
+ 20,
137
+ 50,
138
+ 100
139
+ ].map((value) => formatUsd(value)));
140
+ const PER_DECISION_USD_CYCLE = Object.freeze([
141
+ .01,
142
+ .025,
143
+ .05,
144
+ .1,
145
+ .25,
146
+ .5,
147
+ 1
148
+ ].map((value) => formatUsd(value)));
149
+ /** Parse a staged USD cell back to a number; junk keeps the input. */
150
+ function parseUsd(cell) {
151
+ const value = Number(cell.replace("$", ""));
152
+ return Number.isFinite(value) && value > 0 ? value : null;
153
+ }
154
+ function buildAutonomyTab(input) {
155
+ return {
156
+ id: "autonomy",
157
+ title: "Autonomy",
158
+ groups: [
159
+ {
160
+ title: "Goal loop (persisted mission, long sessions)",
161
+ rows: [
162
+ {
163
+ id: "autonomy.goal_loop.enabled",
164
+ name: "Goal loop",
165
+ value: input.goalLoop.enabled ? "enabled" : "disabled",
166
+ cycle: GOAL_LOOP_ENABLED_CYCLE,
167
+ note: "mission persists in .pantheon/goals; auto-continues with cooldown" + (input.goalLoopRestartPending ? " · ⚠ saved value applies after OpenCode restart" : " · applies after OpenCode restart")
168
+ },
169
+ {
170
+ id: "autonomy.goal_loop.maxContinuations",
171
+ name: "Max continuations",
172
+ value: String(input.goalLoop.maxContinuations),
173
+ note: "1..200 — the anti-runaway cap per mission"
174
+ },
175
+ {
176
+ id: "autonomy.goal_loop.cooldownMs",
177
+ name: "Cooldown (ms)",
178
+ value: String(input.goalLoop.cooldownMs),
179
+ note: "min 1000ms · between continuations"
180
+ }
181
+ ]
182
+ },
183
+ {
184
+ title: "Decision budgets (applies live)",
185
+ rows: [{
186
+ id: "autonomy.budget.monthly",
187
+ name: "Monthly cap",
188
+ value: formatUsd(input.budgets.monthlyUsd),
189
+ cycle: MONTHLY_USD_CYCLE,
190
+ note: "the ledger refuses gated calls past this"
191
+ }, {
192
+ id: "autonomy.budget.perDecision",
193
+ name: "Per-decision cap",
194
+ value: formatUsd(input.budgets.perDecisionUsd),
195
+ cycle: PER_DECISION_USD_CYCLE,
196
+ note: "each gated call above this is refused"
197
+ }]
198
+ },
199
+ {
200
+ title: "Decision gradient (documented — J1 owns the risk axis)",
201
+ rows: [
202
+ {
203
+ id: "autonomy.gradient.solo",
204
+ name: "Decide solo",
205
+ value: "reversible + low risk",
206
+ note: "edits, routine fixes, ordering ties — no gate"
207
+ },
208
+ {
209
+ id: "autonomy.gradient.jev",
210
+ name: "Jev decides",
211
+ value: "typed ambiguity",
212
+ note: "readings, ranking, verification — budget-capped"
213
+ },
214
+ {
215
+ id: "autonomy.gradient.human",
216
+ name: "Human decides",
217
+ value: "high risk (J1)",
218
+ note: "enforce ladder via PANTHEON_J1_* (J1 tab)"
219
+ }
220
+ ]
221
+ }
222
+ ]
223
+ };
224
+ }
225
+ //#endregion
63
226
  //#region src/decision-router-state.ts
64
227
  /**
65
228
  * decision-router-state.ts — the Decision Model section of the settings window.
@@ -93,7 +256,8 @@ const DEFAULT_DECISION_CONFIG = Object.freeze({
93
256
  egress_consent: false,
94
257
  enabled_candidates: Object.freeze([])
95
258
  });
96
- Object.freeze([
259
+ /** The runtime's provider→model matrix (drift-pinned against the installer source). */
260
+ const DECISION_KNOWN_PROVIDERS = Object.freeze([
97
261
  "openai-decisions",
98
262
  "typesafe-jev",
99
263
  "opencode-console-jev",
@@ -101,6 +265,42 @@ Object.freeze([
101
265
  "vercel-gateway-jev",
102
266
  "cloudflare-workers-jev"
103
267
  ]);
268
+ const DECISION_CONSENT_CYCLE = Object.freeze(["not granted", "granted"]);
269
+ /** provider → model, straight from the runtime matrix (drift-pinned in tests). */
270
+ const DECISION_KNOWN_MODELS = Object.freeze({
271
+ "openai-decisions": "gpt-6-luna",
272
+ "typesafe-jev": "jev-1.14.0",
273
+ "opencode-console-jev": "jev-1.13",
274
+ "openrouter-jev": "typesafe/jev-1.13",
275
+ "vercel-gateway-jev": "typesafe-ai/jev",
276
+ "cloudflare-workers-jev": "clef"
277
+ });
278
+ /**
279
+ * Credential surface per provider: the ENV VAR the host provider entry reads
280
+ * (`{env:VAR}` indirection — the window NEVER holds key values) plus the setup
281
+ * note. Drift-pinned against the installer/runtime sources in tests.
282
+ */
283
+ const DECISION_PROVIDER_CREDENTIALS = Object.freeze({
284
+ "openai-decisions": { note: "host-configured model — provision via `decision-router setup-model openai-decisions`" },
285
+ "typesafe-jev": {
286
+ env: "TYPESAFE_API_KEY",
287
+ note: "export TYPESAFE_API_KEY=… then restart"
288
+ },
289
+ "opencode-console-jev": { note: "rides your OpenCode login — no separate key" },
290
+ "openrouter-jev": {
291
+ env: "OPENROUTER_API_KEY",
292
+ note: "export OPENROUTER_API_KEY=… then restart"
293
+ },
294
+ "vercel-gateway-jev": {
295
+ env: "AI_GATEWAY_API_KEY",
296
+ note: "export AI_GATEWAY_API_KEY=… then restart"
297
+ },
298
+ "cloudflare-workers-jev": {
299
+ env: "CLOUDFLARE_API_TOKEN",
300
+ note: "needs accountId (setup-model --account-id=…) + CLOUDFLARE_API_TOKEN"
301
+ }
302
+ });
303
+ const DECISION_TARGET_CYCLE = Object.freeze(DECISION_KNOWN_PROVIDERS.map((provider) => `${provider}/${DECISION_KNOWN_MODELS[provider]}`));
104
304
  function decisionRouterConfigPath(env = process.env) {
105
305
  const xdg = env.XDG_CONFIG_HOME;
106
306
  const home = env.HOME ?? "";
@@ -198,7 +398,7 @@ function setDecisionEnabled(config, enabled) {
198
398
  if (enabled) {
199
399
  if (!(config.selection.mode === "local" || config.enabled_candidates.length === 0) && !config.egress_consent) return {
200
400
  ok: false,
201
- reason: "remote candidates need egress consent — grant via `decision-router setup-model`"
401
+ reason: "remote candidates need egress consent — toggle Egress consent in this tab, then enable"
202
402
  };
203
403
  }
204
404
  return {
@@ -222,7 +422,75 @@ function writeDecisionRouterConfig(config, env = process.env) {
222
422
  renameSync(temp, path);
223
423
  chmodSync(path, 384);
224
424
  }
225
- function buildDecisionTab(read) {
425
+ const DECISION_SELECTION_CYCLE = Object.freeze([
426
+ "local",
427
+ "auto",
428
+ "explicit"
429
+ ]);
430
+ /** Stage a selection/consent row into a config copy; unknown rows are no-ops. */
431
+ function applyDecisionRow(config, id, value) {
432
+ const next = {
433
+ ...config,
434
+ selection: { ...config.selection },
435
+ enabled_candidates: [...config.enabled_candidates]
436
+ };
437
+ switch (id) {
438
+ case "decision.selection.mode": {
439
+ const mode = value;
440
+ if (mode !== "local" && mode !== "auto" && mode !== "explicit") return config;
441
+ next.selection.mode = mode;
442
+ if (mode === "local") next.enabled_candidates = [];
443
+ return next;
444
+ }
445
+ case "decision.selection.target": {
446
+ const separator = value.indexOf("/");
447
+ if (separator <= 0) return config;
448
+ const provider = value.slice(0, separator);
449
+ const model = value.slice(separator + 1);
450
+ if (!DECISION_KNOWN_PROVIDERS.includes(provider)) return config;
451
+ if (DECISION_KNOWN_MODELS[provider] !== model) return config;
452
+ next.selection = {
453
+ mode: "explicit",
454
+ provider,
455
+ model
456
+ };
457
+ next.enabled_candidates = [{
458
+ provider,
459
+ model
460
+ }];
461
+ return next;
462
+ }
463
+ case "decision.consent":
464
+ next.egress_consent = value === "granted";
465
+ return next;
466
+ default: return config;
467
+ }
468
+ }
469
+ /** Provider ids as they appear in the host auth store / config providers. */
470
+ const PROVIDER_AUTH_NAMES = Object.freeze({
471
+ "openai-decisions": Object.freeze(["openai"]),
472
+ "typesafe-jev": Object.freeze(["typesafe-ai"]),
473
+ "opencode-console-jev": Object.freeze([]),
474
+ "openrouter-jev": Object.freeze(["openrouter"]),
475
+ "vercel-gateway-jev": Object.freeze(["vercel-ai-gateway", "vercel"]),
476
+ "cloudflare-workers-jev": Object.freeze(["cloudflare-workers-ai"])
477
+ });
478
+ /**
479
+ * TWO recognition forms (field feedback beta.6: keys registered via
480
+ * `opencode auth login` showed MISSING because only env vars were checked):
481
+ * env var set → 'env'; provider present in the host auth store → 'auth
482
+ * store'; provider entry in opencode.json providers → 'config'. Values are
483
+ * NEVER read — existence only.
484
+ */
485
+ function credentialStatus(provider, env, authProviders, configProviders) {
486
+ const credential = DECISION_PROVIDER_CREDENTIALS[provider];
487
+ if (credential?.env !== void 0 && env[credential.env]) return "env";
488
+ for (const name of PROVIDER_AUTH_NAMES[provider] ?? []) if (authProviders.has(name)) return "auth store";
489
+ for (const name of PROVIDER_AUTH_NAMES[provider] ?? []) if (configProviders.has(name)) return "config";
490
+ if (provider === "opencode-console-jev") return "auth store";
491
+ return "missing";
492
+ }
493
+ function buildDecisionTab(read, env = process.env, authProviders = /* @__PURE__ */ new Set(), configProviders = /* @__PURE__ */ new Set()) {
226
494
  const { config, corrupt } = read;
227
495
  const rows = [{
228
496
  id: "decision.enabled",
@@ -231,23 +499,50 @@ function buildDecisionTab(read) {
231
499
  ...corrupt ? {} : { cycle: DECISION_ENABLED_CYCLE },
232
500
  note: corrupt ? "config unreadable/invalid — runtime fail-closes; repair via `decision-router setup-model`" : "applies live — the runtime re-reads this on every gated call"
233
501
  }, {
234
- id: "decision.selection",
235
- name: "Selection",
236
- value: `${config.selection.mode}${config.selection.provider ? ` · ${config.selection.provider}` : ""}`,
502
+ id: "decision.selection.mode",
503
+ name: "Selection mode",
504
+ value: config.selection.mode,
505
+ ...corrupt ? {} : { cycle: DECISION_SELECTION_CYCLE },
237
506
  note: "local routes on-device; auto/explicit pick a remote decision model"
238
507
  }];
508
+ if (config.selection.mode === "explicit" || config.selection.provider !== void 0) rows.push({
509
+ id: "decision.selection.target",
510
+ name: "Explicit target",
511
+ value: config.selection.provider ? `${config.selection.provider}/${config.selection.model ?? ""}` : "none",
512
+ ...corrupt || config.selection.mode !== "explicit" ? {} : { cycle: DECISION_TARGET_CYCLE },
513
+ note: "provider/model — sets the candidate list"
514
+ });
239
515
  if (config.enabled_candidates.length > 0) rows.push({
240
516
  id: "decision.candidates",
241
517
  name: "Candidates",
242
518
  value: String(config.enabled_candidates.length),
243
519
  note: config.egress_consent ? config.enabled_candidates.map((candidate) => `${candidate.provider}/${candidate.model}`).join(", ") : "egress consent NOT granted — remote routes fail closed"
244
520
  });
521
+ rows.push({
522
+ id: "decision.consent",
523
+ name: "Egress consent",
524
+ value: config.egress_consent ? "granted" : "not granted",
525
+ ...corrupt ? {} : { cycle: DECISION_CONSENT_CYCLE },
526
+ note: "granted = remote decision routes may call their gateway (budget-capped)"
527
+ });
245
528
  return {
246
529
  id: "decision",
247
530
  title: "Decision",
248
531
  groups: [{
249
532
  title: "Decision router",
250
533
  rows
534
+ }, {
535
+ title: "Credentials (status only — values never enter the window)",
536
+ rows: DECISION_KNOWN_PROVIDERS.map((provider) => {
537
+ const status = credentialStatus(provider, env, authProviders, configProviders);
538
+ const credential = DECISION_PROVIDER_CREDENTIALS[provider] ?? { note: "" };
539
+ return {
540
+ id: `decision.key.${provider}`,
541
+ name: provider,
542
+ value: status === "missing" ? "MISSING" : status,
543
+ note: credential.note
544
+ };
545
+ })
251
546
  }]
252
547
  };
253
548
  }
@@ -383,6 +678,45 @@ function stageValue(draft, row, direction) {
383
678
  [row.id]: staged
384
679
  };
385
680
  }
681
+ /** Stage an explicit target value for one row (the Defaults action path). */
682
+ function stageRowToValue(draft, row, target) {
683
+ if (!row.cycle?.includes(target)) return draft;
684
+ if (target === row.value) {
685
+ if (draft[row.id] === void 0) return draft;
686
+ const next = { ...draft };
687
+ delete next[row.id];
688
+ return next;
689
+ }
690
+ return {
691
+ ...draft,
692
+ [row.id]: target
693
+ };
694
+ }
695
+ /**
696
+ * Stage every cyclable row's DEFAULT value of a tab. Rows already at their
697
+ * default have their staged entry dropped; rows staged elsewhere keep it
698
+ * until the Defaults action targets them.
699
+ */
700
+ function stageDefaults(draft, tab) {
701
+ let next = draft;
702
+ for (const row of tabRows(tab)) {
703
+ if (row.cycle === void 0 || row.def === void 0) continue;
704
+ const candidate = next[row.id] ?? row.value;
705
+ if (candidate === row.def) {
706
+ if (next[row.id] !== void 0) {
707
+ const copy = { ...next };
708
+ delete copy[row.id];
709
+ next = copy;
710
+ }
711
+ continue;
712
+ }
713
+ next = stageRowToValue(next, {
714
+ ...row,
715
+ value: candidate
716
+ }, row.def);
717
+ }
718
+ return next;
719
+ }
386
720
  /** Drop every staged entry of one tab (ctrl+r). */
387
721
  function resetTab(draft, tab) {
388
722
  const ids = new Set(tabRows(tab).map((row) => row.id));
@@ -467,6 +801,44 @@ function buildAboutTab(version) {
467
801
  }] }]
468
802
  };
469
803
  }
804
+ function buildChangelogTab(version, items = []) {
805
+ const rows = [];
806
+ if (items.length > 0) items.forEach((item, index) => {
807
+ rows.push({
808
+ id: `changelog.item.${index + 1}`,
809
+ name: item.title.slice(0, 26),
810
+ value: item.detail.length > 20 ? `${item.detail.slice(0, 19)}…` : item.detail,
811
+ note: item.detail
812
+ });
813
+ });
814
+ else rows.push({
815
+ id: "changelog.info",
816
+ name: "Release",
817
+ value: `v${version}`,
818
+ note: "view full history in CHANGELOG.md or GitHub releases"
819
+ });
820
+ return {
821
+ id: "changelog",
822
+ title: "Changelog",
823
+ groups: [{
824
+ title: `What's New in v${version}`,
825
+ rows
826
+ }, {
827
+ title: "Release References",
828
+ rows: [{
829
+ id: "changelog.docs",
830
+ name: "Documentation",
831
+ value: "CHANGELOG.md",
832
+ note: "shipped at plugin root and repository root"
833
+ }, {
834
+ id: "changelog.repo",
835
+ name: "GitHub Repository",
836
+ value: "ils15/pantheon-opencode",
837
+ note: "releases, pull requests and discussion"
838
+ }]
839
+ }]
840
+ };
841
+ }
470
842
  /** Semver-ish compare for X.Y.Z[-beta.N]; betas sort before their release. */
471
843
  function comparePantheonVersions(left, right) {
472
844
  const parse = (version) => {
@@ -830,12 +1202,23 @@ function initTuiPrefs(context) {
830
1202
  if (stash() !== void 0) return;
831
1203
  try {
832
1204
  const handle = context.storage?.store?.("tui-prefs", { initial: DEFAULT_TUI_PREFS });
833
- if (handle !== void 0) globalThis[PREFS_SYMBOL] = handle;
1205
+ if (handle !== void 0) {
1206
+ globalThis[PREFS_SYMBOL] = handle;
1207
+ if (!handle[0]?.layout) handle[1]((draft) => {
1208
+ if (!draft.layout) draft.layout = { ...DEFAULT_TUI_PREFS.layout };
1209
+ }).catch(() => {});
1210
+ }
834
1211
  } catch {}
835
1212
  }
836
1213
  /** The live reactive prefs (read properties inside memos/JSX — tracked). */
837
1214
  function tuiPrefs() {
838
- return stash()?.[0] ?? DEFAULT_TUI_PREFS;
1215
+ const s = stash()?.[0];
1216
+ if (!s) return DEFAULT_TUI_PREFS;
1217
+ if (!s.layout) return {
1218
+ ...s,
1219
+ layout: DEFAULT_TUI_PREFS.layout
1220
+ };
1221
+ return s;
839
1222
  }
840
1223
  /** Stage a mutation against the durable store; resolves when persisted. */
841
1224
  function mutateTuiPrefs(mutation) {
@@ -850,8 +1233,33 @@ const GAUGE_STYLES = Object.freeze([
850
1233
  "off"
851
1234
  ]);
852
1235
  const ENABLED_CYCLE = Object.freeze(["enabled", "disabled"]);
1236
+ const BAR_SHAPES_CYCLE = Object.freeze([
1237
+ "line",
1238
+ "block",
1239
+ "smooth",
1240
+ "ascii",
1241
+ "dots",
1242
+ "braille"
1243
+ ]);
1244
+ const BAR_WIDTHS_CYCLE = Object.freeze([
1245
+ "standard",
1246
+ "compact",
1247
+ "wide",
1248
+ "full"
1249
+ ]);
1250
+ const LAYOUT_PRESETS_CYCLE = Object.freeze(["comfortable", "compact"]);
1251
+ const SEPARATOR_STYLES_CYCLE = Object.freeze([
1252
+ "spaces",
1253
+ "pipes",
1254
+ "dots",
1255
+ "slashes"
1256
+ ]);
853
1257
  const DEFAULT_TUI_PREFS = {
854
1258
  version: 1,
1259
+ layout: {
1260
+ preset: "comfortable",
1261
+ separator: "spaces"
1262
+ },
855
1263
  sidebar: {
856
1264
  header: {
857
1265
  version: true,
@@ -866,6 +1274,9 @@ const DEFAULT_TUI_PREFS = {
866
1274
  },
867
1275
  context: {
868
1276
  gauge: "both",
1277
+ barShape: "line",
1278
+ barWidth: "standard",
1279
+ evenMark: false,
869
1280
  tokens: true,
870
1281
  spent: true,
871
1282
  modelUsage: true,
@@ -891,6 +1302,49 @@ function buildTuiTab(prefs) {
891
1302
  id: "tui",
892
1303
  title: "TUI",
893
1304
  groups: [
1305
+ {
1306
+ title: "Preset & Layout",
1307
+ rows: [{
1308
+ id: "tui.layout.preset",
1309
+ name: "Layout preset",
1310
+ value: prefs.layout?.preset ?? DEFAULT_TUI_PREFS.layout.preset,
1311
+ cycle: LAYOUT_PRESETS_CYCLE,
1312
+ note: "comfortable | compact — sets spacing & borders"
1313
+ }, {
1314
+ id: "tui.layout.separator",
1315
+ name: "Separator",
1316
+ value: prefs.layout?.separator ?? DEFAULT_TUI_PREFS.layout.separator,
1317
+ cycle: SEPARATOR_STYLES_CYCLE,
1318
+ note: "spaces | pipes | dots | slashes — status line glyphs"
1319
+ }]
1320
+ },
1321
+ {
1322
+ title: "Bars & Gauges",
1323
+ rows: [
1324
+ {
1325
+ id: "tui.sidebar.context.barShape",
1326
+ name: "Bar shape",
1327
+ value: prefs.sidebar.context.barShape,
1328
+ cycle: BAR_SHAPES_CYCLE,
1329
+ note: "line (━─) | block (▰▱) | smooth (█░) | ascii (=) | dots (●○) | braille"
1330
+ },
1331
+ {
1332
+ id: "tui.sidebar.context.barWidth",
1333
+ name: "Bar width",
1334
+ value: prefs.sidebar.context.barWidth,
1335
+ cycle: BAR_WIDTHS_CYCLE,
1336
+ note: "standard (12) | compact (8) | wide (16) | full (20 cells)"
1337
+ },
1338
+ row("tui.sidebar.context.evenMark", "Even-use mark", prefs.sidebar.context.evenMark, "| indicator at 50% midpoint in gauge bars"),
1339
+ {
1340
+ id: "tui.sidebar.context.gauge",
1341
+ name: "Gauge style",
1342
+ value: prefs.sidebar.context.gauge,
1343
+ cycle: GAUGE_STYLES,
1344
+ note: "both | bar | percent | off — `▰▱ 42% of 200k`"
1345
+ }
1346
+ ]
1347
+ },
894
1348
  {
895
1349
  title: "Sidebar header",
896
1350
  rows: [
@@ -911,13 +1365,6 @@ function buildTuiTab(prefs) {
911
1365
  {
912
1366
  title: "Context block detail",
913
1367
  rows: [
914
- {
915
- id: "tui.sidebar.context.gauge",
916
- name: "Gauge style",
917
- value: prefs.sidebar.context.gauge,
918
- cycle: GAUGE_STYLES,
919
- note: "both | bar | percent | off — `▰▱ 42% of 200k`"
920
- },
921
1368
  row("tui.sidebar.context.tokens", "Tokens row", prefs.sidebar.context.tokens, "the raw token count line"),
922
1369
  row("tui.sidebar.context.spent", "Spent row", prefs.sidebar.context.spent, "the `$… gasto na sessão` line"),
923
1370
  row("tui.sidebar.context.modelUsage", "Model usage table", prefs.sidebar.context.modelUsage, "per-model tokens/USD"),
@@ -939,6 +1386,27 @@ function buildTuiTab(prefs) {
939
1386
  function applyTuiRow(draft, id, value) {
940
1387
  const enabled = value === "enabled";
941
1388
  switch (id) {
1389
+ case "tui.layout.preset":
1390
+ if (LAYOUT_PRESETS_CYCLE.includes(value)) {
1391
+ if (!draft.layout) draft.layout = { ...DEFAULT_TUI_PREFS.layout };
1392
+ draft.layout.preset = value;
1393
+ }
1394
+ return;
1395
+ case "tui.layout.separator":
1396
+ if (SEPARATOR_STYLES_CYCLE.includes(value)) {
1397
+ if (!draft.layout) draft.layout = { ...DEFAULT_TUI_PREFS.layout };
1398
+ draft.layout.separator = value;
1399
+ }
1400
+ return;
1401
+ case "tui.sidebar.context.barShape":
1402
+ if (BAR_SHAPES_CYCLE.includes(value)) draft.sidebar.context.barShape = value;
1403
+ return;
1404
+ case "tui.sidebar.context.barWidth":
1405
+ if (BAR_WIDTHS_CYCLE.includes(value)) draft.sidebar.context.barWidth = value;
1406
+ return;
1407
+ case "tui.sidebar.context.evenMark":
1408
+ draft.sidebar.context.evenMark = enabled;
1409
+ return;
942
1410
  case "tui.sidebar.header.version":
943
1411
  draft.sidebar.header.version = enabled;
944
1412
  return;
@@ -1008,13 +1476,16 @@ function formatAgo(ms) {
1008
1476
  }
1009
1477
  function buildUpdatesTab(input) {
1010
1478
  const nowMs = input.nowMs ?? Date.now();
1011
- const channel = updateChannelFor(input.currentVersion);
1479
+ const channel = input.selectedChannel ?? updateChannelFor(input.currentVersion);
1012
1480
  const lastCheckMs = input.state.lastCheckMs;
1013
1481
  const latest = input.lastCheckedVersion ?? input.state.lastNotifiedVersion;
1482
+ const stable = (version) => !/-beta\.\d+$/.test(version);
1483
+ const newer = latest !== void 0 && comparePantheonVersions(latest, input.currentVersion) > 0 && !(stable(input.currentVersion) && !stable(latest));
1014
1484
  const rows = [{
1015
1485
  id: "update.channel",
1016
1486
  name: "Channel",
1017
1487
  value: channel,
1488
+ cycle: ["stable", "beta"],
1018
1489
  note: "stable tracks npm `latest`; beta tracks npm `beta`"
1019
1490
  }, {
1020
1491
  id: "update.check",
@@ -1024,24 +1495,243 @@ function buildUpdatesTab(input) {
1024
1495
  note: "enter probes the registry for the running channel"
1025
1496
  }];
1026
1497
  if (latest) {
1027
- const stable = (version) => !/-beta\.\d+$/.test(version);
1028
- const newer = comparePantheonVersions(latest, input.currentVersion) > 0 && !(stable(input.currentVersion) && !stable(latest));
1029
1498
  rows.push({
1030
1499
  id: "update.latest",
1031
1500
  name: "Registry",
1032
1501
  value: newer ? `v${latest} available` : "up to date",
1033
1502
  note: newer ? "adopt with `pantheon-opencode update`" : "no newer compatible version"
1034
1503
  });
1504
+ rows.push({
1505
+ id: "update.run",
1506
+ name: "Update now",
1507
+ value: input.updating ? "updating…" : newer ? `install v${latest}` : "reinstall / refresh",
1508
+ action: "update-run",
1509
+ note: newer ? "enter runs `pantheon-opencode update`" : "enter refreshes installed copy"
1510
+ });
1035
1511
  }
1512
+ rows.push({
1513
+ id: "update.command",
1514
+ name: "CLI command",
1515
+ value: channel === "beta" ? "pantheon-opencode update" : "pantheon-opencode update --stable",
1516
+ note: "run in terminal or OpenCode Desktop terminal"
1517
+ });
1036
1518
  return {
1037
1519
  id: "updates",
1038
1520
  title: "Updates",
1039
1521
  groups: [{
1040
- title: "Updates",
1522
+ title: "Updates & Maintenance",
1041
1523
  rows
1042
1524
  }]
1043
1525
  };
1044
1526
  }
1527
+ /** Prefix of the "+N more" line appended when the bullet budget is exceeded. */
1528
+ const WHATS_NEW_MORE_PREFIX = "… +";
1529
+ const EMPTY_HIGHLIGHTS = {
1530
+ version: null,
1531
+ found: false,
1532
+ groups: [],
1533
+ totalItems: 0,
1534
+ truncated: false
1535
+ };
1536
+ /** Escape regex metacharacters so a version like 1.0.0 matches literally. */
1537
+ function escapeRegExp(text) {
1538
+ return text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
1539
+ }
1540
+ /**
1541
+ * Extract the body of a version section from changelog text — inline replica
1542
+ * of scripts/changelog-extract.mjs `extractSection` (see that file for the
1543
+ * full contract: `## [<version>] - YYYY-MM-DD`, leading `v` and the date
1544
+ * optional, `## [Unreleased]` never matched).
1545
+ */
1546
+ function extractSection(changelogText, version) {
1547
+ const normalized = String(version).trim().replace(/^v/i, "");
1548
+ if (!normalized || /^unreleased$/i.test(normalized)) return {
1549
+ found: false,
1550
+ body: null
1551
+ };
1552
+ const escaped = escapeRegExp(normalized);
1553
+ const match = new RegExp(`^##[ \\t]+\\[v?${escaped}\\](?:[ \\t]*-[ \\t]*\\d{4}-\\d{2}-\\d{2})?(?=[ \\t]|$)`, "m").exec(changelogText);
1554
+ if (!match) return {
1555
+ found: false,
1556
+ body: null
1557
+ };
1558
+ const newline = changelogText.indexOf("\n", match.index);
1559
+ const start = newline === -1 ? changelogText.length : newline + 1;
1560
+ const nextHeading = /^##[ \t]+\[/m.exec(changelogText.slice(start));
1561
+ const end = nextHeading ? start + nextHeading.index : changelogText.length;
1562
+ return {
1563
+ found: true,
1564
+ body: changelogText.slice(start, end).trim()
1565
+ };
1566
+ }
1567
+ /**
1568
+ * Reduce one markdown line to plain text: links keep their label, emphasis
1569
+ * and inline-code markers are dropped, HTML comment fragments are removed,
1570
+ * and whitespace collapses. Deliberately simple — the input is our own
1571
+ * CHANGELOG (lint-capped at 200 chars per bullet), not hostile input.
1572
+ */
1573
+ function stripMarkdown(text) {
1574
+ return text.replace(/<!--[\s\S]*?-->/g, " ").replace(/\[([^\]]+)\]\([^)]*\)/g, "$1").replace(/(\*\*|__)/g, "").replace(/`/g, "").replace(/\s+/g, " ").trim();
1575
+ }
1576
+ /** Strip the leading H3 marker (`### Added` → `Added`). */
1577
+ function stripHeading(text) {
1578
+ return text.replace(/^#{1,6}[ \t]+/, "").trim();
1579
+ }
1580
+ /**
1581
+ * Extract the curated summary block (`### 🆕 What's New` or `## 🆕 What's New`)
1582
+ * from a section body: its bullets only, each truncated to
1583
+ * WHATS_NEW_ITEM_MAX_CHARS, capped to WHATS_NEW_SUMMARY_MAX_ITEMS. Null when
1584
+ * the section carries no summary block (the full-section fallback applies).
1585
+ */
1586
+ function extractWhatsNewSummary(body) {
1587
+ const lines = body.split("\n");
1588
+ const start = lines.findIndex((line) => /^#{2,3}[ \t]+.*What'?s New/i.test(line.trim()));
1589
+ if (start === -1) return null;
1590
+ const items = [];
1591
+ for (const rawLine of lines.slice(start + 1)) {
1592
+ const line = rawLine.trim();
1593
+ if (line === "" || line.startsWith("<!--")) continue;
1594
+ if (/^#{1,6}[ \t]/.test(line)) break;
1595
+ if (!/^[-*][ \t]/.test(line)) continue;
1596
+ if (items.length >= 6) break;
1597
+ const content = stripMarkdown(line.replace(/^[-*][ \t]+/, ""));
1598
+ if (content === "") continue;
1599
+ items.push(content.length > 140 ? `${content.slice(0, 139)}…` : content);
1600
+ }
1601
+ return items.length > 0 ? items : null;
1602
+ }
1603
+ /**
1604
+ * Extract the release highlights for `version`. When the section carries a
1605
+ * curated `🆕 What's New` summary block, THE WINDOW SHOWS ONLY THAT (the
1606
+ * full Added/Changed/Fixed walls are for the CHANGELOG readers, not the
1607
+ * dialog); otherwise it falls back to the H3-group extraction bounded to
1608
+ * WHATS_NEW_MAX_ITEMS bullets. A missing section, a bullet-less section or a
1609
+ * blank changelog all return EMPTY_HIGHLIGHTS (no window).
1610
+ */
1611
+ function extractHighlights(changelogText, version) {
1612
+ const { found, body } = extractSection(changelogText ?? "", version ?? "");
1613
+ if (!found || !body) return { ...EMPTY_HIGHLIGHTS };
1614
+ const summary = extractWhatsNewSummary(body);
1615
+ if (summary !== null) return {
1616
+ version: String(version).trim().replace(/^v/i, ""),
1617
+ found: true,
1618
+ groups: [{
1619
+ heading: null,
1620
+ items: summary
1621
+ }],
1622
+ totalItems: summary.length,
1623
+ truncated: false
1624
+ };
1625
+ const groups = [];
1626
+ let totalItems = 0;
1627
+ let truncated = false;
1628
+ for (const rawLine of body.split("\n")) {
1629
+ const line = rawLine.trim();
1630
+ if (line === "" || line.startsWith("<!--")) continue;
1631
+ if (/^#{1,6}[ \t]/.test(line)) {
1632
+ const heading = stripMarkdown(stripHeading(line));
1633
+ if (heading === "") continue;
1634
+ if (groups.at(-1)?.items.length === 0) groups.pop();
1635
+ groups.push({
1636
+ heading,
1637
+ items: []
1638
+ });
1639
+ continue;
1640
+ }
1641
+ if (totalItems >= 12) {
1642
+ if (/^[-*][ \t]/.test(line)) totalItems += 1;
1643
+ continue;
1644
+ }
1645
+ const isBullet = /^[-*][ \t]/.test(line);
1646
+ const continuation = (groups.at(-1)?.items.length ?? 0) > 0;
1647
+ if (!isBullet && !continuation) continue;
1648
+ const content = stripMarkdown(isBullet ? line.replace(/^[-*][ \t]+/, "") : line);
1649
+ if (content === "") continue;
1650
+ const bounded = content.length > 140 ? `${content.slice(0, 139)}…` : content;
1651
+ const group = groups.at(-1);
1652
+ if (group === void 0) groups.push({
1653
+ heading: null,
1654
+ items: [bounded]
1655
+ });
1656
+ else if (isBullet || group.items.length === 0) group.items.push(bounded);
1657
+ else group.items[group.items.length - 1] = `${group.items.at(-1)} ${bounded}`.trim();
1658
+ if (isBullet) totalItems += 1;
1659
+ }
1660
+ const kept = groups.filter((group) => group.items.length > 0);
1661
+ truncated = totalItems > 12;
1662
+ return {
1663
+ version: found ? String(version).trim().replace(/^v/i, "") : null,
1664
+ found,
1665
+ groups: kept,
1666
+ totalItems,
1667
+ truncated
1668
+ };
1669
+ }
1670
+ /** Window title — mirrors the sidebar's `Pantheon v<version>` convention. */
1671
+ function whatsNewTitle(version) {
1672
+ return `O que há de novo — Pantheon v${String(version).trim().replace(/^v/i, "")}`;
1673
+ }
1674
+ /** Flat display lines for the window: group headings, `• ` bullets, `+N more`. */
1675
+ function whatsNewLines(highlights) {
1676
+ const lines = [];
1677
+ for (const group of highlights.groups) {
1678
+ if (group.heading !== null) lines.push(group.heading);
1679
+ for (const item of group.items) lines.push(`• ${item}`);
1680
+ }
1681
+ if (highlights.truncated) {
1682
+ const hidden = Math.max(0, highlights.totalItems - 12);
1683
+ if (hidden > 0) lines.push(`${WHATS_NEW_MORE_PREFIX}${hidden} mais`);
1684
+ }
1685
+ return lines;
1686
+ }
1687
+ /**
1688
+ * Candidate CHANGELOG.md locations for a bundle, first readable wins:
1689
+ * 1. the plugin copy root (`<configDir>/plugins/pantheon-tui/CHANGELOG.md`,
1690
+ * shipped by both installers next to package.json);
1691
+ * 2. the package root (dev checkout; also an npm-package install when the
1692
+ * bundle runs from `<pkg>/src/plugins/tui/dist/`).
1693
+ */
1694
+ function changelogCandidates(bundlePath) {
1695
+ const dist = dirname(bundlePath);
1696
+ const copyRoot = dirname(dist);
1697
+ const packageRoot = dirname(dirname(dirname(copyRoot)));
1698
+ return [join(copyRoot, "CHANGELOG.md"), join(packageRoot, "CHANGELOG.md")];
1699
+ }
1700
+ /** Read the first existing candidate; null when none is readable (no window). */
1701
+ async function readChangelogForBundle(bundleUrl) {
1702
+ try {
1703
+ const bundlePath = fileURLToPath(bundleUrl);
1704
+ for (const candidate of changelogCandidates(bundlePath)) try {
1705
+ return await readFile(candidate, "utf8");
1706
+ } catch {}
1707
+ return null;
1708
+ } catch {
1709
+ return null;
1710
+ }
1711
+ }
1712
+ /** The ambient build-time version, or null outside a tsdown build. */
1713
+ function embeddedVersion() {
1714
+ return "2.0.0-rc.1";
1715
+ }
1716
+ /**
1717
+ * Resolve the running Pantheon version for the what's-new window: the plugin
1718
+ * copy's own package.json first (the copy root two levels above the bundle,
1719
+ * then the package root four levels above — the same legs as the V1 sidebar's
1720
+ * detectVersion try 0a/0b), falling back to the tsdown build embed. Null when
1721
+ * nothing resolves → no window (fail-open).
1722
+ */
1723
+ async function resolveRunningVersion$1(bundleUrl, embedded = embeddedVersion()) {
1724
+ try {
1725
+ const bundlePath = fileURLToPath(bundleUrl);
1726
+ const dist = dirname(bundlePath);
1727
+ for (const root of [dirname(dist), dirname(dirname(dirname(dist)))]) try {
1728
+ const raw = await readFile(join(root, "package.json"), "utf8");
1729
+ const parsed = JSON.parse(raw);
1730
+ if (typeof parsed.version === "string" && parsed.version.trim() !== "") return parsed.version;
1731
+ } catch {}
1732
+ } catch {}
1733
+ return embedded;
1734
+ }
1045
1735
  //#endregion
1046
1736
  //#region src/pantheon-settings.tsx
1047
1737
  /** @jsxImportSource @opentui/solid */
@@ -1067,7 +1757,28 @@ function buildUpdatesTab(input) {
1067
1757
  * report beta.2: navigation "stopped working" was exactly that theft).
1068
1758
  */
1069
1759
  const ROUTE_NAME = "pantheon-settings";
1760
+ /** The input mode the page pushes while mounted (composer layers sleep). */
1761
+ const ROUTE_MODE = "pantheon-settings";
1070
1762
  /** Loose local shape of a host route (the real Route lives in the host typings). */
1763
+ /**
1764
+ * Strip a LIVE route object down to the plain shape the route store expects.
1765
+ * `router.current()` returns the host's live data (reactive proxies, location
1766
+ * objects with cycles) and the host's navigate deep-clones via JSON.stringify
1767
+ * — passing the live object through throws "cyclic structures" and the
1768
+ * window could never close (field report beta.5, root cause).
1769
+ */
1770
+ function plainRoute(route) {
1771
+ if (route === void 0) return { type: "home" };
1772
+ if (route.type === "session" && "sessionID" in route && typeof route.sessionID === "string") return {
1773
+ type: "session",
1774
+ sessionID: route.sessionID
1775
+ };
1776
+ if (route.type === "plugin" && typeof route.name === "string") return {
1777
+ type: "plugin",
1778
+ name: route.name
1779
+ };
1780
+ return { type: "home" };
1781
+ }
1071
1782
  const [blocking, setBlocking] = createSignal(false);
1072
1783
  /** True while a Pantheon settings surface (page or fallback dialog) is open. */
1073
1784
  function pantheonSettingsBlocking() {
@@ -1111,6 +1822,90 @@ function readOverridesLoad() {
1111
1822
  function writeOverridesToDisk(load) {
1112
1823
  writeFileSync(globalOverridesPath(), serializeOverrides(load.global), "utf8");
1113
1824
  }
1825
+ function userOpenCodeConfigPath() {
1826
+ const xdgConfig = process.env.XDG_CONFIG_HOME ?? join(process.env.HOME ?? "", ".config");
1827
+ return join(xdgConfig, "opencode", "opencode.json");
1828
+ }
1829
+ /** Read options.goal_loop from the user's opencode.json (fail-open). */
1830
+ function readGoalLoopPrefs() {
1831
+ const fallback = { ...DEFAULT_GOAL_LOOP_PREFS };
1832
+ try {
1833
+ const raw = JSON.parse(readFileSync(userOpenCodeConfigPath(), "utf8"))?.options?.goal_loop;
1834
+ if (raw && typeof raw === "object") return {
1835
+ enabled: typeof raw.enabled === "boolean" ? raw.enabled : fallback.enabled,
1836
+ cooldownMs: typeof raw.cooldownMs === "number" && raw.cooldownMs >= 1e3 ? Math.floor(raw.cooldownMs) : fallback.cooldownMs,
1837
+ maxContinuations: typeof raw.maxContinuations === "number" && raw.maxContinuations >= 1 ? Math.min(200, Math.floor(raw.maxContinuations)) : fallback.maxContinuations
1838
+ };
1839
+ } catch {}
1840
+ return fallback;
1841
+ }
1842
+ /** Read the decision budgets from decision-router.json's `budget` envelope (fail-open). */
1843
+ function readDecisionBudgets() {
1844
+ const fallback = { ...DEFAULT_DECISION_BUDGETS };
1845
+ try {
1846
+ const path = join(process.env.XDG_CONFIG_HOME ?? join(process.env.HOME ?? "", ".config"), "pantheon", "decision-router.json");
1847
+ const raw = JSON.parse(readFileSync(path, "utf8"))?.budget;
1848
+ if (raw && typeof raw === "object") return {
1849
+ monthlyUsd: typeof raw.monthlyUsd === "number" && raw.monthlyUsd > 0 ? raw.monthlyUsd : fallback.monthlyUsd,
1850
+ perDecisionUsd: typeof raw.perDecisionUsd === "number" && raw.perDecisionUsd > 0 ? raw.perDecisionUsd : fallback.perDecisionUsd
1851
+ };
1852
+ } catch {}
1853
+ return fallback;
1854
+ }
1855
+ /**
1856
+ * Surgically set one key under `options` in the user's opencode.json
1857
+ * (preserving every other key). Startup-applied options live here — the
1858
+ * runtime resolves them once at plugin setup.
1859
+ */
1860
+ function writeUserOption(key, value) {
1861
+ const path = userOpenCodeConfigPath();
1862
+ let doc = {};
1863
+ try {
1864
+ const parsed = JSON.parse(readFileSync(path, "utf8"));
1865
+ if (typeof parsed === "object" && parsed !== null && !Array.isArray(parsed)) doc = parsed;
1866
+ } catch {}
1867
+ const options = typeof doc.options === "object" && doc.options !== null && !Array.isArray(doc.options) ? { ...doc.options } : {};
1868
+ options[key] = value;
1869
+ doc.options = options;
1870
+ writeFileSync(path, `${JSON.stringify(doc, null, 2)}\n`);
1871
+ }
1872
+ /** Merge the `budget` envelope into decision-router.json (0600 preserved). */
1873
+ function writeDecisionBudget(budgets) {
1874
+ const path = join(process.env.XDG_CONFIG_HOME ?? join(process.env.HOME ?? "", ".config"), "pantheon", "decision-router.json");
1875
+ let doc = {};
1876
+ try {
1877
+ const parsed = JSON.parse(readFileSync(path, "utf8"));
1878
+ if (typeof parsed === "object" && parsed !== null && !Array.isArray(parsed)) doc = parsed;
1879
+ } catch {
1880
+ throw new Error("decision-router.json unreadable — repair via `decision-router setup-model`");
1881
+ }
1882
+ doc.budget = { ...budgets };
1883
+ const temp = `${path}.tui.tmp`;
1884
+ writeFileSync(temp, `${JSON.stringify(doc, null, 2)}\n`, { mode: 384 });
1885
+ renameSync(temp, path);
1886
+ }
1887
+ function decisionAuthStorePath() {
1888
+ const xdgData = process.env.XDG_DATA_HOME ?? join(process.env.HOME ?? "", ".local", "share");
1889
+ return join(xdgData, "opencode", "auth.json");
1890
+ }
1891
+ /** Provider ids registered in the host auth store (existence only — never values). */
1892
+ function readAuthProviders() {
1893
+ const names = /* @__PURE__ */ new Set();
1894
+ try {
1895
+ const parsed = JSON.parse(readFileSync(decisionAuthStorePath(), "utf8"));
1896
+ for (const key of Object.keys(parsed)) names.add(key);
1897
+ } catch {}
1898
+ return names;
1899
+ }
1900
+ /** Provider ids present in opencode.json `providers` (the config copy the host reads). */
1901
+ function readConfigProviders() {
1902
+ const names = /* @__PURE__ */ new Set();
1903
+ try {
1904
+ const parsed = JSON.parse(readFileSync(userOpenCodeConfigPath(), "utf8"));
1905
+ for (const key of Object.keys(parsed?.providers ?? {})) names.add(key);
1906
+ } catch {}
1907
+ return names;
1908
+ }
1114
1909
  function updateCheckStatePath() {
1115
1910
  const stateDir = process.env.XDG_STATE_HOME ?? join(process.env.HOME ?? "", ".local", "state");
1116
1911
  return join(stateDir, "pantheon", "update-check.json");
@@ -1122,9 +1917,9 @@ function readUpdateCheckState() {
1122
1917
  return {};
1123
1918
  }
1124
1919
  }
1125
- async function fetchLatestForChannel(currentVersion) {
1920
+ async function fetchLatestForChannel(channel) {
1126
1921
  try {
1127
- const response = await fetch(registryUrlForChannel(updateChannelFor(currentVersion)), { signal: AbortSignal.timeout(5e3) });
1922
+ const response = await fetch(registryUrlForChannel(channel), { signal: AbortSignal.timeout(5e3) });
1128
1923
  return String((await response.json())?.version ?? "") || null;
1129
1924
  } catch {
1130
1925
  return null;
@@ -1140,162 +1935,379 @@ function persistUpdateCheckState(previous, latest) {
1140
1935
  } : null, Date.now()), null, 2)}\n`);
1141
1936
  } catch {}
1142
1937
  }
1143
- function resolveRunningVersion$1() {
1144
- try {
1145
- return JSON.parse(readFileSync(new URL("../../package.json", import.meta.url), "utf8")).version ?? "unknown";
1146
- } catch {
1147
- return "unknown";
1148
- }
1938
+ function resolveRunningVersion() {
1939
+ return "2.0.0-rc.1";
1149
1940
  }
1150
1941
  const VALUE_WIDTH = 22;
1151
1942
  function SettingsWindow(props) {
1152
1943
  const tab = () => props.tabs()[props.page()] ?? props.tabs()[0] ?? EMPTY_TAB;
1153
- const rows = () => tabRows(tab());
1154
1944
  return (() => {
1155
- var _el$ = createElement("box"), _el$2 = createElement("box"), _el$3 = createElement("text"), _el$4 = createElement("text"), _el$6 = createElement("text"), _el$9 = createElement("text"), _el$0 = createElement("text");
1945
+ var _el$ = createElement("box"), _el$2 = createElement("box"), _el$3 = createElement("text"), _el$4 = createElement("box"), _el$5 = createElement("box"), _el$6 = createElement("text"), _el$8 = createElement("box"), _el$9 = createElement("box"), _el$0 = createElement("text"), _el$10 = createElement("box"), _el$11 = createElement("box"), _el$12 = createElement("box"), _el$13 = createElement("text"), _el$15 = createElement("text"), _el$17 = createElement("box"), _el$18 = createElement("text"), _el$19 = createElement("text");
1156
1946
  insertNode(_el$, _el$2);
1157
- insertNode(_el$, _el$6);
1158
- insertNode(_el$, _el$9);
1159
- insertNode(_el$, _el$0);
1947
+ insertNode(_el$, _el$8);
1948
+ insertNode(_el$, _el$10);
1160
1949
  setProp(_el$, "flexDirection", "column");
1161
1950
  setProp(_el$, "paddingLeft", 1);
1162
1951
  setProp(_el$, "paddingRight", 1);
1163
1952
  setProp(_el$, "paddingTop", 1);
1164
1953
  insertNode(_el$2, _el$3);
1165
1954
  insertNode(_el$2, _el$4);
1955
+ insertNode(_el$2, _el$5);
1956
+ insertNode(_el$2, _el$6);
1166
1957
  setProp(_el$2, "flexDirection", "row");
1958
+ setProp(_el$2, "alignItems", "center");
1167
1959
  setProp(_el$3, "attributes", 1);
1168
1960
  insert(_el$3, () => `Pantheon v${props.version}`);
1169
- insert(_el$2, createComponent(For, {
1961
+ setProp(_el$4, "width", 2);
1962
+ setProp(_el$5, "flexDirection", "row");
1963
+ setProp(_el$5, "flexGrow", 1);
1964
+ setProp(_el$5, "flexShrink", 1);
1965
+ insert(_el$5, createComponent(For, {
1170
1966
  get each() {
1171
1967
  return props.tabs();
1172
1968
  },
1173
- children: (t, index) => (() => {
1174
- var _el$10 = createElement("text");
1175
- spread(_el$10, mergeProps({ get fg() {
1176
- return memo(() => index() === props.page())() ? props.fg : props.muted;
1177
- } }, () => index() === props.page() ? { attributes: 1 } : {}), true);
1178
- insert(_el$10, () => ` ${t.title}${tabDirty(props.draft(), t) ? " ●" : ""}`);
1179
- return _el$10;
1180
- })()
1181
- }), _el$4);
1182
- insertNode(_el$4, createTextNode(` esc`));
1183
- insertNode(_el$6, createTextNode(`────────────────────────────────────────────────────────────────────────`));
1184
- insert(_el$, createComponent(For, {
1969
+ children: (t, index) => {
1970
+ const isActive = () => index() === props.page();
1971
+ return (() => {
1972
+ var _el$41 = createElement("text");
1973
+ setProp(_el$41, "flexShrink", 0);
1974
+ spread(_el$41, mergeProps({ get fg() {
1975
+ return memo(() => !!isActive())() ? props.warn ?? props.fg : props.muted;
1976
+ } }, () => isActive() ? { attributes: 1 } : {}), true);
1977
+ insert(_el$41, () => `${t.title}${tabDirty(props.draft(), t) ? " ●" : ""} `);
1978
+ return _el$41;
1979
+ })();
1980
+ }
1981
+ }));
1982
+ insertNode(_el$6, createTextNode(`esc`));
1983
+ insertNode(_el$8, _el$9);
1984
+ setProp(_el$8, "flexDirection", "row");
1985
+ setProp(_el$8, "height", 1);
1986
+ insertNode(_el$9, _el$0);
1987
+ setProp(_el$9, "flexGrow", 1);
1988
+ insertNode(_el$0, createTextNode(`──────────────────────────────────────────────────────────────────────────────`));
1989
+ insertNode(_el$10, _el$11);
1990
+ insertNode(_el$10, _el$17);
1991
+ setProp(_el$10, "flexDirection", "row");
1992
+ insertNode(_el$11, _el$12);
1993
+ insertNode(_el$11, _el$13);
1994
+ insertNode(_el$11, _el$15);
1995
+ setProp(_el$11, "width", 18);
1996
+ setProp(_el$11, "flexDirection", "column");
1997
+ insert(_el$11, createComponent(For, {
1998
+ get each() {
1999
+ return props.tabs();
2000
+ },
2001
+ children: (t, index) => {
2002
+ const isActive = () => index() === props.page();
2003
+ return (() => {
2004
+ var _el$42 = createElement("text");
2005
+ spread(_el$42, mergeProps({ get fg() {
2006
+ return memo(() => !!isActive())() ? props.warn ?? props.fg : props.muted;
2007
+ } }, () => isActive() ? { attributes: 1 } : {}), true);
2008
+ insert(_el$42, () => `${isActive() ? "▸ " : " "}${t.title}${tabDirty(props.draft(), t) ? " ●" : ""}`);
2009
+ return _el$42;
2010
+ })();
2011
+ }
2012
+ }), _el$12);
2013
+ setProp(_el$12, "height", 1);
2014
+ insertNode(_el$13, createTextNode(`1-9: tab`));
2015
+ insertNode(_el$15, createTextNode(`tab: next`));
2016
+ insertNode(_el$17, _el$18);
2017
+ insertNode(_el$17, _el$19);
2018
+ setProp(_el$17, "flexGrow", 1);
2019
+ setProp(_el$17, "flexShrink", 1);
2020
+ setProp(_el$17, "flexDirection", "column");
2021
+ setProp(_el$17, "paddingLeft", 1);
2022
+ setProp(_el$18, "attributes", 1);
2023
+ insert(_el$18, () => tab().title);
2024
+ insertNode(_el$19, createTextNode(`────────────────────────────────────────`));
2025
+ insert(_el$17, createComponent(For, {
1185
2026
  get each() {
1186
2027
  return tab().groups;
1187
2028
  },
1188
2029
  children: (group) => (() => {
1189
- var _el$11 = createElement("box"), _el$13 = createElement("box");
1190
- insertNode(_el$11, _el$13);
1191
- setProp(_el$11, "flexDirection", "column");
1192
- insert(_el$11, createComponent(Show, {
2030
+ var _el$43 = createElement("box"), _el$45 = createElement("box");
2031
+ insertNode(_el$43, _el$45);
2032
+ setProp(_el$43, "flexDirection", "column");
2033
+ insert(_el$43, createComponent(Show, {
1193
2034
  get when() {
1194
2035
  return group.title !== void 0;
1195
2036
  },
1196
2037
  get children() {
1197
- var _el$12 = createElement("text");
1198
- setProp(_el$12, "attributes", 1);
1199
- insert(_el$12, () => group.title);
1200
- effect((_$p) => setProp(_el$12, "fg", props.fg, _$p));
1201
- return _el$12;
2038
+ var _el$44 = createElement("text");
2039
+ setProp(_el$44, "attributes", 1);
2040
+ insert(_el$44, () => group.title);
2041
+ effect((_$p) => setProp(_el$44, "fg", props.warn ?? props.fg, _$p));
2042
+ return _el$44;
1202
2043
  }
1203
- }), _el$13);
1204
- insert(_el$11, createComponent(For, {
2044
+ }), _el$45);
2045
+ insert(_el$43, createComponent(For, {
1205
2046
  get each() {
1206
2047
  return group.rows;
1207
2048
  },
1208
2049
  children: (row) => {
1209
- const isSelected = () => rows()[props.selected()]?.id === row.id;
2050
+ const isSelected = () => row.id === props.selectedId();
1210
2051
  const display = () => props.draft()[row.id] ?? row.value;
1211
2052
  const staged = () => props.draft()[row.id] !== void 0;
1212
- const gutter = () => isSelected() ? "▸ " : " ";
2053
+ const gutter = () => isSelected() ? " " : " ";
1213
2054
  const valueCell = () => row.cycle !== void 0 ? `< ${display()} >` : display();
1214
2055
  return (() => {
1215
- var _el$14 = createElement("box"), _el$15 = createElement("box"), _el$16 = createElement("text"), _el$17 = createElement("box"), _el$18 = createElement("text");
1216
- insertNode(_el$14, _el$15);
1217
- insertNode(_el$14, _el$17);
1218
- setProp(_el$14, "flexDirection", "row");
1219
- insertNode(_el$15, _el$16);
1220
- setProp(_el$15, "width", 28);
1221
- spread(_el$16, mergeProps({ get fg() {
1222
- return props.fg;
2056
+ var _el$46 = createElement("box"), _el$47 = createElement("box"), _el$48 = createElement("text"), _el$49 = createElement("box"), _el$50 = createElement("text");
2057
+ insertNode(_el$46, _el$47);
2058
+ insertNode(_el$46, _el$49);
2059
+ setProp(_el$46, "flexDirection", "row");
2060
+ insertNode(_el$47, _el$48);
2061
+ setProp(_el$47, "width", 30);
2062
+ spread(_el$48, mergeProps({ get fg() {
2063
+ return memo(() => !!isSelected())() ? "#000000" : props.fg;
1223
2064
  } }, () => isSelected() ? { attributes: 1 } : {}), true);
1224
- insert(_el$16, () => `${gutter()}${row.name}`.padEnd(28));
1225
- insertNode(_el$17, _el$18);
1226
- setProp(_el$17, "width", 22);
1227
- spread(_el$18, mergeProps({ get fg() {
1228
- return memo(() => !!(isSelected() || staged()))() ? props.fg : props.muted;
1229
- } }, () => isSelected() ? { attributes: 1 } : {}), true);
1230
- insert(_el$18, () => `${valueCell()}${staged() ? " ●" : ""}`.padEnd(VALUE_WIDTH));
1231
- insert(_el$14, createComponent(Show, {
2065
+ insert(_el$48, () => `${gutter()}${row.name}`.padEnd(30));
2066
+ insertNode(_el$49, _el$50);
2067
+ setProp(_el$49, "width", 22);
2068
+ spread(_el$50, mergeProps({ get fg() {
2069
+ return memo(() => !!isSelected())() ? "#000000" : memo(() => !!staged())() ? props.warn ?? props.fg : props.muted;
2070
+ } }, () => isSelected() || staged() ? { attributes: 1 } : {}), true);
2071
+ insert(_el$50, () => `${valueCell()}${staged() ? " ●" : ""}`.padEnd(VALUE_WIDTH));
2072
+ insert(_el$46, createComponent(Show, {
1232
2073
  get when() {
1233
2074
  return row.note !== void 0;
1234
2075
  },
1235
2076
  get children() {
1236
- var _el$19 = createElement("box"), _el$20 = createElement("text");
1237
- insertNode(_el$19, _el$20);
1238
- setProp(_el$19, "flexGrow", 1);
1239
- setProp(_el$19, "flexShrink", 1);
1240
- insert(_el$20, () => row.note);
1241
- effect((_$p) => setProp(_el$20, "fg", props.muted, _$p));
1242
- return _el$19;
2077
+ var _el$51 = createElement("box"), _el$52 = createElement("text");
2078
+ insertNode(_el$51, _el$52);
2079
+ setProp(_el$51, "flexGrow", 1);
2080
+ setProp(_el$51, "flexShrink", 1);
2081
+ insert(_el$52, () => row.note);
2082
+ effect((_$p) => setProp(_el$52, "fg", isSelected() ? "#111827" : props.muted, _$p));
2083
+ return _el$51;
1243
2084
  }
1244
2085
  }), null);
1245
- return _el$14;
2086
+ effect((_$p) => setProp(_el$46, "backgroundColor", isSelected() ? props.warn ?? "#f59e0b" : void 0, _$p));
2087
+ return _el$46;
1246
2088
  })();
1247
2089
  }
1248
- }), _el$13);
1249
- setProp(_el$13, "height", 1);
1250
- return _el$11;
2090
+ }), _el$45);
2091
+ setProp(_el$45, "height", 1);
2092
+ return _el$43;
1251
2093
  })()
1252
- }), _el$9);
2094
+ }), null);
1253
2095
  insert(_el$, createComponent(Show, {
1254
2096
  get when() {
1255
2097
  return props.notice() !== void 0;
1256
2098
  },
1257
2099
  get children() {
1258
- var _el$8 = createElement("text");
1259
- insert(_el$8, () => `⚠ ${props.notice()}`);
1260
- effect((_$p) => setProp(_el$8, "fg", props.warn ?? props.muted, _$p));
1261
- return _el$8;
2100
+ var _el$21 = createElement("text");
2101
+ insert(_el$21, (() => {
2102
+ var _c$ = memo(() => !!(props.notice()?.startsWith("✅") || props.notice()?.startsWith("saved")));
2103
+ return () => _c$() ? props.notice() : `⚠ ${props.notice()}`;
2104
+ })());
2105
+ effect((_$p) => setProp(_el$21, "fg", props.notice()?.startsWith("✅") ? props.fg : props.warn ?? props.muted, _$p));
2106
+ return _el$21;
2107
+ }
2108
+ }), null);
2109
+ insert(_el$, createComponent(Show, {
2110
+ get when() {
2111
+ return props.confirmExit?.();
2112
+ },
2113
+ get fallback() {
2114
+ return (() => {
2115
+ var _el$53 = createElement("box"), _el$71 = createElement("text");
2116
+ insertNode(_el$53, _el$71);
2117
+ setProp(_el$53, "flexDirection", "column");
2118
+ insert(_el$53, createComponent(Show, {
2119
+ get when() {
2120
+ return draftDirty(props.draft());
2121
+ },
2122
+ get fallback() {
2123
+ return (() => {
2124
+ var _el$73 = createElement("box"), _el$74 = createElement("box"), _el$75 = createElement("text"), _el$77 = createElement("text"), _el$79 = createElement("box"), _el$80 = createElement("text"), _el$82 = createElement("text"), _el$84 = createElement("box"), _el$85 = createElement("text"), _el$87 = createElement("box"), _el$88 = createElement("text");
2125
+ insertNode(_el$73, _el$74);
2126
+ insertNode(_el$73, _el$77);
2127
+ insertNode(_el$73, _el$79);
2128
+ insertNode(_el$73, _el$82);
2129
+ insertNode(_el$73, _el$84);
2130
+ insertNode(_el$73, _el$87);
2131
+ insertNode(_el$73, _el$88);
2132
+ setProp(_el$73, "flexDirection", "row");
2133
+ insertNode(_el$74, _el$75);
2134
+ setProp(_el$74, "backgroundColor", "#262626");
2135
+ insertNode(_el$75, createTextNode(` Close `));
2136
+ setProp(_el$75, "fg", "#ffffff");
2137
+ insertNode(_el$77, createTextNode(` `));
2138
+ insertNode(_el$79, _el$80);
2139
+ setProp(_el$79, "backgroundColor", "#262626");
2140
+ insertNode(_el$80, createTextNode(` Reset page `));
2141
+ setProp(_el$80, "fg", "#ffffff");
2142
+ insertNode(_el$82, createTextNode(` `));
2143
+ insertNode(_el$84, _el$85);
2144
+ setProp(_el$84, "backgroundColor", "#262626");
2145
+ insertNode(_el$85, createTextNode(` Defaults `));
2146
+ setProp(_el$85, "fg", "#ffffff");
2147
+ setProp(_el$87, "flexGrow", 1);
2148
+ insertNode(_el$88, createTextNode(`no staged changes`));
2149
+ effect((_p$) => {
2150
+ var _v$13 = props.muted, _v$14 = props.muted, _v$15 = props.muted;
2151
+ _v$13 !== _p$.e && (_p$.e = setProp(_el$77, "fg", _v$13, _p$.e));
2152
+ _v$14 !== _p$.t && (_p$.t = setProp(_el$82, "fg", _v$14, _p$.t));
2153
+ _v$15 !== _p$.a && (_p$.a = setProp(_el$88, "fg", _v$15, _p$.a));
2154
+ return _p$;
2155
+ }, {
2156
+ e: void 0,
2157
+ t: void 0,
2158
+ a: void 0
2159
+ });
2160
+ return _el$73;
2161
+ })();
2162
+ },
2163
+ get children() {
2164
+ var _el$54 = createElement("box"), _el$55 = createElement("box"), _el$56 = createElement("text"), _el$58 = createElement("text"), _el$60 = createElement("box"), _el$61 = createElement("text"), _el$63 = createElement("text"), _el$65 = createElement("box"), _el$66 = createElement("text"), _el$68 = createElement("box"), _el$69 = createElement("text");
2165
+ insertNode(_el$54, _el$55);
2166
+ insertNode(_el$54, _el$58);
2167
+ insertNode(_el$54, _el$60);
2168
+ insertNode(_el$54, _el$63);
2169
+ insertNode(_el$54, _el$65);
2170
+ insertNode(_el$54, _el$68);
2171
+ insertNode(_el$54, _el$69);
2172
+ setProp(_el$54, "flexDirection", "row");
2173
+ insertNode(_el$55, _el$56);
2174
+ setProp(_el$55, "backgroundColor", "#fba970");
2175
+ insertNode(_el$56, createTextNode(` Save `));
2176
+ setProp(_el$56, "fg", "#000000");
2177
+ insertNode(_el$58, createTextNode(` `));
2178
+ insertNode(_el$60, _el$61);
2179
+ setProp(_el$60, "backgroundColor", "#262626");
2180
+ insertNode(_el$61, createTextNode(` Discard `));
2181
+ setProp(_el$61, "fg", "#ffffff");
2182
+ insertNode(_el$63, createTextNode(` `));
2183
+ insertNode(_el$65, _el$66);
2184
+ setProp(_el$65, "backgroundColor", "#262626");
2185
+ insertNode(_el$66, createTextNode(` Reset page `));
2186
+ setProp(_el$66, "fg", "#ffffff");
2187
+ setProp(_el$68, "flexGrow", 1);
2188
+ insertNode(_el$69, createTextNode(`unsaved changes`));
2189
+ effect((_p$) => {
2190
+ var _v$10 = props.muted, _v$11 = props.muted, _v$12 = props.warn ?? "#f59e0b";
2191
+ _v$10 !== _p$.e && (_p$.e = setProp(_el$58, "fg", _v$10, _p$.e));
2192
+ _v$11 !== _p$.t && (_p$.t = setProp(_el$63, "fg", _v$11, _p$.t));
2193
+ _v$12 !== _p$.a && (_p$.a = setProp(_el$69, "fg", _v$12, _p$.a));
2194
+ return _p$;
2195
+ }, {
2196
+ e: void 0,
2197
+ t: void 0,
2198
+ a: void 0
2199
+ });
2200
+ return _el$54;
2201
+ }
2202
+ }), _el$71);
2203
+ insertNode(_el$71, createTextNode(`› or ←/→ change · ↑↓ select · tab next tab · ctrl+s save · ctrl+r reset page · esc close`));
2204
+ effect((_$p) => setProp(_el$71, "fg", props.muted, _$p));
2205
+ return _el$53;
2206
+ })();
2207
+ },
2208
+ get children() {
2209
+ var _el$22 = createElement("box"), _el$23 = createElement("box"), _el$24 = createElement("text"), _el$26 = createElement("box"), _el$27 = createElement("text"), _el$29 = createElement("text"), _el$31 = createElement("box"), _el$32 = createElement("text"), _el$34 = createElement("text"), _el$36 = createElement("box"), _el$37 = createElement("text"), _el$39 = createElement("text");
2210
+ insertNode(_el$22, _el$23);
2211
+ insertNode(_el$22, _el$39);
2212
+ setProp(_el$22, "flexDirection", "column");
2213
+ insertNode(_el$23, _el$24);
2214
+ insertNode(_el$23, _el$26);
2215
+ insertNode(_el$23, _el$29);
2216
+ insertNode(_el$23, _el$31);
2217
+ insertNode(_el$23, _el$34);
2218
+ insertNode(_el$23, _el$36);
2219
+ setProp(_el$23, "flexDirection", "row");
2220
+ insertNode(_el$24, createTextNode(`Keep your changes? `));
2221
+ setProp(_el$24, "attributes", 1);
2222
+ insertNode(_el$26, _el$27);
2223
+ setProp(_el$26, "backgroundColor", "#fba970");
2224
+ insertNode(_el$27, createTextNode(` Save `));
2225
+ setProp(_el$27, "fg", "#000000");
2226
+ insertNode(_el$29, createTextNode(` `));
2227
+ insertNode(_el$31, _el$32);
2228
+ setProp(_el$31, "backgroundColor", "#262626");
2229
+ insertNode(_el$32, createTextNode(` Discard `));
2230
+ setProp(_el$32, "fg", "#ffffff");
2231
+ insertNode(_el$34, createTextNode(` `));
2232
+ insertNode(_el$36, _el$37);
2233
+ setProp(_el$36, "backgroundColor", "#262626");
2234
+ insertNode(_el$37, createTextNode(` Keep editing `));
2235
+ setProp(_el$37, "fg", "#ffffff");
2236
+ insertNode(_el$39, createTextNode(`ctrl+s save · d discard the changes · esc keep editing`));
2237
+ effect((_p$) => {
2238
+ var _v$ = props.warn ?? "#f59e0b", _v$2 = props.muted, _v$3 = props.muted, _v$4 = props.muted;
2239
+ _v$ !== _p$.e && (_p$.e = setProp(_el$24, "fg", _v$, _p$.e));
2240
+ _v$2 !== _p$.t && (_p$.t = setProp(_el$29, "fg", _v$2, _p$.t));
2241
+ _v$3 !== _p$.a && (_p$.a = setProp(_el$34, "fg", _v$3, _p$.a));
2242
+ _v$4 !== _p$.o && (_p$.o = setProp(_el$39, "fg", _v$4, _p$.o));
2243
+ return _p$;
2244
+ }, {
2245
+ e: void 0,
2246
+ t: void 0,
2247
+ a: void 0,
2248
+ o: void 0
2249
+ });
2250
+ return _el$22;
1262
2251
  }
1263
- }), _el$9);
1264
- insert(_el$9, (() => {
1265
- var _c$ = memo(() => !!draftDirty(props.draft()));
1266
- return () => _c$() ? `● unsaved (${draftCount(props.draft())}) — ctrl+s save · ctrl+r reset page` : "no staged changes";
1267
- })());
1268
- insertNode(_el$0, createTextNode(`1-9 tab · ←/→ change value · enter apply · tab next tab · ctrl+s save · ctrl+r reset page · esc/q close`));
2252
+ }), null);
1269
2253
  effect((_p$) => {
1270
- var _v$ = props.fg, _v$2 = props.muted, _v$3 = props.muted, _v$4 = draftDirty(props.draft()) ? props.warn ?? props.fg : props.muted, _v$5 = props.muted;
1271
- _v$ !== _p$.e && (_p$.e = setProp(_el$3, "fg", _v$, _p$.e));
1272
- _v$2 !== _p$.t && (_p$.t = setProp(_el$4, "fg", _v$2, _p$.t));
1273
- _v$3 !== _p$.a && (_p$.a = setProp(_el$6, "fg", _v$3, _p$.a));
1274
- _v$4 !== _p$.o && (_p$.o = setProp(_el$9, "fg", _v$4, _p$.o));
1275
- _v$5 !== _p$.i && (_p$.i = setProp(_el$0, "fg", _v$5, _p$.i));
2254
+ var _v$5 = props.fg, _v$6 = props.muted, _v$7 = props.muted, _v$8 = props.muted, _v$9 = props.muted, _v$0 = props.warn ?? props.fg, _v$1 = props.muted;
2255
+ _v$5 !== _p$.e && (_p$.e = setProp(_el$3, "fg", _v$5, _p$.e));
2256
+ _v$6 !== _p$.t && (_p$.t = setProp(_el$6, "fg", _v$6, _p$.t));
2257
+ _v$7 !== _p$.a && (_p$.a = setProp(_el$0, "fg", _v$7, _p$.a));
2258
+ _v$8 !== _p$.o && (_p$.o = setProp(_el$13, "fg", _v$8, _p$.o));
2259
+ _v$9 !== _p$.i && (_p$.i = setProp(_el$15, "fg", _v$9, _p$.i));
2260
+ _v$0 !== _p$.n && (_p$.n = setProp(_el$18, "fg", _v$0, _p$.n));
2261
+ _v$1 !== _p$.s && (_p$.s = setProp(_el$19, "fg", _v$1, _p$.s));
1276
2262
  return _p$;
1277
2263
  }, {
1278
2264
  e: void 0,
1279
2265
  t: void 0,
1280
2266
  a: void 0,
1281
2267
  o: void 0,
1282
- i: void 0
2268
+ i: void 0,
2269
+ n: void 0,
2270
+ s: void 0
1283
2271
  });
1284
2272
  return _el$;
1285
2273
  })();
1286
2274
  }
1287
2275
  let pageApi;
1288
2276
  function createWindowController(context, exit) {
2277
+ const currentVersion = resolveRunningVersion();
1289
2278
  const [page, setPage] = createSignal(0);
1290
2279
  const [selected, setSelected] = createSignal(0);
1291
2280
  const [load, setLoad] = createSignal(readOverridesLoad());
1292
2281
  const [decision, setDecision] = createSignal(readDecisionRouterConfig());
2282
+ const [goalLoop, setGoalLoop] = createSignal(readGoalLoopPrefs());
2283
+ const [budgets, setBudgets] = createSignal(readDecisionBudgets());
2284
+ const [autonomyRestartPending, setAutonomyRestartPending] = createSignal(false);
1293
2285
  const [presetTick, setPresetTick] = createSignal(0);
2286
+ const [selectedChannel, setSelectedChannel] = createSignal(updateChannelFor(currentVersion));
1294
2287
  const [lastChecked, setLastChecked] = createSignal(void 0);
1295
2288
  const [checking, setChecking] = createSignal(false);
2289
+ const [updating, setUpdating] = createSignal(false);
2290
+ const [changelogItems, setChangelogItems] = createSignal([]);
1296
2291
  const [draft, setDraft] = createSignal({});
1297
2292
  const [notice, setNotice] = createSignal(void 0);
1298
- const currentVersion = resolveRunningVersion$1();
2293
+ const [confirmExit, setConfirmExit] = createSignal(false);
2294
+ readChangelogForBundle(import.meta.url).then((text) => {
2295
+ if (!text) return;
2296
+ const hl = extractHighlights(text, currentVersion);
2297
+ if (hl.found) {
2298
+ const items = [];
2299
+ for (const group of hl.groups) for (const item of group.items) {
2300
+ const dash = item.indexOf("—");
2301
+ const title = dash !== -1 ? item.slice(0, dash).trim() : item.slice(0, 26);
2302
+ items.push({
2303
+ title,
2304
+ detail: item,
2305
+ group: group.heading ?? void 0
2306
+ });
2307
+ }
2308
+ setChangelogItems(items);
2309
+ }
2310
+ });
1299
2311
  const presetInput = () => {
1300
2312
  presetTick();
1301
2313
  return {
@@ -1307,7 +2319,9 @@ function createWindowController(context, exit) {
1307
2319
  const input = {
1308
2320
  currentVersion,
1309
2321
  state: readUpdateCheckState(),
2322
+ selectedChannel: selectedChannel(),
1310
2323
  checking: checking(),
2324
+ updating: updating(),
1311
2325
  nowMs: Date.now()
1312
2326
  };
1313
2327
  const seen = lastChecked();
@@ -1316,11 +2330,17 @@ function createWindowController(context, exit) {
1316
2330
  };
1317
2331
  const tabs = () => [
1318
2332
  buildGatesTab(load()),
1319
- buildDecisionTab(decision()),
2333
+ buildDecisionTab(decision(), process.env, readAuthProviders(), readConfigProviders()),
1320
2334
  buildPresetTab(presetInput()),
1321
2335
  buildTuiTab(tuiPrefs()),
2336
+ buildAutonomyTab({
2337
+ goalLoop: goalLoop(),
2338
+ budgets: budgets(),
2339
+ goalLoopRestartPending: autonomyRestartPending()
2340
+ }),
1322
2341
  buildJ1Tab(process.env, false),
1323
2342
  buildUpdatesTab(updatesInput()),
2343
+ buildChangelogTab(currentVersion, changelogItems()),
1324
2344
  buildDoctorTab({
1325
2345
  runningVersion: currentVersion,
1326
2346
  nodeVersion: process.versions.node,
@@ -1330,26 +2350,70 @@ function createWindowController(context, exit) {
1330
2350
  ];
1331
2351
  const rows = () => tabRows(tabs()[page()] ?? tabs()[0] ?? EMPTY_TAB);
1332
2352
  const move = (delta) => {
2353
+ if (confirmExit()) setConfirmExit(false);
1333
2354
  const list = rows();
1334
2355
  if (list.length === 0) return;
1335
2356
  setSelected((current) => Math.min(Math.max(current + delta, 0), list.length - 1));
1336
2357
  };
1337
2358
  const step = (direction) => {
2359
+ if (confirmExit()) setConfirmExit(false);
1338
2360
  const row = rows()[selected()];
1339
2361
  if (row === void 0) return;
1340
2362
  setNotice(void 0);
1341
2363
  setDraft(stageValue(draft(), row, direction));
1342
2364
  };
1343
- const checkUpdatesNow = () => {
2365
+ const checkUpdatesNow = (targetChannel = selectedChannel()) => {
1344
2366
  if (checking()) return;
1345
2367
  setChecking(true);
1346
2368
  setNotice(void 0);
1347
- fetchLatestForChannel(currentVersion).then((latest) => {
1348
- if (latest) setLastChecked(latest);
1349
- persistUpdateCheckState(readUpdateCheckState(), latest);
2369
+ fetchLatestForChannel(targetChannel).then((latest) => {
2370
+ if (latest) {
2371
+ setLastChecked(latest);
2372
+ persistUpdateCheckState(readUpdateCheckState(), latest);
2373
+ }
1350
2374
  }).catch(() => {}).finally(() => setChecking(false));
1351
2375
  };
2376
+ const runUpdateNow = () => {
2377
+ if (updating()) return;
2378
+ setUpdating(true);
2379
+ setNotice(`updating to ${selectedChannel()} channel…`);
2380
+ execFile("npm", [
2381
+ "install",
2382
+ "-g",
2383
+ `pantheon-opencode@${selectedChannel()}`
2384
+ ], { timeout: 6e4 }, (err) => {
2385
+ setUpdating(false);
2386
+ if (err) {
2387
+ setNotice("run in terminal: pantheon-opencode update");
2388
+ try {
2389
+ context.ui.toast?.show?.({
2390
+ variant: "warning",
2391
+ message: "Update requires terminal permissions: run `pantheon-opencode update`"
2392
+ });
2393
+ } catch {}
2394
+ } else {
2395
+ setNotice("✅ update complete — restart OpenCode or run `npx pantheon-opencode init`");
2396
+ try {
2397
+ context.ui.toast?.show?.({
2398
+ variant: "info",
2399
+ message: "Pantheon updated successfully!"
2400
+ });
2401
+ } catch {}
2402
+ }
2403
+ });
2404
+ };
1352
2405
  const dispatchWrite = (id, value) => {
2406
+ if (id === "update.channel") {
2407
+ if (value === "stable" || value === "beta") {
2408
+ setSelectedChannel(value);
2409
+ checkUpdatesNow(value);
2410
+ return { ok: true };
2411
+ }
2412
+ return {
2413
+ ok: false,
2414
+ reason: "unknown channel"
2415
+ };
2416
+ }
1353
2417
  if (id.startsWith("gate.")) {
1354
2418
  if (!canWriteOverrides(load())) return {
1355
2419
  ok: false,
@@ -1400,6 +2464,31 @@ function createWindowController(context, exit) {
1400
2464
  };
1401
2465
  }
1402
2466
  }
2467
+ if (id === "decision.selection.mode" || id === "decision.selection.target" || id === "decision.consent") {
2468
+ const current = decision();
2469
+ if (current.corrupt) return {
2470
+ ok: false,
2471
+ reason: "decision-router.json unreadable — repair via `decision-router setup-model`"
2472
+ };
2473
+ const staged = applyDecisionRow(current.config, id, value);
2474
+ if (staged === current.config) return {
2475
+ ok: false,
2476
+ reason: "unknown or invalid value"
2477
+ };
2478
+ try {
2479
+ writeDecisionRouterConfig(staged);
2480
+ setDecision({
2481
+ config: staged,
2482
+ corrupt: false
2483
+ });
2484
+ return { ok: true };
2485
+ } catch {
2486
+ return {
2487
+ ok: false,
2488
+ reason: "decision-router disk write failed"
2489
+ };
2490
+ }
2491
+ }
1403
2492
  if (id === "preset") try {
1404
2493
  if (value === "none") clearActivePreset(globalActivePresetPath());
1405
2494
  else writeActivePreset(globalActivePresetPath(), value);
@@ -1408,8 +2497,58 @@ function createWindowController(context, exit) {
1408
2497
  } catch (error) {
1409
2498
  return {
1410
2499
  ok: false,
1411
- reason: error instanceof Error ? error.message : "preset marker write failed"
2500
+ reason: error instanceof Error ? error.message : "preset marker write failed"
2501
+ };
2502
+ }
2503
+ if (id.startsWith("autonomy.goal_loop.")) {
2504
+ const next = { ...goalLoop() };
2505
+ if (id === "autonomy.goal_loop.enabled") next.enabled = value === "enabled";
2506
+ else if (id === "autonomy.goal_loop.maxContinuations") {
2507
+ const parsed = Number(value);
2508
+ if (!Number.isFinite(parsed) || parsed < 1 || parsed > 200) return {
2509
+ ok: false,
2510
+ reason: "max continuations must be 1..200"
2511
+ };
2512
+ next.maxContinuations = Math.floor(parsed);
2513
+ } else if (id === "autonomy.goal_loop.cooldownMs") {
2514
+ const parsed = Number(value);
2515
+ if (!Number.isFinite(parsed) || parsed < 1e3) return {
2516
+ ok: false,
2517
+ reason: "cooldown must be >= 1000ms"
2518
+ };
2519
+ next.cooldownMs = Math.floor(parsed);
2520
+ }
2521
+ try {
2522
+ writeUserOption("goal_loop", next);
2523
+ setGoalLoop(next);
2524
+ setAutonomyRestartPending(true);
2525
+ return { ok: true };
2526
+ } catch {
2527
+ return {
2528
+ ok: false,
2529
+ reason: "opencode.json write failed"
2530
+ };
2531
+ }
2532
+ }
2533
+ if (id === "autonomy.budget.monthly" || id === "autonomy.budget.perDecision") {
2534
+ const parsed = parseUsd(value);
2535
+ if (parsed === null) return {
2536
+ ok: false,
2537
+ reason: "invalid USD value"
1412
2538
  };
2539
+ const next = { ...budgets() };
2540
+ if (id === "autonomy.budget.monthly") next.monthlyUsd = parsed;
2541
+ else next.perDecisionUsd = parsed;
2542
+ try {
2543
+ writeDecisionBudget(next);
2544
+ setBudgets(next);
2545
+ return { ok: true };
2546
+ } catch {
2547
+ return {
2548
+ ok: false,
2549
+ reason: "budget write failed"
2550
+ };
2551
+ }
1413
2552
  }
1414
2553
  if (id.startsWith("tui.")) try {
1415
2554
  mutateTuiPrefs((prefsDraft) => applyTuiRow(prefsDraft, id, value)).then(() => setNotice(void 0)).catch(() => setNotice("tui prefs: persist failed — the change is active for this session only"));
@@ -1439,47 +2578,83 @@ function createWindowController(context, exit) {
1439
2578
  setPresetTick((tick) => tick + 1);
1440
2579
  }
1441
2580
  if (failed.length > 0) setNotice(`${failed.map((f) => `${f.id}: ${f.reason}`).join(" · ")} — staged changes kept`);
1442
- else setNotice(`saved ${applied.length} change${applied.length === 1 ? "" : "s"}`);
2581
+ else {
2582
+ setNotice(`saved ${applied.length} change${applied.length === 1 ? "" : "s"}`);
2583
+ if (confirmExit()) exit();
2584
+ }
1443
2585
  };
1444
2586
  const resetPage = () => {
2587
+ if (confirmExit()) setConfirmExit(false);
1445
2588
  const tab = tabs()[page()];
1446
2589
  if (tab === void 0) return;
1447
2590
  setDraft(resetTab(draft(), tab));
1448
2591
  setNotice(void 0);
1449
2592
  };
2593
+ const stageDefaultsPage = () => {
2594
+ if (confirmExit()) setConfirmExit(false);
2595
+ const tab = tabs()[page()];
2596
+ if (tab === void 0) return;
2597
+ setNotice(void 0);
2598
+ setDraft(stageDefaults(draft(), tab));
2599
+ };
1450
2600
  const nextTab = () => {
2601
+ if (confirmExit()) setConfirmExit(false);
1451
2602
  setPage((current) => (current + 1) % tabs().length);
1452
2603
  setSelected(0);
1453
2604
  };
1454
2605
  const close = () => {
1455
- if (draftDirty(draft())) {
2606
+ const staged = draftCount(draft());
2607
+ if (staged > 0 && !confirmExit()) {
2608
+ setConfirmExit(true);
2609
+ return;
2610
+ }
2611
+ if (staged > 0) {
2612
+ setDraft({});
1456
2613
  try {
1457
- Promise.resolve(context.ui.dialog.confirm({
1458
- title: "Pantheon settings",
1459
- message: "Discard unsaved settings changes?"
1460
- })).then((confirmed) => {
1461
- if (confirmed === true) exit();
2614
+ context.ui.toast?.show?.({
2615
+ variant: "info",
2616
+ message: `settings: ${staged} staged change${staged === 1 ? "" : "s"} discarded`
1462
2617
  });
1463
2618
  } catch {}
1464
- return;
1465
2619
  }
1466
2620
  exit();
1467
2621
  };
2622
+ const discard = () => {
2623
+ const staged = draftCount(draft());
2624
+ setDraft({});
2625
+ setConfirmExit(false);
2626
+ if (staged > 0) try {
2627
+ context.ui.toast?.show?.({
2628
+ variant: "info",
2629
+ message: `settings: ${staged} staged change${staged === 1 ? "" : "s"} discarded`
2630
+ });
2631
+ } catch {}
2632
+ exit();
2633
+ };
2634
+ const cancelExit = () => {
2635
+ setConfirmExit(false);
2636
+ };
2637
+ const selectedId = () => rows()[selected()]?.id;
1468
2638
  return {
1469
2639
  tabs,
1470
2640
  page,
1471
- selected,
2641
+ selectedId,
1472
2642
  draft,
1473
2643
  notice,
2644
+ confirmExit: () => confirmExit(),
1474
2645
  api: {
1475
2646
  move,
1476
2647
  step,
1477
2648
  actuate: () => {
1478
- if (rows()[selected()]?.action === "update-check") checkUpdatesNow();
2649
+ if (confirmExit()) setConfirmExit(false);
2650
+ const row = rows()[selected()];
2651
+ if (row?.action === "update-check") checkUpdatesNow();
2652
+ else if (row?.action === "update-run") runUpdateNow();
1479
2653
  else step(1);
1480
2654
  },
1481
2655
  nextTab,
1482
2656
  jumpTab: (index) => {
2657
+ if (confirmExit()) setConfirmExit(false);
1483
2658
  if (index >= 0 && index < tabs().length) {
1484
2659
  setPage(index);
1485
2660
  setSelected(0);
@@ -1487,7 +2662,11 @@ function createWindowController(context, exit) {
1487
2662
  },
1488
2663
  save,
1489
2664
  resetPage,
1490
- close
2665
+ stageDefaults: stageDefaultsPage,
2666
+ close,
2667
+ discard,
2668
+ cancelExit,
2669
+ confirmExit: () => confirmExit()
1491
2670
  },
1492
2671
  cleanup: () => {
1493
2672
  pageApi = void 0;
@@ -1501,12 +2680,16 @@ function SettingsPage(props) {
1501
2680
  const controller = createWindowController(context, () => navigateBack(context, returnRoute !== void 0 ? { returnRoute } : {}));
1502
2681
  const theme = context.theme?.text ?? {};
1503
2682
  const warn = theme?.feedback?.warning?.base ?? theme.muted;
2683
+ try {
2684
+ const popMode = context.keymap?.mode?.push?.(ROUTE_MODE);
2685
+ if (popMode !== void 0) onCleanup(() => popMode());
2686
+ } catch {}
1504
2687
  onCleanup(controller.cleanup);
1505
2688
  setBlocking(true);
1506
2689
  pageApi = controller.api;
1507
2690
  return createComponent(SettingsWindow, {
1508
2691
  get version() {
1509
- return resolveRunningVersion$1();
2692
+ return resolveRunningVersion();
1510
2693
  },
1511
2694
  get tabs() {
1512
2695
  return controller.tabs;
@@ -1514,8 +2697,8 @@ function SettingsPage(props) {
1514
2697
  get page() {
1515
2698
  return controller.page;
1516
2699
  },
1517
- get selected() {
1518
- return controller.selected;
2700
+ get selectedId() {
2701
+ return controller.selectedId;
1519
2702
  },
1520
2703
  get draft() {
1521
2704
  return controller.draft;
@@ -1523,6 +2706,9 @@ function SettingsPage(props) {
1523
2706
  get notice() {
1524
2707
  return controller.notice;
1525
2708
  },
2709
+ get confirmExit() {
2710
+ return controller.confirmExit;
2711
+ },
1526
2712
  get fg() {
1527
2713
  return theme.base;
1528
2714
  },
@@ -1563,7 +2749,7 @@ function openSettingsDialog(context) {
1563
2749
  try {
1564
2750
  context.ui.dialog.show(() => createComponent(SettingsWindow, {
1565
2751
  get version() {
1566
- return resolveRunningVersion$1();
2752
+ return resolveRunningVersion();
1567
2753
  },
1568
2754
  get tabs() {
1569
2755
  return controller.tabs;
@@ -1571,8 +2757,8 @@ function openSettingsDialog(context) {
1571
2757
  get page() {
1572
2758
  return controller.page;
1573
2759
  },
1574
- get selected() {
1575
- return controller.selected;
2760
+ get selectedId() {
2761
+ return controller.selectedId;
1576
2762
  },
1577
2763
  get draft() {
1578
2764
  return controller.draft;
@@ -1580,6 +2766,9 @@ function openSettingsDialog(context) {
1580
2766
  get notice() {
1581
2767
  return controller.notice;
1582
2768
  },
2769
+ get confirmExit() {
2770
+ return controller.confirmExit;
2771
+ },
1583
2772
  get fg() {
1584
2773
  return theme.base;
1585
2774
  },
@@ -1617,7 +2806,37 @@ function setupPantheonSettings(context) {
1617
2806
  title: "Close settings",
1618
2807
  bind: "escape,q",
1619
2808
  run: () => {
1620
- pageApi?.close();
2809
+ try {
2810
+ context.ui.toast?.show?.({
2811
+ variant: "info",
2812
+ message: "settings: close command fired"
2813
+ });
2814
+ } catch {}
2815
+ if (pageApi === void 0) {
2816
+ try {
2817
+ context.ui.toast?.show?.({
2818
+ variant: "warning",
2819
+ message: "settings: no window controller bound"
2820
+ });
2821
+ } catch {}
2822
+ return;
2823
+ }
2824
+ if (pageApi.confirmExit?.()) {
2825
+ pageApi.cancelExit?.();
2826
+ return;
2827
+ }
2828
+ pageApi.close();
2829
+ }
2830
+ },
2831
+ {
2832
+ id: "pantheon.settings.discard",
2833
+ title: "Discard staged changes and exit",
2834
+ bind: "d",
2835
+ run: () => {
2836
+ if (pageApi?.confirmExit?.()) {
2837
+ pageApi.discard?.();
2838
+ return;
2839
+ }
1621
2840
  }
1622
2841
  },
1623
2842
  {
@@ -1684,6 +2903,14 @@ function setupPantheonSettings(context) {
1684
2903
  pageApi?.resetPage();
1685
2904
  }
1686
2905
  },
2906
+ {
2907
+ id: "pantheon.settings.defaults",
2908
+ title: "Stage defaults for this tab",
2909
+ bind: "ctrl+d",
2910
+ run: () => {
2911
+ pageApi?.stageDefaults();
2912
+ }
2913
+ },
1687
2914
  ...Array.from({ length: 9 }, (_, index) => ({
1688
2915
  id: `pantheon.settings.tab.${index + 1}`,
1689
2916
  title: `Jump to tab ${index + 1}`,
@@ -1695,7 +2922,7 @@ function setupPantheonSettings(context) {
1695
2922
  ];
1696
2923
  try {
1697
2924
  context.keymap.layer(() => ({
1698
- mode: "global",
2925
+ mode: ROUTE_MODE,
1699
2926
  priority: 1,
1700
2927
  enabled: () => routeGated(),
1701
2928
  commands
@@ -1716,7 +2943,7 @@ async function openPantheonSettings(context) {
1716
2943
  let returnRoute;
1717
2944
  try {
1718
2945
  const current = context.ui.router.current();
1719
- if (!(current.type === "plugin" && current.name === "pantheon-settings")) returnRoute = current;
2946
+ if (!(current.type === "plugin" && current.name === "pantheon-settings")) returnRoute = plainRoute(current);
1720
2947
  } catch {
1721
2948
  returnRoute = void 0;
1722
2949
  }
@@ -1852,214 +3079,6 @@ function cellWidth(value) {
1852
3079
  for (const { segment } of GRAPHEMES.segment(value)) width += graphemeWidth(segment);
1853
3080
  return width;
1854
3081
  }
1855
- /** Prefix of the "+N more" line appended when the bullet budget is exceeded. */
1856
- const WHATS_NEW_MORE_PREFIX = "… +";
1857
- const EMPTY_HIGHLIGHTS = {
1858
- version: null,
1859
- found: false,
1860
- groups: [],
1861
- totalItems: 0,
1862
- truncated: false
1863
- };
1864
- /** Escape regex metacharacters so a version like 1.0.0 matches literally. */
1865
- function escapeRegExp(text) {
1866
- return text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
1867
- }
1868
- /**
1869
- * Extract the body of a version section from changelog text — inline replica
1870
- * of scripts/changelog-extract.mjs `extractSection` (see that file for the
1871
- * full contract: `## [<version>] - YYYY-MM-DD`, leading `v` and the date
1872
- * optional, `## [Unreleased]` never matched).
1873
- */
1874
- function extractSection(changelogText, version) {
1875
- const normalized = String(version).trim().replace(/^v/i, "");
1876
- if (!normalized || /^unreleased$/i.test(normalized)) return {
1877
- found: false,
1878
- body: null
1879
- };
1880
- const escaped = escapeRegExp(normalized);
1881
- const match = new RegExp(`^##[ \\t]+\\[v?${escaped}\\](?:[ \\t]*-[ \\t]*\\d{4}-\\d{2}-\\d{2})?(?=[ \\t]|$)`, "m").exec(changelogText);
1882
- if (!match) return {
1883
- found: false,
1884
- body: null
1885
- };
1886
- const newline = changelogText.indexOf("\n", match.index);
1887
- const start = newline === -1 ? changelogText.length : newline + 1;
1888
- const nextHeading = /^##[ \t]+\[/m.exec(changelogText.slice(start));
1889
- const end = nextHeading ? start + nextHeading.index : changelogText.length;
1890
- return {
1891
- found: true,
1892
- body: changelogText.slice(start, end).trim()
1893
- };
1894
- }
1895
- /**
1896
- * Reduce one markdown line to plain text: links keep their label, emphasis
1897
- * and inline-code markers are dropped, HTML comment fragments are removed,
1898
- * and whitespace collapses. Deliberately simple — the input is our own
1899
- * CHANGELOG (lint-capped at 200 chars per bullet), not hostile input.
1900
- */
1901
- function stripMarkdown(text) {
1902
- return text.replace(/<!--[\s\S]*?-->/g, " ").replace(/\[([^\]]+)\]\([^)]*\)/g, "$1").replace(/(\*\*|__)/g, "").replace(/`/g, "").replace(/\s+/g, " ").trim();
1903
- }
1904
- /** Strip the leading H3 marker (`### Added` → `Added`). */
1905
- function stripHeading(text) {
1906
- return text.replace(/^#{1,6}[ \t]+/, "").trim();
1907
- }
1908
- /**
1909
- * Extract the curated summary block (`### 🆕 What's New` or `## 🆕 What's New`)
1910
- * from a section body: its bullets only, each truncated to
1911
- * WHATS_NEW_ITEM_MAX_CHARS, capped to WHATS_NEW_SUMMARY_MAX_ITEMS. Null when
1912
- * the section carries no summary block (the full-section fallback applies).
1913
- */
1914
- function extractWhatsNewSummary(body) {
1915
- const lines = body.split("\n");
1916
- const start = lines.findIndex((line) => /^#{2,3}[ \t]+.*What'?s New/i.test(line.trim()));
1917
- if (start === -1) return null;
1918
- const items = [];
1919
- for (const rawLine of lines.slice(start + 1)) {
1920
- const line = rawLine.trim();
1921
- if (line === "" || line.startsWith("<!--")) continue;
1922
- if (/^#{1,6}[ \t]/.test(line)) break;
1923
- if (!/^[-*][ \t]/.test(line)) continue;
1924
- if (items.length >= 6) break;
1925
- const content = stripMarkdown(line.replace(/^[-*][ \t]+/, ""));
1926
- if (content === "") continue;
1927
- items.push(content.length > 140 ? `${content.slice(0, 139)}…` : content);
1928
- }
1929
- return items.length > 0 ? items : null;
1930
- }
1931
- /**
1932
- * Extract the release highlights for `version`. When the section carries a
1933
- * curated `🆕 What's New` summary block, THE WINDOW SHOWS ONLY THAT (the
1934
- * full Added/Changed/Fixed walls are for the CHANGELOG readers, not the
1935
- * dialog); otherwise it falls back to the H3-group extraction bounded to
1936
- * WHATS_NEW_MAX_ITEMS bullets. A missing section, a bullet-less section or a
1937
- * blank changelog all return EMPTY_HIGHLIGHTS (no window).
1938
- */
1939
- function extractHighlights(changelogText, version) {
1940
- const { found, body } = extractSection(changelogText ?? "", version ?? "");
1941
- if (!found || !body) return { ...EMPTY_HIGHLIGHTS };
1942
- const summary = extractWhatsNewSummary(body);
1943
- if (summary !== null) return {
1944
- version: String(version).trim().replace(/^v/i, ""),
1945
- found: true,
1946
- groups: [{
1947
- heading: null,
1948
- items: summary
1949
- }],
1950
- totalItems: summary.length,
1951
- truncated: false
1952
- };
1953
- const groups = [];
1954
- let totalItems = 0;
1955
- let truncated = false;
1956
- for (const rawLine of body.split("\n")) {
1957
- const line = rawLine.trim();
1958
- if (line === "" || line.startsWith("<!--")) continue;
1959
- if (/^#{1,6}[ \t]/.test(line)) {
1960
- const heading = stripMarkdown(stripHeading(line));
1961
- if (heading === "") continue;
1962
- if (groups.at(-1)?.items.length === 0) groups.pop();
1963
- groups.push({
1964
- heading,
1965
- items: []
1966
- });
1967
- continue;
1968
- }
1969
- if (totalItems >= 12) {
1970
- if (/^[-*][ \t]/.test(line)) totalItems += 1;
1971
- continue;
1972
- }
1973
- const isBullet = /^[-*][ \t]/.test(line);
1974
- const continuation = (groups.at(-1)?.items.length ?? 0) > 0;
1975
- if (!isBullet && !continuation) continue;
1976
- const content = stripMarkdown(isBullet ? line.replace(/^[-*][ \t]+/, "") : line);
1977
- if (content === "") continue;
1978
- const bounded = content.length > 140 ? `${content.slice(0, 139)}…` : content;
1979
- const group = groups.at(-1);
1980
- if (group === void 0) groups.push({
1981
- heading: null,
1982
- items: [bounded]
1983
- });
1984
- else if (isBullet || group.items.length === 0) group.items.push(bounded);
1985
- else group.items[group.items.length - 1] = `${group.items.at(-1)} ${bounded}`.trim();
1986
- if (isBullet) totalItems += 1;
1987
- }
1988
- const kept = groups.filter((group) => group.items.length > 0);
1989
- truncated = totalItems > 12;
1990
- return {
1991
- version: found ? String(version).trim().replace(/^v/i, "") : null,
1992
- found,
1993
- groups: kept,
1994
- totalItems,
1995
- truncated
1996
- };
1997
- }
1998
- /** Window title — mirrors the sidebar's `Pantheon v<version>` convention. */
1999
- function whatsNewTitle(version) {
2000
- return `O que há de novo — Pantheon v${String(version).trim().replace(/^v/i, "")}`;
2001
- }
2002
- /** Flat display lines for the window: group headings, `• ` bullets, `+N more`. */
2003
- function whatsNewLines(highlights) {
2004
- const lines = [];
2005
- for (const group of highlights.groups) {
2006
- if (group.heading !== null) lines.push(group.heading);
2007
- for (const item of group.items) lines.push(`• ${item}`);
2008
- }
2009
- if (highlights.truncated) {
2010
- const hidden = Math.max(0, highlights.totalItems - 12);
2011
- if (hidden > 0) lines.push(`${WHATS_NEW_MORE_PREFIX}${hidden} mais`);
2012
- }
2013
- return lines;
2014
- }
2015
- /**
2016
- * Candidate CHANGELOG.md locations for a bundle, first readable wins:
2017
- * 1. the plugin copy root (`<configDir>/plugins/pantheon-tui/CHANGELOG.md`,
2018
- * shipped by both installers next to package.json);
2019
- * 2. the package root (dev checkout; also an npm-package install when the
2020
- * bundle runs from `<pkg>/src/plugins/tui/dist/`).
2021
- */
2022
- function changelogCandidates(bundlePath) {
2023
- const dist = dirname(bundlePath);
2024
- const copyRoot = dirname(dist);
2025
- const packageRoot = dirname(dirname(dirname(copyRoot)));
2026
- return [join(copyRoot, "CHANGELOG.md"), join(packageRoot, "CHANGELOG.md")];
2027
- }
2028
- /** Read the first existing candidate; null when none is readable (no window). */
2029
- async function readChangelogForBundle(bundleUrl) {
2030
- try {
2031
- const bundlePath = fileURLToPath(bundleUrl);
2032
- for (const candidate of changelogCandidates(bundlePath)) try {
2033
- return await readFile(candidate, "utf8");
2034
- } catch {}
2035
- return null;
2036
- } catch {
2037
- return null;
2038
- }
2039
- }
2040
- /** The ambient build-time version, or null outside a tsdown build. */
2041
- function embeddedVersion() {
2042
- return "2.0.0-beta.5";
2043
- }
2044
- /**
2045
- * Resolve the running Pantheon version for the what's-new window: the plugin
2046
- * copy's own package.json first (the copy root two levels above the bundle,
2047
- * then the package root four levels above — the same legs as the V1 sidebar's
2048
- * detectVersion try 0a/0b), falling back to the tsdown build embed. Null when
2049
- * nothing resolves → no window (fail-open).
2050
- */
2051
- async function resolveRunningVersion(bundleUrl, embedded = embeddedVersion()) {
2052
- try {
2053
- const bundlePath = fileURLToPath(bundleUrl);
2054
- const dist = dirname(bundlePath);
2055
- for (const root of [dirname(dist), dirname(dirname(dirname(dist)))]) try {
2056
- const raw = await readFile(join(root, "package.json"), "utf8");
2057
- const parsed = JSON.parse(raw);
2058
- if (typeof parsed.version === "string" && parsed.version.trim() !== "") return parsed.version;
2059
- } catch {}
2060
- } catch {}
2061
- return embedded;
2062
- }
2063
3082
  //#endregion
2064
3083
  //#region src/whats-new-state.ts
2065
3084
  /**
@@ -2326,7 +3345,7 @@ function WhatsNewContent(props) {
2326
3345
  */
2327
3346
  async function maybeShowWhatsNewV2(context) {
2328
3347
  try {
2329
- const version = await resolveRunningVersion(import.meta.url);
3348
+ const version = await resolveRunningVersion$1(import.meta.url);
2330
3349
  if (!version) return;
2331
3350
  const statePath = await defaultWhatsNewStatePath();
2332
3351
  const changelogText = await readChangelogForBundle(import.meta.url);
@@ -2888,7 +3907,7 @@ function turnTokensPerSecond(messages, position) {
2888
3907
  * unavailable (never `undefined%`). A block with neither tokens nor cost
2889
3908
  * yields null. `gaugeStyle` (the TUI tab's pref) picks the percent-row
2890
3909
  * shape: `both` (default), `bar`, `percent`, or `off` (row omitted). Pure. */
2891
- function contextBlockRows(usage, cost, gaugeStyle = "both") {
3910
+ function contextBlockRows(usage, cost, gaugeStyle = "both", barOptions) {
2892
3911
  const spentValue = formatSpent(cost);
2893
3912
  const spent = spentValue === null ? null : {
2894
3913
  lead: null,
@@ -2912,7 +3931,7 @@ function contextBlockRows(usage, cost, gaugeStyle = "both") {
2912
3931
  };
2913
3932
  const percentValue = numberOrNull(usage.percent);
2914
3933
  const window = formatContextWindow(usage.limit);
2915
- const bar = contextBar(percentValue);
3934
+ const bar = contextBar(percentValue, barOptions ?? 12);
2916
3935
  let percent = null;
2917
3936
  if (gaugeStyle !== "off" && bar !== null && percentValue !== null) {
2918
3937
  const suffix = window === null ? null : ` of ${window}`;
@@ -4697,7 +5716,7 @@ async function checkForPantheonUpdate(context) {
4697
5716
  const latest = String((await response.json())?.version ?? "");
4698
5717
  if (!latest) return;
4699
5718
  const notice = pickUpdateNotice({
4700
- currentVersion: "2.0.0-beta.5",
5719
+ currentVersion: "2.0.0-rc.1",
4701
5720
  latestVersion: latest,
4702
5721
  state: readState(),
4703
5722
  nowMs: Date.now()
@@ -5461,7 +6480,12 @@ function Sidebar(props) {
5461
6480
  const usageHidden = () => hiddenModelUsageText(model.modelUsage().hidden, model.modelUsage().hiddenCost);
5462
6481
  const contextRows = () => {
5463
6482
  const prefs = tuiPrefs();
5464
- const rows = contextBlockRows(model.contextUsage(), model.cost(), prefs.sidebar.context.gauge);
6483
+ const barCells = prefs.sidebar.context.barWidth === "compact" ? 8 : prefs.sidebar.context.barWidth === "wide" ? 16 : prefs.sidebar.context.barWidth === "full" ? 20 : 12;
6484
+ const rows = contextBlockRows(model.contextUsage(), model.cost(), prefs.sidebar.context.gauge, {
6485
+ shape: prefs.sidebar.context.barShape,
6486
+ cells: barCells,
6487
+ evenMark: prefs.sidebar.context.evenMark
6488
+ });
5465
6489
  if (rows === null) return null;
5466
6490
  return {
5467
6491
  tokens: prefs.sidebar.context.tokens ? rows.tokens : null,
@@ -5484,7 +6508,8 @@ function Sidebar(props) {
5484
6508
  var _el$12 = createElement("box");
5485
6509
  setProp(_el$12, "flexDirection", "column");
5486
6510
  setProp(_el$12, "width", "100%");
5487
- setProp(_el$12, "padding", 1);
6511
+ setProp(_el$12, "paddingLeft", 1);
6512
+ setProp(_el$12, "paddingRight", 1);
5488
6513
  insert(_el$12, createComponent(Show, {
5489
6514
  get when() {
5490
6515
  return header().version;
@@ -5492,7 +6517,7 @@ function Sidebar(props) {
5492
6517
  get children() {
5493
6518
  var _el$13 = createElement("text");
5494
6519
  setProp(_el$13, "attributes", 1);
5495
- insert(_el$13, `Pantheon v2.0.0-beta.5`);
6520
+ insert(_el$13, `Pantheon v2.0.0-rc.1`);
5496
6521
  effect((_$p) => setProp(_el$13, "fg", text(), _$p));
5497
6522
  return _el$13;
5498
6523
  }
@@ -5762,9 +6787,9 @@ function Sidebar(props) {
5762
6787
  insertNode(_el$39, createTextNode(`⎇ `));
5763
6788
  insert(_el$41, () => truncateLabel(value(), 32));
5764
6789
  effect((_p$) => {
5765
- var _v$3 = muted(), _v$4 = text();
5766
- _v$3 !== _p$.e && (_p$.e = setProp(_el$39, "fg", _v$3, _p$.e));
5767
- _v$4 !== _p$.t && (_p$.t = setProp(_el$41, "fg", _v$4, _p$.t));
6790
+ var _v$5 = muted(), _v$6 = text();
6791
+ _v$5 !== _p$.e && (_p$.e = setProp(_el$39, "fg", _v$5, _p$.e));
6792
+ _v$6 !== _p$.t && (_p$.t = setProp(_el$41, "fg", _v$6, _p$.t));
5768
6793
  return _p$;
5769
6794
  }, {
5770
6795
  e: void 0,
@@ -5900,9 +6925,9 @@ function Sidebar(props) {
5900
6925
  setProp(_el$47, "flexShrink", 0);
5901
6926
  insert(_el$48, () => row.text);
5902
6927
  effect((_p$) => {
5903
- var _v$5 = open(row.id), _v$6 = tone("success");
5904
- _v$5 !== _p$.e && (_p$.e = setProp(_el$47, "onMouseDown", _v$5, _p$.e));
5905
- _v$6 !== _p$.t && (_p$.t = setProp(_el$48, "fg", _v$6, _p$.t));
6928
+ var _v$7 = open(row.id), _v$8 = tone("success");
6929
+ _v$7 !== _p$.e && (_p$.e = setProp(_el$47, "onMouseDown", _v$7, _p$.e));
6930
+ _v$8 !== _p$.t && (_p$.t = setProp(_el$48, "fg", _v$8, _p$.t));
5906
6931
  return _p$;
5907
6932
  }, {
5908
6933
  e: void 0,
@@ -5975,6 +7000,15 @@ function Sidebar(props) {
5975
7000
  return _el$23;
5976
7001
  }
5977
7002
  }), null);
7003
+ effect((_p$) => {
7004
+ var _v$3 = tuiPrefs().layout.preset === "compact" ? 0 : 1, _v$4 = tuiPrefs().layout.preset === "compact" ? 0 : 1;
7005
+ _v$3 !== _p$.e && (_p$.e = setProp(_el$12, "paddingTop", _v$3, _p$.e));
7006
+ _v$4 !== _p$.t && (_p$.t = setProp(_el$12, "paddingBottom", _v$4, _p$.t));
7007
+ return _p$;
7008
+ }, {
7009
+ e: void 0,
7010
+ t: void 0
7011
+ });
5978
7012
  return _el$12;
5979
7013
  })();
5980
7014
  }
@@ -6052,10 +7086,10 @@ function DispatchPanel(props) {
6052
7086
  insert(_el$55, () => selected(row.id) ? `▸ ` : " ");
6053
7087
  insert(_el$56, () => row.text);
6054
7088
  effect((_p$) => {
6055
- var _v$7 = selected(row.id) ? text() : muted(), _v$8 = rowFg(row.state), _v$9 = selected(row.id) ? 1 : 0;
6056
- _v$7 !== _p$.e && (_p$.e = setProp(_el$55, "fg", _v$7, _p$.e));
6057
- _v$8 !== _p$.t && (_p$.t = setProp(_el$56, "fg", _v$8, _p$.t));
6058
- _v$9 !== _p$.a && (_p$.a = setProp(_el$56, "attributes", _v$9, _p$.a));
7089
+ var _v$9 = selected(row.id) ? text() : muted(), _v$0 = rowFg(row.state), _v$1 = selected(row.id) ? 1 : 0;
7090
+ _v$9 !== _p$.e && (_p$.e = setProp(_el$55, "fg", _v$9, _p$.e));
7091
+ _v$0 !== _p$.t && (_p$.t = setProp(_el$56, "fg", _v$0, _p$.t));
7092
+ _v$1 !== _p$.a && (_p$.a = setProp(_el$56, "attributes", _v$1, _p$.a));
6059
7093
  return _p$;
6060
7094
  }, {
6061
7095
  e: void 0,
@@ -6187,10 +7221,10 @@ function DispatchPanel(props) {
6187
7221
  setProp(_el$66, "height", 1);
6188
7222
  insert(_el$67, () => model.footer());
6189
7223
  effect((_p$) => {
6190
- var _v$0 = text(), _v$1 = muted(), _v$10 = muted();
6191
- _v$0 !== _p$.e && (_p$.e = setProp(_el$61, "fg", _v$0, _p$.e));
6192
- _v$1 !== _p$.t && (_p$.t = setProp(_el$62, "fg", _v$1, _p$.t));
6193
- _v$10 !== _p$.a && (_p$.a = setProp(_el$67, "fg", _v$10, _p$.a));
7224
+ var _v$10 = text(), _v$11 = muted(), _v$12 = muted();
7225
+ _v$10 !== _p$.e && (_p$.e = setProp(_el$61, "fg", _v$10, _p$.e));
7226
+ _v$11 !== _p$.t && (_p$.t = setProp(_el$62, "fg", _v$11, _p$.t));
7227
+ _v$12 !== _p$.a && (_p$.a = setProp(_el$67, "fg", _v$12, _p$.a));
6194
7228
  return _p$;
6195
7229
  }, {
6196
7230
  e: void 0,
@@ -6255,7 +7289,7 @@ function HomeStatus(props) {
6255
7289
  },
6256
7290
  get children() {
6257
7291
  var _el$73 = createElement("text");
6258
- insert(_el$73, () => `Pantheon v2.0.0-beta.5${preset().name ? ` ▸ ${preset().name}` : ""}`);
7292
+ insert(_el$73, () => `Pantheon v2.0.0-rc.1${preset().name ? ` ▸ ${preset().name}` : ""}`);
6259
7293
  effect((_$p) => setProp(_el$73, "fg", muted(), _$p));
6260
7294
  return _el$73;
6261
7295
  }