@warpgogol/forge 9.7.0 → 10.0.0
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/AGENTS.md +50 -27
- package/CHANGELOG.md +52 -0
- package/bin/cli.js +0 -0
- package/dist/os/adr/handlers/archive.d.ts.map +1 -1
- package/dist/os/adr/handlers/archive.js +3 -7
- package/dist/os/adr/handlers/archive.js.map +1 -1
- package/dist/os/adr/handlers/list-create.d.ts.map +1 -1
- package/dist/os/adr/handlers/list-create.js +8 -6
- package/dist/os/adr/handlers/list-create.js.map +1 -1
- package/dist/os/audit/handlers/archive.d.ts.map +1 -1
- package/dist/os/audit/handlers/archive.js +3 -7
- package/dist/os/audit/handlers/archive.js.map +1 -1
- package/dist/os/codebase/handlers/codebase-measure-symbols.d.ts.map +1 -1
- package/dist/os/codebase/handlers/codebase-measure-symbols.js +35 -4
- package/dist/os/codebase/handlers/codebase-measure-symbols.js.map +1 -1
- package/dist/os/core/archive-regen.d.ts +1 -0
- package/dist/os/core/archive-regen.d.ts.map +1 -1
- package/dist/os/core/archive-regen.js +31 -6
- package/dist/os/core/archive-regen.js.map +1 -1
- package/dist/os/core/core.module.d.ts.map +1 -1
- package/dist/os/core/core.module.js +6 -69
- package/dist/os/core/core.module.js.map +1 -1
- package/dist/os/core/handlers/assets-helpers.d.ts.map +1 -1
- package/dist/os/core/handlers/assets-helpers.js +2 -3
- package/dist/os/core/handlers/assets-helpers.js.map +1 -1
- package/dist/os/core/handlers/determinism-check.d.ts.map +1 -1
- package/dist/os/core/handlers/determinism-check.js +2 -3
- package/dist/os/core/handlers/determinism-check.js.map +1 -1
- package/dist/os/core/handlers/pinned-check.d.ts +13 -0
- package/dist/os/core/handlers/pinned-check.d.ts.map +1 -1
- package/dist/os/core/handlers/pinned-check.js +25 -0
- package/dist/os/core/handlers/pinned-check.js.map +1 -1
- package/dist/os/core/handlers/pinned-types.d.ts +7 -0
- package/dist/os/core/handlers/pinned-types.d.ts.map +1 -1
- package/dist/os/core/handlers/pinned-validate.d.ts.map +1 -1
- package/dist/os/core/handlers/pinned-validate.js +24 -1
- package/dist/os/core/handlers/pinned-validate.js.map +1 -1
- package/dist/os/core/handlers/release-prepare.d.ts.map +1 -1
- package/dist/os/core/handlers/release-prepare.js +2 -4
- package/dist/os/core/handlers/release-prepare.js.map +1 -1
- package/dist/os/flow/digest.d.ts +73 -1
- package/dist/os/flow/digest.d.ts.map +1 -1
- package/dist/os/flow/digest.js +344 -92
- package/dist/os/flow/digest.js.map +1 -1
- package/dist/os/flow/evidence-lock.d.ts +36 -0
- package/dist/os/flow/evidence-lock.d.ts.map +1 -0
- package/dist/os/flow/evidence-lock.js +156 -0
- package/dist/os/flow/evidence-lock.js.map +1 -0
- package/dist/os/flow/flow.module.d.ts.map +1 -1
- package/dist/os/flow/flow.module.js +36 -14
- package/dist/os/flow/flow.module.js.map +1 -1
- package/dist/os/flow/git.d.ts +50 -3
- package/dist/os/flow/git.d.ts.map +1 -1
- package/dist/os/flow/git.js +144 -12
- package/dist/os/flow/git.js.map +1 -1
- package/dist/os/flow/handlers/flow-digest.d.ts.map +1 -1
- package/dist/os/flow/handlers/flow-digest.js +3 -5
- package/dist/os/flow/handlers/flow-digest.js.map +1 -1
- package/dist/os/flow/handlers/flow-peers.js +1 -1
- package/dist/os/flow/handlers/flow-peers.js.map +1 -1
- package/dist/os/flow/handlers/flow-push.d.ts +81 -0
- package/dist/os/flow/handlers/flow-push.d.ts.map +1 -1
- package/dist/os/flow/handlers/flow-push.js +642 -138
- package/dist/os/flow/handlers/flow-push.js.map +1 -1
- package/dist/os/flow/locks.d.ts +8 -0
- package/dist/os/flow/locks.d.ts.map +1 -1
- package/dist/os/flow/locks.js +6 -3
- package/dist/os/flow/locks.js.map +1 -1
- package/dist/os/{mission → flow}/open-missions.d.ts +1 -2
- package/dist/os/flow/open-missions.d.ts.map +1 -0
- package/dist/os/flow/open-missions.js +37 -0
- package/dist/os/flow/open-missions.js.map +1 -0
- package/dist/os/flow/preflight.d.ts.map +1 -1
- package/dist/os/flow/preflight.js +5 -3
- package/dist/os/flow/preflight.js.map +1 -1
- package/dist/os/flow/registry.d.ts +9 -5
- package/dist/os/flow/registry.d.ts.map +1 -1
- package/dist/os/flow/registry.js +2 -2
- package/dist/os/flow/registry.js.map +1 -1
- package/dist/os/friction/friction.module.d.ts.map +1 -1
- package/dist/os/friction/friction.module.js +30 -5
- package/dist/os/friction/friction.module.js.map +1 -1
- package/dist/os/friction/handlers/friction-add.d.ts.map +1 -1
- package/dist/os/friction/handlers/friction-add.js +10 -17
- package/dist/os/friction/handlers/friction-add.js.map +1 -1
- package/dist/os/friction/handlers/friction-migrate.d.ts.map +1 -1
- package/dist/os/friction/handlers/friction-migrate.js +188 -2
- package/dist/os/friction/handlers/friction-migrate.js.map +1 -1
- package/dist/os/friction/store.d.ts +4 -0
- package/dist/os/friction/store.d.ts.map +1 -1
- package/dist/os/friction/store.js +20 -0
- package/dist/os/friction/store.js.map +1 -1
- package/dist/os/friction/types.d.ts +12 -0
- package/dist/os/friction/types.d.ts.map +1 -1
- package/dist/os/friction/types.js +8 -0
- package/dist/os/friction/types.js.map +1 -1
- package/dist/os/gate/handlers/gate-probe-catalog.d.ts.map +1 -1
- package/dist/os/gate/handlers/gate-probe-catalog.js +38 -5
- package/dist/os/gate/handlers/gate-probe-catalog.js.map +1 -1
- package/dist/os/plan/handlers/archive.d.ts.map +1 -1
- package/dist/os/plan/handlers/archive.js +3 -7
- package/dist/os/plan/handlers/archive.js.map +1 -1
- package/dist/os/rfc/handlers/archive.d.ts.map +1 -1
- package/dist/os/rfc/handlers/archive.js +3 -7
- package/dist/os/rfc/handlers/archive.js.map +1 -1
- package/dist/os/rfc/handlers/list-create.d.ts.map +1 -1
- package/dist/os/rfc/handlers/list-create.js +15 -7
- package/dist/os/rfc/handlers/list-create.js.map +1 -1
- package/dist/os/session/handlers/archive.d.ts.map +1 -1
- package/dist/os/session/handlers/archive.js +3 -7
- package/dist/os/session/handlers/archive.js.map +1 -1
- package/dist/os/system/handlers/system-product-register.d.ts +24 -0
- package/dist/os/system/handlers/system-product-register.d.ts.map +1 -0
- package/dist/os/system/handlers/system-product-register.js +322 -0
- package/dist/os/system/handlers/system-product-register.js.map +1 -0
- package/dist/os/system/handlers/system-products-status.d.ts +23 -0
- package/dist/os/system/handlers/system-products-status.d.ts.map +1 -0
- package/dist/os/system/handlers/system-products-status.js +235 -0
- package/dist/os/system/handlers/system-products-status.js.map +1 -0
- package/dist/os/system/schemas.d.ts +13 -0
- package/dist/os/system/schemas.d.ts.map +1 -1
- package/dist/os/system/schemas.js +15 -0
- package/dist/os/system/schemas.js.map +1 -1
- package/dist/os/system/system.module.d.ts.map +1 -1
- package/dist/os/system/system.module.js +113 -3
- package/dist/os/system/system.module.js.map +1 -1
- package/dist/src/command-modules.d.ts.map +1 -1
- package/dist/src/command-modules.js +0 -2
- package/dist/src/command-modules.js.map +1 -1
- package/dist/src/config/forge-config.d.ts +2 -0
- package/dist/src/config/forge-config.d.ts.map +1 -1
- package/dist/src/config/forge-config.js +11 -10
- package/dist/src/config/forge-config.js.map +1 -1
- package/dist/src/index.d.ts +0 -2
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +0 -2
- package/dist/src/index.js.map +1 -1
- package/dist/src/onboarding/create.d.ts.map +1 -1
- package/dist/src/onboarding/create.js +27 -2
- package/dist/src/onboarding/create.js.map +1 -1
- package/dist/src/onboarding/doctor.d.ts +0 -5
- package/dist/src/onboarding/doctor.d.ts.map +1 -1
- package/dist/src/onboarding/doctor.js +6 -79
- package/dist/src/onboarding/doctor.js.map +1 -1
- package/dist/src/onboarding/npm-token-check.d.ts +1 -1
- package/dist/src/onboarding/npm-token-check.d.ts.map +1 -1
- package/dist/src/onboarding/npm-token-check.js +2 -2
- package/dist/src/onboarding/npm-token-check.js.map +1 -1
- package/dist/src/profiles/stack-profile.js +2 -2
- package/dist/src/types.js +2 -2
- package/dist/src/utils/hash.d.ts +1 -0
- package/dist/src/utils/hash.d.ts.map +1 -1
- package/dist/src/utils/hash.js +4 -0
- package/dist/src/utils/hash.js.map +1 -1
- package/dist/{os/mission → src/utils}/lockfile.d.ts +1 -18
- package/dist/src/utils/lockfile.d.ts.map +1 -0
- package/dist/src/utils/lockfile.js +70 -0
- package/dist/src/utils/lockfile.js.map +1 -0
- package/dist/src/utils/verifier-git.d.ts +27 -1
- package/dist/src/utils/verifier-git.d.ts.map +1 -1
- package/dist/src/utils/verifier-git.js +36 -6
- package/dist/src/utils/verifier-git.js.map +1 -1
- package/docs/reference/system-hub.md +104 -0
- package/os/adr/handlers/archive.ts +3 -11
- package/os/adr/handlers/list-create.test.ts +174 -0
- package/os/adr/handlers/list-create.ts +16 -8
- package/os/audit/handlers/archive.ts +3 -11
- package/os/codebase/handlers/codebase-measure-symbols.ts +32 -4
- package/os/core/archive-regen.ts +33 -7
- package/os/core/core.module.ts +10 -76
- package/os/core/docs-archive.test.ts +25 -0
- package/os/core/handlers/assets-helpers.ts +2 -4
- package/os/core/handlers/determinism-check.ts +2 -3
- package/os/core/handlers/lifecycle-handlers.test.ts +529 -0
- package/os/core/handlers/pinned-check.ts +30 -0
- package/os/core/handlers/pinned-types.ts +7 -0
- package/os/core/handlers/pinned-validate.ts +28 -3
- package/os/core/handlers/release-prepare.ts +2 -4
- package/os/correctness/gate/trust-boundary-cx18.test.ts +1 -1
- package/os/flow/digest.ts +436 -95
- package/os/flow/evidence-lock.ts +184 -0
- package/os/flow/flow.module.ts +37 -14
- package/os/flow/git.ts +206 -11
- package/os/flow/handlers/flow-digest.ts +12 -8
- package/os/flow/handlers/flow-peers.ts +1 -1
- package/os/flow/handlers/flow-push.ts +725 -137
- package/os/flow/locks.ts +24 -7
- package/os/flow/open-missions.ts +45 -0
- package/os/flow/preflight.ts +5 -3
- package/os/flow/registry.ts +7 -3
- package/os/flow/tests/digest-id-inputs.test.ts +106 -0
- package/os/flow/tests/digest-persist.test.ts +243 -0
- package/os/flow/tests/evidence-preflight-surface-skip.test.ts +218 -0
- package/os/flow/tests/flow-push-attest.test.ts +137 -0
- package/os/flow/tests/flow-push-review-baseline.test.ts +339 -0
- package/os/flow/tests/flow-push-verifier-batch.test.ts +134 -0
- package/os/flow/tests/release-lines.test.ts +136 -0
- package/os/flow/tests/state-roots.test.ts +1 -48
- package/os/friction/friction-add.test.ts +42 -0
- package/os/friction/friction-migrate.test.ts +67 -2
- package/os/friction/friction.module.ts +33 -5
- package/os/friction/handlers/friction-add.ts +10 -15
- package/os/friction/handlers/friction-migrate.ts +220 -1
- package/os/friction/store.ts +19 -0
- package/os/friction/types.ts +8 -0
- package/os/gate/handlers/gate-probe-catalog.ts +39 -7
- package/os/gate/handlers/gate-probe-ratchet.test.ts +57 -22
- package/os/plan/handlers/archive.ts +3 -11
- package/os/rfc/handlers/archive.ts +3 -11
- package/os/rfc/handlers/list-create.ts +22 -17
- package/os/rfc/handlers/validate-corpus.test.ts +149 -0
- package/os/rfc/probe-batch.test.ts +253 -0
- package/os/rfc/verifier/rfc-1391/ac10-operating-model-policy.acceptance.test.ts +63 -0
- package/os/session/handlers/archive.ts +3 -11
- package/os/system/handlers/system-product-register.ts +492 -0
- package/os/system/handlers/system-products-status.ts +395 -0
- package/os/system/schemas.ts +17 -0
- package/os/system/system.module.ts +117 -3
- package/os/system/tests/system-product-register.test.ts +304 -0
- package/os/system/tests/system-products-status.test.ts +154 -0
- package/package.json +161 -506
- package/profiles/root-agents-system.md +82 -0
- package/profiles/system.yaml +1 -0
- package/src/command-modules.ts +0 -2
- package/src/config/forge-config.ts +16 -11
- package/src/index.ts +0 -2
- package/src/onboarding/create-superfolder-guard.test.ts +73 -0
- package/src/onboarding/create.ts +28 -2
- package/src/onboarding/doctor.ts +9 -96
- package/src/onboarding/npm-token-check.ts +3 -3
- package/src/profiles/stack-profile.ts +2 -2
- package/src/tests/evidence-consult-serialization.test.ts +202 -0
- package/src/tests/pinned-validate.test.ts +194 -0
- package/src/tests/pkg-health-self-scan.test.ts +29 -0
- package/src/tests/profile-flow-hooks.test.ts +1 -0
- package/src/tests/profile-schema.test.ts +1 -0
- package/src/tests/rfc-evidence-sync.test.ts +369 -0
- package/src/tests/skill-agents-sync.test.ts +192 -0
- package/src/tests/stack-profile.test.ts +1 -0
- package/src/types.ts +2 -2
- package/src/utils/hash.ts +5 -0
- package/src/utils/lockfile.ts +78 -0
- package/src/utils/verifier-git.ts +53 -5
- package/dist/os/core/handlers/forge-autonomy-validate.d.ts +0 -25
- package/dist/os/core/handlers/forge-autonomy-validate.d.ts.map +0 -1
- package/dist/os/core/handlers/forge-autonomy-validate.js +0 -208
- package/dist/os/core/handlers/forge-autonomy-validate.js.map +0 -1
- package/dist/os/mission/handlers/archive.d.ts +0 -4
- package/dist/os/mission/handlers/archive.d.ts.map +0 -1
- package/dist/os/mission/handlers/archive.js +0 -587
- package/dist/os/mission/handlers/archive.js.map +0 -1
- package/dist/os/mission/importer-block.d.ts +0 -19
- package/dist/os/mission/importer-block.d.ts.map +0 -1
- package/dist/os/mission/importer-block.js +0 -124
- package/dist/os/mission/importer-block.js.map +0 -1
- package/dist/os/mission/index.d.ts +0 -2
- package/dist/os/mission/index.d.ts.map +0 -1
- package/dist/os/mission/index.js +0 -15
- package/dist/os/mission/index.js.map +0 -1
- package/dist/os/mission/lockfile.d.ts.map +0 -1
- package/dist/os/mission/lockfile.js +0 -138
- package/dist/os/mission/lockfile.js.map +0 -1
- package/dist/os/mission/mission.module.d.ts +0 -3
- package/dist/os/mission/mission.module.d.ts.map +0 -1
- package/dist/os/mission/mission.module.js +0 -63
- package/dist/os/mission/mission.module.js.map +0 -1
- package/dist/os/mission/open-missions.d.ts.map +0 -1
- package/dist/os/mission/open-missions.js +0 -42
- package/dist/os/mission/open-missions.js.map +0 -1
- package/dist/os/mission/types.d.ts +0 -23
- package/dist/os/mission/types.d.ts.map +0 -1
- package/dist/os/mission/types.js +0 -19
- package/dist/os/mission/types.js.map +0 -1
- package/dist/os/werkstatt/handlers/lock.d.ts +0 -10
- package/dist/os/werkstatt/handlers/lock.d.ts.map +0 -1
- package/dist/os/werkstatt/handlers/lock.js +0 -153
- package/dist/os/werkstatt/handlers/lock.js.map +0 -1
- package/dist/os/werkstatt/handlers/schema.d.ts +0 -33
- package/dist/os/werkstatt/handlers/schema.d.ts.map +0 -1
- package/dist/os/werkstatt/handlers/schema.js +0 -42
- package/dist/os/werkstatt/handlers/schema.js.map +0 -1
- package/dist/os/werkstatt/handlers/werkstatt-lock-recover.d.ts +0 -15
- package/dist/os/werkstatt/handlers/werkstatt-lock-recover.d.ts.map +0 -1
- package/dist/os/werkstatt/handlers/werkstatt-lock-recover.js +0 -171
- package/dist/os/werkstatt/handlers/werkstatt-lock-recover.js.map +0 -1
- package/dist/os/werkstatt/handlers/werkstatt-lock-status.d.ts +0 -18
- package/dist/os/werkstatt/handlers/werkstatt-lock-status.d.ts.map +0 -1
- package/dist/os/werkstatt/handlers/werkstatt-lock-status.js +0 -51
- package/dist/os/werkstatt/handlers/werkstatt-lock-status.js.map +0 -1
- package/dist/os/werkstatt/handlers/werkstatt-operation-validate.d.ts +0 -11
- package/dist/os/werkstatt/handlers/werkstatt-operation-validate.d.ts.map +0 -1
- package/dist/os/werkstatt/handlers/werkstatt-operation-validate.js +0 -86
- package/dist/os/werkstatt/handlers/werkstatt-operation-validate.js.map +0 -1
- package/dist/os/werkstatt/handlers/workspace-deps.d.ts +0 -12
- package/dist/os/werkstatt/handlers/workspace-deps.d.ts.map +0 -1
- package/dist/os/werkstatt/handlers/workspace-deps.js +0 -42
- package/dist/os/werkstatt/handlers/workspace-deps.js.map +0 -1
- package/dist/os/werkstatt/index.d.ts +0 -7
- package/dist/os/werkstatt/index.d.ts.map +0 -1
- package/dist/os/werkstatt/index.js +0 -18
- package/dist/os/werkstatt/index.js.map +0 -1
- package/dist/os/werkstatt/werkstatt.module.d.ts +0 -3
- package/dist/os/werkstatt/werkstatt.module.d.ts.map +0 -1
- package/dist/os/werkstatt/werkstatt.module.js +0 -91
- package/dist/os/werkstatt/werkstatt.module.js.map +0 -1
- package/os/core/handlers/forge-autonomy-validate.ts +0 -276
- package/os/correctness/gate/trust-boundary-cx19.test.ts +0 -514
- package/os/mission/handlers/archive.test.ts +0 -764
- package/os/mission/handlers/archive.ts +0 -719
- package/os/mission/handlers/ship-inflight-degraded.test.ts +0 -105
- package/os/mission/importer-block.ts +0 -119
- package/os/mission/index.ts +0 -15
- package/os/mission/lockfile.ts +0 -152
- package/os/mission/mission.module.ts +0 -68
- package/os/mission/open-missions.ts +0 -50
- package/os/mission/types.ts +0 -42
- package/os/werkstatt/handlers/lock.ts +0 -168
- package/os/werkstatt/handlers/schema.ts +0 -47
- package/os/werkstatt/handlers/werkstatt-lock-recover.ts +0 -206
- package/os/werkstatt/handlers/werkstatt-lock-status.ts +0 -82
- package/os/werkstatt/handlers/werkstatt-operation-validate.ts +0 -112
- package/os/werkstatt/handlers/workspace-deps.ts +0 -56
- package/os/werkstatt/index.ts +0 -39
- package/os/werkstatt/werkstatt.module.ts +0 -95
- package/src/tests/doctor-autonomy.test.ts +0 -246
- package/src/tests/forge-autonomy-validate.test.ts +0 -159
- package/src/tests/werkstatt-lock.test.ts +0 -357
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
/*
|
|
2
|
+
<MODULE_CONTRACT>
|
|
3
|
+
<purpose>RFC-1633: per-commonGitDir serialization of judged evidence
|
|
4
|
+
consults. `.git/forge/evidence-consult.lock` rides the locks.ts machinery
|
|
5
|
+
(withFlowLock — pid+bootId liveness, RFC-1504 dead/stale classification);
|
|
6
|
+
bounded wait surfaces EVIDENCE-LOCKED naming the holder. The lock wraps ONE
|
|
7
|
+
gitEvidenceAttempt — a flux ride-out retry re-acquires so a retrying holder
|
|
8
|
+
never starves waiters. Internal enumeration reads (preflight:false) skip
|
|
9
|
+
it — they already run inside the holder's serialized window.</purpose>
|
|
10
|
+
<non-goals>
|
|
11
|
+
<item>No cross-host coordination — same machine-local trust model as integrate.lock.</item>
|
|
12
|
+
<item>No commonGitDir consult — resolution is pure fs (.git gitfile + commondir); the registry's commonGitDir(io) helper rides gitEvidence and would recurse through the lock itself.</item>
|
|
13
|
+
<item>No preflight/watch/settle work — the consult body owns judgment; this module owns scheduling only.</item>
|
|
14
|
+
</non-goals>
|
|
15
|
+
<KEY_DECISIONS>
|
|
16
|
+
<item>Per-attempt scope, not per-call: the flux ride-out releases the lock between retries (RFC-1633 enhance — convoy fairness).</item>
|
|
17
|
+
<item>Reentrancy via AsyncLocalStorage: a consult invoked INSIDE a held consult's fn inherits the consult context and skips re-locking; a concurrent consult has its own context and waits — same-process serialization is preserved (AC-1).</item>
|
|
18
|
+
<item>Unresolvable commonGitDir skips the lock — a repo whose .git cannot even be read fails closed in preflight on its own merits.</item>
|
|
19
|
+
<item>Journal events append on break/refusal only (bounded cardinality) — acquire/release would spam journal.jsonl, whose event union is closed.</item>
|
|
20
|
+
</KEY_DECISIONS>
|
|
21
|
+
<CHANGE_SUMMARY>
|
|
22
|
+
<item>RFC-1633: initial — evidence-consult serialization + env-declared wait/budget defaults</item>
|
|
23
|
+
<item>RFC-1633: serialize evidence consults + bestEffort reader mode (RFC-1633)</item>
|
|
24
|
+
<item>RFC-1633: review round 1 — digest envInputs, package-wide bestEffort scan, holder command, serialized standalone preflight</item>
|
|
25
|
+
</CHANGE_SUMMARY>
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
29
|
+
import { existsSync, readFileSync, statSync } from "node:fs";
|
|
30
|
+
import { mkdir, open, readFile } from "node:fs/promises";
|
|
31
|
+
import { isAbsolute, join, resolve } from "node:path";
|
|
32
|
+
|
|
33
|
+
import { withFlowLock } from "./locks.ts";
|
|
34
|
+
import type { LockTimeoutError } from "./locks.ts";
|
|
35
|
+
|
|
36
|
+
/** Lock artifact under the repo's common gitdir — shared across worktrees,
|
|
37
|
+
* which is exactly what serialization needs (parallel sessions consult the
|
|
38
|
+
* same .git). */
|
|
39
|
+
export const EVIDENCE_CONSULT_LOCK_RELATIVE_PATH = "forge/evidence-consult.lock";
|
|
40
|
+
|
|
41
|
+
export const EVIDENCE_LOCKED_PREFIX = "EVIDENCE-LOCKED";
|
|
42
|
+
|
|
43
|
+
/** Declared defaults — generous on purpose; tunable via envInputs declared
|
|
44
|
+
* on flow.integrate / flow.push / flow.digest (flow.module.ts). */
|
|
45
|
+
export const DEFAULT_EVIDENCE_LOCK_WAIT_MS = 120_000;
|
|
46
|
+
export const DEFAULT_EVIDENCE_LOCK_STALE_MS = 600_000;
|
|
47
|
+
export const DEFAULT_EVIDENCE_CONSULT_BUDGET_MS = 300_000;
|
|
48
|
+
|
|
49
|
+
function envMs(name: string, fallback: number): number {
|
|
50
|
+
const parsed = Number.parseInt(process.env[name] ?? "", 10);
|
|
51
|
+
return Number.isFinite(parsed) && parsed > 0 ? parsed : fallback;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function evidenceLockWaitMs(opt?: number): number {
|
|
55
|
+
return opt ?? envMs("FORGE_EVIDENCE_LOCK_WAIT_MS", DEFAULT_EVIDENCE_LOCK_WAIT_MS);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function evidenceConsultBudgetMs(opt?: number): number {
|
|
59
|
+
return opt ?? envMs("FORGE_EVIDENCE_CONSULT_BUDGET_MS", DEFAULT_EVIDENCE_CONSULT_BUDGET_MS);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Resolve the common gitdir without a consult — `registry.ts`'s
|
|
64
|
+
* `commonGitDir(io)` helper rides `gitEvidence` itself and would recurse
|
|
65
|
+
* through this lock. Pure fs: `.git` gitfile → gitdir, `commondir` → common.
|
|
66
|
+
* `null` when the surface cannot be read — the consult then fails closed
|
|
67
|
+
* in preflight on its own merits.
|
|
68
|
+
*/
|
|
69
|
+
export function resolveEvidenceCommonGitDir(repoRoot: string): string | null {
|
|
70
|
+
try {
|
|
71
|
+
const dotGit = join(repoRoot, ".git");
|
|
72
|
+
let gitdir: string;
|
|
73
|
+
if (statSync(dotGit).isFile()) {
|
|
74
|
+
const match = /^gitdir:\s*(.+)$/m.exec(readFileSync(dotGit, "utf8"));
|
|
75
|
+
if (match === null) return null;
|
|
76
|
+
const target = match[1]!.trim();
|
|
77
|
+
gitdir = isAbsolute(target) ? target : resolve(repoRoot, target);
|
|
78
|
+
} else {
|
|
79
|
+
gitdir = dotGit;
|
|
80
|
+
}
|
|
81
|
+
const commonFile = join(gitdir, "commondir");
|
|
82
|
+
if (existsSync(commonFile)) {
|
|
83
|
+
const rel = readFileSync(commonFile, "utf8").trim();
|
|
84
|
+
if (rel.length > 0) return isAbsolute(rel) ? rel : resolve(gitdir, rel);
|
|
85
|
+
}
|
|
86
|
+
return gitdir;
|
|
87
|
+
} catch {
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** AsyncLocalStorage reentrancy marker: a consult invoked INSIDE a held
|
|
93
|
+
* consult's fn inherits this context and skips re-locking (self-deadlock
|
|
94
|
+
* otherwise); a concurrent consult has its own context and queues normally
|
|
95
|
+
* — intra-process consults serialize exactly like cross-process ones. */
|
|
96
|
+
const consultContext = new AsyncLocalStorage<boolean>();
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Bounded-cheap journal bookkeeping: only lock breaks and wait refusals
|
|
100
|
+
* append (acquire/release would flood the closed journal vocabulary —
|
|
101
|
+
* "consult-lock" covers both arms via `rule`). Best-effort — a repo whose
|
|
102
|
+
* `.git/forge/` does not exist yet simply carries no line.
|
|
103
|
+
*/
|
|
104
|
+
async function appendConsultLockJournal(commonGitDir: string, detail: string): Promise<void> {
|
|
105
|
+
try {
|
|
106
|
+
const file = join(commonGitDir, "forge/journal.jsonl");
|
|
107
|
+
if (!existsSync(file)) return;
|
|
108
|
+
const line = `${JSON.stringify({
|
|
109
|
+
at: new Date().toISOString(),
|
|
110
|
+
event: "consult-lock",
|
|
111
|
+
branch: "",
|
|
112
|
+
sha: "",
|
|
113
|
+
detail,
|
|
114
|
+
})}\n`;
|
|
115
|
+
const handle = await open(file, "a");
|
|
116
|
+
try {
|
|
117
|
+
await handle.writeFile(line);
|
|
118
|
+
} finally {
|
|
119
|
+
await handle.close();
|
|
120
|
+
}
|
|
121
|
+
} catch {
|
|
122
|
+
// Journal bookkeeping never gates the consult.
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Serialize one judged consult attempt against every other consult on the
|
|
128
|
+
* same commonGitDir. `LockTimeoutError` propagates — the caller maps it to
|
|
129
|
+
* the EVIDENCE-LOCKED refusal; `describeEvidenceLockError` renders it.
|
|
130
|
+
*/
|
|
131
|
+
export async function withEvidenceConsultLock<T>(
|
|
132
|
+
repoRoot: string,
|
|
133
|
+
opts: {
|
|
134
|
+
waitMs?: number;
|
|
135
|
+
command?: string;
|
|
136
|
+
now?: () => number;
|
|
137
|
+
sleep?: (ms: number) => Promise<void>;
|
|
138
|
+
},
|
|
139
|
+
fn: () => Promise<T>,
|
|
140
|
+
): Promise<T> {
|
|
141
|
+
const common = resolveEvidenceCommonGitDir(repoRoot);
|
|
142
|
+
if (common === null) return fn();
|
|
143
|
+
const lockPath = join(common, EVIDENCE_CONSULT_LOCK_RELATIVE_PATH);
|
|
144
|
+
if (consultContext.getStore() === true) return fn();
|
|
145
|
+
await mkdir(join(common, "forge"), { recursive: true });
|
|
146
|
+
return await withFlowLock(
|
|
147
|
+
lockPath,
|
|
148
|
+
{
|
|
149
|
+
waitMs: evidenceLockWaitMs(opts.waitMs),
|
|
150
|
+
staleMs: DEFAULT_EVIDENCE_LOCK_STALE_MS,
|
|
151
|
+
extraContent: opts.command !== undefined ? { command: opts.command } : undefined,
|
|
152
|
+
onStale: (lock) => {
|
|
153
|
+
void appendConsultLockJournal(
|
|
154
|
+
common,
|
|
155
|
+
`evidence-consult lock broken (${lock.reason}, pid ${lock.pid ?? "unknown"}, age ${lock.ageMs}ms)`,
|
|
156
|
+
);
|
|
157
|
+
},
|
|
158
|
+
now: opts.now,
|
|
159
|
+
sleep: opts.sleep,
|
|
160
|
+
},
|
|
161
|
+
() => consultContext.run(true, fn),
|
|
162
|
+
{ readFile: async (p) => readFile(p, "utf8") },
|
|
163
|
+
);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/** Render a LockTimeoutError from withEvidenceConsultLock into the
|
|
167
|
+
* EVIDENCE-LOCKED refusal stderr — names the holder when one was observed. */
|
|
168
|
+
export async function describeEvidenceLockError(
|
|
169
|
+
repoRoot: string,
|
|
170
|
+
error: LockTimeoutError,
|
|
171
|
+
): Promise<string> {
|
|
172
|
+
const holder =
|
|
173
|
+
error.holder !== undefined
|
|
174
|
+
? `holder pid ${error.holder.pid}${error.holder.host !== undefined ? ` on ${error.holder.host}` : ""} since ${error.holder.at}${error.holder.command !== undefined ? ` (${error.holder.command})` : ""}`
|
|
175
|
+
: "holder unknown";
|
|
176
|
+
const common = resolveEvidenceCommonGitDir(repoRoot);
|
|
177
|
+
if (common !== null) {
|
|
178
|
+
void appendConsultLockJournal(
|
|
179
|
+
common,
|
|
180
|
+
`EVIDENCE-LOCKED refusal — ${holder} (lock ${error.lockPath})`,
|
|
181
|
+
);
|
|
182
|
+
}
|
|
183
|
+
return `${EVIDENCE_LOCKED_PREFIX}: judged evidence consult waited past the lock budget — ${holder} (lock ${error.lockPath})`;
|
|
184
|
+
}
|
package/os/flow/flow.module.ts
CHANGED
|
@@ -9,18 +9,12 @@ the idempotent two-phase repository adoption (FLOW-ADOPT-01..06, -08).</purpose>
|
|
|
9
9
|
</non-goals>
|
|
10
10
|
</MODULE_CONTRACT>
|
|
11
11
|
<CHANGE_SUMMARY>
|
|
12
|
-
<item>RFC-
|
|
13
|
-
<item>RFC-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
forge.yaml), project.owner + push.requireVerifierReview config, trust-boundary
|
|
19
|
-
scaffold (CODEOWNERS + forge-policy workflow) and reference docs.</item>
|
|
20
|
-
<item>RFC-1616: close RFC-1616 r13 trust-boundary counterexamples</item>
|
|
21
|
-
<item>RFC-1626: make gate-isolation sweeps durable and refuse foreign uncommitted work</item>
|
|
22
|
-
<item>RFC-1616: declare subprocess env inputs and drop pull_request trigger</item>
|
|
23
|
-
<history>RFC-1486, RFC-1487, RFC-1488, RFC-1490, RFC-1491, RFC-1498, RFC-1502, RFC-1503, RFC-1517, RFC-1528, RFC-1531, RFC-1533, RFC-1537, RFC-1538, RFC-1543, RFC-1568, RFC-1573, RFC-1580, RFC-1589, RFC-1597, RFC-1599, RFC-1600</history>
|
|
12
|
+
<item>RFC-1633: serialize evidence consults + bestEffort reader mode (RFC-1633)</item>
|
|
13
|
+
<item>RFC-1633: review round 1 — digest envInputs, package-wide bestEffort scan, holder command, serialized standalone preflight</item>
|
|
14
|
+
<item>RFC-1638: persist reviewed digests + attest pushed state by input hash</item>
|
|
15
|
+
<item>RFC-1638: review round 1 — payload preimage binding, fail-closed coverage scan, FLOW-PUSH-15</item>
|
|
16
|
+
<item>RFC-1643: committed verifier-review baseline for flow.push</item>
|
|
17
|
+
<history>RFC-1486, RFC-1487, RFC-1488, RFC-1490, RFC-1491, RFC-1498, RFC-1502, RFC-1503, RFC-1517, RFC-1528, RFC-1531, RFC-1533, RFC-1537, RFC-1538, RFC-1543, RFC-1568, RFC-1573, RFC-1580, RFC-1589, RFC-1592, RFC-1597, RFC-1599, RFC-1600, RFC-1616, RFC-1626</history>
|
|
24
18
|
</CHANGE_SUMMARY>
|
|
25
19
|
*/
|
|
26
20
|
|
|
@@ -366,7 +360,11 @@ export async function createForgeFlowModule(): Promise<ForgeModule> {
|
|
|
366
360
|
description: "Evaluate the integration's preconditions without mutating.",
|
|
367
361
|
},
|
|
368
362
|
},
|
|
369
|
-
envInputs: [
|
|
363
|
+
envInputs: [
|
|
364
|
+
{ name: "FORGE_INTEGRATE_PRELOCK", required: false },
|
|
365
|
+
{ name: "FORGE_EVIDENCE_LOCK_WAIT_MS", required: false },
|
|
366
|
+
{ name: "FORGE_EVIDENCE_CONSULT_BUDGET_MS", required: false },
|
|
367
|
+
],
|
|
370
368
|
execute: runFlowIntegrate,
|
|
371
369
|
},
|
|
372
370
|
{
|
|
@@ -638,6 +636,13 @@ export async function createForgeFlowModule(): Promise<ForgeModule> {
|
|
|
638
636
|
description: "Skip git fetch origin --prune — digest on existing remote-tracking refs.",
|
|
639
637
|
},
|
|
640
638
|
},
|
|
639
|
+
envInputs: [
|
|
640
|
+
{ name: "COMSPEC", required: false },
|
|
641
|
+
{ name: "PATHEXT", required: false },
|
|
642
|
+
{ name: "PATH", required: false },
|
|
643
|
+
{ name: "FORGE_EVIDENCE_LOCK_WAIT_MS", required: false },
|
|
644
|
+
{ name: "FORGE_EVIDENCE_CONSULT_BUDGET_MS", required: false },
|
|
645
|
+
],
|
|
641
646
|
execute: runFlowDigest,
|
|
642
647
|
},
|
|
643
648
|
{
|
|
@@ -693,6 +698,8 @@ export async function createForgeFlowModule(): Promise<ForgeModule> {
|
|
|
693
698
|
{ name: "COMSPEC", required: false },
|
|
694
699
|
{ name: "PATHEXT", required: false },
|
|
695
700
|
{ name: "PATH", required: false },
|
|
701
|
+
{ name: "FORGE_EVIDENCE_LOCK_WAIT_MS", required: false },
|
|
702
|
+
{ name: "FORGE_EVIDENCE_CONSULT_BUDGET_MS", required: false },
|
|
696
703
|
],
|
|
697
704
|
execute: runFlowDiscard,
|
|
698
705
|
},
|
|
@@ -825,6 +832,9 @@ export async function createForgeFlowModule(): Promise<ForgeModule> {
|
|
|
825
832
|
{ id: "FLOW-PUSH-06", severity: "error" },
|
|
826
833
|
{ id: "FLOW-PUSH-07", severity: "error" },
|
|
827
834
|
{ id: "FLOW-PUSH-08", severity: "error" },
|
|
835
|
+
{ id: "FLOW-PUSH-15", severity: "error" },
|
|
836
|
+
{ id: "FLOW-PUSH-16", severity: "warning" },
|
|
837
|
+
{ id: "FLOW-PUSH-17", severity: "warning" },
|
|
828
838
|
{ id: "FLOW-PUB-01", severity: "error" },
|
|
829
839
|
{ id: "PKG-HEALTH-10", severity: "error" },
|
|
830
840
|
{ id: "FLOW-07", severity: "error" },
|
|
@@ -840,6 +850,7 @@ export async function createForgeFlowModule(): Promise<ForgeModule> {
|
|
|
840
850
|
reads: [
|
|
841
851
|
"forge.yaml",
|
|
842
852
|
".git/**",
|
|
853
|
+
".github/workflows/**",
|
|
843
854
|
"docs/rfcs/*.md",
|
|
844
855
|
"hooks/**",
|
|
845
856
|
"pnpm-workspace.yaml",
|
|
@@ -866,13 +877,25 @@ export async function createForgeFlowModule(): Promise<ForgeModule> {
|
|
|
866
877
|
"trailers (X-Expectation-Origin / X-Verifier-Report / " +
|
|
867
878
|
"X-Correctness-Weakening / X-Policy-Digest). Required when the " +
|
|
868
879
|
"unpushed range contains any (FLOW-PUSH-08), unless the repo " +
|
|
869
|
-
"opts out with push.requireVerifierReview: false (RFC-1616)."
|
|
880
|
+
"opts out with push.requireVerifierReview: false (RFC-1616). " +
|
|
881
|
+
"Trailer commits that are ancestors of a committed " +
|
|
882
|
+
"push.verifierReviewedThrough baseline do not require it " +
|
|
883
|
+
"(RFC-1643) — only the operator moves that baseline.",
|
|
884
|
+
},
|
|
885
|
+
recount: {
|
|
886
|
+
kind: "boolean",
|
|
887
|
+
required: false,
|
|
888
|
+
description:
|
|
889
|
+
"RFC-1638: force the full digest recount instead of the " +
|
|
890
|
+
"persisted-digest input-hash attestation.",
|
|
870
891
|
},
|
|
871
892
|
},
|
|
872
893
|
envInputs: [
|
|
873
894
|
{ name: "COMSPEC", required: false },
|
|
874
895
|
{ name: "PATHEXT", required: false },
|
|
875
896
|
{ name: "PATH", required: false },
|
|
897
|
+
{ name: "FORGE_EVIDENCE_LOCK_WAIT_MS", required: false },
|
|
898
|
+
{ name: "FORGE_EVIDENCE_CONSULT_BUDGET_MS", required: false },
|
|
876
899
|
],
|
|
877
900
|
execute: runFlowPush,
|
|
878
901
|
},
|
package/os/flow/git.ts
CHANGED
|
@@ -13,11 +13,11 @@ are checked (DNA-106), and each helper expresses exactly one git fact.</purpose>
|
|
|
13
13
|
<item>FORGE_STATE_FILES is an exact-path/prefix allowlist; removers delete tolerated paths right before worktree removal.</item>
|
|
14
14
|
</KEY_DECISIONS>
|
|
15
15
|
<CHANGE_SUMMARY>
|
|
16
|
-
<item>RFC-1616: close r37 trust-boundary counterexamples — silent-write channel, live object/geometry consults, claims TOCTOU (RFC-1616 r37)</item>
|
|
17
|
-
<item>RFC-1616: close r38 trust-boundary counterexamples — worktree consult surface, root fd-binding</item>
|
|
18
|
-
<item>RFC-1616: totalize the worktree arm — anchored reads, compare-under-arm, check-ignore, embedded-gitdir refusal</item>
|
|
19
16
|
<item>RFC-1616: admit-list ls-files worktree scope and pin internal check-ignore consults (RFC-1616 r40)</item>
|
|
20
17
|
<item>RFC-1616: close r41 trust-boundary counterexamples — per-argv ignored-dir prune, file-valued argv strip/forbid, unconditional upstream pins</item>
|
|
18
|
+
<item>RFC-1633: serialize evidence consults + bestEffort reader mode (RFC-1633)</item>
|
|
19
|
+
<item>RFC-1638: persist reviewed digests + attest pushed state by input hash</item>
|
|
20
|
+
<item>RFC-1644: skip the worktree-surface capture for consults whose arm consumes none</item>
|
|
21
21
|
<history>ADR-0124, RFC-1486, RFC-1487, RFC-1490, RFC-1491, RFC-1515, RFC-1531, RFC-1616</history>
|
|
22
22
|
</CHANGE_SUMMARY>
|
|
23
23
|
*/
|
|
@@ -56,12 +56,44 @@ import {
|
|
|
56
56
|
resolveWorktreeArm,
|
|
57
57
|
type EvidenceFingerprint,
|
|
58
58
|
type EvidencePreflight,
|
|
59
|
+
type EvidencePreflightOptions,
|
|
60
|
+
consultReadsWorktreeSurface,
|
|
59
61
|
EVIDENCE_REFUSED_PREFIX,
|
|
60
62
|
isEvidenceGitQuery,
|
|
61
63
|
isIndexConsultingRead,
|
|
62
64
|
reportsRepoGeometry,
|
|
63
65
|
repoShaped,
|
|
64
66
|
} from "../../src/utils/verifier-git.ts";
|
|
67
|
+
import { LockTimeoutError } from "./locks.ts";
|
|
68
|
+
import {
|
|
69
|
+
describeEvidenceLockError,
|
|
70
|
+
evidenceConsultBudgetMs,
|
|
71
|
+
withEvidenceConsultLock,
|
|
72
|
+
} from "./evidence-lock.ts";
|
|
73
|
+
|
|
74
|
+
/** RFC-1633: consult modes — `judged` is the default judged consult
|
|
75
|
+
* (preflight+watch+settle, trusted:true); `bestEffort` skips all judgment
|
|
76
|
+
* machinery for non-verdict readers and marks the result untrusted. */
|
|
77
|
+
export type EvidenceMode = "judged" | "bestEffort";
|
|
78
|
+
|
|
79
|
+
export interface EvidenceResult extends ExecResult {
|
|
80
|
+
/** RFC-1633: false only for mode "bestEffort" results — advisory data
|
|
81
|
+
* no verdict may consume (`assertJudgedEvidence` polices the boundary). */
|
|
82
|
+
trusted: boolean;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** RFC-1633: verdict-consuming boundaries assert judged provenance — a
|
|
86
|
+
* `trusted:false` result here is a wiring error, not an environmental
|
|
87
|
+
* refusal, so it throws EVIDENCE-MODE rather than returning data. */
|
|
88
|
+
export function assertJudgedEvidence(
|
|
89
|
+
result: EvidenceResult,
|
|
90
|
+
): asserts result is EvidenceResult & { trusted: true } {
|
|
91
|
+
if (result.trusted !== true) {
|
|
92
|
+
throw new Error(
|
|
93
|
+
"EVIDENCE-MODE: untrusted (bestEffort) evidence reached a verdict-consuming boundary",
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
65
97
|
|
|
66
98
|
/**
|
|
67
99
|
* The argv judgment the evidence channel applies — owned by
|
|
@@ -74,6 +106,25 @@ export { isEvidenceGitQuery };
|
|
|
74
106
|
|
|
75
107
|
export const MIN_GIT_VERSION = "2.33";
|
|
76
108
|
|
|
109
|
+
/**
|
|
110
|
+
* RFC-1638 test seam: observes every consult argv on both channels so the
|
|
111
|
+
* DigestInputs coverage test can assert each collector read maps to a
|
|
112
|
+
* declared input field. Production paths never set it.
|
|
113
|
+
*/
|
|
114
|
+
export const consultProbe: {
|
|
115
|
+
current: ((argv: readonly string[], channel: "evidence" | "session") => void) | null;
|
|
116
|
+
} = { current: null };
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* RFC-1644 test seam: observes every completed `evidencePreflight` so the
|
|
120
|
+
* surface-skip suite can assert which consults captured
|
|
121
|
+
* the worktree baseline. Production paths never set it.
|
|
122
|
+
*/
|
|
123
|
+
export const preflightProbe: {
|
|
124
|
+
current:
|
|
125
|
+
((preflight: EvidencePreflight | null, options?: EvidencePreflightOptions) => void) | null;
|
|
126
|
+
} = { current: null };
|
|
127
|
+
|
|
77
128
|
export interface FlowWorktree {
|
|
78
129
|
path: string;
|
|
79
130
|
head: string;
|
|
@@ -88,6 +139,7 @@ export async function git(
|
|
|
88
139
|
args: string[],
|
|
89
140
|
opts?: { env?: Record<string, string> },
|
|
90
141
|
): Promise<ExecResult> {
|
|
142
|
+
consultProbe.current?.(args, "session");
|
|
91
143
|
// Writes and session-config ops (commit identity, credential helpers,
|
|
92
144
|
// url.insteadOf, hooks) need the session environment — the scrubbed
|
|
93
145
|
// evidence channel drops global config, which would break authenticated
|
|
@@ -119,16 +171,50 @@ export async function gitEvidence(
|
|
|
119
171
|
preflight?: boolean;
|
|
120
172
|
/** Extra file inodes folded into the spawn-window watch (see `verifierGit`). */
|
|
121
173
|
extraWatchPaths?: readonly string[];
|
|
174
|
+
/** RFC-1633: opt-in degraded mode for non-verdict readers — skips
|
|
175
|
+
* preflight/watch/settle and the consult lock, returns `trusted: false`.
|
|
176
|
+
* The argv allowlist still applies. */
|
|
177
|
+
mode?: EvidenceMode;
|
|
178
|
+
/** RFC-1633: cumulative bound on preflight+arm+settle, measured from
|
|
179
|
+
* consult-lock acquisition (judged only). */
|
|
180
|
+
consultBudgetMs?: number;
|
|
181
|
+
/** RFC-1633: bound on the evidence-consult lock wait (judged only). */
|
|
182
|
+
lockWaitMs?: number;
|
|
122
183
|
},
|
|
123
|
-
): Promise<
|
|
184
|
+
): Promise<EvidenceResult> {
|
|
185
|
+
consultProbe.current?.(args, "evidence");
|
|
124
186
|
// Runtime argv judgment — the evidence channel spawns a trusted git, so
|
|
125
187
|
// nothing beyond the read-only + pinned-fetch table may reach it, even
|
|
126
|
-
// through a dynamic tail the static scan cannot see (CX-70).
|
|
188
|
+
// through a dynamic tail the static scan cannot see (CX-70). bestEffort
|
|
189
|
+
// consults judge argv on the same table — the allowlist is the channel's
|
|
190
|
+
// argv boundary, independent of provenance mode (RFC-1633).
|
|
127
191
|
if (!isEvidenceGitQuery(args)) {
|
|
128
192
|
return {
|
|
129
193
|
exitCode: -1,
|
|
130
194
|
stdout: "",
|
|
131
195
|
stderr: `gitEvidence refused argv outside the evidence allowlist: git ${args.join(" ")}`,
|
|
196
|
+
trusted: opts?.mode !== "bestEffort",
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
// RFC-1633 bestEffort: the same scrubbed spawn on the resolved real
|
|
200
|
+
// binary — none of the judgment machinery (no preflight, no watch, no
|
|
201
|
+
// settle, no lock). The result is advisory data, never evidence.
|
|
202
|
+
if (opts?.mode === "bestEffort") {
|
|
203
|
+
const r = await spawnCaptured(resolveGitBin(), ["-C", repoRoot, ...args], {
|
|
204
|
+
cwd: repoRoot,
|
|
205
|
+
env: {
|
|
206
|
+
...verifierGitEnv(),
|
|
207
|
+
...filterEvidenceExtraEnv(opts?.extraEnv),
|
|
208
|
+
...(opts?.internalEnv ?? {}),
|
|
209
|
+
},
|
|
210
|
+
timeoutMs: opts?.timeoutMs ?? 60_000,
|
|
211
|
+
maxBuffer: 64 * 1024 * 1024,
|
|
212
|
+
});
|
|
213
|
+
return {
|
|
214
|
+
exitCode: r.exitCode,
|
|
215
|
+
stdout: r.stdout.toString(),
|
|
216
|
+
stderr: r.stderr.toString(),
|
|
217
|
+
trusted: false,
|
|
132
218
|
};
|
|
133
219
|
}
|
|
134
220
|
// A mid-window refusal means the surface MOVED during the judged read —
|
|
@@ -138,19 +224,80 @@ export async function gitEvidence(
|
|
|
138
224
|
// flux budget is spent (RFC-1616 R25 follow-up — callers no longer need
|
|
139
225
|
// per-site catch loops for transient churn).
|
|
140
226
|
const fluxDeadline = Date.now() + 2_000;
|
|
227
|
+
// RFC-1633: judged consults serialize per commonGitDir — the lock wraps
|
|
228
|
+
// ONE attempt so a flux retry re-acquires and a retrying holder never
|
|
229
|
+
// starves waiters. `preflight:false` internal enumeration reads skip
|
|
230
|
+
// the lock (they already run inside the holder's serialized window).
|
|
231
|
+
// consultStartedAt is stamped on first acquisition — the consult budget
|
|
232
|
+
// is cumulative across retries, and the lock wait itself is separately
|
|
233
|
+
// bounded by lockWaitMs.
|
|
234
|
+
let consultStartedAt: number | undefined;
|
|
141
235
|
for (;;) {
|
|
142
|
-
|
|
236
|
+
let r: ExecResult;
|
|
237
|
+
try {
|
|
238
|
+
r =
|
|
239
|
+
opts?.preflight === false
|
|
240
|
+
? await gitEvidenceAttempt(repoRoot, args, opts)
|
|
241
|
+
: await withEvidenceConsultLock(
|
|
242
|
+
repoRoot,
|
|
243
|
+
{ waitMs: opts?.lockWaitMs, command: `git ${args.join(" ")}` },
|
|
244
|
+
async () => {
|
|
245
|
+
consultStartedAt ??= Date.now();
|
|
246
|
+
return gitEvidenceAttempt(repoRoot, args, {
|
|
247
|
+
...opts,
|
|
248
|
+
consultStartedAt,
|
|
249
|
+
});
|
|
250
|
+
},
|
|
251
|
+
);
|
|
252
|
+
} catch (error) {
|
|
253
|
+
// EVIDENCE-LOCKED is a distinct refusal class — it names the lock
|
|
254
|
+
// holder and does NOT re-enter the flux ride-out (which keys on
|
|
255
|
+
// mid-window "during the judged read" refusals).
|
|
256
|
+
if (error instanceof LockTimeoutError) {
|
|
257
|
+
return {
|
|
258
|
+
exitCode: -1,
|
|
259
|
+
stdout: "",
|
|
260
|
+
stderr: await describeEvidenceLockError(repoRoot, error),
|
|
261
|
+
trusted: true,
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
throw error;
|
|
265
|
+
}
|
|
143
266
|
if (
|
|
144
267
|
r.exitCode !== -1 ||
|
|
268
|
+
r.exitCode === null ||
|
|
145
269
|
!r.stderr.includes("during the judged read") ||
|
|
146
270
|
Date.now() >= fluxDeadline
|
|
147
271
|
) {
|
|
148
|
-
return r;
|
|
272
|
+
return { ...r, trusted: true };
|
|
149
273
|
}
|
|
150
274
|
await new Promise((r2) => setTimeout(r2, 120));
|
|
151
275
|
}
|
|
152
276
|
}
|
|
153
277
|
|
|
278
|
+
/**
|
|
279
|
+
* RFC-1633: cumulative wall-clock bound on preflight+arm+settle — the clock
|
|
280
|
+
* starts at consult-lock acquisition (`consultStartedAt`), not per phase.
|
|
281
|
+
* Returns the EVIDENCE-BUDGET refusal naming the active phase, or null.
|
|
282
|
+
* Exported for the RFC-1633 serialization tests.
|
|
283
|
+
*/
|
|
284
|
+
export function evidenceBudgetBreach(
|
|
285
|
+
args: string[],
|
|
286
|
+
phase: "preflight" | "arm" | "settle",
|
|
287
|
+
consultStartedAt: number | undefined,
|
|
288
|
+
consultBudgetMs: number | undefined,
|
|
289
|
+
): ExecResult | null {
|
|
290
|
+
if (consultStartedAt === undefined) return null;
|
|
291
|
+
const budgetMs = evidenceConsultBudgetMs(consultBudgetMs);
|
|
292
|
+
const elapsed = Date.now() - consultStartedAt;
|
|
293
|
+
if (elapsed <= budgetMs) return null;
|
|
294
|
+
return {
|
|
295
|
+
exitCode: -1,
|
|
296
|
+
stdout: "",
|
|
297
|
+
stderr: `EVIDENCE-BUDGET: ${phase} exceeded the cumulative consult budget (${elapsed}ms elapsed > ${budgetMs}ms budget): git ${args.join(" ")}`,
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
|
|
154
301
|
/** One armed-and-judged evidence spawn — see `gitEvidence`'s flux ride-out. */
|
|
155
302
|
async function gitEvidenceAttempt(
|
|
156
303
|
repoRoot: string,
|
|
@@ -162,6 +309,10 @@ async function gitEvidenceAttempt(
|
|
|
162
309
|
preflight?: boolean;
|
|
163
310
|
/** Extra file inodes folded into the spawn-window watch (see `verifierGit`). */
|
|
164
311
|
extraWatchPaths?: readonly string[];
|
|
312
|
+
/** RFC-1633: consult budget clock start (lock acquisition instant). */
|
|
313
|
+
consultStartedAt?: number;
|
|
314
|
+
/** RFC-1633: cumulative preflight+arm+settle bound. */
|
|
315
|
+
consultBudgetMs?: number;
|
|
165
316
|
},
|
|
166
317
|
): Promise<ExecResult> {
|
|
167
318
|
// The session-writable repo surface is judged before every spawn —
|
|
@@ -172,7 +323,14 @@ async function gitEvidenceAttempt(
|
|
|
172
323
|
// preflight enumerates through this same channel (preflight:false
|
|
173
324
|
// breaks the recursion), so every subprocess on the evidence path stays
|
|
174
325
|
// inside this argv-judged body.
|
|
175
|
-
|
|
326
|
+
// RFC-1644: the worktree baseline is captured only when this consult's
|
|
327
|
+
// arm consumes it — derived from the immutable argv, so every
|
|
328
|
+
// re-preflight below re-derives the same value.
|
|
329
|
+
const surfaceOpt: EvidencePreflightOptions = {
|
|
330
|
+
worktreeSurface: consultReadsWorktreeSurface(args) ? "capture" : "skip",
|
|
331
|
+
};
|
|
332
|
+
let preflight =
|
|
333
|
+
opts?.preflight === false ? null : await evidencePreflight(repoRoot, undefined, surfaceOpt);
|
|
176
334
|
// Re-prove the fingerprint right before the spawn, and keep re-
|
|
177
335
|
// preflighting while the surface drifts — the LAST check is always
|
|
178
336
|
// immediate before the spawn (R13-D1: a one-shot reprove+reflight
|
|
@@ -187,7 +345,17 @@ async function gitEvidenceAttempt(
|
|
|
187
345
|
// steer re-resolution into a forged common dir (CX-143).
|
|
188
346
|
const priorFp = preflight.fingerprint;
|
|
189
347
|
closeEvidenceIndex(preflight);
|
|
190
|
-
preflight = attempt >= 2 ? null : await evidencePreflight(repoRoot, priorFp);
|
|
348
|
+
preflight = attempt >= 2 ? null : await evidencePreflight(repoRoot, priorFp, surfaceOpt);
|
|
349
|
+
}
|
|
350
|
+
const preflightBreach = evidenceBudgetBreach(
|
|
351
|
+
args,
|
|
352
|
+
"preflight",
|
|
353
|
+
opts?.consultStartedAt,
|
|
354
|
+
opts?.consultBudgetMs,
|
|
355
|
+
);
|
|
356
|
+
if (preflightBreach !== null) {
|
|
357
|
+
closeEvidenceIndex(preflight);
|
|
358
|
+
return preflightBreach;
|
|
191
359
|
}
|
|
192
360
|
// The spawn-window watch (CX-r22): the judged child opens `.git`
|
|
193
361
|
// metadata inside ITS lifetime — the reprove ends at spawn, not at
|
|
@@ -227,9 +395,23 @@ async function gitEvidenceAttempt(
|
|
|
227
395
|
await windowWatch.settle();
|
|
228
396
|
windowWatch = null;
|
|
229
397
|
closeEvidenceIndex(preflight);
|
|
230
|
-
preflight =
|
|
398
|
+
preflight =
|
|
399
|
+
armAttempt >= 1
|
|
400
|
+
? null
|
|
401
|
+
: await evidencePreflight(repoRoot, preflight.fingerprint, surfaceOpt);
|
|
231
402
|
}
|
|
232
403
|
}
|
|
404
|
+
const armBreach = evidenceBudgetBreach(
|
|
405
|
+
args,
|
|
406
|
+
"arm",
|
|
407
|
+
opts?.consultStartedAt,
|
|
408
|
+
opts?.consultBudgetMs,
|
|
409
|
+
);
|
|
410
|
+
if (armBreach !== null) {
|
|
411
|
+
if (windowWatch !== null) await windowWatch.settle();
|
|
412
|
+
closeEvidenceIndex(preflight);
|
|
413
|
+
return armBreach;
|
|
414
|
+
}
|
|
233
415
|
try {
|
|
234
416
|
if (preflight === null && opts?.preflight !== false) {
|
|
235
417
|
return {
|
|
@@ -366,6 +548,13 @@ async function gitEvidenceAttempt(
|
|
|
366
548
|
};
|
|
367
549
|
}
|
|
368
550
|
}
|
|
551
|
+
const settleBreach = evidenceBudgetBreach(
|
|
552
|
+
args,
|
|
553
|
+
"settle",
|
|
554
|
+
opts?.consultStartedAt,
|
|
555
|
+
opts?.consultBudgetMs,
|
|
556
|
+
);
|
|
557
|
+
if (settleBreach !== null) return settleBreach;
|
|
369
558
|
let stdout = r.stdout.toString();
|
|
370
559
|
if (overlayRefs && reportsRepoGeometry(args) && preflight?.overlay != null) {
|
|
371
560
|
stdout = substituteOverlayPaths(
|
|
@@ -402,6 +591,7 @@ async function gitEvidenceAttempt(
|
|
|
402
591
|
export async function evidencePreflight(
|
|
403
592
|
repoRoot: string,
|
|
404
593
|
prior?: EvidenceFingerprint | null,
|
|
594
|
+
options?: EvidencePreflightOptions,
|
|
405
595
|
): Promise<EvidencePreflight | null> {
|
|
406
596
|
// Indirection files first (CX-134/135): the `.git` gitfile/commondir
|
|
407
597
|
// state the `--git-path` resolves depend on must be captured BEFORE
|
|
@@ -536,7 +726,11 @@ export async function evidencePreflight(
|
|
|
536
726
|
// the capture-instant state, so a flip/hide landing between capture
|
|
537
727
|
// and arm reads as drift (the `.git` fingerprint's own semantics)
|
|
538
728
|
// instead of being silently adopted as the pin baseline.
|
|
539
|
-
|
|
729
|
+
// RFC-1644: skipped exactly when the consult's worktree arm consumes no
|
|
730
|
+
// surface — `worktreeSurface` stays `undefined` (fail-closed for arms).
|
|
731
|
+
if (options?.worktreeSurface === "skip") {
|
|
732
|
+
preflight.worktreeSurfaceSkipped = true;
|
|
733
|
+
} else if (preflight.index?.names !== undefined && fingerprint.workTree !== null) {
|
|
540
734
|
const wt = fingerprint.workTree;
|
|
541
735
|
const surface = captureWorktreeSurface(wt, preflight.index.names);
|
|
542
736
|
// CX-r39 reliability, CX-r41-F1: directories git reports ignored
|
|
@@ -572,6 +766,7 @@ export async function evidencePreflight(
|
|
|
572
766
|
markIgnoredDirs(surface, ignored);
|
|
573
767
|
preflight.worktreeSurface = surface;
|
|
574
768
|
}
|
|
769
|
+
preflightProbe.current?.(preflight, options);
|
|
575
770
|
return preflight;
|
|
576
771
|
}
|
|
577
772
|
|