Skip to content

Coding agents: an extension for Pi (earendil-works/pi) #564

Closed as not planned

Description

@LoopGlitch26

Pi's coding agent loads TypeScript extensions that see each tool call before it runs (extensions). A tool_call handler gets toolName, toolCallId and input, and blocks the call by returning {block: true, reason}; a handler that throws blocks it too ("tool_call errors block the tool (fail-safe)"). tool_result carries the same toolCallId with the result (content, isError), and session_start, session_shutdown and input cover the session and what the person typed. Every MCP call (mcp__<server>__<tool>) and every call a codemode script makes goes through the same handlers, a nested one with parentToolCallId (MCP). Pi finds extensions in ~/.pi/agent/extensions/ and, once a project is trusted, in its .pi/extensions/. The built-in tools are bash (command), read (path), write (path, content), edit (path, edits), grep, find and ls (path), and powershell. Pi has 120k GitHub stars; v1.5.0 shipped on 2 Nov 2026.

This is the shape of OpenCode's plugin, which Tracekit already generates (_opencode_plugin in tracekit/agent_hooks.py): a small extension that spawns the Python hook for each event without blocking Pi's event loop. Unlike OpenCode, Pi also gives session and prompt events, so prompts and session ends can be recorded.

Task:

  1. In a real pi run, confirm that tool_call waits for a handler that takes minutes (a held call), what ctx.sessionManager.getSessionId() and getSessionFile() return (a run id, and a transcript to hash), and whether input carries the typed prompt before expansion. Record the payloads the extension builds as cases in tests/data/harness/pi.json.
  2. Add pi to AGENT_NAMES. tool(): bash → Bash, read → Read, write → Write, edit → Edit (path: path), grep, find and ls decided on path, MCP tools as mcp__<server>__<tool>. Decide how powershell is decided (Tracekit's shell rules read POSIX shells; holding it for a person is the safe default) and say so in the docs.
  3. Generate ~/.pi/agent/extensions/tracekit.ts (--project: .pi/extensions/tracekit.ts) with a marker line, refusing to overwrite a file Tracekit didn't write, as _install_opencode does. Its tool_call handler returns {block: true, reason} unless the hook exits 0, and kills a hook still running after 600 s and blocks; tool_result, session_start, session_shutdown and input send the post-tool, session and prompt events. Wire tracekit init --dev [--v2] --agent pi / uninstall / doctor.
  4. Tests: in tests/test_agent_hooks.py (mapping, the generated extension, the installer's refusal) and the recorded cases through cases("pi") in tests/test_harness_hooks_v2.py.
  5. Add ~/.pi/agent/extensions and .pi/extensions to TK-F009/TK-F015 in tracekit/policy2/packs/coding.yaml, a column in docs/coding-agents.md, and docs/limits.md rows: pi --no-extensions (-ne) starts Pi without Tracekit's extension; a project's extension loads only once the project is trusted; how powershell is decided.

Done when: in a real Pi session (say which version in the PR) a denied call is blocked, a held call waits for tracekit approvals approve, an MCP call is decided, and the session's calls and prompts show up in tracekit last; the tests pass and make test passes.

Comment here to claim it. Commits need a DCO sign-off (git commit -s).

Activity

  1. LoopGlitch26 commented on Nov 10, 2026

    @LoopGlitch26
    MemberAuthor

    Refreshed as #696 with current file paths.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions