Skip to content

Commit 813bbd1

Browse files
authored
fix(acp): integrate the Buzz Pi adapter fork (#7552)
## Summary PR #7335 worked around missing Pi adapter support by generating a private Pi launcher and injecting Buzz's standing prompt and skills at process launch. The Buzz Pi fork now carries the required adapter extensions, so this removes that launcher and returns prompt construction to the normal ACP session path while retaining the base-prompt composition introduced by #7335. The Pi preset now installs `salman1993/pi-acp` and launches its renamed `buzz-pi-acp` binary. Buzz adds `-- --skill <harness-cwd>/.agents/skills` only when launching that binary, sends the complete composed prompt as the `_meta.systemPrompt` replacement string on `session/new` only when `initialize.agentInfo.name` is `buzz-pi-acp`, and sends the scoped title alongside it as `_meta.sessionTitle`. The fork identity is treated as system-prompt capable regardless of its reported ACP protocol version, which prevents duplicate legacy user-message framing. Upstream `pi-acp` does not receive either fork-specific behavior. Observer transcript projection accepts the string, `{ replace }`, and `{ append }` metadata forms. The fork now stores restore metadata in one atomic file per session under `~/.pi/buzz-pi-acp/sessions/`. This prevents concurrent Buzz workers from overwriting another session's prompt or title. The fix landed in [salman1993/buzz-pi-acp#9](salman1993/buzz-pi-acp#9). This supersedes the closed #7508. No agent-configuration rules changed; this changes the Buzz Pi adapter contract and launch arguments. ### Related issue #7329 ### Testing Installed fork commit `09cf07e436b8f18e52401558f988f31a15702313` through the documented Git URL. The installed bundle matched the committed `dist/index.js` byte for byte and contained the `~/.pi/buzz-pi-acp` metadata path. The fork's 106 non-skipped tests, typecheck, and lint pass. Ran the ignored real-Pi integration test through Buzz's production session composer. The test exercised the renamed package, `agentInfo.name`, and the new per-session metadata store. Base, persona, team, core-memory, huddle, canvas, and skill markers each appeared once after switching sessions and again after restarting the adapter, while the other session and Pi's native default prompt were absent. Added regression coverage proving `buzz-pi-acp` receives fork-specific system-prompt metadata and managed skills while upstream `pi-acp` does not. `just ci` passes. Generated with Codex --------- Signed-off-by: Salman Mohammed <[email protected]>
1 parent 092c6a7 commit 813bbd1

15 files changed

Lines changed: 812 additions & 639 deletions

File tree

‎crates/buzz-acp/TESTING.md‎

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Pi adapter integration
2+
3+
Buzz's Pi preset uses [salman1993/pi-acp](https://github.com/salman1993/pi-acp).
4+
Requires Node.js 22 or newer. Install Pi and configure its model provider,
5+
then install the adapter directly from the fork:
6+
7+
```sh
8+
npm install -g @earendil-works/pi-coding-agent
9+
pi
10+
npm install -g --install-links=true git+https://github.com/salman1993/pi-acp.git#main
11+
```
12+
13+
Restart Buzz, then select **Pi** as the agent harness. Buzz starts `buzz-pi-acp`
14+
automatically. Run the same adapter install command again to update it.
15+
The unscoped `npm install -g pi-acp` command installs the upstream package,
16+
without these extensions. Use fresh sessions to replace old user-framed
17+
standing instructions.
18+
19+
Buzz adds `-- --skill <harness-cwd>/.agents/skills` when launching `buzz-pi-acp`.
20+
An existing separator and explicit Pi options are preserved. Managed agents
21+
run from the Buzz nest (normally `~/.buzz`): Desktop sets the `buzz-acp` child
22+
CWD through `default_agent_workdir()`, and adapters inherit it. The default
23+
skill directory is that launch workspace's `.agents/skills`. Standalone CLI
24+
launches use the caller's working directory.
25+
The path is fixed at adapter launch and applies to every Pi subprocess.
26+
27+
The full composed session prompt is sent as a replacement string through the
28+
provisional `session/new.params._meta.systemPrompt` field. Buzz recognizes
29+
`buzz-pi-acp` by the agent name returned during initialization, regardless of
30+
protocol version. Upstream `pi-acp` does not receive this fork-specific metadata.
31+
No custom capability negotiation or legacy Pi prompt fallback is used.
32+
Session titles continue to use `_meta.sessionTitle`.
33+
34+
## Validation
35+
36+
Activate Hermit from the Buzz repository root, then run the package tests:
37+
38+
```sh
39+
. ./bin/activate-hermit
40+
cargo test -p buzz-acp
41+
```
42+
43+
To exercise the real adapter through Buzz's production session composer:
44+
45+
```sh
46+
BUZZ_TEST_PI_ACP=/absolute/pi-acp/dist/index.js \
47+
cargo test -p buzz-acp real_pi_preserves -- --ignored
48+
```
49+
50+
This test requires Node and Pi on PATH. It isolates HOME and Pi settings,
51+
disables extensions and context files, and uses a synthetic transcript without
52+
model calls. It inspects Pi's effective prompt through RPC HTML export after
53+
switching sessions and restarting the adapter. Base, persona, team, core memory,
54+
huddle, canvas, and the extra skill must each appear once, without another
55+
session's instructions or Pi's default coding preamble.
56+
57+
HTML export reports the exporting process's current system prompt. It cannot
58+
recover a historical prompt from an old transcript alone.

‎crates/buzz-acp/src/acp.rs‎

Lines changed: 28 additions & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ use crate::usage::{
2222
/// Lines exceeding this limit are rejected to prevent OOM from rogue agents.
2323
const MAX_LINE_SIZE: usize = 10_000_000; // 10 MB
2424

25+
/// Package and binary name used by Buzz's Pi ACP fork.
26+
pub(crate) const BUZZ_PI_ACP_NAME: &str = "buzz-pi-acp";
27+
2528
/// An MCP server configuration passed to `session/new`.
2629
///
2730
/// Corresponds to the `McpServerStdio` variant in the ACP schema.
@@ -460,8 +463,17 @@ impl AcpClient {
460463
use std::process::Stdio;
461464

462465
let mut cmd = tokio::process::Command::new(command);
463-
cmd.args(args)
464-
.stdin(Stdio::piped())
466+
cmd.args(args);
467+
if crate::config::normalize_agent_command_identity(command) == BUZZ_PI_ACP_NAME {
468+
if !args.iter().any(|arg| arg == "--") {
469+
cmd.arg("--");
470+
}
471+
// Desktop launches buzz-acp in the Buzz nest; adapters inherit that
472+
// workspace. Keep managed skills tied to launch CWD across sessions.
473+
cmd.arg("--skill")
474+
.arg(std::env::current_dir()?.join(".agents/skills"));
475+
}
476+
cmd.stdin(Stdio::piped())
465477
.stdout(Stdio::piped())
466478
// Inherit stderr so agent logs are visible in the harness terminal.
467479
.stderr(Stdio::inherit())
@@ -637,14 +649,16 @@ impl AcpClient {
637649
///
638650
/// - `None` — no system-prompt field in the request (legacy framing).
639651
/// - `Some(SystemPromptTransport::Field(text))` — bare `systemPrompt` field
640-
/// (ACP protocol v2, buzz-agent, goose unused).
652+
/// (ACP protocol v2, buzz-agent; goose unused).
653+
/// - `Some(SystemPromptTransport::PiMeta(text))` — `_meta.systemPrompt`
654+
/// as a replacement string for the Buzz pi-acp fork.
641655
/// - `Some(SystemPromptTransport::ClaudeMeta(text))` — `_meta.systemPrompt`
642656
/// as `{"append": text}`, keeping claude-agent-acp's native preset intact.
643657
///
644658
/// `session_title` rides in `_meta.sessionTitle` when `Some`; `_meta` is
645659
/// omitted entirely otherwise, since adapters may distinguish an absent
646-
/// member from a null one. When both `ClaudeMeta` and `session_title` are
647-
/// present the two `_meta` members are merged into a single object.
660+
/// member from a null one. Metadata prompt transports and the title are
661+
/// merged into a single object.
648662
///
649663
/// Callers use [`extract_model_config_options`] and [`extract_model_state`]
650664
/// to pull model info from the raw result.
@@ -663,14 +677,17 @@ impl AcpClient {
663677
Some(SystemPromptTransport::Field(sp)) => {
664678
params["systemPrompt"] = serde_json::Value::String(sp.to_owned());
665679
}
680+
Some(SystemPromptTransport::PiMeta(sp)) => {
681+
params["_meta"]["systemPrompt"] = serde_json::Value::String(sp.to_owned());
682+
}
666683
Some(SystemPromptTransport::ClaudeMeta(sp)) => {
667684
// Merge into _meta so sessionTitle (set below) is not clobbered.
668685
params["_meta"]["systemPrompt"] = serde_json::json!({ "append": sp });
669686
}
670687
None => {}
671688
}
672689
if let Some(title) = session_title {
673-
// Merge — _meta may already carry systemPrompt from ClaudeMeta above.
690+
// Merge — _meta may already carry a system prompt from an adapter extension.
674691
params["_meta"]["sessionTitle"] = serde_json::Value::String(title.to_owned());
675692
}
676693
let result = self.send_request("session/new", params).await?;
@@ -2131,16 +2148,18 @@ pub struct SessionNewResponse {
21312148

21322149
/// How to deliver a system prompt on `session/new`.
21332150
///
2134-
/// The two variants match the two mechanisms supported by current adapters:
2135-
///
21362151
/// - **`Field`** — bare `systemPrompt` field (ACP protocol v2, buzz-agent).
2152+
/// - **`PiMeta`** — `_meta.systemPrompt: text`, used by the Buzz pi-acp fork
2153+
/// to replace Pi's native system prompt.
21372154
/// - **`ClaudeMeta`** — `_meta.systemPrompt: {"append": text}`, used by
21382155
/// `claude-agent-acp` to append to the adapter's own native system prompt
21392156
/// while keeping its tool-use preset intact.
21402157
#[derive(Debug, Clone, PartialEq)]
21412158
pub enum SystemPromptTransport<'a> {
21422159
/// Deliver as a bare top-level `systemPrompt` field.
21432160
Field(&'a str),
2161+
/// Deliver as `_meta.systemPrompt: text`.
2162+
PiMeta(&'a str),
21442163
/// Deliver as `_meta.systemPrompt: {"append": text}`.
21452164
ClaudeMeta(&'a str),
21462165
}
@@ -3631,123 +3650,7 @@ mod tests {
36313650

36323651
// ── claude-agent-acp _meta.systemPrompt transport ─────────────────────
36333652

3634-
#[tokio::test]
3635-
async fn session_new_full_sends_claude_meta_system_prompt_when_claude_meta_transport() {
3636-
// When ClaudeMeta transport is requested, the prompt must appear as
3637-
// _meta.systemPrompt: {"append": text} — never as a bare systemPrompt field.
3638-
let script = r#"
3639-
read -t 2 _init
3640-
echo '{"jsonrpc":"2.0","id":0,"result":{"protocolVersion":1,"agentCapabilities":{}}}'
3641-
read -t 2 REQ
3642-
echo '{"jsonrpc":"2.0","id":1,"result":{"sessionId":"ses_claude","_receivedRequest":'"$REQ"'}}'
3643-
sleep 1
3644-
"#;
3645-
let mut client = spawn_script(script).await;
3646-
client
3647-
.initialize()
3648-
.await
3649-
.expect("initialize should succeed");
3650-
3651-
let resp = client
3652-
.session_new_full(
3653-
"/tmp",
3654-
vec![],
3655-
Some(SystemPromptTransport::ClaudeMeta("Be concise")),
3656-
None,
3657-
)
3658-
.await
3659-
.expect("session_new_full should succeed");
3660-
3661-
let received = &resp.raw["_receivedRequest"];
3662-
assert!(
3663-
received["params"].get("systemPrompt").is_none(),
3664-
"bare systemPrompt must not be present for ClaudeMeta transport"
3665-
);
3666-
assert_eq!(
3667-
received["params"]["_meta"]["systemPrompt"]["append"].as_str(),
3668-
Some("Be concise"),
3669-
"_meta.systemPrompt.append must carry the prompt text"
3670-
);
3671-
}
3672-
3673-
#[tokio::test]
3674-
async fn session_new_full_merges_claude_meta_and_session_title_into_single_meta_object() {
3675-
// Both ClaudeMeta prompt and session_title must coexist under _meta —
3676-
// the prompt must not clobber sessionTitle or vice versa.
3677-
let script = r#"
3678-
read -t 2 _init
3679-
echo '{"jsonrpc":"2.0","id":0,"result":{"protocolVersion":1,"agentCapabilities":{}}}'
3680-
read -t 2 REQ
3681-
echo '{"jsonrpc":"2.0","id":1,"result":{"sessionId":"ses_merged","_receivedRequest":'"$REQ"'}}'
3682-
sleep 1
3683-
"#;
3684-
let mut client = spawn_script(script).await;
3685-
client
3686-
.initialize()
3687-
.await
3688-
.expect("initialize should succeed");
3689-
3690-
let resp = client
3691-
.session_new_full(
3692-
"/tmp",
3693-
vec![],
3694-
Some(SystemPromptTransport::ClaudeMeta("Be concise")),
3695-
Some("Fizz · #buzz-dev"),
3696-
)
3697-
.await
3698-
.expect("session_new_full should succeed");
3699-
3700-
let received = &resp.raw["_receivedRequest"];
3701-
assert_eq!(
3702-
received["params"]["_meta"]["systemPrompt"]["append"].as_str(),
3703-
Some("Be concise"),
3704-
"_meta.systemPrompt.append must be present"
3705-
);
3706-
assert_eq!(
3707-
received["params"]["_meta"]["sessionTitle"].as_str(),
3708-
Some("Fizz · #buzz-dev"),
3709-
"_meta.sessionTitle must be present alongside systemPrompt"
3710-
);
3711-
}
3712-
3713-
// ── Goose-native steer scaffold (PR follow-up to #1160) ──────────────
3714-
3715-
/// Helper: spawn an inert `cat` subprocess so we have a real AcpClient
3716-
/// to drive `handle_session_update` against. `cat` never writes back,
3717-
/// which is fine — these tests don't read from the agent, they just
3718-
/// feed JSON into the parser.
3719-
async fn spawn_inert_client() -> AcpClient {
3720-
AcpClient::spawn("cat", &[], &[], false)
3721-
.await
3722-
.expect("spawn cat as inert client")
3723-
}
3724-
3725-
/// Build a `session/update` JSON-RPC notification carrying a
3726-
/// `session_info_update` with the given `_meta.goose.activeRunId` value.
3727-
/// Pass `None` to omit the `activeRunId` field entirely.
3728-
///
3729-
/// `_meta` is nested inside the `update` object (per the ACP
3730-
/// `SessionInfoUpdate` schema), matching what goose and buzz-agent
3731-
/// emit on the wire.
3732-
fn session_info_update_msg(active_run_id: Option<serde_json::Value>) -> serde_json::Value {
3733-
let mut goose = serde_json::Map::new();
3734-
if let Some(v) = active_run_id {
3735-
goose.insert("activeRunId".to_string(), v);
3736-
}
3737-
let mut meta = serde_json::Map::new();
3738-
meta.insert("goose".to_string(), serde_json::Value::Object(goose));
3739-
serde_json::json!({
3740-
"jsonrpc": "2.0",
3741-
"method": "session/update",
3742-
"params": {
3743-
"sessionId": "test-session",
3744-
"update": {
3745-
"sessionUpdate": "session_info_update",
3746-
"_meta": serde_json::Value::Object(meta),
3747-
},
3748-
}
3749-
})
3750-
}
3653+
include!("acp/system_prompt_tests.rs");
37513654

37523655
#[tokio::test]
37533656
async fn active_run_id_sets_on_string() {

0 commit comments

Comments
 (0)