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/// Meridian Flow's own tools (mars-agents#207). Flow is a consumer, not a `HarnessId`, so
448/// its table lowers a policy for Flow to read but never a native file. Flow's
449/// tool keeps the capability's name, `ask_user`; `ask` is only a tool-policy action word. Flow
450/// ships no `glob` tool yet, so `glob` is absent. Flow's tool set is closed: every canonical
451/// capability has a row, `Absent` where Flow lacks the tool, so `unknown` on Flow only ever
452/// means a name Mars does not recognize.
453const FLOW: Table = &[
454    ("read", Tools(&["read"])),
455    ("write", Tools(&["write"])),
456    ("edit", Tools(&["write"])),
457    ("grep", Tools(&["grep"])),
458    ("glob", Absent),
459    ("ls", Tools(&["ls"])),
460    ("skill", Tools(&["skill"])),
461    ("ask_user", Tools(&["ask_user"])),
462    (
463        "agent",
464        Tools(&[
465            "spawn",
466            "thread_message",
467            "thread_report",
468            "thread_ls",
469            "thread_history",
470        ]),
471    ),
472    ("work", Tools(&["work"])),
473    ("bash", Absent),
474    ("task", Absent),
475    ("workflow", Absent),
476    ("notebook", Absent),
477    ("web", Absent),
478    ("web_search", Absent),
479    ("web_fetch", Absent),
480    ("cron", Absent),
481    ("notifications", Absent),
482    ("plan_mode", Absent),
483    ("worktree", Absent),
484    ("lsp", Absent),
485    ("monitor", Absent),
486    ("send_user_file", Absent),
487    ("schedule_wakeup", Absent),
488    ("remote_trigger", Absent),
489    ("tool_search", Absent),
490    ("image", Absent),
491];
492
493#[cfg(test)]
494mod tests {
495    use super::*;
496
497    /// Every tool each harness ships, with where the list came from. A name in a table above
498    /// that is not here is a guess.
499    fn real_tools(harness: HarnessId) -> &'static [&'static str] {
500        match harness {
501            // Tools reference + 2.1.307 binary, plus `TaskOutput`: removed in 2.1.277, so 2.1.307
502            // no longer offers it, but older builds do (see the `task` row).
503            HarnessId::Claude => &[
504                "Agent",
505                "Artifact",
506                "AskUserQuestion",
507                "Bash",
508                "CronCreate",
509                "CronDelete",
510                "CronList",
511                "DesignSync",
512                "Edit",
513                "EndConversation",
514                "EnterPlanMode",
515                "EnterWorktree",
516                "ExitPlanMode",
517                "ExitWorktree",
518                "Glob",
519                "Grep",
520                "ListAgents",
521                "ListMcpResourcesTool",
522                "LSP",
523                "Monitor",
524                "NotebookEdit",
525                "PowerShell",
526                "PushNotification",
527                "Read",
528                "ReadMcpResourceTool",
529                "RemoteTrigger",
530                "ReportFindings",
531                "ScheduleWakeup",
532                "SendFeedback",
533                "SendMessage",
534                "SendUserFile",
535                "ShareOnboardingGuide",
536                "Skill",
537                "SubagentHandback",
538                "TaskCreate",
539                "TaskGet",
540                "TaskList",
541                "TaskOutput",
542                "TaskStop",
543                "TaskUpdate",
544                "TodoWrite",
545                "ToolSearch",
546                "WaitForMcpServers",
547                "WebFetch",
548                "WebSearch",
549                "Workflow",
550                "Write",
551            ],
552            // 0.163.0 binary: tool handlers (`core/src/tools/handlers/`) and registered tool
553            // names. Leaves out experimental and internal tools no capability names (`sleep`,
554            // `current_time`, `skills.list`, `skills.read`, memory and message-board tools).
555            HarnessId::Codex => &[
556                "apply_patch",
557                "close_agent",
558                "exec_command",
559                "followup_task",
560                "image_generation",
561                "interrupt_agent",
562                "js_repl",
563                "list_agents",
564                "list_mcp_resource_templates",
565                "list_mcp_resources",
566                "read_mcp_resource",
567                "request_permissions",
568                "request_user_input",
569                "resume_agent",
570                "send_input",
571                "send_message",
572                "spawn_agent",
573                "tool_search",
574                "update_plan",
575                "view_image",
576                "wait_agent",
577                "web_search",
578                "write_stdin",
579            ],
580            // v1 permission names: opencode.ai/docs/permissions, v1.19.3 / v2.0.29 captures and
581            // binaries.
582            HarnessId::OpenCode => &[
583                "bash",
584                "edit",
585                "glob",
586                "grep",
587                "list",
588                "lsp",
589                "plan_enter",
590                "plan_exit",
591                "question",
592                "read",
593                "skill",
594                "task",
595                "todowrite",
596                "webfetch",
597                "websearch",
598            ],
599            // Package `@earendil-works/pi-coding-agent` dist/core/tools/index.js.
600            HarnessId::Pi => &[
601                "bash",
602                "edit",
603                "find",
604                "grep",
605                "ls",
606                "powershell",
607                "read",
608                "write",
609            ],
610            // Mars 0.16 table; not re-verified (target unmaintained).
611            HarnessId::Cursor => &[
612                "AskQuestion",
613                "EditNotebook",
614                "Glob",
615                "Grep",
616                "Read",
617                "Shell",
618                "Skill",
619                "StrReplace",
620                "SwitchMode",
621                "Task",
622                "TodoWrite",
623                "WebFetch",
624                "WebSearch",
625                "Write",
626            ],
627        }
628    }
629
630    #[test]
631    fn every_native_name_and_native_tool_is_a_real_tool_of_its_harness() {
632        for &harness in crate::harness::ALL {
633            let real = real_tools(harness);
634            for (capability, native) in table(Host::Harness(harness)) {
635                let lists: &[&[&str]] = match native {
636                    Tools(names) => &[names],
637                    ScopedTools {
638                        unscoped, scoped, ..
639                    } => &[unscoped, scoped],
640                    Absent | NoSwitch(_) => &[],
641                };
642                for names in lists {
643                    assert!(
644                        !names.is_empty(),
645                        "{harness:?} `{capability}` names no tool"
646                    );
647                    for name in *names {
648                        assert!(
649                            real.contains(name),
650                            "{harness:?} `{capability}` maps to `{name}`, which is not in its real tool list"
651                        );
652                    }
653                }
654                assert!(
655                    native.native_tools().iter().all(|name| real.contains(name)),
656                    "{harness:?} `{capability}` has a native tool outside its real tool list"
657                );
658            }
659        }
660    }
661
662    #[test]
663    fn claude_scoped_file_rules_separate_permission_names_from_native_tools() {
664        for (capability, unscoped, scoped) in [
665            ("write", &["Write"][..], &["Edit"][..]),
666            (
667                "edit",
668                &["Edit", "Write", "NotebookEdit"][..],
669                &["Edit"][..],
670            ),
671            ("notebook", &["NotebookEdit"][..], &["Edit"][..]),
672            ("glob", &["Glob"][..], &["Read"][..]),
673            ("grep", &["Grep"][..], &["Read"][..]),
674        ] {
675            let Some(ScopedTools {
676                unscoped: actual_unscoped,
677                scoped: actual_scoped,
678                note,
679            }) = lookup(capability, HarnessId::Claude)
680            else {
681                panic!("Claude `{capability}` must distinguish bare and scoped rules");
682            };
683            assert_eq!(actual_unscoped, unscoped, "{capability} bare rule");
684            assert_eq!(actual_scoped, scoped, "{capability} scoped rule");
685            assert_eq!(
686                lookup(capability, HarnessId::Claude)
687                    .expect("row")
688                    .native_tools(),
689                unscoped,
690                "{capability} availability tools"
691            );
692            assert!(
693                !note.is_empty(),
694                "{capability} must explain the wider category"
695            );
696        }
697
698        assert_eq!(
699            lookup("web_fetch", HarnessId::Claude),
700            Some(Tools(&["WebFetch"]))
701        );
702    }
703
704    #[test]
705    fn every_row_is_a_canonical_capability_named_once() {
706        for &harness in crate::harness::ALL {
707            let mut seen = std::collections::HashSet::new();
708            for (capability, _) in table(Host::Harness(harness)) {
709                assert!(
710                    crate::tool_names::is_canonical_capability(capability),
711                    "{harness:?} has a row for `{capability}`, which is not a canonical capability"
712                );
713                assert!(
714                    seen.insert(*capability),
715                    "{harness:?} repeats `{capability}`"
716                );
717            }
718        }
719    }
720
721    #[test]
722    fn flow_answers_for_every_canonical_capability() {
723        for capability in crate::tool_names::canonical_capabilities() {
724            assert!(
725                lookup(capability, Host::MeridianFlow).is_some(),
726                "Flow has no row for `{capability}`"
727            );
728        }
729    }
730
731    #[test]
732    fn maintained_harnesses_answer_for_every_canonical_capability() {
733        // A missing row means Mars has not decided. The maintained harnesses decide every
734        // capability: tools, `Absent`, or `NoSwitch`.
735        for harness in [
736            HarnessId::Claude,
737            HarnessId::Codex,
738            HarnessId::OpenCode,
739            HarnessId::Pi,
740        ] {
741            for capability in crate::tool_names::canonical_capabilities() {
742                assert!(
743                    lookup(capability, harness).is_some(),
744                    "{harness:?} has no row for `{capability}`"
745                );
746            }
747        }
748    }
749}