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/// Cursor. Unmaintained: these rows are carried over unchanged from Mars 0.16's
415/// overrides and PascalCase convention, not re-verified against a current Cursor. Cursor
416/// `edit` has always named only `StrReplace`, so it does not cover `Write`. Anything the old
417/// convention guessed beyond these rows is now `unknown`.
418pub(crate) const CURSOR: Table = &[
419    ("bash", Tools(&["Shell"])),
420    ("ls", Absent),
421    ("work", Absent),
422    ("read", Tools(&["Read"])),
423    ("write", Tools(&["Write"])),
424    ("edit", Tools(&["StrReplace"])),
425    ("notebook", Tools(&["EditNotebook"])),
426    ("agent", Tools(&["Task"])),
427    ("skill", Tools(&["Skill"])),
428    ("glob", Tools(&["Glob"])),
429    ("grep", Tools(&["Grep"])),
430    ("web", Tools(&["WebSearch", "WebFetch"])),
431    ("web_search", Tools(&["WebSearch"])),
432    ("web_fetch", Tools(&["WebFetch"])),
433    ("ask_user", Tools(&["AskQuestion"])),
434    ("task", Tools(&["TodoWrite"])),
435    ("plan_mode", Tools(&["SwitchMode"])),
436];
437
438/// Antigravity CLI (`agy`) 1.5.12.
439///
440/// Source: live probes of plugin agents. An agent's `tools` list loaded with `find_by_name`, `grep_search`,
441/// `list_dir`, `multi_replace_file_content`, `read_file`, `replace_file_content`,
442/// `run_command`, `search_web` and `write_to_file` together, and a shell call ran;
443/// `view_file` is the same tool as `read_file`: listing both
444/// fails. `browser_subagent`, `codebase_search`, `view_code_item` and `view_file_outline` did
445/// not resolve. One unknown name makes the agent fail at its first prompt, so a row holds only
446/// a name a probe loaded, and a tool nobody loaded is `Absent` here, which means "Mars knows
447/// no name to write", not "agy has no such tool". `agy` gives every agent every MCP server whatever
448/// `tools` says, and `call_mcp_tool` in `tools` fails the agent at its first prompt, so no name
449/// is written for MCP (`tool_project`). The subagent tool is
450/// `invoke_subagent` in permission requests, but no probe listed it in `tools`, so `agent` is
451/// `NoSwitch` until one does. `agy` loads a skill by reading its `SKILL.md` with `read_file`.
452pub(crate) const AGY: Table = &[
453    ("bash", Tools(&["run_command"])),
454    ("ls", Tools(&["list_dir"])),
455    ("work", Absent),
456    ("read", Tools(&["read_file"])),
457    ("write", Tools(&["write_to_file"])),
458    (
459        "edit",
460        Tools(&[
461            "replace_file_content",
462            "multi_replace_file_content",
463            "write_to_file",
464        ]),
465    ),
466    ("notebook", Absent),
467    (
468        "agent",
469        NoSwitch("agy's subagent tool (`invoke_subagent`) is not a verified `tools` name"),
470    ),
471    (
472        "skill",
473        NoSwitch("agy loads skills by reading files; no switch"),
474    ),
475    ("workflow", Absent),
476    ("glob", Tools(&["find_by_name"])),
477    ("grep", Tools(&["grep_search"])),
478    ("web", Tools(&["search_web"])),
479    ("web_search", Tools(&["search_web"])),
480    ("web_fetch", Absent),
481    ("ask_user", Absent),
482    ("task", Absent),
483    ("plan_mode", Absent),
484    ("cron", Absent),
485    ("notifications", Absent),
486    ("worktree", Absent),
487    ("lsp", Absent),
488    ("monitor", Absent),
489    ("send_user_file", Absent),
490    ("schedule_wakeup", Absent),
491    ("remote_trigger", Absent),
492    ("tool_search", Absent),
493    ("image", Absent),
494];
495
496/// Every native tool name Mars knows for `host`, sorted.
497pub fn every_tool(host: impl Into<Host>) -> Vec<&'static str> {
498    let mut names: Vec<&'static str> = host
499        .into()
500        .spec()
501        .tools
502        .iter()
503        .flat_map(|(_, native)| native.native_tools().iter().copied())
504        .collect();
505    names.sort_unstable();
506    names.dedup();
507    names
508}
509
510/// Flow's connection tools, which `mcp(...)` rules and MCP wire tokens lower onto. Flow has no
511/// per-server MCP tools: each of these takes the server as an argument. A connection tool Flow
512/// adds joins by being listed here.
513pub const FLOW_CONNECTION_TOOLS: &[&str] = &["mcp_describe", "mcp_call", "mcp_run"];
514
515/// Meridian Flow's own tools (mars-agents#207). Flow is a consumer, not a `HarnessId`, so
516/// its table lowers a policy for Flow to read but never a native file. Flow's
517/// tool keeps the capability's name, `ask_user`; `ask` is only a tool-policy action word. Flow
518/// ships no `glob` tool yet, so `glob` is absent. Flow's tool set is closed: every canonical
519/// capability has a row, `Absent` where Flow lacks the tool, so `unknown` on Flow only ever
520/// means a name Mars does not recognize.
521pub(crate) const FLOW: Table = &[
522    ("read", Tools(&["read"])),
523    ("write", Tools(&["write"])),
524    ("edit", Tools(&["write"])),
525    ("grep", Tools(&["grep"])),
526    ("glob", Absent),
527    ("ls", Tools(&["ls"])),
528    ("skill", Tools(&["skill"])),
529    ("ask_user", Tools(&["ask_user"])),
530    (
531        "agent",
532        Tools(&[
533            "spawn",
534            "thread_message",
535            "thread_report",
536            "thread_ls",
537            "thread_history",
538        ]),
539    ),
540    ("work", Tools(&["work"])),
541    ("bash", Absent),
542    ("task", Absent),
543    ("workflow", Absent),
544    ("notebook", Absent),
545    ("web", Absent),
546    ("web_search", Absent),
547    ("web_fetch", Absent),
548    ("cron", Absent),
549    ("notifications", Absent),
550    ("plan_mode", Absent),
551    ("worktree", Absent),
552    ("lsp", Absent),
553    ("monitor", Absent),
554    ("send_user_file", Absent),
555    ("schedule_wakeup", Absent),
556    ("remote_trigger", Absent),
557    ("tool_search", Absent),
558    ("image", Absent),
559];
560
561#[cfg(test)]
562mod tests {
563    use super::*;
564    use crate::HarnessId;
565
566    /// Every tool each harness ships, with where the list came from. A name in a table above
567    /// that is not here is a guess.
568    fn real_tools(harness: HarnessId) -> &'static [&'static str] {
569        match harness {
570            // Tools reference + 2.1.307 binary, plus `TaskOutput`: removed in 2.1.277, so 2.1.307
571            // no longer offers it, but older builds do (see the `task` row).
572            HarnessId::Claude => &[
573                "Agent",
574                "Artifact",
575                "AskUserQuestion",
576                "Bash",
577                "CronCreate",
578                "CronDelete",
579                "CronList",
580                "DesignSync",
581                "Edit",
582                "EndConversation",
583                "EnterPlanMode",
584                "EnterWorktree",
585                "ExitPlanMode",
586                "ExitWorktree",
587                "Glob",
588                "Grep",
589                "ListAgents",
590                "ListMcpResourcesTool",
591                "LSP",
592                "Monitor",
593                "NotebookEdit",
594                "PowerShell",
595                "PushNotification",
596                "Read",
597                "ReadMcpResourceTool",
598                "RemoteTrigger",
599                "ReportFindings",
600                "ScheduleWakeup",
601                "SendFeedback",
602                "SendMessage",
603                "SendUserFile",
604                "ShareOnboardingGuide",
605                "Skill",
606                "SubagentHandback",
607                "TaskCreate",
608                "TaskGet",
609                "TaskList",
610                "TaskOutput",
611                "TaskStop",
612                "TaskUpdate",
613                "TodoWrite",
614                "ToolSearch",
615                "WaitForMcpServers",
616                "WebFetch",
617                "WebSearch",
618                "Workflow",
619                "Write",
620            ],
621            // 0.163.0 binary: tool handlers (`core/src/tools/handlers/`) and registered tool
622            // names. Leaves out experimental and internal tools no capability names (`sleep`,
623            // `current_time`, `skills.list`, `skills.read`, memory and message-board tools).
624            HarnessId::Codex => &[
625                "apply_patch",
626                "close_agent",
627                "exec_command",
628                "followup_task",
629                "image_generation",
630                "interrupt_agent",
631                "js_repl",
632                "list_agents",
633                "list_mcp_resource_templates",
634                "list_mcp_resources",
635                "read_mcp_resource",
636                "request_permissions",
637                "request_user_input",
638                "resume_agent",
639                "send_input",
640                "send_message",
641                "spawn_agent",
642                "tool_search",
643                "update_plan",
644                "view_image",
645                "wait_agent",
646                "web_search",
647                "write_stdin",
648            ],
649            // v1 permission names: opencode.ai/docs/permissions, v1.19.3 / v2.0.29 captures and
650            // binaries.
651            HarnessId::OpenCode => &[
652                "bash",
653                "edit",
654                "glob",
655                "grep",
656                "list",
657                "lsp",
658                "plan_enter",
659                "plan_exit",
660                "question",
661                "read",
662                "skill",
663                "task",
664                "todowrite",
665                "webfetch",
666                "websearch",
667            ],
668            // Package `@earendil-works/pi-coding-agent` dist/core/tools/index.js.
669            HarnessId::Pi => &[
670                "bash",
671                "edit",
672                "find",
673                "grep",
674                "ls",
675                "powershell",
676                "read",
677                "write",
678            ],
679            // `agy` 1.5.12: the names the probes in the `AGY` doc comment loaded as agent tools.
680            HarnessId::Agy => &[
681                "find_by_name",
682                "grep_search",
683                "list_dir",
684                "multi_replace_file_content",
685                "read_file",
686                "replace_file_content",
687                "run_command",
688                "search_web",
689                "write_to_file",
690            ],
691            // Mars 0.16 table; not re-verified (target unmaintained).
692            HarnessId::Cursor => &[
693                "AskQuestion",
694                "EditNotebook",
695                "Glob",
696                "Grep",
697                "Read",
698                "Shell",
699                "Skill",
700                "StrReplace",
701                "SwitchMode",
702                "Task",
703                "TodoWrite",
704                "WebFetch",
705                "WebSearch",
706                "Write",
707            ],
708        }
709    }
710
711    #[test]
712    fn every_native_name_and_native_tool_is_a_real_tool_of_its_harness() {
713        for &harness in crate::harness::ALL {
714            let real = real_tools(harness);
715            for (capability, native) in Host::Harness(harness).spec().tools {
716                let lists: &[&[&str]] = match native {
717                    Tools(names) => &[names],
718                    ScopedTools {
719                        unscoped, scoped, ..
720                    } => &[unscoped, scoped],
721                    Absent | NoSwitch(_) => &[],
722                };
723                for names in lists {
724                    assert!(
725                        !names.is_empty(),
726                        "{harness:?} `{capability}` names no tool"
727                    );
728                    for name in *names {
729                        assert!(
730                            real.contains(name),
731                            "{harness:?} `{capability}` maps to `{name}`, which is not in its real tool list"
732                        );
733                    }
734                }
735                assert!(
736                    native.native_tools().iter().all(|name| real.contains(name)),
737                    "{harness:?} `{capability}` has a native tool outside its real tool list"
738                );
739            }
740        }
741    }
742
743    #[test]
744    fn claude_scoped_file_rules_separate_permission_names_from_native_tools() {
745        for (capability, unscoped, scoped) in [
746            ("write", &["Write"][..], &["Edit"][..]),
747            (
748                "edit",
749                &["Edit", "Write", "NotebookEdit"][..],
750                &["Edit"][..],
751            ),
752            ("notebook", &["NotebookEdit"][..], &["Edit"][..]),
753            ("glob", &["Glob"][..], &["Read"][..]),
754            ("grep", &["Grep"][..], &["Read"][..]),
755        ] {
756            let Some(ScopedTools {
757                unscoped: actual_unscoped,
758                scoped: actual_scoped,
759                note,
760            }) = lookup(capability, HarnessId::Claude)
761            else {
762                panic!("Claude `{capability}` must distinguish bare and scoped rules");
763            };
764            assert_eq!(actual_unscoped, unscoped, "{capability} bare rule");
765            assert_eq!(actual_scoped, scoped, "{capability} scoped rule");
766            assert_eq!(
767                lookup(capability, HarnessId::Claude)
768                    .expect("row")
769                    .native_tools(),
770                unscoped,
771                "{capability} availability tools"
772            );
773            assert!(
774                !note.is_empty(),
775                "{capability} must explain the wider category"
776            );
777        }
778
779        assert_eq!(
780            lookup("web_fetch", HarnessId::Claude),
781            Some(Tools(&["WebFetch"]))
782        );
783    }
784
785    #[test]
786    fn every_row_is_a_canonical_capability_named_once() {
787        for &harness in crate::harness::ALL {
788            let mut seen = std::collections::HashSet::new();
789            for (capability, _) in Host::Harness(harness).spec().tools {
790                assert!(
791                    crate::tool_names::is_canonical_capability(capability),
792                    "{harness:?} has a row for `{capability}`, which is not a canonical capability"
793                );
794                assert!(
795                    seen.insert(*capability),
796                    "{harness:?} repeats `{capability}`"
797                );
798            }
799        }
800    }
801
802    #[test]
803    fn flow_answers_for_every_canonical_capability() {
804        for capability in crate::tool_names::canonical_capabilities() {
805            assert!(
806                lookup(capability, Host::MeridianFlow).is_some(),
807                "Flow has no row for `{capability}`"
808            );
809        }
810    }
811
812    #[test]
813    fn maintained_harnesses_answer_for_every_canonical_capability() {
814        // A missing row means Mars has not decided. The maintained harnesses decide every
815        // capability: tools, `Absent`, or `NoSwitch`.
816        for harness in [
817            HarnessId::Claude,
818            HarnessId::Codex,
819            HarnessId::OpenCode,
820            HarnessId::Pi,
821            HarnessId::Agy,
822        ] {
823            for capability in crate::tool_names::canonical_capabilities() {
824                assert!(
825                    lookup(capability, harness).is_some(),
826                    "{harness:?} has no row for `{capability}`"
827                );
828            }
829        }
830    }
831}