1use std::collections::BTreeMap;
18
19use serde::Serialize;
20
21use crate::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
60pub(crate) type Table = &'static [(&'static str, Native)];
61
62pub 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#[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#[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
117pub 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
135pub(crate) const CLAUDE: Table = &[
149 ("bash", Tools(&["Bash"])),
150 ("read", Tools(&["Read"])),
151 ("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 (
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
240pub(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
315pub(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
359pub 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
371pub(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
414pub(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
438pub(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
496pub 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
510pub const FLOW_CONNECTION_TOOLS: &[&str] = &["mcp_describe", "mcp_call", "mcp_run"];
514
515pub(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 fn real_tools(harness: HarnessId) -> &'static [&'static str] {
569 match harness {
570 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 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 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 HarnessId::Pi => &[
670 "bash",
671 "edit",
672 "find",
673 "grep",
674 "ls",
675 "powershell",
676 "read",
677 "write",
678 ],
679 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 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 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}