Skip to content

Commit a35771f

Browse files
feat(desktop): refine agent catalog sharing (#2439)
## Summary - add custom-agent catalog sharing and hide built-ins from discovery - let owners publish later catalog updates from Share or while saving edits — the save always persists locally, and the publish reports `published` or `queued` (flushed automatically once the relay is reachable again) - preserve agent type, model, and runtime across snapshot import/export - simplify agent and team entry points and tighten catalog layout - migrate the legacy global retention queue into the owner's active scope so pending catalog publishes survive the upgrade - keep the agent list and edits usable in recovery mode by degrading to unshared projections when scope resolution or the retention DB fails - track catalog provenance on copied personas, so adding an already-added foreign agent resolves to the existing copy instead of creating a duplicate - scope inbound persona events to the community relay they arrived on - page the catalog read past the relay's 1,000-row query clamp - unify the share dialog's memory-level choice into a single "What's included" selector that drives both DM-send and copy-link delivery (all six combinations preserved), group the delivery rows above the option rows, and label the catalog toggle "Not shared" / "Shared" - keep emoji avatars on catalog entries — they persist as inline percent-encoded SVG, which the catalog projection's http(s)-only URL guard used to drop, so a shared agent showed initials instead of its avatar - drop the "Active in communities" card from Agents settings, superseded by the per-channel runtime controls in the members sidebar ## Screenshots ### Agent actions ![Agent actions](https://raw.githubusercontent.com/block/buzz/4643581cd0882d8b101b04e3d8be290ea7e39f08/pr-2439--01-agent-menu.png) ### Team avatar stack ![Team avatar stack](https://raw.githubusercontent.com/block/buzz/4643581cd0882d8b101b04e3d8be290ea7e39f08/pr-2439--02-team-menu.png) ### Catalog sharing ![Catalog sharing](https://raw.githubusercontent.com/block/buzz/648d6eaf6df7d4daa5b7375948ed221f723793d6/pr-2439--03-share-to-catalog.png) ### Publish while editing ![Publish while editing](https://raw.githubusercontent.com/block/buzz/bd4eb473ff456f6e665173054dc5a0f764594d1e/pr-2439--01-edit-agent-publish-updates.png) ### Publish from Share ![Publish from Share](https://raw.githubusercontent.com/block/buzz/648d6eaf6df7d4daa5b7375948ed221f723793d6/pr-2439--02-share-dialog-publish-updates.png) ### Catalog details ![Catalog details](https://raw.githubusercontent.com/block/buzz/4643581cd0882d8b101b04e3d8be290ea7e39f08/pr-2439--04-agent-catalog.png) --------- Signed-off-by: kenny lopez <[email protected]> Signed-off-by: Will Pfleger <[email protected]> Co-authored-by: Will Pfleger <[email protected]>
1 parent 3afa129 commit a35771f

102 files changed

Lines changed: 6135 additions & 1986 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎desktop/scripts/check-file-sizes.mjs‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ const overrides = new Map([
9898
// 3-phase (stage/stop/commit) + commit_cascade_agents injectable helper for
9999
// retry-safety. Load-bearing reviewer-required change; queued to split.
100100
// Consolidation removed the legacy persona-card import/export codecs.
101-
["src-tauri/src/commands/personas/mod.rs", 984],
102101
// #1418 read-path fix: get_thread_replies' blocker fix (shared TIMELINE_KINDS
103102
// const + build_thread_replies_filter helper, mirroring the channel sibling so
104103
// the two p-gate filters can't drift) plus two guard unit tests. The file was
@@ -257,7 +256,11 @@ const overrides = new Map([
257256
// (#2680) to indicate runtimes that need a separate CLI install.
258257
// +6: ManagedAgent.runtime record-level pin + JSDoc so the harness delete
259258
// confirmation can count referencing agents (review fix for #2773).
260-
["src/shared/api/types.ts", 1058],
259+
// +21: CatalogSourceCoordinate + the `catalogSource` fields on AgentPersona
260+
// and CreatePersonaInput. The coordinate is the only identifier a catalog
261+
// copy keeps, so it is what stops the catalog re-offering "Add" for an
262+
// already-added foreign entry. Queued to split.
263+
["src/shared/api/types.ts", 1079],
261264
// harness-persona-sync feature growth, queued to split in the resolver-unify
262265
// refactor followup. discovery.rs is dominated by the new test module
263266
// (the effective_agent_command / divergent / create-time override matrix);
@@ -398,7 +401,9 @@ const overrides = new Map([
398401
// the full (major, minor, patch) triple instead of a bare major, plus
399402
// below-the-floor and uncomparable-version (partial / prerelease) classification
400403
// regressions for the fail-closed parse.
401-
["src-tauri/src/managed_agents/discovery/tests.rs", 1922],
404+
// +2 (1922 -> 1924): the AgentDefinition and ManagedAgentRecord fixtures each
405+
// set the new mandatory `catalog_source` field.
406+
["src-tauri/src/managed_agents/discovery/tests.rs", 1924],
402407
// identity-import-keyring: the identity resolution state machine's behavioral
403408
// matrix (46 tests over FakeIdentityStore — probe × marker × file cells,
404409
// adoption / read-back-corruption / marker-failure arms, recovery-mode
@@ -593,7 +598,9 @@ const overrides = new Map([
593598
// computing had_* so stale materialized snapshot bytes can never be tagged
594599
// BuzzExplicit and shadow the definition/global fallthrough; the dead
595600
// persona-model re-tag branch replaced; two new regression tests added.
596-
["src-tauri/src/commands/agent_config.rs", 1110],
601+
// +2 (1110 -> 1112): the agent_record and persona_with_model test fixtures
602+
// each set the new mandatory `catalog_source` field.
603+
["src-tauri/src/commands/agent_config.rs", 1112],
597604
// codex-install-auto-restart review-fixes: should_restart_after_install
598605
// takes pid_alive:bool (pure predicate, no OS-dependent call); 3 racy
599606
// cache tests replaced with 6 pure availability_drift predicate tests;

‎desktop/src-tauri/src/commands/agent_config.rs‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ use crate::{
2121

2222
/// Subset of the goose file config exposed to the frontend for gate evaluation.
2323
///
24-
/// Only the fields the dialog gate needs — not the full `RuntimeConfigSurface`.
25-
/// The gate uses this to know which requirements are already satisfied in the
24+
/// Only the fields the dialog gate needs. This tracks which requirements are already satisfied in the
2625
/// harness config file, so it can show "Set in goose config" rather than
2726
/// surfacing a false missing-key marker.
2827
#[derive(Debug, Serialize)]
@@ -685,8 +684,10 @@ mod tests {
685684
name_pool: Vec::new(),
686685
is_builtin: false,
687686
is_active: true,
687+
shared: false,
688688
source_team: None,
689689
source_team_persona_slug: None,
690+
catalog_source: None,
690691
definition_respond_to: None,
691692
definition_respond_to_allowlist: Vec::new(),
692693
definition_parallelism: None,
@@ -709,8 +710,10 @@ mod tests {
709710
name_pool: Vec::new(),
710711
is_builtin: false,
711712
is_active: true,
713+
shared: false,
712714
source_team: None,
713715
source_team_persona_slug: None,
716+
catalog_source: None,
714717
env_vars: Default::default(),
715718
respond_to: None,
716719
respond_to_allowlist: Vec::new(),

‎desktop/src-tauri/src/commands/agent_models_tests.rs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,8 +394,10 @@ fn model_discovery_ignores_stale_record_for_linked_agent() {
394394
name_pool: Vec::new(),
395395
is_builtin: false,
396396
is_active: true,
397+
shared: false,
397398
source_team: None,
398399
source_team_persona_slug: None,
400+
catalog_source: None,
399401
env_vars: BTreeMap::new(),
400402
respond_to: None,
401403
respond_to_allowlist: Vec::new(),

‎desktop/src-tauri/src/commands/agents.rs‎

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ use crate::{
66
managed_agents::{
77
build_managed_agent_summary, current_instance_id, discover_provider_candidates,
88
ensure_persona_is_active, find_managed_agent_mut, load_managed_agents, load_personas,
9-
load_teams, managed_agent_avatar_url, managed_agents_base_dir, normalize_agent_args,
10-
provider_deploy, resolve_provider_binary, save_managed_agents, start_managed_agent_process,
9+
load_teams, managed_agent_avatar_url, normalize_agent_args, provider_deploy,
10+
resolve_provider_binary, save_managed_agents, start_managed_agent_process,
1111
stop_managed_agent_process, stop_managed_agent_workspace_pair,
1212
sync_managed_agent_processes, try_regenerate_nest, validate_provider_config, BackendKind,
1313
CreateManagedAgentRequest, CreateManagedAgentResponse, ManagedAgentRecord,
@@ -18,8 +18,7 @@ use crate::{
1818
util::now_iso,
1919
};
2020

21-
/// Read the workspace owner's pubkey hex from app state without holding the
22-
/// lock for longer than necessary. Used to populate `BUZZ_ACP_AGENT_OWNER`
21+
/// Read the workspace owner pubkey without holding the lock. Used to populate `BUZZ_ACP_AGENT_OWNER`
2322
/// as a fallback for legacy agent records that have no NIP-OA `auth_tag`.
2423
pub(super) fn workspace_owner_hex(state: &AppState) -> Result<String, String> {
2524
let keys = state.keys.lock().map_err(|e| e.to_string())?;
@@ -48,12 +47,12 @@ pub(super) fn retain_managed_agent_pending(
4847
use crate::managed_agents::{reconcile::retain_agent_record, retention::open_retention_db};
4948

5049
let result = (|| -> Result<(), String> {
51-
let conn = open_retention_db(&managed_agents_base_dir(app)?.join("retention.db"))?;
52-
let keys = state.signing_keys()?;
50+
let scope = crate::managed_agents::retention::active_retention_scope(app, state)?;
51+
let conn = open_retention_db(&scope.db_path)?;
5352
// Shared engine with the boot-time reconcile: projection content diff
5453
// (no republish for runtime-only churn) + monotonic created_at bump
5554
// past the retained head (NIP-AP step 3).
56-
retain_agent_record(&conn, &keys, record).map(|_| ())
55+
retain_agent_record(&conn, &scope.owner_keys, record).map(|_| ())
5756
})();
5857
if let Err(e) = result {
5958
eprintln!("buzz-desktop: agent-retain: {e}");
@@ -89,15 +88,12 @@ pub(super) fn tombstone_managed_agent_pending(
8988
const KIND_DELETE: u32 = 5;
9089

9190
let result = (|| -> Result<(), String> {
92-
let (owner_pubkey, event) = {
93-
let keys = state.signing_keys()?;
94-
let owner_pubkey = keys.public_key().to_hex();
95-
let event = build_agent_delete(agent_pubkey, &owner_pubkey)?
96-
.sign_with_keys(&keys)
97-
.map_err(|e| format!("failed to sign managed-agent tombstone: {e}"))?;
98-
(owner_pubkey, event)
99-
};
100-
let conn = open_retention_db(&managed_agents_base_dir(app)?.join("retention.db"))?;
91+
let scope = crate::managed_agents::retention::active_retention_scope(app, state)?;
92+
let owner_pubkey = scope.owner_keys.public_key().to_hex();
93+
let event = build_agent_delete(agent_pubkey, &owner_pubkey)?
94+
.sign_with_keys(&scope.owner_keys)
95+
.map_err(|e| format!("failed to sign managed-agent tombstone: {e}"))?;
96+
let conn = open_retention_db(&scope.db_path)?;
10197
delete_retained_event(&conn, KIND_MANAGED_AGENT, &owner_pubkey, agent_pubkey)?;
10298
retain_event(
10399
&conn,
@@ -183,13 +179,10 @@ pub(super) fn archive_managed_agent_pending(app: &AppHandle, state: &AppState, a
183179
use nostr::JsonUtil;
184180

185181
let result = (|| -> Result<(), String> {
186-
let (owner_pubkey, event) = {
187-
let keys = state.signing_keys()?;
188-
let owner_pubkey = keys.public_key().to_hex();
189-
let event = build_agent_archive_request(&keys, agent_pubkey)?;
190-
(owner_pubkey, event)
191-
};
192-
let conn = open_retention_db(&managed_agents_base_dir(app)?.join("retention.db"))?;
182+
let scope = crate::managed_agents::retention::active_retention_scope(app, state)?;
183+
let owner_pubkey = scope.owner_keys.public_key().to_hex();
184+
let event = build_agent_archive_request(&scope.owner_keys, agent_pubkey)?;
185+
let conn = open_retention_db(&scope.db_path)?;
193186
retain_event(
194187
&conn,
195188
&RetainedEvent {
@@ -904,8 +897,10 @@ pub async fn create_managed_agent(
904897
name_pool: Vec::new(),
905898
is_builtin: false,
906899
is_active: true,
900+
shared: false,
907901
source_team: None,
908902
source_team_persona_slug: None,
903+
catalog_source: None,
909904
definition_respond_to: None,
910905
definition_respond_to_allowlist: Vec::new(),
911906
definition_parallelism: None,

‎desktop/src-tauri/src/commands/agents_tests.rs‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,10 @@ fn bare_agent_record(
5353
name_pool: vec![],
5454
is_builtin: false,
5555
is_active: true,
56+
shared: false,
5657
source_team: None,
5758
source_team_persona_slug: None,
59+
catalog_source: None,
5860
relay_mesh: None,
5961
auto_restart_on_config_change: false,
6062
definition_respond_to: None,
@@ -75,8 +77,10 @@ fn persona_record(id: &str, model: Option<&str>, provider: Option<&str>) -> Agen
7577
name_pool: vec![],
7678
is_builtin: false,
7779
is_active: true,
80+
shared: false,
7881
source_team: None,
7982
source_team_persona_slug: None,
83+
catalog_source: None,
8084
env_vars: BTreeMap::new(),
8185
respond_to: None,
8286
respond_to_allowlist: vec![],

‎desktop/src-tauri/src/commands/media_download.rs‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,7 @@ mod tests {
610610
version: FORMAT_VERSION,
611611
definition: AgentSnapshotDefinition {
612612
name: "test".to_string(),
613+
source_is_builtin: false,
613614
system_prompt: None,
614615
runtime: None,
615616
model: None,
@@ -659,6 +660,7 @@ mod tests {
659660
version: FORMAT_VERSION,
660661
definition: AgentSnapshotDefinition {
661662
name: "test".to_string(),
663+
source_is_builtin: false,
662664
system_prompt: None,
663665
runtime: None,
664666
model: None,
@@ -704,6 +706,7 @@ mod tests {
704706
version: FORMAT_VERSION,
705707
definition: AgentSnapshotDefinition {
706708
name: "test".to_string(),
709+
source_is_builtin: false,
707710
system_prompt: None,
708711
runtime: None,
709712
model: None,

‎desktop/src-tauri/src/commands/media_snapshot_png.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ mod tests {
158158
version: 1,
159159
definition: AgentSnapshotDefinition {
160160
name: "Tree Trunks".to_string(),
161+
source_is_builtin: false,
161162
system_prompt: Some("You are a helpful agent.".to_string()),
162163
runtime: Some("goose".to_string()),
163164
model: None,
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
//! The persona creation command surface, split from `mod.rs` (file-size cap)
2+
//! as the sibling of [`super::update`].
3+
4+
use tauri::AppHandle;
5+
use uuid::Uuid;
6+
7+
use crate::{
8+
app_state::AppState,
9+
managed_agents::{
10+
apply_persona_behavior, load_personas, save_personas, try_regenerate_nest, AgentDefinition,
11+
CatalogSource, CreatePersonaRequest,
12+
},
13+
util::now_iso,
14+
};
15+
16+
use super::{pending, retain_persona_pending, trim_optional, trim_required};
17+
18+
#[tauri::command]
19+
pub async fn create_persona(
20+
input: CreatePersonaRequest,
21+
app: AppHandle,
22+
) -> Result<AgentDefinition, String> {
23+
use tauri::Manager;
24+
tokio::task::spawn_blocking(move || {
25+
let state = app.state::<AppState>();
26+
let display_name = trim_required(&input.display_name, "Display name")?;
27+
// System prompt optional: core memory is auto-injected. Empty is valid.
28+
let system_prompt = input.system_prompt.trim().to_string();
29+
let avatar_url = trim_optional(input.avatar_url);
30+
let runtime = trim_optional(input.runtime);
31+
let model = trim_optional(input.model);
32+
let provider = trim_optional(input.provider);
33+
// Normalized before the store is touched: a coordinate that can't match
34+
// a publication is worse than no coordinate, because it silently
35+
// re-enables the duplicate add it exists to prevent.
36+
let catalog_source = input
37+
.catalog_source
38+
.map(CatalogSource::normalized)
39+
.transpose()?;
40+
let now = now_iso();
41+
let _store_guard = state
42+
.managed_agents_store_lock
43+
.lock()
44+
.map_err(|error| error.to_string())?;
45+
let mut personas = load_personas(&app)?;
46+
pending::project_active_persona_sharing(&app, &state, &mut personas);
47+
let name_pool: Vec<String> = input
48+
.name_pool
49+
.into_iter()
50+
.map(|s| s.trim().to_string())
51+
.filter(|s| !s.is_empty())
52+
.collect();
53+
crate::managed_agents::validate_user_env_keys(&input.env_vars)?;
54+
let mut persona = AgentDefinition {
55+
id: Uuid::new_v4().to_string(),
56+
display_name,
57+
avatar_url,
58+
system_prompt,
59+
runtime,
60+
model,
61+
provider,
62+
name_pool,
63+
is_builtin: false,
64+
is_active: true,
65+
shared: false,
66+
source_team: None,
67+
source_team_persona_slug: None,
68+
catalog_source,
69+
env_vars: input.env_vars,
70+
respond_to: None,
71+
respond_to_allowlist: Vec::new(),
72+
parallelism: None,
73+
created_at: now.clone(),
74+
updated_at: now,
75+
};
76+
apply_persona_behavior(&mut persona, input.behavior)?;
77+
personas.push(persona.clone());
78+
save_personas(&app, &personas)?;
79+
retain_persona_pending(&app, &state, &persona);
80+
try_regenerate_nest(&app);
81+
Ok(persona)
82+
})
83+
.await
84+
.map_err(|e| format!("spawn_blocking failed: {e}"))?
85+
}

‎desktop/src-tauri/src/commands/personas/delete_cascade_tests.rs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,10 @@ fn make_agent(
6161
name_pool: vec![],
6262
is_builtin: false,
6363
is_active: true,
64+
shared: false,
6465
source_team: None,
6566
source_team_persona_slug: None,
67+
catalog_source: None,
6668
relay_mesh: None,
6769
auto_restart_on_config_change: false,
6870
definition_respond_to: None,

0 commit comments

Comments
 (0)