pantheon-opencode 1.7.0 → 2.0.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (173) hide show
  1. package/AGENTS.global.md +2 -2
  2. package/AGENTS.md +3 -3
  3. package/CHANGELOG.md +85 -59
  4. package/README.md +74 -48
  5. package/README.pt-BR.md +19 -19
  6. package/bin/pantheon-init.mjs +11 -48
  7. package/package.json +9 -13
  8. package/plugin.json +2 -2
  9. package/pyproject.toml +1 -1
  10. package/scripts/build-agents-md.mjs +7 -6
  11. package/scripts/{check-plugin-v2-coverage.mjs → check-plugin-coverage.mjs} +7 -7
  12. package/scripts/{decision-router-v2-budget.mjs → decision-router-budget-gates.mjs} +1 -1
  13. package/scripts/{decision-router-v2-egress.mjs → decision-router-egress.mjs} +1 -1
  14. package/scripts/decision-router.mjs +2 -2
  15. package/scripts/docs-media.mjs +1 -1
  16. package/scripts/doctor.mjs +225 -136
  17. package/scripts/install/behavior-overrides.bundle.mjs +123 -0
  18. package/scripts/install/{v2-capabilities.mjs → capabilities.mjs} +7 -7
  19. package/scripts/install/config-migration.mjs +60 -253
  20. package/scripts/install/file-inventory.mjs +6 -4
  21. package/scripts/install/interactive.mjs +1 -1
  22. package/scripts/install/opencode-state.mjs +13 -12
  23. package/scripts/install/opencode-version.mjs +97 -162
  24. package/scripts/install/opencode.mjs +271 -428
  25. package/scripts/install/plan.mjs +1 -9
  26. package/scripts/install/plugin.mjs +19 -35
  27. package/scripts/install/shared.mjs +40 -1
  28. package/scripts/package-evidence.mjs +1 -4
  29. package/scripts/probe-pantheon-cost.mjs +1 -1
  30. package/scripts/reconcile.mjs +5 -7
  31. package/scripts/release-gates.mjs +22 -61
  32. package/scripts/setup-v2-config.mjs +10 -8
  33. package/scripts/setup.mjs +12 -22
  34. package/scripts/sync-tui.mjs +9 -17
  35. package/scripts/{test-opencode-v2-sandbox.sh → test-opencode-sandbox.sh} +9 -9
  36. package/scripts/update-skills-lock.mjs +24 -12
  37. package/scripts/update.mjs +17 -1
  38. package/scripts/validate-routing.mjs +79 -4
  39. package/scripts/validate-sandbox-install.mjs +3 -3
  40. package/skills-lock.json +25 -8
  41. package/src/agents/zeus.md +1 -0
  42. package/src/pantheon/behavior-overrides.ts +191 -0
  43. package/src/pantheon/{v2-bounded-read.ts → bounded-read.ts} +1 -1
  44. package/src/pantheon/cost-command.ts +1 -1
  45. package/src/pantheon/{v2-decision-contracts.ts → decision-contracts.ts} +3 -3
  46. package/src/pantheon/{v2-decision-points → decision-points}/p1-agent.ts +3 -3
  47. package/src/pantheon/{v2-decision-points → decision-points}/p10-claims.ts +2 -2
  48. package/src/pantheon/{v2-decision-points → decision-points}/p11-catalog.ts +2 -2
  49. package/src/pantheon/{v2-decision-points → decision-points}/p2-skill.ts +3 -3
  50. package/src/pantheon/{v2-decision-points → decision-points}/p3-complexity.ts +6 -6
  51. package/src/pantheon/{v2-decision-points → decision-points}/p4-memory.ts +2 -2
  52. package/src/pantheon/{v2-decision-points → decision-points}/p5-themis-verify.ts +2 -2
  53. package/src/pantheon/{v2-decision-points → decision-points}/p6-council.ts +3 -3
  54. package/src/pantheon/{v2-decision-points → decision-points}/p7-loop.ts +5 -5
  55. package/src/pantheon/{v2-decision-points → decision-points}/p8-guardrail.ts +2 -2
  56. package/src/pantheon/{v2-decision-points → decision-points}/p9-memory-compaction.ts +2 -2
  57. package/src/pantheon/{v2-decision-points.ts → decision-points.ts} +5 -5
  58. package/src/pantheon/{v2-decision-policy.ts → decision-policy.ts} +2 -2
  59. package/src/pantheon/{v2-decision-prompt-surface.ts → decision-prompt-surface.ts} +3 -3
  60. package/src/pantheon/{v2-decision-registry.ts → decision-registry.ts} +10 -13
  61. package/src/pantheon/{v2-decision-resource-ids.ts → decision-resource-ids.ts} +1 -1
  62. package/src/pantheon/{v2-decision-shadow.ts → decision-shadow.ts} +1 -1
  63. package/src/pantheon/{v2-decision-telemetry.ts → decision-telemetry.ts} +1 -1
  64. package/src/pantheon/{v2-execute-after.ts → execute-after.ts} +4 -4
  65. package/src/pantheon/goal-store.ts +7 -0
  66. package/src/pantheon/{v2-hook-engine.ts → hook-engine.ts} +3 -3
  67. package/src/pantheon/jev-decision-tool.ts +3 -3
  68. package/src/pantheon/jev-decisions.ts +12 -6
  69. package/src/pantheon/jev-escalation.ts +6 -6
  70. package/src/pantheon/jev-quality-score.ts +2 -2
  71. package/src/pantheon/jev-rank-verify.ts +2 -2
  72. package/src/pantheon/jev-risk-gate.ts +4 -4
  73. package/src/pantheon/local-decision-agents.ts +1 -1
  74. package/src/pantheon/local-decision-router.ts +1 -1
  75. package/src/pantheon/local-decision-tool.ts +2 -2
  76. package/src/pantheon/local-orchestration.ts +1 -1
  77. package/src/pantheon/model-command.ts +1 -1
  78. package/src/pantheon/{v2-vision.ts → native-vision.ts} +12 -15
  79. package/src/pantheon/pantheon-decision-catalog.ts +12 -0
  80. package/src/pantheon/{v2-shell-hooks.ts → shell-hooks.ts} +4 -4
  81. package/src/pantheon/{v2-tools.ts → tools.ts} +4 -4
  82. package/src/pantheon/{v2-unsupported.d.mts → unsupported.d.mts} +3 -3
  83. package/src/pantheon/{v2-unsupported.mjs → unsupported.mjs} +8 -8
  84. package/src/pantheon/update-notifier.ts +101 -0
  85. package/src/pantheon/vision-local.ts +12 -3
  86. package/src/pantheon/vision.ts +120 -2
  87. package/src/{plugin-v2 → plugin}/index.ts +7 -7
  88. package/src/plugin.ts +2870 -500
  89. package/src/plugins/hook-runner.ts +3 -3
  90. package/src/plugins/tui/dist/server.d.ts +23 -9
  91. package/src/plugins/tui/dist/server.d.ts.map +1 -1
  92. package/src/plugins/tui/dist/server.js +25 -12
  93. package/src/plugins/tui/dist/server.js.map +1 -1
  94. package/src/plugins/tui/dist/tui.d.ts +1023 -494
  95. package/src/plugins/tui/dist/tui.d.ts.map +1 -1
  96. package/src/plugins/tui/dist/tui.js +5612 -2086
  97. package/src/plugins/tui/dist/tui.js.map +1 -1
  98. package/src/plugins/tui/{index-v2.ts → index.ts} +1 -1
  99. package/src/plugins/tui/package-lock.json +2 -42
  100. package/src/plugins/tui/package.json +4 -10
  101. package/src/plugins/tui/src/cost-data.ts +1 -1
  102. package/src/plugins/tui/src/decision-router-state.ts +242 -0
  103. package/src/plugins/tui/src/doctor-state.ts +198 -0
  104. package/src/plugins/tui/src/index.tsx +4222 -2822
  105. package/src/plugins/tui/src/j1-gate-status.ts +85 -0
  106. package/src/plugins/tui/src/pantheon-settings-state.ts +245 -0
  107. package/src/plugins/tui/src/pantheon-settings.tsx +442 -0
  108. package/src/plugins/tui/src/preset-state.ts +143 -0
  109. package/src/plugins/tui/src/server.ts +23 -10
  110. package/src/plugins/tui/src/update-notice.ts +90 -0
  111. package/src/plugins/tui/src/update-status.ts +98 -0
  112. package/src/plugins/tui/tsconfig.typecheck.json +9 -2
  113. package/src/plugins/tui/tsdown.config.ts +3 -5
  114. package/src/plugins/tui/tui.ts +1 -2
  115. package/src/routing.yml +36 -0
  116. package/src/skills/README.md +16 -1
  117. package/src/skills/artifact-management/SKILL.md +10 -67
  118. package/src/skills/artifact-management/references/artifact-templates.md +71 -0
  119. package/src/skills/auto-continue/SKILL.md +10 -0
  120. package/src/skills/code-review-checklist/SKILL.md +11 -44
  121. package/src/skills/code-review-checklist/references/review-checklists.md +54 -0
  122. package/src/skills/instruction-forge/SKILL.md +57 -0
  123. package/src/skills/instruction-forge/references/agents-md-doctrine.md +50 -0
  124. package/src/skills/instruction-forge/references/eval-doctrine.md +37 -0
  125. package/src/skills/instruction-forge/references/skill-doctrine.md +62 -0
  126. package/src/skills/memory-bank/SKILL.md +11 -90
  127. package/src/skills/memory-bank/references/anti-patterns.md +33 -0
  128. package/src/skills/memory-bank/references/product-adoption.md +19 -0
  129. package/src/skills/memory-bank/references/storage-model.md +21 -0
  130. package/src/skills/memory-bank/references/structure-and-frequency.md +44 -0
  131. package/src/skills/reflect/SKILL.md +1 -0
  132. package/src/skills/session-goal/SKILL.md +7 -54
  133. package/src/skills/session-goal/references/goal-format.md +26 -0
  134. package/src/skills/session-goal/references/session-reuse.md +44 -0
  135. package/src/skills/tdd-with-agents/SKILL.md +11 -101
  136. package/src/skills/tdd-with-agents/references/advanced-testing-patterns.md +58 -0
  137. package/src/skills/tdd-with-agents/references/testing-by-layer.md +60 -0
  138. package/src/skills/visual-review-pipeline/SKILL.md +11 -120
  139. package/src/skills/visual-review-pipeline/references/findings-schema.md +49 -0
  140. package/src/skills/visual-review-pipeline/references/workflow-steps.md +111 -0
  141. package/scripts/hooks/log-session-start.sh +0 -48
  142. package/scripts/hooks/validate-post-conditions.sh +0 -21
  143. package/scripts/hooks/validate-talos-scope.sh +0 -50
  144. package/scripts/hooks/validate-tool-safety.sh +0 -49
  145. package/src/pantheon/goal-loop.ts +0 -314
  146. package/src/pantheon/idle-continuation.ts +0 -52
  147. package/src/pantheon/todo-preserve.ts +0 -301
  148. package/src/pantheon/tool-ceiling.ts +0 -159
  149. package/src/pantheon/v2-bridge.ts +0 -153
  150. package/src/plugin-v2.ts +0 -2954
  151. package/src/plugins/pantheon-hooks.ts +0 -1433
  152. package/src/plugins/tui/dist/server-v2.d.ts +0 -30
  153. package/src/plugins/tui/dist/server-v2.d.ts.map +0 -1
  154. package/src/plugins/tui/dist/server-v2.js +0 -33
  155. package/src/plugins/tui/dist/server-v2.js.map +0 -1
  156. package/src/plugins/tui/dist/tui-v2.d.ts +0 -1039
  157. package/src/plugins/tui/dist/tui-v2.d.ts.map +0 -1
  158. package/src/plugins/tui/dist/tui-v2.js +0 -4597
  159. package/src/plugins/tui/dist/tui-v2.js.map +0 -1
  160. package/src/plugins/tui/src/index-v2.tsx +0 -4496
  161. package/src/plugins/tui/src/server-v2.ts +0 -28
  162. package/src/plugins/tui/tui-v2.ts +0 -2
  163. /package/src/pantheon/{v2-decision-budget.ts → decision-budget.ts} +0 -0
  164. /package/src/pantheon/{v2-decision-egress.ts → decision-egress.ts} +0 -0
  165. /package/src/pantheon/{v2-decision-events.ts → decision-events.ts} +0 -0
  166. /package/src/pantheon/{v2-decision-heuristic.ts → decision-heuristic.ts} +0 -0
  167. /package/src/pantheon/{v2-decision-premises.ts → decision-premises.ts} +0 -0
  168. /package/src/pantheon/{v2-decision-rank.ts → decision-rank.ts} +0 -0
  169. /package/src/pantheon/{v2-decision-verify.ts → decision-verify.ts} +0 -0
  170. /package/src/pantheon/{v2-delegation-enforce.ts → delegation-policy.ts} +0 -0
  171. /package/src/pantheon/{v2-model-overrides.ts → model-overrides.ts} +0 -0
  172. /package/src/pantheon/{v2-native-decisions.ts → native-decisions.ts} +0 -0
  173. /package/src/plugins/tui/src/{opencode-v2.d.ts → opencode.d.ts} +0 -0
@@ -0,0 +1,123 @@
1
+ // Generated by scripts/build-decision-router.mjs. The published CLI cannot
2
+ // import TypeScript from node_modules, so it imports this prebuilt ESM bundle
3
+ // instead. Do not edit: run `npm run build:decision-router`.
4
+
5
+ // src/pantheon/behavior-overrides.ts
6
+ var OVERRIDE_CONTENT_MAX = 8e3;
7
+ var OVERRIDE_REASON_MAX = 200;
8
+ function validateEntry(id, value, label, errors) {
9
+ if (value === null || typeof value !== "object" || Array.isArray(value)) {
10
+ errors.push(`${label}: "${id}" must be an object`);
11
+ return;
12
+ }
13
+ const entry = value;
14
+ for (const key of Object.keys(entry)) {
15
+ if (key !== "action" && key !== "content" && key !== "reason") {
16
+ errors.push(`${label}: "${id}" has unknown key "${key}"`);
17
+ }
18
+ }
19
+ if (entry.action !== "disable" && entry.action !== "replace") {
20
+ errors.push(`${label}: "${id}".action must be "disable" or "replace"`);
21
+ return;
22
+ }
23
+ if (entry.action === "replace") {
24
+ const content = entry.content;
25
+ if (typeof content !== "string" || content.length === 0) {
26
+ errors.push(`${label}: "${id}".content is required for action "replace"`);
27
+ } else if (content.length > OVERRIDE_CONTENT_MAX) {
28
+ errors.push(
29
+ `${label}: "${id}".content is ${content.length} chars \u2014 over the ${OVERRIDE_CONTENT_MAX}-char cap`
30
+ );
31
+ }
32
+ }
33
+ if (entry.reason !== void 0 && (typeof entry.reason !== "string" || entry.reason.length > OVERRIDE_REASON_MAX)) {
34
+ errors.push(`${label}: "${id}".reason must be a string of at most ${OVERRIDE_REASON_MAX} chars`);
35
+ }
36
+ }
37
+ function parseOverridesFile(raw, label = "overrides") {
38
+ const errors = [];
39
+ let data;
40
+ try {
41
+ data = JSON.parse(raw);
42
+ } catch (error) {
43
+ return { entries: {}, errors: [`${label}: invalid JSON (${error.message})`] };
44
+ }
45
+ if (data === null || typeof data !== "object" || Array.isArray(data)) {
46
+ return { entries: {}, errors: [`${label}: top level must be an object`] };
47
+ }
48
+ const entries = {};
49
+ for (const [id, value] of Object.entries(data)) {
50
+ const before = errors.length;
51
+ validateEntry(id, value, label, errors);
52
+ if (errors.length === before && value && typeof value === "object") {
53
+ entries[id] = value;
54
+ }
55
+ }
56
+ return { entries, errors };
57
+ }
58
+ function mergeOverrides(globalRaw, projectRaw) {
59
+ const errors = [];
60
+ const effective = {};
61
+ if (globalRaw !== void 0) {
62
+ const g = parseOverridesFile(globalRaw, "global overrides");
63
+ errors.push(...g.errors);
64
+ Object.assign(effective, g.entries);
65
+ }
66
+ if (projectRaw !== void 0) {
67
+ const p = parseOverridesFile(projectRaw, "project overrides");
68
+ errors.push(...p.errors);
69
+ Object.assign(effective, p.entries);
70
+ }
71
+ return { entries: effective, errors };
72
+ }
73
+ function unknownBehaviorIds(effective, registry) {
74
+ const known = new Set(registry.map((b) => b.id));
75
+ return Object.keys(effective).filter((id) => !known.has(id)).sort();
76
+ }
77
+ function installDecision(effective, registry, id) {
78
+ const spec = registry.find((b) => b.id === id);
79
+ if (spec === void 0 || spec.kind !== "install") return void 0;
80
+ const entry = effective[id];
81
+ if (entry === void 0) return void 0;
82
+ if (entry.action === "disable") return "skip";
83
+ return { content: entry.content ?? "" };
84
+ }
85
+ function isRuntimeDisabled(effective, registry, id) {
86
+ const spec = registry.find((b) => b.id === id);
87
+ if (spec === void 0 || spec.kind !== "runtime") return false;
88
+ return effective[id]?.action === "disable";
89
+ }
90
+ function classifyOverrideFiles(registry, projectRaw, globalRaw) {
91
+ const warnings = [];
92
+ const global = globalRaw === void 0 ? void 0 : parseOverridesFile(globalRaw, "global overrides");
93
+ const project = projectRaw === void 0 ? void 0 : parseOverridesFile(projectRaw, "project overrides");
94
+ for (const parsed of [global, project]) {
95
+ if (parsed === void 0) continue;
96
+ for (const error of parsed.errors) {
97
+ warnings.push({
98
+ code: "override_schema_invalid",
99
+ file: parsed === project ? "project" : "global",
100
+ message: error
101
+ });
102
+ }
103
+ }
104
+ const effective = mergeOverrides(globalRaw, projectRaw).entries;
105
+ for (const id of unknownBehaviorIds(effective, registry)) {
106
+ warnings.push({
107
+ code: "override_unknown_behavior",
108
+ file: project?.entries[id] !== void 0 ? "project" : "global",
109
+ message: `override names unknown behavior "${id}" \u2014 it is not in the routing.yml behaviors registry`
110
+ });
111
+ }
112
+ return { warnings, effective };
113
+ }
114
+ export {
115
+ OVERRIDE_CONTENT_MAX,
116
+ OVERRIDE_REASON_MAX,
117
+ classifyOverrideFiles,
118
+ installDecision,
119
+ isRuntimeDisabled,
120
+ mergeOverrides,
121
+ parseOverridesFile,
122
+ unknownBehaviorIds
123
+ };
@@ -1,5 +1,5 @@
1
1
  /**
2
- * v2-capabilities.mjs — what the OpenCode V2 plugin surface ACTUALLY is.
2
+ * capabilities.mjs — what the OpenCode V2 plugin surface ACTUALLY is.
3
3
  *
4
4
  * Two reporting defects this module exists to prevent, both of them statements
5
5
  * that were narrower than the truth:
@@ -16,20 +16,20 @@
16
16
  * `tool`/`agent`/`command`/`reference` transforms and five session events.
17
17
  * A user deciding between generations is entitled to both halves.
18
18
  *
19
- * The registered surface below is derived from `src/plugin-v2.ts` (the
19
+ * The registered surface below is derived from `src/plugin.ts` (the
20
20
  * registration sites, not the module header: the header still claims the
21
21
  * caller/target matrix is enforced, while the enforcement guard's own docstring
22
22
  * records that omitting the hierarchy wiring skips that branch — the gap is
23
23
  * stated here as a gap).
24
24
  *
25
25
  * The seed itself is IMPORTED, never copied: an installer that restated these
26
- * strings could drift from `src/pantheon/v2-unsupported.mjs`, and a test pins
26
+ * strings could drift from `src/pantheon/unsupported.mjs`, and a test pins
27
27
  * the two together.
28
28
  *
29
- * @module v2-capabilities
29
+ * @module capabilities
30
30
  */
