pantheon-opencode 2.0.0-beta.3 → 2.0.0-beta.4

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.
@@ -59,6 +59,25 @@ function formatSpent(cost) {
59
59
  const MODEL_USAGE_VISIBLE_CEILING = 3;
60
60
  const MODEL_USAGE_MESSAGE_LIMIT = 400;
61
61
  const MODEL_USAGE_SESSION_LIMIT = 8;
62
+ //#endregion
63
+ //#region src/decision-router-state.ts
64
+ /**
65
+ * decision-router-state.ts — the Decision Model section of the settings window.
66
+ *
67
+ * TUI-local replica of the user-level decision-router config
68
+ * (scripts/install/decision-router-config.mjs — the bundle must stay
69
+ * self-contained); tests/tui-decision-router-state.test.mjs pins the schema
70
+ * version, the exact key set and the provider matrix against that source.
71
+ *
72
+ * The runtime re-reads this file on EVERY gated call (jev-decision-tool.ts),
73
+ * so a write here applies live — no restart. The strict exact-key schema is
74
+ * load-bearing: any unknown key fail-closes the runtime to disabled/local,
75
+ * so the writer validates before persisting.
76
+ *
77
+ * Egress consent is CLI-owned: the window never writes `egress_consent`, and
78
+ * refuses to enable the router while remote candidates exist without it.
79
+ */
80
+ const DECISION_ENABLED_CYCLE = Object.freeze(["enabled", "disabled"]);
62
81
  /** Exact top-level key set — anything else fail-closes the runtime. */
63
82
  const DECISION_CONFIG_KEYS = Object.freeze([
64
83
  "egress_consent",
@@ -203,30 +222,33 @@ function writeDecisionRouterConfig(config, env = process.env) {
203
222
  renameSync(temp, path);
204
223
  chmodSync(path, 384);
205
224
  }
206
- function buildDecisionSection(read) {
225
+ function buildDecisionTab(read) {
207
226
  const { config, corrupt } = read;
208
227
  const rows = [{
209
228
  id: "decision.enabled",
210
- title: `Decision router: ${config.enabled ? "enabled" : "disabled"}`,
211
- description: corrupt ? "config file unreadable/invalid — the runtime fail-closes to disabled" : "the runtime re-reads this file on every gated call — applies live",
212
- disabled: !config.enabled
229
+ name: "Router",
230
+ value: config.enabled ? "enabled" : "disabled",
231
+ ...corrupt ? {} : { cycle: DECISION_ENABLED_CYCLE },
232
+ 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"
213
233
  }, {
214
234
  id: "decision.selection",
215
- title: `Selection: ${config.selection.mode}${config.selection.provider ? ` · ${config.selection.provider}` : ""}`,
216
- description: "local routes on-device; auto/explicit pick a remote decision model",
217
- selectable: false
235
+ name: "Selection",
236
+ value: `${config.selection.mode}${config.selection.provider ? ` · ${config.selection.provider}` : ""}`,
237
+ note: "local routes on-device; auto/explicit pick a remote decision model"
218
238
  }];
219
239
  if (config.enabled_candidates.length > 0) rows.push({
220
240
  id: "decision.candidates",
221
- title: `Candidates: ${config.enabled_candidates.map((candidate) => `${candidate.provider}/${candidate.model}`).join(", ")}`,
222
- description: config.egress_consent ? "egress consent granted" : "egress consent NOT granted — remote routes fail closed",
223
- selectable: false
241
+ name: "Candidates",
242
+ value: String(config.enabled_candidates.length),
243
+ note: config.egress_consent ? config.enabled_candidates.map((candidate) => `${candidate.provider}/${candidate.model}`).join(", ") : "egress consent NOT granted — remote routes fail closed"
224
244
  });
225
245
  return {
226
246
  id: "decision",
227
- title: "Decision Model",
228
- rows,
229
- hint: corrupt ? "repair via `decision-router setup-model` — writes refused on an invalid file" : "enter: enable/disable · consent and candidates via `decision-router setup-model`"
247
+ title: "Decision",
248
+ groups: [{
249
+ title: "Decision router",
250
+ rows
251
+ }]
230
252
  };
231
253
  }
232
254
  //#endregion
@@ -280,38 +302,11 @@ new Set(SETTINGS_BEHAVIORS.map((b) => b.id));
280
302
  function isBehaviorDisabled(effective, id) {
281
303
  return effective[id]?.action === "disable";
282
304
  }
283
- /** The rows up/down can reach and enter can dispatch on, in order. */
284
- function selectableRows(section) {
285
- return section.rows.filter((row) => row.selectable !== false);
286
- }
287
- /** Flat selection order across every section of the window. */
288
- function flatSelectableRows(sections) {
289
- return sections.flatMap((section) => selectableRows(section));
290
- }
291
- function firstSelectableId(sections) {
292
- return flatSelectableRows(sections)[0]?.id;
293
- }
294
- /**
295
- * Merge for DISPLAY only, mirroring the runtime precedence: the project file
296
- * wins per id (whole entry). The window still writes only the global file.
297
- */
298
- function mergedOverrides(load) {
299
- return {
300
- ...load.global,
301
- ...load.project
302
- };
303
- }
304
- function canWriteOverrides(load) {
305
- return !load.corruptGlobal;
306
- }
307
305
  const TOGGLE_REASON = "toggled in /pantheon-settings";
308
306
  /**
309
- * Toggle: disabled -> enabled; enabled -> disabled.
310
- *
311
- * A `replace` entry is never destroyed by a toggle ("never trap user state"):
312
- * disabling keeps its `content` under the disable entry, and re-enabling
313
- * restores the replace. A settings-written disable (no content) is removed
314
- * outright so the overrides file does not accumulate toggle noise.
307
+ * Toggle (a targeted write keeps the toggle semantics: a `replace` entry is
308
+ * never destroyed — disabling keeps its `content`, re-enabling restores the
309
+ * replace; a settings-written disable is removed outright, no toggle noise).
315
310
  */
316
311
  function toggledOverrides(effective, id, reason = TOGGLE_REASON) {
317
312
  const next = { ...effective };
@@ -336,64 +331,142 @@ function toggledOverrides(effective, id, reason = TOGGLE_REASON) {
336
331
  };
337
332
  return next;
338
333
  }
334
+ /** Set an explicit on/off target (the cycler's save path) via the toggle semantics. */
335
+ function setOverrideState(effective, id, target, reason = TOGGLE_REASON) {
336
+ const disabled = isBehaviorDisabled(effective, id);
337
+ if (target === "disabled" === disabled) return effective;
338
+ return toggledOverrides(effective, id, reason);
339
+ }
339
340
  function serializeOverrides(effective) {
340
341
  const ordered = {};
341
342
  for (const id of Object.keys(effective).sort()) ordered[id] = effective[id];
342
343
  return `${JSON.stringify(ordered, null, 2)}\n`;
343
344
  }
344
- /**
345
- * The Gates & Overrides page: behavior state from BOTH overrides files.
346
- * A project-owned entry wins the runtime merge and the window only writes
347
- * the global file, so project rows are marked and not togglable here.
348
- */
349
- function buildGatesSection(load) {
345
+ /** Merge for DISPLAY only, mirroring the runtime precedence: project wins per id. */
346
+ function mergedOverrides(load) {
347
+ return {
348
+ ...load.global,
349
+ ...load.project
350
+ };
351
+ }
352
+ function canWriteOverrides(load) {
353
+ return !load.corruptGlobal;
354
+ }
355
+ /** Neutral tab for out-of-range indexes (noUncheckedIndexedAccess guard). */
356
+ const EMPTY_TAB = {
357
+ id: "empty",
358
+ title: "",
359
+ groups: []
360
+ };
361
+ /** Flat, in-order rows of a tab (the up/down navigation space). */
362
+ function tabRows(tab) {
363
+ return tab.groups.flatMap((group) => group.rows);
364
+ }
365
+ /** Step through the cycle with wrap-around; non-cyclable rows return the input. */
366
+ function cycleValue(value, cycle, direction) {
367
+ if (cycle.length === 0) return value;
368
+ const index = cycle.indexOf(value);
369
+ if (index === -1) return cycle[0] ?? value;
370
+ return cycle[(index + direction + cycle.length) % cycle.length] ?? value;
371
+ }
372
+ function stageValue(draft, row, direction) {
373
+ if (row.cycle === void 0) return draft;
374
+ const staged = cycleValue(draft[row.id] ?? row.value, row.cycle, direction);
375
+ if (staged === row.value) {
376
+ if (draft[row.id] === void 0) return draft;
377
+ const next = { ...draft };
378
+ delete next[row.id];
379
+ return next;
380
+ }
381
+ return {
382
+ ...draft,
383
+ [row.id]: staged
384
+ };
385
+ }
386
+ /** Drop every staged entry of one tab (ctrl+r). */
387
+ function resetTab(draft, tab) {
388
+ const ids = new Set(tabRows(tab).map((row) => row.id));
389
+ const next = {};
390
+ for (const [id, value] of Object.entries(draft)) if (!ids.has(id)) next[id] = value;
391
+ return next;
392
+ }
393
+ function draftCount(draft) {
394
+ return Object.keys(draft).length;
395
+ }
396
+ function draftDirty(draft) {
397
+ return draftCount(draft) > 0;
398
+ }
399
+ function tabDirty(draft, tab) {
400
+ return tabRows(tab).some((row) => draft[row.id] !== void 0);
401
+ }
402
+ /** Apply every staged entry; failures are collected, never thrown. */
403
+ function applyDraft(draft, writer) {
404
+ const applied = [];
405
+ const failed = [];
406
+ for (const [id, value] of Object.entries(draft)) {
407
+ const result = writer(id, value);
408
+ if (result.ok) applied.push(id);
409
+ else failed.push({
410
+ id,
411
+ reason: result.reason ?? "write failed"
412
+ });
413
+ }
414
+ return {
415
+ applied,
416
+ failed
417
+ };
418
+ }
419
+ /** The rows that succeeded and are still in the draft (failed ones stay staged). */
420
+ function settledDraft(draft, applied) {
421
+ const next = {};
422
+ for (const [id, value] of Object.entries(draft)) if (!applied.includes(id)) next[id] = value;
423
+ return next;
424
+ }
425
+ const GATES_ENABLED_CYCLE = Object.freeze(["enabled", "disabled"]);
426
+ function buildGatesTab(load) {
350
427
  const merged = mergedOverrides(load);
351
- const rows = SETTINGS_BEHAVIORS.map((behavior) => {
428
+ const rowFor = (behavior) => {
352
429
  const fromProject = load.project[behavior.id] !== void 0;
430
+ const writable = !fromProject && canWriteOverrides(load);
353
431
  return {
354
432
  id: `gate.${behavior.id}`,
355
- title: fromProject ? `${behavior.title} (project)` : behavior.title,
356
- description: behavior.description,
357
- disabled: isBehaviorDisabled(merged, behavior.id),
358
- selectable: !fromProject,
359
- source: fromProject ? "project" : "global"
433
+ name: fromProject ? `${behavior.title} (project)` : behavior.title,
434
+ value: isBehaviorDisabled(merged, behavior.id) ? "disabled" : "enabled",
435
+ ...writable ? { cycle: GATES_ENABLED_CYCLE } : {},
436
+ note: fromProject ? "project file wins at runtime — edit .pantheon/overrides.json" : behavior.description
360
437
  };
361
- });
438
+ };
439
+ const install = SETTINGS_BEHAVIORS.filter((behavior) => behavior.kind === "install");
440
+ const runtime = SETTINGS_BEHAVIORS.filter((behavior) => behavior.kind === "runtime");
362
441
  return {
363
442
  id: "gates",
364
- title: "Gates & Overrides",
365
- hint: canWriteOverrides(load) ? "enter: disable/enable · writes pantheon-overrides.json (global)" : "overrides file unreadable — writes refused; repair with `pantheon-opencode doctor --fix`",
366
- rows
443
+ title: "Gates",
444
+ groups: [{
445
+ title: "Install skills",
446
+ rows: install.map(rowFor)
447
+ }, {
448
+ title: "Runtime gates",
449
+ rows: runtime.map(rowFor)
450
+ }]
367
451
  };
368
452
  }
369
- function buildAboutSection(version) {
453
+ function buildAboutTab(version) {
370
454
  return {
371
455
  id: "about",
372
456
  title: "About",
373
- rows: [{
457
+ groups: [{ rows: [{
374
458
  id: "about.version",
375
- title: `Pantheon v${version}`,
376
- description: "OpenCode 2.x only — the V1 contract is removed.",
377
- selectable: false
459
+ name: "Version",
460
+ value: `v${version}`,
461
+ note: "OpenCode 2.x only — the V1 contract is removed"
378
462
  }, {
379
463
  id: "about.behaviors",
380
- title: `${SETTINGS_BEHAVIORS.length} togglable behaviors`,
381
- description: "Docs: docs/design/2.0-settings-and-install.md",
382
- selectable: false
383
- }]
464
+ name: "Behaviors",
465
+ value: String(SETTINGS_BEHAVIORS.length),
466
+ note: "docs/design/2.0-settings-and-install.md"
467
+ }] }]
384
468
  };
385
469
  }
386
- //#endregion
387
- //#region src/update-notice.ts
388
- /**
389
- * Update notifier core (TUI-local copy — the bundle must stay self-contained,
390
- * same precedent as cost-data.ts/model-pricing.ts).
391
- *
392
- * Pin + notify, never silent auto-update: one notice per newer version,
393
- * TTL-cached, offline-safe, and a stable install is never advertised a beta
394
- * (the update guard owns that crossing). docs/design/2.0-settings-and-install.md
395
- */
396
- const UPDATE_CHECK_TTL_MS = 216e5;
397
470
  /** Semver-ish compare for X.Y.Z[-beta.N]; betas sort before their release. */
398
471
  function comparePantheonVersions(left, right) {
399
472
  const parse = (version) => {
@@ -536,46 +609,49 @@ function classifyDecisionConfigHealth(env = process.env) {
536
609
  if (!existsSync(join(env.XDG_CONFIG_HOME ?? join(env.HOME ?? "", ".config"), "pantheon", "decision-router.json"))) return { status: "absent" };
537
610
  return readDecisionRouterConfig(env).corrupt ? { status: "corrupt" } : { status: "ok" };
538
611
  }
539
- function buildDoctorSection(input) {
612
+ function buildDoctorTab(input) {
540
613
  const env = input.env ?? process.env;
541
614
  const rows = [];
542
615
  const version = classifyInstallVersion(input.runningVersion, env);
543
616
  rows.push({
544
617
  id: "doctor.version",
545
- title: version.status === "ok" ? `Installed version: v${version.installed} — matches` : version.status === "older" ? `Installed v${version.installed} is older than the runtime v${input.runningVersion}` : version.status === "newer" ? `Installed v${version.installed} is newer than the runtime v${input.runningVersion}` : "Installed version: unknown (no install-state)",
546
- description: version.status === "older" ? "refresh with `pantheon-opencode update`" : "read from <config>/opencode/.pantheon/install-state.json",
547
- marker: version.status === "ok" ? "[✓]" : version.status === "older" ? "[!]" : "[i]",
548
- selectable: false
618
+ name: "Install version",
619
+ value: version.status === "ok" ? `v${version.installed} — matches` : version.status === "older" ? `v${version.installed} older` : version.status === "newer" ? `v${version.installed} newer` : "unknown",
620
+ note: version.status === "older" ? "refresh with `pantheon-opencode update`" : "read from <config>/opencode/.pantheon/install-state.json"
549
621
  });
550
622
  const nodeOk = isSupportedNodeFloor(input.nodeVersion);
551
623
  rows.push({
552
624
  id: "doctor.node",
553
- title: `Node runtime: ${input.nodeVersion.replace(/^v/, "")}`,
554
- description: nodeOk ? `meets the >= ${MIN_SUPPORTED_NODE_VERSION} floor` : `below the >= ${MIN_SUPPORTED_NODE_VERSION} floor — tooling may refuse`,
555
- marker: nodeOk ? "[✓]" : "[!]",
556
- selectable: false
625
+ name: "Node runtime",
626
+ value: input.nodeVersion.replace(/^v/, ""),
627
+ note: nodeOk ? `meets the >= ${MIN_SUPPORTED_NODE_VERSION} floor` : `below the >= ${MIN_SUPPORTED_NODE_VERSION} floor — tooling may refuse`
557
628
  });
558
629
  const overrides = classifyOverridesHealth(input.load);
559
630
  rows.push({
560
631
  id: "doctor.overrides",
561
- title: overrides.status === "clean" ? "Overrides: valid" : overrides.status === "corrupt" ? "Overrides: global file unreadable" : `Overrides: ${overrides.unknownIds.length} unknown id(s)`,
562
- description: overrides.status === "unknown-ids" ? `${overrides.unknownIds.join(", ")} — harmless; repair with doctor --fix` : overrides.status === "corrupt" ? "writes are refused until repaired (doctor --fix)" : "both files parse against the behavior registry",
563
- marker: overrides.status === "clean" ? "[✓]" : overrides.status === "corrupt" ? "[✗]" : "[!]",
564
- selectable: false
632
+ name: "Overrides",
633
+ value: overrides.status === "clean" ? "valid" : overrides.status === "corrupt" ? "unreadable" : `${overrides.unknownIds.length} unknown id(s)`,
634
+ note: overrides.status === "unknown-ids" ? `${overrides.unknownIds.join(", ")} — harmless; repair with doctor --fix` : overrides.status === "corrupt" ? "writes are refused until repaired (doctor --fix)" : "both files parse against the behavior registry"
565
635
  });
566
636
  const decision = classifyDecisionConfigHealth(env);
567
637
  rows.push({
568
638
  id: "doctor.decision",
569
- title: decision.status === "ok" ? "Decision config: valid" : decision.status === "corrupt" ? "Decision config: unreadable — runtime fail-closes" : "Decision config: absent (local defaults)",
570
- description: "read from <config>/pantheon/decision-router.json",
571
- marker: decision.status === "corrupt" ? "[✗]" : "[✓]",
572
- selectable: false
639
+ name: "Decision config",
640
+ value: decision.status === "ok" ? "valid" : decision.status === "corrupt" ? "corrupt" : "absent",
641
+ note: decision.status === "corrupt" ? "runtime fail-closes to disabled · read from <config>/pantheon/decision-router.json" : "read from <config>/pantheon/decision-router.json"
573
642
  });
574
643
  return {
575
644
  id: "doctor",
576
645
  title: "Doctor",
577
- rows,
578
- hint: "file checks only — the full doctor (MCP smoke, venv, git) is `pantheon-opencode doctor`"
646
+ groups: [{
647
+ title: "Health (file-derived)",
648
+ rows
649
+ }, { rows: [{
650
+ id: "doctor.cli",
651
+ name: "Full check",
652
+ value: "`pantheon-opencode doctor`",
653
+ note: "MCP smoke, venv pins, git stay in the CLI"
654
+ }] }]
579
655
  };
580
656
  }
581
657
  //#endregion
@@ -610,36 +686,36 @@ const MODE_DESCRIPTION = {
610
686
  warn: "RESERVED — behaves as shadow in this release",
611
687
  enforce: "high-risk scores DENY the tool call (fail-open on gate unavailability)"
612
688
  };
613
- function buildJ1Section(env, disabledByOverride) {
689
+ function buildJ1Tab(env, disabledByOverride) {
614
690
  const mode = j1ModeFromEnv(env);
615
691
  const threshold = j1ThresholdFromEnv(env);
616
692
  const gateState = disabledByOverride ? "disabled via overrides" : mode === "off" ? "off (env unset)" : "active";
617
- const rows = [
618
- {
619
- id: "j1.mode",
620
- title: `Mode: ${mode}`,
621
- description: MODE_DESCRIPTION[mode],
622
- ...disabledByOverride ? { marker: "[!]" } : {},
623
- selectable: false
624
- },
625
- {
626
- id: "j1.threshold",
627
- title: `Enforce threshold: ${threshold}`,
628
- description: "deny at or above; 0..1, default 0.8",
629
- selectable: false
630
- },
631
- {
632
- id: "j1.gate",
633
- title: `Gate: ${gateState}`,
634
- description: "the runtime plugin reads this once at startup",
635
- selectable: false
636
- }
637
- ];
638
693
  return {
639
694
  id: "j1",
640
- title: "J1 Risk Gate",
641
- hint: `set ${J1_FLAG_ENV} / ${J1_THRESHOLD_ENV} — restart applies`,
642
- rows
695
+ title: "J1",
696
+ groups: [{
697
+ title: "Ladder (env-only — never written here)",
698
+ rows: [
699
+ {
700
+ id: "j1.mode",
701
+ name: "Mode",
702
+ value: mode,
703
+ note: `${MODE_DESCRIPTION[mode]} · restart applies`
704
+ },
705
+ {
706
+ id: "j1.threshold",
707
+ name: "Enforce threshold",
708
+ value: String(threshold),
709
+ note: "deny at or above · 0..1 · default 0.8"
710
+ },
711
+ {
712
+ id: "j1.gate",
713
+ name: "Gate",
714
+ value: gateState,
715
+ note: `${J1_FLAG_ENV} / ${J1_THRESHOLD_ENV} · read once at startup`
716
+ }
717
+ ]
718
+ }]
643
719
  };
644
720
  }
645
721
  //#endregion
@@ -718,32 +794,28 @@ function backupMarker(path) {
718
794
  mkdirSync(dirname(path), { recursive: true });
719
795
  copyFileSync(path, `${path}.bak`);
720
796
  }
721
- function buildPresetSection(input) {
722
- const rows = PRESET_NAMES.map((name) => ({
723
- id: `preset.${name}`,
724
- title: name,
725
- description: input.globalName === name ? "active (global)" : "enter: activate globally",
726
- disabled: input.globalName === name
727
- }));
728
- rows.push({
729
- id: "preset.none",
730
- title: "none",
731
- description: "clear the global marker — opencode defaults",
732
- disabled: input.globalName === null,
733
- marker: input.globalName === null ? "[x]" : "[ ]"
734
- });
797
+ const PRESET_CYCLE = Object.freeze(["none", ...PRESET_NAMES]);
798
+ function buildPresetTab(input) {
799
+ const rows = [{
800
+ id: "preset",
801
+ name: "Preset",
802
+ value: input.globalName ?? "none",
803
+ cycle: PRESET_CYCLE,
804
+ note: "global marker · atomic write, .bak backup · none = opencode defaults"
805
+ }];
735
806
  if (input.projectName !== null) rows.push({
736
807
  id: "preset.project",
737
- title: `${input.projectName} (project)`,
738
- description: `${projectActivePresetPath()} wins over the global marker`,
739
- marker: "[!]",
740
- selectable: false
808
+ name: "Project",
809
+ value: input.projectName,
810
+ note: `${projectActivePresetPath()} wins over the global marker — read-only here`
741
811
  });
742
812
  return {
743
813
  id: "preset",
744
- title: "Model Preset",
745
- rows,
746
- hint: "enter: activate globally · writes <config>/opencode/.pantheon/active-preset.json"
814
+ title: "Preset",
815
+ groups: [{
816
+ title: "Model preset",
817
+ rows
818
+ }]
747
819
  };
748
820
  }
749
821
  //#endregion
@@ -765,54 +837,74 @@ function formatAgo(ms) {
765
837
  if (ms < 864e5) return `${Math.floor(ms / 36e5)}h ago`;
766
838
  return `${Math.floor(ms / 864e5)}d ago`;
767
839
  }
768
- function buildUpdatesSection(input) {
840
+ function buildUpdatesTab(input) {
769
841
  const nowMs = input.nowMs ?? Date.now();
770
842
  const channel = updateChannelFor(input.currentVersion);
771
843
  const lastCheckMs = input.state.lastCheckMs;
772
844
  const latest = input.lastCheckedVersion ?? input.state.lastNotifiedVersion;
773
845
  const rows = [{
774
846
  id: "update.channel",
775
- title: `Channel: ${channel}`,
776
- description: "stable tracks npm `latest`; beta tracks npm `beta`",
777
- selectable: false
847
+ name: "Channel",
848
+ value: channel,
849
+ note: "stable tracks npm `latest`; beta tracks npm `beta`"
778
850
  }, {
779
851
  id: "update.check",
780
- title: "Check now",
781
- description: input.checking ? "checking…" : lastCheckMs ? `last check ${formatAgo(nowMs - lastCheckMs)}` : "never checked",
782
- marker: " → ",
783
- selectable: true
852
+ name: "Check now",
853
+ value: input.checking ? "checking…" : lastCheckMs ? `last check ${formatAgo(nowMs - lastCheckMs)}` : "never checked",
854
+ action: "update-check",
855
+ note: "enter probes the registry for the running channel"
784
856
  }];
785
857
  if (latest) {
786
858
  const stable = (version) => !/-beta\.\d+$/.test(version);
787
859
  const newer = comparePantheonVersions(latest, input.currentVersion) > 0 && !(stable(input.currentVersion) && !stable(latest));
788
860
  rows.push({
789
861
  id: "update.latest",
790
- title: newer ? `Update available: v${latest}` : `Up to date (latest seen v${latest})`,
791
- description: newer ? "adopt with `pantheon-opencode update`" : "checked against the registry",
792
- marker: newer ? "[!]" : "[✓]",
793
- selectable: false
862
+ name: "Registry",
863
+ value: newer ? `v${latest} available` : "up to date",
864
+ note: newer ? "adopt with `pantheon-opencode update`" : "no newer compatible version"
794
865
  });
795
866
  }
796
867
  return {
797
868
  id: "updates",
798
869
  title: "Updates",
799
- hint: `refresh = \`pantheon-opencode update\` · notice TTL ${UPDATE_CHECK_TTL_MS / 36e5}h`,
800
- rows
870
+ groups: [{
871
+ title: "Updates",
872
+ rows
873
+ }]
801
874
  };
802
875
  }
803
876
  //#endregion
804
877
  //#region src/pantheon-settings.tsx
805
878
  /** @jsxImportSource @opentui/solid */
806
879
  /**
807
- * pantheon-settings.tsx — the /pantheon-settings window.
880
+ * pantheon-settings.tsx — the /pantheon-settings window (2.0.0-beta.4).
808
881
  *
809
- * One section per page, keyboard-first: `tab` cycles sections, `up`/`down`
810
- * select, `enter`/`space` dispatches the selected row (the Gates section
811
- * writes the GLOBAL overrides file — the same one the installer and doctor
812
- * consume; Updates runs a registry check). `escape`/`q` closes. The
813
- * gated-layer pattern mirrors the dispatch panel and whats-new windows.
814
- * Every failure path is silent (fail-open).
882
+ * A FULL-SCREEN settings window in the OpenCode Quota shape: a tab header,
883
+ * grouped setting rows with ←/→ value cyclers, a note column, and a
884
+ * save/reset footer. The surface is a ROUTER PAGE (`ui.router.register` +
885
+ * `navigate({type:'plugin'})`) — true full-screen, reachable from the home
886
+ * route AND sessions, no focus dance (binary-verified precedent: the host's
887
+ * own opencode.diffs plugin). Hosts without a router fall back to the old
888
+ * dialog with the same commands (fail-open).
889
+ *
890
+ * Edits stage into a DRAFT: ←/→ cycles a row's value, `ctrl+s` saves every
891
+ * staged row through the per-surface guards, `ctrl+r` resets the current
892
+ * tab, `esc`/`q` confirms before discarding. The disk never changes before
893
+ * save, and every refusal surfaces in the notice line — never silent.
894
+ *
895
+ * The keymap layer is registered ONCE at setup with `priority: 1` (the host
896
+ * resolves bind conflicts by priority then registration order — a stale
897
+ * dispatch-panel layer must never win while this window is open; field
898
+ * report beta.2: navigation "stopped working" was exactly that theft).
815
899
  */
900
+ const ROUTE_NAME = "pantheon-settings";
901
+ /** Loose local shape of a host route (the real Route lives in the host typings). */
902
+ const [blocking, setBlocking] = createSignal(false);
903
+ /** True while a Pantheon settings surface (page or fallback dialog) is open. */
904
+ function pantheonSettingsBlocking() {
905
+ return blocking();
906
+ }
907
+ let routerAvailable = false;
816
908
  function globalOverridesPath() {
817
909
  const xdgConfig = process.env.XDG_CONFIG_HOME ?? join(process.env.HOME ?? "", ".config");
818
910
  return join(xdgConfig, "opencode", "pantheon-overrides.json");
@@ -820,7 +912,6 @@ function globalOverridesPath() {
820
912
  function projectOverridesPath() {
821
913
  return join(process.cwd(), ".pantheon", "overrides.json");
822
914
  }
823
- /** Read one overrides file; a missing file is empty, an unreadable one is corrupt. */
824
915
  function readOneOverrides(path) {
825
916
  try {
826
917
  const parsed = JSON.parse(readFileSync(path, "utf8"));
@@ -862,10 +953,6 @@ function readUpdateCheckState() {
862
953
  return {};
863
954
  }
864
955
  }
865
- /**
866
- * Registry check for the RUNNING version's channel (beta installs ask the
867
- * beta dist-tag). Resolves with the latest version seen, or null offline.
868
- */
869
956
  async function fetchLatestForChannel(currentVersion) {
870
957
  try {
871
958
  const response = await fetch(registryUrlForChannel(updateChannelFor(currentVersion)), { signal: AbortSignal.timeout(5e3) });
@@ -891,280 +978,578 @@ function resolveRunningVersion$1() {
891
978
  return "unknown";
892
979
  }
893
980
  }
894
- function SettingsContent(props) {
895
- const section = () => props.sections()[props.page()] ?? {
896
- id: "empty",
897
- title: "",
898
- rows: []
899
- };
981
+ const VALUE_WIDTH = 22;
982
+ function SettingsWindow(props) {
983
+ const tab = () => props.tabs()[props.page()] ?? props.tabs()[0] ?? EMPTY_TAB;
984
+ const rows = () => tabRows(tab());
900
985
  return (() => {
901
- var _el$ = createElement("box"), _el$2 = createElement("text"), _el$3 = createElement("text"), _el$5 = createElement("box"), _el$7 = createElement("text"), _el$8 = createTextNode(`tab: section · up/down: select · enter: apply · esc/q: close`);
986
+ 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");
902
987
  insertNode(_el$, _el$2);
903
- insertNode(_el$, _el$3);
904
- insertNode(_el$, _el$5);
905
- insertNode(_el$, _el$7);
988
+ insertNode(_el$, _el$6);
989
+ insertNode(_el$, _el$9);
990
+ insertNode(_el$, _el$0);
906
991
  setProp(_el$, "flexDirection", "column");
907
992
  setProp(_el$, "paddingLeft", 1);
908
993
  setProp(_el$, "paddingRight", 1);
909
994
  setProp(_el$, "paddingTop", 1);
910
- setProp(_el$2, "attributes", 1);
911
- insert(_el$2, () => section().title);
912
- insertNode(_el$3, createTextNode(`──────────────────────────────────────`));
995
+ insertNode(_el$2, _el$3);
996
+ insertNode(_el$2, _el$4);
997
+ setProp(_el$2, "flexDirection", "row");
998
+ setProp(_el$3, "attributes", 1);
999
+ insert(_el$3, () => `Pantheon v${props.version}`);
1000
+ insert(_el$2, createComponent(For, {
1001
+ get each() {
1002
+ return props.tabs();
1003
+ },
1004
+ children: (t, index) => (() => {
1005
+ var _el$10 = createElement("text");
1006
+ spread(_el$10, mergeProps({ get fg() {
1007
+ return memo(() => index() === props.page())() ? props.fg : props.muted;
1008
+ } }, () => index() === props.page() ? { attributes: 1 } : {}), true);
1009
+ insert(_el$10, () => ` ${t.title}${tabDirty(props.draft(), t) ? " ●" : ""}`);
1010
+ return _el$10;
1011
+ })()
1012
+ }), _el$4);
1013
+ insertNode(_el$4, createTextNode(` esc`));
1014
+ insertNode(_el$6, createTextNode(`────────────────────────────────────────────────────────────────────────`));
913
1015
  insert(_el$, createComponent(For, {
914
1016
  get each() {
915
- return section().rows;
1017
+ return tab().groups;
916
1018
  },
917
- children: (row) => {
918
- const isSelected = () => row.selectable !== false && row.id === props.selectedId();
919
- const marker = () => row.marker ?? (row.disabled ? "[x]" : "[ ]");
920
- return (() => {
921
- var _el$9 = createElement("box"), _el$0 = createElement("text");
922
- insertNode(_el$9, _el$0);
923
- setProp(_el$9, "flexDirection", "column");
924
- spread(_el$0, mergeProps({ get fg() {
925
- return memo(() => !!isSelected())() ? props.fg : props.muted;
926
- } }, () => isSelected() ? { attributes: 1 } : {}), true);
927
- insert(_el$0, () => `${marker()} ${row.title}${isSelected() ? " <-" : ""}`);
928
- insert(_el$9, createComponent(Show, {
929
- get when() {
930
- return row.description !== "";
931
- },
932
- get children() {
933
- var _el$1 = createElement("text");
934
- insert(_el$1, () => ` ${row.description}`);
935
- effect((_$p) => setProp(_el$1, "fg", props.muted, _$p));
936
- return _el$1;
937
- }
938
- }), null);
939
- return _el$9;
940
- })();
941
- }
942
- }), _el$5);
943
- setProp(_el$5, "height", 1);
1019
+ children: (group) => (() => {
1020
+ var _el$11 = createElement("box"), _el$13 = createElement("box");
1021
+ insertNode(_el$11, _el$13);
1022
+ setProp(_el$11, "flexDirection", "column");
1023
+ insert(_el$11, createComponent(Show, {
1024
+ get when() {
1025
+ return group.title !== void 0;
1026
+ },
1027
+ get children() {
1028
+ var _el$12 = createElement("text");
1029
+ setProp(_el$12, "attributes", 1);
1030
+ insert(_el$12, () => group.title);
1031
+ effect((_$p) => setProp(_el$12, "fg", props.fg, _$p));
1032
+ return _el$12;
1033
+ }
1034
+ }), _el$13);
1035
+ insert(_el$11, createComponent(For, {
1036
+ get each() {
1037
+ return group.rows;
1038
+ },
1039
+ children: (row) => {
1040
+ const isSelected = () => rows()[props.selected()]?.id === row.id;
1041
+ const display = () => props.draft()[row.id] ?? row.value;
1042
+ const staged = () => props.draft()[row.id] !== void 0;
1043
+ const gutter = () => isSelected() ? "▸ " : " ";
1044
+ const valueCell = () => row.cycle !== void 0 ? `< ${display()} >` : display();
1045
+ return (() => {
1046
+ var _el$14 = createElement("box"), _el$15 = createElement("box"), _el$16 = createElement("text"), _el$17 = createElement("box"), _el$18 = createElement("text");
1047
+ insertNode(_el$14, _el$15);
1048
+ insertNode(_el$14, _el$17);
1049
+ setProp(_el$14, "flexDirection", "row");
1050
+ insertNode(_el$15, _el$16);
1051
+ setProp(_el$15, "width", 28);
1052
+ spread(_el$16, mergeProps({ get fg() {
1053
+ return props.fg;
1054
+ } }, () => isSelected() ? { attributes: 1 } : {}), true);
1055
+ insert(_el$16, () => `${gutter()}${row.name}`.padEnd(28));
1056
+ insertNode(_el$17, _el$18);
1057
+ setProp(_el$17, "width", 22);
1058
+ spread(_el$18, mergeProps({ get fg() {
1059
+ return memo(() => !!(isSelected() || staged()))() ? props.fg : props.muted;
1060
+ } }, () => isSelected() ? { attributes: 1 } : {}), true);
1061
+ insert(_el$18, () => `${valueCell()}${staged() ? " ●" : ""}`.padEnd(VALUE_WIDTH));
1062
+ insert(_el$14, createComponent(Show, {
1063
+ get when() {
1064
+ return row.note !== void 0;
1065
+ },
1066
+ get children() {
1067
+ var _el$19 = createElement("box"), _el$20 = createElement("text");
1068
+ insertNode(_el$19, _el$20);
1069
+ setProp(_el$19, "flexGrow", 1);
1070
+ setProp(_el$19, "flexShrink", 1);
1071
+ insert(_el$20, () => row.note);
1072
+ effect((_$p) => setProp(_el$20, "fg", props.muted, _$p));
1073
+ return _el$19;
1074
+ }
1075
+ }), null);
1076
+ return _el$14;
1077
+ })();
1078
+ }
1079
+ }), _el$13);
1080
+ setProp(_el$13, "height", 1);
1081
+ return _el$11;
1082
+ })()
1083
+ }), _el$9);
944
1084
  insert(_el$, createComponent(Show, {
945
1085
  get when() {
946
- return section().hint !== void 0;
1086
+ return props.notice() !== void 0;
947
1087
  },
948
1088
  get children() {
949
- var _el$6 = createElement("text");
950
- insert(_el$6, () => section().hint);
951
- effect((_$p) => setProp(_el$6, "fg", props.muted, _$p));
952
- return _el$6;
1089
+ var _el$8 = createElement("text");
1090
+ insert(_el$8, () => `⚠ ${props.notice()}`);
1091
+ effect((_$p) => setProp(_el$8, "fg", props.warn ?? props.muted, _$p));
1092
+ return _el$8;
953
1093
  }
954
- }), _el$7);
955
- insertNode(_el$7, _el$8);
956
- insert(_el$7, () => `${props.page() + 1}/${props.sections().length} · `, _el$8);
1094
+ }), _el$9);
1095
+ insert(_el$9, (() => {
1096
+ var _c$ = memo(() => !!draftDirty(props.draft()));
1097
+ return () => _c$() ? `● unsaved (${draftCount(props.draft())}) — ctrl+s save · ctrl+r reset page` : "no staged changes";
1098
+ })());
1099
+ insertNode(_el$0, createTextNode(`1-9 tab · ←/→ change value · enter apply · tab next tab · ctrl+s save · ctrl+r reset page · esc/q close`));
957
1100
  effect((_p$) => {
958
- var _v$ = props.fg, _v$2 = props.muted, _v$3 = props.muted;
959
- _v$ !== _p$.e && (_p$.e = setProp(_el$2, "fg", _v$, _p$.e));
960
- _v$2 !== _p$.t && (_p$.t = setProp(_el$3, "fg", _v$2, _p$.t));
961
- _v$3 !== _p$.a && (_p$.a = setProp(_el$7, "fg", _v$3, _p$.a));
1101
+ 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;
1102
+ _v$ !== _p$.e && (_p$.e = setProp(_el$3, "fg", _v$, _p$.e));
1103
+ _v$2 !== _p$.t && (_p$.t = setProp(_el$4, "fg", _v$2, _p$.t));
1104
+ _v$3 !== _p$.a && (_p$.a = setProp(_el$6, "fg", _v$3, _p$.a));
1105
+ _v$4 !== _p$.o && (_p$.o = setProp(_el$9, "fg", _v$4, _p$.o));
1106
+ _v$5 !== _p$.i && (_p$.i = setProp(_el$0, "fg", _v$5, _p$.i));
962
1107
  return _p$;
963
1108
  }, {
964
1109
  e: void 0,
965
1110
  t: void 0,
966
- a: void 0
1111
+ a: void 0,
1112
+ o: void 0,
1113
+ i: void 0
967
1114
  });
968
1115
  return _el$;
969
1116
  })();
970
1117
  }
971
- /**
972
- * Entry glue: read both overrides files, then show the window through the
973
- * host dialog stack once. The gated keymap layer is inert while the window
974
- * is closed. Never throws.
975
- */
976
- async function maybeShowPantheonSettings(context) {
977
- try {
978
- const [open, setOpen] = createSignal(false);
979
- const [page, setPage] = createSignal(0);
980
- const [load, setLoad] = createSignal(readOverridesLoad());
981
- const [lastChecked, setLastChecked] = createSignal(void 0);
982
- const [checking, setChecking] = createSignal(false);
983
- const [decision, setDecision] = createSignal(readDecisionRouterConfig());
984
- const [presetTick, setPresetTick] = createSignal(0);
985
- const currentVersion = resolveRunningVersion$1();
986
- const updatesInput = () => {
987
- const input = {
988
- currentVersion,
989
- state: readUpdateCheckState(),
990
- checking: checking(),
991
- nowMs: Date.now()
992
- };
993
- const seen = lastChecked();
994
- if (seen !== void 0) input.lastCheckedVersion = seen;
995
- return input;
996
- };
997
- const presetInput = () => {
998
- presetTick();
999
- return {
1000
- globalName: readActivePresetMarker(globalActivePresetPath())?.name ?? null,
1001
- projectName: readActivePresetMarker(projectActivePresetPath())?.name ?? null
1002
- };
1003
- };
1004
- const sections = () => [
1005
- buildGatesSection(load()),
1006
- buildDecisionSection(decision()),
1007
- buildPresetSection(presetInput()),
1008
- buildJ1Section(process.env, isBehaviorDisabled(mergedOverrides(load()), "gate-j1-risk-gate")),
1009
- buildUpdatesSection(updatesInput()),
1010
- buildDoctorSection({
1011
- runningVersion: currentVersion,
1012
- nodeVersion: process.versions.node,
1013
- load: load()
1014
- }),
1015
- buildAboutSection(currentVersion)
1016
- ];
1017
- const [selectedId, setSelectedId] = createSignal(firstSelectableId(sections()));
1018
- const move = (delta) => {
1019
- const list = flatSelectableRows(sections());
1020
- if (list.length === 0) return;
1021
- const current = list.findIndex((row) => row.id === selectedId());
1022
- const nextIndex = current === -1 ? 0 : Math.min(Math.max(current + delta, 0), list.length - 1);
1023
- setSelectedId(list[nextIndex]?.id);
1118
+ let pageApi;
1119
+ function createWindowController(context, exit) {
1120
+ const [page, setPage] = createSignal(0);
1121
+ const [selected, setSelected] = createSignal(0);
1122
+ const [load, setLoad] = createSignal(readOverridesLoad());
1123
+ const [decision, setDecision] = createSignal(readDecisionRouterConfig());
1124
+ const [presetTick, setPresetTick] = createSignal(0);
1125
+ const [lastChecked, setLastChecked] = createSignal(void 0);
1126
+ const [checking, setChecking] = createSignal(false);
1127
+ const [draft, setDraft] = createSignal({});
1128
+ const [notice, setNotice] = createSignal(void 0);
1129
+ const currentVersion = resolveRunningVersion$1();
1130
+ const presetInput = () => {
1131
+ presetTick();
1132
+ return {
1133
+ globalName: readActivePresetMarker(globalActivePresetPath())?.name ?? null,
1134
+ projectName: readActivePresetMarker(projectActivePresetPath())?.name ?? null
1024
1135
  };
1025
- const flipSection = () => {
1026
- const count = sections().length;
1027
- const next = (page() + 1) % count;
1028
- setPage(next);
1029
- const target = sections()[next];
1030
- if (target === void 0) return;
1031
- const within = flatSelectableRows([target])[0];
1032
- if (within) setSelectedId(within.id);
1136
+ };
1137
+ const updatesInput = () => {
1138
+ const input = {
1139
+ currentVersion,
1140
+ state: readUpdateCheckState(),
1141
+ checking: checking(),
1142
+ nowMs: Date.now()
1033
1143
  };
1034
- const toggleSelectedGate = () => {
1035
- const id = selectedId();
1036
- if (id === void 0 || !id.startsWith("gate.")) return false;
1037
- if (!canWriteOverrides(load())) return void 0;
1038
- const behaviorId = id.slice(5);
1039
- const next = {
1040
- ...load(),
1041
- global: toggledOverrides(load().global, behaviorId)
1144
+ const seen = lastChecked();
1145
+ if (seen !== void 0) input.lastCheckedVersion = seen;
1146
+ return input;
1147
+ };
1148
+ const tabs = () => [
1149
+ buildGatesTab(load()),
1150
+ buildDecisionTab(decision()),
1151
+ buildPresetTab(presetInput()),
1152
+ buildJ1Tab(process.env, false),
1153
+ buildUpdatesTab(updatesInput()),
1154
+ buildDoctorTab({
1155
+ runningVersion: currentVersion,
1156
+ nodeVersion: process.versions.node,
1157
+ load: load()
1158
+ }),
1159
+ buildAboutTab(currentVersion)
1160
+ ];
1161
+ const rows = () => tabRows(tabs()[page()] ?? tabs()[0] ?? EMPTY_TAB);
1162
+ const move = (delta) => {
1163
+ const list = rows();
1164
+ if (list.length === 0) return;
1165
+ setSelected((current) => Math.min(Math.max(current + delta, 0), list.length - 1));
1166
+ };
1167
+ const step = (direction) => {
1168
+ const row = rows()[selected()];
1169
+ if (row === void 0) return;
1170
+ setNotice(void 0);
1171
+ setDraft(stageValue(draft(), row, direction));
1172
+ };
1173
+ const checkUpdatesNow = () => {
1174
+ if (checking()) return;
1175
+ setChecking(true);
1176
+ setNotice(void 0);
1177
+ fetchLatestForChannel(currentVersion).then((latest) => {
1178
+ if (latest) setLastChecked(latest);
1179
+ persistUpdateCheckState(readUpdateCheckState(), latest);
1180
+ }).catch(() => {}).finally(() => setChecking(false));
1181
+ };
1182
+ const dispatchWrite = (id, value) => {
1183
+ if (id.startsWith("gate.")) {
1184
+ if (!canWriteOverrides(load())) return {
1185
+ ok: false,
1186
+ reason: "overrides file unreadable — repair with `doctor --fix`"
1042
1187
  };
1188
+ const behaviorId = id.slice(5);
1189
+ const nextGlobal = setOverrideState(load().global, behaviorId, value === "disabled" ? "disabled" : "enabled");
1190
+ if (nextGlobal === load().global) return { ok: true };
1043
1191
  try {
1044
- writeOverridesToDisk(next);
1045
- setLoad(next);
1046
- } catch {}
1047
- };
1048
- const checkUpdatesNow = () => {
1049
- if (checking()) return void 0;
1050
- setChecking(true);
1051
- fetchLatestForChannel(currentVersion).then((latest) => {
1052
- if (latest) setLastChecked(latest);
1053
- persistUpdateCheckState(readUpdateCheckState(), latest);
1054
- }).catch(() => {}).finally(() => setChecking(false));
1055
- };
1056
- const toggleDecisionEnabled = () => {
1192
+ writeOverridesToDisk({
1193
+ ...load(),
1194
+ global: nextGlobal
1195
+ });
1196
+ setLoad({
1197
+ ...load(),
1198
+ global: nextGlobal
1199
+ });
1200
+ return { ok: true };
1201
+ } catch {
1202
+ return {
1203
+ ok: false,
1204
+ reason: "overrides disk write failed"
1205
+ };
1206
+ }
1207
+ }
1208
+ if (id === "decision.enabled") {
1057
1209
  const current = decision();
1058
- if (current.corrupt) return void 0;
1059
- const next = setDecisionEnabled(current.config, !current.config.enabled);
1060
- if (!next.ok) return void 0;
1210
+ if (current.corrupt) return {
1211
+ ok: false,
1212
+ reason: "decision-router.json unreadable — repair via `decision-router setup-model`"
1213
+ };
1214
+ const guarded = setDecisionEnabled(current.config, value === "enabled");
1215
+ if (!guarded.ok) return {
1216
+ ok: false,
1217
+ reason: guarded.reason
1218
+ };
1061
1219
  try {
1062
- writeDecisionRouterConfig(next.config);
1220
+ writeDecisionRouterConfig(guarded.config);
1063
1221
  setDecision({
1064
- config: next.config,
1222
+ config: guarded.config,
1065
1223
  corrupt: false
1066
1224
  });
1067
- } catch {}
1225
+ return { ok: true };
1226
+ } catch {
1227
+ return {
1228
+ ok: false,
1229
+ reason: "decision-router disk write failed"
1230
+ };
1231
+ }
1232
+ }
1233
+ if (id === "preset") try {
1234
+ if (value === "none") clearActivePreset(globalActivePresetPath());
1235
+ else writeActivePreset(globalActivePresetPath(), value);
1236
+ setPresetTick((tick) => tick + 1);
1237
+ return { ok: true };
1238
+ } catch (error) {
1239
+ return {
1240
+ ok: false,
1241
+ reason: error instanceof Error ? error.message : "preset marker write failed"
1242
+ };
1243
+ }
1244
+ return {
1245
+ ok: false,
1246
+ reason: "unknown staged row"
1068
1247
  };
1069
- const applySelectedPreset = () => {
1070
- const id = selectedId();
1071
- if (id === void 0) return void 0;
1072
- const name = id.startsWith("preset.") ? id.slice(7) : null;
1073
- if (name === null || name === "project") return void 0;
1074
- const path = globalActivePresetPath();
1248
+ };
1249
+ const save = () => {
1250
+ if (!draftDirty(draft())) {
1251
+ setNotice("nothing staged — ←/→ stages a change first");
1252
+ return;
1253
+ }
1254
+ const writer = dispatchWrite;
1255
+ const { applied, failed } = applyDraft(draft(), writer);
1256
+ if (applied.length > 0) {
1257
+ setDraft(settledDraft(draft(), applied));
1258
+ setLoad(readOverridesLoad());
1259
+ setDecision(readDecisionRouterConfig());
1260
+ setPresetTick((tick) => tick + 1);
1261
+ }
1262
+ if (failed.length > 0) setNotice(`${failed.map((f) => `${f.id}: ${f.reason}`).join(" · ")} — staged changes kept`);
1263
+ else setNotice(`saved ${applied.length} change${applied.length === 1 ? "" : "s"}`);
1264
+ };
1265
+ const resetPage = () => {
1266
+ const tab = tabs()[page()];
1267
+ if (tab === void 0) return;
1268
+ setDraft(resetTab(draft(), tab));
1269
+ setNotice(void 0);
1270
+ };
1271
+ const nextTab = () => {
1272
+ setPage((current) => (current + 1) % tabs().length);
1273
+ setSelected(0);
1274
+ };
1275
+ const close = () => {
1276
+ if (draftDirty(draft())) {
1075
1277
  try {
1076
- if (name === "none") clearActivePreset(path);
1077
- else writeActivePreset(path, name);
1078
- setPresetTick((tick) => tick + 1);
1278
+ Promise.resolve(context.ui.dialog.confirm({
1279
+ title: "Pantheon settings",
1280
+ message: "Discard unsaved settings changes?"
1281
+ })).then((confirmed) => {
1282
+ if (confirmed === true) exit();
1283
+ });
1079
1284
  } catch {}
1080
- };
1081
- let dismiss = () => {};
1285
+ return;
1286
+ }
1287
+ exit();
1288
+ };
1289
+ return {
1290
+ tabs,
1291
+ page,
1292
+ selected,
1293
+ draft,
1294
+ notice,
1295
+ api: {
1296
+ move,
1297
+ step,
1298
+ actuate: () => {
1299
+ if (rows()[selected()]?.action === "update-check") checkUpdatesNow();
1300
+ else step(1);
1301
+ },
1302
+ nextTab,
1303
+ jumpTab: (index) => {
1304
+ if (index >= 0 && index < tabs().length) {
1305
+ setPage(index);
1306
+ setSelected(0);
1307
+ }
1308
+ },
1309
+ save,
1310
+ resetPage,
1311
+ close
1312
+ },
1313
+ cleanup: () => {
1314
+ pageApi = void 0;
1315
+ setBlocking(false);
1316
+ }
1317
+ };
1318
+ }
1319
+ function SettingsPage(props) {
1320
+ const returnRoute = props.data?.returnRoute;
1321
+ const context = props.context;
1322
+ const controller = createWindowController(context, () => navigateBack(context, returnRoute !== void 0 ? { returnRoute } : {}));
1323
+ const theme = context.theme?.text ?? {};
1324
+ const warn = theme?.feedback?.warning?.base ?? theme.muted;
1325
+ onCleanup(controller.cleanup);
1326
+ setBlocking(true);
1327
+ pageApi = controller.api;
1328
+ return createComponent(SettingsWindow, {
1329
+ get version() {
1330
+ return resolveRunningVersion$1();
1331
+ },
1332
+ get tabs() {
1333
+ return controller.tabs;
1334
+ },
1335
+ get page() {
1336
+ return controller.page;
1337
+ },
1338
+ get selected() {
1339
+ return controller.selected;
1340
+ },
1341
+ get draft() {
1342
+ return controller.draft;
1343
+ },
1344
+ get notice() {
1345
+ return controller.notice;
1346
+ },
1347
+ get fg() {
1348
+ return theme.base;
1349
+ },
1350
+ get muted() {
1351
+ return theme.muted;
1352
+ },
1353
+ warn
1354
+ });
1355
+ }
1356
+ function navigateBack(context, data) {
1357
+ try {
1358
+ context.ui.router.navigate(data?.returnRoute ?? { type: "home" });
1359
+ } catch {}
1360
+ }
1361
+ const [dialogOpen, setDialogOpen] = createSignal(false);
1362
+ let dialogDismiss = () => {};
1363
+ function openSettingsDialog(context) {
1364
+ const controller = createWindowController(context, () => dialogDismiss());
1365
+ const theme = context.theme?.text ?? {};
1366
+ const warn = theme?.feedback?.warning?.base ?? theme.muted;
1367
+ controller.cleanup = () => {
1368
+ pageApi = void 0;
1369
+ setBlocking(false);
1370
+ setDialogOpen(false);
1371
+ };
1372
+ const close = () => {
1373
+ controller.cleanup();
1374
+ };
1375
+ dialogDismiss = () => {
1082
1376
  try {
1083
- context.keymap.layer(() => ({
1084
- mode: "global",
1085
- enabled: () => open(),
1086
- commands: [
1087
- {
1088
- id: "pantheon.settings.close",
1089
- title: "Close settings",
1090
- bind: "escape,q",
1091
- run: () => {
1092
- if (!open()) return false;
1093
- dismiss();
1094
- }
1095
- },
1096
- {
1097
- id: "pantheon.settings.down",
1098
- title: "Select next",
1099
- bind: "down,j",
1100
- run: () => {
1101
- if (!open()) return false;
1102
- move(1);
1103
- }
1104
- },
1105
- {
1106
- id: "pantheon.settings.up",
1107
- title: "Select previous",
1108
- bind: "up,k",
1109
- run: () => {
1110
- if (!open()) return false;
1111
- move(-1);
1112
- }
1113
- },
1114
- {
1115
- id: "pantheon.settings.toggle",
1116
- title: "Apply the selected row",
1117
- bind: "enter,space",
1118
- run: () => {
1119
- if (!open()) return false;
1120
- const id = selectedId();
1121
- if (id?.startsWith("gate.")) return toggleSelectedGate();
1122
- if (id === "decision.enabled") return toggleDecisionEnabled();
1123
- if (id?.startsWith("preset.")) return applySelectedPreset();
1124
- if (id === "update.check") return checkUpdatesNow();
1125
- }
1126
- },
1127
- {
1128
- id: "pantheon.settings.section",
1129
- title: "Next section",
1130
- bind: "tab",
1131
- run: () => {
1132
- if (!open()) return false;
1133
- flipSection();
1134
- }
1135
- }
1136
- ]
1137
- }));
1377
+ context.ui.dialog.clear();
1138
1378
  } catch {}
1139
- const close = () => {
1140
- setOpen(false);
1141
- };
1142
- dismiss = () => {
1143
- try {
1144
- context.ui.dialog.clear();
1145
- } catch {}
1146
- close();
1147
- };
1148
- setOpen(true);
1149
- setPage(0);
1379
+ close();
1380
+ };
1381
+ setBlocking(true);
1382
+ setDialogOpen(true);
1383
+ pageApi = controller.api;
1384
+ try {
1385
+ context.ui.dialog.show(() => createComponent(SettingsWindow, {
1386
+ get version() {
1387
+ return resolveRunningVersion$1();
1388
+ },
1389
+ get tabs() {
1390
+ return controller.tabs;
1391
+ },
1392
+ get page() {
1393
+ return controller.page;
1394
+ },
1395
+ get selected() {
1396
+ return controller.selected;
1397
+ },
1398
+ get draft() {
1399
+ return controller.draft;
1400
+ },
1401
+ get notice() {
1402
+ return controller.notice;
1403
+ },
1404
+ get fg() {
1405
+ return theme.base;
1406
+ },
1407
+ get muted() {
1408
+ return theme.muted;
1409
+ },
1410
+ warn
1411
+ }), close);
1412
+ } catch {}
1413
+ }
1414
+ function setupPantheonSettings(context) {
1415
+ try {
1416
+ context.ui.router?.register?.({
1417
+ name: ROUTE_NAME,
1418
+ render: ({ data }) => createComponent(SettingsPage, {
1419
+ context,
1420
+ data
1421
+ })
1422
+ });
1423
+ routerAvailable = true;
1424
+ } catch {
1425
+ routerAvailable = false;
1426
+ }
1427
+ const routeGated = () => {
1150
1428
  try {
1151
- const theme = context.theme?.text ?? {};
1152
- context.ui.dialog.show(() => createComponent(SettingsContent, {
1153
- sections,
1154
- page,
1155
- selectedId,
1156
- get fg() {
1157
- return theme.base;
1158
- },
1159
- get muted() {
1160
- return theme.muted;
1161
- }
1162
- }), close);
1429
+ const route = context.ui?.router?.current?.();
1430
+ return route?.type === "plugin" && route.name === "pantheon-settings";
1431
+ } catch {
1432
+ return false;
1433
+ }
1434
+ };
1435
+ const commands = [
1436
+ {
1437
+ id: "pantheon.settings.close",
1438
+ title: "Close settings",
1439
+ bind: "escape,q",
1440
+ run: () => {
1441
+ pageApi?.close();
1442
+ }
1443
+ },
1444
+ {
1445
+ id: "pantheon.settings.down",
1446
+ title: "Select next row",
1447
+ bind: "down,j",
1448
+ run: () => {
1449
+ pageApi?.move(1);
1450
+ }
1451
+ },
1452
+ {
1453
+ id: "pantheon.settings.up",
1454
+ title: "Select previous row",
1455
+ bind: "up,k",
1456
+ run: () => {
1457
+ pageApi?.move(-1);
1458
+ }
1459
+ },
1460
+ {
1461
+ id: "pantheon.settings.cycle.next",
1462
+ title: "Stage the next value",
1463
+ bind: "right,l",
1464
+ run: () => {
1465
+ pageApi?.step(1);
1466
+ }
1467
+ },
1468
+ {
1469
+ id: "pantheon.settings.cycle.prev",
1470
+ title: "Stage the previous value",
1471
+ bind: "left,h",
1472
+ run: () => {
1473
+ pageApi?.step(-1);
1474
+ }
1475
+ },
1476
+ {
1477
+ id: "pantheon.settings.actuate",
1478
+ title: "Apply / act on the row",
1479
+ bind: "enter,space",
1480
+ run: () => {
1481
+ pageApi?.actuate();
1482
+ }
1483
+ },
1484
+ {
1485
+ id: "pantheon.settings.next.tab",
1486
+ title: "Next settings tab",
1487
+ bind: "tab",
1488
+ run: () => {
1489
+ pageApi?.nextTab();
1490
+ }
1491
+ },
1492
+ {
1493
+ id: "pantheon.settings.save",
1494
+ title: "Save staged changes",
1495
+ bind: "ctrl+s",
1496
+ run: () => {
1497
+ pageApi?.save();
1498
+ }
1499
+ },
1500
+ {
1501
+ id: "pantheon.settings.reset.page",
1502
+ title: "Reset this tab",
1503
+ bind: "ctrl+r",
1504
+ run: () => {
1505
+ pageApi?.resetPage();
1506
+ }
1507
+ },
1508
+ ...Array.from({ length: 9 }, (_, index) => ({
1509
+ id: `pantheon.settings.tab.${index + 1}`,
1510
+ title: `Jump to tab ${index + 1}`,
1511
+ bind: String(index + 1),
1512
+ run: () => {
1513
+ pageApi?.jumpTab(index);
1514
+ }
1515
+ }))
1516
+ ];
1517
+ try {
1518
+ context.keymap.layer(() => ({
1519
+ mode: "global",
1520
+ priority: 1,
1521
+ enabled: () => routeGated(),
1522
+ commands
1523
+ }));
1524
+ } catch {}
1525
+ try {
1526
+ context.keymap.layer(() => ({
1527
+ mode: "global",
1528
+ priority: 1,
1529
+ enabled: () => dialogOpen(),
1530
+ commands
1531
+ }));
1532
+ } catch {}
1533
+ }
1534
+ async function openPantheonSettings(context) {
1535
+ try {
1536
+ if (routerAvailable && context.ui?.router?.navigate) {
1537
+ let returnRoute;
1163
1538
  try {
1164
- context.ui.dialog.set?.({ size: "xlarge" });
1165
- } catch {}
1166
- } catch {}
1539
+ const current = context.ui.router.current();
1540
+ if (!(current.type === "plugin" && current.name === "pantheon-settings")) returnRoute = current;
1541
+ } catch {
1542
+ returnRoute = void 0;
1543
+ }
1544
+ context.ui.router.navigate({
1545
+ type: "plugin",
1546
+ name: ROUTE_NAME,
1547
+ ...returnRoute !== void 0 ? { data: { returnRoute } } : {}
1548
+ });
1549
+ return;
1550
+ }
1167
1551
  } catch {}
1552
+ openSettingsDialog(context);
1168
1553
  }
1169
1554
  //#endregion
1170
1555
  //#region src/sidebar-width.ts
@@ -1475,7 +1860,7 @@ async function readChangelogForBundle(bundleUrl) {
1475
1860
  }
1476
1861
  /** The ambient build-time version, or null outside a tsdown build. */
1477
1862
  function embeddedVersion() {
1478
- return "2.0.0-beta.3";
1863
+ return "2.0.0-beta.4";
1479
1864
  }
1480
1865
  /**
1481
1866
  * Resolve the running Pantheon version for the what's-new window: the plugin
@@ -4113,7 +4498,7 @@ async function checkForPantheonUpdate(context) {
4113
4498
  const latest = String((await response.json())?.version ?? "");
4114
4499
  if (!latest) return;
4115
4500
  const notice = pickUpdateNotice({
4116
- currentVersion: "2.0.0-beta.3",
4501
+ currentVersion: "2.0.0-beta.4",
4117
4502
  latestVersion: latest,
4118
4503
  state: readState(),
4119
4504
  nowMs: Date.now()
@@ -4893,7 +5278,7 @@ function Sidebar(props) {
4893
5278
  setProp(_el$12, "width", "100%");
4894
5279
  setProp(_el$12, "padding", 1);
4895
5280
  setProp(_el$13, "attributes", 1);
4896
- insert(_el$13, `Pantheon v2.0.0-beta.3`);
5281
+ insert(_el$13, `Pantheon v2.0.0-beta.4`);
4897
5282
  insert(_el$14, () => presetHeaderLine(model.preset().name ?? "", model.provider()));
4898
5283
  insert(_el$12, createComponent(Show, {
4899
5284
  get when() {
@@ -5389,7 +5774,7 @@ function runDispatchPanelCommand(action, panel, model) {
5389
5774
  * focused and the composer lost its keys. `enabled` (the documented gate) makes
5390
5775
  * the whole layer inert until `panel.focused` is true. Pure. */
5391
5776
  function dispatchPanelKeymapLayer(panel, model) {
5392
- const focused = () => panel.focused === true;
5777
+ const focused = () => panel.focused === true && !pantheonSettingsBlocking();
5393
5778
  return {
5394
5779
  mode: "global",
5395
5780
  enabled: focused,
@@ -5621,7 +6006,7 @@ function PantheonSettingsCommandLayer(props) {
5621
6006
  palette: true,
5622
6007
  slash: { name: "pantheon-settings" },
5623
6008
  run: () => {
5624
- maybeShowPantheonSettings(props.context);
6009
+ openPantheonSettings(props.context);
5625
6010
  }
5626
6011
  }]
5627
6012
  }));
@@ -5635,7 +6020,7 @@ function HomeStatus(props) {
5635
6020
  const muted = () => props.context.theme?.text?.muted ?? props.context.theme?.text?.base;
5636
6021
  return (() => {
5637
6022
  var _el$72 = createElement("text");
5638
- insert(_el$72, () => `Pantheon v2.0.0-beta.3${preset().name ? ` ▸ ${preset().name}` : ""}`);
6023
+ insert(_el$72, () => `Pantheon v2.0.0-beta.4${preset().name ? ` ▸ ${preset().name}` : ""}`);
5639
6024
  effect((_$p) => setProp(_el$72, "fg", muted(), _$p));
5640
6025
  return _el$72;
5641
6026
  })();
@@ -5749,6 +6134,9 @@ const plugin = Plugin.define({
5749
6134
  append: "app",
5750
6135
  render: () => createComponent(PantheonSettingsCommandLayer, { context })
5751
6136
  });
6137
+ try {
6138
+ setupPantheonSettings(context);
6139
+ } catch {}
5752
6140
  maybeShowWhatsNewV2(context);
5753
6141
  return () => {
5754
6142
  clearTimeout(updateNoticeTimer);