@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,74 @@
|
|
|
1
|
+
// Sign and verify D29 first-access records with the existing effect-ledger trust.
|
|
2
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
3
|
+
import { dirname, resolve } from 'node:path';
|
|
4
|
+
import { fileURLToPath } from 'node:url';
|
|
5
|
+
import Ajv2020 from 'ajv/dist/2020.js';
|
|
6
|
+
import addFormats from 'ajv-formats';
|
|
7
|
+
import { activeKey, assertKeyring, checkSignature } from '../../effects/keyring.js';
|
|
8
|
+
import { canonicalJson } from '../../security/artifact-trust.js';
|
|
9
|
+
import { heldoutDigest } from './contract.js';
|
|
10
|
+
export const HELDOUT_ACCESS_PAYLOAD_TYPE = 'application/vnd.aiwg.decision-d29-access+json';
|
|
11
|
+
let validator;
|
|
12
|
+
export function validateHeldoutAccess(value) {
|
|
13
|
+
if (!validator) {
|
|
14
|
+
const here = dirname(fileURLToPath(import.meta.url));
|
|
15
|
+
const name = 'D29Study.v10.schema.json';
|
|
16
|
+
const root = [resolve(here, '../../../schemas/decision'), resolve(here, '../../../../schemas/decision')]
|
|
17
|
+
.find(path => existsSync(resolve(path, name)));
|
|
18
|
+
if (!root)
|
|
19
|
+
throw new Error('first-access schema unavailable');
|
|
20
|
+
const schema = JSON.parse(readFileSync(resolve(root, name), 'utf8'));
|
|
21
|
+
const ajv = new Ajv2020({ strict: true });
|
|
22
|
+
addFormats(ajv);
|
|
23
|
+
validator = ajv.compile(schema);
|
|
24
|
+
}
|
|
25
|
+
if (!validator(value))
|
|
26
|
+
throw new Error('first-access record schema invalid');
|
|
27
|
+
}
|
|
28
|
+
const payload = (body) => Buffer.from(canonicalJson(body), 'utf8');
|
|
29
|
+
/** The keyring must come from protected host state, never from the access record. */
|
|
30
|
+
export function verifyHeldoutAccess(access, keyring) {
|
|
31
|
+
if (!access?.signature)
|
|
32
|
+
throw new Error('first-access signature missing');
|
|
33
|
+
if (typeof access.firstTestAccessAt !== 'string' || !Number.isFinite(Date.parse(access.firstTestAccessAt))) {
|
|
34
|
+
throw new Error('first-access timestamp is not a valid date-time');
|
|
35
|
+
}
|
|
36
|
+
validateHeldoutAccess(access);
|
|
37
|
+
try {
|
|
38
|
+
assertKeyring(keyring);
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
throw new Error('first-access keyring invalid or unavailable');
|
|
42
|
+
}
|
|
43
|
+
const { signature, ...body } = access;
|
|
44
|
+
const result = checkSignature(keyring, signature.keyid, signature.sig, HELDOUT_ACCESS_PAYLOAD_TYPE, payload(body), access.firstTestAccessAt);
|
|
45
|
+
if (result !== 'ok')
|
|
46
|
+
throw new Error(`first-access signature ${result}`);
|
|
47
|
+
}
|
|
48
|
+
/** Called at first access, before any test dispatch; never re-sign records during scoring. */
|
|
49
|
+
export function signHeldoutAccess(body, trust) {
|
|
50
|
+
assertKeyring(trust.keyring);
|
|
51
|
+
if (activeKey(trust.keyring).keyid !== trust.signingKey.keyid)
|
|
52
|
+
throw new Error('first-access signing key is not active');
|
|
53
|
+
const record = { ...body, signature: { keyid: trust.signingKey.keyid,
|
|
54
|
+
sig: trust.signingKey.signPae(HELDOUT_ACCESS_PAYLOAD_TYPE, payload(body)) } };
|
|
55
|
+
verifyHeldoutAccess(record, trust.keyring);
|
|
56
|
+
return record;
|
|
57
|
+
}
|
|
58
|
+
/** Uses the same configured delivery ledger as worker qualification; does not provision keys. */
|
|
59
|
+
export async function createHeldoutAccess(bundle, firstTestAccessAt, projectDir, injected, anchoredAt = bundle.preregistration.frozenAt) {
|
|
60
|
+
let trust = injected;
|
|
61
|
+
if (!trust) {
|
|
62
|
+
const { effectSession, openLedger } = await import('../../effects/host.js');
|
|
63
|
+
const { readLedgerKeyring } = await import('../../effects/ledger.js');
|
|
64
|
+
const ledger = openLedger(await effectSession(projectDir));
|
|
65
|
+
const keyring = await readLedgerKeyring(ledger);
|
|
66
|
+
if (!keyring)
|
|
67
|
+
throw new Error('first-access effect-ledger keyring unavailable');
|
|
68
|
+
trust = { keyring, signingKey: await ledger.signingKey() };
|
|
69
|
+
}
|
|
70
|
+
return signHeldoutAccess({ schemaVersion: 'decision-d29-access/v2', runId: bundle.approval.runId,
|
|
71
|
+
analysisDigest: bundle.preregistration.studyAnalysisDigest, frozenBundleDigest: heldoutDigest(bundle),
|
|
72
|
+
anchoredAt, firstTestAccessAt, reference: `heldout-run:${bundle.approval.runId}` }, trust);
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=access.js.map
|
|
@@ -132,6 +132,7 @@ export async function validateHeldoutPhaseAccess(bundle, runsRoot, priorRuns, ac
|
|
|
132
132
|
if (calibrationApproval(frozen.bundle) && !record.lineage.some(item => item.runId === frozen.bundle.approval.runId))
|
|
133
133
|
throw new HeldoutError('calibration-phase-lineage');
|
|
134
134
|
}
|
|
135
|
+
return record.sealedAt;
|
|
135
136
|
}
|
|
136
137
|
catch {
|
|
137
138
|
throw new HeldoutError('calibration-phase-access');
|
|
@@ -14,6 +14,7 @@ import { redactText } from '../../governance/redaction.js';
|
|
|
14
14
|
import { heldoutDigest, heldoutRequest, heldoutReservationMicros, heldoutReservationTokens, HeldoutError, HELDOUT_ENV_GATE, heldoutRowsInScope, heldoutResumeAttempts, heldoutPendingRequests, planHeldoutCollection, validateHeldoutBundle } from './contract.js';
|
|
15
15
|
import { appendHeldoutSpend, appendHeldoutEvent, heldoutDirectory, heldoutEvidenceDigest, heldoutRunsRoot, readHeldoutFile, readHeldoutJournal, reconcileHeldoutBaseline, scanHeldoutSpend, writeHeldoutFile, validateHeldoutJournal, heldoutCollectionAllowance } from './journal.js';
|
|
16
16
|
import { readHeldoutFrozen, sealHeldoutCalibrationPhase, validateHeldoutPhaseAccess } from './calibration.js';
|
|
17
|
+
import { createHeldoutAccess } from './access.js';
|
|
17
18
|
import { D17_MULTIFACT_CALIBRATION_NOT_AFTER, usesD17MultifactGenerator } from './study-generators.js';
|
|
18
19
|
const byteDigest = (bytes) => `sha256:${createHash('sha256').update(bytes).digest('hex')}`;
|
|
19
20
|
const delay = (ms) => new Promise(done => setTimeout(done, ms));
|
|
@@ -88,13 +89,19 @@ export async function collectHeldoutStudy(options) {
|
|
|
88
89
|
}
|
|
89
90
|
}
|
|
90
91
|
const testPhaseAccessAt = a.calibration.mode === 'staged' && a.calibration.phase === 'test' ? new Date(started).toISOString() : null;
|
|
91
|
-
await validateHeldoutPhaseAccess(bundle, heldoutRunsRoot(options.artifactRoot), prior.runs, testPhaseAccessAt);
|
|
92
|
+
const accessAnchoredAt = await validateHeldoutPhaseAccess(bundle, heldoutRunsRoot(options.artifactRoot), prior.runs, testPhaseAccessAt);
|
|
92
93
|
if (testPhaseAccessAt !== null)
|
|
93
94
|
await planHeldoutCollection(bundle, options.trustedApprovalDigest);
|
|
94
95
|
const rows = heldoutRowsInScope(bundle);
|
|
95
96
|
const run = join(heldoutRunsRoot(options.artifactRoot), a.runId);
|
|
96
97
|
await mkdir(run, { mode: 0o700 });
|
|
97
98
|
await writeHeldoutFile(join(run, 'frozen.json'), { schemaVersion: 'decision-heldout-frozen/v1', source: offline ? 'injected-transport' : 'provider', approval: { study: a.study, runId: a.runId }, bundle, baselineDigests, testPhaseAccessAt, collectionStartedAt: new Date(started).toISOString(), digest: heldoutDigest(bundle), priorRuns: prior.runs.filter(r => r.study === a.study && r.corpusDigest === a.corpusDigest) });
|
|
99
|
+
if (a.study === 'D29' && testPhaseAccessAt !== null) {
|
|
100
|
+
if (offline && !offline.accessSigning)
|
|
101
|
+
throw new HeldoutError('offline-access-signing-required');
|
|
102
|
+
const access = await createHeldoutAccess(bundle, testPhaseAccessAt, options.sourceRoot, offline?.accessSigning, accessAnchoredAt);
|
|
103
|
+
await writeHeldoutFile(join(run, 'access.json'), access);
|
|
104
|
+
}
|
|
98
105
|
const events = [];
|
|
99
106
|
const allowance = heldoutCollectionAllowance(a, prior);
|
|
100
107
|
let calls = 0, reserved = 0, accounted = 0, tokens = 0, lastDispatch = started - plan.minDispatchIntervalMs;
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
// Adapt the frozen D23 policy and validated observations to the shipped gate evaluator.
|
|
2
|
+
import { artifactDigest } from '../validate.js';
|
|
3
|
+
import { evaluateGates, sealGateHoldout, sealUpstream } from '../../gates/evaluate.js';
|
|
4
|
+
import { GateRegistry } from '../../gates/registry.js';
|
|
5
|
+
import { createCoreProviderRegistry, evidenceProvider, pairedProvider, proportionProvider } from '../../gates/providers/index.js';
|
|
6
|
+
import { qualifyGateParameter } from '../../gates/types.js';
|
|
7
|
+
export const COMPARATIVE_REPLAY_POLICY = {
|
|
8
|
+
minimumTestRoots: 400, minimumSliceRoots: 100, levelBps: 9500,
|
|
9
|
+
pairedMethod: 'newcombe-10', errorMethod: 'wilson', nonInferiorityMarginBps: -100,
|
|
10
|
+
maxErrorUpperBps: 100, maxSliceErrorUpperBps: 500,
|
|
11
|
+
maxBackendCalls: 0, maxTokens: 0, maxCostMicros: 0, requireExactReproduction: true,
|
|
12
|
+
};
|
|
13
|
+
const PACK_ID = 'project:d23-comparative-replay';
|
|
14
|
+
const SLICES = ['threshold-boundary', 'priority-loss', 'unchanged-control', 'unreplayable'];
|
|
15
|
+
const ALL = { mode: 'all' };
|
|
16
|
+
const LOWER = 'lower-is-stricter';
|
|
17
|
+
const HIGHER = 'higher-is-stricter';
|
|
18
|
+
const CHECKS = ['reports-valid', 'zero-call-budget-violated', 'reproduction-mismatch',
|
|
19
|
+
'integrity-sample-mismatch', 'reviewer-audit-pending'];
|
|
20
|
+
const NON_DIAGNOSTIC = new Set(['integrity-ceiling', 'integrity-sample-mismatch', 'reviewer-audit-pending']);
|
|
21
|
+
function replayPack() {
|
|
22
|
+
const errors = { provider: proportionProvider.id, name: 'false-ready' };
|
|
23
|
+
const gate = (id, kind, rest) => ({ id, kind, scope: ALL, direction: LOWER, onFail: 'HOLD', ...rest });
|
|
24
|
+
return {
|
|
25
|
+
apiVersion: 'gates.aiwg.io/v1alpha1', kind: 'GatePack',
|
|
26
|
+
metadata: { id: PACK_ID, version: '1.0.0', description: 'Frozen D23 comparative policy replay criteria.' },
|
|
27
|
+
spec: {
|
|
28
|
+
parameters: {
|
|
29
|
+
minimumTestRoots: { type: 'count', direction: HIGHER },
|
|
30
|
+
minimumSliceRoots: { type: 'count', direction: HIGHER },
|
|
31
|
+
levelBps: { type: 'level', direction: HIGHER },
|
|
32
|
+
nonInferiorityMarginBps: { type: 'value', direction: HIGHER },
|
|
33
|
+
maxErrorUpperBps: { type: 'bps', direction: LOWER },
|
|
34
|
+
maxSliceErrorUpperBps: { type: 'bps', direction: LOWER },
|
|
35
|
+
},
|
|
36
|
+
metrics: {
|
|
37
|
+
'false-ready': { provider: proportionProvider.id, kind: 'proportion' },
|
|
38
|
+
coverage: { provider: proportionProvider.id, kind: 'proportion' },
|
|
39
|
+
contrast: { provider: pairedProvider.id, kind: 'paired' },
|
|
40
|
+
attestations: { provider: evidenceProvider.id, kind: 'evidence' },
|
|
41
|
+
},
|
|
42
|
+
gates: [
|
|
43
|
+
gate('test-support-insufficient', 'minimum-n', { metric: errors, direction: HIGHER,
|
|
44
|
+
minimumN: { param: 'minimumTestRoots' } }),
|
|
45
|
+
gate('diagnostic-errors', 'count-max', { metric: errors, threshold: { op: 'lte', value: 0 } }),
|
|
46
|
+
gate('false-no-change', 'count-max', { metric: { provider: proportionProvider.id, name: 'coverage' },
|
|
47
|
+
threshold: { op: 'lte', value: 0 } }),
|
|
48
|
+
gate('non-inferiority-failed', 'paired-difference', {
|
|
49
|
+
metric: { provider: pairedProvider.id, name: 'contrast' }, direction: HIGHER,
|
|
50
|
+
statistic: { kind: 'paired-difference', method: 'newcombe', levelBps: { param: 'levelBps' },
|
|
51
|
+
mode: 'non-inferiority', marginBps: { param: 'nonInferiorityMarginBps' } },
|
|
52
|
+
}),
|
|
53
|
+
gate('error-bound-failed', 'interval-bound', { metric: errors,
|
|
54
|
+
statistic: { kind: 'interval-bound', method: 'wilson', bound: 'upper', levelBps: { param: 'levelBps' } },
|
|
55
|
+
threshold: { op: 'lte', param: 'maxErrorUpperBps' } }),
|
|
56
|
+
gate('slice-support', 'minimum-n', { metric: errors, direction: HIGHER, scope: { mode: 'each' },
|
|
57
|
+
minimumN: { param: 'minimumSliceRoots' } }),
|
|
58
|
+
gate('slice-errors', 'count-max', { metric: errors, scope: { mode: 'each' }, threshold: { op: 'lte', value: 0 } }),
|
|
59
|
+
gate('slice-error-bound', 'interval-bound', { metric: errors, scope: { mode: 'each' },
|
|
60
|
+
statistic: { kind: 'interval-bound', method: 'wilson', bound: 'upper', levelBps: { param: 'levelBps' } },
|
|
61
|
+
threshold: { op: 'lte', param: 'maxSliceErrorUpperBps' } }),
|
|
62
|
+
...CHECKS.map(id => gate(id, 'evidence', {
|
|
63
|
+
metric: { provider: evidenceProvider.id, name: 'attestations' }, evidence: { required: [id] },
|
|
64
|
+
})),
|
|
65
|
+
gate('integrity-ceiling', 'upstream-ceiling', { direction: HIGHER, floor: true }),
|
|
66
|
+
],
|
|
67
|
+
combine: { rule: 'max-severity' },
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
/** Pure adapter; historical D23 trust pins remain validated by the comparative report owner. */
|
|
72
|
+
export function comparativeReplayGateInput(input, rows, usage, reportFindings) {
|
|
73
|
+
const plan = input.preregistration;
|
|
74
|
+
if (plan.pairedMethod !== COMPARATIVE_REPLAY_POLICY.pairedMethod
|
|
75
|
+
|| plan.errorMethod !== COMPARATIVE_REPLAY_POLICY.errorMethod) {
|
|
76
|
+
throw new Error('D23 comparative replay requires pairedMethod newcombe-10 and errorMethod wilson');
|
|
77
|
+
}
|
|
78
|
+
const providers = createCoreProviderRegistry();
|
|
79
|
+
const registry = new GateRegistry(providers);
|
|
80
|
+
registry.registerPack(replayPack(), { namespace: 'project' });
|
|
81
|
+
const pack = registry.resolvePack(PACK_ID);
|
|
82
|
+
const metricProviders = [proportionProvider, pairedProvider, evidenceProvider];
|
|
83
|
+
const binding = {
|
|
84
|
+
apiVersion: 'gates.aiwg.io/v1alpha1', kind: 'GateBinding',
|
|
85
|
+
metadata: { id: plan.id, version: '1.0.0', description: 'D23 frozen synthetic policy replay.' },
|
|
86
|
+
spec: {
|
|
87
|
+
packs: [{ id: PACK_ID, version: '1.0.0', digest: pack.digest, resolvedDigest: pack.resolvedDigest }],
|
|
88
|
+
parameters: Object.fromEntries(['minimumTestRoots', 'minimumSliceRoots', 'levelBps',
|
|
89
|
+
'nonInferiorityMarginBps', 'maxErrorUpperBps', 'maxSliceErrorUpperBps'].map(name => [qualifyGateParameter(PACK_ID, name), plan[name]])),
|
|
90
|
+
slices: [...SLICES], references: [],
|
|
91
|
+
metricProviders: metricProviders.map(({ id, version, sourceDigest }) => ({ id, version, sourceDigest })),
|
|
92
|
+
registeredAt: plan.frozenAt, frozenAt: plan.frozenAt,
|
|
93
|
+
corpusDigest: plan.corpusDigest, goldDigest: plan.goldDigest, splitDigest: plan.splitDigest,
|
|
94
|
+
},
|
|
95
|
+
};
|
|
96
|
+
const testRows = rows.filter(row => row.split === 'test');
|
|
97
|
+
const checks = {
|
|
98
|
+
'reports-valid': reportFindings.size === 0,
|
|
99
|
+
'zero-call-budget-violated': usage.backendCalls <= plan.maxBackendCalls
|
|
100
|
+
&& usage.tokens <= plan.maxTokens && usage.costMicros <= plan.maxCostMicros,
|
|
101
|
+
'reproduction-mismatch': usage.exactReproduction,
|
|
102
|
+
'integrity-sample-mismatch': input.integrity.sample_n === testRows.length,
|
|
103
|
+
'reviewer-audit-pending': false,
|
|
104
|
+
};
|
|
105
|
+
const trustedBindingDigest = artifactDigest(binding);
|
|
106
|
+
return {
|
|
107
|
+
binding, registry, trustedBindingDigest,
|
|
108
|
+
holdout: sealGateHoldout({ frozenDigest: trustedBindingDigest, firstAccessedAt: input.accessedAt }),
|
|
109
|
+
upstream: sealUpstream(input.integrity), now: input.accessedAt,
|
|
110
|
+
// Legacy retained D23 policy: no ambient project configuration may change historical replay.
|
|
111
|
+
floors: 'none-explicit-opt-out',
|
|
112
|
+
metrics: { providers: {
|
|
113
|
+
[proportionProvider.id]: proportionProvider.compute(testRows.flatMap(row => [
|
|
114
|
+
{ slice: row.slice, metric: 'false-ready', event: !row.correct },
|
|
115
|
+
{ slice: row.slice, metric: 'coverage', event: row.falseNoChange },
|
|
116
|
+
])),
|
|
117
|
+
[pairedProvider.id]: pairedProvider.compute(testRows.map(row => ({ slice: row.slice, candidate: row.correct, baseline: true }))),
|
|
118
|
+
[evidenceProvider.id]: evidenceProvider.compute(CHECKS.map(id => ({ id, passed: checks[id] }))),
|
|
119
|
+
} },
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
export function evaluateComparativeReplayGates(...args) {
|
|
123
|
+
const context = comparativeReplayGateInput(...args);
|
|
124
|
+
return { binding: context.binding, gateReport: evaluateGates(context) };
|
|
125
|
+
}
|
|
126
|
+
/** Translate gate evidence to the retained D23 finding vocabulary without re-evaluating thresholds. */
|
|
127
|
+
export function comparativeReplayGateFindings(report) {
|
|
128
|
+
const failed = report.gateEvidence.filter(gate => gate.status !== 'pass');
|
|
129
|
+
const findings = new Set(failed.filter(gate => gate.gateId !== 'reports-valid' && gate.gateId !== 'integrity-ceiling')
|
|
130
|
+
.map(gate => gate.gateId.startsWith('slice-') ? `slice-failed:${gate.slice}` : gate.gateId));
|
|
131
|
+
for (const reason of report.upstream?.reasons ?? [])
|
|
132
|
+
findings.add(reason.replace(/^upstream:/, ''));
|
|
133
|
+
return { findings: [...findings], diagnosticDecision: failed.some(gate => !NON_DIAGNOSTIC.has(gate.gateId)) ? 'fail' : 'pass' };
|
|
134
|
+
}
|
|
135
|
+
//# sourceMappingURL=comparative-gates.js.map
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import { assertDecisionCeiling
|
|
2
|
-
import {
|
|
3
|
-
import { qualificationIntegrityAllowlistProblems } from '../qualification/release.js';
|
|
1
|
+
import { assertDecisionCeiling } from '../../gates/lattice.js';
|
|
2
|
+
import { comparativeReplayGateFindings, evaluateComparativeReplayGates } from './comparative-gates.js';
|
|
4
3
|
import { checkSensitivitySchema, sensitivityDigest, validateSensitivityReport } from './contract.js';
|
|
5
4
|
export const REPLAY_SLICES = ['threshold-boundary', 'priority-loss', 'unchanged-control', 'unreplayable'];
|
|
6
5
|
const DIGEST = /^sha256:[0-9a-f]{64}$/;
|
|
7
|
-
const bpsUpper = (events, n, levelBps) => n ? Math.ceil(wilsonScoreInterval({ events, n, levelBps })[1] * 10_000) : null;
|
|
8
6
|
export function validateComparativeReplayPreregistration(value) {
|
|
9
7
|
checkSensitivitySchema('comparativePlan', value);
|
|
10
8
|
if (value.minimumTestRoots < value.minimumSliceRoots * REPLAY_SLICES.length) {
|
|
@@ -15,7 +13,7 @@ export function validateComparativeReplayPreregistration(value) {
|
|
|
15
13
|
throw new Error('comparative replay preregistration digest mismatch');
|
|
16
14
|
}
|
|
17
15
|
/** Rebuild from trusted preregistration, stored reports and independently authored gold. */
|
|
18
|
-
export function
|
|
16
|
+
export function buildComparativeReplayEvaluation(input) {
|
|
19
17
|
const plan = input.preregistration;
|
|
20
18
|
validateComparativeReplayPreregistration(plan);
|
|
21
19
|
if (plan.digest !== input.trustedPreregistrationDigest)
|
|
@@ -92,45 +90,21 @@ export function buildComparativeReplayReport(input) {
|
|
|
92
90
|
const testRows = rows.filter(row => row.split === 'test');
|
|
93
91
|
const errors = testRows.filter(row => !row.correct).length;
|
|
94
92
|
const falseNoChange = testRows.filter(row => row.falseNoChange).length;
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
const
|
|
93
|
+
if (input.reviewerAuditDigest !== null)
|
|
94
|
+
throw new Error('operator review ingestion is not implemented');
|
|
95
|
+
const { binding, gateReport: gates } = evaluateComparativeReplayGates(input, rows, { backendCalls, tokens, costMicros, exactReproduction }, findings);
|
|
96
|
+
const { diagnosticDecision, findings: gateFindings } = comparativeReplayGateFindings(gates);
|
|
97
|
+
for (const finding of gateFindings)
|
|
98
|
+
findings.add(finding);
|
|
99
|
+
const pairedLowerBps = gates.gateEvidence.find(gate => gate.gateId === 'non-inferiority-failed')?.statistic?.lowerBps ?? null;
|
|
100
|
+
const errorUpperBps = gates.gateEvidence.find(gate => gate.gateId === 'error-bound-failed')?.statistic?.upperBps ?? null;
|
|
98
101
|
const slices = Object.fromEntries(REPLAY_SLICES.map(slice => {
|
|
99
102
|
const items = testRows.filter(row => row.slice === slice);
|
|
100
|
-
|
|
101
|
-
|
|
103
|
+
return [slice, { roots: items.length, errors: items.filter(row => !row.correct).length,
|
|
104
|
+
errorUpperBps: gates.gateEvidence.find(gate => gate.gateId === 'slice-error-bound' && gate.slice === slice)?.statistic?.upperBps ?? null }];
|
|
102
105
|
}));
|
|
103
|
-
if (testRows.length < plan.minimumTestRoots)
|
|
104
|
-
findings.add('test-support-insufficient');
|
|
105
|
-
if (errors > 0)
|
|
106
|
-
findings.add('diagnostic-errors');
|
|
107
|
-
if (falseNoChange > 0)
|
|
108
|
-
findings.add('false-no-change');
|
|
109
|
-
if (pairedLowerBps === null || pairedLowerBps < plan.nonInferiorityMarginBps)
|
|
110
|
-
findings.add('non-inferiority-failed');
|
|
111
|
-
if (errorUpperBps === null || errorUpperBps > plan.maxErrorUpperBps)
|
|
112
|
-
findings.add('error-bound-failed');
|
|
113
|
-
for (const slice of REPLAY_SLICES) {
|
|
114
|
-
const metric = slices[slice];
|
|
115
|
-
if (metric.roots < plan.minimumSliceRoots || metric.errors > 0
|
|
116
|
-
|| metric.errorUpperBps === null || metric.errorUpperBps > plan.maxSliceErrorUpperBps)
|
|
117
|
-
findings.add(`slice-failed:${slice}`);
|
|
118
|
-
}
|
|
119
|
-
if (backendCalls > plan.maxBackendCalls || tokens > plan.maxTokens || costMicros > plan.maxCostMicros)
|
|
120
|
-
findings.add('zero-call-budget-violated');
|
|
121
|
-
if (!exactReproduction)
|
|
122
|
-
findings.add('reproduction-mismatch');
|
|
123
|
-
const diagnosticDecision = findings.size === 0 ? 'pass' : 'fail';
|
|
124
|
-
for (const problem of qualificationIntegrityAllowlistProblems(input.integrity))
|
|
125
|
-
findings.add(problem);
|
|
126
|
-
if (input.integrity.sample_n !== testRows.length)
|
|
127
|
-
findings.add('integrity-sample-mismatch');
|
|
128
|
-
if (input.reviewerAuditDigest !== null)
|
|
129
|
-
throw new Error('operator review ingestion is not implemented');
|
|
130
|
-
findings.add('reviewer-audit-pending');
|
|
131
106
|
const upstreamDecision = input.integrity.release_gate.decision;
|
|
132
|
-
const decision =
|
|
133
|
-
|| input.integrity.compromise_labels.length > 0 ? 'ROLLBACK' : 'PROMOTE', findings.size > 0 ? 'HOLD' : 'PROMOTE');
|
|
107
|
+
const decision = gates.decision;
|
|
134
108
|
const payload = {
|
|
135
109
|
schemaVersion: 'decision-comparative-replay-report/v1', mode: 'shadow',
|
|
136
110
|
semantics: 'associative-sensitivity-not-causal', actionAuthorization: 'not-authorized',
|
|
@@ -143,7 +117,10 @@ export function buildComparativeReplayReport(input) {
|
|
|
143
117
|
};
|
|
144
118
|
const report = { ...payload, digest: sensitivityDigest(payload) };
|
|
145
119
|
checkSensitivitySchema('comparativeReport', report);
|
|
146
|
-
return report;
|
|
120
|
+
return { report, binding, gateReport: gates };
|
|
121
|
+
}
|
|
122
|
+
export function buildComparativeReplayReport(input) {
|
|
123
|
+
return buildComparativeReplayEvaluation(input).report;
|
|
147
124
|
}
|
|
148
125
|
export function validateComparativeReplayReport(report, input) {
|
|
149
126
|
checkSensitivitySchema('comparativeReport', report);
|
|
@@ -63,13 +63,12 @@ export function fileDigestVerifier(options) {
|
|
|
63
63
|
if (errno(error) !== 'ENOENT' && errno(error) !== 'ENOTDIR')
|
|
64
64
|
return unknown('container-unreadable');
|
|
65
65
|
// Missing: `absent` only when the nearest existing ancestor is itself contained.
|
|
66
|
-
let parent =
|
|
66
|
+
let parent = lexical;
|
|
67
67
|
for (;;) {
|
|
68
|
+
// An existing but unresolvable component (such as a dangling
|
|
69
|
+
// symlink) is unknown. Never step above it and call the file absent.
|
|
68
70
|
try {
|
|
69
|
-
|
|
70
|
-
if (realParent !== root && !inside(root, realParent))
|
|
71
|
-
return unknown('container-unreadable');
|
|
72
|
-
break;
|
|
71
|
+
await lstat(parent);
|
|
73
72
|
}
|
|
74
73
|
catch (inner) {
|
|
75
74
|
if (errno(inner) !== 'ENOENT' && errno(inner) !== 'ENOTDIR')
|
|
@@ -77,6 +76,18 @@ export function fileDigestVerifier(options) {
|
|
|
77
76
|
if (parent === dirname(parent))
|
|
78
77
|
return unknown('container-unreadable');
|
|
79
78
|
parent = dirname(parent);
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
try {
|
|
82
|
+
const realParent = await realpath(parent);
|
|
83
|
+
if (realParent !== root && !inside(root, realParent))
|
|
84
|
+
return unknown('container-unreadable');
|
|
85
|
+
if (!(await lstat(realParent)).isDirectory())
|
|
86
|
+
return unknown('container-unreadable');
|
|
87
|
+
break;
|
|
88
|
+
}
|
|
89
|
+
catch {
|
|
90
|
+
return unknown('container-unreadable');
|
|
80
91
|
}
|
|
81
92
|
}
|
|
82
93
|
const evidence = { path, expectedDigest: digest, found: false };
|
|
@@ -97,6 +108,12 @@ export function fileDigestVerifier(options) {
|
|
|
97
108
|
return unknown('container-unreadable');
|
|
98
109
|
}
|
|
99
110
|
const evidence = { path, expectedDigest: digest, actualDigest: actual, found: true };
|
|
111
|
+
// Query-only callers may ask whether a digest is absent. Replay callers
|
|
112
|
+
// must also prove that existing bytes are the recorded pre-write state.
|
|
113
|
+
if (actual !== digest && request.expected.previousDigest !== undefined
|
|
114
|
+
&& actual !== request.expected.previousDigest) {
|
|
115
|
+
return { ...unknown('evidence-conflict'), evidence };
|
|
116
|
+
}
|
|
100
117
|
return actual === digest
|
|
101
118
|
? { result: 'present', reason: 'digest-match', complete: true, evidence }
|
|
102
119
|
: { result: 'absent', reason: 'complete-query-no-match', complete: true, evidence };
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
// Merge and undo Claude attribution defaults, and inspect effective settings offline.
|
|
2
|
+
import { promises as fs } from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import os from 'node:os';
|
|
5
|
+
const DEFAULTS = { commit: '', pr: '', sessionUrl: false };
|
|
6
|
+
const object = (value) => value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
7
|
+
export function mergeClaudeAttribution(settings, warnings) {
|
|
8
|
+
if (settings.attribution !== undefined && !object(settings.attribution)) {
|
|
9
|
+
warnings.push('Preserved operator attribution setting; expected an object.');
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
if (settings.aiwg !== undefined && !object(settings.aiwg)) {
|
|
13
|
+
warnings.push('Preserved the existing non-object "aiwg" setting; AIWG attribution defaults were not merged.');
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
const attribution = (settings.attribution ??= {});
|
|
17
|
+
const aiwg = (settings.aiwg ?? {});
|
|
18
|
+
const owned = new Set(Array.isArray(aiwg.attributionKeys) ? aiwg.attributionKeys : []);
|
|
19
|
+
for (const [key, value] of Object.entries(DEFAULTS)) {
|
|
20
|
+
if (attribution[key] === undefined) {
|
|
21
|
+
attribution[key] = value;
|
|
22
|
+
owned.add(key);
|
|
23
|
+
}
|
|
24
|
+
else if (attribution[key] !== value) {
|
|
25
|
+
warnings.push(`Preserved operator attribution.${key}; attribution remains enabled. Clear it explicitly to disable attribution.`);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
if (owned.size) {
|
|
29
|
+
aiwg.attributionKeys = [...owned];
|
|
30
|
+
settings.aiwg = aiwg;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
export function undoClaudeAttribution(settings) {
|
|
34
|
+
if (!object(settings.aiwg) || !Array.isArray(settings.aiwg.attributionKeys))
|
|
35
|
+
return false;
|
|
36
|
+
const attribution = settings.attribution;
|
|
37
|
+
if (object(attribution)) {
|
|
38
|
+
for (const key of settings.aiwg.attributionKeys) {
|
|
39
|
+
if (Object.hasOwn(DEFAULTS, key) && attribution[key] === DEFAULTS[key]) {
|
|
40
|
+
delete attribution[key];
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
if (Object.keys(attribution).length === 0)
|
|
44
|
+
delete settings.attribution;
|
|
45
|
+
}
|
|
46
|
+
delete settings.aiwg.attributionKeys;
|
|
47
|
+
if (Object.keys(settings.aiwg).length === 0)
|
|
48
|
+
delete settings.aiwg;
|
|
49
|
+
return true;
|
|
50
|
+
}
|
|
51
|
+
/** Higher-precedence files override individual keys; missing keys use Claude defaults. */
|
|
52
|
+
export async function checkClaudeAttribution(projectPath, home = os.homedir(), managedFile = path.join(process.platform === 'darwin' ? '/Library/Application Support/ClaudeCode'
|
|
53
|
+
: process.platform === 'win32' ? path.join(process.env.ProgramFiles || 'C:\\Program Files', 'ClaudeCode')
|
|
54
|
+
: '/etc/claude-code', 'managed-settings.json')) {
|
|
55
|
+
const effective = { commit: '(Claude default)', pr: '(Claude default)', sessionUrl: true };
|
|
56
|
+
const sources = [path.join(home, '.claude/settings.json'), path.join(projectPath, '.claude/settings.json'),
|
|
57
|
+
path.join(projectPath, '.claude/settings.local.json'), managedFile];
|
|
58
|
+
try {
|
|
59
|
+
for (const file of sources) {
|
|
60
|
+
let settings;
|
|
61
|
+
try {
|
|
62
|
+
settings = JSON.parse(await fs.readFile(file, 'utf8'));
|
|
63
|
+
}
|
|
64
|
+
catch (err) {
|
|
65
|
+
if (err.code === 'ENOENT')
|
|
66
|
+
continue;
|
|
67
|
+
throw err;
|
|
68
|
+
}
|
|
69
|
+
if (settings.attribution === false)
|
|
70
|
+
Object.assign(effective, DEFAULTS);
|
|
71
|
+
else if (object(settings.attribution))
|
|
72
|
+
Object.assign(effective, settings.attribution);
|
|
73
|
+
}
|
|
74
|
+
const enabled = Object.keys(DEFAULTS).filter(key => effective[key] !== DEFAULTS[key]);
|
|
75
|
+
return enabled.length ? { status: 'warn', message: `Effective Claude attribution enabled: ${enabled.join(', ')}. Run: aiwg use all --provider claude. Existing operator values are preserved; clear those keys explicitly in the overriding settings file. Session-only overrides are not inspected.` }
|
|
76
|
+
: { status: 'ok', message: 'Claude attribution disabled by user/project/managed settings (session-only overrides are not inspected).' };
|
|
77
|
+
}
|
|
78
|
+
catch (err) {
|
|
79
|
+
return { status: 'warn', message: `Could not inspect Claude attribution: ${err instanceof Error ? err.message : String(err)}. Run: aiwg use all --provider claude after repairing settings JSON.` };
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
//# sourceMappingURL=claude-attribution.js.map
|