diff --git a/epiphany-core/src/coordinator_acceptance.rs b/epiphany-core/src/coordinator_acceptance.rs index b2142be1..d8a229e7 100644 --- a/epiphany-core/src/coordinator_acceptance.rs +++ b/epiphany-core/src/coordinator_acceptance.rs @@ -25,6 +25,7 @@ impl std::error::Error for EpiphanyCoordinatorAdmissionError {} /// Codex compatibility surfaces may translate requests into calls on this /// service, but they do not receive a persistence hook or retain an independent /// state opinion. +#[derive(Debug, Clone)] pub struct EpiphanyRoleAcceptanceUpdate { pub state_update: EpiphanyStateUpdate, pub applied_patch: EpiphanyRoleStatePatchDocument, @@ -35,6 +36,7 @@ pub struct EpiphanyRoleAcceptanceUpdate { pub mind_review: MindGatewayReview, } +#[derive(Debug, Clone)] pub struct EpiphanyReorientAcceptanceUpdate { pub state_update: EpiphanyStateUpdate, pub changed_fields: Vec, @@ -44,6 +46,112 @@ pub struct EpiphanyReorientAcceptanceUpdate { pub mind_review: MindGatewayReview, } +#[derive(Debug, Clone)] +pub struct EpiphanyNativeRoleAcceptance { + pub state: EpiphanyThreadState, + pub finding: EpiphanyRoleFindingInterpretation, + pub update: EpiphanyRoleAcceptanceUpdate, +} + +pub fn accept_coordinator_role_finding( + store: &Path, + thread_id: &str, + state: &EpiphanyThreadState, + role_id: EpiphanyRoleResultRoleId, + binding_id: &str, + expected_revision: Option, + reference_turn_id: Option, + accepted_at: String, + nonce: &str, +) -> anyhow::Result { + let snapshot = read_role_result_snapshot(Some(state), Some(store), role_id, binding_id); + if snapshot.status != EpiphanyCoordinatorRoleResultStatus::Completed { + return Err(anyhow::anyhow!( + "role finding is not completed: {}", + snapshot.note + )); + } + let finding = snapshot + .finding + .ok_or_else(|| anyhow::anyhow!("completed role result has no typed finding"))?; + let label = role_label_lower(role_id); + let update = build_native_role_acceptance_update( + expected_revision, + role_id, + binding_id, + &finding, + format!("ev-{label}-{nonce}"), + format!("obs-{label}-{nonce}"), + accepted_at.clone(), + ) + .map_err(anyhow::Error::msg)?; + let contract = acceptance_launch_contract_for_binding(store, state, binding_id, "role") + .map_err(|error| anyhow::anyhow!(error.to_string()))?; + let mut available = vec![MIND_GATEWAY_REVIEW_TYPE.to_string()]; + let mut prerequisites = Vec::new(); + if role_id == EpiphanyRoleResultRoleId::Research { + let packet = eyes_evidence_packet_from_research_finding( + format!("eyes-packet-{}", update.accepted_receipt_id), + &finding, + &update.applied_patch, + accepted_at.clone(), + ); + available.push(EYES_EVIDENCE_PACKET_TYPE.to_string()); + prerequisites.push(EpiphanyAcceptancePrerequisite::Eyes(packet)); + let grant_id = format!( + "substrate-grant-{}", + finding.runtime_job_id.as_deref().unwrap_or_default() + ); + if runtime_substrate_gate_repo_access_grant_receipt(store, &grant_id)?.is_some() { + available.push(SUBSTRATE_GATE_REPO_ACCESS_GRANT_RECEIPT_TYPE.to_string()); + } + } else if role_id == EpiphanyRoleResultRoleId::Verification { + let verdict = soul_verdict_receipt_from_verification_finding( + format!("soul-verdict-{}", update.accepted_receipt_id), + &finding, + accepted_at.clone(), + ); + available.push(SOUL_VERDICT_RECEIPT_TYPE.to_string()); + prerequisites.push(EpiphanyAcceptancePrerequisite::Soul(verdict)); + } + enforce_acceptance_receipt_proofs( + &contract, + &role_acceptance_claimed_effects(role_id, &update.changed_fields), + &available, + &role_acceptance_enforceable_receipts(role_id), + ) + .map_err(|error| anyhow::anyhow!(error.to_string()))?; + let next_state = apply_coordinator_state_update_to_state( + state, + update.state_update.clone(), + reference_turn_id, + )?; + let commit = mind_state_commit_receipt( + format!("mind-commit-{}", update.accepted_receipt_id), + &update.mind_review, + next_state.revision, + update + .changed_fields + .iter() + .map(|field| format!("{field:?}")) + .collect(), + accepted_at, + ); + commit_state_with_mind_witness( + store, + thread_id, + &next_state, + &update.mind_review, + &commit, + &prerequisites, + )?; + Ok(EpiphanyNativeRoleAcceptance { + state: next_state, + finding, + update, + }) +} + pub fn completed_role_finding( runtime_store_path: Option<&Path>, state: &EpiphanyThreadState, diff --git a/epiphany-core/src/coordinator_service.rs b/epiphany-core/src/coordinator_service.rs index 88dd023a..908d1079 100644 --- a/epiphany-core/src/coordinator_service.rs +++ b/epiphany-core/src/coordinator_service.rs @@ -1,9 +1,15 @@ use crate::EpiphanyCoordinatorReorientResultSnapshot; use crate::EpiphanyCoordinatorRoleResultSnapshot; use crate::EpiphanyCoordinatorStateApplied; +use crate::EpiphanyJobLaunchRequest; +use crate::EpiphanyJobLaunchResult; +use crate::EpiphanyNativeRoleAcceptance; use crate::EpiphanyRoleResultRoleId; use crate::EpiphanyStateUpdate; +use crate::accept_coordinator_role_finding; use crate::apply_coordinator_state_update; +use crate::commit_coordinator_job_launch; +use crate::plan_coordinator_job_launch; use crate::read_coordinator_state; use crate::read_reorient_result_snapshot; use crate::read_role_result_snapshot; @@ -77,6 +83,56 @@ impl EpiphanyCoordinatorService { reference_turn_id, ) } + + pub fn launch_job( + &self, + thread_id: &str, + state: &EpiphanyThreadState, + request: &EpiphanyJobLaunchRequest, + launcher_job_id: String, + backend_job_id: String, + created_at: String, + ) -> Result { + let plan = plan_coordinator_job_launch( + state, + request, + &self.runtime_spine_store, + launcher_job_id, + backend_job_id, + )?; + commit_coordinator_job_launch( + &self.runtime_spine_store, + thread_id, + state, + request, + &plan, + created_at, + ) + } + + pub fn accept_role( + &self, + thread_id: &str, + state: &EpiphanyThreadState, + role_id: EpiphanyRoleResultRoleId, + binding_id: &str, + expected_revision: Option, + reference_turn_id: Option, + accepted_at: String, + nonce: &str, + ) -> Result { + accept_coordinator_role_finding( + &self.runtime_spine_store, + thread_id, + state, + role_id, + binding_id, + expected_revision, + reference_turn_id, + accepted_at, + nonce, + ) + } } #[cfg(test)] @@ -86,7 +142,7 @@ mod tests { let source = include_str!("coordinator_service.rs"); let production = source.split("#[cfg(test)]").next().unwrap_or(source); assert!( - production.lines().count() < 90, + production.lines().count() < 140, "coordinator facade regrew into a host brain" ); for forbidden in [ diff --git a/epiphany-core/src/lib.rs b/epiphany-core/src/lib.rs index de5fc8ac..78b4446d 100644 --- a/epiphany-core/src/lib.rs +++ b/epiphany-core/src/lib.rs @@ -126,8 +126,10 @@ pub use agent_utterance_state::derive_agent_utterance_state; pub use continuity_gateway::*; pub use coordinator_acceptance::EpiphanyAcceptancePrerequisite; pub use coordinator_acceptance::EpiphanyCoordinatorAdmissionError; +pub use coordinator_acceptance::EpiphanyNativeRoleAcceptance; pub use coordinator_acceptance::EpiphanyReorientAcceptanceUpdate; pub use coordinator_acceptance::EpiphanyRoleAcceptanceUpdate; +pub use coordinator_acceptance::accept_coordinator_role_finding; pub use coordinator_acceptance::acceptance_launch_contract_for_binding; pub use coordinator_acceptance::build_native_reorient_acceptance_update; pub use coordinator_acceptance::build_native_role_acceptance_update; diff --git a/notes/fresh-workspace-handoff.md b/notes/fresh-workspace-handoff.md index 79134fe6..d220c197 100644 --- a/notes/fresh-workspace-handoff.md +++ b/notes/fresh-workspace-handoff.md @@ -1841,6 +1841,14 @@ Hands evidence projection, and absence of bridge/AppServer/JSON dependencies. Do not rewire the coordinator through the context-free launch builders: use this native context organ so Codex starvation does not starve the workers too. +`EpiphanyCoordinatorService` now exposes native `launch_job` and `accept_role` +actuators. The latter owns the complete role-accept path: typed result readback, +policy-shaped acceptance update, launch-contract proof enforcement, Research +Substrate Gate/Eyes or Verification/Soul prerequisites, Mind commit witness, +and atomic state publication. Thirteen focused coordinator tests pass. The +compatibility bridge still contains its older copy of that orchestration; cut +that copy before rewiring `epiphany-mvp-coordinator`, or authority remains split. + ## Immediate Re-entry Instruction After compaction, first rehydrate and reorient from the listed files and git diff --git a/notes/native-coordinator-liberation-map.md b/notes/native-coordinator-liberation-map.md index 3d28c8d4..eaaa50db 100644 --- a/notes/native-coordinator-liberation-map.md +++ b/notes/native-coordinator-liberation-map.md @@ -160,6 +160,13 @@ work-loop telemetry, and bounded prompt rendering. The compatibility bridge's `launch_context` module is only a re-export membrane. Coordinator rewiring must use these same functions; a context-free launch is not an acceptable shortcut. +The coordinator façade now exposes typed `launch_job` and `accept_role` +actuators. `launch_job` composes native planning with the atomic launch commit; +`accept_role` loads the typed completed finding, builds and proof-checks the +Mind-gated acceptance, and atomically publishes state plus witnesses. Callers +must delegate to these methods rather than replaying their choreography. The +compatibility bridge's role-accept body is the next obsolete policy copy to cut. + ## Acceptance Transaction Wound The compatibility bridge currently persists prerequisite receipts, writes diff --git a/state/ledgers.msgpack b/state/ledgers.msgpack index ba3fc236..a197e074 100644 Binary files a/state/ledgers.msgpack and b/state/ledgers.msgpack differ diff --git a/state/map.yaml b/state/map.yaml index 0a9f38fd..d675d6e0 100644 --- a/state/map.yaml +++ b/state/map.yaml @@ -659,4 +659,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`. Gjallar 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: Remove `thread/epiphany/*` JSON-RPC from `epiphany-mvp-coordinator` by wiring it directly to the native coordinator service and native `coordinator_launch_context`. Launch context, launch persistence, result readback, and acceptance now have native owners; preserve the same Verse, memory, Hands, Soul, and Modeling context when cutting the AppServerClient route. + next_action: Delegate the compatibility bridge's role-accept choreography to `EpiphanyCoordinatorService::accept_role`, then wire `epiphany-mvp-coordinator` directly to the service's typed launch/result/acceptance operations and native launch context. Remove `thread/epiphany/*` and AppServerClient only after the obsolete bridge policy copy is cut.