Delete false runtime catalog authority

This commit is contained in:
Meta Vens 2026-08-23 16:24:53 +02:00
commit 03140a47db
9 changed files with 34 additions and 1542 deletions

View file

@ -1,649 +0,0 @@
use anyhow::Context;
use anyhow::Result;
use anyhow::anyhow;
use chrono::SecondsFormat;
use epiphany_core::EpiphanyCoordinatorRunReceipt;
use epiphany_core::EpiphanyRuntimeJob;
use epiphany_core::EpiphanyRuntimeJobResult;
use epiphany_core::EpiphanyRuntimeRoleWorkerResult;
use epiphany_core::EpiphanyRuntimeSession;
use epiphany_core::RuntimeSpineInitOptions;
use epiphany_core::RuntimeSpineJobOptions;
use epiphany_core::RuntimeSpineJobResultOptions;
use epiphany_core::RuntimeSpineSessionClosureOptions;
use epiphany_core::RuntimeSpineSessionOptions;
use epiphany_core::close_runtime_session;
use epiphany_core::complete_runtime_job;
use epiphany_core::create_runtime_job;
use epiphany_core::create_runtime_session;
use epiphany_core::initialize_runtime_spine;
use epiphany_core::runtime_has_actionable_eyes_frontier;
use epiphany_core::runtime_has_actionable_hands_frontier;
use epiphany_core::runtime_spine_cache;
use epiphany_core::runtime_spine_status;
use epiphany_core::write_runtime_hello_frame;
use epiphany_core::write_runtime_schema_catalog_json;
use epiphany_model_adapter::EpiphanyModelInputItem;
use epiphany_model_adapter::EpiphanyModelRequest;
use std::env;
use std::path::PathBuf;
use uuid::Uuid;
const DEFAULT_STORE: &str = "state/runtime-spine.msgpack";
fn main() -> Result<()> {
let args = Args::parse()?;
match args.command {
Command::Init {
runtime_id,
display_name,
} => {
let identity = initialize_runtime_spine(
&args.store,
RuntimeSpineInitOptions {
runtime_id,
display_name,
created_at: now(),
},
)?;
println!("runtime spine initialized");
println!("store: {}", args.store.display());
println!("runtime: {}", identity.runtime_id);
println!(
"documents: {}",
epiphany_core::runtime_registered_document_types().join(", ")
);
}
Command::Status => {
let status = runtime_spine_status(&args.store)?;
println!("runtime spine status");
println!("store: {}", status.store);
println!("present: {}", status.present);
println!(
"runtime: {}",
status.runtime_id.unwrap_or_else(|| "missing".to_string())
);
println!(
"display: {}",
status.display_name.unwrap_or_else(|| "missing".to_string())
);
println!(
"sessions: {} active: {}",
status.sessions, status.active_sessions
);
println!("jobs: {} open: {}", status.jobs, status.open_jobs);
println!("job results: {}", status.job_results);
println!(
"actionable frontiers: Hands={} Eyes={}",
runtime_has_actionable_hands_frontier(&args.store)?,
runtime_has_actionable_eyes_frontier(&args.store)?
);
println!(
"tool invocations: {} pending: {} receipts: {}",
status.tool_invocation_intents,
status.pending_tool_invocations,
status.tool_invocation_receipts
);
if !status.supported_document_types.is_empty() {
println!("documents: {}", status.supported_document_types.join(", "));
}
}
Command::ListJobs => {
let mut cache = runtime_spine_cache(&args.store)?;
cache.pull_all_backing_stores()?;
let mut jobs = cache.get_all::<EpiphanyRuntimeJob>()?;
let results = cache.get_all::<EpiphanyRuntimeJobResult>()?;
jobs.sort_by(|left, right| left.created_at.cmp(&right.created_at));
println!("runtime jobs");
for job in jobs {
let result = results.iter().find(|result| result.job_id == job.job_id);
println!(
"{}\t{:?}\t{}\t{}\t{}",
job.job_id,
job.status,
job.role,
result
.map(|result| result.result_id.as_str())
.unwrap_or("no-result"),
job.summary.replace(['\r', '\n', '\t'], " ")
);
}
}
Command::ListSessions => {
let mut cache = runtime_spine_cache(&args.store)?;
cache.pull_all_backing_stores()?;
let mut sessions = cache.get_all::<EpiphanyRuntimeSession>()?;
sessions.sort_by(|left, right| left.created_at.cmp(&right.created_at));
println!("runtime sessions");
for session in sessions {
println!(
"{}\t{:?}\t{}",
session.session_id,
session.status,
session.objective.replace(['\r', '\n', '\t'], " ")
);
}
}
Command::ListModelRequests => {
let mut cache = runtime_spine_cache(&args.store)?;
cache.pull_all_backing_stores()?;
let mut requests = cache.get_all::<EpiphanyModelRequest>()?;
requests.sort_by(|left, right| left.request_id.cmp(&right.request_id));
println!("model requests");
for request in requests {
let input_chars = request
.input
.iter()
.map(model_input_item_chars)
.sum::<usize>();
let tool_names = request
.tools
.iter()
.map(|tool| tool.name.as_str())
.collect::<Vec<_>>()
.join(",");
println!(
"{}\t{}\t{}\tinstructions={}\tinputItems={}\tinputChars={}\ttools={}\ttoolNames={}\tcontract={}",
request.request_id,
request.provider,
request.model,
request.instructions.chars().count(),
request.input.len(),
input_chars,
request.tools.len(),
if tool_names.is_empty() {
"none"
} else {
tool_names.as_str()
},
request.output_contract_id.as_deref().unwrap_or("none")
);
}
}
Command::ListCoordinatorRuns => {
let mut cache = runtime_spine_cache(&args.store)?;
cache.pull_all_backing_stores()?;
let mut receipts = cache.get_all::<EpiphanyCoordinatorRunReceipt>()?;
receipts.sort_by(|left, right| {
left.created_at
.cmp(&right.created_at)
.then_with(|| left.receipt_id.cmp(&right.receipt_id))
});
println!("coordinator runs");
for receipt in receipts {
println!(
"{}\t{}\t{}\t{}\t{}\t{}",
receipt.created_at,
receipt.receipt_id,
receipt.thread_id,
receipt.status,
receipt.final_action,
receipt
.final_reason
.as_deref()
.unwrap_or("no-reason")
.replace(['\r', '\n', '\t'], " ")
);
}
}
Command::ListRepoModelProposals => {
let mut cache = runtime_spine_cache(&args.store)?;
cache.pull_all_backing_stores()?;
let mut results = cache.get_all::<EpiphanyRuntimeRoleWorkerResult>()?;
results.sort_by(|left, right| left.job_id.cmp(&right.job_id));
println!("RepoModel mutation proposals");
for result in results {
let Some(proposal) = result.repo_model_mutation_proposal()? else {
continue;
};
let operations = proposal.operations()?;
println!(
"{}\t{}\t{}\t{}",
result.job_id,
proposal.proposal_id,
result.decision_context_id,
serde_json::to_string(&operations)?
);
}
}
Command::OpenSession {
session_id,
objective,
coordinator_note,
} => {
let session = create_runtime_session(
&args.store,
RuntimeSpineSessionOptions {
session_id,
objective,
created_at: now(),
coordinator_note,
},
)?;
println!("runtime session opened");
println!("session: {}", session.session_id);
println!("objective: {}", session.objective);
}
Command::CloseSession {
session_id,
summary,
} => {
let session = close_runtime_session(
&args.store,
RuntimeSpineSessionClosureOptions {
session_id,
completed_at: now(),
summary,
},
)?;
println!("runtime session completed");
println!("session: {}", session.session_id);
}
Command::OpenJob {
job_id,
session_id,
role,
summary,
artifact_refs,
} => {
let job = create_runtime_job(
&args.store,
RuntimeSpineJobOptions {
job_id,
session_id,
role,
created_at: now(),
summary,
artifact_refs,
},
)?;
println!("runtime job opened");
println!("job: {}", job.job_id);
println!("session: {}", job.session_id);
println!("role: {}", job.role);
}
Command::CompleteJob {
result_id,
job_id,
verdict,
summary,
next_safe_move,
evidence_refs,
artifact_refs,
} => {
let result = complete_runtime_job(
&args.store,
RuntimeSpineJobResultOptions {
result_id,
job_id,
completed_at: now(),
verdict,
summary,
next_safe_move,
evidence_refs,
artifact_refs,
decision_context_id: None,
},
)?;
println!("runtime job completed");
println!("result: {}", result.result_id);
println!("job: {}", result.job_id);
println!("verdict: {}", result.verdict);
}
Command::HelloFrame { output } => {
let bytes = write_runtime_hello_frame(&args.store, &output)?;
println!("cultnet hello frame written");
println!("path: {}", output.display());
println!("bytes: {bytes}");
}
Command::SchemaCatalog {
output,
include_schema_json,
} => {
let bytes = write_runtime_schema_catalog_json(&output, include_schema_json)?;
println!("cultnet schema catalog written");
println!("path: {}", output.display());
println!("bytes: {bytes}");
}
}
Ok(())
}
#[derive(Debug)]
struct Args {
store: PathBuf,
command: Command,
}
#[derive(Debug)]
enum Command {
Init {
runtime_id: String,
display_name: String,
},
Status,
ListJobs,
ListSessions,
ListModelRequests,
ListCoordinatorRuns,
ListRepoModelProposals,
OpenSession {
session_id: String,
objective: String,
coordinator_note: String,
},
CloseSession {
session_id: String,
summary: String,
},
OpenJob {
job_id: String,
session_id: String,
role: String,
summary: String,
artifact_refs: Vec<String>,
},
CompleteJob {
result_id: String,
job_id: String,
verdict: String,
summary: String,
next_safe_move: String,
evidence_refs: Vec<String>,
artifact_refs: Vec<String>,
},
HelloFrame {
output: PathBuf,
},
SchemaCatalog {
output: PathBuf,
include_schema_json: bool,
},
}
impl Args {
fn parse() -> Result<Self> {
let mut store = PathBuf::from(DEFAULT_STORE);
let mut positional = Vec::new();
let mut args = env::args().skip(1);
while let Some(arg) = args.next() {
match arg.as_str() {
"--store" => store = take_path(&mut args, "--store")?,
_ => positional.push(arg),
}
}
let command = parse_command(positional)?;
Ok(Self { store, command })
}
}
fn parse_command(mut args: Vec<String>) -> Result<Command> {
if args.is_empty() {
return Err(anyhow!(usage()));
}
let command = args.remove(0);
match command.as_str() {
"init" => {
let mut runtime_id = "epiphany-local".to_string();
let mut display_name = "Epiphany Local".to_string();
parse_options(args, |name, value| match name {
"--runtime-id" => {
runtime_id = value;
Ok(())
}
"--display-name" => {
display_name = value;
Ok(())
}
_ => Err(anyhow!("unknown init argument: {name}")),
})?;
Ok(Command::Init {
runtime_id,
display_name,
})
}
"status" => Ok(Command::Status),
"list-jobs" => Ok(Command::ListJobs),
"list-sessions" => Ok(Command::ListSessions),
"list-model-requests" => Ok(Command::ListModelRequests),
"list-coordinator-runs" => Ok(Command::ListCoordinatorRuns),
"list-repo-model-proposals" => Ok(Command::ListRepoModelProposals),
"open-session" => {
let mut session_id = format!("session-{}", Uuid::new_v4());
let mut objective = String::new();
let mut coordinator_note = String::new();
parse_options(args, |name, value| match name {
"--session-id" => {
session_id = value;
Ok(())
}
"--objective" => {
objective = value;
Ok(())
}
"--coordinator-note" => {
coordinator_note = value;
Ok(())
}
_ => Err(anyhow!("unknown open-session argument: {name}")),
})?;
if objective.trim().is_empty() {
return Err(anyhow!("open-session requires --objective"));
}
Ok(Command::OpenSession {
session_id,
objective,
coordinator_note,
})
}
"open-job" => {
let mut job_id = format!("job-{}", Uuid::new_v4());
let mut session_id = String::new();
let mut role = String::new();
let mut summary = String::new();
let mut artifact_refs = Vec::new();
parse_options(args, |name, value| match name {
"--job-id" => {
job_id = value;
Ok(())
}
"--session-id" => {
session_id = value;
Ok(())
}
"--role" => {
role = value;
Ok(())
}
"--summary" => {
summary = value;
Ok(())
}
"--artifact-ref" => {
artifact_refs.push(value);
Ok(())
}
_ => Err(anyhow!("unknown open-job argument: {name}")),
})?;
if session_id.trim().is_empty() {
return Err(anyhow!("open-job requires --session-id"));
}
if role.trim().is_empty() {
return Err(anyhow!("open-job requires --role"));
}
Ok(Command::OpenJob {
job_id,
session_id,
role,
summary,
artifact_refs,
})
}
"close-session" => {
let mut session_id = String::new();
let mut summary = String::new();
parse_options(args, |name, value| match name {
"--session-id" => {
session_id = value;
Ok(())
}
"--summary" => {
summary = value;
Ok(())
}
_ => Err(anyhow!("unknown close-session argument: {name}")),
})?;
if session_id.trim().is_empty() {
return Err(anyhow!("close-session requires --session-id"));
}
if summary.trim().is_empty() {
return Err(anyhow!("close-session requires --summary"));
}
Ok(Command::CloseSession {
session_id,
summary,
})
}
"complete-job" => {
let mut result_id = format!("result-{}", Uuid::new_v4());
let mut job_id = String::new();
let mut verdict = String::new();
let mut summary = String::new();
let mut next_safe_move = String::new();
let mut evidence_refs = Vec::new();
let mut artifact_refs = Vec::new();
parse_options(args, |name, value| match name {
"--result-id" => {
result_id = value;
Ok(())
}
"--job-id" => {
job_id = value;
Ok(())
}
"--verdict" => {
verdict = value;
Ok(())
}
"--summary" => {
summary = value;
Ok(())
}
"--next-safe-move" => {
next_safe_move = value;
Ok(())
}
"--evidence-ref" => {
evidence_refs.push(value);
Ok(())
}
"--artifact-ref" => {
artifact_refs.push(value);
Ok(())
}
_ => Err(anyhow!("unknown complete-job argument: {name}")),
})?;
if job_id.trim().is_empty() {
return Err(anyhow!("complete-job requires --job-id"));
}
if verdict.trim().is_empty() {
return Err(anyhow!("complete-job requires --verdict"));
}
if summary.trim().is_empty() {
return Err(anyhow!("complete-job requires --summary"));
}
Ok(Command::CompleteJob {
result_id,
job_id,
verdict,
summary,
next_safe_move,
evidence_refs,
artifact_refs,
})
}
"hello-frame" => {
let mut output = PathBuf::from(".epiphany-dogfood/runtime-spine/hello.cultnet");
parse_options(args, |name, value| match name {
"--output" => {
output = PathBuf::from(value);
Ok(())
}
_ => Err(anyhow!("unknown hello-frame argument: {name}")),
})?;
Ok(Command::HelloFrame { output })
}
"schema-catalog" => {
let mut output = PathBuf::from(".epiphany-dogfood/runtime-spine/schema-catalog.json");
let mut include_schema_json = false;
parse_options(args, |name, value| match name {
"--output" => {
output = PathBuf::from(value);
Ok(())
}
"--include-schema-json" => {
include_schema_json = parse_bool_flag(&value, "--include-schema-json")?;
Ok(())
}
_ => Err(anyhow!("unknown schema-catalog argument: {name}")),
})?;
Ok(Command::SchemaCatalog {
output,
include_schema_json,
})
}
_ => Err(anyhow!(usage())),
}
}
fn parse_options(
args: Vec<String>,
mut on_option: impl FnMut(&str, String) -> Result<()>,
) -> Result<()> {
let mut args = args.into_iter();
while let Some(name) = args.next() {
if !name.starts_with("--") {
return Err(anyhow!("unexpected positional argument: {name}"));
}
let value = args
.next()
.with_context(|| format!("{name} requires a value"))?;
on_option(&name, value)?;
}
Ok(())
}
fn take_path(args: &mut impl Iterator<Item = String>, name: &str) -> Result<PathBuf> {
args.next()
.map(PathBuf::from)
.ok_or_else(|| anyhow!("{name} requires a value"))
}
fn parse_bool_flag(value: &str, name: &str) -> Result<bool> {
match value {
"true" | "1" | "yes" => Ok(true),
"false" | "0" | "no" => Ok(false),
_ => Err(anyhow!("{name} must be true/false")),
}
}
fn now() -> String {
chrono::Utc::now().to_rfc3339_opts(SecondsFormat::Secs, true)
}
fn usage() -> &'static str {
"usage: epiphany-runtime-spine [--store path] <init|status|list-jobs|list-sessions|list-model-requests|list-coordinator-runs|list-repo-model-proposals|open-session|close-session|open-job|complete-job|hello-frame|schema-catalog>"
}
fn model_input_item_chars(item: &EpiphanyModelInputItem) -> usize {
match item {
EpiphanyModelInputItem::UserText { text }
| EpiphanyModelInputItem::AssistantText { text } => text.chars().count(),
EpiphanyModelInputItem::ToolCall {
call_id,
name,
arguments,
} => call_id.chars().count() + name.chars().count() + arguments.chars().count(),
EpiphanyModelInputItem::ToolResult { output, .. } => output.chars().count(),
}
}