@aiwg/cli 2026.10.16 → 2026.10.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (128) hide show
  1. package/dist/src/artifacts/corpus-tools/resolve.js +21 -4
  2. package/dist/src/artifacts/query-engine-corpus.js +217 -0
  3. package/dist/src/artifacts/query-engine-discover-output.js +229 -0
  4. package/dist/src/artifacts/query-engine-discover.js +285 -0
  5. package/dist/src/artifacts/query-engine-entries.js +188 -0
  6. package/dist/src/artifacts/query-engine-index.js +249 -0
  7. package/dist/src/artifacts/query-engine-matching.js +143 -0
  8. package/dist/src/artifacts/query-engine-options.js +2 -0
  9. package/dist/src/artifacts/query-engine-rules.js +202 -0
  10. package/dist/src/artifacts/query-engine-scoring.js +436 -0
  11. package/dist/src/artifacts/query-engine-show-card.js +194 -0
  12. package/dist/src/artifacts/query-engine-show-load.js +211 -0
  13. package/dist/src/artifacts/query-engine-show.js +300 -0
  14. package/dist/src/artifacts/query-engine.js +7 -2576
  15. package/dist/src/cli/handlers/mc-agents.js +111 -0
  16. package/dist/src/cli/handlers/mc-args.js +54 -0
  17. package/dist/src/cli/handlers/mc-control.js +227 -0
  18. package/dist/src/cli/handlers/mc-dispatch.js +203 -0
  19. package/dist/src/cli/handlers/mc-help.js +171 -0
  20. package/dist/src/cli/handlers/mc-run.js +343 -0
  21. package/dist/src/cli/handlers/mc-session.js +138 -0
  22. package/dist/src/cli/handlers/mc-status.js +258 -0
  23. package/dist/src/cli/handlers/mc-summary.js +43 -0
  24. package/dist/src/cli/handlers/mc-types.js +3 -0
  25. package/dist/src/cli/handlers/mc-worker.js +205 -0
  26. package/dist/src/cli/handlers/mc.js +12 -1665
  27. package/dist/src/cli/handlers/models-refusal.js +13 -0
  28. package/dist/src/cli/handlers/models.js +2 -1
  29. package/dist/src/cli/handlers/remove-bundled.js +133 -0
  30. package/dist/src/cli/handlers/remove-options.js +31 -0
  31. package/dist/src/cli/handlers/remove-user.js +174 -0
  32. package/dist/src/cli/handlers/remove.js +201 -0
  33. package/dist/src/cli/handlers/subcommands-bundles.js +257 -0
  34. package/dist/src/cli/handlers/subcommands-discovery.js +165 -0
  35. package/dist/src/cli/handlers/subcommands-list-format.js +129 -0
  36. package/dist/src/cli/handlers/subcommands-list.js +250 -0
  37. package/dist/src/cli/handlers/subcommands-plugins.js +213 -0
  38. package/dist/src/cli/handlers/subcommands-quickref.js +58 -0
  39. package/dist/src/cli/handlers/subcommands-rlm.js +113 -0
  40. package/dist/src/cli/handlers/subcommands-services.js +66 -0
  41. package/dist/src/cli/handlers/subcommands-storage.js +259 -0
  42. package/dist/src/cli/handlers/subcommands.js +18 -1984
  43. package/dist/src/cli/scope-resolver.js +1 -142
  44. package/dist/src/cli/user-scope-mirror.js +173 -0
  45. package/dist/src/config/dispatch-host-thresholds.js +2 -0
  46. package/dist/src/config/dispatch-thresholds-runtime.mjs +4 -0
  47. package/dist/src/config/host-resource-report.d.mts +5 -0
  48. package/dist/src/config/host-resource-report.mjs +36 -6
  49. package/dist/src/config/host-resource-runtime.d.mts +3 -0
  50. package/dist/src/config/host-resource-runtime.mjs +9 -6
  51. package/dist/src/decision/ensemble-study/artifacts.js +7 -0
  52. package/dist/src/decision/ensemble-study/gate-policy.js +58 -0
  53. package/dist/src/decision/ensemble-study/gates.js +78 -0
  54. package/dist/src/decision/ensemble-study/protocol.js +18 -21
  55. package/dist/src/decision/ensemble-study/score.js +3 -2
  56. package/dist/src/decision/ensemble-study/statistics.js +7 -26
  57. package/dist/src/decision/sensitivity/comparative-gates.js +135 -0
  58. package/dist/src/decision/sensitivity/comparative.js +18 -41
  59. package/dist/src/extensions/claude-hooks-installer.js +18 -0
  60. package/dist/src/gates/evaluate.js +2 -358
  61. package/dist/src/gates/observations.js +363 -0
  62. package/dist/src/gates/pack-composition.js +270 -0
  63. package/dist/src/gates/pack-tightening.js +197 -0
  64. package/dist/src/gates/pack-validation.js +262 -0
  65. package/dist/src/gates/registry-error.js +5 -0
  66. package/dist/src/gates/registry.js +13 -685
  67. package/dist/src/mcp/json-document.mjs +29 -0
  68. package/dist/src/mcp/muse-native-config.mjs +1 -28
  69. package/dist/src/mission-protocol/worker-review-gate.js +7 -0
  70. package/dist/src/models/worker-plan.js +5 -5
  71. package/dist/src/plugin/command-ownership.js +34 -0
  72. package/dist/src/plugin/skill-command-frontmatter.js +197 -0
  73. package/dist/src/plugin/skill-command-translator.js +6 -232
  74. package/dist/src/providers/context-output-ownership.js +26 -0
  75. package/dist/src/providers/deployment-ownership.d.mts +19 -0
  76. package/dist/src/providers/deployment-ownership.mjs +226 -0
  77. package/dist/src/providers/deployment-removal.js +200 -0
  78. package/dist/src/providers/removal-transaction.js +86 -0
  79. package/dist/src/providers/settings-document.d.mts +3 -0
  80. package/dist/src/providers/settings-document.mjs +47 -0
  81. package/dist/src/providers/settings-removal.js +190 -0
  82. package/dist/src/providers/skill-ownership.d.mts +19 -2
  83. package/dist/src/providers/skill-ownership.mjs +12 -4
  84. package/dist/src/providers/transformation-receipt-integration.js +15 -271
  85. package/dist/src/providers/transformation-receipt-outputs.js +99 -0
  86. package/dist/src/providers/transformation-receipt-source.js +194 -0
  87. package/dist/src/research/identity.js +8 -2
  88. package/dist/src/research/reference-match.js +42 -7
  89. package/dist/src/rules/activation.mjs +15 -6
  90. package/dist/src/rules/core-startup.mjs +2 -2
  91. package/dist/src/serve/mission-conductor.js +4 -0
  92. package/dist/src/serve/mission-summary.js +56 -0
  93. package/dist/src/smiths/context-pipeline/aiwg-md.js +23 -0
  94. package/dist/src/smiths/context-pipeline/context-file-safety.js +3 -0
  95. package/dist/src/smiths/context-pipeline/generator.js +1 -1
  96. package/dist/src/smiths/hook-bridge/index.js +9 -0
  97. package/package.json +4 -1
  98. package/schemas/decision/D17StudyProtocol.v1.schema.json +39 -67
  99. package/tools/agents/deploy-agents.mjs +16 -677
  100. package/tools/agents/deploy-command-mirrors.mjs +229 -0
  101. package/tools/agents/deploy-options.mjs +258 -0
  102. package/tools/agents/deploy-support.mjs +165 -0
  103. package/tools/agents/providers/base-addon-discovery.mjs +139 -0
  104. package/tools/agents/providers/base-behaviors.mjs +168 -0
  105. package/tools/agents/providers/base-context.mjs +205 -0
  106. package/tools/agents/providers/base-contract.mjs +116 -0
  107. package/tools/agents/providers/base-files.mjs +252 -0
  108. package/tools/agents/providers/base-flat-artifacts.mjs +233 -0
  109. package/tools/agents/providers/base-framework-discovery.mjs +309 -0
  110. package/tools/agents/providers/base-frontmatter.mjs +196 -0
  111. package/tools/agents/providers/base-inventory.mjs +269 -0
  112. package/tools/agents/providers/base-kernel-skills.mjs +354 -0
  113. package/tools/agents/providers/base-migrations.mjs +258 -0
  114. package/tools/agents/providers/base-models-platforms.mjs +273 -0
  115. package/tools/agents/providers/base-rule-index.mjs +450 -0
  116. package/tools/agents/providers/base-runtime.mjs +60 -0
  117. package/tools/agents/providers/base-skill-copy.mjs +273 -0
  118. package/tools/agents/providers/base.mjs +16 -3364
  119. package/tools/agents/providers/claude-post-deploy.mjs +10 -2
  120. package/tools/agents/providers/hermes-startup.mjs +0 -5
  121. package/tools/agents/providers/muse.mjs +7 -2
  122. package/tools/agents/providers/rule-delivery-surface.mjs +31 -4
  123. package/tools/agents/providers/rule-deployment-commit.mjs +19 -15
  124. package/tools/agents/providers/rule-deployment-prepare.mjs +11 -2
  125. package/tools/agents/providers/rule-projection.mjs +3 -0
  126. package/tools/ralph-external/lib/worker-invocation-processes.mjs +4 -2
  127. package/tools/ralph-external/lib/worker-termination.mjs +15 -8
  128. package/vscode-extension/schemas/aiwg.config.v1.json +2 -4
