Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions crates/agent-controller/src/app_agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1273,9 +1273,7 @@ impl AppAgents {
return Ok(());
};
// Under the keys lock, a joining row is no Join under way.
let last = !rows
.iter()
.any(|other| other.relay != relay && other.live(pubkey, &other.relay));
let last = last_membership(&rows, pubkey, relay);
let unfinished: Vec<&AppAgent> = rows
.iter()
.filter(|other| {
Expand Down Expand Up @@ -1304,6 +1302,12 @@ impl AppAgents {
Ok(())
})
}
/// Whether removing it from the community at `relay` leaves it in none:
Comment thread
wpfleger96 marked this conversation as resolved.
Resolved
/// as `remove` decides, so unfinished joins elsewhere don't count.
pub fn is_last_membership(&self, pubkey: &str, relay: &str) -> Result<bool> {
let relay = canonical_relay(relay)?;
Ok(last_membership(&self.list()?, pubkey, &relay))
}
/// Deletes every key it still has, as an erase that removes agents does
/// before the rows go with app data. Absence is success, so it repeats safely.
pub fn delete_keys(&self, credentials: &dyn Credentials) -> Result<()> {
Expand All @@ -1324,6 +1328,12 @@ impl AppAgents {
}
}

fn last_membership(rows: &[AppAgent], pubkey: &str, relay: &str) -> bool {
!rows
.iter()
.any(|other| other.relay != relay && other.live(pubkey, &other.relay))
}

/// One copy of the app taking an agent out of a community: see
/// `AppAgents::hold_removal`. Dropping it lets go.
#[derive(Debug)]
Expand Down
27 changes: 27 additions & 0 deletions crates/agent-controller/src/app_agent/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1876,3 +1876,30 @@ fn a_forced_profile_republishes_a_current_one_with_its_saved_owner_proof() {
assert_eq!(event["tags"], serde_json::json!([saved]));
assert!(event["created_at"].as_u64() > first["created_at"].as_u64());
}

#[test]
fn the_last_membership_ignores_unfinished_joins_and_counts_live_ones() {
const OTHER: &str = "wss://other.example";
let dir = tempfile::tempdir().unwrap();
let credentials = Memory::default();
let (agents, agent) = created(dir.path(), &credentials);
assert!(agents.is_last_membership(&agent.pubkey, RELAY).unwrap());
agents
.update(|rows| {
rows.push(AppAgent {
relay: OTHER.into(),
home: Some(RELAY.into()),
joining: true,
..agent.clone()
});
Ok(())
})
.unwrap();
// As `remove` decides: an unfinished join is no community it stays in.
assert!(agents.is_last_membership(&agent.pubkey, RELAY).unwrap());
agents
.join(&agent.pubkey, RELAY, OTHER, None, &credentials)
.unwrap();
assert!(!agents.is_last_membership(&agent.pubkey, RELAY).unwrap());
assert!(!agents.is_last_membership(&agent.pubkey, OTHER).unwrap());
}
25 changes: 24 additions & 1 deletion crates/dev-credential-helper/src/policy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
/// Bumped when the request format or the set of served items changes.
/// `just desktop me` installs one helper per protocol, so checkouts on
/// different protocols each keep a helper that understands them.
pub const PROTOCOL: u32 = 1;
pub const PROTOCOL: u32 = 2;

/// Largest value read or written, in either direction.
#[cfg_attr(not(target_os = "macos"), allow(dead_code))]
Expand Down Expand Up @@ -131,6 +131,8 @@ pub fn allowed(operation: Operation, service: &str, account: &str) -> bool {
account == "typesafe"
}
"xyz.block.buzz.desktop.claude-api-key.debug" => account == "anthropic",
// Each local agent's own environment variables, by its pubkey.
"xyz.block.buzz.desktop.agent-env.agent.debug" => hex64(account),
"xyz.block.buzz.desktop.external-app-pairing.v1" => hex64(account),
_ => false,
}
Expand Down Expand Up @@ -222,6 +224,21 @@ mod tests {
"xyz.block.buzz.desktop.claude-api-key.debug",
"anthropic",
),
(
Replace,
"xyz.block.buzz.desktop.agent-env.agent.debug",
hex.as_str(),
),
(
Read,
"xyz.block.buzz.desktop.agent-env.agent.debug",
hex.as_str(),
),
(
Delete,
"xyz.block.buzz.desktop.agent-env.agent.debug",
hex.as_str(),
),
(
Replace,
"xyz.block.buzz.desktop.external-app-pairing.v1",
Expand Down Expand Up @@ -278,6 +295,12 @@ mod tests {
),
(Read, "xyz.block.buzz.desktop.jev-key", "typesafe"),
(Read, "xyz.block.buzz.desktop.claude-api-key", "anthropic"),
(Read, "xyz.block.buzz.desktop.agent-env.agent", hex.as_str()),
(
Read,
"xyz.block.buzz.desktop.agent-env.agent.debug",
upper.as_str(),
),
(
Read,
"xyz.block.buzz.desktop.claude-api-key.debug",
Expand Down
13 changes: 13 additions & 0 deletions docs/buzz-help.md
Original file line number Diff line number Diff line change
Expand Up @@ -1774,6 +1774,19 @@ If an agent reports incompatible synced settings, choose the **Previous Versions
the team. Teams made before teams synced move to their agents' community
automatically once it syncs teams; a team whose agents are in different
communities stays on this Mac.
- **Settings → Agent details → Environment variables** sets variables one
local Claude Code, Codex, Goose or Pi agent starts with, such as API keys.
They're kept in the OS credential store on this computer, never synced, and
values aren't shown again after saving. Protected agents don't get them, and
a harness's own variables win, except that a saved `ANTHROPIC_API_KEY` wins
over the shared Claude key. Names that choose a model, provider or
endpoint, `PATH`, and `BUZZ_*`/`NOSTR_*` are refused. A save applies to agent
processes started afterward; running ones keep the old list until
**Restart agent**, which stops only that agent's processes in every
community so its next message starts them with the saved list. It asks
first, and it's refused while the agent is answering or in a call. A Codex or Pi agent
with its own list runs in its own process. Removing the agent from its last
community on this computer deletes its list.
- Each Claude agent running on this computer keeps its own `claude` process for
each active conversation. While an unprotected one runs here, Buzz also keeps
one shared process ready for the next new conversation. Each of these starts
Expand Down
2 changes: 2 additions & 0 deletions src-tauri/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,8 @@ fn main() {
"app_agent_remember",
"app_agent_claim",
"app_agent_release",
"agent_env_status",
"agent_env_set",
"claude_api_key_status",
"claude_api_key_set",
"claude_api_key_clear",
Expand Down
2 changes: 2 additions & 0 deletions src-tauri/capabilities/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@
"allow-app-agent-remember",
"allow-app-agent-claim",
"allow-app-agent-release",
"allow-agent-env-status",
"allow-agent-env-set",
"allow-claude-api-key-status",
"allow-claude-api-key-set",
"allow-claude-api-key-clear",
Expand Down
Loading