pub fn narrow(state: &CooperationState, query: &Query) -> CooperationStateExpand description
The state narrowed to query. The digest is the whole fold’s, carried unchanged: it is
what two runtimes compare, and a page of the state is not a state of its own.
use std::sync::Arc;
use majordomus_cli::mesh::identity::NodeIdentity;
use majordomus_cli::mesh::journal::{ClaimMode, EventBody, Journal, SessionInfo, StreamLiveness};
use majordomus_cli::mesh::state::fold;
let j = Journal::open(Arc::new(NodeIdentity::ephemeral().unwrap()), "0000000000000001",
"repo".into(), None).unwrap();
j.append_own(EventBody::SessionOpened { info: SessionInfo::named("s1", "claude-code") })
.unwrap();
for (claim, path) in [("c1", "apps/a"), ("c2", "apps/b")] {
j.append_own(EventBody::ClaimAcquired { claim: claim.into(), session: "s1".into(),
scope: vec![path.into()], intent: Some("work".into()), mode: ClaimMode::Exclusive,
issue: Some("#1".into()) }).unwrap();
}
j.append_own(EventBody::ClaimReleased { claim: "c1".into() }).unwrap();
let state = fold(&j.events(), &|_| StreamLiveness::Own);
use majordomus_cli::mesh::page::{narrow, ClaimFilter, Query};
let live = narrow(&state, &Query { claims: Some(ClaimFilter::Live), ..Query::default() });
assert_eq!(live.claims.len(), 1, "the released claim is left out");
assert_eq!(live.digest, state.digest, "the whole fold's digest");