pantheon-opencode 1.7.0 → 2.0.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.global.md +2 -2
- package/AGENTS.md +3 -3
- package/CHANGELOG.md +85 -59
- package/README.md +74 -48
- package/README.pt-BR.md +19 -19
- package/bin/pantheon-init.mjs +11 -48
- package/package.json +9 -13
- package/plugin.json +2 -2
- package/pyproject.toml +1 -1
- package/scripts/build-agents-md.mjs +7 -6
- package/scripts/{check-plugin-v2-coverage.mjs → check-plugin-coverage.mjs} +7 -7
- package/scripts/{decision-router-v2-budget.mjs → decision-router-budget-gates.mjs} +1 -1
- package/scripts/{decision-router-v2-egress.mjs → decision-router-egress.mjs} +1 -1
- package/scripts/decision-router.mjs +2 -2
- package/scripts/docs-media.mjs +1 -1
- package/scripts/doctor.mjs +225 -136
- package/scripts/install/behavior-overrides.bundle.mjs +123 -0
- package/scripts/install/{v2-capabilities.mjs → capabilities.mjs} +7 -7
- package/scripts/install/config-migration.mjs +60 -253
- package/scripts/install/file-inventory.mjs +6 -4
- package/scripts/install/interactive.mjs +1 -1
- package/scripts/install/opencode-state.mjs +13 -12
- package/scripts/install/opencode-version.mjs +97 -162
- package/scripts/install/opencode.mjs +271 -428
- package/scripts/install/plan.mjs +1 -9
- package/scripts/install/plugin.mjs +19 -35
- package/scripts/install/shared.mjs +40 -1
- package/scripts/package-evidence.mjs +1 -4
- package/scripts/probe-pantheon-cost.mjs +1 -1
- package/scripts/reconcile.mjs +5 -7
- package/scripts/release-gates.mjs +22 -61
- package/scripts/setup-v2-config.mjs +10 -8
- package/scripts/setup.mjs +12 -22
- package/scripts/sync-tui.mjs +9 -17
- package/scripts/{test-opencode-v2-sandbox.sh → test-opencode-sandbox.sh} +9 -9
- package/scripts/update-skills-lock.mjs +24 -12
- package/scripts/update.mjs +17 -1
- package/scripts/validate-routing.mjs +79 -4
- package/scripts/validate-sandbox-install.mjs +3 -3
- package/skills-lock.json +25 -8
- package/src/agents/zeus.md +1 -0
- package/src/pantheon/behavior-overrides.ts +191 -0
- package/src/pantheon/{v2-bounded-read.ts → bounded-read.ts} +1 -1
- package/src/pantheon/cost-command.ts +1 -1
- package/src/pantheon/{v2-decision-contracts.ts → decision-contracts.ts} +3 -3
- package/src/pantheon/{v2-decision-points → decision-points}/p1-agent.ts +3 -3
- package/src/pantheon/{v2-decision-points → decision-points}/p10-claims.ts +2 -2
- package/src/pantheon/{v2-decision-points → decision-points}/p11-catalog.ts +2 -2
- package/src/pantheon/{v2-decision-points → decision-points}/p2-skill.ts +3 -3
- package/src/pantheon/{v2-decision-points → decision-points}/p3-complexity.ts +6 -6
- package/src/pantheon/{v2-decision-points → decision-points}/p4-memory.ts +2 -2
- package/src/pantheon/{v2-decision-points → decision-points}/p5-themis-verify.ts +2 -2
- package/src/pantheon/{v2-decision-points → decision-points}/p6-council.ts +3 -3
- package/src/pantheon/{v2-decision-points → decision-points}/p7-loop.ts +5 -5
- package/src/pantheon/{v2-decision-points → decision-points}/p8-guardrail.ts +2 -2
- package/src/pantheon/{v2-decision-points → decision-points}/p9-memory-compaction.ts +2 -2
- package/src/pantheon/{v2-decision-points.ts → decision-points.ts} +5 -5
- package/src/pantheon/{v2-decision-policy.ts → decision-policy.ts} +2 -2
- package/src/pantheon/{v2-decision-prompt-surface.ts → decision-prompt-surface.ts} +3 -3
- package/src/pantheon/{v2-decision-registry.ts → decision-registry.ts} +10 -13
- package/src/pantheon/{v2-decision-resource-ids.ts → decision-resource-ids.ts} +1 -1
- package/src/pantheon/{v2-decision-shadow.ts → decision-shadow.ts} +1 -1
- package/src/pantheon/{v2-decision-telemetry.ts → decision-telemetry.ts} +1 -1
- package/src/pantheon/{v2-execute-after.ts → execute-after.ts} +4 -4
- package/src/pantheon/goal-store.ts +7 -0
- package/src/pantheon/{v2-hook-engine.ts → hook-engine.ts} +3 -3
- package/src/pantheon/jev-decision-tool.ts +3 -3
- package/src/pantheon/jev-decisions.ts +12 -6
- package/src/pantheon/jev-escalation.ts +6 -6
- package/src/pantheon/jev-quality-score.ts +2 -2
- package/src/pantheon/jev-rank-verify.ts +2 -2
- package/src/pantheon/jev-risk-gate.ts +4 -4
- package/src/pantheon/local-decision-agents.ts +1 -1
- package/src/pantheon/local-decision-router.ts +1 -1
- package/src/pantheon/local-decision-tool.ts +2 -2
- package/src/pantheon/local-orchestration.ts +1 -1
- package/src/pantheon/model-command.ts +1 -1
- package/src/pantheon/{v2-vision.ts → native-vision.ts} +12 -15
- package/src/pantheon/pantheon-decision-catalog.ts +12 -0
- package/src/pantheon/{v2-shell-hooks.ts → shell-hooks.ts} +4 -4
- package/src/pantheon/{v2-tools.ts → tools.ts} +4 -4
- package/src/pantheon/{v2-unsupported.d.mts → unsupported.d.mts} +3 -3
- package/src/pantheon/{v2-unsupported.mjs → unsupported.mjs} +8 -8
- package/src/pantheon/update-notifier.ts +101 -0
- package/src/pantheon/vision-local.ts +12 -3
- package/src/pantheon/vision.ts +120 -2
- package/src/{plugin-v2 → plugin}/index.ts +7 -7
- package/src/plugin.ts +2870 -500
- package/src/plugins/hook-runner.ts +3 -3
- package/src/plugins/tui/dist/server.d.ts +23 -9
- package/src/plugins/tui/dist/server.d.ts.map +1 -1
- package/src/plugins/tui/dist/server.js +25 -12
- package/src/plugins/tui/dist/server.js.map +1 -1
- package/src/plugins/tui/dist/tui.d.ts +1023 -494
- package/src/plugins/tui/dist/tui.d.ts.map +1 -1
- package/src/plugins/tui/dist/tui.js +5612 -2086
- package/src/plugins/tui/dist/tui.js.map +1 -1
- package/src/plugins/tui/{index-v2.ts → index.ts} +1 -1
- package/src/plugins/tui/package-lock.json +2 -42
- package/src/plugins/tui/package.json +4 -10
- package/src/plugins/tui/src/cost-data.ts +1 -1
- package/src/plugins/tui/src/decision-router-state.ts +242 -0
- package/src/plugins/tui/src/doctor-state.ts +198 -0
- package/src/plugins/tui/src/index.tsx +4222 -2822
- package/src/plugins/tui/src/j1-gate-status.ts +85 -0
- package/src/plugins/tui/src/pantheon-settings-state.ts +245 -0
- package/src/plugins/tui/src/pantheon-settings.tsx +442 -0
- package/src/plugins/tui/src/preset-state.ts +143 -0
- package/src/plugins/tui/src/server.ts +23 -10
- package/src/plugins/tui/src/update-notice.ts +90 -0
- package/src/plugins/tui/src/update-status.ts +98 -0
- package/src/plugins/tui/tsconfig.typecheck.json +9 -2
- package/src/plugins/tui/tsdown.config.ts +3 -5
- package/src/plugins/tui/tui.ts +1 -2
- package/src/routing.yml +36 -0
- package/src/skills/README.md +16 -1
- package/src/skills/artifact-management/SKILL.md +10 -67
- package/src/skills/artifact-management/references/artifact-templates.md +71 -0
- package/src/skills/auto-continue/SKILL.md +10 -0
- package/src/skills/code-review-checklist/SKILL.md +11 -44
- package/src/skills/code-review-checklist/references/review-checklists.md +54 -0
- package/src/skills/instruction-forge/SKILL.md +57 -0
- package/src/skills/instruction-forge/references/agents-md-doctrine.md +50 -0
- package/src/skills/instruction-forge/references/eval-doctrine.md +37 -0
- package/src/skills/instruction-forge/references/skill-doctrine.md +62 -0
- package/src/skills/memory-bank/SKILL.md +11 -90
- package/src/skills/memory-bank/references/anti-patterns.md +33 -0
- package/src/skills/memory-bank/references/product-adoption.md +19 -0
- package/src/skills/memory-bank/references/storage-model.md +21 -0
- package/src/skills/memory-bank/references/structure-and-frequency.md +44 -0
- package/src/skills/reflect/SKILL.md +1 -0
- package/src/skills/session-goal/SKILL.md +7 -54
- package/src/skills/session-goal/references/goal-format.md +26 -0
- package/src/skills/session-goal/references/session-reuse.md +44 -0
- package/src/skills/tdd-with-agents/SKILL.md +11 -101
- package/src/skills/tdd-with-agents/references/advanced-testing-patterns.md +58 -0
- package/src/skills/tdd-with-agents/references/testing-by-layer.md +60 -0
- package/src/skills/visual-review-pipeline/SKILL.md +11 -120
- package/src/skills/visual-review-pipeline/references/findings-schema.md +49 -0
- package/src/skills/visual-review-pipeline/references/workflow-steps.md +111 -0
- package/scripts/hooks/log-session-start.sh +0 -48
- package/scripts/hooks/validate-post-conditions.sh +0 -21
- package/scripts/hooks/validate-talos-scope.sh +0 -50
- package/scripts/hooks/validate-tool-safety.sh +0 -49
- package/src/pantheon/goal-loop.ts +0 -314
- package/src/pantheon/idle-continuation.ts +0 -52
- package/src/pantheon/todo-preserve.ts +0 -301
- package/src/pantheon/tool-ceiling.ts +0 -159
- package/src/pantheon/v2-bridge.ts +0 -153
- package/src/plugin-v2.ts +0 -2954
- package/src/plugins/pantheon-hooks.ts +0 -1433
- package/src/plugins/tui/dist/server-v2.d.ts +0 -30
- package/src/plugins/tui/dist/server-v2.d.ts.map +0 -1
- package/src/plugins/tui/dist/server-v2.js +0 -33
- package/src/plugins/tui/dist/server-v2.js.map +0 -1
- package/src/plugins/tui/dist/tui-v2.d.ts +0 -1039
- package/src/plugins/tui/dist/tui-v2.d.ts.map +0 -1
- package/src/plugins/tui/dist/tui-v2.js +0 -4597
- package/src/plugins/tui/dist/tui-v2.js.map +0 -1
- package/src/plugins/tui/src/index-v2.tsx +0 -4496
- package/src/plugins/tui/src/server-v2.ts +0 -28
- package/src/plugins/tui/tui-v2.ts +0 -2
- /package/src/pantheon/{v2-decision-budget.ts → decision-budget.ts} +0 -0
- /package/src/pantheon/{v2-decision-egress.ts → decision-egress.ts} +0 -0
- /package/src/pantheon/{v2-decision-events.ts → decision-events.ts} +0 -0
- /package/src/pantheon/{v2-decision-heuristic.ts → decision-heuristic.ts} +0 -0
- /package/src/pantheon/{v2-decision-premises.ts → decision-premises.ts} +0 -0
- /package/src/pantheon/{v2-decision-rank.ts → decision-rank.ts} +0 -0
- /package/src/pantheon/{v2-decision-verify.ts → decision-verify.ts} +0 -0
- /package/src/pantheon/{v2-delegation-enforce.ts → delegation-policy.ts} +0 -0
- /package/src/pantheon/{v2-model-overrides.ts → model-overrides.ts} +0 -0
- /package/src/pantheon/{v2-native-decisions.ts → native-decisions.ts} +0 -0
- /package/src/plugins/tui/src/{opencode-v2.d.ts → opencode.d.ts} +0 -0
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* j1-gate-status.ts — the J1 Risk Gate section of the settings window.
|
|
3
|
+
*
|
|
4
|
+
* TUI-local replica of the ladder in src/pantheon/jev-risk-gate.ts (the
|
|
5
|
+
* bundle must stay self-contained); tests/tui-settings-j1.test.mjs pins the
|
|
6
|
+
* env names, the ladder values and the default threshold against that source.
|
|
7
|
+
*
|
|
8
|
+
* STATUS ONLY by design: the ladder has no file surface yet — mode and
|
|
9
|
+
* threshold are env-only and read once at plugin setup — so nothing here
|
|
10
|
+
* writes, and the section says so. A file surface is a runtime-plugin change
|
|
11
|
+
* (beta.3 candidate), not a window change.
|
|
12
|
+
*/
|
|
13
|
+
import type { SettingsRow, SettingsSection } from './pantheon-settings-state.ts'
|
|
14
|
+
|
|
15
|
+
export const J1_FLAG_ENV = 'PANTHEON_J1_RISK_SCORE'
|
|
16
|
+
export const J1_THRESHOLD_ENV = 'PANTHEON_J1_ENFORCE_THRESHOLD'
|
|
17
|
+
export const J1_THRESHOLD_DEFAULT = 0.8
|
|
18
|
+
|
|
19
|
+
export type J1Mode = 'off' | 'shadow' | 'warn' | 'enforce'
|
|
20
|
+
|
|
21
|
+
/** `1`/`on`/`true` map to `shadow` for back-compatibility with the shipped setup. */
|
|
22
|
+
const FLAG_ON = new Set(['1', 'on', 'true', 'shadow'])
|
|
23
|
+
|
|
24
|
+
export function j1ModeFromEnv(env: Record<string, string | undefined> = process.env): J1Mode {
|
|
25
|
+
const raw = (env[J1_FLAG_ENV] ?? '').trim().toLowerCase()
|
|
26
|
+
if (raw === 'enforce') return 'enforce'
|
|
27
|
+
if (raw === 'warn') return 'warn'
|
|
28
|
+
return FLAG_ON.has(raw) ? 'shadow' : 'off'
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** Invalid or out-of-range values fall back to the default — a typo must not disable the gate. */
|
|
32
|
+
export function j1ThresholdFromEnv(env: Record<string, string | undefined> = process.env): number {
|
|
33
|
+
const text = (env[J1_THRESHOLD_ENV] ?? '').trim()
|
|
34
|
+
if (text === '') return J1_THRESHOLD_DEFAULT
|
|
35
|
+
const raw = Number(text)
|
|
36
|
+
if (!Number.isFinite(raw) || raw < 0 || raw > 1) return J1_THRESHOLD_DEFAULT
|
|
37
|
+
return raw
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const MODE_DESCRIPTION: Record<J1Mode, string> = {
|
|
41
|
+
off: 'nothing fires (hard zero)',
|
|
42
|
+
shadow: 'observe + record; invisible in the session',
|
|
43
|
+
warn: 'RESERVED — behaves as shadow in this release',
|
|
44
|
+
enforce: 'high-risk scores DENY the tool call (fail-open on gate unavailability)',
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function buildJ1Section(
|
|
48
|
+
env: Record<string, string | undefined>,
|
|
49
|
+
disabledByOverride: boolean,
|
|
50
|
+
): SettingsSection {
|
|
51
|
+
const mode = j1ModeFromEnv(env)
|
|
52
|
+
const threshold = j1ThresholdFromEnv(env)
|
|
53
|
+
const gateState = disabledByOverride
|
|
54
|
+
? 'disabled via overrides'
|
|
55
|
+
: mode === 'off'
|
|
56
|
+
? 'off (env unset)'
|
|
57
|
+
: 'active'
|
|
58
|
+
const rows: SettingsRow[] = [
|
|
59
|
+
{
|
|
60
|
+
id: 'j1.mode',
|
|
61
|
+
title: `Mode: ${mode}`,
|
|
62
|
+
description: MODE_DESCRIPTION[mode],
|
|
63
|
+
...(disabledByOverride ? { marker: '[!]' } : {}),
|
|
64
|
+
selectable: false,
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
id: 'j1.threshold',
|
|
68
|
+
title: `Enforce threshold: ${threshold}`,
|
|
69
|
+
description: 'deny at or above; 0..1, default 0.8',
|
|
70
|
+
selectable: false,
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
id: 'j1.gate',
|
|
74
|
+
title: `Gate: ${gateState}`,
|
|
75
|
+
description: 'the runtime plugin reads this once at startup',
|
|
76
|
+
selectable: false,
|
|
77
|
+
},
|
|
78
|
+
]
|
|
79
|
+
return {
|
|
80
|
+
id: 'j1',
|
|
81
|
+
title: 'J1 Risk Gate',
|
|
82
|
+
hint: `set ${J1_FLAG_ENV} / ${J1_THRESHOLD_ENV} — restart applies`,
|
|
83
|
+
rows,
|
|
84
|
+
}
|
|
85
|
+
}
|
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* pantheon-settings-state.ts — the pure state core of the settings window.
|
|
3
|
+
*
|
|
4
|
+
* TUI-local copy doctrine (same as cost-data.ts): the bundle must stay
|
|
5
|
+
* self-contained. The behaviors registry mirrors routing.yml's `behaviors:`
|
|
6
|
+
* (drift-pinned by tests/pantheon-settings-state.test.mjs); the Gates section
|
|
7
|
+
* reads and writes the GLOBAL overrides file — the same one
|
|
8
|
+
* `pantheon-opencode`'s installer and doctor consume
|
|
9
|
+
* (`<config-dir>/pantheon-overrides.json`).
|
|
10
|
+
*
|
|
11
|
+
* Sections: the window renders one section per page. This module owns the
|
|
12
|
+
* section/row model and the Gates section; other sections live in sibling
|
|
13
|
+
* TUI-local modules (j1-gate-status.ts, update-status.ts, …) and follow the
|
|
14
|
+
* same shape.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
export interface SettingsBehavior {
|
|
18
|
+
id: string
|
|
19
|
+
kind: 'install' | 'runtime'
|
|
20
|
+
title: string
|
|
21
|
+
description: string
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** Mirrors routing.yml `behaviors:` — drift-pinned by the registry test. */
|
|
25
|
+
export const SETTINGS_BEHAVIORS: readonly SettingsBehavior[] = Object.freeze([
|
|
26
|
+
{
|
|
27
|
+
id: 'skill-auto-continue',
|
|
28
|
+
kind: 'install',
|
|
29
|
+
title: 'Auto-continue skill',
|
|
30
|
+
description: 'Continue multi-step todos while keeping safety gates.',
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
id: 'skill-tdd-with-agents',
|
|
34
|
+
kind: 'install',
|
|
35
|
+
title: 'TDD with agents skill',
|
|
36
|
+
description: 'RED, GREEN, REFACTOR test-driven implementation.',
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
id: 'skill-code-review-checklist',
|
|
40
|
+
kind: 'install',
|
|
41
|
+
title: 'Code review checklist skill',
|
|
42
|
+
description: 'Systematic code review and quality gates.',
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
id: 'skill-prompt-refinery',
|
|
46
|
+
kind: 'install',
|
|
47
|
+
title: 'Prompt refinery skill',
|
|
48
|
+
description: 'Vague requests refined — silent adjust, >> full contract.',
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
id: 'gate-idle-todo-enforcer',
|
|
52
|
+
kind: 'runtime',
|
|
53
|
+
title: 'Idle todo enforcer',
|
|
54
|
+
description: 'Continues pending todos when a session goes idle.',
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
id: 'gate-context-pruner',
|
|
58
|
+
kind: 'runtime',
|
|
59
|
+
title: 'Context pruner',
|
|
60
|
+
description: 'Prunes repeated tool output before summarization.',
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
id: 'gate-j1-risk-gate',
|
|
64
|
+
kind: 'runtime',
|
|
65
|
+
title: 'J1 risk gate',
|
|
66
|
+
description: 'High-risk tool calls demand explicit human approval.',
|
|
67
|
+
},
|
|
68
|
+
])
|
|
69
|
+
|
|
70
|
+
export interface OverrideEntry {
|
|
71
|
+
action: 'disable' | 'replace'
|
|
72
|
+
content?: string
|
|
73
|
+
reason?: string
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export type EffectiveOverrides = Record<string, OverrideEntry>
|
|
77
|
+
|
|
78
|
+
/** Which behaviors the settings window can toggle (runtime + install skills). */
|
|
79
|
+
export const SETTINGS_TOGGLABLE_IDS = new Set(SETTINGS_BEHAVIORS.map((b) => b.id))
|
|
80
|
+
|
|
81
|
+
export function isBehaviorDisabled(effective: EffectiveOverrides, id: string): boolean {
|
|
82
|
+
return effective[id]?.action === 'disable'
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// ── Section / row model ────────────────────────────────────────────────
|
|
86
|
+
|
|
87
|
+
export interface SettingsRow {
|
|
88
|
+
/** Namespaced action key (`gate.<behavior-id>`, `update.check`, …). */
|
|
89
|
+
id: string
|
|
90
|
+
title: string
|
|
91
|
+
description: string
|
|
92
|
+
/** Gates rows: the override disables the behavior (`[x]` marker). */
|
|
93
|
+
disabled?: boolean
|
|
94
|
+
/** Overrides the `[x]`/`[ ]` marker (`→` action, `✓`/`!` status). */
|
|
95
|
+
marker?: string
|
|
96
|
+
/** false → skipped by up/down and never dispatched by enter (info lines). */
|
|
97
|
+
selectable?: boolean
|
|
98
|
+
/** The effective entry comes from the PROJECT overrides file (read-only). */
|
|
99
|
+
source?: 'global' | 'project'
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export interface SettingsSection {
|
|
103
|
+
id: string
|
|
104
|
+
title: string
|
|
105
|
+
/** One muted hint line under the rows. */
|
|
106
|
+
hint?: string
|
|
107
|
+
rows: SettingsRow[]
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** The rows up/down can reach and enter can dispatch on, in order. */
|
|
111
|
+
export function selectableRows(section: SettingsSection): SettingsRow[] {
|
|
112
|
+
return section.rows.filter((row) => row.selectable !== false)
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** Flat selection order across every section of the window. */
|
|
116
|
+
export function flatSelectableRows(sections: readonly SettingsSection[]): SettingsRow[] {
|
|
117
|
+
return sections.flatMap((section) => selectableRows(section))
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export function firstSelectableId(sections: readonly SettingsSection[]): string | undefined {
|
|
121
|
+
return flatSelectableRows(sections)[0]?.id
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// ── Overrides load (global + project files) ────────────────────────────
|
|
125
|
+
|
|
126
|
+
export interface OverridesLoad {
|
|
127
|
+
global: EffectiveOverrides
|
|
128
|
+
project: EffectiveOverrides
|
|
129
|
+
/** The GLOBAL file exists but does not parse — writes are refused. */
|
|
130
|
+
corruptGlobal: boolean
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Merge for DISPLAY only, mirroring the runtime precedence: the project file
|
|
135
|
+
* wins per id (whole entry). The window still writes only the global file.
|
|
136
|
+
*/
|
|
137
|
+
export function mergedOverrides(load: OverridesLoad): EffectiveOverrides {
|
|
138
|
+
return { ...load.global, ...load.project }
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export function canWriteOverrides(load: OverridesLoad): boolean {
|
|
142
|
+
return !load.corruptGlobal
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// ── Toggle semantics ───────────────────────────────────────────────────
|
|
146
|
+
|
|
147
|
+
export const TOGGLE_REASON = 'toggled in /pantheon-settings'
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Toggle: disabled -> enabled; enabled -> disabled.
|
|
151
|
+
*
|
|
152
|
+
* A `replace` entry is never destroyed by a toggle ("never trap user state"):
|
|
153
|
+
* disabling keeps its `content` under the disable entry, and re-enabling
|
|
154
|
+
* restores the replace. A settings-written disable (no content) is removed
|
|
155
|
+
* outright so the overrides file does not accumulate toggle noise.
|
|
156
|
+
*/
|
|
157
|
+
export function toggledOverrides(
|
|
158
|
+
effective: EffectiveOverrides,
|
|
159
|
+
id: string,
|
|
160
|
+
reason: string = TOGGLE_REASON,
|
|
161
|
+
): EffectiveOverrides {
|
|
162
|
+
const next: EffectiveOverrides = { ...effective }
|
|
163
|
+
const entry = next[id]
|
|
164
|
+
if (entry?.action === 'disable') {
|
|
165
|
+
if (entry.content !== undefined) {
|
|
166
|
+
// A settings-written disable restores a clean replace; a hand-authored
|
|
167
|
+
// disable+content keeps its own provenance reason.
|
|
168
|
+
next[id] =
|
|
169
|
+
entry.reason === reason
|
|
170
|
+
? { action: 'replace', content: entry.content }
|
|
171
|
+
: {
|
|
172
|
+
action: 'replace',
|
|
173
|
+
content: entry.content,
|
|
174
|
+
...(entry.reason !== undefined ? { reason: entry.reason } : {}),
|
|
175
|
+
}
|
|
176
|
+
} else {
|
|
177
|
+
delete next[id]
|
|
178
|
+
}
|
|
179
|
+
} else {
|
|
180
|
+
next[id] =
|
|
181
|
+
entry?.content !== undefined
|
|
182
|
+
? { action: 'disable', reason, content: entry.content }
|
|
183
|
+
: { action: 'disable', reason }
|
|
184
|
+
}
|
|
185
|
+
return next
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
export function serializeOverrides(effective: EffectiveOverrides): string {
|
|
189
|
+
const ordered: Record<string, unknown> = {}
|
|
190
|
+
for (const id of Object.keys(effective).sort()) ordered[id] = effective[id]
|
|
191
|
+
return `${JSON.stringify(ordered, null, 2)}\n`
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// ── Gates section ──────────────────────────────────────────────────────
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* The Gates & Overrides page: behavior state from BOTH overrides files.
|
|
198
|
+
* A project-owned entry wins the runtime merge and the window only writes
|
|
199
|
+
* the global file, so project rows are marked and not togglable here.
|
|
200
|
+
*/
|
|
201
|
+
export function buildGatesSection(load: OverridesLoad): SettingsSection {
|
|
202
|
+
const merged = mergedOverrides(load)
|
|
203
|
+
const rows: SettingsRow[] = SETTINGS_BEHAVIORS.map((behavior) => {
|
|
204
|
+
const fromProject = load.project[behavior.id] !== undefined
|
|
205
|
+
return {
|
|
206
|
+
id: `gate.${behavior.id}`,
|
|
207
|
+
title: fromProject ? `${behavior.title} (project)` : behavior.title,
|
|
208
|
+
description: behavior.description,
|
|
209
|
+
disabled: isBehaviorDisabled(merged, behavior.id),
|
|
210
|
+
selectable: !fromProject,
|
|
211
|
+
source: fromProject ? 'project' : 'global',
|
|
212
|
+
}
|
|
213
|
+
})
|
|
214
|
+
return {
|
|
215
|
+
id: 'gates',
|
|
216
|
+
title: 'Gates & Overrides',
|
|
217
|
+
hint: canWriteOverrides(load)
|
|
218
|
+
? 'enter: disable/enable · writes pantheon-overrides.json (global)'
|
|
219
|
+
: 'overrides file unreadable — writes refused; repair with `pantheon-opencode doctor --fix`',
|
|
220
|
+
rows,
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
// ── About section ──────────────────────────────────────────────────────
|
|
225
|
+
|
|
226
|
+
export function buildAboutSection(version: string): SettingsSection {
|
|
227
|
+
return {
|
|
228
|
+
id: 'about',
|
|
229
|
+
title: 'About',
|
|
230
|
+
rows: [
|
|
231
|
+
{
|
|
232
|
+
id: 'about.version',
|
|
233
|
+
title: `Pantheon v${version}`,
|
|
234
|
+
description: 'OpenCode 2.x only — the V1 contract is removed.',
|
|
235
|
+
selectable: false,
|
|
236
|
+
},
|
|
237
|
+
{
|
|
238
|
+
id: 'about.behaviors',
|
|
239
|
+
title: `${SETTINGS_BEHAVIORS.length} togglable behaviors`,
|
|
240
|
+
description: 'Docs: docs/design/2.0-settings-and-install.md',
|
|
241
|
+
selectable: false,
|
|
242
|
+
},
|
|
243
|
+
],
|
|
244
|
+
}
|
|
245
|
+
}
|