@team-agent/installer 0.5.127 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -4
- package/README.zh.md +1 -1
- package/package.json +4 -8
- package/skills/team-agent/SKILL.md +41 -26
- package/skills/team-agent/command-coverage.json +170 -184
- package/skills/team-agent/docs/reference/team-agent-operator.md +66 -32
- package/skills/team-agent/references/recovery-runbook.md +1 -1
- package/skills/team-agent/references/team-agent-operator.md +66 -32
- package/templates/team_state.md +1 -1
- package/Cargo.lock +0 -1063
- package/Cargo.toml +0 -36
- package/crates/team-agent/Cargo.toml +0 -69
- package/crates/team-agent/src/app_server_test_support.rs +0 -258
- package/crates/team-agent/src/cli/adapters.rs +0 -1298
- package/crates/team-agent/src/cli/arguments.rs +0 -401
- package/crates/team-agent/src/cli/attach_app_server_leader.rs +0 -98
- package/crates/team-agent/src/cli/diagnose.rs +0 -1675
- package/crates/team-agent/src/cli/emit.rs +0 -2898
- package/crates/team-agent/src/cli/grok_slot.rs +0 -384
- package/crates/team-agent/src/cli/helpers.rs +0 -91
- package/crates/team-agent/src/cli/intent/runtime.rs +0 -1189
- package/crates/team-agent/src/cli/intent/runtime_tests.rs +0 -821
- package/crates/team-agent/src/cli/intent/tests.rs +0 -691
- package/crates/team-agent/src/cli/intent.rs +0 -664
- package/crates/team-agent/src/cli/leader.rs +0 -300
- package/crates/team-agent/src/cli/leader_prompt.rs +0 -261
- package/crates/team-agent/src/cli/leaders.rs +0 -418
- package/crates/team-agent/src/cli/mod.rs +0 -6528
- package/crates/team-agent/src/cli/models.rs +0 -449
- package/crates/team-agent/src/cli/named_address.rs +0 -1651
- package/crates/team-agent/src/cli/profile.rs +0 -342
- package/crates/team-agent/src/cli/route.rs +0 -212
- package/crates/team-agent/src/cli/send/coordinator.rs +0 -164
- package/crates/team-agent/src/cli/send/mailbox.rs +0 -145
- package/crates/team-agent/src/cli/send/persist.rs +0 -192
- package/crates/team-agent/src/cli/send/presentation.rs +0 -370
- package/crates/team-agent/src/cli/send/resolve.rs +0 -573
- package/crates/team-agent/src/cli/send.rs +0 -201
- package/crates/team-agent/src/cli/shutdown_socket.rs +0 -288
- package/crates/team-agent/src/cli/spec.rs +0 -159
- package/crates/team-agent/src/cli/status.rs +0 -280
- package/crates/team-agent/src/cli/status_port/agents.rs +0 -358
- package/crates/team-agent/src/cli/status_port/approvals.rs +0 -79
- package/crates/team-agent/src/cli/status_port/brief.rs +0 -2043
- package/crates/team-agent/src/cli/status_port/compact.rs +0 -240
- package/crates/team-agent/src/cli/status_port/format.rs +0 -146
- package/crates/team-agent/src/cli/status_port/inbox.rs +0 -62
- package/crates/team-agent/src/cli/status_port/runtime.rs +0 -197
- package/crates/team-agent/src/cli/status_port/snapshot.rs +0 -208
- package/crates/team-agent/src/cli/status_port/store.rs +0 -416
- package/crates/team-agent/src/cli/status_port/tests.rs +0 -90
- package/crates/team-agent/src/cli/status_port.rs +0 -92
- package/crates/team-agent/src/cli/tests/base.rs +0 -885
- package/crates/team-agent/src/cli/tests/divergence.rs +0 -518
- package/crates/team-agent/src/cli/tests/lane_c.rs +0 -453
- package/crates/team-agent/src/cli/tests/leader_watch.rs +0 -372
- package/crates/team-agent/src/cli/tests/main_preserved.rs +0 -430
- package/crates/team-agent/src/cli/tests/missing_subcommands.rs +0 -336
- package/crates/team-agent/src/cli/tests/mod.rs +0 -137
- package/crates/team-agent/src/cli/tests/named_address.rs +0 -760
- package/crates/team-agent/src/cli/tests/parser_safety.rs +0 -383
- package/crates/team-agent/src/cli/tests/run_delegation.rs +0 -481
- package/crates/team-agent/src/cli/tests/shutdown_kill_plan.rs +0 -2179
- package/crates/team-agent/src/cli/tests/status_brief.rs +0 -1514
- package/crates/team-agent/src/cli/tests/status_send.rs +0 -1091
- package/crates/team-agent/src/cli/tests/verb_install_skill.rs +0 -93
- package/crates/team-agent/src/cli/tests/verb_profile.rs +0 -392
- package/crates/team-agent/src/cli/triage.rs +0 -234
- package/crates/team-agent/src/cli/types.rs +0 -591
- package/crates/team-agent/src/codex_app_server.rs +0 -546
- package/crates/team-agent/src/communication_mode/mod.rs +0 -56
- package/crates/team-agent/src/compiler/tests.rs +0 -842
- package/crates/team-agent/src/compiler.rs +0 -691
- package/crates/team-agent/src/conpty/backend.rs +0 -829
- package/crates/team-agent/src/conpty/mod.rs +0 -33
- package/crates/team-agent/src/contract_runtime/backend.rs +0 -1610
- package/crates/team-agent/src/contract_runtime/commands.rs +0 -671
- package/crates/team-agent/src/contract_runtime/config.rs +0 -354
- package/crates/team-agent/src/contract_runtime/config_tests.rs +0 -56
- package/crates/team-agent/src/contract_runtime/discovery.rs +0 -438
- package/crates/team-agent/src/contract_runtime/fork.rs +0 -368
- package/crates/team-agent/src/contract_runtime/forward.rs +0 -288
- package/crates/team-agent/src/contract_runtime/framework.rs +0 -350
- package/crates/team-agent/src/contract_runtime/mcp.rs +0 -399
- package/crates/team-agent/src/contract_runtime/mod.rs +0 -17
- package/crates/team-agent/src/contract_runtime/prompt.rs +0 -216
- package/crates/team-agent/src/contract_runtime/pump.rs +0 -271
- package/crates/team-agent/src/contract_runtime/registry.rs +0 -589
- package/crates/team-agent/src/contract_runtime/workspace.rs +0 -228
- package/crates/team-agent/src/coordinator/backoff.rs +0 -741
- package/crates/team-agent/src/coordinator/conpty_shim.rs +0 -805
- package/crates/team-agent/src/coordinator/health.rs +0 -1185
- package/crates/team-agent/src/coordinator/mod.rs +0 -119
- package/crates/team-agent/src/coordinator/orphan.rs +0 -110
- package/crates/team-agent/src/coordinator/runtime_detectors.rs +0 -798
- package/crates/team-agent/src/coordinator/runtime_observation.rs +0 -84
- package/crates/team-agent/src/coordinator/steps/abnormal.rs +0 -2309
- package/crates/team-agent/src/coordinator/steps/delivery.rs +0 -15
- package/crates/team-agent/src/coordinator/steps/health_sync.rs +0 -15
- package/crates/team-agent/src/coordinator/steps/mod.rs +0 -126
- package/crates/team-agent/src/coordinator/steps/persist.rs +0 -15
- package/crates/team-agent/src/coordinator/steps/runtime_prompts.rs +0 -15
- package/crates/team-agent/src/coordinator/steps/session_gate.rs +0 -16
- package/crates/team-agent/src/coordinator/tests/a0_lostupdate.rs +0 -158
- package/crates/team-agent/src/coordinator/tests/abnormal.rs +0 -312
- package/crates/team-agent/src/coordinator/tests/api_error_recovery.rs +0 -338
- package/crates/team-agent/src/coordinator/tests/basics.rs +0 -211
- package/crates/team-agent/src/coordinator/tests/daemon.rs +0 -514
- package/crates/team-agent/src/coordinator/tests/energy.rs +0 -549
- package/crates/team-agent/src/coordinator/tests/health_sync.rs +0 -461
- package/crates/team-agent/src/coordinator/tests/main_preserved.rs +0 -186
- package/crates/team-agent/src/coordinator/tests/mod.rs +0 -295
- package/crates/team-agent/src/coordinator/tests/s3_bounded.rs +0 -207
- package/crates/team-agent/src/coordinator/tests/spine.rs +0 -308
- package/crates/team-agent/src/coordinator/tests/takeover.rs +0 -286
- package/crates/team-agent/src/coordinator/tests/tick_core.rs +0 -237
- package/crates/team-agent/src/coordinator/tick.rs +0 -3112
- package/crates/team-agent/src/coordinator/types.rs +0 -540
- package/crates/team-agent/src/db/agent_health_capture.rs +0 -126
- package/crates/team-agent/src/db/message_store.rs +0 -1585
- package/crates/team-agent/src/db/migration.rs +0 -984
- package/crates/team-agent/src/db/mod.rs +0 -26
- package/crates/team-agent/src/db/schema.rs +0 -663
- package/crates/team-agent/src/diagnose/comms.rs +0 -242
- package/crates/team-agent/src/diagnose/mod.rs +0 -44
- package/crates/team-agent/src/diagnose/orphans.rs +0 -889
- package/crates/team-agent/src/event_log.rs +0 -502
- package/crates/team-agent/src/fake_worker.rs +0 -303
- package/crates/team-agent/src/kill_audit.rs +0 -106
- package/crates/team-agent/src/layout/manager.rs +0 -248
- package/crates/team-agent/src/layout/mod.rs +0 -36
- package/crates/team-agent/src/layout/overlay.rs +0 -134
- package/crates/team-agent/src/layout/placement.rs +0 -52
- package/crates/team-agent/src/layout/recovery.rs +0 -106
- package/crates/team-agent/src/layout/runtime_sessions.rs +0 -317
- package/crates/team-agent/src/layout/sessions.rs +0 -294
- package/crates/team-agent/src/layout/tmux_endpoint.rs +0 -165
- package/crates/team-agent/src/layout/worker_env.rs +0 -721
- package/crates/team-agent/src/layout/worker_window_helpers.rs +0 -37
- package/crates/team-agent/src/leader/helpers.rs +0 -178
- package/crates/team-agent/src/leader/incident.rs +0 -6
- package/crates/team-agent/src/leader/lease.rs +0 -3356
- package/crates/team-agent/src/leader/mod.rs +0 -104
- package/crates/team-agent/src/leader/owner_bind.rs +0 -400
- package/crates/team-agent/src/leader/prompt.rs +0 -905
- package/crates/team-agent/src/leader/provider_attribution.rs +0 -247
- package/crates/team-agent/src/leader/rediscover/tests.rs +0 -689
- package/crates/team-agent/src/leader/rediscover.rs +0 -1192
- package/crates/team-agent/src/leader/registry.rs +0 -883
- package/crates/team-agent/src/leader/start.rs +0 -4500
- package/crates/team-agent/src/leader/takeover.rs +0 -65
- package/crates/team-agent/src/leader/tests/basics.rs +0 -337
- package/crates/team-agent/src/leader/tests/byte_findings.rs +0 -355
- package/crates/team-agent/src/leader/tests/claim_leader_mailbox_flush_contract.rs +0 -544
- package/crates/team-agent/src/leader/tests/historical_inventory_upgrade_gate_red.rs +0 -624
- package/crates/team-agent/src/leader/tests/identity.rs +0 -465
- package/crates/team-agent/src/leader/tests/identity_session_names.rs +0 -42
- package/crates/team-agent/src/leader/tests/idle.rs +0 -113
- package/crates/team-agent/src/leader/tests/lease_api.rs +0 -520
- package/crates/team-agent/src/leader/tests/lease_claim.rs +0 -629
- package/crates/team-agent/src/leader/tests/mod.rs +0 -106
- package/crates/team-agent/src/leader/tests/prompt_contract.rs +0 -267
- package/crates/team-agent/src/leader/tests/rediscover.rs +0 -403
- package/crates/team-agent/src/leader/tests/rehomed_env.rs +0 -83
- package/crates/team-agent/src/leader/tests/team_in_team_state_scope_red.rs +0 -1273
- package/crates/team-agent/src/leader/tests/terminal_and_replay_vs_rerender_invariants_red.rs +0 -417
- package/crates/team-agent/src/leader/tests/wake_start_owner.rs +0 -168
- package/crates/team-agent/src/leader/types.rs +0 -534
- package/crates/team-agent/src/lib.rs +0 -145
- package/crates/team-agent/src/lifecycle/helpers.rs +0 -212
- package/crates/team-agent/src/lifecycle/launch/add_agent.rs +0 -848
- package/crates/team-agent/src/lifecycle/launch/add_agent_state.rs +0 -393
- package/crates/team-agent/src/lifecycle/launch/agent_state.rs +0 -332
- package/crates/team-agent/src/lifecycle/launch/clone_agent.rs +0 -178
- package/crates/team-agent/src/lifecycle/launch/fork_agent.rs +0 -82
- package/crates/team-agent/src/lifecycle/launch/fork_entry.rs +0 -63
- package/crates/team-agent/src/lifecycle/launch/identity.rs +0 -674
- package/crates/team-agent/src/lifecycle/launch/layout.rs +0 -350
- package/crates/team-agent/src/lifecycle/launch/leader_context.rs +0 -589
- package/crates/team-agent/src/lifecycle/launch/mcp_config.rs +0 -152
- package/crates/team-agent/src/lifecycle/launch/ownership.rs +0 -105
- package/crates/team-agent/src/lifecycle/launch/pi_mcp.rs +0 -629
- package/crates/team-agent/src/lifecycle/launch/pi_mcp_extension.js +0 -226
- package/crates/team-agent/src/lifecycle/launch/plan.rs +0 -269
- package/crates/team-agent/src/lifecycle/launch/quick_start.rs +0 -5176
- package/crates/team-agent/src/lifecycle/launch/quick_start_transport.rs +0 -368
- package/crates/team-agent/src/lifecycle/launch/readiness.rs +0 -519
- package/crates/team-agent/src/lifecycle/launch/role_source.rs +0 -287
- package/crates/team-agent/src/lifecycle/launch/spawn.rs +0 -450
- package/crates/team-agent/src/lifecycle/launch/spec_state.rs +0 -801
- package/crates/team-agent/src/lifecycle/launch/state_projection.rs +0 -624
- package/crates/team-agent/src/lifecycle/launch/worker_env.rs +0 -558
- package/crates/team-agent/src/lifecycle/launch.rs +0 -534
- package/crates/team-agent/src/lifecycle/lock.rs +0 -350
- package/crates/team-agent/src/lifecycle/mod.rs +0 -79
- package/crates/team-agent/src/lifecycle/pane_input_lock.rs +0 -239
- package/crates/team-agent/src/lifecycle/profile_launch.rs +0 -757
- package/crates/team-agent/src/lifecycle/profile_smoke.rs +0 -557
- package/crates/team-agent/src/lifecycle/restart/agent.rs +0 -2198
- package/crates/team-agent/src/lifecycle/restart/common.rs +0 -2052
- package/crates/team-agent/src/lifecycle/restart/orchestrator.rs +0 -65
- package/crates/team-agent/src/lifecycle/restart/preflight.rs +0 -113
- package/crates/team-agent/src/lifecycle/restart/rebuild.rs +0 -5135
- package/crates/team-agent/src/lifecycle/restart/remove.rs +0 -1504
- package/crates/team-agent/src/lifecycle/restart/selection.rs +0 -559
- package/crates/team-agent/src/lifecycle/restart/team_state.rs +0 -329
- package/crates/team-agent/src/lifecycle/restart.rs +0 -223
- package/crates/team-agent/src/lifecycle/role_config.rs +0 -1205
- package/crates/team-agent/src/lifecycle/tests/acceptance_b_batch_red.rs +0 -1021
- package/crates/team-agent/src/lifecycle/tests/agent_ops.rs +0 -1205
- package/crates/team-agent/src/lifecycle/tests/b0_legacy_snapshot_nonauthority_contract.rs +0 -265
- package/crates/team-agent/src/lifecycle/tests/b0_reader_hideone_audit_contract.rs +0 -490
- package/crates/team-agent/src/lifecycle/tests/behavioral_diff_264_red.rs +0 -656
- package/crates/team-agent/src/lifecycle/tests/claude_profile_launch_red.rs +0 -135
- package/crates/team-agent/src/lifecycle/tests/cli_argv_routing_red.rs +0 -1415
- package/crates/team-agent/src/lifecycle/tests/clone_agent_preserves_source_tools.rs +0 -427
- package/crates/team-agent/src/lifecycle/tests/clone_fork_copilot_perms_red.rs +0 -396
- package/crates/team-agent/src/lifecycle/tests/communication_mode_runtime_contract_red.rs +0 -418
- package/crates/team-agent/src/lifecycle/tests/copilot_provider_red.rs +0 -2039
- package/crates/team-agent/src/lifecycle/tests/core.rs +0 -1298
- package/crates/team-agent/src/lifecycle/tests/f032_startup_prompt_best_effort_red.rs +0 -315
- package/crates/team-agent/src/lifecycle/tests/fixtures/pi_list_models_g0.stdout.txt +0 -222
- package/crates/team-agent/src/lifecycle/tests/fixtures/pi_list_models_spaced_ids.stdout.txt +0 -9
- package/crates/team-agent/src/lifecycle/tests/fixtures/pi_native_mcp_host.mjs +0 -71
- package/crates/team-agent/src/lifecycle/tests/gate_fixtures.rs +0 -562
- package/crates/team-agent/src/lifecycle/tests/grok_require_explicit_model_red.rs +0 -110
- package/crates/team-agent/src/lifecycle/tests/harvest2_a_batch_red.rs +0 -472
- package/crates/team-agent/src/lifecycle/tests/host_cotenant_death_p0_contract.rs +0 -921
- package/crates/team-agent/src/lifecycle/tests/issue238_codex_effort_contract.rs +0 -68
- package/crates/team-agent/src/lifecycle/tests/lane_ops.rs +0 -1851
- package/crates/team-agent/src/lifecycle/tests/launch_spawn.rs +0 -3981
- package/crates/team-agent/src/lifecycle/tests/lifecycle_lock.rs +0 -339
- package/crates/team-agent/src/lifecycle/tests/lifecycle_rollback_red.rs +0 -596
- package/crates/team-agent/src/lifecycle/tests/main_preserved.rs +0 -513
- package/crates/team-agent/src/lifecycle/tests/mcp_tool_name_format_red.rs +0 -69
- package/crates/team-agent/src/lifecycle/tests/phase_b_contracts.rs +0 -824
- package/crates/team-agent/src/lifecycle/tests/phase_golden.rs +0 -723
- package/crates/team-agent/src/lifecycle/tests/pi_catalog_red.rs +0 -152
- package/crates/team-agent/src/lifecycle/tests/pi_command_red.rs +0 -182
- package/crates/team-agent/src/lifecycle/tests/pi_dual_entry_red.rs +0 -374
- package/crates/team-agent/src/lifecycle/tests/pi_executable_mcp_red.rs +0 -546
- package/crates/team-agent/src/lifecycle/tests/pi_lifecycle_doctor_red.rs +0 -31
- package/crates/team-agent/src/lifecycle/tests/pi_native_mcp_capability_red.rs +0 -528
- package/crates/team-agent/src/lifecycle/tests/pi_session_delivery_red.rs +0 -134
- package/crates/team-agent/src/lifecycle/tests/quick_start_worker_readiness_red.rs +0 -333
- package/crates/team-agent/src/lifecycle/tests/realmachine_clusters_1_6_red.rs +0 -786
- package/crates/team-agent/src/lifecycle/tests/realmachine_residual_g1_g4_red.rs +0 -648
- package/crates/team-agent/src/lifecycle/tests/restart.rs +0 -185
- package/crates/team-agent/src/lifecycle/tests/restart_build_before_destroy_0540_contract.rs +0 -1053
- package/crates/team-agent/src/lifecycle/tests/restart_liveness_red.rs +0 -679
- package/crates/team-agent/src/lifecycle/tests/restart_rebind_hotfix_252_red.rs +0 -1126
- package/crates/team-agent/src/lifecycle/tests/restart_session_capture_red.rs +0 -153
- package/crates/team-agent/src/lifecycle/tests/resume_recover_red.rs +0 -427
- package/crates/team-agent/src/lifecycle/tests/stale_team_saveconflict_contract.rs +0 -431
- package/crates/team-agent/src/lifecycle/tests/startup_latency_contract.rs +0 -1066
- package/crates/team-agent/src/lifecycle/tests/status_credential_redaction_contract.rs +0 -876
- package/crates/team-agent/src/lifecycle/tests/subprep_codex_trust_roundtrip_red.rs +0 -1026
- package/crates/team-agent/src/lifecycle/tests/swallow_batch4_semantics_red.rs +0 -90
- package/crates/team-agent/src/lifecycle/tests/team_in_team_identity_scope_red.rs +0 -543
- package/crates/team-agent/src/lifecycle/tests/team_in_team_sibling_quick_start_red.rs +0 -1103
- package/crates/team-agent/src/lifecycle/tests/team_in_team_state_scope_red.rs +0 -1276
- package/crates/team-agent/src/lifecycle/tests/team_key_retirement_roster_red.rs +0 -145
- package/crates/team-agent/src/lifecycle/tests/team_key_retirement_txn_red.rs +0 -603
- package/crates/team-agent/src/lifecycle/tests/test_isolation_escape_contract.rs +0 -936
- package/crates/team-agent/src/lifecycle/tests/upgrade_compat_0211_red.rs +0 -970
- package/crates/team-agent/src/lifecycle/tests/verify_rs031_window_consistency_red.rs +0 -996
- package/crates/team-agent/src/lifecycle/tests/worker_spawn_env_red.rs +0 -827
- package/crates/team-agent/src/lifecycle/tests.rs +0 -102
- package/crates/team-agent/src/lifecycle/types.rs +0 -861
- package/crates/team-agent/src/lifecycle/worker_command_context.rs +0 -370
- package/crates/team-agent/src/main.rs +0 -52
- package/crates/team-agent/src/mcp_server/helpers.rs +0 -510
- package/crates/team-agent/src/mcp_server/lifecycle_tools/mod.rs +0 -6
- package/crates/team-agent/src/mcp_server/lifecycle_tools/state_status.rs +0 -43
- package/crates/team-agent/src/mcp_server/mod.rs +0 -119
- package/crates/team-agent/src/mcp_server/normalize.rs +0 -485
- package/crates/team-agent/src/mcp_server/readiness.rs +0 -546
- package/crates/team-agent/src/mcp_server/readiness_tests.rs +0 -369
- package/crates/team-agent/src/mcp_server/tests/golden.rs +0 -285
- package/crates/team-agent/src/mcp_server/tests/normalize.rs +0 -247
- package/crates/team-agent/src/mcp_server/tests/scoped.rs +0 -168
- package/crates/team-agent/src/mcp_server/tests/send.rs +0 -388
- package/crates/team-agent/src/mcp_server/tests/tools.rs +0 -343
- package/crates/team-agent/src/mcp_server/tests/wire.rs +0 -254
- package/crates/team-agent/src/mcp_server/tests.rs +0 -43
- package/crates/team-agent/src/mcp_server/tools.rs +0 -1015
- package/crates/team-agent/src/mcp_server/types.rs +0 -396
- package/crates/team-agent/src/mcp_server/wire.rs +0 -867
- package/crates/team-agent/src/messaging/activity.rs +0 -461
- package/crates/team-agent/src/messaging/address.rs +0 -87
- package/crates/team-agent/src/messaging/delivery.rs +0 -3785
- package/crates/team-agent/src/messaging/delivery_consumption_tests.rs +0 -234
- package/crates/team-agent/src/messaging/enter_rescue.rs +0 -362
- package/crates/team-agent/src/messaging/enter_rescue_tests.rs +0 -633
- package/crates/team-agent/src/messaging/helpers.rs +0 -354
- package/crates/team-agent/src/messaging/leader_channel.rs +0 -287
- package/crates/team-agent/src/messaging/leader_receiver.rs +0 -786
- package/crates/team-agent/src/messaging/mod.rs +0 -166
- package/crates/team-agent/src/messaging/persist.rs +0 -377
- package/crates/team-agent/src/messaging/presentation.rs +0 -417
- package/crates/team-agent/src/messaging/results/collection_tests.rs +0 -719
- package/crates/team-agent/src/messaging/results.rs +0 -1415
- package/crates/team-agent/src/messaging/scheduler.rs +0 -217
- package/crates/team-agent/src/messaging/selftest.rs +0 -315
- package/crates/team-agent/src/messaging/send.rs +0 -981
- package/crates/team-agent/src/messaging/tests/basic.rs +0 -346
- package/crates/team-agent/src/messaging/tests/dup_inject.rs +0 -551
- package/crates/team-agent/src/messaging/tests/e23.rs +0 -49
- package/crates/team-agent/src/messaging/tests/leader_channel.rs +0 -169
- package/crates/team-agent/src/messaging/tests/leader_inject_acceptance.rs +0 -817
- package/crates/team-agent/src/messaging/tests/main_preserved.rs +0 -85
- package/crates/team-agent/src/messaging/tests/mod.rs +0 -306
- package/crates/team-agent/src/messaging/tests/runtime.rs +0 -3655
- package/crates/team-agent/src/messaging/tests/spine.rs +0 -837
- package/crates/team-agent/src/messaging/tests/wave2.rs +0 -381
- package/crates/team-agent/src/messaging/trust.rs +0 -215
- package/crates/team-agent/src/messaging/types.rs +0 -471
- package/crates/team-agent/src/messaging/wait.rs +0 -366
- package/crates/team-agent/src/messaging/watchers.rs +0 -916
- package/crates/team-agent/src/model/enums.rs +0 -356
- package/crates/team-agent/src/model/errors.rs +0 -18
- package/crates/team-agent/src/model/ids.rs +0 -165
- package/crates/team-agent/src/model/mod.rs +0 -29
- package/crates/team-agent/src/model/name_similarity.rs +0 -252
- package/crates/team-agent/src/model/pane_authority_refusal.rs +0 -359
- package/crates/team-agent/src/model/paths.rs +0 -257
- package/crates/team-agent/src/model/routing.rs +0 -387
- package/crates/team-agent/src/model/spec.rs +0 -1184
- package/crates/team-agent/src/model/task_graph.rs +0 -321
- package/crates/team-agent/src/model/testdata/fuzz.golden.yaml +0 -43
- package/crates/team-agent/src/model/testdata/fuzz.yaml +0 -43
- package/crates/team-agent/src/model/testdata/spec_invalid_a.yaml +0 -209
- package/crates/team-agent/src/model/testdata/team.spec.golden.yaml +0 -208
- package/crates/team-agent/src/model/testdata/team.spec.yaml +0 -208
- package/crates/team-agent/src/model/yaml/tests.rs +0 -188
- package/crates/team-agent/src/model/yaml.rs +0 -802
- package/crates/team-agent/src/os_probe.rs +0 -280
- package/crates/team-agent/src/packaging/install.rs +0 -219
- package/crates/team-agent/src/packaging/migrate.rs +0 -38
- package/crates/team-agent/src/packaging/mod.rs +0 -91
- package/crates/team-agent/src/packaging/repair.rs +0 -33
- package/crates/team-agent/src/packaging/tests.rs +0 -822
- package/crates/team-agent/src/packaging/types.rs +0 -417
- package/crates/team-agent/src/platform/argv.rs +0 -331
- package/crates/team-agent/src/platform/errors.rs +0 -104
- package/crates/team-agent/src/platform/file_lock.rs +0 -279
- package/crates/team-agent/src/platform/mod.rs +0 -5
- package/crates/team-agent/src/platform/process.rs +0 -545
- package/crates/team-agent/src/provider/adapter.rs +0 -898
- package/crates/team-agent/src/provider/adapters/copilot.rs +0 -75
- package/crates/team-agent/src/provider/adapters/copilot_fork.rs +0 -307
- package/crates/team-agent/src/provider/adapters/fake.rs +0 -18
- package/crates/team-agent/src/provider/adapters/mod.rs +0 -28
- package/crates/team-agent/src/provider/approvals/mod.rs +0 -3
- package/crates/team-agent/src/provider/approvals/parsing.rs +0 -586
- package/crates/team-agent/src/provider/approvals/runtime_prompts.rs +0 -205
- package/crates/team-agent/src/provider/argv_route.rs +0 -405
- package/crates/team-agent/src/provider/bypass_flags.rs +0 -116
- package/crates/team-agent/src/provider/classify.rs +0 -773
- package/crates/team-agent/src/provider/command_helpers.rs +0 -45
- package/crates/team-agent/src/provider/faults.rs +0 -165
- package/crates/team-agent/src/provider/helpers.rs +0 -52
- package/crates/team-agent/src/provider/mod.rs +0 -78
- package/crates/team-agent/src/provider/model_catalog.rs +0 -722
- package/crates/team-agent/src/provider/session/capture.rs +0 -2631
- package/crates/team-agent/src/provider/session/context_fork/outcome.rs +0 -168
- package/crates/team-agent/src/provider/session/context_fork.rs +0 -264
- package/crates/team-agent/src/provider/session/mod.rs +0 -36
- package/crates/team-agent/src/provider/session/resume.rs +0 -269
- package/crates/team-agent/src/provider/session_scan/common/tests.rs +0 -316
- package/crates/team-agent/src/provider/session_scan/common.rs +0 -618
- package/crates/team-agent/src/provider/session_scan/copilot.rs +0 -280
- package/crates/team-agent/src/provider/session_scan/pi.rs +0 -152
- package/crates/team-agent/src/provider/session_scan.rs +0 -61
- package/crates/team-agent/src/provider/startup_prompt.rs +0 -757
- package/crates/team-agent/src/provider/submit_now.rs +0 -71
- package/crates/team-agent/src/provider/testdata/copilot-ready-marker.txt +0 -5
- package/crates/team-agent/src/provider/testdata/copilot-trust-prompt.txt +0 -19
- package/crates/team-agent/src/provider/testdata/grok-models-authenticated.stdout +0 -9
- package/crates/team-agent/src/provider/testdata/grok-models-unauthenticated.stdout +0 -7
- package/crates/team-agent/src/provider/tests/adapter.rs +0 -354
- package/crates/team-agent/src/provider/tests/classify.rs +0 -201
- package/crates/team-agent/src/provider/tests/command_helpers.rs +0 -26
- package/crates/team-agent/src/provider/tests/copilot_fork.rs +0 -191
- package/crates/team-agent/src/provider/tests/faults.rs +0 -200
- package/crates/team-agent/src/provider/tests/idle.rs +0 -140
- package/crates/team-agent/src/provider/tests/wire.rs +0 -213
- package/crates/team-agent/src/provider/tests.rs +0 -32
- package/crates/team-agent/src/provider/types.rs +0 -529
- package/crates/team-agent/src/provider/wire.rs +0 -406
- package/crates/team-agent/src/redaction.rs +0 -259
- package/crates/team-agent/src/state/abnormal_watch/tests/mod.rs +0 -248
- package/crates/team-agent/src/state/abnormal_watch.rs +0 -144
- package/crates/team-agent/src/state/identity.rs +0 -914
- package/crates/team-agent/src/state/identity_keys.rs +0 -132
- package/crates/team-agent/src/state/mod.rs +0 -74
- package/crates/team-agent/src/state/owner_gate.rs +0 -482
- package/crates/team-agent/src/state/ownership.rs +0 -563
- package/crates/team-agent/src/state/paths.rs +0 -395
- package/crates/team-agent/src/state/persist.rs +0 -3811
- package/crates/team-agent/src/state/projection.rs +0 -1508
- package/crates/team-agent/src/state/repository/intent.rs +0 -14
- package/crates/team-agent/src/state/repository/tests.rs +0 -184
- package/crates/team-agent/src/state/repository.rs +0 -866
- package/crates/team-agent/src/state/selector.rs +0 -160
- package/crates/team-agent/src/state/testdata/state-rich.canonical.json +0 -133
- package/crates/team-agent/src/tmux_backend/enter_rescue.rs +0 -325
- package/crates/team-agent/src/tmux_backend/enter_rescue_tests.rs +0 -432
- package/crates/team-agent/src/tmux_backend/native_input.rs +0 -513
- package/crates/team-agent/src/tmux_backend/native_input_tests.rs +0 -742
- package/crates/team-agent/src/tmux_backend/tests.rs +0 -4254
- package/crates/team-agent/src/tmux_backend.rs +0 -4527
- package/crates/team-agent/src/topology.rs +0 -537
- package/crates/team-agent/src/transport/enter_rescue.rs +0 -166
- package/crates/team-agent/src/transport/native_input.rs +0 -491
- package/crates/team-agent/src/transport/test_support.rs +0 -743
- package/crates/team-agent/src/transport/tests/behavior.rs +0 -326
- package/crates/team-agent/src/transport/tests/mod.rs +0 -194
- package/crates/team-agent/src/transport/tests/wire.rs +0 -574
- package/crates/team-agent/src/transport.rs +0 -1655
- package/crates/team-agent/src/transport_factory.rs +0 -819
|
@@ -1,866 +0,0 @@
|
|
|
1
|
-
//!
|
|
2
|
-
//! StateRepository facade. Task/note commits apply bounded mutations under the
|
|
3
|
-
//! existing state-save lock; coordinator commits carry only observation deltas.
|
|
4
|
-
//! Other writer clusters retain their legacy dispatch below.
|
|
5
|
-
//!
|
|
6
|
-
//! Ref:
|
|
7
|
-
//! - `.team/artifacts/s1a-state-repository-design.md` (skeleton)
|
|
8
|
-
//! - `.team/artifacts/s1b-writer-cluster-locate.md` (0.5.42 first
|
|
9
|
-
//! writer-cluster migration: `CoordinatorTick` + `ClaimLeader`)
|
|
10
|
-
//!
|
|
11
|
-
//! `StateRepository` is a thin write facade that dispatches every write
|
|
12
|
-
//! to the existing helper family without changing helper behavior,
|
|
13
|
-
//! merge policy, or on-disk layout. The value it adds is that every
|
|
14
|
-
//! write now carries a `StateWriteIntent`, so writer clusters migrate
|
|
15
|
-
//! one semantic at a time.
|
|
16
|
-
//!
|
|
17
|
-
//! 0.5.42 status: first real consumers are the daemon `Coordinator::
|
|
18
|
-
//! tick` production save (`CoordinatorTick`) and the lease/claim
|
|
19
|
-
//! writer cluster's two terminal saves (`ClaimLeader`) —
|
|
20
|
-
//! `write_lease_dual_state` + `save_claim_team_scoped_state`.
|
|
21
|
-
//! Post-S1b, the direct-save allowlist drops from 73 to 70; the three
|
|
22
|
-
//! migrated sites have no allowlist row and every future direct save
|
|
23
|
-
//! must either enter through `StateRepository` or claim an explicit
|
|
24
|
-
//! new allowlist row (fail-closed).
|
|
25
|
-
//!
|
|
26
|
-
//! Non-goals kept from S1a (design §11) + reasserted by
|
|
27
|
-
//! s1b-writer-cluster-locate.md §7: no schema rewrite, no path layout
|
|
28
|
-
//! change, no helper deletion, no epoch computation in the repository,
|
|
29
|
-
//! no retry / reload / event emission, no reinterpretation of
|
|
30
|
-
//! `owner_epoch` / `topology_convergence` / readback proof — the
|
|
31
|
-
//! caller still owns the whole `Value`, and repository dispatches to
|
|
32
|
-
//! the same existing persist helper the direct edge used to hit.
|
|
33
|
-
|
|
34
|
-
#![deny(clippy::unwrap_used, clippy::expect_used, clippy::panic)]
|
|
35
|
-
|
|
36
|
-
use std::path::Path;
|
|
37
|
-
|
|
38
|
-
use serde_json::Value;
|
|
39
|
-
|
|
40
|
-
use super::StateError;
|
|
41
|
-
// S1a alias imports keep dispatch traceable to the exact legacy helper family
|
|
42
|
-
// while letting the repository body avoid the raw `save_runtime_state(`/
|
|
43
|
-
// `save_team_scoped_state(` tokens that the governance scanner counts.
|
|
44
|
-
#[allow(unused_imports)]
|
|
45
|
-
use super::persist::{
|
|
46
|
-
load_runtime_state as helper_load_workspace,
|
|
47
|
-
runtime_state_path as helper_workspace_path, save_runtime_state as helper_write_root,
|
|
48
|
-
save_runtime_state_reapplying_after_conflict as helper_write_root_reapply,
|
|
49
|
-
save_runtime_state_with_deleted_agents as helper_write_root_with_deleted_agents,
|
|
50
|
-
save_runtime_state_with_lifecycle_topology_authority as helper_write_root_with_lifecycle_topology_authority,
|
|
51
|
-
save_runtime_state_with_lifecycle_topology_authority_and_capture_backfill_skip as helper_write_root_with_lifecycle_topology_authority_and_capture_backfill_skip,
|
|
52
|
-
save_runtime_state_with_receiver_authority as helper_write_root_with_receiver_authority,
|
|
53
|
-
save_runtime_state_with_receiver_authority_and_expected
|
|
54
|
-
as helper_write_root_with_receiver_authority_and_expected,
|
|
55
|
-
save_runtime_state_with_exact_owner_receiver_cleanup
|
|
56
|
-
as helper_write_root_with_exact_owner_receiver_cleanup,
|
|
57
|
-
save_runtime_state_with_exact_owner_receiver_restore
|
|
58
|
-
as helper_write_root_with_exact_owner_receiver_restore,
|
|
59
|
-
save_runtime_state_with_team_tombstone_lifecycle_topology_authority as helper_write_root_with_team_tombstone_lifecycle_topology_authority,
|
|
60
|
-
save_runtime_state_with_team_tombstoned_agents as helper_write_root_with_team_tombstoned_agents,
|
|
61
|
-
save_runtime_state_without_migrations as helper_write_root_without_migrations,
|
|
62
|
-
};
|
|
63
|
-
use super::projection::{
|
|
64
|
-
resolve_team_scoped_state as helper_resolve_team_scoped,
|
|
65
|
-
save_team_scoped_state as helper_write_team_scoped,
|
|
66
|
-
save_team_scoped_state_reapplying_after_conflict as helper_write_team_scoped_reapply,
|
|
67
|
-
save_team_scoped_state_with_deleted_agents as helper_write_team_scoped_with_deleted_agents,
|
|
68
|
-
save_team_scoped_state_with_lifecycle_topology_authority as helper_write_team_scoped_with_lifecycle_topology_authority,
|
|
69
|
-
save_team_scoped_state_with_lifecycle_topology_authority_and_capture_backfill_skip as helper_write_team_scoped_with_lifecycle_topology_authority_and_capture_backfill_skip,
|
|
70
|
-
save_team_scoped_state_with_tombstone_lifecycle_topology_authority as helper_write_team_scoped_with_tombstone_lifecycle_topology_authority,
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
mod intent;
|
|
74
|
-
|
|
75
|
-
/// Repository facade for workspace state reads and writes.
|
|
76
|
-
///
|
|
77
|
-
/// S1a scope: hold the workspace path, expose `load_workspace`/`load_team`
|
|
78
|
-
/// and a `save`/`save_reapplying` pair that both take a `StateWriteIntent`.
|
|
79
|
-
/// The concrete dispatch stays byte-identical to the pre-S1a call graph.
|
|
80
|
-
pub struct StateRepository<'a> {
|
|
81
|
-
workspace: &'a Path,
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
impl<'a> StateRepository<'a> {
|
|
85
|
-
///
|
|
86
|
-
/// Construct a repository bound to a workspace root.
|
|
87
|
-
pub fn new(workspace: &'a Path) -> Self {
|
|
88
|
-
Self { workspace }
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
///
|
|
92
|
-
/// Load the raw workspace state document.
|
|
93
|
-
pub fn load_workspace(&self) -> Result<Value, StateError> {
|
|
94
|
-
helper_load_workspace(self.workspace)
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
///
|
|
98
|
-
/// Load the canonical workspace document without running read-time
|
|
99
|
-
/// migrations. `None` preserves the legacy raw-reader distinction between
|
|
100
|
-
/// a missing file and a present empty/default document.
|
|
101
|
-
pub fn load_workspace_if_exists_without_migrations(
|
|
102
|
-
&self,
|
|
103
|
-
) -> Result<Option<Value>, StateError> {
|
|
104
|
-
if !helper_workspace_path(self.workspace).exists() {
|
|
105
|
-
return Ok(None);
|
|
106
|
-
}
|
|
107
|
-
let text = std::fs::read_to_string(helper_workspace_path(self.workspace))?;
|
|
108
|
-
serde_json::from_str(&text).map(Some).map_err(StateError::from)
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
///
|
|
112
|
-
/// Resolve a team-scoped projection using the existing projection selector.
|
|
113
|
-
/// `team_key = None` selects the ambient team the same way as pre-S1a.
|
|
114
|
-
pub fn load_team(&self, team_key: Option<&str>) -> Result<Value, StateError> {
|
|
115
|
-
let (state, refusal) = helper_resolve_team_scoped(self.workspace, team_key)?;
|
|
116
|
-
if let Some(refusal) = refusal {
|
|
117
|
-
return Err(StateError::TeamSelect(refusal.to_string()));
|
|
118
|
-
}
|
|
119
|
-
state.ok_or_else(|| {
|
|
120
|
-
StateError::TeamSelect(
|
|
121
|
-
"resolve_team_scoped_state returned no state and no refusal".to_string(),
|
|
122
|
-
)
|
|
123
|
-
})
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
///
|
|
127
|
-
/// Persist `state` under the supplied intent. S1a dispatch is a pure
|
|
128
|
-
/// forward call to the same legacy helper family that the caller used
|
|
129
|
-
/// before S1a; the intent selects the family, not the merge semantics.
|
|
130
|
-
pub fn save(&self, intent: StateWriteIntent<'_>, state: &Value) -> Result<(), StateError> {
|
|
131
|
-
if let StateWriteIntent::CoordinatorTick { team_key } = &intent {
|
|
132
|
-
return self.save_coordinator_tick(team_key, state);
|
|
133
|
-
}
|
|
134
|
-
route_direct(self.workspace, intent, state)
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
///
|
|
138
|
-
/// Persist `state` and let `reapply` re-materialize the write on
|
|
139
|
-
/// SaveConflict, matching the pre-S1a `_reapplying_after_conflict` helper
|
|
140
|
-
/// behavior for reapply-shaped intents.
|
|
141
|
-
pub fn save_reapplying<F>(
|
|
142
|
-
&self,
|
|
143
|
-
intent: StateWriteIntent<'_>,
|
|
144
|
-
state: &Value,
|
|
145
|
-
reapply: F,
|
|
146
|
-
) -> Result<(), StateError>
|
|
147
|
-
where
|
|
148
|
-
F: FnOnce(&mut Value),
|
|
149
|
-
{
|
|
150
|
-
#[cfg(test)]
|
|
151
|
-
test_support::before_commit();
|
|
152
|
-
route_reapply(self.workspace, intent, state, reapply)
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
/// Commit a bounded Team delta once against latest under state-save.
|
|
156
|
-
/// Return the committed Team view for callers that produce Markdown afterwards.
|
|
157
|
-
pub fn commit<F>(&self, intent: StateWriteIntent<'_>, update: F) -> Result<Value, StateError>
|
|
158
|
-
where
|
|
159
|
-
F: FnOnce(&mut Value),
|
|
160
|
-
{
|
|
161
|
-
#[cfg(test)]
|
|
162
|
-
test_support::before_commit();
|
|
163
|
-
let lifecycle_target = match &intent {
|
|
164
|
-
StateWriteIntent::StartAgent { team_key, agent_id } => Some((*team_key, *agent_id)),
|
|
165
|
-
_ => None,
|
|
166
|
-
};
|
|
167
|
-
let team_key = match intent {
|
|
168
|
-
StateWriteIntent::ResultCollection { owner_team_id } => owner_team_id,
|
|
169
|
-
StateWriteIntent::ForkAgent { team_key, .. }
|
|
170
|
-
| StateWriteIntent::StartAgent { team_key, .. } => Some(team_key),
|
|
171
|
-
_ => {
|
|
172
|
-
return Err(StateError::SaveFailed(
|
|
173
|
-
"intent does not accept a bounded Team delta".into(),
|
|
174
|
-
))
|
|
175
|
-
}
|
|
176
|
-
};
|
|
177
|
-
let committed = super::persist::update_runtime_state_with_lifecycle_target(self.workspace, lifecycle_target, |latest| {
|
|
178
|
-
let mut selected = bounded_team_view(latest, team_key)?;
|
|
179
|
-
update(&mut selected);
|
|
180
|
-
Ok(match team_key {
|
|
181
|
-
Some(key) => super::projection::merge_committed_team(latest, &selected, key),
|
|
182
|
-
None => selected,
|
|
183
|
-
})
|
|
184
|
-
})?;
|
|
185
|
-
bounded_team_view(&committed, team_key)
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
/// Commit a messaging delta against its exact canonical owner under state-save.
|
|
189
|
-
/// Unlike ordinary compatibility writes, owner loss cannot select raw/default
|
|
190
|
-
/// state, and a failed receiver check cannot be reapplied to another team.
|
|
191
|
-
pub(crate) fn commit_messaging_checked<F>(
|
|
192
|
-
&self,
|
|
193
|
-
intent: StateWriteIntent<'_>,
|
|
194
|
-
update: F,
|
|
195
|
-
) -> Result<(), StateError>
|
|
196
|
-
where
|
|
197
|
-
F: FnOnce(&mut Value) -> Result<(), StateError>,
|
|
198
|
-
{
|
|
199
|
-
let StateWriteIntent::MessagingDeliveryState { owner_team_id: Some(team) } = intent else {
|
|
200
|
-
return Err(StateError::SaveFailed("checked messaging requires an owner".into()));
|
|
201
|
-
};
|
|
202
|
-
#[cfg(test)]
|
|
203
|
-
test_support::before_commit();
|
|
204
|
-
super::persist::update_runtime_state(self.workspace, |latest| {
|
|
205
|
-
if team.is_empty() || !matches!(
|
|
206
|
-
super::projection::resolve_owner_team_id(latest, team),
|
|
207
|
-
super::projection::OwnerTeamResolution::Canonical(key) if key == team
|
|
208
|
-
) {
|
|
209
|
-
return Err(StateError::SaveConflict("messaging owner changed before commit".into()));
|
|
210
|
-
}
|
|
211
|
-
let nested = latest.get("teams").and_then(Value::as_object)
|
|
212
|
-
.is_some_and(|teams| teams.contains_key(team));
|
|
213
|
-
let mut selected = if nested {
|
|
214
|
-
super::projection::project_top_level_view(latest, team)
|
|
215
|
-
} else if legacy_single_team_state(latest)
|
|
216
|
-
&& (latest.get("active_team_key").and_then(Value::as_str) == Some(team)
|
|
217
|
-
|| super::projection::team_state_key(latest) == team
|
|
218
|
-
|| latest.get("session_name").and_then(Value::as_str)
|
|
219
|
-
.and_then(|session| session.strip_prefix("team-")) == Some(team))
|
|
220
|
-
{
|
|
221
|
-
latest.clone()
|
|
222
|
-
} else {
|
|
223
|
-
return Err(StateError::SaveConflict("messaging owner no longer exists".into()));
|
|
224
|
-
};
|
|
225
|
-
update(&mut selected)?;
|
|
226
|
-
Ok(if nested {
|
|
227
|
-
super::projection::merge_committed_team(latest, &selected, team)
|
|
228
|
-
} else {
|
|
229
|
-
selected
|
|
230
|
-
})
|
|
231
|
-
})?;
|
|
232
|
-
Ok(())
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
/// Atomically replace only the fork target row in the selected team.
|
|
236
|
-
pub(crate) fn commit_fork_agent(
|
|
237
|
-
&self,
|
|
238
|
-
intent: StateWriteIntent<'_>,
|
|
239
|
-
target_row: &Value,
|
|
240
|
-
) -> Result<(), StateError> {
|
|
241
|
-
let (team_key, agent_id) = match &intent {
|
|
242
|
-
StateWriteIntent::ForkAgent {
|
|
243
|
-
team_key,
|
|
244
|
-
agent_id,
|
|
245
|
-
} => (*team_key, *agent_id),
|
|
246
|
-
_ => {
|
|
247
|
-
return Err(StateError::SaveFailed(
|
|
248
|
-
"fork target delta requires ForkAgent intent".into(),
|
|
249
|
-
))
|
|
250
|
-
}
|
|
251
|
-
};
|
|
252
|
-
let target_row = target_row.clone();
|
|
253
|
-
let mut found = false;
|
|
254
|
-
self.commit(
|
|
255
|
-
StateWriteIntent::ForkAgent { team_key, agent_id },
|
|
256
|
-
|selected| {
|
|
257
|
-
if let Some(row) = selected
|
|
258
|
-
.get_mut("agents")
|
|
259
|
-
.and_then(Value::as_object_mut)
|
|
260
|
-
.and_then(|agents| agents.get_mut(agent_id))
|
|
261
|
-
{
|
|
262
|
-
*row = target_row;
|
|
263
|
-
found = true;
|
|
264
|
-
}
|
|
265
|
-
},
|
|
266
|
-
)?;
|
|
267
|
-
if found {
|
|
268
|
-
Ok(())
|
|
269
|
-
} else {
|
|
270
|
-
Err(StateError::SaveFailed(
|
|
271
|
-
"ForkAgent target row is missing from selected team".into(),
|
|
272
|
-
))
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
fn save_coordinator_tick(&self, team_key: &str, state: &Value) -> Result<(), StateError> {
|
|
277
|
-
let incoming = state.clone();
|
|
278
|
-
super::persist::update_runtime_state(self.workspace, |latest| {
|
|
279
|
-
let mut incoming_team = bounded_team_view(&incoming, Some(team_key))?;
|
|
280
|
-
let latest_team = bounded_team_view(latest, Some(team_key))?;
|
|
281
|
-
preserve_latest_fork_rows(&mut incoming_team, &latest_team);
|
|
282
|
-
let mut checked =
|
|
283
|
-
super::projection::merge_committed_team(latest, &incoming_team, team_key);
|
|
284
|
-
super::persist::merge_ordinary_state(&mut checked, latest)?;
|
|
285
|
-
let checked = bounded_team_view(&checked, Some(team_key))?;
|
|
286
|
-
Ok(super::projection::merge_committed_team(
|
|
287
|
-
latest, &checked, team_key,
|
|
288
|
-
))
|
|
289
|
-
})?;
|
|
290
|
-
Ok(())
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
/// Fence the sampled incarnation with the existing persist guards, then
|
|
294
|
-
/// commit only this tick's agent observations and coordinator bookkeeping.
|
|
295
|
-
pub fn commit_observations(
|
|
296
|
-
&self,
|
|
297
|
-
intent: StateWriteIntent<'_>,
|
|
298
|
-
before: &Value,
|
|
299
|
-
observed: &Value,
|
|
300
|
-
) -> Result<(), StateError> {
|
|
301
|
-
let StateWriteIntent::CoordinatorTick { team_key } = intent else {
|
|
302
|
-
return Err(StateError::SaveFailed("intent does not accept observations".into()));
|
|
303
|
-
};
|
|
304
|
-
let sampled_legacy =
|
|
305
|
-
legacy_single_team_state(before) && legacy_single_team_state(observed);
|
|
306
|
-
let sampled_identity = legacy_team_identity(before);
|
|
307
|
-
super::persist::update_runtime_state(self.workspace, |latest| {
|
|
308
|
-
if sampled_legacy {
|
|
309
|
-
if sampled_identity != legacy_team_identity(observed)
|
|
310
|
-
|| !legacy_single_team_state(latest)
|
|
311
|
-
|| sampled_identity != legacy_team_identity(latest)
|
|
312
|
-
{
|
|
313
|
-
return Err(StateError::SaveConflict(
|
|
314
|
-
"legacy coordinator observation scope changed before commit".to_string(),
|
|
315
|
-
));
|
|
316
|
-
}
|
|
317
|
-
let mut checked = observed.clone();
|
|
318
|
-
preserve_latest_fork_rows(&mut checked, latest);
|
|
319
|
-
super::persist::merge_ordinary_state(&mut checked, latest)?;
|
|
320
|
-
if !legacy_single_team_state(&checked)
|
|
321
|
-
|| sampled_identity != legacy_team_identity(&checked)
|
|
322
|
-
{
|
|
323
|
-
return Err(StateError::SaveConflict(
|
|
324
|
-
"legacy coordinator observation scope changed during validation"
|
|
325
|
-
.to_string(),
|
|
326
|
-
));
|
|
327
|
-
}
|
|
328
|
-
let mut selected = latest.clone();
|
|
329
|
-
for field in ["agents", "coordinator"] {
|
|
330
|
-
if before[field] != checked[field] {
|
|
331
|
-
apply_observation_delta(
|
|
332
|
-
&before[field],
|
|
333
|
-
&checked[field],
|
|
334
|
-
&mut selected[field],
|
|
335
|
-
);
|
|
336
|
-
}
|
|
337
|
-
}
|
|
338
|
-
return Ok(selected);
|
|
339
|
-
}
|
|
340
|
-
let mut observed_with_delta = observed.clone();
|
|
341
|
-
sync_team_observation_delta(before, &mut observed_with_delta, team_key);
|
|
342
|
-
let mut observed_team = bounded_team_view(&observed_with_delta, Some(team_key))?;
|
|
343
|
-
let latest_team = bounded_team_view(latest, Some(team_key))?;
|
|
344
|
-
preserve_latest_fork_rows(&mut observed_team, &latest_team);
|
|
345
|
-
let mut checked =
|
|
346
|
-
super::projection::merge_committed_team(latest, &observed_team, team_key);
|
|
347
|
-
super::persist::merge_ordinary_state(&mut checked, latest)?;
|
|
348
|
-
let checked = bounded_team_view(&checked, Some(team_key))?;
|
|
349
|
-
let mut selected = bounded_team_view(latest, Some(team_key))?;
|
|
350
|
-
for field in ["agents", "coordinator"] {
|
|
351
|
-
if before[field] != checked[field] {
|
|
352
|
-
apply_observation_delta(&before[field], &checked[field], &mut selected[field]);
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
sync_team_observation_delta(before, &mut selected, team_key);
|
|
356
|
-
Ok(super::projection::merge_committed_team(latest, &selected, team_key))
|
|
357
|
-
})?;
|
|
358
|
-
Ok(())
|
|
359
|
-
}
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
// Coordinator observations do not own fork-target lifecycle rows.
|
|
363
|
-
fn preserve_latest_fork_rows(incoming: &mut Value, latest: &Value) {
|
|
364
|
-
let Some(latest_agents) = latest.get("agents").and_then(Value::as_object) else {
|
|
365
|
-
return;
|
|
366
|
-
};
|
|
367
|
-
let Some(incoming_agents) = incoming.get_mut("agents").and_then(Value::as_object_mut) else {
|
|
368
|
-
return;
|
|
369
|
-
};
|
|
370
|
-
for (agent_id, latest_agent) in latest_agents {
|
|
371
|
-
if latest_agent
|
|
372
|
-
.get("forked_from")
|
|
373
|
-
.and_then(Value::as_str)
|
|
374
|
-
.is_some_and(|source| !source.is_empty())
|
|
375
|
-
{
|
|
376
|
-
incoming_agents.insert(agent_id.clone(), latest_agent.clone());
|
|
377
|
-
}
|
|
378
|
-
}
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
fn legacy_single_team_state(state: &Value) -> bool {
|
|
382
|
-
match state.get("teams") {
|
|
383
|
-
None => true,
|
|
384
|
-
Some(Value::Object(teams)) => teams.is_empty(),
|
|
385
|
-
Some(_) => false,
|
|
386
|
-
}
|
|
387
|
-
}
|
|
388
|
-
|
|
389
|
-
fn legacy_team_identity(state: &Value) -> [Option<String>; 5] {
|
|
390
|
-
[
|
|
391
|
-
"active_team_key",
|
|
392
|
-
"team_key",
|
|
393
|
-
"session_name",
|
|
394
|
-
"team_dir",
|
|
395
|
-
"spec_path",
|
|
396
|
-
]
|
|
397
|
-
.map(|field| {
|
|
398
|
-
state
|
|
399
|
-
.get(field)
|
|
400
|
-
.and_then(Value::as_str)
|
|
401
|
-
.filter(|value| !value.is_empty())
|
|
402
|
-
.map(str::to_string)
|
|
403
|
-
})
|
|
404
|
-
}
|
|
405
|
-
|
|
406
|
-
fn bounded_team_view(state: &Value, team_key: Option<&str>) -> Result<Value, StateError> {
|
|
407
|
-
let Some(key) = team_key else { return Ok(state.clone()); };
|
|
408
|
-
if state.get("teams").and_then(Value::as_object).is_some_and(|teams| teams.contains_key(key)) {
|
|
409
|
-
return Ok(super::projection::project_top_level_view(state, key));
|
|
410
|
-
}
|
|
411
|
-
if state.get("teams").and_then(Value::as_object).is_some_and(|teams| !teams.is_empty()) {
|
|
412
|
-
return Err(StateError::TeamSelect(format!("team no longer exists: {key}")));
|
|
413
|
-
}
|
|
414
|
-
Ok(state.clone())
|
|
415
|
-
}
|
|
416
|
-
|
|
417
|
-
// Diffing is limited to the two observation blocks above, never a whole-state
|
|
418
|
-
// merge. Equal fields retain a concurrent writer's value; removed fields clear.
|
|
419
|
-
fn apply_observation_delta(before: &Value, observed: &Value, latest: &mut Value) {
|
|
420
|
-
if before == observed { return; }
|
|
421
|
-
if let Some(observed) = observed.as_object() {
|
|
422
|
-
if !latest.is_object() { *latest = serde_json::json!({}); }
|
|
423
|
-
if let Some(before) = before.as_object() {
|
|
424
|
-
for key in before.keys().filter(|key| !observed.contains_key(*key)) {
|
|
425
|
-
if let Some(latest) = latest.as_object_mut() { latest.remove(key); }
|
|
426
|
-
}
|
|
427
|
-
}
|
|
428
|
-
for (key, value) in observed {
|
|
429
|
-
apply_observation_delta(&before[key], value, &mut latest[key]);
|
|
430
|
-
}
|
|
431
|
-
} else {
|
|
432
|
-
*latest = observed.clone();
|
|
433
|
-
}
|
|
434
|
-
}
|
|
435
|
-
|
|
436
|
-
// The coordinator observes a projected team view, while its nested `teams`
|
|
437
|
-
// snapshot remains stale. Carry only observation deltas back to the canonical
|
|
438
|
-
// team entry before `bounded_team_view` projects it again.
|
|
439
|
-
fn sync_team_observation_delta(before: &Value, observed: &mut Value, team_key: &str) {
|
|
440
|
-
for field in ["agents", "coordinator"] {
|
|
441
|
-
let before_value = before.get(field).cloned().unwrap_or(Value::Null);
|
|
442
|
-
let observed_value = observed.get(field).cloned().unwrap_or(Value::Null);
|
|
443
|
-
if before_value == observed_value {
|
|
444
|
-
continue;
|
|
445
|
-
}
|
|
446
|
-
let Some(team_entry) = observed
|
|
447
|
-
.get_mut("teams")
|
|
448
|
-
.and_then(Value::as_object_mut)
|
|
449
|
-
.and_then(|teams| teams.get_mut(team_key))
|
|
450
|
-
.and_then(Value::as_object_mut)
|
|
451
|
-
else {
|
|
452
|
-
continue;
|
|
453
|
-
};
|
|
454
|
-
if field == "coordinator" && !team_entry.contains_key(field) {
|
|
455
|
-
team_entry.insert(field.to_string(), serde_json::json!({}));
|
|
456
|
-
}
|
|
457
|
-
let slot = team_entry
|
|
458
|
-
.entry(field.to_string())
|
|
459
|
-
.or_insert_with(|| before_value.clone());
|
|
460
|
-
apply_observation_delta(&before_value, &observed_value, slot);
|
|
461
|
-
}
|
|
462
|
-
}
|
|
463
|
-
|
|
464
|
-
/// Closed semantic catalog of workspace state writes. Every allowlisted
|
|
465
|
-
/// callsite maps to exactly one variant, and there is intentionally no
|
|
466
|
-
/// generic escape bucket. Any new state write must earn its own variant so
|
|
467
|
-
/// that S1b can migrate it deliberately (see design section 3).
|
|
468
|
-
///
|
|
469
|
-
/// Ordering follows design section 5 group order (lifecycle, agent ops,
|
|
470
|
-
/// leader/coordinator, MCP, messaging, then diagnostic seams).
|
|
471
|
-
pub enum StateWriteIntent<'a> {
|
|
472
|
-
LaunchTeam {
|
|
473
|
-
team_key: &'a str,
|
|
474
|
-
},
|
|
475
|
-
AddAgent {
|
|
476
|
-
team_key: &'a str,
|
|
477
|
-
agent_id: &'a str,
|
|
478
|
-
},
|
|
479
|
-
AnnotateTeamDepth {
|
|
480
|
-
team_key: &'a str,
|
|
481
|
-
},
|
|
482
|
-
ShutdownTeam {
|
|
483
|
-
team_key: Option<&'a str>,
|
|
484
|
-
clean: bool,
|
|
485
|
-
},
|
|
486
|
-
PromoteLiveSiblingAfterShutdown {
|
|
487
|
-
stopped_team_key: &'a str,
|
|
488
|
-
promoted_team_key: &'a str,
|
|
489
|
-
},
|
|
490
|
-
RestartTeam {
|
|
491
|
-
team_key: &'a str,
|
|
492
|
-
topology_authority_agent_ids: &'a [&'a str],
|
|
493
|
-
skip_capture_backfill_agent_ids: &'a [&'a str],
|
|
494
|
-
},
|
|
495
|
-
RestartSessionRepair {
|
|
496
|
-
team_key: &'a str,
|
|
497
|
-
},
|
|
498
|
-
StartAgent {
|
|
499
|
-
team_key: &'a str,
|
|
500
|
-
agent_id: &'a str,
|
|
501
|
-
},
|
|
502
|
-
StopAgent {
|
|
503
|
-
team_key: &'a str,
|
|
504
|
-
agent_id: &'a str,
|
|
505
|
-
},
|
|
506
|
-
ResetAgent {
|
|
507
|
-
team_key: &'a str,
|
|
508
|
-
agent_id: &'a str,
|
|
509
|
-
discard_session: bool,
|
|
510
|
-
},
|
|
511
|
-
RemoveAgent {
|
|
512
|
-
team_key: &'a str,
|
|
513
|
-
agent_id: &'a str,
|
|
514
|
-
},
|
|
515
|
-
ForkAgent {
|
|
516
|
-
team_key: &'a str,
|
|
517
|
-
agent_id: &'a str,
|
|
518
|
-
},
|
|
519
|
-
AgentRollback {
|
|
520
|
-
team_key: Option<&'a str>,
|
|
521
|
-
agent_id: &'a str,
|
|
522
|
-
},
|
|
523
|
-
ForceRecreateRollback {
|
|
524
|
-
team_key: &'a str,
|
|
525
|
-
agent_id: &'a str,
|
|
526
|
-
},
|
|
527
|
-
ClaimLeader {
|
|
528
|
-
team_key: &'a str,
|
|
529
|
-
},
|
|
530
|
-
ClaimLeaderFreshCaller {
|
|
531
|
-
team_key: &'a str,
|
|
532
|
-
expected_owner: &'a Value,
|
|
533
|
-
expected_receiver: &'a Value,
|
|
534
|
-
},
|
|
535
|
-
ClearExactTeamOwner {
|
|
536
|
-
team_key: &'a str,
|
|
537
|
-
seed: &'a Value,
|
|
538
|
-
},
|
|
539
|
-
ClearExactTeamOwnerAndReceiver {
|
|
540
|
-
team_key: &'a str,
|
|
541
|
-
seed: &'a Value,
|
|
542
|
-
expected_receiver: &'a Value,
|
|
543
|
-
},
|
|
544
|
-
RestoreExactTeamOwnerAndReceiver {
|
|
545
|
-
team_key: &'a str,
|
|
546
|
-
expected_owner: &'a Value,
|
|
547
|
-
expected_receiver: &'a Value,
|
|
548
|
-
previous_owner: &'a Value,
|
|
549
|
-
previous_receiver: &'a Value,
|
|
550
|
-
},
|
|
551
|
-
LeaderBindingRestoreNonTargetTeams {
|
|
552
|
-
target_team_key: &'a str,
|
|
553
|
-
},
|
|
554
|
-
/// Strip extra keys written by a failed or degraded quick-start bind attempt.
|
|
555
|
-
QuickStartBindingCleanup {
|
|
556
|
-
team_key: &'a str,
|
|
557
|
-
},
|
|
558
|
-
LeaderStartBinding {
|
|
559
|
-
team_key: &'a str,
|
|
560
|
-
transport_kind: &'a str,
|
|
561
|
-
},
|
|
562
|
-
CoordinatorTick {
|
|
563
|
-
team_key: &'a str,
|
|
564
|
-
},
|
|
565
|
-
CoordinatorConptyShim {
|
|
566
|
-
team_key: Option<&'a str>,
|
|
567
|
-
},
|
|
568
|
-
MessagingDeliveryState {
|
|
569
|
-
owner_team_id: Option<&'a str>,
|
|
570
|
-
},
|
|
571
|
-
MessagingTurnArm {
|
|
572
|
-
owner_team_id: Option<&'a str>,
|
|
573
|
-
},
|
|
574
|
-
MessagingSessionCapture,
|
|
575
|
-
ResultCollection {
|
|
576
|
-
owner_team_id: Option<&'a str>,
|
|
577
|
-
},
|
|
578
|
-
TaskRepair {
|
|
579
|
-
team_key: Option<&'a str>,
|
|
580
|
-
},
|
|
581
|
-
SelfMigration,
|
|
582
|
-
}
|
|
583
|
-
|
|
584
|
-
// S1a dispatch: every intent forwards to the same pre-S1a helper family; only naming shifted.
|
|
585
|
-
// When S1b migrates a writer cluster, only the arms below change;
|
|
586
|
-
// the callsites and tests keep talking to `StateRepository`.
|
|
587
|
-
fn route_direct(
|
|
588
|
-
workspace: &Path,
|
|
589
|
-
intent: StateWriteIntent<'_>,
|
|
590
|
-
state: &Value,
|
|
591
|
-
) -> Result<(), StateError> {
|
|
592
|
-
match intent {
|
|
593
|
-
// LaunchTeam -> the launch writer path uses the root helper today
|
|
594
|
-
// (`save_runtime_state` at lifecycle/launch.rs:996).
|
|
595
|
-
StateWriteIntent::LaunchTeam { .. } => helper_write_root(workspace, state),
|
|
596
|
-
StateWriteIntent::AddAgent { team_key, agent_id } => {
|
|
597
|
-
helper_write_team_scoped_with_lifecycle_topology_authority(
|
|
598
|
-
workspace,
|
|
599
|
-
state,
|
|
600
|
-
team_key,
|
|
601
|
-
&[agent_id],
|
|
602
|
-
)
|
|
603
|
-
}
|
|
604
|
-
// AnnotateTeamDepth also lives on the root save path.
|
|
605
|
-
StateWriteIntent::AnnotateTeamDepth { .. } => helper_write_root(workspace, state),
|
|
606
|
-
// ShutdownTeam: scoped clean shutdown uses `save_team_scoped_state`;
|
|
607
|
-
// bare (non-scoped) shutdown uses `save_runtime_state`. The
|
|
608
|
-
// `team_key` presence encodes the same clean-vs-bare split as the
|
|
609
|
-
// pre-S1a `shutdown_with_transport_and_state` branch at cli/mod.rs:886/895.
|
|
610
|
-
StateWriteIntent::ShutdownTeam { team_key, .. } => match team_key {
|
|
611
|
-
Some(_) => helper_write_team_scoped(workspace, state),
|
|
612
|
-
None => helper_write_root(workspace, state),
|
|
613
|
-
},
|
|
614
|
-
// PromoteLiveSiblingAfterShutdown writes the promoted projection at
|
|
615
|
-
// cli/mod.rs:3526 via the root helper.
|
|
616
|
-
StateWriteIntent::PromoteLiveSiblingAfterShutdown { .. } => {
|
|
617
|
-
helper_write_root(workspace, state)
|
|
618
|
-
}
|
|
619
|
-
// RestartTeam: existing rebuild/common path uses
|
|
620
|
-
// `save_team_scoped_state_with_lifecycle_topology_authority_and_capture_backfill_skip`
|
|
621
|
-
// at lifecycle/restart/common.rs:633.
|
|
622
|
-
StateWriteIntent::RestartTeam {
|
|
623
|
-
team_key,
|
|
624
|
-
topology_authority_agent_ids,
|
|
625
|
-
skip_capture_backfill_agent_ids,
|
|
626
|
-
} => helper_write_team_scoped_with_lifecycle_topology_authority_and_capture_backfill_skip(
|
|
627
|
-
workspace,
|
|
628
|
-
state,
|
|
629
|
-
team_key,
|
|
630
|
-
skip_capture_backfill_agent_ids,
|
|
631
|
-
topology_authority_agent_ids,
|
|
632
|
-
),
|
|
633
|
-
// RestartSessionRepair uses the same scoped helper first, with a
|
|
634
|
-
// reapply overlay in the caller (rebuild.rs:1545/1555). S1a preserves
|
|
635
|
-
// the direct-write form here; reapply routes through `save_reapplying`.
|
|
636
|
-
StateWriteIntent::RestartSessionRepair { .. } => helper_write_team_scoped(workspace, state),
|
|
637
|
-
// StartAgent - the launch add-agent tail lands via
|
|
638
|
-
// `save_team_scoped_state_with_lifecycle_topology_authority` today.
|
|
639
|
-
StateWriteIntent::StartAgent { team_key, .. } => {
|
|
640
|
-
helper_write_team_scoped_with_lifecycle_topology_authority(workspace, state, team_key, &[])
|
|
641
|
-
}
|
|
642
|
-
// StopAgent uses the legacy helper family
|
|
643
|
-
// `save_team_scoped_state_with_lifecycle_topology_authority`,
|
|
644
|
-
// matching lifecycle/restart/agent.rs:911.
|
|
645
|
-
StateWriteIntent::StopAgent { team_key, agent_id } => {
|
|
646
|
-
helper_write_team_scoped_with_lifecycle_topology_authority(
|
|
647
|
-
workspace,
|
|
648
|
-
state,
|
|
649
|
-
team_key,
|
|
650
|
-
&[agent_id],
|
|
651
|
-
)
|
|
652
|
-
}
|
|
653
|
-
// ResetAgent discard-session dispatches to
|
|
654
|
-
// `save_team_scoped_state_with_tombstone_lifecycle_topology_authority`,
|
|
655
|
-
// matching lifecycle/restart/agent.rs:1355. Non-discard falls back to
|
|
656
|
-
// the same lifecycle topology-authority helper as StopAgent.
|
|
657
|
-
StateWriteIntent::ResetAgent {
|
|
658
|
-
team_key,
|
|
659
|
-
agent_id,
|
|
660
|
-
discard_session,
|
|
661
|
-
} => {
|
|
662
|
-
if discard_session {
|
|
663
|
-
helper_write_team_scoped_with_tombstone_lifecycle_topology_authority(
|
|
664
|
-
workspace,
|
|
665
|
-
state,
|
|
666
|
-
team_key,
|
|
667
|
-
&[agent_id],
|
|
668
|
-
)
|
|
669
|
-
} else {
|
|
670
|
-
helper_write_team_scoped_with_lifecycle_topology_authority(
|
|
671
|
-
workspace,
|
|
672
|
-
state,
|
|
673
|
-
team_key,
|
|
674
|
-
&[agent_id],
|
|
675
|
-
)
|
|
676
|
-
}
|
|
677
|
-
}
|
|
678
|
-
// RemoveAgent -> deleted-agents helper family
|
|
679
|
-
// (lifecycle/restart/remove.rs:263).
|
|
680
|
-
StateWriteIntent::RemoveAgent { agent_id, .. } => {
|
|
681
|
-
helper_write_team_scoped_with_deleted_agents(workspace, state, &[agent_id])
|
|
682
|
-
}
|
|
683
|
-
// ForkAgent mutates a selected team projection, so persist it back to
|
|
684
|
-
// that projection with the forked row as lifecycle topology authority.
|
|
685
|
-
StateWriteIntent::ForkAgent { team_key, agent_id } => {
|
|
686
|
-
helper_write_team_scoped_with_lifecycle_topology_authority(
|
|
687
|
-
workspace,
|
|
688
|
-
state,
|
|
689
|
-
team_key,
|
|
690
|
-
&[agent_id],
|
|
691
|
-
)
|
|
692
|
-
}
|
|
693
|
-
// Team-scoped rollback must restore only the selected projection and
|
|
694
|
-
// preserve sibling teams. Legacy callers without a team keep the root
|
|
695
|
-
// deleted-agents writer.
|
|
696
|
-
StateWriteIntent::AgentRollback { team_key, agent_id } => match team_key {
|
|
697
|
-
Some(_) => helper_write_team_scoped_with_deleted_agents(workspace, state, &[agent_id]),
|
|
698
|
-
None => helper_write_root_with_deleted_agents(workspace, state, &[agent_id]),
|
|
699
|
-
},
|
|
700
|
-
// Force-recreate rollback restores an existing row after the
|
|
701
|
-
// replacement spawn has advanced its lifecycle tuple. The selected
|
|
702
|
-
// row is therefore the explicit topology authority.
|
|
703
|
-
StateWriteIntent::ForceRecreateRollback { team_key, agent_id } => {
|
|
704
|
-
helper_write_team_scoped_with_lifecycle_topology_authority(
|
|
705
|
-
workspace,
|
|
706
|
-
state,
|
|
707
|
-
team_key,
|
|
708
|
-
&[agent_id],
|
|
709
|
-
)
|
|
710
|
-
}
|
|
711
|
-
// ClaimLeader -> leader/lease.rs:1625 uses the root helper, and the
|
|
712
|
-
// scoped preserve-claim-fields variant at :1702 uses the team-tombstoned
|
|
713
|
-
// agents helper.
|
|
714
|
-
StateWriteIntent::ClaimLeader { team_key } => {
|
|
715
|
-
helper_write_root_with_receiver_authority(workspace, state, team_key, None)
|
|
716
|
-
}
|
|
717
|
-
StateWriteIntent::ClaimLeaderFreshCaller {
|
|
718
|
-
team_key,
|
|
719
|
-
expected_owner,
|
|
720
|
-
expected_receiver,
|
|
721
|
-
} => helper_write_root_with_receiver_authority_and_expected(
|
|
722
|
-
workspace,
|
|
723
|
-
state,
|
|
724
|
-
team_key,
|
|
725
|
-
expected_owner,
|
|
726
|
-
expected_receiver,
|
|
727
|
-
),
|
|
728
|
-
StateWriteIntent::ClearExactTeamOwner { team_key, seed } => {
|
|
729
|
-
helper_write_root_with_receiver_authority(workspace, state, team_key, Some(seed))
|
|
730
|
-
}
|
|
731
|
-
StateWriteIntent::ClearExactTeamOwnerAndReceiver {
|
|
732
|
-
team_key,
|
|
733
|
-
seed,
|
|
734
|
-
expected_receiver,
|
|
735
|
-
} => helper_write_root_with_exact_owner_receiver_cleanup(
|
|
736
|
-
workspace,
|
|
737
|
-
state,
|
|
738
|
-
team_key,
|
|
739
|
-
seed,
|
|
740
|
-
expected_receiver,
|
|
741
|
-
),
|
|
742
|
-
StateWriteIntent::RestoreExactTeamOwnerAndReceiver {
|
|
743
|
-
team_key,
|
|
744
|
-
expected_owner,
|
|
745
|
-
expected_receiver,
|
|
746
|
-
previous_owner,
|
|
747
|
-
previous_receiver,
|
|
748
|
-
} => helper_write_root_with_exact_owner_receiver_restore(
|
|
749
|
-
workspace,
|
|
750
|
-
state,
|
|
751
|
-
team_key,
|
|
752
|
-
expected_owner,
|
|
753
|
-
expected_receiver,
|
|
754
|
-
previous_owner,
|
|
755
|
-
previous_receiver,
|
|
756
|
-
),
|
|
757
|
-
StateWriteIntent::QuickStartBindingCleanup { .. } => helper_write_root(workspace, state),
|
|
758
|
-
StateWriteIntent::LeaderBindingRestoreNonTargetTeams { .. } => {
|
|
759
|
-
helper_write_root_without_migrations(workspace, state)
|
|
760
|
-
}
|
|
761
|
-
// LeaderStartBinding -> managed/exec/external all root-save at
|
|
762
|
-
// leader/start.rs:795/903/946.
|
|
763
|
-
StateWriteIntent::LeaderStartBinding { team_key, .. } => {
|
|
764
|
-
helper_write_root_with_receiver_authority(workspace, state, team_key, None)
|
|
765
|
-
}
|
|
766
|
-
// CoordinatorTick dispatches to the existing scoped helper
|
|
767
|
-
// (`save_team_scoped_state`) preserving coordinator/tick.rs:427.
|
|
768
|
-
StateWriteIntent::CoordinatorTick { .. } => helper_write_team_scoped(workspace, state),
|
|
769
|
-
// CoordinatorConptyShim -> root save
|
|
770
|
-
// (coordinator/conpty_shim.rs:426/674).
|
|
771
|
-
StateWriteIntent::CoordinatorConptyShim { .. } => helper_write_root(workspace, state),
|
|
772
|
-
// MessagingDeliveryState direct writes cover team-scoped, root
|
|
773
|
-
// fallback, and root (messaging/delivery.rs:2356/2358/2361).
|
|
774
|
-
StateWriteIntent::MessagingDeliveryState { owner_team_id } => match owner_team_id {
|
|
775
|
-
Some(_) => helper_write_team_scoped(workspace, state),
|
|
776
|
-
None => helper_write_root(workspace, state),
|
|
777
|
-
},
|
|
778
|
-
// MessagingTurnArm -> root save (messaging/activity.rs:83).
|
|
779
|
-
StateWriteIntent::MessagingTurnArm { .. } => helper_write_root(workspace, state),
|
|
780
|
-
// MessagingSessionCapture -> root save; the post-send capture backfill
|
|
781
|
-
// at messaging/send.rs used the root helper directly before it was
|
|
782
|
-
// migrated onto the repository.
|
|
783
|
-
StateWriteIntent::MessagingSessionCapture => helper_write_root(workspace, state),
|
|
784
|
-
// ResultCollection direct-write path uses `save_team_scoped_state`
|
|
785
|
-
// when an owner_team_id is bound and `save_runtime_state` at the root
|
|
786
|
-
// otherwise (messaging/results.rs:201/211). The reapply-shaped
|
|
787
|
-
// variants live in `route_reapply` and preserve
|
|
788
|
-
// `save_team_scoped_state_reapplying_after_conflict` /
|
|
789
|
-
// `save_runtime_state_reapplying_after_conflict` semantics.
|
|
790
|
-
StateWriteIntent::ResultCollection { owner_team_id } => match owner_team_id {
|
|
791
|
-
Some(_) => helper_write_team_scoped(workspace, state),
|
|
792
|
-
None => helper_write_root(workspace, state),
|
|
793
|
-
},
|
|
794
|
-
// TaskRepair -> `save_team_scoped_state` (cli/adapters.rs:675).
|
|
795
|
-
StateWriteIntent::TaskRepair { .. } => helper_write_team_scoped(workspace, state),
|
|
796
|
-
// SelfMigration persists through the root helper.
|
|
797
|
-
StateWriteIntent::SelfMigration => helper_write_root(workspace, state),
|
|
798
|
-
}
|
|
799
|
-
}
|
|
800
|
-
|
|
801
|
-
// Route intents that historically used the `_reapplying_after_conflict`
|
|
802
|
-
// helper family. Behavior stays identical: S1a chooses the same helper the
|
|
803
|
-
// legacy caller would have chosen for a reapply.
|
|
804
|
-
#[derive(Clone, Copy, Eq, PartialEq)]
|
|
805
|
-
enum ReapplyScope {
|
|
806
|
-
Root,
|
|
807
|
-
Team,
|
|
808
|
-
}
|
|
809
|
-
|
|
810
|
-
fn reapply_scope(intent: &StateWriteIntent<'_>) -> ReapplyScope {
|
|
811
|
-
if matches!(
|
|
812
|
-
intent,
|
|
813
|
-
StateWriteIntent::RestartSessionRepair { .. }
|
|
814
|
-
| StateWriteIntent::MessagingDeliveryState {
|
|
815
|
-
owner_team_id: Some(_),
|
|
816
|
-
}
|
|
817
|
-
| StateWriteIntent::ResultCollection {
|
|
818
|
-
owner_team_id: Some(_),
|
|
819
|
-
}
|
|
820
|
-
| StateWriteIntent::CoordinatorTick { .. }
|
|
821
|
-
) {
|
|
822
|
-
ReapplyScope::Team
|
|
823
|
-
} else {
|
|
824
|
-
ReapplyScope::Root
|
|
825
|
-
}
|
|
826
|
-
}
|
|
827
|
-
|
|
828
|
-
fn route_reapply<F>(
|
|
829
|
-
workspace: &Path,
|
|
830
|
-
intent: StateWriteIntent<'_>,
|
|
831
|
-
state: &Value,
|
|
832
|
-
reapply: F,
|
|
833
|
-
) -> Result<(), StateError>
|
|
834
|
-
where
|
|
835
|
-
F: FnOnce(&mut Value),
|
|
836
|
-
{
|
|
837
|
-
if matches!(&intent, StateWriteIntent::ResultCollection { .. })
|
|
838
|
-
{
|
|
839
|
-
return StateRepository::new(workspace).commit(intent, reapply).map(|_| ());
|
|
840
|
-
}
|
|
841
|
-
if reapply_scope(&intent) == ReapplyScope::Team {
|
|
842
|
-
helper_write_team_scoped_reapply(workspace, state, reapply)
|
|
843
|
-
} else {
|
|
844
|
-
helper_write_root_reapply(workspace, state, reapply)
|
|
845
|
-
}
|
|
846
|
-
}
|
|
847
|
-
|
|
848
|
-
#[cfg(test)]
|
|
849
|
-
mod tests;
|
|
850
|
-
|
|
851
|
-
#[cfg(test)]
|
|
852
|
-
pub(crate) mod test_support {
|
|
853
|
-
thread_local! {
|
|
854
|
-
static BEFORE_COMMIT: std::cell::RefCell<Option<Box<dyn FnOnce()>>> = const {
|
|
855
|
-
std::cell::RefCell::new(None)
|
|
856
|
-
};
|
|
857
|
-
}
|
|
858
|
-
|
|
859
|
-
pub(crate) fn set_before_commit(hook: impl FnOnce() + 'static) {
|
|
860
|
-
BEFORE_COMMIT.with(|slot| *slot.borrow_mut() = Some(Box::new(hook)));
|
|
861
|
-
}
|
|
862
|
-
|
|
863
|
-
pub(super) fn before_commit() {
|
|
864
|
-
if let Some(hook) = BEFORE_COMMIT.with(|slot| slot.borrow_mut().take()) { hook(); }
|
|
865
|
-
}
|
|
866
|
-
}
|