Add native operator snapshots

This commit is contained in:
Meta Vens 2026-05-27 20:58:31 +01:00
commit 3abd6803a4
14 changed files with 672 additions and 39 deletions

View file

@ -4,14 +4,17 @@ use epiphany_core::EPIPHANY_CULTMESH_INTERNAL_VERSE_ID;
use epiphany_core::EPIPHANY_CULTMESH_STATUS_SCHEMA_VERSION;
use epiphany_core::EpiphanyCultMeshStatusEntry;
use epiphany_core::default_epiphany_cultmesh_operator_status;
use epiphany_core::epiphany_cultmesh_operator_snapshot_from_status_json;
use epiphany_core::load_epiphany_cultmesh_operator_status;
use epiphany_core::load_epiphany_cultmesh_status;
use epiphany_core::load_latest_epiphany_cultmesh_operator_snapshot;
use epiphany_core::write_epiphany_cultmesh_body_contracts;
use epiphany_core::write_epiphany_cultmesh_eyes_contracts;
use epiphany_core::write_epiphany_cultmesh_global_room_policies;
use epiphany_core::write_epiphany_cultmesh_hands_contracts;
use epiphany_core::write_epiphany_cultmesh_life_contracts;
use epiphany_core::write_epiphany_cultmesh_mind_contracts;
use epiphany_core::write_epiphany_cultmesh_operator_snapshot;
use epiphany_core::write_epiphany_cultmesh_operator_status;
use epiphany_core::write_epiphany_cultmesh_soul_contracts;
use epiphany_core::write_epiphany_cultmesh_status;
@ -47,6 +50,42 @@ fn main() -> Result<()> {
"2026-05-27T00:00:00Z",
);
write_epiphany_cultmesh_operator_status(&store, operator_status.clone())?;
let operator_snapshot = epiphany_cultmesh_operator_snapshot_from_status_json(
"epiphany-cultmesh-smoke",
"cultmesh-smoke-status",
"2026-05-27T00:00:00Z",
"status",
".epiphany-smoke/cultmesh/status.json",
&serde_json::json!({
"threadId": "thread-smoke",
"scene": {
"scene": {
"stateStatus": "missing",
"availableActions": ["crrc", "roles"]
}
},
"pressure": {
"pressure": {
"level": "low"
}
},
"reorient": {
"decision": {
"action": "regather",
"nextAction": "Regather source context."
}
},
"crrc": {
"recommendation": {
"action": "regatherManually"
}
},
"coordinator": {
"action": "wait"
}
}),
)?;
write_epiphany_cultmesh_operator_snapshot(&store, operator_snapshot.clone())?;
let loaded = load_epiphany_cultmesh_status(&store, "epiphany-cultmesh-smoke")?;
if loaded != Some(status) {
anyhow::bail!("CultMesh smoke failed to round-trip Epiphany status document");
@ -56,6 +95,11 @@ fn main() -> Result<()> {
if loaded_operator_status != Some(operator_status) {
anyhow::bail!("CultMesh smoke failed to round-trip Epiphany operator status document");
}
let loaded_operator_snapshot =
load_latest_epiphany_cultmesh_operator_snapshot(&store, "epiphany-cultmesh-smoke")?;
if loaded_operator_snapshot != Some(operator_snapshot) {
anyhow::bail!("CultMesh smoke failed to round-trip Epiphany operator snapshot document");
}
println!(
"epiphany cultmesh smoke ok: {}",

View file

@ -0,0 +1,164 @@
use anyhow::Context;
use anyhow::Result;
use chrono::Utc;
use epiphany_core::epiphany_cultmesh_operator_snapshot_from_status_json;
use epiphany_core::load_latest_epiphany_cultmesh_operator_snapshot;
use epiphany_core::write_epiphany_cultmesh_operator_snapshot;
use serde_json::Value;
use serde_json::json;
use std::env;
use std::fs;
use std::path::PathBuf;
fn main() -> Result<()> {
let args = Args::parse()?;
match args.command.as_str() {
"from-status" => {
let input = args.input.context("from-status requires --input")?;
let source = fs::read_to_string(&input)
.with_context(|| format!("failed to read {}", input.display()))?;
let status_json: Value = serde_json::from_str(&source)
.with_context(|| format!("failed to parse {}", input.display()))?;
let snapshot = epiphany_cultmesh_operator_snapshot_from_status_json(
args.runtime_id.clone(),
args.snapshot_id.clone(),
Utc::now().to_rfc3339(),
args.source_mode.clone(),
input.to_string_lossy(),
&status_json,
)?;
let written = write_epiphany_cultmesh_operator_snapshot(&args.store, snapshot)?;
print_json(json!({
"status": "written",
"store": args.store,
"snapshot": written,
}))?;
}
"latest" => {
let latest =
load_latest_epiphany_cultmesh_operator_snapshot(&args.store, &args.runtime_id)?;
print_json(json!({
"status": if latest.is_some() { "ready" } else { "missing" },
"store": args.store,
"snapshot": latest,
}))?;
}
"smoke" => {
let status_json = json!({
"threadId": "thread-smoke",
"scene": {
"scene": {
"stateStatus": "missing",
"availableActions": ["crrc", "roles"]
}
},
"pressure": {
"pressure": {
"level": "low"
}
},
"reorient": {
"decision": {
"action": "regather",
"nextAction": "Regather source context."
}
},
"crrc": {
"recommendation": {
"action": "regatherManually"
}
},
"coordinator": {
"action": "wait"
},
"rawResult": {
"sealed": true
}
});
let snapshot = epiphany_cultmesh_operator_snapshot_from_status_json(
args.runtime_id.clone(),
args.snapshot_id.clone(),
"2026-05-27T00:00:00Z",
"status",
".epiphany-smoke/operator-status.json",
&status_json,
)?;
write_epiphany_cultmesh_operator_snapshot(&args.store, snapshot.clone())?;
let latest =
load_latest_epiphany_cultmesh_operator_snapshot(&args.store, &args.runtime_id)?;
if latest != Some(snapshot) {
anyhow::bail!("operator snapshot did not round-trip through CultMesh");
}
print_json(json!({
"status": "ok",
"store": args.store,
"runtimeId": args.runtime_id,
"snapshotId": args.snapshot_id,
}))?;
}
other => anyhow::bail!("unknown command {other:?}; use from-status, latest, or smoke"),
}
Ok(())
}
struct Args {
command: String,
store: PathBuf,
runtime_id: String,
snapshot_id: String,
source_mode: String,
input: Option<PathBuf>,
}
impl Args {
fn parse() -> Result<Self> {
let mut values = env::args().skip(1);
let command = values.next().unwrap_or_else(|| "latest".to_string());
let mut store = PathBuf::from(".epiphany-run/cultmesh/operator-snapshots.ccmp");
let mut runtime_id = "epiphany-local".to_string();
let mut snapshot_id = format!("snapshot-{}", Utc::now().timestamp());
let mut source_mode = "status".to_string();
let mut input = None;
while let Some(arg) = values.next() {
match arg.as_str() {
"--store" => {
store = PathBuf::from(values.next().context("missing --store value")?);
}
"--runtime-id" => {
runtime_id = values.next().context("missing --runtime-id value")?;
}
"--snapshot-id" => {
snapshot_id = values.next().context("missing --snapshot-id value")?;
}
"--source-mode" => {
source_mode = values.next().context("missing --source-mode value")?;
}
"--input" => {
input = Some(PathBuf::from(
values.next().context("missing --input value")?,
));
}
_ => anyhow::bail!("unknown argument {arg:?}"),
}
}
if let Some(parent) = store.parent() {
fs::create_dir_all(parent)?;
}
Ok(Self {
command,
store,
runtime_id,
snapshot_id,
source_mode,
input,
})
}
}
fn print_json(value: Value) -> Result<()> {
println!("{}", serde_json::to_string_pretty(&value)?);
Ok(())
}