pantheon-opencode 1.6.0-beta.8 → 1.6.0

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 (141) hide show
  1. package/AGENTS.global.md +118 -0
  2. package/AGENTS.md +18 -168
  3. package/CHANGELOG.md +126 -346
  4. package/README.md +83 -608
  5. package/README.pt-BR.md +120 -345
  6. package/bin/pantheon-init.mjs +366 -132
  7. package/commands/pantheon-audit.md +7 -1
  8. package/commands/pantheon-consolidate.md +1 -1
  9. package/commands/pantheon-deepwork.md +14 -3
  10. package/commands/pantheon-focus.md +17 -0
  11. package/commands/pantheon-vision.md +61 -12
  12. package/package.json +19 -11
  13. package/plugin.json +1 -1
  14. package/pyproject.toml +6 -2
  15. package/scripts/_pantheon_paths.py +24 -0
  16. package/scripts/build-agents-md.mjs +368 -69
  17. package/scripts/changelog-merge.mjs +161 -0
  18. package/scripts/check-plugin-v2-coverage.mjs +11 -8
  19. package/scripts/docs-check-changelog.mjs +204 -0
  20. package/scripts/docs-link-check.mjs +314 -0
  21. package/scripts/docs-media.mjs +157 -0
  22. package/scripts/doctor.mjs +828 -40
  23. package/scripts/install/agents-md.mjs +2 -2
  24. package/scripts/install/backup.mjs +648 -0
  25. package/scripts/install/cli-ui.mjs +303 -72
  26. package/scripts/install/component-selection.mjs +61 -0
  27. package/scripts/install/config-migration.mjs +583 -27
  28. package/scripts/install/exit-codes.mjs +26 -0
  29. package/scripts/install/file-inventory.mjs +555 -0
  30. package/scripts/install/health-check.mjs +31 -25
  31. package/scripts/install/interactive.mjs +78 -383
  32. package/scripts/install/migrate.mjs +49 -25
  33. package/scripts/install/model-picker.mjs +218 -250
  34. package/scripts/install/opencode-version.mjs +83 -21
  35. package/scripts/install/opencode.mjs +1465 -180
  36. package/scripts/install/plan-artifact.mjs +517 -0
  37. package/scripts/install/plan.mjs +475 -0
  38. package/scripts/install/plugin.mjs +251 -30
  39. package/scripts/install/prompt-result.mjs +2 -0
  40. package/scripts/install/shared.mjs +256 -99
  41. package/scripts/install/state.mjs +63 -8
  42. package/scripts/install/strings.mjs +60 -4
  43. package/scripts/install/venv.mjs +90 -47
  44. package/scripts/install/verify.mjs +128 -0
  45. package/scripts/install/vision-prompt.mjs +173 -0
  46. package/scripts/install-mcp.mjs +2 -2
  47. package/scripts/manifest-inventory.mjs +49 -3
  48. package/scripts/mcp_persistence.py +1535 -1050
  49. package/scripts/memory_mcp.py +12 -843
  50. package/scripts/node-engine-policy.mjs +85 -0
  51. package/scripts/package-evidence.mjs +10 -2
  52. package/scripts/postinstall.mjs +26 -26
  53. package/scripts/probe-pantheon-cost.mjs +118 -19
  54. package/scripts/prune.mjs +9 -3
  55. package/scripts/reconcile.mjs +325 -0
  56. package/scripts/release-gates.mjs +682 -0
  57. package/scripts/restore.mjs +222 -0
  58. package/scripts/run-node-tests.mjs +24 -8
  59. package/scripts/sync-artifacts.mjs +20 -7
  60. package/scripts/sync-tui.mjs +29 -4
  61. package/scripts/test-opencode-v2-sandbox.sh +36 -123
  62. package/scripts/uninstall.mjs +369 -34
  63. package/scripts/update.mjs +164 -0
  64. package/scripts/validate-node-engine-policy.mjs +13 -0
  65. package/scripts/version-check.mjs +34 -1
  66. package/scripts/versioning.mjs +23 -3
  67. package/scripts/vision-status.mjs +682 -0
  68. package/skills-lock.json +8 -8
  69. package/src/agents/aphrodite.md +13 -10
  70. package/src/agents/apollo.md +4 -5
  71. package/src/agents/athena.md +74 -46
  72. package/src/agents/demeter.md +10 -7
  73. package/src/agents/gaia.md +0 -1
  74. package/src/agents/hephaestus.md +4 -3
  75. package/src/agents/hermes.md +10 -9
  76. package/src/agents/iris.md +6 -1
  77. package/src/agents/mnemosyne.md +14 -15
  78. package/src/agents/nyx.md +4 -4
  79. package/src/agents/prometheus.md +12 -11
  80. package/src/agents/talos.md +6 -0
  81. package/src/agents/zeus.md +84 -56
  82. package/src/instructions/agent-return-format.instructions.md +12 -41
  83. package/src/instructions/memory-protocol.instructions.md +5 -11
  84. package/src/instructions/test-economy.instructions.md +12 -0
  85. package/src/instructions/yagni.instructions.md +6 -15
  86. package/src/instructions/zeus-anti-stall.instructions.md +6 -6
  87. package/src/instructions/zeus-communication-rules.instructions.md +6 -6
  88. package/src/instructions/zeus-council-synthesis.instructions.md +11 -12
  89. package/src/instructions/zeus-memory-operations.instructions.md +13 -7
  90. package/src/instructions/zeus-timeout-retry.instructions.md +36 -10
  91. package/src/mcp/_pantheon_paths.py +24 -0
  92. package/src/mcp/mcp_codemap_module.py +86 -18
  93. package/src/mcp/mcp_persistence.py +1535 -1050
  94. package/src/mcp/memory_mcp.py +444 -94
  95. package/src/mcp/pantheon_vision.py +285 -41
  96. package/src/mcp/requirements-mcp.txt +5 -0
  97. package/src/pantheon/context-pruner.ts +541 -0
  98. package/src/pantheon/cost-command.ts +814 -60
  99. package/src/pantheon/goal-loop.ts +11 -8
  100. package/src/pantheon/memory-context.ts +1017 -0
  101. package/src/pantheon/model-agents.ts +19 -0
  102. package/src/pantheon/model-command.ts +218 -56
  103. package/src/pantheon/model-pricing.ts +536 -0
  104. package/src/pantheon/presets.mjs +2 -0
  105. package/src/pantheon/task-result-guard.ts +50 -14
  106. package/src/pantheon/v2-bounded-read.ts +640 -0
  107. package/src/pantheon/v2-delegation-enforce.ts +133 -6
  108. package/src/pantheon/v2-execute-after.ts +135 -24
  109. package/src/pantheon/v2-model-overrides.ts +275 -0
  110. package/src/pantheon/v2-tools.ts +89 -35
  111. package/src/pantheon/v2-unsupported.mjs +2 -3
  112. package/src/pantheon/v2-vision.ts +622 -0
  113. package/src/pantheon/vision-local.ts +531 -0
  114. package/src/pantheon/vision.ts +1160 -115
  115. package/src/plugin-v2.ts +654 -162
  116. package/src/plugin.ts +15 -11
  117. package/src/plugins/tui/dist/tui-v2.d.ts +1036 -0
  118. package/src/plugins/tui/dist/tui-v2.d.ts.map +1 -0
  119. package/src/plugins/tui/dist/tui-v2.js +3808 -0
  120. package/src/plugins/tui/dist/tui-v2.js.map +1 -0
  121. package/src/plugins/tui/dist/tui.js +4 -4
  122. package/src/plugins/tui/index-v2.ts +6 -0
  123. package/src/plugins/tui/package-lock.json +5416 -1297
  124. package/src/plugins/tui/package.json +14 -10
  125. package/src/plugins/tui/src/index-v2.tsx +4372 -0
  126. package/src/plugins/tui/src/index.tsx +3 -3
  127. package/src/plugins/tui/src/opencode-v2.d.ts +13 -0
  128. package/src/plugins/tui/tsconfig.typecheck.json +5 -0
  129. package/src/plugins/tui/tsdown.config.ts +2 -2
  130. package/src/plugins/tui/tui-v2.ts +2 -0
  131. package/src/plugins/tui/tui.ts +3 -0
  132. package/src/routing.yml +50 -5
  133. package/src/skills/agent-coordination/SKILL.md +7 -2
  134. package/src/skills/artifact-management/SKILL.md +5 -1
  135. package/src/skills/auto-continue/SKILL.md +14 -6
  136. package/src/skills/codemap/SKILL.md +1 -1
  137. package/src/skills/memory-bank/SKILL.md +21 -13
  138. package/src/skills/session-goal/SKILL.md +14 -15
  139. package/src/skills/spec-driven-development/SKILL.md +3 -1
  140. package/src/skills/worktrees/SKILL.md +30 -11
  141. package/scripts/probe-context-rehydrate.mjs +0 -263
