From b2ff4f9d72ff4d8056056198b9ddb990389c0381 Mon Sep 17 00:00:00 2001 From: Drake Stapleton Date: Sun, 4 Oct 2026 16:32:23 -0500 Subject: [PATCH 1/4] feat(adapter-aien): use AIEN-owned EffectAuthority path Co-Authored-By: Claude Sonnet 5.5 --- adapters/aien/Cargo.lock | 4 +- adapters/aien/Cargo.toml | 6 +- adapters/aien/README.md | 49 +++- adapters/aien/src/lib.rs | 242 ++++++++++++++---- ...3-aien-adapter-uses-existing-primitives.md | 12 + 5 files changed, 249 insertions(+), 64 deletions(-) diff --git a/adapters/aien/Cargo.lock b/adapters/aien/Cargo.lock index 4046d0e..93132db 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=75800398eb53646444d4c12e5a27fdc26cd14e04#75800398eb53646444d4c12e5a27fdc26cd14e04" +source = "git+https://github.com/aien-dev/aien-sovereign-core.git?rev=bdcb2d4fb631df7777b2ce9fbda41088a2abcd7e#bdcb2d4fb631df7777b2ce9fbda41088a2abcd7e" 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=75800398eb53646444d4c12e5a27fdc26cd14e04#75800398eb53646444d4c12e5a27fdc26cd14e04" +source = "git+https://github.com/aien-dev/aien-sovereign-core.git?rev=bdcb2d4fb631df7777b2ce9fbda41088a2abcd7e#bdcb2d4fb631df7777b2ce9fbda41088a2abcd7e" dependencies = [ "aien-capability", "async-trait", diff --git a/adapters/aien/Cargo.toml b/adapters/aien/Cargo.toml index 8af139d..816e73f 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 (public GitHub, exact commits the Phase 0 audit read). -aien-capability = { git = "https://github.com/aien-dev/aien-sovereign-core.git", rev = "75800398eb53646444d4c12e5a27fdc26cd14e04" } -aien-mcp = { git = "https://github.com/aien-dev/aien-sovereign-core.git", rev = "75800398eb53646444d4c12e5a27fdc26cd14e04" } +# Pinned AIEN sources: aien-dev/aien-sovereign-core PR #203 branch head (TEMPORARY; re-pin to the merge commit). +aien-capability = { git = "https://github.com/aien-dev/aien-sovereign-core.git", rev = "bdcb2d4fb631df7777b2ce9fbda41088a2abcd7e" } +aien-mcp = { git = "https://github.com/aien-dev/aien-sovereign-core.git", rev = "bdcb2d4fb631df7777b2ce9fbda41088a2abcd7e" } # 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/README.md b/adapters/aien/README.md index 66653b5..bb29314 100644 --- a/adapters/aien/README.md +++ b/adapters/aien/README.md @@ -5,17 +5,18 @@ authority machinery. License: AGPL-3.0-or-later (see `LICENSE`). Design: `docs/a **This adapter never changes AIEN and AIEN keeps all authority.** It builds nothing that AIEN could mistake for its own decision: no `AuthorizedEffect`, no `DoctrineDecision`, no -`SafetyDecision`. `authorized` appears only when AIEN's own gate returned `Ok` for a capability -AIEN's own classifier calls speculation-safe. Any effectful capability is `requires_approval` -with the reason `AIEN production cannot mint AuthorizedEffect; approval must come from AIEN` -and no approval id (AIEN has none to hand out). Nothing under `rust/`, `spec/`, `python/` or +`SafetyDecision`. `authorized` appears only when AIEN's own gate returned `Ok` for a read, or when AIEN's +`EffectLane::authorize` minted an `AuthorizedEffect` after AIEN's `EffectClassAuthority` said Allow. +`requires_approval` and `denied` carry AIEN's reason. No approval id is invented (AIEN has none to +hand out) and nothing is consumed. Nothing under `rust/`, `spec/`, `python/` or `conformance/` and no AIEN repository is modified. ## Pinned AIEN sources `aien-capability` and `aien-mcp` are git dependencies pinned to -`aien-dev/aien-sovereign-core@75800398eb53646444d4c12e5a27fdc26cd14e04` (the commit the Phase 0 -audit read). `aegis` (feature `aegis-gate`, on by default) cannot be a git dependency because +`aien-dev/aien-sovereign-core@bdcb2d4fb631df7777b2ce9fbda41088a2abcd7e` (head of PR #203, +`0.2/aien-mcp-authority`, which adds the production authority seam; TEMPORARY, re-pin to the merge +commit once #203 lands). `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 (`../aien-protocols/crates/*`). The build therefore expects this layout next to the INTERPLANE checkout: @@ -45,8 +46,32 @@ All paths relative to the pinned clones. | `MemoryWire` (in-process `McpWire`) | `aien-mcp/src/memory.rs:11` | | `aegis::pre_dispatch_check` (live allowlist gate) | `aegis-runtime/src/enforcement.rs:31` (`ALLOWED_SKILLS` at `:14`) | -`AuthorizedEffect` (`aien-mcp/src/effect.rs:40`) is never touched; its only constructor is -`#[cfg(test)]` (`effect.rs:77`). +`AuthorizedEffect` is never constructed here. The only production mint is crate-private inside +`aien-mcp`, reached through `EffectLane::authorize(intent, scope, &dyn EffectAuthority)`; the adapter +passes AIEN's own `EffectClassAuthority`. A test (`adapter_source_never_constructs_authorized_effect`) +greps `src/lib.rs` for struct-literal construction, `authorize_for_test`, `mint(` and any local +`EffectAuthority` impl. + +## Effect path (0.2) + +Reads are unchanged (speculative lane). Everything else (`routing_class` not Pure/ReadOnly) goes: +stage intent (a speculation-safe local-ephemeral tool cannot be staged by AIEN, so a plain +`EffectIntent` is used; it carries no authority) -> `EffectLane::authorize` with +`EffectClassAuthority` -> in `decide`: + +| AIEN decision | Crossveil decision | Executes | +|---|---|---| +| Allow / AllowRestricted (PURE, READ_*, LOCAL_EPHEMERAL) | `authorized`; the minted effect is held until `execute` | yes, via `EffectLane::execute_effect`; result carries the `EffectReceipt` | +| RequireApproval (EXTERNAL_WRITE, WORLD_MUTATION, SECRET_BEARING, SPAWN_PROCESS) | `requires_approval`, `runtime_state` has `staged=true` and `intent_digest=...` | no | +| Deny (EXTERNAL_IRREVERSIBLE, unknown tool or bits, stale intent) | `denied` with AIEN's reason | no | +| Contain | `denied` with AIEN's reason | no | + +Not implemented: approval consumption. `requires_approval` is a pending handle (the intent digest); +aien-mcp has no approval store wired, so there is no way yet to approve and then execute. The +stock `write_file` and `bash_eval` descriptors are WORLD_MUTATION, so they stay pending. +`with_effects(name, bits)` re-declares a stock capability's `ToolEffects` (used by tests with a +LOCAL_EPHEMERAL temp-dir write and an EXTERNAL_IRREVERSIBLE deny); AIEN's authority decides from +the new bits. ## Reimplemented, and why @@ -74,11 +99,9 @@ operator-side process. ## Not executed -Everything that is not a read: `write_file`, `bash_eval` and any unknown name return -`status: error`, `code: execution_error`, message `not executed by the reference adapter` if -`execute()` is ever called on them (the pipeline never does: those decisions are -`requires_approval`). Approval-to-execution stays `requires_approval` until AIEN ships a -production mint (its ADR 0016 R8). +`bash_eval` has no provider body, and any call whose decision is not authorized +returns `status: error`, `code: execution_error`, message `not executed by the reference adapter` +if `execute()` is ever called on it. `write_file` executes only with an AIEN-minted effect. ## Fail closed diff --git a/adapters/aien/src/lib.rs b/adapters/aien/src/lib.rs index 457e45d..febbaec 100644 --- a/adapters/aien/src/lib.rs +++ b/adapters/aien/src/lib.rs @@ -2,19 +2,25 @@ //! //! The adapter composes AIEN's existing primitives and mints nothing. It never constructs an //! `AuthorizedEffect`, a `DoctrineDecision` or a `SafetyDecision`. `authorized` is only ever the -//! translation of an `Ok` that AIEN's own gate returned, for a capability AIEN classifies as -//! speculation-safe. +//! translation of an answer AIEN produced: an `Ok` from AIEN's gate for a read, or an +//! `AuthorizedEffect` that `aien_mcp::EffectLane::authorize` minted after AIEN's own +//! `EffectClassAuthority` said Allow. `requires_approval` and `denied` carry AIEN's reason. +use std::collections::{BTreeMap, HashMap}; use std::fs; use std::path::{Component, Path, PathBuf}; use std::sync::atomic::{AtomicUsize, Ordering}; use std::sync::Arc; use aien_capability::{ - catalog_digest, routing_class, speculation_safe, Digest32, EffectClass, ProviderId, - ToolDescriptor, ToolEffects, + catalog_digest, routing_class, speculation_safe, Digest32, EffectClass, EffectId, JNodeId, + ProviderId, ToolDescriptor, ToolEffects, WorldId, }; use aien_mcp::memory::MemoryWire; -use aien_mcp::{CallOutcome, SessionManager, SpeculativeLane, SpeculativeToolCall}; +use aien_mcp::{ + AuthorityOutcome, AuthorizedEffect, CallOutcome, EffectClassAuthority, EffectIntent, + EffectLane, EffectScope, Error as McpError, SessionManager, SpeculativeLane, + SpeculativeToolCall, +}; use interplane_core::*; use interplane_crossaxis::MappingTable; use interplane_crossveil::{CallContext, RuntimeAuthority}; @@ -22,14 +28,14 @@ use serde_json::{json, Map, Value}; /// Runtime id carried in every decision, result and catalog. pub const RUNTIME_ID: &str = "aien"; -/// Pinned reply for any effectful capability (ADR 0003 item 2). -pub const APPROVAL_REASON: &str = - "AIEN production cannot mint AuthorizedEffect; approval must come from AIEN"; /// Pinned reply for everything the reference adapter does not run. pub const NOT_EXECUTED: &str = "not executed by the reference adapter"; /// Pinned reply when the AIEN gate is not linked or the adapter was built unavailable. pub const UNAVAILABLE: &str = "aien runtime not available"; +/// `authority.policy_engine` of every effect decision: AIEN's own authority. +pub const ENGINE_EFFECT: &str = "aien-mcp.EffectClassAuthority"; + const MAX_READ_BYTES: u64 = 1 << 20; /// One capability: AIEN-side name, effects, and the argument schema (all string-typed). @@ -82,17 +88,21 @@ fn hex(d: &Digest32) -> String { d.0.iter().map(|b| format!("{b:02x}")).collect() } -fn descriptors() -> Vec { +fn descriptors(overrides: &BTreeMap) -> Vec { SPECS .iter() .map(|s| { + let effects = overrides + .get(s.name) + .copied() + .unwrap_or_else(|| (s.effects)()); let sd = interplane_core::digest(&Value::Object(schema_for(s))); let raw = sd.trim_start_matches("sha256:"); let mut bytes = [0u8; 32]; for (i, b) in bytes.iter_mut().enumerate() { *b = u8::from_str_radix(&raw[2 * i..2 * i + 2], 16).unwrap_or(0); } - ToolDescriptor::new(s.name, (s.effects)(), Digest32(bytes)) + ToolDescriptor::new(s.name, effects, Digest32(bytes)) }) .collect() } @@ -103,7 +113,11 @@ pub struct AienAuthority { trust_workspace: bool, available: bool, descriptors: Vec, + overrides: BTreeMap, lane: SpeculativeLane, + effect_lane: EffectLane, + /// Effects AIEN minted in `decide`, waiting for `execute`. The adapter only holds them. + authorized: HashMap>, provider: ProviderId, runtime: tokio::runtime::Runtime, wire_calls: Arc, @@ -145,8 +159,11 @@ impl AienAuthority { workspace, trust_workspace: false, available: available && cfg!(feature = "aegis-gate"), - descriptors: descriptors(), + descriptors: descriptors(&BTreeMap::new()), + overrides: BTreeMap::new(), lane: SpeculativeLane::new(aien_mcp::McpBroker::new()), + effect_lane: EffectLane::new(aien_mcp::McpBroker::new()), + authorized: HashMap::new(), provider: ProviderId::new("interplane-reference"), runtime, wire_calls: Arc::new(AtomicUsize::new(0)), @@ -159,16 +176,31 @@ impl AienAuthority { let counter = self.wire_calls.clone(); let wire = MemoryWire::new(self.descriptors.clone(), move |name, args| { counter.fetch_add(1, Ordering::SeqCst); - read_handler(&root, name, args) + wire_handler(&root, name, args) }); let mgr = SessionManager::new(); self.runtime .block_on(mgr.enroll(self.provider.clone(), Arc::new(wire))) .map_err(|e| e.to_string())?; self.lane = mgr.speculative_lane(); + self.effect_lane = mgr.effect_lane(); Ok(()) } + /// Re-declare the `ToolEffects` of a stock capability (a fixture or a stricter enrollment) + /// and re-enroll. AIEN's authority then decides from the new bits; the adapter decides nothing. + pub fn with_effects(mut self, name: &str, effects: ToolEffects) -> Result { + if !SPECS.iter().any(|s| s.name == name) { + return Err(format!("unknown capability: {name}")); + } + self.overrides.insert(name.to_string(), effects); + self.descriptors = descriptors(&self.overrides); + if let Some(root) = self.workspace.clone() { + self.enroll(root)?; + } + Ok(self) + } + fn spec(&self, name: &str) -> Option<(&Spec, &ToolDescriptor)> { let s = SPECS.iter().find(|s| s.name == name)?; let d = self.descriptors.iter().find(|d| d.name() == name)?; @@ -217,6 +249,91 @@ impl AienAuthority { } } + /// Effect path: stage, then ask AIEN (`EffectLane::authorize` with `EffectClassAuthority`). + /// The adapter translates the answer and never builds the authorized value itself. + fn decide_effect(&mut self, req: &CapabilityRequest, effects: ToolEffects) -> Decision { + if let Some(path) = req.arguments.get("path").and_then(Value::as_str) { + if let Err(why) = self.confine(path) { + return self.decision( + req, + DecisionKind::Denied, + Some(&why), + "adapter.workspace_confinement", + ); + } + } + let args = Value::Object(req.arguments.clone()); + let staged = self.runtime.block_on(self.lane.stage_effect_intent( + &self.provider, + &req.capability, + args.clone(), + )); + let intent = match staged { + Ok(i) => i, + // Speculation-safe but not read-only (local ephemeral): still goes through AIEN's + // authority. An intent is plain data and carries no authority. + Err(McpError::SpeculationSafe) => EffectIntent { + provider: self.provider.clone(), + tool_name: req.capability.clone(), + arguments: args, + capability_digest: catalog_digest(&self.descriptors), + }, + Err(e) => { + let r = e.to_string(); + return self.decision(req, DecisionKind::Denied, Some(&r), ENGINE_EFFECT); + } + }; + let scope = EffectScope { + world_id: WorldId(1), + winning_jnode: JNodeId(1), + idempotency_key: EffectId::from_label(req.request_id.as_str()), + }; + let mut values = vec![format!("effect_class={:?}", routing_class(effects))]; + match self + .effect_lane + .authorize(intent, scope, &EffectClassAuthority) + { + Ok(effect) => { + self.authorized + .insert(req.request_id.as_str().to_string(), effect); + let mut d = self.decision(req, DecisionKind::Authorized, None, ENGINE_EFFECT); + d.runtime_state = Some(RuntimeExtension { + vocabulary: "aien.effects".into(), + values, + extensions: Map::new(), + }); + d + } + Err(AuthorityOutcome::Pending { + intent_digest, + reason, + }) => { + values.push("staged=true".into()); + values.push(format!("intent_digest={}", hex(&intent_digest))); + // AIEN has no approval record for this; none is invented or consumed here. + let mut d = self.decision( + req, + DecisionKind::RequiresApproval, + Some(&reason), + ENGINE_EFFECT, + ); + d.runtime_state = Some(RuntimeExtension { + vocabulary: "aien.effect_intent".into(), + values, + extensions: Map::new(), + }); + d + } + Err(AuthorityOutcome::Denied(r)) | Err(AuthorityOutcome::Contained(r)) => { + self.decision(req, DecisionKind::Denied, Some(&r), ENGINE_EFFECT) + } + Err(AuthorityOutcome::Execution(e)) => { + let r = e.to_string(); + self.decision(req, DecisionKind::Denied, Some(&r), ENGINE_EFFECT) + } + } + } + fn confine(&self, path: &str) -> Result<(), String> { let root = self.workspace.as_ref().ok_or(UNAVAILABLE)?; let p = Path::new(path); @@ -239,8 +356,46 @@ impl AienAuthority { } } -/// Reimplemented: the in-process provider body (AIEN ships `MemoryWire` but no filesystem tools -/// in aien-mcp). Runs only behind `SpeculativeLane::invoke_speculative`. +/// In-process provider body. Reads run behind `SpeculativeLane::invoke_speculative`; `write_file` +/// runs only behind `EffectLane::execute_effect`, i.e. only with an AIEN-minted `AuthorizedEffect`. +fn wire_handler(root: &Path, name: &str, args: &Value) -> CallOutcome { + if name == "write_file" { + return write_handler(root, args); + } + read_handler(root, name, args) +} + +fn write_handler(root: &Path, args: &Value) -> CallOutcome { + let (Some(path), Some(content)) = ( + args.get("path").and_then(Value::as_str), + args.get("content").and_then(Value::as_str), + ) else { + return CallOutcome::Rejected("missing required argument".into()); + }; + let p = Path::new(path); + let full = if p.is_absolute() { + p.to_path_buf() + } else { + root.join(p) + }; + if full.components().any(|c| c == Component::ParentDir) { + return CallOutcome::Rejected(format!("path is outside the workspace: {path}")); + } + let parent_ok = full + .parent() + .and_then(|d| fs::canonicalize(d).ok()) + .is_some_and(|d| d.starts_with(root)); + if !parent_ok { + return CallOutcome::Rejected(format!("path is outside the workspace: {path}")); + } + match fs::write(&full, content) { + Ok(()) => CallOutcome::Finished(json!({"path": path, "bytes": content.len()})), + Err(e) => CallOutcome::Rejected(format!("cannot write {path}: {e}")), + } +} + +/// Reimplemented: the read provider body (AIEN ships `MemoryWire` but no filesystem tools +/// in aien-mcp). fn read_handler(root: &Path, name: &str, args: &Value) -> CallOutcome { let Some(path) = args.get("path").and_then(Value::as_str) else { return CallOutcome::Rejected("missing required argument: path".into()); @@ -344,36 +499,9 @@ impl RuntimeAuthority for AienAuthority { "aegis.enforcement.pre_dispatch_check", ); } - if !speculation_safe(desc.effects()) { - let mut d = self.decision( - req, - DecisionKind::RequiresApproval, - Some(APPROVAL_REASON), - "aien-mcp.speculation_safe", - ); - let mut values = vec![format!("effect_class={:?}", routing_class(desc.effects()))]; - // AIEN records the intent without executing it. No approval id exists until AIEN gives one. - let staged = self.runtime.block_on(self.lane.stage_effect_intent( - &self.provider, - &req.capability, - Value::Object(req.arguments.clone()), - )); - match staged { - Ok(intent) => { - values.push("staged=true".into()); - values.push(format!( - "capability_digest={}", - hex(&intent.capability_digest) - )); - } - Err(e) => values.push(format!("staged=false: {e}")), - } - d.runtime_state = Some(RuntimeExtension { - vocabulary: "aien.effect_intent".into(), - values, - extensions: Map::new(), - }); - return d; + let class = routing_class(desc.effects()); + if !matches!(class, EffectClass::Pure | EffectClass::ReadOnly) { + return self.decide_effect(req, desc.effects()); } // Adapter restriction (can only deny): confine reads to the workspace root. if let Some(path) = req.arguments.get("path").and_then(Value::as_str) { @@ -420,7 +548,29 @@ impl RuntimeAuthority for AienAuthority { .spec(&req.capability) .map(|(_, d)| routing_class(d.effects()) == EffectClass::ReadOnly) .unwrap_or(false); - let mut r = if !decision.is_authorized() || !readable { + let effect = if decision.is_authorized() { + self.authorized.remove(rid) + } else { + None + }; + let mut r = if let Some(effect) = effect { + match self + .runtime + .block_on(self.effect_lane.execute_effect(effect)) + { + Ok(rc) => ToolResult::ok( + rid, + json!({"output": rc.output, "receipt": { + "effect_id": rc.effect_id.0.iter().map(|b| format!("{b:02x}")).collect::(), + "policy_digest": hex(&rc.policy_digest), + "tool_name": rc.tool_name}}), + ), + Err(e) => fail(&match e { + McpError::Rejected(why) => why, + other => other.to_string(), + }), + } + } else if !decision.is_authorized() || !readable { fail(NOT_EXECUTED) } else { let call = SpeculativeToolCall { @@ -432,7 +582,7 @@ impl RuntimeAuthority for AienAuthority { match self.runtime.block_on(self.lane.invoke_speculative(call)) { Ok(out) => ToolResult::ok(rid, out.output), Err(e) => fail(&match e { - aien_mcp::Error::Rejected(why) => why, + McpError::Rejected(why) => why, other => other.to_string(), }), } diff --git a/docs/adr/0003-aien-adapter-uses-existing-primitives.md b/docs/adr/0003-aien-adapter-uses-existing-primitives.md index f26ca62..0c49016 100644 --- a/docs/adr/0003-aien-adapter-uses-existing-primitives.md +++ b/docs/adr/0003-aien-adapter-uses-existing-primitives.md @@ -33,3 +33,15 @@ effect" are both satisfied by AIEN's current machinery; "approval flow to execut `requires_approval` until AIEN ships a production `AuthorizedEffect` mint (its own ADR 0016 R8 says only the AIENOS root does that). The adapter depends on `aien-sovereign-core` crates by git revision 7580039 and never the reverse. + +## Addendum 2026-10-04 (INTERPLANE 0.2): AIEN now owns a production mint; the adapter still mints nothing + +aien-sovereign-core PR #203 adds `aien_mcp::EffectLane::authorize(intent, scope, &dyn EffectAuthority)` +and `EffectClassAuthority` (AIEN, from `ToolEffects`). Items 2 and 3 above change as follows: effects are +no longer stopped at `stage_effect_intent`. The adapter stages, calls `EffectLane::authorize` with AIEN's +`EffectClassAuthority`, and translates the answer: Allow executes through `EffectLane` and returns the +receipt, RequireApproval is `requires_approval` with the intent digest, Deny and Contain are `denied` +with AIEN's reason. Item 4 holds: the adapter never constructs `AuthorizedEffect` (the mint is +crate-private in aien-mcp; a test greps the adapter source), and it adds no policy of its own beyond +the existing deny-only workspace confinement. Approval consumption is still unimplemented: a pending +intent cannot yet be approved and executed. From b34ed89cae2b35a13ee02c706fb5ced3f18c2444 Mon Sep 17 00:00:00 2001 From: Drake Stapleton Date: Sun, 4 Oct 2026 16:32:23 -0500 Subject: [PATCH 2/4] test(adapter-aien): authorized/denied/approval/stale/replay Co-Authored-By: Claude Sonnet 5.5 --- adapters/aien/tests/pipeline.rs | 125 +++++++++++++++++++++++++++++++- 1 file changed, 123 insertions(+), 2 deletions(-) diff --git a/adapters/aien/tests/pipeline.rs b/adapters/aien/tests/pipeline.rs index 624bf29..4b838a8 100644 --- a/adapters/aien/tests/pipeline.rs +++ b/adapters/aien/tests/pipeline.rs @@ -1,4 +1,5 @@ //! Every test drives the real interplane `Pipeline` with `AienAuthority`. +use aien_capability::ToolEffects; use interplane_adapter_aien::*; use interplane_core::*; use interplane_crossaxis::MappingTable; @@ -59,7 +60,7 @@ fn list_dir_ok_and_trusted_flag_is_honoured() { } #[test] -fn effectful_capability_requires_approval_and_never_executes() { +fn world_mutation_requires_approval_and_never_executes() { let ws = workspace(); let mut rt = AienAuthority::new(ws.path()).unwrap(); let table = rt.mapping_table(false); @@ -73,14 +74,134 @@ fn effectful_capability_requires_approval_and_never_executes() { assert_eq!(res.status, ResultStatus::RequiresApproval); assert!(rec.decide_invoked && !rec.execute_invoked); let d = res.decision.as_ref().unwrap(); - assert_eq!(d.reason.as_deref(), Some(APPROVAL_REASON)); + assert!( + d.reason.as_deref().unwrap().contains("needs approval"), + "{d:?}" + ); + assert_eq!(d.authority.policy_engine, ENGINE_EFFECT); + // No approval id exists, so none is invented and nothing is consumed. assert!(d.approval.is_none()); let rs = d.runtime_state.as_ref().unwrap(); assert!(rs.values.contains(&"staged=true".to_string()), "{rs:?}"); + assert!( + rs.values + .iter() + .any(|v| v.starts_with("intent_digest=sha256") || v.starts_with("intent_digest=")), + "{rs:?}" + ); + assert_eq!((rt.execute_calls, rt.wire_calls()), (0, 0)); + assert!(!ws.path().join("x.txt").exists()); +} + +#[test] +fn local_ephemeral_effect_is_authorized_by_aien_and_executes_with_receipt() { + let ws = workspace(); + let mut rt = AienAuthority::new(ws.path()) + .unwrap() + .with_effects("write_file", ToolEffects::LOCAL_EPHEMERAL) + .unwrap(); + let table = rt.mapping_table(true); + let out = run( + &mut rt, + table, + "write_file", + json!({"path": "scratch.txt", "content": "ephemeral"}), + ); + let (rec, res) = (&out.records[0], &out.results[0]); + assert_eq!(res.status, ResultStatus::Ok, "{res:?}"); + assert!(rec.decide_invoked && rec.execute_invoked); + assert_eq!(res.data["output"]["bytes"], 9); + assert_eq!(res.data["receipt"]["tool_name"], "write_file"); + assert!(res.data["receipt"]["effect_id"].as_str().unwrap().len() == 32); + assert_eq!(rec.decision.as_deref(), Some("authorized")); + let f = ws.path().join("scratch.txt"); + assert_eq!(std::fs::read_to_string(&f).unwrap(), "ephemeral"); + assert_eq!(rt.wire_calls(), 1); + std::fs::remove_file(f).unwrap(); +} + +#[test] +fn irreversible_effect_is_denied_with_aiens_reason_and_never_executes() { + let ws = workspace(); + let mut rt = AienAuthority::new(ws.path()) + .unwrap() + .with_effects("write_file", ToolEffects::EXTERNAL_IRREVERSIBLE) + .unwrap(); + let table = rt.mapping_table(false); + let out = run( + &mut rt, + table, + "write_file", + json!({"path": "x.txt", "content": "y"}), + ); + let (rec, res) = (&out.records[0], &out.results[0]); + assert_eq!(res.status, ResultStatus::Denied, "{res:?}"); + assert!(res + .error + .as_ref() + .unwrap() + .message + .contains("irreversible external effects are intents only")); + assert!(!rec.execute_invoked); assert_eq!((rt.execute_calls, rt.wire_calls()), (0, 0)); assert!(!ws.path().join("x.txt").exists()); } +#[test] +fn effect_replay_does_not_execute_twice() { + let ws = workspace(); + let mut rt = AienAuthority::new(ws.path()) + .unwrap() + .with_effects("write_file", ToolEffects::LOCAL_EPHEMERAL) + .unwrap(); + let table = rt.mapping_table(false); + let mut p = Pipeline::new( + DialectRegistry::with_defaults(), + table, + &mut rt, + Limits::default(), + RequestLedger::new(), + ); + let call = json!({"id": "c1", "type": "function", "function": {"name": "write_file", + "arguments": json!({"path": "r.txt", "content": "once"}).to_string()}}); + let turn = json!({"role": "assistant", "content": null, "tool_calls": [call]}); + let first = p.run_turn("openai", "m", &turn, "t", 0); + let second = p.run_turn("openai", "m", &turn, "t", 0); + assert_eq!(first.results[0].status, ResultStatus::Ok); + assert_ne!( + second.results[0].status, + ResultStatus::Ok, + "{:?}", + second.results[0] + ); + assert!(!second.records[0].execute_invoked); + drop(p); + assert_eq!(rt.wire_calls(), 1); +} + +#[test] +fn adapter_source_never_constructs_authorized_effect() { + let src = std::fs::read_to_string(concat!(env!("CARGO_MANIFEST_DIR"), "/src/lib.rs")).unwrap(); + let code: String = src + .lines() + .filter(|l| !l.trim_start().starts_with("//")) + .collect::>() + .join("\n"); + for forbidden in [ + "AuthorizedEffect {", + "AuthorizedEffect{", + "authorize_for_test", + "mint(", + "impl EffectAuthority", + "AuthorityDecision::Allow", + ] { + assert!( + !code.contains(forbidden), + "adapter must not contain `{forbidden}`" + ); + } +} + #[test] fn nonexistent_capability_is_not_found() { let ws = workspace(); From c022a2b8e283429c0adb24d4b1eb4ca3f4135f17 Mon Sep 17 00:00:00 2001 From: Drake Stapleton Date: Sun, 4 Oct 2026 16:45:59 -0500 Subject: [PATCH 3/4] chore(adapter-aien): pin aien-sovereign-core to merged main 2a968bf Co-Authored-By: Claude Fable 5.1 --- adapters/aien/Cargo.lock | 12 ++++++------ adapters/aien/Cargo.toml | 4 ++-- adapters/aien/README.md | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/adapters/aien/Cargo.lock b/adapters/aien/Cargo.lock index 93132db..65a1f56 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=bdcb2d4fb631df7777b2ce9fbda41088a2abcd7e#bdcb2d4fb631df7777b2ce9fbda41088a2abcd7e" +source = "git+https://github.com/aien-dev/aien-sovereign-core.git?rev=2a968bfc2770c012b4d53cfb1669f97594d2ff31#2a968bfc2770c012b4d53cfb1669f97594d2ff31" 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=bdcb2d4fb631df7777b2ce9fbda41088a2abcd7e#bdcb2d4fb631df7777b2ce9fbda41088a2abcd7e" +source = "git+https://github.com/aien-dev/aien-sovereign-core.git?rev=2a968bfc2770c012b4d53cfb1669f97594d2ff31#2a968bfc2770c012b4d53cfb1669f97594d2ff31" dependencies = [ "aien-capability", "async-trait", @@ -761,7 +761,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" dependencies = [ "libc", - "windows-sys 0.61.2", + "windows-sys 0.52.0", ] [[package]] @@ -1671,7 +1671,7 @@ dependencies = [ "once_cell", "socket2", "tracing", - "windows-sys 0.61.2", + "windows-sys 0.52.0", ] [[package]] @@ -1941,7 +1941,7 @@ dependencies = [ "errno", "libc", "linux-raw-sys", - "windows-sys 0.61.2", + "windows-sys 0.52.0", ] [[package]] @@ -2300,7 +2300,7 @@ dependencies = [ "getrandom 0.4.3", "once_cell", "rustix", - "windows-sys 0.61.2", + "windows-sys 0.52.0", ] [[package]] diff --git a/adapters/aien/Cargo.toml b/adapters/aien/Cargo.toml index 816e73f..98d1864 100644 --- a/adapters/aien/Cargo.toml +++ b/adapters/aien/Cargo.toml @@ -22,8 +22,8 @@ serde_json = "1" sha2 = "0.10" tokio = { version = "1", features = ["rt"] } # Pinned AIEN sources: aien-dev/aien-sovereign-core PR #203 branch head (TEMPORARY; re-pin to the merge commit). -aien-capability = { git = "https://github.com/aien-dev/aien-sovereign-core.git", rev = "bdcb2d4fb631df7777b2ce9fbda41088a2abcd7e" } -aien-mcp = { git = "https://github.com/aien-dev/aien-sovereign-core.git", rev = "bdcb2d4fb631df7777b2ce9fbda41088a2abcd7e" } +aien-capability = { git = "https://github.com/aien-dev/aien-sovereign-core.git", rev = "2a968bfc2770c012b4d53cfb1669f97594d2ff31" } +aien-mcp = { git = "https://github.com/aien-dev/aien-sovereign-core.git", rev = "2a968bfc2770c012b4d53cfb1669f97594d2ff31" } # 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/README.md b/adapters/aien/README.md index bb29314..b8b5ddf 100644 --- a/adapters/aien/README.md +++ b/adapters/aien/README.md @@ -14,7 +14,7 @@ hand out) and nothing is consumed. Nothing under `rust/`, `spec/`, `python/` or ## Pinned AIEN sources `aien-capability` and `aien-mcp` are git dependencies pinned to -`aien-dev/aien-sovereign-core@bdcb2d4fb631df7777b2ce9fbda41088a2abcd7e` (head of PR #203, +`aien-dev/aien-sovereign-core@2a968bfc2770c012b4d53cfb1669f97594d2ff31` (main after PR #203 merged, `0.2/aien-mcp-authority`, which adds the production authority seam; TEMPORARY, re-pin to the merge commit once #203 lands). `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 From 9b78e696ddcaefae8f6c587e9f4a4b8201ee1c20 Mon Sep 17 00:00:00 2001 From: Drake Stapleton Date: Sun, 4 Oct 2026 16:46:10 -0500 Subject: [PATCH 4/4] docs(adapter-aien): pin wording after #203 merge Co-Authored-By: Claude Fable 5.1 --- adapters/aien/README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/adapters/aien/README.md b/adapters/aien/README.md index b8b5ddf..0d43d47 100644 --- a/adapters/aien/README.md +++ b/adapters/aien/README.md @@ -15,8 +15,7 @@ hand out) and nothing is consumed. Nothing under `rust/`, `spec/`, `python/` or `aien-capability` and `aien-mcp` are git dependencies pinned to `aien-dev/aien-sovereign-core@2a968bfc2770c012b4d53cfb1669f97594d2ff31` (main after PR #203 merged, -`0.2/aien-mcp-authority`, which adds the production authority seam; TEMPORARY, re-pin to the merge -commit once #203 lands). `aegis` (feature `aegis-gate`, on by default) cannot be a git dependency because +which adds the production 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 (`../aien-protocols/crates/*`). The build therefore expects this layout next to the INTERPLANE checkout: