huginn view: the header names an imported document's source and a moved document's receiver
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
c76e37280d
commit
c4d38bcea5
1 changed files with 81 additions and 1 deletions
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
use std::fmt::Write;
|
||||
|
||||
use huginn_mind::eureka_pipeline::{PipelineResolution, ResolutionOutcome};
|
||||
use huginn_mind::{SourceHits, IndexStatus, PersonaStatus, PipelineDocumentSummary, PipelineDocumentView, PipelineStatus, PipelineStatusSummary};
|
||||
use serde::Serialize;
|
||||
use serde_json::Value;
|
||||
|
|
@ -54,12 +55,26 @@ pub fn view(view: &PipelineDocumentView, raw: bool) -> String {
|
|||
let id = &view.id.id.0;
|
||||
let status = match &view.status {
|
||||
PipelineStatus::InForce => "InForce".to_string(),
|
||||
PipelineStatus::Resolved { resolution, record: PipelineResolution { outcome: ResolutionOutcome::Moved { to }, .. } } => {
|
||||
format!("Resolved Moved to {} by {}", to.0, resolution.id.0)
|
||||
}
|
||||
PipelineStatus::Resolved { resolution, record } => format!("Resolved {} by {}", name_of(&record.outcome), resolution.id.0),
|
||||
};
|
||||
let admission = &view.admission;
|
||||
let who = &admission.provenance;
|
||||
let imported = who.imported_from.as_ref().map_or_else(String::new, |source| {
|
||||
format!(
|
||||
"\nimported from {} ordinal {} receipt {} ({}/{} session {})",
|
||||
source.instance.0,
|
||||
source.ordinal,
|
||||
source.receipt_id.0,
|
||||
name_of(&source.faculty),
|
||||
source.agent.0,
|
||||
source.session.0,
|
||||
)
|
||||
});
|
||||
format!(
|
||||
"{id} {status}\nadmitted {} ordinal {} {}/{} session {} tool {} receipt {}\n{document}",
|
||||
"{id} {status}\nadmitted {} ordinal {} {}/{} session {} tool {} receipt {}{imported}\n{document}",
|
||||
admission.admitted_at,
|
||||
admission.ordinal,
|
||||
name_of(&who.faculty),
|
||||
|
|
@ -145,8 +160,73 @@ fn scalar(value: &Value) -> Option<String> {
|
|||
mod tests {
|
||||
use serde_json::json;
|
||||
|
||||
use huginn_mind::eureka_pipeline::{Date, PipelineDocument, PipelineInstance, PipelineKind, PipelineRef, Short, Slug};
|
||||
use huginn_mind::{AdmissionFacts, Faculty, ImportSource, PipelineProvenance};
|
||||
|
||||
use super::*;
|
||||
|
||||
fn viewed(imported_from: Option<ImportSource>, status: PipelineStatus) -> PipelineDocumentView {
|
||||
PipelineDocumentView {
|
||||
id: PipelineRef { kind: PipelineKind::Instance, id: Short("heimdall:instance:self".into()) },
|
||||
document: PipelineDocument::Instance(PipelineInstance {
|
||||
instance: Slug("heimdall".into()),
|
||||
display_name: Short("Heimdall".into()),
|
||||
created_at: Date("2026-10-10".into()),
|
||||
host: Short("yggdrasil".into()),
|
||||
}),
|
||||
admission: AdmissionFacts {
|
||||
receipt_id: "mind-commit-b".into(),
|
||||
admitted_at: "2026-11-08T12:00:00Z".into(),
|
||||
provenance: PipelineProvenance {
|
||||
faculty: Faculty::SelfFaculty,
|
||||
agent: Short("heimdall-self".into()),
|
||||
session: Short("run-9".into()),
|
||||
tool: Short("huginn".into()),
|
||||
imported_from,
|
||||
},
|
||||
ordinal: 4,
|
||||
},
|
||||
status,
|
||||
}
|
||||
}
|
||||
|
||||
/// A reader of an imported document sees where it came from and who admitted it there; a document
|
||||
/// admitted here prints no source line, and a moved one names its receiver.
|
||||
#[test]
|
||||
fn view_header_names_the_import_source() {
|
||||
let source = ImportSource {
|
||||
instance: Slug("eureka".into()),
|
||||
receipt_id: Short("mind-commit-a".into()),
|
||||
ordinal: 7331,
|
||||
committed_at: Short("2026-11-08T16:20:05Z".into()),
|
||||
faculty: Faculty::Imagination,
|
||||
agent: Short("imagination".into()),
|
||||
session: Short("eureka-self-1108".into()),
|
||||
tool: Short("huginn".into()),
|
||||
external: vec![],
|
||||
};
|
||||
let shown = view(&viewed(Some(source), PipelineStatus::InForce), false);
|
||||
assert!(
|
||||
shown.contains("
|
||||
imported from eureka ordinal 7331 receipt mind-commit-a (Imagination/imagination session eureka-self-1108)
|
||||
"),
|
||||
"{shown}"
|
||||
);
|
||||
assert!(!view(&viewed(None, PipelineStatus::InForce), false).contains("imported from"));
|
||||
|
||||
let record = huginn_mind::eureka_pipeline::PipelineResolution {
|
||||
subject: PipelineRef { kind: PipelineKind::Campaign, id: Short("c:campaign:self".into()) },
|
||||
sequence: 1,
|
||||
outcome: ResolutionOutcome::Moved { to: Slug("heimdall".into()) },
|
||||
rationale: "Her repo.".into(),
|
||||
resolved_on: Date("2026-11-08".into()),
|
||||
};
|
||||
let resolution = PipelineRef { kind: PipelineKind::Resolution, id: Short("c:resolution:campaign.self.n1".into()) };
|
||||
let moved = view(&viewed(None, PipelineStatus::Resolved { resolution, record }), false);
|
||||
assert!(moved.starts_with("heimdall:instance:self Resolved Moved to heimdall by c:resolution:campaign.self.n1
|
||||
"), "{moved}");
|
||||
}
|
||||
|
||||
/// The citation line is what an agent copies: repo, path, the inclusive
|
||||
/// line range and the first seven of the commit.
|
||||
#[test]
|
||||
|
|
|
|||
Loading…
Reference in a new issue