Bind Hands consequences to resolved grants

This commit is contained in:
Meta Vens 2026-07-12 23:47:07 +01:00
commit 1905b48971
6 changed files with 217 additions and 3 deletions

View file

@ -853,6 +853,15 @@ mod tests {
requested_at: "2026-06-12T00:00:01Z".to_string(),
contract: "Test Hands intent.".to_string(),
};
crate::put_substrate_gate_repo_access_grant_receipt(
&runtime_store,
&crate::substrate_gate_coordinator_implementation_grant(
"substrate-grant-context".to_string(),
"hands-job-context".to_string(),
vec![".".to_string()],
"2026-06-12T00:00:00Z".to_string(),
),
)?;
put_hands_action_intent(&runtime_store, &intent)?;
let review = hands_action_review_for_intent(
"hands-review-context".to_string(),

View file

@ -1398,6 +1398,14 @@ pub fn put_substrate_gate_repo_access_grant_receipt(
let mut cache = runtime_spine_cache(store_path)?;
cache.pull_all_backing_stores()?;
require_identity(&cache)?;
if let Some(existing) = cache.get::<SubstrateGateRepoAccessGrantReceipt>(&receipt.receipt_id)? {
if existing != *receipt {
return Err(anyhow!(
"Substrate Gate grant id already belongs to different immutable authority"
));
}
return Ok(());
}
cache.put(&receipt.receipt_id, receipt)?;
Ok(())
}
@ -1433,6 +1441,31 @@ pub fn put_hands_action_intent(
let mut cache = runtime_spine_cache(store_path)?;
cache.pull_all_backing_stores()?;
require_identity(&cache)?;
let grant = cache
.get::<SubstrateGateRepoAccessGrantReceipt>(&intent.substrate_gate_grant_receipt_id)?
.ok_or_else(|| {
anyhow!("Hands action intent requires its persisted Substrate Gate grant")
})?;
if grant.runtime_job_id != intent.runtime_job_id
|| grant.binding_id != intent.binding_id
|| grant.role != intent.role
|| grant.authority_scope != intent.authority_scope
|| !grant
.granted_operations
.iter()
.any(|operation| operation == "read")
|| !intent.requested_paths.iter().all(|path| {
grant.granted_paths.iter().any(|granted| {
granted == "."
|| path == granted
|| path.starts_with(&format!("{}/", granted.trim_end_matches(['/', '\\'])))
})
})
{
return Err(anyhow!(
"Hands action intent does not match its Substrate Gate grant scope"
));
}
cache.put(&intent.intent_id, intent)?;
Ok(())
}
@ -1475,6 +1508,59 @@ pub fn runtime_hands_action_review(
cache.get::<HandsActionReview>(review_id)
}
fn validate_hands_consequence_grant(
store_path: &Path,
intent_id: &str,
review_id: &str,
runtime_job_id: &str,
operation: &str,
changed_paths: &[String],
stated_grant_id: Option<&str>,
) -> Result<()> {
let mut cache = runtime_spine_cache(store_path)?;
cache.pull_all_backing_stores()?;
require_identity(&cache)?;
let intent = cache
.get::<HandsActionIntent>(intent_id)?
.ok_or_else(|| anyhow!("Hands consequence requires its persisted intent"))?;
let review = cache
.get::<HandsActionReview>(review_id)?
.ok_or_else(|| anyhow!("Hands consequence requires its persisted review"))?;
let grant = cache
.get::<SubstrateGateRepoAccessGrantReceipt>(&intent.substrate_gate_grant_receipt_id)?
.ok_or_else(|| anyhow!("Hands consequence requires its persisted Substrate Gate grant"))?;
let paths_covered = changed_paths.iter().all(|path| {
grant.granted_paths.iter().any(|granted| {
granted == "."
|| path == granted
|| path.starts_with(&format!("{}/", granted.trim_end_matches(['/', '\\'])))
})
});
if intent.runtime_job_id != runtime_job_id
|| review.intent_id != intent.intent_id
|| review.decision != "approved"
|| !review
.allowed_operations
.iter()
.any(|allowed| allowed == operation)
|| grant.runtime_job_id != intent.runtime_job_id
|| grant.binding_id != intent.binding_id
|| grant.role != intent.role
|| grant.authority_scope != intent.authority_scope
|| !grant
.granted_operations
.iter()
.any(|allowed| allowed == operation)
|| stated_grant_id.is_some_and(|id| id != grant.receipt_id)
|| !paths_covered
{
return Err(anyhow!(
"Hands consequence does not match its approved review and Substrate Gate grant"
));
}
Ok(())
}
pub fn put_hands_patch_receipt(
store_path: impl AsRef<Path>,
receipt: &HandsPatchReceipt,
@ -1492,6 +1578,15 @@ pub fn put_hands_patch_receipt(
if receipt.changed_paths.is_empty() {
return Err(anyhow!("Hands patch receipt must name changed paths"));
}
validate_hands_consequence_grant(
store_path.as_ref(),
&receipt.intent_id,
&receipt.review_id,
&receipt.runtime_job_id,
"patch",
&receipt.changed_paths,
Some(&receipt.substrate_gate_grant_receipt_id),
)?;
let mut cache = runtime_spine_cache(store_path)?;
cache.pull_all_backing_stores()?;
require_identity(&cache)?;
@ -1524,6 +1619,15 @@ pub fn put_hands_command_receipt(
validate_non_empty(&receipt.command, "Hands command")?;
validate_non_empty(&receipt.exit_code, "Hands command exit code")?;
validate_non_empty(&receipt.emitted_at, "Hands command timestamp")?;
validate_hands_consequence_grant(
store_path.as_ref(),
&receipt.intent_id,
&receipt.review_id,
&receipt.runtime_job_id,
"command",
&[],
Some(&receipt.substrate_gate_grant_receipt_id),
)?;
let mut cache = runtime_spine_cache(store_path)?;
cache.pull_all_backing_stores()?;
require_identity(&cache)?;
@ -1556,6 +1660,15 @@ pub fn put_hands_commit_receipt(
if receipt.changed_paths.is_empty() {
return Err(anyhow!("Hands commit receipt must name changed paths"));
}
validate_hands_consequence_grant(
store_path.as_ref(),
&receipt.intent_id,
&receipt.review_id,
&receipt.runtime_job_id,
"commit",
&receipt.changed_paths,
None,
)?;
let mut cache = runtime_spine_cache(store_path)?;
cache.pull_all_backing_stores()?;
require_identity(&cache)?;
@ -4242,6 +4355,13 @@ mod tests {
runtime_substrate_gate_repo_access_grant_receipt(&store, "substrate-grant-1")?
.expect("Substrate Gate grant should persist");
assert_eq!(stored_grant, substrate_grant);
let hands_grant = crate::substrate_gate_coordinator_implementation_grant(
"substrate-grant-hands-1".to_string(),
"job-implementation-1".to_string(),
vec!["src".to_string()],
"2026-05-06T00:06:20Z".to_string(),
);
put_substrate_gate_repo_access_grant_receipt(&store, &hands_grant)?;
let hands_intent = HandsActionIntent {
schema_version: crate::HANDS_ACTION_INTENT_SCHEMA_VERSION.to_string(),
intent_id: "hands-intent-1".to_string(),
@ -4251,7 +4371,7 @@ mod tests {
authority_scope: "epiphany.role.implementation".to_string(),
requested_action: "patch".to_string(),
requested_paths: vec!["src/lib.rs".to_string()],
substrate_gate_grant_receipt_id: "substrate-grant-1".to_string(),
substrate_gate_grant_receipt_id: "substrate-grant-hands-1".to_string(),
requested_at: "2026-05-06T00:06:30Z".to_string(),
contract: "Hands action intent persists as runtime-spine proof.".to_string(),
};
@ -4260,7 +4380,11 @@ mod tests {
"hands-review-1".to_string(),
&hands_intent,
"approved".to_string(),
vec!["patch".to_string()],
vec![
"patch".to_string(),
"command".to_string(),
"commit".to_string(),
],
vec!["Substrate Gate grant is present.".to_string()],
"2026-05-06T00:06:40Z".to_string(),
);
@ -4351,6 +4475,66 @@ mod tests {
Ok(())
}
#[test]
fn hands_persistence_requires_resolved_matching_grant_authority() -> Result<()> {
let temp = tempdir()?;
let store = temp.path().join("runtime.msgpack");
initialize_runtime_spine(
&store,
RuntimeSpineInitOptions {
runtime_id: "epiphany-test".to_string(),
display_name: "Epiphany Test".to_string(),
created_at: "2026-07-12T00:00:00Z".to_string(),
},
)?;
let mut intent = HandsActionIntent {
schema_version: crate::HANDS_ACTION_INTENT_SCHEMA_VERSION.to_string(),
intent_id: "hands-intent-grant-check".to_string(),
runtime_job_id: "hands-job-grant-check".to_string(),
binding_id: "repo-work-runner".to_string(),
role: "epiphany-hands".to_string(),
authority_scope: "repo.branch_local_work".to_string(),
requested_action: "runAcceptedWorkItem".to_string(),
requested_paths: vec!["README.md".to_string()],
substrate_gate_grant_receipt_id: "missing-grant".to_string(),
requested_at: "2026-07-12T00:00:01Z".to_string(),
contract: "Negative grant resolution proof.".to_string(),
};
assert!(put_hands_action_intent(&store, &intent).is_err());
let grant = crate::substrate_gate_repo_work_planning_grant(
"planning-grant".to_string(),
intent.runtime_job_id.clone(),
vec!["notes".to_string()],
"2026-07-12T00:00:00Z".to_string(),
);
put_substrate_gate_repo_access_grant_receipt(&store, &grant)?;
intent.substrate_gate_grant_receipt_id = grant.receipt_id.clone();
assert!(put_hands_action_intent(&store, &intent).is_err());
intent.requested_paths = vec!["notes/a.md".to_string()];
put_hands_action_intent(&store, &intent)?;
let review = crate::hands_action_review_for_intent(
"hands-review-grant-check".to_string(),
&intent,
"approved".to_string(),
vec!["patch".to_string()],
vec!["test".to_string()],
"2026-07-12T00:00:02Z".to_string(),
);
put_hands_action_review(&store, &review)?;
let patch = crate::hands_patch_receipt_for_review(
"hands-patch-grant-check".to_string(),
&intent,
&review,
vec!["notes/a.md".to_string()],
"test".to_string(),
"2026-07-12T00:00:03Z".to_string(),
);
assert!(put_hands_patch_receipt(&store, &patch).is_err());
Ok(())
}
#[test]
fn latest_hands_chain_uses_latest_same_gate_receipts_before_commit() -> Result<()> {
let temp = tempdir()?;
@ -4376,6 +4560,15 @@ mod tests {
requested_at: "2026-06-13T00:00:01Z".to_string(),
contract: "Test reused Hands gate.".to_string(),
};
put_substrate_gate_repo_access_grant_receipt(
&store,
&crate::substrate_gate_coordinator_implementation_grant(
"substrate-grant-reused".to_string(),
"hands-job-reused".to_string(),
vec![".".to_string()],
"2026-06-13T00:00:00Z".to_string(),
),
)?;
put_hands_action_intent(&store, &intent)?;
let review = crate::hands_action_review_for_intent(
"hands-review-reused".to_string(),

View file

@ -411,3 +411,12 @@ module owns narrow fixed-policy constructors for repo-work planning and
coordinator-approved implementation. Production binaries no longer choose the
binding, role, authority scope, operation set, schema, or contract prose field
by field.
## Hands carrying an unresolved grant label
Hands intent and consequence writers previously validated only that a grant ID
string was nonempty. They now resolve the immutable persisted grant and require
matching runtime job, binding, role, authority scope, allowed operation, and
path coverage. Patch, command, and commit receipts also require the matching
approved Hands review. Missing grants, mismatched paths, and attempts to mutate
under a read-only planning grant are negative-tested refusals.

View file

@ -103,6 +103,9 @@ The confirmed conceptual substitutions have been cut:
- Hands binaries no longer construct Substrate Gate grant structs inline.
Grants are non-exhaustive externally and come from narrow fixed-policy
constructors owned by the `substrate_gate` module.
- Hands persistence resolves its grant rather than trusting an ID label. Grant
identity/scope/operations/paths and approved review must match each intent
and patch/command/commit consequence; grants are immutable.
The presentation boundary is now plain: `swarm overview` is a generic compact read-only projection. Gjallar is a downstream TUI application on Nightwing and is not an Epiphany organ, provider, owner, runtime, or architectural dependency. Eve/CultUI graphs may be lowered or composited downstream without Epiphany caring which presentation client does it.

Binary file not shown.

View file

@ -660,4 +660,4 @@ current_status:
- Service lifecycle receipt history is now event-only: `load_epiphany_cultmesh_daemon_service_lifecycle_receipts` filters out the `epiphany-local/daemon-service-lifecycle-receipt/latest` mirror, while `load_latest_epiphany_cultmesh_daemon_service_lifecycle_receipt` remains the latest-state reader. Focused unit test `service_lifecycle_receipt_history_excludes_latest_mirror` proves two per-receipt writes return exactly two history records and latest points at the second. Fresh smoke `verse-query-lifecycle-history-filter-smoke` and live overview/triage `local-20260618-145632-497-efac6f0d` / `local-20260618-145632-321-867947af` prove compact swarm sights still expose service lifecycle attention plus the present elevated runbook artifact without daemon pokes or service mutation. Do not use a broad unscoped cargo test filter for this check on Windows; it fans out across bin harnesses and hit a broken pipe during this pass.
- `epiphany-verse-query seed-compact` is the compact seed receipt for wrappers and read-only rites. The older `seed` command still prints the full local Verse context for explicit debugging, but compact wrapper modes now avoid full `seed`/final `query` readback after the combined overview proof exposed Windows debug stack overflow from full-context serialization pressure.
last_completed_repo_swarm_cut: Huginn live-fire has crossed the first real repo Body from Persona pressure to branch-local Hands commit and Soul/Mind closure, and now has repeatable closure and redacted-public-proof mouths. On `E:\Projects\Huginn` branch `epiphany/huginn/first-awakening`, `tools/epiphany_local_run.ps1 -Mode repo-persona-intake` accepted item `huginn-inspection-readback-livefire`, Weksa/Persona intake remained sealed, and `epiphany-work derive-plan` lowered it to model-authored safe family `repo.status_section` for `README.md` only. `tools/epiphany_local_run.ps1 -Mode repo-swarm-run` advanced four bounded pulses: run-from-plan, adopt-from-plan, execute-from-plan, and close-from-execute. Huginn commit `e9b07c38fceabbdc89ea35c2156326c80c0393a2` updated only `README.md`; closure receipt `.epiphany\work\work-close-huginn-inspection-readback-livefire.json` records status `closed`, Soul verdict `passed`, Mind state commit `repo-work-close-huginn-inspection-readback-livefire-mind-commit`, safe family `repo.status_section`, path scope `README.md`, Bifrost publication gate, and `privateStateExposed=false`. Verification also ran Huginn's TypeScript compiler through concrete Node path: `C:\Program Files\nodejs\node.exe E:\Projects\Huginn\node_modules\typescript\bin\tsc -p tsconfig.json` passed. Native verifier `epiphany-repo-livefire-closure-smoke --workspace E:\Projects\Huginn --item huginn-inspection-readback-livefire --expected-path README.md --expected-family repo.status_section --expected-gate awaiting-publication --expected-blocker bifrost-publication-missing` checks closure receipt, Mind map entry, overview gate/blocker, authority seals, and `git show` changed paths, returning `status=ok`, `soulVerdict=passed`, `publicationGate=Bifrost`, and `privateStateExposed=false`. Wrapper `tools/epiphany_local_run.ps1 -Mode repo-livefire-closure -Workspace E:\Projects\Huginn -RepoWorkItem huginn-inspection-readback-livefire -SkipBuild` exposes the same read-only proof through the local operator mouth; artifact `local-20260621-190156-803-2f85ba15` printed commit, path, gate, blocker, Soul verdict, Mind commit receipt, and `privateStateExposed=False` without push, merge, publication, or target mutation. New wrapper `tools/epiphany_local_run.ps1 -Mode repo-work-public-proof -Workspace E:\Projects\Huginn -RepoWorkItem huginn-inspection-readback-livefire -SkipBuild` exports the redacted proof bundle and repo-local Verse index without publishing; artifact `local-20260621-190645-345-4555b1dc` wrote `.epiphany\public\proof-bundles\repo-work-public-proof-huginn-inspection-readback-livefire.json`, proof id `repo-work-public-proof-huginn-inspection-readback-livefire`, SHA-256 `857545b199f3e37eb06c2e757e5cfc201958e46667bb1f8403fd333a22620f63`, nine artifact rows, zero publication rows, and `privateStateExposed=False`. swarm overview readback `local-20260621-190701-140-b9519ec6` sees the `REPO-WORK-PUBLIC-PROOF` row and action row from Huginn's repo-local Verse with the same SHA-256 while Bifrost publication remains missing. Launcher compact modes are now named compact operator-context modes instead of read-only modes, and `bifrost-public-proof` summaries print item, target public Verse, room, proof SHA-256, review receipts, and credit receipts so publication receipts are auditable without claiming upstream sync.
next_action: Continue the conceptual-substitution modeling pass beyond receipt writers. Publication/PR/provider authority is sealed; Modeling/Soul/Mind closure is single-sourced; Hands binaries no longer self-assemble Substrate grants, which now come from narrow non-exhaustive module-owned policies. Audit persistence so Hands intents and receipts resolve and match the actual grant rather than merely naming its id, then inspect daemon lifecycle writers and remaining projections/caches/adapters for substituted authority.
next_action: Continue the conceptual-substitution modeling pass beyond receipt writers. Publication and closure authority is single-sourced; Substrate Gate owns fixed grant policies; Hands intents and consequences now resolve immutable grants plus approved reviews and enforce identity/operation/path scope. Inspect daemon lifecycle writers next, then remaining projections/caches/adapters for substituted authority.