pantheon-opencode 1.6.2-beta.3 → 1.6.2-beta.5
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 +42 -0
- package/README.md +209 -1
- package/bin/pantheon-init.mjs +22 -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-v2-budget.mjs +218 -0
- package/scripts/decision-router-v2-egress.mjs +272 -0
- package/scripts/decision-router.mjs +519 -0
- package/scripts/docs-check-changelog.mjs +5 -3
- package/scripts/install/decision-layer-preview.mjs +376 -0
- package/scripts/install/decision-router-config.mjs +579 -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/scripts/mcp_resources.py +11 -9
- package/scripts/release-notes.mjs +30 -7
- package/scripts/versioning.mjs +41 -5
- package/src/agents/zeus.md +12 -0
- package/src/mcp/eval_store.py +11 -4
- package/src/mcp/mcp_resources.py +11 -9
- package/src/mcp/memory_mcp.py +293 -150
- 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 +268 -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 +281 -0
- package/src/pantheon/local-decision-tool.ts +160 -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-decision-budget.ts +456 -0
- package/src/pantheon/v2-decision-contracts.ts +300 -0
- package/src/pantheon/v2-decision-egress.ts +203 -0
- package/src/pantheon/v2-decision-events.ts +180 -0
- package/src/pantheon/v2-decision-heuristic.ts +121 -0
- package/src/pantheon/v2-decision-points/p1-agent.ts +91 -0
- package/src/pantheon/v2-decision-points/p10-claims.ts +243 -0
- package/src/pantheon/v2-decision-points/p11-catalog.ts +220 -0
- package/src/pantheon/v2-decision-points/p2-skill.ts +83 -0
- package/src/pantheon/v2-decision-points/p3-complexity.ts +108 -0
- package/src/pantheon/v2-decision-points/p4-memory.ts +137 -0
- package/src/pantheon/v2-decision-points/p5-themis-verify.ts +190 -0
- package/src/pantheon/v2-decision-points/p6-council.ts +161 -0
- package/src/pantheon/v2-decision-points/p7-loop.ts +263 -0
- package/src/pantheon/v2-decision-points/p8-guardrail.ts +366 -0
- package/src/pantheon/v2-decision-points/p9-memory-compaction.ts +304 -0
- package/src/pantheon/v2-decision-points.ts +242 -0
- package/src/pantheon/v2-decision-policy.ts +166 -0
- package/src/pantheon/v2-decision-premises.ts +146 -0
- package/src/pantheon/v2-decision-prompt-surface.ts +115 -0
- package/src/pantheon/v2-decision-rank.ts +91 -0
- package/src/pantheon/v2-decision-registry.ts +391 -0
- package/src/pantheon/v2-decision-resource-ids.ts +127 -0
- package/src/pantheon/v2-decision-shadow.ts +123 -0
- package/src/pantheon/v2-decision-telemetry.ts +214 -0
- package/src/pantheon/v2-decision-verify.ts +51 -0
- package/src/pantheon/v2-tools.ts +35 -15
- package/src/plugin-v2.ts +357 -22
- 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,519 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { existsSync } from 'node:fs'
|
|
3
|
+
import { pathToFileURL } from 'node:url'
|
|
4
|
+
// Prebuilt bundles: Node refuses to strip TypeScript types under node_modules,
|
|
5
|
+
// so the published CLI cannot import the TypeScript sources directly. Regenerate
|
|
6
|
+
// with `npm run build:decision-router`; `--check` guards against drift.
|
|
7
|
+
import {
|
|
8
|
+
openLocalDecisionBudgetLedger,
|
|
9
|
+
resolveLocalDecisionBudgetDbPath,
|
|
10
|
+
} from './decision-router-budget.mjs'
|
|
11
|
+
import {
|
|
12
|
+
evaluateCapGate,
|
|
13
|
+
evaluatePeriodGate,
|
|
14
|
+
inspectDecisionBudget,
|
|
15
|
+
listDecisionHoldsReadOnly,
|
|
16
|
+
utcPeriodOf,
|
|
17
|
+
} from './decision-router-v2-budget.mjs'
|
|
18
|
+
import {
|
|
19
|
+
resolveV2DecisionEgress,
|
|
20
|
+
V2_DECISION_EGRESS_DEFAULT,
|
|
21
|
+
V2_DECISION_EGRESS_TRANSPORT,
|
|
22
|
+
} from './decision-router-v2-egress.mjs'
|
|
23
|
+
import {
|
|
24
|
+
applyDecisionLayerPlan,
|
|
25
|
+
buildDecisionLayerPlan,
|
|
26
|
+
formatDecisionLayerPlan,
|
|
27
|
+
resolveInstallStatePath,
|
|
28
|
+
toDecisionLayerPlanJson,
|
|
29
|
+
} from './install/decision-layer-preview.mjs'
|
|
30
|
+
import {
|
|
31
|
+
DECISION_PROVIDER_BUDGET_MAPPING,
|
|
32
|
+
DECISION_ROUTER_MODELS,
|
|
33
|
+
diffDecisionRouterSurfaces,
|
|
34
|
+
readUserDecisionRouterConfig,
|
|
35
|
+
resolveUserDecisionRouterConfigPath,
|
|
36
|
+
updateUserDecisionRouterConfig,
|
|
37
|
+
writeUserDecisionRouterConfig,
|
|
38
|
+
} from './install/decision-router-config.mjs'
|
|
39
|
+
import { readState } from './install/state.mjs'
|
|
40
|
+
|
|
41
|
+
const BUDGET_PROVIDERS = DECISION_PROVIDER_BUDGET_MAPPING
|
|
42
|
+
|
|
43
|
+
const USAGE =
|
|
44
|
+
'Usage: decision-router help|status|setup|preview|select|enable|disable|consent|caps|period|holds'
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Malformed command line (wrong flags, unknown provider, invalid value).
|
|
48
|
+
* Callers report it as a short message; a stack implies a bug, not bad input.
|
|
49
|
+
*/
|
|
50
|
+
export class DecisionRouterUsageError extends TypeError {
|
|
51
|
+
name = 'DecisionRouterUsageError'
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** Read-only command help. Touches no file, ledger or environment path. */
|
|
55
|
+
export function decisionRouterHelp() {
|
|
56
|
+
return [
|
|
57
|
+
USAGE,
|
|
58
|
+
'',
|
|
59
|
+
'Read-only (never create, migrate or write anything):',
|
|
60
|
+
' help this text',
|
|
61
|
+
' status [--target <dir>] configuration, egress posture and budget facts',
|
|
62
|
+
' setup [options] computed artifact diff; writes only with --apply',
|
|
63
|
+
' preview alias of `setup` (never writes)',
|
|
64
|
+
' holds unresolved reservations, read-only',
|
|
65
|
+
'',
|
|
66
|
+
'Explicit actions (each one changes exactly one thing):',
|
|
67
|
+
' select local|auto|<provider>/<model> record a selection; enables nothing',
|
|
68
|
+
' enable | disable turn selection on or off',
|
|
69
|
+
' enable <provider> <model> toggle one candidate',
|
|
70
|
+
' consent yes|no record egress consent',
|
|
71
|
+
' caps user|provider <p>|model <p> <m> --monthly-usd N --per-decision-usd N',
|
|
72
|
+
' period confirm --current none|YYYY-MM --next YYYY-MM',
|
|
73
|
+
'',
|
|
74
|
+
'setup options:',
|
|
75
|
+
' --apply write the previewed artifacts (otherwise nothing is written)',
|
|
76
|
+
' --json machine-readable plan',
|
|
77
|
+
' --target <dir> also reconcile <dir>/.pantheon/install-state.json when present',
|
|
78
|
+
' --selection <value> same values as `select`',
|
|
79
|
+
' --accept-migration allow a schema migration that would enable turn selection',
|
|
80
|
+
'',
|
|
81
|
+
`Egress default: ${V2_DECISION_EGRESS_DEFAULT}. Enablement, consent, one cap- and period-eligible`,
|
|
82
|
+
'candidate and the host permission gate are all required; any missing item means zero requests.',
|
|
83
|
+
`Provider endpoints are retained ${V2_DECISION_EGRESS_TRANSPORT.wireStatus} (UNWIRED) here; this`,
|
|
84
|
+
'interface adds no transport and never claims the transport was removed.',
|
|
85
|
+
].join('\n')
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** Run an explicit, non-secret administrative command for the user-level router config. */
|
|
89
|
+
export async function runDecisionRouterCommand(
|
|
90
|
+
args,
|
|
91
|
+
{ env = process.env, stdout = console.log } = {},
|
|
92
|
+
) {
|
|
93
|
+
const [command, ...rest] = args
|
|
94
|
+
|
|
95
|
+
if (command === 'help' || command === '--help' || command === '-h') {
|
|
96
|
+
if (rest.length > 0) throw new DecisionRouterUsageError(USAGE)
|
|
97
|
+
stdout(decisionRouterHelp())
|
|
98
|
+
return
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (command === 'status') {
|
|
102
|
+
const options = parseNamedFlags(rest, ['--target'])
|
|
103
|
+
const config = readUserDecisionRouterConfig({ env })
|
|
104
|
+
const dbPath = resolveLocalDecisionBudgetDbPath(env)
|
|
105
|
+
const inspection = inspectDecisionBudget(dbPath)
|
|
106
|
+
const wallPeriod = utcPeriodOf(Date.now())
|
|
107
|
+
const egress = describeEgress(config, inspection, wallPeriod)
|
|
108
|
+
|
|
109
|
+
stdout(`Config: ${resolveUserDecisionRouterConfigPath(env)}`)
|
|
110
|
+
stdout(
|
|
111
|
+
`Config file: ${existsSync(resolveUserDecisionRouterConfigPath(env)) ? 'present' : 'absent'}`,
|
|
112
|
+
)
|
|
113
|
+
stdout(`Enabled: ${config.enabled ? 'yes' : 'no'}`)
|
|
114
|
+
stdout(`Selection: ${formatSelection(config.selection)}`)
|
|
115
|
+
stdout(`Egress consent: ${config.egress_consent ? 'yes' : 'no'}`)
|
|
116
|
+
stdout(
|
|
117
|
+
`Enabled candidates: ${config.enabled_candidates.length ? config.enabled_candidates.map(formatCandidate).join(', ') : 'none'}`,
|
|
118
|
+
)
|
|
119
|
+
stdout(describeEgressLine(egress))
|
|
120
|
+
stdout(`Ledger: ${formatLedger(inspection, dbPath)}`)
|
|
121
|
+
stdout(`Budget period: ${formatPeriod(inspection)}`)
|
|
122
|
+
stdout(`Caps: ${formatCaps(inspection)}`)
|
|
123
|
+
if (options['--target'] !== undefined) {
|
|
124
|
+
stdout(`Install-state: ${formatInstallState(config, options['--target'])}`)
|
|
125
|
+
}
|
|
126
|
+
stdout('Mode: read-only — status and help never create, migrate or write anything.')
|
|
127
|
+
return
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
if (command === 'setup' || command === 'preview') {
|
|
131
|
+
const options = parseSetupOptions(rest, command === 'preview')
|
|
132
|
+
const plan = buildDecisionLayerPlan({
|
|
133
|
+
env,
|
|
134
|
+
...(options['--target'] === undefined ? {} : { target: options['--target'] }),
|
|
135
|
+
...(options['--selection'] === undefined
|
|
136
|
+
? {}
|
|
137
|
+
: { selection: parseSelectionTarget(options['--selection']) }),
|
|
138
|
+
acceptMigration: options['--accept-migration'] === true,
|
|
139
|
+
})
|
|
140
|
+
if (options['--json'] === true) {
|
|
141
|
+
stdout(JSON.stringify(toDecisionLayerPlanJson(plan), null, 2))
|
|
142
|
+
} else {
|
|
143
|
+
stdout(
|
|
144
|
+
formatDecisionLayerPlan(plan, {
|
|
145
|
+
scope: options['--target'] ?? 'user',
|
|
146
|
+
applyPending: options['--apply'] === true,
|
|
147
|
+
}),
|
|
148
|
+
)
|
|
149
|
+
}
|
|
150
|
+
if (options['--apply'] === true) {
|
|
151
|
+
const result = applyDecisionLayerPlan(plan, { env })
|
|
152
|
+
stdout(
|
|
153
|
+
`Applied: ${result.written.length} written, ${result.skipped.length} unchanged. ` +
|
|
154
|
+
'No backup copy was created.',
|
|
155
|
+
)
|
|
156
|
+
}
|
|
157
|
+
return
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
if (command === 'select') {
|
|
161
|
+
const target = rest[0]
|
|
162
|
+
if (rest.length !== 1 || typeof target !== 'string')
|
|
163
|
+
throw new DecisionRouterUsageError('Usage: decision-router select local|auto|provider/model')
|
|
164
|
+
const selection = parseSelectionTarget(target)
|
|
165
|
+
const before = readUserDecisionRouterConfig({ env })
|
|
166
|
+
saveConfig(env, { selection })
|
|
167
|
+
const after = readUserDecisionRouterConfig({ env })
|
|
168
|
+
const revoked = before.egress_consent && !after.egress_consent
|
|
169
|
+
stdout(
|
|
170
|
+
`Selection saved: ${formatSelection(selection)}. ${
|
|
171
|
+
revoked
|
|
172
|
+
? 'Egress consent was revoked because the target changed; nothing was enabled.'
|
|
173
|
+
: 'Enablement, consent, caps and period are unchanged.'
|
|
174
|
+
}`,
|
|
175
|
+
)
|
|
176
|
+
return
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
if (command === 'enable' || command === 'disable') {
|
|
180
|
+
const [provider, model, ...extra] = rest
|
|
181
|
+
if (extra.length) {
|
|
182
|
+
throw new DecisionRouterUsageError(`Usage: decision-router ${command} [<provider> <model>]`)
|
|
183
|
+
}
|
|
184
|
+
if (provider === undefined && model === undefined) {
|
|
185
|
+
saveConfig(env, { enabled: command === 'enable' })
|
|
186
|
+
stdout(
|
|
187
|
+
`Turn selection ${command === 'enable' ? 'enabled' : 'disabled'}. Provider consent and candidate enablement are unchanged.`,
|
|
188
|
+
)
|
|
189
|
+
return
|
|
190
|
+
}
|
|
191
|
+
if (provider === undefined || !isKnownCandidate(provider, model)) {
|
|
192
|
+
throw new DecisionRouterUsageError(`Usage: decision-router ${command} <provider> <model>`)
|
|
193
|
+
}
|
|
194
|
+
const config = readUserDecisionRouterConfig({ env })
|
|
195
|
+
const key = candidateKey(provider, model)
|
|
196
|
+
const candidates = config.enabled_candidates.filter(
|
|
197
|
+
(candidate) => candidateKey(candidate.provider, candidate.model) !== key,
|
|
198
|
+
)
|
|
199
|
+
if (command === 'enable') candidates.push({ provider, model })
|
|
200
|
+
saveConfig(env, { enabled_candidates: candidates })
|
|
201
|
+
stdout(`${command === 'enable' ? 'Enabled' : 'Disabled'} ${provider}/${model}.`)
|
|
202
|
+
return
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
if (command === 'consent') {
|
|
206
|
+
const value = rest[0]
|
|
207
|
+
if (rest.length !== 1 || (value !== 'yes' && value !== 'no')) {
|
|
208
|
+
throw new DecisionRouterUsageError('Usage: decision-router consent yes|no')
|
|
209
|
+
}
|
|
210
|
+
saveConfig(env, { egress_consent: value === 'yes' })
|
|
211
|
+
stdout(`Egress consent saved: ${value}.`)
|
|
212
|
+
return
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
if (command === 'caps') {
|
|
216
|
+
const [scope, ...scopeArgs] = rest
|
|
217
|
+
const { monthly, perDecision, rest: targetArgs } = parseCaps(scopeArgs)
|
|
218
|
+
const ledger = openLedger(env)
|
|
219
|
+
try {
|
|
220
|
+
if (scope === 'user' && targetArgs.length === 0) {
|
|
221
|
+
ledger.configureUserCaps({ monthlyCapMicros: monthly, perDecisionCapMicros: perDecision })
|
|
222
|
+
} else if (scope === 'provider' && targetArgs.length === 1) {
|
|
223
|
+
const budgetProvider = Object.hasOwn(BUDGET_PROVIDERS, targetArgs[0])
|
|
224
|
+
? BUDGET_PROVIDERS[targetArgs[0]]
|
|
225
|
+
: undefined
|
|
226
|
+
if (!budgetProvider) throw new DecisionRouterUsageError('Unsupported budget provider')
|
|
227
|
+
ledger.configureProviderCaps(budgetProvider, {
|
|
228
|
+
monthlyCapMicros: monthly,
|
|
229
|
+
perDecisionCapMicros: perDecision,
|
|
230
|
+
})
|
|
231
|
+
} else if (scope === 'model' && targetArgs.length === 2) {
|
|
232
|
+
const [provider, model] = targetArgs
|
|
233
|
+
if (!isKnownCandidate(provider, model))
|
|
234
|
+
throw new DecisionRouterUsageError('Unsupported provider/model pair')
|
|
235
|
+
ledger.configureModelCaps(BUDGET_PROVIDERS[provider], model, {
|
|
236
|
+
monthlyCapMicros: monthly,
|
|
237
|
+
perDecisionCapMicros: perDecision,
|
|
238
|
+
})
|
|
239
|
+
} else {
|
|
240
|
+
throw new DecisionRouterUsageError(
|
|
241
|
+
'Usage: decision-router caps user|provider <provider>|model <provider> <model> --monthly-usd N --per-decision-usd N',
|
|
242
|
+
)
|
|
243
|
+
}
|
|
244
|
+
} finally {
|
|
245
|
+
ledger.close()
|
|
246
|
+
}
|
|
247
|
+
stdout(
|
|
248
|
+
`Configured ${scope} admission caps. Caps limit local admission; they are not invoice guarantees.`,
|
|
249
|
+
)
|
|
250
|
+
return
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
if (command === 'holds' && rest.length === 0) {
|
|
254
|
+
// Read-only: a listing must never create, migrate or reserve anything (D8).
|
|
255
|
+
const holds = listDecisionHoldsReadOnly(resolveLocalDecisionBudgetDbPath(env))
|
|
256
|
+
if (holds === null || holds.length === 0) {
|
|
257
|
+
stdout('No unresolved provider holds.')
|
|
258
|
+
return
|
|
259
|
+
}
|
|
260
|
+
for (const hold of holds) {
|
|
261
|
+
stdout(
|
|
262
|
+
`Hold ${hold.reservationId}: status=${hold.state} provider=${hold.provider} model=${hold.model} period=${hold.period} reserved_micros=${hold.reservedMicros}`,
|
|
263
|
+
)
|
|
264
|
+
}
|
|
265
|
+
stdout(
|
|
266
|
+
'This listing is read-only: it does not reserve, reconcile, release or prune, it never ' +
|
|
267
|
+
'creates or migrates the ledger, and unresolved holds are never auto-released. ' +
|
|
268
|
+
'Reconcile or resolve them explicitly before pruning their period.',
|
|
269
|
+
)
|
|
270
|
+
return
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
if (command === 'period') {
|
|
274
|
+
const [action, ...periodArgs] = rest
|
|
275
|
+
if (action !== 'confirm')
|
|
276
|
+
throw new DecisionRouterUsageError(
|
|
277
|
+
'Usage: decision-router period confirm --current none|YYYY-MM --next YYYY-MM',
|
|
278
|
+
)
|
|
279
|
+
const options = parseNamedOptions(periodArgs, ['--current', '--next'])
|
|
280
|
+
const expected = options['--current'] === 'none' ? null : options['--current']
|
|
281
|
+
const target = options['--next']
|
|
282
|
+
if ((expected !== null && !isMonth(expected)) || !isMonth(target)) {
|
|
283
|
+
throw new DecisionRouterUsageError(
|
|
284
|
+
'Budget periods must use YYYY-MM; initial current period is `none`',
|
|
285
|
+
)
|
|
286
|
+
}
|
|
287
|
+
const ledger = openLedger(env)
|
|
288
|
+
try {
|
|
289
|
+
const result = ledger.confirmBudgetPeriod(expected, target)
|
|
290
|
+
if (result.status !== 'confirmed')
|
|
291
|
+
throw new Error(`Budget period confirmation denied: ${result.reason}`)
|
|
292
|
+
stdout(`Explicit period confirmed: ${result.activePeriod}. Automatic rollover is disabled.`)
|
|
293
|
+
} finally {
|
|
294
|
+
ledger.close()
|
|
295
|
+
}
|
|
296
|
+
return
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
throw new DecisionRouterUsageError(USAGE)
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
/** Cap- and period-eligible candidates, read-only, from the separated surfaces. */
|
|
303
|
+
function capEligibleCandidates(config, inspection, wallPeriod) {
|
|
304
|
+
if (inspection.caps === null) return []
|
|
305
|
+
const period = evaluatePeriodGate({
|
|
306
|
+
activePeriod: inspection.period.activePeriod,
|
|
307
|
+
wallPeriod,
|
|
308
|
+
})
|
|
309
|
+
return config.enabled_candidates.filter(({ provider, model }) => {
|
|
310
|
+
const accounting = DECISION_PROVIDER_BUDGET_MAPPING[provider]
|
|
311
|
+
if (!accounting) return false
|
|
312
|
+
const cap = evaluateCapGate({
|
|
313
|
+
user: inspection.caps.user ?? undefined,
|
|
314
|
+
provider: inspection.caps.providers[accounting],
|
|
315
|
+
model: inspection.caps.models[`${accounting}/${model}`],
|
|
316
|
+
})
|
|
317
|
+
return cap.ok && period.ok
|
|
318
|
+
})
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
function describeEgress(config, inspection, wallPeriod) {
|
|
322
|
+
return resolveV2DecisionEgress(config, capEligibleCandidates(config, inspection, wallPeriod))
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
function describeEgressLine(egress) {
|
|
326
|
+
if (egress.mode === 'opt-in') {
|
|
327
|
+
return `Egress: opt-in (${egress.reason}) — ${egress.provider}/${egress.candidate.model}`
|
|
328
|
+
}
|
|
329
|
+
return `Egress: ${egress.mode} (${egress.reason}) — zero requests`
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
function formatLedger(inspection, dbPath) {
|
|
333
|
+
const { ledger } = inspection
|
|
334
|
+
if (!ledger.present) return `${dbPath} (absent; not created by this command)`
|
|
335
|
+
if (!ledger.readable) return `${dbPath} (unreadable: ${ledger.reason})`
|
|
336
|
+
return `${dbPath} (schema v${ledger.schemaVersion}, ${ledger.holds} unresolved hold(s), ${ledger.reservations} reservation(s))`
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
function formatPeriod(inspection) {
|
|
340
|
+
const { ledger, period } = inspection
|
|
341
|
+
if (!ledger.present) return 'unconfirmed (no ledger)'
|
|
342
|
+
if (!ledger.readable) return `unknown (${ledger.reason})`
|
|
343
|
+
return period.activePeriod ?? 'unconfirmed'
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
function formatCaps(inspection) {
|
|
347
|
+
if (inspection.caps === null) return 'none (no ledger)'
|
|
348
|
+
const providers = Object.keys(inspection.caps.providers).length
|
|
349
|
+
const models = Object.keys(inspection.caps.models).length
|
|
350
|
+
return `${inspection.caps.user === null ? 'user none' : 'user set'}, ${providers} provider, ${models} model`
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
function formatInstallState(config, target) {
|
|
354
|
+
const statePath = resolveInstallStatePath(target)
|
|
355
|
+
if (!existsSync(statePath)) return `no install-state at ${statePath} (nothing to reconcile)`
|
|
356
|
+
const state = readState(target)
|
|
357
|
+
if (state === null) {
|
|
358
|
+
return `unreadable install-state at ${statePath} (left untouched; repair or reinstall first)`
|
|
359
|
+
}
|
|
360
|
+
const diff = diffDecisionRouterSurfaces(config, state.decision_router)
|
|
361
|
+
if (diff.differences.length === 0) return `consistent with ${statePath}`
|
|
362
|
+
const fields = diff.differences
|
|
363
|
+
.map(
|
|
364
|
+
(entry) =>
|
|
365
|
+
`${entry.field}: install-state ${String(entry.installState)} -> user-config ${String(entry.userConfig)}`,
|
|
366
|
+
)
|
|
367
|
+
.join(', ')
|
|
368
|
+
return `divergent from ${statePath} (${fields}); run \`decision-router setup --target ${target} --apply\``
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
function parseSelectionTarget(target) {
|
|
372
|
+
if (target === 'local' || target === 'auto') return { mode: target }
|
|
373
|
+
const [provider, model, ...extra] = String(target).split('/')
|
|
374
|
+
if (extra.length || !isKnownCandidate(provider, model)) {
|
|
375
|
+
throw new DecisionRouterUsageError('Selection must name one supported provider/model pair')
|
|
376
|
+
}
|
|
377
|
+
return { mode: 'explicit', provider, model }
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
function parseNamedFlags(args, expected) {
|
|
381
|
+
const result = Object.create(null)
|
|
382
|
+
for (let index = 0; index < args.length; index += 1) {
|
|
383
|
+
const flag = args[index]
|
|
384
|
+
if (!expected.includes(flag) || Object.hasOwn(result, flag)) {
|
|
385
|
+
throw new DecisionRouterUsageError(USAGE)
|
|
386
|
+
}
|
|
387
|
+
const value = args[index + 1]
|
|
388
|
+
if (value === undefined || value.startsWith('--')) throw new DecisionRouterUsageError(USAGE)
|
|
389
|
+
result[flag] = value
|
|
390
|
+
index += 1
|
|
391
|
+
}
|
|
392
|
+
return result
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
function parseSetupOptions(args, forbidApply) {
|
|
396
|
+
const result = Object.create(null)
|
|
397
|
+
let index = 0
|
|
398
|
+
while (index < args.length) {
|
|
399
|
+
const flag = args[index]
|
|
400
|
+
if (flag === '--apply') {
|
|
401
|
+
if (forbidApply) {
|
|
402
|
+
throw new DecisionRouterUsageError('preview never writes; use `setup --apply`')
|
|
403
|
+
}
|
|
404
|
+
if (result['--apply'] === true) throw new DecisionRouterUsageError(USAGE)
|
|
405
|
+
result['--apply'] = true
|
|
406
|
+
index += 1
|
|
407
|
+
continue
|
|
408
|
+
}
|
|
409
|
+
if (flag === '--json' || flag === '--accept-migration') {
|
|
410
|
+
if (result[flag] === true) throw new DecisionRouterUsageError(USAGE)
|
|
411
|
+
result[flag] = true
|
|
412
|
+
index += 1
|
|
413
|
+
continue
|
|
414
|
+
}
|
|
415
|
+
if (flag === '--target' || flag === '--selection') {
|
|
416
|
+
const value = args[index + 1]
|
|
417
|
+
if (value === undefined || value.startsWith('--') || Object.hasOwn(result, flag)) {
|
|
418
|
+
throw new DecisionRouterUsageError(USAGE)
|
|
419
|
+
}
|
|
420
|
+
result[flag] = value
|
|
421
|
+
index += 2
|
|
422
|
+
continue
|
|
423
|
+
}
|
|
424
|
+
throw new DecisionRouterUsageError(USAGE)
|
|
425
|
+
}
|
|
426
|
+
return result
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
function saveConfig(env, update) {
|
|
430
|
+
const current = readUserDecisionRouterConfig({ env })
|
|
431
|
+
const next = updateUserDecisionRouterConfig(current, update)
|
|
432
|
+
writeUserDecisionRouterConfig(next, { env })
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
function openLedger(env) {
|
|
436
|
+
return openLocalDecisionBudgetLedger({ dbPath: resolveLocalDecisionBudgetDbPath(env) })
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
function parseCaps(args) {
|
|
440
|
+
const firstFlag = args.findIndex((arg) => arg.startsWith('--'))
|
|
441
|
+
const targetArgs = firstFlag === -1 ? args : args.slice(0, firstFlag)
|
|
442
|
+
const optionArgs = firstFlag === -1 ? [] : args.slice(firstFlag)
|
|
443
|
+
const missing = ['--monthly-usd', '--per-decision-usd'].filter(
|
|
444
|
+
(flag) => !optionArgs.includes(flag),
|
|
445
|
+
)
|
|
446
|
+
if (missing.length > 0) {
|
|
447
|
+
throw new DecisionRouterUsageError('Both --monthly-usd and --per-decision-usd are required')
|
|
448
|
+
}
|
|
449
|
+
const flags = parseNamedOptions(optionArgs, ['--monthly-usd', '--per-decision-usd'])
|
|
450
|
+
return {
|
|
451
|
+
monthly: parseUsdMicros(flags['--monthly-usd']),
|
|
452
|
+
perDecision: parseUsdMicros(flags['--per-decision-usd']),
|
|
453
|
+
rest: targetArgs,
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
function parseNamedOptions(args, expected) {
|
|
458
|
+
if (args.length !== expected.length * 2)
|
|
459
|
+
throw new DecisionRouterUsageError('Missing or extra command options')
|
|
460
|
+
const result = Object.create(null)
|
|
461
|
+
for (let index = 0; index < args.length; index += 2) {
|
|
462
|
+
const key = args[index]
|
|
463
|
+
const value = args[index + 1]
|
|
464
|
+
if (!expected.includes(key) || Object.hasOwn(result, key) || !value || value.startsWith('--')) {
|
|
465
|
+
throw new DecisionRouterUsageError('Invalid or duplicate command option')
|
|
466
|
+
}
|
|
467
|
+
result[key] = value
|
|
468
|
+
}
|
|
469
|
+
if (expected.some((key) => !Object.hasOwn(result, key)))
|
|
470
|
+
throw new DecisionRouterUsageError('Missing command option')
|
|
471
|
+
return result
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
function parseUsdMicros(value) {
|
|
475
|
+
if (typeof value !== 'string' || !/^(0|[1-9]\d*)(?:\.\d{1,6})?$/.test(value)) {
|
|
476
|
+
throw new DecisionRouterUsageError(
|
|
477
|
+
'USD cap must be a non-negative decimal with at most six fractional digits',
|
|
478
|
+
)
|
|
479
|
+
}
|
|
480
|
+
const [whole, fraction = ''] = value.split('.')
|
|
481
|
+
const micros = Number(whole) * 1_000_000 + Number(fraction.padEnd(6, '0'))
|
|
482
|
+
if (!Number.isSafeInteger(micros))
|
|
483
|
+
throw new DecisionRouterUsageError('USD cap exceeds the supported range')
|
|
484
|
+
return micros
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
function isKnownCandidate(provider, model) {
|
|
488
|
+
return (
|
|
489
|
+
typeof provider === 'string' &&
|
|
490
|
+
typeof model === 'string' &&
|
|
491
|
+
DECISION_ROUTER_MODELS[provider]?.includes(model)
|
|
492
|
+
)
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
function isMonth(value) {
|
|
496
|
+
return typeof value === 'string' && /^\d{4}-(0[1-9]|1[0-2])$/.test(value)
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
function candidateKey(provider, model) {
|
|
500
|
+
return `${provider}/${model}`
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
function formatSelection(selection) {
|
|
504
|
+
if (selection.mode === 'explicit') return `${selection.provider}/${selection.model}`
|
|
505
|
+
return selection.mode
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
function formatCandidate(candidate) {
|
|
509
|
+
return `${candidate.provider}/${candidate.model}`
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
|
|
513
|
+
runDecisionRouterCommand(process.argv.slice(2)).catch((error) => {
|
|
514
|
+
console.error(
|
|
515
|
+
`Error: ${error instanceof Error ? error.message : 'Decision-router command failed'}`,
|
|
516
|
+
)
|
|
517
|
+
process.exitCode = 1
|
|
518
|
+
})
|
|
519
|
+
}
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* - a bullet over 200 characters (including continuation lines) in those
|
|
11
11
|
* sections;
|
|
12
12
|
* - an empty subsection under [Unreleased];
|
|
13
|
-
* - any
|
|
13
|
+
* - any emoji H2 except the generated `🆕 What's New` and `🐞 Fixed` headings;
|
|
14
14
|
* - a missing Deprecated or Removed block in the newest stable version.
|
|
15
15
|
*
|
|
16
16
|
* Historical sections are archived records: only their version-heading shape
|
|
@@ -26,7 +26,9 @@ const ROOT = join(dirname(fileURLToPath(import.meta.url)), '..')
|
|
|
26
26
|
const CHANGELOG = process.argv[2] ? process.argv[2] : join(ROOT, 'CHANGELOG.md')
|
|
27
27
|
const MAX_BULLET = 200
|
|
28
28
|
const ALLOWED_H3 = new Set(['Added', 'Changed', 'Deprecated', 'Removed', 'Fixed', 'Security'])
|
|
29
|
-
const EMOJI_H2 =
|
|
29
|
+
const EMOJI_H2 =
|
|
30
|
+
/^##\s+(?:\p{Extended_Pictographic}|\p{Regional_Indicator}{2}|[#*0-9]\uFE0F?\u20E3)/u
|
|
31
|
+
const ALLOWED_GENERATED_H2 = /^##\s+(?:🆕 What's New|🐞 Fixed)\s*$/
|
|
30
32
|
const STABLE_VERSION_HEADING = /^## \[v?(\d+\.\d+\.\d+)\] - \d{4}-\d{2}-\d{2}$/
|
|
31
33
|
// Historical headings may carry a pre-release suffix, a month-only date, or a
|
|
32
34
|
// "(candidate)" marker.
|
|
@@ -104,7 +106,7 @@ function main() {
|
|
|
104
106
|
if (line.startsWith('## ')) {
|
|
105
107
|
closeSection()
|
|
106
108
|
|
|
107
|
-
if (EMOJI_H2.test(line)) {
|
|
109
|
+
if (EMOJI_H2.test(line) && !ALLOWED_GENERATED_H2.test(line)) {
|
|
108
110
|
findings.push(`${lineNo}: emoji H2 is not allowed (${line.trim()})`)
|
|
109
111
|
continue
|
|
110
112
|
}
|