31
31
 
32
- import { listV2UnsupportedFeatures } from '../../src/pantheon/v2-unsupported.mjs'
32
+ import { listV2UnsupportedFeatures } from '../../src/pantheon/unsupported.mjs'
33
33
 
34
34
  /** Tools registered unconditionally through `ctx.tool.transform`. */
35
35
  export const V2_REGISTERED_TOOLS = Object.freeze([
@@ -129,7 +129,7 @@ export function formatV2CapabilityNotice(capabilities = v2Capabilities()) {
129
129
  /**
130
130
  * Whether a `plugins` list registers the Pantheon V2 entry.
131
131
  *
132
- * Matched on the `plugin-v2` marker so every real spelling counts: the
132
+ * Matched on the `plugin` marker so every real spelling counts: the
133
133
  * canonical directory, an absolute path to it, and the package export.
134
134
  *
135
135
  * @param {unknown} ref
@@ -142,7 +142,7 @@ export function isPantheonV2Reference(ref) {
142
142
  : ref && typeof ref === 'object'
143
143
  ? (ref.package ?? ref.path ?? ref.source ?? ref.id ?? ref.name)
144
144
  : undefined
145
- return typeof candidate === 'string' && candidate.includes('plugin-v2')
145
+ return typeof candidate === 'string' && candidate.includes('plugin')
146
146
  }
147
147
 
148
148
  /**
@@ -1,11 +1,16 @@
1
1
  /**
2
- * config-migration.mjs — Bidirectional V1↔V2 config format migration
2
+ * config-migration.mjs — legacy V1-shaped config normalization for the V2 path
3
3
  *
4
- * Converts opencode.json between:
4
+ * Pantheon 2.0 targets OpenCode 2.x only; this module is the ONE-WAY compat
5
+ * pass that normalizes a legacy (OpenCode 1.x-era) config shape before the V2
6
+ * host reads it:
5
7
  * - V1 (object-based): `permission`, `agent`, `provider`, `mcp` with flat keys
6
8
  * - V2 (array-based): `permissions`, `agents`, `providers`, and
7
9
  * `mcp.servers.<name>` server configuration.
8
10
  *
11
+ * The backward (V2→V1) direction is gone with the V1 contract: nothing writes
12
+ * a V1-shaped config anymore.
13
+ *
9
14
  * Rules:
10
15
  * 1. Deep clone before mutating — never modifies input
11
16
  * 2. Unknown fields pass through untouched
@@ -55,21 +60,12 @@ const V1_PERMISSION_TO_ACTION = {
55
60
  bash: 'shell',
56
61
  task: 'subagent',
57
62
  skill: 'skill',
58
- // Listed before `write` so the reverse map resolves `edit` to the canonical
59
- // V1 key instead of to the alias.
60
63
  edit: 'edit',
61
64
  write: 'edit',
62
65
  websearch: 'websearch',
63
66
  // passthrough unknowns
64
67
  }
65
68
 
66
- /** Effect restrictiveness is used only when V2 rules must collapse into V1 keys. */
67
- const EFFECT_RESTRICTIVENESS = { allow: 1, ask: 2, deny: 3 }
68
-
69
- function isKnownEffect(effect) {
70
- return typeof effect === 'string' && Object.hasOwn(EFFECT_RESTRICTIVENESS, effect)
71
- }
72
-
73
69
  /** A structurally valid permission rule, used for redacted malformed-entry counts. */
74
70
  function isValidPermissionEntry(entry) {
75
71
  return (
@@ -88,44 +84,6 @@ function warnInvalidPermissionEntries(entries) {
88
84
  )
89
85
  }
90
86
 
91
- /**
92
- * Resolve two effects proposed for the same action+resource.
93
- *
94
- * Security bias: `deny` always wins, including against an unrecognized effect,
95
- * and an unrecognized effect never silently replaces a known one. When both
96
- * effects are unrecognized they cannot be ranked, so the first is kept and the
97
- * warning says exactly that — it makes no restrictiveness claim.
98
- *
99
- * @returns {string} the effect to keep
100
- */
101
- function resolveEffects(current, next) {
102
- if (current === next) return current
103
-
104
- const currentKnown = isKnownEffect(current)
105
- const nextKnown = isKnownEffect(next)
106
-
107
- if (!currentKnown && !nextKnown) {
108
- console.warn(
109
- '[config-migration] Unrecognized effects could not be ranked; keeping the first value.',
110
- )
111
- return current
112
- }
113
- if (currentKnown && !nextKnown) {
114
- console.warn('[config-migration] An unrecognized effect could not replace a known effect.')
115
- return current
116
- }
117
- if (!currentKnown && nextKnown) {
118
- console.warn('[config-migration] A known effect replaced an unrecognized effect.')
119
- return next
120
- }
121
-
122
- const winner = EFFECT_RESTRICTIVENESS[next] > EFFECT_RESTRICTIVENESS[current] ? next : current
123
- console.warn(
124
- '[config-migration] Conflicting effects were found; keeping the more restrictive value.',
125
- )
126
- return winner
127
- }
128
-
129
87
  /**
130
88
  * Define an own enumerable property. Plain assignment is not enough for
131
89
  * attacker-controlled keys: `obj['__proto__'] = value` mutates the prototype
@@ -317,64 +275,12 @@ function assertV1ActionNormalizationDoesNotCollapseSources(provenance) {
317
275
  }
318
276
  }
319
277
 
320
- /**
321
- * Convert V2 permissions array back to V1 permission object.
322
- *
323
- * Rules that land on the same V1 key+resource are merged with the same
324
- * restrictiveness policy as the forward map (`deny > ask > allow`, `deny`
325
- * always wins, an unrecognized effect never replaces a known one). "Last wins"
326
- * would let `[{edit,*,deny},{edit,*,allow}]` downgrade a deny to allow, which
327
- * is the opposite of what the forward direction guarantees.
328
- */
329
- function convertPermissionsV2toV1(permArray) {
330
- // Reverse action mapping: V2 action → V1 key. Aliases collapse onto one action
331
- // (`write` and `edit` both → `edit`), so the FIRST key wins — the canonical
332
- // V1 spelling — instead of the alias that happens to be listed last.
333
- // Null prototype + hasOwn: actions named like Object.prototype members
334
- // (`__proto__`, `constructor`, `toString`) must pass through literally.
335
- const ACTION_TO_V1 = Object.create(null)
336
- for (const [v1Key, action] of Object.entries(V1_PERMISSION_TO_ACTION)) {
337
- if (!Object.hasOwn(ACTION_TO_V1, action)) ACTION_TO_V1[action] = v1Key
338
- }
339
-
340
- // Group by V1 key first, resolving collisions per resource, so the output
341
- // shape (scalar for a lone "*" rule, object otherwise) does not depend on
342
- // array order.
343
- const byKey = new Map()
344
- for (const { action, resource, effect } of permArray) {
345
- const v1Key = Object.hasOwn(ACTION_TO_V1, action) ? ACTION_TO_V1[action] : action
346
- let rules = byKey.get(v1Key)
347
- if (rules === undefined) {
348
- rules = new Map()
349
- byKey.set(v1Key, rules)
350
- }
351
- rules.set(resource, rules.has(resource) ? resolveEffects(rules.get(resource), effect) : effect)
352
- }
353
-
354
- const result = {}
355
- for (const [v1Key, rules] of byKey) {
356
- if (rules.size === 1 && rules.has('*')) {
357
- setOwn(result, v1Key, rules.get('*'))
358
- continue
359
- }
360
- const group = {}
361
- for (const [resource, effect] of rules) setOwn(group, resource, effect)
362
- setOwn(result, v1Key, group)
363
- }
364
- return result
365
- }
366
-
367
278
  /** Provider name consolidation: V1 → V2 */
368
279
  const PROVIDER_RENAME = {
369
280
  'azure-cognitive-services': 'azure',
370
281
  'google-vertex-anthropic': 'google-vertex',
371
282
  }
372
283
 
373
- /** Reverse: V2 → V1 */
374
- const PROVIDER_RENAME_REVERSE = Object.fromEntries(
375
- Object.entries(PROVIDER_RENAME).map(([k, v]) => [v, k]),
376
- )
377
-
378
284
  /**
379
285
  * Convert a single V1 provider config to V2.
380
286
  *
@@ -436,64 +342,6 @@ function convertProviderV1toV2(_name, config) {
436
342
  return result
437
343
  }
438
344
 
439
- /**
440
- * Convert a single V2 provider config back to V1.
441
- */
442
- function convertProviderV2toV1(_name, config) {
443
- const result = { ...config }
444
-
445
- // package → npm (strip aisdk: prefix)
446
- if (result.package !== undefined) {
447
- result.npm = result.package.startsWith('aisdk:') ? result.package.slice(6) : result.package
448
- delete result.package
449
- }
450
-
451
- // settings.baseURL → api
452
- if (result.settings?.baseURL !== undefined) {
453
- result.api = result.settings.baseURL
454
- const { baseURL, ...restSettings } = result.settings
455
- if (Object.keys(restSettings).length > 0) {
456
- result.settings = restSettings
457
- } else {
458
- delete result.settings
459
- }
460
- }
461
-
462
- // settings.apiKey → options.apiKey
463
- if (result.settings?.apiKey !== undefined) {
464
- if (!result.options) result.options = {}
465
- result.options.apiKey = result.settings.apiKey
466
- const { apiKey, ...restSettings } = result.settings || {}
467
- if (Object.keys(restSettings).length > 0) {
468
- result.settings = restSettings
469
- } else {
470
- delete result.settings
471
- }
472
- }
473
-
474
- // Model key with #suffix → variant field
475
- // Also rename model-level "media" → "attachment"
476
- if (result.models) {
477
- const newModels = {}
478
- for (const [modelKey, modelConfig] of Object.entries(result.models)) {
479
- const { media, ...restConfig } = modelConfig || {}
480
- const finalConfig = { ...restConfig }
481
- if (media !== undefined) {
482
- finalConfig.attachment = media
483
- }
484
- if (modelKey.includes('#')) {
485
- const [baseName, variant] = modelKey.split('#', 2)
486
- newModels[baseName] = { ...finalConfig, variant }
487
- } else {
488
- newModels[modelKey] = finalConfig
489
- }
490
- }
491
- result.models = newModels
492
- }
493
-
494
- return result
495
- }
496
-
497
345
  /**
498
346
  * Validate the MCP source shape before any installer seeding can normalize it.
499
347
  * Returns the shape decision consumed by the converter so both paths apply
@@ -607,7 +455,7 @@ function convertMcpV1toV2(mcpConfig) {
607
455
  if (Object.hasOwn(servers, name)) {
608
456
  throw new Error('Conflicting flat and nested MCP server entries cannot be merged safely.')
609
457
  }
610
- const srv = normalizeMcpServerFlags(serverConfig, 'v2')
458
+ const srv = normalizeMcpServerFlags(serverConfig)
611
459
 
612
460
  // Normalize legacy V2's split timeout to the V1/V2-compatible number.
613
461
  if (srv.timeout !== undefined && srv.timeout !== null) {
@@ -626,15 +474,14 @@ function convertMcpV1toV2(mcpConfig) {
626
474
  }
627
475
 
628
476
  /**
629
- * Normalize the V1 `enabled` and V2 `disabled` spellings without guessing
630
- * when both are present. OpenCode V2 connects configured servers by default;
477
+ * Normalize legacy MCP server flags to the V2 spelling. `enabled: true` is the
478
+ * OpenCode 1.x opt-in; OpenCode V2 connects configured servers by default and
631
479
  * `disabled: true` is the native opt-out.
632
480
  *
633
481
  * @param {object} serverConfig
634
- * @param {'v1' | 'v2'} targetVersion
635
482
  * @returns {object}
636
483
  */
637
- function normalizeMcpServerFlags(serverConfig, targetVersion) {
484
+ function normalizeMcpServerFlags(serverConfig) {
638
485
  const srv = { ...serverConfig }
639
486
  const hasEnabled = Object.hasOwn(srv, 'enabled')
640
487
  const hasDisabled = Object.hasOwn(srv, 'disabled')
@@ -648,32 +495,13 @@ function normalizeMcpServerFlags(serverConfig, targetVersion) {
648
495
  throw new TypeError('Conflicting MCP enabled and disabled flags.')
649
496
  }
650
497
 
651
- if (targetVersion === 'v2') {
652
- if (hasEnabled) {
653
- srv.disabled = !srv.enabled
654
- delete srv.enabled
655
- }
656
- } else if (hasDisabled) {
657
- srv.enabled = !srv.disabled
658
- delete srv.disabled
498
+ if (hasEnabled) {
499
+ srv.disabled = !srv.enabled
500
+ delete srv.enabled
659
501
  }
660
502
  return srv
661
503
  }
662
504
 
663
- /**
664
- * Convert V2 MCP config back to V1.
665
- */
666
- function convertMcpV2toV1(mcpConfig) {
667
- if (!mcpConfig || typeof mcpConfig !== 'object') return mcpConfig
668
- const v2Servers = convertMcpV1toV2(mcpConfig)?.servers
669
- if (!isPlainObject(v2Servers)) return mcpConfig
670
- const servers = {}
671
- for (const [name, config] of Object.entries(v2Servers)) {
672
- setOwn(servers, name, normalizeMcpServerFlags(config, 'v1'))
673
- }
674
- return servers
675
- }
676
-
677
505
  // ---------------------------------------------------------------------------
678
506
  // MCP entrypoint path migration
679
507
  // ---------------------------------------------------------------------------
@@ -779,11 +607,6 @@ const V1_TO_V2_RENAMES = {
779
607
  permission: 'permissions',
780
608
  }
781
609
 
782
- /** Build reverse map */
783
- const V2_TO_V1_RENAMES = Object.fromEntries(
784
- Object.entries(V1_TO_V2_RENAMES).map(([k, v]) => [v, k]),
785
- )
786
-
787
610
  /**
788
611
  * Agent fields owned by the framework. Mirrors the exported MANAGED_FIELDS in
789
612
  * install/opencode.mjs plus `source`, which the installer writes next to them.
@@ -791,8 +614,8 @@ const V2_TO_V1_RENAMES = Object.fromEntries(
791
614
  * itself when both `agent` and `agents` coexist: these come from the V1 block,
792
615
  * every other field stays the user's.
793
616
  *
794
- * `permissions` is the V2 name — the converter renames the V1 `permission`
795
- * block before the merge runs.
617
+ * `permissions` is the V2 spelling — both the installer and this converter emit
618
+ * the V2 rule array under that key.
796
619
  *
797
620
  * `description` is deliberately absent, and this list is deliberately narrower
798
621
  * than what the installer writes. The installer writes a description only when
@@ -803,12 +626,6 @@ const V2_TO_V1_RENAMES = Object.fromEntries(
803
626
  * migration stricter than the installer and would overwrite a description the
804
627
  * installer deliberately preserves. mergeManagedAgents carries the value across
805
628
  * instead, so it survives the merge without being treated as framework-owned.
806
- *
807
- * KNOWN DEBT: the installer still writes the V1 spelling `permission`, while V2
808
- * reads `permissions`. An agent that goes through this merge can therefore end
809
- * up carrying both keys, with `permission` left as dead weight that nothing
810
- * reads. Tracked for the next slice; not fixed here, because picking a winner
811
- * changes what an install writes.
812
629
  */
813
630
  export const MANAGED_AGENT_FIELDS = Object.freeze([
814
631
  'source',
@@ -1093,14 +910,10 @@ function resolveTopLevelPermissions(config, configuredMcpServers = []) {
1093
910
  // ---------------------------------------------------------------------------
1094
911
 
1095
912
  /**
1096
- * Migrate a V1 opencode.json config to V2 format.
1097
- *
1098
- * When top-level `permission` (V1) and `permissions` (V2) coexist, the V2 array
1099
- * is the base and the V1 rules are merged into it — see
1100
- * `resolveTopLevelPermissions`.
1101
- *
1102
- * @param {object} config - V1 config object (not mutated)
1103
- * @returns {object} V2 config object
913
+ * Collect the configured MCP server names from either config shape (V1 flat map
914
+ * or V2 `mcp.servers`), used to guard permission aliasing.
915
+ * @param {unknown} mcpConfig
916
+ * @returns {string[]}
1104
917
  */
1105
918
  function configuredMcpServerNames(mcpConfig) {
1106
919
  if (!isPlainObject(mcpConfig)) return []
@@ -1112,7 +925,46 @@ function configuredMcpServerNames(mcpConfig) {
1112
925
  })
1113
926
  }
1114
927
 
1115
- export function migrateV1toV2(config, { mcpServerNames = [] } = {}) {
928
+ /**
929
+ * Normalize a legacy (OpenCode 1.x-era) MCP block to the V2 shape: the flat
930
+ * server map is wrapped into `mcp.servers`, legacy `enabled` flags become
931
+ * `disabled`, and split timeouts collapse to one number. An already-nested V2
932
+ * map passes through with its flags normalized.
933
+ *
934
+ * @param {object} mcpConfig - the `mcp` block (not mutated)
935
+ * @returns {{ servers: object }} the V2 `mcp` value
936
+ */
937
+ export function normalizeMcpConfigToV2(mcpConfig) {
938
+ return convertMcpV1toV2(mcpConfig)
939
+ }
940
+
941
+ /**
942
+ * Convert a legacy top-level `permission` policy object into the V2 `permissions`
943
+ * rule array. Used by the installer, by setup, and by the agent-level conversion
944
+ * inside {@link normalizeLegacyV1Config}.
945
+ *
946
+ * @param {object} permObj - V1 permission policy object
947
+ * @param {{ mcpServerNames?: string[] }} [options]
948
+ * @returns {Array<{action: string, resource: string, effect: string}>}
949
+ */
950
+ export function convertLegacyPermissionsToV2(permObj, { mcpServerNames = [] } = {}) {
951
+ return convertPermissionsV1toV2(permObj, mcpServerNames)
952
+ }
953
+
954
+ /**
955
+ * Normalize a legacy V1-shaped opencode.json config to the V2 shape the host
956
+ * reads. This is the one-way compat pass for configs written before the V2-only
957
+ * contract; it is NOT a bidirectional migration (nothing writes V1 anymore).
958
+ *
959
+ * When top-level `permission` (V1) and `permissions` (V2) coexist, the V2 array
960
+ * is the base and the V1 rules are merged into it — see
961
+ * `resolveTopLevelPermissions`.
962
+ *
963
+ * @param {object} config - legacy config object (not mutated)
964
+ * @param {{ mcpServerNames?: string[] }} [options]
965
+ * @returns {object} V2-shaped config object
966
+ */
967
+ export function normalizeLegacyV1Config(config, { mcpServerNames = [] } = {}) {
1116
968
  const c = deepClone(config)
1117
969
  // JSON cloning omits own properties whose value is undefined. Keep a present
1118
970
  // MCP field visible to validation so it cannot be mistaken for absence.
@@ -1172,48 +1024,3 @@ export function migrateV1toV2(config, { mcpServerNames = [] } = {}) {
1172
1024
 
1173
1025
  return result
1174
1026
  }
1175
-
1176
- /**
1177
- * Migrate a V2 opencode.json config back to V1 format.
1178
- *
1179
- * @param {object} config - V2 config object (not mutated)
1180
- * @returns {object} V1 config object
1181
- */
1182
- export function migrateV2toV1(config) {
1183
- const c = deepClone(config)
1184
- const result = {}
1185
-
1186
- for (const [key, value] of Object.entries(c)) {
1187
- const v1Key = V2_TO_V1_RENAMES[key] || key
1188
-
1189
- if (key === 'permissions' && Array.isArray(value)) {
1190
- result.permission = convertPermissionsV2toV1(value)
1191
- } else if (key === 'agents' && typeof value === 'object' && value !== null) {
1192
- const agents = {}
1193
- for (const [agentName, agentConfig] of Object.entries(value)) {
1194
- const ac = { ...agentConfig }
1195
- if (Array.isArray(ac.permissions)) {
1196
- ac.permission = convertPermissionsV2toV1(ac.permissions)
1197
- delete ac.permissions
1198
- }
1199
- agents[agentName] = ac
1200
- }
1201
- result.agent = agents
1202
- } else if (key === 'providers' && typeof value === 'object' && value !== null) {
1203
- const providers = {}
1204
- for (const [provName, provConfig] of Object.entries(value)) {
1205
- const renamed = PROVIDER_RENAME_REVERSE[provName] || provName
1206
- providers[renamed] = convertProviderV2toV1(provName, provConfig)
1207
- }
1208
- result.provider = providers
1209
- } else if (key === 'mcp' && typeof value === 'object' && value !== null) {
1210
- result.mcp = convertMcpV2toV1(value)
1211
- } else if (v1Key !== key) {
1212
- result[v1Key] = value
1213
- } else {
1214
- result[key] = value
1215
- }
1216
- }
1217
-
1218
- return result
1219
- }
@@ -21,17 +21,19 @@ import { assertNoSymlinkAncestors, verifyPathRemoved } from './verify.mjs'
21
21
  export const FILE_INVENTORY_VERSION = 1
22
22
 
23
23
  /** Map installer-owned copy layouts to their logical component without names heuristics. */
24
- export function componentForInstalledPath(target, filePath, { isGlobal, version = 'v1' } = {}) {
24
+ export function componentForInstalledPath(target, filePath, { isGlobal } = {}) {
25
25
  let relPath
26
26
  try {
27
27
  relPath = relativeTargetPath(target, filePath)
28
28
  } catch {
29
29
  return null
30
30
  }
31
- const layout = isGlobal ? 'global' : version === 'v2' ? 'project-v2' : 'project-v1'
32
- const agentRoot = isGlobal || version === 'v2' ? 'agents' : '.opencode/agents'
31
+ // `project-v2` is the persisted layout label of every on-disk inventory; the
32
+ // removed generation's `project-v1` layout no longer exists.
33
+ const layout = isGlobal ? 'global' : 'project-v2'
34
+ const agentRoot = isGlobal ? 'agents' : '.opencode/agents'
33
35
  const skillRoot = isGlobal ? 'skills' : '.opencode/skills'
34
- const commandRoot = isGlobal || version === 'v2' ? 'commands' : '.opencode/commands'
36
+ const commandRoot = isGlobal ? 'commands' : '.opencode/commands'
35
37
  const pluginRoot = isGlobal ? 'plugins/pantheon-tui' : '.opencode/plugins/pantheon-tui'
36
38
  const runtimeRoot = isGlobal ? '' : '.opencode'
37
39
  const startsIn = (prefix) => relPath.startsWith(`${prefix}/`)
@@ -93,7 +93,7 @@ export async function runInteractiveInstall({
93
93
 
94
94
  const componentOptions = [
95
95
  { label: 'agents', value: 'agents', hint: 'Agent configurations and routing (14 agents)' },
96
- { label: 'skills', value: 'skills', hint: `Reusable skill workflows (${22} skills)` },
96
+ { label: 'skills', value: 'skills', hint: `Reusable skill workflows (${23} skills)` },
97
97
  { label: 'instructions', value: 'instructions', hint: 'AGENTS.md and instructional files' },
98
98
  { label: 'prompts', value: 'prompts', hint: 'Prompt templates for agents' },
99
99
  { label: 'commands', value: 'commands', hint: 'OpenCode command shortcuts' },