Extract Epiphany role result policy into core
This commit is contained in:
parent
f229731d7c
commit
1429141b5b
8 changed files with 985 additions and 587 deletions
|
|
@ -36,8 +36,8 @@ pub use cultcache_rs::SingleFileMessagePackBackingStore;
|
|||
pub use distillation::EpiphanyDistillInput;
|
||||
pub use distillation::EpiphanyDistillProposal;
|
||||
pub use distillation::distill_observation;
|
||||
pub use heartbeat_state::EpiphanyHeartbeatStateEntry;
|
||||
pub use heartbeat_state::EpiphanyHeartbeatCognitionEntry;
|
||||
pub use heartbeat_state::EpiphanyHeartbeatStateEntry;
|
||||
pub use heartbeat_state::GhostlightSceneParticipantSeed;
|
||||
pub use heartbeat_state::HEARTBEAT_COGNITION_KEY;
|
||||
pub use heartbeat_state::HEARTBEAT_COGNITION_SCHEMA_VERSION;
|
||||
|
|
@ -121,8 +121,8 @@ pub use runtime_spine::runtime_job_snapshot;
|
|||
pub use runtime_spine::runtime_schema_catalog_response;
|
||||
pub use runtime_spine::runtime_spine_cache;
|
||||
pub use runtime_spine::runtime_spine_status;
|
||||
pub use runtime_spine::write_runtime_schema_catalog_json;
|
||||
pub use runtime_spine::write_runtime_hello_frame;
|
||||
pub use runtime_spine::write_runtime_schema_catalog_json;
|
||||
pub use state_ledger::EpiphanyBranchRecord;
|
||||
pub use state_ledger::EpiphanyLedgerEvidenceRecord;
|
||||
pub use state_ledger::EpiphanyStateLedgerEntry;
|
||||
|
|
@ -159,6 +159,10 @@ pub use surfaces::EpiphanyRoleBoardJob;
|
|||
pub use surfaces::EpiphanyRoleBoardJobStatus;
|
||||
pub use surfaces::EpiphanyRoleBoardLane;
|
||||
pub use surfaces::EpiphanyRoleBoardPlanningSummary;
|
||||
pub use surfaces::EpiphanyRoleFindingInterpretation;
|
||||
pub use surfaces::EpiphanyRoleResultRoleId;
|
||||
pub use surfaces::EpiphanyRoleSelfPersistenceReview;
|
||||
pub use surfaces::EpiphanyRoleSelfPersistenceStatus;
|
||||
pub use surfaces::EpiphanyViewInput;
|
||||
pub use surfaces::EpiphanyViewLens;
|
||||
pub use surfaces::EpiphanyViewOutput;
|
||||
|
|
@ -166,9 +170,14 @@ pub use surfaces::coordinator_automation_action;
|
|||
pub use surfaces::crrc_scene_action_to_coordinator_scene_action;
|
||||
pub use surfaces::derive_pressure_view;
|
||||
pub use surfaces::derive_role_board;
|
||||
pub use surfaces::render_role_board_note;
|
||||
pub use surfaces::imagination_role_state_patch_policy_errors;
|
||||
pub use surfaces::interpret_role_finding;
|
||||
pub use surfaces::modeling_role_state_patch_policy_errors;
|
||||
pub use surfaces::recommend_coordinator_action;
|
||||
pub use surfaces::recommend_crrc_action;
|
||||
pub use surfaces::render_role_board_note;
|
||||
pub use surfaces::reorientation_role_status;
|
||||
pub use surfaces::review_role_self_patch;
|
||||
pub use surfaces::role_board_job_status_to_role_status;
|
||||
pub use surfaces::role_self_memory_target;
|
||||
pub use surfaces::select_coordinator_automation_action;
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ mod coordinator;
|
|||
mod crrc;
|
||||
mod pressure;
|
||||
mod role_board;
|
||||
mod role_result;
|
||||
|
||||
pub use coordinator::EpiphanyCoordinatorAction;
|
||||
pub use coordinator::EpiphanyCoordinatorAutomationAction;
|
||||
|
|
@ -41,6 +42,15 @@ pub use role_board::derive_role_board;
|
|||
pub use role_board::render_role_board_note;
|
||||
pub use role_board::reorientation_role_status;
|
||||
pub use role_board::role_board_job_status_to_role_status;
|
||||
pub use role_result::EpiphanyRoleFindingInterpretation;
|
||||
pub use role_result::EpiphanyRoleResultRoleId;
|
||||
pub use role_result::EpiphanyRoleSelfPersistenceReview;
|
||||
pub use role_result::EpiphanyRoleSelfPersistenceStatus;
|
||||
pub use role_result::imagination_role_state_patch_policy_errors;
|
||||
pub use role_result::interpret_role_finding;
|
||||
pub use role_result::modeling_role_state_patch_policy_errors;
|
||||
pub use role_result::review_role_self_patch;
|
||||
pub use role_result::role_self_memory_target;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct EpiphanyViewInput {
|
||||
|
|
|
|||
880
epiphany-core/src/surfaces/role_result.rs
Normal file
880
epiphany-core/src/surfaces/role_result.rs
Normal file
|
|
@ -0,0 +1,880 @@
|
|||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum EpiphanyRoleResultRoleId {
|
||||
Implementation,
|
||||
Imagination,
|
||||
Modeling,
|
||||
Verification,
|
||||
Reorientation,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum EpiphanyRoleSelfPersistenceStatus {
|
||||
Missing,
|
||||
Accepted,
|
||||
Rejected,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct EpiphanyRoleSelfPersistenceReview {
|
||||
pub status: EpiphanyRoleSelfPersistenceStatus,
|
||||
pub target_agent_id: Option<String>,
|
||||
pub target_path: Option<String>,
|
||||
pub reasons: Vec<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct EpiphanyRoleFindingInterpretation {
|
||||
pub verdict: Option<String>,
|
||||
pub summary: Option<String>,
|
||||
pub next_safe_move: Option<String>,
|
||||
pub checkpoint_summary: Option<String>,
|
||||
pub scratch_summary: Option<String>,
|
||||
pub files_inspected: Vec<String>,
|
||||
pub frontier_node_ids: Vec<String>,
|
||||
pub evidence_ids: Vec<String>,
|
||||
pub artifact_refs: Vec<String>,
|
||||
pub runtime_result_id: Option<String>,
|
||||
pub runtime_job_id: Option<String>,
|
||||
pub open_questions: Vec<String>,
|
||||
pub evidence_gaps: Vec<String>,
|
||||
pub risks: Vec<String>,
|
||||
pub state_patch: Option<serde_json::Value>,
|
||||
pub self_patch: Option<serde_json::Value>,
|
||||
pub self_persistence: Option<EpiphanyRoleSelfPersistenceReview>,
|
||||
pub job_error: Option<String>,
|
||||
pub item_error: Option<String>,
|
||||
}
|
||||
|
||||
pub fn interpret_role_finding(
|
||||
role_id: EpiphanyRoleResultRoleId,
|
||||
raw_result: &serde_json::Value,
|
||||
state_patch_parse_error: Option<String>,
|
||||
job_error: Option<String>,
|
||||
item_error: Option<String>,
|
||||
) -> EpiphanyRoleFindingInterpretation {
|
||||
let state_patch = raw_result.get("statePatch").cloned();
|
||||
let self_patch = raw_result.get("selfPatch").cloned();
|
||||
let self_persistence = self_patch
|
||||
.as_ref()
|
||||
.map(|patch| review_role_self_patch(role_id, patch));
|
||||
let item_error = match role_id {
|
||||
EpiphanyRoleResultRoleId::Imagination => merge_item_error(
|
||||
item_error,
|
||||
imagination_role_state_patch_error(
|
||||
raw_result,
|
||||
state_patch.as_ref(),
|
||||
state_patch_parse_error,
|
||||
),
|
||||
),
|
||||
EpiphanyRoleResultRoleId::Modeling => merge_item_error(
|
||||
item_error,
|
||||
modeling_role_state_patch_error(
|
||||
raw_result,
|
||||
state_patch.as_ref(),
|
||||
state_patch_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"),
|
||||
state_patch,
|
||||
self_patch,
|
||||
self_persistence,
|
||||
job_error,
|
||||
item_error,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn role_self_memory_target(role_id: EpiphanyRoleResultRoleId) -> (&'static str, &'static str) {
|
||||
match role_id {
|
||||
EpiphanyRoleResultRoleId::Imagination => (
|
||||
"epiphany.imagination",
|
||||
"state/agents/imagination.agent-state.json",
|
||||
),
|
||||
EpiphanyRoleResultRoleId::Modeling => {
|
||||
("epiphany.body", "state/agents/body.agent-state.json")
|
||||
}
|
||||
EpiphanyRoleResultRoleId::Verification => {
|
||||
("epiphany.soul", "state/agents/soul.agent-state.json")
|
||||
}
|
||||
EpiphanyRoleResultRoleId::Implementation => {
|
||||
("epiphany.hands", "state/agents/hands.agent-state.json")
|
||||
}
|
||||
EpiphanyRoleResultRoleId::Reorientation => {
|
||||
("epiphany.life", "state/agents/life.agent-state.json")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn review_role_self_patch(
|
||||
role_id: EpiphanyRoleResultRoleId,
|
||||
patch: &serde_json::Value,
|
||||
) -> EpiphanyRoleSelfPersistenceReview {
|
||||
let (expected_agent_id, target_path) = role_self_memory_target(role_id);
|
||||
let mut reasons = Vec::new();
|
||||
let Some(object) = patch.as_object() else {
|
||||
return EpiphanyRoleSelfPersistenceReview {
|
||||
status: EpiphanyRoleSelfPersistenceStatus::Rejected,
|
||||
target_agent_id: Some(expected_agent_id.to_string()),
|
||||
target_path: Some(target_path.to_string()),
|
||||
reasons: vec!["selfPatch must be a JSON object".to_string()],
|
||||
};
|
||||
};
|
||||
|
||||
let agent_id = object.get("agentId").and_then(serde_json::Value::as_str);
|
||||
match agent_id {
|
||||
Some(id) if id == expected_agent_id => {}
|
||||
Some(id) => reasons.push(format!(
|
||||
"selfPatch agentId {id:?} does not match this lane; expected {expected_agent_id:?}"
|
||||
)),
|
||||
None => reasons.push(format!(
|
||||
"selfPatch must include agentId {expected_agent_id:?}"
|
||||
)),
|
||||
}
|
||||
match object.get("reason").and_then(serde_json::Value::as_str) {
|
||||
Some(reason) if reason.trim().len() >= 16 && reason.len() <= 800 => {}
|
||||
Some(_) => reasons.push(
|
||||
"selfPatch reason must be a bounded explanation of at least 16 characters".to_string(),
|
||||
),
|
||||
None => reasons.push(
|
||||
"selfPatch must include a reason explaining why this improves the lane".to_string(),
|
||||
),
|
||||
}
|
||||
|
||||
let allowed = [
|
||||
"agentId",
|
||||
"reason",
|
||||
"evidenceIds",
|
||||
"semanticMemories",
|
||||
"episodicMemories",
|
||||
"relationshipMemories",
|
||||
"goals",
|
||||
"values",
|
||||
"privateNotes",
|
||||
];
|
||||
let forbidden = [
|
||||
"statePatch",
|
||||
"objective",
|
||||
"activeSubgoalId",
|
||||
"subgoals",
|
||||
"invariants",
|
||||
"graphs",
|
||||
"graphFrontier",
|
||||
"graphCheckpoint",
|
||||
"scratch",
|
||||
"investigationCheckpoint",
|
||||
"jobBindings",
|
||||
"planning",
|
||||
"churn",
|
||||
"mode",
|
||||
"codeEdits",
|
||||
"files",
|
||||
"authorityScope",
|
||||
"backendJobId",
|
||||
"rawResult",
|
||||
];
|
||||
for key in object.keys() {
|
||||
if forbidden.contains(&key.as_str()) {
|
||||
reasons.push(format!(
|
||||
"selfPatch field {key:?} is project truth or authority; use statePatch, roleAccept, or another explicit control surface instead"
|
||||
));
|
||||
} else if !allowed.contains(&key.as_str()) {
|
||||
reasons.push(format!(
|
||||
"selfPatch field {key:?} is not part of the bounded memory mutation contract"
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
let mut mutation_count = 0usize;
|
||||
mutation_count += review_self_patch_memories(&mut reasons, object, "semanticMemories");
|
||||
mutation_count += review_self_patch_memories(&mut reasons, object, "episodicMemories");
|
||||
mutation_count += review_self_patch_memories(&mut reasons, object, "relationshipMemories");
|
||||
mutation_count += review_self_patch_goals(&mut reasons, object);
|
||||
mutation_count += review_self_patch_values(&mut reasons, object);
|
||||
mutation_count += review_self_patch_private_notes(&mut reasons, object);
|
||||
review_self_patch_string_array(&mut reasons, object, "evidenceIds", 16, 160);
|
||||
if mutation_count == 0 {
|
||||
reasons.push(
|
||||
"selfPatch must contain at least one semantic memory, episodic memory, relationship memory, goal, value, or private note"
|
||||
.to_string(),
|
||||
);
|
||||
}
|
||||
|
||||
EpiphanyRoleSelfPersistenceReview {
|
||||
status: if reasons.is_empty() {
|
||||
EpiphanyRoleSelfPersistenceStatus::Accepted
|
||||
} else {
|
||||
EpiphanyRoleSelfPersistenceStatus::Rejected
|
||||
},
|
||||
target_agent_id: Some(expected_agent_id.to_string()),
|
||||
target_path: Some(target_path.to_string()),
|
||||
reasons,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn modeling_role_state_patch_policy_errors(patch: &serde_json::Value) -> Vec<String> {
|
||||
let mut errors = Vec::new();
|
||||
if has_field(patch, "objective") {
|
||||
errors
|
||||
.push("objective changes are not allowed through modeling role acceptance".to_string());
|
||||
}
|
||||
if has_field(patch, "activeSubgoalId") || has_field(patch, "subgoals") {
|
||||
errors.push("subgoal changes are not allowed through modeling role acceptance".to_string());
|
||||
}
|
||||
if has_field(patch, "invariants") {
|
||||
errors
|
||||
.push("invariant changes are not allowed through modeling role acceptance".to_string());
|
||||
}
|
||||
if has_field(patch, "jobBindings") {
|
||||
errors.push(
|
||||
"job binding changes are not allowed through modeling role acceptance".to_string(),
|
||||
);
|
||||
}
|
||||
if non_empty_array_field(patch, "acceptanceReceipts") {
|
||||
errors.push(
|
||||
"acceptance receipt changes are owned by roleAccept, not worker statePatch".to_string(),
|
||||
);
|
||||
}
|
||||
if non_empty_array_field(patch, "runtimeLinks") {
|
||||
errors.push(
|
||||
"runtime link changes are owned by launch/read-back surfaces, not worker statePatch"
|
||||
.to_string(),
|
||||
);
|
||||
}
|
||||
if has_field(patch, "planning") {
|
||||
errors
|
||||
.push("planning changes are not allowed through modeling role acceptance".to_string());
|
||||
}
|
||||
if has_field(patch, "churn") || has_field(patch, "mode") {
|
||||
errors.push(
|
||||
"churn or mode changes are not allowed through modeling role acceptance".to_string(),
|
||||
);
|
||||
}
|
||||
if !has_field(patch, "graphs")
|
||||
&& !has_field(patch, "graphFrontier")
|
||||
&& !has_field(patch, "graphCheckpoint")
|
||||
&& !has_field(patch, "scratch")
|
||||
&& !has_field(patch, "investigationCheckpoint")
|
||||
{
|
||||
errors.push(
|
||||
"statePatch must include a modeling field: graphs, graphFrontier, graphCheckpoint, scratch, or investigationCheckpoint"
|
||||
.to_string(),
|
||||
);
|
||||
}
|
||||
errors
|
||||
}
|
||||
|
||||
pub fn imagination_role_state_patch_policy_errors(patch: &serde_json::Value) -> Vec<String> {
|
||||
let mut errors = Vec::new();
|
||||
if has_field(patch, "objective") {
|
||||
errors.push(
|
||||
"objective changes are not allowed through imagination role acceptance".to_string(),
|
||||
);
|
||||
}
|
||||
if has_field(patch, "activeSubgoalId") || has_field(patch, "subgoals") {
|
||||
errors.push(
|
||||
"subgoal changes are not allowed through imagination role acceptance".to_string(),
|
||||
);
|
||||
}
|
||||
if has_field(patch, "invariants") {
|
||||
errors.push(
|
||||
"invariant changes are not allowed through imagination role acceptance".to_string(),
|
||||
);
|
||||
}
|
||||
if has_field(patch, "graphs")
|
||||
|| has_field(patch, "graphFrontier")
|
||||
|| has_field(patch, "graphCheckpoint")
|
||||
|| has_field(patch, "investigationCheckpoint")
|
||||
{
|
||||
errors.push(
|
||||
"graph or checkpoint changes are not allowed through imagination role acceptance"
|
||||
.to_string(),
|
||||
);
|
||||
}
|
||||
if has_field(patch, "scratch") {
|
||||
errors.push(
|
||||
"scratch changes are not allowed through imagination role acceptance".to_string(),
|
||||
);
|
||||
}
|
||||
if has_field(patch, "jobBindings") {
|
||||
errors.push(
|
||||
"job binding changes are not allowed through imagination role acceptance".to_string(),
|
||||
);
|
||||
}
|
||||
if non_empty_array_field(patch, "acceptanceReceipts") {
|
||||
errors.push(
|
||||
"acceptance receipt changes are owned by roleAccept, not worker statePatch".to_string(),
|
||||
);
|
||||
}
|
||||
if non_empty_array_field(patch, "runtimeLinks") {
|
||||
errors.push(
|
||||
"runtime link changes are owned by launch/read-back surfaces, not worker statePatch"
|
||||
.to_string(),
|
||||
);
|
||||
}
|
||||
if has_field(patch, "churn") || has_field(patch, "mode") {
|
||||
errors.push(
|
||||
"churn or mode changes are not allowed through imagination role acceptance".to_string(),
|
||||
);
|
||||
}
|
||||
let Some(planning) = patch.get("planning") else {
|
||||
errors.push("statePatch must include planning changes".to_string());
|
||||
return errors;
|
||||
};
|
||||
let objective_drafts = get_field(planning, "objectiveDrafts", "objective_drafts")
|
||||
.and_then(serde_json::Value::as_array)
|
||||
.cloned()
|
||||
.unwrap_or_default();
|
||||
if objective_drafts.is_empty() {
|
||||
errors.push("planning patch must include at least one objective draft".to_string());
|
||||
}
|
||||
if !objective_drafts.iter().any(|draft| {
|
||||
draft
|
||||
.get("status")
|
||||
.and_then(serde_json::Value::as_str)
|
||||
.is_some_and(|status| status.eq_ignore_ascii_case("draft"))
|
||||
}) {
|
||||
errors.push(
|
||||
"planning patch must include at least one objective draft with status draft"
|
||||
.to_string(),
|
||||
);
|
||||
}
|
||||
for draft in &objective_drafts {
|
||||
let id = draft
|
||||
.get("id")
|
||||
.and_then(serde_json::Value::as_str)
|
||||
.unwrap_or("<missing>");
|
||||
if !draft
|
||||
.get("acceptanceCriteria")
|
||||
.or_else(|| draft.get("acceptance_criteria"))
|
||||
.and_then(serde_json::Value::as_array)
|
||||
.is_some_and(|items| !items.is_empty())
|
||||
{
|
||||
errors.push(format!(
|
||||
"planning objective draft {:?} must include acceptance criteria",
|
||||
id
|
||||
));
|
||||
}
|
||||
if !draft
|
||||
.get("reviewGates")
|
||||
.or_else(|| draft.get("review_gates"))
|
||||
.and_then(serde_json::Value::as_array)
|
||||
.is_some_and(|items| !items.is_empty())
|
||||
{
|
||||
errors.push(format!(
|
||||
"planning objective draft {:?} must include review gates",
|
||||
id
|
||||
));
|
||||
}
|
||||
}
|
||||
errors
|
||||
}
|
||||
|
||||
fn modeling_role_state_patch_error(
|
||||
raw_result: &serde_json::Value,
|
||||
state_patch: Option<&serde_json::Value>,
|
||||
parse_error: Option<String>,
|
||||
) -> Option<String> {
|
||||
let Some(value) = raw_result.get("statePatch") else {
|
||||
return Some("modeling result is not reviewable: missing required statePatch".to_string());
|
||||
};
|
||||
if let Some(error) = parse_error {
|
||||
return Some(format!(
|
||||
"modeling result is not reviewable: invalid statePatch ({error})"
|
||||
));
|
||||
}
|
||||
let errors = modeling_role_state_patch_policy_errors(state_patch.unwrap_or(value));
|
||||
if errors.is_empty() {
|
||||
None
|
||||
} else {
|
||||
Some(format!(
|
||||
"modeling result is not reviewable: {}",
|
||||
errors.join("; ")
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
fn imagination_role_state_patch_error(
|
||||
raw_result: &serde_json::Value,
|
||||
state_patch: Option<&serde_json::Value>,
|
||||
parse_error: Option<String>,
|
||||
) -> Option<String> {
|
||||
let Some(value) = raw_result.get("statePatch") else {
|
||||
return Some(
|
||||
"imagination result is not reviewable: missing required statePatch".to_string(),
|
||||
);
|
||||
};
|
||||
if let Some(error) = parse_error {
|
||||
return Some(format!(
|
||||
"imagination result is not reviewable: invalid statePatch ({error})"
|
||||
));
|
||||
}
|
||||
let errors = imagination_role_state_patch_policy_errors(state_patch.unwrap_or(value));
|
||||
if errors.is_empty() {
|
||||
None
|
||||
} else {
|
||||
Some(format!(
|
||||
"imagination result is not reviewable: {}",
|
||||
errors.join("; ")
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
fn merge_item_error(item_error: Option<String>, extra_error: Option<String>) -> Option<String> {
|
||||
match (item_error, extra_error) {
|
||||
(Some(existing), Some(extra)) => Some(format!("{existing}; {extra}")),
|
||||
(Some(existing), None) => Some(existing),
|
||||
(None, Some(extra)) => Some(extra),
|
||||
(None, None) => None,
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
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()
|
||||
}
|
||||
|
||||
fn has_field(value: &serde_json::Value, key: &str) -> bool {
|
||||
value.get(key).is_some_and(|field| !field.is_null())
|
||||
}
|
||||
|
||||
fn get_field<'a>(
|
||||
value: &'a serde_json::Value,
|
||||
camel_key: &str,
|
||||
snake_key: &str,
|
||||
) -> Option<&'a serde_json::Value> {
|
||||
value.get(camel_key).or_else(|| value.get(snake_key))
|
||||
}
|
||||
|
||||
fn non_empty_array_field(value: &serde_json::Value, key: &str) -> bool {
|
||||
value
|
||||
.get(key)
|
||||
.and_then(serde_json::Value::as_array)
|
||||
.is_some_and(|items| !items.is_empty())
|
||||
}
|
||||
|
||||
fn review_self_patch_memories(
|
||||
reasons: &mut Vec<String>,
|
||||
object: &serde_json::Map<String, serde_json::Value>,
|
||||
field: &str,
|
||||
) -> usize {
|
||||
let Some(value) = object.get(field) else {
|
||||
return 0;
|
||||
};
|
||||
let Some(items) = value.as_array() else {
|
||||
reasons.push(format!("selfPatch {field} must be an array"));
|
||||
return 0;
|
||||
};
|
||||
if items.len() > 8 {
|
||||
reasons.push(format!("selfPatch {field} may contain at most 8 records"));
|
||||
}
|
||||
let mut valid = 0usize;
|
||||
for (index, item) in items.iter().enumerate() {
|
||||
let Some(record) = item.as_object() else {
|
||||
reasons.push(format!("selfPatch {field}[{index}] must be an object"));
|
||||
continue;
|
||||
};
|
||||
review_self_patch_id(reasons, record, field, index, "memoryId", "mem-");
|
||||
review_self_patch_summary(reasons, record, field, index, "summary", 600);
|
||||
review_self_patch_unit(reasons, record, field, index, "salience");
|
||||
review_self_patch_unit(reasons, record, field, index, "confidence");
|
||||
valid += 1;
|
||||
}
|
||||
valid
|
||||
}
|
||||
|
||||
fn review_self_patch_goals(
|
||||
reasons: &mut Vec<String>,
|
||||
object: &serde_json::Map<String, serde_json::Value>,
|
||||
) -> usize {
|
||||
let Some(value) = object.get("goals") else {
|
||||
return 0;
|
||||
};
|
||||
let Some(items) = value.as_array() else {
|
||||
reasons.push("selfPatch goals must be an array".to_string());
|
||||
return 0;
|
||||
};
|
||||
if items.len() > 6 {
|
||||
reasons.push("selfPatch goals may contain at most 6 records".to_string());
|
||||
}
|
||||
let mut valid = 0usize;
|
||||
for (index, item) in items.iter().enumerate() {
|
||||
let Some(record) = item.as_object() else {
|
||||
reasons.push(format!("selfPatch goals[{index}] must be an object"));
|
||||
continue;
|
||||
};
|
||||
review_self_patch_id(reasons, record, "goals", index, "goalId", "goal-");
|
||||
review_self_patch_summary(reasons, record, "goals", index, "description", 700);
|
||||
review_self_patch_string(reasons, record, "goals", index, "scope", 80);
|
||||
review_self_patch_unit(reasons, record, "goals", index, "priority");
|
||||
review_self_patch_string(reasons, record, "goals", index, "emotionalStake", 400);
|
||||
review_self_patch_string(reasons, record, "goals", index, "status", 80);
|
||||
valid += 1;
|
||||
}
|
||||
valid
|
||||
}
|
||||
|
||||
fn review_self_patch_values(
|
||||
reasons: &mut Vec<String>,
|
||||
object: &serde_json::Map<String, serde_json::Value>,
|
||||
) -> usize {
|
||||
let Some(value) = object.get("values") else {
|
||||
return 0;
|
||||
};
|
||||
let Some(items) = value.as_array() else {
|
||||
reasons.push("selfPatch values must be an array".to_string());
|
||||
return 0;
|
||||
};
|
||||
if items.len() > 6 {
|
||||
reasons.push("selfPatch values may contain at most 6 records".to_string());
|
||||
}
|
||||
let mut valid = 0usize;
|
||||
for (index, item) in items.iter().enumerate() {
|
||||
let Some(record) = item.as_object() else {
|
||||
reasons.push(format!("selfPatch values[{index}] must be an object"));
|
||||
continue;
|
||||
};
|
||||
review_self_patch_id(reasons, record, "values", index, "valueId", "value-");
|
||||
review_self_patch_summary(reasons, record, "values", index, "label", 240);
|
||||
review_self_patch_unit(reasons, record, "values", index, "priority");
|
||||
if !record
|
||||
.get("unforgivableIfBetrayed")
|
||||
.is_some_and(serde_json::Value::is_boolean)
|
||||
{
|
||||
reasons.push(format!(
|
||||
"selfPatch values[{index}].unforgivableIfBetrayed must be a boolean"
|
||||
));
|
||||
}
|
||||
valid += 1;
|
||||
}
|
||||
valid
|
||||
}
|
||||
|
||||
fn review_self_patch_private_notes(
|
||||
reasons: &mut Vec<String>,
|
||||
object: &serde_json::Map<String, serde_json::Value>,
|
||||
) -> usize {
|
||||
let Some(value) = object.get("privateNotes") else {
|
||||
return 0;
|
||||
};
|
||||
let Some(items) = value.as_array() else {
|
||||
reasons.push("selfPatch privateNotes must be an array".to_string());
|
||||
return 0;
|
||||
};
|
||||
if items.len() > 6 {
|
||||
reasons.push("selfPatch privateNotes may contain at most 6 records".to_string());
|
||||
}
|
||||
for (index, item) in items.iter().enumerate() {
|
||||
match item.as_str() {
|
||||
Some(text) if !text.trim().is_empty() && text.len() <= 600 => {}
|
||||
_ => reasons.push(format!(
|
||||
"selfPatch privateNotes[{index}] must be non-empty text under 600 characters"
|
||||
)),
|
||||
}
|
||||
}
|
||||
items.len()
|
||||
}
|
||||
|
||||
fn review_self_patch_string_array(
|
||||
reasons: &mut Vec<String>,
|
||||
object: &serde_json::Map<String, serde_json::Value>,
|
||||
field: &str,
|
||||
max_items: usize,
|
||||
max_len: usize,
|
||||
) {
|
||||
let Some(value) = object.get(field) else {
|
||||
return;
|
||||
};
|
||||
let Some(items) = value.as_array() else {
|
||||
reasons.push(format!("selfPatch {field} must be an array"));
|
||||
return;
|
||||
};
|
||||
if items.len() > max_items {
|
||||
reasons.push(format!(
|
||||
"selfPatch {field} may contain at most {max_items} records"
|
||||
));
|
||||
}
|
||||
for (index, item) in items.iter().enumerate() {
|
||||
match item.as_str() {
|
||||
Some(text) if !text.trim().is_empty() && text.len() <= max_len => {}
|
||||
_ => reasons.push(format!(
|
||||
"selfPatch {field}[{index}] must be non-empty text under {max_len} characters"
|
||||
)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn review_self_patch_id(
|
||||
reasons: &mut Vec<String>,
|
||||
record: &serde_json::Map<String, serde_json::Value>,
|
||||
collection: &str,
|
||||
index: usize,
|
||||
field: &str,
|
||||
prefix: &str,
|
||||
) {
|
||||
match record.get(field).and_then(serde_json::Value::as_str) {
|
||||
Some(id)
|
||||
if id.starts_with(prefix)
|
||||
&& id.len() <= 120
|
||||
&& id
|
||||
.chars()
|
||||
.all(|ch| ch.is_ascii_alphanumeric() || "-_.".contains(ch)) => {}
|
||||
Some(_) => reasons.push(format!(
|
||||
"selfPatch {collection}[{index}].{field} must start with {prefix:?}, avoid whitespace, and stay under 120 characters"
|
||||
)),
|
||||
None => reasons.push(format!(
|
||||
"selfPatch {collection}[{index}].{field} is required"
|
||||
)),
|
||||
}
|
||||
}
|
||||
|
||||
fn review_self_patch_summary(
|
||||
reasons: &mut Vec<String>,
|
||||
record: &serde_json::Map<String, serde_json::Value>,
|
||||
collection: &str,
|
||||
index: usize,
|
||||
field: &str,
|
||||
max_len: usize,
|
||||
) {
|
||||
match record.get(field).and_then(serde_json::Value::as_str) {
|
||||
Some(text) if !text.trim().is_empty() && text.len() <= max_len => {}
|
||||
Some(_) => reasons.push(format!(
|
||||
"selfPatch {collection}[{index}].{field} must be non-empty text under {max_len} characters"
|
||||
)),
|
||||
None => reasons.push(format!(
|
||||
"selfPatch {collection}[{index}].{field} is required"
|
||||
)),
|
||||
}
|
||||
}
|
||||
|
||||
fn review_self_patch_string(
|
||||
reasons: &mut Vec<String>,
|
||||
record: &serde_json::Map<String, serde_json::Value>,
|
||||
collection: &str,
|
||||
index: usize,
|
||||
field: &str,
|
||||
max_len: usize,
|
||||
) {
|
||||
match record.get(field).and_then(serde_json::Value::as_str) {
|
||||
Some(text) if !text.trim().is_empty() && text.len() <= max_len => {}
|
||||
Some(_) => reasons.push(format!(
|
||||
"selfPatch {collection}[{index}].{field} must be non-empty text under {max_len} characters"
|
||||
)),
|
||||
None => reasons.push(format!(
|
||||
"selfPatch {collection}[{index}].{field} is required"
|
||||
)),
|
||||
}
|
||||
}
|
||||
|
||||
fn review_self_patch_unit(
|
||||
reasons: &mut Vec<String>,
|
||||
record: &serde_json::Map<String, serde_json::Value>,
|
||||
collection: &str,
|
||||
index: usize,
|
||||
field: &str,
|
||||
) {
|
||||
match record.get(field).and_then(serde_json::Value::as_f64) {
|
||||
Some(value) if (0.0..=1.0).contains(&value) => {}
|
||||
Some(_) => reasons.push(format!(
|
||||
"selfPatch {collection}[{index}].{field} must be between 0 and 1"
|
||||
)),
|
||||
None => reasons.push(format!(
|
||||
"selfPatch {collection}[{index}].{field} is required"
|
||||
)),
|
||||
}
|
||||
}
|
||||
|
||||
#[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"
|
||||
}),
|
||||
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"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn reviews_acceptable_self_patch() {
|
||||
let finding = interpret_role_finding(
|
||||
EpiphanyRoleResultRoleId::Modeling,
|
||||
&serde_json::json!({
|
||||
"statePatch": {"scratch": {"summary": "Source-grounded modeling checkpoint."}},
|
||||
"selfPatch": {
|
||||
"agentId": "epiphany.body",
|
||||
"reason": "The Body should remember graph growth must stay source-grounded and bounded.",
|
||||
"semanticMemories": [{
|
||||
"memoryId": "mem-body-source-grounded-growth",
|
||||
"summary": "Grow graph and checkpoint state only when source evidence makes the anatomy harder to misread.",
|
||||
"salience": 0.82,
|
||||
"confidence": 0.9
|
||||
}]
|
||||
}
|
||||
}),
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
);
|
||||
|
||||
let review = finding.self_persistence.as_ref().unwrap();
|
||||
assert_eq!(review.status, EpiphanyRoleSelfPersistenceStatus::Accepted);
|
||||
assert_eq!(review.target_agent_id.as_deref(), Some("epiphany.body"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rejects_bad_self_patch() {
|
||||
let finding = interpret_role_finding(
|
||||
EpiphanyRoleResultRoleId::Verification,
|
||||
&serde_json::json!({
|
||||
"selfPatch": {
|
||||
"agentId": "epiphany.body",
|
||||
"reason": "Too broad.",
|
||||
"graphs": {},
|
||||
"semanticMemories": [{
|
||||
"memoryId": "mem-soul-bad-project-truth",
|
||||
"summary": "Project graph state belongs in memory now.",
|
||||
"salience": 0.7,
|
||||
"confidence": 0.4
|
||||
}]
|
||||
}
|
||||
}),
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
);
|
||||
|
||||
let review = finding.self_persistence.as_ref().unwrap();
|
||||
assert_eq!(review.status, EpiphanyRoleSelfPersistenceStatus::Rejected);
|
||||
assert!(
|
||||
review
|
||||
.reasons
|
||||
.iter()
|
||||
.any(|reason| reason.contains("expected \"epiphany.soul\""))
|
||||
);
|
||||
assert!(
|
||||
review
|
||||
.reasons
|
||||
.iter()
|
||||
.any(|reason| reason.contains("project truth"))
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn marks_modeling_without_patch_unreviewable() {
|
||||
let missing = interpret_role_finding(
|
||||
EpiphanyRoleResultRoleId::Modeling,
|
||||
&serde_json::json!({"verdict": "checkpoint-ready"}),
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
);
|
||||
|
||||
assert!(
|
||||
missing
|
||||
.item_error
|
||||
.as_deref()
|
||||
.is_some_and(|error| error.contains("missing required statePatch"))
|
||||
);
|
||||
|
||||
let reviewable = interpret_role_finding(
|
||||
EpiphanyRoleResultRoleId::Modeling,
|
||||
&serde_json::json!({"statePatch": {"scratch": {"summary": "banked"}}}),
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
);
|
||||
|
||||
assert!(reviewable.item_error.is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn marks_imagination_without_planning_patch_unreviewable() {
|
||||
let missing = interpret_role_finding(
|
||||
EpiphanyRoleResultRoleId::Imagination,
|
||||
&serde_json::json!({"verdict": "draft-ready"}),
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
);
|
||||
|
||||
assert!(
|
||||
missing
|
||||
.item_error
|
||||
.as_deref()
|
||||
.is_some_and(|error| error.contains("missing required statePatch"))
|
||||
);
|
||||
|
||||
let reviewable = interpret_role_finding(
|
||||
EpiphanyRoleResultRoleId::Imagination,
|
||||
&serde_json::json!({
|
||||
"statePatch": {
|
||||
"planning": {
|
||||
"objectiveDrafts": [{
|
||||
"id": "draft-imagination-test",
|
||||
"status": "draft",
|
||||
"acceptanceCriteria": ["A criterion"],
|
||||
"reviewGates": ["human review"]
|
||||
}]
|
||||
}
|
||||
}
|
||||
}),
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
);
|
||||
|
||||
assert!(reviewable.item_error.is_none());
|
||||
}
|
||||
}
|
||||
|
|
@ -36,7 +36,7 @@ The spine exists in more than twenty-five live paths:
|
|||
- reorientation policy: the `reorient` view lens reuses the same live/stored thread view plus mapped pressure/freshness/watcher signals, and derives a bounded `resume`/`regather` verdict with checkpoint-path/frontier reasons without mutating, compacting, scheduling, notifying, or continuing work in [v2.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server-protocol/src/protocol/v2.rs:4514), [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:4394), and [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:11424).
|
||||
- CRRC coordinator recommendation: the `crrc` view lens reuses pressure/freshness/watcher/reorientation mapping plus the fixed `reorient-worker` binding and result read-back helper, recognizes already accepted reorientation findings so an accepted result is not recommended for acceptance again, and calls pure `epiphany-core` CRRC policy to return one bounded recommendation such as continue, prepare checkpoint, launch worker, wait, review, accept, or regather manually without mutating, launching, accepting, compacting, notifying, scheduling, or silently continuing work in [v2.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server-protocol/src/protocol/v2.rs:4661), [crrc.rs](E:/Projects/EpiphanyAgent/epiphany-core/src/surfaces/crrc.rs:60), and [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:4546).
|
||||
- role ownership projection: the `roles` view lens reuses the same state/jobs/pressure/reorient/result/CRRC signals as the coordinator loop, and projects implementation, Imagination/planning, modeling/checkpoint, verification/review, and reorientation lanes with owner roles, status, linked jobs, authority scopes, and recommended scene actions without launching, scheduling, accepting, compacting, notifying, or mutating state. App-server adapts concrete protocol jobs and thread state, while the pure role-board projection policy now lives in [role_board.rs](E:/Projects/EpiphanyAgent/epiphany-core/src/surfaces/role_board.rs:70).
|
||||
- role specialist launch/read-back/acceptance: app-server declares experimental `thread/epiphany/roleLaunch`, read-only `thread/epiphany/roleResult`, and write-gated `thread/epiphany/roleAccept`. `roleLaunch` accepts fixed Imagination/planning, modeling/checkpoint, and verification/review role ids, builds bounded specialist payloads from authoritative Epiphany state, routes them through the heartbeat-backed `epiphany_launch_job` seam, opens a typed runtime-spine job receipt, and emits the normal `jobLaunch` state update for `jobBindings` only. `roleResult` resolves heartbeat bindings through typed runtime-spine job results and seals legacy `agent_jobs` bindings, projecting structured output as a reviewable finding with verdict, summary, next safe move, inspected files, frontier/evidence ids, optional `statePatch`, optional `selfPatch`, coordinator `selfPersistence` review, raw result, and errors without mutation, promotion, scheduling, or hidden continuation. `selfPatch` is a Ghostlight-shaped lane-memory request, not project truth: the coordinator accepts only role-matched, bounded, evidence-grounded memory/goal/value/private-note mutations and refuses objectives, graphs, checkpoints, scratch, planning, jobs, authority, code edits, or raw transcripts with reasons. `roleAccept` accepts completed heartbeat findings from typed runtime-spine results, accepts completed Imagination findings only when they contain a valid planning-only patch with draft Objective Draft review gates, accepts completed modeling/checkpoint findings only with a modeling-safe `statePatch`, applies accepted project patches through the existing Epiphany state validator, appends audit observation/evidence, and carries the same `selfPersistence` review. GUI/coordinator accept paths then apply accepted `selfPatch` requests to typed CultCache role dossiers in `state/agents.msgpack` through the native `epiphany-agent-memory-store` binary. Implementation stays owned by the main coding agent, verification output remains review-only, and reorientation stays on the CRRC-specific `reorientLaunch` / `reorientResult` / `reorientAccept` path.
|
||||
- role specialist launch/read-back/acceptance: app-server declares experimental `thread/epiphany/roleLaunch`, read-only `thread/epiphany/roleResult`, and write-gated `thread/epiphany/roleAccept`. `roleLaunch` accepts fixed Imagination/planning, modeling/checkpoint, and verification/review role ids, builds bounded specialist payloads from authoritative Epiphany state, routes them through the heartbeat-backed `epiphany_launch_job` seam, opens a typed runtime-spine job receipt, and emits the normal `jobLaunch` state update for `jobBindings` only. `roleResult` resolves heartbeat bindings through typed runtime-spine job results and seals legacy `agent_jobs` bindings, then adapts worker JSON through core role-result interpretation in [role_result.rs](E:/Projects/EpiphanyAgent/epiphany-core/src/surfaces/role_result.rs:45), projecting structured output as a reviewable finding with verdict, summary, next safe move, inspected files, frontier/evidence ids, optional `statePatch`, optional `selfPatch`, coordinator `selfPersistence` review, and errors without mutation, promotion, scheduling, or hidden continuation. `selfPatch` is a Ghostlight-shaped lane-memory request, not project truth: core accepts only role-matched, bounded, evidence-grounded memory/goal/value/private-note mutations and refuses objectives, graphs, checkpoints, scratch, planning, jobs, authority, code edits, or raw transcripts with reasons. `roleAccept` accepts completed heartbeat findings from typed runtime-spine results, accepts completed Imagination findings only when they contain a valid planning-only patch with draft Objective Draft review gates, accepts completed modeling/checkpoint findings only with a modeling-safe `statePatch`, applies accepted project patches through the existing Epiphany state validator, appends audit observation/evidence, and carries the same `selfPersistence` review. GUI/coordinator accept paths then apply accepted `selfPatch` requests to typed CultCache role dossiers in `state/agents.msgpack` through the native `epiphany-agent-memory-store` binary. Implementation stays owned by the main coding agent, verification output remains review-only, and reorientation stays on the CRRC-specific `reorientLaunch` / `reorientResult` / `reorientAccept` path.
|
||||
- shared prompt memory projection and role dossiers: the prompt config now carries `[shared].persistent_memory` in [epiphany_specialists.toml](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/prompts/epiphany_specialists.toml:2). App-server parses that block, prepends it through `epiphany_agent_prompt_with_memory`, and therefore projects the same Ghostlight-derived memory into fixed role specialist instructions, reorientation-worker instructions, coordinator notes, and CRRC checkpoint steering. The base `<epiphany_state>` doctrine reinforces the Perfect Machine rule through [prompt.rs](E:/Projects/EpiphanyAgent/epiphany-core/src/prompt.rs:31) and [epiphany_doctrine.md](E:/Projects/EpiphanyAgent/epiphany-core/src/prompts/epiphany_doctrine.md:1). Individual Ghostlight-shaped role dossiers now live in typed CultCache `state/agents.msgpack`, and the native `epiphany-agent-memory-store` binary validates, reviews, and applies bounded self-memory patches through the Rust store.
|
||||
- fixed-lane coordinator: the `coordinator` view lens composes role, pressure, reorient, CRRC, role result, and reorient result signals, and returns one current action without mutation. App-server assembles host/protocol inputs, but the pure fixed-lane decision ladder now lives in `epiphany-core` in [coordinator.rs](E:/Projects/EpiphanyAgent/epiphany-core/src/surfaces/coordinator.rs:132). Review acceptance and implementation clearance are intentionally different: an accepted verification finding clears implementation only when the verifier verdict is `pass`; accepted `needs-evidence`, `needs-review`, or `fail` findings route back toward modeling/checkpoint strengthening before code work resumes. `regatherManually` is now fallback, not a supervisor-puppeteering excuse: completed unaccepted modeling findings stop at `reviewModelingResult`, modeling acceptance precedes verification, and fixed lane actions are considered before manual regather.
|
||||
- MVP operator view: native `epiphany-mvp-status` launches app-server over stdio, starts or reads one thread, gathers scene, planning, pressure, reorient, jobs, roles, Imagination/modeling/verification role results, reorient result, CRRC responses, heartbeat, and Face bubble artifacts, and renders them as text or JSON so the loop can be dogfooded without Python owning the product surface.
|
||||
|
|
@ -55,7 +55,7 @@ The thick Epiphany-owned implementation is mostly outside vendored Codex now:
|
|||
- deterministic observation distillation lives in [epiphany-core/src/distillation.rs](E:/Projects/EpiphanyAgent/epiphany-core/src/distillation.rs:28).
|
||||
- deterministic map/churn proposal from verified, evidence-backed observations lives in [epiphany-core/src/proposal.rs](E:/Projects/EpiphanyAgent/epiphany-core/src/proposal.rs:115).
|
||||
- verifier-backed promotion policy lives in [epiphany-core/src/promotion.rs](E:/Projects/EpiphanyAgent/epiphany-core/src/promotion.rs:33).
|
||||
- pressure, pure CRRC recommendation policy, fixed-lane coordinator decision policy, and role-board projection policy live in [pressure.rs](E:/Projects/EpiphanyAgent/epiphany-core/src/surfaces/pressure.rs:15), [crrc.rs](E:/Projects/EpiphanyAgent/epiphany-core/src/surfaces/crrc.rs:60), [coordinator.rs](E:/Projects/EpiphanyAgent/epiphany-core/src/surfaces/coordinator.rs:132), and [role_board.rs](E:/Projects/EpiphanyAgent/epiphany-core/src/surfaces/role_board.rs:70).
|
||||
- pressure, pure CRRC recommendation policy, fixed-lane coordinator decision policy, role-board projection policy, and role-result interpretation/self-persistence review policy live in [pressure.rs](E:/Projects/EpiphanyAgent/epiphany-core/src/surfaces/pressure.rs:15), [crrc.rs](E:/Projects/EpiphanyAgent/epiphany-core/src/surfaces/crrc.rs:60), [coordinator.rs](E:/Projects/EpiphanyAgent/epiphany-core/src/surfaces/coordinator.rs:132), [role_board.rs](E:/Projects/EpiphanyAgent/epiphany-core/src/surfaces/role_board.rs:70), and [role_result.rs](E:/Projects/EpiphanyAgent/epiphany-core/src/surfaces/role_result.rs:45).
|
||||
|
||||
## Whole Control Flow
|
||||
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ remembers doctrine; the branch remembers the blade.
|
|||
## Current Orientation
|
||||
|
||||
- Do not copy exact branch or HEAD from this note. Run `git status --short --branch` and `git log --oneline -5`.
|
||||
- Top priority is still foundation cleanup, not outward feature work. Read `notes/epiphany-architectural-teardown.md` before touching Epiphany control-plane code. The May 2026 suspicion pass found that the app-server Epiphany control plane had become architectural Jenga: too much policy, projection, lifecycle glue, prompt packet assembly, coordinator sequencing, and test authority lives in `vendor/codex/codex-rs/app-server/src/codex_message_processor.rs`. The rebuild has begun: pressure policy, pure CRRC recommendation policy, fixed-lane coordinator decision policy, and role-board projection policy moved into `epiphany-core`, typed acceptance receipts replaced summary-string identity for live accept paths, runtime links are dual-written on launch, and result read-back now prefers runtime links.
|
||||
- Top priority is still foundation cleanup, not outward feature work. Read `notes/epiphany-architectural-teardown.md` before touching Epiphany control-plane code. The May 2026 suspicion pass found that the app-server Epiphany control plane had become architectural Jenga: too much policy, projection, lifecycle glue, prompt packet assembly, coordinator sequencing, and test authority lives in `vendor/codex/codex-rs/app-server/src/codex_message_processor.rs`. The rebuild has begun: pressure policy, pure CRRC recommendation policy, fixed-lane coordinator decision policy, role-board projection policy, and role-result interpretation/self-persistence review policy moved into `epiphany-core`, typed acceptance receipts replaced summary-string identity for live accept paths, runtime links are dual-written on launch, and result read-back now prefers runtime links.
|
||||
- Read `notes/epiphany-ideal-architecture-rebuild-plan.md` immediately after the teardown. It defines the smallest coherent replacement architecture: durable `EpiphanyState`, runtime-spine-owned `RuntimeState`, separate role memory/heartbeat state, `epiphany-core` as policy owner, app-server as adapter, Aquarium as reflector, typed acceptance receipts, and derived view lenses instead of a protocol verb zoo.
|
||||
- Do not continue Aquarium UI, bridge, Face, or dogfood expansion until the teardown has a source-grounded cleanup slice plan. Epiphany is the foundation; patches on patches are not a purification rite, they are how the altar becomes load-bearing garbage.
|
||||
- Phase 1 through Phase 5 are complete enough.
|
||||
|
|
@ -367,15 +367,15 @@ The next real move is still foundation cleanup. Start from
|
|||
`notes/epiphany-ideal-architecture-rebuild-plan.md`, not from the older outward
|
||||
Phase 6 bridge/UI trail. Landed rebuild cuts: `epiphany-core/src/surfaces/`
|
||||
exists, pressure view derivation/tests, pure CRRC recommendation policy/tests,
|
||||
fixed-lane coordinator decision policy/tests, and role-board projection
|
||||
policy/tests live in core, live acceptance writes typed receipts keyed by runtime result id,
|
||||
fixed-lane coordinator decision policy/tests, role-board projection policy/tests,
|
||||
and role-result interpretation/self-persistence review policy/tests live in core, live acceptance writes typed receipts keyed by runtime result id,
|
||||
summary-string acceptance identity is gone for live paths, launches dual-write
|
||||
runtime links, result read-back prefers those runtime links, normal public
|
||||
`raw_result` is sealed, MVP consumers use `thread/epiphany/view`, heartbeat
|
||||
cognition is quarantined, and the old scene/jobs/roles/planning/pressure/reorient/
|
||||
CRRC/coordinator read wrappers are deleted. The next cut is role-result
|
||||
interpretation or acceptance policy extraction into `epiphany-core`. No Agile
|
||||
confetti. No new balcony on the swaying tower.
|
||||
CRRC/coordinator read wrappers are deleted. The next cut is acceptance/application
|
||||
policy extraction into `epiphany-core`, followed by runtime/job lifecycle mirror
|
||||
cleanup. No Agile confetti. No new balcony on the swaying tower.
|
||||
|
||||
The Phase 6 freshness slice is landed. It exposes read-only
|
||||
`thread/epiphany/freshness` from live retrieval summaries plus graph
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -100,7 +100,7 @@ accepted_design:
|
|||
- `thread/epiphany/retrieve`, `thread/epiphany/distill`, `thread/epiphany/propose`, `thread/epiphany/freshness`, `thread/epiphany/context`, `thread/epiphany/graphQuery`, and `thread/epiphany/view` stay read-only.
|
||||
- `thread/epiphany/index` writes the retrieval catalog, not durable Epiphany understanding; catalog is auspex output, not doctrine.
|
||||
- Qdrant is the preferred persistent semantic backend; BM25 remains the bootstrap/fallback/control path.
|
||||
- `epiphany-core` owns prompt rendering, rollout replay helpers, retrieval/indexing, distillation, proposal, promotion policy, pressure derivation, pure CRRC recommendation policy, fixed-lane coordinator decision policy, and role-board projection policy where possible.
|
||||
- `epiphany-core` owns prompt rendering, rollout replay helpers, retrieval/indexing, distillation, proposal, promotion policy, pressure derivation, pure CRRC recommendation policy, fixed-lane coordinator decision policy, role-board projection policy, and role-result interpretation/self-persistence review policy where possible.
|
||||
- Vendored Codex keeps the thin typed host seam: protocol types, thread bridges, app-server protocol, request routing, and rollout integration.
|
||||
- The current algorithmic map is the source-grounded description of live control flow.
|
||||
- Compact-Rehydrate-Reorient-Continue is an architecture primitive; automatic runtime coordination is not landed yet.
|
||||
|
|
@ -273,4 +273,4 @@ rejected_paths:
|
|||
|
||||
current_status:
|
||||
summary: Phase 1 durable state through Phase 6 coordinator/specialist/CRRC/backend organs are landed, and the May 2026 rebuild has started cutting the app-server control-plane tumor. Pressure policy now lives in `epiphany-core`; role/reorient acceptance writes typed `acceptance_receipts`; live duplicate-acceptance checks use runtime result receipt identity instead of summary strings; launch writes durable `runtime_links`; and role/reorient result read-back follows runtime links before falling back to legacy bindings.
|
||||
next_action: Continue the teardown/rebuild migration from `notes/epiphany-ideal-architecture-rebuild-plan.md`. Landed cuts now shrink `jobBindings`, remove normal public `raw_result`, add the canonical `thread/epiphany/view` lens wrapper, migrate MVP consumers, quarantine heartbeat cognition blobs, delete the old scene/jobs/roles/planning/pressure/reorient/CRRC/coordinator read wrappers, and move pure CRRC, fixed-lane coordinator decision policy, and role-board projection policy into `epiphany-core`. The next bounded cut is to extract role-result interpretation or acceptance policy from app-server into `epiphany-core`. Do not resume outward Aquarium/bridge/Face/dogfood expansion until this foundation cleanup is materially farther along.
|
||||
next_action: Continue the teardown/rebuild migration from `notes/epiphany-ideal-architecture-rebuild-plan.md`. Landed cuts now shrink `jobBindings`, remove normal public `raw_result`, add the canonical `thread/epiphany/view` lens wrapper, migrate MVP consumers, quarantine heartbeat cognition blobs, delete the old scene/jobs/roles/planning/pressure/reorient/CRRC/coordinator read wrappers, and move pure CRRC, fixed-lane coordinator decision policy, role-board projection policy, and role-result interpretation/self-persistence review policy into `epiphany-core`. The next bounded cut is to finish extracting acceptance/application policy from app-server into `epiphany-core`, then reassess runtime/job lifecycle mirror cleanup. Do not resume outward Aquarium/bridge/Face/dogfood expansion until this foundation cleanup is materially farther along.
|
||||
|
|
|
|||
|
|
@ -523,12 +523,19 @@ use epiphany_core::EpiphanyRoleBoardJob;
|
|||
use epiphany_core::EpiphanyRoleBoardJobStatus;
|
||||
use epiphany_core::EpiphanyRoleBoardLane;
|
||||
use epiphany_core::EpiphanyRoleBoardPlanningSummary;
|
||||
use epiphany_core::EpiphanyRoleFindingInterpretation;
|
||||
use epiphany_core::EpiphanyRoleResultRoleId;
|
||||
use epiphany_core::EpiphanyRoleSelfPersistenceReview as CoreEpiphanyRoleSelfPersistenceReview;
|
||||
use epiphany_core::EpiphanyRoleSelfPersistenceStatus as CoreEpiphanyRoleSelfPersistenceStatus;
|
||||
use epiphany_core::EpiphanyRuntimeJobResult;
|
||||
use epiphany_core::EpiphanyRuntimeJobSnapshot;
|
||||
use epiphany_core::EpiphanyRuntimeJobStatus;
|
||||
use epiphany_core::coordinator_automation_action;
|
||||
use epiphany_core::derive_pressure_view;
|
||||
use epiphany_core::derive_role_board;
|
||||
use epiphany_core::imagination_role_state_patch_policy_errors;
|
||||
use epiphany_core::interpret_role_finding;
|
||||
use epiphany_core::modeling_role_state_patch_policy_errors;
|
||||
use epiphany_core::recommend_coordinator_action;
|
||||
use epiphany_core::recommend_crrc_action;
|
||||
use epiphany_core::render_role_board_note;
|
||||
|
|
@ -13306,464 +13313,85 @@ fn map_epiphany_role_finding(
|
|||
job_error: Option<String>,
|
||||
item_error: Option<String>,
|
||||
) -> ThreadEpiphanyRoleFinding {
|
||||
let state_patch = raw_result
|
||||
let state_patch_result = raw_result
|
||||
.get("statePatch")
|
||||
.cloned()
|
||||
.and_then(|patch| serde_json::from_value(patch).ok());
|
||||
let self_patch = raw_result.get("selfPatch").cloned();
|
||||
let self_persistence = self_patch
|
||||
.map(serde_json::from_value::<ThreadEpiphanyUpdatePatch>);
|
||||
let state_patch = state_patch_result
|
||||
.as_ref()
|
||||
.map(|patch| review_epiphany_role_self_patch(role_id, patch));
|
||||
let item_error = match role_id {
|
||||
ThreadEpiphanyRoleId::Imagination => merge_epiphany_item_error(
|
||||
item_error,
|
||||
imagination_role_state_patch_error(&raw_result, state_patch.as_ref()),
|
||||
),
|
||||
ThreadEpiphanyRoleId::Modeling => merge_epiphany_item_error(
|
||||
item_error,
|
||||
modeling_role_state_patch_error(&raw_result, state_patch.as_ref()),
|
||||
),
|
||||
ThreadEpiphanyRoleId::Implementation
|
||||
| ThreadEpiphanyRoleId::Verification
|
||||
| ThreadEpiphanyRoleId::Reorientation => item_error,
|
||||
};
|
||||
ThreadEpiphanyRoleFinding {
|
||||
role_id,
|
||||
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"),
|
||||
state_patch,
|
||||
self_patch,
|
||||
self_persistence,
|
||||
.and_then(|result| result.as_ref().ok().cloned());
|
||||
let state_patch_parse_error = state_patch_result
|
||||
.as_ref()
|
||||
.and_then(|result| result.as_ref().err().map(ToString::to_string));
|
||||
let finding = interpret_role_finding(
|
||||
map_core_role_result_role_id(role_id),
|
||||
&raw_result,
|
||||
state_patch_parse_error,
|
||||
job_error,
|
||||
item_error,
|
||||
}
|
||||
);
|
||||
map_protocol_role_finding(role_id, finding, state_patch)
|
||||
}
|
||||
|
||||
fn merge_epiphany_item_error(
|
||||
item_error: Option<String>,
|
||||
modeling_error: Option<String>,
|
||||
) -> Option<String> {
|
||||
match (item_error, modeling_error) {
|
||||
(Some(existing), Some(extra)) => Some(format!("{existing}; {extra}")),
|
||||
(Some(existing), None) => Some(existing),
|
||||
(None, Some(extra)) => Some(extra),
|
||||
(None, None) => None,
|
||||
}
|
||||
}
|
||||
|
||||
fn epiphany_role_self_memory_target(role_id: ThreadEpiphanyRoleId) -> (&'static str, &'static str) {
|
||||
match role_id {
|
||||
ThreadEpiphanyRoleId::Imagination => (
|
||||
"epiphany.imagination",
|
||||
"state/agents/imagination.agent-state.json",
|
||||
),
|
||||
ThreadEpiphanyRoleId::Modeling => ("epiphany.body", "state/agents/body.agent-state.json"),
|
||||
ThreadEpiphanyRoleId::Verification => {
|
||||
("epiphany.soul", "state/agents/soul.agent-state.json")
|
||||
}
|
||||
ThreadEpiphanyRoleId::Implementation => {
|
||||
("epiphany.hands", "state/agents/hands.agent-state.json")
|
||||
}
|
||||
ThreadEpiphanyRoleId::Reorientation => {
|
||||
("epiphany.life", "state/agents/life.agent-state.json")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn review_epiphany_role_self_patch(
|
||||
fn map_protocol_role_finding(
|
||||
role_id: ThreadEpiphanyRoleId,
|
||||
patch: &serde_json::Value,
|
||||
finding: EpiphanyRoleFindingInterpretation,
|
||||
state_patch: Option<ThreadEpiphanyUpdatePatch>,
|
||||
) -> ThreadEpiphanyRoleFinding {
|
||||
ThreadEpiphanyRoleFinding {
|
||||
role_id,
|
||||
verdict: finding.verdict,
|
||||
summary: finding.summary,
|
||||
next_safe_move: finding.next_safe_move,
|
||||
checkpoint_summary: finding.checkpoint_summary,
|
||||
scratch_summary: finding.scratch_summary,
|
||||
files_inspected: finding.files_inspected,
|
||||
frontier_node_ids: finding.frontier_node_ids,
|
||||
evidence_ids: finding.evidence_ids,
|
||||
artifact_refs: finding.artifact_refs,
|
||||
runtime_result_id: finding.runtime_result_id,
|
||||
runtime_job_id: finding.runtime_job_id,
|
||||
open_questions: finding.open_questions,
|
||||
evidence_gaps: finding.evidence_gaps,
|
||||
risks: finding.risks,
|
||||
state_patch,
|
||||
self_patch: finding.self_patch,
|
||||
self_persistence: finding
|
||||
.self_persistence
|
||||
.map(map_protocol_role_self_persistence_review),
|
||||
job_error: finding.job_error,
|
||||
item_error: finding.item_error,
|
||||
}
|
||||
}
|
||||
|
||||
fn map_core_role_result_role_id(role_id: ThreadEpiphanyRoleId) -> EpiphanyRoleResultRoleId {
|
||||
match role_id {
|
||||
ThreadEpiphanyRoleId::Implementation => EpiphanyRoleResultRoleId::Implementation,
|
||||
ThreadEpiphanyRoleId::Imagination => EpiphanyRoleResultRoleId::Imagination,
|
||||
ThreadEpiphanyRoleId::Modeling => EpiphanyRoleResultRoleId::Modeling,
|
||||
ThreadEpiphanyRoleId::Verification => EpiphanyRoleResultRoleId::Verification,
|
||||
ThreadEpiphanyRoleId::Reorientation => EpiphanyRoleResultRoleId::Reorientation,
|
||||
}
|
||||
}
|
||||
|
||||
fn map_protocol_role_self_persistence_review(
|
||||
review: CoreEpiphanyRoleSelfPersistenceReview,
|
||||
) -> ThreadEpiphanyRoleSelfPersistenceReview {
|
||||
let (expected_agent_id, target_path) = epiphany_role_self_memory_target(role_id);
|
||||
let mut reasons = Vec::new();
|
||||
let Some(object) = patch.as_object() else {
|
||||
return ThreadEpiphanyRoleSelfPersistenceReview {
|
||||
status: ThreadEpiphanyRoleSelfPersistenceStatus::Rejected,
|
||||
target_agent_id: Some(expected_agent_id.to_string()),
|
||||
target_path: Some(target_path.to_string()),
|
||||
reasons: vec!["selfPatch must be a JSON object".to_string()],
|
||||
};
|
||||
};
|
||||
|
||||
let agent_id = object.get("agentId").and_then(serde_json::Value::as_str);
|
||||
match agent_id {
|
||||
Some(id) if id == expected_agent_id => {}
|
||||
Some(id) => reasons.push(format!(
|
||||
"selfPatch agentId {id:?} does not match this lane; expected {expected_agent_id:?}"
|
||||
)),
|
||||
None => reasons.push(format!(
|
||||
"selfPatch must include agentId {expected_agent_id:?}"
|
||||
)),
|
||||
}
|
||||
match object.get("reason").and_then(serde_json::Value::as_str) {
|
||||
Some(reason) if reason.trim().len() >= 16 && reason.len() <= 800 => {}
|
||||
Some(_) => reasons.push(
|
||||
"selfPatch reason must be a bounded explanation of at least 16 characters".to_string(),
|
||||
),
|
||||
None => reasons.push(
|
||||
"selfPatch must include a reason explaining why this improves the lane".to_string(),
|
||||
),
|
||||
}
|
||||
|
||||
let allowed = [
|
||||
"agentId",
|
||||
"reason",
|
||||
"evidenceIds",
|
||||
"semanticMemories",
|
||||
"episodicMemories",
|
||||
"relationshipMemories",
|
||||
"goals",
|
||||
"values",
|
||||
"privateNotes",
|
||||
];
|
||||
let forbidden = [
|
||||
"statePatch",
|
||||
"objective",
|
||||
"activeSubgoalId",
|
||||
"subgoals",
|
||||
"invariants",
|
||||
"graphs",
|
||||
"graphFrontier",
|
||||
"graphCheckpoint",
|
||||
"scratch",
|
||||
"investigationCheckpoint",
|
||||
"jobBindings",
|
||||
"planning",
|
||||
"churn",
|
||||
"mode",
|
||||
"codeEdits",
|
||||
"files",
|
||||
"authorityScope",
|
||||
"backendJobId",
|
||||
"rawResult",
|
||||
];
|
||||
for key in object.keys() {
|
||||
if forbidden.contains(&key.as_str()) {
|
||||
reasons.push(format!(
|
||||
"selfPatch field {key:?} is project truth or authority; use statePatch, roleAccept, or another explicit control surface instead"
|
||||
));
|
||||
} else if !allowed.contains(&key.as_str()) {
|
||||
reasons.push(format!(
|
||||
"selfPatch field {key:?} is not part of the bounded memory mutation contract"
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
let mut mutation_count = 0usize;
|
||||
mutation_count += review_self_patch_memories(&mut reasons, object, "semanticMemories");
|
||||
mutation_count += review_self_patch_memories(&mut reasons, object, "episodicMemories");
|
||||
mutation_count += review_self_patch_memories(&mut reasons, object, "relationshipMemories");
|
||||
mutation_count += review_self_patch_goals(&mut reasons, object);
|
||||
mutation_count += review_self_patch_values(&mut reasons, object);
|
||||
mutation_count += review_self_patch_private_notes(&mut reasons, object);
|
||||
review_self_patch_string_array(&mut reasons, object, "evidenceIds", 16, 160);
|
||||
if mutation_count == 0 {
|
||||
reasons.push(
|
||||
"selfPatch must contain at least one semantic memory, episodic memory, relationship memory, goal, value, or private note"
|
||||
.to_string(),
|
||||
);
|
||||
}
|
||||
|
||||
ThreadEpiphanyRoleSelfPersistenceReview {
|
||||
status: if reasons.is_empty() {
|
||||
ThreadEpiphanyRoleSelfPersistenceStatus::Accepted
|
||||
} else {
|
||||
ThreadEpiphanyRoleSelfPersistenceStatus::Rejected
|
||||
status: match review.status {
|
||||
CoreEpiphanyRoleSelfPersistenceStatus::Missing => {
|
||||
ThreadEpiphanyRoleSelfPersistenceStatus::Missing
|
||||
}
|
||||
CoreEpiphanyRoleSelfPersistenceStatus::Accepted => {
|
||||
ThreadEpiphanyRoleSelfPersistenceStatus::Accepted
|
||||
}
|
||||
CoreEpiphanyRoleSelfPersistenceStatus::Rejected => {
|
||||
ThreadEpiphanyRoleSelfPersistenceStatus::Rejected
|
||||
}
|
||||
},
|
||||
target_agent_id: Some(expected_agent_id.to_string()),
|
||||
target_path: Some(target_path.to_string()),
|
||||
reasons,
|
||||
}
|
||||
}
|
||||
|
||||
fn review_self_patch_memories(
|
||||
reasons: &mut Vec<String>,
|
||||
object: &serde_json::Map<String, serde_json::Value>,
|
||||
field: &str,
|
||||
) -> usize {
|
||||
let Some(value) = object.get(field) else {
|
||||
return 0;
|
||||
};
|
||||
let Some(items) = value.as_array() else {
|
||||
reasons.push(format!("selfPatch {field} must be an array"));
|
||||
return 0;
|
||||
};
|
||||
if items.len() > 8 {
|
||||
reasons.push(format!("selfPatch {field} may contain at most 8 records"));
|
||||
}
|
||||
let mut valid = 0usize;
|
||||
for (index, item) in items.iter().enumerate() {
|
||||
let Some(record) = item.as_object() else {
|
||||
reasons.push(format!("selfPatch {field}[{index}] must be an object"));
|
||||
continue;
|
||||
};
|
||||
review_self_patch_id(reasons, record, field, index, "memoryId", "mem-");
|
||||
review_self_patch_summary(reasons, record, field, index, "summary", 600);
|
||||
review_self_patch_unit(reasons, record, field, index, "salience");
|
||||
review_self_patch_unit(reasons, record, field, index, "confidence");
|
||||
valid += 1;
|
||||
}
|
||||
valid
|
||||
}
|
||||
|
||||
fn review_self_patch_goals(
|
||||
reasons: &mut Vec<String>,
|
||||
object: &serde_json::Map<String, serde_json::Value>,
|
||||
) -> usize {
|
||||
let Some(value) = object.get("goals") else {
|
||||
return 0;
|
||||
};
|
||||
let Some(items) = value.as_array() else {
|
||||
reasons.push("selfPatch goals must be an array".to_string());
|
||||
return 0;
|
||||
};
|
||||
if items.len() > 6 {
|
||||
reasons.push("selfPatch goals may contain at most 6 records".to_string());
|
||||
}
|
||||
let mut valid = 0usize;
|
||||
for (index, item) in items.iter().enumerate() {
|
||||
let Some(record) = item.as_object() else {
|
||||
reasons.push(format!("selfPatch goals[{index}] must be an object"));
|
||||
continue;
|
||||
};
|
||||
review_self_patch_id(reasons, record, "goals", index, "goalId", "goal-");
|
||||
review_self_patch_summary(reasons, record, "goals", index, "description", 700);
|
||||
review_self_patch_string(reasons, record, "goals", index, "scope", 80);
|
||||
review_self_patch_unit(reasons, record, "goals", index, "priority");
|
||||
review_self_patch_string(reasons, record, "goals", index, "emotionalStake", 400);
|
||||
review_self_patch_string(reasons, record, "goals", index, "status", 80);
|
||||
valid += 1;
|
||||
}
|
||||
valid
|
||||
}
|
||||
|
||||
fn review_self_patch_values(
|
||||
reasons: &mut Vec<String>,
|
||||
object: &serde_json::Map<String, serde_json::Value>,
|
||||
) -> usize {
|
||||
let Some(value) = object.get("values") else {
|
||||
return 0;
|
||||
};
|
||||
let Some(items) = value.as_array() else {
|
||||
reasons.push("selfPatch values must be an array".to_string());
|
||||
return 0;
|
||||
};
|
||||
if items.len() > 6 {
|
||||
reasons.push("selfPatch values may contain at most 6 records".to_string());
|
||||
}
|
||||
let mut valid = 0usize;
|
||||
for (index, item) in items.iter().enumerate() {
|
||||
let Some(record) = item.as_object() else {
|
||||
reasons.push(format!("selfPatch values[{index}] must be an object"));
|
||||
continue;
|
||||
};
|
||||
review_self_patch_id(reasons, record, "values", index, "valueId", "value-");
|
||||
review_self_patch_summary(reasons, record, "values", index, "label", 240);
|
||||
review_self_patch_unit(reasons, record, "values", index, "priority");
|
||||
if !record
|
||||
.get("unforgivableIfBetrayed")
|
||||
.is_some_and(serde_json::Value::is_boolean)
|
||||
{
|
||||
reasons.push(format!(
|
||||
"selfPatch values[{index}].unforgivableIfBetrayed must be a boolean"
|
||||
));
|
||||
}
|
||||
valid += 1;
|
||||
}
|
||||
valid
|
||||
}
|
||||
|
||||
fn review_self_patch_private_notes(
|
||||
reasons: &mut Vec<String>,
|
||||
object: &serde_json::Map<String, serde_json::Value>,
|
||||
) -> usize {
|
||||
let Some(value) = object.get("privateNotes") else {
|
||||
return 0;
|
||||
};
|
||||
let Some(items) = value.as_array() else {
|
||||
reasons.push("selfPatch privateNotes must be an array".to_string());
|
||||
return 0;
|
||||
};
|
||||
if items.len() > 6 {
|
||||
reasons.push("selfPatch privateNotes may contain at most 6 records".to_string());
|
||||
}
|
||||
for (index, item) in items.iter().enumerate() {
|
||||
match item.as_str() {
|
||||
Some(text) if !text.trim().is_empty() && text.len() <= 600 => {}
|
||||
_ => reasons.push(format!(
|
||||
"selfPatch privateNotes[{index}] must be non-empty text under 600 characters"
|
||||
)),
|
||||
}
|
||||
}
|
||||
items.len()
|
||||
}
|
||||
|
||||
fn review_self_patch_string_array(
|
||||
reasons: &mut Vec<String>,
|
||||
object: &serde_json::Map<String, serde_json::Value>,
|
||||
field: &str,
|
||||
max_items: usize,
|
||||
max_len: usize,
|
||||
) {
|
||||
let Some(value) = object.get(field) else {
|
||||
return;
|
||||
};
|
||||
let Some(items) = value.as_array() else {
|
||||
reasons.push(format!("selfPatch {field} must be an array"));
|
||||
return;
|
||||
};
|
||||
if items.len() > max_items {
|
||||
reasons.push(format!(
|
||||
"selfPatch {field} may contain at most {max_items} records"
|
||||
));
|
||||
}
|
||||
for (index, item) in items.iter().enumerate() {
|
||||
match item.as_str() {
|
||||
Some(text) if !text.trim().is_empty() && text.len() <= max_len => {}
|
||||
_ => reasons.push(format!(
|
||||
"selfPatch {field}[{index}] must be non-empty text under {max_len} characters"
|
||||
)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn review_self_patch_id(
|
||||
reasons: &mut Vec<String>,
|
||||
record: &serde_json::Map<String, serde_json::Value>,
|
||||
collection: &str,
|
||||
index: usize,
|
||||
field: &str,
|
||||
prefix: &str,
|
||||
) {
|
||||
match record.get(field).and_then(serde_json::Value::as_str) {
|
||||
Some(id)
|
||||
if id.starts_with(prefix)
|
||||
&& id.len() <= 120
|
||||
&& id.chars().all(|ch| ch.is_ascii_alphanumeric() || "-_.".contains(ch)) => {}
|
||||
Some(_) => reasons.push(format!(
|
||||
"selfPatch {collection}[{index}].{field} must start with {prefix:?}, avoid whitespace, and stay under 120 characters"
|
||||
)),
|
||||
None => reasons.push(format!(
|
||||
"selfPatch {collection}[{index}].{field} is required"
|
||||
)),
|
||||
}
|
||||
}
|
||||
|
||||
fn review_self_patch_summary(
|
||||
reasons: &mut Vec<String>,
|
||||
record: &serde_json::Map<String, serde_json::Value>,
|
||||
collection: &str,
|
||||
index: usize,
|
||||
field: &str,
|
||||
max_len: usize,
|
||||
) {
|
||||
match record.get(field).and_then(serde_json::Value::as_str) {
|
||||
Some(text) if !text.trim().is_empty() && text.len() <= max_len => {}
|
||||
Some(_) => reasons.push(format!(
|
||||
"selfPatch {collection}[{index}].{field} must be non-empty text under {max_len} characters"
|
||||
)),
|
||||
None => reasons.push(format!(
|
||||
"selfPatch {collection}[{index}].{field} is required"
|
||||
)),
|
||||
}
|
||||
}
|
||||
|
||||
fn review_self_patch_string(
|
||||
reasons: &mut Vec<String>,
|
||||
record: &serde_json::Map<String, serde_json::Value>,
|
||||
collection: &str,
|
||||
index: usize,
|
||||
field: &str,
|
||||
max_len: usize,
|
||||
) {
|
||||
match record.get(field).and_then(serde_json::Value::as_str) {
|
||||
Some(text) if !text.trim().is_empty() && text.len() <= max_len => {}
|
||||
Some(_) => reasons.push(format!(
|
||||
"selfPatch {collection}[{index}].{field} must be non-empty text under {max_len} characters"
|
||||
)),
|
||||
None => reasons.push(format!(
|
||||
"selfPatch {collection}[{index}].{field} is required"
|
||||
)),
|
||||
}
|
||||
}
|
||||
|
||||
fn review_self_patch_unit(
|
||||
reasons: &mut Vec<String>,
|
||||
record: &serde_json::Map<String, serde_json::Value>,
|
||||
collection: &str,
|
||||
index: usize,
|
||||
field: &str,
|
||||
) {
|
||||
match record.get(field).and_then(serde_json::Value::as_f64) {
|
||||
Some(value) if (0.0..=1.0).contains(&value) => {}
|
||||
Some(_) => reasons.push(format!(
|
||||
"selfPatch {collection}[{index}].{field} must be between 0 and 1"
|
||||
)),
|
||||
None => reasons.push(format!(
|
||||
"selfPatch {collection}[{index}].{field} is required"
|
||||
)),
|
||||
}
|
||||
}
|
||||
|
||||
fn modeling_role_state_patch_error(
|
||||
raw_result: &serde_json::Value,
|
||||
state_patch: Option<&ThreadEpiphanyUpdatePatch>,
|
||||
) -> Option<String> {
|
||||
let Some(value) = raw_result.get("statePatch") else {
|
||||
return Some("modeling result is not reviewable: missing required statePatch".to_string());
|
||||
};
|
||||
let Some(patch) = state_patch else {
|
||||
return Some(format!(
|
||||
"modeling result is not reviewable: invalid statePatch ({})",
|
||||
serde_json::from_value::<ThreadEpiphanyUpdatePatch>(value.clone()).unwrap_err()
|
||||
));
|
||||
};
|
||||
let errors = modeling_role_accept_patch_errors(patch);
|
||||
if errors.is_empty() {
|
||||
None
|
||||
} else {
|
||||
Some(format!(
|
||||
"modeling result is not reviewable: {}",
|
||||
errors.join("; ")
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
fn imagination_role_state_patch_error(
|
||||
raw_result: &serde_json::Value,
|
||||
state_patch: Option<&ThreadEpiphanyUpdatePatch>,
|
||||
) -> Option<String> {
|
||||
let Some(value) = raw_result.get("statePatch") else {
|
||||
return Some(
|
||||
"imagination result is not reviewable: missing required statePatch".to_string(),
|
||||
);
|
||||
};
|
||||
let Some(patch) = state_patch else {
|
||||
return Some(format!(
|
||||
"imagination result is not reviewable: invalid statePatch ({})",
|
||||
serde_json::from_value::<ThreadEpiphanyUpdatePatch>(value.clone()).unwrap_err()
|
||||
));
|
||||
};
|
||||
let errors = imagination_role_accept_patch_errors(patch);
|
||||
if errors.is_empty() {
|
||||
None
|
||||
} else {
|
||||
Some(format!(
|
||||
"imagination result is not reviewable: {}",
|
||||
errors.join("; ")
|
||||
))
|
||||
target_agent_id: review.target_agent_id,
|
||||
target_path: review.target_path,
|
||||
reasons: review.reasons,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -15232,142 +14860,13 @@ fn parse_role_finding_state_patch(
|
|||
}
|
||||
|
||||
fn imagination_role_accept_patch_errors(patch: &ThreadEpiphanyUpdatePatch) -> Vec<String> {
|
||||
let mut errors = Vec::new();
|
||||
if patch.objective.is_some() {
|
||||
errors.push(
|
||||
"objective changes are not allowed through imagination role acceptance".to_string(),
|
||||
);
|
||||
}
|
||||
if patch.active_subgoal_id.is_some() || patch.subgoals.is_some() {
|
||||
errors.push(
|
||||
"subgoal changes are not allowed through imagination role acceptance".to_string(),
|
||||
);
|
||||
}
|
||||
if patch.invariants.is_some() {
|
||||
errors.push(
|
||||
"invariant changes are not allowed through imagination role acceptance".to_string(),
|
||||
);
|
||||
}
|
||||
if patch.graphs.is_some()
|
||||
|| patch.graph_frontier.is_some()
|
||||
|| patch.graph_checkpoint.is_some()
|
||||
|| patch.investigation_checkpoint.is_some()
|
||||
{
|
||||
errors.push(
|
||||
"graph or checkpoint changes are not allowed through imagination role acceptance"
|
||||
.to_string(),
|
||||
);
|
||||
}
|
||||
if patch.scratch.is_some() {
|
||||
errors.push(
|
||||
"scratch changes are not allowed through imagination role acceptance".to_string(),
|
||||
);
|
||||
}
|
||||
if patch.job_bindings.is_some() {
|
||||
errors.push(
|
||||
"job binding changes are not allowed through imagination role acceptance".to_string(),
|
||||
);
|
||||
}
|
||||
if !patch.acceptance_receipts.is_empty() {
|
||||
errors.push(
|
||||
"acceptance receipt changes are owned by roleAccept, not worker statePatch".to_string(),
|
||||
);
|
||||
}
|
||||
if !patch.runtime_links.is_empty() {
|
||||
errors.push(
|
||||
"runtime link changes are owned by launch/read-back surfaces, not worker statePatch"
|
||||
.to_string(),
|
||||
);
|
||||
}
|
||||
if patch.churn.is_some() || patch.mode.is_some() {
|
||||
errors.push(
|
||||
"churn or mode changes are not allowed through imagination role acceptance".to_string(),
|
||||
);
|
||||
}
|
||||
let Some(planning) = patch.planning.as_ref() else {
|
||||
errors.push("statePatch must include planning changes".to_string());
|
||||
return errors;
|
||||
};
|
||||
if planning.objective_drafts.is_empty() {
|
||||
errors.push("planning patch must include at least one objective draft".to_string());
|
||||
}
|
||||
if !planning
|
||||
.objective_drafts
|
||||
.iter()
|
||||
.any(|draft| draft.status.eq_ignore_ascii_case("draft"))
|
||||
{
|
||||
errors.push(
|
||||
"planning patch must include at least one objective draft with status draft"
|
||||
.to_string(),
|
||||
);
|
||||
}
|
||||
for draft in &planning.objective_drafts {
|
||||
if draft.acceptance_criteria.is_empty() {
|
||||
errors.push(format!(
|
||||
"planning objective draft {:?} must include acceptance criteria",
|
||||
draft.id
|
||||
));
|
||||
}
|
||||
if draft.review_gates.is_empty() {
|
||||
errors.push(format!(
|
||||
"planning objective draft {:?} must include review gates",
|
||||
draft.id
|
||||
));
|
||||
}
|
||||
}
|
||||
errors
|
||||
let value = serde_json::to_value(patch).unwrap_or_else(|_| serde_json::Value::Null);
|
||||
imagination_role_state_patch_policy_errors(&value)
|
||||
}
|
||||
|
||||
fn modeling_role_accept_patch_errors(patch: &ThreadEpiphanyUpdatePatch) -> Vec<String> {
|
||||
let mut errors = Vec::new();
|
||||
if patch.objective.is_some() {
|
||||
errors
|
||||
.push("objective changes are not allowed through modeling role acceptance".to_string());
|
||||
}
|
||||
if patch.active_subgoal_id.is_some() || patch.subgoals.is_some() {
|
||||
errors.push("subgoal changes are not allowed through modeling role acceptance".to_string());
|
||||
}
|
||||
if patch.invariants.is_some() {
|
||||
errors
|
||||
.push("invariant changes are not allowed through modeling role acceptance".to_string());
|
||||
}
|
||||
if patch.job_bindings.is_some() {
|
||||
errors.push(
|
||||
"job binding changes are not allowed through modeling role acceptance".to_string(),
|
||||
);
|
||||
}
|
||||
if !patch.acceptance_receipts.is_empty() {
|
||||
errors.push(
|
||||
"acceptance receipt changes are owned by roleAccept, not worker statePatch".to_string(),
|
||||
);
|
||||
}
|
||||
if !patch.runtime_links.is_empty() {
|
||||
errors.push(
|
||||
"runtime link changes are owned by launch/read-back surfaces, not worker statePatch"
|
||||
.to_string(),
|
||||
);
|
||||
}
|
||||
if patch.planning.is_some() {
|
||||
errors
|
||||
.push("planning changes are not allowed through modeling role acceptance".to_string());
|
||||
}
|
||||
if patch.churn.is_some() || patch.mode.is_some() {
|
||||
errors.push(
|
||||
"churn or mode changes are not allowed through modeling role acceptance".to_string(),
|
||||
);
|
||||
}
|
||||
if patch.graphs.is_none()
|
||||
&& patch.graph_frontier.is_none()
|
||||
&& patch.graph_checkpoint.is_none()
|
||||
&& patch.scratch.is_none()
|
||||
&& patch.investigation_checkpoint.is_none()
|
||||
{
|
||||
errors.push(
|
||||
"statePatch must include a modeling field: graphs, graphFrontier, graphCheckpoint, scratch, or investigationCheckpoint"
|
||||
.to_string(),
|
||||
);
|
||||
}
|
||||
errors
|
||||
let value = serde_json::to_value(patch).unwrap_or_else(|_| serde_json::Value::Null);
|
||||
modeling_role_state_patch_policy_errors(&value)
|
||||
}
|
||||
|
||||
fn role_finding_summary(finding: &ThreadEpiphanyRoleFinding) -> String {
|
||||
|
|
|
|||
Reference in a new issue