Bind Idunn sight to real lifecycle evidence

This commit is contained in:
Meta Vens 2026-07-13 18:25:19 +01:00
commit af34ef6b9a
8 changed files with 510 additions and 201 deletions

View file

@ -77,6 +77,7 @@ use epiphany_core::load_latest_epiphany_cultmesh_repo_work_map_entry;
use epiphany_core::load_latest_epiphany_cultmesh_repo_work_overview;
use epiphany_core::load_latest_epiphany_cultmesh_repo_work_public_proof;
use epiphany_core::load_latest_epiphany_cultmesh_repo_work_readiness;
use epiphany_core::native_process_executable_path;
use epiphany_core::observe_native_process;
use epiphany_core::open_epiphany_cultmesh_node;
use epiphany_core::publish_epiphany_cultmesh_provider_state;
@ -103,6 +104,7 @@ use std::fs;
use std::path::{Path, PathBuf};
const WRAPPER_OVERVIEW_COMMAND: &str = "tools/epiphany_local_run.ps1 -Mode swarm-overview";
const DIRECT_MANAGED_SERVICE_SIGHT_COMMAND: &str = "epiphany-verse-query managed-services";
const WRAPPER_SWARM_ONLINE_RUNBOOK_COMMAND: &str =
"tools/epiphany_local_run.ps1 -Mode swarm-online-runbook";
const WRAPPER_POKE_NON_READY_COMMAND: &str = "tools/epiphany_local_run.ps1 -Mode swarm-poke-down";
@ -377,7 +379,7 @@ fn run_cli() -> Result<()> {
"attentionCount": report.attention_count,
"rows": report.rows,
"tuiRows": report.tui_rows,
"privateStateExposed": false,
"privateStateExposed": report.private_state_exposed,
}))?
);
}
@ -795,6 +797,7 @@ fn run_cli() -> Result<()> {
"tools": "epiphany-verse-query tool-directory",
"receipts": "epiphany-verse-query receipt-directory",
"restartPolicies": "epiphany-verse-query restart-policy-directory",
"managedServiceSight": DIRECT_MANAGED_SERVICE_SIGHT_COMMAND,
"repoWorkOverview": "epiphany-work overview --workspace <repo> --item <item>",
"repoWorkMap": "epiphany-verse-query swarm-overview",
"idunnDeploymentAftercareAudit": DIRECT_IDUNN_DEPLOYMENT_AFTERCARE_AUDIT_COMMAND,
@ -3267,7 +3270,7 @@ struct DaemonToolDirectoryReport {
host_attention_count: usize,
}
#[derive(Serialize)]
#[derive(Clone, Debug, PartialEq, Serialize)]
#[serde(rename_all = "camelCase")]
struct ManagedServiceSightReport {
status: String,
@ -3275,9 +3278,10 @@ struct ManagedServiceSightReport {
attention_count: usize,
rows: Vec<ManagedServiceSightRow>,
tui_rows: Vec<String>,
private_state_exposed: bool,
}
#[derive(Serialize)]
#[derive(Clone, Debug, PartialEq, Serialize)]
#[serde(rename_all = "camelCase")]
struct ManagedServiceSightRow {
service_id: String,
@ -3286,6 +3290,7 @@ struct ManagedServiceSightRow {
restart_mode: String,
process_observation: String,
process_id: Option<u32>,
process_identity_verified: bool,
lifecycle_receipt_id: Option<String>,
lifecycle_status: Option<String>,
last_pulse_status: Option<String>,
@ -3308,11 +3313,21 @@ fn managed_service_sight_report(
.filter(|receipt| receipt.service_id == policy.service_id)
.max_by(|left, right| left.started_at_utc.cmp(&right.started_at_utc));
let process_id = latest.and_then(|receipt| receipt.process_id);
let process_observation = process_id
let mut process_observation = process_id
.map(observe_native_process)
.transpose()?
.map(|observation| observation.label().to_string())
.unwrap_or_else(|| "missing".to_string());
let process_identity_verified = if process_observation == "alive" {
latest.is_some_and(|receipt| {
verify_process_executable_identity(process_id, &receipt.executable_sha256)
})
} else {
false
};
if process_observation == "alive" && !process_identity_verified {
process_observation = "identity-unverified".to_string();
}
let pulse = compact_last_service_pulse(&policy);
rows.push(ManagedServiceSightRow {
service_id: policy.service_id,
@ -3321,6 +3336,7 @@ fn managed_service_sight_report(
restart_mode: policy.restart_mode,
process_observation,
process_id,
process_identity_verified,
lifecycle_receipt_id: latest.map(|receipt| receipt.receipt_id.clone()),
lifecycle_status: latest.map(|receipt| receipt.status.clone()),
last_pulse_status: pulse
@ -3335,6 +3351,12 @@ fn managed_service_sight_report(
private_state_exposed: false,
});
}
Ok(managed_service_sight_report_from_rows(rows))
}
fn managed_service_sight_report_from_rows(
mut rows: Vec<ManagedServiceSightRow>,
) -> ManagedServiceSightReport {
rows.sort_by(|left, right| left.service_id.cmp(&right.service_id));
let alive_count = rows
.iter()
@ -3349,7 +3371,13 @@ fn managed_service_sight_report(
.map(|row| {
format!(
"{} | service={} | owner={} | desired={} | restart={} | observed={} | pid={} | lifecycle={} | pulse={} | iteration={} | private=false",
if row.enabled && row.process_observation == "alive" { "READY" } else { "ATTN" },
if !row.enabled {
"DISABLED"
} else if row.process_observation == "alive" {
"READY"
} else {
"ATTN"
},
row.service_id,
row.owner_daemon_id,
if row.enabled { "enabled" } else { "disabled" },
@ -3362,7 +3390,7 @@ fn managed_service_sight_report(
)
})
.collect();
Ok(ManagedServiceSightReport {
ManagedServiceSightReport {
status: if attention_count == 0 {
"ready"
} else {
@ -3373,7 +3401,28 @@ fn managed_service_sight_report(
attention_count,
rows,
tui_rows,
})
private_state_exposed: false,
}
}
fn verify_process_executable_identity(process_id: Option<u32>, expected_sha256: &str) -> bool {
let Some(process_id) = process_id else {
return false;
};
if expected_sha256.trim().is_empty() {
return false;
}
let Ok(Some(path)) = native_process_executable_path(process_id) else {
return false;
};
let Ok(bytes) = fs::read(path) else {
return false;
};
format!("{:x}", Sha256::digest(bytes)).eq_ignore_ascii_case(expected_sha256.trim())
}
fn managed_service_overview_requires_attention(report: &ManagedServiceSightReport) -> bool {
report.attention_count > 0
}
fn compact_last_service_pulse(
@ -3441,6 +3490,7 @@ struct SwarmOverviewReport {
tool_host_attention_tui_rows: Vec<String>,
service_lifecycle_attention_rows: Vec<ReceiptDirectoryRow>,
service_lifecycle_attention_tui_rows: Vec<String>,
managed_service_report: ManagedServiceSightReport,
service_execution_failed_check_count: usize,
service_execution_missing_check_count: usize,
service_execution_failed_check_rows: Vec<EpiphanyServiceExecutionAuditCheck>,
@ -3796,6 +3846,10 @@ struct SwarmOverviewOutput {
tool_host_attention_tui_rows: Vec<String>,
service_lifecycle_attention_count: usize,
service_lifecycle_attention_rows: Vec<ReceiptDirectoryRow>,
managed_service_count: usize,
managed_service_alive_count: usize,
managed_service_attention_count: usize,
managed_service_rows: Vec<ManagedServiceSightRow>,
service_execution_failed_check_count: usize,
service_execution_missing_check_count: usize,
service_execution_failed_check_rows: Vec<EpiphanyServiceExecutionAuditCheck>,
@ -3904,6 +3958,10 @@ impl SwarmOverviewOutput {
tool_host_attention_tui_rows: report.tool_host_attention_tui_rows,
service_lifecycle_attention_count: report.service_lifecycle_attention_rows.len(),
service_lifecycle_attention_rows: report.service_lifecycle_attention_rows,
managed_service_count: report.managed_service_report.rows.len(),
managed_service_alive_count: report.managed_service_report.alive_count,
managed_service_attention_count: report.managed_service_report.attention_count,
managed_service_rows: report.managed_service_report.rows,
service_execution_failed_check_count: report.service_execution_failed_check_count,
service_execution_missing_check_count: report.service_execution_missing_check_count,
service_execution_failed_check_rows: report.service_execution_failed_check_rows,
@ -6165,6 +6223,7 @@ fn load_swarm_overview_report(args: &Args) -> Result<SwarmOverviewReport> {
args.runtime_id.clone(),
)?;
let policy_report = daemon_restart_policy_directory_report_from_rows(&policy_directory);
let managed_service_report = managed_service_sight_report(&args.store, &args.runtime_id)?;
let lifecycle_receipts = load_epiphany_cultmesh_daemon_service_lifecycle_receipts(
&args.store,
args.runtime_id.clone(),
@ -6271,6 +6330,7 @@ fn load_swarm_overview_report(args: &Args) -> Result<SwarmOverviewReport> {
let recovery_status = if topology_report.rows.is_empty() {
"unknown".to_string()
} else if policy_report.status == "ok"
&& !managed_service_overview_requires_attention(&managed_service_report)
&& cluster_service_lifecycle_attention.is_none()
&& service_lifecycle_attention.is_none()
{
@ -6299,7 +6359,13 @@ fn load_swarm_overview_report(args: &Args) -> Result<SwarmOverviewReport> {
WRAPPER_POKE_NON_READY_COMMAND.to_string(),
)
} else if recovery_status != "ready" {
if policy_report.status != "ok" {
if managed_service_overview_requires_attention(&managed_service_report) {
(
DIRECT_MANAGED_SERVICE_SIGHT_COMMAND.to_string(),
"managed-services".to_string(),
DIRECT_MANAGED_SERVICE_SIGHT_COMMAND.to_string(),
)
} else if policy_report.status != "ok" {
(
"epiphany-verse-query restart-policy-directory".to_string(),
"service-policy-directory".to_string(),
@ -6420,6 +6486,11 @@ fn load_swarm_overview_report(args: &Args) -> Result<SwarmOverviewReport> {
.any(|row| row.private_state_exposed)
|| tool_report.rows.iter().any(|row| row.private_state_exposed)
|| policy_report.private_state_exposed
|| managed_service_report.private_state_exposed
|| managed_service_report
.rows
.iter()
.any(|row| row.private_state_exposed)
|| repo_work_overviews
.iter()
.any(|overview| overview.private_state_exposed)
@ -6508,6 +6579,7 @@ fn load_swarm_overview_report(args: &Args) -> Result<SwarmOverviewReport> {
tool_host_attention_tui_rows,
service_lifecycle_attention_rows,
service_lifecycle_attention_tui_rows,
managed_service_report,
service_execution_failed_check_count,
service_execution_missing_check_count,
service_execution_failed_check_rows,
@ -9517,6 +9589,100 @@ fn required_list(values: &Option<Vec<String>>, message: &str) -> Result<Vec<Stri
mod lifecycle_projection_tests {
use super::*;
fn managed_service_row(
service_id: &str,
enabled: bool,
process_observation: &str,
lifecycle_status: &str,
) -> ManagedServiceSightRow {
ManagedServiceSightRow {
service_id: service_id.to_string(),
owner_daemon_id: "Idunn".to_string(),
enabled,
restart_mode: "on-failure".to_string(),
process_observation: process_observation.to_string(),
process_id: Some(4242),
process_identity_verified: process_observation == "alive",
lifecycle_receipt_id: Some("stale-receipt".to_string()),
lifecycle_status: Some(lifecycle_status.to_string()),
last_pulse_status: Some("ready".to_string()),
last_pulse_iteration: Some(7),
last_pulse_artifact: Some("sealed-artifact".to_string()),
private_state_exposed: false,
}
}
#[test]
fn managed_service_native_dead_observation_beats_stale_lifecycle_readiness() {
let report = managed_service_sight_report_from_rows(vec![managed_service_row(
"svc-dead", true, "dead", "ready",
)]);
assert_eq!(report.status, "attention");
assert_eq!(report.attention_count, 1);
assert!(managed_service_overview_requires_attention(&report));
assert!(report.tui_rows[0].starts_with("ATTN |"));
}
#[test]
fn disabled_managed_service_does_not_force_overview_attention() {
let report = managed_service_sight_report_from_rows(vec![managed_service_row(
"svc-disabled",
false,
"missing",
"ready",
)]);
assert_eq!(report.status, "ready");
assert_eq!(report.attention_count, 0);
assert!(!managed_service_overview_requires_attention(&report));
assert!(report.tui_rows[0].starts_with("DISABLED |"));
}
#[test]
fn unverified_process_identity_cannot_satisfy_managed_service_sight() {
let mut row = managed_service_row("svc-reused-pid", true, "identity-unverified", "ready");
row.process_identity_verified = false;
let report = managed_service_sight_report_from_rows(vec![row]);
assert_eq!(report.status, "attention");
assert_eq!(report.alive_count, 0);
assert!(managed_service_overview_requires_attention(&report));
}
#[test]
fn specialist_and_overview_share_compact_sealed_sight_rows() -> Result<()> {
let report = managed_service_sight_report_from_rows(vec![managed_service_row(
"svc-shared",
true,
"alive",
"ready",
)]);
let specialist_projection = serde_json::to_value(&report)?;
let overview_rows = serde_json::to_value(&report.rows)?;
assert_eq!(specialist_projection["rows"], overview_rows);
assert_eq!(specialist_projection["privateStateExposed"], false);
assert_eq!(
specialist_projection["rows"][0]["privateStateExposed"],
false
);
assert!(specialist_projection.get("privatePayload").is_none());
assert!(
specialist_projection["rows"][0]
.get("privatePayload")
.is_none()
);
Ok(())
}
#[test]
fn swarm_managed_service_route_is_read_only_idunn_sight() {
assert_eq!(
DIRECT_MANAGED_SERVICE_SIGHT_COMMAND,
"epiphany-verse-query managed-services"
);
for forbidden in ["reconcile", "launch", "restart", "write", "deploy"] {
assert!(!DIRECT_MANAGED_SERVICE_SIGHT_COMMAND.contains(forbidden));
}
}
#[test]
fn repo_work_stage_lens_preserves_per_family_ownership() {
let expected = [

View file

@ -10,6 +10,8 @@ use epiphany_core::EPIPHANY_CULTMESH_REPO_WORK_OVERVIEW_SCHEMA_VERSION;
use epiphany_core::EPIPHANY_CULTMESH_REPO_WORK_PUBLIC_PROOF_SCHEMA_VERSION;
use epiphany_core::EPIPHANY_CULTMESH_REPO_WORK_READINESS_SCHEMA_VERSION;
use epiphany_core::EPIPHANY_CULTMESH_WEKSA_LOWERING_RECEIPT_SCHEMA_VERSION;
use epiphany_core::EpiphanyCultMeshIdunnAftercareAuditReceiptEntry;
use epiphany_core::EpiphanyCultMeshIdunnDeploymentReceiptEntry;
use epiphany_core::EpiphanyCultMeshRepoWorkMapEntry;
use epiphany_core::EpiphanyCultMeshRepoWorkOverviewEntry;
use epiphany_core::EpiphanyCultMeshRepoWorkPublicProofEntry;
@ -315,7 +317,6 @@ struct ReadinessArgs {
public_proof: Option<PathBuf>,
idunn_lifecycle_receipt: Option<PathBuf>,
tool_directory_receipt: Option<PathBuf>,
deployment_aftercare_audit_receipt: Option<PathBuf>,
deployment_aftercare_audit_receipt_ref: Option<String>,
write_receipt: bool,
}
@ -342,9 +343,7 @@ struct DeploymentAftercareAuditArgs {
local_verse_store: Option<PathBuf>,
runtime_id: String,
runbook_receipt: Option<PathBuf>,
idunn_deployment_receipt: Option<PathBuf>,
idunn_deployment_receipt_ref: Option<String>,
aftercare_audit_receipt: Option<PathBuf>,
aftercare_audit_receipt_ref: Option<String>,
write_receipt: bool,
}
@ -924,7 +923,6 @@ fn parse_readiness_args(args: impl Iterator<Item = String>) -> Result<ReadinessA
let mut public_proof = None;
let mut idunn_lifecycle_receipt = None;
let mut tool_directory_receipt = None;
let mut deployment_aftercare_audit_receipt = None;
let mut deployment_aftercare_audit_receipt_ref = None;
let mut write_receipt = true;
@ -944,12 +942,6 @@ fn parse_readiness_args(args: impl Iterator<Item = String>) -> Result<ReadinessA
"--tool-directory-receipt" | "--tool-directory-ref" => {
tool_directory_receipt = Some(take_path(&mut args, "--tool-directory-receipt")?);
}
"--deployment-aftercare-audit-receipt" | "--deployment-aftercare-receipt" => {
deployment_aftercare_audit_receipt = Some(take_path(
&mut args,
"--deployment-aftercare-audit-receipt",
)?);
}
"--deployment-aftercare-audit-receipt-ref" | "--deployment-aftercare-receipt-ref" => {
deployment_aftercare_audit_receipt_ref = Some(take_string(
&mut args,
@ -968,7 +960,6 @@ fn parse_readiness_args(args: impl Iterator<Item = String>) -> Result<ReadinessA
public_proof,
idunn_lifecycle_receipt,
tool_directory_receipt,
deployment_aftercare_audit_receipt,
deployment_aftercare_audit_receipt_ref,
write_receipt,
})
@ -1039,9 +1030,7 @@ fn parse_deployment_aftercare_audit_args(
let mut local_verse_store = None;
let mut runtime_id = "repo-swarm-local".to_string();
let mut runbook_receipt = None;
let mut idunn_deployment_receipt = None;
let mut idunn_deployment_receipt_ref = None;
let mut aftercare_audit_receipt = None;
let mut aftercare_audit_receipt_ref = None;
let mut write_receipt = true;
@ -1057,16 +1046,10 @@ fn parse_deployment_aftercare_audit_args(
"--runbook-receipt" => {
runbook_receipt = Some(take_path(&mut args, "--runbook-receipt")?)
}
"--idunn-deployment-receipt" | "--deployment-receipt" => {
idunn_deployment_receipt = Some(take_path(&mut args, "--idunn-deployment-receipt")?)
}
"--idunn-deployment-receipt-ref" | "--deployment-receipt-ref" => {
idunn_deployment_receipt_ref =
Some(take_string(&mut args, "--idunn-deployment-receipt-ref")?)
}
"--aftercare-audit-receipt" | "--aftercare-receipt" => {
aftercare_audit_receipt = Some(take_path(&mut args, "--aftercare-audit-receipt")?)
}
"--aftercare-audit-receipt-ref" | "--aftercare-receipt-ref" => {
aftercare_audit_receipt_ref =
Some(take_string(&mut args, "--aftercare-audit-receipt-ref")?)
@ -1085,9 +1068,7 @@ fn parse_deployment_aftercare_audit_args(
local_verse_store,
runtime_id,
runbook_receipt,
idunn_deployment_receipt,
idunn_deployment_receipt_ref,
aftercare_audit_receipt,
aftercare_audit_receipt_ref,
write_receipt,
})
@ -10174,18 +10155,6 @@ fn run_readiness(args: ReadinessArgs) -> Result<Value> {
"Supply --idunn-lifecycle-receipt or run repo-work-service-audit into the repo work artifact directory.",
));
}
let default_deployment_aftercare_audit_receipt =
artifact_dir.join("deployment-aftercare-audit.json");
let deployment_aftercare_audit_path =
args.deployment_aftercare_audit_receipt
.as_ref()
.or_else(|| {
if default_deployment_aftercare_audit_receipt.exists() {
Some(&default_deployment_aftercare_audit_receipt)
} else {
None
}
});
if let Some(receipt_ref) = args.deployment_aftercare_audit_receipt_ref.as_ref() {
let readiness_store = local_verse_store
.clone()
@ -10203,11 +10172,38 @@ fn run_readiness(args: ReadinessArgs) -> Result<Value> {
)?
};
if let Some(receipt) = receipt {
let status_ok = matches!(receipt.status.as_str(), "ok" | "complete" | "passed");
let status_ok = receipt.status == "complete";
let deployment = load_epiphany_cultmesh_idunn_deployment_receipt(
&readiness_store,
runtime_id.clone(),
&receipt.deployment_receipt_id,
)?;
let current_commit = git_output(&workspace, &["rev-parse", "HEAD"])?;
let runbook =
read_json_if_exists(&artifact_dir.join("deployment-execution-runbook.json"))?;
let runbook_watched_ref = runbook
.as_ref()
.and_then(|value| string_from_json(value, &["watchedRef"]));
let runbook_commit = runbook
.as_ref()
.and_then(|value| string_from_json(value, &["currentCommit"]));
let deployment_chain_ok = deployment.as_ref().is_some_and(|deployment| {
idunn_deployment_aftercare_chain_valid(
deployment,
&receipt,
&runtime_id,
&current_commit,
runbook_watched_ref.as_deref(),
runbook_commit.as_deref(),
)
});
let satisfied = receipt.schema_version
== "gamecult.idunn.deployment_aftercare_audit.v0"
&& status_ok
&& receipt.runtime_id == runtime_id
&& receipt.verse_id == EPIPHANY_CULTMESH_LOCAL_AREA_VERSE_ID
&& !receipt.private_state_exposed;
let satisfied = satisfied && deployment_chain_ok;
rows.push(json!({
"kind": "deployment-aftercare",
"owner": "Idunn",
@ -10222,10 +10218,12 @@ fn run_readiness(args: ReadinessArgs) -> Result<Value> {
"runtimeId": runtime_id.clone(),
"receiptId": receipt.receipt_id,
"deploymentReceiptId": receipt.deployment_receipt_id,
"underlyingDeploymentReceiptResolved": deployment.is_some(),
"underlyingDeploymentChainValid": deployment_chain_ok,
"auditRef": receipt.audit_ref,
"satisfied": satisfied,
"status": if satisfied { "satisfied" } else { "missing" },
"note": "Idunn deployment aftercare audit was supplied from repo-local CultMesh sight.",
"note": "Readiness re-resolved and validated the typed Idunn deployment and aftercare chain from repo-local CultMesh sight.",
"deploymentAuthority": false,
"gitPushAuthority": false,
"serviceLifecycleAuthority": false,
@ -10239,32 +10237,12 @@ fn run_readiness(args: ReadinessArgs) -> Result<Value> {
"Supply --deployment-aftercare-audit-receipt-ref after Idunn records deployment aftercare in the repo-local Verse.",
));
}
} else if let Some(path) = deployment_aftercare_audit_path {
let receipt = read_json_if_exists(path)?;
let satisfied = receipt.as_ref().is_some_and(|receipt| {
string_from_json(receipt, &["schemaVersion"]).as_deref()
== Some("epiphany.repo_deployment_aftercare_audit.v0")
&& string_from_json(receipt, &["status"]).as_deref() == Some("complete")
&& bool_from_json(receipt, &["deploymentComplete"]) == Some(true)
&& bool_from_json(receipt, &["deploymentAuthority"]) == Some(false)
&& bool_from_json(receipt, &["gitPushAuthority"]) == Some(false)
&& bool_from_json(receipt, &["serviceLifecycleAuthority"]) == Some(false)
&& bool_from_json(receipt, &["privateStateExposed"]) == Some(false)
});
rows.push(readiness_path_row(
"deployment-aftercare",
"Idunn",
"epiphany.repo_deployment_aftercare_audit.v0",
path,
satisfied,
"Idunn deployment aftercare audit completed and stayed sight-only.",
)?);
} else {
rows.push(readiness_missing_row(
"deployment-aftercare",
"Idunn",
"epiphany.repo_deployment_aftercare_audit.v0",
"Supply --deployment-aftercare-audit-receipt, --deployment-aftercare-audit-receipt-ref, or run deployment-aftercare-audit into the repo work artifact directory.",
"gamecult.idunn.deployment_aftercare_audit.v0 + gamecult.idunn.deployment_receipt.v0",
"Supply --deployment-aftercare-audit-receipt-ref after Idunn records the bound deployment and aftercare chain in the repo-local Verse.",
));
}
let default_tool_directory_receipt = artifact_dir.join("tool-directory.json");
@ -10778,9 +10756,7 @@ fn run_deployment_aftercare_audit(args: DeploymentAftercareAuditArgs) -> Result<
let local_verse_store = args
.local_verse_store
.unwrap_or_else(|| workspace.join(".epiphany").join("local-verse.ccmp"));
let idunn_deployment_receipt_path = args.idunn_deployment_receipt;
let idunn_deployment_receipt_ref = args.idunn_deployment_receipt_ref;
let aftercare_audit_receipt_path = args.aftercare_audit_receipt;
let aftercare_audit_receipt_ref = args.aftercare_audit_receipt_ref;
let runtime_id = args.runtime_id;
let local_verse_store_display = local_verse_store.display().to_string();
@ -10805,9 +10781,9 @@ fn run_deployment_aftercare_audit(args: DeploymentAftercareAuditArgs) -> Result<
.to_string(),
);
let idunn_deployment_summary = if let Some(receipt_ref) = idunn_deployment_receipt_ref.as_ref()
let idunn_deployment_receipt = if let Some(receipt_ref) = idunn_deployment_receipt_ref.as_ref()
{
let receipt = if receipt_ref.trim().is_empty() || receipt_ref.trim() == "latest" {
if receipt_ref.trim().is_empty() || receipt_ref.trim() == "latest" {
load_latest_epiphany_cultmesh_idunn_deployment_receipt(
&local_verse_store,
runtime_id.clone(),
@ -10818,80 +10794,13 @@ fn run_deployment_aftercare_audit(args: DeploymentAftercareAuditArgs) -> Result<
runtime_id.clone(),
receipt_ref,
)?
};
if let Some(receipt) = receipt {
let schema_ok = receipt.schema_version == "gamecult.idunn.deployment_receipt.v0";
let status_ok = matches!(
receipt.status.as_str(),
"ok" | "complete" | "deployed" | "passed"
);
let private_ok = !receipt.private_state_exposed;
push_assertion(
&mut assertions,
"idunn-deployment-receipt-valid",
schema_ok && status_ok && private_ok,
"Idunn deployment receipt carries the expected CultMesh contract, successful status, and private-state seal."
.to_string(),
);
json!({
"source": "cultmesh",
"store": local_verse_store_display.clone(),
"runtimeId": runtime_id.clone(),
"receiptRef": receipt_ref,
"receiptId": receipt.receipt_id,
"schemaVersion": receipt.schema_version,
"status": receipt.status,
"trigger": receipt.trigger,
"watchedRef": receipt.watched_ref,
"resultRef": receipt.result_ref,
"privateStateExposed": receipt.private_state_exposed
})
} else {
push_assertion(
&mut assertions,
"idunn-deployment-receipt-present",
false,
format!(
"Idunn deployment receipt ref {receipt_ref:?} was not found in the local Verse store."
),
);
Value::Null
}
} else if let Some(path) = idunn_deployment_receipt_path.as_ref() {
let receipt = read_json(path)?;
let schema_ok = string_from_json(&receipt, &["schemaVersion"]).as_deref()
== Some("gamecult.idunn.deployment_receipt.v0");
let status =
string_from_json(&receipt, &["status"]).unwrap_or_else(|| "missing".to_string());
let status_ok = matches!(status.as_str(), "ok" | "complete" | "deployed" | "passed");
let private_ok =
bool_from_json(&receipt, &["privateStateExposed"]).unwrap_or(false) == false;
push_assertion(
&mut assertions,
"idunn-deployment-receipt-valid",
schema_ok && status_ok && private_ok,
"Idunn deployment receipt carries the expected contract, successful status, and private-state seal."
.to_string(),
);
json!({
"source": "file",
"path": path,
"schemaVersion": string_from_json(&receipt, &["schemaVersion"]).unwrap_or_else(|| "missing".to_string()),
"status": status,
"privateStateExposed": bool_from_json(&receipt, &["privateStateExposed"]).unwrap_or(false)
})
} else {
push_assertion(
&mut assertions,
"idunn-deployment-receipt-present",
false,
"Idunn deployment receipt was not supplied.".to_string(),
);
Value::Null
None
};
let aftercare_summary = if let Some(receipt_ref) = aftercare_audit_receipt_ref.as_ref() {
let receipt = if receipt_ref.trim().is_empty() || receipt_ref.trim() == "latest" {
let aftercare_audit_receipt = if let Some(receipt_ref) = aftercare_audit_receipt_ref.as_ref() {
if receipt_ref.trim().is_empty() || receipt_ref.trim() == "latest" {
load_latest_epiphany_cultmesh_idunn_aftercare_audit_receipt(
&local_verse_store,
runtime_id.clone(),
@ -10902,75 +10811,90 @@ fn run_deployment_aftercare_audit(args: DeploymentAftercareAuditArgs) -> Result<
runtime_id.clone(),
receipt_ref,
)?
};
if let Some(receipt) = receipt {
let schema_ok =
receipt.schema_version == "gamecult.idunn.deployment_aftercare_audit.v0";
let status_ok = matches!(receipt.status.as_str(), "ok" | "complete" | "passed");
let private_ok = !receipt.private_state_exposed;
push_assertion(
&mut assertions,
"idunn-aftercare-audit-receipt-valid",
schema_ok && status_ok && private_ok,
"Idunn aftercare audit receipt carries the expected CultMesh contract, successful status, and private-state seal."
.to_string(),
);
json!({
"source": "cultmesh",
"store": local_verse_store_display.clone(),
"runtimeId": runtime_id.clone(),
"receiptRef": receipt_ref,
"receiptId": receipt.receipt_id,
"schemaVersion": receipt.schema_version,
"status": receipt.status,
"checkedRef": receipt.checked_ref,
"deploymentReceiptId": receipt.deployment_receipt_id,
"auditRef": receipt.audit_ref,
"privateStateExposed": receipt.private_state_exposed
})
} else {
push_assertion(
&mut assertions,
"idunn-aftercare-audit-receipt-present",
false,
format!(
"Idunn aftercare audit receipt ref {receipt_ref:?} was not found in the local Verse store."
),
);
Value::Null
}
} else if let Some(path) = aftercare_audit_receipt_path.as_ref() {
let receipt = read_json(path)?;
let schema_ok = string_from_json(&receipt, &["schemaVersion"]).as_deref()
== Some("gamecult.idunn.deployment_aftercare_audit.v0");
let status =
string_from_json(&receipt, &["status"]).unwrap_or_else(|| "missing".to_string());
let status_ok = matches!(status.as_str(), "ok" | "complete" | "passed");
let private_ok =
bool_from_json(&receipt, &["privateStateExposed"]).unwrap_or(false) == false;
} else {
None
};
let current_commit = git_output(&workspace, &["rev-parse", "HEAD"])?;
let runbook_watched_ref = runbook_receipt
.as_ref()
.and_then(|receipt| string_from_json(receipt, &["watchedRef"]));
let runbook_commit = runbook_receipt
.as_ref()
.and_then(|receipt| string_from_json(receipt, &["currentCommit"]));
let deployment_valid = idunn_deployment_receipt.as_ref().is_some_and(|receipt| {
receipt.schema_version == "gamecult.idunn.deployment_receipt.v0"
&& receipt.status == "deployed"
&& !receipt.receipt_id.trim().is_empty()
&& !receipt.result_ref.trim().is_empty()
&& receipt.runtime_id == runtime_id
&& receipt.verse_id == EPIPHANY_CULTMESH_LOCAL_AREA_VERSE_ID
&& !receipt.private_state_exposed
&& runbook_watched_ref.as_deref() == Some(receipt.watched_ref.as_str())
&& runbook_commit.as_deref() == Some(receipt.source_commit.as_str())
&& receipt.source_commit == current_commit
});
push_assertion(
&mut assertions,
"idunn-deployment-receipt-chain-valid",
deployment_valid,
"CultMesh Idunn deployment receipt is bound to this runtime, local Verse, runbook watched ref, immutable source commit, and current HEAD."
.to_string(),
);
let aftercare_valid = aftercare_audit_receipt.as_ref().is_some_and(|aftercare| {
idunn_deployment_receipt.as_ref().is_some_and(|deployment| {
idunn_deployment_aftercare_chain_valid(
deployment,
aftercare,
&runtime_id,
&current_commit,
runbook_watched_ref.as_deref(),
runbook_commit.as_deref(),
)
})
});
push_assertion(
&mut assertions,
"idunn-aftercare-receipt-chain-valid",
aftercare_valid,
"CultMesh Idunn aftercare receipt is bound to the exact deployment receipt, runtime, local Verse, and deployed result ref."
.to_string(),
);
if idunn_deployment_receipt.is_none() {
push_assertion(
&mut assertions,
"idunn-aftercare-audit-receipt-valid",
schema_ok && status_ok && private_ok,
"Idunn aftercare audit receipt carries the expected contract, successful status, and private-state seal."
"idunn-deployment-receipt-present",
false,
"Typed Idunn deployment receipt was not resolved from the local Verse store."
.to_string(),
);
json!({
"source": "file",
"path": path,
"schemaVersion": string_from_json(&receipt, &["schemaVersion"]).unwrap_or_else(|| "missing".to_string()),
"status": status,
"privateStateExposed": bool_from_json(&receipt, &["privateStateExposed"]).unwrap_or(false)
})
} else {
}
if aftercare_audit_receipt.is_none() {
push_assertion(
&mut assertions,
"idunn-aftercare-audit-receipt-present",
false,
"Idunn aftercare audit receipt was not supplied.".to_string(),
"Typed Idunn aftercare receipt was not resolved from the local Verse store."
.to_string(),
);
Value::Null
};
}
let idunn_deployment_summary = idunn_deployment_receipt.as_ref().map_or(Value::Null, |receipt| json!({
"source": "cultmesh", "store": local_verse_store_display.clone(), "runtimeId": receipt.runtime_id,
"verseId": receipt.verse_id, "receiptRef": idunn_deployment_receipt_ref, "receiptId": receipt.receipt_id,
"schemaVersion": receipt.schema_version, "status": receipt.status, "trigger": receipt.trigger,
"watchedRef": receipt.watched_ref, "sourceCommit": receipt.source_commit, "resultRef": receipt.result_ref,
"privateStateExposed": receipt.private_state_exposed
}));
let aftercare_summary = aftercare_audit_receipt.as_ref().map_or(Value::Null, |receipt| json!({
"source": "cultmesh", "store": local_verse_store_display.clone(), "runtimeId": receipt.runtime_id,
"verseId": receipt.verse_id, "receiptRef": aftercare_audit_receipt_ref, "receiptId": receipt.receipt_id,
"schemaVersion": receipt.schema_version, "status": receipt.status, "checkedRef": receipt.checked_ref,
"deploymentReceiptId": receipt.deployment_receipt_id, "auditRef": receipt.audit_ref,
"privateStateExposed": receipt.private_state_exposed
}));
let all_passed = assertions
.iter()
@ -11016,6 +10940,37 @@ fn run_deployment_aftercare_audit(args: DeploymentAftercareAuditArgs) -> Result<
Ok(receipt)
}
fn idunn_deployment_aftercare_chain_valid(
deployment: &EpiphanyCultMeshIdunnDeploymentReceiptEntry,
aftercare: &EpiphanyCultMeshIdunnAftercareAuditReceiptEntry,
runtime_id: &str,
current_commit: &str,
runbook_watched_ref: Option<&str>,
runbook_commit: Option<&str>,
) -> bool {
deployment.schema_version == "gamecult.idunn.deployment_receipt.v0"
&& deployment.status == "deployed"
&& aftercare.schema_version == "gamecult.idunn.deployment_aftercare_audit.v0"
&& aftercare.status == "complete"
&& !deployment.receipt_id.trim().is_empty()
&& !deployment.result_ref.trim().is_empty()
&& !aftercare.receipt_id.trim().is_empty()
&& !aftercare.audit_ref.trim().is_empty()
&& deployment.runtime_id == runtime_id
&& aftercare.runtime_id == runtime_id
&& deployment.runtime_id == aftercare.runtime_id
&& deployment.verse_id == EPIPHANY_CULTMESH_LOCAL_AREA_VERSE_ID
&& aftercare.verse_id == EPIPHANY_CULTMESH_LOCAL_AREA_VERSE_ID
&& deployment.verse_id == aftercare.verse_id
&& aftercare.deployment_receipt_id == deployment.receipt_id
&& aftercare.checked_ref == deployment.result_ref
&& deployment.source_commit == current_commit
&& runbook_commit == Some(deployment.source_commit.as_str())
&& runbook_watched_ref == Some(deployment.watched_ref.as_str())
&& !deployment.private_state_exposed
&& !aftercare.private_state_exposed
}
fn run_export_proof(args: ExportProofArgs) -> Result<Value> {
let workspace = args
.workspace
@ -13528,6 +13483,127 @@ idunn_deployment_authority_required = true
assert!(parse_repo_deployment_config(&missing_typed_field).is_err());
}
fn idunn_deployment_fixture() -> EpiphanyCultMeshIdunnDeploymentReceiptEntry {
EpiphanyCultMeshIdunnDeploymentReceiptEntry {
schema_version: "gamecult.idunn.deployment_receipt.v0".to_string(),
receipt_id: "deployment-1".to_string(),
runtime_id: "repo-swarm-local".to_string(),
verse_id: EPIPHANY_CULTMESH_LOCAL_AREA_VERSE_ID.to_string(),
status: "deployed".to_string(),
trigger: "git-push".to_string(),
watched_ref: "refs/heads/main".to_string(),
source_commit: "abc123".to_string(),
result_ref: "deploy/result/abc123".to_string(),
result_summary: "deployed".to_string(),
private_state_exposed: false,
notes: vec![],
}
}
fn idunn_aftercare_fixture() -> EpiphanyCultMeshIdunnAftercareAuditReceiptEntry {
EpiphanyCultMeshIdunnAftercareAuditReceiptEntry {
schema_version: "gamecult.idunn.deployment_aftercare_audit.v0".to_string(),
receipt_id: "aftercare-1".to_string(),
runtime_id: "repo-swarm-local".to_string(),
verse_id: EPIPHANY_CULTMESH_LOCAL_AREA_VERSE_ID.to_string(),
status: "complete".to_string(),
checked_ref: "deploy/result/abc123".to_string(),
deployment_receipt_id: "deployment-1".to_string(),
audit_ref: "audit/abc123".to_string(),
result_summary: "healthy".to_string(),
private_state_exposed: false,
notes: vec![],
}
}
#[test]
fn deployment_aftercare_rejects_raw_response_files_and_cached_projection() {
for forbidden in ["--idunn-deployment-receipt", "--aftercare-audit-receipt"] {
assert!(
parse_deployment_aftercare_audit_args(
[
"--workspace".to_string(),
".".to_string(),
forbidden.to_string(),
"minimal-three-field-blob.json".to_string(),
]
.into_iter()
)
.is_err()
);
}
assert!(
parse_readiness_args(
[
"--workspace".to_string(),
".".to_string(),
"--deployment-aftercare-audit-receipt".to_string(),
"cached-projection.json".to_string(),
]
.into_iter()
)
.is_err()
);
}
#[test]
fn deployment_aftercare_requires_the_conjunctively_bound_idunn_chain() {
let deployment = idunn_deployment_fixture();
let aftercare = idunn_aftercare_fixture();
let valid =
|deployment: &EpiphanyCultMeshIdunnDeploymentReceiptEntry,
aftercare: &EpiphanyCultMeshIdunnAftercareAuditReceiptEntry| {
idunn_deployment_aftercare_chain_valid(
deployment,
aftercare,
"repo-swarm-local",
"abc123",
Some("refs/heads/main"),
Some("abc123"),
)
};
assert!(valid(&deployment, &aftercare));
let mut forged = aftercare.clone();
forged.deployment_receipt_id = "other-deployment".to_string();
assert!(!valid(&deployment, &forged));
forged = aftercare.clone();
forged.checked_ref = "other-result".to_string();
assert!(!valid(&deployment, &forged));
forged = aftercare.clone();
forged.runtime_id = "other-runtime".to_string();
assert!(!valid(&deployment, &forged));
forged = aftercare.clone();
forged.verse_id = "other-verse".to_string();
assert!(!valid(&deployment, &forged));
let mut forged_deployment = deployment.clone();
forged_deployment.source_commit = "other-commit".to_string();
assert!(!valid(&forged_deployment, &aftercare));
forged_deployment = deployment.clone();
forged_deployment.watched_ref = "refs/heads/other".to_string();
assert!(!valid(&forged_deployment, &aftercare));
forged_deployment = deployment.clone();
forged_deployment.status = "complete".to_string();
assert!(!valid(&forged_deployment, &aftercare));
forged_deployment = deployment.clone();
forged_deployment.receipt_id.clear();
assert!(!valid(&forged_deployment, &aftercare));
forged_deployment = deployment.clone();
forged_deployment.result_ref.clear();
assert!(!valid(&forged_deployment, &aftercare));
forged = aftercare.clone();
forged.status = "passed".to_string();
assert!(!valid(&deployment, &forged));
forged = aftercare.clone();
forged.receipt_id.clear();
assert!(!valid(&deployment, &forged));
forged = aftercare.clone();
forged.audit_ref.clear();
assert!(!valid(&deployment, &forged));
}
#[test]
fn deployment_closure_uses_the_typed_config_model() {
let source = include_str!("epiphany-work.rs");
@ -14794,10 +14870,10 @@ fn print_usage() {
execute --workspace <repo> [--item <id>] [--from-plan <path>] [--command <command>] [--changed-path <path>] [--commit-message <text>]\n\
close --workspace <repo> [--item <id>] [--execute-receipt <path>]\n\
overview --workspace <repo> [--item <id>] [--accept-receipt <path>] [--no-write]\n\
readiness --workspace <repo> [--item <id>] [--accept-receipt <path>] [--public-proof <path>] [--idunn-lifecycle-receipt <path>] [--deployment-aftercare-audit-receipt <path>|--deployment-aftercare-audit-receipt-ref <ref>] [--tool-directory-receipt <path>] [--no-write]\n\
readiness --workspace <repo> [--item <id>] [--accept-receipt <path>] [--public-proof <path>] [--idunn-lifecycle-receipt <path>] [--deployment-aftercare-audit-receipt-ref <ref>] [--tool-directory-receipt <path>] [--no-write]\n\
deployment-config-audit --workspace <repo> [--artifact-dir <path>] [--no-write]\n\
deployment-execution-runbook --workspace <repo> [--artifact-dir <path>] [--remote origin] [--no-write]\n\
deployment-aftercare-audit --workspace <repo> [--artifact-dir <path>] [--local-verse-store <path>] [--runtime-id <id>] [--runbook-receipt <path>] [--idunn-deployment-receipt-ref <ref>|--idunn-deployment-receipt <path>] [--aftercare-audit-receipt-ref <ref>|--aftercare-audit-receipt <path>] [--no-write]\n\
deployment-aftercare-audit --workspace <repo> [--artifact-dir <path>] [--local-verse-store <path>] [--runtime-id <id>] [--runbook-receipt <path>] [--idunn-deployment-receipt-ref <ref>] [--aftercare-audit-receipt-ref <ref>] [--no-write]\n\
export-proof --workspace <repo> [--item <id>] [--accept-receipt <path>] [--output <path>] [--local-verse-store <path>] [--runtime-id repo-swarm-local]\n\
tick --workspace <repo> [--item <id>] [--local-verse-store <path>] [--runtime-store <path>] [--dry-run]\n\
queue-run --workspace <repo> [--local-verse-store <path>] [--runtime-id repo-swarm-local] [--max-items 1] [--dry-run]"

View file

@ -716,6 +716,7 @@ pub use persona_turn::persona_projected_surface_is_clean;
pub use persona_turn::render_persona_semantic_memory_recall;
pub use persona_turn::semantic_memory_recall_from_heartbeat_action;
pub use process_observation::EpiphanyProcessObservation;
pub use process_observation::native_process_executable_path;
pub use process_observation::observe_native_process;
pub use promotion::EpiphanyPromotionDecision;
pub use promotion::EpiphanyPromotionInput;

View file

@ -1,4 +1,5 @@
use anyhow::Result;
use std::path::PathBuf;
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum EpiphanyProcessObservation {
@ -7,6 +8,39 @@ pub enum EpiphanyProcessObservation {
Missing,
}
#[cfg(windows)]
pub fn native_process_executable_path(process_id: u32) -> Result<Option<PathBuf>> {
use windows_sys::Win32::Foundation::CloseHandle;
use windows_sys::Win32::System::Threading::{
OpenProcess, PROCESS_QUERY_LIMITED_INFORMATION, QueryFullProcessImageNameW,
};
unsafe {
let handle = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, 0, process_id);
if handle.is_null() {
return Ok(None);
}
let mut buffer = vec![0_u16; 32_768];
let mut length = buffer.len() as u32;
let read = QueryFullProcessImageNameW(handle, 0, buffer.as_mut_ptr(), &mut length);
CloseHandle(handle);
if read == 0 {
return Ok(None);
}
buffer.truncate(length as usize);
Ok(Some(PathBuf::from(String::from_utf16(&buffer)?)))
}
}
#[cfg(unix)]
pub fn native_process_executable_path(process_id: u32) -> Result<Option<PathBuf>> {
let path = PathBuf::from(format!("/proc/{process_id}/exe"));
match std::fs::read_link(path) {
Ok(path) => Ok(Some(path)),
Err(error) if error.kind() == std::io::ErrorKind::NotFound => Ok(None),
Err(error) => Err(error.into()),
}
}
impl EpiphanyProcessObservation {
pub fn label(self) -> &'static str {
match self {