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 AGY: Table = &[
429 ("bash", Tools(&["run_command"])),
430 ("ls", Tools(&["list_dir"])),
431 ("work", Absent),
432 ("read", Tools(&["read_file"])),
433 ("write", Tools(&["write_to_file"])),
434 (
435 "edit",
436 Tools(&[
437 "replace_file_content",
438 "multi_replace_file_content",
439 "write_to_file",
440 ]),
441 ),
442 ("notebook", Absent),
443 (
444 "agent",
445 NoSwitch("agy's subagent tool (`invoke_subagent`) is not a verified `tools` name"),
446 ),
447 (
448 "skill",
449 NoSwitch("agy loads skills by reading files; no switch"),
450 ),
451 ("workflow", Absent),
452 ("glob", Tools(&["find_by_name"])),
453 ("grep", Tools(&["grep_search"])),
454 ("web", Tools(&["search_web"])),
455 ("web_search", Tools(&["search_web"])),
456 ("web_fetch", Absent),
457 ("ask_user", Absent),
458 ("task", Absent),
459 ("plan_mode", Absent),
460 ("cron", Absent),
461 ("notifications", Absent),
462 ("worktree", Absent),
463 ("lsp", Absent),
464 ("monitor", Absent),
465 ("send_user_file", Absent),
466 ("schedule_wakeup", Absent),
467 ("remote_trigger", Absent),
468 ("tool_search", Absent),
469 ("image", Absent),
470];
471
472pub fn every_tool(host: impl Into<Host>) -> Vec<&'static str> {
474 let mut names: Vec<&'static str> = host
475 .into()
476 .spec()
477 .tools
478 .iter()
479 .flat_map(|(_, native)| native.native_tools().iter().copied())
480 .collect();
481 names.sort_unstable();
482 names.dedup();
483 names
484}
485
486pub const FLOW_CONNECTION_TOOLS: &[&str] = &["mcp_describe", "mcp_call", "mcp_run"];
490
491pub(crate) const FLOW: Table = &[
498 ("read", Tools(&["read"])),
499 ("write", Tools(&["write"])),
500 ("edit", Tools(&["write"])),
501 ("grep", Tools(&["grep"])),
502 ("glob", Absent),
503 ("ls", Tools(&["ls"])),
504 ("skill", Tools(&["skill"])),
505 ("ask_user", Tools(&["ask_user"])),
506 (
507 "agent",
508 Tools(&[
509 "spawn",
510 "thread_message",
511 "thread_report",
512 "thread_ls",
513 "thread_history",
514 ]),
515 ),
516 ("work", Tools(&["work"])),
517 ("bash", Absent),
518 ("task", Absent),
519 ("workflow", Absent),
520 ("notebook", Absent),
521 ("web", Absent),
522 ("web_search", Absent),
523 ("web_fetch", Absent),
524 ("cron", Absent),
525 ("notifications", Absent),
526 ("plan_mode", Absent),
527 ("worktree", Absent),
528 ("lsp", Absent),
529 ("monitor", Absent),
530 ("send_user_file", Absent),
531 ("schedule_wakeup", Absent),
532 ("remote_trigger", Absent),
533 ("tool_search", Absent),
534 ("image", Absent),
535];
536
537#[cfg(test)]
538mod tests {
539 use super::*;
540 use crate::HarnessId;
541
542 fn real_tools(harness: HarnessId) -> &'static [&'static str] {
545 match harness {
546 HarnessId::Claude => &[
549 "Agent",
550 "Artifact",
551 "AskUserQuestion",
552 "Bash",
553 "CronCreate",
554 "CronDelete",
555 "CronList",
556 "DesignSync",
557 "Edit",
558 "EndConversation",
559 "EnterPlanMode",
560 "EnterWorktree",
561 "ExitPlanMode",
562 "ExitWorktree",
563 "Glob",
564 "Grep",
565 "ListAgents",
566 "ListMcpResourcesTool",
567 "LSP",
568 "Monitor",
569 "NotebookEdit",
570 "PowerShell",
571 "PushNotification",
572 "Read",
573 "ReadMcpResourceTool",
574 "RemoteTrigger",
575 "ReportFindings",
576 "ScheduleWakeup",
577 "SendFeedback",
578 "SendMessage",
579 "SendUserFile",
580 "ShareOnboardingGuide",
581 "Skill",
582 "SubagentHandback",
583 "TaskCreate",
584 "TaskGet",
585 "TaskList",
586 "TaskOutput",
587 "TaskStop",
588 "TaskUpdate",
589 "TodoWrite",
590 "ToolSearch",
591 "WaitForMcpServers",
592 "WebFetch",
593 "WebSearch",
594 "Workflow",
595 "Write",
596 ],
597 HarnessId::Codex => &[
601 "apply_patch",
602 "close_agent",
603 "exec_command",
604 "followup_task",
605 "image_generation",
606 "interrupt_agent",
607 "js_repl",
608 "list_agents",
609 "list_mcp_resource_templates",
610 "list_mcp_resources",
611 "read_mcp_resource",
612 "request_permissions",
613 "request_user_input",
614 "resume_agent",
615 "send_input",
616 "send_message",
617 "spawn_agent",
618 "tool_search",
619 "update_plan",
620 "view_image",
621 "wait_agent",
622 "web_search",
623 "write_stdin",
624 ],
625 HarnessId::OpenCode => &[
628 "bash",
629 "edit",
630 "glob",
631 "grep",
632 "list",
633 "lsp",
634 "plan_enter",
635 "plan_exit",
636 "question",
637 "read",
638 "skill",
639 "task",
640 "todowrite",
641 "webfetch",
642 "websearch",
643 ],
644 HarnessId::Pi => &[
646 "bash",
647 "edit",
648 "find",
649 "grep",
650 "ls",
651 "powershell",
652 "read",
653 "write",
654 ],
655 HarnessId::Agy => &[
657 "find_by_name",
658 "grep_search",
659 "list_dir",
660 "multi_replace_file_content",
661 "read_file",
662 "replace_file_content",
663 "run_command",
664 "search_web",
665 "write_to_file",
666 ],
667 }
668 }
669
670 #[test]
671 fn every_native_name_and_native_tool_is_a_real_tool_of_its_harness() {
672 for &harness in crate::harness::ALL {
673 let real = real_tools(harness);
674 for (capability, native) in Host::Harness(harness).spec().tools {
675 let lists: &[&[&str]] = match native {
676 Tools(names) => &[names],
677 ScopedTools {
678 unscoped, scoped, ..
679 } => &[unscoped, scoped],
680 Absent | NoSwitch(_) => &[],
681 };
682 for names in lists {
683 assert!(
684 !names.is_empty(),
685 "{harness:?} `{capability}` names no tool"
686 );
687 for name in *names {
688 assert!(
689 real.contains(name),
690 "{harness:?} `{capability}` maps to `{name}`, which is not in its real tool list"
691 );
692 }
693 }
694 assert!(
695 native.native_tools().iter().all(|name| real.contains(name)),
696 "{harness:?} `{capability}` has a native tool outside its real tool list"
697 );
698 }
699 }
700 }
701
702 #[test]
703 fn claude_scoped_file_rules_separate_permission_names_from_native_tools() {
704 for (capability, unscoped, scoped) in [
705 ("write", &["Write"][..], &["Edit"][..]),
706 (
707 "edit",
708 &["Edit", "Write", "NotebookEdit"][..],
709 &["Edit"][..],
710 ),
711 ("notebook", &["NotebookEdit"][..], &["Edit"][..]),
712 ("glob", &["Glob"][..], &["Read"][..]),
713 ("grep", &["Grep"][..], &["Read"][..]),
714 ] {
715 let Some(ScopedTools {
716 unscoped: actual_unscoped,
717 scoped: actual_scoped,
718 note,
719 }) = lookup(capability, HarnessId::Claude)
720 else {
721 panic!("Claude `{capability}` must distinguish bare and scoped rules");
722 };
723 assert_eq!(actual_unscoped, unscoped, "{capability} bare rule");
724 assert_eq!(actual_scoped, scoped, "{capability} scoped rule");
725 assert_eq!(
726 lookup(capability, HarnessId::Claude)
727 .expect("row")
728 .native_tools(),
729 unscoped,
730 "{capability} availability tools"
731 );
732 assert!(
733 !note.is_empty(),
734 "{capability} must explain the wider category"
735 );
736 }
737
738 assert_eq!(
739 lookup("web_fetch", HarnessId::Claude),
740 Some(Tools(&["WebFetch"]))
741 );
742 }
743
744 #[test]
745 fn every_row_is_a_canonical_capability_named_once() {
746 for &harness in crate::harness::ALL {
747 let mut seen = std::collections::HashSet::new();
748 for (capability, _) in Host::Harness(harness).spec().tools {
749 assert!(
750 crate::tool_names::is_canonical_capability(capability),
751 "{harness:?} has a row for `{capability}`, which is not a canonical capability"
752 );
753 assert!(
754 seen.insert(*capability),
755 "{harness:?} repeats `{capability}`"
756 );
757 }
758 }
759 }
760
761 #[test]
762 fn flow_answers_for_every_canonical_capability() {
763 for capability in crate::tool_names::canonical_capabilities() {
764 assert!(
765 lookup(capability, Host::MeridianFlow).is_some(),
766 "Flow has no row for `{capability}`"
767 );
768 }
769 }
770
771 #[test]
772 fn maintained_harnesses_answer_for_every_canonical_capability() {
773 for harness in [
776 HarnessId::Claude,
777 HarnessId::Codex,
778 HarnessId::OpenCode,
779 HarnessId::Pi,
780 HarnessId::Agy,
781 ] {
782 for capability in crate::tool_names::canonical_capabilities() {
783 assert!(
784 lookup(capability, harness).is_some(),
785 "{harness:?} has no row for `{capability}`"
786 );
787 }
788 }
789 }
790}