Add Body repo access contracts

This commit is contained in:
Meta Vens 2026-05-24 12:59:14 +01:00
commit ca2575aff3
10 changed files with 415 additions and 0 deletions

View file

@ -4,6 +4,7 @@ use epiphany_core::EPIPHANY_CULTMESH_INTERNAL_VERSE_ID;
use epiphany_core::EPIPHANY_CULTMESH_STATUS_SCHEMA_VERSION;
use epiphany_core::EpiphanyCultMeshStatusEntry;
use epiphany_core::load_epiphany_cultmesh_status;
use epiphany_core::write_epiphany_cultmesh_body_contracts;
use epiphany_core::write_epiphany_cultmesh_global_room_policies;
use epiphany_core::write_epiphany_cultmesh_mind_contracts;
use epiphany_core::write_epiphany_cultmesh_status;
@ -29,6 +30,7 @@ fn main() -> Result<()> {
write_epiphany_cultmesh_verse_policies(&store, "epiphany-cultmesh-smoke")?;
write_epiphany_cultmesh_global_room_policies(&store, "epiphany-cultmesh-smoke")?;
write_epiphany_cultmesh_mind_contracts(&store, "epiphany-cultmesh-smoke")?;
write_epiphany_cultmesh_body_contracts(&store, "epiphany-cultmesh-smoke")?;
let loaded = load_epiphany_cultmesh_status(&store, "epiphany-cultmesh-smoke")?;
if loaded != Some(status) {
anyhow::bail!("CultMesh smoke failed to round-trip Epiphany status document");

View file

@ -0,0 +1,127 @@
use serde::Deserialize;
use serde::Serialize;
pub const BODY_REPO_ACCESS_REQUEST_TYPE: &str = "epiphany.body.repo_access_request";
pub const BODY_REPO_ACCESS_REVIEW_TYPE: &str = "epiphany.body.repo_access_review";
pub const BODY_REPO_ACCESS_GRANT_RECEIPT_TYPE: &str = "epiphany.body.repo_access_grant_receipt";
pub const BODY_REPO_ACCESS_REFUSAL_RECEIPT_TYPE: &str = "epiphany.body.repo_access_refusal_receipt";
pub const BODY_REPO_SNAPSHOT_RECEIPT_TYPE: &str = "epiphany.body.repo_snapshot_receipt";
pub const BODY_REPO_MUTATION_RECEIPT_TYPE: &str = "epiphany.body.repo_mutation_receipt";
pub const BODY_REPO_ACCESS_REQUEST_SCHEMA_VERSION: &str = "epiphany.body.repo_access_request.v0";
pub const BODY_REPO_ACCESS_REVIEW_SCHEMA_VERSION: &str = "epiphany.body.repo_access_review.v0";
pub const BODY_REPO_ACCESS_GRANT_RECEIPT_SCHEMA_VERSION: &str =
"epiphany.body.repo_access_grant_receipt.v0";
pub const BODY_REPO_ACCESS_REFUSAL_RECEIPT_SCHEMA_VERSION: &str =
"epiphany.body.repo_access_refusal_receipt.v0";
pub const BODY_REPO_SNAPSHOT_RECEIPT_SCHEMA_VERSION: &str =
"epiphany.body.repo_snapshot_receipt.v0";
pub const BODY_REPO_MUTATION_RECEIPT_SCHEMA_VERSION: &str =
"epiphany.body.repo_mutation_receipt.v0";
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct BodyCultNetContract {
pub contract_id: String,
pub verse_id: String,
pub document_type: String,
pub payload_schema_version: String,
pub authority: String,
pub operations: Vec<String>,
pub intent_document_types: Vec<String>,
pub receipt_document_types: Vec<String>,
pub notes: Vec<String>,
}
pub fn default_body_cultnet_contracts() -> Vec<BodyCultNetContract> {
vec![
BodyCultNetContract {
contract_id: "epiphany.body.repo_access.review".to_string(),
verse_id: "epiphany-internal".to_string(),
document_type: BODY_REPO_ACCESS_REQUEST_TYPE.to_string(),
payload_schema_version: BODY_REPO_ACCESS_REQUEST_SCHEMA_VERSION.to_string(),
authority: "body".to_string(),
operations: vec![
"intentSubmit".to_string(),
"receiptWatch".to_string(),
"snapshot".to_string(),
],
intent_document_types: vec![BODY_REPO_ACCESS_REQUEST_TYPE.to_string()],
receipt_document_types: vec![
BODY_REPO_ACCESS_REVIEW_TYPE.to_string(),
BODY_REPO_ACCESS_GRANT_RECEIPT_TYPE.to_string(),
BODY_REPO_ACCESS_REFUSAL_RECEIPT_TYPE.to_string(),
],
notes: vec![
"Body is the repo access guardian: workers request repository reads, indexing, commands, edits, and bridge operations here.".to_string(),
"Hands may mutate files only after Body grants scoped access; Eyes may inspect only through scoped Body read/index grants.".to_string(),
],
},
BodyCultNetContract {
contract_id: "epiphany.body.repo_access.review_receipts".to_string(),
verse_id: "epiphany-internal".to_string(),
document_type: BODY_REPO_ACCESS_REVIEW_TYPE.to_string(),
payload_schema_version: BODY_REPO_ACCESS_REVIEW_SCHEMA_VERSION.to_string(),
authority: "readOnly".to_string(),
operations: vec!["snapshot".to_string(), "receiptWatch".to_string()],
intent_document_types: Vec::new(),
receipt_document_types: Vec::new(),
notes: vec![
"Body reviews explain which repo paths, operations, commands, and bridge surfaces were granted or refused.".to_string(),
],
},
BodyCultNetContract {
contract_id: "epiphany.body.repo_snapshot.receipts".to_string(),
verse_id: "epiphany-internal".to_string(),
document_type: BODY_REPO_SNAPSHOT_RECEIPT_TYPE.to_string(),
payload_schema_version: BODY_REPO_SNAPSHOT_RECEIPT_SCHEMA_VERSION.to_string(),
authority: "readOnly".to_string(),
operations: vec!["snapshot".to_string(), "receiptWatch".to_string()],
intent_document_types: Vec::new(),
receipt_document_types: Vec::new(),
notes: vec![
"Repo snapshots are evidence projections from Body access; they do not grant future access by existing.".to_string(),
],
},
BodyCultNetContract {
contract_id: "epiphany.body.repo_mutation.receipts".to_string(),
verse_id: "epiphany-internal".to_string(),
document_type: BODY_REPO_MUTATION_RECEIPT_TYPE.to_string(),
payload_schema_version: BODY_REPO_MUTATION_RECEIPT_SCHEMA_VERSION.to_string(),
authority: "readOnly".to_string(),
operations: vec!["snapshot".to_string(), "receiptWatch".to_string()],
intent_document_types: Vec::new(),
receipt_document_types: Vec::new(),
notes: vec![
"Repo mutation receipts prove Body granted the scoped substrate touch before Hands changed files or ran repo-affecting commands.".to_string(),
],
},
]
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn body_contracts_make_internal_verse_the_repo_access_gate() {
let contracts = default_body_cultnet_contracts();
let repo_access = contracts
.iter()
.find(|contract| contract.contract_id == "epiphany.body.repo_access.review")
.expect("repo access review contract");
assert_eq!(repo_access.verse_id, "epiphany-internal");
assert_eq!(repo_access.authority, "body");
assert!(
repo_access
.notes
.iter()
.any(|note| note.contains("repo access guardian"))
);
assert!(
repo_access
.receipt_document_types
.contains(&BODY_REPO_ACCESS_GRANT_RECEIPT_TYPE.to_string())
);
}
}

View file

@ -1,3 +1,4 @@
use crate::default_body_cultnet_contracts;
use crate::default_mind_cultnet_contracts;
use anyhow::Result;
use cultcache_rs::DatabaseEntry;
@ -18,6 +19,9 @@ pub const EPIPHANY_CULTMESH_GLOBAL_ROOM_POLICY_SCHEMA_VERSION: &str =
pub const EPIPHANY_CULTMESH_MIND_CONTRACT_TYPE: &str = "epiphany.cultmesh.mind_contract";
pub const EPIPHANY_CULTMESH_MIND_CONTRACT_SCHEMA_VERSION: &str =
"epiphany.cultmesh.mind_contract.v0";
pub const EPIPHANY_CULTMESH_BODY_CONTRACT_TYPE: &str = "epiphany.cultmesh.body_contract";
pub const EPIPHANY_CULTMESH_BODY_CONTRACT_SCHEMA_VERSION: &str =
"epiphany.cultmesh.body_contract.v0";
pub const EPIPHANY_CULTMESH_INTERNAL_VERSE_ID: &str = "epiphany-internal";
pub const EPIPHANY_CULTMESH_LOCAL_AREA_VERSE_ID: &str = "gamecult-local";
pub const EPIPHANY_CULTMESH_GLOBAL_VERSE_ID: &str = "epiphany-global";
@ -125,11 +129,40 @@ pub struct EpiphanyCultMeshMindContractEntry {
pub notes: Vec<String>,
}
#[derive(Clone, Debug, PartialEq, Eq, DatabaseEntry)]
#[cultcache(
type = "epiphany.cultmesh.body_contract",
schema = "EpiphanyCultMeshBodyContractEntry"
)]
pub struct EpiphanyCultMeshBodyContractEntry {
#[cultcache(key = 0)]
pub schema_version: String,
#[cultcache(key = 1)]
pub contract_id: String,
#[cultcache(key = 2)]
pub verse_id: String,
#[cultcache(key = 3)]
pub document_type: String,
#[cultcache(key = 4)]
pub payload_schema_version: String,
#[cultcache(key = 5)]
pub authority: String,
#[cultcache(key = 6)]
pub operations: Vec<String>,
#[cultcache(key = 7)]
pub intent_document_types: Vec<String>,
#[cultcache(key = 8)]
pub receipt_document_types: Vec<String>,
#[cultcache(key = 9)]
pub notes: Vec<String>,
}
cultmesh_documents!(EpiphanyCultMeshDocuments {
EpiphanyCultMeshStatusEntry => EPIPHANY_CULTMESH_STATUS_SCHEMA_VERSION,
EpiphanyCultMeshVersePolicyEntry => EPIPHANY_CULTMESH_VERSE_POLICY_SCHEMA_VERSION,
EpiphanyCultMeshGlobalRoomPolicyEntry => EPIPHANY_CULTMESH_GLOBAL_ROOM_POLICY_SCHEMA_VERSION,
EpiphanyCultMeshMindContractEntry => EPIPHANY_CULTMESH_MIND_CONTRACT_SCHEMA_VERSION,
EpiphanyCultMeshBodyContractEntry => EPIPHANY_CULTMESH_BODY_CONTRACT_SCHEMA_VERSION,
});
pub fn open_epiphany_cultmesh_node(
@ -309,6 +342,37 @@ pub fn write_epiphany_cultmesh_mind_contracts(
Ok(written)
}
pub fn epiphany_cultmesh_body_contracts() -> Vec<EpiphanyCultMeshBodyContractEntry> {
default_body_cultnet_contracts()
.into_iter()
.map(|contract| EpiphanyCultMeshBodyContractEntry {
schema_version: EPIPHANY_CULTMESH_BODY_CONTRACT_SCHEMA_VERSION.to_string(),
contract_id: contract.contract_id,
verse_id: contract.verse_id,
document_type: contract.document_type,
payload_schema_version: contract.payload_schema_version,
authority: contract.authority,
operations: contract.operations,
intent_document_types: contract.intent_document_types,
receipt_document_types: contract.receipt_document_types,
notes: contract.notes,
})
.collect()
}
pub fn write_epiphany_cultmesh_body_contracts(
store_path: impl AsRef<Path>,
runtime_id: impl Into<String>,
) -> Result<Vec<EpiphanyCultMeshBodyContractEntry>> {
let mut node = open_epiphany_cultmesh_node(store_path, runtime_id)?;
let mut written = Vec::new();
for contract in epiphany_cultmesh_body_contracts() {
written.push(node.put(contract.contract_id.clone(), &contract)?);
}
node.flush()?;
Ok(written)
}
#[cfg(test)]
mod tests {
use super::*;
@ -415,4 +479,27 @@ mod tests {
);
Ok(())
}
#[test]
fn body_contracts_use_verses_to_keep_repo_access_guarded() -> Result<()> {
let temp = tempfile::tempdir()?;
let store = temp.path().join("epiphany-body-contracts.ccmp");
let written = write_epiphany_cultmesh_body_contracts(&store, "epiphany-test")?;
assert!(written.len() >= 4);
let node = open_epiphany_cultmesh_node(&store, "epiphany-test")?;
let repo_access = node.get_required::<EpiphanyCultMeshBodyContractEntry>(
"epiphany.body.repo_access.review",
)?;
assert_eq!(repo_access.verse_id, EPIPHANY_CULTMESH_INTERNAL_VERSE_ID);
assert_eq!(repo_access.authority, "body");
assert!(
repo_access
.notes
.iter()
.any(|note| note.contains("repo access guardian"))
);
Ok(())
}
}

