Skip to main content

artifactize_core/verify_tools/
catalog.rs

1//! The complete public tool surface; deliberately no credential or Human actions.
2use super::{
3    input::{DEFAULT_WAIT_SECONDS, MAX_WAIT_SECONDS, MIN_SCOPE_IDS, RUN_LIST_LIMIT, SCOPE_IDS},
4    tool::{PluginTool, ReadTool, ToolId, VerifyTool},
5};
6use crate::{
7    inspect::DEFAULT_LOG_TAIL_LINES, runs::RESULT_PAGE_SIZE, types::MAX_RUN_COMMENT_CHARS,
8};
9use serde_json::{Map, Value, json};
10use std::borrow::Cow;
11
12/// One tool's protocol-neutral wire contract, shared by MCP and Chat.
13pub struct Tool {
14    pub name: &'static str,
15    pub description: Cow<'static, str>,
16    pub schema: Map<String, Value>,
17    pub hints: Hints,
18}
19
20pub struct Hints {
21    pub open_world: bool,
22    pub read_only: bool,
23    pub destructive: bool,
24    pub idempotent: bool,
25}
26
27/// Match core's ASCII RequestKey bound, keeping retry identities compact in stored receipts.
28const REQUEST_KEY_CHARS: usize = 128;
29
30/// Match the core log snapshot bound so one MCP response stays bounded.
31const LOG_TAIL_LINES: usize = 200;
32/// Match the core literal-search bound to limit scanning input per request.
33const LOG_SEARCH_CHARS: usize = 2048;
34/// Match core's identifier bound for a backend name, so a name no declaration can use is
35/// refused before the provider lookup.
36const BACKEND_NAME_CHARS: usize = 64;
37
38// The outer object is typed; only each individual JSON Schema value needs `json!`.
39macro_rules! object {
40    ({$($key:literal : $value:tt),+ $(,)?}) => {
41        Map::from_iter([$(($key.into(), json!($value))),+])
42    };
43}
44
45pub fn tools() -> Vec<Tool> {
46    let scope = json!({"oneOf": [
47        {"type":"object","properties":{"kind":{"const":"all"}},"required":["kind"],"additionalProperties":false},
48        {"type":"object","properties":{"kind":{"const":"artifact"},"artifactId":{"type":"string"}},"required":["kind","artifactId"],"additionalProperties":false},
49        {"type":"object","properties":{"kind":{"const":"eval"},"evalId":{"type":"string"}},"required":["kind","evalId"],"additionalProperties":false},
50        {"type":"object","properties":{"kind":{"const":"artifacts"},"artifactIds":{"type":"array","items":{"type":"string"},"minItems":MIN_SCOPE_IDS,"maxItems":SCOPE_IDS}},"required":["kind","artifactIds"],"additionalProperties":false},
51        {"type":"object","properties":{"kind":{"const":"evals"},"evalIds":{"type":"array","items":{"type":"string"},"minItems":MIN_SCOPE_IDS,"maxItems":SCOPE_IDS}},"required":["kind","evalIds"],"additionalProperties":false}
52    ]});
53    let string = json!({"type":"string"});
54    vec![
55        tool(
56            ReadTool::Plugins,
57            "List built-in and installed project Artifact types.",
58            Map::new(),
59            &[],
60        ),
61        tool(
62            PluginTool::Add,
63            "Install a plugin folder from an absolute path. Only run for a package the user trusts.",
64            object!({"path":string}),
65            &["path"],
66        ),
67        tool(
68            PluginTool::Remove,
69            "Remove an installed Artifact type plugin by type name.",
70            object!({"type":string}),
71            &["type"],
72        ),
73        tool(
74            VerifyTool::Start,
75            "Submit a durable Run; acceptance is not approval. Same caller key returns the same attempt. A comment, a short note on what you are working on, is shown to people with the Run and changes nothing it does. Speculation defaults off; concurrency is unlimited unless jobs is explicitly given; backend limits still apply. Sign-offs the Run selected never hold up other evals (one outside the scope does, and the Run ends incomplete until the scope includes it): the Run stays waiting_human while one is claimed or its idle grace runs, then ends yellow when only sign-offs remain, which is not full approval.",
76            object!({"scope":scope,"jobs":{"type":"integer","minimum":1,"maximum":u32::MAX},"request_key":{"type":"string","pattern":format!("^[A-Za-z0-9._:-]{{1,{REQUEST_KEY_CHARS}}}$")},"comment":{"type":"string","minLength":1,"maxLength":MAX_RUN_COMMENT_CHARS},"speculate":{"type":"boolean","default":false}}),
77            &["scope"],
78        ),
79        tool(
80            VerifyTool::Status,
81            "Compact saved Run state and counts.",
82            object!({"run":string}),
83            &["run"],
84        ),
85        tool(
86            VerifyTool::Wait,
87            "Observe Run end or bound, equally for all eval kinds. Disconnect/cancellation only drops this observer.",
88            object!({"run":string,"seconds":{"type":"integer","minimum":0,"maximum":MAX_WAIT_SECONDS,"default":DEFAULT_WAIT_SECONDS}}),
89            &["run"],
90        ),
91        tool(
92            VerifyTool::Watch,
93            "Subscribe for this bounded call: progress notifications carry JSON update/eval_result/outcome events when the client supplies _meta.progressToken. Reattachment replays saved results. Returns compact observation; only outcome/verify_result is final validation. No conversation injection or background subscription.",
94            object!({"run":string}),
95            &["run"],
96        ),
97        tool(
98            VerifyTool::Result,
99            format!(
100                "Terminal verdict and at most {RESULT_PAGE_SIZE} concise findings; follow next_cursor. Active Runs return ready:false."
101            ),
102            object!({"run":string,"cursor":string}),
103            &["run"],
104        ),
105        tool(
106            VerifyTool::Cancel,
107            "Explicitly request cancellation; committed evidence remains. Observe settlement for cleanup.",
108            object!({"run":string}),
109            &["run"],
110        ),
111        tool(
112            ReadTool::Status,
113            "Predict execute/reuse/wait using the CLI's status operation. May run trusted fingerprint commands.",
114            object!({"scope":scope}),
115            &[],
116        ),
117        tool(
118            ReadTool::Graph,
119            "Discover static Artifacts, eval criteria, input/consumer relations and cycles without running commands. Scope selects required inputs; impact includes downstream consumers and their inputs, conservatively, not exact cache invalidation.",
120            object!({"scope":scope,"impact":{"type":"boolean","default":false}}),
121            &[],
122        ),
123        tool(
124            ReadTool::Logs,
125            format!(
126                "Inspect runtime stdout/stderr without the full request. Defaults to last {DEFAULT_LOG_TAIL_LINES} lines per stream; explicit evidence distinguishes full local capture, partial, saved audit and missing. Search is literal. Tail/range exclusive. next_start continues forward queries."
127            ),
128            object!({"id":string,"stream":{"enum":["stdout","stderr","both"],"default":"both"},"tail":{"type":"integer","minimum":1,"maximum":LOG_TAIL_LINES},"start":{"type":"integer","minimum":1},"end":{"type":"integer","minimum":1},"search":{"type":"string","minLength":1,"maxLength":LOG_SEARCH_CHARS}}),
129            &["id"],
130        ),
131        tool(
132            ReadTool::Config,
133            "Validate declarations, without hashing or executing project tools.",
134            Map::new(),
135            &[],
136        ),
137        tool(
138            ReadTool::Runs,
139            "List this repository's saved Runs, newest first. Offset selects older records.",
140            object!({"limit":{"type":"integer","minimum":0,"maximum":RUN_LIST_LIMIT,"default":RUN_LIST_LIMIT},"offset":{"type":"integer","minimum":0}}),
141            &[],
142        ),
143        tool(
144            ReadTool::Run,
145            "Read saved Run audit, same JSON as CLI run show.",
146            object!({"run":string}),
147            &["run"],
148        ),
149        tool(
150            ReadTool::Requests,
151            "Read requests from this repository, optionally one Run. No sign-off authority.",
152            object!({"run":string}),
153            &[],
154        ),
155        tool(
156            ReadTool::Request,
157            "Read saved request audit and criteria. No claim or submit.",
158            object!({"id":string}),
159            &["id"],
160        ),
161        tool(
162            ReadTool::Session,
163            "Read saved Agent conversation or summary. Never send a follow-up.",
164            object!({"reference":string,"summary":{"type":"boolean","default":false}}),
165            &["reference"],
166        ),
167        tool(
168            ReadTool::Tools,
169            "Static preflight only; never execute tools or start sessions.",
170            object!({"eval":string,"artifact":string,"audience":{"enum":["agent","human"]},"tool":string}),
171            &[],
172        ),
173        tool(
174            ReadTool::Doctor,
175            "Inspect backend and state readiness without changing credentials.",
176            Map::new(),
177            &[],
178        ),
179        tool(
180            ReadTool::Models,
181            "List models available from the named backend: a built-in provider (codex, claude-agent, antigravity, openai, anthropic, gemini) or a custom provider set up on this machine.",
182            object!({"provider":{"type":"string","pattern":format!("^[A-Za-z0-9][A-Za-z0-9_-]{{0,{}}}$", BACKEND_NAME_CHARS - 1)}}),
183            &["provider"],
184        ),
185        tool(
186            ReadTool::Remote,
187            "Inspect configured review store, token source and reachability; never disclose the token.",
188            Map::new(),
189            &[],
190        ),
191        tool(
192            ReadTool::Cache,
193            "Read latest reusable record, or full history; never remove a record.",
194            object!({"key":string,"history":{"type":"boolean","default":false}}),
195            &["key"],
196        ),
197    ]
198}
199fn tool(
200    id: impl Into<ToolId>,
201    description: impl Into<Cow<'static, str>>,
202    mut properties: Map<String, Value>,
203    required: &[&str],
204) -> Tool {
205    let id = id.into();
206    let description = description.into();
207    let description = if matches!(id, ToolId::Read(_)) {
208        properties.insert("cursor".into(), json!({"type":"string"}));
209        format!(
210            "{description} Returns bounded pages of exact CLI JSON: concatenate entries.text, following next_cursor, then parse JSON."
211        ).into()
212    } else {
213        description
214    };
215    properties.insert(
216        "project".into(),
217        json!({"type":"string","description":"The absolute project folder; needed only when the host names no project."}),
218    );
219    let schema = object!({"type":"object","properties":properties,"required":required,"additionalProperties":false});
220    Tool {
221        name: id.name(),
222        description,
223        schema,
224        hints: annotations(id),
225    }
226}
227
228enum Effect {
229    ReadOnly,
230    Mutating(Mutation),
231}
232
233enum Mutation {
234    NonIdempotent,
235    IdempotentDestructive,
236}
237
238enum Reach {
239    Closed,
240    Open,
241}
242
243fn annotations(id: ToolId) -> Hints {
244    use ReadTool as Read;
245    use VerifyTool as Verify;
246    let (effect, reach) = match id {
247        ToolId::Verify(Verify::Start) => (Effect::Mutating(Mutation::NonIdempotent), Reach::Open),
248        ToolId::Verify(Verify::Cancel) => (
249            Effect::Mutating(Mutation::IdempotentDestructive),
250            Reach::Closed,
251        ),
252        ToolId::Plugin(PluginTool::Add) => {
253            (Effect::Mutating(Mutation::NonIdempotent), Reach::Closed)
254        }
255        ToolId::Plugin(PluginTool::Remove) => (
256            Effect::Mutating(Mutation::IdempotentDestructive),
257            Reach::Closed,
258        ),
259        ToolId::Read(Read::Status) => (Effect::Mutating(Mutation::NonIdempotent), Reach::Closed),
260        ToolId::Read(Read::Models | Read::Remote) => (Effect::ReadOnly, Reach::Open),
261        ToolId::Verify(Verify::Status | Verify::Wait | Verify::Watch | Verify::Result)
262        | ToolId::Read(
263            Read::Graph
264            | Read::Logs
265            | Read::Config
266            | Read::Runs
267            | Read::Run
268            | Read::Requests
269            | Read::Request
270            | Read::Session
271            | Read::Tools
272            | Read::Doctor
273            | Read::Cache
274            | Read::Plugins,
275        ) => (Effect::ReadOnly, Reach::Closed),
276    };
277    Hints {
278        open_world: matches!(reach, Reach::Open),
279        read_only: matches!(effect, Effect::ReadOnly),
280        destructive: matches!(effect, Effect::Mutating(Mutation::IdempotentDestructive)),
281        idempotent: !matches!(effect, Effect::Mutating(Mutation::NonIdempotent)),
282    }
283}