Files
gabrielvidalandClaude Opus 5.5 d7758d3bf5 feat(parse): the neutral tool-name table + ThreadItem.native in the API schema
readers/toolnames.py: the ~17 cross-harness names (shell, read, edit,
agent, todo…), Claude Code's names mapped onto them, the opencode
mirror's own names, the harness-namespaced rest (claude:CronCreate,
opencode:execute, agy:manage_task; a lowercase name in an unstamped legacy
file is pi's), MCP names untouched. Not wired into the readers yet.

ThreadItem gains `native` (the harness's own name when it differs);
openapi.json + the generated types re-dumped.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-24 17:41:13 +01:00

94 lines
3.8 KiB
Python

"""Neutral tool names — what a reader puts in a ``tool_call`` event's
``tool``; the harness's own name rides in ``native``
(``docs/transcript-format.md``, "Tool names").
About 17 tools mean the same thing on every harness and get a neutral name
(``CORE``). Every other tool keeps its own name behind its harness id
(``claude:CronCreate``, ``opencode:execute``, ``agy:manage_task``), and an MCP
tool keeps its ``mcp__server__tool`` name. The fold, the cost buckets and the
resource / lifecycle / deploy / worktree detection key on these names only.
The table below is Claude Code's vocabulary — and so also that of the pi /
opencode / agy transcripts the hub's converters wrote *disguised as Claude
Code* before v1 (``legacy.py``): their tools were renamed to Claude Code's on
the way in, so they map through the same table, under their own harness id
when it is stamped on the records."""
# The cross-harness vocabulary.
CORE = (
"shell", "shell_output", "shell_kill",
"read", "write", "edit", "apply_patch", "delete_file",
"grep", "glob", "list_dir",
"web_fetch", "web_search",
"agent", "skill", "todo", "ask_user",
)
# Claude Code's name → the neutral one.
CLAUDE = {
"Bash": "shell",
"BashOutput": "shell_output", "TaskOutput": "shell_output",
"KillShell": "shell_kill", "TaskStop": "shell_kill",
"Read": "read", "NotebookRead": "read",
"Write": "write",
"Edit": "edit", "MultiEdit": "edit", "NotebookEdit": "edit",
"Grep": "grep", "Glob": "glob", "LS": "list_dir",
"WebFetch": "web_fetch", "WebSearch": "web_search",
"Agent": "agent", "Task": "agent",
"Skill": "skill",
"TodoWrite": "todo", "TaskCreate": "todo", "TaskUpdate": "todo",
"TaskGet": "todo", "TaskList": "todo",
"AskUserQuestion": "ask_user",
}
# Names the opencode mirror invented for what Claude Code has no tool for: a
# patch it could not split per file, a file a patch deleted.
LEGACY = {"ApplyPatch": "apply_patch", "DeleteFile": "delete_file"}
# A harness's own tool the legacy converter renamed to a Claude-Code-looking
# name: the tool's real (native) name, which its namespaced name is built on.
LEGACY_OWN = {"opencode": {"Execute": "execute"}}
# The names the hub's own code used before the neutral ones (parser v44 and
# older) — for consumers that may still meet them: an older hub's API, a
# worker's older CLI, a summary not re-indexed yet.
OLD_BUCKETS = {"bash": "shell", "task": "todo"}
def is_mcp(name: str) -> bool:
"""An MCP tool: ``mcp__server__tool`` (Claude Code, opencode, agy's
``call_mcp_tool``) or agy's own ``mcp_server_tool`` spelling."""
return name.startswith("mcp_")
def namespaced(harness: str, name: str) -> str:
"""``harness:name`` — a tool only that harness has."""
return f"{harness}:{name}"
def claude_name(name, harness: str | None = None):
"""The neutral name of a tool a Claude-Code-format record names.
``harness``: the harness the record says wrote it (``entrypoint``:
``opencode``, ``agy``), None for Claude Code's own records — and for pi's
runner, which stamps none: a lowercase name there is pi's (Claude Code's
own tools are PascalCase, MCP tools start ``mcp_``)."""
if not isinstance(name, str) or not name:
return name
n = CLAUDE.get(name) or LEGACY.get(name)
if n is not None:
return n
if is_mcp(name):
return name
if harness is None:
harness = "pi" if name[:1].islower() else "claude"
return namespaced(harness, LEGACY_OWN.get(harness, {}).get(name, name))
def display_name(name: str | None) -> str:
"""A namespaced name without its harness id (``claude:CronCreate`` →
``CronCreate``), for text meant for people."""
if not name:
return ""
head, sep, rest = name.partition(":")
return rest if sep and head.isidentifier() and not is_mcp(name) else name