artifactize-core 0.27.2

The library behind artifactize: Artifacts, evals, reviews, the monitor and review models, and the shared operations every interface calls.
Documentation
//! Protocol-neutral implementation of the public Verify and inspection tools.
mod catalog;
mod error;
mod input;
mod page;
mod read;
mod tool;

pub use catalog::{Hints, Tool, tools};
pub use error::{ArgumentsError, Error};
pub use input::Call;
pub use page::{CursorError, Page};

use serde::Serialize;
use tokio_util::sync::CancellationToken;

use crate::{project::VerifyOptions, runs};
use input::{Command, Plugin, Verify};

#[derive(Serialize)]
#[serde(untagged)]
pub enum Output {
    Observation(runs::RunObservation),
    Cancellation(runs::CancelAcknowledgement),
    Inspection(Page),
    Plugin(PluginResult),
}

#[derive(Serialize)]
#[serde(tag = "action", rename_all = "lowercase")]
pub enum PluginResult {
    Added(crate::config::plugins::PluginInfo),
    Removed {
        #[serde(rename = "namespace")]
        name: crate::config::PluginName,
    },
}

/// Whether `name` is one of the public tools, served or not.
pub fn is_tool(name: &str) -> bool {
    tool::ToolId::parse(name).is_some()
}

/// The Run's `run_show` JSON, read at once and whole, with managed secrets scrubbed.
pub async fn run_json(context: &runs::Context, run: &crate::types::RunId) -> Result<String, Error> {
    read::run(context, run).await
}

impl Call {
    /// Execute an operation in the scope resolved by its transport.
    pub async fn execute(
        self,
        context: &runs::Context,
        cancel: CancellationToken,
    ) -> Result<Output, Error> {
        let command = match self.command {
            Command::Verify(command) => command,
            Command::Plugin(plugin) => {
                use crate::config::plugins;
                let result = match plugin {
                    Plugin::Add(args) => PluginResult::Added(
                        plugins::add(context.repo(), &args.path).map_err(Error::Config)?,
                    ),
                    Plugin::Remove(args) => {
                        plugins::remove(context.repo(), &args.name).map_err(Error::Config)?;
                        PluginResult::Removed { name: args.name }
                    }
                };
                return Ok(Output::Plugin(result));
            }
            Command::Inspect(inspection) => {
                return Ok(Output::Inspection(
                    read::inspect(context, inspection, cancel).await?,
                ));
            }
        };
        Ok(match command {
            Verify::Start(args) => {
                let options = VerifyOptions {
                    jobs: args.jobs.map(|limit| limit.get() as usize),
                    modes: runs::RunModes {
                        speculate: args.speculate,
                    },
                    comment: args.comment.clone(),
                    ..Default::default()
                };
                let fingerprint = args.request_key.as_ref().map(|_| args.fingerprint());
                Output::Observation(
                    runs::start_with_args_hash(
                        context,
                        args.scope.selection(),
                        &options,
                        args.request_key,
                        fingerprint,
                    )
                    .await?,
                )
            }
            Verify::Cancel(run) => Output::Cancellation(runs::cancel(context, &run).await?),
        })
    }
}