pantheon-opencode 1.6.2-beta.3 → 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.
- package/CHANGELOG.md +34 -0
- package/README.md +38 -1
- package/bin/pantheon-init.mjs +17 -0
- package/package.json +9 -3
- package/plugin.json +1 -1
- package/pyproject.toml +1 -1
- package/scripts/decision-router-budget.mjs +781 -0
- package/scripts/decision-router.mjs +297 -0
- package/scripts/install/decision-router-config.mjs +432 -0
- package/scripts/install/interactive.mjs +76 -5
- package/scripts/install/opencode.mjs +12 -0
- package/scripts/install/state.mjs +5 -0
- package/scripts/install/strings.mjs +4 -0
- package/src/agents/zeus.md +12 -0
- package/src/pantheon/local-decision-agents.ts +170 -0
- package/src/pantheon/local-decision-budget.ts +1043 -0
- package/src/pantheon/local-decision-egress-gate.ts +264 -0
- package/src/pantheon/local-decision-prompt.ts +123 -0
- package/src/pantheon/local-decision-provider-matrix.ts +92 -0
- package/src/pantheon/local-decision-provider-protocol.ts +335 -0
- package/src/pantheon/local-decision-provider.internal.ts +260 -0
- package/src/pantheon/local-decision-router.ts +225 -0
- package/src/pantheon/local-decision-skills.ts +171 -0
- package/src/pantheon/local-decision-tool.ts +126 -0
- package/src/pantheon/local-decision-turn.ts +338 -0
- package/src/pantheon/local-decision-usage-evidence.internal.ts +207 -0
- package/src/pantheon/local-orchestration.ts +322 -0
- package/src/pantheon/pantheon-decision-catalog.ts +101 -0
- package/src/pantheon/v2-tools.ts +15 -14
- package/src/plugin-v2.ts +52 -19
- package/src/plugin.ts +4 -0
- package/src/plugins/tui/dist/tui-v2.js +3 -3
- package/src/plugins/tui/dist/tui.js +1 -1
- package/src/plugins/tui/package-lock.json +2 -2
- 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
|
+
}
|
|
@@ -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,8 +54,8 @@ 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, 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
60
|
* `cancelPoint` names the setup choice where the user stopped (`components` or
|
|
55
61
|
* `target`), so the caller can print one explainable line and persist the same
|
|
@@ -59,6 +65,7 @@ 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
|
} = {}) {
|
|
@@ -68,8 +75,16 @@ export async function runInteractiveInstall({
|
|
|
68
75
|
|
|
69
76
|
// Preserve the same component and target defaults without asking a terminal
|
|
70
77
|
// prompt library to access stdin. Apply authorization is handled once, after
|
|
71
|
-
// the installer has built and displayed the complete plan.
|
|
72
|
-
|
|
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
|
+
}
|
|
73
88
|
|
|
74
89
|
prompts.intro?.('OpenCode Installer')
|
|
75
90
|
|
|
@@ -111,5 +126,61 @@ export async function runInteractiveInstall({
|
|
|
111
126
|
})
|
|
112
127
|
if (cancelPrompt(prompts, target, 'target')) return { canceled: true, cancelPoint: 'target' }
|
|
113
128
|
|
|
114
|
-
|
|
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,
|
|
156
|
+
})
|
|
157
|
+
if (cancelPrompt(prompts, provider, 'decisionRouter')) {
|
|
158
|
+
return { canceled: true, cancelPoint: 'decisionRouter' }
|
|
159
|
+
}
|
|
160
|
+
|
|
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
|
+
}
|
|
115
186
|
}
|
|
@@ -50,6 +50,7 @@ import {
|
|
|
50
50
|
validateMcpV1toV2Source,
|
|
51
51
|
} from './config-migration.mjs'
|
|
52
52
|
import { resolveGlobalConfigDirectory } from './config-paths.mjs'
|
|
53
|
+
import { migrateDecisionRouterConfig } from './decision-router-config.mjs'
|
|
53
54
|
import { componentForInstalledPath, updateFileInventory } from './file-inventory.mjs'
|
|
54
55
|
import { healthCheck } from './health-check.mjs'
|
|
55
56
|
import {
|
|
@@ -1640,6 +1641,9 @@ async function installPass(
|
|
|
1640
1641
|
const componentSet = new Set(
|
|
1641
1642
|
opts.noMcp ? components.filter((component) => component !== 'runtime') : components,
|
|
1642
1643
|
)
|
|
1644
|
+
let decisionRouterConfig = migrateDecisionRouterConfig(
|
|
1645
|
+
opts.decisionRouterConfig ?? readState(target)?.decision_router,
|
|
1646
|
+
)
|
|
1643
1647
|
const stats = summary.opencode
|
|
1644
1648
|
// Per-call baseline. `stats` is the module-level cumulative summary, so the
|
|
1645
1649
|
// consistency guard must compare against THIS call's delta, not the total.
|
|
@@ -1789,6 +1793,10 @@ async function installPass(
|
|
|
1789
1793
|
components: promptComponents,
|
|
1790
1794
|
defaultComponents: promptDefaults,
|
|
1791
1795
|
noMcp: opts.noMcp === true,
|
|
1796
|
+
getDecisionRouterConfig: (selection) => {
|
|
1797
|
+
const selectionTarget = selection === 'project' ? process.cwd() : target
|
|
1798
|
+
return readState(selectionTarget)?.decision_router
|
|
1799
|
+
},
|
|
1792
1800
|
prompts: opts.deps?.prompts,
|
|
1793
1801
|
isTTY: opts.deps?.isTTY,
|
|
1794
1802
|
})
|
|
@@ -1824,6 +1832,8 @@ async function installPass(
|
|
|
1824
1832
|
for (const c of newComponents) componentSet.add(c)
|
|
1825
1833
|
|
|
1826
1834
|
target = selectedTarget
|
|
1835
|
+
decisionRouterConfig = migrateDecisionRouterConfig(result.decisionRouterConfig)
|
|
1836
|
+
opts.decisionRouterConfig = decisionRouterConfig
|
|
1827
1837
|
if (!dryRun && _lastRun) _lastRun.target = target
|
|
1828
1838
|
}
|
|
1829
1839
|
|
|
@@ -3171,6 +3181,7 @@ async function installPass(
|
|
|
3171
3181
|
const packageVersion = JSON.parse(readFileSync(join(ROOT, 'package.json'), 'utf8')).version
|
|
3172
3182
|
let state = projectedState ?? readState(target)
|
|
3173
3183
|
if (!state) state = createInitialState(packageVersion, planTimestamp)
|
|
3184
|
+
state.decision_router = decisionRouterConfig
|
|
3174
3185
|
state.pantheon_version = packageVersion
|
|
3175
3186
|
state.updated_at = planTimestamp
|
|
3176
3187
|
state.schema_version = 2
|
|
@@ -3319,6 +3330,7 @@ async function installPass(
|
|
|
3319
3330
|
throw new Error('Installation state exists but cannot be read; refusing to replace it')
|
|
3320
3331
|
}
|
|
3321
3332
|
state ??= createInitialState(packageVersion, planTimestamp)
|
|
3333
|
+
state.decision_router = decisionRouterConfig
|
|
3322
3334
|
state.pantheon_version = packageVersion
|
|
3323
3335
|
state.updated_at = planTimestamp
|
|
3324
3336
|
for (const component of ['agents', 'skills', 'plugins', 'runtime']) {
|
|
@@ -31,6 +31,7 @@
|
|
|
31
31
|
|
|
32
32
|
import { existsSync, mkdirSync, readFileSync } from 'node:fs'
|
|
33
33
|
import { join, resolve } from 'node:path'
|
|
34
|
+
import { migrateDecisionRouterConfig } from './decision-router-config.mjs'
|
|
34
35
|
import { assertNoSymlinkAncestors, writeFileAtomically } from './verify.mjs'
|
|
35
36
|
|
|
36
37
|
const STATE_FILE = 'install-state.json'
|
|
@@ -82,6 +83,7 @@ export function createInitialState(version, updatedAt = new Date().toISOString()
|
|
|
82
83
|
plugins: { version: 1, status: 'pending' },
|
|
83
84
|
runtime: { version: 1, status: 'pending' },
|
|
84
85
|
},
|
|
86
|
+
decision_router: migrateDecisionRouterConfig(undefined),
|
|
85
87
|
file_inventory: emptyFileInventory(false),
|
|
86
88
|
}
|
|
87
89
|
}
|
|
@@ -139,6 +141,7 @@ export function upgradeStateV1toV2(state) {
|
|
|
139
141
|
plugins: { version: 1, status: 'unknown' },
|
|
140
142
|
runtime: { version: 1, status: 'unknown' },
|
|
141
143
|
},
|
|
144
|
+
decision_router: migrateDecisionRouterConfig(state.decision_router),
|
|
142
145
|
file_inventory: normalizeFileInventory(state),
|
|
143
146
|
}
|
|
144
147
|
}
|
|
@@ -174,6 +177,7 @@ function ensureV2Shape(state) {
|
|
|
174
177
|
) {
|
|
175
178
|
state.file_inventory = invalidFileInventory()
|
|
176
179
|
}
|
|
180
|
+
state.decision_router = migrateDecisionRouterConfig(state.decision_router)
|
|
177
181
|
return state
|
|
178
182
|
}
|
|
179
183
|
|
|
@@ -206,6 +210,7 @@ export function writeState(target, state, options = {}) {
|
|
|
206
210
|
state.schema_version = 2
|
|
207
211
|
if (!Object.hasOwn(state, 'migration_schema_version')) state.migration_schema_version = null
|
|
208
212
|
if (!Array.isArray(state.applied_migrations)) state.applied_migrations = []
|
|
213
|
+
state.decision_router = migrateDecisionRouterConfig(state.decision_router)
|
|
209
214
|
if (!Object.hasOwn(state, 'file_inventory')) {
|
|
210
215
|
state.file_inventory = emptyFileInventory(true)
|
|
211
216
|
} else if (
|
|
@@ -21,6 +21,8 @@ const TABLE = {
|
|
|
21
21
|
cancelPoints: {
|
|
22
22
|
components: 'component selection',
|
|
23
23
|
target: 'install location',
|
|
24
|
+
decisionRouter: 'decision router selection',
|
|
25
|
+
egressConsent: 'external data-sharing consent',
|
|
24
26
|
confirmation: 'pre-install confirmation',
|
|
25
27
|
review: 'review prompt',
|
|
26
28
|
interrupt: 'interrupt (Ctrl-C)',
|
|
@@ -114,6 +116,8 @@ const TABLE = {
|
|
|
114
116
|
cancelPoints: {
|
|
115
117
|
components: 'seleção de componentes',
|
|
116
118
|
target: 'local da instalação',
|
|
119
|
+
decisionRouter: 'seleção do roteador decisório',
|
|
120
|
+
egressConsent: 'consentimento de compartilhamento externo',
|
|
117
121
|
confirmation: 'confirmação antes de instalar',
|
|
118
122
|
review: 'prompt de revisão',
|
|
119
123
|
interrupt: 'interrupção (Ctrl-C)',
|
package/src/agents/zeus.md
CHANGED
|
@@ -36,6 +36,18 @@ skills:
|
|
|
36
36
|
|
|
37
37
|
**Coordenador APENAS. Zeus NUNCA lê arquivos de código-fonte.** Toda leitura de `src/`, `tests/`, `scripts/` vai para @apollo. Leia apenas: config, docs, memory bank, delegação.
|
|
38
38
|
|
|
39
|
+
## Local advisory routing before native delegation
|
|
40
|
+
|
|
41
|
+
- For an obvious, bounded task with one clear specialist, dispatch directly with the native `subagent` tool. Do not call `pantheon_local_decision`, Jev, council, or Athena planning just to confirm an obvious route.
|
|
42
|
+
- For a genuinely ambiguous specialist choice, use `pantheon_local_decision` only if it is present. It evaluates locally only; provider transport/API has been removed, and provider configuration, consent, caps, or period confirmation do not enable runtime calls. If absent, unconfigured, or it abstains, continue with your own routing judgment and the host's actual native tool schema.
|
|
43
|
+
- Build `candidateAgents` only from targets currently shown as available by native `subagent` and allowed by current routing/grants. Do not invent candidates. Supply only relevant available skill IDs and resource IDs; `domain` is one exact candidate ID only when the domain mapping is clear, otherwise null. Pass no task text, transcript, file contents, memory contents, credentials, or secrets.
|
|
44
|
+
- Treat the returned agent/skill/resource IDs and memory boolean as recommendations, not authorization. Re-check the candidate against current routing, grants, and availability before dispatch. Preserve all fixed review, human-approval, data-integrity, and security gates regardless of complexity or recommendation.
|
|
45
|
+
- If `recommendMemorySearch` is true and prior project history could change the outcome, Zeus may make one selective local `pantheon-memory` search. Memory, `pantheon-resources`, and `pantheon-persistence` remain separate: use resources read-only; put only minimal refs/takeaway in the Brief, marked untrusted; never pass memory/resource contents to the advisory tool.
|
|
46
|
+
- Construct the final Brief locally and use native `subagent` unchanged; native dispatch is always the final routing action. The local recommendation tool never dispatches, loads skills/resources, searches memory, or changes grants/gates. No remote Jev or OpenAI Decisions runtime calls are available, regardless of user control settings.
|
|
47
|
+
This local-only guarantee applies only to decision routing, not all product egress.
|
|
48
|
+
Separately documented quota (including manual `/quota-go-check`) and Vision
|
|
49
|
+
integrations retain their own external-request behavior.
|
|
50
|
+
|
|
39
51
|
## Visual Context for Implementation
|
|
40
52
|
|
|
41
53
|
Zeus never implements code, but visual references from the user are implementation context and must reach the specialist who does the work.
|