Skip to main content

artifactize_core/
inspect.rs

1//! Shared non-interactive JSON projections. Interfaces add rendering and paging only.
2mod logs;
3pub mod session;
4pub use logs::{DEFAULT_TAIL as DEFAULT_LOG_TAIL_LINES, LogOptions, LogQuery, Stream, logs};
5
6use crate::{config::read_workspace_config, types::RequestId};
7use serde::Serialize;
8use serde_json::{Value, json};
9use std::path::Path;
10
11#[derive(Debug, Serialize)]
12pub struct ConfigCheck {
13    pub ok: bool,
14    pub artifacts: usize,
15    pub evals: usize,
16    #[serde(skip_serializing_if = "Vec::is_empty")]
17    pub notes: Vec<String>,
18}
19pub fn config_check(repo: &Path) -> Result<ConfigCheck, String> {
20    let config = read_workspace_config(repo).map_err(|error| error.to_string())?;
21    Ok(ConfigCheck {
22        notes: config
23            .artifacts
24            .values()
25            .filter_map(|artifact| {
26                crate::scope::validate_file_target(&config.root, artifact)
27                    .err()
28                    .map(|error| error.to_string())
29            })
30            .collect(),
31        ok: true,
32        artifacts: config.artifacts.len(),
33        evals: config.evals.len(),
34    })
35}
36
37pub async fn request_show(
38    state: &Path,
39    id: &RequestId,
40    now: time::OffsetDateTime,
41) -> Result<Value, String> {
42    Ok(crate::query::request_output(
43        &crate::store::read_request(state, id).await?,
44        now,
45    ))
46}
47
48pub async fn request_list(
49    state: &Path,
50    run: Option<&crate::types::RunId>,
51    repo: Option<&Path>,
52    now: time::OffsetDateTime,
53) -> Result<Vec<Value>, String> {
54    let views = crate::store::read_requests_for_run(state, run.cloned(), repo).await?;
55    Ok(views
56        .iter()
57        .map(|view| crate::query::request_output(view, now))
58        .collect())
59}
60
61pub async fn remote_status(state: Option<&Path>, repo: Option<&Path>) -> Result<Value, String> {
62    Ok(remote_output(
63        crate::auth::remote::status(state, repo).await?.as_ref(),
64    ))
65}
66
67pub fn remote_output(status: Option<&crate::auth::remote::Status>) -> Value {
68    match status {
69        Some(status) => {
70            let mut value = json!(status);
71            value["configured"] = json!(true);
72            value
73        }
74        None => json!({"configured": false}),
75    }
76}
77
78pub async fn session_show(
79    state: &Path,
80    selector: &session::Selector,
81    summary: bool,
82) -> Result<session::Shown, String> {
83    session::show(state, selector, summary).await
84}