pi-acp Documentation

repository·main·Indexed 19 days ago

https://github.com/svkozak/pi-acp

An Agent Client Protocol (ACP) adapter for the 'pi' coding agent (v0.80.4+). It enables ACP-compliant clients, such as the Zed editor, to communicate with the pi agent via JSON-RPC 2.0 over stdio. Features include support for slash commands (built-in, skill-based, and file-based prompts), session management, and configurable embedded context support via the PI_ACP_ENABLE_EMBEDDED_CONTEXT environment variable.

Tokens
8.1K
Snippets
32
Records
39
Agent score
68%

What's inside pi-acp

  1. Understand pi-acp limitations

    main

    When using pi-acp, be aware of the following current limitations:

    • No Filesystem or Terminal Delegation: pi-acp does not support ACP fs/* or terminal/* delegation. The pi agent reads, writes, and executes commands locally on your machine.
    • MCP Support: While MCP servers are accepted in ACP parameters and stored in session state, they are not automatically wired through to pi by this adapter. To use MCP with pi, you must use the pi-mcp-adapter.
    • Streaming: Assistant streaming is sent as agent_message_chunk. There is currently no separate stream for 'thoughts'.
    • Queueing: The queueing mechanism is implemented client-side and behaves like pi's one-at-a-time mode.
  2. Use slash commands in pi-acp

    main

    You can use slash commands within your ACP client to control the pi agent. Commands are categorized into three types:

    1. File-based commands (Prompts)

    These are loaded from your local filesystem:

    • User commands: ~/.pi/agent/prompts/**/*.md
    • Project commands: <cwd>/.pi/prompts/**/*.md

    2. Built-in commands

    • /compact [instructions...] – Run pi compaction (with optional custom instructions).
    • /autocompact on|off|toggle – Toggle automatic compaction.
    • /export – Export the current session to HTML in the session cwd.
    • /session – Show session stats (tokens, messages, cost, session file).
    • /name <name> – Set the session display name.
    • /queue all|one-at-a-time – Set the pi queue mode (unstable).
    • /changelog – Print the installed pi changelog.
    • /steering – Get/set pi Steering Mode.
    • /follow-up – Get/set pi Follow-up Mode.

    3. Skill commands

    If skills are enabled in your pi settings, they appear as /skill:skill-name in the ACP client.

    Note: Slash commands provided by pi extensions are not currently supported.

  3. Authenticate with the ACP Registry

    main

    If your ACP client (like Zed) requires authentication for the ACP Registry, it may show an Authenticate banner. You can perform the interactive login/setup by running pi-acp in a terminal with the --terminal-login flag.

    pi-acp --terminal-login
  4. Install pi-acp as an ACP agent

    main

    To use pi-acp with an ACP client like Zed, you can choose from several installation methods. Ensure you have pi (v0.80.4+) installed and available on your PATH before proceeding.

    In Zed, run the zed: acp registry command and select the pi ACP adapter. This automatically configures your settings.json.

    Using npx (No global install)

    Add this configuration to your Zed settings.json to always run the latest version:

    "agent_servers": {
      "pi": {
        "type": "custom",
        "command": "npx",
        "args": ["-y", "pi-acp"],
        "env": {}
      }
    }

    Global Install

    Install the package globally via npm:

    npm install -g pi-acp

    Then configure your client:

    "agent_servers": {
      "pi": {
        "type": "custom",
        "command": "pi-acp",
        "args": [],
        "env": {}
      }
    }

    From Source

    Build the project and point your client to the dist/index.js file:

    npm install
    npm run build
    "agent_servers": {
      "pi": {
        "type": "custom",
        "command": "node",
        "args": ["/path/to/pi-acp/dist/index.js"],
        "env": {}
      }
    }
  5. How terminal authentication works in pi-acp

    main

    The pi_terminal_login method allows users to configure API keys or log in via an interactive terminal session.

    For clients like Zed, the authentication method includes a _meta['terminal-auth'] object. This object contains a launch specification (command and arguments) that the client uses to trigger the terminal interface.

    When the terminal login is triggered, the command executed is typically:

    1. The current Node.js executable running the script: node <path-to-index.js> --terminal-login
    2. Or, if the above is not detectable, the fallback command: pi-acp --terminal-login
    // Conceptual shape of the terminal auth method returned by getAuthMethods()
    {
      "id": "pi_terminal_login",
      "name": "Launch pi in the terminal",
      "description": "Start pi in an interactive terminal to configure API keys or login",
      "type": "terminal",
      "args": ["--terminal-login"],
      "env": {},
      "_meta": {
        "terminal-auth": {
          "command": "node",
          "args": ["/path/to/dist/index.js", "--terminal-login"],
          "label": "Launch pi"
        }
      }
    }
  6. Configure embedded context support via PI_ACP_ENABLE_EMBEDDED_CONTEXT

    main

    By default, pi-acp does not advertise support for ACP promptCapabilities.embeddedContext. To enable this feature—allowing compliant ACP clients to send resource blocks—set the PI_ACP_ENABLE_EMBEDDED_CONTEXT environment variable to true in your client configuration.

    If disabled, pi-acp will still gracefully handle incoming resource blocks by converting them into plain-text prompt context.

    "agent_servers": {
      "pi": {
        "type": "custom",
        "command": "node",
        "args": ["/path/to/pi-acp/dist/index.js"],
        "env": {
            "PI_ACP_ENABLE_EMBEDDED_CONTEXT": "true"
        }
      }
    }
  7. Use slash commands with arguments

    main

    When a slash command is expanded, you can pass arguments to it. These arguments are substituted into the command's content using bash-style placeholders.

    Substitution Placeholders

    • $@: Replaces this token with all provided arguments joined by spaces.
    • $1, $2, etc.: Replaces the token with the specific argument at that index (1-based).

    Argument Parsing

    Arguments are parsed using space delimiters, but they support single (') or double (") quotes to allow for arguments containing spaces.

    Example Usage

    If your command file explain.md contains: Please explain this code: $@ and focus on $1.

    Invoking /explain "async function test() {}" performance will expand to: Please explain this code: async function test() {} and focus on performance.

  8. Define and load slash commands via Markdown files

    main

    Slash commands in pi-acp are defined as Markdown files located in specific directories. This allows you to create reusable prompt templates that can be invoked using the /command syntax.

    Command Locations

    Commands are loaded from two primary locations:

    1. User Commands: ~/.pi/agent/prompts/**/*.md (Global across all projects).
    2. Project Commands: <project-root>/.pi/prompts/**/*.md (Specific to the current working directory).

    Command Structure

    Each .md file represents a command. The filename (without the .md extension) becomes the command name. You can use YAML frontmatter to provide a custom description.

    • Name: Derived from the filename.
    • Description: Taken from the description key in the YAML frontmatter. If no frontmatter is present, the first line of the file is used as the description (truncated to 60 characters).
    • Content: The body of the Markdown file, which serves as the prompt template.
    • Source Label: Automatically appended to the description to indicate origin, e.g., (user), (user:subdir), (project), or (project:subdir).

    Example Markdown File

    Create a file at ~/.pi/agent/prompts/refactor.md:

    ---
    description: Refactors the provided code for readability
    ---
    
    Refactor the following code using best practices:
    
    $@
  9. Authenticate via Terminal Login

    main

    The pi-acp adapter supports a terminal-based authentication flow. When an ACP client launches the agent with the --terminal-login flag, pi-acp will spawn the underlying pi command (configured via PI_ACP_PI_COMMAND) to handle the login process in the current terminal session.

    If the pi command is not found, an error message will be displayed suggesting installation via:

    npm install -g @earendil-works/pi-coding-agent

    node path/to/pi-acp --terminal-login
  10. Suppress startup messages with quietStartup

    main

    The quietStartup setting determines whether the agent suppresses its verbose startup prelude.

    It can be configured in two ways:

    1. Directly as a top-level boolean: "quietStartup": true.
    2. Using the legacy key "quietStart": true (maintained for backward compatibility).

    Defaults to false (messages are shown) if not specified.

    {
      "quietStartup": true
    }
  11. Configure the pi agent directory

    main

    The location of the pi agent configuration and session data can be controlled via the following mechanisms:

    MethodKeyDescription
    Environment VariablePI_CODING_AGENT_DIRSets the base directory for the agent. Default is ~/.pi/agent.
    Settings Filesettings.jsonLocated in the agent directory. Contains a sessionDir key to override the sessions folder.

    Example settings.json:

    {
      "sessionDir": "/custom/path/to/sessions"
    }
  12. Configure pi-acp settings via settings.json

    main

    Settings in pi-acp are managed through settings.json files using a hierarchical merge strategy: Project settings override Global settings.

    Configuration Locations

    1. Global Settings: Located in the agent directory. By default, this is ~/.pi/agent/settings.json. You can override this location by setting the PI_CODING_AGENT_DIR environment variable.
    2. Project Settings: Located at the root of your project in .pi/settings.json.

    Settings Hierarchy

    When a setting is defined in both files, the value in the project-level .pi/settings.json takes precedence over the global settings.json.

    // Example Global Settings (~/.pi/agent/settings.json)
    {
      "quietStartup": true,
      "skills": {
        "enableSkillCommands": false
      }
    }
    
    // Example Project Settings (./.pi/settings.json)
    {
      "enableSkillCommands": true
    }