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
@@ -0,0 +1,432 @@
1
+ import { chmodSync, lstatSync, mkdirSync, readFileSync } from 'node:fs'
2
+ import { homedir } from 'node:os'
3
+ import { dirname, isAbsolute, join, parse, resolve, sep } from 'node:path'
4
+ import { assertNoSymlinkAncestors, writeFileAtomically } from './verify.mjs'
5
+
6
+ /** Versioned, non-secret installer preference for the advisory decision router. */
7
+ export const DECISION_ROUTER_CONFIG_SCHEMA_VERSION = 1
8
+
9
+ /**
10
+ * Legacy installer-state providers. This file is target metadata only: the
11
+ * runtime reads the user-level configuration below, never install-state.
12
+ */
13
+ export const DECISION_ROUTER_PROVIDERS = Object.freeze(['local', 'openai-decisions', 'jev', 'auto'])
14
+
15
+ export const DEFAULT_DECISION_ROUTER_CONFIG = Object.freeze({
16
+ schema_version: DECISION_ROUTER_CONFIG_SCHEMA_VERSION,
17
+ provider: 'local',
18
+ egress_consent: false,
19
+ })
20
+
21
+ /**
22
+ * Canonical user-level provider/model matrix. The provider identifiers are the
23
+ * same ones used by the runtime selector and by the private provider adapter;
24
+ * `decision-provider-budget.ts` maps them onto the ledger's accounting names.
25
+ */
26
+ export const DECISION_ROUTER_MODELS = Object.freeze({
27
+ 'openai-decisions': Object.freeze(['gpt-6-luna']),
28
+ 'typesafe-jev': Object.freeze(['jev-1.14.0']),
29
+ 'opencode-console-jev': Object.freeze(['jev-1.13']),
30
+ 'opencode-console-jev-free': Object.freeze(['jev-1.13-free']),
31
+ })
32
+
33
+ /** Single mapping from a user-level provider ID to the local budget provider. */
34
+ export const DECISION_PROVIDER_BUDGET_MAPPING = Object.freeze({
35
+ 'openai-decisions': 'openai-decisions',
36
+ 'typesafe-jev': 'typesafe-jev',
37
+ 'opencode-console-jev': 'opencode-console',
38
+ 'opencode-console-jev-free': 'jev-free',
39
+ })
40
+
41
+ /** Providers whose usage and price are documented well enough to reconcile. */
42
+ export const REMOTELY_ELIGIBLE_DECISION_PROVIDERS = Object.freeze([
43
+ 'openai-decisions',
44
+ 'typesafe-jev',
45
+ ])
46
+
47
+ export const USER_DECISION_ROUTER_CONFIG_SCHEMA_VERSION = 2
48
+ export const DEFAULT_USER_DECISION_ROUTER_CONFIG = Object.freeze({
49
+ schema_version: USER_DECISION_ROUTER_CONFIG_SCHEMA_VERSION,
50
+ enabled: false,
51
+ selection: Object.freeze({ mode: 'local' }),
52
+ egress_consent: false,
53
+ enabled_candidates: Object.freeze([]),
54
+ })
55
+
56
+ const LEGACY_PROVIDER_ALIASES = Object.freeze({ jev: 'typesafe-jev' })
57
+ const userCandidateProviders = new Set(Object.keys(DECISION_ROUTER_MODELS))
58
+ const remotelyEligibleProviders = new Set(REMOTELY_ELIGIBLE_DECISION_PROVIDERS)
59
+ const USER_CONFIG_KEYS = [
60
+ 'egress_consent',
61
+ 'enabled',
62
+ 'enabled_candidates',
63
+ 'schema_version',
64
+ 'selection',
65
+ ]
66
+ const LEGACY_USER_CONFIG_KEYS = [
67
+ 'egress_consent',
68
+ 'enabled_candidates',
69
+ 'schema_version',
70
+ 'selection',
71
+ ]
72
+
73
+ const providerSet = new Set(DECISION_ROUTER_PROVIDERS)
74
+ const externalProviderSet = new Set(['openai-decisions', 'jev', 'typesafe-jev'])
75
+
76
+ /** Canonicalize the legacy `jev` spelling once, at every user-config boundary. */
77
+ export function normalizeDecisionProviderId(provider) {
78
+ if (typeof provider !== 'string') return provider
79
+ return LEGACY_PROVIDER_ALIASES[provider] ?? provider
80
+ }
81
+
82
+ /**
83
+ * Migrate/validate persisted preference data. Missing or invalid legacy data is
84
+ * fail-closed: Local, no egress consent. Credentials are neither accepted nor
85
+ * inspected here.
86
+ * @param {unknown} value
87
+ * @returns {{ schema_version: 1, provider: string, egress_consent: boolean }}
88
+ */
89
+ export function migrateDecisionRouterConfig(value) {
90
+ if (
91
+ !value ||
92
+ typeof value !== 'object' ||
93
+ Array.isArray(value) ||
94
+ value.schema_version !== DECISION_ROUTER_CONFIG_SCHEMA_VERSION ||
95
+ !providerSet.has(value.provider) ||
96
+ typeof value.egress_consent !== 'boolean'
97
+ ) {
98
+ return { ...DEFAULT_DECISION_ROUTER_CONFIG }
99
+ }
100
+
101
+ return {
102
+ schema_version: DECISION_ROUTER_CONFIG_SCHEMA_VERSION,
103
+ provider: value.provider,
104
+ egress_consent: value.provider === 'local' ? false : value.egress_consent,
105
+ }
106
+ }
107
+
108
+ /** Build the only preference shape the installer persists. */
109
+ export function createDecisionRouterConfig(provider, egressConsent = false) {
110
+ return migrateDecisionRouterConfig({
111
+ schema_version: DECISION_ROUTER_CONFIG_SCHEMA_VERSION,
112
+ provider,
113
+ egress_consent: provider === 'local' ? false : egressConsent === true,
114
+ })
115
+ }
116
+
117
+ /**
118
+ * Resolve a preference without probing the environment or credentials.
119
+ * Auto can choose only one separately authorized provider; zero or multiple
120
+ * candidates, missing consent, or a missing explicit budget all stay Local.
121
+ * @param {{ schema_version?: number, provider?: string, egress_consent?: boolean }} config
122
+ * @param {{ authorizedProviders?: string[], budgetConfigured?: boolean }} [options]
123
+ * @returns {'local'|'openai-decisions'|'jev'|'typesafe-jev'}
124
+ */
125
+ export function resolveDecisionRouterProvider(
126
+ config,
127
+ { authorizedProviders = [], budgetConfigured = false } = {},
128
+ ) {
129
+ const preference = migrateDecisionRouterConfig(config)
130
+ if (!preference.egress_consent || budgetConfigured !== true) return 'local'
131
+ if (preference.provider === 'local') return 'local'
132
+
133
+ if (preference.provider === 'auto') {
134
+ const candidates = [
135
+ ...new Set(authorizedProviders.filter((provider) => externalProviderSet.has(provider))),
136
+ ]
137
+ return candidates.length === 1 ? candidates[0] : 'local'
138
+ }
139
+
140
+ return externalProviderSet.has(preference.provider) ? preference.provider : 'local'
141
+ }
142
+
143
+ /**
144
+ * Resolve Pantheon's private non-secret user configuration path.
145
+ * @param {Readonly<Record<string, string | undefined>>} [env]
146
+ */
147
+ export function resolveUserDecisionRouterConfigPath(env = process.env) {
148
+ const xdg = env.XDG_CONFIG_HOME
149
+ const home = env.HOME && isAbsolute(env.HOME) ? env.HOME : homedir()
150
+ const root = xdg && isAbsolute(xdg) ? xdg : join(home, '.config')
151
+ return resolve(root, 'pantheon', 'decision-router.json')
152
+ }
153
+
154
+ /** Migrate invalid or missing user data to a local-only, no-consent config. */
155
+ export function migrateUserDecisionRouterConfig(value) {
156
+ if (!isPlainObject(value)) return cloneDefaultUserConfig()
157
+ if (value.schema_version === 1) return migrateLegacyUserConfig(value)
158
+ if (value.schema_version !== USER_DECISION_ROUTER_CONFIG_SCHEMA_VERSION) {
159
+ return cloneDefaultUserConfig()
160
+ }
161
+ if (
162
+ !hasExactKeys(value, USER_CONFIG_KEYS) ||
163
+ typeof value.egress_consent !== 'boolean' ||
164
+ typeof value.enabled !== 'boolean' ||
165
+ !Array.isArray(value.enabled_candidates)
166
+ ) {
167
+ return cloneDefaultUserConfig()
168
+ }
169
+ const selection = normalizeSelection(value.selection)
170
+ const candidates = normalizeEnabledCandidates(value.enabled_candidates)
171
+ if (selection === null || candidates === null) return cloneDefaultUserConfig()
172
+ return {
173
+ schema_version: USER_DECISION_ROUTER_CONFIG_SCHEMA_VERSION,
174
+ enabled: value.enabled,
175
+ selection,
176
+ egress_consent: selection.mode === 'local' ? false : value.egress_consent,
177
+ enabled_candidates: candidates,
178
+ }
179
+ }
180
+
181
+ /**
182
+ * Schema v1 predated the explicit `enabled` switch. Preserve intent only when
183
+ * the user had selected a provider, consented, and enabled at least one
184
+ * candidate; every other legacy shape migrates to disabled.
185
+ */
186
+ function migrateLegacyUserConfig(value) {
187
+ if (
188
+ !hasExactKeys(value, LEGACY_USER_CONFIG_KEYS) ||
189
+ typeof value.egress_consent !== 'boolean' ||
190
+ !Array.isArray(value.enabled_candidates)
191
+ ) {
192
+ return cloneDefaultUserConfig()
193
+ }
194
+ const selection = normalizeSelection(value.selection)
195
+ const candidates = normalizeEnabledCandidates(value.enabled_candidates)
196
+ if (selection === null || candidates === null) return cloneDefaultUserConfig()
197
+ const egressConsent = selection.mode === 'local' ? false : value.egress_consent
198
+ return {
199
+ schema_version: USER_DECISION_ROUTER_CONFIG_SCHEMA_VERSION,
200
+ enabled: selection.mode !== 'local' && egressConsent && candidates.length > 0,
201
+ selection,
202
+ egress_consent: egressConsent,
203
+ enabled_candidates: candidates,
204
+ }
205
+ }
206
+
207
+ /** Return a validated immutable update, without implying consent or enablement. */
208
+ export function updateUserDecisionRouterConfig(config, update) {
209
+ const current = migrateUserDecisionRouterConfig(config)
210
+ if (!isPlainObject(update)) throw new TypeError('Invalid decision-router update')
211
+ if (
212
+ Object.keys(update).some(
213
+ (key) => !['enabled', 'selection', 'egress_consent', 'enabled_candidates'].includes(key),
214
+ )
215
+ ) {
216
+ throw new TypeError('Unsupported decision-router configuration field')
217
+ }
218
+ if (Object.hasOwn(update, 'selection') && normalizeSelection(update.selection) === null) {
219
+ throw new TypeError('Invalid decision-router selection')
220
+ }
221
+ if (Object.hasOwn(update, 'enabled') && typeof update.enabled !== 'boolean') {
222
+ throw new TypeError('Enabled must be explicitly true or false')
223
+ }
224
+ if (Object.hasOwn(update, 'egress_consent') && typeof update.egress_consent !== 'boolean') {
225
+ throw new TypeError('Egress consent must be explicitly true or false')
226
+ }
227
+ if (
228
+ Object.hasOwn(update, 'enabled_candidates') &&
229
+ normalizeEnabledCandidates(update.enabled_candidates) === null
230
+ ) {
231
+ throw new TypeError('Invalid enabled provider/model candidates')
232
+ }
233
+ const next = { ...current, ...update }
234
+ const normalized = migrateUserDecisionRouterConfig(next)
235
+ if (normalized.selection.mode === 'local' && update.egress_consent === true) {
236
+ throw new TypeError('Local selection cannot enable egress consent')
237
+ }
238
+ return normalized
239
+ }
240
+
241
+ /** True only when the user explicitly enabled turn selection. */
242
+ export function isUserDecisionRouterEnabled(config) {
243
+ return migrateUserDecisionRouterConfig(config).enabled
244
+ }
245
+
246
+ /** Auto resolves only one enabled, cap-valid direct provider/model tuple. */
247
+ export function resolveUserDecisionRouterCandidate(config, capValidCandidates = []) {
248
+ const preference = migrateUserDecisionRouterConfig(config)
249
+ if (!preference.enabled || !preference.egress_consent) return null
250
+ const validKeys = new Set(
251
+ capValidCandidates
252
+ .filter(isKnownCandidate)
253
+ .map(({ provider, model }) => candidateKey(normalizeDecisionProviderId(provider), model)),
254
+ )
255
+ const enabled = preference.enabled_candidates.filter(
256
+ (candidate) =>
257
+ remotelyEligibleProviders.has(candidate.provider) &&
258
+ validKeys.has(candidateKey(candidate.provider, candidate.model)),
259
+ )
260
+ if (preference.selection.mode === 'local') return null
261
+ if (preference.selection.mode === 'explicit') {
262
+ const selected = preference.selection
263
+ return (
264
+ enabled.find(
265
+ (candidate) =>
266
+ candidateKey(candidate.provider, candidate.model) ===
267
+ candidateKey(selected.provider, selected.model),
268
+ ) ?? null
269
+ )
270
+ }
271
+ return enabled.length === 1 ? enabled[0] : null
272
+ }
273
+
274
+ /** Read only a private user-level JSON file. Invalid contents fail closed. */
275
+ export function readUserDecisionRouterConfig({ env = process.env } = {}) {
276
+ const filePath = resolveUserDecisionRouterConfigPath(env)
277
+ try {
278
+ assertNoSymlinkAncestors(filePath)
279
+ assertTrustedDirectoryChain(dirname(filePath))
280
+ const stat = lstatSync(filePath)
281
+ assertPrivatePath(stat, true)
282
+ const parsed = JSON.parse(readFileSync(filePath, 'utf8'))
283
+ return migrateUserDecisionRouterConfig(parsed)
284
+ } catch (error) {
285
+ if (error?.code === 'ENOENT') return cloneDefaultUserConfig()
286
+ throw error
287
+ }
288
+ }
289
+
290
+ /** Persist only non-secret preference data in a user-owned 0600 file. */
291
+ export function writeUserDecisionRouterConfig(config, { env = process.env } = {}) {
292
+ const normalized = migrateUserDecisionRouterConfig(config)
293
+ if (JSON.stringify(normalized) !== JSON.stringify(config)) {
294
+ throw new TypeError('Refusing to persist invalid decision-router configuration')
295
+ }
296
+ const filePath = resolveUserDecisionRouterConfigPath(env)
297
+ const directory = dirname(filePath)
298
+ assertNoSymlinkAncestors(directory, { includeLeaf: false })
299
+ mkdirSync(directory, { recursive: true, mode: 0o700 })
300
+ assertNoSymlinkAncestors(directory)
301
+ assertTrustedDirectoryChain(directory)
302
+ assertPrivateDirectory(directory)
303
+ try {
304
+ const existing = lstatSync(filePath)
305
+ assertPrivatePath(existing, true)
306
+ } catch (error) {
307
+ if (error?.code !== 'ENOENT') throw error
308
+ }
309
+ writeFileAtomically(filePath, `${JSON.stringify(normalized, null, 2)}\n`)
310
+ chmodSync(filePath, 0o600)
311
+ return filePath
312
+ }
313
+
314
+ function normalizeSelection(value) {
315
+ if (!isPlainObject(value) || typeof value.mode !== 'string') return null
316
+ if (value.mode === 'local' || value.mode === 'auto') {
317
+ return Object.keys(value).length === 1 ? { mode: value.mode } : null
318
+ }
319
+ if (
320
+ value.mode !== 'explicit' ||
321
+ Object.keys(value).length !== 3 ||
322
+ !isKnownCandidate({ provider: value.provider, model: value.model })
323
+ ) {
324
+ return null
325
+ }
326
+ return {
327
+ mode: 'explicit',
328
+ provider: normalizeDecisionProviderId(value.provider),
329
+ model: value.model,
330
+ }
331
+ }
332
+
333
+ function normalizeEnabledCandidates(value) {
334
+ const seen = new Set()
335
+ const result = []
336
+ for (const item of value) {
337
+ if (!isKnownCandidate(item) || Object.keys(item).length !== 2) return null
338
+ const provider = normalizeDecisionProviderId(item.provider)
339
+ const key = candidateKey(provider, item.model)
340
+ if (seen.has(key)) return null
341
+ seen.add(key)
342
+ result.push({ provider, model: item.model })
343
+ }
344
+ return result
345
+ }
346
+
347
+ function isKnownCandidate(value) {
348
+ if (
349
+ !isPlainObject(value) ||
350
+ typeof value.provider !== 'string' ||
351
+ typeof value.model !== 'string'
352
+ ) {
353
+ return false
354
+ }
355
+ const provider = normalizeDecisionProviderId(value.provider)
356
+ return (
357
+ userCandidateProviders.has(provider) && DECISION_ROUTER_MODELS[provider].includes(value.model)
358
+ )
359
+ }
360
+
361
+ function candidateKey(provider, model) {
362
+ return `${provider}/${model}`
363
+ }
364
+
365
+ function isPlainObject(value) {
366
+ if (value === null || typeof value !== 'object' || Array.isArray(value)) return false
367
+ const prototype = Object.getPrototypeOf(value)
368
+ return prototype === Object.prototype || prototype === null
369
+ }
370
+
371
+ function hasExactKeys(value, keys) {
372
+ const actual = Object.keys(value).sort()
373
+ const expected = [...keys].sort()
374
+ return actual.length === expected.length && actual.every((key, index) => key === expected[index])
375
+ }
376
+
377
+ function cloneDefaultUserConfig() {
378
+ return {
379
+ schema_version: DEFAULT_USER_DECISION_ROUTER_CONFIG.schema_version,
380
+ enabled: false,
381
+ selection: { mode: 'local' },
382
+ egress_consent: false,
383
+ enabled_candidates: [],
384
+ }
385
+ }
386
+
387
+ function assertPrivatePath(stat, isFile) {
388
+ if (stat.isSymbolicLink() || (isFile ? !stat.isFile() : !stat.isDirectory())) {
389
+ throw new Error('Decision-router configuration path is not a regular private path')
390
+ }
391
+ if (typeof process.getuid !== 'function' || stat.uid !== process.getuid()) {
392
+ throw new Error('Decision-router configuration must be owned by the current user')
393
+ }
394
+ if ((stat.mode & 0o077) !== 0)
395
+ throw new Error('Decision-router configuration permissions must be private')
396
+ }
397
+
398
+ function assertPrivateDirectory(directory) {
399
+ const stat = lstatSync(directory)
400
+ assertPrivatePath(stat, false)
401
+ }
402
+
403
+ function assertTrustedDirectoryChain(directory) {
404
+ const absolute = resolve(directory)
405
+ const root = parse(absolute).root
406
+ const parts = absolute.slice(root.length).split(sep).filter(Boolean)
407
+ let current = root
408
+ const uid = process.getuid?.()
409
+ if (uid === undefined)
410
+ throw new Error('Decision-router configuration requires user ownership checks')
411
+ for (const part of parts) {
412
+ current = join(current, part)
413
+ let stat
414
+ try {
415
+ stat = lstatSync(current)
416
+ } catch (error) {
417
+ if (error?.code === 'ENOENT') return
418
+ throw error
419
+ }
420
+ if (!stat.isDirectory() || stat.isSymbolicLink()) {
421
+ throw new Error('Decision-router configuration path contains a non-directory component')
422
+ }
423
+ if (stat.uid !== uid && stat.uid !== 0) {
424
+ throw new Error('Decision-router configuration path has an untrusted owner')
425
+ }
426
+ const mode = stat.mode & 0o7777
427
+ const rootStickyDirectory = stat.uid === 0 && (mode & 0o1000) !== 0
428
+ if ((mode & 0o022) !== 0 && !rootStickyDirectory) {
429
+ throw new Error('Decision-router configuration path is writable by other users')
430
+ }
431
+ }
432
+ }
@@ -198,27 +198,36 @@ export function healthCheck(target, { dryRun = false, pythonTarget = target } =
198
198
  // repointed: check 5 already asserts the capability that matters, and a
199
199
  // second sqlite3 import probe would tell us nothing new.
200
200
 
201
- // Check 5: SQLite FTS5 available
201
+ // Check 5: prove FTS5 can actually create a virtual table. Compile flags alone
202
+ // are not a capability test, and the memory MCP has no supported fallback.
202
203
  if (python) {
203
204
  const fts5Cmd = [
204
205
  '-c',
205
- 'import sqlite3; ' +
206
- "row = sqlite3.connect(':memory:').execute('PRAGMA compile_options').fetchall(); " +
207
- "fts5 = any('ENABLE_FTS5' in str(r[0]) for r in row); " +
208
- "print(f'SQLite {sqlite3.sqlite_version} FTS5={fts5}')",
206
+ 'import sqlite3, sys\n' +
207
+ "db = sqlite3.connect(':memory:')\n" +
208
+ 'version = sqlite3.sqlite_version\n' +
209
+ 'try:\n' +
210
+ ' db.execute("CREATE VIRTUAL TABLE fts5_probe USING fts5(content)")\n' +
211
+ 'except sqlite3.Error as exc:\n' +
212
+ ' print(f"SQLite {version} FTS5=False: {exc}")\n' +
213
+ ' sys.exit(1)\n' +
214
+ 'print(f"SQLite {version} FTS5=True")',
209
215
  ]
210
216
  const result = spawnSync(python, fts5Cmd, { stdio: 'pipe' })
211
- if (result.status === 0) {
212
- results.passed.push({
213
- check: 'sqlite-fts5',
214
- detail: result.stdout.toString().trim(),
215
- })
217
+ const detail = result.stdout.toString().trim() || result.stderr.toString().trim()
218
+ if (result.status === 0 && /\bFTS5=True\b/.test(detail)) {
219
+ results.passed.push({ check: 'sqlite-fts5', detail })
216
220
  } else {
217
221
  results.failed.push({
218
222
  check: 'sqlite-fts5',
219
- detail: result.stderr.toString().trim().split('\n').slice(-1)[0],
223
+ detail: detail || 'Python could not verify SQLite FTS5 support',
220
224
  })
221
225
  }
226
+ } else {
227
+ results.failed.push({
228
+ check: 'sqlite-fts5',
229
+ detail: 'Python is unavailable for the FTS5 probe',
230
+ })
222
231
  }
223
232
 
224
233
  return results
@@ -1,6 +1,12 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  import * as clack from '@clack/prompts'
4
+ import {
5
+ createDecisionRouterConfig,
6
+ DECISION_ROUTER_PROVIDERS,
7
+ DEFAULT_DECISION_ROUTER_CONFIG,
8
+ migrateDecisionRouterConfig,
9
+ } from './decision-router-config.mjs'
4
10
  import { PROMPT_CANCELED } from './prompt-result.mjs'
5
11
  import { strings } from './strings.mjs'
6
12
 
@@ -48,17 +54,18 @@ export async function promptReview(
48
54
  /**
49
55
  * Collect interactive setup choices before the installer begins any writes.
50
56
  *
51
- * @param {{ components?: string[], defaultComponents?: string[], noMcp?: boolean, prompts?: typeof clack, isTTY?: boolean }} [options]
52
- * @returns {Promise<{ components?: Set<string>, target?: string, confirmed?: boolean, canceled?: boolean, cancelPoint?: string }>}
57
+ * @param {{ components?: string[], defaultComponents?: string[], noMcp?: boolean, prompts?: typeof clack, isTTY?: boolean, getDecisionRouterConfig?: (target: string) => unknown }} [options]
58
+ * @returns {Promise<{ components?: Set<string>, target?: string, decisionRouterConfig?: object, canceled?: boolean, cancelPoint?: string }>}
53
59
  *
54
- * `cancelPoint` names the step the user stopped at (`components`, `target`,
55
- * `confirmation`), so the caller can print one explainable line and persist the
56
- * same stable key in the run record.
60
+ * `cancelPoint` names the setup choice where the user stopped (`components` or
61
+ * `target`), so the caller can print one explainable line and persist the same
62
+ * stable key in the run record.
57
63
  */
58
64
  export async function runInteractiveInstall({
59
65
  components = [],
60
66
  defaultComponents = [],
61
67
  noMcp = false,
68
+ getDecisionRouterConfig = () => DEFAULT_DECISION_ROUTER_CONFIG,
62
69
  prompts = clack,
63
70
  isTTY = isTerminal(),
64
71
  } = {}) {
@@ -66,9 +73,18 @@ export async function runInteractiveInstall({
66
73
  const defaults = (defaultComponents.length > 0 ? defaultComponents : components).filter(isAllowed)
67
74
  const defaultSet = new Set(defaults)
68
75
 
69
- // Preserve the prior no-TTY fallback (defaults, global target, and no apply
70
- // authorization) without asking a terminal prompt library to access stdin.
71
- if (!isTTY) return { components: defaultSet, target: 'global', confirmed: true }
76
+ // Preserve the same component and target defaults without asking a terminal
77
+ // prompt library to access stdin. Apply authorization is handled once, after
78
+ // the installer has built and displayed the complete plan. Re-read the
79
+ // selected default target's preference so --interactive without a TTY does
80
+ // not reset an existing provider choice or consent on update.
81
+ if (!isTTY) {
82
+ return {
83
+ components: defaultSet,
84
+ target: 'global',
85
+ decisionRouterConfig: migrateDecisionRouterConfig(getDecisionRouterConfig('global')),
86
+ }
87
+ }
72
88
 
73
89
  prompts.intro?.('OpenCode Installer')
74
90
 
@@ -110,13 +126,61 @@ export async function runInteractiveInstall({
110
126
  })
111
127
  if (cancelPrompt(prompts, target, 'target')) return { canceled: true, cancelPoint: 'target' }
112
128
 
113
- const confirmed = await prompts.confirm({
114
- message: `Install ${selectedComponents.size} component(s) in ${target === 'global' ? 'global config' : 'current project'}?`,
115
- initialValue: true,
129
+ const previousConfig = migrateDecisionRouterConfig(getDecisionRouterConfig(target))
130
+ const provider = await prompts.select({
131
+ message:
132
+ 'Decision-router installer preference (default: Local). This records target-specific metadata only; runtime provider/model settings, egress consent, caps, and period confirmation are managed separately with `npx pantheon-opencode decision-router ...`. Installation makes no provider requests.',
133
+ options: [
134
+ {
135
+ label: 'Local',
136
+ value: DECISION_ROUTER_PROVIDERS[0],
137
+ hint: 'Local recommendation logic; no task data is sent to a provider',
138
+ },
139
+ {
140
+ label: 'OpenAI Decisions',
141
+ value: DECISION_ROUTER_PROVIDERS[1],
142
+ hint: 'GPT-6 Luna installer metadata only; set runtime config separately',
143
+ },
144
+ {
145
+ label: 'Jev',
146
+ value: DECISION_ROUTER_PROVIDERS[2],
147
+ hint: 'TypeSafe Jev installer metadata only; set runtime config separately',
148
+ },
149
+ {
150
+ label: 'Auto',
151
+ value: DECISION_ROUTER_PROVIDERS[3],
152
+ hint: 'Installer metadata only; runtime Auto requires one cap-valid enabled candidate',
153
+ },
154
+ ],
155
+ initialValue: previousConfig.provider,
116
156
  })
117
- if (cancelPrompt(prompts, confirmed, 'confirmation')) {
118
- return { canceled: true, cancelPoint: 'confirmation' }
157
+ if (cancelPrompt(prompts, provider, 'decisionRouter')) {
158
+ return { canceled: true, cancelPoint: 'decisionRouter' }
119
159
  }
120
160
 
121
- return { components: selectedComponents, target, confirmed }
161
+ let egressConsent = false
162
+ if (provider !== 'local') {
163
+ const providerLabel =
164
+ provider === 'openai-decisions'
165
+ ? 'OpenAI Decisions'
166
+ : provider === 'jev'
167
+ ? 'Jev'
168
+ : 'the Auto-selected provider'
169
+ const consent = await prompts.confirm({
170
+ message:
171
+ `Save a legacy installer consent preference for potential future ${providerLabel} use? ` +
172
+ 'This is not runtime consent and does not authorize provider transmission. Configure actual user-level consent and caps with `npx pantheon-opencode decision-router ...`. Installation makes no provider requests.',
173
+ initialValue: previousConfig.provider === provider && previousConfig.egress_consent,
174
+ })
175
+ if (cancelPrompt(prompts, consent, 'egressConsent')) {
176
+ return { canceled: true, cancelPoint: 'egressConsent' }
177
+ }
178
+ egressConsent = consent === true
179
+ }
180
+
181
+ return {
182
+ components: selectedComponents,
183
+ target,
184
+ decisionRouterConfig: createDecisionRouterConfig(provider, egressConsent),
185
+ }
122
186
  }
@@ -33,7 +33,7 @@
33
33
  * Build and REGISTER a SIGINT handler.
34
34
  *
35
35
  * @param {{
36
- * message: string,
36
+ * message: string | (() => string),
37
37
  * json?: boolean,
38
38
  * onInterrupt?: () => void,
39
39
  * endGaugeLine?: () => void,
@@ -62,8 +62,9 @@ export function createInterruptHandler({
62
62
  // The progress gauge owns the current terminal line; close it so the
63
63
  // message is not appended to a half-drawn bar and then erased.
64
64
  endGaugeLine()
65
- if (json) writeStderr(message)
66
- else logStderr(message)
65
+ const line = typeof message === 'function' ? message() : message
66
+ if (json) writeStderr(line)
67
+ else logStderr(line)
67
68
  onInterrupt()
68
69
  } finally {
69
70
  exit(130)