diff --git a/epiphany-core/src/agent_launch.rs b/epiphany-core/src/agent_launch.rs index 597ce034..af584059 100644 --- a/epiphany-core/src/agent_launch.rs +++ b/epiphany-core/src/agent_launch.rs @@ -65,7 +65,11 @@ pub fn epiphany_role_label(role_id: EpiphanyRoleResultRoleId) -> &'static str { fn repo_frontier_item_output_schema() -> serde_json::Value { serde_json::json!({ "type": "object", - "required": ["id", "migration_body", "question", "gap", "target_claim_ids", "recommended_next_organ", "status"], + "required": [ + "id", "migration_body", "question", "gap", "target_claim_ids", + "repository_scope", "recommended_next_organ", "dependency_item_ids", + "status", "evidence_refs" + ], "properties": { "id": {"type": "string", "minLength": 1}, "migration_body": {"type": "string", "minLength": 1}, @@ -77,7 +81,11 @@ fn repo_frontier_item_output_schema() -> serde_json::Value { "description": "RepoModel node identities whose claims this frontier item changes or resolves.", "items": {"type": "string", "minLength": 1} }, - "source_scope": {"type": "array", "items": {"type": "string"}}, + "repository_scope": { + "type": "array", + "description": "A strict lexicographically sorted, duplicate-free repository-relative path ceiling for this wound. Include every path downstream Planning may authorize Hands to change, including not-yet-created outputs. Do not list inspected or evidence files unless they are genuinely within the possible consequence scope; those facts belong in filesInspected, evidence_refs, and the sealed reasoning basis.", + "items": {"type": "string", "minLength": 1} + }, "recommended_next_organ": {"type": "string", "minLength": 1}, "dependency_item_ids": { "type": "array", @@ -661,7 +669,7 @@ pub fn epiphany_proposal_modeling_output_schema( "proposalFrontierDraft": { "type": "object", "required": [ - "migrationBody", "question", "gap", "targetClaimIds", "sourceScope", + "migrationBody", "question", "gap", "targetClaimIds", "repositoryScope", "recommendedNextOrgan", "dependencyItemIds", "evidenceRefs" ], "properties": { @@ -669,9 +677,10 @@ pub fn epiphany_proposal_modeling_output_schema( "question": {"type": "string", "minLength": 1}, "gap": {"type": "string", "minLength": 1}, "targetClaimIds": {"type": "array", "items": {"type": "string"}}, - "sourceScope": { + "repositoryScope": { "type": "array", "minItems": 1, + "description": "A strict lexicographically sorted, duplicate-free repository-relative path ceiling for this wound. Include intended outputs that downstream Planning may authorize Hands to change; do not substitute files inspected as evidence.", "items": {"type": "string", "minLength": 1} }, "recommendedNextOrgan": {"type": "string", "enum": recommended_organs}, @@ -727,7 +736,7 @@ pub fn epiphany_frontier_planning_output_schema() -> serde_json::Value { "safe_paths": { "type": "array", "minItems": 1, - "description": "A strict lexicographically sorted, duplicate-free narrowing of the immutable planning context source_scope. Every path must equal one source_scope entry or be a descendant of one; never add an adjacent or otherwise unscoped path.", + "description": "A strict lexicographically sorted, duplicate-free narrowing of the immutable planning context repository_scope. Every path must equal one repository_scope entry or be a descendant of one; never add an adjacent or otherwise unscoped path.", "items": {"type": "string", "minLength": 1} }, "action": {"type": "string", "minLength": 1}, @@ -1161,6 +1170,24 @@ mod tests { assert!(!prompt.contains("Heartbeat: every lane")); } + #[test] + fn frontier_schema_separates_repository_authority_from_observed_sources() { + let schema = repo_frontier_item_output_schema(); + let properties = schema["properties"] + .as_object() + .expect("frontier properties"); + assert!(properties.contains_key("repository_scope")); + assert!(!properties.contains_key("source_scope")); + assert!( + properties["repository_scope"]["description"] + .as_str() + .is_some_and(|description| { + description.contains("not-yet-created outputs") + && description.contains("evidence files") + }) + ); + } + #[test] fn role_self_patch_schema_matches_canonical_numeric_memory_contract() { let schema = epiphany_role_launch_output_schema(EpiphanyRoleResultRoleId::Verification); @@ -1305,6 +1332,13 @@ mod tests { let draft = &schema["properties"]["proposalFrontierDraft"]; let draft_properties = draft["properties"].as_object().expect("draft properties"); let draft_required = draft["required"].as_array().expect("draft required"); + assert!(draft_properties.contains_key("repositoryScope")); + assert!(!draft_properties.contains_key("sourceScope")); + assert!( + draft_properties["repositoryScope"]["description"] + .as_str() + .is_some_and(|description| description.contains("intended outputs")) + ); assert!( draft_properties .keys() diff --git a/epiphany-core/src/bin/epiphany-hands-action.rs b/epiphany-core/src/bin/epiphany-hands-action.rs index 29286813..1f930b07 100644 --- a/epiphany-core/src/bin/epiphany-hands-action.rs +++ b/epiphany-core/src/bin/epiphany-hands-action.rs @@ -914,7 +914,7 @@ mod tests { question: "Can Hands record the approved consequence?".into(), gap: "The CLI path needs its exact adopted route.".into(), target_claim_ids: vec![node.id.clone()], - source_scope: requested_paths.clone(), + repository_scope: requested_paths.clone(), recommended_next_organ: "Hands".into(), adopted_plan: Some(RepoFrontierAdoptedPlan { planning_request_id: "hands-action-planning-request".into(), @@ -1013,7 +1013,7 @@ mod tests { hands_intent_id: intent.intent_id, hands_review_id: review.review_id, substrate_grant_receipt_id: grant.receipt_id, - requested_paths: route.source_scope, + requested_paths: route.authorized_paths, granted_at: review.reviewed_at, contract: epiphany_core::REPO_FRONTIER_HANDS_AUTHORITY_CONTRACT.into(), }, diff --git a/epiphany-core/src/bin/epiphany-mvp-coordinator.rs b/epiphany-core/src/bin/epiphany-mvp-coordinator.rs index f4ec8cb9..2637af59 100644 --- a/epiphany-core/src/bin/epiphany-mvp-coordinator.rs +++ b/epiphany-core/src/bin/epiphany-mvp-coordinator.rs @@ -1611,7 +1611,7 @@ fn record_hands_implementation_gate( ); let runtime_job_id = format!("hands-implementation-{suffix}"); let grant_id = format!("substrate-grant-{runtime_job_id}"); - let requested_paths = route.source_scope.clone(); + let requested_paths = route.authorized_paths.clone(); let substrate_grant = substrate_gate_coordinator_implementation_grant( grant_id.clone(), diff --git a/epiphany-core/src/current_work.rs b/epiphany-core/src/current_work.rs index fe87cb3a..8850c9f6 100644 --- a/epiphany-core/src/current_work.rs +++ b/epiphany-core/src/current_work.rs @@ -4398,7 +4398,7 @@ mod tests { question: "Should this proposal advance?".into(), gap: "The proposal needs an adopted plan.".into(), target_claim_ids: vec!["body-node".into()], - source_scope: vec!["epiphany-core/src".into()], + repository_scope: vec!["epiphany-core/src".into()], recommended_next_organ: "Imagination".into(), dependency_item_ids: vec!["body-node".into()], status: RepoFrontierStatus::Active, @@ -4587,7 +4587,7 @@ mod tests { question: "Should this proposal advance?".into(), gap: "The proposal needs an adopted plan.".into(), target_claim_ids: vec!["body-node".into()], - source_scope: vec!["epiphany-core/src".into()], + repository_scope: vec!["epiphany-core/src".into()], recommended_next_organ: "Imagination".into(), status: RepoFrontierStatus::Active, evidence_refs: vec![proposal.proposal_id.clone()], @@ -4690,7 +4690,7 @@ mod tests { question: frontier_item.question.clone(), gap: frontier_item.gap.clone(), target_claim_ids: frontier_item.target_claim_ids.clone(), - source_scope: frontier_item.source_scope.clone(), + authorized_paths: frontier_item.repository_scope.clone(), adopted_plan: frontier_item.adopted_plan.clone(), selected_at: "2026-08-17T00:00:14Z".into(), contract: crate::REPO_FRONTIER_ROUTE_CONTRACT.into(), @@ -4701,7 +4701,7 @@ mod tests { let grant = crate::substrate_gate_coordinator_implementation_grant( "substrate-grant-hands-verification-fixture".into(), hands_job_id.into(), - route.source_scope.clone(), + route.authorized_paths.clone(), "2026-08-17T00:00:14.100Z".into(), ); crate::put_substrate_gate_repo_access_grant_receipt(&store, &grant)?; @@ -4713,7 +4713,7 @@ mod tests { role: "epiphany-hands".into(), authority_scope: "epiphany.role.implementation".into(), requested_action: "continueImplementation".into(), - requested_paths: route.source_scope.clone(), + requested_paths: route.authorized_paths.clone(), substrate_gate_grant_receipt_id: grant.receipt_id.clone(), requested_at: "2026-08-17T00:00:14.200Z".into(), contract: "The exact Hands consequence under Verification.".into(), @@ -4747,7 +4747,7 @@ mod tests { hands_intent_id: intent.intent_id.clone(), hands_review_id: hands_review.review_id.clone(), substrate_grant_receipt_id: grant.receipt_id.clone(), - requested_paths: route.source_scope.clone(), + requested_paths: route.authorized_paths.clone(), granted_at: hands_review.reviewed_at.clone(), contract: crate::REPO_FRONTIER_HANDS_AUTHORITY_CONTRACT.into(), }; @@ -4756,7 +4756,7 @@ mod tests { "hands-patch-verification-fixture".into(), &intent, &hands_review, - route.source_scope.clone(), + route.authorized_paths.clone(), "Applied the exact bounded change.".into(), "2026-08-17T00:00:14.400Z".into(), ); @@ -4779,7 +4779,7 @@ mod tests { &hands_review, "0123456789abcdef0123456789abcdef01234567".into(), "codex/verification-fixture".into(), - route.source_scope.clone(), + route.authorized_paths.clone(), "Committed the exact bounded consequence.".into(), "2026-08-17T00:00:14.600Z".into(), ); @@ -5483,7 +5483,7 @@ mod tests { question: "How should the keyed Mind cut continue?".into(), gap: "The exact frontier needs one bounded plan.".into(), target_claim_ids: vec!["body-node".into()], - source_scope: vec!["epiphany-core/src".into()], + repository_scope: vec!["epiphany-core/src".into()], recommended_next_organ: "Imagination".into(), status: RepoFrontierStatus::Active, evidence_refs: vec![verdict.receipt_id.clone()], @@ -5709,7 +5709,7 @@ mod tests { model_source_documents: planning_request.model_source_documents.clone(), frontier_item_id: planning_request.frontier_item_id.clone(), frontier_item_hash: planning_request.frontier_item_hash.clone(), - safe_paths: planning_request.source_scope.clone(), + safe_paths: planning_request.repository_scope.clone(), action: "Replace aggregate planning authority with keyed current work.".into(), command: "cargo test --manifest-path epiphany-core/Cargo.toml --lib".into(), checks: vec!["planning lifecycle is thread-free".into()], @@ -5975,7 +5975,7 @@ mod tests { question: "What external evidence resolves this claim?".into(), gap: "The current Body cannot answer this external question.".into(), target_claim_ids: vec!["body-node".into()], - source_scope: vec!["epiphany-core/src".into()], + repository_scope: vec!["epiphany-core/src".into()], recommended_next_organ: "Eyes".into(), status: RepoFrontierStatus::Active, evidence_refs: vec![verdict.receipt_id.clone()], diff --git a/epiphany-core/src/frontier_plan_chain.rs b/epiphany-core/src/frontier_plan_chain.rs index 5377046b..273d5bc8 100644 --- a/epiphany-core/src/frontier_plan_chain.rs +++ b/epiphany-core/src/frontier_plan_chain.rs @@ -74,11 +74,11 @@ fn validate_current_frontier_route<'a>( .map_err(|error| format!("failed to hash current frontier item: {error}"))? ) ); - let expected_source_scope = current_item + let expected_authorized_paths = current_item .adopted_plan .as_ref() .map(|plan| plan.safe_paths.as_slice()) - .unwrap_or(current_item.source_scope.as_slice()); + .unwrap_or(current_item.repository_scope.as_slice()); if route.schema_version != crate::REPO_FRONTIER_ROUTE_SCHEMA_VERSION || route.contract != crate::REPO_FRONTIER_ROUTE_CONTRACT || route.next_organ != crate::RepoFrontierNextOrgan::Hands @@ -87,7 +87,7 @@ fn validate_current_frontier_route<'a>( || route.question != current_item.question || route.gap != current_item.gap || route.target_claim_ids != current_item.target_claim_ids - || route.source_scope != expected_source_scope + || route.authorized_paths != expected_authorized_paths || route.adopted_plan != current_item.adopted_plan || current_item.status != crate::RepoFrontierStatus::Active || current_item.recommended_next_organ != "Hands" diff --git a/epiphany-core/src/memory_graph/mod.rs b/epiphany-core/src/memory_graph/mod.rs index d1017144..24edb2f2 100644 --- a/epiphany-core/src/memory_graph/mod.rs +++ b/epiphany-core/src/memory_graph/mod.rs @@ -45,7 +45,9 @@ pub use semantic_projection::*; pub use semantic_projector::*; pub use semantic_projector_pulse::*; pub use validation::EpiphanyMemoryGraphValidationError; +pub(crate) use validation::frontier_item_has_routeable_repository_scope; pub use validation::lifecycle_allowed_for_profile; +pub(crate) use validation::repo_paths_are_canonical_and_safe; pub use validation::validate_memory_graph_snapshot; pub(crate) fn push_unique(target: &mut Vec, value: String) { diff --git a/epiphany-core/src/memory_graph/semantic_projection.rs b/epiphany-core/src/memory_graph/semantic_projection.rs index fcdfe70a..86f956ad 100644 --- a/epiphany-core/src/memory_graph/semantic_projection.rs +++ b/epiphany-core/src/memory_graph/semantic_projection.rs @@ -319,7 +319,7 @@ pub fn derive_semantic_projection( domain, EpiphanyMemoryProfile::RepoArchitecture, SemanticLifecycle::Frontier(item.status), - item.source_scope + item.repository_scope .iter() .chain(&item.evidence_refs) .cloned() @@ -563,6 +563,7 @@ mod tests { migration_body: "finish projection".into(), gap: "not wired".into(), target_claim_ids: vec!["repo-node".into()], + repository_scope: vec!["epiphany-core".into()], recommended_next_organ: "Hands".into(), status: RepoFrontierStatus::Active, ..Default::default() diff --git a/epiphany-core/src/memory_graph/validation.rs b/epiphany-core/src/memory_graph/validation.rs index 3cfb2240..c9ac7fe3 100644 --- a/epiphany-core/src/memory_graph/validation.rs +++ b/epiphany-core/src/memory_graph/validation.rs @@ -8,6 +8,28 @@ use super::EpiphanyMemorySummary; use super::RepoFrontierStatus; use std::collections::{HashMap, HashSet}; +pub(crate) fn repo_paths_are_canonical_and_safe(paths: &[String]) -> bool { + paths.windows(2).all(|pair| pair[0] < pair[1]) + && paths.iter().all(|path| { + !path.is_empty() + && !path.starts_with('/') + && !path.contains('\\') + && !path + .split('/') + .any(|component| component.is_empty() || matches!(component, "." | "..")) + && !path + .split('/') + .next() + .is_some_and(|component| component.contains(':')) + }) +} + +pub(crate) fn frontier_item_has_routeable_repository_scope( + item: &epiphany_state_model::RepoFrontierItem, +) -> bool { + !item.repository_scope.is_empty() && repo_paths_are_canonical_and_safe(&item.repository_scope) +} + #[derive(Debug, Clone, PartialEq, Eq)] pub struct EpiphanyMemoryGraphValidationError { pub path: String, @@ -118,6 +140,26 @@ pub fn validate_memory_graph_snapshot( "recommended next organ is required", &mut errors, ); + if !item.repository_scope.is_empty() + && !repo_paths_are_canonical_and_safe(&item.repository_scope) + { + errors.push(EpiphanyMemoryGraphValidationError::new( + format!("{path}.repository_scope"), + "repository scope must be a strict sorted set of canonical repository-relative paths", + )); + } + if unresolved + && matches!( + item.recommended_next_organ.as_str(), + "Hands" | "Eyes" | "Imagination" + ) + && !frontier_item_has_routeable_repository_scope(item) + { + errors.push(EpiphanyMemoryGraphValidationError::new( + format!("{path}.repository_scope"), + "an unresolved routed frontier requires a non-empty canonical repository scope", + )); + } if !item.public_source_refs.is_empty() { if item.recommended_next_organ != "Eyes" { errors.push(EpiphanyMemoryGraphValidationError::new( @@ -484,3 +526,26 @@ fn required( errors.push(EpiphanyMemoryGraphValidationError::new(path, message)); } } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn repository_path_law_is_ordered_and_platform_independent() { + assert!(repo_paths_are_canonical_and_safe(&[ + "OX-CAPSTONE.md".into(), + "epiphany-core/src/lib.rs".into(), + ])); + for invalid in [ + vec!["notes/source.md".into(), "OX-CAPSTONE.md".into()], + vec!["../outside".into()], + vec!["epiphany-core\\src\\lib.rs".into()], + vec!["C:/outside".into()], + vec!["epiphany-core//src".into()], + vec!["epiphany-core/./src".into()], + ] { + assert!(!repo_paths_are_canonical_and_safe(&invalid)); + } + } +} diff --git a/epiphany-core/src/mind_documents.rs b/epiphany-core/src/mind_documents.rs index 1732ded0..740c35f2 100644 --- a/epiphany-core/src/mind_documents.rs +++ b/epiphany-core/src/mind_documents.rs @@ -13,7 +13,7 @@ use sha2::{Digest, Sha256}; use crate::{EpiphanyMindDocumentVersion, runtime_spine_cache}; -pub const MIND_SCHEMA_EPOCH: &str = "epiphany.mind.epoch.v3"; +pub const MIND_SCHEMA_EPOCH: &str = "epiphany.mind.epoch.v4"; pub const MIND_OBJECTIVE_KEY: &str = "objective"; pub const MIND_FOCUS_KEY: &str = "focus"; pub const MIND_MODE_KEY: &str = "mode"; diff --git a/epiphany-core/src/repo_model_documents.rs b/epiphany-core/src/repo_model_documents.rs index eaed8142..c2a9844c 100644 --- a/epiphany-core/src/repo_model_documents.rs +++ b/epiphany-core/src/repo_model_documents.rs @@ -12,7 +12,7 @@ use sha2::{Digest, Sha256}; use crate::{EpiphanyMindDocumentVersion, runtime_spine_cache, validate_memory_graph_snapshot}; -pub const REPO_MODEL_SCHEMA_EPOCH: &str = "epiphany.repo_model.epoch.v1"; +pub const REPO_MODEL_SCHEMA_EPOCH: &str = "epiphany.repo_model.epoch.v2"; pub const REPO_MODEL_IDENTITY_KEY: &str = "repo-model"; const HISTORICAL_AGGREGATE_REPO_MODEL_TYPE: &str = "epiphany.memory_graph"; const HISTORICAL_AGGREGATE_REPO_MODEL_KEY: &str = "default"; @@ -1850,7 +1850,7 @@ mod tests { migration_body: "repo".into(), question: "What remains?".into(), target_claim_ids: vec![node.id.clone()], - source_scope: vec!["epiphany-core".into()], + repository_scope: vec!["epiphany-core".into()], recommended_next_organ: "Modeling".into(), status: RepoFrontierStatus::Active, ..Default::default() @@ -1898,6 +1898,31 @@ mod tests { let replay = initialize_keyed_repo_model(&store, &seed, "2026-08-14T00:00:02Z")?; assert_eq!(first, replay); assert_eq!(first.claim_obligations[0].node_id, "node-seed"); + let invalid_routed_frontier = make_proposal( + "invalid-routed-frontier", + &body, + vec![EpiphanyRepoModelMutationOperation::PutFrontier { + item: RepoFrontierItem { + id: "frontier-invalid-route-scope".into(), + migration_body: "Create OX-CAPSTONE.md".into(), + question: "Can Planning authorize the intended output?".into(), + gap: "The model confused inspected evidence with future path authority.".into(), + target_claim_ids: vec!["node-seed".into()], + repository_scope: vec!["notes/source.md".into(), "OX-CAPSTONE.md".into()], + recommended_next_organ: "Imagination".into(), + status: RepoFrontierStatus::Active, + ..Default::default() + }, + }], + )?; + let error = plan_repo_model_mutation(&store, &invalid_routed_frontier) + .expect_err("noncanonical routed scope must refuse before RepoModel writes"); + assert!(error.to_string().contains("repository_scope")); + assert!( + runtime_spine_cache(&store)? + .get::("frontier-invalid-route-scope")? + .is_none() + ); let mut cache = runtime_spine_cache(&store)?; cache.pull_all_backing_stores()?; assert_eq!( diff --git a/epiphany-core/src/repo_model_gateway.rs b/epiphany-core/src/repo_model_gateway.rs index 71c85369..86f3d36b 100644 --- a/epiphany-core/src/repo_model_gateway.rs +++ b/epiphany-core/src/repo_model_gateway.rs @@ -7,13 +7,13 @@ //! 2. Self selects exactly one eligible Imagination item and commits a //! `RepoFrontierPlanningRequest`. Imagination returns a //! `RepoFrontierPlanCandidate` whose safe paths may only narrow the item's -//! source scope. +//! repository scope. //! 3. Self commits a `RepoFrontierPlanMindRequest`. Mind alone adopts, refuses, //! or holds the candidate through `RepoFrontierPlanDecisionReceipt`. //! 4. Only an adopted decision may be embedded in `RepoFrontierRoute` by //! `runtime_spine::select_and_commit_repo_frontier_route`. Route selection //! binds the current admitted model revision, admission receipt, frontier -//! hash, and source scope in one compare-and-swap operation. +//! hash, and repository scope in one compare-and-swap operation. //! 5. Hands remains powerless until the coordinator pairs that route with a //! reviewed Hands intent, Substrate Gate receipt, and //! `RepoFrontierHandsAuthority`. Hands receipts describe consequences; they @@ -424,7 +424,7 @@ pub struct RepoFrontierPlanningRequest { #[cultcache(key = 6)] pub selected_organ: String, #[cultcache(key = 7)] - pub source_scope: Vec, + pub repository_scope: Vec, #[cultcache(key = 8)] pub requested_at: String, #[cultcache(key = 9)] @@ -492,7 +492,7 @@ pub struct RepoFrontierResearchRequest { #[cultcache(key = 5)] pub frontier_item_hash: String, #[cultcache(key = 6)] - pub source_scope: Vec, + pub repository_scope: Vec, #[cultcache(key = 7)] pub requested_at: String, #[cultcache(key = 8)] @@ -598,7 +598,7 @@ pub struct RepoFrontierPlanningCandidateEligibility { pub eligible: bool, pub status_valid: bool, pub recommended_next_organ_valid: bool, - pub source_scope_valid: bool, + pub repository_scope_valid: bool, pub challenged_target_claim_ids: Vec, pub unresolved_dependency_item_ids: Vec, } @@ -830,7 +830,7 @@ pub struct RepoFrontierRoute { #[cultcache(key = 10)] pub target_claim_ids: Vec, #[cultcache(key = 11)] - pub source_scope: Vec, + pub authorized_paths: Vec, #[cultcache(key = 12, default)] pub adopted_plan: Option, #[cultcache(key = 13)] diff --git a/epiphany-core/src/runtime_spine.rs b/epiphany-core/src/runtime_spine.rs index df81e43b..7a56a2df 100644 --- a/epiphany-core/src/runtime_spine.rs +++ b/epiphany-core/src/runtime_spine.rs @@ -170,7 +170,7 @@ pub const TOOL_INVOCATION_RECEIPT_TYPE: &str = "epiphany.tool_invocation_receipt pub const RUNTIME_IDENTITY_KEY: &str = "self"; pub const RUNTIME_SWARM_BINDING_KEY: &str = "runtime-swarm-binding"; pub const RUNTIME_SWARM_BINDING_SCHEMA_VERSION: &str = "epiphany.runtime.swarm_binding.v0"; -pub const RUNTIME_SPINE_SCHEMA_VERSION: &str = "epiphany.runtime_spine.v4"; +pub const RUNTIME_SPINE_SCHEMA_VERSION: &str = "epiphany.runtime_spine.v5"; pub const EPIPHANY_RUNTIME_ROOT_SESSION_ID: &str = "epiphany-main"; pub const RUNTIME_MODEL_EXECUTION_BINDING_SCHEMA_VERSION: &str = "epiphany.runtime.model_execution_binding.v0"; @@ -3797,7 +3797,7 @@ fn validate_repo_frontier_verdict_modeling_mutation( || item.migration_body != authority.frontier_item.migration_body || item.question != authority.frontier_item.question || item.target_claim_ids != authority.frontier_item.target_claim_ids - || item.source_scope != authority.frontier_item.source_scope + || item.repository_scope != authority.frontier_item.repository_scope || item.recommended_next_organ != authority.frontier_item.recommended_next_organ || item.adopted_plan != authority.frontier_item.adopted_plan || item.dependency_item_ids != authority.frontier_item.dependency_item_ids @@ -6048,8 +6048,7 @@ pub(crate) fn validate_proposal_modeling_worker_admission( .evidence_refs .iter() .any(|id| id == &proposal.proposal_id) - || upserts[0].source_scope.is_empty() - || !safe_sorted_unique_paths(&upserts[0].source_scope) + || !crate::memory_graph::frontier_item_has_routeable_repository_scope(upserts[0]) || upserts[0].public_source_refs != if upserts[0].recommended_next_organ == "Eyes" { proposal.public_source_refs.clone() @@ -7296,7 +7295,7 @@ pub fn select_and_commit_repo_frontier_planning_request( frontier_item_id: item.id.clone(), frontier_item_hash: item_hash, selected_organ: "Imagination".into(), - source_scope: item.source_scope.clone(), + repository_scope: item.repository_scope.clone(), requested_at: at.into(), contract: REPO_FRONTIER_PLANNING_CONTRACT.into(), runtime_id: identity.runtime_id, @@ -7344,8 +7343,8 @@ fn validate_repo_frontier_planning_request( || request.frontier_item_id.trim().is_empty() || request.frontier_item_hash.trim().is_empty() || request.selected_organ != "Imagination" - || request.source_scope.is_empty() - || !safe_sorted_unique_paths(&request.source_scope) + || request.repository_scope.is_empty() + || !crate::memory_graph::repo_paths_are_canonical_and_safe(&request.repository_scope) || request.frontier_authority_documents.is_empty() || request.frontier_authority_documents.iter().any(|document| { document.validate().is_err() @@ -7420,7 +7419,7 @@ fn validate_repo_frontier_planning_request( || request.request_id != expected_request_id || request.frontier_item_id != item.id || request.frontier_item_hash != repo_frontier_item_hash(&item)? - || request.source_scope != item.source_scope + || request.repository_scope != item.repository_scope { return Err(anyhow!( "frontier planning request diverges from its sealed frontier authority" @@ -7632,8 +7631,7 @@ fn imagination_frontier_item_is_actionable( }; item.status == crate::RepoFrontierStatus::Active && item.recommended_next_organ == "Imagination" - && !item.source_scope.is_empty() - && safe_sorted_unique_paths(&item.source_scope) + && crate::memory_graph::frontier_item_has_routeable_repository_scope(item) && frontier_target_claims_unchallenged(item, challenges) && item.dependency_item_ids.iter().all(|id| terminal(id)) } @@ -7867,9 +7865,9 @@ fn validate_repo_frontier_plan_candidate_against_request( let item = validate_repo_frontier_planning_request(request)?; frontier_authority_envelopes(cache, &request.frontier_authority_documents)?; if repo_frontier_item_hash(&item)? != request.frontier_item_hash - || item.source_scope != request.source_scope + || item.repository_scope != request.repository_scope || !candidate.safe_paths.iter().all(|path| { - request.source_scope.iter().any(|scope| { + request.repository_scope.iter().any(|scope| { path == scope || path.starts_with(&format!("{}/", scope.trim_end_matches(['/', '\\']))) }) @@ -8104,7 +8102,7 @@ impl RepoFrontierPlanCandidate { fn selected_fields_invalid(&self) -> bool { self.candidate_id.trim().is_empty() || self.safe_paths.is_empty() - || !safe_sorted_unique_paths(&self.safe_paths) + || !crate::memory_graph::repo_paths_are_canonical_and_safe(&self.safe_paths) || self.action.trim().is_empty() || self.command.trim().is_empty() || self.checks.is_empty() @@ -8134,9 +8132,9 @@ pub fn select_and_commit_repo_frontier_route( let challenges = current_repo_model_claim_challenges(&cache, ¤t, &basis)?; let item = actionable_hands_frontier_item(¤t, &challenges) .ok_or_else(|| anyhow!("current repo model has no eligible Hands frontier route"))?; - if !safe_sorted_unique_paths(&item.source_scope) || item.source_scope.is_empty() { + if !crate::memory_graph::frontier_item_has_routeable_repository_scope(item) { return Err(anyhow!( - "Hands frontier route requires safe sorted source scope" + "Hands frontier route requires canonical repository scope" )); } let item_hash = format!("{:x}", Sha256::digest(rmp_serde::to_vec_named(&item)?)); @@ -8157,11 +8155,11 @@ pub fn select_and_commit_repo_frontier_route( question: item.question.clone(), gap: item.gap.clone(), target_claim_ids: item.target_claim_ids.clone(), - source_scope: item + authorized_paths: item .adopted_plan .as_ref() .map(|plan| plan.safe_paths.clone()) - .unwrap_or_else(|| item.source_scope.clone()), + .unwrap_or_else(|| item.repository_scope.clone()), adopted_plan: item.adopted_plan.clone(), selected_at: at.to_string(), contract: REPO_FRONTIER_ROUTE_CONTRACT.to_string(), @@ -8230,8 +8228,7 @@ fn frontier_item_is_actionable_for_organ( }; item.status == crate::RepoFrontierStatus::Active && item.recommended_next_organ == organ - && !item.source_scope.is_empty() - && safe_sorted_unique_paths(&item.source_scope) + && crate::memory_graph::frontier_item_has_routeable_repository_scope(item) && (!require_unchallenged_targets || frontier_target_claims_unchallenged(item, challenges)) && item.dependency_item_ids.iter().all(|dependency_id| { model @@ -8384,8 +8381,8 @@ fn validate_repo_frontier_research_request( || chrono::DateTime::parse_from_rfc3339(&request.requested_at).is_err() || request.frontier_item_id.is_empty() || request.frontier_item_hash.is_empty() - || request.source_scope.is_empty() - || !safe_sorted_unique_paths(&request.source_scope) + || request.repository_scope.is_empty() + || !crate::memory_graph::repo_paths_are_canonical_and_safe(&request.repository_scope) || request.frontier_authority_documents.is_empty() { return Err(anyhow!("invalid frontier Research request")); @@ -8434,7 +8431,7 @@ fn validate_repo_frontier_research_request( != expected_authority_ids || request.frontier_item_id != frontier.id || request.frontier_item_hash != repo_frontier_item_hash(&frontier)? - || request.source_scope != frontier.source_scope + || request.repository_scope != frontier.repository_scope || request.public_source_refs != crate::ImmutableGithubSource::canonicalize_set( frontier.public_source_refs.iter().map(String::as_str), @@ -8596,7 +8593,7 @@ fn repo_frontier_research_request_for_admitted_item( frontier_authority_documents, frontier_item_id: item.id.clone(), frontier_item_hash: item_hash, - source_scope: item.source_scope.clone(), + repository_scope: item.repository_scope.clone(), requested_at: requested_at.to_string(), runtime_id: runtime_id.to_string(), contract: REPO_FRONTIER_RESEARCH_REQUEST_CONTRACT.to_string(), @@ -8900,8 +8897,8 @@ fn repo_frontier_research_request_is_actionable( ) -> Result { if request.schema_version != REPO_FRONTIER_RESEARCH_REQUEST_SCHEMA_VERSION || request.contract != REPO_FRONTIER_RESEARCH_REQUEST_CONTRACT - || request.source_scope.is_empty() - || !safe_sorted_unique_paths(&request.source_scope) + || request.repository_scope.is_empty() + || !crate::memory_graph::repo_paths_are_canonical_and_safe(&request.repository_scope) { return Err(anyhow!("invalid frontier Research request")); } @@ -8924,7 +8921,7 @@ pub fn runtime_has_actionable_imagination_frontier( /// Read-only Self signal explaining the exact canonical blockers on every /// active Imagination frontier. It derives from the same admitted RepoModel, -/// current claim-challenge set, source-scope predicate, and dependency rule as +/// current claim-challenge set, repository-scope predicate, and dependency rule as /// planning selection; it neither creates nor repairs authority. pub fn runtime_repo_frontier_planning_eligibility( runtime_store: impl AsRef, @@ -8964,8 +8961,8 @@ pub fn runtime_repo_frontier_planning_eligibility( .map(|item| { let status_valid = item.status == crate::RepoFrontierStatus::Active; let recommended_next_organ_valid = item.recommended_next_organ == "Imagination"; - let source_scope_valid = - !item.source_scope.is_empty() && safe_sorted_unique_paths(&item.source_scope); + let repository_scope_valid = + crate::memory_graph::frontier_item_has_routeable_repository_scope(item); let mut challenged_target_claim_ids = challenges .iter() .filter(|challenge| item.target_claim_ids.contains(&challenge.target_claim_id)) @@ -8992,12 +8989,12 @@ pub fn runtime_repo_frontier_planning_eligibility( eligible: model_count == 1 && status_valid && recommended_next_organ_valid - && source_scope_valid + && repository_scope_valid && challenged_target_claim_ids.is_empty() && unresolved_dependency_item_ids.is_empty(), status_valid, recommended_next_organ_valid, - source_scope_valid, + repository_scope_valid, challenged_target_claim_ids, unresolved_dependency_item_ids, } @@ -9676,7 +9673,7 @@ fn validate_repo_frontier_hands_authority_chain( .get::(&authority.substrate_grant_receipt_id)? .ok_or_else(|| anyhow!("Hands authority requires its persisted Substrate grant"))?; let within_scope = authority.requested_paths.iter().all(|path| { - route.source_scope.iter().any(|scope| { + route.authorized_paths.iter().any(|scope| { path == scope || path.starts_with(&format!("{}/", scope.trim_end_matches(['/', '\\']))) }) }); @@ -9721,7 +9718,7 @@ fn validate_repo_frontier_hands_authority_chain( || route .adopted_plan .as_ref() - .is_some_and(|plan| route.source_scope != plan.safe_paths) + .is_some_and(|plan| route.authorized_paths != plan.safe_paths) || !adopted_plan_binding_is_exact || review.intent_id != intent.intent_id || review.decision != "approved" @@ -9761,7 +9758,7 @@ pub fn put_repo_frontier_hands_authority( if authority.schema_version != REPO_FRONTIER_HANDS_AUTHORITY_SCHEMA_VERSION || authority.contract != REPO_FRONTIER_HANDS_AUTHORITY_CONTRACT || chrono::DateTime::parse_from_rfc3339(&authority.granted_at).is_err() - || !safe_sorted_unique_paths(&authority.requested_paths) + || !crate::memory_graph::repo_paths_are_canonical_and_safe(&authority.requested_paths) || authority.requested_paths.is_empty() { return Err(anyhow!("invalid repo frontier Hands authority contract")); @@ -9785,7 +9782,7 @@ pub fn put_repo_frontier_hands_authority( anyhow!("repo frontier Hands authority requires its persisted Substrate grant") })?; let within_scope = authority.requested_paths.iter().all(|path| { - route.source_scope.iter().any(|scope| { + route.authorized_paths.iter().any(|scope| { path == scope || path.starts_with(&format!("{}/", scope.trim_end_matches(['/', '\\']))) }) }); @@ -9867,7 +9864,9 @@ pub fn relinquish_repo_frontier_hands_route( } chrono::DateTime::parse_from_rfc3339(&relinquished_at) .map_err(|_| anyhow!("Hands refusal timestamp must be RFC3339"))?; - if missing_required_paths.is_empty() || !safe_sorted_unique_paths(&missing_required_paths) { + if missing_required_paths.is_empty() + || !crate::memory_graph::repo_paths_are_canonical_and_safe(&missing_required_paths) + { return Err(anyhow!( "Hands refusal paths must be non-empty and canonical" )); @@ -9910,7 +9909,7 @@ pub fn relinquish_repo_frontier_hands_route( .get::(&authority.route_id)? .ok_or_else(|| anyhow!("Hands refusal lost its route"))?; if missing_required_paths.iter().all(|path| { - route.source_scope.iter().any(|scope| { + route.authorized_paths.iter().any(|scope| { path == scope || path.starts_with(&format!("{}/", scope.trim_end_matches(['/', '\\']))) }) }) { @@ -10634,17 +10633,6 @@ pub fn commit_repo_frontier_verification_request_for_chain( Ok(request) } -fn safe_sorted_unique_paths(paths: &[String]) -> bool { - paths.windows(2).all(|pair| pair[0] < pair[1]) - && paths.iter().all(|path| { - !path.is_empty() - && !Path::new(path).is_absolute() - && !Path::new(path) - .components() - .any(|part| matches!(part, std::path::Component::ParentDir)) - }) -} - fn validate_hands_consequence_grant( store_path: &Path, intent_id: &str, diff --git a/epiphany-core/src/surfaces/worker_launch.rs b/epiphany-core/src/surfaces/worker_launch.rs index 33dd6a22..5e40346f 100644 --- a/epiphany-core/src/surfaces/worker_launch.rs +++ b/epiphany-core/src/surfaces/worker_launch.rs @@ -149,7 +149,7 @@ pub struct RepoFrontierResearchContextProjection { pub frontier_authority_documents: Vec, pub frontier_item_id: String, pub frontier_item_hash: String, - pub source_scope: Vec, + pub repository_scope: Vec, #[serde(default)] pub public_source_refs: Vec, pub contract: String, @@ -165,7 +165,7 @@ impl From<&crate::RepoFrontierResearchRequest> for RepoFrontierResearchContextPr frontier_authority_documents: request.frontier_authority_documents.clone(), frontier_item_id: request.frontier_item_id.clone(), frontier_item_hash: request.frontier_item_hash.clone(), - source_scope: request.source_scope.clone(), + repository_scope: request.repository_scope.clone(), public_source_refs: request.public_source_refs.clone(), contract: REPO_FRONTIER_RESEARCH_CONTEXT_CONTRACT.to_string(), } @@ -224,7 +224,7 @@ pub struct RepoFrontierPlanningContextProjection { pub frontier_item_hash: String, pub selected_organ: String, #[serde(default)] - pub source_scope: Vec, + pub repository_scope: Vec, pub requested_at: String, pub runtime_id: String, pub frontier_authority_documents: Vec, @@ -242,7 +242,7 @@ impl RepoFrontierPlanningContextProjection { frontier_item_id: request.frontier_item_id.clone(), frontier_item_hash: request.frontier_item_hash.clone(), selected_organ: request.selected_organ.clone(), - source_scope: request.source_scope.clone(), + repository_scope: request.repository_scope.clone(), requested_at: request.requested_at.clone(), runtime_id: request.runtime_id.clone(), frontier_authority_documents: request.frontier_authority_documents.clone(), diff --git a/epiphany-openai-runtime/src/lib.rs b/epiphany-openai-runtime/src/lib.rs index e3f5441a..d48e667e 100644 --- a/epiphany-openai-runtime/src/lib.rs +++ b/epiphany-openai-runtime/src/lib.rs @@ -1774,7 +1774,7 @@ fn worker_output_contract_text( EpiphanyWorkerLaunchDocument::Role(document) if document.frontier_planning_context.is_some() => { - "Required frontier-planning result fields: roleId, verdict, summary, nextSafeMove, filesInspected, frontierPlanCandidate. Emit only the semantic plan content. Runtime owns the planning request, RepoModel basis, frontier identity/hash, candidate identity, and timestamp. frontierPlanCandidate.safe_paths may narrow but must never expand the immutable source_scope: every safe path must exactly equal a source_scope entry or be a descendant of one, in strict lexicographic order without duplicates. Do not include adjacent files merely because the plan would benefit from them; identify them as a stop condition instead. Do not emit generic Mind patches, selfPatch, or repoModelOperations." + "Required frontier-planning result fields: roleId, verdict, summary, nextSafeMove, filesInspected, frontierPlanCandidate. Emit only the semantic plan content. Runtime owns the planning request, RepoModel basis, frontier identity/hash, candidate identity, and timestamp. frontierPlanCandidate.safe_paths may narrow but must never expand the immutable repository_scope: every safe path must exactly equal a repository_scope entry or be a descendant of one, in strict lexicographic order without duplicates. Do not include adjacent files merely because the plan would benefit from them; identify them as a stop condition instead. Do not emit generic Mind patches, selfPatch, or repoModelOperations." } EpiphanyWorkerLaunchDocument::Role(document) if document @@ -1799,7 +1799,7 @@ fn worker_output_contract_text( "Required Verification fields: roleId=verification, verdict, summary, nextSafeMove, filesInspected, evidenceIds, and risks. Audit only the exact typed request, route, and Hands receipts in the sealed projection. Runtime owns request and route identity; do not emit identity, generic Mind patches, repoModelOperations, commands, release, or deployment cargo." } EpiphanyWorkerLaunchDocument::Role(_) => { - "Required role-result fields: roleId, verdict, summary, nextSafeMove, filesInspected. Research emits one researchDecision containing only its exact evidence, grounded observations, and optional investigation checkpoint. Modeling emits repoModelOperations, an array of semantic keyed operations; use an empty array when no RepoModel mutation is proposed. Never emit proposal ids, model revisions or hashes, timestamps, strong reads, writes, receipts, or generic state patches. For ordinary Modeling, checkpoint-update-needed is a typed claim that the Body map contains a future design gap: encode exactly one PutFrontier operation with a new active, unadopted frontier, recommended_next_organ=Imagination, empty dependency_item_ids, safe non-empty source_scope, and evidence_refs grounded in top-level evidenceIds. checkpoint-ready may carry only local Atlas offer/claim transitions or an empty operation array; regather-needed requires an empty operation array. Neither may mutate frontier. nextSafeMove is display-only and never routes an organ. Use arrays for frontierNodeIds, evidenceIds, openQuestions, evidenceGaps, risks, and artifactRefs when present." + "Required role-result fields: roleId, verdict, summary, nextSafeMove, filesInspected. Research emits one researchDecision containing only its exact evidence, grounded observations, and optional investigation checkpoint. Modeling emits repoModelOperations, an array of semantic keyed operations; use an empty array when no RepoModel mutation is proposed. Never emit proposal ids, model revisions or hashes, timestamps, strong reads, writes, receipts, or generic state patches. For ordinary Modeling, checkpoint-update-needed is a typed claim that the Body map contains a future design gap: encode exactly one PutFrontier operation with a new active, unadopted frontier, recommended_next_organ=Imagination, empty dependency_item_ids, a safe non-empty repository_scope, and evidence_refs grounded in top-level evidenceIds. repository_scope is the strict sorted repository-relative path ceiling that downstream Planning may authorize Hands to change; include intended outputs, including files that do not yet exist, and do not substitute filesInspected or evidence sources. checkpoint-ready may carry only local Atlas offer/claim transitions or an empty operation array; regather-needed requires an empty operation array. Neither may mutate frontier. nextSafeMove is display-only and never routes an organ. Use arrays for frontierNodeIds, evidenceIds, openQuestions, evidenceGaps, risks, and artifactRefs when present." } EpiphanyWorkerLaunchDocument::Reorient(_) => { "Required reorient-result fields: mode, summary, nextSafeMove. Include checkpointStillValid, filesInspected, frontierNodeIds, evidenceIds, openQuestions, and continuityRisks when present." @@ -1842,7 +1842,7 @@ struct ProposalFrontierDraftIngress { question: String, gap: String, target_claim_ids: Vec, - source_scope: Vec, + repository_scope: Vec, recommended_next_organ: String, dependency_item_ids: Vec, evidence_refs: Vec, @@ -2037,9 +2037,9 @@ fn role_worker_result_from_ingress( let mut target_claim_ids = clean_string_vec(&draft.target_claim_ids); target_claim_ids.sort(); target_claim_ids.dedup(); - let mut source_scope = clean_string_vec(&draft.source_scope); - source_scope.sort(); - source_scope.dedup(); + let mut repository_scope = clean_string_vec(&draft.repository_scope); + repository_scope.sort(); + repository_scope.dedup(); let mut dependency_item_ids = clean_string_vec(&draft.dependency_item_ids); dependency_item_ids.sort(); dependency_item_ids.dedup(); @@ -2059,7 +2059,7 @@ fn role_worker_result_from_ingress( question: draft.question.trim().to_string(), gap: draft.gap.trim().to_string(), target_claim_ids, - source_scope, + repository_scope, recommended_next_organ: draft.recommended_next_organ.trim().to_string(), adopted_plan: None, dependency_item_ids, @@ -3030,7 +3030,7 @@ mod tests { question: "Does exact grant state own launchability?".into(), gap: "Broader autonomous turnover remains open.".into(), target_claim_ids: vec!["claim-grant-owned".into()], - source_scope: vec!["epiphany-core/src/resident_self.rs".into()], + repository_scope: vec!["epiphany-core/src/resident_self.rs".into()], recommended_next_organ: "Eyes".into(), dependency_item_ids: Vec::new(), evidence_refs: vec!["tool:grant-lifecycle".into()], @@ -3428,7 +3428,7 @@ mod tests { frontier_item_id: "frontier-1".into(), frontier_item_hash: "frontier-hash".into(), selected_organ: "Imagination".into(), - source_scope: vec!["src".into(), "tests".into()], + repository_scope: vec!["src".into(), "tests".into()], requested_at: "2026-07-15T09:59:00Z".into(), runtime_id: "runtime-1".into(), }; @@ -3774,7 +3774,7 @@ mod tests { frontier_item_id: "frontier-1".into(), frontier_item_hash: "frontier-hash-1".into(), selected_organ: "Imagination".into(), - source_scope: vec!["epiphany-openai-runtime".into()], + repository_scope: vec!["epiphany-openai-runtime".into()], requested_at: "2026-07-15T09:58:00Z".into(), contract: epiphany_core::REPO_FRONTIER_PLANNING_CONTRACT.into(), runtime_id: "runtime-1".into(), @@ -4013,7 +4013,7 @@ mod tests { question: "Did the verified consequence hold?".to_string(), gap: "Awaiting verdict incorporation.".to_string(), target_claim_ids: vec!["claim-1".to_string()], - source_scope: vec!["epiphany-core".to_string()], + repository_scope: vec!["epiphany-core".to_string()], recommended_next_organ: "Hands".to_string(), adopted_plan: None, dependency_item_ids: Vec::new(), @@ -4054,7 +4054,7 @@ mod tests { question: frontier_item.question.clone(), gap: frontier_item.gap.clone(), target_claim_ids: frontier_item.target_claim_ids.clone(), - source_scope: frontier_item.source_scope.clone(), + authorized_paths: frontier_item.repository_scope.clone(), adopted_plan: frontier_item.adopted_plan.clone(), selected_at: "2026-08-08T00:00:00Z".into(), contract: epiphany_core::REPO_FRONTIER_ROUTE_CONTRACT.into(), diff --git a/epiphany-state-model/src/lib.rs b/epiphany-state-model/src/lib.rs index bb2eafa6..c16d9d01 100644 --- a/epiphany-state-model/src/lib.rs +++ b/epiphany-state-model/src/lib.rs @@ -699,7 +699,10 @@ pub struct RepoFrontierItem { pub target_claim_ids: Vec, #[serde(default, skip_serializing_if = "Vec::is_empty")] #[ts(type = "Array")] - pub source_scope: Vec, + /// Canonical repository-relative path ceiling for this wound. This is the + /// scope that downstream Planning may narrow and Hands may eventually + /// change; inspected files and evidence provenance belong elsewhere. + pub repository_scope: Vec, pub recommended_next_organ: String, /// The exact plan admitted by Mind for this frontier item. Imagination may /// propose this payload, but only the dedicated model transition may make @@ -800,7 +803,7 @@ pub fn reorient_checkpoint_from_admitted_repo_model( .frontier .iter() .filter(|item| item.status == RepoFrontierStatus::Active) - .flat_map(|item| item.source_scope.iter()) + .flat_map(|item| item.repository_scope.iter()) .map(|path| EpiphanyCodeRef { path: path.into(), start_line: None,