pantheon-opencode 1.6.2-beta.4 → 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 +8 -0
- package/README.md +174 -3
- package/bin/pantheon-init.mjs +6 -1
- package/package.json +1 -1
- package/plugin.json +1 -1
- package/pyproject.toml +1 -1
- package/scripts/decision-router-budget.mjs +3 -3
- package/scripts/decision-router-v2-budget.mjs +218 -0
- package/scripts/decision-router-v2-egress.mjs +272 -0
- package/scripts/decision-router.mjs +268 -46
- package/scripts/docs-check-changelog.mjs +5 -3
- package/scripts/install/decision-layer-preview.mjs +376 -0
- package/scripts/install/decision-router-config.mjs +158 -11
- package/scripts/mcp_resources.py +11 -9
- package/scripts/release-notes.mjs +30 -7
- package/scripts/versioning.mjs +41 -5
- 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-prompt.ts +181 -36
- package/src/pantheon/local-decision-skills.ts +115 -5
- package/src/pantheon/local-decision-tool.ts +35 -1
- 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 +21 -2
- package/src/plugin-v2.ts +305 -3
- 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,272 @@
|
|
|
1
|
+
// Generated by scripts/build-decision-router.mjs. The published CLI cannot
|
|
2
|
+
// import TypeScript from node_modules, so it imports this prebuilt ESM bundle
|
|
3
|
+
// instead. Do not edit: run `npm run build:decision-router`.
|
|
4
|
+
|
|
5
|
+
// scripts/install/decision-router-config.mjs
|
|
6
|
+
var DECISION_ROUTER_CONFIG_SCHEMA_VERSION = 1;
|
|
7
|
+
var DECISION_ROUTER_PROVIDERS = Object.freeze(["local", "openai-decisions", "jev", "auto"]);
|
|
8
|
+
var DEFAULT_DECISION_ROUTER_CONFIG = Object.freeze({
|
|
9
|
+
schema_version: DECISION_ROUTER_CONFIG_SCHEMA_VERSION,
|
|
10
|
+
provider: "local",
|
|
11
|
+
egress_consent: false
|
|
12
|
+
});
|
|
13
|
+
var DECISION_ROUTER_MODELS = Object.freeze({
|
|
14
|
+
"openai-decisions": Object.freeze(["gpt-6-luna"]),
|
|
15
|
+
"typesafe-jev": Object.freeze(["jev-1.14.0"]),
|
|
16
|
+
"opencode-console-jev": Object.freeze(["jev-1.13"]),
|
|
17
|
+
"opencode-console-jev-free": Object.freeze(["jev-1.13-free"])
|
|
18
|
+
});
|
|
19
|
+
var DECISION_PROVIDER_BUDGET_MAPPING = Object.freeze({
|
|
20
|
+
"openai-decisions": "openai-decisions",
|
|
21
|
+
"typesafe-jev": "typesafe-jev",
|
|
22
|
+
"opencode-console-jev": "opencode-console",
|
|
23
|
+
"opencode-console-jev-free": "jev-free"
|
|
24
|
+
});
|
|
25
|
+
var REMOTELY_ELIGIBLE_DECISION_PROVIDERS = Object.freeze([
|
|
26
|
+
"openai-decisions",
|
|
27
|
+
"typesafe-jev"
|
|
28
|
+
]);
|
|
29
|
+
var USER_DECISION_ROUTER_CONFIG_SCHEMA_VERSION = 2;
|
|
30
|
+
var DEFAULT_USER_DECISION_ROUTER_CONFIG = Object.freeze({
|
|
31
|
+
schema_version: USER_DECISION_ROUTER_CONFIG_SCHEMA_VERSION,
|
|
32
|
+
enabled: false,
|
|
33
|
+
selection: Object.freeze({ mode: "local" }),
|
|
34
|
+
egress_consent: false,
|
|
35
|
+
enabled_candidates: Object.freeze([])
|
|
36
|
+
});
|
|
37
|
+
var LEGACY_PROVIDER_ALIASES = Object.freeze({ jev: "typesafe-jev" });
|
|
38
|
+
var userCandidateProviders = new Set(Object.keys(DECISION_ROUTER_MODELS));
|
|
39
|
+
var remotelyEligibleProviders = new Set(REMOTELY_ELIGIBLE_DECISION_PROVIDERS);
|
|
40
|
+
var USER_CONFIG_KEYS = [
|
|
41
|
+
"egress_consent",
|
|
42
|
+
"enabled",
|
|
43
|
+
"enabled_candidates",
|
|
44
|
+
"schema_version",
|
|
45
|
+
"selection"
|
|
46
|
+
];
|
|
47
|
+
var LEGACY_USER_CONFIG_KEYS = [
|
|
48
|
+
"egress_consent",
|
|
49
|
+
"enabled_candidates",
|
|
50
|
+
"schema_version",
|
|
51
|
+
"selection"
|
|
52
|
+
];
|
|
53
|
+
var ACCEPTED_INSTALL_STATE_PROVIDERS = /* @__PURE__ */ new Set([...DECISION_ROUTER_PROVIDERS, "typesafe-jev"]);
|
|
54
|
+
function normalizeDecisionProviderId(provider) {
|
|
55
|
+
if (typeof provider !== "string") return provider;
|
|
56
|
+
return LEGACY_PROVIDER_ALIASES[provider] ?? provider;
|
|
57
|
+
}
|
|
58
|
+
function migrateUserDecisionRouterConfig(value) {
|
|
59
|
+
if (!isPlainObject(value)) return cloneDefaultUserConfig();
|
|
60
|
+
if (value.schema_version === 1) return migrateLegacyUserConfig(value);
|
|
61
|
+
if (value.schema_version !== USER_DECISION_ROUTER_CONFIG_SCHEMA_VERSION) {
|
|
62
|
+
return cloneDefaultUserConfig();
|
|
63
|
+
}
|
|
64
|
+
if (!hasExactKeys(value, USER_CONFIG_KEYS) || typeof value.egress_consent !== "boolean" || typeof value.enabled !== "boolean" || !Array.isArray(value.enabled_candidates)) {
|
|
65
|
+
return cloneDefaultUserConfig();
|
|
66
|
+
}
|
|
67
|
+
const selection = normalizeSelection(value.selection);
|
|
68
|
+
const candidates = normalizeEnabledCandidates(value.enabled_candidates);
|
|
69
|
+
if (selection === null || candidates === null) return cloneDefaultUserConfig();
|
|
70
|
+
return {
|
|
71
|
+
schema_version: USER_DECISION_ROUTER_CONFIG_SCHEMA_VERSION,
|
|
72
|
+
enabled: value.enabled,
|
|
73
|
+
selection,
|
|
74
|
+
egress_consent: selection.mode === "local" ? false : value.egress_consent,
|
|
75
|
+
enabled_candidates: candidates
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
function migrateLegacyUserConfig(value) {
|
|
79
|
+
if (!hasExactKeys(value, LEGACY_USER_CONFIG_KEYS) || typeof value.egress_consent !== "boolean" || !Array.isArray(value.enabled_candidates)) {
|
|
80
|
+
return cloneDefaultUserConfig();
|
|
81
|
+
}
|
|
82
|
+
const selection = normalizeSelection(value.selection);
|
|
83
|
+
const candidates = normalizeEnabledCandidates(value.enabled_candidates);
|
|
84
|
+
if (selection === null || candidates === null) return cloneDefaultUserConfig();
|
|
85
|
+
const egressConsent = selection.mode === "local" ? false : value.egress_consent;
|
|
86
|
+
return {
|
|
87
|
+
schema_version: USER_DECISION_ROUTER_CONFIG_SCHEMA_VERSION,
|
|
88
|
+
enabled: selection.mode !== "local" && egressConsent && candidates.length > 0,
|
|
89
|
+
selection,
|
|
90
|
+
egress_consent: egressConsent,
|
|
91
|
+
enabled_candidates: candidates
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
function eligibleAutoCandidates(preference, capValidCandidates) {
|
|
95
|
+
const validKeys = new Set(
|
|
96
|
+
capValidCandidates.filter(isKnownCandidate).map(({ provider, model }) => candidateKey(normalizeDecisionProviderId(provider), model))
|
|
97
|
+
);
|
|
98
|
+
return preference.enabled_candidates.filter(
|
|
99
|
+
(candidate) => remotelyEligibleProviders.has(candidate.provider) && validKeys.has(candidateKey(candidate.provider, candidate.model))
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
function explainUserDecisionRouterAutoSelection(config, capValidCandidates = []) {
|
|
103
|
+
const preference = migrateUserDecisionRouterConfig(config);
|
|
104
|
+
if (!preference.enabled) return { outcome: "ineligible", reason: "DISABLED" };
|
|
105
|
+
if (!preference.egress_consent) return { outcome: "ineligible", reason: "CONSENT_MISSING" };
|
|
106
|
+
if (preference.selection.mode !== "auto") return { outcome: "ineligible", reason: "NOT_AUTO" };
|
|
107
|
+
const eligible = eligibleAutoCandidates(preference, capValidCandidates);
|
|
108
|
+
if (eligible.length === 0) {
|
|
109
|
+
return { outcome: "none", reason: "NO_ELIGIBLE_CANDIDATE", count: 0 };
|
|
110
|
+
}
|
|
111
|
+
if (eligible.length > 1) {
|
|
112
|
+
return {
|
|
113
|
+
outcome: "ambiguous",
|
|
114
|
+
reason: "MULTIPLE_ELIGIBLE_CANDIDATES",
|
|
115
|
+
count: eligible.length
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
return {
|
|
119
|
+
outcome: "single",
|
|
120
|
+
reason: "SINGLE_ELIGIBLE_CANDIDATE",
|
|
121
|
+
count: 1,
|
|
122
|
+
candidate: eligible[0]
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
function normalizeSelection(value) {
|
|
126
|
+
if (!isPlainObject(value) || typeof value.mode !== "string") return null;
|
|
127
|
+
if (value.mode === "local" || value.mode === "auto") {
|
|
128
|
+
return Object.keys(value).length === 1 ? { mode: value.mode } : null;
|
|
129
|
+
}
|
|
130
|
+
if (value.mode !== "explicit" || Object.keys(value).length !== 3 || !isKnownCandidate({ provider: value.provider, model: value.model })) {
|
|
131
|
+
return null;
|
|
132
|
+
}
|
|
133
|
+
return {
|
|
134
|
+
mode: "explicit",
|
|
135
|
+
provider: normalizeDecisionProviderId(value.provider),
|
|
136
|
+
model: value.model
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
function normalizeEnabledCandidates(value) {
|
|
140
|
+
const seen = /* @__PURE__ */ new Set();
|
|
141
|
+
const result = [];
|
|
142
|
+
for (const item of value) {
|
|
143
|
+
if (!isKnownCandidate(item) || Object.keys(item).length !== 2) return null;
|
|
144
|
+
const provider = normalizeDecisionProviderId(item.provider);
|
|
145
|
+
const key = candidateKey(provider, item.model);
|
|
146
|
+
if (seen.has(key)) return null;
|
|
147
|
+
seen.add(key);
|
|
148
|
+
result.push({ provider, model: item.model });
|
|
149
|
+
}
|
|
150
|
+
return result;
|
|
151
|
+
}
|
|
152
|
+
function isKnownCandidate(value) {
|
|
153
|
+
if (!isPlainObject(value) || typeof value.provider !== "string" || typeof value.model !== "string") {
|
|
154
|
+
return false;
|
|
155
|
+
}
|
|
156
|
+
const provider = normalizeDecisionProviderId(value.provider);
|
|
157
|
+
return userCandidateProviders.has(provider) && DECISION_ROUTER_MODELS[provider].includes(value.model);
|
|
158
|
+
}
|
|
159
|
+
function candidateKey(provider, model) {
|
|
160
|
+
return `${provider}/${model}`;
|
|
161
|
+
}
|
|
162
|
+
function isPlainObject(value) {
|
|
163
|
+
if (value === null || typeof value !== "object" || Array.isArray(value)) return false;
|
|
164
|
+
const prototype = Object.getPrototypeOf(value);
|
|
165
|
+
return prototype === Object.prototype || prototype === null;
|
|
166
|
+
}
|
|
167
|
+
function hasExactKeys(value, keys) {
|
|
168
|
+
const actual = Object.keys(value).sort();
|
|
169
|
+
const expected = [...keys].sort();
|
|
170
|
+
return actual.length === expected.length && actual.every((key, index) => key === expected[index]);
|
|
171
|
+
}
|
|
172
|
+
function cloneDefaultUserConfig() {
|
|
173
|
+
return {
|
|
174
|
+
schema_version: DEFAULT_USER_DECISION_ROUTER_CONFIG.schema_version,
|
|
175
|
+
enabled: false,
|
|
176
|
+
selection: { mode: "local" },
|
|
177
|
+
egress_consent: false,
|
|
178
|
+
enabled_candidates: []
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
// src/pantheon/v2-decision-egress.ts
|
|
183
|
+
var V2_DECISION_EGRESS_DEFAULT = "off";
|
|
184
|
+
var DECLARED_EGRESS_ENDPOINTS = Object.freeze([
|
|
185
|
+
{ url: "https://api.openai.com/v1/decisions", wireStatus: "unwired" },
|
|
186
|
+
{ url: "https://api.typesafe.ai/v1/systemone", wireStatus: "unwired" },
|
|
187
|
+
{ url: "https://opencode.ai/inference/systemone/v1/systemone", wireStatus: "unwired" }
|
|
188
|
+
]);
|
|
189
|
+
var V2_DECISION_EGRESS_EXERCISED_PATHS = Object.freeze([]);
|
|
190
|
+
var V2_DECISION_EGRESS_ENDPOINT_WIRE_STATUS = Object.freeze(
|
|
191
|
+
Object.fromEntries(DECLARED_EGRESS_ENDPOINTS.map(({ url, wireStatus }) => [url, wireStatus]))
|
|
192
|
+
);
|
|
193
|
+
function findUnverifiedEgressEndpoints(endpoints, endpointWireStatus, exercisedPaths = V2_DECISION_EGRESS_EXERCISED_PATHS) {
|
|
194
|
+
const exercised = new Set(exercisedPaths);
|
|
195
|
+
return Object.freeze(
|
|
196
|
+
endpoints.filter((endpoint) => {
|
|
197
|
+
const status = endpointWireStatus[endpoint];
|
|
198
|
+
if (status === "unwired") return false;
|
|
199
|
+
if (status === "wired") return !exercised.has(endpoint);
|
|
200
|
+
return true;
|
|
201
|
+
})
|
|
202
|
+
);
|
|
203
|
+
}
|
|
204
|
+
var V2_DECISION_EGRESS_TRANSPORT = Object.freeze({
|
|
205
|
+
wireStatus: "unwired",
|
|
206
|
+
wired: false,
|
|
207
|
+
note: "Endpoints are retained inert (UNWIRED) in this surface. No transport, retry or fallback exists here, and this module never claims the transport was removed. Verification covers only the paths a probe exercised \u2014 none \u2014 and every declared endpoint carries an explicit wire status so an unverified endpoint fails a test instead of passing silently.",
|
|
208
|
+
endpoints: Object.freeze(DECLARED_EGRESS_ENDPOINTS.map(({ url }) => url)),
|
|
209
|
+
endpointWireStatus: V2_DECISION_EGRESS_ENDPOINT_WIRE_STATUS
|
|
210
|
+
});
|
|
211
|
+
function resolveV2DecisionEgress(config, capEligibleCandidates = []) {
|
|
212
|
+
const preference = migrateUserDecisionRouterConfig(config);
|
|
213
|
+
const candidates = preference.enabled_candidates.length;
|
|
214
|
+
if (!preference.enabled) {
|
|
215
|
+
return { mode: "off", reason: "DISABLED", candidates };
|
|
216
|
+
}
|
|
217
|
+
if (preference.selection.mode === "local") {
|
|
218
|
+
return { mode: "off", reason: "LOCAL_SELECTION", candidates };
|
|
219
|
+
}
|
|
220
|
+
if (!preference.egress_consent) {
|
|
221
|
+
return { mode: "off", reason: "CONSENT_MISSING", candidates };
|
|
222
|
+
}
|
|
223
|
+
if (preference.selection.mode === "auto") {
|
|
224
|
+
const explained = explainUserDecisionRouterAutoSelection(
|
|
225
|
+
preference,
|
|
226
|
+
capEligibleCandidates
|
|
227
|
+
);
|
|
228
|
+
if (explained.outcome === "ambiguous") {
|
|
229
|
+
return { mode: "off", reason: "AMBIGUOUS_CANDIDATES", candidates: explained.count };
|
|
230
|
+
}
|
|
231
|
+
if (explained.outcome !== "single") {
|
|
232
|
+
return { mode: "off", reason: "NO_ELIGIBLE_CANDIDATE", candidates: 0 };
|
|
233
|
+
}
|
|
234
|
+
return {
|
|
235
|
+
mode: "opt-in",
|
|
236
|
+
reason: "EXPLICIT_OPT_IN",
|
|
237
|
+
provider: explained.candidate.provider,
|
|
238
|
+
candidate: explained.candidate
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
const selected = preference.selection;
|
|
242
|
+
const match = capEligibleCandidates.find(
|
|
243
|
+
(candidate) => candidate.provider === selected.provider && candidate.model === selected.model
|
|
244
|
+
);
|
|
245
|
+
if (match === void 0) {
|
|
246
|
+
return { mode: "off", reason: "NO_ELIGIBLE_CANDIDATE", candidates };
|
|
247
|
+
}
|
|
248
|
+
return {
|
|
249
|
+
mode: "opt-in",
|
|
250
|
+
reason: "EXPLICIT_OPT_IN",
|
|
251
|
+
provider: selected.provider,
|
|
252
|
+
candidate: match
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
function v2DecisionEgressMaySend(state) {
|
|
256
|
+
return state.mode === "opt-in" && state.reason === "EXPLICIT_OPT_IN";
|
|
257
|
+
}
|
|
258
|
+
function assertV2DecisionEgressOptIn(state) {
|
|
259
|
+
if (!v2DecisionEgressMaySend(state)) {
|
|
260
|
+
throw new Error(`Decision egress is off (${state.mode === "off" ? state.reason : "unknown"})`);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
export {
|
|
264
|
+
V2_DECISION_EGRESS_DEFAULT,
|
|
265
|
+
V2_DECISION_EGRESS_ENDPOINT_WIRE_STATUS,
|
|
266
|
+
V2_DECISION_EGRESS_EXERCISED_PATHS,
|
|
267
|
+
V2_DECISION_EGRESS_TRANSPORT,
|
|
268
|
+
assertV2DecisionEgressOptIn,
|
|
269
|
+
findUnverifiedEgressEndpoints,
|
|
270
|
+
resolveV2DecisionEgress,
|
|
271
|
+
v2DecisionEgressMaySend
|
|
272
|
+
};
|
|
@@ -1,24 +1,48 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { existsSync } from 'node:fs'
|
|
3
3
|
import { pathToFileURL } from 'node:url'
|
|
4
|
-
// Prebuilt
|
|
5
|
-
// so the published CLI cannot import the
|
|
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
6
|
// with `npm run build:decision-router`; `--check` guards against drift.
|
|
7
7
|
import {
|
|
8
8
|
openLocalDecisionBudgetLedger,
|
|
9
9
|
resolveLocalDecisionBudgetDbPath,
|
|
10
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'
|
|
11
30
|
import {
|
|
12
31
|
DECISION_PROVIDER_BUDGET_MAPPING,
|
|
13
32
|
DECISION_ROUTER_MODELS,
|
|
33
|
+
diffDecisionRouterSurfaces,
|
|
14
34
|
readUserDecisionRouterConfig,
|
|
15
35
|
resolveUserDecisionRouterConfigPath,
|
|
16
36
|
updateUserDecisionRouterConfig,
|
|
17
37
|
writeUserDecisionRouterConfig,
|
|
18
38
|
} from './install/decision-router-config.mjs'
|
|
39
|
+
import { readState } from './install/state.mjs'
|
|
19
40
|
|
|
20
41
|
const BUDGET_PROVIDERS = DECISION_PROVIDER_BUDGET_MAPPING
|
|
21
42
|
|
|
43
|
+
const USAGE =
|
|
44
|
+
'Usage: decision-router help|status|setup|preview|select|enable|disable|consent|caps|period|holds'
|
|
45
|
+
|
|
22
46
|
/**
|
|
23
47
|
* Malformed command line (wrong flags, unknown provider, invalid value).
|
|
24
48
|
* Callers report it as a short message; a stack implies a bug, not bad input.
|
|
@@ -27,26 +51,108 @@ export class DecisionRouterUsageError extends TypeError {
|
|
|
27
51
|
name = 'DecisionRouterUsageError'
|
|
28
52
|
}
|
|
29
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
|
+
|
|
30
88
|
/** Run an explicit, non-secret administrative command for the user-level router config. */
|
|
31
89
|
export async function runDecisionRouterCommand(
|
|
32
90
|
args,
|
|
33
91
|
{ env = process.env, stdout = console.log } = {},
|
|
34
92
|
) {
|
|
35
93
|
const [command, ...rest] = args
|
|
36
|
-
|
|
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'])
|
|
37
103
|
const config = readUserDecisionRouterConfig({ env })
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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 {
|
|
44
143
|
stdout(
|
|
45
|
-
|
|
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.',
|
|
46
155
|
)
|
|
47
|
-
stdout(`Active budget period: ${ledger.getActiveBudgetPeriod() ?? 'unconfirmed'}`)
|
|
48
|
-
} finally {
|
|
49
|
-
ledger.close()
|
|
50
156
|
}
|
|
51
157
|
return
|
|
52
158
|
}
|
|
@@ -55,18 +161,18 @@ export async function runDecisionRouterCommand(
|
|
|
55
161
|
const target = rest[0]
|
|
56
162
|
if (rest.length !== 1 || typeof target !== 'string')
|
|
57
163
|
throw new DecisionRouterUsageError('Usage: decision-router select local|auto|provider/model')
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
selection = { mode: target }
|
|
61
|
-
} else {
|
|
62
|
-
const [provider, model, ...extra] = target.split('/')
|
|
63
|
-
if (extra.length || !isKnownCandidate(provider, model)) {
|
|
64
|
-
throw new DecisionRouterUsageError('Selection must name one supported provider/model pair')
|
|
65
|
-
}
|
|
66
|
-
selection = { mode: 'explicit', provider, model }
|
|
67
|
-
}
|
|
164
|
+
const selection = parseSelectionTarget(target)
|
|
165
|
+
const before = readUserDecisionRouterConfig({ env })
|
|
68
166
|
saveConfig(env, { selection })
|
|
69
|
-
|
|
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
|
+
)
|
|
70
176
|
return
|
|
71
177
|
}
|
|
72
178
|
|
|
@@ -145,31 +251,22 @@ export async function runDecisionRouterCommand(
|
|
|
145
251
|
}
|
|
146
252
|
|
|
147
253
|
if (command === 'holds' && rest.length === 0) {
|
|
148
|
-
|
|
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) {
|
|
149
257
|
stdout('No unresolved provider holds.')
|
|
150
258
|
return
|
|
151
259
|
}
|
|
152
|
-
const
|
|
153
|
-
try {
|
|
154
|
-
const holds = ledger.listUncertainReservations()
|
|
155
|
-
if (holds.length === 0) {
|
|
156
|
-
stdout('No unresolved provider holds.')
|
|
157
|
-
return
|
|
158
|
-
}
|
|
159
|
-
for (const hold of holds) {
|
|
160
|
-
stdout(
|
|
161
|
-
`Hold ${hold.reservationId}: status=${hold.state} provider=${hold.provider} model=${hold.model} period=${hold.period} reserved_micros=${hold.reservedMicros}`,
|
|
162
|
-
)
|
|
163
|
-
}
|
|
260
|
+
for (const hold of holds) {
|
|
164
261
|
stdout(
|
|
165
|
-
|
|
166
|
-
'Opening an existing ledger may apply a forward-only schema migration. ' +
|
|
167
|
-
'Unresolved holds are never auto-released; reconcile or resolve them ' +
|
|
168
|
-
'explicitly before pruning their period.',
|
|
262
|
+
`Hold ${hold.reservationId}: status=${hold.state} provider=${hold.provider} model=${hold.model} period=${hold.period} reserved_micros=${hold.reservedMicros}`,
|
|
169
263
|
)
|
|
170
|
-
} finally {
|
|
171
|
-
ledger.close()
|
|
172
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
|
+
)
|
|
173
270
|
return
|
|
174
271
|
}
|
|
175
272
|
|
|
@@ -199,9 +296,134 @@ export async function runDecisionRouterCommand(
|
|
|
199
296
|
return
|
|
200
297
|
}
|
|
201
298
|
|
|
202
|
-
throw new DecisionRouterUsageError(
|
|
203
|
-
|
|
204
|
-
|
|
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
|
|
205
427
|
}
|
|
206
428
|
|
|
207
429
|
function saveConfig(env, update) {
|
|
@@ -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
|
}
|