View file

@ -1,5 +1,6 @@
mod agent_memory;
mod agent_utterance_state;
mod body_gateway;
mod cultmesh_integration;
mod distillation;
mod face_turn;
@ -53,12 +54,28 @@ pub use agent_utterance_state::AgentUtteranceState;
pub use agent_utterance_state::AgentUtteranceValue;
pub use agent_utterance_state::WEKSA_UTTERANCE_HANDOFF_SCHEMA_VERSION;
pub use agent_utterance_state::derive_agent_utterance_state;
pub use body_gateway::BODY_REPO_ACCESS_GRANT_RECEIPT_SCHEMA_VERSION;
pub use body_gateway::BODY_REPO_ACCESS_GRANT_RECEIPT_TYPE;
pub use body_gateway::BODY_REPO_ACCESS_REFUSAL_RECEIPT_SCHEMA_VERSION;
pub use body_gateway::BODY_REPO_ACCESS_REFUSAL_RECEIPT_TYPE;
pub use body_gateway::BODY_REPO_ACCESS_REQUEST_SCHEMA_VERSION;
pub use body_gateway::BODY_REPO_ACCESS_REQUEST_TYPE;
pub use body_gateway::BODY_REPO_ACCESS_REVIEW_SCHEMA_VERSION;
pub use body_gateway::BODY_REPO_ACCESS_REVIEW_TYPE;
pub use body_gateway::BODY_REPO_MUTATION_RECEIPT_SCHEMA_VERSION;
pub use body_gateway::BODY_REPO_MUTATION_RECEIPT_TYPE;
pub use body_gateway::BODY_REPO_SNAPSHOT_RECEIPT_SCHEMA_VERSION;
pub use body_gateway::BODY_REPO_SNAPSHOT_RECEIPT_TYPE;
pub use body_gateway::BodyCultNetContract;
pub use body_gateway::default_body_cultnet_contracts;
pub use cultcache_rs::CacheBackingStore;
pub use cultcache_rs::CultCache;
pub use cultcache_rs::CultCacheEnvelope;
pub use cultcache_rs::DatabaseEntry;
pub use cultcache_rs::PushAllOptions;
pub use cultcache_rs::SingleFileMessagePackBackingStore;
pub use cultmesh_integration::EPIPHANY_CULTMESH_BODY_CONTRACT_SCHEMA_VERSION;
pub use cultmesh_integration::EPIPHANY_CULTMESH_BODY_CONTRACT_TYPE;
pub use cultmesh_integration::EPIPHANY_CULTMESH_GLOBAL_ROOM_POLICY_SCHEMA_VERSION;
pub use cultmesh_integration::EPIPHANY_CULTMESH_GLOBAL_ROOM_POLICY_TYPE;
pub use cultmesh_integration::EPIPHANY_CULTMESH_GLOBAL_TIER;
@ -74,16 +91,19 @@ pub use cultmesh_integration::EPIPHANY_CULTMESH_STATUS_SCHEMA_VERSION;
pub use cultmesh_integration::EPIPHANY_CULTMESH_STATUS_TYPE;
pub use cultmesh_integration::EPIPHANY_CULTMESH_VERSE_POLICY_SCHEMA_VERSION;
pub use cultmesh_integration::EPIPHANY_CULTMESH_VERSE_POLICY_TYPE;
pub use cultmesh_integration::EpiphanyCultMeshBodyContractEntry;
pub use cultmesh_integration::EpiphanyCultMeshDocuments;
pub use cultmesh_integration::EpiphanyCultMeshGlobalRoomPolicyEntry;
pub use cultmesh_integration::EpiphanyCultMeshMindContractEntry;
pub use cultmesh_integration::EpiphanyCultMeshStatusEntry;
pub use cultmesh_integration::EpiphanyCultMeshVersePolicyEntry;
pub use cultmesh_integration::epiphany_cultmesh_body_contracts;
pub use cultmesh_integration::epiphany_cultmesh_global_room_policies;
pub use cultmesh_integration::epiphany_cultmesh_mind_contracts;
pub use cultmesh_integration::epiphany_cultmesh_verse_policies;
pub use cultmesh_integration::load_epiphany_cultmesh_status;
pub use cultmesh_integration::open_epiphany_cultmesh_node;
pub use cultmesh_integration::write_epiphany_cultmesh_body_contracts;
pub use cultmesh_integration::write_epiphany_cultmesh_global_room_policies;
pub use cultmesh_integration::write_epiphany_cultmesh_mind_contracts;
pub use cultmesh_integration::write_epiphany_cultmesh_status;