@@ -1,15 +1,10 @@
1
+ // Validate pinned inputs and combine per-gate outcomes into a deterministic report.
2
+ import { seriesFor, metricKindOf, expandScope, evaluateObservation } from './observations.js';
1
3
  import { ceilingDecision, maxOutcome } from './lattice.js';
2
4
  import { evaluateUpstreamCeiling } from './upstream-ceiling.js';
3
5
  import { artifactDigest } from '../decision/validate.js';
4
- import { evaluatePredicate } from '../decision/predicates.js';
5
- import { clopperPearsonInterval } from './stats/clopper-pearson.js';
6
- import { wilsonScoreInterval } from './stats/binomial.js';
7
- import { pairedMeanDifferenceBootstrap } from './stats/bootstrap.js';
8
- import { PairedDifferenceError } from './stats/error.js';
9
- import { pairedBinaryDifferenceInterval, pairedNonInferiority } from './stats/paired.js';
10
6
  import { GateRegistry, authoredGatePacksOf, gateProvidersOf, resolveGateBinding } from './registry.js';
11
7
  import { GATE_PROVIDER_DEFAULT_TIMEOUT_MS, GATE_PROVIDER_MAX_OUTPUT_BYTES, deriveIsolatedSeed, isLoaderIssuedProvider, runIsolatedProviderSync, sealProviderSection, } from './providers/loader.js';
