Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/interplane-mv/patches/acfd0dfc9a00de64 # interplane-mv INTERPLANE: open interoperability protocol between AI models and agent runtimes. Models express intent. Runtimes retain authority. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers ## GitHub aien-dev/interplane-mv#82 (code only) closed derived `acfd0dfc9a00de64` #82 Imported from GitHub aien-dev/interplane-mv#82 (code only) GitHub's metadata for this pull request is unavailable: its state is DERIVED from the commits (merged: the head is reachable from this project's main; open: GitHub kept a merge ref; else closed). Base `01bc340d783dcc2c0db2946dbce24e5d026d4886` · Head `6894a6819477eeaa8ca76e280095c6d743589795` ### Apply it ``` git checkout -b patch-acfd0dfc9a00de64 01bc340d783dcc2c0db2946dbce24e5d026d4886 curl -fsSL https://interplane.io/drakestapleton/interplane-mv/patches/acfd0dfc9a00de64.patch | git am ``` Raw patch (mbox) · Diff ### Provenance This proposal is imported from GitHub; it is not signed by its author. Its import statement and source record: ``` github-import 1 aien-dev/interplane-mv 82 6894a6819477eeaa8ca76e280095c6d743589795 ``` ``` {"kind":"github-import","owner":"aien-dev","repo":"interplane-mv","number":82,"url":"https://github.com/aien-dev/interplane-mv/pull/82","export_sha256":"967c79e26a893657b5cdaa45efd442be5dbd2ecfe68e25f9a8c1b5da4d60d452","imported_utc":"2026-11-18T16:40:12Z","metadata":"unavailable","state_derived":true} ``` ### Changes ``` diff --git a/CURRENT_STATE.md b/CURRENT_STATE.md index 5cd5806..c8d899a 100644 --- a/CURRENT_STATE.md +++ b/CURRENT_STATE.md @@ -10,7 +10,7 @@ Pinned sources: | Project | Repo | Commit | Default branch | License | |---|---|---|---|---| | Odysseus | odysseus-dev/odysseus | 2992bf6 (2026-10-01) | dev | AGPL-3.0 | -| AIEN sovereign core | aien-dev/aien-sovereign-core | 7580039 (2026-10-04 re-audit: origin/main 0bcd558, 3 attention/ABI commits, no authority change) | main | AGPL-3.0-or-later | +| AIEN sovereign core | aien-dev/aien-sovereign-core | 9b5e6e8 (2026-10-08 adapter pin; was 7580039 at the 2026-10-04 re-audit) | main | AGPL-3.0-or-later | | AIEN aegis-runtime | aien-dev/aegis-runtime | f4e8709 (2026-10-04 re-audit: still origin/main) | main | AGPL-3.0-or-later | | AIEN protocols | aien-dev/aien-protocols | 3a4cdbe (2026-10-04 re-audit: still origin/main) | main | AGPL-3.0-or-later | | AIEN architecture | aien-dev/aien-architecture | 6c95697 (2026-10-04 re-audit: still origin/main) | main | AGPL-3.0-or-later | diff --git a/STATUS.md b/STATUS.md index 26815d8..f164594 100644 --- a/STATUS.md +++ b/STATUS.md @@ -26,7 +26,7 @@ byte-identical) · `qualified` (measured against a real model/backend). | Source-class coverage (0.3 cut P4) | conformant | conformant | cases 31-40 | one fixture per source class asserting every InputRecord field; mock gains `read_document`, `load_skill`, `call_provider`; skills and tool descriptions are `external_untrusted`; host registers model_generated input | | Conformance runner | implemented | implemented | 45/45 both (40 cases + 5 lifecycle, verdicts byte-identical) | `--dump` writes canonical results per case | | Interplane Probe | qualified | qualified | - | both run live against Qwen3.5-9B/Ollama 0.34.0 with identical verdicts (reports under qualification/reports) | -| AIEN adapter | tested (on the real EffectAuthority path; approved writes through the authenticated daemon ledger route; pinned sovereign-core 4d4dfd4 (#296 daemon-minted grants only, #295 signed requirements goal; #262, #260); was 10 pipeline tests in 0.1) | - | - | ADR 0003; real aien-mcp SpeculativeLane + aegis gate; aien-cli SafetyEngine not linkable (private); AGPL | +| AIEN adapter | tested (on the real EffectAuthority path; approved writes through the authenticated daemon ledger route; pinned sovereign-core 9b5e6e8 (live gate: adapters/aien/scripts/test-live-daemon.sh; earlier 4d4dfd4: #296 daemon-minted grants only, #295 signed requirements goal; #262, #260); was 10 pipeline tests in 0.1) | - | - | ADR 0003; real aien-mcp SpeculativeLane + aegis gate; aien-cli SafetyEngine not linkable (private); AGPL | | Odysseus adapter | - | tested (70 tests vs odysseus@2992bf6) | - | executes read_file/ls/glob/grep via Odysseus handlers; approval continuation unsupported, every continuation refused (cut A4); AGPL | | Before/after receipt (0.1 goal) | - | qualified | 2 runs, reproduced | examples/receipt | | CrossAxis gate, 0.2 pre-registered (37 pairs, qwen3.5:9b on Ollama) | - | qualified: FAIL | bench/runs/qual-20261004T2207Z | T 0.877 PASS, S PASS (B 0.730 vs A 0.676), O1 0.865 FAIL, O2 0/5 FAIL; model did not use the discovery tool. See docs/REPORT-0.2.md. 0.2x held-out campaign (bench/PROTOCOL-0.2x.md) not run: runner prepared; arm 3 negative controls N1 and N2 (denied and approval-pending calls cause no expansion and no execution) tested offline in bench/tools/test_runner_offline.py | diff --git a/adapters/aien/Cargo.lock b/adapters/aien/Cargo.lock index f2d044b..62dc59c 100644 --- a/adapters/aien/Cargo.lock +++ b/adapters/aien/Cargo.lock @@ -83,7 +83,7 @@ dependencies = [ [[package]] name = "aien-capability" version = "0.1.0" -source = "git+https://github.com/aien-dev/aien-sovereign-core.git?rev=4d4dfd459ae7e7c6c175edc5017816d079c621a9#4d4dfd459ae7e7c6c175edc5017816d079c621a9" +source = "git+https://github.com/aien-dev/aien-sovereign-core.git?rev=9b5e6e82359f4ad6b6f03042e83ef6411c5f15ce#9b5e6e82359f4ad6b6f03042e83ef6411c5f15ce" dependencies = [ "sha2 0.10.9", ] @@ -134,7 +134,7 @@ dependencies = [ [[package]] name = "aien-mcp" version = "0.1.0" -source = "git+https://github.com/aien-dev/aien-sovereign-core.git?rev=4d4dfd459ae7e7c6c175edc5017816d079c621a9#4d4dfd459ae7e7c6c175edc5017816d079c621a9" +source = "git+https://github.com/aien-dev/aien-sovereign-core.git?rev=9b5e6e82359f4ad6b6f03042e83ef6411c5f15ce#9b5e6e82359f4ad6b6f03042e83ef6411c5f15ce" dependencies = [ "aien-capability", "async-trait", diff --git a/adapters/aien/Cargo.toml b/adapters/aien/Cargo.toml index 40da0d6..779072f 100644 --- a/adapters/aien/Cargo.toml +++ b/adapters/aien/Cargo.toml @@ -21,9 +21,9 @@ interplane-crossveil = { path = "../../rust/crates/interplane-crossveil" } serde_json = "1" sha2 = "0.10" tokio = { version = "1", features = ["rt"] } -# Pinned AIEN sources: aien-dev/aien-sovereign-core main at 4d4dfd4 (#296 merged: the daemon honours only grants it minted itself, sovereign-core #261; #295 merged: an approved proposal carries a signed requirements goal and a missing one is refused, #289). aien-capability and aien-mcp are byte-identical to 8bcd79b (#262 merged: the authenticated ComposeApprovedProposal daemon command this adapter hands approved writes to; aien-capability and aien-mcp are byte-identical to 7d37da1, #260 merged: two-phase approval spend, reserve/commit/release, EffectLane::with_clock). Before that, aien-capability and aien-mcp were unchanged since 0bdc97a (PR #208: idempotency ledger bound to effect identity, revocable unspent grants; #207 exposure-aware authority; #204 single-use approvals). -aien-capability = { git = "https://github.com/aien-dev/aien-sovereign-core.git", rev = "4d4dfd459ae7e7c6c175edc5017816d079c621a9" } -aien-mcp = { git = "https://github.com/aien-dev/aien-sovereign-core.git", rev = "4d4dfd459ae7e7c6c175edc5017816d079c621a9" } +# Pinned AIEN sources: aien-dev/aien-sovereign-core main at 9b5e6e8. aien-capability and aien-mcp are byte-identical since 4d4dfd4 (git diff --stat 4d4dfd4 9b5e6e8 -- crates/aien-capability crates/aien-mcp is empty) and the live gate (scripts/test-live-daemon.sh) passed against a daemon built from 9b5e6e8. At 4d4dfd4 (#296 merged: the daemon honours only grants it minted itself, sovereign-core #261; #295 merged: an approved proposal carries a signed requirements goal and a missing one is refused, #289). aien-capability and aien-mcp are byte-identical to 8bcd79b (#262 merged: the authenticated ComposeApprovedProposal daemon command this adapter hands approved writes to; aien-capability and aien-mcp are byte-identical to 7d37da1, #260 merged: two-phase approval spend, reserve/commit/release, EffectLane::with_clock). Before that, aien-capability and aien-mcp were unchanged since 0bdc97a (PR #208: idempotency ledger bound to effect identity, revocable unspent grants; #207 exposure-aware authority; #204 single-use approvals). +aien-capability = { git = "https://github.com/aien-dev/aien-sovereign-core.git", rev = "9b5e6e82359f4ad6b6f03042e83ef6411c5f15ce" } +aien-mcp = { git = "https://github.com/aien-dev/aien-sovereign-core.git", rev = "9b5e6e82359f4ad6b6f03042e83ef6411c5f15ce" } # aegis-runtime cannot be a git dependency: its own Cargo.toml reaches a sibling checkout # (`../aien-protocols/crates/*`). Layout required (see README): next to this repository, # `interplane-audit/aegis-runtime` at f4e870953a466bb1cf68f1d88285929024cf1ba9 and diff --git a/adapters/aien/PINS b/adapters/aien/PINS index 6de1b0d..5032756 100644 --- a/adapters/aien/PINS +++ b/adapters/aien/PINS @@ -5,4 +5,4 @@ AEGIS_RUNTIME_REV=f4e870953a466bb1cf68f1d88285929024cf1ba9 AIEN_PROTOCOLS_REPO=https://github.com/aien-dev/aien-protocols.git AIEN_PROTOCOLS_REV=3a4cdbe8d360a2e1ddb3e8b108684048b9d4ba10 # Pinned in Cargo.toml (git dependency); CI checks that Cargo.toml and this line agree. -SOVEREIGN_CORE_REV=4d4dfd459ae7e7c6c175edc5017816d079c621a9 +SOVEREIGN_CORE_REV=9b5e6e82359f4ad6b6f03042e83ef6411c5f15ce diff --git a/adapters/aien/README.md b/adapters/aien/README.md index f91573d..82a133d 100644 --- a/adapters/aien/README.md +++ b/adapters/aien/README.md @@ -14,7 +14,7 @@ spent only by AIEN. Nothing under `rust/`, `spec/`, `python/` or ## Pinned AIEN sources `aien-capability` and `aien-mcp` are git dependencies pinned to -`aien-dev/aien-sovereign-core@4d4dfd459ae7e7c6c175edc5017816d079c621a9` (main 2026-10-07, after PR #296 merged: the daemon honours only grants it minted itself and refuses every caller-written authorization note, sovereign-core #261; and PR #295: an approved proposal carries a signed requirements goal, a missing one is refused, #289. `crates/aien-capability` and `crates/aien-mcp` are byte-identical to 8bcd79b, main after PR #262 merged: the authenticated `ComposeApprovedProposal` daemon command the ledger route uses; `crates/aien-capability` and `crates/aien-mcp` are byte-identical to 7d37da1, after PR #260 merged: two-phase approval spend, a grant is reserved at mint, committed when the effect runs, released if the effect is dropped, and `EffectLane::with_clock` re-checks expiry at commit; before #260 `crates/aien-capability` and `crates/aien-mcp` are byte-identical to 0bdc97a, main after PR #208 merged, which binds the idempotency ledger to effect identity and lets an approver revoke an unspent grant; before it, PR #207 merged, +`aien-dev/aien-sovereign-core@9b5e6e82359f4ad6b6f03042e83ef6411c5f15ce` (main 2026-10-08; `crates/aien-capability` and `crates/aien-mcp` are byte-identical to 4d4dfd4, `git diff --stat 4d4dfd4 9b5e6e8 -- crates/aien-capability crates/aien-mcp` is empty, and the live gate below passed against a daemon built from 9b5e6e8. 4d4dfd4 was main 2026-10-07, after PR #296 merged: the daemon honours only grants it minted itself and refuses every caller-written authorization note, sovereign-core #261; and PR #295: an approved proposal carries a signed requirements goal, a missing one is refused, #289. `crates/aien-capability` and `crates/aien-mcp` are byte-identical to 8bcd79b, main after PR #262 merged: the authenticated `ComposeApprovedProposal` daemon command the ledger route uses; `crates/aien-capability` and `crates/aien-mcp` are byte-identical to 7d37da1, after PR #260 merged: two-phase approval spend, a grant is reserved at mint, committed when the effect runs, released if the effect is dropped, and `EffectLane::with_clock` re-checks expiry at commit; before #260 `crates/aien-capability` and `crates/aien-mcp` are byte-identical to 0bdc97a, main after PR #208 merged, which binds the idempotency ledger to effect identity and lets an approver revoke an unspent grant; before it, PR #207 merged, which makes the authority exposure-aware, on top of PR #204 single-use approvals and the PR #203 authority seam). `aegis` (feature `aegis-gate`, on by default) cannot be a git dependency because `aegis-runtime`'s own `Cargo.toml` reaches a sibling checkout by relative path @@ -170,7 +170,7 @@ not WALDO provenance and not a full provenance chain: trace_id and request_id ar Evidence: `tests/compose_ledger.rs` rows 1-8 (approved write with both hash identities, forged approval id, stale target, replay including a re-presented approval id, operator stop/resume, adapter restart, the T4 injection subset, forged handoffs) need `AIEN_BIN` (an `aien-cli` binary -built from sovereign-core main 4d4dfd4) and `cargo test -- --ignored`; rows 10 and 11 (#260 expiry and re-mint) likewise; row 9 (desk key out of the model's +built from sovereign-core main 9b5e6e8) and `cargo test -- --ignored`; rows 10 and 11 (#260 expiry and re-mint) likewise; row 9 (desk key out of the model's reach, key file rules) always runs. Recorded run at this pin (CPU evidence only, 2026-10-08 00:52Z to 00:58Z): `aien-cli` built from @@ -271,6 +271,43 @@ Evidence: `tests/exposure.rs` (5 host-registered untrusted sources and a workspa `write_file` and `bash_eval`: all held, 0 executed, nothing written). A `bash_eval` outside the catalogued forms is refused earlier by the AEGIS gate. +## Live verified run gate + +`scripts/test-live-daemon.sh` is the one command that ties the live daemon rows to the offline +provenance verifier: + +``` +AIEN_BIN= AIEN_LEDGER_MODEL_DIR= \ + OUT= scripts/test-live-daemon.sh # LIVE_ROWS="row1_ x1_ x2_ x3_ x4_" limits the rows +``` + +It (1) runs the `#[ignore]`d live tests against a real `aien-cli daemon` (`--ignored --test-threads=1`; +each row starts a daemon that loads the model, about 6.5 min on the CPU reference backend with a debug +build) and fails if zero tests ran or row 1 or an attack test `x1_`..`x4_` did not; (2) row 1 exports its +run with `provenance_export::export_bundle` (the daemon's own `ComposeRecall` views of the claim, +settlement, grant, intent and ack, the load log, the trace, the loaded model files, `COMPANION.json`) +and the gate runs `provenance verify` on it; the only accepted verdict is exactly +`PASS_LABELLED_INCOMPLETE missing=link:model_turn effect=aien-ledger-slice/1:strong proposal=scripted_turn`; +(3) it tampers with hard-linked copies of the bundle and requires named refusals: an untouched copy +still passes (negative control), a changed proposal content or a changed ack fails `digest_mismatch`, +the same change with the manifest restamped fails `binding_mismatch`, and a truncated record fails +`size_mismatch`; (4) it writes `OUT/receipt.json` (adapter commit, binary sha256, sovereign-core +revision, omega lock, verdict, test names, negative-check verdicts, timestamps). + +What a pass proves: for one real daemon run, the claim, settlement, grant, intent and ack the daemon +wrote agree with each other and with the INTERPLANE call (path, bytes, request, trace, the approval key +recomputed from the grant's own fields, the daemon process identity), and the verifier refuses the +tampered copies above. + +What it does not prove: the exported records carry no signatures, so the verifier cannot tell an export +from a hand-written file (`provenance/BINDING.md`, Trust); the model turn is scripted, so the verdict is +labelled incomplete (no authorship claim); the desk MAC for `ComposeAuthorize` stays default-off (not +changed here; this path authenticates by the desk-key MAC regardless); CPU reference backend only; the +daemon does not report whether the native compose library is linked or which revision it was built +from, so the receipt records those as caller-asserted or `UNVERIFIED`. + +Recorded run: `evidence/live-gate-2026-10-08/receipt.json` (CPU, debug `aien-cli` sha256 9704f29f..., sovereign-core 9b5e6e8 caller-asserted, omega 6c6180c). It ran `LIVE_ROWS="row1_ x1_ x2_ x3_ x4_"` (5 tests); rows 2-8, 10 and 11 passed against the same binary in an earlier unrecorded-by-this-gate run (14 of 14), not by this receipt. + ## Build and test ``` diff --git a/adapters/aien/evidence/live-gate-2026-10-08/receipt.json b/adapters/aien/evidence/live-gate-2026-10-08/receipt.json new file mode 100644 index 0000000..13bec0a --- /dev/null +++ b/adapters/aien/evidence/live-gate-2026-10-08/receipt.json @@ -0,0 +1,38 @@ +{ + "kind": "interplane-aien-live-gate-receipt", + "adapter_commit": "061639dc349fd8fa12d15f30000d6b22eb486c08", + "adapter_dirty": false, + "sovereign_core_bin_sha256": "9704f29f68348097516ab45382852c70c1c22aec36d868cb2be564b8cd039c2f", + "sovereign_core_rev": "9b5e6e82359f4ad6b6f03042e83ef6411c5f15ce", + "sovereign_core_rev_basis": "caller-asserted: the daemon does not print its revision", + "omega_lock": "6c6180cf378075b61291f4565d226eba38b4decd", + "backend": "CPU reference (as printed in the daemon log)", + "verdict": "PASS_LABELLED_INCOMPLETE missing=link:model_turn effect=aien-ledger-slice/1:strong proposal=scripted_turn", + "bundle_companion_sha256": "92d0b7835ff8b43ebfd7fdd80c1ee37bcc5715ddedc1606c137d54d4fa9a9954", + "tests": { + "passed": 5, + "names": [ + "row1_approved_write_lands_and_is_done", + "x1_client_minted_grant_unused_when_the_handoff_refuses", + "x2_no_fallback_write_when_the_daemon_is_gone", + "x3_effect_uses_the_daemon_grant_not_a_client_one", + "x4_planted_temp_symlink_does_not_redirect_the_write" + ] + }, + "negative_checks": [ + "control PASS_LABELLED_INCOMPLETE missing=link:model_turn effect=aien-ledger-slice/1:strong proposal=scripted_turn", + "content_bytes FAIL digest_mismatch: interplane_trace", + "content_restamped FAIL binding_mismatch: interplane.arguments.content request=w1", + "ack_bytes FAIL digest_mismatch: ledger_ack", + "ack_restamped FAIL binding_mismatch: ledger_ack.state", + "truncated FAIL size_mismatch: ledger_intent declared=746 actual=20" + ], + "started": "2026-10-08T18:16:25Z", + "finished": "2026-10-08T18:51:47Z", + "limits": [ + "records are unsigned exports; the verifier cannot tell an export from a hand-written file", + "desk MAC for ComposeAuthorize stays default-off (not changed here)", + "native compose library linking is not reported by the daemon", + "the model turn is scripted: proposal authorship is not claimed" + ] +} diff --git a/adapters/aien/scripts/test-live-daemon.sh b/adapters/aien/scripts/test-live-daemon.sh new file mode 100755 index 0000000..9090bdd --- /dev/null +++ b/adapters/aien/scripts/test-live-daemon.sh @@ -0,0 +1,159 @@ +#!/usr/bin/env bash +# Live verified-run gate for the INTERPLANE AIEN adapter. +# +# Runs the adapter's live-daemon tests (they are #[ignore]d: they start a real `aien-cli daemon`, +# ~6.5 min each on the CPU reference backend), then feeds the bundle row 1 exported to the offline +# provenance verifier and checks the verdict, then tampers with copies of the bundle and requires +# the verifier to refuse each with a named code. It cannot pass vacuously: zero tests run, a +# missing required row, a failed test, a missing bundle or an unexpected verdict all fail it. +# +# Inputs (environment): +# AIEN_BIN native aien-cli binary (required) +# AIEN_LEDGER_MODEL_DIR dir with model.safetensors, tokenizer.json, config.json +# (default: the unsloth Llama-3.2-1B-Instruct snapshot in the HF cache) +# OUT output dir (required; rows/ live.log receipt.json are written here) +# Optional: +# LIVE_ROWS space-separated test-name filters (default: every live test). Row 1 and +# the four attack tests (x1_ x2_ x3_ x4_) are ALWAYS required to have run. +# SOVEREIGN_CORE_REV revision the binary was built from; the daemon does not print it, so it is +# recorded as caller-asserted (default UNVERIFIED) +# OMEGA_LOCK_REV omega revision of the linked compose library; default: git rev-parse of +# $AIEN_OMEGA_COMPOSE_DIR when set, else UNVERIFIED +# CARGO_TARGET_DIR build dir +# Exit 0 only when every check passed. No process is killed here; the daemons are the tests' own. +set -euo pipefail + +here="$(cd "$(dirname "$0")" && pwd)" +adapter="$(cd "$here/.." && pwd)" +repo="$(cd "$adapter/../.." && pwd)" +die() { echo "GATE FAIL: $*" >&2; exit 1; } + +: "${AIEN_BIN:?AIEN_BIN must name the native aien-cli binary}" +: "${OUT:?OUT must name the output directory}" +[ -x "$AIEN_BIN" ] || die "AIEN_BIN not executable: $AIEN_BIN" +command -v jq >/dev/null || die "jq is required" +model_dir="${AIEN_LEDGER_MODEL_DIR:-$HOME/.cache/huggingface/hub/models--unsloth--Llama-3.2-1B-Instruct/snapshots/5a8abab4a5d6f164389b1079fb721cfab8d7126c}" +for f in model.safetensors tokenizer.json config.json; do + [ -f "$model_dir/$f" ] || die "model dir lacks $f: $model_dir" +done +if command -v quietlock >/dev/null && ! quietlock check >/dev/null 2>&1; then + die "quiet flag is held (quietlock check): no long run now" +fi +mkdir -p "$OUT" +OUT="$(cd "$OUT" && pwd)" +[ ! -e "$OUT/rows" ] || die "$OUT/rows exists: use a fresh OUT (a sealed run is never overwritten)" +started="$(date -u +%FT%TZ)" +required="row1_ x1_ x2_ x3_ x4_" +rows="${LIVE_ROWS:-}" +if [ -n "$rows" ]; then + for r in $required; do + case " $rows " in *" $r "*) ;; *) die "LIVE_ROWS must include $r (required rows: $required)";; esac + done +fi + +# 1. The live tests. +log="$OUT/live.log" +set +e +(cd "$adapter" && AIEN_BIN="$AIEN_BIN" AIEN_LEDGER_MODEL_DIR="$model_dir" LEDGER_OUT="$OUT/rows" \ + cargo test --locked --test compose_ledger --test compose_ledger_attacks -- --ignored --test-threads=1 $rows) >"$log" 2>&1 +test_rc=$? +set -e +[ "$test_rc" -eq 0 ] || { tail -5 "$log" >&2; die "live tests exited $test_rc (log $log)"; } +passed="$(grep -c '^test .* \.\.\. ok$' "$log" || true)" +failed="$(grep -c '^test .* \.\.\. FAILED$' "$log" || true)" +[ "$passed" -ge 1 ] || die "zero live tests ran (vacuous pass refused)" +[ "$failed" -eq 0 ] || die "$failed live tests failed" +for r in $required; do + grep -q "^test .*${r}.* \.\.\. ok$" "$log" || die "required test $r did not run and pass" +done +tests_json="$(grep '^test .* \.\.\. ok$' "$log" | sed 's/^test \(.*\) \.\.\. ok$/\1/' | jq -R . | jq -s .)" + +# 2. The verifier on the freshly exported row-1 bundle. +bundle="$OUT/rows/row1/bundle" +[ -f "$bundle/COMPANION.json" ] || die "row 1 exported no bundle: $bundle/COMPANION.json" +verify() { (cd "$repo/provenance" && cargo run -q --locked --release -- verify "$1" 2>&1 || true) | tail -1; } +want_incomplete="PASS_LABELLED_INCOMPLETE missing=link:model_turn effect=aien-ledger-slice/1:strong proposal=scripted_turn" +verdict="$(verify "$bundle")" +case "$verdict" in + "$want_incomplete") ;; + *) die "unexpected verdict on the live bundle: $verdict";; +esac + +# 3. Tamper checks on hard-linked copies (a changed file is written fresh, never in place). +neg="$OUT/negative" +mkdir -p "$neg" +fork() { rm -rf "$neg/$1"; cp -al "$bundle" "$neg/$1"; } +restamp() { # bundle record-name: set the manifest's sha256 and size to the file as it is now + local d="$1" n="$2" p; p="$(jq -r ".records.$n.path" "$d/COMPANION.json")" + jq --arg n "$n" --arg s "$(sha256sum "$d/$p" | cut -d' ' -f1)" --argjson b "$(wc -c <"$d/$p")" \ + '.records[$n].sha256=$s | .records[$n].bytes=$b' "$d/COMPANION.json" >"$d/COMPANION.tmp" + mv "$d/COMPANION.tmp" "$d/COMPANION.json" +} +rewrite() { # bundle record-name sed-expression: same-length byte edit, written as a fresh file + local d="$1" n="$2" p; p="$(jq -r ".records.$n.path" "$d/COMPANION.json")" + sed "$3" "$d/$p" >"$d/$p.new" + cmp -s "$d/$p" "$d/$p.new" && die "tamper edit changed nothing in $p" + [ "$(wc -c <"$d/$p")" -eq "$(wc -c <"$d/$p.new")" ] || die "tamper edit changed the size of $p" + rm "$d/$p"; mv "$d/$p.new" "$d/$p" +} +expect() { # name bundle code + local v; v="$(verify "$2")" + case "$v" in "FAIL $3:"*) echo "negative $1: $v";; *) die "negative $1: wanted FAIL $3, got: $v";; esac + echo "$1 $v" >>"$neg/verdicts.txt" +} +: >"$neg/verdicts.txt" +fork control +[ "$(verify "$neg/control")" = "$verdict" ] || die "negative control: an untouched copy no longer verifies" +echo "control $verdict" >>"$neg/verdicts.txt" +# (a) the proposal content in the trace changes; the manifest still names the old digest. +fork content_bytes +rewrite "$neg/content_bytes" interplane_trace 's/Friday/Monday/' +expect content_bytes "$neg/content_bytes" digest_mismatch +# (b) same change, manifest restamped to hide it: the grant's content digest still disagrees. +fork content_restamped +rewrite "$neg/content_restamped" interplane_trace 's/Friday/Monday/' +restamp "$neg/content_restamped" interplane_trace +expect content_restamped "$neg/content_restamped" binding_mismatch +# (c) the ack record's state changes (same-length byte edit); the manifest still names the old digest. +fork ack_bytes +rewrite "$neg/ack_bytes" ledger_ack 's/\\"state\\":\\"DONE\\"/\\"state\\":\\"HOLD\\"/' +expect ack_bytes "$neg/ack_bytes" digest_mismatch +# (d) same change, restamped: the daemon-written ack must say DONE. +fork ack_restamped +rewrite "$neg/ack_restamped" ledger_ack 's/\\"state\\":\\"DONE\\"/\\"state\\":\\"HOLD\\"/' +restamp "$neg/ack_restamped" ledger_ack +expect ack_restamped "$neg/ack_restamped" binding_mismatch +# (e) a retained file is truncated (partial write). +fork truncated +p="$(jq -r .records.ledger_intent.path "$neg/truncated/COMPANION.json")" +head -c 20 "$neg/truncated/$p" >"$neg/truncated/$p.new"; rm "$neg/truncated/$p"; mv "$neg/truncated/$p.new" "$neg/truncated/$p" +expect truncated "$neg/truncated" size_mismatch + +# 4. Receipt. +finished="$(date -u +%FT%TZ)" +omega="${OMEGA_LOCK_REV:-}" +if [ -z "$omega" ] && [ -n "${AIEN_OMEGA_COMPOSE_DIR:-}" ]; then + omega="$(git -C "$AIEN_OMEGA_COMPOSE_DIR" rev-parse HEAD 2>/dev/null || true)" +fi +dirty=false; [ -z "$(git -C "$repo" status --porcelain -- adapters provenance 2>/dev/null)" ] || dirty=true +jq -n \ + --arg adapter_commit "$(git -C "$repo" rev-parse HEAD)" --argjson adapter_dirty "$dirty" \ + --arg bin_sha "$(sha256sum "$AIEN_BIN" | cut -d' ' -f1)" \ + --arg sc_rev "${SOVEREIGN_CORE_REV:-UNVERIFIED}" \ + --arg sc_rev_basis "$([ -n "${SOVEREIGN_CORE_REV:-}" ] && echo 'caller-asserted: the daemon does not print its revision' || echo 'the daemon does not print its revision')" \ + --arg omega "${omega:-UNVERIFIED}" --arg verdict "$verdict" \ + --arg companion_sha "$(sha256sum "$bundle/COMPANION.json" | cut -d' ' -f1)" \ + --argjson tests "$tests_json" --argjson passed "$passed" \ + --arg started "$started" --arg finished "$finished" \ + --arg negatives "$(cat "$neg/verdicts.txt")" \ + '{kind: "interplane-aien-live-gate-receipt", adapter_commit: $adapter_commit, adapter_dirty: $adapter_dirty, + sovereign_core_bin_sha256: $bin_sha, sovereign_core_rev: $sc_rev, sovereign_core_rev_basis: $sc_rev_basis, + omega_lock: $omega, backend: "CPU reference (as printed in the daemon log)", + verdict: $verdict, bundle_companion_sha256: $companion_sha, + tests: {passed: $passed, names: $tests}, negative_checks: ($negatives | split("\n") | map(select(length>0))), + started: $started, finished: $finished, + limits: ["records are unsigned exports; the verifier cannot tell an export from a hand-written file", + "desk MAC for ComposeAuthorize stays default-off (not changed here)", + "native compose library linking is not reported by the daemon", + "the model turn is scripted: proposal authorship is not claimed"]}' >"$OUT/receipt.json" +echo "GATE PASS: $passed live tests, verdict: $verdict; receipt $OUT/receipt.json" diff --git a/adapters/aien/src/lib.rs b/adapters/aien/src/lib.rs index 1cdb780..5dff1a5 100644 --- a/adapters/aien/src/lib.rs +++ b/adapters/aien/src/lib.rs @@ -30,6 +30,7 @@ use interplane_crossveil::{CallContext, ObservedRecord, Pipeline, Refusal, Runti use serde_json::{json, Map, Value}; pub mod compose_ledger; +pub mod provenance_export; pub use compose_ledger::{ hmac_sha256, ApprovalBinding, ComposeLedgerAuthority, DeskKey, LedgerClient, APPROVAL_BINDING_VERSION, BOUND_REQUIREMENTS, DEFAULT_APPROVER, LEDGER_BOUNDARY, diff --git a/adapters/aien/src/provenance_export.rs b/adapters/aien/src/provenance_export.rs new file mode 100644 index 0000000..99c08f2 --- /dev/null +++ b/adapters/aien/src/provenance_export.rs @@ -0,0 +1,419 @@ +//! Export of one live adapter run as a provenance bundle (`provenance/` verifier input). +//! +//! After a live row against a real `aien-cli daemon`, [`export_bundle`] writes a directory that +//! `cd provenance && cargo run -q --locked -- verify ` can judge: the daemon's own +//! `ComposeRecall` views of the claim, the settlement, the grant, the intent and the ack (raw, +//! unchanged), a `daemon-run.json` the harness writes from `/proc`, the daemon's load log, the +//! INTERPLANE trace of this run, the model files the daemon loaded (hard link, or copy), and a +//! `COMPANION.json` naming each by path, size and SHA-256. +//! +//! Honest labels, nothing invented: the proposal here is a SCRIPTED turn (the test wrote the tool +//! call), so the manifest says `proposal_origin: scripted_turn` and the verdict can never be +//! `PASS complete`; it is `PASS_LABELLED_INCOMPLETE missing=link:model_turn`. The model's training +//! history is unknown (`lineage.kind = unknown_pretraining`, with the origin the caller names). +//! No record is signed; the verifier cannot tell an export from a hand-written file (see +//! `provenance/BINDING.md`, Trust). This module reads the daemon and writes files; it grants and +//! decides nothing. +use crate::compose_ledger::LedgerClient; +use serde_json::{json, Map, Value}; +use sha2::{Digest, Sha256}; +use std::path::{Path, PathBuf}; + +/// What the exporter needs to know about the finished run. +pub struct LiveRun<'a> { + /// Bundle directory; created, and refused when it already holds a `COMPANION.json`. + pub out: &'a Path, + pub client: &'a LedgerClient, + /// The `aien-cli` binary the daemon was started from. + pub aien_bin: &'a Path, + /// Process id of that daemon (the harness spawned it). + pub daemon_pid: u32, + /// The daemon's stdout log (contains the model load line and the socket line). + pub daemon_log: &'a Path, + pub socket: &'a Path, + pub workspace: &'a Path, + /// Directory holding `model.safetensors`, `tokenizer.json` and `config.json`. + pub model_dir: &'a Path, + /// Where the weights came from (`model_id`, `revision`), restated and not judged. + pub model_origin: (&'a str, &'a str), + /// The label on the scripted "model" in the trace. + pub model_label: &'a str, + pub trace_id: &'a str, + /// `serde_json::to_value` of the pipeline's intent, of its `requires_approval` result and of + /// the final result of the approved continuation. + pub intent: &'a Value, + pub pending: &'a Value, + pub final_result: &'a Value, + /// RFC 3339 times of the request and of completion (see [`rfc3339_utc`]). + pub t_request: &'a str, + pub t_done: &'a str, +} + +/// What was written. +#[derive(Debug)] +pub struct ExportReport { + pub dir: PathBuf, + pub request_id: String, + pub claim: u64, + pub ack: u64, + pub executable_sha256: String, + pub model_hardlinked: bool, +} + +pub fn sha256_hex(b: &[u8]) -> String { + format!("{:x}", Sha256::digest(b)) +} + +fn sha256_file(p: &Path) -> Result { + use std::io::Read; + let mut f = std::fs::File::open(p).map_err(|e| format!("{}: {e}", p.display()))?; + let (mut h, mut buf) = (Sha256::new(), vec![0u8; 1 << 20]); + loop { + let n = f.read(&mut buf).map_err(|e| e.to_string())?; + if n == 0 { + break; + } + h.update(&buf[..n]); + } + Ok(format!("{:x}", h.finalize())) +} + +/// `YYYY-MM-DDTHH:MM:SSZ` for a Unix time in seconds (proleptic Gregorian, UTC). +pub fn rfc3339_utc(secs: u64) -> String { + let (days, rem) = (secs / 86_400, secs % 86_400); + let z = days as i64 + 719_468; + let era = z.div_euclid(146_097); + let doe = z.rem_euclid(146_097); + let yoe = (doe - doe / 1_460 + doe / 36_524 - doe / 146_096) / 365; + let doy = doe - (365 * yoe + yoe / 4 - yoe / 100); + let mp = (5 * doy + 2) / 153; + let d = doy - (153 * mp + 2) / 5 + 1; + let m = if mp < 10 { mp + 3 } else { mp - 9 }; + let y = yoe + era * 400 + i64::from(m <= 2); + format!( + "{y:04}-{m:02}-{d:02}T{:02}:{:02}:{:02}Z", + rem / 3600, + rem % 3600 / 60, + rem % 60 + ) +} + +/// Now, as RFC 3339 UTC. +pub fn now_rfc3339() -> String { + let s = std::time::SystemTime::now() + .duration_since(std::time::UNIX_EPOCH) + .map(|d| d.as_secs()) + .unwrap_or(0); + rfc3339_utc(s) +} + +/// Field 22 of `/proc//stat` (start time in clock ticks since boot), the same identity the +/// daemon writes into its replay claim as `executor.start`. +pub fn proc_start_ticks(pid: u32) -> Result { + let stat = std::fs::read_to_string(format!("/proc/{pid}/stat")).map_err(|e| e.to_string())?; + // `comm` may hold spaces and parentheses: split after the LAST ')'. + let rest = stat.rsplit_once(')').ok_or("stat: no ')'")?.1; + rest.split_whitespace() + .nth(19) + .and_then(|x| x.parse().ok()) + .ok_or_else(|| "stat: no start time".into()) +} + +fn write(dir: &Path, rel: &str, bytes: &[u8]) -> Result<(), String> { + let p = dir.join(rel); + std::fs::create_dir_all(p.parent().ok_or("no parent")?).map_err(|e| e.to_string())?; + std::fs::write(&p, bytes).map_err(|e| format!("{}: {e}", p.display())) +} + +/// Write a record file and list it in the manifest by path, digest and size. +fn put( + dir: &Path, + records: &mut Map, + name: &str, + rel: &str, + bytes: Vec, +) -> Result<(), String> { + write(dir, rel, &bytes)?; + records.insert( + name.into(), + json!({"path": rel, "sha256": sha256_hex(&bytes), "bytes": bytes.len()}), + ); + Ok(()) +} + +fn pretty(v: &Value) -> Vec { + serde_json::to_vec_pretty(v).unwrap_or_default() +} + +/// The raw `ComposeRecall` view (`cited[]`) of one record id. +fn view(cited: &[Value], id: u64) -> Result { + cited + .iter() + .find(|v| v["id"].as_u64() == Some(id)) + .cloned() + .ok_or_else(|| format!("record {id} not returned by ComposeRecall")) +} + +fn text_of(v: &Value) -> Value { + v["text"] + .as_str() + .and_then(|t| serde_json::from_str(t).ok()) + .unwrap_or(Value::Null) +} + +/// Write the bundle and return what it holds. Errors say what was missing; nothing is guessed. +pub fn export_bundle(run: &LiveRun<'_>) -> Result { + if run.out.join("COMPANION.json").exists() { + return Err(format!( + "{} already holds a COMPANION.json (a sealed record is never rewritten)", + run.out.display() + )); + } + std::fs::create_dir_all(run.out).map_err(|e| e.to_string())?; + let rc = &run.final_result["data"]["receipt"]; + let id_of = |k: &str| { + rc[k] + .as_u64() + .or_else(|| rc["handoff"][k].as_u64()) + .ok_or_else(|| format!("receipt has no {k}")) + }; + let (claim, grant, intent, ack) = ( + id_of("replay_claim")?, + id_of("grant_id")?, + id_of("intent_id")?, + id_of("ack_record_id")?, + ); + let request_id = run.final_result["request_id"] + .as_str() + .ok_or("final result has no request_id")? + .to_string(); + + // The daemon's own export command, over the window claim..=ack. + let ids: Vec = (claim..=ack).collect(); + let recalled = run.client.recall(&ids, None)?; + if !recalled["missing"].as_array().is_some_and(|m| m.is_empty()) { + return Err(format!( + "ComposeRecall missing records: {}", + recalled["missing"] + )); + } + let cited = recalled["cited"] + .as_array() + .ok_or("ComposeRecall: no cited")?; + let committed = cited + .iter() + .find(|v| { + let t = text_of(v); + t["approved_submission"] == "committed" && t["claim"].as_u64() == Some(claim) + }) + .cloned() + .ok_or("no committed settlement record for the claim")?; + + let mut records = Map::new(); + put( + run.out, + &mut records, + "ledger_claim", + "records/aien/ledger-claim.json", + pretty(&view(cited, claim)?), + )?; + put( + run.out, + &mut records, + "ledger_committed", + "records/aien/ledger-committed.json", + pretty(&committed), + )?; + put( + run.out, + &mut records, + "ledger_grant", + "records/aien/ledger-grant.json", + pretty(&view(cited, grant)?), + )?; + put( + run.out, + &mut records, + "ledger_intent", + "records/aien/ledger-intent.json", + pretty(&view(cited, intent)?), + )?; + put( + run.out, + &mut records, + "ledger_ack", + "records/aien/ledger-ack.json", + pretty(&view(cited, ack)?), + )?; + + let exe_sha = sha256_file(run.aien_bin)?; + let boot_id = std::fs::read_to_string("/proc/sys/kernel/random/boot_id") + .map(|s| s.trim().to_string()) + .unwrap_or_default(); + let daemon_run = json!({"kind": "aien-daemon-run", "pid": run.daemon_pid, + "start_ticks": proc_start_ticks(run.daemon_pid)?, + "socket": run.socket.to_str().ok_or("socket path")?, + "workspace": run.workspace.to_str().ok_or("workspace path")?, + "executable_sha256": exe_sha, "boot_id": boot_id, + "note": "written by the run harness from /proc//stat and the spawned child pid, not by the daemon"}); + put( + run.out, + &mut records, + "daemon_run", + "records/aien/daemon-run.json", + pretty(&daemon_run), + )?; + put( + run.out, + &mut records, + "aien_load_log", + "records/aien/daemon-load.log", + std::fs::read(run.daemon_log).map_err(|e| format!("daemon log: {e}"))?, + )?; + + // The trace: the request the pipeline admitted, its requires_approval result, the final result. + let env = + |n: u32, parent: Option<&str>, src: (&str, &str), dst: (&str, &str), t: &str, p: &Value| { + let mut e = json!({"interplane_version": "0.1", "message_id": format!("m-{n}"), + "trace_id": run.trace_id, "timestamp": t, + "source": {"kind": src.0, "id": src.1}, "destination": {"kind": dst.0, "id": dst.1}, + "payload": p}); + if let Some(pp) = parent { + e["parent_id"] = json!(pp); + } + e + }; + let model = ("model", run.model_label); + let trace = json!([ + env( + 1, + None, + model, + ("runtime", "aien"), + run.t_request, + run.intent + ), + env( + 2, + Some("m-1"), + ("runtime", "aien"), + model, + run.t_request, + run.pending + ), + env( + 3, + Some("m-1"), + ("runtime", "aien"), + model, + run.t_done, + run.final_result + ), + ]); + for e in trace.as_array().into_iter().flatten() { + interplane_core::validate_envelope_value(e) + .map_err(|c| format!("trace envelope invalid {c:?}"))?; + } + put( + run.out, + &mut records, + "interplane_trace", + "records/interplane/trace.json", + pretty(&trace), + )?; + + // The model files the daemon loaded: hard link when on one filesystem, else a copy. + let mut hardlinked = true; + for (name, file) in [ + ("export_weights", "model.safetensors"), + ("export_tokenizer", "tokenizer.json"), + ("export_config", "config.json"), + ] { + let src = std::fs::canonicalize(run.model_dir.join(file)) + .map_err(|e| format!("{}: {e}", run.model_dir.join(file).display()))?; + let rel = format!("records/export/{file}"); + let dst = run.out.join(&rel); + std::fs::create_dir_all(dst.parent().ok_or("no parent")?).map_err(|e| e.to_string())?; + let _ = std::fs::remove_file(&dst); + if std::fs::hard_link(&src, &dst).is_err() { + hardlinked = false; + std::fs::copy(&src, &dst).map_err(|e| format!("copy {}: {e}", src.display()))?; + } + records.insert( + name.into(), + json!({"path": rel, "sha256": sha256_file(&dst)?, + "bytes": std::fs::metadata(&dst).map_err(|e| e.to_string())?.len()}), + ); + } + + let companion = json!({ + "kind": "interplane-provenance-companion", "schema": 0, + "fixture": {"class": "real", "note": "Real daemon; the five ledger records are the daemon's own ComposeRecall output (pretty-printed only); daemon_run.json and the 3-message trace are written by the test harness, including their timestamps. The model turn is SCRIPTED by the test (the tool call is a test constant), so authorship of the proposal is not claimed; the model only loaded."}, + "lineage": {"kind": "unknown_pretraining", + "origin": {"model_id": run.model_origin.0, "model_id_source": "caller-asserted (AIEN_LEDGER_MODEL_ID or default; not checked against the model directory)", "revision": run.model_origin.1, + "note": "weights as downloaded; no training evidence is held"}}, + "export": {"format": "huggingface", "chat_template": Value::Null}, + "load_support": {"declared": "supported_structural"}, + "aien": {"candidate_id": Value::Null, "executable": "aien-cli", "executable_sha256": exe_sha, + "note": "no frozen AIEN candidate: no candidate_manifest record; CPU-reference backend as printed in the daemon log; whether the compose library was native-linked is not reported by the daemon"}, + "interplane": {"trace_id": run.trace_id, "request_id": request_id}, + "effect": {"binding": "aien-ledger-slice/1", "approval_binding": "aien.approval.v2", + "proposal_origin": "scripted_turn"}, + "completeness": {"state": "incomplete", "missing": ["link:model_turn"], + "reason": "the INTERPLANE model turn is scripted by the test: nothing links this model to the effect's content"}, + "records": Value::Object(records), + }); + write(run.out, "COMPANION.json", &pretty(&companion))?; + Ok(ExportReport { + dir: run.out.to_path_buf(), + request_id, + claim, + ack, + executable_sha256: exe_sha, + model_hardlinked: hardlinked, + }) +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn rfc3339_known_instants() { + assert_eq!(rfc3339_utc(0), "1970-01-01T00:00:00Z"); + assert_eq!(rfc3339_utc(951_782_400), "2000-02-29T00:00:00Z"); + assert_eq!(rfc3339_utc(1_791_417_600), "2026-10-08T00:00:00Z"); + } + + #[test] + fn own_start_ticks_are_readable() { + assert!(proc_start_ticks(std::process::id()).unwrap() > 0); + } + + #[test] + fn refuses_to_overwrite_a_sealed_bundle() { + let d = tempfile::tempdir().unwrap(); + std::fs::write(d.path().join("COMPANION.json"), b"{}").unwrap(); + let c = LedgerClient::new(d.path().join("none.sock")); + let v = json!(null); + let r = export_bundle(&LiveRun { + out: d.path(), + client: &c, + aien_bin: Path::new("/nonexistent"), + daemon_pid: 1, + daemon_log: Path::new("/nonexistent"), + socket: Path::new("/x"), + workspace: Path::new("/x"), + model_dir: Path::new("/x"), + model_origin: ("m", "r"), + model_label: "m", + trace_id: "t", + intent: &v, + pending: &v, + final_result: &v, + t_request: "t", + t_done: "t", + }); + assert!(r.unwrap_err().contains("never rewritten")); + } +} diff --git a/adapters/aien/tests/compose_ledger.rs b/adapters/aien/tests/compose_ledger.rs index 507f2cd..1667708 100644 --- a/adapters/aien/tests/compose_ledger.rs +++ b/adapters/aien/tests/compose_ledger.rs @@ -54,6 +54,7 @@ struct Daemon { sock: PathBuf, desk_key_id: String, log: PathBuf, + model: PathBuf, started_ms: u128, _keep: Option, } @@ -147,6 +148,7 @@ fn daemon(row: &str) -> Option { sock: sock.clone(), desk_key_id, log: log.clone(), + model: model.clone(), started_ms: 0, _keep: keep, }; @@ -322,7 +324,7 @@ fn pipe<'a>(rt: &'a mut ComposeLedgerAuthority, l: &ComposeLedgerAuthority) -> P } /// Propose `write_file path content` as request `id`; it must stop at requires_approval. -fn propose(p: &mut Pipeline<'_>, n: u64, id: &str, path: &str, content: &str) { +fn propose(p: &mut Pipeline<'_>, n: u64, id: &str, path: &str, content: &str) -> (Value, Value) { let out = p.run_turn( "openai", "scripted", @@ -340,6 +342,10 @@ fn propose(p: &mut Pipeline<'_>, n: u64, id: &str, path: &str, content: &str) { "{:?}", out.results[0] ); + ( + serde_json::to_value(&out.intents[0]).unwrap(), + serde_json::to_value(&out.results[0]).unwrap(), + ) } /// Host approves request `id` (one AIEN grant) as `drake` and continues it. @@ -359,6 +365,50 @@ fn approve( (r, g) } +/// With `LEDGER_OUT` set (the live gate), write the row-1 run as a provenance bundle in +/// `/bundle` for `provenance verify`. Without it nothing is exported (a temp dir would +/// make the model copy pointless). +fn export_provenance( + d: &Daemon, + intent: &Value, + pending: &Value, + res: &ToolResult, + t_request: &str, + t_done: &str, +) { + if std::env::var("LEDGER_OUT").is_err() { + return; + } + let bin = std::env::var("AIEN_BIN").expect("AIEN_BIN"); + let model_id = std::env::var("AIEN_LEDGER_MODEL_ID") + .unwrap_or_else(|_| "unsloth/Llama-3.2-1B-Instruct".into()); + let revision = std::fs::canonicalize(&d.model) + .ok() + .and_then(|p| p.file_name().map(|n| n.to_string_lossy().into_owned())) + .unwrap_or_default(); + let final_result = serde_json::to_value(res).unwrap(); + let rep = provenance_export::export_bundle(&provenance_export::LiveRun { + out: &d.root.join("bundle"), + client: &d.client(), + aien_bin: Path::new(&bin), + daemon_pid: d.child.id(), + daemon_log: &d.log, + socket: &d.sock, + workspace: &d.ws(), + model_dir: &d.model, + model_origin: (&model_id, &revision), + model_label: "scripted-test-model", + trace_id: TRACE, + intent, + pending, + final_result: &final_result, + t_request, + t_done, + }) + .expect("provenance export"); + println!("PROVENANCE_BUNDLE {}", rep.dir.display()); +} + fn lock() -> std::sync::MutexGuard<'static, ()> { SERIAL.lock().unwrap_or_else(|e| e.into_inner()) } @@ -373,9 +423,11 @@ fn row1_approved_write_lands_and_is_done() { let l = ledger(&d); let mut rt = l.clone(); let mut p = pipe(&mut rt, &l); - propose(&mut p, 0, "w1", "summary.txt", EXPECTED); + let (intent_v, pending_v) = propose(&mut p, 0, "w1", "summary.txt", EXPECTED); + let t_request = provenance_export::now_rfc3339(); let (res, _) = approve(&mut p, &l, "w1"); assert_eq!(res.status, ResultStatus::Ok, "{res:?}"); + let t_done = provenance_export::now_rfc3339(); let rc = res.data["receipt"].clone(); assert_eq!(rc["state"], "DONE"); assert_eq!(rc["boundary"], LEDGER_BOUNDARY); @@ -448,6 +500,7 @@ fn row1_approved_write_lands_and_is_done() { json!({"verdict": "PASS", "records_before": before, "records_after": after, "receipt": rc, "journal": recs, "file_sha256": hex(&written), "expected_sha256": hex(EXPECTED.as_bytes())}), ); + export_provenance(&d, &intent_v, &pending_v, &res, &t_request, &t_done); } #[test] ```