View file

@ -1,5 +1,17 @@
use crate::EpiphanyWorkerLaunchDocument;
use crate::agent_memory::AGENT_MEMORY_TYPE;
use crate::body_gateway::BODY_REPO_ACCESS_GRANT_RECEIPT_SCHEMA_VERSION;
use crate::body_gateway::BODY_REPO_ACCESS_GRANT_RECEIPT_TYPE;
use crate::body_gateway::BODY_REPO_ACCESS_REFUSAL_RECEIPT_SCHEMA_VERSION;
use crate::body_gateway::BODY_REPO_ACCESS_REFUSAL_RECEIPT_TYPE;
use crate::body_gateway::BODY_REPO_ACCESS_REQUEST_SCHEMA_VERSION;
use crate::body_gateway::BODY_REPO_ACCESS_REQUEST_TYPE;
use crate::body_gateway::BODY_REPO_ACCESS_REVIEW_SCHEMA_VERSION;
use crate::body_gateway::BODY_REPO_ACCESS_REVIEW_TYPE;
use crate::body_gateway::BODY_REPO_MUTATION_RECEIPT_SCHEMA_VERSION;
use crate::body_gateway::BODY_REPO_MUTATION_RECEIPT_TYPE;
use crate::body_gateway::BODY_REPO_SNAPSHOT_RECEIPT_SCHEMA_VERSION;
use crate::body_gateway::BODY_REPO_SNAPSHOT_RECEIPT_TYPE;
use crate::heartbeat_state::HEARTBEAT_STATE_SCHEMA_VERSION;
use crate::heartbeat_state::HEARTBEAT_STATE_TYPE;
use crate::memory_graph::MEMORY_GRAPH_SCHEMA_VERSION;
@ -1529,6 +1541,90 @@ fn epiphany_mutation_contracts() -> Vec<CultNetDocumentMutationContract> {
"The global Verse never receives private state authority by being interesting.",
],
),
mutation_contract(
BODY_REPO_ACCESS_REQUEST_TYPE,
BODY_REPO_ACCESS_REQUEST_SCHEMA_VERSION,
vec![
CultNetDocumentOperation::Snapshot,
CultNetDocumentOperation::IntentSubmit,
CultNetDocumentOperation::ReceiptWatch,
],
CultNetMutationAuthority::Coordinator,
vec![BODY_REPO_ACCESS_REQUEST_TYPE],
vec![
BODY_REPO_ACCESS_REVIEW_TYPE,
BODY_REPO_ACCESS_GRANT_RECEIPT_TYPE,
BODY_REPO_ACCESS_REFUSAL_RECEIPT_TYPE,
],
vec![
"Body is the repository access guardian: reads, indexing, edits, commands, and bridge operations must be requested through this contract.",
"Hands mutates only after a scoped Body grant; Eyes inspects only after a scoped Body read/index grant.",
],
),
mutation_contract(
BODY_REPO_ACCESS_REVIEW_TYPE,
BODY_REPO_ACCESS_REVIEW_SCHEMA_VERSION,
vec![
CultNetDocumentOperation::Snapshot,
CultNetDocumentOperation::ReceiptWatch,
],
CultNetMutationAuthority::ReadOnly,
vec![],
vec![],
vec![
"Body reviews explain granted/refused repo paths, operations, commands, and bridge surfaces.",
],
),
mutation_contract(
BODY_REPO_ACCESS_GRANT_RECEIPT_TYPE,
BODY_REPO_ACCESS_GRANT_RECEIPT_SCHEMA_VERSION,
vec![
CultNetDocumentOperation::Snapshot,
CultNetDocumentOperation::ReceiptWatch,
],
CultNetMutationAuthority::ReadOnly,
vec![],
vec![],
vec!["A Body grant receipt scopes a permitted repo touch."],
),
mutation_contract(
BODY_REPO_ACCESS_REFUSAL_RECEIPT_TYPE,
BODY_REPO_ACCESS_REFUSAL_RECEIPT_SCHEMA_VERSION,
vec![
CultNetDocumentOperation::Snapshot,
CultNetDocumentOperation::ReceiptWatch,
],
CultNetMutationAuthority::ReadOnly,
vec![],
vec![],
vec!["A Body refusal receipt preserves why repo access was denied."],
),
mutation_contract(
BODY_REPO_SNAPSHOT_RECEIPT_TYPE,
BODY_REPO_SNAPSHOT_RECEIPT_SCHEMA_VERSION,
vec![
CultNetDocumentOperation::Snapshot,
CultNetDocumentOperation::ReceiptWatch,
],
CultNetMutationAuthority::ReadOnly,
vec![],
vec![],
vec!["Repo snapshots are evidence projections from Body-gated access."],
),
mutation_contract(
BODY_REPO_MUTATION_RECEIPT_TYPE,
BODY_REPO_MUTATION_RECEIPT_SCHEMA_VERSION,
vec![
CultNetDocumentOperation::Snapshot,
CultNetDocumentOperation::ReceiptWatch,
],
CultNetMutationAuthority::ReadOnly,
vec![],
vec![],
vec![
"Repo mutation receipts prove Body granted the substrate touch before Hands changed files or ran repo-affecting commands.",
],
),
mutation_contract(
RUNTIME_EVENT_TYPE,
RUNTIME_SPINE_SCHEMA_VERSION,
@ -2294,6 +2390,27 @@ mod tests {
.iter()
.any(|note| note.contains("persistent state guardian"))
}));
let body_repo_contract = contracts
.iter()
.find(|contract| contract.document_type == BODY_REPO_ACCESS_REQUEST_TYPE)
.expect("Body repo access should advertise a mutation contract");
assert_eq!(
body_repo_contract.authority,
CultNetMutationAuthority::Coordinator
);
assert!(
body_repo_contract
.receipt_document_types
.as_ref()
.is_some_and(|items| items
.iter()
.any(|item| item == BODY_REPO_ACCESS_GRANT_RECEIPT_TYPE))
);
assert!(body_repo_contract.notes.as_ref().is_some_and(|notes| {
notes
.iter()
.any(|note| note.contains("repository access guardian"))
}));
let coordinator_contract = contracts
.iter()
.find(|contract| contract.document_type == SURFACE_COORDINATOR_TYPE)