Skip to content

Worktree text

worktree_text

Text renderers for GitWorktreeTool dual-format ToolResult.

Transform the structured data dict produced by :class:axm_git.tools.worktree.GitWorktreeTool into a compact text representation, covering all three sub-modes::

Text Only
git_worktree | ✓ | list · {n} worktrees
{path} {head7} {branch}
...

git_worktree | ✓ | add · {branch} @ {base}
{path}

git_worktree | ✓ | remove
{removed}

git_worktree | ✗ | {error}

render_add_text(data)

Render the add sub-mode ({"path", "branch", "base"}).

Source code in packages/axm-git/src/axm_git/tools/worktree_text.py
Python
def render_add_text(data: dict[str, object]) -> str:
    """Render the ``add`` sub-mode (``{"path", "branch", "base"}``)."""
    branch = _as_str(data.get("branch"))
    base = _as_str(data.get("base"))
    path = _as_str(data.get("path"))
    return f"git_worktree | ✓ | add · {branch} @ {base}\n{path}"

render_failure_text(*, error, data)

Render any failure (invalid action, not-a-repo, git error).

Appends a child-repo hint when data carries suggestions.

Source code in packages/axm-git/src/axm_git/tools/worktree_text.py
Python
def render_failure_text(*, error: str, data: dict[str, object] | None) -> str:
    """Render any failure (invalid action, not-a-repo, git error).

    Appends a child-repo hint when *data* carries ``suggestions``.
    """
    header = f"git_worktree | ✗ | {error}"
    suggestions = _as_str_list(data.get("suggestions")) if data else []
    if suggestions:
        return f"{header}\nhint: pass one as path: {', '.join(suggestions)}"
    return header

render_list_text(data)

Render the list sub-mode ({"worktrees": [...]}).

Source code in packages/axm-git/src/axm_git/tools/worktree_text.py
Python
def render_list_text(data: dict[str, object]) -> str:
    """Render the ``list`` sub-mode (``{"worktrees": [...]}``)."""
    raw = data.get("worktrees")
    worktrees = [w for w in raw if isinstance(w, dict)] if isinstance(raw, list) else []
    header = f"git_worktree | ✓ | list · {len(worktrees)} worktrees"
    if not worktrees:
        return header
    return "\n".join([header, *(_worktree_line(w) for w in worktrees)])

render_remove_text(data)

Render the remove sub-mode ({"removed": ...}).

Source code in packages/axm-git/src/axm_git/tools/worktree_text.py
Python
def render_remove_text(data: dict[str, object]) -> str:
    """Render the ``remove`` sub-mode (``{"removed": ...}``)."""
    return f"git_worktree | ✓ | remove\n{_as_str(data.get('removed'))}"