Skip to content

Commit f0173c0

Browse files
7a9c8f0147a0755c5d499320bda5535cd5014715e52fb7757dfe3dadde1cef09@buzz.block.builderlab.xyznpub1re830n24qhgstulznk5dxdluccspxkxxdq643lm4q3zwwwjgsuqqmcmdrm
authored andcommitted
fix(desktop): lock internal agents to owner access
Co-authored-by: npub102wg7q285p64ch2fjvstmf2ntn2sz3c4u5hmwatalc76mhsuauysftjtfj <7a9c8f0147a0755c5d499320bda5535cd5014715e52fb7757dfe3dadde1cef09@buzz.block.builderlab.xyz> Signed-off-by: npub102wg7q285p64ch2fjvstmf2ntn2sz3c4u5hmwatalc76mhsuauysftjtfj <7a9c8f0147a0755c5d499320bda5535cd5014715e52fb7757dfe3dadde1cef09@buzz.block.builderlab.xyz>
1 parent 03f645e commit f0173c0

23 files changed

Lines changed: 427 additions & 85 deletions

File tree

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,9 @@ const overrides = new Map([
8080
// ratcheting 1443 -> 1295. Queued to split further in the A2 fold.
8181
// global-agent-config: resolve_deploy_model_provider + visibility exports
8282
// add ~40 lines on top of the 1A.1 ratchet. Queued to split.
83-
["src-tauri/src/commands/agents.rs", 1340],
83+
// internal-owner-only: create-time policy normalization adds a small
84+
// security boundary while keeping OSS respond-to behavior unchanged.
85+
["src-tauri/src/commands/agents.rs", 1349],
8486
// agent-lifecycle-fixes: cascade-delete in delete_persona restructured into
8587
// 3-phase (stage/stop/commit) + commit_cascade_agents injectable helper for
8688
// retry-safety. Load-bearing reviewer-required change; queued to split.
@@ -118,7 +120,8 @@ const overrides = new Map([
118120
// receipts (write_agent_runtime_receipt atomic JSON + remove/read_all
119121
// helpers) replace the pubkey-keyed PID file, plus the hashed pair-scoped
120122
// runtime log path. Load-bearing crash-recovery surface; queued to split.
121-
["src-tauri/src/managed_agents/storage.rs", 1383],
123+
// internal-owner-only: persistence choke point normalizes local agent access.
124+
["src-tauri/src/managed_agents/storage.rs", 1386],
122125
// harness-persona-sync: persona-runtime resolution threaded into the spawn
123126
// path here. Load-bearing feature growth; queued to split in the resolver
124127
// unify refactor followup. +26 for resolve_effective_prompt_model_provider
@@ -131,7 +134,9 @@ const overrides = new Map([
131134
// record_provider param + applies persona_field_with_record_fallback. +5 lines.
132135
// global-agent-config: spawn_agent_child loads global config and merges as
133136
// lowest env layer (+8 lines). Queued to split.
134-
["src-tauri/src/managed_agents/runtime.rs", 2216],
137+
// internal-owner-only: runtime authorization normalization protects stale
138+
// or hand-edited records before spawning an internal managed agent.
139+
["src-tauri/src/managed_agents/runtime.rs", 2228],
135140
// config-bridge setup-payload env-boundary fix adds readiness wiring in
136141
// spawn_agent_child; load-bearing security fix, queued to split.
137142
["src-tauri/src/managed_agents/config_bridge/reader.rs", 1016],
@@ -541,7 +546,9 @@ const overrides = new Map([
541546
// isRuntimeAutoSeededRef tracking for edit-mode seeding (Fizz shows models);
542547
// runtimeSupportsLlmProviderSelection guard on discovery provider (codex fix);
543548
// hideProviderIds computation for Databricks v1 gate. Queued to split.
544-
["src/features/agents/ui/AgentDefinitionDialog.tsx", 1035],
549+
// internal-owner-only: queries the backend policy so the internal build can
550+
// hide definition-level access controls while OSS keeps them configurable.
551+
["src/features/agents/ui/AgentDefinitionDialog.tsx", 1043],
545552
]);
546553

547554
await runFileSizeCheck({

‎desktop/src-tauri/build.rs‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,15 @@ fn main() {
1515
println!("cargo:rerun-if-env-changed=BUZZ_BUILD_RELAY_RECONNECT_CMD");
1616
println!("cargo:rerun-if-env-changed=BUZZ_BUILD_OBSERVER_ARCHIVE_DEFAULT");
1717
println!("cargo:rerun-if-env-changed=BUZZ_BUILD_AGENT_METRIC_ARCHIVE_DEFAULT");
18+
println!("cargo:rerun-if-env-changed=BUZZ_BUILD_INTERNAL");
1819
println!("cargo:rustc-check-cfg=cfg(buzz_updater_enabled)");
1920

21+
// Explicit distribution identity. Internal packaging sets this presence-only
22+
// marker; OSS/custom builds remain public regardless of baked defaults.
23+
if std::env::var("BUZZ_BUILD_INTERNAL").is_ok() {
24+
println!("cargo:rustc-env=BUZZ_DESKTOP_BUILD_INTERNAL=1");
25+
}
26+
2027
if let Ok(relay_url) = std::env::var("BUZZ_RELAY_URL") {
2128
println!("cargo:rustc-env=BUZZ_DESKTOP_BUILD_RELAY_URL={relay_url}");
2229
}

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

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -767,6 +767,12 @@ async fn discover_databricks_models(
767767
}))
768768
}
769769

770+
/// Return whether this build enforces owner-only managed-agent access.
771+
#[tauri::command]
772+
pub fn agent_access_owner_only() -> bool {
773+
crate::managed_agents::internal_build()
774+
}
775+
770776
/// Update mutable fields on an existing managed agent record.
771777
///
772778
/// Does NOT auto-restart the agent. Runtime config changes (system prompt,
@@ -874,28 +880,11 @@ pub async fn update_managed_agent(
874880
record.relay_mesh = Some(crate::managed_agents::RelayMeshConfig { model_ref });
875881
}
876882

877-
// Inbound author gate: merge patch onto current values, then validate
878-
// the merged state. This lets a single update switch to Allowlist AND
879-
// supply pubkeys atomically.
880-
let prospective_mode = input.respond_to.unwrap_or(record.respond_to);
881-
let prospective_allowlist = match input.respond_to_allowlist.as_ref() {
882-
Some(list) => crate::managed_agents::validate_respond_to_allowlist(list)?,
883-
None => record.respond_to_allowlist.clone(),
884-
};
885-
if prospective_mode == crate::managed_agents::RespondTo::Allowlist
886-
&& prospective_allowlist.is_empty()
887-
{
888-
return Err(
889-
"respond-to mode 'allowlist' requires at least one pubkey in the allowlist"
890-
.to_string(),
891-
);
892-
}
893-
record.respond_to = prospective_mode;
894-
// Preserve the persisted allowlist across mode toggles — only replace
895-
// when the caller explicitly supplied a new list.
896-
if input.respond_to_allowlist.is_some() {
897-
record.respond_to_allowlist = prospective_allowlist;
898-
}
883+
crate::managed_agents::apply_update_access(
884+
record,
885+
input.respond_to,
886+
input.respond_to_allowlist.as_deref(),
887+
)?;
899888

900889
record.updated_at = now_iso();
901890

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

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -578,22 +578,12 @@ pub async fn create_managed_agent(
578578
}
579579
crate::managed_agents::validate_user_env_keys(&input.env_vars)?;
580580

581-
// Validate & normalize the respond-to allowlist BEFORE any side effects.
582-
// The harness has its own validator (buzz-acp/src/config.rs) but we want
583-
// to catch malformed input at the boundary so the agent never tries to
584-
// start with a list that will crash it on launch. The mode/allowlist
585-
// pairing (and the definition-default fallback) is resolved later at the
586-
// mint site via `resolve_mint_behavioral_defaults`, where the linked
587-
// definition is in hand.
588-
let respond_to_allowlist =
589-
crate::managed_agents::validate_respond_to_allowlist(&input.respond_to_allowlist)?;
590-
if input.respond_to == Some(crate::managed_agents::RespondTo::Allowlist)
591-
&& respond_to_allowlist.is_empty()
592-
{
593-
return Err(
594-
"respond-to mode 'allowlist' requires at least one pubkey in the allowlist".to_string(),
595-
);
596-
}
581+
let (requested_respond_to, respond_to_allowlist) =
582+
crate::managed_agents::resolve_create_access(
583+
&input.backend,
584+
input.respond_to,
585+
&input.respond_to_allowlist,
586+
)?;
597587

598588
// Snapshot the workspace owner pubkey for the legacy-record auth_tag
599589
// fallback. Computed outside the records lock to keep lock ordering simple.
@@ -817,7 +807,7 @@ pub async fn create_managed_agent(
817807
// point for definition behavioral strings — fails loudly on a bad
818808
// mode/range instead of minting an agent the author didn't describe.
819809
let minted = crate::managed_agents::resolve_mint_behavioral_defaults(
820-
input.respond_to,
810+
requested_respond_to,
821811
respond_to_allowlist.clone(),
822812
input.parallelism,
823813
linked_persona.as_ref(),

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ pub async fn create_persona(
9898
updated_at: now,
9999
};
100100
apply_persona_behavior(&mut persona, input.behavior)?;
101+
crate::managed_agents::normalize_definition_access(&mut persona);
101102
personas.push(persona.clone());
102103
save_personas(&app, &personas)?;
103104
retain_persona_pending(&app, &state, &persona);
@@ -197,6 +198,7 @@ pub async fn update_persona(
197198
persona.env_vars = env_vars;
198199
}
199200
apply_persona_behavior(persona, input.behavior)?;
201+
crate::managed_agents::normalize_definition_access(persona);
200202
persona.updated_at = now_iso();
201203

202204
let result = persona.clone();
@@ -815,9 +817,14 @@ fn apply_inbound_persona(personas: &mut Vec<AgentDefinition>, inbound: AgentDefi
815817
local.respond_to = inbound.respond_to;
816818
local.respond_to_allowlist = inbound.respond_to_allowlist;
817819
local.parallelism = inbound.parallelism;
820+
crate::managed_agents::normalize_definition_access(local);
818821
local.updated_at = inbound.updated_at;
819822
}
820-
None => personas.push(inbound),
823+
None => {
824+
let mut inbound = inbound;
825+
crate::managed_agents::normalize_definition_access(&mut inbound);
826+
personas.push(inbound);
827+
}
821828
}
822829
}
823830

@@ -859,6 +866,7 @@ fn apply_inbound_managed_agent(
859866
local.parallelism = inbound.parallelism;
860867
local.respond_to = inbound.respond_to;
861868
local.respond_to_allowlist = inbound.respond_to_allowlist;
869+
crate::managed_agents::normalize_managed_agent_access(local);
862870
}
863871
}
864872

‎desktop/src-tauri/src/commands/personas/snapshot/import.rs‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ pub async fn confirm_agent_snapshot_import(
393393
let persona_id = uuid::Uuid::new_v4().to_string();
394394

395395
// Build persona from snapshot definition.
396-
let persona = AgentDefinition {
396+
let mut persona = AgentDefinition {
397397
id: persona_id.clone(),
398398
display_name: display_name.clone(),
399399
avatar_url: effective_avatar.clone(),
@@ -417,6 +417,7 @@ pub async fn confirm_agent_snapshot_import(
417417
created_at: now.clone(),
418418
updated_at: now.clone(),
419419
};
420+
crate::managed_agents::normalize_definition_access(&mut persona);
420421

421422
personas.push(persona.clone());
422423
save_personas(&app, &personas)?;
@@ -426,7 +427,7 @@ pub async fn confirm_agent_snapshot_import(
426427

427428
// Build the managed agent record — no machine-local commands, no
428429
// secrets, no lineage from the snapshot.
429-
let record = ManagedAgentRecord {
430+
let mut record = ManagedAgentRecord {
430431
pubkey: pubkey.clone(),
431432
name: display_name.clone(),
432433
display_name: None,
@@ -485,6 +486,7 @@ pub async fn confirm_agent_snapshot_import(
485486
runtime: snapshot.definition.runtime.clone(),
486487
name_pool: snapshot.definition.name_pool.clone(),
487488
};
489+
crate::managed_agents::normalize_managed_agent_access(&mut record);
488490

489491
records.push(record.clone());
490492
save_managed_agents(&app, &records)?;

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ fn definition_from_snapshot(
118118
let respond_to = (behavior.respond_to != crate::managed_agents::RespondTo::default())
119119
.then(|| behavior.respond_to.as_str().to_string());
120120

121-
Ok(AgentDefinition {
121+
let mut definition = AgentDefinition {
122122
id: Uuid::new_v4().to_string(),
123123
display_name: member.profile.display_name.trim().to_string(),
124124
avatar_url: effective_avatar(member),
@@ -137,7 +137,9 @@ fn definition_from_snapshot(
137137
parallelism: behavior.parallelism,
138138
created_at: now.to_string(),
139139
updated_at: now.to_string(),
140-
})
140+
};
141+
crate::managed_agents::normalize_definition_access(&mut definition);
142+
Ok(definition)
141143
}
142144

143145
pub(crate) fn build_import_definitions(
@@ -547,7 +549,7 @@ pub async fn confirm_team_snapshot_import(
547549
};
548550

549551
// Build the ManagedAgentRecord for this member.
550-
let record = ManagedAgentRecord {
552+
let mut record = ManagedAgentRecord {
551553
pubkey: pubkey.clone(),
552554
name: display_name.clone(),
553555
display_name: None,
@@ -608,6 +610,7 @@ pub async fn confirm_team_snapshot_import(
608610
runtime: member.definition.runtime.clone(),
609611
name_pool: member.definition.name_pool.clone(),
610612
};
613+
crate::managed_agents::normalize_managed_agent_access(&mut record);
611614

612615
minted.push(MintedMember {
613616
definition,

‎desktop/src-tauri/src/lib.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -787,6 +787,7 @@ pub fn run() {
787787
get_managed_agent_log,
788788
get_agent_models,
789789
discover_agent_models,
790+
agent_access_owner_only,
790791
get_agent_config_surface,
791792
get_runtime_file_config,
792793
get_baked_build_env_keys,

0 commit comments

Comments
 (0)