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