Skip to content

Commit 5621006

Browse files
authored
refactor: move agent Git bootstrap into ACP harness (#7819)
discovered in #7742 (comment) ## Summary Goose uses its native shell, so it bypassed the Git identity and signing setup inside `buzz-dev-mcp`. Agent commits could use the host Git identity, while MCP shells had a separate config. This moves Git setup into `buzz-acp`, where both paths receive the same agent identity, Nostr signer, and relay-scoped credential helper. Before: ```text Buzz Desktop └─ buzz-acp ← Desktop supplied relay Git authentication ├─ Goose → native shell ← no agent Git author or signing setup └─ Buzz Agent └─ buzz-dev-mcp └─ shell ← MCP created the keyfile and Git signing config ``` After: ```text Buzz Desktop or Sprig └─ buzz-acp ← owns the keyfile, identity, signing, and scoped credentials ├─ Goose → native shell ← inherits the complete Git environment └─ Buzz Agent └─ buzz-dev-mcp └─ shell ← receives the same Git environment via mcpServers[].env ``` The harness keeps the signing key in a private temporary file and removes it on normal exit, startup failure, and graceful termination. It composes inherited `GIT_CONFIG_*` entries, forwards the complete block to MCP servers, and bundles the helpers through the ACP multicall entrypoint. For standard `buzz-acp` launches, Desktop and Sprig no longer write Git config. A custom Desktop ACP command bypasses the harness, so Desktop preserves its prior relay-scoped credential helper for that supported override. This changes Git settings for every ACP runtime. The startup signal path also changes so a termination during adapter initialization removes the keyfile. The temporary file can remain after SIGKILL or a machine crash. ### Related issue Related: #6177 covers stricter commit identity enforcement and touches the same Git paths. That PR and this one need to be reconciled before either lands. No issue was found for this runtime bootstrap gap. ### Testing - Ran the ignored `git_runtime_tests` with real Goose 1.50.0 and Buzz Agent ACP sessions. `real_goose_native_git_shell` passed again on this PR branch with `BUZZ_TEST_BIN_DIR` pointing to built binaries. Goose made a signed commit and tag through its native shell; Buzz Agent did the same through its MCP shell. Both verified signatures, identity, credential scoping, and keyfile cleanup. - Built the Linux Sprig image and ran `scripts/test-sprig-image.sh buzz-sprig:acp-git-bootstrap`. The container made and verified a signed commit and tag, then confirmed keyfile removal after SIGTERM. - `just ci` passed on the original branch. After rebasing onto `main` and addressing review feedback, the ACP Git bootstrap integration tests, focused desktop smoke test, custom-command regression test, formatting, and ACP/Desktop Clippy passed. The pre-push hook hit two timing-sensitive ACP deadline tests under parallel load; both passed alone and the complete ACP package passed serially (964 library, 2 Git bootstrap, 9 pool lifecycle tests). The push used `--no-verify` after those checks; GitHub CI is rerunning on the new head. - Under injected `BUZZ_ACP_ALLOWED_RESPOND_TO`, `BUZZ_ACP_LAZY_POOL`, and `BUZZ_ACP_IDLE_POOL_SLEEP`, the clean-env serial package command in `crates/buzz-acp/TESTING.md` passed: 964 active library tests, 2 Git bootstrap tests, and 9 pool lifecycle tests. Both named Databricks OAuth tests passed locally; another reviewer reproduced their environment-specific failures on `main`. - No authenticated relay clone or push was run. The local probes used disposable repositories and did not contact a relay. Generated with Codex --------- Signed-off-by: Salman Mohammed <[email protected]>
1 parent 4142d2b commit 5621006

23 files changed

Lines changed: 1346 additions & 751 deletions

File tree

‎.github/workflows/sprig.yml‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
name: Sprig
22

33
# Builds and publishes Sprig — one deploy-anywhere Linux multicall binary for:
4-
# buzz-acp ACP harness that bridges Buzz events to the LLM agent
4+
# buzz-acp ACP harness (multicall Git helpers) that bridges Buzz events to the LLM agent
55
# buzz-agent ACP-compliant agent (spawns MCP, calls LLMs)
6-
# buzz-dev-mcp Developer MCP server (multicall: rg, tree, buzz,
7-
# git-credential-nostr, git-sign-nostr)
6+
# buzz-dev-mcp Developer MCP server (multicall: rg, tree, buzz)
87
#
98
# Targets: x86_64-unknown-linux-musl and aarch64-unknown-linux-musl (static
109
# musl so the tarball runs on any modern Linux without libc surprises).

‎Cargo.lock‎

Lines changed: 4 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Dockerfile.sprig‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,7 @@ FROM alpine:3.22@sha256:14358309a308569c32bdc37e2e0e9694be33a9d99e68afb0f5ff33cc
2323

2424
RUN apk add --no-cache bash ca-certificates curl git \
2525
&& adduser -D -h /home/agent agent \
26-
&& install -d -o agent -g agent /workspace /home/agent \
27-
&& git config --system gpg.format x509 \
28-
&& git config --system gpg.x509.program /usr/local/bin/git-sign-nostr \
29-
&& git config --system commit.gpgSign true \
30-
&& git config --system tag.gpgSign true
26+
&& install -d -o agent -g agent /workspace /home/agent
3127

3228
COPY --from=builder --chmod=0755 /build/target/sprig/sprig /usr/local/bin/sprig
3329
COPY --chmod=0755 scripts/sprig-entrypoint.sh /usr/local/bin/sprig-entrypoint

‎crates/buzz-acp/Cargo.toml‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ buzz-core = { workspace = true }
2121
buzz-sdk = { workspace = true }
2222
buzz-persona = { path = "../buzz-persona" }
2323

24+
# Git multicall helpers and ephemeral key ownership
25+
git-credential-nostr = { path = "../git-credential-nostr" }
26+
git-sign-nostr = { path = "../git-sign-nostr" }
27+
tempfile = "3"
28+
zeroize = { workspace = true }
29+
2430
# Nostr
2531
nostr = { workspace = true }
2632

‎crates/buzz-acp/README.md‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,3 +355,25 @@ See the [root TESTING.md](../../TESTING.md) for the full integration testing gui
355355
## License
356356

357357
Apache-2.0
358+
359+
## Git in coding runtimes
360+
361+
The harness configures agent authorship, Nostr commit/tag signing, and Git
362+
credentials for native runtime shells and declared MCP servers. Author names
363+
use `BUZZ_ACP_DISPLAY_NAME` (sanitized, with an npub fallback); email retains
364+
the public key and relay host. Inherited author/committer name and email
365+
overrides are cleared so native shells use the same agent attribution as MCP.
366+
Credential helpers are scoped to the selected
367+
relay's `/git` URLs. Existing `GIT_CONFIG_*` entries are preserved before the
368+
harness's overrides, and the complete block is forwarded in `mcpServers[].env`
369+
for agents that clear their MCP child environment.
370+
371+
`buzz-acp` includes both Git helpers as multicall personalities, so standalone
372+
and remote launches need no separate signer installation. The harness creates
373+
private helper aliases and a 0600 keyfile, keeps them alive across adapter
374+
respawns, and removes them when it exits normally or completes graceful
375+
shutdown. As with other temporary files, SIGKILL or a machine crash cannot run
376+
cleanup. `BUZZ_PRIVATE_KEY` remains available to the Buzz CLI; adapters do not
377+
receive the redundant `NOSTR_PRIVATE_KEY` variable. No global Git config is
378+
modified. Standalone `buzz-dev-mcp` supplies utility aliases only; a non-Buzz
379+
ACP client must supply any desired Git environment itself.

‎crates/buzz-acp/TESTING.md‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,41 @@ Make sure `pi` and `buzz-pi-acp` are on PATH, then restart Buzz.
2121
cargo test -p buzz-acp
2222
```
2323

24+
Managed agent sessions may already export harness options. Clear them when
25+
running the package suite: three CLI parsing tests assert the unset defaults,
26+
and inherited values would change the inputs those tests exercise. Running the
27+
package serially also avoids scheduling flakes in existing short-deadline tests.
28+
29+
```sh
30+
env -u BUZZ_ACP_ALLOWED_RESPOND_TO \
31+
-u BUZZ_ACP_LAZY_POOL \
32+
-u BUZZ_ACP_IDLE_POOL_SLEEP \
33+
cargo test -p buzz-acp -- --test-threads=1
34+
```
35+
2436
Run the ignored real-adapter test with a built fork checkout:
2537

2638
```sh
2739
BUZZ_TEST_PI_ACP=/absolute/buzz-pi-acp/dist/index.js \
2840
cargo test -p buzz-acp real_pi_preserves -- --ignored
2941
```
42+
43+
## Git bootstrap
44+
45+
`cargo test -p buzz-acp --test git_bootstrap` starts the actual harness with a
46+
probe adapter, runs real signed commits/tags and scoped credential resolution,
47+
and verifies key cleanup on startup failure and SIGTERM. No relay is contacted.
48+
49+
To exercise the real runtime boundaries on Unix:
50+
51+
```sh
52+
cargo build -p buzz-acp -p buzz-agent -p buzz-dev-mcp
53+
BUZZ_TEST_BIN_DIR="$PWD/target/debug" cargo test -p buzz-acp git_runtime_tests -- --ignored --nocapture
54+
```
55+
56+
The Buzz Agent test uses a deterministic local OpenAI-compatible response to
57+
invoke the actual MCP shell. The Goose test requires an installed, configured
58+
Goose and uses its provider to invoke the native developer shell. Both operate
59+
only on temporary local repositories, verify commit/tag signatures and identity,
60+
check unrelated-remote credential scoping, and assert keyfile removal. They do
61+
not replace authenticated relay clone/push/readback testing.

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,32 @@ impl AcpClient {
528528
cmd.env("CODEX_CONFIG", merged);
529529
}
530530

531+
// The harness composes the entire Git config block once. It must replace
532+
// inherited counts/PATH rather than mixing two independently indexed blocks.
533+
for (name, value) in extra_env
534+
.iter()
535+
.filter(|(name, _)| crate::git::is_managed_env(name))
536+
{
537+
cmd.env(name, value);
538+
}
539+
// Git applies this older injection channel after GIT_CONFIG_COUNT.
540+
// Keeping it would let an ambient user.name or signing setting win
541+
// over the harness-owned agent identity in native shells.
542+
cmd.env_remove("GIT_CONFIG_PARAMETERS");
543+
cmd.env_remove("NOSTR_PRIVATE_KEY");
544+
if extra_env.iter().any(|(name, _)| name == "GIT_CONFIG_COUNT") {
545+
// Native shells inherit these overrides, while buzz-agent clears
546+
// them for MCP. Let both paths use the harness's agent identity.
547+
for name in [
548+
"GIT_AUTHOR_NAME",
549+
"GIT_AUTHOR_EMAIL",
550+
"GIT_COMMITTER_NAME",
551+
"GIT_COMMITTER_EMAIL",
552+
] {
553+
cmd.env_remove(name);
554+
}
555+
}
556+
531557
// Spawn the agent in its own process group so SIGKILL doesn't propagate
532558
// to the harness's own process group on Unix.
533559
// tokio::process::Command::process_group is a stable tokio API (no extra imports needed).

0 commit comments

Comments
 (0)