Feed local Verse context into bridge launches
This commit is contained in:
parent
edd93a11b9
commit
ece708b76f
11 changed files with 174 additions and 16 deletions
|
|
@ -1,9 +1,9 @@
|
|||
use epiphany_core::EPIPHANY_IMAGINATION_OWNER_ROLE;
|
||||
use epiphany_core::EPIPHANY_IMAGINATION_ROLE_BINDING_ID;
|
||||
use epiphany_core::EPIPHANY_MODELING_ROLE_BINDING_ID;
|
||||
use epiphany_core::EPIPHANY_RESEARCH_ROLE_BINDING_ID;
|
||||
use epiphany_core::EPIPHANY_REORIENT_LAUNCH_BINDING_ID;
|
||||
use epiphany_core::EPIPHANY_REORIENT_OWNER_ROLE;
|
||||
use epiphany_core::EPIPHANY_RESEARCH_ROLE_BINDING_ID;
|
||||
use epiphany_core::EPIPHANY_VERIFICATION_ROLE_BINDING_ID;
|
||||
use epiphany_core::EpiphanyCoordinatorAutomationAction as CoreEpiphanyCoordinatorAutomationAction;
|
||||
use epiphany_core::EpiphanyCoordinatorDecision as CoreEpiphanyCoordinatorDecision;
|
||||
|
|
@ -31,7 +31,7 @@ use epiphany_core::EpiphanyRoleBoardLane;
|
|||
use epiphany_core::EpiphanyRoleBoardPlanningSummary;
|
||||
use epiphany_core::EpiphanyRoleResultRoleId;
|
||||
use epiphany_core::EpiphanyTokenUsageSnapshot;
|
||||
use epiphany_core::build_epiphany_reorient_launch_request;
|
||||
use epiphany_core::build_epiphany_reorient_launch_request_with_dynamic_context;
|
||||
use epiphany_core::derive_coordinator_finding_signals;
|
||||
use epiphany_core::derive_coordinator_status;
|
||||
use epiphany_core::derive_role_board;
|
||||
|
|
@ -43,6 +43,8 @@ use epiphany_core::select_coordinator_automation_action;
|
|||
use epiphany_state_model::EpiphanyRetrievalState;
|
||||
use epiphany_state_model::EpiphanyThreadState;
|
||||
|
||||
use crate::launch_context::render_launch_dynamic_prompt_context;
|
||||
use crate::launch_context::reorient_launch_context_focus;
|
||||
use crate::pressure::derive_epiphany_pressure;
|
||||
use crate::reorient::EpiphanyFreshnessWatcherSnapshot;
|
||||
use crate::reorient::derive_epiphany_freshness_view;
|
||||
|
|
@ -296,13 +298,20 @@ pub async fn select_epiphany_coordinator_automation(
|
|||
.investigation_checkpoint
|
||||
.as_ref()
|
||||
.map(|checkpoint| {
|
||||
build_epiphany_reorient_launch_request(
|
||||
let dynamic_prompt_context = render_launch_dynamic_prompt_context(
|
||||
input.runtime_store_path,
|
||||
input.state,
|
||||
reorient_launch_context_focus(input.state, &reorient_decision.next_action),
|
||||
)
|
||||
.ok();
|
||||
build_epiphany_reorient_launch_request_with_dynamic_context(
|
||||
input.thread_id,
|
||||
Some(input.state.revision),
|
||||
None,
|
||||
input.state,
|
||||
checkpoint,
|
||||
&reorient_decision,
|
||||
dynamic_prompt_context,
|
||||
)
|
||||
}),
|
||||
EpiphanyCoordinatorAutomationAction::None
|
||||
|
|
|
|||
|
|
@ -8,10 +8,10 @@ pub use epiphany_core::EPIPHANY_IMAGINATION_OWNER_ROLE;
|
|||
pub use epiphany_core::EPIPHANY_IMAGINATION_ROLE_BINDING_ID;
|
||||
pub use epiphany_core::EPIPHANY_MODELING_OWNER_ROLE;
|
||||
pub use epiphany_core::EPIPHANY_MODELING_ROLE_BINDING_ID;
|
||||
pub use epiphany_core::EPIPHANY_RESEARCH_OWNER_ROLE;
|
||||
pub use epiphany_core::EPIPHANY_RESEARCH_ROLE_BINDING_ID;
|
||||
pub use epiphany_core::EPIPHANY_REORIENT_LAUNCH_BINDING_ID;
|
||||
pub use epiphany_core::EPIPHANY_REORIENT_OWNER_ROLE;
|
||||
pub use epiphany_core::EPIPHANY_RESEARCH_OWNER_ROLE;
|
||||
pub use epiphany_core::EPIPHANY_RESEARCH_ROLE_BINDING_ID;
|
||||
pub use epiphany_core::EPIPHANY_VERIFICATION_OWNER_ROLE;
|
||||
pub use epiphany_core::EPIPHANY_VERIFICATION_ROLE_BINDING_ID;
|
||||
pub use epiphany_core::EpiphanyCoordinatorPromptConfig;
|
||||
|
|
|
|||
117
epiphany-codex-bridge/src/launch_context.rs
Normal file
117
epiphany-codex-bridge/src/launch_context.rs
Normal file
|
|
@ -0,0 +1,117 @@
|
|||
use chrono::SecondsFormat;
|
||||
use chrono::Utc;
|
||||
use epiphany_core::EpiphanyMemoryContextPacket;
|
||||
use epiphany_core::EpiphanyPromptContextInput;
|
||||
use epiphany_core::EpiphanyThreadState;
|
||||
use epiphany_core::query_epiphany_local_verse_context;
|
||||
use epiphany_core::render_epiphany_prompt_context;
|
||||
use epiphany_core::seed_epiphany_local_verse_context;
|
||||
use std::path::Path;
|
||||
use std::path::PathBuf;
|
||||
|
||||
pub const EPIPHANY_LOCAL_VERSE_RUNTIME_ID: &str = "epiphany-local";
|
||||
|
||||
pub fn local_verse_store_path(runtime_store_path: &Path) -> PathBuf {
|
||||
runtime_store_path
|
||||
.parent()
|
||||
.unwrap_or_else(|| Path::new("."))
|
||||
.join("local-verse.ccmp")
|
||||
}
|
||||
|
||||
pub fn role_launch_context_focus(state: &EpiphanyThreadState, role_label: &str) -> String {
|
||||
let objective = state
|
||||
.objective
|
||||
.as_deref()
|
||||
.map(str::trim)
|
||||
.filter(|objective| !objective.is_empty())
|
||||
.unwrap_or("Epiphany worker launch");
|
||||
format!("Launch `{role_label}` worker for: {objective}")
|
||||
}
|
||||
|
||||
pub fn reorient_launch_context_focus(state: &EpiphanyThreadState, next_action: &str) -> String {
|
||||
let objective = state
|
||||
.objective
|
||||
.as_deref()
|
||||
.map(str::trim)
|
||||
.filter(|objective| !objective.is_empty())
|
||||
.unwrap_or("Epiphany reorientation");
|
||||
format!("Launch reorientation worker for: {objective}. Next action: {next_action}")
|
||||
}
|
||||
|
||||
pub fn render_launch_dynamic_prompt_context(
|
||||
runtime_store_path: &Path,
|
||||
state: &EpiphanyThreadState,
|
||||
focus: String,
|
||||
) -> Result<String, String> {
|
||||
let local_verse_store = local_verse_store_path(runtime_store_path);
|
||||
seed_epiphany_local_verse_context(
|
||||
&local_verse_store,
|
||||
EPIPHANY_LOCAL_VERSE_RUNTIME_ID,
|
||||
Utc::now().to_rfc3339_opts(SecondsFormat::Secs, true),
|
||||
)
|
||||
.map_err(|error| {
|
||||
format!(
|
||||
"failed to seed local Verse context store {}: {error}",
|
||||
local_verse_store.display()
|
||||
)
|
||||
})?;
|
||||
let local_verse =
|
||||
query_epiphany_local_verse_context(&local_verse_store, EPIPHANY_LOCAL_VERSE_RUNTIME_ID)
|
||||
.map_err(|error| {
|
||||
format!(
|
||||
"failed to query local Verse context store {}: {error}",
|
||||
local_verse_store.display()
|
||||
)
|
||||
})?;
|
||||
let memory_context = EpiphanyMemoryContextPacket {
|
||||
id: format!("memctx-launch-state-rev-{}", state.revision),
|
||||
query_id: "bridge-launch-local-verse-only".to_string(),
|
||||
warnings: vec![
|
||||
"Semantic memory graph context is not connected to this bridge launch path yet; this packet carries local Verse context only.".to_string(),
|
||||
],
|
||||
..Default::default()
|
||||
};
|
||||
Ok(render_epiphany_prompt_context(
|
||||
&EpiphanyPromptContextInput {
|
||||
focus,
|
||||
local_verse,
|
||||
memory_context,
|
||||
},
|
||||
))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use std::fs;
|
||||
use uuid::Uuid;
|
||||
|
||||
#[test]
|
||||
fn launch_context_renders_local_verse_packet() -> anyhow::Result<()> {
|
||||
let temp =
|
||||
std::env::temp_dir().join(format!("epiphany-bridge-launch-context-{}", Uuid::new_v4()));
|
||||
fs::create_dir_all(&temp)?;
|
||||
let runtime_store = temp.join("runtime-spine.msgpack");
|
||||
let state = EpiphanyThreadState {
|
||||
revision: 7,
|
||||
objective: Some("Test launch context.".to_string()),
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let rendered = render_launch_dynamic_prompt_context(
|
||||
&runtime_store,
|
||||
&state,
|
||||
role_launch_context_focus(&state, "modeling"),
|
||||
)
|
||||
.map_err(anyhow::Error::msg)?;
|
||||
|
||||
assert!(rendered.contains("<epiphany_dynamic_context>"));
|
||||
assert!(rendered.contains("Test launch context."));
|
||||
assert!(rendered.contains("Odin"));
|
||||
assert!(rendered.contains("Yggdrasil"));
|
||||
assert!(rendered.contains("local Verse context only"));
|
||||
assert!(local_verse_store_path(&runtime_store).exists());
|
||||
fs::remove_dir_all(&temp)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
@ -25,6 +25,7 @@ pub mod error;
|
|||
pub mod invalidation;
|
||||
pub mod jobs;
|
||||
pub mod launch;
|
||||
pub mod launch_context;
|
||||
pub mod mutation;
|
||||
pub mod mutation_service;
|
||||
pub mod pressure;
|
||||
|
|
|
|||
|
|
@ -31,8 +31,8 @@ use epiphany_core::RuntimeSpineHeartbeatLaunchPlanOptions;
|
|||
use epiphany_core::SOUL_VERDICT_RECEIPT_TYPE;
|
||||
use epiphany_core::SUBSTRATE_GATE_REPO_ACCESS_GRANT_RECEIPT_TYPE;
|
||||
use epiphany_core::apply_epiphany_state_update;
|
||||
use epiphany_core::build_epiphany_reorient_launch_request;
|
||||
use epiphany_core::build_epiphany_role_launch_request;
|
||||
use epiphany_core::build_epiphany_reorient_launch_request_with_dynamic_context;
|
||||
use epiphany_core::build_epiphany_role_launch_request_with_dynamic_context;
|
||||
use epiphany_core::clear_epiphany_job_binding_backend;
|
||||
use epiphany_core::continuity_recovery_receipt_from_reorient_finding;
|
||||
use epiphany_core::epiphany_role_label;
|
||||
|
|
@ -73,6 +73,9 @@ use crate::jobs::derive_epiphany_jobs;
|
|||
use crate::jobs::epiphany_blocked_state_job;
|
||||
use crate::jobs::map_interrupted_epiphany_job;
|
||||
use crate::jobs::map_launched_epiphany_job;
|
||||
use crate::launch_context::render_launch_dynamic_prompt_context;
|
||||
use crate::launch_context::reorient_launch_context_focus;
|
||||
use crate::launch_context::role_launch_context_focus;
|
||||
use crate::mutation::build_reorient_acceptance_update;
|
||||
use crate::mutation::build_role_acceptance_update;
|
||||
use crate::mutation::epiphany_job_launch_changed_fields;
|
||||
|
|
@ -698,12 +701,22 @@ pub async fn launch_thread_epiphany_role(
|
|||
.to_string(),
|
||||
)
|
||||
})?;
|
||||
let launch_request = build_epiphany_role_launch_request(
|
||||
validate_expected_revision(expected_revision, state.revision)?;
|
||||
let runtime_store_path = thread.epiphany_runtime_spine_store_path().await;
|
||||
let role_label = epiphany_role_label(role_id);
|
||||
let dynamic_prompt_context = render_launch_dynamic_prompt_context(
|
||||
runtime_store_path.as_path(),
|
||||
&state,
|
||||
role_launch_context_focus(&state, role_label),
|
||||
)
|
||||
.map_err(EpiphanyBridgeError::Fatal)?;
|
||||
let launch_request = build_epiphany_role_launch_request_with_dynamic_context(
|
||||
thread_id,
|
||||
role_id,
|
||||
expected_revision,
|
||||
max_runtime_seconds,
|
||||
&state,
|
||||
Some(dynamic_prompt_context),
|
||||
)
|
||||
.map_err(EpiphanyBridgeError::InvalidRequest)?;
|
||||
launch_thread_epiphany_job(
|
||||
|
|
@ -801,6 +814,7 @@ pub async fn launch_thread_epiphany_reorient(
|
|||
decision.note
|
||||
))
|
||||
})?;
|
||||
validate_expected_revision(expected_revision, state.revision)?;
|
||||
let checkpoint = state.investigation_checkpoint.as_ref().ok_or_else(|| {
|
||||
EpiphanyBridgeError::InvalidRequest(format!(
|
||||
"cannot launch a reorientation worker without a durable investigation checkpoint: {}",
|
||||
|
|
@ -808,13 +822,21 @@ pub async fn launch_thread_epiphany_reorient(
|
|||
))
|
||||
})?;
|
||||
|
||||
let launch_request = build_epiphany_reorient_launch_request(
|
||||
let runtime_store_path = thread.epiphany_runtime_spine_store_path().await;
|
||||
let dynamic_prompt_context = render_launch_dynamic_prompt_context(
|
||||
runtime_store_path.as_path(),
|
||||
state,
|
||||
reorient_launch_context_focus(state, &decision.next_action),
|
||||
)
|
||||
.map_err(EpiphanyBridgeError::Fatal)?;
|
||||
let launch_request = build_epiphany_reorient_launch_request_with_dynamic_context(
|
||||
thread_id,
|
||||
expected_revision,
|
||||
max_runtime_seconds,
|
||||
state,
|
||||
checkpoint,
|
||||
&decision,
|
||||
Some(dynamic_prompt_context),
|
||||
);
|
||||
let changed_fields = epiphany_job_launch_changed_fields();
|
||||
let launched = launch_epiphany_job_on_thread(thread, launch_request).await?;
|
||||
|
|
|
|||
|
|
@ -492,7 +492,10 @@ pub fn load_launch_organ_contract_for_runtime_job(
|
|||
)));
|
||||
}
|
||||
if request.organ_launch_contract.dependencies.is_empty()
|
||||
|| request.organ_launch_contract.receipt_proof_profiles.is_empty()
|
||||
|| request
|
||||
.organ_launch_contract
|
||||
.receipt_proof_profiles
|
||||
.is_empty()
|
||||
{
|
||||
return Err(EpiphanyBridgeError::InvalidRequest(format!(
|
||||
"cannot accept runtime job {:?}: worker launch request has no organ dependency/proof-profile contract",
|
||||
|
|
|
|||
Reference in a new issue