refactor(teams): unify team model and kill directory-backed team layer#1846
Open
wpfleger96 wants to merge 3 commits into
Open
refactor(teams): unify team model and kill directory-backed team layer#1846wpfleger96 wants to merge 3 commits into
wpfleger96 wants to merge 3 commits into
Conversation
Collapse two parallel team systems (directory-backed packs and JSON-store teams) into one unified model where team instructions are a first-class field layered at runtime, and snapshots replace directory-based sharing. The pack/directory layer baked team instructions into each member's system_prompt at resolve time, creating N identical copies and requiring reverse-parsing to recover the raw body. The unified model stores instructions once on TeamRecord and layers them as a discrete [Team Instructions] section at spawn — consistent with how base, core memory, and canvas are already layered. Key changes: - team_id binding on ManagedAgentRecord for instance→team resolution - instructions field on TeamRecord with relay kind:30176 projection - [Team Instructions] runtime section in both modern and legacy paths - Boot migration: lifts instructions.md, backfills team_id, detaches directory-backed teams (clears source_dir/is_symlink/symlink_target/ version/persona_team_dir/persona_name_in_team) - Team snapshot import mints per-member keypairs + ManagedAgentRecords with two-phase all-or-none atomicity and memory restore - Deletes: writeback module, persona_card, 5 old Tauri commands, pack-ZIP parsing, directory install/sync, TeamImportDialog, TeamImportUpdateDialog, and all associated test/state/plan files
…, and dead code T4: migration detach now uses atomic_write_json_restricted / atomic_write_json instead of raw std::fs::write, ensuring a mid-write crash leaves the prior valid JSON intact and the idempotency gate open for retry. T5: team snapshot import Phase 3 snapshots the raw agent store before writes and rolls back on partial failure — save_managed_agents or save_teams errors restore the pre-import state. retain_*_pending calls moved after all writes succeed to avoid spurious in-memory state on rollback. F4: removed unreachable legacy import path from TeamDialog.tsx (file picker, drag listeners, import state, handlers) and deleted teamDialogImportState module + tests. Deleted migrate_packs_to_teams_* husk tests that reimplemented deleted production logic. Deleted #[cfg(test)] filter_derived_provider_model_env_vars wrapper and its tests. Updated stale team-pack suppression comment in runtime.rs.
The import store phase now snapshots both files (or notes them absent) before writing, cleans minted keyring entries on failure via a new result-returning try_delete_agent_key seam, and aggregates rollback errors alongside the original write failure. Process death between commits is explicitly outside contract. Also: delete stale packs-migration test husk and section header, replace duplicate idempotency test with write-seam interruption test, fix event_sync.rs prerequisite comment.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Collapses two parallel team systems — directory-backed packs and JSON-store teams — into one unified model where team instructions are a first-class field layered at runtime, and snapshots replace directory-based team sharing.
What changed
Unified team model with first-class instructions
TeamRecord.instructions: Option<String>replaces the old pattern of baking pack instructions into each member'ssystem_promptviacompose_prompt.team_id: Option<String>onManagedAgentRecordbinds deployed instances to their team, resolving the multi-team-persona ambiguity (a persona in 3 teams deployed 3× = 3 instances, 3team_ids).instructionsfield is projected onto the relay kind:30176 event, synced inbound, and wired through create/update request types +TeamDialogeditor UI.Runtime
[Team Instructions]sectionwith_team()inpool.rsinserts a[Team Instructions]section between[System]and[Agent Memory — core], consistent with how base, core memory, and canvas are already layered.protocol_version >= 2,pool.rs) and legacy (user-message sections,queue.rs) prompt paths carry it.BUZZ_ACP_TEAM_INSTRUCTIONSenv var, resolved from the instance'steam_id→ localTeamRecord.instructionsat spawn. Editing team instructions rehashes → restart (same discipline aseffective_spawn_prompt).Boot migration (T4)
detach_directory_backed_teamsstep (afterbackfill_standalone_agents): liftsinstructions.mdtext toTeamRecord.instructions, backfillsteam_idonManagedAgentRecords, clearssource_dir/is_symlink/symlink_target/version/persona_team_dir/persona_name_in_team.Team snapshot parity (T5)
TeamSnapshotMetacarriesinstructions; export accepts caller-suppliedMemoryLevel(PNG format forcesNoneper the shared-image plaintext guard).confirm_team_snapshot_importmints per-member keypairs +ManagedAgentRecords with two-phase all-or-none atomicity: validate all → mint keypairs/auth-tags in memory → single store-lock write of allAgentDefinitions +ManagedAgentRecords (withteam_id) +TeamRecord→ profile sync → memory restore with per-member error reporting. Failing member N leaves zero local records.Deleted: entire directory-backed team file layer (T6)
writeback.rsmodule (1152 lines),persona_card.rs, 5 Tauri commands (install_team_from_directory,sync_team_directory,pick_team_directory,export_team_to_json,parse_team_file),parse_team_from_pack_zip, directory install/sync helpers, old migration functions (migrate_packs_to_teams,reconcile_persona_team_dirs,sync_team_personas).TeamImportDialog,TeamImportUpdateDialog,teamImportPlan,teamImportUpdateState+ tests, olduseTeamActionshandlers (export/import/install/sync/reveal), oldtauriTeamsbindings,TeamsSectionfile-import UI (drag zone, Export/Sync/Reveal/Install buttons).BUZZ_ACP_PERSONA_PACK/BUZZ_ACP_PERSONA_NAMEenv vars +config.rspack re-resolve branch +spawn_hash.rspack-fallback suppression exception.User-facing behavior change
Directory-backed team packs (installed from local directories or imported from
.zipfiles) are superseded by the unified team model. Existing directory-backed teams are silently migrated on next app launch — they become standard relay-synced teams with their instructions preserved as a first-class field. The directory install, sync, and export-to-flat-JSON workflows are removed; team sharing is now exclusively via.team.json/.team.pngsnapshots (matching the agent snapshot flow).