An interactive command-line interface and Zed Agent Connection Protocol (ACP) bridge server for the remote "Pinky and the Brain" agent service.
With patb-cli, you can converse with the remote agent directly from your terminal or integrate it seamlessly into the Zed Editor as a custom AI assistant.
- Interactive CLI REPL: Start a direct conversation with the agent in your terminal.
- Zed ACP Bridge: Implements the ACP (JSON-RPC 2.0 over standard I/O) to function as a Zed-compatible external agent server.
- Real-Time Streaming: Supports progress notifications and real-time streaming of response chunks.
- File Delivery: Files the agent writes are downloaded and saved to your disk, not left on the server it runs on.
- Auto-Config: Loads configuration parameters (such as the API key) from environment variables or a local
.envfile.
The CLI acts as a client wrapper and gateway for the remote server hosted at d33ib4uu7f4xpi.cloudfront.net.
graph TD
A[User / Zed Editor] -->|Interactive Prompt or ACP RPC| B(patb-cli)
B -->|1. Create Thread| C[Remote Service]
B -->|2. Trigger Run| C
C -->|3. Event Stream + artifact announcements| B
B -->|4. Fetch artifact bytes| C
B -->|5. Write file to local disk| D[(Your filesystem)]
B -->|6. Format Output / Progress| A
The agent runs in a container. A tool that writes with fs writes to that filesystem β a real
path, on a disk you cannot reach β which is why an article "saved" by the hosted agent used to
appear nowhere at all.
So the service does not report such a path. It publishes what it wrote as a retrievable artifact: the run's event stream announces the file with its name, size and SHA-256, and this CLI downloads it, verifies the hash, writes it to your own disk and prints where it went.
πΎ Saved to D:\_code-projects\articles\game-of-life.md
Files go to ./articles by default, relative to wherever you started the CLI. Both the filename and
any folder the agent names arrive over the network from a language model, so writes are confined to
that directory unless you say otherwise with --allow-any-path. A refused write is reported, never
silent:
β οΈ Could not save "aimed.md": The agent asked to write "aimed.md" to "C:\Windows\Temp", which is
outside D:\_code-projects\articles. Re-run with --allow-any-path to permit that, or use
--out-dir to move the directory artifacts are written to.
The article stays on the service either way, so a failed delivery can be retried by asking again.
- Node.js (v20.0.0 or higher recommended)
- npm (comes with Node.js)
Clone or navigate to the project directory and install the developer dependencies:
npm installCompile the TypeScript source code to JavaScript:
npm run buildThis compiles the code into the dist/ directory.
The tool requires a PATBA_API_KEY to authenticate requests with the remote service. You can configure this in two ways:
Create a .env file in your current working directory (where you run the CLI command):
PATBA_API_KEY=your_secret_api_key_hereExport the key directly to your environment:
- Windows (PowerShell):
$env:PATBA_API_KEY="your_secret_api_key_here"
- macOS / Linux:
export PATBA_API_KEY="your_secret_api_key_here"
The CLI supports two primary operational modes: Interactive REPL (default) and Zed ACP Bridge.
To start an interactive conversation with the agent:
node dist/index.jsOr, if you link/install the CLI globally (npm link or npm install -g .):
patb-cli- Converse: Type your query and press
Enter. - Progress Tracking: The CLI outputs run state (e.g.,
π [the-brain] Run complete) tostderrso thatstdoutremains clean. - Exit: Type
exitorquitto end the session.
To run patb-cli as a background server facilitating communications between Zed Editor and the remote agent service:
node dist/index.js --bridge
# or
patb-cli --bridgeThis mode communicates using standard JSON-RPC 2.0 protocols over stdin/stdout.
To add patb-cli as an external agent server in Zed:
- Open Zed.
- Open your Zed configuration file using the Command Palette (
ctrl-shift-porcmd-shift-pand typezed: open settings). - Add the server entry under the
agent_serversblock.
Example snippet for settings.json:
{
"agent_servers": {
"patb-agent": {
"type": "custom",
"command": "node",
"args": ["D:/_code-projects/patb-cli/dist/index.js", "--bridge"]
}
}
}(Make sure to replace D:/_code-projects/patb-cli/dist/index.js with the absolute path to your compiled entry point, and use forward slashes / even on Windows).
- Save the settings. You can now use the Agent panel in Zed to start threads and select the
the-brainagent.
| Flag | Alias | Description |
|---|---|---|
--bridge |
-b |
Starts the server in Zed ACP JSON-RPC 2.0 Bridge mode. |
--help |
-h |
Prints the CLI help menu showing usage and exits. |
--out-dir <path> |
Directory files the agent writes are saved to. Default ./articles, relative to the current directory. Env: PATBA_OUT_DIR. |
|
--allow-any-path |
Permits a write outside --out-dir when you have asked the agent for a specific folder. Off by default. |
|
--host <url> |
Service to talk to. Defaults to the deployed one; useful for pointing at a server running locally. Env: PATBA_HOST. |
If no flags are supplied, the CLI defaults to the Interactive REPL mode.
==================================================
π§ Pinky and the Brain - Remote Agent CLI REPL
Initializing remote session (API Key: abcd...wxyz)...
==================================================
π§΅ Remote Thread ID: thread_abc123xyz
Type your message to prompt the agent workflow.
Type 'exit' or 'quit' to end the session.
==================================================
π€ You: hello
π€ Agent executing...
π [the-brain] Starting agent workflow for: the-brain
π [the-brain] Run complete
--------------------------------------------------
π€ Response:
Ah, Pinky! Behold the four pillars of tonight's potential enlightenment:
1. AWS Cloud Practitioner Certification β the CLF-C02 exam.
2. Cellular Automata β Conway's Game of Life, Wolfram, Lenia, particle life.
3. English for Certifications β IELTS, TOEFL and Cambridge.
4. Technical Interview Preparation β role-based roadmaps.
Which shall we conquer first?
--------------------------------------------------
Below is an example exchange that happens under the hood when communicating in bridge mode:
Request (initialize):
{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"1.0"}}Response:
{"jsonrpc":"2.0","id":1,"result":{"protocolVersion":"1.0","serverInfo":{"name":"patb-cli-bridge","version":"1.0.0"},"capabilities":{"agents":true}}}- Cause: The CLI was unable to find
PATBA_API_KEYeither in your environment variables or in a.envfile in the directory where the command was executed. - Solution: Ensure your
.envfile containing the key is in the Current Working Directory (process.cwd()) from which you are running the command, or set it as a system environment variable.
- Error message:
β Failed to initialize remote thread: {"error":"401 Unauthorized"}(or other network error). - Cause: This usually indicates a network connection failure to the remote API hostname (
d33ib4uu7f4xpi.cloudfront.net) or an invalid/expired/incorrect API key. - Solution:
- Verify your internet connection.
- Check that the value of
PATBA_API_KEYis correct, valid, and active. - Test connectivity manually using
curl:curl -X POST -H "X-API-Key: YOUR_API_KEY" https://d33ib4uu7f4xpi.cloudfront.net/threads
- Cause: Zed cannot find the
nodeexecutable or the path toindex.jsin yoursettings.jsonis incorrect. - Solution:
- Double check that you've compiled the source files by running
npm run build. - Verify that the path to
dist/index.jsis absolute and uses forward slashes/. - If using a global command, make sure
patb-cliis in your system'sPATH. You can verify this by runningpatb-cli -hin a new terminal window. - Check the Zed log files (
zed: open login the command palette) to see the exact error output.
- Double check that you've compiled the source files by running
- Cause: Running files without building first, or Node version discrepancies.
- Solution: Make sure Node.js is updated (v20+). Always run
npm run buildafter editing TypeScript code.