Skip to content

Commit 448baee

Browse files
wpfleger96npub1mn7jgtj4w2pd0g0zeuhxsa6jy6p0rewxz4kujt98my82ahfmp72sxjexk7
andauthored
feat(teams): unify team model, snapshot sharing, and PNG memory parity (#1846)
Signed-off-by: Will Pfleger <[email protected]> Co-authored-by: npub1mn7jgtj4w2pd0g0zeuhxsa6jy6p0rewxz4kujt98my82ahfmp72sxjexk7 <dcfd242e557282d7a1e2cf2e6877522682f1e5c6156dc92ca7d90eaedd3b0f95@sprout-oss.stage.blox.sqprod.co>
1 parent 37bc962 commit 448baee

89 files changed

Lines changed: 4433 additions & 6130 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.

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

Lines changed: 17 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -422,14 +422,9 @@ pub struct CliArgs {
422422
#[arg(long, env = "BUZZ_ACP_ALLOWED_RESPOND_TO", value_delimiter = ',')]
423423
pub allowed_respond_to: Option<Vec<String>>,
424424

425-
/// Path to a persona pack directory. Used with --persona-name to configure
426-
/// the agent from a .persona.md pack instead of CLI flags.
427-
#[arg(long, env = "BUZZ_ACP_PERSONA_PACK")]
428-
pub persona_pack: Option<PathBuf>,
429-
430-
/// Name of the persona within the pack to use. Required when --persona-pack is set.
431-
#[arg(long, env = "BUZZ_ACP_PERSONA_NAME")]
432-
pub persona_name: Option<String>,
425+
/// Team-owned instructions layered after `[System]` and before agent memory.
426+
#[arg(long, env = "BUZZ_ACP_TEAM_INSTRUCTIONS")]
427+
pub team_instructions: Option<String>,
433428

434429
/// Publish encrypted ACP observer frames over the relay.
435430
#[arg(long, env = "BUZZ_ACP_RELAY_OBSERVER", default_value_t = false)]
@@ -462,6 +457,8 @@ pub struct Config {
462457
pub turn_liveness_secs: u64,
463458
pub heartbeat_prompt: Option<String>,
464459
pub system_prompt: Option<String>,
460+
/// Team-owned instructions layered separately from the agent system prompt.
461+
pub team_instructions: Option<String>,
465462
pub initial_message: Option<String>,
466463
pub subscribe_mode: SubscribeMode,
467464
pub dedup_mode: DedupMode,
@@ -705,7 +702,7 @@ impl Config {
705702
.replace_range(.., &"0".repeat(args.private_key.len()));
706703
args.private_key.clear();
707704

708-
let mut system_prompt = if let Some(text) = args.system_prompt {
705+
let system_prompt = if let Some(text) = args.system_prompt {
709706
Some(text)
710707
} else if let Some(ref path) = args.system_prompt_file {
711708
Some(std::fs::read_to_string(path)?)
@@ -902,52 +899,10 @@ impl Config {
902899
Vec::new()
903900
};
904901

905-
//
906-
// Precedence: CLI/env args > persona values > built-in defaults.
907-
// Persona fills in what's missing. Explicit flags always win.
908-
let (persona_system_prompt, persona_model, mut persona_env_vars) =
909-
match (&args.persona_pack, &args.persona_name) {
910-
(Some(pack_dir), Some(name)) => {
911-
let pack = buzz_persona::resolve::resolve_pack(pack_dir).map_err(|e| {
912-
ConfigError::ConfigFile(format!(
913-
"failed to resolve pack {}: {e}",
914-
pack_dir.display()
915-
))
916-
})?;
917-
let persona = pack
918-
.personas
919-
.into_iter()
920-
.find(|p| p.name == *name)
921-
.ok_or_else(|| {
922-
ConfigError::ConfigFile(format!(
923-
"persona '{name}' not found in pack {}",
924-
pack_dir.display()
925-
))
926-
})?;
927-
(
928-
Some(persona.system_prompt),
929-
persona.model,
930-
persona.runtime_env_vars,
931-
)
932-
}
933-
(Some(_), None) => {
934-
return Err(ConfigError::ConfigFile(
935-
"--persona-pack requires --persona-name".into(),
936-
));
937-
}
938-
(None, Some(_)) => {
939-
return Err(ConfigError::ConfigFile(
940-
"--persona-name requires --persona-pack".into(),
941-
));
942-
}
943-
(None, None) => (None, None, vec![]),
944-
};
945-
946-
// Apply persona defaults: CLI/env wins, persona fills gaps.
947-
if system_prompt.is_none() {
948-
system_prompt = persona_system_prompt;
949-
}
950-
let model = args.model.or(persona_model);
902+
// Spawned desktop agents now carry a complete instance snapshot. Team
903+
// instructions arrive independently so they can be layered at runtime.
904+
let mut persona_env_vars = Vec::new();
905+
let model = args.model;
951906

952907
// Inject CODEX_CONFIG so the @agentclientprotocol/codex-acp adapter (1.x)
953908
// opens the Seatbelt network sandbox for buzz-cli (an MCP subprocess). No-op
@@ -975,6 +930,12 @@ impl Config {
975930
turn_liveness_secs,
976931
heartbeat_prompt,
977932
system_prompt,
933+
team_instructions: args
934+
.team_instructions
935+
.as_deref()
936+
.map(str::trim)
937+
.filter(|value| !value.is_empty())
938+
.map(str::to_string),
978939
initial_message: args.initial_message,
979940
subscribe_mode: args.subscribe,
980941
dedup_mode: args.dedup,
@@ -1346,6 +1307,7 @@ mod tests {
13461307
turn_liveness_secs: 10,
13471308
heartbeat_prompt: None,
13481309
system_prompt: None,
1310+
team_instructions: None,
13491311
initial_message: None,
13501312
subscribe_mode: mode,
13511313
dedup_mode: DedupMode::Queue,

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1399,6 +1399,7 @@ async fn tokio_main() -> Result<()> {
13991399
turn_liveness_interval: Duration::from_secs(config.turn_liveness_secs),
14001400
dedup_mode: config.dedup_mode,
14011401
system_prompt: config.system_prompt.clone(),
1402+
team_instructions: config.team_instructions.clone(),
14021403
base_prompt: if config.no_base_prompt {
14031404
None
14041405
} else if let Some(content) = base_prompt_content {
@@ -3881,6 +3882,7 @@ mod build_mcp_servers_tests {
38813882
turn_liveness_secs: 10,
38823883
heartbeat_prompt: None,
38833884
system_prompt: None,
3885+
team_instructions: None,
38843886
initial_message: None,
38853887
subscribe_mode: config::SubscribeMode::All,
38863888
dedup_mode: config::DedupMode::Queue,
@@ -4045,6 +4047,7 @@ mod error_outcome_emission_tests {
40454047
turn_liveness_secs: 10,
40464048
heartbeat_prompt: None,
40474049
system_prompt: None,
4050+
team_instructions: None,
40484051
initial_message: None,
40494052
subscribe_mode: config::SubscribeMode::All,
40504053
dedup_mode: config::DedupMode::Queue,

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

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,7 @@ pub struct PromptContext {
379379
pub turn_liveness_interval: Duration,
380380
pub dedup_mode: DedupMode,
381381
pub system_prompt: Option<String>,
382+
pub team_instructions: Option<String>,
382383
pub heartbeat_prompt: Option<String>,
383384
/// Base prompt content, or `None` if `--no-base-prompt` was passed.
384385
///
@@ -694,7 +695,10 @@ async fn create_session_and_apply_model(
694695
let combined_system_prompt: Option<String> = if agent.protocol_version >= 2 {
695696
with_canvas(
696697
with_core(
697-
framed_system_prompt(&ctx.cwd, ctx.base_prompt, ctx.system_prompt.as_deref()),
698+
with_team(
699+
framed_system_prompt(&ctx.cwd, ctx.base_prompt, ctx.system_prompt.as_deref()),
700+
ctx.team_instructions.as_deref(),
701+
),
698702
agent_core,
699703
),
700704
agent_canvas,
@@ -1027,6 +1031,21 @@ fn workspace_section(cwd: &str) -> Option<String> {
10271031
}
10281032
}
10291033

1034+
/// Append the team-owned instruction section after `[System]` and before core memory.
1035+
fn with_team(prompt: Option<String>, instructions: Option<&str>) -> Option<String> {
1036+
let instructions = instructions
1037+
.map(str::trim)
1038+
.filter(|value| !value.is_empty());
1039+
match (prompt, instructions) {
1040+
(Some(prompt), Some(instructions)) => {
1041+
Some(format!("{prompt}\n\n[Team Instructions]\n{instructions}"))
1042+
}
1043+
(None, Some(instructions)) => Some(format!("[Team Instructions]\n{instructions}")),
1044+
(Some(prompt), None) => Some(prompt),
1045+
(None, None) => None,
1046+
}
1047+
}
1048+
10301049
/// Append the agent's core memory section onto the framed system prompt.
10311050
///
10321051
/// Core already carries its own `[Agent Memory — core]` header from
@@ -1552,6 +1571,7 @@ pub async fn run_prompt_task(
15521571
has_system_prompt_support: agent.protocol_version >= 2,
15531572
base_prompt: ctx.base_prompt,
15541573
system_prompt: ctx.system_prompt.as_deref(),
1574+
team_instructions: ctx.team_instructions.as_deref(),
15551575
agent_canvas: agent_canvas.as_deref(),
15561576
},
15571577
)
@@ -4527,6 +4547,7 @@ mod tests {
45274547
turn_liveness_interval: Duration::ZERO,
45284548
dedup_mode: DedupMode::Drop,
45294549
system_prompt: None,
4550+
team_instructions: None,
45304551
heartbeat_prompt: None,
45314552
base_prompt: None,
45324553
cwd: ".".to_string(),

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1327,6 +1327,8 @@ pub struct FormatPromptArgs<'a> {
13271327
pub base_prompt: Option<&'a str>,
13281328
/// System prompt content for legacy agents (protocol_version < 2).
13291329
pub system_prompt: Option<&'a str>,
1330+
/// Team instructions for legacy agents, rendered after `[System]`.
1331+
pub team_instructions: Option<&'a str>,
13301332
/// Rendered `[Channel Canvas]` metadata section for legacy agents.
13311333
///
13321334
/// For modern agents (protocol_version >= 2) the section is delivered via
@@ -1395,6 +1397,13 @@ pub fn format_prompt(batch: &FlushBatch, args: &FormatPromptArgs<'_>) -> Vec<Str
13951397
if let Some(sp) = args.system_prompt {
13961398
sections.push(format!("[System]\n{sp}"));
13971399
}
1400+
if let Some(team) = args
1401+
.team_instructions
1402+
.map(str::trim)
1403+
.filter(|value| !value.is_empty())
1404+
{
1405+
sections.push(format!("[Team Instructions]\n{team}"));
1406+
}
13981407
}
13991408

14001409
// NIP-AE agent core memory (rendered by `engram_fetch::build_core_section`).

‎crates/buzz-persona/src/resolve.rs‎

Lines changed: 12 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,10 @@ pub struct ResolvedPersona {
2828
pub avatar: Option<String>,
2929
pub version: String,
3030

31-
// → Config.system_prompt (persona body + pack_instructions)
31+
// → Config.system_prompt (persona body only)
3232
pub system_prompt: String,
33+
/// Pack-owned instructions kept separate for the team model migration.
34+
pub pack_instructions: Option<String>,
3335

3436
// → Config.model (plain model ID, post-split)
3537
pub model: Option<String>,
@@ -195,7 +197,11 @@ fn resolve_one_persona(
195197
pack_instructions: Option<&str>,
196198
shared_mcp: Option<&serde_json::Value>,
197199
) -> ResolvedPersona {
198-
let system_prompt = compose_prompt(&lp.prompt, pack_instructions);
200+
let system_prompt = lp.prompt.clone();
201+
let pack_instructions = pack_instructions
202+
.map(str::trim)
203+
.filter(|instructions| !instructions.is_empty())
204+
.map(str::to_string);
199205

200206
// Split "provider:model-id" into separate fields (V3 contract).
201207
let (llm_provider, model) = match lp.model.as_deref() {
@@ -228,6 +234,7 @@ fn resolve_one_persona(
228234
avatar: lp.avatar.clone(),
229235
version,
230236
system_prompt,
237+
pack_instructions,
231238
model,
232239
llm_provider,
233240
runtime: lp.runtime.clone(),
@@ -244,16 +251,6 @@ fn resolve_one_persona(
244251
}
245252
}
246253

247-
/// Compose the effective system prompt: persona body + pack instructions.
248-
fn compose_prompt(persona_prompt: &str, pack_instructions: Option<&str>) -> String {
249-
match pack_instructions {
250-
Some(instructions) if !instructions.trim().is_empty() => {
251-
format!("{persona_prompt}\n\n---\n# Team Instructions\n{instructions}")
252-
}
253-
_ => persona_prompt.to_owned(),
254-
}
255-
}
256-
257254
/// Convert `TriggersData` to `ResolvedTriggers`.
258255
fn resolve_triggers(rt: Option<&TriggersData>) -> ResolvedTriggers {
259256
match rt {
@@ -407,26 +404,6 @@ mod tests {
407404

408405
use crate::merge::{HooksData, TriggersData};
409406

410-
#[test]
411-
fn compose_prompt_body_only() {
412-
let result = compose_prompt("You are a bot.", None);
413-
assert_eq!(result, "You are a bot.");
414-
}
415-
416-
#[test]
417-
fn compose_prompt_with_instructions() {
418-
let result = compose_prompt("You are a bot.", Some("Follow the rules."));
419-
assert!(result.starts_with("You are a bot."));
420-
assert!(result.contains("# Team Instructions"));
421-
assert!(result.contains("Follow the rules."));
422-
}
423-
424-
#[test]
425-
fn compose_prompt_empty_instructions_ignored() {
426-
let result = compose_prompt("You are a bot.", Some(" "));
427-
assert_eq!(result, "You are a bot.");
428-
}
429-
430407
#[test]
431408
fn triggers_from_triggers_data() {
432409
let data = TriggersData {
@@ -708,10 +685,9 @@ mod tests {
708685
let pack = resolve_pack(dir).unwrap();
709686
let p = &pack.personas[0];
710687

711-
// Prompt composed with instructions
712-
assert!(p.system_prompt.contains("You are Bot."));
713-
assert!(p.system_prompt.contains("# Team Instructions"));
714-
assert!(p.system_prompt.contains("Always be helpful."));
688+
// Persona body kept separate from pack instructions.
689+
assert_eq!(p.system_prompt, "You are Bot.\n");
690+
assert_eq!(p.pack_instructions.as_deref(), Some("Always be helpful."));
715691

716692
// Model split into separate fields (V3 contract)
717693
assert_eq!(p.model.as_deref(), Some("claude-sonnet-4-20250514"));

‎crates/buzz-persona/tests/integration.rs‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -420,18 +420,20 @@ fn resolve_full_pipeline() {
420420
assert_eq!(lep.llm_provider.as_deref(), Some("anthropic"));
421421
assert_eq!(lep.model.as_deref(), Some("claude-sonnet-4-20250514"));
422422

423-
// System prompt composed: persona body + pack instructions
423+
// System prompt is persona body only; pack instructions stay separate.
424424
assert!(
425425
pip.system_prompt.contains("You are Pip"),
426426
"pip prompt should contain persona body"
427427
);
428428
assert!(
429-
pip.system_prompt.contains("Be helpful"),
430-
"pip prompt should contain pack instructions"
429+
!pip.system_prompt.contains("Be helpful"),
430+
"pip prompt should not contain pack instructions"
431431
);
432432
assert!(
433-
pip.system_prompt.contains("Team Instructions"),
434-
"pip prompt should contain instructions header"
433+
pip.pack_instructions
434+
.as_deref()
435+
.is_some_and(|instructions| instructions.contains("Be helpful")),
436+
"pip.pack_instructions should carry the pack instructions"
435437
);
436438

437439
// Temperature inherited from defaults

‎desktop/playwright.config.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ export default defineConfig({
123123
"**/tokens.spec.ts",
124124
"**/persona-env-vars.spec.ts",
125125
"**/persona-sync.spec.ts",
126+
"**/team-snapshot.spec.ts",
126127
"**/mesh-compute.spec.ts",
127128
"**/parity-ancestor-island.spec.ts",
128129
],

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

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ const overrides = new Map([
107107
["src-tauri/src/managed_agents/nest.rs", 704],
108108
// keyring-dev-isolation: agent key migration added copy_agent_keys_between_stores
109109
// and load_readonly support; file grew past 1000 default. Queued to split.
110-
["src-tauri/src/managed_agents/storage.rs", 1325],
110+
// +7 for try_delete_agent_key result-returning seam (snapshot-import rollback).
111+
["src-tauri/src/managed_agents/storage.rs", 1335],
111112
// harness-persona-sync: persona-runtime resolution threaded into the spawn
112113
// path here. Load-bearing feature growth; queued to split in the resolver
113114
// unify refactor followup. +26 for resolve_effective_prompt_model_provider
@@ -164,7 +165,9 @@ const overrides = new Map([
164165
// setup-mode requirements. The Windows-only requirement and serialization
165166
// test add eight lines; split remains queued with the existing file debt.
166167
// Windows Doctor install fix: cli_install_commands_windows field added to test stubs.
167-
["src-tauri/src/managed_agents/readiness.rs", 1764],
168+
// team-instructions-first-class: ManagedAgentRecord fixture gains the new
169+
// team_id field (+1 line).
170+
["src-tauri/src/managed_agents/readiness.rs", 1765],
168171
// applyWorkspace reposDir parameter plus the validateReposDir binding,
169172
// threaded through Tauri invokes for configurable repos_dir, plus the
170173
// harness-persona-sync `harnessOverride` create-input bit — load-bearing
@@ -197,7 +200,9 @@ const overrides = new Map([
197200
// RawInstallRuntimeResult + fromRawInstallRuntimeResult mapper (+2).
198201
// Git Bash Doctor discovery adds the raw Tauri response and its camelCase
199202
// mapper. This is the existing API boundary; split remains queued.
200-
["src/shared/api/tauri.ts", 1304],
203+
// team-instructions-first-class: createManagedAgent Tauri bridge threads the
204+
// new teamId input through to the backend (+1 line).
205+
["src/shared/api/tauri.ts", 1305],
201206
// doctor-npm-eacces-preflight: hint field added to InstallStepResult (+1 line).
202207
// codex-acp-package-swap: "adapter_outdated" variant added to AcpAvailabilityStatus (+1 line).
203208
// doctor-install-reliability: AuthStatus tagged union + nodeRequired/authStatus/
@@ -208,7 +213,11 @@ const overrides = new Map([
208213
// Git Bash prerequisite payload adds four fields to the shared Tauri API
209214
// contract. This is the canonical type location; split remains queued.
210215
// signout-wipe: resetFailed field added to Identity type (+6 lines).
211-
["src/shared/api/types.ts", 1044],
216+
// team-instructions-first-class: CreateManagedAgentInput.teamId (+2, incl.
217+
// doc comment) and AgentTeam/CreateTeamInput/UpdateTeamInput.instructions
218+
// (+3) — the new team-id spawn link and the runtime-layered instructions
219+
// field.
220+
["src/shared/api/types.ts", 1047],
212221
// readiness-gate: PersonaDialog.tsx threads computeLocalModeGate +
213222
// requiredCredentialEnvKeys + RequiredFieldLabel so the "New agent" dialog
214223
// shows required markers and credential amber rows (parity with
@@ -280,7 +289,9 @@ const overrides = new Map([
280289
// candidates, cli_install_commands_for_os PowerShell selection, login_shell_path
281290
// None regression, .cmd shim resolution, no-git-bash error hint.
282291
// +32: deterministic .cmd resolver + no-registry + install_shell_from tests.
283-
["src-tauri/src/managed_agents/discovery/tests.rs", 1270],
292+
// team-instructions-first-class: record_with test fixture gained the new
293+
// ManagedAgentRecord.team_id field (+1 line) alongside persona_team_dir.
294+
["src-tauri/src/managed_agents/discovery/tests.rs", 1271],
284295
// identity-import-keyring: the identity resolution state machine's behavioral
285296
// matrix (46 tests over FakeIdentityStore — probe × marker × file cells,
286297
// adoption / read-back-corruption / marker-failure arms, recovery-mode

0 commit comments

Comments
 (0)