pantheon-opencode 1.6.2-beta.2 → 1.6.2-beta.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/CHANGELOG.md +48 -0
  2. package/README.md +56 -16
  3. package/bin/pantheon-init.mjs +68 -13
  4. package/package.json +10 -3
  5. package/plugin.json +1 -1
  6. package/prompts/README.md +58 -0
  7. package/prompts/debug-issue.prompt.md +46 -0
  8. package/prompts/dynamic/agora-generated.txt +38 -0
  9. package/prompts/dynamic/orchestrate-generated.txt +51 -0
  10. package/prompts/focus.prompt.md +42 -0
  11. package/prompts/implement-feature.prompt.md +39 -0
  12. package/prompts/optimize-database.prompt.md +58 -0
  13. package/prompts/orchestrate-with-zeus.prompt.md +441 -0
  14. package/prompts/plan-architecture.prompt.md +59 -0
  15. package/prompts/quick-discovery-large-codebase.prompt.md +294 -0
  16. package/prompts/quick-plan-large-feature.prompt.md +197 -0
  17. package/prompts/semantic-summarize.md +50 -0
  18. package/prompts/sketch.prompt.md +91 -0
  19. package/prompts/subtask.prompt.md +131 -0
  20. package/pyproject.toml +1 -1
  21. package/scripts/decision-router-budget.mjs +781 -0
  22. package/scripts/decision-router.mjs +297 -0
  23. package/scripts/install/component-selection.mjs +9 -4
  24. package/scripts/install/decision-router-config.mjs +432 -0
  25. package/scripts/install/health-check.mjs +20 -11
  26. package/scripts/install/interactive.mjs +78 -14
  27. package/scripts/install/interrupt.mjs +4 -3
  28. package/scripts/install/migrate.mjs +123 -72
  29. package/scripts/install/opencode.mjs +162 -114
  30. package/scripts/install/plan.mjs +8 -1
  31. package/scripts/install/state.mjs +12 -0
  32. package/scripts/install/strings.mjs +10 -0
  33. package/scripts/install/venv.mjs +34 -17
  34. package/scripts/restore.mjs +22 -10
  35. package/scripts/test-opencode-v2-sandbox.sh +10 -6
  36. package/src/agents/zeus.md +12 -0
  37. package/src/pantheon/local-decision-agents.ts +170 -0
  38. package/src/pantheon/local-decision-budget.ts +1043 -0
  39. package/src/pantheon/local-decision-egress-gate.ts +264 -0
  40. package/src/pantheon/local-decision-prompt.ts +123 -0
  41. package/src/pantheon/local-decision-provider-matrix.ts +92 -0
  42. package/src/pantheon/local-decision-provider-protocol.ts +335 -0
  43. package/src/pantheon/local-decision-provider.internal.ts +260 -0
  44. package/src/pantheon/local-decision-router.ts +225 -0
  45. package/src/pantheon/local-decision-skills.ts +171 -0
  46. package/src/pantheon/local-decision-tool.ts +126 -0
  47. package/src/pantheon/local-decision-turn.ts +338 -0
  48. package/src/pantheon/local-decision-usage-evidence.internal.ts +207 -0
  49. package/src/pantheon/local-orchestration.ts +322 -0
  50. package/src/pantheon/pantheon-decision-catalog.ts +101 -0
  51. package/src/pantheon/v2-tools.ts +15 -14
  52. package/src/plugin-v2.ts +52 -19
  53. package/src/plugin.ts +4 -0
  54. package/src/plugins/tui/dist/tui-v2.js +3 -3
  55. package/src/plugins/tui/dist/tui.js +1 -1
  56. package/src/plugins/tui/package-lock.json +2 -2
  57. package/src/plugins/tui/package.json +1 -1
@@ -11,9 +11,8 @@
11
11
  import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs'
12
12
  import { dirname, join } from 'node:path'
13
13
  import { fileURLToPath } from 'node:url'
14
- import { configure as configureUi, tag } from './cli-ui.mjs'
15
14
  import { ACTIONS, fingerprintOutput, recordChange } from './plan.mjs'
16
- import { createInitialState, readState, writeState } from './state.mjs'
15
+ import { createInitialState, MIGRATION_SCHEMA_VERSION, readState, writeState } from './state.mjs'
17
16
 
18
17
  const __dirname = dirname(fileURLToPath(import.meta.url))
19
18
  const ROOT = join(__dirname, '..', '..')
@@ -47,76 +46,84 @@ export function detectVersion(target) {
47
46
  * @param {string} target - Installation directory
48
47
  * @param {string|null} currentVersion - Detected version (null = fresh install)
49
48
  * @param {{ dryRun?: boolean, recorder?: (change: object) => void }} [options]
50
- * @returns {{ applied: number, messages: string[] }}
49
+ * @returns {{ applied: number, messages: string[], plannedState: object|null, status?: 'invalid'|'unsupported', marker?: unknown, message?: string }}
51
50
  */
52
- export function runMigrations(
53
- target,
54
- currentVersion,
55
- { dryRun = false, recorder = null, updatedAt = new Date().toISOString() } = {},
56
- ) {
51
+ export function runMigrations(target, options = {}, legacyOptions = {}) {
52
+ // Preserve the old `(target, version, options)` call shape for downstream
53
+ // callers while making the persisted migration marker authoritative.
54
+ const explicitVersion = typeof options === 'string' ? options : null
55
+ const {
56
+ dryRun = false,
57
+ recorder = null,
58
+ updatedAt = new Date().toISOString(),
59
+ } = typeof options === 'object' && options !== null ? options : legacyOptions
60
+ const state = readState(target)
61
+ if (!state) return { applied: 0, messages: [], plannedState: null }
62
+
63
+ const schemaMarker = state.migration_schema_version
64
+ if (schemaMarker !== null && schemaMarker !== undefined) {
65
+ const parsedMarker = parseSemver(schemaMarker)
66
+ if (!parsedMarker) return blockedMigration('invalid', schemaMarker)
67
+ if (compareSemver(parsedMarker, parseSemver(MIGRATION_SCHEMA_VERSION)) > 0) {
68
+ return blockedMigration('unsupported', schemaMarker)
69
+ }
70
+ }
71
+
72
+ const currentVersion =
73
+ state.migration_schema_version ?? explicitVersion ?? state.pantheon_version ?? null
57
74
  const applied = []
58
- const semver = parseSemver(currentVersion)
75
+ let cursor = parseSemver(currentVersion)
59
76
 
60
77
  // ── Migration: v3.10.0 → v3.18.0 ──────────────────────────────────
61
78
  // Fix dangling references, add Memory Protocol
62
- if (semver && lt(semver, [3, 18, 0])) {
79
+ if (cursor && compareSemver(cursor, parseSemver('3.18.0')) < 0) {
63
80
  applied.push({
64
- from: formatSemver(semver),
81
+ from: formatSemver(cursor),
65
82
  to: '3.18.0',
66
83
  description: 'Fix dangling references, add Memory Protocol',
67
84
  })
68
- semver[0] = 3
69
- semver[1] = 18
70
- semver[2] = 0
85
+ cursor = parseSemver('3.18.0')
71
86
  }
72
87
 
73
88
  // ── Migration: v3.18.0 → v3.19.0 ──────────────────────────────────
74
89
  // Add runtime component, _pantheon_paths
75
- if (semver && lt(semver, [3, 19, 0])) {
90
+ if (cursor && compareSemver(cursor, parseSemver('3.19.0')) < 0) {
76
91
  applied.push({
77
- from: formatSemver(semver),
92
+ from: formatSemver(cursor),
78
93
  to: '3.19.0',
79
94
  description: 'Add runtime component, _pantheon_paths',
80
95
  })
81
- semver[0] = 3
82
- semver[1] = 19
83
- semver[2] = 0
96
+ cursor = parseSemver('3.19.0')
84
97
  }
85
98
 
86
99
  // ── Migration: v3.19.0 → v3.19.1 ──────────────────────────────────
87
100
  // Add persistence MCP, fix 157 dangling refs
88
- if (semver && lt(semver, [3, 19, 1])) {
101
+ if (cursor && compareSemver(cursor, parseSemver('3.19.1')) < 0) {
89
102
  applied.push({
90
- from: formatSemver(semver),
103
+ from: formatSemver(cursor),
91
104
  to: '3.19.1',
92
105
  description: 'Add persistence MCP, fix dangling refs',
93
106
  })
94
- semver[0] = 3
95
- semver[1] = 19
96
- semver[2] = 1
107
+ cursor = parseSemver('3.19.1')
97
108
  }
98
109
 
99
110
  // ── Migration: v3.19.1 → v3.19.2 ──────────────────────────────────
100
111
  // Upgrade state schema from v1 to v2
101
- if (semver && lt(semver, [3, 19, 2])) {
112
+ if (cursor && compareSemver(cursor, parseSemver(MIGRATION_SCHEMA_VERSION)) < 0) {
102
113
  applied.push({
103
- from: formatSemver(semver),
104
- to: '3.19.2',
114
+ from: formatSemver(cursor),
115
+ to: MIGRATION_SCHEMA_VERSION,
105
116
  description: 'Upgrade install state schema to v2 with component tracking',
106
117
  })
107
- semver[0] = 3
108
- semver[1] = 19
109
- semver[2] = 2
118
+ cursor = parseSemver(MIGRATION_SCHEMA_VERSION)
110
119
  }
111
120
 
112
121
  // ── Write updated state ───────────────────────────────────────────
113
- if (applied.length > 0) {
122
+ const markerChanged = state.migration_schema_version !== MIGRATION_SCHEMA_VERSION
123
+ if (applied.length > 0 || markerChanged) {
114
124
  const statePath = join(target, '.pantheon', 'install-state.json')
115
- const newVersion = formatSemver(semver)
116
- let state = readState(target)
117
- const stateExisted = state !== null
118
- if (!state) state = createInitialState(newVersion, updatedAt)
119
- state.pantheon_version = newVersion
125
+ const stateExisted = true
126
+ state.applied_migrations ??= []
120
127
  for (const m of applied) {
121
128
  state.applied_migrations.push({
122
129
  from: m.from,
@@ -133,6 +140,7 @@ export function runMigrations(
133
140
  runtime: { version: 1, status: 'installed' },
134
141
  }
135
142
  }
143
+ state.migration_schema_version = MIGRATION_SCHEMA_VERSION
136
144
  state.updated_at = updatedAt
137
145
  state.schema_version = 2
138
146
  const stateContent = `${JSON.stringify(state, null, 2)}\n`
@@ -155,12 +163,20 @@ export function runMigrations(
155
163
  }
156
164
 
157
165
  return {
158
- applied: applied.length,
166
+ applied: 0,
159
167
  messages: applied.map((m) => `${m.from} → ${m.to}: ${m.description}`),
160
168
  plannedState: null,
161
169
  }
162
170
  }
163
171
 
172
+ function blockedMigration(status, marker) {
173
+ const message =
174
+ status === 'unsupported'
175
+ ? `Migration schema ${marker} is newer than supported ${MIGRATION_SCHEMA_VERSION}; refusing to downgrade or modify the installation.`
176
+ : 'Invalid migration schema marker; refusing to modify the installation.'
177
+ return { applied: 0, messages: [], plannedState: null, status, marker, message }
178
+ }
179
+
164
180
  // ---------------------------------------------------------------------------
165
181
  // Checkpoint system for crash recovery
166
182
  // ---------------------------------------------------------------------------
@@ -279,7 +295,7 @@ export function rollbackMigration(target, version) {
279
295
  console.log(` Rolling back migration: ${targetMigration.from} -> ${targetMigration.to}`)
280
296
 
281
297
  targetMigration.status = 'rolled_back'
282
- state.pantheon_version = targetMigration.from
298
+ state.migration_schema_version = targetMigration.from
283
299
  writeState(target, state)
284
300
 
285
301
  console.log(` [OK] Rolled back to ${targetMigration.from}`)
@@ -307,46 +323,69 @@ export function listAppliedMigrations(target) {
307
323
  // Minimal semver helpers (no external deps)
308
324
  // ---------------------------------------------------------------------------
309
325
 
310
- /**
311
- * Parse "x.y.z" → [major, minor, patch] or null.
312
- * @param {string|null} v
313
- * @returns {number[]|null}
314
- */
315
- function parseSemver(v) {
316
- if (!v || typeof v !== 'string') return null
317
- const parts = v.split('.').map(Number)
318
- if (parts.length < 2 || parts.some(Number.isNaN)) return null
319
- return [parts[0], parts[1], parts[2] ?? 0]
320
- }
321
-
322
- /**
323
- * Format [major, minor, patch] → "x.y.z".
324
- * @param {number[]} v
325
- * @returns {string}
326
- */
327
- function formatSemver(v) {
328
- return `${v[0]}.${v[1]}.${v[2]}`
326
+ /** Parse strict SemVer precedence, accepting an optional `v` and build metadata. */
327
+ export function parseSemver(value) {
328
+ if (typeof value !== 'string') return null
329
+ const match = value.match(
330
+ /^v?(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/,
331
+ )
332
+ if (!match) return null
333
+ const prerelease = match[4]
334
+ ? match[4].split('.').map((identifier) => {
335
+ if (!/^\d+$/.test(identifier)) return identifier
336
+ if (identifier.length > 1 && identifier.startsWith('0')) return null
337
+ return Number(identifier)
338
+ })
339
+ : []
340
+ if (prerelease.includes(null)) return null
341
+
342
+ const parsed = {
343
+ major: Number(match[1]),
344
+ minor: Number(match[2]),
345
+ patch: Number(match[3]),
346
+ prerelease,
347
+ }
348
+ Object.defineProperty(parsed, 'compare', {
349
+ enumerable: false,
350
+ value: (other) => compareSemver(parsed, other),
351
+ })
352
+ return parsed
329
353
  }
330
354
 
331
- /**
332
- * Compare two semver arrays: is a < b?
333
- * @param {number[]} a
334
- * @param {number[]} b
335
- * @returns {boolean}
336
- */
337
- function lt(a, b) {
338
- for (let i = 0; i < 3; i++) {
339
- if ((a[i] ?? 0) !== (b[i] ?? 0)) {
340
- return (a[i] ?? 0) < (b[i] ?? 0)
355
+ function compareSemver(left, right) {
356
+ for (const field of ['major', 'minor', 'patch']) {
357
+ if (left[field] !== right[field]) return left[field] < right[field] ? -1 : 1
358
+ }
359
+ const a = left.prerelease
360
+ const b = right.prerelease
361
+ if (a.length === 0 || b.length === 0) {
362
+ if (a.length === b.length) return 0
363
+ return a.length === 0 ? 1 : -1
364
+ }
365
+ const length = Math.min(a.length, b.length)
366
+ for (let index = 0; index < length; index += 1) {
367
+ if (a[index] === b[index]) continue
368
+ if (typeof a[index] === 'number' && typeof b[index] === 'number') {
369
+ return a[index] < b[index] ? -1 : 1
341
370
  }
371
+ if (typeof a[index] === 'number') return -1
372
+ if (typeof b[index] === 'number') return 1
373
+ return a[index] < b[index] ? -1 : 1
342
374
  }
343
- return false
375
+ if (a.length === b.length) return 0
376
+ return a.length < b.length ? -1 : 1
377
+ }
378
+
379
+ function formatSemver(value) {
380
+ const core = `${value.major}.${value.minor}.${value.patch}`
381
+ return value.prerelease.length === 0 ? core : `${core}-${value.prerelease.join('.')}`
344
382
  }
345
383
 
346
384
  // ---------------------------------------------------------------------------
347
385
  // CLI entry point
348
386
  // ---------------------------------------------------------------------------
349
- function main() {
387
+ async function main() {
388
+ const { configure: configureUi, tag } = await import('./cli-ui.mjs')
350
389
  const args = process.argv.slice(2)
351
390
  const targetIdx = args.indexOf('--target')
352
391
  const target = targetIdx !== -1 ? args[targetIdx + 1] : process.cwd()
@@ -394,12 +433,21 @@ function main() {
394
433
 
395
434
  console.log(` Current version: ${currentVersion}`)
396
435
 
397
- if (!force && currentVersion === PANTHON_VERSION) {
436
+ const state = readState(target)
437
+ if (
438
+ !force &&
439
+ currentVersion === PANTHON_VERSION &&
440
+ state?.migration_schema_version === MIGRATION_SCHEMA_VERSION
441
+ ) {
398
442
  console.log(' [OK] Already at latest version — no migrations needed')
399
443
  return
400
444
  }
401
445
 
402
- const migration = runMigrations(target, currentVersion, { dryRun })
446
+ const migration = runMigrations(target, { dryRun })
447
+
448
+ if (migration.status === 'unsupported' || migration.status === 'invalid') {
449
+ throw new Error(migration.message)
450
+ }
403
451
 
404
452
  if (migration.applied > 0) {
405
453
  console.log(` [OK] Applied ${migration.applied} migration(s):`)
@@ -412,5 +460,8 @@ function main() {
412
460
  }
413
461
 
414
462
  if (process.argv[1] && import.meta.url === `file://${process.argv[1]}`) {
415
- main()
463
+ main().catch((error) => {
464
+ console.error(` [ERROR] ${error instanceof Error ? error.message : String(error)}`)
465
+ process.exitCode = 1
466
+ })
416
467
  }