@aiwg/cli 2026.10.16 → 2026.10.19
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/agentic/code/providers/capability-matrix.yaml +51 -0
- package/agentic/code/providers/flue/README.md +62 -0
- package/agentic/code/providers/flue/templates/aiwg/tools.ts +120 -0
- package/agentic/code/providers/model-capabilities.v1.json +23 -0
- package/agentic/code/providers/model-catalog.v1.json +9 -0
- package/dist/src/artifacts/corpus-tools/resolve.js +28 -6
- package/dist/src/artifacts/query-engine-corpus.js +217 -0
- package/dist/src/artifacts/query-engine-discover-output.js +229 -0
- package/dist/src/artifacts/query-engine-discover.js +285 -0
- package/dist/src/artifacts/query-engine-entries.js +188 -0
- package/dist/src/artifacts/query-engine-index.js +249 -0
- package/dist/src/artifacts/query-engine-matching.js +143 -0
- package/dist/src/artifacts/query-engine-options.js +2 -0
- package/dist/src/artifacts/query-engine-rules.js +202 -0
- package/dist/src/artifacts/query-engine-scoring.js +436 -0
- package/dist/src/artifacts/query-engine-show-card.js +194 -0
- package/dist/src/artifacts/query-engine-show-load.js +211 -0
- package/dist/src/artifacts/query-engine-show.js +300 -0
- package/dist/src/artifacts/query-engine.js +7 -2576
- package/dist/src/cli/handlers/help.js +1 -1
- package/dist/src/cli/handlers/init.js +1 -0
- package/dist/src/cli/handlers/mc-agents.js +111 -0
- package/dist/src/cli/handlers/mc-args.js +54 -0
- package/dist/src/cli/handlers/mc-control.js +227 -0
- package/dist/src/cli/handlers/mc-dispatch.js +203 -0
- package/dist/src/cli/handlers/mc-help.js +171 -0
- package/dist/src/cli/handlers/mc-run.js +343 -0
- package/dist/src/cli/handlers/mc-session.js +138 -0
- package/dist/src/cli/handlers/mc-status.js +258 -0
- package/dist/src/cli/handlers/mc-summary.js +43 -0
- package/dist/src/cli/handlers/mc-types.js +3 -0
- package/dist/src/cli/handlers/mc-worker.js +205 -0
- package/dist/src/cli/handlers/mc.js +12 -1665
- package/dist/src/cli/handlers/models-refusal.js +13 -0
- package/dist/src/cli/handlers/models.js +2 -1
- package/dist/src/cli/handlers/remove-bundled.js +133 -0
- package/dist/src/cli/handlers/remove-options.js +31 -0
- package/dist/src/cli/handlers/remove-user.js +174 -0
- package/dist/src/cli/handlers/remove.js +201 -0
- package/dist/src/cli/handlers/subcommands-bundles.js +257 -0
- package/dist/src/cli/handlers/subcommands-discovery.js +165 -0
- package/dist/src/cli/handlers/subcommands-list-format.js +129 -0
- package/dist/src/cli/handlers/subcommands-list.js +250 -0
- package/dist/src/cli/handlers/subcommands-plugins.js +213 -0
- package/dist/src/cli/handlers/subcommands-quickref.js +58 -0
- package/dist/src/cli/handlers/subcommands-rlm.js +113 -0
- package/dist/src/cli/handlers/subcommands-services.js +66 -0
- package/dist/src/cli/handlers/subcommands-storage.js +259 -0
- package/dist/src/cli/handlers/subcommands.js +18 -1984
- package/dist/src/cli/handlers/use.js +11 -5
- package/dist/src/cli/scope-resolver.js +1 -142
- package/dist/src/cli/services/deployment-verification.js +3 -0
- package/dist/src/cli/user-scope-mirror.js +173 -0
- package/dist/src/config/dispatch-host-thresholds.js +2 -0
- package/dist/src/config/dispatch-thresholds-runtime.mjs +4 -0
- package/dist/src/config/host-resource-report.d.mts +5 -0
- package/dist/src/config/host-resource-report.mjs +36 -6
- package/dist/src/config/host-resource-runtime.d.mts +3 -0
- package/dist/src/config/host-resource-runtime.mjs +9 -6
- package/dist/src/decision/ensemble-study/artifacts.js +7 -0
- package/dist/src/decision/ensemble-study/gate-policy.js +58 -0
- package/dist/src/decision/ensemble-study/gates.js +78 -0
- package/dist/src/decision/ensemble-study/protocol.js +18 -21
- package/dist/src/decision/ensemble-study/score.js +3 -2
- package/dist/src/decision/ensemble-study/statistics.js +7 -26
- package/dist/src/decision/sensitivity/comparative-gates.js +135 -0
- package/dist/src/decision/sensitivity/comparative.js +18 -41
- package/dist/src/extensions/claude-hooks-installer.js +18 -0
- package/dist/src/gates/evaluate.js +2 -358
- package/dist/src/gates/observations.js +363 -0
- package/dist/src/gates/pack-composition.js +270 -0
- package/dist/src/gates/pack-tightening.js +197 -0
- package/dist/src/gates/pack-validation.js +262 -0
- package/dist/src/gates/registry-error.js +5 -0
- package/dist/src/gates/registry.js +13 -685
- package/dist/src/mcp/json-document.mjs +29 -0
- package/dist/src/mcp/muse-native-config.mjs +1 -28
- package/dist/src/memory/provider-memory-adapter.js +1 -0
- package/dist/src/mission-protocol/worker-review-gate.js +7 -0
- package/dist/src/models/model-capabilities.v1.json +23 -0
- package/dist/src/models/model-catalog.v1.json +9 -0
- package/dist/src/models/policy-resources.js +1 -1
- package/dist/src/models/worker-plan.js +5 -5
- package/dist/src/plugin/command-ownership.js +34 -0
- package/dist/src/plugin/skill-command-frontmatter.js +197 -0
- package/dist/src/plugin/skill-command-translator.js +6 -232
- package/dist/src/providers/capability-matrix.yaml +51 -0
- package/dist/src/providers/context-output-ownership.js +26 -0
- package/dist/src/providers/deployment-ownership.d.mts +20 -0
- package/dist/src/providers/deployment-ownership.mjs +236 -0
- package/dist/src/providers/deployment-removal.js +222 -0
- package/dist/src/providers/provider-context-contracts.js +8 -0
- package/dist/src/providers/provider-definition-schema.js +1 -0
- package/dist/src/providers/provider-definitions.js +1 -0
- package/dist/src/providers/provider-seeds-3.js +18 -0
- package/dist/src/providers/removal-transaction.js +86 -0
- package/dist/src/providers/settings-document.d.mts +3 -0
- package/dist/src/providers/settings-document.mjs +47 -0
- package/dist/src/providers/settings-removal.js +190 -0
- package/dist/src/providers/skill-ownership.d.mts +20 -2
- package/dist/src/providers/skill-ownership.mjs +12 -4
- package/dist/src/providers/transformation-receipt-integration.js +15 -271
- package/dist/src/providers/transformation-receipt-outputs.js +99 -0
- package/dist/src/providers/transformation-receipt-source.js +194 -0
- package/dist/src/research/identity.js +8 -2
- package/dist/src/research/reference-match.js +66 -8
- package/dist/src/rules/activation.mjs +15 -6
- package/dist/src/rules/core-startup.mjs +2 -2
- package/dist/src/serve/mission-conductor.js +4 -0
- package/dist/src/serve/mission-summary.js +56 -0
- package/dist/src/skills/deployment-ownership.js +2 -2
- package/dist/src/skills/deployment-policy.js +9 -0
- package/dist/src/smiths/context-pipeline/aiwg-md.js +23 -0
- package/dist/src/smiths/context-pipeline/context-file-safety.js +3 -0
- package/dist/src/smiths/context-pipeline/flue-context.js +25 -0
- package/dist/src/smiths/context-pipeline/generator.js +7 -2
- package/dist/src/smiths/context-pipeline/workspace-bootstrap.js +9 -7
- package/dist/src/smiths/hook-bridge/index.js +9 -0
- package/package.json +5 -1
- package/schemas/decision/D17StudyProtocol.v1.schema.json +39 -67
- package/tools/agents/deploy-agents.mjs +21 -680
- package/tools/agents/deploy-command-mirrors.mjs +229 -0
- package/tools/agents/deploy-options.mjs +267 -0
- package/tools/agents/deploy-support.mjs +165 -0
- package/tools/agents/providers/base-addon-discovery.mjs +139 -0
- package/tools/agents/providers/base-behaviors.mjs +168 -0
- package/tools/agents/providers/base-context.mjs +205 -0
- package/tools/agents/providers/base-contract.mjs +116 -0
- package/tools/agents/providers/base-files.mjs +252 -0
- package/tools/agents/providers/base-flat-artifacts.mjs +233 -0
- package/tools/agents/providers/base-framework-discovery.mjs +309 -0
- package/tools/agents/providers/base-frontmatter.mjs +196 -0
- package/tools/agents/providers/base-inventory.mjs +269 -0
- package/tools/agents/providers/base-kernel-skills.mjs +354 -0
- package/tools/agents/providers/base-migrations.mjs +258 -0
- package/tools/agents/providers/base-models-platforms.mjs +273 -0
- package/tools/agents/providers/base-rule-index.mjs +450 -0
- package/tools/agents/providers/base-runtime.mjs +60 -0
- package/tools/agents/providers/base-skill-copy.mjs +273 -0
- package/tools/agents/providers/base.mjs +16 -3364
- package/tools/agents/providers/claude-post-deploy.mjs +10 -2
- package/tools/agents/providers/flue-project.mjs +79 -0
- package/tools/agents/providers/flue-specialists.mjs +64 -0
- package/tools/agents/providers/flue.mjs +50 -0
- package/tools/agents/providers/hermes-startup.mjs +0 -5
- package/tools/agents/providers/muse.mjs +7 -2
- package/tools/agents/providers/rule-delivery-surface.mjs +33 -5
- package/tools/agents/providers/rule-deployment-commit.mjs +19 -15
- package/tools/agents/providers/rule-deployment-prepare.mjs +13 -3
- package/tools/agents/providers/rule-projection.mjs +3 -0
- package/tools/agents/providers/rule-startup.mjs +3 -3
- package/tools/agents/use-rule-selection.mjs +17 -0
- package/tools/ralph-external/lib/worker-invocation-processes.mjs +4 -2
- package/tools/ralph-external/lib/worker-termination.mjs +15 -8
- package/vscode-extension/schemas/aiwg.config.v1.json +2 -4
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
// Prove monotone gate tightening across inheritance and project floors.
|
|
2
|
+
import { ceilingDecision } from './lattice.js';
|
|
3
|
+
import { canonicalJson } from '../security/artifact-trust.js';
|
|
4
|
+
import { GateRegistryError } from './registry-error.js';
|
|
5
|
+
import { isParamRef, resolveNumberDefault } from './pack-validation.js';
|
|
6
|
+
const fail = (message) => { throw new GateRegistryError(message); };
|
|
7
|
+
/** Resolve a `$param` threshold against pack parameter defaults. Null when no default pins it. */
|
|
8
|
+
export function resolveThresholdDefault(gate, params) {
|
|
9
|
+
if (gate.threshold === undefined)
|
|
10
|
+
return null;
|
|
11
|
+
if (gate.threshold.value !== undefined)
|
|
12
|
+
return gate.threshold.value;
|
|
13
|
+
if (gate.threshold.param === undefined)
|
|
14
|
+
return null;
|
|
15
|
+
return params[gate.threshold.param]?.default ?? null;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Scope-tightening rules per gate kind. A scope change is a tightening only when
|
|
19
|
+
* the child observes every slice the parent observes under every possible
|
|
20
|
+
* binding inventory (so a breach the parent sees can never go unobserved)
|
|
21
|
+
* and every world that fails the child also fails the parent:
|
|
22
|
+
* - `listed` may only widen (more slices fail in a superset of worlds);
|
|
23
|
+
* - `pooled` sets are fixed;
|
|
24
|
+
* - `listed -> each` widens coverage to the whole binding inventory, so the
|
|
25
|
+
* child's `except` must exclude none of the parent's listed slices;
|
|
26
|
+
* - `all -> each` covers the whole inventory only with no exceptions, and is a
|
|
27
|
+
* tightening only when per-slice checks are strictly harder than the pooled
|
|
28
|
+
* check (`count-min`, `minimum-n`); for `count-max` the pooled bound is
|
|
29
|
+
* strictly harder (pooled<=2 implies per-slice<=2, not vice versa), and for
|
|
30
|
+
* interval/paired/bootstrap/value gates pooled and per-slice bounds are
|
|
31
|
+
* incomparable — so the change is rejected for every other kind.
|
|
32
|
+
* Every other cross-mode change crosses aggregation or drops coverage and is
|
|
33
|
+
* rejected for every kind.
|
|
34
|
+
*/
|
|
35
|
+
function assertScopeTightens(parent, child) {
|
|
36
|
+
const from = parent.scope;
|
|
37
|
+
const to = child.scope;
|
|
38
|
+
if (from.mode === to.mode) {
|
|
39
|
+
if (to.mode === 'listed' || to.mode === 'pooled') {
|
|
40
|
+
const before = new Set(from.slices ?? []);
|
|
41
|
+
const after = new Set(to.slices ?? []);
|
|
42
|
+
if (to.mode === 'listed') {
|
|
43
|
+
// A wider listed set fails in a superset of worlds, so it tightens.
|
|
44
|
+
for (const slice of before) {
|
|
45
|
+
if (!after.has(slice))
|
|
46
|
+
fail(`gate ${child.id} scope listed may not drop inherited slices`);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
else if (after.size !== before.size || [...after].some(slice => !before.has(slice))) {
|
|
50
|
+
fail(`gate ${child.id} scope pooled may not change its slice set`);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
const beforeExcept = new Set(from.except ?? []);
|
|
54
|
+
for (const slice of to.except ?? []) {
|
|
55
|
+
if (!beforeExcept.has(slice))
|
|
56
|
+
fail(`gate ${child.id} scope may only narrow inherited exceptions`);
|
|
57
|
+
}
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
if (from.mode === 'listed' && to.mode === 'each') {
|
|
61
|
+
const excluded = new Set(to.except ?? []);
|
|
62
|
+
for (const slice of from.slices ?? []) {
|
|
63
|
+
if (excluded.has(slice))
|
|
64
|
+
fail(`gate ${child.id} scope listed -> each may not except inherited slice '${slice}'`);
|
|
65
|
+
}
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
if (from.mode === 'all' && to.mode === 'each'
|
|
69
|
+
&& (child.kind === 'count-min' || child.kind === 'minimum-n')) {
|
|
70
|
+
// `all` watches the whole inventory: any exception drops a watched slice.
|
|
71
|
+
if ((to.except ?? []).length)
|
|
72
|
+
fail(`gate ${child.id} scope all -> each may not except slices`);
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
fail(`gate ${child.id} scope change ${from.mode} -> ${to.mode} is not a monotone tightening`);
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Proves monotone tightening of a child gate over its parent. Any loosening —
|
|
79
|
+
* a relaxed threshold, a literal rewritten as a bindable parameter, a renamed
|
|
80
|
+
* parameter, a lowered minimumN, a demoted outcome, a widened scope
|
|
81
|
+
* or a changed statistic — is a load error.
|
|
82
|
+
*/
|
|
83
|
+
export function assertGateTightens(parent, child, params) {
|
|
84
|
+
if (parent.kind !== child.kind)
|
|
85
|
+
fail(`gate ${child.id} may not change kind ${parent.kind} -> ${child.kind}`);
|
|
86
|
+
if (canonicalJson(parent.metric ?? null) !== canonicalJson(child.metric ?? null)) {
|
|
87
|
+
fail(`gate ${child.id} may not change its metric reference`);
|
|
88
|
+
}
|
|
89
|
+
if (parent.direction !== child.direction)
|
|
90
|
+
fail(`gate ${child.id} may not change its tightening direction`);
|
|
91
|
+
const parentStatistic = parent.statistic;
|
|
92
|
+
const childStatistic = child.statistic;
|
|
93
|
+
if (canonicalJson({ ...parentStatistic, levelBps: 0, marginBps: 0 })
|
|
94
|
+
!== canonicalJson({ ...childStatistic, levelBps: 0, marginBps: 0 })) {
|
|
95
|
+
fail(`gate ${child.id} may not change its statistic (levelBps and marginBps aside)`);
|
|
96
|
+
}
|
|
97
|
+
// A literal level is a pinned bound: rewriting it as a parameter hands the
|
|
98
|
+
// bound to the binding, whose allowed range is wider than the literal.
|
|
99
|
+
const parentLevel = parentStatistic?.levelBps;
|
|
100
|
+
const childLevel = childStatistic?.levelBps;
|
|
101
|
+
if (typeof parentLevel === 'number' && isParamRef(childLevel)) {
|
|
102
|
+
fail(`gate ${child.id} may not convert a literal levelBps into a parameter`);
|
|
103
|
+
}
|
|
104
|
+
if (isParamRef(parentLevel) && isParamRef(childLevel) && parentLevel.param !== childLevel.param) {
|
|
105
|
+
fail(`gate ${child.id} may not rename its levelBps parameter`);
|
|
106
|
+
}
|
|
107
|
+
const levelBefore = parentLevel === undefined ? undefined : resolveNumberDefault(parentLevel, params, 'level');
|
|
108
|
+
const levelAfter = childLevel === undefined ? undefined : resolveNumberDefault(childLevel, params, 'level');
|
|
109
|
+
if (levelBefore === null || levelAfter === null) {
|
|
110
|
+
if (canonicalJson(parentLevel ?? null) !== canonicalJson(childLevel ?? null)) {
|
|
111
|
+
fail(`gate ${child.id} levelBps change is unresolvable without parameter defaults`);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
else if ((levelAfter ?? levelBefore) !== undefined && (levelAfter ?? 0) < (levelBefore ?? 0)) {
|
|
115
|
+
fail(`gate ${child.id} may only raise levelBps`);
|
|
116
|
+
}
|
|
117
|
+
if ((parentStatistic?.mode ?? 'non-inferiority') !== (childStatistic?.mode ?? 'non-inferiority')) {
|
|
118
|
+
fail(`gate ${child.id} may not change its paired mode`);
|
|
119
|
+
}
|
|
120
|
+
const parentMargin = parentStatistic?.marginBps;
|
|
121
|
+
const childMargin = childStatistic?.marginBps;
|
|
122
|
+
if (typeof parentMargin === 'number' && isParamRef(childMargin)) {
|
|
123
|
+
fail(`gate ${child.id} may not convert a literal marginBps into a parameter`);
|
|
124
|
+
}
|
|
125
|
+
if (isParamRef(parentMargin) && isParamRef(childMargin) && parentMargin.param !== childMargin.param) {
|
|
126
|
+
fail(`gate ${child.id} may not rename its marginBps parameter`);
|
|
127
|
+
}
|
|
128
|
+
const marginBefore = resolveNumberDefault(parentMargin ?? 0, params, 'value');
|
|
129
|
+
const marginAfter = resolveNumberDefault(childMargin ?? 0, params, 'value');
|
|
130
|
+
if (marginBefore === null || marginAfter === null) {
|
|
131
|
+
if (canonicalJson(parentMargin ?? null) !== canonicalJson(childMargin ?? null)) {
|
|
132
|
+
fail(`gate ${child.id} marginBps change is unresolvable without parameter defaults`);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
else if (marginAfter < marginBefore) {
|
|
136
|
+
fail(`gate ${child.id} may only raise marginBps`);
|
|
137
|
+
}
|
|
138
|
+
// A literal threshold is a pinned bound. Rewriting it as a parameter hands the
|
|
139
|
+
// bound to the binding, whose allowed range (e.g. 0..10000 bps) is wider than
|
|
140
|
+
// the literal — a loosening no default-equality check can see. Forbid it.
|
|
141
|
+
if (parent.threshold?.value !== undefined && child.threshold?.param !== undefined) {
|
|
142
|
+
fail(`gate ${child.id} may not convert a literal threshold into a parameter`);
|
|
143
|
+
}
|
|
144
|
+
// Renaming a parameter rebinds the gate to a fresh default and range. Params
|
|
145
|
+
// may only keep their name with a tighter-or-equal default.
|
|
146
|
+
if (parent.threshold?.param !== undefined && child.threshold?.param !== undefined
|
|
147
|
+
&& parent.threshold.param !== child.threshold.param) {
|
|
148
|
+
fail(`gate ${child.id} may not rename its threshold parameter`);
|
|
149
|
+
}
|
|
150
|
+
const before = resolveThresholdDefault(parent, params);
|
|
151
|
+
const after = resolveThresholdDefault(child, params);
|
|
152
|
+
if (before === null || after === null) {
|
|
153
|
+
if (canonicalJson(parent.threshold ?? null) !== canonicalJson(child.threshold ?? null)) {
|
|
154
|
+
fail(`gate ${child.id} threshold change is unresolvable without parameter defaults`);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
else if (child.direction === 'lower-is-stricter' ? after > before : after < before) {
|
|
158
|
+
fail(`gate ${child.id} threshold ${before} -> ${after} loosens direction ${child.direction}`);
|
|
159
|
+
}
|
|
160
|
+
if (typeof parent.minimumN === 'number' && isParamRef(child.minimumN)) {
|
|
161
|
+
fail(`gate ${child.id} may not convert a literal minimumN into a parameter`);
|
|
162
|
+
}
|
|
163
|
+
if (isParamRef(parent.minimumN) && isParamRef(child.minimumN) && parent.minimumN.param !== child.minimumN.param) {
|
|
164
|
+
fail(`gate ${child.id} may not rename its minimumN parameter`);
|
|
165
|
+
}
|
|
166
|
+
const minimumBefore = parent.minimumN === undefined ? 0 : resolveNumberDefault(parent.minimumN, params, 'count');
|
|
167
|
+
const minimumAfter = child.minimumN === undefined ? 0 : resolveNumberDefault(child.minimumN, params, 'count');
|
|
168
|
+
if (minimumBefore === null || minimumAfter === null) {
|
|
169
|
+
if (canonicalJson(parent.minimumN ?? null) !== canonicalJson(child.minimumN ?? null)) {
|
|
170
|
+
fail(`gate ${child.id} minimumN change is unresolvable without parameter defaults`);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
else if (minimumAfter < minimumBefore) {
|
|
174
|
+
fail(`gate ${child.id} may only raise minimumN`);
|
|
175
|
+
}
|
|
176
|
+
if (ceilingDecision(child.onFail, parent.onFail) !== child.onFail) {
|
|
177
|
+
fail(`gate ${child.id} may not demote onFail ROLLBACK -> HOLD`);
|
|
178
|
+
}
|
|
179
|
+
// Insufficient evidence always holds: ROLLBACK needs an observed blocking
|
|
180
|
+
// failure, so neither side may name it. Checked here as well as in schema
|
|
181
|
+
// and pack validation because this pure function is the tightening gate.
|
|
182
|
+
if ((parent.onInsufficient ?? 'HOLD') !== 'HOLD' || (child.onInsufficient ?? 'HOLD') !== 'HOLD') {
|
|
183
|
+
fail(`gate ${child.id} onInsufficient must be HOLD: insufficient evidence never rolls back`);
|
|
184
|
+
}
|
|
185
|
+
if (parent.floor === true && child.floor !== true)
|
|
186
|
+
fail(`gate ${child.id} is a floor gate and cannot be un-floored`);
|
|
187
|
+
assertScopeTightens(parent, child);
|
|
188
|
+
const afterEvidence = new Set(child.evidence?.required ?? []);
|
|
189
|
+
for (const id of parent.evidence?.required ?? []) {
|
|
190
|
+
if (!afterEvidence.has(id))
|
|
191
|
+
fail(`gate ${child.id} may not drop required evidence ${id}`);
|
|
192
|
+
}
|
|
193
|
+
if (canonicalJson(parent.predicate ?? null) !== canonicalJson(child.predicate ?? null)) {
|
|
194
|
+
fail(`gate ${child.id} may not change its predicate`);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
//# sourceMappingURL=pack-tightening.js.map
|
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
// Validate gate declarations and resolve numeric parameter defaults.
|
|
2
|
+
import { GateRegistryError } from './registry-error.js';
|
|
3
|
+
const fail = (message) => { throw new GateRegistryError(message); };
|
|
4
|
+
const STATISTICAL_KINDS = ['interval-bound', 'paired-difference', 'bootstrap-bound'];
|
|
5
|
+
function checkThresholdBlock(gate, params) {
|
|
6
|
+
const needsThreshold = gate.kind === 'interval-bound' || gate.kind === 'bootstrap-bound'
|
|
7
|
+
|| gate.kind === 'count-max' || gate.kind === 'count-min' || gate.kind === 'value-threshold';
|
|
8
|
+
const threshold = gate.threshold;
|
|
9
|
+
if (threshold === undefined) {
|
|
10
|
+
if (needsThreshold)
|
|
11
|
+
fail(`gate ${gate.id} of kind ${gate.kind} requires a threshold`);
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
if (!needsThreshold)
|
|
15
|
+
fail(`gate ${gate.id} of kind ${gate.kind} must not carry a threshold`);
|
|
16
|
+
const param = threshold.param === undefined ? undefined : params[threshold.param];
|
|
17
|
+
if (threshold.param !== undefined && param === undefined)
|
|
18
|
+
fail(`gate ${gate.id} references unknown parameter '${threshold.param}'`);
|
|
19
|
+
const expectedParamType = gate.kind === 'interval-bound' || gate.kind === 'bootstrap-bound' ? 'bps'
|
|
20
|
+
: gate.kind === 'count-max' || gate.kind === 'count-min' ? 'count' : 'value';
|
|
21
|
+
if (param !== undefined && param.type !== expectedParamType) {
|
|
22
|
+
fail(`gate ${gate.id} parameter '${threshold.param}' must have type ${expectedParamType}`);
|
|
23
|
+
}
|
|
24
|
+
if (threshold.value !== undefined) {
|
|
25
|
+
if (!Number.isFinite(threshold.value))
|
|
26
|
+
fail(`gate ${gate.id} threshold value must be finite`);
|
|
27
|
+
if (expectedParamType === 'bps' && (threshold.value < 0 || threshold.value > 10000)) {
|
|
28
|
+
fail(`gate ${gate.id} threshold must be within 0..10000 bps`);
|
|
29
|
+
}
|
|
30
|
+
if (expectedParamType === 'count' && (!Number.isSafeInteger(threshold.value) || threshold.value < 0)) {
|
|
31
|
+
fail(`gate ${gate.id} threshold must be a non-negative integer count`);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
const op = gate.kind === 'count-max' ? 'lte' : gate.kind === 'count-min' ? 'gte' : threshold.op;
|
|
35
|
+
if (gate.kind === 'count-max' && threshold.op !== 'lte')
|
|
36
|
+
fail(`gate ${gate.id} count-max requires op lte`);
|
|
37
|
+
if (gate.kind === 'count-min' && threshold.op !== 'gte')
|
|
38
|
+
fail(`gate ${gate.id} count-min requires op gte`);
|
|
39
|
+
if (gate.kind === 'interval-bound' && gate.statistic?.bound === 'upper' && threshold.op !== 'lte') {
|
|
40
|
+
fail(`gate ${gate.id} upper-bound gates require op lte`);
|
|
41
|
+
}
|
|
42
|
+
if (gate.kind === 'interval-bound' && gate.statistic?.bound === 'lower' && threshold.op !== 'gte') {
|
|
43
|
+
fail(`gate ${gate.id} lower-bound gates require op gte`);
|
|
44
|
+
}
|
|
45
|
+
if (gate.kind === 'value-threshold') {
|
|
46
|
+
if (threshold.op === 'lte' && gate.direction !== 'lower-is-stricter')
|
|
47
|
+
fail(`gate ${gate.id} lte requires direction lower-is-stricter`);
|
|
48
|
+
if (threshold.op === 'gte' && gate.direction !== 'higher-is-stricter')
|
|
49
|
+
fail(`gate ${gate.id} gte requires direction higher-is-stricter`);
|
|
50
|
+
}
|
|
51
|
+
if (gate.kind === 'interval-bound' || gate.kind === 'bootstrap-bound') {
|
|
52
|
+
if (op === 'lte' && gate.direction !== 'lower-is-stricter')
|
|
53
|
+
fail(`gate ${gate.id} upper-bound gates require direction lower-is-stricter`);
|
|
54
|
+
if (op === 'gte' && gate.direction !== 'higher-is-stricter')
|
|
55
|
+
fail(`gate ${gate.id} lower-bound gates require direction higher-is-stricter`);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
export const isParamRef = (value) => Boolean(value) && typeof value === 'object' && !Array.isArray(value)
|
|
59
|
+
&& typeof value.param === 'string';
|
|
60
|
+
/**
|
|
61
|
+
* Resolve a literal-or-parameter number against pack parameter defaults.
|
|
62
|
+
* Returns the default for a `{param}` reference, or null when the reference
|
|
63
|
+
* names an unknown parameter, the type mismatches, or no default pins it.
|
|
64
|
+
*/
|
|
65
|
+
export function resolveNumberDefault(value, params, expectedType) {
|
|
66
|
+
if (value === undefined)
|
|
67
|
+
return null;
|
|
68
|
+
if (typeof value === 'number')
|
|
69
|
+
return value;
|
|
70
|
+
if (!isParamRef(value))
|
|
71
|
+
return null;
|
|
72
|
+
const declared = params[value.param];
|
|
73
|
+
if (declared === undefined || declared.type !== expectedType)
|
|
74
|
+
return null;
|
|
75
|
+
return declared.default ?? null;
|
|
76
|
+
}
|
|
77
|
+
/** A literal-or-parameter reference names a known parameter of the expected type. */
|
|
78
|
+
function checkParamRef(gateId, value, params, expectedType, what) {
|
|
79
|
+
if (value === undefined || typeof value === 'number')
|
|
80
|
+
return;
|
|
81
|
+
if (!isParamRef(value) || params[value.param] === undefined) {
|
|
82
|
+
fail(`gate ${gateId} ${what} references unknown parameter '${value?.param}'`);
|
|
83
|
+
}
|
|
84
|
+
if (params[value.param].type !== expectedType) {
|
|
85
|
+
fail(`gate ${gateId} ${what} parameter '${value.param}' must have type ${expectedType}`);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
/** Signed margins use value parameters; mode constrains the resolved integer range. */
|
|
89
|
+
export function checkPairedMargin(gateId, mode, margin) {
|
|
90
|
+
if (!Number.isSafeInteger(margin) || margin < -10000 || margin > 10000) {
|
|
91
|
+
fail(`gate ${gateId} marginBps must be an integer within -10000..10000`);
|
|
92
|
+
}
|
|
93
|
+
if (mode === 'non-inferiority' && margin > 0)
|
|
94
|
+
fail(`gate ${gateId} non-inferiority marginBps must be non-positive`);
|
|
95
|
+
if (mode === 'superiority' && margin < 0)
|
|
96
|
+
fail(`gate ${gateId} superiority marginBps must be non-negative`);
|
|
97
|
+
}
|
|
98
|
+
/** Statistic coherence per kind. Irrelevant statistic fields are rejected so confused authoring fails at load. */
|
|
99
|
+
function checkStatisticBlock(gate, params) {
|
|
100
|
+
const statistic = gate.statistic;
|
|
101
|
+
if (statistic === undefined) {
|
|
102
|
+
if (STATISTICAL_KINDS.includes(gate.kind)) {
|
|
103
|
+
fail(`gate ${gate.id} of kind ${gate.kind} requires a statistic`);
|
|
104
|
+
}
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
if (!STATISTICAL_KINDS.includes(gate.kind)) {
|
|
108
|
+
fail(`gate ${gate.id} of kind ${gate.kind} must not carry a statistic`);
|
|
109
|
+
}
|
|
110
|
+
if (statistic.kind !== gate.kind)
|
|
111
|
+
fail(`gate ${gate.id} statistic kind must match the gate kind`);
|
|
112
|
+
const { method, bound, levelBps, mode, marginBps, seed, resamples, bounds } = statistic;
|
|
113
|
+
if (gate.kind === 'interval-bound') {
|
|
114
|
+
if (method !== undefined && method !== 'wilson' && method !== 'clopper-pearson') {
|
|
115
|
+
fail(`gate ${gate.id} interval-bound method must be wilson or clopper-pearson`);
|
|
116
|
+
}
|
|
117
|
+
if (bound !== 'upper' && bound !== 'lower')
|
|
118
|
+
fail(`gate ${gate.id} interval-bound requires bound upper|lower`);
|
|
119
|
+
if (levelBps === undefined)
|
|
120
|
+
fail(`gate ${gate.id} interval-bound requires levelBps`);
|
|
121
|
+
checkParamRef(gate.id, levelBps, params, 'level', 'levelBps');
|
|
122
|
+
if (mode !== undefined || marginBps !== undefined || seed !== undefined || resamples !== undefined || bounds !== undefined) {
|
|
123
|
+
fail(`gate ${gate.id} interval-bound must not carry mode, margin, seed, resamples or bounds`);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
else if (gate.kind === 'paired-difference') {
|
|
127
|
+
if (method !== undefined && method !== 'newcombe' && method !== 'tango') {
|
|
128
|
+
fail(`gate ${gate.id} paired-difference method must be newcombe or tango`);
|
|
129
|
+
}
|
|
130
|
+
if (bound !== undefined)
|
|
131
|
+
fail(`gate ${gate.id} paired-difference must not carry bound`);
|
|
132
|
+
if (levelBps === undefined)
|
|
133
|
+
fail(`gate ${gate.id} paired-difference requires levelBps`);
|
|
134
|
+
checkParamRef(gate.id, levelBps, params, 'level', 'levelBps');
|
|
135
|
+
const resolvedMode = mode ?? 'non-inferiority';
|
|
136
|
+
if (resolvedMode !== 'non-inferiority' && resolvedMode !== 'superiority')
|
|
137
|
+
fail(`gate ${gate.id} unknown paired mode`);
|
|
138
|
+
if (resolvedMode === 'non-inferiority' && marginBps === undefined)
|
|
139
|
+
fail(`gate ${gate.id} non-inferiority requires marginBps`);
|
|
140
|
+
checkParamRef(gate.id, marginBps, params, 'value', 'marginBps');
|
|
141
|
+
if (isParamRef(marginBps) && params[marginBps.param].direction !== 'higher-is-stricter') {
|
|
142
|
+
fail(`gate ${gate.id} marginBps parameter must be higher-is-stricter`);
|
|
143
|
+
}
|
|
144
|
+
const margin = resolveNumberDefault(marginBps, params, 'value');
|
|
145
|
+
if (margin !== null)
|
|
146
|
+
checkPairedMargin(gate.id, resolvedMode, margin);
|
|
147
|
+
if (seed !== undefined || resamples !== undefined || bounds !== undefined) {
|
|
148
|
+
fail(`gate ${gate.id} paired-difference must not carry seed, resamples or bounds`);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
else {
|
|
152
|
+
if (method !== undefined && method !== 'bootstrap')
|
|
153
|
+
fail(`gate ${gate.id} bootstrap-bound method must be bootstrap`);
|
|
154
|
+
if (bound !== 'upper' && bound !== 'lower')
|
|
155
|
+
fail(`gate ${gate.id} bootstrap-bound requires bound upper|lower`);
|
|
156
|
+
if (levelBps === undefined || seed === undefined || resamples === undefined || bounds === undefined) {
|
|
157
|
+
fail(`gate ${gate.id} bootstrap-bound requires levelBps, seed, resamples and bounds`);
|
|
158
|
+
}
|
|
159
|
+
checkParamRef(gate.id, levelBps, params, 'level', 'levelBps');
|
|
160
|
+
if (mode !== undefined || marginBps !== undefined)
|
|
161
|
+
fail(`gate ${gate.id} bootstrap-bound must not carry mode or margin`);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
function checkParameter(name, parameter) {
|
|
165
|
+
if (parameter.default !== undefined) {
|
|
166
|
+
if (!Number.isFinite(parameter.default))
|
|
167
|
+
fail(`parameter ${name} default must be finite`);
|
|
168
|
+
if (parameter.type === 'bps' && (parameter.default < 0 || parameter.default > 10000)) {
|
|
169
|
+
fail(`parameter ${name} bps default must be within 0..10000`);
|
|
170
|
+
}
|
|
171
|
+
if (parameter.type === 'level' && (!Number.isSafeInteger(parameter.default)
|
|
172
|
+
|| parameter.default <= 5000 || parameter.default >= 9999)) {
|
|
173
|
+
fail(`parameter ${name} level default must be an integer strictly between 5000 and 9999`);
|
|
174
|
+
}
|
|
175
|
+
if (parameter.type === 'count' && (!Number.isSafeInteger(parameter.default) || parameter.default < 0)) {
|
|
176
|
+
fail(`parameter ${name} count default must be a non-negative integer`);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
/** Semantic validation of one fully resolved pack against the provider registry. */
|
|
181
|
+
export function validateResolvedPack(pack, providers) {
|
|
182
|
+
const ids = pack.spec.gates.map(gate => gate.id);
|
|
183
|
+
if (new Set(ids).size !== ids.length)
|
|
184
|
+
fail(`pack ${pack.metadata.id} has duplicate gate ids`);
|
|
185
|
+
const params = pack.spec.parameters ?? {};
|
|
186
|
+
for (const [name, parameter] of Object.entries(params))
|
|
187
|
+
checkParameter(name, parameter);
|
|
188
|
+
for (const [name, metric] of Object.entries(pack.spec.metrics)) {
|
|
189
|
+
if (!providers.has(metric.provider))
|
|
190
|
+
fail(`pack ${pack.metadata.id} metric ${name} names unknown provider ${metric.provider}`);
|
|
191
|
+
const provider = providers.get(metric.provider);
|
|
192
|
+
const declared = provider.metrics[name];
|
|
193
|
+
if (declared === undefined)
|
|
194
|
+
fail(`pack ${pack.metadata.id} metric ${name} is not computed by ${metric.provider}`);
|
|
195
|
+
if (declared.kind !== metric.kind) {
|
|
196
|
+
fail(`pack ${pack.metadata.id} metric ${name} kind ${metric.kind} does not match provider kind ${declared.kind}`);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
for (const gate of pack.spec.gates) {
|
|
200
|
+
if (gate.onFail !== 'HOLD' && gate.onFail !== 'ROLLBACK') {
|
|
201
|
+
fail(`gate ${gate.id} onFail must be HOLD or ROLLBACK, never PROMOTE`);
|
|
202
|
+
}
|
|
203
|
+
// Insufficient evidence always holds: ROLLBACK needs an observed blocking
|
|
204
|
+
// failure, never a shortfall. Rejected here at load, not just in schema.
|
|
205
|
+
if (gate.onInsufficient !== undefined && gate.onInsufficient !== 'HOLD') {
|
|
206
|
+
fail(`gate ${gate.id} onInsufficient must be HOLD: insufficient evidence never rolls back`);
|
|
207
|
+
}
|
|
208
|
+
if (gate.metric !== undefined) {
|
|
209
|
+
const declared = pack.spec.metrics[gate.metric.name];
|
|
210
|
+
if (declared === undefined || declared.provider !== gate.metric.provider) {
|
|
211
|
+
fail(`gate ${gate.id} references undeclared metric ${gate.metric.provider}:${gate.metric.name}`);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
const metricKind = gate.metric === undefined ? undefined : pack.spec.metrics[gate.metric.name]?.kind;
|
|
215
|
+
const expectedKind = gate.kind === 'interval-bound' || gate.kind === 'count-max' || gate.kind === 'count-min' ? 'proportion'
|
|
216
|
+
: gate.kind === 'paired-difference' ? 'paired' : gate.kind === 'bootstrap-bound' ? 'differences'
|
|
217
|
+
: gate.kind === 'value-threshold' ? 'scalar' : gate.kind === 'evidence' ? 'evidence' : undefined;
|
|
218
|
+
if (expectedKind !== undefined && metricKind !== expectedKind) {
|
|
219
|
+
fail(`gate ${gate.id} of kind ${gate.kind} requires a ${expectedKind} metric`);
|
|
220
|
+
}
|
|
221
|
+
checkThresholdBlock(gate, params);
|
|
222
|
+
checkStatisticBlock(gate, params);
|
|
223
|
+
checkParamRef(gate.id, gate.minimumN, params, 'count', 'minimumN');
|
|
224
|
+
if (gate.kind === 'minimum-n') {
|
|
225
|
+
if (gate.minimumN === undefined)
|
|
226
|
+
fail(`gate ${gate.id} minimum-n requires minimumN >= 1`);
|
|
227
|
+
// A default is the enforced minimum, so a defaulted reference must pin
|
|
228
|
+
// at least 1; a defaultless reference is supplied by the binding and an
|
|
229
|
+
// unresolvable value holds at evaluation, never promotes.
|
|
230
|
+
const resolved = resolveNumberDefault(gate.minimumN, params, 'count');
|
|
231
|
+
if (typeof gate.minimumN === 'number' && gate.minimumN < 1) {
|
|
232
|
+
fail(`gate ${gate.id} minimum-n requires minimumN >= 1`);
|
|
233
|
+
}
|
|
234
|
+
if (isParamRef(gate.minimumN) && params[gate.minimumN.param]?.default !== undefined && (resolved ?? 0) < 1) {
|
|
235
|
+
fail(`gate ${gate.id} minimum-n requires minimumN >= 1`);
|
|
236
|
+
}
|
|
237
|
+
if (metricKind === 'evidence')
|
|
238
|
+
fail(`gate ${gate.id} minimum-n cannot observe an evidence metric`);
|
|
239
|
+
}
|
|
240
|
+
else if (gate.minimumN !== undefined && typeof gate.minimumN === 'number'
|
|
241
|
+
&& (!Number.isSafeInteger(gate.minimumN) || gate.minimumN < 0)) {
|
|
242
|
+
fail(`gate ${gate.id} minimumN must be a non-negative integer`);
|
|
243
|
+
}
|
|
244
|
+
if (gate.kind === 'evidence' && (gate.evidence === undefined || !gate.evidence.required.length)) {
|
|
245
|
+
fail(`gate ${gate.id} evidence requires a nonempty required list`);
|
|
246
|
+
}
|
|
247
|
+
if (gate.kind !== 'evidence' && gate.evidence !== undefined)
|
|
248
|
+
fail(`gate ${gate.id} of kind ${gate.kind} must not carry evidence`);
|
|
249
|
+
if (gate.kind !== 'predicate' && gate.predicate !== undefined)
|
|
250
|
+
fail(`gate ${gate.id} of kind ${gate.kind} must not carry a predicate`);
|
|
251
|
+
if ((gate.scope.mode === 'listed' || gate.scope.mode === 'pooled')
|
|
252
|
+
&& (gate.scope.slices === undefined || !gate.scope.slices.length)) {
|
|
253
|
+
fail(`gate ${gate.id} scope ${gate.scope.mode} requires a nonempty slices list`);
|
|
254
|
+
}
|
|
255
|
+
// `except` is honoured only by `each` (per-slice minus exclusions). Any other
|
|
256
|
+
// mode silently ignoring it would be a fail-open scoping bug, so it is a load error.
|
|
257
|
+
if (gate.scope.except !== undefined && gate.scope.mode !== 'each') {
|
|
258
|
+
fail(`gate ${gate.id} scope except is only allowed with mode each`);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
//# sourceMappingURL=pack-validation.js.map
|