@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
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
// Linux host measurements shared by dispatch preflight and resource reports.
|
|
2
|
+
import { readFileSync, readdirSync, statfsSync } from 'node:fs';
|
|
3
|
+
import os from 'node:os';
|
|
4
|
+
import { spawnSync } from 'node:child_process';
|
|
5
|
+
import { WORKER_INVOCATION_MARKER } from './worker-invocation-marker.mjs';
|
|
6
|
+
const BYTES_PER_GB = 1024 ** 3;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Parse MemAvailable (kB) from /proc/meminfo text. Returns GiB or undefined
|
|
10
|
+
* when the field is absent/unparsable. Pure: tests feed synthetic fixtures.
|
|
11
|
+
*/
|
|
12
|
+
function parseMemAvailableGb(meminfoText) {
|
|
13
|
+
if (typeof meminfoText !== 'string') return undefined;
|
|
14
|
+
const match = meminfoText.match(/^MemAvailable:\s+(\d+)\s+kB$/m);
|
|
15
|
+
if (!match) return undefined;
|
|
16
|
+
const gib = Number(match[1]) / 1024 / 1024;
|
|
17
|
+
return Number.isFinite(gib) ? gib : undefined;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Parse memory pressure from /proc/pressure/memory text. Returns
|
|
22
|
+
* `{ avg10, avg60, avg300 }` from the `some` line, or null when no `some`
|
|
23
|
+
* line parses. Pure: tests feed synthetic fixtures.
|
|
24
|
+
*/
|
|
25
|
+
function parseMemoryPsi(pressureText) {
|
|
26
|
+
if (typeof pressureText !== 'string') return null;
|
|
27
|
+
for (const line of pressureText.split('\n')) {
|
|
28
|
+
if (!line.startsWith('some')) continue;
|
|
29
|
+
const values = {};
|
|
30
|
+
for (const part of line.split(/\s+/)) {
|
|
31
|
+
const [key, raw] = part.split('=');
|
|
32
|
+
if ((key === 'avg10' || key === 'avg60' || key === 'avg300') && raw !== undefined) {
|
|
33
|
+
const value = Number(raw);
|
|
34
|
+
if (Number.isFinite(value)) values[key] = value;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
if (values.avg10 !== undefined && values.avg60 !== undefined && values.avg300 !== undefined) return values;
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Parse /proc/loadavg text. Returns `{ load1, load5, load15 }` or null.
|
|
45
|
+
* Pure: tests feed synthetic fixtures.
|
|
46
|
+
*/
|
|
47
|
+
function parseLoadAverages(loadavgText) {
|
|
48
|
+
if (typeof loadavgText !== 'string') return null;
|
|
49
|
+
const parts = loadavgText.trim().split(/\s+/);
|
|
50
|
+
const loads = parts.slice(0, 3).map(Number);
|
|
51
|
+
if (loads.length !== 3 || loads.some(value => !Number.isFinite(value))) return null;
|
|
52
|
+
return { load1: loads[0], load5: loads[1], load15: loads[2] };
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** List active current-user launcher units, retaining identity for deduplication. */
|
|
56
|
+
function listWorkerUnits({ spawn = spawnSync } = {}) {
|
|
57
|
+
try {
|
|
58
|
+
const result = spawn('systemctl', ['--user', 'list-units', '--type=service',
|
|
59
|
+
'--state=running,activating', '--no-legend', '--plain', 'aiwg-worker-*'],
|
|
60
|
+
{ encoding: 'utf8', timeout: 1000 });
|
|
61
|
+
if (result.error || result.status !== 0) return undefined;
|
|
62
|
+
return [...new Set(String(result.stdout ?? '').split('\n')
|
|
63
|
+
.map(line => /^(aiwg-worker-[^\s]+\.service)\s/.exec(line.trim())?.[1]).filter(Boolean))];
|
|
64
|
+
} catch { return undefined; }
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function countWorkerUnits(options) {
|
|
68
|
+
return listWorkerUnits(options)?.length;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** Count owned invocations once; CLI comm counts are informational only. */
|
|
72
|
+
function countWorkerProcesses({
|
|
73
|
+
readDir = readdirSync,
|
|
74
|
+
readText = path => readFileSync(path, 'utf8'),
|
|
75
|
+
uid = process.getuid?.(),
|
|
76
|
+
groupNames = [],
|
|
77
|
+
listWorkerUnits: readUnitList,
|
|
78
|
+
countWorkerUnits: readUnitCount,
|
|
79
|
+
} = {}) {
|
|
80
|
+
if (process.platform !== 'linux' || uid === undefined) return undefined;
|
|
81
|
+
let units, unitNames;
|
|
82
|
+
try {
|
|
83
|
+
const listed = readUnitList ? readUnitList() : readUnitCount ? readUnitCount() : listWorkerUnits();
|
|
84
|
+
if (Array.isArray(listed)) unitNames = new Set(listed);
|
|
85
|
+
const counted = unitNames ? unitNames.size : listed;
|
|
86
|
+
if (Number.isInteger(counted) && counted >= 0) units = counted;
|
|
87
|
+
} catch { /* Owned-process scanning remains available. */ }
|
|
88
|
+
const source = units === undefined ? 'owned-process-fallback' : 'systemd-units-and-marked-processes';
|
|
89
|
+
// Reuse existing identities; UUID-only IDs carry no group evidence.
|
|
90
|
+
const identify = value => new Set(groupNames.filter(name => value === name || value.startsWith(`${name}-`)));
|
|
91
|
+
const unitGroups = new Map([...(unitNames ?? [])].map(unit =>
|
|
92
|
+
[unit, identify(unit.slice('aiwg-worker-'.length, -'.service'.length))]));
|
|
93
|
+
let entries, procUnavailable = false;
|
|
94
|
+
try { entries = readDir('/proc'); }
|
|
95
|
+
catch {
|
|
96
|
+
if (units === undefined) return undefined;
|
|
97
|
+
entries = []; procUnavailable = true;
|
|
98
|
+
}
|
|
99
|
+
const hostCliProcesses = { codex: 0, muse: 0 };
|
|
100
|
+
const invocations = new Set(), unitInvocations = new Set();
|
|
101
|
+
const invocationGroups = new Map();
|
|
102
|
+
const merge = (target, evidence) => { for (const name of evidence) target.add(name); };
|
|
103
|
+
for (const entry of entries) {
|
|
104
|
+
if (!/^\d+$/.test(entry)) continue;
|
|
105
|
+
try {
|
|
106
|
+
const status = readText(`/proc/${entry}/status`);
|
|
107
|
+
const owner = status.match(/^Uid:\s+(\d+)/m);
|
|
108
|
+
if (!owner || Number(owner[1]) !== uid) continue;
|
|
109
|
+
const optional = field => {
|
|
110
|
+
try { return readText(`/proc/${entry}/${field}`); } catch { return ''; }
|
|
111
|
+
};
|
|
112
|
+
const comm = optional('comm').trim();
|
|
113
|
+
if (comm === 'codex') hostCliProcesses.codex += 1;
|
|
114
|
+
if (comm === 'muse-bin' || comm === 'muse') hostCliProcesses.muse += 1;
|
|
115
|
+
const marker = optional('environ').split('\0').find(field => field.startsWith(`${WORKER_INVOCATION_MARKER}=`));
|
|
116
|
+
const invocation = marker?.slice(WORKER_INVOCATION_MARKER.length + 1);
|
|
117
|
+
if (!invocation) continue;
|
|
118
|
+
invocations.add(invocation);
|
|
119
|
+
if (!invocationGroups.has(invocation)) invocationGroups.set(invocation, identify(invocation));
|
|
120
|
+
const cgroupUnits = optional('cgroup').match(/aiwg-worker-[^/\s]+\.service(?=\/|\s|$)/g) ?? [];
|
|
121
|
+
if (cgroupUnits.some(unit => unitNames ? unitNames.has(unit) : units > 0)) unitInvocations.add(invocation);
|
|
122
|
+
for (const unit of cgroupUnits.filter(unit => unitGroups.has(unit))) {
|
|
123
|
+
merge(unitGroups.get(unit), invocationGroups.get(invocation));
|
|
124
|
+
}
|
|
125
|
+
} catch { /* Processes may exit during the scan. */ }
|
|
126
|
+
}
|
|
127
|
+
const byGroup = {};
|
|
128
|
+
for (const evidence of [...unitGroups.values(), ...[...invocationGroups]
|
|
129
|
+
.filter(([id]) => !unitInvocations.has(id)).map(([, evidence]) => evidence)]) {
|
|
130
|
+
if (evidence.size === 1) {
|
|
131
|
+
const [name] = evidence;
|
|
132
|
+
byGroup[name] = (byGroup[name] ?? 0) + 1;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
return { ...(groupNames.length ? { byGroup } : {}), total: (units ?? 0) + [...invocations].filter(id => !unitInvocations.has(id)).length,
|
|
136
|
+
...(procUnavailable ? {} : { hostCliProcesses }), units, source };
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function defaultCountWorkers(options) {
|
|
140
|
+
return countWorkerProcesses(options)?.total;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Sample live host signals. All inputs are injectable so tests use synthetic
|
|
145
|
+
* meminfo/pressure/loadavg fixtures instead of the real /proc:
|
|
146
|
+
* `{ readText, coreCount, countWorkers }`. Non-Linux hosts report
|
|
147
|
+
* `{ supported: false }`; the gate turns that into an explicit diagnostic
|
|
148
|
+
* (MVP qualifies Linux per NFR-OG-008) rather than an implicit pass.
|
|
149
|
+
*/
|
|
150
|
+
/**
|
|
151
|
+
* Convert one statfs result to GiB. Non-finite or negative samples are
|
|
152
|
+
* rejected (fail closed): a NaN/Infinity/-1 reading must never become a
|
|
153
|
+
* passing number downstream.
|
|
154
|
+
*/
|
|
155
|
+
function toFreeDiskGb(disk) {
|
|
156
|
+
const gb = (Number(disk?.bavail) * Number(disk?.bsize)) / BYTES_PER_GB;
|
|
157
|
+
return Number.isFinite(gb) && gb >= 0 ? gb : undefined;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Sample free disk on the caller-supplied filesystem(s): `readers.paths`
|
|
162
|
+
* names the actual evidence root and worktree, and the gate takes the
|
|
163
|
+
* minimum across them. Any unreadable, non-finite or negative sample — or
|
|
164
|
+
* no supplied filesystem at all — yields undefined so the gate fails closed
|
|
165
|
+
* instead of admitting on the conductor's process-cwd filesystem.
|
|
166
|
+
* `readers.statfs` (zero-arg) and `readers.statfsPath` (per-path) stay as
|
|
167
|
+
* injectable test seams; there is no process.cwd() fallback.
|
|
168
|
+
*/
|
|
169
|
+
function sampleFreeDiskGb(readers) {
|
|
170
|
+
if (Array.isArray(readers.paths)) {
|
|
171
|
+
if (readers.paths.length === 0) return undefined;
|
|
172
|
+
const statOne = typeof readers.statfsPath === 'function' ? readers.statfsPath : (path) => statfsSync(path);
|
|
173
|
+
let minimum;
|
|
174
|
+
for (const path of readers.paths) {
|
|
175
|
+
let sample;
|
|
176
|
+
try {
|
|
177
|
+
sample = toFreeDiskGb(statOne(path));
|
|
178
|
+
} catch {
|
|
179
|
+
return undefined;
|
|
180
|
+
}
|
|
181
|
+
if (sample === undefined) return undefined;
|
|
182
|
+
minimum = minimum === undefined ? sample : Math.min(minimum, sample);
|
|
183
|
+
}
|
|
184
|
+
return minimum;
|
|
185
|
+
}
|
|
186
|
+
if (typeof readers.statfs === 'function') {
|
|
187
|
+
try {
|
|
188
|
+
return toFreeDiskGb(readers.statfs());
|
|
189
|
+
} catch {
|
|
190
|
+
return undefined;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
return undefined;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
function readLiveHostResources(readers = {}) {
|
|
197
|
+
// Capture the start of collection, so slow readers cannot make old values newer.
|
|
198
|
+
const collectedAt = new Date((readers.now ?? Date.now)()).toISOString();
|
|
199
|
+
const readText = readers.readText ?? (path => readFileSync(path, 'utf8'));
|
|
200
|
+
const coreCount = readers.coreCount ?? (() => os.cpus().length);
|
|
201
|
+
const countWorkers = readers.countWorkers ?? (() => countWorkerProcesses(readers));
|
|
202
|
+
// 08 disk-pressure admission: free disk sampled through the same injectable
|
|
203
|
+
// resolver path as every other live signal, so tests feed synthetic values.
|
|
204
|
+
// Callers supply the evidence/worktree filesystems via `readers.paths`
|
|
205
|
+
// (threaded through `checkWorkerDispatch({ paths })`); without them free
|
|
206
|
+
// disk is unknown and the gate fails closed.
|
|
207
|
+
if (process.platform !== 'linux' && readers.readText === undefined) {
|
|
208
|
+
return { collectedAt, supported: false, reason: `live dispatch signals require Linux /proc (this host: ${process.platform})` };
|
|
209
|
+
}
|
|
210
|
+
const readOptional = (path) => {
|
|
211
|
+
try {
|
|
212
|
+
return readText(path);
|
|
213
|
+
} catch {
|
|
214
|
+
return undefined;
|
|
215
|
+
}
|
|
216
|
+
};
|
|
217
|
+
const cores = coreCount();
|
|
218
|
+
const load = parseLoadAverages(readOptional('/proc/loadavg') ?? '');
|
|
219
|
+
const psi = parseMemoryPsi(readOptional('/proc/pressure/memory') ?? '');
|
|
220
|
+
let workers;
|
|
221
|
+
try {
|
|
222
|
+
workers = countWorkers();
|
|
223
|
+
} catch {
|
|
224
|
+
workers = undefined;
|
|
225
|
+
}
|
|
226
|
+
return {
|
|
227
|
+
collectedAt,
|
|
228
|
+
supported: true,
|
|
229
|
+
availMemGb: parseMemAvailableGb(readOptional('/proc/meminfo') ?? ''),
|
|
230
|
+
load1: load?.load1,
|
|
231
|
+
cores: Number.isFinite(cores) && cores > 0 ? cores : undefined,
|
|
232
|
+
loadRatio: load && cores ? load.load1 / cores : undefined,
|
|
233
|
+
memPsiAvg10: psi?.avg10,
|
|
234
|
+
memPsiAvg60: psi?.avg60,
|
|
235
|
+
memPsiAvg300: psi?.avg300,
|
|
236
|
+
workers: typeof workers === 'object' ? workers?.total : workers,
|
|
237
|
+
...(typeof workers === 'object' ? { hostCliProcesses: workers?.hostCliProcesses, workerUnits: workers?.units,
|
|
238
|
+
workerCountingSource: workers?.source, workerGroups: workers?.byGroup } : {}),
|
|
239
|
+
freeDiskGb: sampleFreeDiskGb(readers),
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* Evaluate sampled live signals against thresholds. Every breach becomes a
|
|
245
|
+
* BLOCK failure naming its signal. Unknown-but-required signals (threshold
|
|
246
|
+
* configured, signal undetectable) fail closed with reason 'not detectable'.
|
|
247
|
+
*/
|
|
248
|
+
function evaluateDispatchGate(live, thresholds) {
|
|
249
|
+
const failures = [];
|
|
250
|
+
if (!live || live.supported === false) {
|
|
251
|
+
return {
|
|
252
|
+
ok: false,
|
|
253
|
+
failures: [{ signal: 'platform', reason: live?.reason ?? 'live host signals unavailable' }],
|
|
254
|
+
thresholds,
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
const breach = (signal, actual, threshold, reason) => failures.push({ signal, actual, threshold, reason });
|
|
258
|
+
if (!Number.isFinite(live.availMemGb)) breach('avail-mem', undefined, thresholds.min_avail_mem_gb, 'MemAvailable not detectable on this host');
|
|
259
|
+
else if (live.availMemGb < thresholds.min_avail_mem_gb) {
|
|
260
|
+
breach('avail-mem', live.availMemGb, thresholds.min_avail_mem_gb, `available ${live.availMemGb.toFixed(1)}GB < ${thresholds.min_avail_mem_gb}GB`);
|
|
261
|
+
}
|
|
262
|
+
if (!Number.isFinite(live.loadRatio)) breach('load', undefined, thresholds.max_load_ratio, 'load average not detectable on this host');
|
|
263
|
+
else if (live.loadRatio > thresholds.max_load_ratio) {
|
|
264
|
+
breach('load', live.loadRatio, thresholds.max_load_ratio, `load ratio ${live.loadRatio.toFixed(2)} > ${thresholds.max_load_ratio}`);
|
|
265
|
+
}
|
|
266
|
+
if (!Number.isFinite(live.memPsiAvg10)) breach('mem-psi-avg10', undefined, thresholds.max_mem_psi_avg10, '/proc/pressure/memory not detectable on this host');
|
|
267
|
+
else if (live.memPsiAvg10 > thresholds.max_mem_psi_avg10) {
|
|
268
|
+
breach('mem-psi-avg10', live.memPsiAvg10, thresholds.max_mem_psi_avg10, `memory PSI avg10 ${live.memPsiAvg10} > ${thresholds.max_mem_psi_avg10}`);
|
|
269
|
+
}
|
|
270
|
+
if (!Number.isFinite(live.memPsiAvg60)) breach('mem-psi-avg60', undefined, thresholds.max_mem_psi_avg60, '/proc/pressure/memory not detectable on this host');
|
|
271
|
+
else if (live.memPsiAvg60 > thresholds.max_mem_psi_avg60) {
|
|
272
|
+
breach('mem-psi-avg60', live.memPsiAvg60, thresholds.max_mem_psi_avg60, `memory PSI avg60 ${live.memPsiAvg60} > ${thresholds.max_mem_psi_avg60}`);
|
|
273
|
+
}
|
|
274
|
+
if (thresholds.max_workers !== undefined) {
|
|
275
|
+
if (!Number.isFinite(live.workers)) breach('workers', undefined, thresholds.max_workers, 'worker count not detectable on this host');
|
|
276
|
+
else if (live.workers >= thresholds.max_workers) {
|
|
277
|
+
breach('workers', live.workers, thresholds.max_workers, `${live.workers} running workers >= ${thresholds.max_workers}`);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
// 08 disk-pressure admission: unknown-but-required free disk fails closed,
|
|
281
|
+
// like every other required signal; under-threshold free disk blocks.
|
|
282
|
+
// Pre-sampled NaN/Infinity/negative readings are rejected here too, so a
|
|
283
|
+
// forged or broken sample can never satisfy the gate.
|
|
284
|
+
if (thresholds.min_free_disk_gb !== undefined && thresholds.min_free_disk_gb > 0) {
|
|
285
|
+
const disk = live.freeDiskGb;
|
|
286
|
+
if (disk === undefined || !Number.isFinite(disk) || disk < 0) {
|
|
287
|
+
breach('free-disk', undefined, thresholds.min_free_disk_gb, 'free disk not detectable on this host');
|
|
288
|
+
} else if (disk < thresholds.min_free_disk_gb) {
|
|
289
|
+
breach('free-disk', disk, thresholds.min_free_disk_gb, `free ${disk.toFixed(1)}GB < ${thresholds.min_free_disk_gb}GB`);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
return { ok: failures.length === 0, failures, thresholds };
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
|
|
296
|
+
export { parseMemAvailableGb, parseMemoryPsi, parseLoadAverages, listWorkerUnits, countWorkerUnits, countWorkerProcesses, defaultCountWorkers, readLiveHostResources, evaluateDispatchGate };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// Keep automatic redeployment from changing the explicitly installed selection.
|
|
2
|
+
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
3
|
+
import { resolve } from 'node:path';
|
|
4
|
+
import { REGISTRY_ID_TO_USE_NAME } from './framework-aliases.js';
|
|
5
|
+
const selection = new AsyncLocalStorage();
|
|
6
|
+
export function withInstalledSelection(project, installed, deploy) {
|
|
7
|
+
return selection.run({ project: resolve(project), installed: structuredClone(installed) }, deploy);
|
|
8
|
+
}
|
|
9
|
+
export function preserveInstalledSelection(project, config) {
|
|
10
|
+
const current = selection.getStore();
|
|
11
|
+
if (!current || current.project !== resolve(project))
|
|
12
|
+
return config;
|
|
13
|
+
const guarded = { ...config };
|
|
14
|
+
if (current.installed === undefined)
|
|
15
|
+
delete guarded.installed;
|
|
16
|
+
else
|
|
17
|
+
guarded.installed = Object.fromEntries(Object.entries(current.installed).map(([id, entry]) => [
|
|
18
|
+
id, structuredClone(config.installed?.[REGISTRY_ID_TO_USE_NAME[id] ?? id] ?? config.installed?.[id] ?? entry),
|
|
19
|
+
]));
|
|
20
|
+
return guarded;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=installed-selection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const WORKER_INVOCATION_MARKER: 'AIWG_WORKER_INVOCATION_ID';
|
|
@@ -5,6 +5,7 @@ import { fileURLToPath } from 'node:url';
|
|
|
5
5
|
import Ajv2020 from 'ajv/dist/2020.js';
|
|
6
6
|
import { admitEntry, DEFAULT_ENTRY_LIMITS } from '../entry.js';
|
|
7
7
|
import { heldoutDigest } from '../heldout/contract.js';
|
|
8
|
+
import { D17_ANALYSIS, validateD17Analysis } from './protocol.js';
|
|
8
9
|
const schemas = { analysis: 'D17StudyAnalysis', splits: 'D17StudySplits', gold: 'D17StudyGold',
|
|
9
10
|
review: 'D17StudyReview', guide: 'D17StudyGuide', report: 'D17StudyReport',
|
|
10
11
|
nativeTemplates: 'D17StudyNativeTemplates', dryRun: 'D17StudyDryRun',
|
|
@@ -33,6 +34,12 @@ export function validateD17Artifact(name, value) {
|
|
|
33
34
|
admitEntry(value, name === 'report' || name === 'reportV2' ? reportLimits : limits);
|
|
34
35
|
if (!validators[name]?.(value))
|
|
35
36
|
throw new Error(`D17 invalid ${name} artifact`);
|
|
37
|
+
if (name === 'analysis' || name === 'analysisV2') {
|
|
38
|
+
validateD17Analysis(value.protocol);
|
|
39
|
+
}
|
|
40
|
+
if (name === 'nativeTemplates') {
|
|
41
|
+
validateD17Analysis({ ...D17_ANALYSIS, native: value.comparison.pairedMetrics });
|
|
42
|
+
}
|
|
36
43
|
if (name === 'report' || name === 'reportV2') {
|
|
37
44
|
const report = value;
|
|
38
45
|
assertDecisionCeiling(report.decision, ceilingDecision('HOLD', report.integrity.release_gate.decision, report.integrity.compromise_labels.length ? 'ROLLBACK' : 'PROMOTE'));
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { scalarProvider } from '../../gates/providers/index.js';
|
|
2
|
+
export const D17_PACK_ID = 'project:d17-study';
|
|
3
|
+
export const D17_SLICES = ['direct-facts', 'multi-fact', 'negation', 'authority'];
|
|
4
|
+
const base = {
|
|
5
|
+
minimumPairs: 1200, minimumPerSlice: 300, maximumMissingPairs: 0,
|
|
6
|
+
nonInferiorityMarginBps: -300, benefitLowerExclusiveBps: 0,
|
|
7
|
+
maximumBrierUpperBps: 200, maximumAcceptedErrorUpperBps: 500,
|
|
8
|
+
minimumCoverageLowerBps: 6000, maximumAbstentionUpperBps: 500,
|
|
9
|
+
maximumP95LatencyIncreaseMs: 15000, maximumDisagreementBps: 1000,
|
|
10
|
+
minimumSuccessfulMembers: 3, highAgreementWarningBps: 100,
|
|
11
|
+
nativeRiskCoverage: 0.01, nativeLatency: 10000, nativeTokens: 8000, nativeCost: 800,
|
|
12
|
+
};
|
|
13
|
+
export const D17_NATIVE = [
|
|
14
|
+
{ metric: 'quality', comparison: 'delta-at-least', param: 'nonInferiorityMarginBps', divisor: 10000 },
|
|
15
|
+
{ metric: 'calibration', comparison: 'delta-at-most', param: 'maximumBrierUpperBps', divisor: 10000 },
|
|
16
|
+
{ metric: 'risk-coverage', comparison: 'delta-at-most', param: 'nativeRiskCoverage', divisor: 1 },
|
|
17
|
+
{ metric: 'abstention', comparison: 'delta-at-most', param: 'maximumAbstentionUpperBps', divisor: 10000 },
|
|
18
|
+
{ metric: 'latency', comparison: 'delta-at-most', param: 'nativeLatency', divisor: 1 },
|
|
19
|
+
{ metric: 'tokens', comparison: 'delta-at-most', param: 'nativeTokens', divisor: 1 },
|
|
20
|
+
{ metric: 'cost', comparison: 'delta-at-most', param: 'nativeCost', divisor: 1 },
|
|
21
|
+
{ metric: 'slice', comparison: 'delta-at-least', param: 'nonInferiorityMarginBps', divisor: 10000 },
|
|
22
|
+
];
|
|
23
|
+
export const d17NativeParameter = (metric) => `native_${metric.replaceAll('-', '_')}`;
|
|
24
|
+
export const D17_NATIVE_BOUNDS = Object.fromEntries(D17_NATIVE.map(row => [d17NativeParameter(row.metric), base[row.param] / row.divisor]));
|
|
25
|
+
export const D17_GATE_PARAMETERS = { ...base, ...D17_NATIVE_BOUNDS };
|
|
26
|
+
/** Scalar targets are the historical rounded endpoints, not newly recomputed intervals. */
|
|
27
|
+
export function d17GatePack() {
|
|
28
|
+
const definitions = [
|
|
29
|
+
['incomplete-pairs', 'minimumPairs', 'gte'], ['missing-pairs', 'maximumMissingPairs', 'lte'],
|
|
30
|
+
...D17_SLICES.map(slice => [`slice-support-${slice}`, 'minimumPerSlice', 'gte']),
|
|
31
|
+
['quality-ni', 'nonInferiorityMarginBps', 'gte'], ['brier-upper', 'maximumBrierUpperBps', 'lte'],
|
|
32
|
+
['abstention-upper', 'maximumAbstentionUpperBps', 'lte'],
|
|
33
|
+
['accepted-risk-upper', 'maximumAcceptedErrorUpperBps', 'lte'],
|
|
34
|
+
['coverage-lower', 'minimumCoverageLowerBps', 'gte'],
|
|
35
|
+
['latency-p95', 'maximumP95LatencyIncreaseMs', 'lte'],
|
|
36
|
+
['benefit', 'benefitLowerExclusiveBps', 'gte'],
|
|
37
|
+
...D17_NATIVE.map(row => [`native-${row.metric}`, d17NativeParameter(row.metric),
|
|
38
|
+
row.comparison === 'delta-at-least' ? 'gte' : 'lte']),
|
|
39
|
+
];
|
|
40
|
+
const direction = (name) => name.startsWith('minimum') || name === 'nonInferiorityMarginBps'
|
|
41
|
+
|| name === 'benefitLowerExclusiveBps' || name === 'native_quality' || name === 'native_slice' ? 'higher-is-stricter' : 'lower-is-stricter';
|
|
42
|
+
const gates = definitions.map(([id, param, op]) => {
|
|
43
|
+
const support = param === 'minimumPairs' || param === 'minimumPerSlice';
|
|
44
|
+
return { id, kind: support ? 'minimum-n' : 'value-threshold',
|
|
45
|
+
metric: { provider: scalarProvider.id, name: 'measurement' },
|
|
46
|
+
...(support ? { minimumN: { param } } : { threshold: { op, param } }),
|
|
47
|
+
scope: { mode: 'listed', slices: [id] },
|
|
48
|
+
...(id.startsWith('native-') ? { minimumN: { param: 'minimumPairs' } } : {}),
|
|
49
|
+
direction: op === 'gte' ? 'higher-is-stricter' : 'lower-is-stricter', onFail: 'HOLD' };
|
|
50
|
+
});
|
|
51
|
+
return { apiVersion: 'gates.aiwg.io/v1alpha1', kind: 'GatePack',
|
|
52
|
+
metadata: { id: D17_PACK_ID, version: '1.0.0', description: 'D17 historical diagnostic endpoints.' },
|
|
53
|
+
spec: { parameters: Object.fromEntries(Object.keys(D17_GATE_PARAMETERS).map(name => [name,
|
|
54
|
+
{ type: name === 'minimumPairs' || name === 'minimumPerSlice' ? 'count' : 'value', direction: direction(name) }])),
|
|
55
|
+
metrics: { measurement: { provider: scalarProvider.id, kind: 'scalar' } }, gates,
|
|
56
|
+
combine: { rule: 'max-severity' } } };
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=gate-policy.js.map
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
// Adapt validated D17 measurements to gate bindings without changing retained report bytes.
|
|
2
|
+
import { artifactDigest } from '../validate.js';
|
|
3
|
+
import { evaluateGates, sealGateHoldout, sealUpstream } from '../../gates/evaluate.js';
|
|
4
|
+
import { ceilingDecision } from '../../gates/lattice.js';
|
|
5
|
+
import { GateRegistry } from '../../gates/registry.js';
|
|
6
|
+
import { createCoreProviderRegistry, scalarProvider } from '../../gates/providers/index.js';
|
|
7
|
+
import { qualifyGateParameter } from '../../gates/types.js';
|
|
8
|
+
import { D17_GATE_PARAMETERS, D17_PACK_ID, d17GatePack } from './gate-policy.js';
|
|
9
|
+
const registry = new GateRegistry(createCoreProviderRegistry());
|
|
10
|
+
registry.registerPack(d17GatePack(), { namespace: 'project' });
|
|
11
|
+
const pack = registry.resolvePack(D17_PACK_ID);
|
|
12
|
+
const stamp = '2026-10-01T00:00:00.000Z';
|
|
13
|
+
export function d17GateBinding() {
|
|
14
|
+
return { apiVersion: 'gates.aiwg.io/v1alpha1', kind: 'GateBinding',
|
|
15
|
+
metadata: { id: 'd17-study', version: '1.0.0', description: 'Legacy D17 diagnostic replay policy.' },
|
|
16
|
+
spec: { packs: [{ id: D17_PACK_ID, version: '1.0.0', digest: pack.digest, resolvedDigest: pack.resolvedDigest }],
|
|
17
|
+
parameters: Object.fromEntries(Object.entries(D17_GATE_PARAMETERS).map(([name, value]) => [qualifyGateParameter(D17_PACK_ID, name), value])),
|
|
18
|
+
slices: pack.resolved.spec.gates.map(gate => gate.id), references: [],
|
|
19
|
+
metricProviders: [{ id: scalarProvider.id, version: scalarProvider.version, sourceDigest: scalarProvider.sourceDigest }],
|
|
20
|
+
registeredAt: stamp, frozenAt: stamp } };
|
|
21
|
+
}
|
|
22
|
+
/** Historical core metrics are caller-trusted; this adapter grants no new freeze/access attestation. */
|
|
23
|
+
export function d17GateInput(measurements, binding = d17GateBinding(), integrity) {
|
|
24
|
+
const m = measurements;
|
|
25
|
+
const bySlice = {};
|
|
26
|
+
const add = (id, value, n = m.sampleN) => { bySlice[id] = { n, value }; };
|
|
27
|
+
add('incomplete-pairs', m.sampleN);
|
|
28
|
+
add('missing-pairs', m.missingIds.length);
|
|
29
|
+
for (const row of m.slices)
|
|
30
|
+
add(`slice-support-${row.slice}`, row.n, row.n);
|
|
31
|
+
add('quality-ni', m.quality?.lowerBps ?? null);
|
|
32
|
+
add('brier-upper', m.brier?.upperBps ?? null);
|
|
33
|
+
add('abstention-upper', m.abstention?.upperBps ?? null);
|
|
34
|
+
add('accepted-risk-upper', m.acceptedErrorUpperBps);
|
|
35
|
+
add('coverage-lower', m.coverageLowerBps);
|
|
36
|
+
add('latency-p95', m.p95LatencyIncreaseMs);
|
|
37
|
+
// Integer basis-point lower bounds: subtract one to retain the strict benefit comparison.
|
|
38
|
+
add('benefit', m.quality ? m.quality.lowerBps - 1 : null);
|
|
39
|
+
for (const row of m.pairedDeltas) {
|
|
40
|
+
add(`native-${row.metric}`, row.delta, row.pairs);
|
|
41
|
+
}
|
|
42
|
+
const trustedBindingDigest = artifactDigest(binding);
|
|
43
|
+
return { binding, registry, trustedBindingDigest, metrics: { providers: {
|
|
44
|
+
[scalarProvider.id]: { version: scalarProvider.version, sourceDigest: scalarProvider.sourceDigest,
|
|
45
|
+
metrics: { measurement: { bySlice, pooled: null } } },
|
|
46
|
+
} }, holdout: sealGateHoldout({ frozenDigest: trustedBindingDigest, firstAccessedAt: null }),
|
|
47
|
+
upstream: integrity ? sealUpstream(integrity) : null, now: stamp,
|
|
48
|
+
// Legacy D17 replay must not pick up ambient project policy or claim a new operator approval.
|
|
49
|
+
floors: 'none-explicit-opt-out' };
|
|
50
|
+
}
|
|
51
|
+
/** Translate evaluated statuses only; threshold comparisons belong exclusively to evaluateGates. */
|
|
52
|
+
export function d17GateFindings(report) {
|
|
53
|
+
const findings = new Set();
|
|
54
|
+
for (const gate of report.gateEvidence) {
|
|
55
|
+
if (gate.status === 'pass' || gate.gateId === 'benefit')
|
|
56
|
+
continue;
|
|
57
|
+
if (gate.gateId === 'missing-pairs')
|
|
58
|
+
findings.add('incomplete-pairs');
|
|
59
|
+
else if (gate.gateId.startsWith('slice-support-'))
|
|
60
|
+
findings.add(`slice-insufficient:${gate.gateId.slice(14)}`);
|
|
61
|
+
else if (gate.gateId.startsWith('native-'))
|
|
62
|
+
findings.add(`paired-delta-${gate.n === 0 ? 'unknown' : gate.status === 'insufficient'
|
|
63
|
+
? 'insufficient' : 'failed'}:${gate.gateId.slice(7)}`);
|
|
64
|
+
else
|
|
65
|
+
findings.add(gate.gateId);
|
|
66
|
+
}
|
|
67
|
+
return { findings: [...findings].sort(), statisticalGate: findings.size ? 'HOLD' : 'pass',
|
|
68
|
+
benefitSupported: report.gateEvidence.some(gate => gate.gateId === 'benefit' && gate.status === 'pass') };
|
|
69
|
+
}
|
|
70
|
+
export function evaluateD17Statistics(measurements, binding, integrity) {
|
|
71
|
+
return evaluateGates(d17GateInput(measurements, binding, integrity));
|
|
72
|
+
}
|
|
73
|
+
/** Independent diagnostic ceiling: neither a binding nor the calibrated D09 route may promote a study. */
|
|
74
|
+
export function d17StudyDecision(report, integrity) {
|
|
75
|
+
// Preserve D17's original release/label policy rather than adopting additional upstream allowlist rules.
|
|
76
|
+
return ceilingDecision('HOLD', report.ceilings.packOutcome, report.ceilings.bindingCeiling, integrity.release_gate.decision, integrity.compromise_labels.length ? 'ROLLBACK' : 'PROMOTE');
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=gates.js.map
|
|
@@ -3,31 +3,28 @@ import { dirname, resolve } from 'node:path';
|
|
|
3
3
|
import { fileURLToPath } from 'node:url';
|
|
4
4
|
import Ajv2020 from 'ajv/dist/2020.js';
|
|
5
5
|
import { admitEntry } from '../entry.js';
|
|
6
|
+
import { canonicalJson } from '../../security/artifact-trust.js';
|
|
7
|
+
import { D17_GATE_PARAMETERS as bounds, D17_NATIVE, D17_NATIVE_BOUNDS, d17NativeParameter, D17_SLICES } from './gate-policy.js';
|
|
6
8
|
/** Frozen synthetic-population protocol. A changed threshold requires a new preregistration. */
|
|
7
9
|
export const D17_ANALYSIS = {
|
|
8
10
|
schemaVersion: 'decision-d17-protocol/v1',
|
|
9
|
-
minimumPairs:
|
|
10
|
-
slices:
|
|
11
|
-
minimumPerSlice:
|
|
12
|
-
interval: { method: 'newcombe-10', levelBps: 9500, nonInferiorityMarginBps:
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
11
|
+
minimumPairs: bounds.minimumPairs,
|
|
12
|
+
slices: D17_SLICES,
|
|
13
|
+
minimumPerSlice: bounds.minimumPerSlice,
|
|
14
|
+
interval: { method: 'newcombe-10', levelBps: 9500, nonInferiorityMarginBps: bounds.nonInferiorityMarginBps,
|
|
15
|
+
benefitLowerExclusiveBps: bounds.benefitLowerExclusiveBps },
|
|
16
|
+
brier: { method: 'percentile-bootstrap', levelBps: 9500, seed: 2611, resamples: 20000, maximumUpperBps: bounds.maximumBrierUpperBps },
|
|
17
|
+
risk: { method: 'wilson', levelBps: 9500, maximumAcceptedErrorUpperBps: bounds.maximumAcceptedErrorUpperBps,
|
|
18
|
+
minimumCoverageLowerBps: bounds.minimumCoverageLowerBps },
|
|
19
|
+
abstention: { method: 'newcombe-10', levelBps: 9500, maximumUpperBps: bounds.maximumAbstentionUpperBps },
|
|
20
|
+
maximumP95LatencyIncreaseMs: bounds.maximumP95LatencyIncreaseMs,
|
|
21
|
+
acceptance: { tieRule: 'defer', disagreementMetric: 'jensen-shannon-v1', maximumDisagreementBps: bounds.maximumDisagreementBps,
|
|
22
|
+
minimumSuccessfulMembers: bounds.minimumSuccessfulMembers, highAgreementWarningBps: bounds.highAgreementWarningBps },
|
|
19
23
|
economics: { kind: 'additional-cost-tolerance', positiveNetSavingsRequired: false, separateTradeoffApprovalRequired: true },
|
|
20
|
-
native:
|
|
21
|
-
|
|
22
|
-
{ metric: 'calibration', comparison: 'delta-at-most', bound: 0.02, minimumPairs: 1200 },
|
|
23
|
-
{ metric: 'risk-coverage', comparison: 'delta-at-most', bound: 0.01, minimumPairs: 1200 },
|
|
24
|
-
{ metric: 'abstention', comparison: 'delta-at-most', bound: 0.05, minimumPairs: 1200 },
|
|
25
|
-
{ metric: 'latency', comparison: 'delta-at-most', bound: 10000, minimumPairs: 1200 },
|
|
26
|
-
{ metric: 'tokens', comparison: 'delta-at-most', bound: 8000, minimumPairs: 1200 },
|
|
27
|
-
{ metric: 'cost', comparison: 'delta-at-most', bound: 800, minimumPairs: 1200 },
|
|
28
|
-
{ metric: 'slice', comparison: 'delta-at-least', bound: -0.03, minimumPairs: 1200 },
|
|
29
|
-
],
|
|
24
|
+
native: D17_NATIVE.map(row => ({ metric: row.metric, comparison: row.comparison,
|
|
25
|
+
bound: D17_NATIVE_BOUNDS[d17NativeParameter(row.metric)], minimumPairs: bounds.minimumPairs })),
|
|
30
26
|
};
|
|
27
|
+
const frozenProtocol = canonicalJson(D17_ANALYSIS);
|
|
31
28
|
const here = dirname(fileURLToPath(import.meta.url));
|
|
32
29
|
const schema = [resolve(here, '../../../schemas/decision'), resolve(here, '../../../../schemas/decision')]
|
|
33
30
|
.map(directory => resolve(directory, 'D17StudyProtocol.v1.schema.json')).find(existsSync);
|
|
@@ -36,7 +33,7 @@ if (!schema)
|
|
|
36
33
|
const validator = new Ajv2020({ strict: true }).compile(JSON.parse(readFileSync(schema, 'utf8')));
|
|
37
34
|
export function validateD17Analysis(value) {
|
|
38
35
|
admitEntry(value);
|
|
39
|
-
if (!validator(value))
|
|
36
|
+
if (!validator(value) || canonicalJson(value) !== frozenProtocol)
|
|
40
37
|
throw new Error('D17 protocol differs from the frozen v1 design');
|
|
41
38
|
}
|
|
42
39
|
/**
|
|
@@ -8,6 +8,7 @@ import { championChallengerInputSetDigest, championChallengerShadowBaseline, run
|
|
|
8
8
|
import { qualificationIntegrityAllowlistProblems } from '../qualification/release.js';
|
|
9
9
|
import { evaluateBinaryHeldout, freezeQualificationSplit } from '../qualification/quality.js';
|
|
10
10
|
import { D17_ANALYSIS } from './protocol.js';
|
|
11
|
+
import { d17StudyDecision, evaluateD17Statistics } from './gates.js';
|
|
11
12
|
import { d17Statistics } from './statistics.js';
|
|
12
13
|
import { validateD17Artifact } from './artifacts.js';
|
|
13
14
|
import { applyD17Mapping, assertD17Staged, d17AttemptsByRow, d17RawProbabilities, verifyD17CalibrationSet } from './calibration.js';
|
|
@@ -146,7 +147,7 @@ export async function scoreD17Study(input, prepared) {
|
|
|
146
147
|
calibrationDiagnostics: { champion: binary('champion'), challenger: binary('challenger'), calibrated: false },
|
|
147
148
|
pending: ['D09 compatible member and aggregate calibration', 'blind gold audit and delayed repeats', 'separate extra-cost tradeoff approval',
|
|
148
149
|
'protected native report approval and eligibility'],
|
|
149
|
-
decision:
|
|
150
|
+
decision: d17StudyDecision(evaluateD17Statistics(statistics, undefined, input.integrity), input.integrity) };
|
|
150
151
|
validateD17Artifact('report', report);
|
|
151
152
|
return report;
|
|
152
153
|
}
|
|
@@ -326,7 +327,7 @@ export async function scoreD17StagedStudy(input, prepared, context) {
|
|
|
326
327
|
mappingDigest: heldoutDigest(verified[role].mapping), compatibility: { action: 'allow',
|
|
327
328
|
state: verified[role].compatibility.state, pinId: verified[role].compatibility.pinId } });
|
|
328
329
|
const approved = input.approvedCalibration;
|
|
329
|
-
const decision =
|
|
330
|
+
const decision = d17StudyDecision(evaluateD17Statistics(statistics, undefined, input.integrity), input.integrity);
|
|
330
331
|
const report = { schemaVersion: 'decision-d17-study-report/v2', scope: 'synthetic-staged-calibrated',
|
|
331
332
|
calibrated: true, d09Qualified: true, calibratedGate: true,
|
|
332
333
|
corpusDigest: heldoutDigest(prepared.corpus), preregistrationDigest: heldoutDigest(prepared.preregistration),
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { pairedBinaryDifferenceInterval, pairedMeanDifferenceBootstrap,
|
|
2
|
-
import { pairedDeltaFinding } from '../ensemble/contract.js';
|
|
1
|
+
import { pairedBinaryDifferenceInterval, pairedMeanDifferenceBootstrap, wilsonScoreInterval } from '../qualification/quality.js';
|
|
3
2
|
import { D17_ANALYSIS, validateD17Analysis } from './protocol.js';
|
|
3
|
+
import { d17GateFindings, evaluateD17Statistics } from './gates.js';
|
|
4
4
|
const mean = (values) => values.reduce((sum, n) => sum + n, 0) / values.length;
|
|
5
5
|
const p95 = (values) => [...values].sort((a, b) => a - b)[Math.ceil(values.length * 0.95) - 1];
|
|
6
6
|
/** Abstentions are false for correctness, but true events in their own paired endpoint. */
|
|
@@ -13,7 +13,7 @@ function interval(pairs, endpoint, levelBps) {
|
|
|
13
13
|
return pairedBinaryDifferenceInterval({ counts, levelBps, method: 'newcombe-10' });
|
|
14
14
|
}
|
|
15
15
|
/** Local descriptive statistics, never a release authorization. Missing endpoints withhold native reporting. */
|
|
16
|
-
export function d17Statistics(pairs, expectedIds, protocol = D17_ANALYSIS) {
|
|
16
|
+
export function d17Statistics(pairs, expectedIds, protocol = D17_ANALYSIS, binding) {
|
|
17
17
|
validateD17Analysis(protocol);
|
|
18
18
|
const p = protocol;
|
|
19
19
|
if (new Set(expectedIds).size !== expectedIds.length || new Set(pairs.map(row => row.id)).size !== pairs.length
|
|
@@ -27,14 +27,9 @@ export function d17Statistics(pairs, expectedIds, protocol = D17_ANALYSIS) {
|
|
|
27
27
|
|| arm.tokens !== null && (!Number.isSafeInteger(arm.tokens) || arm.tokens < 0))
|
|
28
28
|
throw new Error('D17 unknown or invalid measurement');
|
|
29
29
|
}
|
|
30
|
-
const findings = [];
|
|
31
|
-
if (pairs.length !== expectedIds.length || pairs.length < p.minimumPairs)
|
|
32
|
-
findings.push('incomplete-pairs');
|
|
33
30
|
const slices = p.slices.map(slice => {
|
|
34
31
|
const rows = pairs.filter(row => row.slice === slice);
|
|
35
32
|
const delta = rows.length ? mean(rows.map(row => Number(row.challenger.correct) - Number(row.champion.correct))) : null;
|
|
36
|
-
if (rows.length < p.minimumPerSlice)
|
|
37
|
-
findings.push(`slice-insufficient:${slice}`);
|
|
38
33
|
return { slice, n: rows.length, qualityDelta: delta, harm: delta !== null && delta < 0, descriptiveOnly: true };
|
|
39
34
|
});
|
|
40
35
|
const metrics = (arm) => ({ quality: Number(arm.correct), calibration: arm.brier,
|
|
@@ -43,9 +38,6 @@ export function d17Statistics(pairs, expectedIds, protocol = D17_ANALYSIS) {
|
|
|
43
38
|
const pairedDeltas = p.native.map(threshold => {
|
|
44
39
|
const complete = pairs.filter(row => metrics(row.champion)[threshold.metric] !== null && metrics(row.challenger)[threshold.metric] !== null);
|
|
45
40
|
const item = { metric: threshold.metric, pairs: complete.length, delta: complete.length ? mean(complete.map(row => metrics(row.challenger)[threshold.metric] - metrics(row.champion)[threshold.metric])) : null };
|
|
46
|
-
const finding = pairedDeltaFinding(threshold, item);
|
|
47
|
-
if (finding)
|
|
48
|
-
findings.push(finding);
|
|
49
41
|
return item;
|
|
50
42
|
});
|
|
51
43
|
const quality = pairs.length ? interval(pairs, arm => arm.correct, p.interval.levelBps) : null;
|
|
@@ -58,26 +50,15 @@ export function d17Statistics(pairs, expectedIds, protocol = D17_ANALYSIS) {
|
|
|
58
50
|
const acceptedErrorUpperBps = risk ? Math.ceil(risk[1] * 10000) : null;
|
|
59
51
|
const coverageLowerBps = coverage ? Math.floor(coverage[0] * 10000) : null;
|
|
60
52
|
const p95LatencyIncreaseMs = pairs.length ? p95(pairs.map(row => row.challenger.latencyMs)) - p95(pairs.map(row => row.champion.latencyMs)) : null;
|
|
61
|
-
if (!quality || pairedNonInferiority({ interval: quality, marginBps: p.interval.nonInferiorityMarginBps }).decision !== 'non-inferior')
|
|
62
|
-
findings.push('quality-ni');
|
|
63
|
-
if (!brier || brier.upperBps > p.brier.maximumUpperBps)
|
|
64
|
-
findings.push('brier-upper');
|
|
65
|
-
if (!abstention || abstention.upperBps > p.abstention.maximumUpperBps)
|
|
66
|
-
findings.push('abstention-upper');
|
|
67
|
-
if (acceptedErrorUpperBps === null || acceptedErrorUpperBps > p.risk.maximumAcceptedErrorUpperBps)
|
|
68
|
-
findings.push('accepted-risk-upper');
|
|
69
|
-
if (coverageLowerBps === null || coverageLowerBps < p.risk.minimumCoverageLowerBps)
|
|
70
|
-
findings.push('coverage-lower');
|
|
71
|
-
if (p95LatencyIncreaseMs === null || p95LatencyIncreaseMs > p.maximumP95LatencyIncreaseMs)
|
|
72
|
-
findings.push('latency-p95');
|
|
73
53
|
const observed = new Set(pairs.map(row => row.id));
|
|
74
|
-
|
|
54
|
+
const measurements = { sampleN: pairs.length, missingIds: expectedIds.filter(id => !observed.has(id)), slices, pairedDeltas,
|
|
75
55
|
quality, brier, abstention, acceptedN: accepted.length, acceptedErrors: errors, acceptedErrorUpperBps, coverageLowerBps,
|
|
76
56
|
p95LatencyIncreaseMs, latencyDifferencesMs: pairs.map(row => row.challenger.latencyMs - row.champion.latencyMs),
|
|
77
57
|
netSavingsMicros: pairs.reduce((sum, row) => sum + row.champion.reservedCostMicros - row.challenger.reservedCostMicros, 0),
|
|
78
58
|
costBasis: 'nonrefundable-reservations-including-failed-attempts',
|
|
79
|
-
|
|
80
|
-
|
|
59
|
+
};
|
|
60
|
+
const gates = d17GateFindings(evaluateD17Statistics(measurements, binding));
|
|
61
|
+
return { ...measurements, benefitSupported: gates.benefitSupported, findings: gates.findings, statisticalGate: gates.statisticalGate,
|
|
81
62
|
worstCaseFailureAsError: { n: expectedIds.length, championCorrect: pairs.filter(row => row.champion.correct).length,
|
|
82
63
|
challengerCorrect: pairs.filter(row => row.challenger.correct).length, missingPairsCountedAsErrors: expectedIds.length - pairs.length } };
|
|
83
64
|
}
|