12
- import { qualifyGateParameter } from './types.js';
13
8
  export class GateEvaluationError extends Error {
14
9
  constructor(message) { super(message); this.name = 'GateEvaluationError'; }
15
10
  }
@@ -45,357 +40,6 @@ export function sealGateHoldout(input) {
45
40
  return { ...payload, digest: artifactDigest(payload) };
46
41
  }
47
42
  const fail = (message) => { throw new GateEvaluationError(message); };
48
- const isRecord = (value) => Boolean(value) && typeof value === 'object' && !Array.isArray(value);
49
- function supportOf(observation) {
50
- const n = observation?.n;
51
- return typeof n === 'number' && Number.isSafeInteger(n) && n >= 0 ? n : null;
52
- }
53
- function poolObservations(kind, observations) {
54
- if (!observations.length)
55
- return null;
56
- if (kind === 'proportion') {
57
- let n = 0;
58
- let events = 0;
59
- for (const observation of observations) {
60
- if (supportOf(observation) === null || typeof observation.events !== 'number'
61
- || !Number.isSafeInteger(observation.events) || observation.events < 0)
62
- return null;
63
- if (observation.events > observation.n)
64
- return null;
65
- n += observation.n;
66
- events += observation.events;
67
- }
68
- return { n, events };
69
- }
70
- if (kind === 'paired') {
71
- const total = { both: 0, candidateOnly: 0, baselineOnly: 0, neither: 0 };
72
- let n = 0;
73
- for (const observation of observations) {
74
- const cells = isRecord(observation?.paired)
75
- ? ['both', 'candidateOnly', 'baselineOnly', 'neither'].map(key => observation.paired[key])
76
- : [];
77
- if (supportOf(observation) === null || cells.length !== 4
78
- || cells.some(cell => !Number.isSafeInteger(cell) || cell < 0)) {
79
- return null;
80
- }
81
- const [both, candidateOnly, baselineOnly, neither] = cells;
82
- // The counted support must equal the cell sums; a disagreement is unknown, fail closed.
83
- if (observation.n !== both + candidateOnly + baselineOnly + neither)
84
- return null;
85
- n += observation.n;
86
- total.both += both;
87
- total.candidateOnly += candidateOnly;
88
- total.baselineOnly += baselineOnly;
89
- total.neither += neither;
90
- }
91
- return { n, paired: total };
92
- }
93
- if (kind === 'scalar') {
94
- let n = 0;
95
- let weighted = 0;
96
- for (const observation of observations) {
97
- if (supportOf(observation) === null || typeof observation.value !== 'number' || !Number.isFinite(observation.value))
98
- return null;
99
- n += observation.n;
100
- weighted += observation.n * observation.value;
101
- }
102
- return n === 0 ? null : { n, value: weighted / n };
103
- }
104
- if (kind === 'differences') {
105
- const differences = [];
106
- let n = 0;
107
- for (const observation of observations) {
108
- if (supportOf(observation) === null || !Array.isArray(observation.differences)
109
- || observation.differences.some(value => typeof value !== 'number' || !Number.isFinite(value)))
110
- return null;
111
- if (observation.n !== observation.differences.length)
112
- return null;
113
- n += observation.n;
114
- differences.push(...observation.differences);
115
- }
116
- return { n, differences };
117
- }
118
- if (kind === 'evidence') {
119
- const available = observations.flatMap(observation => observation?.available ?? []);
120
- if (observations.some(observation => !Array.isArray(observation?.available)))
121
- return null;
122
- return { available };
123
- }
124
- return null;
125
- }
126
- function seriesFor(gate, pack, metrics) {
127
- if (gate.metric === undefined)
128
- return null;
129
- const declared = pack.resolved.spec.metrics[gate.metric.name];
130
- if (declared === undefined || declared.provider !== gate.metric.provider)
131
- return null;
132
- return metrics.providers[gate.metric.provider]?.metrics[gate.metric.name] ?? null;
133
- }
134
- function metricKindOf(gate, pack) {
135
- if (gate.metric === undefined)
136
- return '';
137
- return pack.resolved.spec.metrics[gate.metric.name]?.kind ?? '';
138
- }
139
- function expandScope(gate, kind, series, slices) {
140
- const mode = gate.scope.mode;
141
- if (mode === 'all')
142
- return [{ slice: null, observation: series?.pooled ?? null }];
143
- if (mode === 'pooled') {
144
- const observations = (gate.scope.slices ?? []).map(slice => series?.bySlice[slice] ?? null);
145
- if (observations.some(observation => observation === null)) {
146
- return [{ slice: null, observation: null }];
147
- }
148
- return [{ slice: null, observation: poolObservations(kind, observations) }];
149
- }
150
- const excluded = new Set(gate.scope.except ?? []);
151
- const names = mode === 'each' ? slices.filter(slice => !excluded.has(slice)) : (gate.scope.slices ?? []);
152
- return names.map(slice => ({ slice, observation: series?.bySlice[slice] ?? null }));
153
- }
154
- function pairedCells(observation) {
155
- if (!isRecord(observation?.paired))
156
- return null;
157
- const cells = ['both', 'candidateOnly', 'baselineOnly', 'neither'].map(key => observation.paired[key]);
158
- if (cells.some(cell => !Number.isSafeInteger(cell) || cell < 0))
159
- return null;
160
- const [both, candidateOnly, baselineOnly, neither] = cells;
161
- return { both, candidateOnly, baselineOnly, neither };
162
- }
163
- /**
164
- * Resolve a literal-or-parameter gate number against the binding's
165
- * preregistered values. Null when a `{param}` reference has no resolved
166
- * value: callers hold as `parameter-missing`, never promote.
167
- */
168
- function resolveGateNumber(value, packId, parameters) {
169
- if (value === undefined)
170
- return null;
171
- if (typeof value === 'number')
172
- return value;
173
- if (value !== null && typeof value === 'object' && typeof value.param === 'string') {
174
- const resolved = parameters[qualifyGateParameter(packId, value.param)];
175
- return typeof resolved === 'number' ? resolved : null;
176
- }
177
- return null;
178
- }
179
- function evaluateObservation(gate, observation, context) {
180
- const { packId, parameters, metrics, upstream, nowMs, slice, slices } = context;
181
- const base = { slice, n: supportOf(observation) };
182
- const minimumN = gate.minimumN === undefined ? 0 : resolveGateNumber(gate.minimumN, packId, parameters);
183
- // Evidence gates observe attestations, not counted support; upstream and predicate
184
- // gates read the ceiling and the whole document. None of them take an n.
185
- if (gate.kind !== 'upstream-ceiling' && gate.kind !== 'predicate' && gate.kind !== 'evidence') {
186
- if (observation === null || observation === undefined)
187
- return { ...base, status: 'insufficient', reason: 'metric-missing' };
188
- if (base.n === null)
189
- return { ...base, status: 'insufficient', reason: 'support-unknown' };
190
- if (minimumN === null)
191
- return { ...base, status: 'insufficient', reason: 'parameter-missing' };
192
- if (base.n < minimumN)
193
- return { ...base, status: 'insufficient', reason: 'below-minimum-n' };
194
- }
195
- const thresholdValue = () => {
196
- if (gate.threshold?.value !== undefined)
197
- return gate.threshold.value;
198
- if (gate.threshold?.param !== undefined) {
199
- const value = parameters[qualifyGateParameter(packId, gate.threshold.param)];
200
- return typeof value === 'number' ? value : null;
201
- }
202
- return null;
203
- };
204
- switch (gate.kind) {
205
- case 'minimum-n': {
206
- const target = gate.minimumN === undefined ? null : resolveGateNumber(gate.minimumN, packId, parameters);
207
- if (target === null) {
208
- return { ...base, status: 'insufficient', reason: 'parameter-missing',
209
- statistic: { method: 'support-count' } };
210
- }
211
- const passed = base.n >= target;
212
- return { ...base, status: passed ? 'pass' : 'insufficient', reason: passed ? 'support-met' : 'below-minimum-n',
213
- statistic: { method: 'support-count' } };
214
- }
215
- case 'interval-bound': {
216
- const events = observation?.events;
217
- if (typeof events !== 'number' || !Number.isSafeInteger(events) || events < 0) {
218
- return { ...base, status: 'insufficient', reason: 'events-unknown', events: null };
219
- }
220
- if (events > base.n)
221
- return { ...base, status: 'insufficient', reason: 'events-exceed-n', events };
222
- const target = thresholdValue();
223
- if (target === null)
224
- return { ...base, status: 'insufficient', reason: 'parameter-missing', events };
225
- const method = gate.statistic?.method ?? 'wilson';
226
- const levelBps = resolveGateNumber(gate.statistic?.levelBps, packId, parameters);
227
- if (levelBps === null)
228
- return { ...base, status: 'insufficient', reason: 'parameter-missing', events };
229
- let lower;
230
- let upper;
231
- try {
232
- if (method === 'clopper-pearson') {
233
- ({ lower, upper } = clopperPearsonInterval({ events, n: base.n, levelBps }));
234
- }
235
- else {
236
- [lower, upper] = wilsonScoreInterval({ events, n: base.n, levelBps });
237
- }
238
- }
239
- catch (error) {
240
- if (error instanceof PairedDifferenceError) {
241
- return { ...base, status: 'insufficient', reason: 'statistic-invalid', events };
242
- }
243
- throw error;
244
- }
245
- const lowerBps = Math.max(0, Math.floor(lower * 10000));
246
- const upperBps = Math.min(10000, Math.ceil(upper * 10000));
247
- const estimateBps = Math.round(events / base.n * 10000);
248
- const passed = gate.statistic?.bound === 'upper' ? upperBps <= target : lowerBps >= target;
249
- return { ...base, status: passed ? 'pass' : 'fail', reason: passed ? 'bound-within-threshold' : 'bound-breaches-threshold',
250
- events, statistic: { method, levelBps, lowerBps, upperBps, estimateBps },
251
- threshold: { op: gate.threshold?.op, ...(gate.threshold?.value !== undefined
252
- ? { value: gate.threshold.value } : { param: gate.threshold?.param }), resolved: target } };
253
- }
254
- case 'paired-difference': {
255
- const cells = pairedCells(observation);
256
- if (cells === null)
257
- return { ...base, status: 'insufficient', reason: 'paired-unknown' };
258
- if (base.n !== cells.both + cells.candidateOnly + cells.baselineOnly + cells.neither) {
259
- return { ...base, status: 'insufficient', reason: 'observation-mismatch' };
260
- }
261
- const method = gate.statistic?.method ?? 'newcombe';
262
- const levelBps = resolveGateNumber(gate.statistic?.levelBps, packId, parameters);
263
- if (levelBps === null)
264
- return { ...base, status: 'insufficient', reason: 'parameter-missing' };
265
- let interval;
266
- try {
267
- interval = pairedBinaryDifferenceInterval({ counts: cells, levelBps, method: method === 'tango' ? 'tango' : 'newcombe-10' });
268
- }
269
- catch (error) {
270
- if (error instanceof PairedDifferenceError)
271
- return { ...base, status: 'insufficient', reason: 'paired-invalid' };
272
- throw error;
273
- }
274
- const mode = gate.statistic?.mode ?? 'non-inferiority';
275
- const margin = gate.statistic?.marginBps ?? 0;
276
- const statistic = { method, levelBps, lowerBps: interval.lowerBps, upperBps: interval.upperBps,
277
- estimateBps: interval.estimateBps };
278
- const threshold = { op: 'gte', resolved: margin };
279
- if (mode === 'non-inferiority') {
280
- const verdict = pairedNonInferiority({ interval, marginBps: margin });
281
- if (verdict.decision === 'insufficient')
282
- return { ...base, status: 'insufficient', reason: 'paired-invalid', statistic, threshold };
283
- const passed = verdict.decision === 'non-inferior';
284
- return { ...base, status: passed ? 'pass' : 'fail',
285
- reason: passed ? 'lower-bound-at-or-above-margin' : 'lower-bound-below-margin', statistic, threshold };
286
- }
287
- const passed = interval.lowerBps > margin;
288
- return { ...base, status: passed ? 'pass' : 'fail',
289
- reason: passed ? 'lower-bound-above-margin' : 'lower-bound-at-or-below-margin', statistic, threshold };
290
- }
291
- case 'bootstrap-bound': {
292
- const differences = observation?.differences;
293
- if (!Array.isArray(differences))
294
- return { ...base, status: 'insufficient', reason: 'differences-unknown' };
295
- if (differences.length !== base.n)
296
- return { ...base, status: 'insufficient', reason: 'observation-mismatch' };
297
- const target = thresholdValue();
298
- if (target === null)
299
- return { ...base, status: 'insufficient', reason: 'parameter-missing' };
300
- const levelBps = resolveGateNumber(gate.statistic?.levelBps, packId, parameters);
301
- if (levelBps === null)
302
- return { ...base, status: 'insufficient', reason: 'parameter-missing' };
303
- let interval;
304
- try {
305
- interval = pairedMeanDifferenceBootstrap({ differences, levelBps,
306
- seed: gate.statistic?.seed, resamples: gate.statistic?.resamples,
307
- bounds: gate.statistic?.bounds });
308
- }
309
- catch (error) {
310
- if (error instanceof PairedDifferenceError)
311
- return { ...base, status: 'insufficient', reason: 'statistic-invalid' };
312
- throw error;
313
- }
314
- const passed = gate.statistic?.bound === 'upper' ? interval.upperBps <= target : interval.lowerBps >= target;
315
- return { ...base, status: passed ? 'pass' : 'fail', reason: passed ? 'bound-within-threshold' : 'bound-breaches-threshold',
316
- statistic: { method: 'bootstrap', levelBps, lowerBps: interval.lowerBps,
317
- upperBps: interval.upperBps, estimateBps: interval.estimateBps },
318
- threshold: { op: gate.threshold?.op, ...(gate.threshold?.value !== undefined
319
- ? { value: gate.threshold.value } : { param: gate.threshold?.param }), resolved: target } };
320
- }
321
- case 'count-max':
322
- case 'count-min': {
323
- const events = observation?.events;
324
- if (typeof events !== 'number' || !Number.isSafeInteger(events) || events < 0) {
325
- return { ...base, status: 'insufficient', reason: 'events-unknown', events: null };
326
- }
327
- if (events > base.n)
328
- return { ...base, status: 'insufficient', reason: 'events-exceed-n', events };
329
- const target = thresholdValue();
330
- if (target === null)
331
- return { ...base, status: 'insufficient', reason: 'parameter-missing', events };
332
- const passed = gate.kind === 'count-max' ? events <= target : events >= target;
333
- return { ...base, status: passed ? 'pass' : 'fail', reason: passed ? 'count-within-threshold' : 'count-breaches-threshold',
334
- events, statistic: { method: 'exact-count' },
335
- threshold: { op: gate.threshold?.op, ...(gate.threshold?.value !== undefined
336
- ? { value: gate.threshold.value } : { param: gate.threshold?.param }), resolved: target } };
337
- }
338
- case 'value-threshold': {
339
- const value = observation?.value;
340
- if (typeof value !== 'number' || !Number.isFinite(value)) {
341
- return { ...base, status: 'insufficient', reason: 'value-unknown' };
342
- }
343
- const target = thresholdValue();
344
- if (target === null)
345
- return { ...base, status: 'insufficient', reason: 'parameter-missing' };
346
- const passed = gate.threshold?.op === 'lte' ? value <= target : value >= target;
347
- return { ...base, status: passed ? 'pass' : 'fail', reason: passed ? 'value-within-threshold' : 'value-breaches-threshold',
348
- statistic: { method: 'exact-value' },
349
- threshold: { op: gate.threshold?.op, ...(gate.threshold?.value !== undefined
350
- ? { value: gate.threshold.value } : { param: gate.threshold?.param }), resolved: target } };
351
- }
352
- case 'evidence': {
353
- const available = observation?.available;
354
- if (!Array.isArray(available))
355
- return { ...base, status: 'insufficient', reason: 'evidence-unknown' };
356
- for (const id of gate.evidence?.required ?? []) {
357
- const entry = available.find(candidate => candidate?.id === id);
358
- if (entry === undefined)
359
- return { ...base, status: 'insufficient', reason: 'evidence-missing', statistic: { method: 'evidence-present' } };
360
- if (entry.passed !== true) {
361
- return { ...base, status: 'fail', reason: 'evidence-failed', statistic: { method: 'evidence-present' } };
362
- }
363
- if (entry.expiresAt !== undefined && entry.expiresAt !== null) {
364
- const expiry = Date.parse(entry.expiresAt);
365
- if (!Number.isFinite(expiry) || expiry <= nowMs) {
366
- return { ...base, status: 'fail', reason: 'evidence-expired', statistic: { method: 'evidence-present' } };
367
- }
368
- }
369
- }
370
- return { ...base, status: 'pass', reason: 'evidence-present', statistic: { method: 'evidence-present' } };
371
- }
372
- case 'predicate': {
373
- let value = 'unknown';
374
- try {
375
- value = evaluatePredicate(gate.predicate, { metrics, parameters, slices }, {});
376
- }
377
- catch {
378
- value = 'unknown';
379
- }
380
- if (value === true)
381
- return { ...base, status: 'pass', reason: 'predicate-true', statistic: { method: 'predicate' } };
382
- if (value === false)
383
- return { ...base, status: 'fail', reason: 'predicate-false', statistic: { method: 'predicate' } };
384
- return { ...base, status: 'insufficient', reason: 'predicate-unknown', statistic: { method: 'predicate' } };
385
- }
386
- case 'upstream-ceiling': {
387
- if (upstream === null)
388
- return { ...base, status: 'insufficient', reason: 'upstream-missing',
389
- statistic: { method: 'upstream-integrity' } };
390
- const { problems, compromised } = evaluateUpstreamCeiling(upstream.metadata);
391
- if (!problems.length) {
392
- return { ...base, status: 'pass', reason: 'upstream-clean', statistic: { method: 'upstream-integrity' } };
393
- }
394
- return { ...base, status: 'fail', reason: compromised ? 'upstream-compromised' : 'upstream-allowlist',
395
- statistic: { method: 'upstream-integrity' } };
396
- }
397
- }
398
- }
399
43
  function digestRecordsOrFail(records, providerId) {
400
44
  try {
401
45
  return artifactDigest(records);