huginn CLI over HuginnClient: whoami, view, query, recipes, admit with read-back, schema
A new bin of eureka-state, crates/eureka-state/src/bin/huginn/: the agents' shell door to the mind. Text out, typed exit codes, strict decode of agent-written JSON (unknown key paths refused, never values), the named campaign-state recipes, and a read-back after every committed admission. lib.rs, main.rs and tests/mcp.rs are untouched. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
f003801138
commit
02cb3dadcd
10 changed files with 2224 additions and 2 deletions
106
crates/eureka-state/src/bin/huginn/render.rs
Normal file
106
crates/eureka-state/src/bin/huginn/render.rs
Normal file
|
|
@ -0,0 +1,106 @@
|
|||
//! Text for stdout. Display only: nothing here decides an answer.
|
||||
|
||||
use std::fmt::Write;
|
||||
|
||||
use huginn_mind::{IndexStatus, PipelineDocumentSummary, PipelineDocumentView, PipelineStatus, PipelineStatusSummary};
|
||||
use serde::Serialize;
|
||||
use serde_json::Value;
|
||||
|
||||
/// A header line is cut here, so a page of them stays one screen per dozen.
|
||||
const HEADER_MAX_CHARS: usize = 240;
|
||||
|
||||
/// The variant or string a serde-tagged value is spelled as: `Hands` for a
|
||||
/// faculty, `Fixed` for an outcome.
|
||||
pub fn name_of<T: Serialize>(value: &T) -> String {
|
||||
match serde_json::to_value(value) {
|
||||
Ok(Value::String(name)) => name,
|
||||
Ok(Value::Object(fields)) => fields.keys().next().cloned().unwrap_or_default(),
|
||||
_ => String::new(),
|
||||
}
|
||||
}
|
||||
|
||||
/// An index status as one token and its numbers: `Behind pending=3`.
|
||||
pub fn index_state(index: &IndexStatus) -> String {
|
||||
let mut text = name_of(index);
|
||||
if let Ok(Value::Object(variant)) = serde_json::to_value(index)
|
||||
&& let Some(Value::Object(fields)) = variant.values().next()
|
||||
{
|
||||
for (key, value) in fields {
|
||||
if let Some(shown) = scalar(value) {
|
||||
let _ = write!(text, " {key}={shown}");
|
||||
}
|
||||
}
|
||||
}
|
||||
text
|
||||
}
|
||||
|
||||
/// One document as `view` prints it: id and status, the admission facts, then
|
||||
/// the `{kind, value}` document as pretty JSON. `raw` is the JSON alone.
|
||||
pub fn view(view: &PipelineDocumentView, raw: bool) -> String {
|
||||
let document = serde_json::to_string_pretty(&view.document).unwrap_or_default();
|
||||
if raw {
|
||||
return document;
|
||||
}
|
||||
let id = &view.id.id.0;
|
||||
let status = match &view.status {
|
||||
PipelineStatus::InForce => "InForce".to_string(),
|
||||
PipelineStatus::Resolved { resolution, record } => format!("Resolved {} by {}", name_of(&record.outcome), resolution.id.0),
|
||||
};
|
||||
let admission = &view.admission;
|
||||
let who = &admission.provenance;
|
||||
format!(
|
||||
"{id} {status}\nadmitted {} ordinal {} {}/{} session {} tool {} receipt {}\n{document}",
|
||||
admission.admitted_at,
|
||||
admission.ordinal,
|
||||
name_of(&who.faculty),
|
||||
who.agent.0,
|
||||
who.session.0,
|
||||
who.tool.0,
|
||||
admission.receipt_id,
|
||||
)
|
||||
}
|
||||
|
||||
/// One header as a line: `<id> <status> <faculty> <title or label> k=v...`
|
||||
/// over the header's scalar facts.
|
||||
pub fn header(item: &PipelineDocumentSummary) -> String {
|
||||
let status = match &item.status {
|
||||
PipelineStatusSummary::InForce => "InForce".to_string(),
|
||||
PipelineStatusSummary::Resolved { outcome, .. } => format!("Resolved:{}", name_of(outcome)),
|
||||
};
|
||||
let mut line = format!("{} {status} {}", item.id.id.0, name_of(&item.admission.provenance.faculty));
|
||||
if let Ok(facts) = serde_json::to_value(&item.facts)
|
||||
&& let Some(Value::Object(facts)) = facts.get("value")
|
||||
{
|
||||
if let Some(Value::String(name)) = facts.get("title").or_else(|| facts.get("label")) {
|
||||
let _ = write!(line, " {name}");
|
||||
}
|
||||
for (key, value) in facts {
|
||||
if key != "title"
|
||||
&& key != "label"
|
||||
&& let Some(shown) = scalar(value)
|
||||
{
|
||||
let _ = write!(line, " {key}={shown}");
|
||||
}
|
||||
}
|
||||
}
|
||||
line.chars().take(HEADER_MAX_CHARS).collect()
|
||||
}
|
||||
|
||||
/// A fact as one token: a string, a number, a flag, a reference's id, or a
|
||||
/// list of those joined by commas. Anything deeper is not a header fact.
|
||||
fn scalar(value: &Value) -> Option<String> {
|
||||
match value {
|
||||
Value::String(text) if !text.is_empty() => Some(text.clone()),
|
||||
Value::Number(number) => Some(number.to_string()),
|
||||
Value::Bool(flag) => Some(flag.to_string()),
|
||||
Value::Array(items) => {
|
||||
let shown: Vec<String> = items.iter().filter_map(scalar).collect();
|
||||
if shown.is_empty() { None } else { Some(shown.join(",")) }
|
||||
}
|
||||
Value::Object(fields) => match fields.get("id") {
|
||||
Some(Value::String(id)) => Some(id.clone()),
|
||||
_ => None,
|
||||
},
|
||||
Value::String(_) | Value::Null => None,
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue