@aiwg/cli 2026.10.15 → 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.
- package/agentic/code/providers/pi/aiwg-bridge.ts +45 -7
- package/dist/src/artifacts/citation-parser.js +7 -6
- package/dist/src/artifacts/corpus-tools/citation-densify.js +4 -2
- package/dist/src/artifacts/corpus-tools/cli.js +8 -3
- package/dist/src/artifacts/corpus-tools/discovery-log.js +26 -24
- package/dist/src/artifacts/corpus-tools/expand-cli.js +3 -2
- package/dist/src/artifacts/corpus-tools/expand-dates.js +107 -0
- package/dist/src/artifacts/corpus-tools/expand-queue.js +4 -1
- package/dist/src/artifacts/corpus-tools/expand-review.js +104 -0
- package/dist/src/artifacts/corpus-tools/expand-state.js +17 -1
- package/dist/src/artifacts/corpus-tools/expand.js +16 -17
- package/dist/src/artifacts/corpus-tools/induction-audit.js +7 -6
- package/dist/src/artifacts/corpus-tools/integrity-scan.js +3 -3
- package/dist/src/artifacts/corpus-tools/radar-shared.js +7 -9
- package/dist/src/artifacts/corpus-tools/ref-files.js +11 -0
- package/dist/src/artifacts/corpus-tools/resolve-cli.js +11 -3
- package/dist/src/artifacts/corpus-tools/resolve.js +42 -11
- package/dist/src/artifacts/corpus-tools/retrieval-lab.js +2 -1
- package/dist/src/artifacts/corpus-tools/sidecar-lint.js +4 -4
- package/dist/src/artifacts/corpus-tools/sidecar-repair.js +2 -1
- package/dist/src/artifacts/corpus-views/ref-parser.js +3 -17
- package/dist/src/artifacts/graph-query.js +5 -3
- package/dist/src/artifacts/hybrid-query.js +11 -2
- package/dist/src/artifacts/index-refresh.js +2 -0
- 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/daemon.js +17 -1
- package/dist/src/cli/handlers/doctor-args.js +10 -5
- package/dist/src/cli/handlers/doctor-help.js +4 -1
- package/dist/src/cli/handlers/index.js +2 -2
- 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-resource-sample.js +10 -0
- package/dist/src/cli/handlers/models.js +5 -3
- package/dist/src/cli/handlers/regenerate.js +8 -16
- 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/sessions.js +7 -7
- 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 -1976
- package/dist/src/cli/handlers/update.js +157 -0
- package/dist/src/cli/handlers/use.js +14 -4
- package/dist/src/cli/handlers/utilities.js +3 -560
- package/dist/src/cli/handlers/utility-doctor.js +412 -0
- package/dist/src/cli/scope-resolver.js +1 -142
- package/dist/src/cli/services/deployment-verification.js +0 -1
- package/dist/src/cli/user-scope-mirror.js +173 -0
- package/dist/src/config/aiwg-config.js +2 -1
- package/dist/src/config/authorization-cli.js +7 -3
- package/dist/src/config/dispatch-host-thresholds.js +2 -0
- package/dist/src/config/dispatch-thresholds-runtime.d.mts +3 -2
- package/dist/src/config/dispatch-thresholds-runtime.mjs +21 -7
- package/dist/src/config/framework-aliases.js +12 -0
- package/dist/src/config/host-resource-report.d.mts +24 -0
- package/dist/src/config/host-resource-report.mjs +110 -0
- package/dist/src/config/host-resource-runtime.d.mts +37 -0
- package/dist/src/config/host-resource-runtime.mjs +296 -0
- package/dist/src/config/installed-selection.js +22 -0
- package/dist/src/config/worker-invocation-marker.d.mts +1 -0
- package/dist/src/config/worker-invocation-marker.mjs +2 -0
- 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/heldout/access.js +74 -0
- package/dist/src/decision/heldout/calibration.js +1 -0
- package/dist/src/decision/heldout/collector.js +8 -1
- package/dist/src/decision/sensitivity/comparative-gates.js +135 -0
- package/dist/src/decision/sensitivity/comparative.js +18 -41
- package/dist/src/effects/verifiers/file.js +22 -5
- package/dist/src/extensions/claude-attribution.js +82 -0
- package/dist/src/extensions/claude-hooks-installer.js +133 -69
- package/dist/src/extensions/commands/daemon.js +109 -0
- package/dist/src/extensions/commands/definitions.js +5 -89
- package/dist/src/gates/evaluate.js +2 -358
- package/dist/src/gates/heldout.js +17 -7
- 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/lint/check-patterns.js +163 -0
- package/dist/src/lint/checks.js +268 -0
- package/dist/src/lint/reference-resolution.js +54 -0
- package/dist/src/lint/runner.js +3 -465
- package/dist/src/mcp/helpers.mjs +11 -1
- package/dist/src/mcp/json-document.mjs +29 -0
- package/dist/src/mcp/muse-native-config.mjs +1 -28
- package/dist/src/memory/project-registry.js +44 -4
- package/dist/src/mission-protocol/worker-review-gate.js +7 -0
- package/dist/src/models/worker-plan.js +36 -5
- package/dist/src/models/wrapper-deployment.js +25 -12
- package/dist/src/models/wrapper-enforcement.js +47 -7
- package/dist/src/network-analysis/research.js +2 -1
- 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/policy/hitl-check.js +14 -4
- package/dist/src/policy/hitl-consume.js +54 -0
- package/dist/src/policy/hitl-receipt.js +2 -0
- package/dist/src/policy/hitl.js +11 -3
- package/dist/src/providers/context-output-ownership.js +26 -0
- package/dist/src/providers/deployment-ownership.d.mts +19 -0
- package/dist/src/providers/deployment-ownership.mjs +226 -0
- package/dist/src/providers/deployment-removal.js +200 -0
- package/dist/src/providers/provider-context-contracts.js +162 -0
- package/dist/src/providers/provider-definition-schema.js +136 -0
- package/dist/src/providers/provider-definitions.js +8 -1298
- package/dist/src/providers/provider-seeds-1.js +360 -0
- package/dist/src/providers/provider-seeds-2.js +387 -0
- package/dist/src/providers/provider-seeds-3.js +262 -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 +19 -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/clients/arxiv.js +4 -30
- package/dist/src/research/clients/base.js +48 -22
- package/dist/src/research/identity.js +42 -4
- package/dist/src/research/query-cli.js +3 -87
- package/dist/src/research/query-options.js +87 -0
- package/dist/src/research/reference-match.js +105 -24
- package/dist/src/research/services/acquisition.js +9 -7
- package/dist/src/research/services/citation.js +5 -2
- package/dist/src/research/types.js +2 -0
- package/dist/src/rules/activation.mjs +15 -6
- package/dist/src/rules/core-startup.mjs +2 -2
- package/dist/src/serve/mission-conductor.js +52 -4
- package/dist/src/serve/mission-summary.js +56 -0
- package/dist/src/sessions/adapters/grok-build-native.js +23 -0
- package/dist/src/sessions/adapters/grok-build.js +14 -7
- package/dist/src/sessions/workspace-discovery.js +5 -5
- package/dist/src/smiths/context-pipeline/aiwg-md.js +39 -46
- package/dist/src/smiths/context-pipeline/claude-hook.js +1 -1
- package/dist/src/smiths/context-pipeline/code-regions.js +28 -0
- package/dist/src/smiths/context-pipeline/context-file-safety.js +3 -0
- package/dist/src/smiths/context-pipeline/finalization.js +81 -51
- package/dist/src/smiths/context-pipeline/generator.js +10 -11
- package/dist/src/smiths/context-pipeline/managed-hook.js +1 -1
- package/dist/src/smiths/context-pipeline/muse-bridge.js +2 -2
- package/dist/src/smiths/context-pipeline/provider-policy.js +6 -12
- package/dist/src/smiths/context-pipeline/workspace-audit.js +299 -0
- package/dist/src/smiths/context-pipeline/workspace-bootstrap.js +148 -0
- package/dist/src/smiths/context-pipeline/workspace-context-shared.js +111 -0
- package/dist/src/smiths/context-pipeline/workspace-context.js +8 -1373
- package/dist/src/smiths/context-pipeline/workspace-doctor.js +192 -0
- package/dist/src/smiths/context-pipeline/workspace-document.js +201 -0
- package/dist/src/smiths/context-pipeline/workspace-extraction.js +205 -0
- package/dist/src/smiths/context-pipeline/workspace-migration.js +250 -0
- package/dist/src/smiths/hook-bridge/index.js +9 -0
- package/package.json +13 -1
- package/schemas/decision/D17StudyProtocol.v1.schema.json +39 -67
- package/schemas/decision/D29Study.v10.schema.json +65 -0
- package/tools/agents/deploy-agents.mjs +24 -675
- package/tools/agents/deploy-command-mirrors.mjs +229 -0
- package/tools/agents/deploy-options.mjs +258 -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 +20 -1
- package/tools/agents/providers/context-write.mjs +4 -0
- package/tools/agents/providers/hermes-startup.mjs +0 -5
- package/tools/agents/providers/muse.mjs +7 -2
- package/tools/agents/providers/pi.mjs +3 -1
- package/tools/agents/providers/rule-delivery-surface.mjs +359 -0
- package/tools/agents/providers/rule-delivery.mjs +20 -1144
- package/tools/agents/providers/rule-deployment-commit.mjs +148 -0
- package/tools/agents/providers/rule-deployment-prepare.mjs +461 -0
- package/tools/agents/providers/rule-deployment-state.mjs +300 -0
- package/tools/agents/providers/rule-projection.mjs +3 -0
- package/tools/daemon/README.md +511 -0
- package/tools/daemon/adapters/base-adapter.mjs +84 -0
- package/tools/daemon/adapters/webhook-adapter.mjs +107 -0
- package/tools/daemon/agent-supervisor.mjs +299 -0
- package/tools/daemon/automation-engine.mjs +310 -0
- package/tools/daemon/autonomous-engine.mjs +346 -0
- package/tools/daemon/behavior-loader.mjs +316 -0
- package/tools/daemon/behavior.mjs +174 -0
- package/tools/daemon/concierge/intent-router.mjs +401 -0
- package/tools/daemon/concierge/orchestrator.mjs +272 -0
- package/tools/daemon/concierge/response-translator.mjs +462 -0
- package/tools/daemon/config.mjs +377 -0
- package/tools/daemon/cron-scheduler.mjs +178 -0
- package/tools/daemon/daemon-main.mjs +1169 -0
- package/tools/daemon/event-router.mjs +84 -0
- package/tools/daemon/file-watcher.mjs +383 -0
- package/tools/daemon/index.mjs +1181 -0
- package/tools/daemon/init-profile.mjs +124 -0
- package/tools/daemon/ipc-client.mjs +197 -0
- package/tools/daemon/ipc-ops-handlers.mjs +236 -0
- package/tools/daemon/ipc-server.mjs +275 -0
- package/tools/daemon/maintenance-owner.mjs +79 -0
- package/tools/daemon/memory-manager.mjs +386 -0
- package/tools/daemon/message-router.mjs +194 -0
- package/tools/daemon/provider-watcher.mjs +585 -0
- package/tools/daemon/pty-adapter.mjs +420 -0
- package/tools/daemon/repl-chat.mjs +359 -0
- package/tools/daemon/resource-bounds.mjs +88 -0
- package/tools/daemon/sandbox-transport.mjs +295 -0
- package/tools/daemon/scheduled-task-runner.mjs +535 -0
- package/tools/daemon/task-store.mjs +450 -0
- package/tools/daemon/tmux-manager.mjs +324 -0
- package/tools/daemon/update-policy.mjs +517 -0
- package/tools/daemon/web-server.mjs +399 -0
- package/tools/daemon/web-ui/index.html +585 -0
- package/tools/daemon/web-ui/styles.css +156 -0
- package/tools/docker/Dockerfile.daemon +35 -0
- package/tools/docker/container-manager.mjs +291 -0
- package/tools/messaging/adapter-registry.mjs +230 -0
- package/tools/messaging/adapters/base.mjs +326 -0
- package/tools/messaging/adapters/discord.mjs +462 -0
- package/tools/messaging/adapters/slack.mjs +402 -0
- package/tools/messaging/adapters/telegram.mjs +552 -0
- package/tools/messaging/chat-handler.mjs +297 -0
- package/tools/messaging/command-router.mjs +269 -0
- package/tools/messaging/event-bus.mjs +199 -0
- package/tools/messaging/index.mjs +456 -0
- package/tools/messaging/message-formatter.mjs +320 -0
- package/tools/messaging/room-manager.mjs +277 -0
- package/tools/messaging/types.mjs +94 -0
- package/tools/providers/pi-bridge-policy.mjs +4 -0
- package/tools/ralph-external/daemon-supervisor.mjs +394 -0
- package/tools/ralph-external/lib/behavior-registry.mjs +270 -0
- package/tools/ralph-external/lib/worker-invocation-processes.mjs +7 -4
- package/tools/ralph-external/lib/worker-isolation-args.mjs +217 -0
- package/tools/ralph-external/lib/worker-isolation-status.mjs +19 -0
- package/tools/ralph-external/lib/worker-isolation.mjs +11 -237
- package/tools/ralph-external/lib/worker-overflow.mjs +10 -2
- package/tools/ralph-external/lib/worker-termination.mjs +15 -8
- package/tools/ralph-external/lib/worker-unit-cleanup.mjs +72 -0
- package/tools/ralph-external/session-launcher.mjs +7 -7
- package/tools/scripts/resource-preflight.mjs +3 -242
- 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);
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
// Verify the frozen bundle, its pinned analysis and the independently anchored first-access record.
|
|
2
2
|
import { heldoutDigest } from '../decision/heldout/contract.js';
|
|
3
3
|
import { artifactDigest } from '../decision/validate.js';
|
|
4
|
+
import { verifyHeldoutAccess } from '../decision/heldout/access.js';
|
|
4
5
|
import { evaluateGates, GateEvaluationError, sealGateHoldout } from './evaluate.js';
|
|
5
6
|
/**
|
|
6
7
|
* Derive gate inputs from HeldoutFrozen without altering its historical bytes.
|
|
7
8
|
* The existing bundle contains only corpus, preregistration and approval, so
|
|
8
9
|
* its studyAnalysisDigest must first verify the supplied analysis containing
|
|
9
10
|
* the binding. The access record pins that same analysis (and hence binding).
|
|
10
|
-
* Its
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
* the access anchor independently, just as for the existing D29 scorer.
|
|
11
|
+
* Its signed body covers both digests, run ID and first-access time. The host
|
|
12
|
+
* selects the keyring independently; the retained access digest is an extra
|
|
13
|
+
* integrity check, never a substitute for signature verification.
|
|
14
14
|
*/
|
|
15
15
|
export function sealGateHoldoutFromFrozen(input) {
|
|
16
|
-
const { frozen, analysis, access, trustedAccessDigest } = input;
|
|
16
|
+
const { frozen, analysis, access, trustedAccessDigest, keyring } = input;
|
|
17
17
|
if (!frozen?.bundle || frozen.digest !== heldoutDigest(frozen.bundle)) {
|
|
18
18
|
throw new GateEvaluationError('frozen bundle digest does not match its content');
|
|
19
19
|
}
|
|
@@ -25,11 +25,21 @@ export function sealGateHoldoutFromFrozen(input) {
|
|
|
25
25
|
|| heldoutDigest(access) !== trustedAccessDigest) {
|
|
26
26
|
throw new GateEvaluationError('first-access digest does not match its trusted pin');
|
|
27
27
|
}
|
|
28
|
+
if (!access.signature)
|
|
29
|
+
throw new GateEvaluationError('first-access signature missing');
|
|
28
30
|
if (access.analysisDigest !== analysisDigest) {
|
|
29
31
|
throw new GateEvaluationError('first-access record does not belong to the frozen analysis and binding');
|
|
30
32
|
}
|
|
31
|
-
if (
|
|
32
|
-
throw new GateEvaluationError('first-access
|
|
33
|
+
if (access.frozenBundleDigest !== frozen.digest) {
|
|
34
|
+
throw new GateEvaluationError('first-access frozen-bundle digest does not match the frozen record');
|
|
35
|
+
}
|
|
36
|
+
if (access.runId !== frozen.bundle.approval.runId)
|
|
37
|
+
throw new GateEvaluationError('first-access run ID does not match the frozen approval');
|
|
38
|
+
try {
|
|
39
|
+
verifyHeldoutAccess(access, keyring);
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
throw new GateEvaluationError(error.message);
|
|
33
43
|
}
|
|
34
44
|
const trustedBindingDigest = artifactDigest(analysis.gateBinding);
|
|
35
45
|
return { trustedBindingDigest,
|