From a57e7ab1a2a593794a2f1f1187d7c0b2daaa461e Mon Sep 17 00:00:00 2001 From: omesser Date: Thu, 10 Sep 2026 18:15:14 +0300 Subject: [PATCH] feat(harness): Reach Pi through the pi-acp adapter References #607 Co-authored-by: Cursor --- README.md | 4 +++- docs/DEVELOPMENT.md | 2 +- docs/research/buddy-harness-two-way.md | 2 +- src-tauri/src/harness.rs | 12 +++++++++--- src-tauri/src/main.rs | 3 ++- src-tauri/src/settings.rs | 2 +- src-tauri/src/settings/form.rs | 4 ++-- src/chat.js | 1 + 8 files changed, 20 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 5d6a48ce4..5a10c8a75 100644 --- a/README.md +++ b/README.md @@ -154,6 +154,7 @@ Named rows are smoked with `scripts/probe-harness.sh` (see [DEVELOPMENT.md](./do | `claude` | `npx -y @agentclientprotocol/claude-agent-acp@latest` | Zed's adapter over the Claude Agent SDK; no first-party ACP mode. Fresh and resumed sessions both work. | | `hermes` | `hermes acp` | First-party. Fresh sessions work; a resume that cannot restore the session reopens (#448). | | `opencode` | `opencode acp` | First-party. Fresh and resumed sessions both work. | +| `pi` | `npx -y pi-acp@latest` | Zed-registry adapter (`pi-acp`); no first-party ACP. Fresh and resumed sessions both work. Chat-only (no MCP). Footnote: requires a global `pi` on `PATH` — install with `brew install pi-coding-agent` (Homebrew pins Node in the shebang). `npx`/`node`/`pi` must resolve in the app's environment (Finder-launched builds inherit launchd's `PATH`, same as every other `npx` row). An unconfigured Pi may pick up an ambient provider key from the inherited environment; configuring `~/.pi/agent/` (e.g. `omlx launch pi`) wins over that fallback. npm-global `pi` can shadow the keg; `npm uninstall -g @earendil-works/pi-coding-agent` then `brew link pi-coding-agent`. Startup banner on the first fresh-session bubble is #597, not this row. | | `grok` | `grok agent stdio` | First-party, Grok Build. `grok` alone is the interactive TUI, so the subcommand is the whole of the row. Fresh and resumed sessions both work. | | anything else | as typed, split on whitespace | Unnamed, and it works: any command that speaks ACP on stdio attaches. GitHub Copilot CLI (`copilot --acp --stdio`) reaches ai-buddy this way today and earns a named row once smoked (#457). Google has none: the Gemini CLI is sunset, and Antigravity speaks its own protocol rather than ACP (#603), so it needs an adapter (#604). | @@ -164,10 +165,11 @@ How they handle session differs, and changes what ai-buddy can do with them: | `claude` | yes | yes | yes | http | none advertised when signed in | | `hermes` | yes | yes, after the reopen | yes | stdio | two: custom runtime credentials, Configure Hermes provider | | `opencode` | yes | yes | yes | http | Login with opencode | +| `pi` | yes | yes | yes | none | `pi_terminal_login` | | `grok` | yes | yes | yes | http | three: xai.api_key, cached_token, Grok | | anything else | unverified | unverified | unverified | unverified | unverified | -- † What `initialize` advertised: `claude`, `opencode` and `grok` set `agentCapabilities.mcpCapabilities.http` (the running app hands the loopback URL); `hermes` omits it and gets the stdio binary that relays to the same endpoint (ADR-0023, ADR-0026). `opencode` and `grok` also advertise `sse`, which nothing here reads. +- † What `initialize` advertised: `claude`, `opencode` and `grok` set `agentCapabilities.mcpCapabilities.http` (the running app hands the loopback URL); `hermes` and `pi` omit it and get the stdio binary that relays to the same endpoint (ADR-0023, ADR-0026). `pi` advertises no HTTP MCP and gets nothing forwarded today. `opencode` and `grok` also advertise `sse`, which nothing here reads. - ‡ `authMethods` is what is *available*, not what is outstanding — an empty list is no proof a login is unnecessary. Only `session/new` answering `-32000` is (ADR-0022). ### Harness ↔ MCP diff --git a/docs/DEVELOPMENT.md b/docs/DEVELOPMENT.md index 1bc38aa4d..141a0b896 100644 --- a/docs/DEVELOPMENT.md +++ b/docs/DEVELOPMENT.md @@ -208,7 +208,7 @@ Every variable that names a switch reads the same words: `1`, `on`, `true` or `y | `AI_BUDDY_DIRECTOR` | The Director on or off, whatever Settings saved. Off keeps Static even when a key is set; on still needs a key or a local server. The window and the tray name the variable and disable the toggle. | | `AI_BUDDY_DIRECTOR_TIMEOUT_SECS` | One turn's budget, whichever mind serves it: an HTTP Completer request or a Harness `session/prompt`. Expiry cancels the turn. Default 20 remote, 120 local — a cold local model loads weights on the first call. | | `AI_BUDDY_DIRECTOR_MAX_TOKENS` | Reply cap for the HTTP Completer. Default 80 remote, 512 local. A Harness decides its own reply length. | -| `AI_BUDDY_HARNESS` | Attach a Harness as the Completer instead of the HTTP one: `claude`, `codex`, `grok`, `hermes`, `opencode`, or a command line that speaks ACP on stdio. The Harness signs in on its own; a not-signed-in one is named in the Chat surface with the command that fixes it. Set and empty is the kill switch — Off, whatever the AI tab's AI source row saved. Unset falls through to that row, which offers the same choices (Off, the presets, and Custom). ADR-0017, #436. | +| `AI_BUDDY_HARNESS` | Attach a Harness as the Completer instead of the HTTP one: `claude`, `codex`, `grok`, `hermes`, `opencode`, `pi`, or a command line that speaks ACP on stdio. The Harness signs in on its own; a not-signed-in one is named in the Chat surface with the command that fixes it. Set and empty is the kill switch — Off, whatever the AI tab's AI source row saved. Unset falls through to that row, which offers the same choices (Off, the presets, and Custom). ADR-0017, #436. | | `AI_BUDDY_MCP_URL`, `AI_BUDDY_MCP_TOKEN` | Where the running app serves MCP on loopback, and the per-run bearer token that reaches it. The app sets both on the stdio MCP server entry it hands the Harness, and the shim relays there; with neither set it answers every call with a failure. Set them by hand to point the shim at an app you are already running. Never written to a file or a log. ADR-0026. | | `AI_BUDDY_MCP_BIN` | Where the stdio MCP server binary is, when it is not beside the app. Overrides Settings → Development's "MCP server binary", and is read at attach, so a change lands on the next one. First of three stdio routes: this, else an `ai-buddy-mcp` sidecar beside the app, else the app binary itself (`--mcp-stdio`). All three relay to the running app over loopback, so a `speak` over them reaches the buddy once the app hands them the two variables above (#501). A Harness that advertises `mcpCapabilities.http` is handed the app's own loopback MCP server directly (ADR-0023). | | `AI_BUDDY_HARNESS_AUTH_RETRY_SECS` | How long a Harness that has not signed in is left alone before `session/new` is tried again. Overrides Settings → Development's "Auth retry, in seconds", and 60 stands when neither says anything. Read when the Session is built, so a change lands on the next attach. | diff --git a/docs/research/buddy-harness-two-way.md b/docs/research/buddy-harness-two-way.md index 97fb53cc3..09449d3cb 100644 --- a/docs/research/buddy-harness-two-way.md +++ b/docs/research/buddy-harness-two-way.md @@ -482,7 +482,7 @@ advertises an A2A server endpoint. Don't stretch it. 7. **Pi gets a second adapter, not a compromise.** Buddy → Pi is `pi --mode rpc` with `{"type":"prompt",...}` and `streamingBehavior`; Pi → Buddy is a Pi extension wrapping the same tool set, because Pi has no MCP. - Do not adopt the third-party `pi-acp` as the shipped path. + The shipped path is now the registry adapter; Buddy→Pi is `npx -y pi-acp@latest`; Pi→Buddy tools are still a Pi extension, not MCP. Point at #607. 8. **Treat Claude Code `channels` as an optional enhancement behind a flag**, if ambient wake latency ever justifies it. It is the only way to push into a session the user started themselves, and it is a research preview behind an diff --git a/src-tauri/src/harness.rs b/src-tauri/src/harness.rs index 7526137e5..f4a9b330b 100644 --- a/src-tauri/src/harness.rs +++ b/src-tauri/src/harness.rs @@ -95,8 +95,9 @@ pub struct Launch { /// mode; `grok agent stdio`, `hermes acp` and `opencode acp` are /// first-party. Anything else is a command line of the user's own, which is /// how Copilot CLI attaches until it is smoked. Google has no row: the Gemini -/// CLI is sunset and Antigravity does not speak ACP (#603). Pi is deferred -/// (ADR-0022). +/// CLI is sunset and Antigravity does not speak ACP (#603). Pi is a named row +/// through Zed's registry adapter, same shape as `claude`. Copilot still +/// attaches via Custom until smoked. /// /// The README's Harness Support table is this table's user-facing half and is /// maintained by hand: a name or command changed here, or a new @@ -131,6 +132,7 @@ pub fn launch(value: Option<&str>) -> Option { "grok" => (value, vec!["grok", "agent", "stdio"]), "hermes" => (value, vec!["hermes", "acp"]), "opencode" => (value, vec!["opencode", "acp"]), + "pi" => (value, vec!["npx", "-y", "pi-acp@latest"]), custom => { let argv: Vec<&str> = custom.split_whitespace().collect(); (argv[0], argv) @@ -1940,6 +1942,10 @@ mod tests { ); assert_eq!(launch(Some("hermes")).unwrap().argv, ["hermes", "acp"]); assert_eq!(launch(Some("opencode")).unwrap().argv, ["opencode", "acp"]); + assert_eq!( + launch(Some("pi")).unwrap().argv, + ["npx", "-y", "pi-acp@latest"] + ); let custom = launch(Some(" my-agent --acp --quiet ")).unwrap(); assert_eq!(custom.name, "my-agent"); assert_eq!(custom.argv, ["my-agent", "--acp", "--quiet"]); @@ -2011,7 +2017,7 @@ mod tests { /// it is, with no key set, no config dir moved, and no `--bare`. #[test] fn child_command_sets_no_env_and_passes_no_bare() { - for name in ["claude", "codex", "grok", "hermes", "opencode"] { + for name in ["claude", "codex", "grok", "hermes", "opencode", "pi"] { let launch = launch(Some(name)).unwrap(); let command = launch.command(Path::new("/tmp")); assert_eq!(command.get_envs().count(), 0, "{name} sets env"); diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 7e35bd659..fb1a08ef2 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -1223,7 +1223,7 @@ fn permission_answer(request: String, option: String) { #[tauri::command] fn select_harness(harness: String, state: tauri::State<'_, SettingsState>) -> Result<(), String> { // Validate that this is a known preset - if !["claude", "codex", "grok", "hermes", "opencode"].contains(&harness.as_str()) { + if !["claude", "codex", "grok", "hermes", "opencode", "pi"].contains(&harness.as_str()) { return Err(format!("unknown Harness preset: {harness}")); } @@ -1249,6 +1249,7 @@ fn harness_login(harness: String) -> Result<(), String> { "grok" => vec!["grok", "login"], "hermes" => vec!["hermes", "login"], "opencode" => vec!["opencode", "login"], + "pi" => vec!["npx", "-y", "pi-acp@latest", "--terminal-login"], _ => return Err(format!("unknown Harness: {harness}")), }; diff --git a/src-tauri/src/settings.rs b/src-tauri/src/settings.rs index 2833c6312..464094cb7 100644 --- a/src-tauri/src/settings.rs +++ b/src-tauri/src/settings.rs @@ -1261,7 +1261,7 @@ pub struct Settings { pub director_wake_secs: String, /// Which Harness is the Completer, in the values `AI_BUDDY_HARNESS` takes: /// empty for none, a preset name (`claude`, `codex`, `grok`, `hermes`, - /// `opencode`), or `custom`, which defers to `harness_command`. The + /// `opencode`, `pi`), or `custom`, which defers to `harness_command`. The /// variable outranks it, and either way `harness::retarget` reaches the /// attachment now (#500). pub harness: String, diff --git a/src-tauri/src/settings/form.rs b/src-tauri/src/settings/form.rs index de6fef853..2c87ba4fd 100644 --- a/src-tauri/src/settings/form.rs +++ b/src-tauri/src/settings/form.rs @@ -328,7 +328,7 @@ pub const HARNESS_CUSTOM_VALUE: &str = "custom"; /// The named launch rows, in ADR-0022's order. Copilot reaches the same /// Completer through Custom until a turn has been smoked. Antigravity cannot: /// it does not speak ACP, and wants an adapter first (#604). -pub const HARNESS_PRESETS: [&str; 5] = ["claude", "codex", "grok", "hermes", "opencode"]; +pub const HARNESS_PRESETS: [&str; 6] = ["claude", "codex", "grok", "hermes", "opencode", "pi"]; /// The endpoints the Base URL picker names, as (group, name, base URL). /// @@ -2066,7 +2066,7 @@ mod tests { let (_, options, _) = popup_row(&description, HARNESS_ID); assert_eq!( options, - ["Off", "claude", "codex", "grok", "hermes", "opencode", "Custom"] + ["Off", "claude", "codex", "grok", "hermes", "opencode", "pi", "Custom"] ); assert_eq!( description.text_write(HARNESS_ID), diff --git a/src/chat.js b/src/chat.js index 5d0674d86..498c9aa97 100644 --- a/src/chat.js +++ b/src/chat.js @@ -280,6 +280,7 @@ function attached(opening) { grok: "Grok", opencode: "OpenCode", hermes: "Hermes", + pi: "Pi", }; const harnessName = displayNames[opening.harness_name] || opening.harness_name || "The Harness"; title.textContent = `${harnessName} needs login`;