@team-agent/installer 0.5.128 → 0.6.1
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 +4 -4
- package/README.zh.md +1 -1
- package/package.json +4 -8
- package/skills/team-agent/SKILL.md +37 -20
- package/skills/team-agent/command-coverage.json +169 -183
- package/skills/team-agent/docs/reference/team-agent-operator.md +64 -30
- package/skills/team-agent/references/recovery-runbook.md +1 -1
- package/skills/team-agent/references/team-agent-operator.md +64 -30
- 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 -1288
- package/crates/team-agent/src/cli/arguments.rs +0 -405
- package/crates/team-agent/src/cli/attach_app_server_leader.rs +0 -98
- package/crates/team-agent/src/cli/diagnose.rs +0 -1721
- package/crates/team-agent/src/cli/emit.rs +0 -2930
- 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 -1216
- package/crates/team-agent/src/cli/intent/runtime_tests.rs +0 -912
- package/crates/team-agent/src/cli/intent/tests.rs +0 -689
- 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 -6545
- package/crates/team-agent/src/cli/models.rs +0 -1206
- 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/schedule.rs +0 -175
- 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 -156
- 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 -199
- package/crates/team-agent/src/cli/shutdown_socket.rs +0 -288
- package/crates/team-agent/src/cli/spec.rs +0 -165
- 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 -1981
- 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 -322
- 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 -761
- package/crates/team-agent/src/cli/tests/parser_safety.rs +0 -383
- package/crates/team-agent/src/cli/tests/run_delegation.rs +0 -484
- 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 -888
- 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 -827
- package/crates/team-agent/src/compiler.rs +0 -890
- 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 -1744
- package/crates/team-agent/src/contract_runtime/commands.rs +0 -671
- package/crates/team-agent/src/contract_runtime/config.rs +0 -364
- package/crates/team-agent/src/contract_runtime/config_tests.rs +0 -76
- package/crates/team-agent/src/contract_runtime/discovery.rs +0 -449
- package/crates/team-agent/src/contract_runtime/fork.rs +0 -361
- package/crates/team-agent/src/contract_runtime/forward.rs +0 -288
- package/crates/team-agent/src/contract_runtime/framework.rs +0 -367
- package/crates/team-agent/src/contract_runtime/mcp.rs +0 -394
- 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 -553
- 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 -300
- 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 -503
- 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 -3024
- 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 -1527
- 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/direct_delivery.rs +0 -368
- 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/inbox_store.rs +0 -169
- 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 -888
- package/crates/team-agent/src/leader/start.rs +0 -4501
- 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 -268
- 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 -147
- package/crates/team-agent/src/lifecycle/helpers.rs +0 -212
- package/crates/team-agent/src/lifecycle/launch/add_agent.rs +0 -881
- package/crates/team-agent/src/lifecycle/launch/add_agent_state.rs +0 -598
- package/crates/team-agent/src/lifecycle/launch/agent_state.rs +0 -332
- package/crates/team-agent/src/lifecycle/launch/clone_agent.rs +0 -204
- package/crates/team-agent/src/lifecycle/launch/fork_agent.rs +0 -107
- package/crates/team-agent/src/lifecycle/launch/fork_entry.rs +0 -144
- 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 -160
- package/crates/team-agent/src/lifecycle/launch/ownership.rs +0 -105
- package/crates/team-agent/src/lifecycle/launch/pi_mcp.rs +0 -899
- package/crates/team-agent/src/lifecycle/launch/pi_mcp_extension.js +0 -225
- package/crates/team-agent/src/lifecycle/launch/plan.rs +0 -269
- package/crates/team-agent/src/lifecycle/launch/quick_start.rs +0 -5200
- 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 -473
- 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 -557
- 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 -1067
- package/crates/team-agent/src/lifecycle/profile_smoke.rs +0 -557
- package/crates/team-agent/src/lifecycle/restart/agent.rs +0 -2199
- package/crates/team-agent/src/lifecycle/restart/avatar.rs +0 -1798
- package/crates/team-agent/src/lifecycle/restart/claude_fork.rs +0 -163
- package/crates/team-agent/src/lifecycle/restart/common.rs +0 -2362
- 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 -227
- package/crates/team-agent/src/lifecycle/role_config.rs +0 -1230
- 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_compatible_config_red.rs +0 -325
- package/crates/team-agent/src/lifecycle/tests/claude_profile_launch_red.rs +0 -447
- package/crates/team-agent/src/lifecycle/tests/cli_argv_routing_red.rs +0 -1638
- 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 -770
- package/crates/team-agent/src/lifecycle/tests/communication_mode_runtime_contract_red.rs +0 -419
- package/crates/team-agent/src/lifecycle/tests/copilot_provider_red.rs +0 -2035
- package/crates/team-agent/src/lifecycle/tests/core.rs +0 -1327
- 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 -72
- 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 -512
- 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 -3983
- 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 -164
- package/crates/team-agent/src/lifecycle/tests/pi_command_red.rs +0 -200
- package/crates/team-agent/src/lifecycle/tests/pi_compiler_red.rs +0 -210
- package/crates/team-agent/src/lifecycle/tests/pi_dual_entry_red.rs +0 -527
- package/crates/team-agent/src/lifecycle/tests/pi_executable_mcp_red.rs +0 -1062
- package/crates/team-agent/src/lifecycle/tests/pi_fork_session_inheritance_red.rs +0 -1419
- package/crates/team-agent/src/lifecycle/tests/pi_lifecycle_doctor_red.rs +0 -98
- package/crates/team-agent/src/lifecycle/tests/pi_native_mcp_capability_red.rs +0 -550
- package/crates/team-agent/src/lifecycle/tests/pi_session_delivery_red.rs +0 -226
- package/crates/team-agent/src/lifecycle/tests/quick_start_worker_readiness_red.rs +0 -332
- 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 -342
- 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 -995
- package/crates/team-agent/src/lifecycle/tests/worker_spawn_env_red.rs +0 -836
- package/crates/team-agent/src/lifecycle/tests.rs +0 -105
- package/crates/team-agent/src/lifecycle/types.rs +0 -877
- package/crates/team-agent/src/lifecycle/worker_command_context.rs +0 -363
- 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 -527
- package/crates/team-agent/src/mcp_server/readiness_tests.rs +0 -348
- 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 -158
- package/crates/team-agent/src/mcp_server/tests/send.rs +0 -353
- package/crates/team-agent/src/mcp_server/tests/tools.rs +0 -341
- 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 -889
- 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 -3727
- 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 -336
- 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 -167
- 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/reminders.rs +0 -316
- 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 -223
- 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 -657
- 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 -3549
- package/crates/team-agent/src/messaging/tests/spine.rs +0 -853
- 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 -472
- 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 -1150
- package/crates/team-agent/src/provider/adapters/claude.rs +0 -78
- package/crates/team-agent/src/provider/adapters/claude_fork.rs +0 -131
- 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 -30
- package/crates/team-agent/src/provider/adapters/pi.rs +0 -106
- 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 -708
- 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 -910
- package/crates/team-agent/src/provider/session/capture.rs +0 -2731
- package/crates/team-agent/src/provider/session/context_fork/claude.rs +0 -123
- package/crates/team-agent/src/provider/session/context_fork/outcome.rs +0 -172
- package/crates/team-agent/src/provider/session/context_fork.rs +0 -396
- 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/claude.rs +0 -523
- package/crates/team-agent/src/provider/session_scan/common/tests.rs +0 -316
- package/crates/team-agent/src/provider/session_scan/common.rs +0 -654
- package/crates/team-agent/src/provider/session_scan/copilot.rs +0 -280
- package/crates/team-agent/src/provider/session_scan/pi.rs +0 -185
- package/crates/team-agent/src/provider/session_scan.rs +0 -71
- 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 -441
- package/crates/team-agent/src/provider/tests/classify.rs +0 -148
- package/crates/team-agent/src/provider/tests/command_helpers.rs +0 -35
- 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 -177
- 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 -394
- 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/test_support/models_timeout_fixture.rs +0 -144
- 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 -4103
- package/crates/team-agent/src/tmux_backend.rs +0 -4492
- 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,624 +0,0 @@
|
|
|
1
|
-
//! ---
|
|
2
|
-
//! purpose: 冷启后把席位实况投影进 runtime state,并做团队级合并、投影与 owner 清洗
|
|
3
|
-
//! contract:
|
|
4
|
-
//! provides:
|
|
5
|
-
//! - name: persist_spawn_agent_state
|
|
6
|
-
//! what: 按 spawn 结果与 tmux 实况写出各席位状态,分 running/paused/spawn_failed
|
|
7
|
-
//! - name: save_launched_team_state_for_key
|
|
8
|
-
//! what: 把本次团队状态并入既有 state,投影后经 repository 落盘
|
|
9
|
-
//! - name: merge_workspace_team_state_with_key
|
|
10
|
-
//! what: 以显式团队键把本次状态并进 teams 表,不丢既有团队
|
|
11
|
-
//! - name: drop_worker_pane_seeded_owner
|
|
12
|
-
//! what: 识别出被 worker pane 误种的 owner 并改种 unbound owner
|
|
13
|
-
//! depends:
|
|
14
|
-
//! - crate::state::repository
|
|
15
|
-
//! - crate::state::projection
|
|
16
|
-
//! - crate::state::persist
|
|
17
|
-
//! - crate::state::ownership
|
|
18
|
-
//! - crate::tmux_backend
|
|
19
|
-
//! - crate::lifecycle::launch::agent_state
|
|
20
|
-
//! - crate::lifecycle::launch::identity
|
|
21
|
-
//! - crate::lifecycle::launch::leader_context
|
|
22
|
-
//! - crate::lifecycle::launch::spec_state
|
|
23
|
-
//! - crate::lifecycle::launch::worker_env
|
|
24
|
-
//! boundary:
|
|
25
|
-
//! - 只写 state,不 spawn、不 kill、不开显示
|
|
26
|
-
//! - 落盘一律经 StateRepository 带写意图,不直接改文件
|
|
27
|
-
//! - owner 归属判不准时倒向 unbound,不认领他队的 pane
|
|
28
|
-
//! maturity: wired
|
|
29
|
-
//! ---
|
|
30
|
-
//!
|
|
31
|
-
use std::collections::{BTreeMap, BTreeSet};
|
|
32
|
-
use std::path::{Path, PathBuf};
|
|
33
|
-
use std::process::Command;
|
|
34
|
-
|
|
35
|
-
use crate::lifecycle::lock::{acquire_agent_lifecycle_lock, LifecycleLockRequest};
|
|
36
|
-
use crate::lifecycle::profile_launch::parse_provider;
|
|
37
|
-
use crate::lifecycle::*;
|
|
38
|
-
use crate::model::enums::{AuthMode, PaneLiveness, Provider, ProviderEffort};
|
|
39
|
-
use crate::model::ids::AgentId;
|
|
40
|
-
use crate::model::yaml::{self, Value};
|
|
41
|
-
use crate::state::persist::load_runtime_state;
|
|
42
|
-
use crate::transport::{PaneId, SessionName, Target, Transport};
|
|
43
|
-
|
|
44
|
-
use super::agent_state::running_agent_state;
|
|
45
|
-
use super::identity::{explicit_active_team_key, runtime_team_key_for_spec};
|
|
46
|
-
use super::leader_context::{
|
|
47
|
-
owner_pane_belongs_to_other_team, seed_unbound_launched_owner, unbound_launched_owner,
|
|
48
|
-
};
|
|
49
|
-
use super::spec_state::{has_positive_caller_leader_env, spec_agent_values};
|
|
50
|
-
use super::worker_env::{agent_is_paused, spawn_timestamp_for_agent};
|
|
51
|
-
|
|
52
|
-
/// ---
|
|
53
|
-
/// purpose: 把本次 spawn 的结果写成 runtime state 里的各席位状态
|
|
54
|
-
/// params:
|
|
55
|
-
/// started: 本次 spawn 成功返回的席位
|
|
56
|
-
/// transport: 用于查活窗口与 pane pid
|
|
57
|
-
/// returns: 成功返回空值。spec 里 paused 的席位记 paused,spawn 后窗口不在的记 spawn_failed,其余记 running
|
|
58
|
-
/// errors: 读或写 runtime state 失败时返回 StatePersist
|
|
59
|
-
/// ---
|
|
60
|
-
pub(super) fn persist_spawn_agent_state(
|
|
61
|
-
workspace: &Path,
|
|
62
|
-
spec_path: &Path,
|
|
63
|
-
spec: &Value,
|
|
64
|
-
session_name: &SessionName,
|
|
65
|
-
transport: &dyn Transport,
|
|
66
|
-
started: &[StartedAgent],
|
|
67
|
-
) -> Result<(), LifecycleError> {
|
|
68
|
-
let state_path = crate::state::persist::runtime_state_path(workspace);
|
|
69
|
-
let mut state = match crate::state::repository::StateRepository::new(workspace)
|
|
70
|
-
.load_workspace_if_exists_without_migrations()
|
|
71
|
-
{
|
|
72
|
-
Ok(Some(state)) => state,
|
|
73
|
-
Ok(None) => serde_json::json!({"agents": {}}),
|
|
74
|
-
Err(crate::state::StateError::Io(error)) => {
|
|
75
|
-
return Err(LifecycleError::StatePersist(format!(
|
|
76
|
-
"{}: {error}",
|
|
77
|
-
state_path.display()
|
|
78
|
-
)))
|
|
79
|
-
}
|
|
80
|
-
Err(crate::state::StateError::Json(error)) => {
|
|
81
|
-
return Err(LifecycleError::StatePersist(format!(
|
|
82
|
-
"{}: {error}",
|
|
83
|
-
state_path.display()
|
|
84
|
-
)))
|
|
85
|
-
}
|
|
86
|
-
Err(error) => {
|
|
87
|
-
return Err(LifecycleError::StatePersist(format!(
|
|
88
|
-
"{}: {error}",
|
|
89
|
-
state_path.display()
|
|
90
|
-
)))
|
|
91
|
-
}
|
|
92
|
-
};
|
|
93
|
-
let team_id = runtime_team_key_for_spec(spec_path, spec, session_name);
|
|
94
|
-
let worker_tmux_socket = launched_worker_tmux_socket(transport, workspace);
|
|
95
|
-
drop_worker_pane_seeded_owner(&mut state, &team_id, started, worker_tmux_socket.as_deref());
|
|
96
|
-
// Only persist running state for agents whose spawn still has a live target.
|
|
97
|
-
let live_windows: BTreeSet<String> = transport
|
|
98
|
-
.list_windows(session_name)
|
|
99
|
-
.unwrap_or_default()
|
|
100
|
-
.into_iter()
|
|
101
|
-
.map(|w| w.as_str().to_string())
|
|
102
|
-
.collect();
|
|
103
|
-
let live_started_agents: BTreeSet<String> = started
|
|
104
|
-
.iter()
|
|
105
|
-
.map(|agent| agent.agent_id.as_str().to_string())
|
|
106
|
-
.collect();
|
|
107
|
-
let pane_pids_by_agent = pane_pids_by_started_agent(transport, started);
|
|
108
|
-
// E5 解耦:profiles 随**角色定义**(team_dir),不随 spec(已迁出到 .team/runtime)。
|
|
109
|
-
// 优先 state.team_dir(角色目录),回落 spec_path.parent()(legacy 同目录布局)。
|
|
110
|
-
let profile_dir = state
|
|
111
|
-
.get("team_dir")
|
|
112
|
-
.and_then(serde_json::Value::as_str)
|
|
113
|
-
.filter(|s| !s.is_empty())
|
|
114
|
-
.map(|dir| Path::new(dir).join("profiles"))
|
|
115
|
-
.unwrap_or_else(|| spec_path.parent().unwrap_or(workspace).join("profiles"));
|
|
116
|
-
let mut agents = serde_json::Map::new();
|
|
117
|
-
let mut spawn_index = 0_u32;
|
|
118
|
-
for agent in spec_agent_values(spec) {
|
|
119
|
-
let Some(id) = agent.get("id").and_then(Value::as_str) else {
|
|
120
|
-
continue;
|
|
121
|
-
};
|
|
122
|
-
#[cfg(unix)]
|
|
123
|
-
if let Some(descriptor) = agent
|
|
124
|
-
.get("provider")
|
|
125
|
-
.and_then(Value::as_str)
|
|
126
|
-
.and_then(crate::contract_runtime::registry::descriptor)
|
|
127
|
-
{
|
|
128
|
-
let projected = if agent_is_paused(agent) {
|
|
129
|
-
serde_json::json!({"agent_id":id,"provider":descriptor.identity.id,"runtime_family":"contract","status":"paused","paused":true,"contract_instance":null,"pane_id":null})
|
|
130
|
-
} else {
|
|
131
|
-
crate::contract_runtime::framework::project_seat(workspace, &team_id, id)
|
|
132
|
-
.map_err(|error| LifecycleError::StatePersist(error.to_string()))?
|
|
133
|
-
};
|
|
134
|
-
agents.insert(id.to_string(), projected);
|
|
135
|
-
continue;
|
|
136
|
-
}
|
|
137
|
-
let provider = agent
|
|
138
|
-
.get("provider")
|
|
139
|
-
.and_then(Value::as_str)
|
|
140
|
-
.and_then(parse_provider)
|
|
141
|
-
.unwrap_or(Provider::Codex);
|
|
142
|
-
if agent_is_paused(agent) {
|
|
143
|
-
let mut paused = serde_json::Map::new();
|
|
144
|
-
paused.insert("status".to_string(), serde_json::json!("paused"));
|
|
145
|
-
paused.insert("provider".to_string(), serde_json::json!(provider));
|
|
146
|
-
agents.insert(id.to_string(), serde_json::Value::Object(paused));
|
|
147
|
-
continue;
|
|
148
|
-
}
|
|
149
|
-
let started_agent = started.iter().find(|agent| agent.agent_id.as_str() == id);
|
|
150
|
-
let window = agent.get("window").and_then(Value::as_str).unwrap_or(id);
|
|
151
|
-
if !live_started_agents.contains(id)
|
|
152
|
-
|| (!live_windows.is_empty() && !live_windows.contains(window))
|
|
153
|
-
{
|
|
154
|
-
let mut failed = serde_json::Map::new();
|
|
155
|
-
failed.insert("status".to_string(), serde_json::json!("spawn_failed"));
|
|
156
|
-
failed.insert("provider".to_string(), serde_json::json!(provider));
|
|
157
|
-
failed.insert("agent_id".to_string(), serde_json::json!(id));
|
|
158
|
-
failed.insert("window".to_string(), serde_json::json!(window));
|
|
159
|
-
failed.insert(
|
|
160
|
-
"reason".to_string(),
|
|
161
|
-
serde_json::json!("tmux window not present after spawn"),
|
|
162
|
-
);
|
|
163
|
-
agents.insert(id.to_string(), serde_json::Value::Object(failed));
|
|
164
|
-
continue;
|
|
165
|
-
}
|
|
166
|
-
let pane_pid = pane_pids_by_agent.get(id).copied();
|
|
167
|
-
let spawned_at = started_agent
|
|
168
|
-
.map(|started| started.spawned_at.clone())
|
|
169
|
-
.unwrap_or_else(|| spawn_timestamp_for_agent(spawn_index));
|
|
170
|
-
spawn_index = spawn_index.saturating_add(1);
|
|
171
|
-
agents.insert(
|
|
172
|
-
id.to_string(),
|
|
173
|
-
running_agent_state(
|
|
174
|
-
agent,
|
|
175
|
-
id,
|
|
176
|
-
provider,
|
|
177
|
-
workspace,
|
|
178
|
-
workspace,
|
|
179
|
-
&spawned_at,
|
|
180
|
-
&team_id,
|
|
181
|
-
Some(agent_id_to_pane_id(started, id)),
|
|
182
|
-
pane_pid,
|
|
183
|
-
started_agent,
|
|
184
|
-
Some(&profile_dir),
|
|
185
|
-
)?,
|
|
186
|
-
);
|
|
187
|
-
}
|
|
188
|
-
let generation = started
|
|
189
|
-
.first()
|
|
190
|
-
.map(|agent| agent.spawned_at.as_str())
|
|
191
|
-
.unwrap_or(session_name.as_str());
|
|
192
|
-
// Use the same birth identity as the native session owner marker. Worker
|
|
193
|
-
// spawned_at may change on start-agent; this session generation must not.
|
|
194
|
-
if let Some(obj) = state.as_object_mut() {
|
|
195
|
-
obj.insert("agents".to_string(), serde_json::Value::Object(agents));
|
|
196
|
-
obj.insert("generation".to_string(), serde_json::json!(generation));
|
|
197
|
-
} else {
|
|
198
|
-
state = serde_json::json!({"agents": agents, "generation": generation});
|
|
199
|
-
}
|
|
200
|
-
save_launched_team_state_for_key(workspace, &state, Some(&team_id), None)
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
/// ---
|
|
204
|
-
/// purpose: 给出各已起席位对应 pane 的进程号
|
|
205
|
-
/// returns: agent_id 到 pane pid 的映射,查不到的席位不出现
|
|
206
|
-
/// ---
|
|
207
|
-
pub(super) fn pane_pids_by_started_agent(
|
|
208
|
-
transport: &dyn Transport,
|
|
209
|
-
started: &[StartedAgent],
|
|
210
|
-
) -> BTreeMap<String, u32> {
|
|
211
|
-
let panes = transport.list_targets().unwrap_or_default();
|
|
212
|
-
started
|
|
213
|
-
.iter()
|
|
214
|
-
.filter_map(|agent| {
|
|
215
|
-
panes
|
|
216
|
-
.iter()
|
|
217
|
-
.find(|pane| pane.pane_id.as_str() == agent.target)
|
|
218
|
-
.and_then(|pane| pane.pane_pid)
|
|
219
|
-
.map(|pid| (agent.agent_id.as_str().to_string(), pid))
|
|
220
|
-
})
|
|
221
|
-
.collect()
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
/// ---
|
|
225
|
-
/// purpose: 由 agent id 找出它这次 spawn 的目标 pane
|
|
226
|
-
/// returns: 命中的 pane 串,找不到时为空串
|
|
227
|
-
/// ---
|
|
228
|
-
pub(super) fn agent_id_to_pane_id<'a>(started: &'a [StartedAgent], agent_id: &str) -> &'a str {
|
|
229
|
-
started
|
|
230
|
-
.iter()
|
|
231
|
-
.find(|agent| agent.agent_id.as_str() == agent_id)
|
|
232
|
-
.map(|agent| agent.target.as_str())
|
|
233
|
-
.unwrap_or("")
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
/// ---
|
|
237
|
-
/// purpose: 不带显式团队键地保存本次团队状态
|
|
238
|
-
/// returns: 成功返回空值
|
|
239
|
-
/// errors: 落盘失败时返回 StatePersist
|
|
240
|
-
/// contract_id: lifecycle.state_projection.save_launched_team_state
|
|
241
|
-
/// ---
|
|
242
|
-
pub(super) fn save_launched_team_state(
|
|
243
|
-
workspace: &Path,
|
|
244
|
-
launched: &serde_json::Value,
|
|
245
|
-
) -> Result<(), LifecycleError> {
|
|
246
|
-
save_launched_team_state_for_key(workspace, launched, None, None)
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
/// ---
|
|
250
|
-
/// purpose: 保存本次团队状态的实体实现,含团队键钉死、owner 清洗、合并与投影
|
|
251
|
-
/// params:
|
|
252
|
-
/// team_key: 显式团队键,为空则由 state 推算
|
|
253
|
-
/// added_agent_id: 本次新增席位 id,写进写意图
|
|
254
|
-
/// returns: 成功返回空值
|
|
255
|
-
/// errors: 落盘失败时返回 StatePersist
|
|
256
|
-
/// contract_id: lifecycle.state_projection.save_launched_team_state
|
|
257
|
-
/// ---
|
|
258
|
-
pub(super) fn save_launched_team_state_for_key(
|
|
259
|
-
workspace: &Path,
|
|
260
|
-
launched: &serde_json::Value,
|
|
261
|
-
team_key: Option<&str>,
|
|
262
|
-
added_agent_id: Option<&str>,
|
|
263
|
-
) -> Result<(), LifecycleError> {
|
|
264
|
-
let existing = load_runtime_state(workspace).unwrap_or_else(|_| serde_json::json!({}));
|
|
265
|
-
let launched_key = team_key
|
|
266
|
-
.filter(|key| !key.is_empty())
|
|
267
|
-
.map(str::to_string)
|
|
268
|
-
.unwrap_or_else(|| crate::state::projection::team_state_key(launched));
|
|
269
|
-
let mut launched = launched.clone();
|
|
270
|
-
if let Some(obj) = launched.as_object_mut() {
|
|
271
|
-
// RM-039-STAT-001 second-round fix (architect verdict
|
|
272
|
-
// 2026-06-22): the canonical runtime team key MUST be written
|
|
273
|
-
// explicitly to `state.team_key`, not only inferred from
|
|
274
|
-
// `team_dir` by `team_state_key`'s cascade. The historical
|
|
275
|
-
// bug: when `team_dir = "./.team/current"` and the runtime team
|
|
276
|
-
// is `rm039-status-working-891`, `team_state_key` cascades to
|
|
277
|
-
// the team_dir basename (`current`), but `active_team_key` is
|
|
278
|
-
// the real team key. Coordinator tick uses `team_state_key`
|
|
279
|
-
// when saving the team-scoped state, so writes land on
|
|
280
|
-
// `teams.current` instead of `teams.<active_team_key>`. Status
|
|
281
|
-
// reads `teams[active_team_key]`, sees stale data.
|
|
282
|
-
//
|
|
283
|
-
// Writing `team_key=launched_key` here pins the first branch of
|
|
284
|
-
// `team_state_key` so the cascade returns the canonical runtime
|
|
285
|
-
// team key everywhere — coordinator tick, save_team_scoped_state,
|
|
286
|
-
// and status selector all agree.
|
|
287
|
-
obj.insert(
|
|
288
|
-
"team_key".to_string(),
|
|
289
|
-
serde_json::Value::String(launched_key.clone()),
|
|
290
|
-
);
|
|
291
|
-
obj.insert(
|
|
292
|
-
"active_team_key".to_string(),
|
|
293
|
-
serde_json::Value::String(launched_key.clone()),
|
|
294
|
-
);
|
|
295
|
-
obj.entry("is_external_leader".to_string())
|
|
296
|
-
.or_insert(serde_json::Value::Bool(false));
|
|
297
|
-
}
|
|
298
|
-
promote_launched_binding_from_team_entry(&mut launched, &launched_key);
|
|
299
|
-
preserve_existing_leader_topology(&existing, &launched_key, &mut launched);
|
|
300
|
-
drop_foreign_seeded_owner(&existing, &launched_key, &mut launched);
|
|
301
|
-
drop_bare_worker_seeded_owner(&mut launched, &launched_key);
|
|
302
|
-
let merged = if team_key.is_some() {
|
|
303
|
-
merge_workspace_team_state_with_key(&existing, &launched, &launched_key)
|
|
304
|
-
} else {
|
|
305
|
-
crate::state::projection::merge_workspace_team_state(&existing, &launched)
|
|
306
|
-
};
|
|
307
|
-
let mut projected = crate::state::projection::project_top_level_view(&merged, &launched_key);
|
|
308
|
-
drop_unbound_top_level_owner(&mut projected);
|
|
309
|
-
let intent = crate::state::repository::StateWriteIntent::launch_team_or_add_agent(
|
|
310
|
-
&launched_key,
|
|
311
|
-
added_agent_id,
|
|
312
|
-
);
|
|
313
|
-
crate::state::repository::StateRepository::new(workspace)
|
|
314
|
-
.save(intent, &projected)
|
|
315
|
-
.map_err(|e| LifecycleError::StatePersist(e.to_string()))
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
/// ---
|
|
319
|
-
/// purpose: 本次状态没写 leader 拓扑字段时,从既有状态里补回来
|
|
320
|
-
/// params:
|
|
321
|
-
/// launched: 就地补 is_external_leader 与 leader_client,已有同名键不覆盖
|
|
322
|
-
/// ---
|
|
323
|
-
pub(super) fn preserve_existing_leader_topology(
|
|
324
|
-
existing: &serde_json::Value,
|
|
325
|
-
launched_key: &str,
|
|
326
|
-
launched: &mut serde_json::Value,
|
|
327
|
-
) {
|
|
328
|
-
let Some(obj) = launched.as_object_mut() else {
|
|
329
|
-
return;
|
|
330
|
-
};
|
|
331
|
-
let existing_team = existing
|
|
332
|
-
.get("teams")
|
|
333
|
-
.and_then(serde_json::Value::as_object)
|
|
334
|
-
.and_then(|teams| teams.get(launched_key))
|
|
335
|
-
.unwrap_or(existing);
|
|
336
|
-
for key in ["is_external_leader", "leader_client"] {
|
|
337
|
-
if !obj.contains_key(key) {
|
|
338
|
-
if let Some(value) = existing_team.get(key).or_else(|| existing.get(key)) {
|
|
339
|
-
obj.insert(key.to_string(), value.clone());
|
|
340
|
-
}
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
/// ---
|
|
346
|
-
/// purpose: 无 leader 身份环境且 owner pane 形如首席 pane 时改种 unbound owner
|
|
347
|
-
/// params:
|
|
348
|
-
/// launched: 就地改写
|
|
349
|
-
/// ---
|
|
350
|
-
pub(super) fn drop_bare_worker_seeded_owner(launched: &mut serde_json::Value, launched_key: &str) {
|
|
351
|
-
if has_positive_caller_leader_env() {
|
|
352
|
-
return;
|
|
353
|
-
}
|
|
354
|
-
let pane = launched
|
|
355
|
-
.get("team_owner")
|
|
356
|
-
.and_then(|owner| owner.get("pane_id"))
|
|
357
|
-
.and_then(serde_json::Value::as_str)
|
|
358
|
-
.unwrap_or("");
|
|
359
|
-
if pane.ends_with("-first") {
|
|
360
|
-
seed_unbound_launched_owner(launched, launched_key);
|
|
361
|
-
}
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
/// ---
|
|
365
|
-
/// purpose: 以显式团队键把本次状态并进 teams 表
|
|
366
|
-
/// returns: 合并后的 state;既有顶层 session 名为空或团队键相同时保留既有 teams 并覆盖本键,否则以既有状态为底再补进本次团队
|
|
367
|
-
/// ---
|
|
368
|
-
pub(super) fn merge_workspace_team_state_with_key(
|
|
369
|
-
existing: &serde_json::Value,
|
|
370
|
-
launched: &serde_json::Value,
|
|
371
|
-
launched_key: &str,
|
|
372
|
-
) -> serde_json::Value {
|
|
373
|
-
let mut launched_obj = launched.as_object().cloned().unwrap_or_default();
|
|
374
|
-
let mut teams = existing
|
|
375
|
-
.get("teams")
|
|
376
|
-
.and_then(serde_json::Value::as_object)
|
|
377
|
-
.cloned()
|
|
378
|
-
.unwrap_or_default();
|
|
379
|
-
let launched_entry = crate::state::projection::compact_team_state(launched);
|
|
380
|
-
if !existing
|
|
381
|
-
.get("session_name")
|
|
382
|
-
.and_then(serde_json::Value::as_str)
|
|
383
|
-
.is_some_and(|session| !session.is_empty())
|
|
384
|
-
{
|
|
385
|
-
teams.insert(launched_key.to_string(), launched_entry);
|
|
386
|
-
launched_obj.insert("teams".to_string(), serde_json::Value::Object(teams));
|
|
387
|
-
return serde_json::Value::Object(launched_obj);
|
|
388
|
-
}
|
|
389
|
-
|
|
390
|
-
let existing_key = explicit_active_team_key(existing)
|
|
391
|
-
.unwrap_or_else(|| crate::state::projection::team_state_key(existing));
|
|
392
|
-
if existing_key == launched_key {
|
|
393
|
-
let mut teams = existing
|
|
394
|
-
.get("teams")
|
|
395
|
-
.and_then(serde_json::Value::as_object)
|
|
396
|
-
.cloned()
|
|
397
|
-
.unwrap_or_default();
|
|
398
|
-
teams.insert(launched_key.to_string(), launched_entry);
|
|
399
|
-
launched_obj.insert("teams".to_string(), serde_json::Value::Object(teams));
|
|
400
|
-
return serde_json::Value::Object(launched_obj);
|
|
401
|
-
}
|
|
402
|
-
|
|
403
|
-
let mut merged = existing.as_object().cloned().unwrap_or_default();
|
|
404
|
-
let mut teams = merged
|
|
405
|
-
.get("teams")
|
|
406
|
-
.and_then(serde_json::Value::as_object)
|
|
407
|
-
.cloned()
|
|
408
|
-
.unwrap_or_default();
|
|
409
|
-
teams
|
|
410
|
-
.entry(existing_key)
|
|
411
|
-
.or_insert_with(|| crate::state::projection::compact_team_state(existing));
|
|
412
|
-
teams.insert(launched_key.to_string(), launched_entry);
|
|
413
|
-
merged.insert("teams".to_string(), serde_json::Value::Object(teams));
|
|
414
|
-
serde_json::Value::Object(merged)
|
|
415
|
-
}
|
|
416
|
-
|
|
417
|
-
#[cfg(test)]
|
|
418
|
-
mod merge_workspace_team_state_with_key_tests {
|
|
419
|
-
use super::*;
|
|
420
|
-
use serde_json::json;
|
|
421
|
-
|
|
422
|
-
#[test]
|
|
423
|
-
fn empty_top_level_existing_session_preserves_existing_teams() {
|
|
424
|
-
let existing = json!({
|
|
425
|
-
"session_name": "",
|
|
426
|
-
"active_team_key": "parent",
|
|
427
|
-
"teams": {
|
|
428
|
-
"parent": {
|
|
429
|
-
"session_name": "team-parent",
|
|
430
|
-
"agents": {"parent_worker": {"status": "running"}}
|
|
431
|
-
}
|
|
432
|
-
}
|
|
433
|
-
});
|
|
434
|
-
let launched = json!({
|
|
435
|
-
"session_name": "team-child",
|
|
436
|
-
"agents": {"child_worker": {"status": "running"}}
|
|
437
|
-
});
|
|
438
|
-
let merged = merge_workspace_team_state_with_key(&existing, &launched, "child");
|
|
439
|
-
assert_eq!(
|
|
440
|
-
merged.pointer("/teams/parent/session_name"),
|
|
441
|
-
Some(&json!("team-parent")),
|
|
442
|
-
"existing.teams must survive even when existing.session_name is empty: {merged}"
|
|
443
|
-
);
|
|
444
|
-
assert_eq!(
|
|
445
|
-
merged.pointer("/teams/child/session_name"),
|
|
446
|
-
Some(&json!("team-child")),
|
|
447
|
-
"launched team must still be inserted under its runtime key: {merged}"
|
|
448
|
-
);
|
|
449
|
-
}
|
|
450
|
-
}
|
|
451
|
-
|
|
452
|
-
/// ---
|
|
453
|
-
/// purpose: 把 teams 表里本团队的绑定字段提到顶层
|
|
454
|
-
/// params:
|
|
455
|
-
/// launched: 就地补 leader_receiver、team_owner 与 owner_epoch,已有同名键不覆盖
|
|
456
|
-
/// ---
|
|
457
|
-
pub(super) fn promote_launched_binding_from_team_entry(
|
|
458
|
-
launched: &mut serde_json::Value,
|
|
459
|
-
launched_key: &str,
|
|
460
|
-
) {
|
|
461
|
-
let entry = launched
|
|
462
|
-
.get("teams")
|
|
463
|
-
.and_then(|teams| teams.get(launched_key))
|
|
464
|
-
.cloned();
|
|
465
|
-
let Some(entry) = entry else {
|
|
466
|
-
return;
|
|
467
|
-
};
|
|
468
|
-
let Some(obj) = launched.as_object_mut() else {
|
|
469
|
-
return;
|
|
470
|
-
};
|
|
471
|
-
for key in ["leader_receiver", "team_owner", "owner_epoch"] {
|
|
472
|
-
if !obj.contains_key(key) {
|
|
473
|
-
if let Some(value) = entry.get(key) {
|
|
474
|
-
obj.insert(key.to_string(), value.clone());
|
|
475
|
-
}
|
|
476
|
-
}
|
|
477
|
-
}
|
|
478
|
-
}
|
|
479
|
-
|
|
480
|
-
/// ---
|
|
481
|
-
/// purpose: 顶层 owner 的 pane 不像真实 pane 时把顶层绑定字段整组删掉
|
|
482
|
-
/// params:
|
|
483
|
-
/// state: 就地删 leader_receiver、team_owner 与 owner_epoch
|
|
484
|
-
/// ---
|
|
485
|
-
pub(super) fn drop_unbound_top_level_owner(state: &mut serde_json::Value) {
|
|
486
|
-
let pane = state
|
|
487
|
-
.get("team_owner")
|
|
488
|
-
.and_then(|owner| owner.get("pane_id"))
|
|
489
|
-
.and_then(serde_json::Value::as_str)
|
|
490
|
-
.unwrap_or("");
|
|
491
|
-
if pane.starts_with('%') || pane.chars().all(|ch| ch.is_ascii_digit()) && !pane.is_empty() {
|
|
492
|
-
return;
|
|
493
|
-
}
|
|
494
|
-
if let Some(obj) = state.as_object_mut() {
|
|
495
|
-
obj.remove("leader_receiver");
|
|
496
|
-
obj.remove("team_owner");
|
|
497
|
-
obj.remove("owner_epoch");
|
|
498
|
-
}
|
|
499
|
-
}
|
|
500
|
-
|
|
501
|
-
/// ---
|
|
502
|
-
/// purpose: 本次 owner 的 pane 已属于别的团队时,改种 unbound owner 或整组删除
|
|
503
|
-
/// params:
|
|
504
|
-
/// existing: 既有 state,用于判断 pane 归属
|
|
505
|
-
/// launched: 就地改写
|
|
506
|
-
/// ---
|
|
507
|
-
pub(super) fn drop_foreign_seeded_owner(
|
|
508
|
-
existing: &serde_json::Value,
|
|
509
|
-
launched_key: &str,
|
|
510
|
-
launched: &mut serde_json::Value,
|
|
511
|
-
) {
|
|
512
|
-
let Some(pane) = launched
|
|
513
|
-
.get("team_owner")
|
|
514
|
-
.and_then(|owner| owner.get("pane_id"))
|
|
515
|
-
.and_then(serde_json::Value::as_str)
|
|
516
|
-
.filter(|pane| !pane.is_empty())
|
|
517
|
-
else {
|
|
518
|
-
return;
|
|
519
|
-
};
|
|
520
|
-
if owner_pane_belongs_to_other_team(existing, launched_key, pane) {
|
|
521
|
-
let replacement = unbound_launched_owner(launched, launched_key);
|
|
522
|
-
// Stage 3a (identity-boundary unified plan, architect direction
|
|
523
|
-
// 2026-06-23): route owner replace through ownership repository.
|
|
524
|
-
// Both branches (Some owner replacement; None = removal) preserve
|
|
525
|
-
// pre-3a behaviour: write_owner overwrites the top-level fields
|
|
526
|
-
// when given; the None branch falls back to direct mutation (the
|
|
527
|
-
// repository has no remove API yet — removal is uncommon enough
|
|
528
|
-
// to leave it inline).
|
|
529
|
-
if let Some(owner) = replacement {
|
|
530
|
-
let record = crate::state::ownership::OwnershipWrite::new().with_team_owner(owner);
|
|
531
|
-
crate::state::ownership::write_owner(launched, launched_key, record);
|
|
532
|
-
if let Some(obj) = launched.as_object_mut() {
|
|
533
|
-
obj.remove("owner_epoch");
|
|
534
|
-
}
|
|
535
|
-
} else if let Some(obj) = launched.as_object_mut() {
|
|
536
|
-
obj.remove("team_owner");
|
|
537
|
-
obj.remove("owner_epoch");
|
|
538
|
-
}
|
|
539
|
-
}
|
|
540
|
-
}
|
|
541
|
-
|
|
542
|
-
/// ---
|
|
543
|
-
/// purpose: 识别 owner 是被 worker 自己的 pane 误种的情形并改种 unbound owner
|
|
544
|
-
/// params:
|
|
545
|
-
/// started: 本次起的席位,用于判断 pane 是否属于 worker
|
|
546
|
-
/// worker_tmux_socket: worker 侧 socket 名,与调用方 socket 比对
|
|
547
|
-
/// returns: 只有在无 leader 身份环境、pane 与调用方 TMUX_PANE 相同且看起来是 worker pane 时才改种
|
|
548
|
-
/// ---
|
|
549
|
-
pub(super) fn drop_worker_pane_seeded_owner(
|
|
550
|
-
launched: &mut serde_json::Value,
|
|
551
|
-
launched_key: &str,
|
|
552
|
-
started: &[StartedAgent],
|
|
553
|
-
worker_tmux_socket: Option<&str>,
|
|
554
|
-
) {
|
|
555
|
-
let Some(pane) = launched
|
|
556
|
-
.get("team_owner")
|
|
557
|
-
.and_then(|owner| owner.get("pane_id"))
|
|
558
|
-
.and_then(serde_json::Value::as_str)
|
|
559
|
-
.filter(|pane| !pane.is_empty())
|
|
560
|
-
else {
|
|
561
|
-
return;
|
|
562
|
-
};
|
|
563
|
-
let leader_pane = std::env::var("TEAM_AGENT_LEADER_PANE_ID")
|
|
564
|
-
.ok()
|
|
565
|
-
.filter(|value| !value.is_empty());
|
|
566
|
-
let tmux_pane = std::env::var("TMUX_PANE")
|
|
567
|
-
.ok()
|
|
568
|
-
.filter(|value| !value.is_empty());
|
|
569
|
-
let has_leader_identity_env = has_positive_caller_leader_env();
|
|
570
|
-
let seeded_from_bare_tmux = !has_leader_identity_env && tmux_pane.as_deref() == Some(pane);
|
|
571
|
-
let caller_tmux_socket = crate::tmux_backend::socket_name_from_tmux_env();
|
|
572
|
-
if seeded_from_bare_tmux
|
|
573
|
-
&& (tmux_sockets_match_or_unknown(caller_tmux_socket.as_deref(), worker_tmux_socket)
|
|
574
|
-
|| pane.ends_with("-first"))
|
|
575
|
-
&& seeded_pane_looks_like_worker(pane, started)
|
|
576
|
-
{
|
|
577
|
-
seed_unbound_launched_owner(launched, launched_key);
|
|
578
|
-
}
|
|
579
|
-
}
|
|
580
|
-
|
|
581
|
-
/// ---
|
|
582
|
-
/// purpose: 判断某 pane 是否像本次起的 worker 的 pane
|
|
583
|
-
/// returns: 形如首席 pane,或与任一席位目标互为前缀时为 true
|
|
584
|
-
/// ---
|
|
585
|
-
pub(super) fn seeded_pane_looks_like_worker(pane: &str, started: &[StartedAgent]) -> bool {
|
|
586
|
-
pane.ends_with("-first")
|
|
587
|
-
|| started.iter().any(|agent| {
|
|
588
|
-
pane == agent.target
|
|
589
|
-
|| pane.starts_with(agent.target.as_str())
|
|
590
|
-
|| agent.target.starts_with(pane)
|
|
591
|
-
})
|
|
592
|
-
}
|
|
593
|
-
|
|
594
|
-
/// ---
|
|
595
|
-
/// purpose: 给出 worker 侧实际使用的 tmux endpoint
|
|
596
|
-
/// returns: transport 是 tmux 后端时优先返回 transport endpoint;缺失时按 workspace 推出 socket 名,否则 None
|
|
597
|
-
/// ---
|
|
598
|
-
pub(super) fn launched_worker_tmux_socket(
|
|
599
|
-
transport: &dyn Transport,
|
|
600
|
-
workspace: &Path,
|
|
601
|
-
) -> Option<String> {
|
|
602
|
-
if matches!(transport.kind(), crate::transport::BackendKind::Tmux) {
|
|
603
|
-
transport
|
|
604
|
-
.tmux_endpoint()
|
|
605
|
-
.or_else(|| Some(crate::tmux_backend::socket_name_for_workspace(workspace)))
|
|
606
|
-
} else {
|
|
607
|
-
None
|
|
608
|
-
}
|
|
609
|
-
}
|
|
610
|
-
|
|
611
|
-
/// ---
|
|
612
|
-
/// purpose: 判断两侧 socket 是否一致或不可判
|
|
613
|
-
/// returns: 两侧都已知时比相等;调用方已知而 worker 未知时为 false;调用方未知时一律为 true
|
|
614
|
-
/// ---
|
|
615
|
-
pub(super) fn tmux_sockets_match_or_unknown(
|
|
616
|
-
caller_socket: Option<&str>,
|
|
617
|
-
worker_socket: Option<&str>,
|
|
618
|
-
) -> bool {
|
|
619
|
-
match (caller_socket, worker_socket) {
|
|
620
|
-
(Some(caller), Some(worker)) => caller == worker,
|
|
621
|
-
(Some(_), None) => false,
|
|
622
|
-
(None, _) => true,
|
|
623
|
-
}
|
|
624
|
-
}
|