aien-dev has reached the 50-credit limit for trial accounts. To continue receiving code reviews, upgrade your plan.
interplane-mv
INTERPLANE: open interoperability protocol between AI models and agent runtimes. Models express intent. Runtimes retain authority.
Brought by drakestapleton
GitHub aien-dev/interplane-mv#22 (code only)
Apply it
git checkout -b patch-f5151561d2b93902 72c1224885ee78c8c65cdd34c39f2b1b6b5827c1 curl -fsSL https://interplane.io/drakestapleton/interplane-mv/patches/f5151561d2b93902.patch | git am
Provenance
github-import 1
aien-dev/interplane-mv
22
4f7d4408d0590775040ef167daf2bc2c9c4e162e
{"kind":"github-import","owner":"aien-dev","repo":"interplane-mv","number":22,"url":"https://github.com/aien-dev/interplane-mv/pull/22","export_sha256":"967c79e26a893657b5cdaa45efd442be5dbd2ecfe68e25f9a8c1b5da4d60d452","imported_utc":"2026-11-18T16:40:00Z","metadata":"unavailable","state_derived":true}
Changes
diff --git a/CHANGELOG.md b/CHANGELOG.md index b30f780..f689021 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - Security: the Rust lifecycle now accepts an approval continuation only with the `approval_id` the runtime minted for that request, as Python already did; before, any non-empty id was accepted. A non-`authorized` continuation value with the minted id is DENIED in both SDKs. Lifecycle conformance cases `lifecycle/01-05`; 30/30 byte-identical. - Trust vocabulary reconciled (plan cut P1, gaps G1-G3): CROSSVEIL.md default is `tool_result` + `unknown` (the undefined `untrusted_tool_content` and `origin` are gone), VERSIONING.md lists `ContentKind` in place of the undefined `Origin`. Python now reads an unrecognized or non-string `content_kind` as `unknown`, as Rust did; non-string trust is `external_untrusted`. Odysseus `system` result integrity maps to `trusted_runtime` unless Odysseus's own gate marks the result untrusted. Conformance cases 26, 27 (with a harness-only `mock_provenance` seam and JCS round-trip checks); 32/32 byte-identical together with lifecycle/01-05. +- InputRecord and Exposure types (plan cut P2): `spec/schemas/input.schema.json`, optional `provenance.exposure` in `intent.schema.json`, Crossveil Trust rules 5 and 6, Rust and Python types in lockstep, one schema-valid example per source class under `conformance/fixtures/input/`, digest fixtures `digest/input-record-01` and `digest/exposure-01` identical in both languages; types only, no pipeline behaviour (cut P3). ## Unreleased (0.2, CrossAxis lane) diff --git a/STATUS.md b/STATUS.md index d4b4fa2..6ebd91b 100644 --- a/STATUS.md +++ b/STATUS.md @@ -18,6 +18,7 @@ byte-identical) · `qualified` (measured against a real model/backend). | CrossAxis expansion v1 (expand + discover, bounded) | conformant | conformant | cases 24, 25 | selections and digests byte-identical across languages; not yet qualified against a live model; never grants authority | | Crossveil pipeline + mock runtime | conformant | conformant | 27 cases | fails closed on adapter faults | | Crossveil trust vocabulary (0.3 cut P1) | conformant | conformant | cases 26, 27 | unrecognized content_kind -> `unknown` in both SDKs (Python used `tool_result` before); absent/null trust -> `unknown`, unrecognized -> `external_untrusted`; `trusted` never true for them, also after a JCS round trip; Odysseus `system` integrity mapped explicitly | +| InputRecord and Exposure types (0.3 cut P2) | conformant | conformant | digest/input-record-01, digest/exposure-01 | schema `input.schema.json`, 9 source-class examples validated in CI; types only: the pipeline records no inputs and computes no exposure until cut P3 | | Crossveil lifecycle: approval continuation | conformant | conformant | lifecycle/01-05 | only the approval_id the runtime minted for that request continues it; forged, empty, missing and other-request ids refused (Rust accepted any non-empty id before 0.3 cut A1); no pipeline continuation call yet (cut A2) | | Reproducibility pins | - | - | - | see docs/RUN-MANIFEST-COMMITS.md (toolchain, pip constraints, action SHAs, AIEN sibling pins) | | Conformance runner | implemented | implemented | 32/32 both (27 cases + 5 lifecycle, verdicts byte-identical) | `--dump` writes canonical results per case | diff --git a/conformance/fixtures/digest/exposure-01.json b/conformance/fixtures/digest/exposure-01.json new file mode 100644 index 0000000..77f37f9 --- /dev/null +++ b/conformance/fixtures/digest/exposure-01.json @@ -0,0 +1,12 @@ +{ + "type": "Exposure", + "value": { + "inputs": [ + "in-0003", + "in-0007" + ], + "floor": "external_untrusted" + }, + "expected_jcs": "{\"floor\":\"external_untrusted\",\"inputs\":[\"in-0003\",\"in-0007\"]}", + "expected_sha256": "sha256:f98388072bbfdd28aa2ba9ed9abb8bc0905cdf542d0e251e4ea7244916a64748" +} diff --git a/conformance/fixtures/digest/input-record-01.json b/conformance/fixtures/digest/input-record-01.json new file mode 100644 index 0000000..4b4eb8a --- /dev/null +++ b/conformance/fixtures/digest/input-record-01.json @@ -0,0 +1,22 @@ +{ + "type": "InputRecord", + "value": { + "input_id": "in-0007", + "content_kind": "web_content", + "trust": "external_untrusted", + "source": { + "kind": "runtime", + "id": "mock-web" + }, + "origin": "https://example.test/page?q=café", + "content_digest": "sha256:abababababababababababababababababababababababababababababababab", + "trace_id": "trace-p2", + "parent_id": null, + "derived_from": [ + "in-0003", + "in-0005" + ] + }, + "expected_jcs": "{\"content_digest\":\"sha256:abababababababababababababababababababababababababababababababab\",\"content_kind\":\"web_content\",\"derived_from\":[\"in-0003\",\"in-0005\"],\"input_id\":\"in-0007\",\"origin\":\"https://example.test/page?q=café\",\"parent_id\":null,\"source\":{\"id\":\"mock-web\",\"kind\":\"runtime\"},\"trace_id\":\"trace-p2\",\"trust\":\"external_untrusted\"}", + "expected_sha256": "sha256:66214ab6be8bc1d7286f835c4b6755382498957f029bc59b60826603369621c1" +} diff --git a/conformance/fixtures/input/document.json b/conformance/fixtures/input/document.json new file mode 100644 index 0000000..a939c25 --- /dev/null +++ b/conformance/fixtures/input/document.json @@ -0,0 +1,16 @@ +{ + "input_id": "in-0004", + "content_kind": "document", + "trust": "external_untrusted", + "source": { + "kind": "runtime", + "id": "mock-docs" + }, + "origin": "file:report.pdf", + "content_digest": "sha256:4444444444444444444444444444444444444444444444444444444444444444", + "trace_id": "trace-ex", + "parent_id": "req-4", + "derived_from": [ + "in-0001" + ] +} diff --git a/conformance/fixtures/input/external-provider.json b/conformance/fixtures/input/external-provider.json new file mode 100644 index 0000000..2b88fd9 --- /dev/null +++ b/conformance/fixtures/input/external-provider.json @@ -0,0 +1,14 @@ +{ + "input_id": "in-0007", + "content_kind": "external_provider", + "trust": "external_untrusted", + "source": { + "kind": "adapter", + "id": "provider-x" + }, + "origin": "provider:search-x", + "content_digest": "sha256:7777777777777777777777777777777777777777777777777777777777777777", + "trace_id": "trace-ex", + "parent_id": "req-6", + "derived_from": [] +} diff --git a/conformance/fixtures/input/memory.json b/conformance/fixtures/input/memory.json new file mode 100644 index 0000000..28acafd --- /dev/null +++ b/conformance/fixtures/input/memory.json @@ -0,0 +1,14 @@ +{ + "input_id": "in-0003", + "content_kind": "memory", + "trust": "workspace_untrusted", + "source": { + "kind": "runtime", + "id": "mock-memory" + }, + "origin": "memory:rec-41", + "content_digest": "sha256:3333333333333333333333333333333333333333333333333333333333333333", + "trace_id": "trace-ex", + "parent_id": "req-3", + "derived_from": [] +} diff --git a/conformance/fixtures/input/runtime-generated.json b/conformance/fixtures/input/runtime-generated.json new file mode 100644 index 0000000..2b1520d --- /dev/null +++ b/conformance/fixtures/input/runtime-generated.json @@ -0,0 +1,14 @@ +{ + "input_id": "in-0008", + "content_kind": "runtime_instruction", + "trust": "trusted_runtime", + "source": { + "kind": "runtime", + "id": "mock-runtime" + }, + "origin": "runtime:system-prompt", + "content_digest": "sha256:8888888888888888888888888888888888888888888888888888888888888888", + "trace_id": "trace-ex", + "parent_id": null, + "derived_from": [] +} diff --git a/conformance/fixtures/input/skill.json b/conformance/fixtures/input/skill.json new file mode 100644 index 0000000..d1a73bb --- /dev/null +++ b/conformance/fixtures/input/skill.json @@ -0,0 +1,14 @@ +{ + "input_id": "in-0005", + "content_kind": "skill", + "trust": "workspace_untrusted", + "source": { + "kind": "runtime", + "id": "mock-skills" + }, + "origin": "runtime:mock-tool-description:filesystem.read", + "content_digest": "sha256:5555555555555555555555555555555555555555555555555555555555555555", + "trace_id": "trace-ex", + "parent_id": null, + "derived_from": [] +} diff --git a/conformance/fixtures/input/tool-output.json b/conformance/fixtures/input/tool-output.json new file mode 100644 index 0000000..db6dfa4 --- /dev/null +++ b/conformance/fixtures/input/tool-output.json @@ -0,0 +1,14 @@ +{ + "input_id": "in-0006", + "content_kind": "tool_result", + "trust": "external_untrusted", + "source": { + "kind": "runtime", + "id": "mock-tools" + }, + "origin": "runtime:mock-shell", + "content_digest": "sha256:6666666666666666666666666666666666666666666666666666666666666666", + "trace_id": "trace-ex", + "parent_id": "req-5", + "derived_from": [] +} diff --git a/conformance/fixtures/input/user-request.json b/conformance/fixtures/input/user-request.json new file mode 100644 index 0000000..2a87fda --- /dev/null +++ b/conformance/fixtures/input/user-request.json @@ -0,0 +1,14 @@ +{ + "input_id": "in-0009", + "content_kind": "user_request", + "trust": "user_supplied", + "source": { + "kind": "operator", + "id": "operator-1" + }, + "origin": "runtime:user-turn-1", + "content_digest": "sha256:9999999999999999999999999999999999999999999999999999999999999999", + "trace_id": "trace-ex", + "parent_id": "msg-1", + "derived_from": [] +} diff --git a/conformance/fixtures/input/web.json b/conformance/fixtures/input/web.json new file mode 100644 index 0000000..18e2af6 --- /dev/null +++ b/conformance/fixtures/input/web.json @@ -0,0 +1,14 @@ +{ + "input_id": "in-0002", + "content_kind": "web_content", + "trust": "external_untrusted", + "source": { + "kind": "runtime", + "id": "mock-web" + }, + "origin": "https://example.test/page", + "content_digest": "sha256:2222222222222222222222222222222222222222222222222222222222222222", + "trace_id": "trace-ex", + "parent_id": "req-2", + "derived_from": [] +} diff --git a/conformance/fixtures/input/workspace.json b/conformance/fixtures/input/workspace.json new file mode 100644 index 0000000..04db737 --- /dev/null +++ b/conformance/fixtures/input/workspace.json @@ -0,0 +1,14 @@ +{ + "input_id": "in-0001", + "content_kind": "workspace_content", + "trust": "workspace_untrusted", + "source": { + "kind": "runtime", + "id": "mock-fs" + }, + "origin": "file:README.md", + "content_digest": "sha256:1111111111111111111111111111111111111111111111111111111111111111", + "trace_id": "trace-ex", + "parent_id": "req-1", + "derived_from": [] +} diff --git a/conformance/runners/validate_fixtures.py b/conformance/runners/validate_fixtures.py index 4f5293a..6aa8d7b 100644 --- a/conformance/runners/validate_fixtures.py +++ b/conformance/runners/validate_fixtures.py @@ -7,7 +7,7 @@ Exit status is non-zero on any failure. Checks: * fixture shape, 27 required cases, filename == case slug * lifecycle/ fixtures: required set, shape, minting decisions valid against decision.schema.json * expected.runtime counts agree with the observed records - * the JCS digest fixture recomputes + * every digest fixture recomputes; InputRecord examples (one per source class) validate * negative control: a mutated envelope MUST fail validation """ import copy, glob, hashlib, json, os, sys @@ -34,6 +34,7 @@ def validator(name): return Draft202012Validator(schemas[name], registry=registry, format_checker=FormatChecker()) V_ENV, V_INTENT = validator("envelope.schema.json"), validator("intent.schema.json") V_SEL = validator("selection.schema.json") +V_INPUT = validator("input.schema.json") V_DEC = validator("decision.schema.json") def check(v, inst, where): @@ -176,12 +177,40 @@ for p in sorted(glob.glob(os.path.join(FIX, "lifecycle", "*.json"))): elif d.get("request_id") != s.get("request_id"): fail("lifecycle/%s: step %d continuation must cite its own request_id" % (name, i)) if lseen != LIFECYCLE: fail("lifecycle cases missing/extra: %s" % sorted(lseen ^ LIFECYCLE)) -# ---- digest fixture -dp = os.path.join(FIX, "digest", "jcs-01.json") -d = load(dp) -got = jcs(d["value"]) -if got != d["expected_jcs"]: fail("digest/jcs-01: expected_jcs mismatch") -if "sha256:" + hashlib.sha256(got.encode("utf-8")).hexdigest() != d["expected_sha256"]: fail("digest/jcs-01: sha256 mismatch") +# ---- digest fixtures (every digest/*.json; a "type" is a schema-checked InputRecord or Exposure) +n_dig = 0 +for dp in sorted(glob.glob(os.path.join(FIX, "digest", "*.json"))): + d = load(dp); dn = "digest/" + os.path.basename(dp)[:-5]; n_dig += 1 + got = jcs(d["value"]) + if got != d["expected_jcs"]: fail("%s: expected_jcs mismatch" % dn) + if "sha256:" + hashlib.sha256(got.encode("utf-8")).hexdigest() != d["expected_sha256"]: fail("%s: sha256 mismatch" % dn) + if d.get("type") == "InputRecord": check(V_INPUT, d["value"], dn) + elif d.get("type") == "Exposure": + check(V_INTENT, {"kind": "tool_request", "request_id": "r", "tool": {"name": "t"}, "arguments": {}, + "provenance": {"dialect": "d", "parser_version": "0.1.0", "exposure": d["value"]}}, dn) + elif "type" in d: fail("%s: unknown type %r" % (dn, d["type"])) + +# ---- InputRecord examples: one per source class (plan cut P2, protocol gate P3) +INPUT_CLASSES = {"workspace": "workspace_content", "web": "web_content", "memory": "memory", "document": "document", + "skill": "skill", "tool-output": "tool_result", "external-provider": "external_provider", + "runtime-generated": "runtime_instruction", "user-request": "user_request"} +have_in = {os.path.basename(x)[:-5] for x in glob.glob(os.path.join(FIX, "input", "*.json"))} +if have_in != set(INPUT_CLASSES): fail("input examples differ: %s" % sorted(have_in ^ set(INPUT_CLASSES))) +for cls, kind in INPUT_CLASSES.items(): + ip = os.path.join(FIX, "input", cls + ".json") + if not os.path.exists(ip): continue + rec = load(ip) + if check(V_INPUT, rec, "input/" + cls) and rec["content_kind"] != kind: + fail("input/%s: content_kind must be %s" % (cls, kind)) + if rec.get("trust") in ("trusted_runtime", "user_supplied") and cls not in ("runtime-generated", "user-request"): + fail("input/%s: only runtime-generated and user-request material may be trusted" % cls) + for k in list(rec): + bad = {x: v for x, v in rec.items() if x != k} + if V_INPUT.is_valid(bad): fail("negative control: input/%s without %s validated" % (cls, k)) + if V_INPUT.is_valid({**rec, "trust": "trusted"}): fail("negative control: input/%s with bad trust validated" % cls) +if V_INTENT.is_valid({"kind": "tool_request", "request_id": "r", "tool": {"name": "t"}, "arguments": {}, + "provenance": {"dialect": "d", "parser_version": "0.1.0", "exposure": {"inputs": [], "floor": "trusted"}}}): + fail("negative control: exposure with bad floor validated") # ---- dialect fixtures n_dial = n_int = 0 @@ -205,7 +234,7 @@ for dia, names in req.items(): have = {os.path.basename(x)[:-5] for x in glob.glob(os.path.join(ROOT, "dialects", "fixtures", dia, "*.json"))} if have != names: fail("dialect %s fixtures differ: %s" % (dia, sorted(have ^ names))) -print("conformance cases: %d, lifecycle cases: %d, explicit envelopes validated: %d, dialect fixtures: %d, dialect intents validated: %d, negative controls: ok" % (n_cases, n_life, n_env, n_dial, n_int)) +print("conformance cases: %d, lifecycle cases: %d, explicit envelopes validated: %d, dialect fixtures: %d, dialect intents validated: %d, digest fixtures: %d, input examples: %d, negative controls: ok" % (n_cases, n_life, n_env, n_dial, n_int, n_dig, len(have_in))) if errors: print("FAIL (%d)" % len(errors)); [print(" -", e) for e in errors]; sys.exit(1) print("PASS") diff --git a/python/interplane/conformance.py b/python/interplane/conformance.py index be64bdd..e8233fa 100644 --- a/python/interplane/conformance.py +++ b/python/interplane/conformance.py @@ -6,7 +6,18 @@ import sys from pathlib import Path from typing import Any, Optional -from .core import Decision, Lifecycle, LifecycleError, Limits, ProtocolError, ToolResult, jcs +from .core import ( + Decision, + Exposure, + InputRecord, + Lifecycle, + LifecycleError, + Limits, + ProtocolError, + ToolResult, + digest, + jcs, +) from .crossaxis import expand, select from .crossveil import canonical_result_payload, default_pipeline @@ -139,6 +150,35 @@ def run_lifecycle_case(case: dict) -> dict: return {"pass": not problems, "steps": steps, "problems": problems} +def typed_roundtrip(type_name: str, value: Any) -> Any: + """Parse ``value`` as the named SDK type and serialize it back.""" + types = {"InputRecord": InputRecord, "Exposure": Exposure} + if type_name not in types: + raise ValueError(f"unknown fixture type {type_name}") + return types[type_name].from_dict(value).to_dict() + + +def check_digest_fixtures(fixtures_dir: str) -> list: + """Check every ``digest/*.json``. A fixture with a ``type`` is parsed as that SDK type and + re-serialized before the JCS and digest are compared. Returns ``[(name, error or None)]``.""" + out = [] + for path in sorted(Path(fixtures_dir, "digest").glob("*.json")): + fx = json.loads(path.read_text(encoding="utf-8")) + err = None + try: + value = fx["value"] + if "type" in fx: + value = typed_roundtrip(fx["type"], value) + if jcs(value) != fx["expected_jcs"]: + err = f"jcs mismatch: got {jcs(value)}" + elif digest(value) != fx["expected_sha256"]: + err = "sha256 mismatch" + except (ValueError, ProtocolError) as e: + err = str(e) + out.append((f"digest/{path.stem}", err)) + return out + + def main(argv: Optional[list] = None) -> int: ap = argparse.ArgumentParser(prog="interplane-conformance") ap.add_argument("fixtures_dir") @@ -166,6 +206,11 @@ def main(argv: Optional[list] = None) -> int: for p in v["problems"]: print(f" {p}") failed += not v["pass"] + for name, err in check_digest_fixtures(args.fixtures_dir): + print(f"{'PASS' if err is None else 'FAIL'} {name}") + if err: + print(f" {err}") + failed += err is not None total = len(verdicts) + len(lifecycle) print(f"{total - failed}/{total} passed") out = { diff --git a/python/interplane/core.py b/python/interplane/core.py index 50f2b5d..09e8a34 100644 --- a/python/interplane/core.py +++ b/python/interplane/core.py @@ -372,6 +372,56 @@ class ToolRequest(Model): TYPES = {"request_id": _STR, "arguments": _DICT, "provenance": _DICT, "extensions": _DICT} +@dataclass +class InputRecord(Model): + """``input.schema.json``: one piece of material placed in front of the model (0.3 cut P2). + + ``trust`` is assigned by the runtime, never by the model. ``parent_id`` is always emitted, as + an explicit ``null`` for host-registered inputs. + """ + + input_id: str + content_kind: str + trust: str + source: Party + origin: str + content_digest: str + trace_id: str + parent_id: Optional[str] = None + derived_from: list = field(default_factory=list) + extra: dict = field(default_factory=dict) + + NESTED = {"source": Party} + TYPES = { + "input_id": _STR, + "content_kind": _STR, + "trust": _STR, + "origin": _STR, + "content_digest": _STR, + "trace_id": _STR, + "parent_id": _STR, + "derived_from": (list,), + } + + def to_dict(self) -> dict: + out = super().to_dict() + out.setdefault("parent_id", None) + return out + + +@dataclass +class Exposure(Model): + """``provenance.exposure`` on a tool_request (0.3 cut P2): the inputs visible to the model and + the least trusted level among them. The pipeline computes it; a value arriving from a model or + an envelope is never read (cut P3).""" + + inputs: list + floor: str + extra: dict = field(default_factory=dict) + + TYPES = {"inputs": (list,), "floor": _STR} + + @dataclass class CapabilityRequest(Model): KIND = "capability_request" diff --git a/python/tests/test_core.py b/python/tests/test_core.py index b745b45..2bdde76 100644 --- a/python/tests/test_core.py +++ b/python/tests/test_core.py @@ -13,6 +13,8 @@ from interplane.core import ( Envelope, ErrorCode, Event, + Exposure, + InputRecord, Lifecycle, LifecycleError, Limits, @@ -246,6 +248,43 @@ def test_jcs_fixture(): assert digest(fx["value"]) == fx["expected_sha256"] +def test_digest_fixtures_all_pass(): + from interplane.conformance import check_digest_fixtures + + results = check_digest_fixtures(str(CONF)) + assert len(results) >= 2 + for name, err in results: + assert err is None, name + + +def test_input_record_examples_roundtrip_and_null_parent_is_explicit(): + files = sorted((CONF / "input").glob("*.json")) + assert len(files) == 9 + for f in files: + raw = json.loads(f.read_text(encoding="utf-8")) + assert InputRecord.from_dict(raw).to_dict() == raw + rec = InputRecord( + input_id="i", + content_kind="memory", + trust="made_up", + source=Party("runtime", "r"), + origin="m", + content_digest="sha256:00", + trace_id="t", + ) + out = rec.to_dict() + assert out["parent_id"] is None and out["derived_from"] == [] and out["trust"] == "made_up" + with pytest.raises(ProtocolError): + InputRecord.from_dict({k: v for k, v in out.items() if k != "origin"}) + + +def test_exposure_roundtrip_and_requires_both_fields(): + raw = {"inputs": ["a"], "floor": "unknown", "x": 1} + assert Exposure.from_dict(raw).to_dict() == raw + with pytest.raises(ProtocolError): + Exposure.from_dict({"inputs": ["a"]}) + + # ---- limits and ledger ---------------------------------------------------------------------- diff --git a/rust/crates/interplane-conformance/src/lib.rs b/rust/crates/interplane-conformance/src/lib.rs index 13d6fc9..9d76539 100644 --- a/rust/crates/interplane-conformance/src/lib.rs +++ b/rust/crates/interplane-conformance/src/lib.rs @@ -253,20 +253,69 @@ pub fn load_fixtures(dir: &Path) -> Result<Vec<Value>, String> { .collect() } -/// Check the JCS digest fixture (`digest/jcs-01.json`) if present. Returns an error text on mismatch. -pub fn check_digest_fixture(dir: &Path) -> Option<String> { - let p = dir.join("digest").join("jcs-01.json"); - let fx: Value = serde_json::from_str(&std::fs::read_to_string(p).ok()?).ok()?; - let got = canonicalize(&fx["value"]); +/// Check every `digest/*.json` fixture. A fixture with a `"type"` is also parsed as that SDK type +/// and re-serialized before the JCS and digest are compared. Returns `(name, error)` per fixture. +pub fn check_digest_fixtures(dir: &Path) -> Vec<(String, Option<String>)> { + let mut paths: Vec<_> = match std::fs::read_dir(dir.join("digest")) { + Ok(rd) => rd + .filter_map(Result::ok) + .map(|e| e.path()) + .filter(|p| p.extension().is_some_and(|x| x == "json")) + .collect(), + Err(_) => return Vec::new(), + }; + paths.sort(); + paths + .iter() + .map(|p| { + let name = format!("digest/{}", p.file_stem().unwrap().to_string_lossy()); + (name, check_digest_file(p)) + }) + .collect() +} + +fn check_digest_file(p: &Path) -> Option<String> { + let fx: Value = match std::fs::read_to_string(p) + .map_err(|e| e.to_string()) + .and_then(|s| serde_json::from_str(&s).map_err(|e| e.to_string())) + { + Ok(v) => v, + Err(e) => return Some(e), + }; + let value = match fx.get("type").and_then(Value::as_str) { + None => fx["value"].clone(), + Some(t) => match typed_roundtrip(t, &fx["value"]) { + Ok(v) => v, + Err(e) => return Some(e), + }, + }; + let got = canonicalize(&value); if fx["expected_jcs"].as_str() != Some(got.as_str()) { return Some(format!("jcs mismatch: got {got}")); } - if fx["expected_sha256"].as_str() != Some(digest(&fx["value"]).as_str()) { + if fx["expected_sha256"].as_str() != Some(digest(&value).as_str()) { return Some("sha256 mismatch".into()); } None } +/// Parse `value` as the named SDK type and serialize it back. +fn typed_roundtrip(ty: &str, value: &Value) -> Result<Value, String> { + let e = |e: serde_json::Error| e.to_string(); + match ty { + "InputRecord" => { + let t: interplane_core::InputRecord = + serde_json::from_value(value.clone()).map_err(e)?; + serde_json::to_value(t).map_err(e) + } + "Exposure" => { + let t: interplane_core::Exposure = serde_json::from_value(value.clone()).map_err(e)?; + serde_json::to_value(t).map_err(e) + } + _ => Err(format!("unknown fixture type {ty}")), + } +} + /// Silence an unused-import lint for `RuntimeAuthority` in docs builds. #[doc(hidden)] pub fn _runtime_id(r: &dyn RuntimeAuthority) -> String { diff --git a/rust/crates/interplane-conformance/src/main.rs b/rust/crates/interplane-conformance/src/main.rs index 0043d49..6e8c342 100644 --- a/rust/crates/interplane-conformance/src/main.rs +++ b/rust/crates/interplane-conformance/src/main.rs @@ -91,12 +91,14 @@ fn main() -> ExitCode { failed += usize::from(!errs.is_empty()); rows.push((case, lifecycle_verdict(&steps, &errs))); } - match check_digest_fixture(&dir) { - Some(e) => { - println!("{:<4} {:<34} FAIL\n - {e}", "-", "digest/jcs-01"); - failed += 1; + for (name, err) in check_digest_fixtures(&dir) { + match err { + Some(e) => { + println!("{:<4} {:<34} FAIL\n - {e}", "-", name); + failed += 1; + } + None => println!("{:<4} {:<34} PASS", "-", name), } - None => println!("{:<4} {:<34} PASS", "-", "digest/jcs-01"), } if let Some(o) = out { if let Err(e) = std::fs::write(&o, canonicalize(&verdicts(rows)) + "\n") { diff --git a/rust/crates/interplane-conformance/tests/fixtures.rs b/rust/crates/interplane-conformance/tests/fixtures.rs index 8e83025..e34152d 100644 --- a/rust/crates/interplane-conformance/tests/fixtures.rs +++ b/rust/crates/interplane-conformance/tests/fixtures.rs @@ -12,7 +12,11 @@ fn every_fixture_passes() { let errs = compare(fx, &run); assert!(errs.is_empty(), "{}: {errs:?}", run.case); } - assert_eq!(check_digest_fixture(&dir), None); + let digests = check_digest_fixtures(&dir); + assert!(digests.len() >= 2); + for (name, err) in digests { + assert_eq!(err, None, "{name}"); + } } #[test] diff --git a/rust/crates/interplane-core/src/types.rs b/rust/crates/interplane-core/src/types.rs index a186809..d475283 100644 --- a/rust/crates/interplane-core/src/types.rs +++ b/rust/crates/interplane-core/src/types.rs @@ -306,6 +306,37 @@ pub struct ToolRequest { pub extensions: Extensions, } +/// `input.schema.json`: one piece of material that was placed in front of the model (0.3 cut P2). +/// `trust` is assigned by the runtime, never by the model. `parent_id` is serialized as an +/// explicit `null` for host-registered inputs. +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +pub struct InputRecord { + pub input_id: String, + pub content_kind: ContentKind, + pub trust: TrustLevel, + pub source: Party, + pub origin: String, + pub content_digest: String, + pub trace_id: String, + #[serde(default)] + pub parent_id: Option<String>, + #[serde(default)] + pub derived_from: Vec<String>, + #[serde(flatten)] + pub extensions: Extensions, +} + +/// `provenance.exposure` on a `tool_request` (0.3 cut P2): the inputs visible to the model when it +/// produced the turn and the least trusted level among them. The pipeline computes it; a value +/// arriving from a model or an envelope is never read (cut P3). +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +pub struct Exposure { + pub inputs: Vec<String>, + pub floor: TrustLevel, + #[serde(flatten)] + pub extensions: Extensions, +} + /// How a capability request was mapped. #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct MappingInfo { diff --git a/rust/crates/interplane-core/tests/core.rs b/rust/crates/interplane-core/tests/core.rs index 297f08c..95aff1e 100644 --- a/rust/crates/interplane-core/tests/core.rs +++ b/rust/crates/interplane-core/tests/core.rs @@ -558,3 +558,38 @@ fn trust_levels_and_unknown_values() { ); assert_eq!(ContentKind::parse("web_content").as_str(), "web_content"); } + +#[test] +fn input_record_examples_roundtrip_and_null_parent_is_explicit() { + let dir = std::path::Path::new(env!("CARGO_MANIFEST_DIR")) + .join("../../../conformance/fixtures/input"); + let mut n = 0; + for e in std::fs::read_dir(dir).unwrap() { + let v: Value = + serde_json::from_str(&std::fs::read_to_string(e.unwrap().path()).unwrap()).unwrap(); + let rec: InputRecord = serde_json::from_value(v.clone()).unwrap(); + assert_eq!(serde_json::to_value(&rec).unwrap(), v); + n += 1; + } + assert_eq!(n, 9); + let mut v = json!({ + "input_id": "i", "content_kind": "memory", "trust": "made_up", "source": {"kind": "runtime", "id": "r"}, + "origin": "m", "content_digest": "sha256:00", "trace_id": "t", "x": 1 + }); + let rec: InputRecord = serde_json::from_value(v.clone()).unwrap(); + assert_eq!(rec.parent_id, None); + assert!(rec.derived_from.is_empty()); + v["parent_id"] = Value::Null; + v["derived_from"] = json!([]); + assert_eq!(serde_json::to_value(&rec).unwrap(), v); +} + +#[test] +fn exposure_roundtrips_inside_provenance_extensions() { + let mut p = tool_request_payload(); + p["provenance"]["exposure"] = json!({"inputs": ["a"], "floor": "unknown"}); + let tr: ToolRequest = serde_json::from_value(p.clone()).unwrap(); + assert_eq!(serde_json::to_value(&tr).unwrap(), p); + let ex: Exposure = serde_json::from_value(p["provenance"]["exposure"].clone()).unwrap(); + assert_eq!(ex.floor, TrustLevel::Undetermined); +} diff --git a/spec/CROSSVEIL.md b/spec/CROSSVEIL.md index de210a5..2fffded 100644 --- a/spec/CROSSVEIL.md +++ b/spec/CROSSVEIL.md @@ -61,6 +61,25 @@ proposal are never flattened into indistinguishable text. Rules: `external_untrusted`. AIEN's aegis-runtime has no equivalent today and the adapter fills in `unknown` honestly. +5. **InputRecord** (`input.schema.json`) names one piece of material placed in front of the model: + `input_id`, `content_kind`, `trust`, `source` (a `Party`: who handed the bytes to the context), + `origin` (a locator: file path, URL, memory record id, provider id or `runtime:<id>`, or a + digest-only form for sensitive locators), `content_digest`, `trace_id`, `parent_id` (the + `message_id` or `request_id` that produced it; `null` for host-registered inputs) and + `derived_from` (`input_id`s it was computed from; may be empty). The runtime assigns `trust`. + Content the model itself generated is `content_kind = model_generated` with trust + `external_untrusted`. The nine source classes are workspace, web, memory, document, skill + (including tool descriptions), tool output, external provider, runtime-generated and user + request; `conformance/fixtures/input/` holds one schema-valid example of each. +6. **Exposure** is the optional `provenance.exposure` on a `tool_request`: + `{inputs: [input_id...], floor: TrustLevel}`, where `floor` is the least trusted level among the + inputs visible to the model when it produced the turn. Order: `trusted_runtime` > + `user_supplied` > `workspace_untrusted` > `external_untrusted`; `unknown` counts as + `external_untrusted`. The pipeline computes it from its own ledger; an `exposure` arriving inside + a model-produced or admitted envelope is discarded and recomputed, never read. In this version + (0.3 cut P2) both are types and schemas only: the pipeline does not yet record inputs or compute + exposure. + Stage names used by this spec and their decision detail: INVALID is `REJECTED` with decision `invalid`; NOT_FOUND is `REJECTED` with decision `not_found`. A `capability_request` whose `mapping.catalog_digest` differs from the runtime's live catalog digest is rejected with diff --git a/spec/schemas/input.schema.json b/spec/schemas/input.schema.json new file mode 100644 index 0000000..799df85 --- /dev/null +++ b/spec/schemas/input.schema.json @@ -0,0 +1,20 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://interplane.dev/schemas/0.1/input.schema.json", + "title": "INTERPLANE InputRecord", + "description": "One piece of material placed in front of the model. Recorded by the runtime or the host, never by the model. `trust` is assigned by the runtime; a model cannot raise it.", + "type": "object", + "required": ["input_id", "content_kind", "trust", "source", "origin", "content_digest", "trace_id", "parent_id", "derived_from"], + "properties": { + "input_id": {"$ref": "common.schema.json#/$defs/Id", "description": "Unique per trace."}, + "content_kind": {"$ref": "common.schema.json#/$defs/ContentKind"}, + "trust": {"$ref": "common.schema.json#/$defs/TrustLevel"}, + "source": {"$ref": "common.schema.json#/$defs/Party", "description": "Who handed the bytes to the context."}, + "origin": {"type": "string", "minLength": 1, "maxLength": 2048, "description": "Locator for where the bytes came from: file path, URL, memory record id, provider id or `runtime:<id>`. May be a digest-only form (`sha256:...`) for sensitive locators."}, + "content_digest": {"$ref": "common.schema.json#/$defs/Digest", "description": "SHA-256 of the exact bytes shown to the model."}, + "trace_id": {"$ref": "common.schema.json#/$defs/Id"}, + "parent_id": {"oneOf": [{"$ref": "common.schema.json#/$defs/Id"}, {"type": "null"}], "description": "The message_id or request_id that produced this input. Null for host-registered inputs."}, + "derived_from": {"type": "array", "items": {"$ref": "common.schema.json#/$defs/Id"}, "description": "input_ids this input was computed from (summaries, nested content). May be empty."} + }, + "additionalProperties": true +} diff --git a/spec/schemas/intent.schema.json b/spec/schemas/intent.schema.json index 844611a..7ffc83a 100644 --- a/spec/schemas/intent.schema.json +++ b/spec/schemas/intent.schema.json @@ -22,7 +22,17 @@ "source_call_id": {"type": ["string", "null"], "maxLength": 256, "description": "The dialect-native call id if the dialect has one (e.g. OpenAI tool_call.id)."}, "source_digest": {"oneOf": [{"$ref": "common.schema.json#/$defs/Digest"}, {"type": "null"}], "description": "SHA-256 of the original dialect-native representation. Raw text is not persisted by default."}, "raw_name": {"type": ["string", "null"], "description": "Exactly what the model emitted as the tool name before canonicalization."}, - "coercion": {"type": ["string", "null"], "enum": ["none", "json_guess", null], "description": "How untyped dialect values were typed."} + "coercion": {"type": ["string", "null"], "enum": ["none", "json_guess", null], "description": "How untyped dialect values were typed."}, + "exposure": { + "type": "object", + "required": ["inputs", "floor"], + "properties": { + "inputs": {"type": "array", "items": {"$ref": "common.schema.json#/$defs/Id"}, "description": "input_ids visible to the model when it produced the turn."}, + "floor": {"$ref": "common.schema.json#/$defs/TrustLevel", "description": "Least trusted level among those inputs. Order: trusted_runtime > user_supplied > workspace_untrusted > external_untrusted; unknown counts as external_untrusted."} + }, + "additionalProperties": true, + "description": "Computed by the pipeline from its own ledger. A value arriving inside a model-produced or admitted envelope is discarded and recomputed, never read." + } }, "additionalProperties": true },