- an older mirror's agy:update_steps {steps} is read as a todo snapshot
(done→completed, skipped/cancelled/canceled→cancelled, else pending)
- task_done notes found by toolUseId or taskIds fold into a card started by
data.taskId (exit code, failed, still-running events, the stop notice)
- a successful manage_task kill stops its task's card
- PARSER_VERSION 48 so past agy conversations get their tasks
- docs: transcript-format (agy column, agy's tasks), CLAUDE.md
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
125 lines
5.2 KiB
Python
125 lines
5.2 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))
|
|
|
|
|
|
# agy's plan steps (`update_steps {steps: [{title, status}]}`) are its
|
|
# TodoWrite: the whole list each call. The agy mirror writes them as `todo`
|
|
# since 2026-12-01; files mirrored before keep `agy:update_steps`, read here.
|
|
AGY_STEP_STATUS = {"done": "completed", "completed": "completed",
|
|
"in_progress": "in_progress", "pending": "pending",
|
|
"skipped": "cancelled", "cancelled": "cancelled",
|
|
"canceled": "cancelled"}
|
|
|
|
|
|
def agy_steps_as_todos(steps) -> dict:
|
|
"""agy's ``update_steps`` input as TodoWrite's ``{todos}`` (any status
|
|
agy may add later reads ``pending``)."""
|
|
todos = []
|
|
for s in steps if isinstance(steps, list) else []:
|
|
if not isinstance(s, dict):
|
|
continue
|
|
title = str(s.get("title") or "").strip()
|
|
st = AGY_STEP_STATUS.get(str(s.get("status") or "").strip().lower(), "pending")
|
|
todos.append({"content": title, "activeForm": title, "status": st})
|
|
return {"todos": todos}
|
|
|
|
|
|
def upgrade_call(tool, native, inp):
|
|
"""A tool call as the readers hand it to the fold: an older mirror's
|
|
``agy:update_steps {steps}`` becomes ``todo {todos}`` (its own name kept
|
|
in ``native``). Anything else unchanged."""
|
|
if tool == "agy:update_steps" and isinstance(inp, dict) and "todos" not in inp:
|
|
return "todo", native or "update_steps", agy_steps_as_todos(inp.get("steps"))
|
|
return tool, native, inp
|
|
|
|
|
|
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
|