@@ -0,0 +1,682 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * release-gates.mjs — the six release gates, fail-closed.
4
+ *
5
+ * ADR-0014 requires every applicable gate to end in an explicit `PASS` on the
6
+ * frozen candidate. This script turns each gate into a binary result and one
7
+ * named evidence file:
8
+ *
9
+ * tests Python/Node/TypeScript suites, the mandatory heavy install tier,
10
+ * and the required coverage thresholds.
11
+ * host The measured OpenCode host evidence, installed and exercised in
12
+ * an isolated sandbox. Support is family-level: a measured row
13
+ * must PASS, an unmeasured supported family is reported as such,
14
+ * and a known-broken host is a failure.
15
+ * install The one immutable .tgz installed as a real user, initialized
16
+ * headlessly, driven through a live host, and compared file-by-file
17
+ * against the checkout.
18
+ * package The same .tgz re-hashed and inspected. No second `npm pack`.
19
+ * changelog The committed `[version]` section exists and is non-empty.
20
+ * metadata Version manifests and the Node engine policy agree.
21
+ *
22
+ * Usage:
23
+ * node scripts/release-gates.mjs <gate> --evidence-dir <dir> [options]
24
+ *
25
+ * Options:
26
+ * --artifact-dir <dir> Directory holding the single .tgz + metadata.json
27
+ * (required by host/install/package).
28
+ * --version <x.y.z> Candidate version (default: package.json version).
29
+ * --target-sha <sha> Full 40-hex candidate SHA (default: TARGET_SHA).
30
+ * --channel stable|beta Release channel (default: RELEASE_CHANNEL|stable).
31
+ * --recovery Recovery dispatch: changelog is the static note.
32
+ *
33
+ * Host evidence: PANTHEON_RELEASE_MATRIX overrides the built-in JSON array. The
34
+ * override is still validated: rows must name a supported family and may not
35
+ * name a known-broken host. A supported family with no row is reported as
36
+ * "supported, unmeasured", not treated as a failure. A measured row that cannot
37
+ * run is a FAIL — this script has no SKIP path on purpose.
38
+ */
39
+
40
+ import { spawnSync } from 'node:child_process'
41
+ import { createHash } from 'node:crypto'
42
+ import {
43
+ accessSync,
44
+ existsSync,
45
+ constants as fsConstants,
46
+ mkdirSync,
47
+ readdirSync,
48
+ readFileSync,
49
+ rmSync,
50
+ statSync,
51
+ writeFileSync,
52
+ } from 'node:fs'
53
+ import { tmpdir } from 'node:os'
54
+ import { basename, dirname, join, resolve } from 'node:path'
55
+ import { fileURLToPath, pathToFileURL } from 'node:url'
56
+
57
+ const ROOT = join(dirname(fileURLToPath(import.meta.url)), '..')
58
+
59
+ const GATE_NAMES = ['tests', 'host', 'install', 'package', 'changelog', 'metadata']
60
+
61
+ /** Support is family-level: these are the families this release supports. */
62
+ export const SUPPORTED_FAMILIES = Object.freeze(['1.19.x', '2.x'])
63
+
64
+ /** Known-broken hosts. Every other member of a supported family is supported. */
65
+ export const KNOWN_BROKEN_HOSTS = Object.freeze(['2.0.22'])
66
+ const UNSUPPORTED_HOSTS = new Set(KNOWN_BROKEN_HOSTS)
67
+
68
+ /**
69
+ * The measured hosts at the time of freezing. Rows are evidence, not the
70
+ * boundary of support: `PANTHEON_RELEASE_MATRIX` overrides them when a release
71
+ * needs to exercise a different host.
72
+ */
73
+ const DEFAULT_MATRIX = [
74
+ { host: '1.19.4', line: '1.19.x', kind: 'v1-permission' },
75
+ { host: '2.0.29', line: '2.x', kind: 'sandbox-v2' },
76
+ { host: '2.0.30', line: '2.x', kind: 'sandbox-v2' },
77
+ { host: '2.1.0', line: '2.x', kind: 'sandbox-v2' },
78
+ { host: '2.1.3', line: '2.x', kind: 'sandbox-v2' },
79
+ ]
80
+
81
+ const REQUIRED_TARBALL_PAYLOAD = [
82
+ 'package/package.json',
83
+ 'package/plugin.json',
84
+ 'package/pyproject.toml',
85
+ 'package/src/plugin.ts',
86
+ 'package/src/plugin-v2.ts',
87
+ 'package/src/plugins/tui/dist/tui.js',
88
+ 'package/src/plugins/tui/package.json',
89
+ 'package/src/plugins/tui/package-lock.json',
90
+ 'package/bin/pantheon-init.mjs',
91
+ 'package/scripts/doctor.mjs',
92
+ 'package/.pantheon/code-mode/compress-inline.py',
93
+ ]
94
+
95
+ function usage(message) {
96
+ console.error(`release-gates: ${message}`)
97
+ console.error(
98
+ 'usage: node scripts/release-gates.mjs <gate> --evidence-dir <dir> [--artifact-dir <dir>] [--version <v>] [--target-sha <sha>] [--channel stable|beta] [--recovery]',
99
+ )
100
+ process.exit(2)
101
+ }
102
+
103
+ function parseArgs(argv) {
104
+ const options = {
105
+ evidenceDir: undefined,
106
+ artifactDir: undefined,
107
+ version: undefined,
108
+ targetSha: process.env.TARGET_SHA,
109
+ channel: process.env.RELEASE_CHANNEL ?? 'stable',
110
+ recovery: false,
111
+ }
112
+ const positional = []
113
+ for (let i = 0; i < argv.length; i += 1) {
114
+ const arg = argv[i]
115
+ if (arg === '--recovery') {
116
+ options.recovery = true
117
+ continue
118
+ }
119
+ if (
120
+ ['--evidence-dir', '--artifact-dir', '--version', '--target-sha', '--channel'].includes(arg)
121
+ ) {
122
+ const value = argv[i + 1]
123
+ if (value === undefined) usage(`${arg} requires a value`)
124
+ const key = arg.slice(2).replace(/-([a-z])/g, (_, letter) => letter.toUpperCase())
125
+ options[key] = value
126
+ i += 1
127
+ continue
128
+ }
129
+ if (arg.startsWith('-')) usage(`unknown option ${arg}`)
130
+ positional.push(arg)
131
+ }
132
+ if (positional.length !== 1) usage('exactly one gate name is required')
133
+ options.gate = positional[0]
134
+ if (!GATE_NAMES.includes(options.gate)) {
135
+ usage(`unknown gate ${options.gate} (expected: ${GATE_NAMES.join(', ')})`)
136
+ }
137
+ options.evidenceDir = resolve(options.evidenceDir ?? join(runnerTemp(), 'release-gate-evidence'))
138
+ if (options.artifactDir) options.artifactDir = resolve(options.artifactDir)
139
+ if (options.targetSha) options.targetSha = String(options.targetSha).toLowerCase()
140
+ options.version = options.version ?? readPackageVersion()
141
+ return options
142
+ }
143
+
144
+ function readPackageVersion() {
145
+ return JSON.parse(readFileSync(join(ROOT, 'package.json'), 'utf8')).version
146
+ }
147
+
148
+ function runnerTemp() {
149
+ return process.env.RUNNER_TEMP ?? tmpdir()
150
+ }
151
+
152
+ function sha256(buffer) {
153
+ return createHash('sha256').update(buffer).digest('hex')
154
+ }
155
+
156
+ function tail(text, limit = 4000) {
157
+ const value = String(text ?? '')
158
+ return value.length > limit ? value.slice(-limit) : value
159
+ }
160
+
161
+ /**
162
+ * Run one command and fail on any non-zero exit. Output is echoed so the CI log
163
+ * keeps the real failure; `echo: false` is for probes whose stdout is data.
164
+ */
165
+ function run(name, command, args = [], options = {}) {
166
+ const started = Date.now()
167
+ const result = spawnSync(command, args, {
168
+ cwd: ROOT,
169
+ env: { ...process.env, ...options.env },
170
+ encoding: 'utf8',
171
+ maxBuffer: 128 * 1024 * 1024,
172
+ })
173
+ const durationMs = Date.now() - started
174
+ const output = `${result.stdout ?? ''}${result.stderr ?? ''}`
175
+ if (options.echo !== false && output) process.stdout.write(output)
176
+ if (result.error) {
177
+ throw new Error(`${name}: could not start ${command}: ${result.error.message}`)
178
+ }
179
+ if (result.signal) throw new Error(`${name}: ${command} was killed by ${result.signal}`)
180
+ if (result.status !== 0) {
181
+ throw new Error(`${name}: ${command} exited ${result.status}\n${tail(output)}`)
182
+ }
183
+ return {
184
+ name,
185
+ status: 'PASS',
186
+ command: [command, ...args].join(' '),
187
+ durationMs,
188
+ output,
189
+ }
190
+ }
191
+
192
+ function requireArtifactDir(options) {
193
+ if (!options.artifactDir) throw new Error('--artifact-dir is required for this gate')
194
+ if (!existsSync(options.artifactDir)) {
195
+ throw new Error(`artifact directory does not exist: ${options.artifactDir}`)
196
+ }
197
+ }
198
+
199
+ function singleTarball(options) {
200
+ requireArtifactDir(options)
201
+ const tarballs = readdirSync(options.artifactDir).filter((name) => name.endsWith('.tgz'))
202
+ if (tarballs.length !== 1) {
203
+ throw new Error(`artifact directory must hold exactly one .tgz, found ${tarballs.length}`)
204
+ }
205
+ const tarball = join(options.artifactDir, tarballs[0])
206
+ if (!statSync(tarball).isFile()) throw new Error(`not a file: ${tarball}`)
207
+ return tarball
208
+ }
209
+
210
+ function sandboxEnv(root, host, tarball, port) {
211
+ return {
212
+ PANTHEON_SANDBOX_ROOT: root,
213
+ PANTHEON_SANDBOX_TARBALL: tarball,
214
+ OPENCODE_V2_SPEC: `@opencode/cli@${host}`,
215
+ OPENCODE_V2_BIN: 'opencode',
216
+ PANTHEON_V2_PORT: String(port),
217
+ PORT: String(port),
218
+ }
219
+ }
220
+
221
+ function safeName(value) {
222
+ return String(value).replace(/[^0-9A-Za-z.-]/g, '-')
223
+ }
224
+
225
+ function installedVersion(root) {
226
+ const manifest = join(
227
+ root,
228
+ 'home',
229
+ '.npm-global',
230
+ 'lib',
231
+ 'node_modules',
232
+ 'pantheon-opencode',
233
+ 'package.json',
234
+ )
235
+ if (!existsSync(manifest)) throw new Error(`installed package manifest is missing: ${manifest}`)
236
+ return JSON.parse(readFileSync(manifest, 'utf8')).version
237
+ }
238
+
239
+ function assertCandidateSha(options) {
240
+ const sha = String(options.targetSha ?? '').toLowerCase()
241
+ if (!/^[0-9a-f]{40}$/.test(sha)) {
242
+ throw new Error('--target-sha must be the full 40-character hexadecimal candidate SHA')
243
+ }
244
+ return sha
245
+ }
246
+
247
+ // ── Gate (a): tests ──────────────────────────────────────────────────────────
248
+
249
+ /**
250
+ * The Python interpreter used by gate (a).
251
+ *
252
+ * The suite imports `fastmcp`/`mcp` at collection time, so it only means
253
+ * anything when run against the exact pins in `src/mcp/requirements-mcp.txt`.
254
+ * `PANTHEON_PYTHON` (the same variable `scripts/doctor.mjs` honours) points at
255
+ * the isolated venv prepared from those pins. When it is set, a missing or
256
+ * non-executable path is a hard failure: falling back to the ambient `python3`
257
+ * is what produced environment-only collection errors instead of a real
258
+ * verdict. Only an unset variable keeps the developer default.
259
+ */
260
+ function gatePython() {
261
+ const configured = String(process.env.PANTHEON_PYTHON ?? '').trim()
262
+ if (!configured) return 'python3'
263
+ const resolved = resolve(configured)
264
+ if (!existsSync(resolved)) {
265
+ throw new Error(`PANTHEON_PYTHON does not exist: ${resolved}`)
266
+ }
267
+ try {
268
+ accessSync(resolved, fsConstants.X_OK)
269
+ } catch {
270
+ throw new Error(`PANTHEON_PYTHON is not executable: ${resolved}`)
271
+ }
272
+ return resolved
273
+ }
274
+
275
+ function testsGate() {
276
+ const python = gatePython()
277
+ const pythonVersion = run('python-version', python, ['--version'], { echo: false }).output.trim()
278
+ const checks = [
279
+ run('python-tests-coverage', python, [
280
+ '-m',
281
+ 'coverage',
282
+ 'run',
283
+ '--branch',
284
+ '--source=src/mcp',
285
+ '-m',
286
+ 'pytest',
287
+ '-q',
288
+ '--tb=short',
289
+ ]),
290
+ run('python-coverage-threshold', python, ['-m', 'coverage', 'report', '--fail-under=80']),
291
+ run('node-tests', 'npm', ['run', 'test:node']),
292
+ run('typescript-tests', 'npm', ['run', 'test:ts']),
293
+ run('plugin-v2-line-coverage', 'npm', ['run', 'coverage:plugin-v2']),
294
+ // Mandatory here and optional in the developer loop: the release gate may
295
+ // not publish without the real-install tier.
296
+ run('install-tier', 'npm', ['run', 'test:install'], {
297
+ env: { PANTHEON_RUN_INSTALL_TESTS: '1' },
298
+ }),
299
+ ]
300
+ return {
301
+ checks,
302
+ details: {
303
+ pythonInterpreter: python,
304
+ pythonVersion,
305
+ pinnedRequirements: ['src/mcp/requirements-mcp.txt', 'src/mcp/requirements-vision.txt'],
306
+ requiredCoverage: [
307
+ 'python: src/mcp branch coverage >= 80% (coverage report --fail-under=80)',
308
+ 'typescript: src/plugin-v2.ts line coverage (coverage:plugin-v2)',
309
+ ],
310
+ notPass: [
311
+ 'Node coverage (`npm run coverage`) is report-only and is NOT a PASS signal.',
312
+ 'TypeScript under src/ outside the plugin-v2 measurement is unmeasured, NOT PASS.',
313
+ ],
314
+ },
315
+ }
316
+ }
317
+
318
+ // ── Gate (b): host compatibility ─────────────────────────────────────────────
319
+
320
+ function matrixFromEnv() {
321
+ const raw = process.env.PANTHEON_RELEASE_MATRIX
322
+ if (!raw) return DEFAULT_MATRIX
323
+ let parsed
324
+ try {
325
+ parsed = JSON.parse(raw)
326
+ } catch (error) {
327
+ throw new Error(`PANTHEON_RELEASE_MATRIX is not valid JSON: ${error.message}`)
328
+ }
329
+ if (!Array.isArray(parsed)) {
330
+ throw new Error('PANTHEON_RELEASE_MATRIX must be a JSON array')
331
+ }
332
+ return parsed
333
+ }
334
+
335
+ export function validateMatrix(matrix) {
336
+ if (!Array.isArray(matrix)) throw new Error('host evidence must be an array')
337
+ for (const row of matrix) {
338
+ if (!row || typeof row !== 'object') throw new Error('matrix rows must be objects')
339
+ if (!/^\d+\.\d+\.\d+$/.test(String(row.host ?? ''))) {
340
+ throw new Error(`matrix row has an invalid host: ${JSON.stringify(row.host)}`)
341
+ }
342
+ if (UNSUPPORTED_HOSTS.has(row.host)) {
343
+ throw new Error(`host ${row.host} is known broken and may not be measured as supported`)
344
+ }
345
+ if (!SUPPORTED_FAMILIES.includes(row.line)) {
346
+ throw new Error(
347
+ `matrix row ${row.host} has an undeclared family: ${JSON.stringify(row.line)}`,
348
+ )
349
+ }
350
+ if (row.line === '1.19.x' && !row.host.startsWith('1.19.')) {
351
+ throw new Error(`host ${row.host} does not belong to the 1.19.x family`)
352
+ }
353
+ if (row.line === '2.x' && !row.host.startsWith('2.')) {
354
+ throw new Error(`host ${row.host} does not belong to the 2.x family`)
355
+ }
356
+ if (row.line === '1.19.x' && row.kind !== 'v1-permission') {
357
+ throw new Error(`kind ${row.kind} cannot run on the 1.19.x family`)
358
+ }
359
+ if (row.line === '2.x' && row.kind !== 'sandbox-v2') {
360
+ throw new Error(`kind ${row.kind} cannot run on the 2.x family`)
361
+ }
362
+ if (!['sandbox-v2', 'v1-permission'].includes(row.kind)) {
363
+ throw new Error(`matrix row ${row.host} has an unknown kind: ${JSON.stringify(row.kind)}`)
364
+ }
365
+ }
366
+ }
367
+
368
+ export function hostEvidenceWarning(checks) {
369
+ return checks.length === 0
370
+ ? 'no measured hosts; supported families are reported as unmeasured'
371
+ : null
372
+ }
373
+
374
+ function v1Proof(root, row) {
375
+ rmSync(root, { recursive: true, force: true })
376
+ const prefix = join(root, 'prefix')
377
+ const home = join(root, 'home')
378
+ mkdirSync(prefix, { recursive: true })
379
+ mkdirSync(home, { recursive: true })
380
+ run(
381
+ `host-${row.host}-install`,
382
+ 'npm',
383
+ ['install', '--global', '--prefix', prefix, `opencode-ai@${row.host}`],
384
+ {
385
+ env: { HOME: home, npm_config_cache: join(root, 'npm-cache') },
386
+ },
387
+ )
388
+ const binary = join(prefix, 'bin', 'opencode')
389
+ return run(`host-${row.host}`, 'bash', ['tests/canary/run-v1-permission-proof.sh'], {
390
+ env: {
391
+ HOME: home,
392
+ XDG_CONFIG_HOME: join(root, 'config'),
393
+ XDG_DATA_HOME: join(root, 'data'),
394
+ XDG_STATE_HOME: join(root, 'state'),
395
+ XDG_CACHE_HOME: join(root, 'cache'),
396
+ PATH: `${join(prefix, 'bin')}:${process.env.PATH ?? ''}`,
397
+ PANTHEON_V1_CANARY_BIN: binary,
398
+ },
399
+ })
400
+ }
401
+
402
+ function hostGate(options) {
403
+ const tarball = singleTarball(options)
404
+ const matrix = matrixFromEnv()
405
+ validateMatrix(matrix)
406
+ const checks = []
407
+ matrix.forEach((row, index) => {
408
+ const root = join(runnerTemp(), `pantheon-release-host-${safeName(row.host)}`)
409
+ if (row.kind === 'sandbox-v2') {
410
+ rmSync(root, { recursive: true, force: true })
411
+ checks.push(
412
+ run(
413
+ `host-${row.host}`,
414
+ 'bash',
415
+ ['scripts/test-opencode-v2-sandbox.sh', '--prepare', '--run', 'v2'],
416
+ {
417
+ env: sandboxEnv(root, row.host, tarball, 49380 + index),
418
+ },
419
+ ),
420
+ )
421
+ return
422
+ }
423
+ checks.push(v1Proof(root, row))
424
+ })
425
+ const measuredFamilies = [...new Set(matrix.map((row) => row.line))]
426
+ const unmeasuredFamilies = SUPPORTED_FAMILIES.filter(
427
+ (family) => !measuredFamilies.includes(family),
428
+ )
429
+ return {
430
+ checks,
431
+ details: {
432
+ supportLevel: 'family',
433
+ supportedFamilies: [...SUPPORTED_FAMILIES],
434
+ measuredFamilies,
435
+ unmeasuredFamilies,
436
+ matrix: matrix.map((row) => ({
437
+ host: row.host,
438
+ line: row.line,
439
+ kind: row.kind,
440
+ status: 'PASS',
441
+ })),
442
+ unsupportedExcluded: [...UNSUPPORTED_HOSTS],
443
+ },
444
+ }
445
+ }
446
+
447
+ // ── Gate (c): install ────────────────────────────────────────────────────────
448
+
449
+ function installGate(options) {
450
+ const tarball = singleTarball(options)
451
+ const host = process.env.PANTHEON_RELEASE_INSTALL_HOST ?? '2.0.30'
452
+ const root = join(runnerTemp(), `pantheon-release-install-${safeName(host)}`)
453
+ const port = Number(process.env.PANTHEON_RELEASE_INSTALL_PORT ?? 49390)
454
+ rmSync(root, { recursive: true, force: true })
455
+
456
+ const sandbox = run(
457
+ 'sandbox-install',
458
+ 'bash',
459
+ ['scripts/test-opencode-v2-sandbox.sh', '--prepare', '--run', 'v2'],
460
+ { env: sandboxEnv(root, host, tarball, port) },
461
+ )
462
+ const version = installedVersion(root)
463
+ if (version !== options.version) {
464
+ throw new Error(
465
+ `installed package version ${version} does not match candidate ${options.version}`,
466
+ )
467
+ }
468
+
469
+ const binary = join(root, 'home', '.npm-global', 'bin', 'opencode')
470
+ const canary = run('tool-canary', 'npm', ['run', 'test:tool-canary'], {
471
+ env: { PANTHEON_TOOL_CANARY_BIN: binary },
472
+ })
473
+ // The canary itself skips when no binary is found. In release context that
474
+ // skip is not a PASS, so a skip marker fails the gate.
475
+ if (/\(skipped\)/.test(canary.output)) {
476
+ throw new Error('host-backed tool canary was skipped; release context requires a real host')
477
+ }
478
+ writeFileSync(join(options.evidenceDir, 'install-canary.log'), canary.output)
479
+
480
+ return {
481
+ checks: [sandbox, canary],
482
+ details: {
483
+ host,
484
+ version,
485
+ tarball: basename(tarball),
486
+ tarballSha256: sha256(readFileSync(tarball)),
487
+ },
488
+ }
489
+ }
490
+
491
+ // ── Gate (d): package ────────────────────────────────────────────────────────
492
+
493
+ function packageGate(options) {
494
+ const tarball = singleTarball(options)
495
+ const metadataPath = join(options.artifactDir, 'metadata.json')
496
+ if (!existsSync(metadataPath)) throw new Error(`artifact metadata is missing: ${metadataPath}`)
497
+ const metadata = JSON.parse(readFileSync(metadataPath, 'utf8'))
498
+ const actualSha = sha256(readFileSync(tarball))
499
+
500
+ if (metadata.targetSha !== options.targetSha) {
501
+ throw new Error('artifact metadata target SHA does not match --target-sha')
502
+ }
503
+ if (metadata.version !== options.version) {
504
+ throw new Error('artifact metadata version does not match --version')
505
+ }
506
+ if (metadata.tarball !== basename(tarball)) {
507
+ throw new Error('artifact metadata does not name the sole .tgz')
508
+ }
509
+ if (metadata.tarballSha256 !== actualSha) {
510
+ throw new Error('artifact SHA-256 does not match metadata')
511
+ }
512
+ const expectedName = `pantheon-opencode-${options.version}.tgz`
513
+ if (basename(tarball) !== expectedName) {
514
+ throw new Error(`artifact must be named ${expectedName}, found ${basename(tarball)}`)
515
+ }
516
+
517
+ const listing = run('tarball-contents', 'tar', ['-tzf', tarball], { echo: false }).output
518
+ const entries = new Set(
519
+ listing
520
+ .split('\n')
521
+ .map((line) => line.trim())
522
+ .filter(Boolean),
523
+ )
524
+ const missing = REQUIRED_TARBALL_PAYLOAD.filter((entry) => !entries.has(entry))
525
+ if (missing.length > 0) {
526
+ throw new Error(`tarball is missing required payload: ${missing.join(', ')}`)
527
+ }
528
+
529
+ const validate = run('package-validate', 'npm', ['run', 'package:validate'])
530
+ return {
531
+ checks: [validate],
532
+ details: {
533
+ tarball: basename(tarball),
534
+ tarballSha256: actualSha,
535
+ targetSha: options.targetSha,
536
+ payloadEntries: entries.size,
537
+ },
538
+ }
539
+ }
540
+
541
+ // ── Gate (e): changelog ──────────────────────────────────────────────────────
542
+
543
+ function changelogGate(options) {
544
+ if (options.recovery) {
545
+ const tag = run('recovery-tag', 'git', ['tag', '-l', `v${options.version}`], { echo: false })
546
+ if (tag.output.trim() !== `v${options.version}`) {
547
+ throw new Error(`recovery tag v${options.version} does not exist on this checkout`)
548
+ }
549
+ return {
550
+ checks: [
551
+ { name: 'recovery-tag', status: 'PASS', command: 'git tag -l', durationMs: tag.durationMs },
552
+ ],
553
+ details: { mode: 'recovery-static', version: options.version },
554
+ }
555
+ }
556
+ const extraction = run(
557
+ 'changelog-section',
558
+ 'node',
559
+ ['scripts/changelog-extract.mjs', options.version],
560
+ {
561
+ echo: false,
562
+ },
563
+ )
564
+ if (!extraction.output.trim()) {
565
+ throw new Error(`CHANGELOG.md has no non-empty [${options.version}] section`)
566
+ }
567
+ writeFileSync(join(options.evidenceDir, 'changelog.md'), extraction.output)
568
+ return {
569
+ checks: [{ ...extraction, output: undefined, sha256: sha256(extraction.output) }],
570
+ details: {
571
+ mode: 'committed-section',
572
+ version: options.version,
573
+ bytes: extraction.output.length,
574
+ },
575
+ }
576
+ }
577
+
578
+ // ── Gate (f): metadata ───────────────────────────────────────────────────────
579
+
580
+ function metadataGate(options) {
581
+ const targetSha = assertCandidateSha(options)
582
+ if (options.version !== readPackageVersion()) {
583
+ throw new Error(`--version ${options.version} does not match package.json`)
584
+ }
585
+ const stable = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$/
586
+ const beta = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)-beta\.[1-9]\d*$/
587
+ if (!['stable', 'beta'].includes(options.channel)) {
588
+ throw new Error(`unknown channel ${options.channel}`)
589
+ }
590
+ if (options.channel === 'stable' && !stable.test(options.version)) {
591
+ throw new Error(`stable channel requires X.Y.Z, found ${options.version}`)
592
+ }
593
+ if (options.channel === 'beta' && !beta.test(options.version)) {
594
+ throw new Error(`beta channel requires X.Y.Z-beta.N, found ${options.version}`)
595
+ }
596
+ const checks = [
597
+ run('version-manifests', 'node', ['scripts/version-check.mjs']),
598
+ run('node-engine-policy', 'node', ['scripts/validate-node-engine-policy.mjs']),
599
+ ]
600
+ return {
601
+ checks,
602
+ details: {
603
+ version: options.version,
604
+ channel: options.channel,
605
+ targetSha,
606
+ recovery: options.recovery,
607
+ },
608
+ }
609
+ }
610
+
611
+ const GATES = {
612
+ tests: testsGate,
613
+ host: hostGate,
614
+ install: installGate,
615
+ package: packageGate,
616
+ changelog: changelogGate,
617
+ metadata: metadataGate,
618
+ }
619
+
620
+ function evidenceCheck(check) {
621
+ const { output, ...rest } = check
622
+ if (typeof output === 'string') {
623
+ rest.outputBytes = Buffer.byteLength(output)
624
+ rest.outputSha256 = sha256(output)
625
+ }
626
+ return rest
627
+ }
628
+
629
+ function writeEvidence(options, record) {
630
+ mkdirSync(options.evidenceDir, { recursive: true })
631
+ const path = join(options.evidenceDir, `${options.gate}.json`)
632
+ const serializable = { ...record, checks: record.checks.map(evidenceCheck) }
633
+ writeFileSync(path, `${JSON.stringify(serializable, null, 2)}\n`)
634
+ return path
635
+ }
636
+
637
+ function main() {
638
+ const options = parseArgs(process.argv.slice(2))
639
+ mkdirSync(options.evidenceDir, { recursive: true })
640
+ const record = {
641
+ gate: options.gate,
642
+ status: 'PASS',
643
+ version: options.version,
644
+ targetSha: options.targetSha,
645
+ channel: options.channel,
646
+ recovery: options.recovery,
647
+ generatedAt: new Date().toISOString(),
648
+ checks: [],
649
+ details: {},
650
+ }
651
+
652
+ try {
653
+ const result = GATES[options.gate](options)
654
+ record.checks = result.checks ?? []
655
+ record.details = result.details ?? {}
656
+ const warning = options.gate === 'host' ? hostEvidenceWarning(record.checks) : null
657
+ if (warning) {
658
+ record.details.hostEvidenceWarning = warning
659
+ console.warn(`GATE host: WARNING — ${warning}`)
660
+ }
661
+ } catch (error) {
662
+ record.status = 'FAIL'
663
+ record.error = error.message
664
+ const path = writeEvidence(options, record)
665
+ console.error(`GATE ${options.gate}: FAIL — ${error.message}`)
666
+ if (process.env.GITHUB_ACTIONS === 'true') {
667
+ console.error(`::error title=Gate ${options.gate}::FAIL — ${tail(error.message, 500)}`)
668
+ }
669
+ console.error(`evidence: ${path}`)
670
+ process.exit(1)
671
+ }
672
+
673
+ const path = writeEvidence(options, record)
674
+ console.log(`GATE ${options.gate}: PASS`)
675
+ if (process.env.GITHUB_ACTIONS === 'true') {
676
+ console.log(`::notice title=Gate ${options.gate}::PASS`)
677
+ }
678
+ console.log(`evidence: ${path}`)
679
+ }
680
+
681
+ const isDirectRun = process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href
682
+ if (isDirectRun) main()