systemprompt-cli 0.15.0

Unified CLI for systemprompt.io AI governance: agent orchestration, MCP governance, analytics, profiles, cloud deploy, and self-hosted operations.
Documentation
//! End-of-run finalization for JSON/YAML output.
//!
//! When a command runs in structured-output mode but emits no artifact of its
//! own, the levelled notices it logged are flushed as a single `message`
//! artifact so stdout always carries exactly one parseable [`CliArtifact`].

use anyhow::Result;

use systemprompt_logging::{
    CliService, drain_notices, is_structured_output, structured_was_emitted,
};
use systemprompt_models::artifacts::{CliArtifact, MessageArtifact, NoticeLine};

pub(super) fn finalize(outcome: &Result<()>) {
    if outcome.is_err() || !is_structured_output() || structured_was_emitted() {
        return;
    }

    let mut lines: Vec<NoticeLine> = drain_notices()
        .into_iter()
        .map(|n| NoticeLine::new(n.level, n.text))
        .collect();
    if lines.is_empty() {
        lines.push(NoticeLine::new("success", "Command completed."));
    }
    CliService::json(&CliArtifact::message(MessageArtifact::new(lines)));
}