Skip to content

API Reference parrot_tools.tool_optimizations.installation

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot_tools.tool_optimizations.installation

View source

Managed installation of the host read guards (FEAT-543).

Installs, reports on, and removes the opt-in PreToolUse guard for Claude Code and Codex, following the same "touch only what we own" discipline as the existing wiki installers:

  • Idempotent. Installing twice produces identical bytes and an "already installed" message.
  • Foreign configuration is preserved. Other hook entries, other matchers and unknown keys are never rewritten or dropped.
  • A malformed config is never clobbered. It raises an actionable error and leaves the file untouched.
  • Uninstall removes only owned entries, identified by the hook module name in the command string, and only collapses containers it emptied.

The user's home directory is never touched: Codex hooks are written to <root>/.codex/hooks.json, project scope only.

Attribute CLAUDE_MATCHER

Attribute CODEX_MATCHER

Attribute HOOK_MODULE

Function guard_status

Report whether the guard is installed and whether the host supports it.

guard_status(root: Path, host: str) -> dict[str, Any]

Parameter Type Default Description
root Path The repository root.
host str claude or codex.

Returns: dict[str, Any] — A mapping with installed, supported, hook_path, thresholds and host_version. Never raises.

Raises:

  • ValueError — The host is not supported.

Function guard_thresholds

Derive guard thresholds from the configured bounded-source toolkit.

The guard must use the same limits as the MCP reader it points at; reading them from the same configuration is what keeps them aligned.

guard_thresholds(root: Path) -> dict[str, Any]

Parameter Type Default Description
root Path The repository root.

Returns: dict[str, Any] — The thresholds mapping written to .parrot/tool-guards.json.

Function hook_command

Build the guard's hook command for a host.

hook_command(root: Path, host: str) -> str

Parameter Type Default Description
root Path The repository root.
host str claude or codex.

Returns: str — The full command string.

Raises:

  • ValueError — The host is not supported.

Function install_guards

Install the read guard for a host, idempotently.

install_guards(root: Path, host: str) -> list[str]

Parameter Type Default Description
root Path The repository root.
host str claude or codex.

Returns: list[str] — Human-readable action strings.

Raises:

  • ValueError — The host is not supported.
  • RuntimeError — A target config file is malformed; nothing is written.

Function resolve_python

Return an absolute interpreter path for the hook command.

Hooks run without the virtualenv on $PATH — notably inside git worktrees — so the command must name the interpreter absolutely.

resolve_python(root: Path) -> str

Parameter Type Default Description
root Path The repository root.

Returns: str — An absolute path to a Python interpreter.

Function uninstall_guards

Remove only the guard entries this module installed.

uninstall_guards(root: Path, host: str) -> list[str]

Parameter Type Default Description
root Path The repository root.
host str claude or codex.

Returns: list[str] — Human-readable action strings.

Raises:

  • ValueError — The host is not supported.
  • RuntimeError — The target config file is malformed; it is left alone.

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally