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