Delete orphan acceptance surfaces
This commit is contained in:
parent
fb85b9b9fa
commit
ef92e85392
4 changed files with 2 additions and 799 deletions
|
|
@ -654,7 +654,6 @@ pub use substrate_gate::substrate_gate_operation_for_governed_tool;
|
|||
pub use substrate_gate::substrate_gate_repo_access_grant_for_worker;
|
||||
pub use substrate_gate::substrate_gate_repo_work_planning_grant;
|
||||
pub use surfaces::AdmittedModelDirectionConsiderationContextProjection;
|
||||
pub use surfaces::EpiphanyAcceptanceBundle;
|
||||
pub use surfaces::EpiphanyCoordinatorAction;
|
||||
pub use surfaces::EpiphanyCoordinatorAutomationAction;
|
||||
pub use surfaces::EpiphanyCoordinatorCrrcRecommendation;
|
||||
|
|
@ -684,13 +683,10 @@ pub use surfaces::EpiphanyPressure;
|
|||
pub use surfaces::EpiphanyPressureBasis;
|
||||
pub use surfaces::EpiphanyPressureLevel;
|
||||
pub use surfaces::EpiphanyPressureStatus;
|
||||
pub use surfaces::EpiphanyReorientAcceptanceBundle;
|
||||
pub use surfaces::EpiphanyReorientAcceptanceFinding;
|
||||
pub use surfaces::EpiphanyReorientAction;
|
||||
pub use surfaces::EpiphanyReorientFindingInterpretation;
|
||||
pub use surfaces::EpiphanyReorientWorkerLaunchDocument;
|
||||
pub use surfaces::EpiphanyResearchDecision;
|
||||
pub use surfaces::EpiphanyRoleAcceptanceFinding;
|
||||
pub use surfaces::EpiphanyRoleBoardInput;
|
||||
pub use surfaces::EpiphanyRoleBoardJob;
|
||||
pub use surfaces::EpiphanyRoleBoardJobStatus;
|
||||
|
|
@ -712,7 +708,6 @@ pub use surfaces::EpiphanySceneStateStatus;
|
|||
pub use surfaces::EpiphanySceneStatusCount;
|
||||
pub use surfaces::EpiphanySceneSubgoal;
|
||||
pub use surfaces::EpiphanyTokenUsageSnapshot;
|
||||
pub use surfaces::EpiphanyViewLens;
|
||||
pub use surfaces::EpiphanyWorkerLaunchDocument;
|
||||
pub use surfaces::ImaginationConsiderationContextProjection;
|
||||
pub use surfaces::REORIENT_WORKER_OUTPUT_CONTRACT_ID;
|
||||
|
|
@ -732,18 +727,11 @@ pub use surfaces::RepoFrontierPlanningContextProjection;
|
|||
pub use surfaces::RepoFrontierProposalModelingContextProjection;
|
||||
pub use surfaces::RepoFrontierResearchContextProjection;
|
||||
pub use surfaces::RepoFrontierVerificationContextProjection;
|
||||
pub use surfaces::build_reorient_acceptance_bundle;
|
||||
pub use surfaces::build_role_acceptance_bundle;
|
||||
pub use surfaces::default_epiphany_view_lenses;
|
||||
pub use surfaces::derive_jobs;
|
||||
pub use surfaces::derive_planning_view;
|
||||
pub use surfaces::derive_pressure_view;
|
||||
pub use surfaces::derive_role_board;
|
||||
pub use surfaces::derive_scene;
|
||||
pub use surfaces::epiphany_view_needs_jobs;
|
||||
pub use surfaces::epiphany_view_needs_pressure;
|
||||
pub use surfaces::epiphany_view_needs_reorientation_inputs;
|
||||
pub use surfaces::epiphany_view_needs_runtime_store;
|
||||
pub use surfaces::interpret_runtime_reorient_worker_result;
|
||||
pub use surfaces::interpret_runtime_role_worker_result;
|
||||
pub use surfaces::recommend_coordinator_action;
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@ mod research_decision;
|
|||
mod role_board;
|
||||
mod role_result;
|
||||
mod scene;
|
||||
mod view;
|
||||
mod worker_launch;
|
||||
|
||||
pub use coordinator_contract::*;
|
||||
|
|
@ -45,15 +44,9 @@ pub use role_board::EpiphanyRoleBoardLane;
|
|||
pub use role_board::derive_role_board;
|
||||
pub use role_board::render_role_board_note;
|
||||
pub use role_board::role_board_job_status_to_role_status;
|
||||
pub use role_result::EpiphanyAcceptanceBundle;
|
||||
pub use role_result::EpiphanyReorientAcceptanceBundle;
|
||||
pub use role_result::EpiphanyReorientAcceptanceFinding;
|
||||
pub use role_result::EpiphanyReorientFindingInterpretation;
|
||||
pub use role_result::EpiphanyRoleAcceptanceFinding;
|
||||
pub use role_result::EpiphanyRoleFindingInterpretation;
|
||||
pub use role_result::EpiphanyRoleResultRoleId;
|
||||
pub use role_result::build_reorient_acceptance_bundle;
|
||||
pub use role_result::build_role_acceptance_bundle;
|
||||
pub use role_result::interpret_runtime_reorient_worker_result;
|
||||
pub use role_result::interpret_runtime_role_worker_result;
|
||||
pub use scene::EpiphanyScene;
|
||||
|
|
@ -70,12 +63,6 @@ pub use scene::EpiphanySceneStateStatus;
|
|||
pub use scene::EpiphanySceneStatusCount;
|
||||
pub use scene::EpiphanySceneSubgoal;
|
||||
pub use scene::derive_scene;
|
||||
pub use view::EpiphanyViewLens;
|
||||
pub use view::default_epiphany_view_lenses;
|
||||
pub use view::epiphany_view_needs_jobs;
|
||||
pub use view::epiphany_view_needs_pressure;
|
||||
pub use view::epiphany_view_needs_reorientation_inputs;
|
||||
pub use view::epiphany_view_needs_runtime_store;
|
||||
pub use worker_launch::AdmittedModelDirectionConsiderationContextProjection;
|
||||
pub use worker_launch::EpiphanyReorientWorkerLaunchDocument;
|
||||
pub use worker_launch::EpiphanyRoleWorkerLaunchDocument;
|
||||
|
|
|
|||
|
|
@ -37,31 +37,6 @@ pub struct EpiphanyRoleFindingInterpretation {
|
|||
pub proposal_modeling_request_id: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct EpiphanyRoleAcceptanceFinding {
|
||||
pub role_id: EpiphanyRoleResultRoleId,
|
||||
pub verdict: Option<String>,
|
||||
pub summary: Option<String>,
|
||||
pub next_safe_move: Option<String>,
|
||||
pub files_inspected: Vec<String>,
|
||||
pub runtime_result_id: Option<String>,
|
||||
pub runtime_job_id: Option<String>,
|
||||
pub projected_fields: Vec<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct EpiphanyReorientAcceptanceFinding {
|
||||
pub mode: Option<String>,
|
||||
pub summary: Option<String>,
|
||||
pub next_safe_move: Option<String>,
|
||||
pub checkpoint_still_valid: Option<bool>,
|
||||
pub files_inspected: Vec<String>,
|
||||
pub runtime_result_id: Option<String>,
|
||||
pub runtime_job_id: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct EpiphanyReorientFindingInterpretation {
|
||||
|
|
@ -79,130 +54,6 @@ pub struct EpiphanyReorientFindingInterpretation {
|
|||
pub item_error: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct EpiphanyAcceptanceBundle {
|
||||
pub accepted_receipt_id: String,
|
||||
pub accepted_observation_id: String,
|
||||
pub accepted_evidence_id: String,
|
||||
pub evidence: EpiphanyEvidenceRecord,
|
||||
pub observation: EpiphanyObservation,
|
||||
pub receipt: EpiphanyAcceptanceReceipt,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct EpiphanyReorientAcceptanceBundle {
|
||||
pub accepted_receipt_id: String,
|
||||
pub accepted_observation_id: String,
|
||||
pub accepted_evidence_id: String,
|
||||
pub evidence: EpiphanyEvidenceRecord,
|
||||
pub observation: EpiphanyObservation,
|
||||
pub receipt: EpiphanyAcceptanceReceipt,
|
||||
pub scratch: Option<EpiphanyScratchPad>,
|
||||
pub investigation_checkpoint: Option<EpiphanyInvestigationCheckpoint>,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
fn interpret_role_finding(
|
||||
role_id: EpiphanyRoleResultRoleId,
|
||||
raw_result: &serde_json::Value,
|
||||
_retired_generic_patch_parse_error: Option<String>,
|
||||
job_error: Option<String>,
|
||||
item_error: Option<String>,
|
||||
) -> EpiphanyRoleFindingInterpretation {
|
||||
let research_decision_result = raw_result
|
||||
.get("researchDecision")
|
||||
.cloned()
|
||||
.map(serde_json::from_value::<crate::EpiphanyResearchDecision>);
|
||||
let research_decision = research_decision_result
|
||||
.as_ref()
|
||||
.and_then(|result| result.as_ref().ok().cloned());
|
||||
let research_decision_parse_error = research_decision_result
|
||||
.as_ref()
|
||||
.and_then(|result| result.as_ref().err().map(ToString::to_string));
|
||||
let repo_model_mutation_proposal_result = raw_result
|
||||
.get("repoModelMutationProposal")
|
||||
.cloned()
|
||||
.map(serde_json::from_value::<crate::EpiphanyRepoModelMutationProposal>);
|
||||
let repo_model_mutation_proposal = repo_model_mutation_proposal_result
|
||||
.as_ref()
|
||||
.and_then(|result| result.as_ref().ok().cloned());
|
||||
let repo_model_mutation_proposal_parse_error = repo_model_mutation_proposal_result
|
||||
.as_ref()
|
||||
.and_then(|result| result.as_ref().err().map(ToString::to_string));
|
||||
let item_error = match role_id {
|
||||
EpiphanyRoleResultRoleId::Imagination => item_error,
|
||||
EpiphanyRoleResultRoleId::Modeling => merge_item_error(
|
||||
item_error,
|
||||
modeling_role_result_error(
|
||||
raw_result.get("repoModelMutationProposal").is_some(),
|
||||
repo_model_mutation_proposal.as_ref(),
|
||||
repo_model_mutation_proposal_parse_error,
|
||||
),
|
||||
),
|
||||
EpiphanyRoleResultRoleId::Research => merge_item_error(
|
||||
item_error,
|
||||
research_role_decision_error(
|
||||
raw_result.get("researchDecision").is_some(),
|
||||
research_decision.as_ref(),
|
||||
research_decision_parse_error,
|
||||
),
|
||||
),
|
||||
EpiphanyRoleResultRoleId::Implementation
|
||||
| EpiphanyRoleResultRoleId::Verification
|
||||
| EpiphanyRoleResultRoleId::Reorientation => item_error,
|
||||
};
|
||||
|
||||
EpiphanyRoleFindingInterpretation {
|
||||
verdict: json_string_field(raw_result, "verdict"),
|
||||
summary: json_string_field(raw_result, "summary"),
|
||||
next_safe_move: json_string_field(raw_result, "nextSafeMove"),
|
||||
checkpoint_summary: json_string_field(raw_result, "checkpointSummary"),
|
||||
scratch_summary: json_string_field(raw_result, "scratchSummary"),
|
||||
files_inspected: json_string_array_field(raw_result, "filesInspected"),
|
||||
frontier_node_ids: json_string_array_field(raw_result, "frontierNodeIds"),
|
||||
evidence_ids: json_string_array_field(raw_result, "evidenceIds"),
|
||||
artifact_refs: json_string_array_field(raw_result, "artifactRefs"),
|
||||
runtime_result_id: json_string_field(raw_result, "runtimeResultId"),
|
||||
runtime_job_id: json_string_field(raw_result, "runtimeJobId"),
|
||||
open_questions: json_string_array_field(raw_result, "openQuestions"),
|
||||
evidence_gaps: json_string_array_field(raw_result, "evidenceGaps"),
|
||||
risks: json_string_array_field(raw_result, "risks"),
|
||||
research_decision,
|
||||
repo_model_mutation_proposal,
|
||||
job_error,
|
||||
item_error,
|
||||
verification_request_id: json_string_field(raw_result, "verificationRequestId"),
|
||||
frontier_route_id: json_string_field(raw_result, "frontierRouteId"),
|
||||
proposal_modeling_request_id: json_string_field(raw_result, "proposalModelingRequestId"),
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
fn interpret_reorient_finding(
|
||||
raw_result: &serde_json::Value,
|
||||
job_error: Option<String>,
|
||||
item_error: Option<String>,
|
||||
) -> EpiphanyReorientFindingInterpretation {
|
||||
EpiphanyReorientFindingInterpretation {
|
||||
mode: json_string_field(raw_result, "mode"),
|
||||
summary: json_string_field(raw_result, "summary"),
|
||||
next_safe_move: json_string_field(raw_result, "nextSafeMove"),
|
||||
checkpoint_still_valid: raw_result
|
||||
.get("checkpointStillValid")
|
||||
.and_then(serde_json::Value::as_bool),
|
||||
files_inspected: json_string_array_field(raw_result, "filesInspected"),
|
||||
frontier_node_ids: json_string_array_field(raw_result, "frontierNodeIds"),
|
||||
evidence_ids: json_string_array_field(raw_result, "evidenceIds"),
|
||||
artifact_refs: json_string_array_field(raw_result, "artifactRefs"),
|
||||
runtime_result_id: json_string_field(raw_result, "runtimeResultId"),
|
||||
runtime_job_id: json_string_field(raw_result, "runtimeJobId"),
|
||||
job_error,
|
||||
item_error,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn interpret_runtime_role_worker_result(
|
||||
role_id: EpiphanyRoleResultRoleId,
|
||||
result: &crate::EpiphanyRuntimeRoleWorkerResult,
|
||||
|
|
@ -296,154 +147,6 @@ pub fn interpret_runtime_reorient_worker_result(
|
|||
}
|
||||
}
|
||||
|
||||
pub fn build_role_acceptance_bundle(
|
||||
binding_id: &str,
|
||||
role: EpiphanyRoleAcceptanceFinding,
|
||||
accepted_evidence_id: String,
|
||||
accepted_observation_id: String,
|
||||
accepted_at: String,
|
||||
) -> Result<EpiphanyAcceptanceBundle, String> {
|
||||
let accepted_kind = role_accepted_kind(role.role_id)?;
|
||||
let accepted_prefix = role_label(role.role_id)?;
|
||||
let runtime_result_id = role
|
||||
.runtime_result_id
|
||||
.clone()
|
||||
.ok_or_else(|| "cannot accept role finding without a runtimeResultId".to_string())?;
|
||||
let runtime_job_id = role
|
||||
.runtime_job_id
|
||||
.clone()
|
||||
.ok_or_else(|| "cannot accept role finding without a runtimeJobId".to_string())?;
|
||||
let accepted_receipt_id = format!("accept-{accepted_prefix}-{runtime_result_id}");
|
||||
let code_refs = role_finding_code_refs(role.role_id, &role.files_inspected);
|
||||
let evidence = EpiphanyEvidenceRecord {
|
||||
id: accepted_evidence_id.clone(),
|
||||
kind: accepted_kind.to_string(),
|
||||
status: "accepted".to_string(),
|
||||
summary: role_finding_summary(&role),
|
||||
code_refs: code_refs.clone(),
|
||||
};
|
||||
let observation = EpiphanyObservation {
|
||||
id: accepted_observation_id.clone(),
|
||||
summary: role_finding_observation_summary(&role),
|
||||
source_kind: accepted_kind.to_string(),
|
||||
status: "accepted".to_string(),
|
||||
code_refs,
|
||||
evidence_ids: vec![accepted_evidence_id.clone()],
|
||||
};
|
||||
let receipt = EpiphanyAcceptanceReceipt {
|
||||
id: accepted_receipt_id.clone(),
|
||||
result_id: runtime_result_id,
|
||||
job_id: runtime_job_id,
|
||||
binding_id: binding_id.to_string(),
|
||||
surface: "roleAccept".to_string(),
|
||||
role_id: accepted_prefix.to_string(),
|
||||
status: "accepted".to_string(),
|
||||
accepted_at,
|
||||
accepted_observation_id: Some(accepted_observation_id.clone()),
|
||||
accepted_evidence_id: Some(accepted_evidence_id.clone()),
|
||||
summary: role.summary.clone(),
|
||||
};
|
||||
Ok(EpiphanyAcceptanceBundle {
|
||||
accepted_receipt_id,
|
||||
accepted_observation_id,
|
||||
accepted_evidence_id,
|
||||
evidence,
|
||||
observation,
|
||||
receipt,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn build_reorient_acceptance_bundle(
|
||||
binding_id: &str,
|
||||
finding: EpiphanyReorientAcceptanceFinding,
|
||||
accepted_evidence_id: String,
|
||||
accepted_observation_id: String,
|
||||
accepted_at: String,
|
||||
update_scratch: bool,
|
||||
investigation_checkpoint: Option<EpiphanyInvestigationCheckpoint>,
|
||||
) -> Result<EpiphanyReorientAcceptanceBundle, String> {
|
||||
let runtime_result_id = finding.runtime_result_id.clone().ok_or_else(|| {
|
||||
"cannot accept reorientation finding without a runtimeResultId".to_string()
|
||||
})?;
|
||||
let runtime_job_id = finding
|
||||
.runtime_job_id
|
||||
.clone()
|
||||
.ok_or_else(|| "cannot accept reorientation finding without a runtimeJobId".to_string())?;
|
||||
let accepted_receipt_id = format!("accept-reorient-{runtime_result_id}");
|
||||
let code_refs = reorient_finding_code_refs(&finding.files_inspected);
|
||||
let evidence = EpiphanyEvidenceRecord {
|
||||
id: accepted_evidence_id.clone(),
|
||||
kind: "reorient_result".to_string(),
|
||||
status: "accepted".to_string(),
|
||||
summary: reorient_finding_summary(&finding),
|
||||
code_refs: code_refs.clone(),
|
||||
};
|
||||
let observation = EpiphanyObservation {
|
||||
id: accepted_observation_id.clone(),
|
||||
summary: reorient_finding_observation_summary(&finding),
|
||||
source_kind: "reorient_result".to_string(),
|
||||
status: "accepted".to_string(),
|
||||
code_refs: code_refs.clone(),
|
||||
evidence_ids: vec![accepted_evidence_id.clone()],
|
||||
};
|
||||
let scratch = update_scratch.then(|| reorient_finding_scratch(binding_id, &finding));
|
||||
let investigation_checkpoint = investigation_checkpoint.map(|checkpoint| {
|
||||
reorient_finding_investigation_checkpoint(
|
||||
checkpoint,
|
||||
accepted_evidence_id.as_str(),
|
||||
code_refs.as_slice(),
|
||||
&finding,
|
||||
)
|
||||
});
|
||||
let receipt = EpiphanyAcceptanceReceipt {
|
||||
id: accepted_receipt_id.clone(),
|
||||
result_id: runtime_result_id,
|
||||
job_id: runtime_job_id,
|
||||
binding_id: binding_id.to_string(),
|
||||
surface: "reorientAccept".to_string(),
|
||||
role_id: "reorientation".to_string(),
|
||||
status: "accepted".to_string(),
|
||||
accepted_at,
|
||||
accepted_observation_id: Some(accepted_observation_id.clone()),
|
||||
accepted_evidence_id: Some(accepted_evidence_id.clone()),
|
||||
summary: finding.summary.clone(),
|
||||
};
|
||||
Ok(EpiphanyReorientAcceptanceBundle {
|
||||
accepted_receipt_id,
|
||||
accepted_observation_id,
|
||||
accepted_evidence_id,
|
||||
evidence,
|
||||
observation,
|
||||
receipt,
|
||||
scratch,
|
||||
investigation_checkpoint,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn role_accepted_kind(role_id: EpiphanyRoleResultRoleId) -> Result<&'static str, String> {
|
||||
match role_id {
|
||||
EpiphanyRoleResultRoleId::Imagination => Ok("planning_synthesis"),
|
||||
EpiphanyRoleResultRoleId::Research => Ok("research_result"),
|
||||
EpiphanyRoleResultRoleId::Modeling => Ok("modeling_result"),
|
||||
EpiphanyRoleResultRoleId::Verification => Ok("verification_result"),
|
||||
EpiphanyRoleResultRoleId::Implementation | EpiphanyRoleResultRoleId::Reorientation => Err(
|
||||
format!("role {role_id:?} cannot be accepted through roleAccept"),
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn role_label(role_id: EpiphanyRoleResultRoleId) -> Result<&'static str, String> {
|
||||
match role_id {
|
||||
EpiphanyRoleResultRoleId::Imagination => Ok("imagination"),
|
||||
EpiphanyRoleResultRoleId::Research => Ok("research"),
|
||||
EpiphanyRoleResultRoleId::Modeling => Ok("modeling"),
|
||||
EpiphanyRoleResultRoleId::Verification => Ok("verification"),
|
||||
EpiphanyRoleResultRoleId::Implementation | EpiphanyRoleResultRoleId::Reorientation => Err(
|
||||
format!("role {role_id:?} cannot be accepted through roleAccept"),
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
fn modeling_role_result_error(
|
||||
repo_model_mutation_proposal_present: bool,
|
||||
repo_model_mutation_proposal: Option<&crate::EpiphanyRepoModelMutationProposal>,
|
||||
|
|
@ -465,7 +168,7 @@ fn modeling_role_result_error(
|
|||
return Some(format!(
|
||||
"modeling result is not reviewable: invalid RepoModel mutation proposal ({error})"
|
||||
));
|
||||
};
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
|
|
@ -478,7 +181,7 @@ fn research_role_decision_error(
|
|||
return Some(
|
||||
"research result is not reviewable: missing required researchDecision".to_string(),
|
||||
);
|
||||
};
|
||||
}
|
||||
if let Some(error) = parse_error {
|
||||
return Some(format!(
|
||||
"research result is not reviewable: invalid researchDecision ({error})"
|
||||
|
|
@ -505,426 +208,3 @@ fn merge_item_error(item_error: Option<String>, extra_error: Option<String>) ->
|
|||
fn empty_string_as_none(value: &str) -> Option<String> {
|
||||
(!value.trim().is_empty()).then(|| value.to_string())
|
||||
}
|
||||
|
||||
fn role_finding_summary(finding: &EpiphanyRoleAcceptanceFinding) -> String {
|
||||
let summary = finding
|
||||
.summary
|
||||
.clone()
|
||||
.unwrap_or_else(|| "Role worker returned a structured finding.".to_string());
|
||||
if let Some(next_safe_move) = finding.next_safe_move.as_deref() {
|
||||
format!("{summary} Next safe move: {next_safe_move}")
|
||||
} else {
|
||||
summary
|
||||
}
|
||||
}
|
||||
|
||||
fn role_finding_observation_summary(finding: &EpiphanyRoleAcceptanceFinding) -> String {
|
||||
let verdict = finding.verdict.as_deref().unwrap_or("unknown");
|
||||
let changed = if finding.projected_fields.is_empty() {
|
||||
"no typed state fields projected".to_string()
|
||||
} else {
|
||||
finding.projected_fields.join(", ")
|
||||
};
|
||||
format!(
|
||||
"Accepted {:?} role result with verdict {verdict}; projected fields: {changed}. {}",
|
||||
finding.role_id,
|
||||
role_finding_summary(finding)
|
||||
)
|
||||
}
|
||||
|
||||
fn role_finding_code_refs(
|
||||
role_id: EpiphanyRoleResultRoleId,
|
||||
files_inspected: &[String],
|
||||
) -> Vec<EpiphanyCodeRef> {
|
||||
files_inspected
|
||||
.iter()
|
||||
.filter(|path| !path.trim().is_empty())
|
||||
.map(|path| EpiphanyCodeRef {
|
||||
path: PathBuf::from(path),
|
||||
start_line: None,
|
||||
end_line: None,
|
||||
symbol: None,
|
||||
note: Some(format!("Inspected by accepted {role_id:?} role worker.")),
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn reorient_finding_summary(finding: &EpiphanyReorientAcceptanceFinding) -> String {
|
||||
let summary = finding
|
||||
.summary
|
||||
.clone()
|
||||
.unwrap_or_else(|| "Reorientation worker returned a structured finding.".to_string());
|
||||
if let Some(next_safe_move) = finding.next_safe_move.as_deref() {
|
||||
format!("{summary} Next safe move: {next_safe_move}")
|
||||
} else {
|
||||
summary
|
||||
}
|
||||
}
|
||||
|
||||
fn reorient_finding_observation_summary(finding: &EpiphanyReorientAcceptanceFinding) -> String {
|
||||
let mode = finding.mode.as_deref().unwrap_or("unknown");
|
||||
let validity = match finding.checkpoint_still_valid {
|
||||
Some(true) => "checkpoint still valid",
|
||||
Some(false) => "checkpoint requires regather",
|
||||
None => "checkpoint validity not reported",
|
||||
};
|
||||
format!(
|
||||
"Accepted {mode} reorientation result: {validity}. {}",
|
||||
reorient_finding_summary(finding)
|
||||
)
|
||||
}
|
||||
|
||||
fn reorient_finding_code_refs(files_inspected: &[String]) -> Vec<EpiphanyCodeRef> {
|
||||
files_inspected
|
||||
.iter()
|
||||
.filter(|path| !path.trim().is_empty())
|
||||
.map(|path| EpiphanyCodeRef {
|
||||
path: PathBuf::from(path),
|
||||
start_line: None,
|
||||
end_line: None,
|
||||
symbol: None,
|
||||
note: Some("Inspected by accepted reorientation worker.".to_string()),
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn reorient_finding_scratch(
|
||||
binding_id: &str,
|
||||
finding: &EpiphanyReorientAcceptanceFinding,
|
||||
) -> EpiphanyScratchPad {
|
||||
let mode = finding.mode.as_deref().unwrap_or("unknown");
|
||||
let checkpoint_validity = match finding.checkpoint_still_valid {
|
||||
Some(true) => "valid",
|
||||
Some(false) => "invalid",
|
||||
None => "unknown",
|
||||
};
|
||||
EpiphanyScratchPad {
|
||||
summary: finding.summary.clone(),
|
||||
hypothesis: Some(format!(
|
||||
"Accepted {mode} reorientation finding from {binding_id}; checkpoint validity is {checkpoint_validity}."
|
||||
)),
|
||||
next_probe: finding.next_safe_move.clone(),
|
||||
notes: vec![format!(
|
||||
"Files inspected: {}",
|
||||
if finding.files_inspected.is_empty() {
|
||||
"none reported".to_string()
|
||||
} else {
|
||||
finding.files_inspected.join(", ")
|
||||
}
|
||||
)],
|
||||
}
|
||||
}
|
||||
|
||||
fn reorient_finding_investigation_checkpoint(
|
||||
mut checkpoint: EpiphanyInvestigationCheckpoint,
|
||||
evidence_id: &str,
|
||||
code_refs: &[EpiphanyCodeRef],
|
||||
finding: &EpiphanyReorientAcceptanceFinding,
|
||||
) -> EpiphanyInvestigationCheckpoint {
|
||||
checkpoint.summary = finding.summary.clone().or(checkpoint.summary);
|
||||
checkpoint.next_action = finding.next_safe_move.clone().or(checkpoint.next_action);
|
||||
checkpoint.disposition = EpiphanyInvestigationDisposition::ResumeReady;
|
||||
if !checkpoint
|
||||
.evidence_ids
|
||||
.iter()
|
||||
.any(|existing| existing == evidence_id)
|
||||
{
|
||||
checkpoint.evidence_ids.push(evidence_id.to_string());
|
||||
}
|
||||
for code_ref in code_refs {
|
||||
if !checkpoint
|
||||
.code_refs
|
||||
.iter()
|
||||
.any(|existing| existing.path == code_ref.path)
|
||||
{
|
||||
checkpoint.code_refs.push(code_ref.clone());
|
||||
}
|
||||
}
|
||||
checkpoint
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
fn json_string_field(value: &serde_json::Value, key: &str) -> Option<String> {
|
||||
value
|
||||
.get(key)
|
||||
.and_then(serde_json::Value::as_str)
|
||||
.map(str::to_string)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
fn json_string_array_field(value: &serde_json::Value, key: &str) -> Vec<String> {
|
||||
value
|
||||
.get(key)
|
||||
.and_then(serde_json::Value::as_array)
|
||||
.map(|values| {
|
||||
values
|
||||
.iter()
|
||||
.filter_map(serde_json::Value::as_str)
|
||||
.map(str::to_string)
|
||||
.collect()
|
||||
})
|
||||
.unwrap_or_default()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn projects_structured_output() {
|
||||
let finding = interpret_role_finding(
|
||||
EpiphanyRoleResultRoleId::Verification,
|
||||
&serde_json::json!({
|
||||
"verdict": "pass",
|
||||
"summary": "The evidence covers the bounded slice.",
|
||||
"nextSafeMove": "Promote after human review.",
|
||||
"filesInspected": ["src/lib.rs"],
|
||||
"frontierNodeIds": ["node-1"],
|
||||
"evidenceIds": ["ev-1"],
|
||||
"artifactRefs": ["artifact:role"],
|
||||
"runtimeResultId": "result-1",
|
||||
"runtimeJobId": "job-1",
|
||||
"proposalModelingRequestId": "proposal-request-1"
|
||||
}),
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
);
|
||||
|
||||
assert_eq!(finding.verdict.as_deref(), Some("pass"));
|
||||
assert_eq!(finding.files_inspected, vec!["src/lib.rs"]);
|
||||
assert_eq!(finding.runtime_result_id.as_deref(), Some("result-1"));
|
||||
assert_eq!(
|
||||
finding.proposal_modeling_request_id.as_deref(),
|
||||
Some("proposal-request-1")
|
||||
);
|
||||
assert_eq!(
|
||||
serde_json::to_value(&finding).unwrap()["proposalModelingRequestId"],
|
||||
"proposal-request-1"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn projects_reorient_structured_output() {
|
||||
let finding = interpret_reorient_finding(
|
||||
&serde_json::json!({
|
||||
"mode": "resume",
|
||||
"summary": "Checkpoint is still warm.",
|
||||
"nextSafeMove": "Continue the bounded cut.",
|
||||
"checkpointStillValid": true,
|
||||
"filesInspected": ["state/map.yaml"],
|
||||
"frontierNodeIds": ["node-1"],
|
||||
"evidenceIds": ["ev-1"],
|
||||
"artifactRefs": ["artifact:reorient"],
|
||||
"runtimeResultId": "result-1",
|
||||
"runtimeJobId": "job-1"
|
||||
}),
|
||||
None,
|
||||
None,
|
||||
);
|
||||
|
||||
assert_eq!(finding.mode.as_deref(), Some("resume"));
|
||||
assert_eq!(finding.checkpoint_still_valid, Some(true));
|
||||
assert_eq!(finding.frontier_node_ids, vec!["node-1"]);
|
||||
assert_eq!(finding.runtime_job_id.as_deref(), Some("job-1"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn marks_modeling_no_mutation_checkpoint_reviewable() {
|
||||
let checkpoint = interpret_role_finding(
|
||||
EpiphanyRoleResultRoleId::Modeling,
|
||||
&serde_json::json!({"verdict": "checkpoint-ready"}),
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
);
|
||||
|
||||
assert!(checkpoint.item_error.is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn research_requires_one_closed_typed_decision() {
|
||||
let missing = interpret_role_finding(
|
||||
EpiphanyRoleResultRoleId::Research,
|
||||
&serde_json::json!({"verdict": "evidence-ready"}),
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
);
|
||||
assert!(
|
||||
missing
|
||||
.item_error
|
||||
.as_deref()
|
||||
.is_some_and(|error| { error.contains("missing required researchDecision") })
|
||||
);
|
||||
|
||||
let reviewable = interpret_role_finding(
|
||||
EpiphanyRoleResultRoleId::Research,
|
||||
&serde_json::json!({
|
||||
"researchDecision": {
|
||||
"evidence": [{
|
||||
"id": "evidence-a",
|
||||
"kind": "source",
|
||||
"status": "ok",
|
||||
"summary": "Exact source proof.",
|
||||
"code_refs": []
|
||||
}],
|
||||
"observations": [{
|
||||
"id": "observation-a",
|
||||
"summary": "Observed exact source proof.",
|
||||
"source_kind": "research",
|
||||
"status": "ok",
|
||||
"code_refs": [],
|
||||
"evidence_ids": ["evidence-a"]
|
||||
}]
|
||||
}
|
||||
}),
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
);
|
||||
assert!(reviewable.item_error.is_none());
|
||||
assert!(reviewable.research_decision.is_some());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn builds_role_acceptance_bundle_from_runtime_identity() {
|
||||
let bundle = build_role_acceptance_bundle(
|
||||
"binding-modeling",
|
||||
EpiphanyRoleAcceptanceFinding {
|
||||
role_id: EpiphanyRoleResultRoleId::Modeling,
|
||||
verdict: Some("checkpoint-ready".to_string()),
|
||||
summary: Some("The map is source-grounded.".to_string()),
|
||||
next_safe_move: Some("Run verification.".to_string()),
|
||||
files_inspected: vec!["src/lib.rs".to_string(), "".to_string()],
|
||||
runtime_result_id: Some("result-123".to_string()),
|
||||
runtime_job_id: Some("job-123".to_string()),
|
||||
projected_fields: vec!["Graphs".to_string(), "InvestigationCheckpoint".to_string()],
|
||||
},
|
||||
"ev-modeling-test".to_string(),
|
||||
"obs-modeling-test".to_string(),
|
||||
"2026-05-12T00:00:00Z".to_string(),
|
||||
)
|
||||
.expect("role acceptance bundle should build");
|
||||
|
||||
assert_eq!(bundle.accepted_receipt_id, "accept-modeling-result-123");
|
||||
assert_eq!(bundle.evidence.kind, "modeling_result");
|
||||
assert_eq!(bundle.observation.source_kind, "modeling_result");
|
||||
assert_eq!(bundle.receipt.result_id, "result-123");
|
||||
assert_eq!(bundle.receipt.job_id, "job-123");
|
||||
assert_eq!(bundle.receipt.surface, "roleAccept");
|
||||
assert_eq!(bundle.receipt.role_id, "modeling");
|
||||
assert!(
|
||||
bundle
|
||||
.observation
|
||||
.summary
|
||||
.contains("Graphs, InvestigationCheckpoint")
|
||||
);
|
||||
assert_eq!(bundle.evidence.code_refs.len(), 1);
|
||||
assert_eq!(
|
||||
bundle.evidence.code_refs[0].path,
|
||||
PathBuf::from("src/lib.rs")
|
||||
);
|
||||
assert!(
|
||||
bundle.evidence.code_refs[0]
|
||||
.note
|
||||
.as_deref()
|
||||
.is_some_and(|note| note.contains("Modeling role worker"))
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn builds_reorient_acceptance_bundle_with_scratch_and_checkpoint() {
|
||||
let checkpoint = EpiphanyInvestigationCheckpoint {
|
||||
checkpoint_id: "checkpoint-1".to_string(),
|
||||
kind: "implementation".to_string(),
|
||||
disposition: EpiphanyInvestigationDisposition::RegatherRequired,
|
||||
focus: "runtime acceptance".to_string(),
|
||||
summary: Some("Old summary".to_string()),
|
||||
next_action: Some("Old move".to_string()),
|
||||
captured_at_turn_id: Some("turn-1".to_string()),
|
||||
open_questions: vec!["Which result owns acceptance?".to_string()],
|
||||
code_refs: vec![EpiphanyCodeRef {
|
||||
path: PathBuf::from("src/old.rs"),
|
||||
start_line: None,
|
||||
end_line: None,
|
||||
symbol: None,
|
||||
note: None,
|
||||
}],
|
||||
evidence_ids: vec!["ev-old".to_string()],
|
||||
};
|
||||
|
||||
let bundle = build_reorient_acceptance_bundle(
|
||||
"reorient-worker",
|
||||
EpiphanyReorientAcceptanceFinding {
|
||||
mode: Some("resume".to_string()),
|
||||
summary: Some("The checkpoint can resume.".to_string()),
|
||||
next_safe_move: Some("Continue the migration.".to_string()),
|
||||
checkpoint_still_valid: Some(true),
|
||||
files_inspected: vec!["src/new.rs".to_string()],
|
||||
runtime_result_id: Some("result-reorient".to_string()),
|
||||
runtime_job_id: Some("job-reorient".to_string()),
|
||||
},
|
||||
"ev-reorient-test".to_string(),
|
||||
"obs-reorient-test".to_string(),
|
||||
"2026-05-12T00:00:00Z".to_string(),
|
||||
true,
|
||||
Some(checkpoint),
|
||||
)
|
||||
.expect("reorient acceptance bundle should build");
|
||||
|
||||
assert_eq!(
|
||||
bundle.accepted_receipt_id,
|
||||
"accept-reorient-result-reorient"
|
||||
);
|
||||
assert_eq!(bundle.receipt.surface, "reorientAccept");
|
||||
assert_eq!(bundle.evidence.kind, "reorient_result");
|
||||
assert!(
|
||||
bundle
|
||||
.observation
|
||||
.summary
|
||||
.contains("checkpoint still valid")
|
||||
);
|
||||
let scratch = bundle.scratch.expect("scratch should be updated");
|
||||
assert_eq!(
|
||||
scratch.summary.as_deref(),
|
||||
Some("The checkpoint can resume.")
|
||||
);
|
||||
assert_eq!(
|
||||
scratch.next_probe.as_deref(),
|
||||
Some("Continue the migration.")
|
||||
);
|
||||
let checkpoint = bundle
|
||||
.investigation_checkpoint
|
||||
.expect("checkpoint should be updated");
|
||||
assert_eq!(
|
||||
checkpoint.disposition,
|
||||
EpiphanyInvestigationDisposition::ResumeReady
|
||||
);
|
||||
assert_eq!(
|
||||
checkpoint.summary.as_deref(),
|
||||
Some("The checkpoint can resume.")
|
||||
);
|
||||
assert!(
|
||||
checkpoint
|
||||
.evidence_ids
|
||||
.iter()
|
||||
.any(|id| id == "ev-reorient-test")
|
||||
);
|
||||
assert!(checkpoint.code_refs.iter().any(|code_ref| {
|
||||
code_ref.path == PathBuf::from("src/new.rs")
|
||||
&& code_ref
|
||||
.note
|
||||
.as_deref()
|
||||
.is_some_and(|note| note.contains("reorientation worker"))
|
||||
}));
|
||||
}
|
||||
}
|
||||
use epiphany_state_model::EpiphanyAcceptanceReceipt;
|
||||
use epiphany_state_model::EpiphanyCodeRef;
|
||||
use epiphany_state_model::EpiphanyEvidenceRecord;
|
||||
use epiphany_state_model::EpiphanyInvestigationCheckpoint;
|
||||
use epiphany_state_model::EpiphanyInvestigationDisposition;
|
||||
use epiphany_state_model::EpiphanyObservation;
|
||||
use epiphany_state_model::EpiphanyScratchPad;
|
||||
use std::path::PathBuf;
|
||||
|
|
|
|||
|
|
@ -1,52 +0,0 @@
|
|||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub enum EpiphanyViewLens {
|
||||
Scene,
|
||||
Jobs,
|
||||
Roles,
|
||||
Planning,
|
||||
Pressure,
|
||||
Reorient,
|
||||
Crrc,
|
||||
Coordinator,
|
||||
}
|
||||
|
||||
pub fn default_epiphany_view_lenses() -> Vec<EpiphanyViewLens> {
|
||||
vec![
|
||||
EpiphanyViewLens::Scene,
|
||||
EpiphanyViewLens::Jobs,
|
||||
EpiphanyViewLens::Roles,
|
||||
EpiphanyViewLens::Planning,
|
||||
EpiphanyViewLens::Pressure,
|
||||
EpiphanyViewLens::Reorient,
|
||||
EpiphanyViewLens::Crrc,
|
||||
EpiphanyViewLens::Coordinator,
|
||||
]
|
||||
}
|
||||
|
||||
pub fn epiphany_view_needs_jobs(lenses: &[EpiphanyViewLens]) -> bool {
|
||||
lenses.contains(&EpiphanyViewLens::Jobs)
|
||||
|| lenses.contains(&EpiphanyViewLens::Roles)
|
||||
|| lenses.contains(&EpiphanyViewLens::Crrc)
|
||||
|| lenses.contains(&EpiphanyViewLens::Coordinator)
|
||||
}
|
||||
|
||||
pub fn epiphany_view_needs_reorientation_inputs(lenses: &[EpiphanyViewLens]) -> bool {
|
||||
lenses.contains(&EpiphanyViewLens::Roles)
|
||||
|| lenses.contains(&EpiphanyViewLens::Reorient)
|
||||
|| lenses.contains(&EpiphanyViewLens::Crrc)
|
||||
|| lenses.contains(&EpiphanyViewLens::Coordinator)
|
||||
}
|
||||
|
||||
pub fn epiphany_view_needs_pressure(lenses: &[EpiphanyViewLens]) -> bool {
|
||||
lenses.contains(&EpiphanyViewLens::Pressure) || epiphany_view_needs_reorientation_inputs(lenses)
|
||||
}
|
||||
|
||||
pub fn epiphany_view_needs_runtime_store(lenses: &[EpiphanyViewLens]) -> bool {
|
||||
lenses.contains(&EpiphanyViewLens::Roles)
|
||||
|| lenses.contains(&EpiphanyViewLens::Crrc)
|
||||
|| lenses.contains(&EpiphanyViewLens::Coordinator)
|
||||
}
|
||||
Reference in a new issue