Skip to main content

mars_schema/
tool_natives.rs

1//! Explicit per-harness native tool names for Mars capabilities.
2//!
3//! One table per harness, one row per capability. Nothing is derived by naming convention: a
4//! row names the harness's real tools (one capability can cover several), says the harness has
5//! no such tool ([`Native::Absent`]), says it does the thing without a tool to switch
6//! ([`Native::NoSwitch`], with the reason), or is missing, which means Mars has not decided for
7//! that harness. Both `NoSwitch` and a missing row report as `unknown`, a gap Meridian
8//! surfaces, because calling an unenforceable deny `absent` would report it as met. A
9//! `NoSwitch` row is a settled fact and carries its reason in the bundle's `note`; a missing
10//! row says Mars has not decided.
11//! [`Native::native_tools`] always returns the unscoped harness tool set. It stays distinct
12//! from a scoped permission spelling such as Claude `Edit(path)` for the `Write` tool.
13//!
14//! Every name below must appear in the harness's real tool list, which the tests pin with the
15//! source each list came from. When a harness ships a tool, add it to that list first.
16
17use std::collections::BTreeMap;
18
19use serde::Serialize;
20
21use crate::Host;
22
23/// What a harness calls a capability.
24#[derive(Clone, Copy, Debug, PartialEq, Eq)]
25pub enum Native {
26    /// The harness's tools for this capability. A deny or allow covers all of them.
27    Tools(&'static [&'static str]),
28    /// A harness uses different permission names once a rule has a scope. Claude's file tools
29    /// are the motivating case: bare `Write` gates that tool, but only `Edit(path)` gates a
30    /// path for every built-in file editor.
31    ScopedTools {
32        unscoped: &'static [&'static str],
33        scoped: &'static [&'static str],
34        note: &'static str,
35    },
36    /// The harness has no such tool, so there is nothing to allow or deny.
37    Absent,
38    /// The harness can do the thing but offers no tool to switch it off (Codex and Pi load
39    /// skills by reading `SKILL.md`; Codex reads, globs and greps through its shell). The
40    /// string says why, for the bundle's `note`.
41    NoSwitch(&'static str),
42}
43
44impl Native {
45    /// The unscoped harness tool names this permission row concerns. Scoped permission names can
46    /// differ from these tools, but availability controls always use the unscoped tool set.
47    pub fn native_tools(self) -> &'static [&'static str] {
48        match self {
49            Self::Tools(names)
50            | Self::ScopedTools {
51                unscoped: names, ..
52            } => names,
53            Self::Absent | Self::NoSwitch(_) => &[],
54        }
55    }
56}
57
58use Native::{Absent, NoSwitch, ScopedTools, Tools};
59
60pub(crate) type Table = &'static [(&'static str, Native)];
61
62/// The row for `capability` on `harness`, or `None` when Mars has no entry.
63pub fn lookup(capability: &str, host: impl Into<Host>) -> Option<Native> {
64    host.into()
65        .spec()
66        .tools
67        .iter()
68        .find(|(name, _)| *name == capability)
69        .map(|(_, native)| *native)
70}
71
72/// What a consumer reads of the tool vocabulary: every capability and, per host, what the
73/// host calls it. Derived only from the tables in this file.
74#[derive(Debug, Clone, Serialize)]
75pub struct Vocabulary {
76    pub capabilities: Vec<crate::tool_names::CapabilityEntry>,
77    pub natives: BTreeMap<&'static str, BTreeMap<&'static str, NativeEntry>>,
78}
79
80/// One row of a host's table, in the published shape.
81#[derive(Debug, Clone, Serialize)]
82#[serde(tag = "kind", rename_all = "kebab-case")]
83pub enum NativeEntry {
84    Tools {
85        tools: &'static [&'static str],
86    },
87    ScopedTools {
88        unscoped: &'static [&'static str],
89        scoped: &'static [&'static str],
90        note: &'static str,
91    },
92    Absent,
93    NoSwitch {
94        note: &'static str,
95    },
96}
97
98impl From<Native> for NativeEntry {
99    fn from(native: Native) -> Self {
100        match native {
101            Tools(tools) => Self::Tools { tools },
102            ScopedTools {
103                unscoped,
104                scoped,
105                note,
106            } => Self::ScopedTools {
107                unscoped,
108                scoped,
109                note,
110            },
111            Absent => Self::Absent,
112            NoSwitch(note) => Self::NoSwitch { note },
113        }
114    }
115}
116
117/// The published vocabulary: the capability list plus one native table per harness and Flow.
118pub fn vocabulary() -> Vocabulary {
119    let rows = |table: Table| {
120        table
121            .iter()
122            .map(|(name, native)| (*name, NativeEntry::from(*native)))
123            .collect()
124    };
125    let natives = Host::ALL
126        .iter()
127        .map(|host| (host.as_str(), rows(host.spec().tools)))
128        .collect();
129    Vocabulary {
130        capabilities: crate::tool_names::capabilities(),
131        natives,
132    }
133}
134
135/// Claude Code 2.1.308.
136///
137/// Source: the tools and permissions references (code.claude.com/docs/en/tools-reference and
138/// code.claude.com/docs/en/permissions) and the 2.1.308
139/// binary. Probed live with `claude -p --disallowedTools`: `Agent` and `Task` both remove the
140/// sub-agent tool, `Edit` alone leaves `Write` and `NotebookEdit` available, and a misspelled
141/// name (`Websearch`) is silently ignored. Bare `edit` therefore names all three file-editing
142/// tools. Scoped file rules are different: Claude consults only `Edit(path)` and `Read(path)`,
143/// not `Write(path)`, `NotebookEdit(path)`, `Glob(path)`, or `Grep(path)`. Direct 2.1.308 probes
144/// confirmed the documented behavior. `WebFetch(domain:...)` is a valid scoped rule.
145/// `agent` is the sub-agent family, as it is on Codex: `Agent` spawns, `SendMessage` and
146/// `ListAgents` reach the agents it spawned, and an `agent: deny` that left them available would
147/// still let the agent steer sub-agents.
148pub(crate) const CLAUDE: Table = &[
149    ("bash", Tools(&["Bash"])),
150    ("read", Tools(&["Read"])),
151    // Claude lists through Bash; there is no listing tool.
152    ("ls", Absent),
153    ("work", Absent),
154    (
155        "write",
156        ScopedTools {
157            unscoped: &["Write"],
158            scoped: &["Edit"],
159            note: "Claude scopes Write through Edit(path): an allow adds no practical write power because Write can replace the whole file, while a deny also refuses other built-in file edits at that path",
160        },
161    ),
162    (
163        "edit",
164        ScopedTools {
165            unscoped: &["Edit", "Write", "NotebookEdit"],
166            scoped: &["Edit"],
167            note: "Claude uses Edit(path) to scope every built-in file-editing tool",
168        },
169    ),
170    (
171        "notebook",
172        ScopedTools {
173            unscoped: &["NotebookEdit"],
174            scoped: &["Edit"],
175            note: "Claude scopes NotebookEdit through Edit(path), which also covers other built-in file edits at that path",
176        },
177    ),
178    (
179        "agent",
180        ScopedTools {
181            unscoped: &["Agent", "SendMessage", "ListAgents"],
182            scoped: &["Agent"],
183            note: "Claude's `Agent(type, ...)` limits which sub-agent types can be started; SendMessage and ListAgents take no scope",
184        },
185    ),
186    ("skill", Tools(&["Skill"])),
187    ("workflow", Tools(&["Workflow"])),
188    (
189        "glob",
190        ScopedTools {
191            unscoped: &["Glob"],
192            scoped: &["Read"],
193            note: "Claude scopes Glob paths through Read(path), which also covers other built-in file readers at that path",
194        },
195    ),
196    (
197        "grep",
198        ScopedTools {
199            unscoped: &["Grep"],
200            scoped: &["Read"],
201            note: "Claude scopes Grep paths through Read(path), which also covers other built-in file readers at that path",
202        },
203    ),
204    ("web", Tools(&["WebSearch", "WebFetch"])),
205    ("web_search", Tools(&["WebSearch"])),
206    ("web_fetch", Tools(&["WebFetch"])),
207    ("ask_user", Tools(&["AskUserQuestion"])),
208    // `TaskStop` stops background tasks; Meridian has always grouped it with the task list.
209    // `TaskOutput` was removed in 2.1.277: 2.1.307 lists it only among retired tool names and
210    // offers no such tool, and `--disallowedTools TaskOutput` there is silently ignored. It stays
211    // because older Claude builds still offer it and Meridian's platform rule denies it.
212    (
213        "task",
214        Tools(&[
215            "TaskCreate",
216            "TaskGet",
217            "TaskList",
218            "TaskOutput",
219            "TaskUpdate",
220            "TaskStop",
221            "TodoWrite",
222        ]),
223    ),
224    ("cron", Tools(&["CronCreate", "CronDelete", "CronList"])),
225    ("notifications", Tools(&["PushNotification"])),
226    ("plan_mode", Tools(&["EnterPlanMode", "ExitPlanMode"])),
227    ("worktree", Tools(&["EnterWorktree", "ExitWorktree"])),
228    ("lsp", Tools(&["LSP"])),
229    ("monitor", Tools(&["Monitor"])),
230    ("send_user_file", Tools(&["SendUserFile"])),
231    ("schedule_wakeup", Tools(&["ScheduleWakeup"])),
232    ("remote_trigger", Tools(&["RemoteTrigger"])),
233    ("tool_search", Tools(&["ToolSearch"])),
234    (
235        "image",
236        NoSwitch("claude views images through Read; no switch"),
237    ),
238];
239
240/// Codex 0.163.0.
241///
242/// Source: the 0.163.0 binary (`core/src/tools/handlers/*` and the tool names it registers).
243/// Shell execution is the unified `exec_command`. `write_stdin` only feeds a session
244/// `exec_command` opened, so `bash` names `exec_command` alone: Meridian gates Codex's shell
245/// with a switch, and denying `exec_command` leaves no session for `write_stdin` to feed.
246/// `agent` names both multi-agent tool sets the binary registers: v1
247/// (`multi_agents/`: spawn_agent, send_input, resume_agent, wait_agent, close_agent) and v2
248/// (`multi_agents_v2/`: spawn_agent, send_message, followup_task, wait_agent, interrupt_agent,
249/// list_agents); the model's `multi_agent_version` picks which one a session gets. Codex has no
250/// notebook tool. It has no file-read, glob or grep tool either, but it does all three through
251/// the shell (`NoSwitch`). `web` is Codex's hosted `web_search`, which also opens and searches
252/// within pages (`OpenPage`, `FindInPage` actions), so `web_fetch` has no tool of its own.
253/// `skill` loads by reading `SKILL.md`; the `skills.list` / `skills.read` tools of the skills
254/// extension are not something Mars can name. `update_plan` is the task list ("Updates the task
255/// plan.").
256pub(crate) const CODEX: Table = &[
257    ("bash", Tools(&["exec_command"])),
258    ("ls", Absent),
259    ("work", Absent),
260    (
261        "read",
262        NoSwitch("codex reads files through its shell; no switch"),
263    ),
264    ("write", Tools(&["apply_patch"])),
265    ("edit", Tools(&["apply_patch"])),
266    ("notebook", Absent),
267    (
268        "agent",
269        Tools(&[
270            "spawn_agent",
271            "send_input",
272            "resume_agent",
273            "wait_agent",
274            "close_agent",
275            "send_message",
276            "followup_task",
277            "interrupt_agent",
278            "list_agents",
279        ]),
280    ),
281    (
282        "skill",
283        NoSwitch("codex loads skills by reading files; no switch"),
284    ),
285    ("workflow", Absent),
286    (
287        "glob",
288        NoSwitch("codex finds files through its shell; no switch"),
289    ),
290    (
291        "grep",
292        NoSwitch("codex searches files through its shell; no switch"),
293    ),
294    ("web", Tools(&["web_search"])),
295    ("web_search", Tools(&["web_search"])),
296    (
297        "web_fetch",
298        NoSwitch("codex opens pages through hosted web_search; no separate switch"),
299    ),
300    ("ask_user", Tools(&["request_user_input"])),
301    ("task", Tools(&["update_plan"])),
302    ("cron", Absent),
303    ("notifications", Absent),
304    ("plan_mode", Absent),
305    ("worktree", Absent),
306    ("lsp", Absent),
307    ("monitor", Absent),
308    ("send_user_file", Absent),
309    ("schedule_wakeup", Absent),
310    ("remote_trigger", Absent),
311    ("tool_search", Tools(&["tool_search"])),
312    ("image", Tools(&["view_image"])),
313];
314
315/// OpenCode, in the v1.19.3 permission vocabulary. Meridian knows the running version and
316/// translates to v2 spellings (`bash` → `shell`, `task` → `subagent`, `write` → `edit`).
317/// Mars does the same for plugin agents in [`opencode_v2_action`], so keep the two in step.
318///
319/// Source: opencode.ai/docs/permissions, the provider tool lists captured from v1.19.3 and
320/// v2.0.29 (`opencode-matrix.md`), and strings from both binaries. `edit` is the permission
321/// that covers `edit`, `write` and `patch`, so `write` has no name of its own. The task list
322/// is `todowrite` alone: `todoread` is in neither binary. `plan_enter` / `plan_exit` are v1.19.3
323/// permissions (its agent defaults deny them); v2.0.29 has no such names, where a rule for
324/// them is inert. OpenCode has no notebook, cron, monitor or tool-search tool.
325pub(crate) const OPENCODE: Table = &[
326    ("bash", Tools(&["bash"])),
327    ("ls", Tools(&["list"])),
328    ("work", Absent),
329    ("read", Tools(&["read"])),
330    ("write", Tools(&["edit"])),
331    ("edit", Tools(&["edit"])),
332    ("notebook", Absent),
333    ("agent", Tools(&["task"])),
334    ("skill", Tools(&["skill"])),
335    ("workflow", Absent),
336    ("glob", Tools(&["glob"])),
337    ("grep", Tools(&["grep"])),
338    ("web", Tools(&["websearch", "webfetch"])),
339    ("web_search", Tools(&["websearch"])),
340    ("web_fetch", Tools(&["webfetch"])),
341    ("ask_user", Tools(&["question"])),
342    ("task", Tools(&["todowrite"])),
343    ("plan_mode", Tools(&["plan_enter", "plan_exit"])),
344    ("cron", Absent),
345    ("notifications", Absent),
346    ("worktree", Absent),
347    ("lsp", Tools(&["lsp"])),
348    ("monitor", Absent),
349    ("send_user_file", Absent),
350    ("schedule_wakeup", Absent),
351    ("remote_trigger", Absent),
352    ("tool_search", Absent),
353    (
354        "image",
355        NoSwitch("opencode views images through read; no switch"),
356    ),
357];
358
359/// The v2 spelling of a v1.19.3 OpenCode permission key, for a consumer that skips OpenCode's
360/// own agent-file loader (which does this translation): the plugin `ctx.agent` API takes v2
361/// rule actions. Keys v2 spells the same pass through.
362pub fn opencode_v2_action(v1: &str) -> &str {
363    match v1 {
364        "bash" => "shell",
365        "write" | "patch" => "edit",
366        "task" => "subagent",
367        other => other,
368    }
369}
370
371/// Pi 1.1.0 / 1.2.0, built-in tools only.
372///
373/// Source: `pi --help` and the installed package's tool registry
374/// (`dist/core/tools/index.js`: bash, edit, find, grep, ls, powershell, read, write). Pi
375/// grows by extensions, which Mars cannot see: `absent` means "no built-in tool", and
376/// Meridian's own extensions register tools (`bash_manage`) that no capability names. Pi's
377/// `edit` and `write` are separate tools, so the `edit` capability covers both. Pi has skills
378/// (`--skill`, `--no-skills`) but they load by reading `SKILL.md`, with no tool to switch
379/// (`NoSwitch`).
380pub(crate) const PI: Table = &[
381    ("bash", Tools(&["bash"])),
382    ("ls", Tools(&["ls"])),
383    ("work", Absent),
384    ("read", Tools(&["read"])),
385    ("write", Tools(&["write"])),
386    ("edit", Tools(&["edit", "write"])),
387    ("notebook", Absent),
388    ("agent", Absent),
389    (
390        "skill",
391        NoSwitch("pi loads skills by reading files; no switch"),
392    ),
393    ("workflow", Absent),
394    ("glob", Tools(&["find"])),
395    ("grep", Tools(&["grep"])),
396    ("web", Absent),
397    ("web_search", Absent),
398    ("web_fetch", Absent),
399    ("ask_user", Absent),
400    ("task", Absent),
401    ("plan_mode", Absent),
402    ("cron", Absent),
403    ("notifications", Absent),
404    ("worktree", Absent),
405    ("lsp", Absent),
406    ("monitor", Absent),
407    ("send_user_file", Absent),
408    ("schedule_wakeup", Absent),
409    ("remote_trigger", Absent),
410    ("tool_search", Absent),
411    ("image", NoSwitch("pi views images through read; no switch")),
412];
413
414/// Antigravity CLI (`agy`) 1.5.12.
415///
416/// Source: live probes of plugin agents. An agent's `tools` list loaded with `find_by_name`, `grep_search`,
417/// `list_dir`, `multi_replace_file_content`, `read_file`, `replace_file_content`,
418/// `run_command`, `search_web` and `write_to_file` together, and a shell call ran;
419/// `view_file` is the same tool as `read_file`: listing both
420/// fails. `browser_subagent`, `codebase_search`, `view_code_item` and `view_file_outline` did
421/// not resolve. One unknown name makes the agent fail at its first prompt, so a row holds only
422/// a name a probe loaded, and a tool nobody loaded is `Absent` here, which means "Mars knows
423/// no name to write", not "agy has no such tool". `agy` gives every agent every MCP server whatever
424/// `tools` says, and `call_mcp_tool` in `tools` fails the agent at its first prompt, so no name
425/// is written for MCP (`tool_project`). The subagent tool is
426/// `invoke_subagent` in permission requests, but no probe listed it in `tools`, so `agent` is
427/// `NoSwitch` until one does. `agy` loads a skill by reading its `SKILL.md` with `read_file`.
428pub(crate) const AGY: Table = &[
429    ("bash", Tools(&["run_command"])),
430    ("ls", Tools(&["list_dir"])),
431    ("work", Absent),
432    ("read", Tools(&["read_file"])),
433    ("write", Tools(&["write_to_file"])),
434    (
435        "edit",
436        Tools(&[
437            "replace_file_content",
438            "multi_replace_file_content",
439            "write_to_file",
440        ]),
441    ),
442    ("notebook", Absent),
443    (
444        "agent",
445        NoSwitch("agy's subagent tool (`invoke_subagent`) is not a verified `tools` name"),
446    ),
447    (
448        "skill",
449        NoSwitch("agy loads skills by reading files; no switch"),
450    ),
451    ("workflow", Absent),
452    ("glob", Tools(&["find_by_name"])),
453    ("grep", Tools(&["grep_search"])),
454    ("web", Tools(&["search_web"])),
455    ("web_search", Tools(&["search_web"])),
456    ("web_fetch", Absent),
457    ("ask_user", Absent),
458    ("task", Absent),
459    ("plan_mode", Absent),
460    ("cron", Absent),
461    ("notifications", Absent),
462    ("worktree", Absent),
463    ("lsp", Absent),
464    ("monitor", Absent),
465    ("send_user_file", Absent),
466    ("schedule_wakeup", Absent),
467    ("remote_trigger", Absent),
468    ("tool_search", Absent),
469    ("image", Absent),
470];
471
472/// Every native tool name Mars knows for `host`, sorted.
473pub fn every_tool(host: impl Into<Host>) -> Vec<&'static str> {
474    let mut names: Vec<&'static str> = host
475        .into()
476        .spec()
477        .tools
478        .iter()
479        .flat_map(|(_, native)| native.native_tools().iter().copied())
480        .collect();
481    names.sort_unstable();
482    names.dedup();
483    names
484}
485
486/// Flow's connection tools, which `mcp(...)` rules and MCP wire tokens lower onto. Flow has no
487/// per-server MCP tools: each of these takes the server as an argument. A connection tool Flow
488/// adds joins by being listed here.
489pub const FLOW_CONNECTION_TOOLS: &[&str] = &["mcp_describe", "mcp_call", "mcp_run"];
490
491/// Meridian Flow's own tools (mars-agents#207). Flow is a consumer, not a `HarnessId`, so
492/// its table lowers a policy for Flow to read but never a native file. Flow's
493/// tool keeps the capability's name, `ask_user`; `ask` is only a tool-policy action word. Flow
494/// ships no `glob` tool yet, so `glob` is absent. Flow's tool set is closed: every canonical
495/// capability has a row, `Absent` where Flow lacks the tool, so `unknown` on Flow only ever
496/// means a name Mars does not recognize.
497pub(crate) const FLOW: Table = &[
498    ("read", Tools(&["read"])),
499    ("write", Tools(&["write"])),
500    ("edit", Tools(&["write"])),
501    ("grep", Tools(&["grep"])),
502    ("glob", Absent),
503    ("ls", Tools(&["ls"])),
504    ("skill", Tools(&["skill"])),
505    ("ask_user", Tools(&["ask_user"])),
506    (
507        "agent",
508        Tools(&[
509            "spawn",
510            "thread_message",
511            "thread_report",
512            "thread_ls",
513            "thread_history",
514        ]),
515    ),
516    ("work", Tools(&["work"])),
517    ("bash", Absent),
518    ("task", Absent),
519    ("workflow", Absent),
520    ("notebook", Absent),
521    ("web", Absent),
522    ("web_search", Absent),
523    ("web_fetch", Absent),
524    ("cron", Absent),
525    ("notifications", Absent),
526    ("plan_mode", Absent),
527    ("worktree", Absent),
528    ("lsp", Absent),
529    ("monitor", Absent),
530    ("send_user_file", Absent),
531    ("schedule_wakeup", Absent),
532    ("remote_trigger", Absent),
533    ("tool_search", Absent),
534    ("image", Absent),
535];
536
537#[cfg(test)]
538mod tests {
539    use super::*;
540    use crate::HarnessId;
541
542    /// Every tool each harness ships, with where the list came from. A name in a table above
543    /// that is not here is a guess.
544    fn real_tools(harness: HarnessId) -> &'static [&'static str] {
545        match harness {
546            // Tools reference + 2.1.307 binary, plus `TaskOutput`: removed in 2.1.277, so 2.1.307
547            // no longer offers it, but older builds do (see the `task` row).
548            HarnessId::Claude => &[
549                "Agent",
550                "Artifact",
551                "AskUserQuestion",
552                "Bash",
553                "CronCreate",
554                "CronDelete",
555                "CronList",
556                "DesignSync",
557                "Edit",
558                "EndConversation",
559                "EnterPlanMode",
560                "EnterWorktree",
561                "ExitPlanMode",
562                "ExitWorktree",
563                "Glob",
564                "Grep",
565                "ListAgents",
566                "ListMcpResourcesTool",
567                "LSP",
568                "Monitor",
569                "NotebookEdit",
570                "PowerShell",
571                "PushNotification",
572                "Read",
573                "ReadMcpResourceTool",
574                "RemoteTrigger",
575                "ReportFindings",
576                "ScheduleWakeup",
577                "SendFeedback",
578                "SendMessage",
579                "SendUserFile",
580                "ShareOnboardingGuide",
581                "Skill",
582                "SubagentHandback",
583                "TaskCreate",
584                "TaskGet",
585                "TaskList",
586                "TaskOutput",
587                "TaskStop",
588                "TaskUpdate",
589                "TodoWrite",
590                "ToolSearch",
591                "WaitForMcpServers",
592                "WebFetch",
593                "WebSearch",
594                "Workflow",
595                "Write",
596            ],
597            // 0.163.0 binary: tool handlers (`core/src/tools/handlers/`) and registered tool
598            // names. Leaves out experimental and internal tools no capability names (`sleep`,
599            // `current_time`, `skills.list`, `skills.read`, memory and message-board tools).
600            HarnessId::Codex => &[
601                "apply_patch",
602                "close_agent",
603                "exec_command",
604                "followup_task",
605                "image_generation",
606                "interrupt_agent",
607                "js_repl",
608                "list_agents",
609                "list_mcp_resource_templates",
610                "list_mcp_resources",
611                "read_mcp_resource",
612                "request_permissions",
613                "request_user_input",
614                "resume_agent",
615                "send_input",
616                "send_message",
617                "spawn_agent",
618                "tool_search",
619                "update_plan",
620                "view_image",
621                "wait_agent",
622                "web_search",
623                "write_stdin",
624            ],
625            // v1 permission names: opencode.ai/docs/permissions, v1.19.3 / v2.0.29 captures and
626            // binaries.
627            HarnessId::OpenCode => &[
628                "bash",
629                "edit",
630                "glob",
631                "grep",
632                "list",
633                "lsp",
634                "plan_enter",
635                "plan_exit",
636                "question",
637                "read",
638                "skill",
639                "task",
640                "todowrite",
641                "webfetch",
642                "websearch",
643            ],
644            // Package `@earendil-works/pi-coding-agent` dist/core/tools/index.js.
645            HarnessId::Pi => &[
646                "bash",
647                "edit",
648                "find",
649                "grep",
650                "ls",
651                "powershell",
652                "read",
653                "write",
654            ],
655            // `agy` 1.5.12: the names the probes in the `AGY` doc comment loaded as agent tools.
656            HarnessId::Agy => &[
657                "find_by_name",
658                "grep_search",
659                "list_dir",
660                "multi_replace_file_content",
661                "read_file",
662                "replace_file_content",
663                "run_command",
664                "search_web",
665                "write_to_file",
666            ],
667        }
668    }
669
670    #[test]
671    fn every_native_name_and_native_tool_is_a_real_tool_of_its_harness() {
672        for &harness in crate::harness::ALL {
673            let real = real_tools(harness);
674            for (capability, native) in Host::Harness(harness).spec().tools {
675                let lists: &[&[&str]] = match native {
676                    Tools(names) => &[names],
677                    ScopedTools {
678                        unscoped, scoped, ..
679                    } => &[unscoped, scoped],
680                    Absent | NoSwitch(_) => &[],
681                };
682                for names in lists {
683                    assert!(
684                        !names.is_empty(),
685                        "{harness:?} `{capability}` names no tool"
686                    );
687                    for name in *names {
688                        assert!(
689                            real.contains(name),
690                            "{harness:?} `{capability}` maps to `{name}`, which is not in its real tool list"
691                        );
692                    }
693                }
694                assert!(
695                    native.native_tools().iter().all(|name| real.contains(name)),
696                    "{harness:?} `{capability}` has a native tool outside its real tool list"
697                );
698            }
699        }
700    }
701
702    #[test]
703    fn claude_scoped_file_rules_separate_permission_names_from_native_tools() {
704        for (capability, unscoped, scoped) in [
705            ("write", &["Write"][..], &["Edit"][..]),
706            (
707                "edit",
708                &["Edit", "Write", "NotebookEdit"][..],
709                &["Edit"][..],
710            ),
711            ("notebook", &["NotebookEdit"][..], &["Edit"][..]),
712            ("glob", &["Glob"][..], &["Read"][..]),
713            ("grep", &["Grep"][..], &["Read"][..]),
714        ] {
715            let Some(ScopedTools {
716                unscoped: actual_unscoped,
717                scoped: actual_scoped,
718                note,
719            }) = lookup(capability, HarnessId::Claude)
720            else {
721                panic!("Claude `{capability}` must distinguish bare and scoped rules");
722            };
723            assert_eq!(actual_unscoped, unscoped, "{capability} bare rule");
724            assert_eq!(actual_scoped, scoped, "{capability} scoped rule");
725            assert_eq!(
726                lookup(capability, HarnessId::Claude)
727                    .expect("row")
728                    .native_tools(),
729                unscoped,
730                "{capability} availability tools"
731            );
732            assert!(
733                !note.is_empty(),
734                "{capability} must explain the wider category"
735            );
736        }
737
738        assert_eq!(
739            lookup("web_fetch", HarnessId::Claude),
740            Some(Tools(&["WebFetch"]))
741        );
742    }
743
744    #[test]
745    fn every_row_is_a_canonical_capability_named_once() {
746        for &harness in crate::harness::ALL {
747            let mut seen = std::collections::HashSet::new();
748            for (capability, _) in Host::Harness(harness).spec().tools {
749                assert!(
750                    crate::tool_names::is_canonical_capability(capability),
751                    "{harness:?} has a row for `{capability}`, which is not a canonical capability"
752                );
753                assert!(
754                    seen.insert(*capability),
755                    "{harness:?} repeats `{capability}`"
756                );
757            }
758        }
759    }
760
761    #[test]
762    fn flow_answers_for_every_canonical_capability() {
763        for capability in crate::tool_names::canonical_capabilities() {
764            assert!(
765                lookup(capability, Host::MeridianFlow).is_some(),
766                "Flow has no row for `{capability}`"
767            );
768        }
769    }
770
771    #[test]
772    fn maintained_harnesses_answer_for_every_canonical_capability() {
773        // A missing row means Mars has not decided. The maintained harnesses decide every
774        // capability: tools, `Absent`, or `NoSwitch`.
775        for harness in [
776            HarnessId::Claude,
777            HarnessId::Codex,
778            HarnessId::OpenCode,
779            HarnessId::Pi,
780            HarnessId::Agy,
781        ] {
782            for capability in crate::tool_names::canonical_capabilities() {
783                assert!(
784                    lookup(capability, harness).is_some(),
785                    "{harness:?} has no row for `{capability}`"
786                );
787            }
788        }
789    }
790}