Skip to main content

artifactize_core/
config.rs

1//! Inert discovery and strict declarations.
2
3use std::{
4    collections::{BTreeMap, BTreeSet},
5    path::{Path, PathBuf},
6};
7
8use thiserror::Error;
9
10mod authored_target;
11mod backend;
12mod declaration;
13mod definition;
14mod discovery;
15pub mod edit;
16mod eval;
17mod identities;
18mod legacy;
19mod location;
20pub mod migrate;
21mod mutex;
22mod plain;
23mod profile;
24mod schemas;
25mod site;
26mod stored;
27mod tools;
28pub(crate) mod validation;
29mod workspace;
30
31pub use crate::types::{ArtifactName, EvalId};
32pub use artifactize_tools::scope::{ArtifactKind, Target, Uri};
33pub use backend::{Backend, Provider};
34pub use declaration::{ArtifactDeclaration, Fingerprint, Views, parse_declaration};
35pub use discovery::read_workspace_config;
36pub(crate) use discovery::read_workspace_declarations;
37use discovery::{logical_join, read_regular_text};
38pub use eval::{EvalDeclaration, EvalPayload, LocalEvalId, Priority};
39pub use identities::{
40    ChildPrefix, EndpointId, ExecutionPinName, HubEpoch, LogicalPath, ModelId, ProfileVariantName,
41    ReferenceName, ToolName, ToolOperationName,
42};
43pub use mutex::MutexTag;
44pub use profile::{Profile, ProfileKind, Reasoning};
45pub use site::{ScopeReadError, Site, read_sites};
46pub(crate) use site::{read_artifact_scope, read_eval_scope};
47pub use stored::{Field, StoredPayload, StoredProfile};
48pub use tools::{
49    AgentTool, Builtin, BuiltinTool, CommandTool, HumanBuiltinTool, HumanCommandTool, HumanTool,
50    HumanToolKind, SessionCommand, ToolProtocol, ToolSession,
51};
52pub use validation::MAX_TIMEOUT_MS;
53pub(crate) use validation::{artifact_name, identifier};
54pub use workspace::{Artifact, Eval, RepoConfig, ReviewRequirement};
55
56/// Format version for artifactize configuration documents.
57pub const CONFIG_FORMAT_VERSION: u32 = 1;
58pub const CONFIG_FILE: &str = "index.artf";
59/// Gitignore-style folder patterns, at the workspace root, that discovery skips.
60pub const IGNORE_FILE: &str = ".artfignore";
61/// Bound named variants and declared input lists to keep discovery and preparation finite.
62const MAX_DECLARED_ITEMS: usize = 64;
63
64#[derive(Debug, Error)]
65#[error("{}: {message}", crate::platform::path_text(.path))]
66pub struct ConfigError {
67    pub path: PathBuf,
68    pub message: String,
69    declaration: Option<(Vec<String>, String)>,
70}
71
72impl ConfigError {
73    pub(crate) fn new(path: impl Into<PathBuf>, message: impl ToString) -> Self {
74        Self {
75            path: path.into(),
76            message: message.to_string(),
77            declaration: None,
78        }
79    }
80
81    /// Position cross-Artifact validation failures at their declaration's typed key.
82    pub(crate) fn declaration(
83        path: impl Into<PathBuf>,
84        keys: &[&str],
85        message: impl ToString,
86    ) -> Self {
87        let path = path.into();
88        let message = message.to_string();
89        let declaration = Some((
90            keys.iter().map(|key| (*key).to_owned()).collect(),
91            message.clone(),
92        ));
93        let message = read_regular_text(&path).map_or(message.clone(), |source| {
94            location::error_at(&source, keys, &message)
95        });
96        Self {
97            path,
98            message,
99            declaration,
100        }
101    }
102}
103
104#[cfg(test)]
105mod tests;