1use std::collections::BTreeMap;
18
19use serde::Serialize;
20
21use crate::{HarnessId, Host};
22
23#[derive(Clone, Copy, Debug, PartialEq, Eq)]
25pub enum Native {
26 Tools(&'static [&'static str]),
28 ScopedTools {
32 unscoped: &'static [&'static str],
33 scoped: &'static [&'static str],
34 note: &'static str,
35 },
36 Absent,
38 NoSwitch(&'static str),
42}
43
44impl Native {
45 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
62pub 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#[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#[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
115pub 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
144const CLAUDE: Table = &[
158 ("bash", Tools(&["Bash"])),
159 ("read", Tools(&["Read"])),
160 ("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 (
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
249const 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
324const 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
368pub 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
380const 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
423const 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
447pub const FLOW_CONNECTION_TOOLS: &[&str] = &["mcp_describe", "mcp_call", "mcp_run"];
451
452const 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 fn real_tools(harness: HarnessId) -> &'static [&'static str] {
505 match harness {
506 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 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 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 HarnessId::Pi => &[
606 "bash",
607 "edit",
608 "find",
609 "grep",
610 "ls",
611 "powershell",
612 "read",
613 "write",
614 ],
615 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 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}