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
447const 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 fn real_tools(harness: HarnessId) -> &'static [&'static str] {
500 match harness {
501 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 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 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 HarnessId::Pi => &[
601 "bash",
602 "edit",
603 "find",
604 "grep",
605 "ls",
606 "powershell",
607 "read",
608 "write",
609 ],
610 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 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}