@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,889 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
use std::collections::{BTreeMap, BTreeSet};
|
|
3
|
-
use std::path::{Path, PathBuf};
|
|
4
|
-
use std::process::Command;
|
|
5
|
-
use std::time::{Duration, Instant};
|
|
6
|
-
|
|
7
|
-
use serde_json::{json, Value};
|
|
8
|
-
|
|
9
|
-
use crate::cli::CliError;
|
|
10
|
-
use crate::coordinator::health::{
|
|
11
|
-
coordinator_metadata_ok, pid_is_running, read_coordinator_metadata, terminate_pid_tree,
|
|
12
|
-
};
|
|
13
|
-
use crate::coordinator::types::{
|
|
14
|
-
CoordinatorMetadata, OrphanReason, Pid, WorkspacePath, PROTOCOL_VERSION,
|
|
15
|
-
};
|
|
16
|
-
// Phase 1d Batch 6: `TmuxBackend` import removed — all sites now use
|
|
17
|
-
// `transport_factory::tmux_socket_name_transport` for grep-visibility.
|
|
18
|
-
use crate::transport::{SessionName, Transport};
|
|
19
|
-
|
|
20
|
-
#[derive(Debug, Clone)]
|
|
21
|
-
struct OrphanRecord {
|
|
22
|
-
kind: &'static str,
|
|
23
|
-
pid: Option<Pid>,
|
|
24
|
-
session: Option<String>,
|
|
25
|
-
tmux_socket: Option<String>,
|
|
26
|
-
workspace: Option<PathBuf>,
|
|
27
|
-
reason: OrphanReason,
|
|
28
|
-
command: Option<String>,
|
|
29
|
-
action: &'static str,
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
#[derive(Debug, Clone)]
|
|
33
|
-
struct ScanReport {
|
|
34
|
-
scanned: usize,
|
|
35
|
-
orphans: Vec<OrphanRecord>,
|
|
36
|
-
ignored_foreign: Vec<OrphanRecord>,
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
#[derive(Debug, Clone)]
|
|
40
|
-
pub(crate) enum OrphanScanScope {
|
|
41
|
-
CurrentWorkspace {
|
|
42
|
-
canonical_current_workspace: PathBuf,
|
|
43
|
-
},
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
impl OrphanScanScope {
|
|
47
|
-
fn current_workspace(workspace: &Path) -> Self {
|
|
48
|
-
Self::CurrentWorkspace {
|
|
49
|
-
canonical_current_workspace: canonicalize_workspace(workspace),
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
fn workspace(&self) -> &Path {
|
|
54
|
-
match self {
|
|
55
|
-
Self::CurrentWorkspace {
|
|
56
|
-
canonical_current_workspace,
|
|
57
|
-
} => canonical_current_workspace,
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
fn canonicalize_workspace(workspace: &Path) -> PathBuf {
|
|
63
|
-
std::fs::canonicalize(workspace).unwrap_or_else(|_| workspace.to_path_buf())
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
fn workspace_matches_scope(scope: &OrphanScanScope, workspace: &Path) -> bool {
|
|
67
|
-
match scope {
|
|
68
|
-
OrphanScanScope::CurrentWorkspace {
|
|
69
|
-
canonical_current_workspace,
|
|
70
|
-
} => canonicalize_workspace(workspace) == *canonical_current_workspace,
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
fn assert_current_workspace_orphan(orphan: &OrphanRecord, scope: &OrphanScanScope) -> bool {
|
|
75
|
-
orphan
|
|
76
|
-
.workspace
|
|
77
|
-
.as_deref()
|
|
78
|
-
.is_some_and(|workspace| workspace_matches_scope(scope, workspace))
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
fn foreign_workspace_record(process: ProcessRow, workspace: PathBuf) -> OrphanRecord {
|
|
82
|
-
OrphanRecord {
|
|
83
|
-
kind: "coordinator_process",
|
|
84
|
-
pid: Some(process.pid),
|
|
85
|
-
session: None,
|
|
86
|
-
tmux_socket: None,
|
|
87
|
-
workspace: Some(workspace),
|
|
88
|
-
reason: OrphanReason::WorkspaceAlive,
|
|
89
|
-
command: Some(process.command),
|
|
90
|
-
action: "none",
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
pub fn orphan_gate_json(workspace: &Path, fix: bool, confirm: bool) -> Result<Value, CliError> {
|
|
95
|
-
if fix && !confirm {
|
|
96
|
-
return Ok(json!({
|
|
97
|
-
"ok": false,
|
|
98
|
-
"gate": "orphans",
|
|
99
|
-
"status": "refused",
|
|
100
|
-
"reason": "fix_requires_confirm",
|
|
101
|
-
"action": "re-run with --gate orphans --fix --confirm",
|
|
102
|
-
}));
|
|
103
|
-
}
|
|
104
|
-
let scope = OrphanScanScope::current_workspace(workspace);
|
|
105
|
-
let report = scan_orphans_bounded(&scope, false);
|
|
106
|
-
if report.orphans.is_empty() {
|
|
107
|
-
return Ok(with_ignored_foreign(
|
|
108
|
-
json!({
|
|
109
|
-
"ok": true,
|
|
110
|
-
"gate": "orphans",
|
|
111
|
-
"status": "passed",
|
|
112
|
-
"scanned": report.scanned,
|
|
113
|
-
"dry_run": !fix,
|
|
114
|
-
"scanned_at": chrono::Utc::now().to_rfc3339(),
|
|
115
|
-
"action_required": false,
|
|
116
|
-
"fix": fix,
|
|
117
|
-
"orphans": [],
|
|
118
|
-
}),
|
|
119
|
-
&report,
|
|
120
|
-
));
|
|
121
|
-
}
|
|
122
|
-
if fix {
|
|
123
|
-
return fix_orphans(&scope, report);
|
|
124
|
-
}
|
|
125
|
-
Ok(with_ignored_foreign(
|
|
126
|
-
json!({
|
|
127
|
-
"ok": false,
|
|
128
|
-
"gate": "orphans",
|
|
129
|
-
"status": "failed",
|
|
130
|
-
"scanned": report.scanned,
|
|
131
|
-
"dry_run": true,
|
|
132
|
-
"scanned_at": chrono::Utc::now().to_rfc3339(),
|
|
133
|
-
"action_required": true,
|
|
134
|
-
"fix": false,
|
|
135
|
-
"orphans": orphan_values(&report.orphans),
|
|
136
|
-
}),
|
|
137
|
-
&report,
|
|
138
|
-
))
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
pub fn cleanup_orphans_json(workspace: &Path, confirm: bool) -> Result<Value, CliError> {
|
|
142
|
-
let scope = OrphanScanScope::current_workspace(workspace);
|
|
143
|
-
let report = scan_orphans_bounded(&scope, false);
|
|
144
|
-
if confirm {
|
|
145
|
-
if report.orphans.is_empty() {
|
|
146
|
-
return Ok(with_ignored_foreign(
|
|
147
|
-
json!({
|
|
148
|
-
"ok": true,
|
|
149
|
-
"scanned": report.scanned,
|
|
150
|
-
"orphans": [],
|
|
151
|
-
"dry_run": false,
|
|
152
|
-
"scanned_at": chrono::Utc::now().to_rfc3339(),
|
|
153
|
-
"killed": [],
|
|
154
|
-
"failed": [],
|
|
155
|
-
}),
|
|
156
|
-
&report,
|
|
157
|
-
));
|
|
158
|
-
}
|
|
159
|
-
return cleanup_confirmed(&scope, report);
|
|
160
|
-
}
|
|
161
|
-
Ok(with_ignored_foreign(
|
|
162
|
-
json!({
|
|
163
|
-
"ok": true,
|
|
164
|
-
"scanned": report.scanned,
|
|
165
|
-
"orphans": orphan_values(&report.orphans),
|
|
166
|
-
"dry_run": true,
|
|
167
|
-
"scanned_at": chrono::Utc::now().to_rfc3339(),
|
|
168
|
-
"action_required": "re-run with --confirm to send SIGTERM",
|
|
169
|
-
}),
|
|
170
|
-
&report,
|
|
171
|
-
))
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
pub fn has_orphan_residue(workspace: &Path) -> bool {
|
|
175
|
-
let scope = OrphanScanScope::current_workspace(workspace);
|
|
176
|
-
!scan_orphans_bounded(&scope, false).orphans.is_empty()
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
pub fn orphan_blocker_detail(workspace: &Path) -> String {
|
|
180
|
-
let scope = OrphanScanScope::current_workspace(workspace);
|
|
181
|
-
let report = scan_orphans_bounded(&scope, false);
|
|
182
|
-
if report.orphans.is_empty() {
|
|
183
|
-
return "no orphan coordinator residue detected".to_string();
|
|
184
|
-
}
|
|
185
|
-
report
|
|
186
|
-
.orphans
|
|
187
|
-
.iter()
|
|
188
|
-
.map(|orphan| {
|
|
189
|
-
let target = orphan
|
|
190
|
-
.pid
|
|
191
|
-
.map(|pid| format!("pid={pid}"))
|
|
192
|
-
.or_else(|| orphan.session.as_ref().map(|s| format!("session={s}")))
|
|
193
|
-
.unwrap_or_else(|| "target=unknown".to_string());
|
|
194
|
-
let workspace = orphan
|
|
195
|
-
.workspace
|
|
196
|
-
.as_ref()
|
|
197
|
-
.map(|p| p.to_string_lossy().to_string())
|
|
198
|
-
.unwrap_or_else(|| "workspace=unknown".to_string());
|
|
199
|
-
format!(
|
|
200
|
-
"{} {target} workspace={workspace} reason={}",
|
|
201
|
-
orphan.kind,
|
|
202
|
-
reason_key(&orphan.reason)
|
|
203
|
-
)
|
|
204
|
-
})
|
|
205
|
-
.collect::<Vec<_>>()
|
|
206
|
-
.join("; ")
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
fn fix_orphans(scope: &OrphanScanScope, report: ScanReport) -> Result<Value, CliError> {
|
|
210
|
-
let cleanup = cleanup_report(report, scope);
|
|
211
|
-
let residual = scan_orphans(scope, false);
|
|
212
|
-
Ok(with_ignored_foreign(
|
|
213
|
-
json!({
|
|
214
|
-
"ok": residual.orphans.is_empty() && cleanup.failed.is_empty(),
|
|
215
|
-
"gate": "orphans",
|
|
216
|
-
"status": if residual.orphans.is_empty() && cleanup.failed.is_empty() { "fixed" } else { "failed" },
|
|
217
|
-
"scanned": cleanup.scanned,
|
|
218
|
-
"dry_run": false,
|
|
219
|
-
"scanned_at": chrono::Utc::now().to_rfc3339(),
|
|
220
|
-
"action_required": !residual.orphans.is_empty() || !cleanup.failed.is_empty(),
|
|
221
|
-
"fix": true,
|
|
222
|
-
"orphans": orphan_values(&residual.orphans),
|
|
223
|
-
"killed": cleanup.killed,
|
|
224
|
-
"failed": cleanup.failed,
|
|
225
|
-
}),
|
|
226
|
-
&residual,
|
|
227
|
-
))
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
fn cleanup_confirmed(scope: &OrphanScanScope, report: ScanReport) -> Result<Value, CliError> {
|
|
231
|
-
let cleanup = cleanup_report(report, scope);
|
|
232
|
-
let residual = scan_orphans(scope, false);
|
|
233
|
-
Ok(with_ignored_foreign(
|
|
234
|
-
json!({
|
|
235
|
-
"ok": residual.orphans.is_empty() && cleanup.failed.is_empty(),
|
|
236
|
-
"scanned": cleanup.scanned,
|
|
237
|
-
"orphans": orphan_values(&residual.orphans),
|
|
238
|
-
"dry_run": false,
|
|
239
|
-
"scanned_at": chrono::Utc::now().to_rfc3339(),
|
|
240
|
-
"killed": cleanup.killed,
|
|
241
|
-
"failed": cleanup.failed,
|
|
242
|
-
}),
|
|
243
|
-
&residual,
|
|
244
|
-
))
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
struct CleanupReport {
|
|
248
|
-
scanned: usize,
|
|
249
|
-
killed: Vec<Value>,
|
|
250
|
-
failed: Vec<Value>,
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
fn cleanup_report(report: ScanReport, scope: &OrphanScanScope) -> CleanupReport {
|
|
254
|
-
let protected = protected_pids();
|
|
255
|
-
let mut killed = Vec::new();
|
|
256
|
-
let mut failed = Vec::new();
|
|
257
|
-
for orphan in &report.orphans {
|
|
258
|
-
if !assert_current_workspace_orphan(orphan, scope) {
|
|
259
|
-
failed.push(orphan_value(orphan, "skipped"));
|
|
260
|
-
continue;
|
|
261
|
-
}
|
|
262
|
-
if let Some(pid) = orphan.pid {
|
|
263
|
-
if protected.contains(&pid.get()) {
|
|
264
|
-
failed.push(orphan_value(orphan, "skipped"));
|
|
265
|
-
continue;
|
|
266
|
-
}
|
|
267
|
-
if terminate_pid_tree(pid) {
|
|
268
|
-
killed.push(orphan_value(orphan, "killed"));
|
|
269
|
-
} else {
|
|
270
|
-
failed.push(orphan_value(orphan, "failed"));
|
|
271
|
-
}
|
|
272
|
-
continue;
|
|
273
|
-
}
|
|
274
|
-
if kill_tmux_session(orphan, scope.workspace()) {
|
|
275
|
-
killed.push(orphan_value(orphan, "killed"));
|
|
276
|
-
} else {
|
|
277
|
-
failed.push(orphan_value(orphan, "failed"));
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
CleanupReport {
|
|
281
|
-
scanned: report.scanned,
|
|
282
|
-
killed,
|
|
283
|
-
failed,
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
fn scan_orphans(scope: &OrphanScanScope, include_unparsed: bool) -> ScanReport {
|
|
288
|
-
let protected = protected_pids();
|
|
289
|
-
let mut scanned = 0;
|
|
290
|
-
let mut orphans = Vec::new();
|
|
291
|
-
let mut ignored_foreign = Vec::new();
|
|
292
|
-
for process in coordinator_processes() {
|
|
293
|
-
if protected.contains(&process.pid.get()) {
|
|
294
|
-
continue;
|
|
295
|
-
}
|
|
296
|
-
scanned += 1;
|
|
297
|
-
let Some(workspace) = parse_workspace_arg(&process.command) else {
|
|
298
|
-
if include_unparsed {
|
|
299
|
-
orphans.push(OrphanRecord {
|
|
300
|
-
kind: "coordinator_process",
|
|
301
|
-
pid: Some(process.pid),
|
|
302
|
-
session: None,
|
|
303
|
-
tmux_socket: None,
|
|
304
|
-
workspace: None,
|
|
305
|
-
reason: OrphanReason::CmdlineUnparsed,
|
|
306
|
-
command: Some(process.command),
|
|
307
|
-
action: "would_kill",
|
|
308
|
-
});
|
|
309
|
-
}
|
|
310
|
-
continue;
|
|
311
|
-
};
|
|
312
|
-
if !workspace_matches_scope(scope, &workspace) {
|
|
313
|
-
ignored_foreign.push(foreign_workspace_record(process, workspace));
|
|
314
|
-
continue;
|
|
315
|
-
}
|
|
316
|
-
if let Some(reason) = classify_workspace_orphan(&workspace, process.pid) {
|
|
317
|
-
orphans.push(OrphanRecord {
|
|
318
|
-
kind: "coordinator_process",
|
|
319
|
-
pid: Some(process.pid),
|
|
320
|
-
session: None,
|
|
321
|
-
tmux_socket: None,
|
|
322
|
-
workspace: Some(workspace),
|
|
323
|
-
reason,
|
|
324
|
-
command: Some(process.command),
|
|
325
|
-
action: "would_kill",
|
|
326
|
-
});
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
for orphan in coordinator_pid_file_orphans(scope) {
|
|
330
|
-
scanned += 1;
|
|
331
|
-
orphans.push(orphan);
|
|
332
|
-
}
|
|
333
|
-
for orphan in tmux_session_orphans(scope) {
|
|
334
|
-
scanned += 1;
|
|
335
|
-
orphans.push(orphan);
|
|
336
|
-
}
|
|
337
|
-
for orphan in provider_mcp_process_orphans(scope) {
|
|
338
|
-
scanned += 1;
|
|
339
|
-
orphans.push(orphan);
|
|
340
|
-
}
|
|
341
|
-
ScanReport {
|
|
342
|
-
scanned,
|
|
343
|
-
orphans,
|
|
344
|
-
ignored_foreign,
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
fn coordinator_pid_file_orphans(scope: &OrphanScanScope) -> Vec<OrphanRecord> {
|
|
349
|
-
temp_scan_roots()
|
|
350
|
-
.into_iter()
|
|
351
|
-
.flat_map(|root| match std::fs::read_dir(root) {
|
|
352
|
-
Ok(entries) => entries.filter_map(Result::ok).collect::<Vec<_>>(),
|
|
353
|
-
Err(_) => Vec::new(),
|
|
354
|
-
})
|
|
355
|
-
.filter_map(|entry| {
|
|
356
|
-
let workspace = entry.path();
|
|
357
|
-
if !workspace.is_dir() || ephemeral_workspace_hint(&workspace).is_none() {
|
|
358
|
-
return None;
|
|
359
|
-
}
|
|
360
|
-
if !workspace_matches_scope(scope, &workspace) {
|
|
361
|
-
return None;
|
|
362
|
-
}
|
|
363
|
-
let pid_path = crate::model::paths::runtime_dir(&workspace).join("coordinator.pid");
|
|
364
|
-
let pid = read_pid_file(&pid_path)?;
|
|
365
|
-
let workspace_path = WorkspacePath::new(workspace.clone());
|
|
366
|
-
let metadata = read_coordinator_metadata(&workspace_path);
|
|
367
|
-
let reason = if pid_is_running(pid).ok() != Some(true) {
|
|
368
|
-
OrphanReason::PidNotRunning
|
|
369
|
-
} else if metadata.is_some() && !coordinator_metadata_ok(metadata.as_ref(), pid) {
|
|
370
|
-
OrphanReason::MetadataMismatch
|
|
371
|
-
} else {
|
|
372
|
-
OrphanReason::EphemeralTempdirPattern {
|
|
373
|
-
hint: ephemeral_workspace_hint(&workspace)
|
|
374
|
-
.unwrap_or_else(|| "ephemeral_workspace".to_string()),
|
|
375
|
-
}
|
|
376
|
-
};
|
|
377
|
-
Some(OrphanRecord {
|
|
378
|
-
kind: "coordinator_metadata",
|
|
379
|
-
pid: Some(pid),
|
|
380
|
-
session: None,
|
|
381
|
-
tmux_socket: None,
|
|
382
|
-
workspace: Some(workspace),
|
|
383
|
-
reason,
|
|
384
|
-
command: None,
|
|
385
|
-
action: "would_kill",
|
|
386
|
-
})
|
|
387
|
-
})
|
|
388
|
-
.collect()
|
|
389
|
-
}
|
|
390
|
-
|
|
391
|
-
fn tmux_session_orphans(scope: &OrphanScanScope) -> Vec<OrphanRecord> {
|
|
392
|
-
tmux_socket_names()
|
|
393
|
-
.into_iter()
|
|
394
|
-
.flat_map(|socket| {
|
|
395
|
-
tmux_list_panes(&socket)
|
|
396
|
-
.into_iter()
|
|
397
|
-
.filter_map(move |pane| {
|
|
398
|
-
let workspace = pane.workspace?;
|
|
399
|
-
if !is_orphan_marker_workspace(&workspace) {
|
|
400
|
-
return None;
|
|
401
|
-
}
|
|
402
|
-
if !workspace_matches_scope(scope, &workspace) {
|
|
403
|
-
return None;
|
|
404
|
-
}
|
|
405
|
-
let reason = classify_workspace_without_pid(&workspace)?;
|
|
406
|
-
Some(OrphanRecord {
|
|
407
|
-
kind: "tmux_session",
|
|
408
|
-
pid: None,
|
|
409
|
-
session: Some(pane.session),
|
|
410
|
-
tmux_socket: Some(socket.clone()),
|
|
411
|
-
workspace: Some(workspace),
|
|
412
|
-
reason,
|
|
413
|
-
command: pane.command,
|
|
414
|
-
action: "would_kill",
|
|
415
|
-
})
|
|
416
|
-
})
|
|
417
|
-
})
|
|
418
|
-
.collect()
|
|
419
|
-
}
|
|
420
|
-
|
|
421
|
-
#[derive(Debug)]
|
|
422
|
-
struct TmuxPaneRow {
|
|
423
|
-
session: String,
|
|
424
|
-
workspace: Option<PathBuf>,
|
|
425
|
-
command: Option<String>,
|
|
426
|
-
}
|
|
427
|
-
|
|
428
|
-
fn tmux_socket_names() -> Vec<String> {
|
|
429
|
-
let mut names = BTreeSet::new();
|
|
430
|
-
for root in tmux_socket_roots() {
|
|
431
|
-
let Ok(entries) = std::fs::read_dir(root) else {
|
|
432
|
-
continue;
|
|
433
|
-
};
|
|
434
|
-
for entry in entries.filter_map(Result::ok) {
|
|
435
|
-
let name = entry.file_name().to_string_lossy().to_string();
|
|
436
|
-
if name.starts_with("ta-") {
|
|
437
|
-
names.insert(name);
|
|
438
|
-
}
|
|
439
|
-
}
|
|
440
|
-
}
|
|
441
|
-
names.into_iter().collect()
|
|
442
|
-
}
|
|
443
|
-
|
|
444
|
-
fn tmux_socket_roots() -> Vec<PathBuf> {
|
|
445
|
-
// 0.5.x Windows portability Batch 1: tmux orphan scan is Unix-only
|
|
446
|
-
// (design §Layering Strategy — "ConPTY orphan diagnostics should be
|
|
447
|
-
// a separate shim registry command later"). On Windows return
|
|
448
|
-
// empty so the caller loops zero times honestly.
|
|
449
|
-
#[cfg(unix)]
|
|
450
|
-
{
|
|
451
|
-
let uid = unsafe { libc::geteuid() };
|
|
452
|
-
let mut roots = vec![PathBuf::from(format!("/tmp/tmux-{uid}"))];
|
|
453
|
-
if let Some(tmpdir) = std::env::var_os("TMPDIR") {
|
|
454
|
-
roots.push(PathBuf::from(tmpdir).join(format!("tmux-{uid}")));
|
|
455
|
-
}
|
|
456
|
-
roots.sort();
|
|
457
|
-
roots.dedup();
|
|
458
|
-
roots
|
|
459
|
-
}
|
|
460
|
-
#[cfg(not(unix))]
|
|
461
|
-
{
|
|
462
|
-
Vec::new()
|
|
463
|
-
}
|
|
464
|
-
}
|
|
465
|
-
|
|
466
|
-
fn tmux_list_panes(socket: &str) -> Vec<TmuxPaneRow> {
|
|
467
|
-
// Phase 1d Batch 6: factory tmux-socket-name helper for
|
|
468
|
-
// grep-visibility. Tmux-only orphan scanner (enumerates tmux socket
|
|
469
|
-
// roots); ConPTY orphan diagnostics are a separate shim registry
|
|
470
|
-
// command, not routed here.
|
|
471
|
-
crate::transport_factory::tmux_socket_name_transport(socket)
|
|
472
|
-
.list_targets()
|
|
473
|
-
.unwrap_or_default()
|
|
474
|
-
.into_iter()
|
|
475
|
-
.map(|pane| TmuxPaneRow {
|
|
476
|
-
session: pane.session.as_str().to_string(),
|
|
477
|
-
workspace: pane.current_path,
|
|
478
|
-
command: pane.current_command,
|
|
479
|
-
})
|
|
480
|
-
.collect()
|
|
481
|
-
}
|
|
482
|
-
|
|
483
|
-
fn provider_mcp_process_orphans(scope: &OrphanScanScope) -> Vec<OrphanRecord> {
|
|
484
|
-
ps_command_rows()
|
|
485
|
-
.into_iter()
|
|
486
|
-
.filter(|row| is_provider_or_mcp_workspace_command(&row.command))
|
|
487
|
-
.filter_map(|process| {
|
|
488
|
-
let workspace = parse_workspace_arg(&process.command)?;
|
|
489
|
-
if !is_orphan_marker_workspace(&workspace) {
|
|
490
|
-
return None;
|
|
491
|
-
}
|
|
492
|
-
if !workspace_matches_scope(scope, &workspace) {
|
|
493
|
-
return None;
|
|
494
|
-
}
|
|
495
|
-
let reason = classify_workspace_without_pid(&workspace)?;
|
|
496
|
-
Some(OrphanRecord {
|
|
497
|
-
kind: if process.command.contains("mcp-server") {
|
|
498
|
-
"mcp_process"
|
|
499
|
-
} else {
|
|
500
|
-
"provider_process"
|
|
501
|
-
},
|
|
502
|
-
pid: Some(process.pid),
|
|
503
|
-
session: None,
|
|
504
|
-
tmux_socket: None,
|
|
505
|
-
workspace: Some(workspace),
|
|
506
|
-
reason,
|
|
507
|
-
command: Some(process.command),
|
|
508
|
-
action: "would_kill",
|
|
509
|
-
})
|
|
510
|
-
})
|
|
511
|
-
.collect()
|
|
512
|
-
}
|
|
513
|
-
|
|
514
|
-
fn temp_scan_roots() -> Vec<PathBuf> {
|
|
515
|
-
let mut roots = Vec::new();
|
|
516
|
-
if let Some(tmpdir) = std::env::var_os("TMPDIR") {
|
|
517
|
-
roots.push(PathBuf::from(tmpdir));
|
|
518
|
-
}
|
|
519
|
-
roots.push(std::env::temp_dir());
|
|
520
|
-
roots.sort();
|
|
521
|
-
roots.dedup();
|
|
522
|
-
roots
|
|
523
|
-
}
|
|
524
|
-
|
|
525
|
-
fn read_pid_file(path: &Path) -> Option<Pid> {
|
|
526
|
-
let text = std::fs::read_to_string(path).ok()?;
|
|
527
|
-
let pid = text.trim().parse::<u32>().ok()?;
|
|
528
|
-
Some(Pid::new(pid))
|
|
529
|
-
}
|
|
530
|
-
|
|
531
|
-
fn scan_orphans_bounded(scope: &OrphanScanScope, include_unparsed: bool) -> ScanReport {
|
|
532
|
-
let deadline = Instant::now() + Duration::from_millis(800);
|
|
533
|
-
let mut scanned = 0;
|
|
534
|
-
let mut by_key = BTreeMap::new();
|
|
535
|
-
let mut foreign_by_key = BTreeMap::new();
|
|
536
|
-
loop {
|
|
537
|
-
let report = scan_orphans(scope, include_unparsed);
|
|
538
|
-
scanned = scanned.max(report.scanned);
|
|
539
|
-
for orphan in report.orphans {
|
|
540
|
-
by_key.insert(orphan_key(&orphan), orphan);
|
|
541
|
-
}
|
|
542
|
-
for orphan in report.ignored_foreign {
|
|
543
|
-
foreign_by_key.insert(orphan_key(&orphan), orphan);
|
|
544
|
-
}
|
|
545
|
-
if !by_key.is_empty() || Instant::now() >= deadline {
|
|
546
|
-
break;
|
|
547
|
-
}
|
|
548
|
-
std::thread::sleep(Duration::from_millis(25));
|
|
549
|
-
}
|
|
550
|
-
ScanReport {
|
|
551
|
-
scanned,
|
|
552
|
-
orphans: by_key.into_values().collect(),
|
|
553
|
-
ignored_foreign: foreign_by_key.into_values().collect(),
|
|
554
|
-
}
|
|
555
|
-
}
|
|
556
|
-
|
|
557
|
-
fn orphan_key(orphan: &OrphanRecord) -> String {
|
|
558
|
-
if let Some(pid) = orphan.pid {
|
|
559
|
-
return format!("pid:{pid}");
|
|
560
|
-
}
|
|
561
|
-
if let Some(session) = &orphan.session {
|
|
562
|
-
return format!(
|
|
563
|
-
"session:{}:{session}",
|
|
564
|
-
orphan.tmux_socket.as_deref().unwrap_or("default")
|
|
565
|
-
);
|
|
566
|
-
}
|
|
567
|
-
orphan.kind.to_string()
|
|
568
|
-
}
|
|
569
|
-
|
|
570
|
-
#[derive(Debug, Clone)]
|
|
571
|
-
struct ProcessRow {
|
|
572
|
-
pid: Pid,
|
|
573
|
-
command: String,
|
|
574
|
-
}
|
|
575
|
-
|
|
576
|
-
fn coordinator_processes() -> Vec<ProcessRow> {
|
|
577
|
-
ps_command_rows()
|
|
578
|
-
.into_iter()
|
|
579
|
-
.filter(|row| is_team_agent_coordinator_command(&row.command))
|
|
580
|
-
.collect()
|
|
581
|
-
}
|
|
582
|
-
|
|
583
|
-
fn ps_command_rows() -> Vec<ProcessRow> {
|
|
584
|
-
let output = match crate::os_probe::bounded_command_output_with_probe(
|
|
585
|
-
Command::new("ps").args(["-axww", "-o", "pid=,command="]),
|
|
586
|
-
"ps_table",
|
|
587
|
-
None,
|
|
588
|
-
) {
|
|
589
|
-
Ok(output) if output.status.success() => output,
|
|
590
|
-
_ => return Vec::new(),
|
|
591
|
-
};
|
|
592
|
-
String::from_utf8_lossy(&output.stdout)
|
|
593
|
-
.lines()
|
|
594
|
-
.filter_map(parse_ps_command_line)
|
|
595
|
-
.collect()
|
|
596
|
-
}
|
|
597
|
-
|
|
598
|
-
fn parse_ps_command_line(line: &str) -> Option<ProcessRow> {
|
|
599
|
-
let line = line.trim_start();
|
|
600
|
-
let split = line.find(char::is_whitespace).unwrap_or(line.len());
|
|
601
|
-
let pid = line.get(..split)?.trim().parse::<u32>().ok()?;
|
|
602
|
-
let command = line.get(split..)?.trim().to_string();
|
|
603
|
-
Some(ProcessRow {
|
|
604
|
-
pid: Pid::new(pid),
|
|
605
|
-
command,
|
|
606
|
-
})
|
|
607
|
-
}
|
|
608
|
-
|
|
609
|
-
fn is_team_agent_coordinator_command(command: &str) -> bool {
|
|
610
|
-
command.contains("team-agent")
|
|
611
|
-
&& command.contains("coordinator")
|
|
612
|
-
&& command.contains("--workspace")
|
|
613
|
-
}
|
|
614
|
-
|
|
615
|
-
fn is_provider_or_mcp_workspace_command(command: &str) -> bool {
|
|
616
|
-
command.contains("--workspace")
|
|
617
|
-
&& (command.contains("mcp-server")
|
|
618
|
-
|| command.contains(" codex ")
|
|
619
|
-
|| command.ends_with(" codex")
|
|
620
|
-
|| command.contains(" claude ")
|
|
621
|
-
|| command.ends_with(" claude")
|
|
622
|
-
|| command.contains("claude-code")
|
|
623
|
-
|| command.contains("fake-worker"))
|
|
624
|
-
}
|
|
625
|
-
|
|
626
|
-
fn parse_workspace_arg(command: &str) -> Option<PathBuf> {
|
|
627
|
-
for (start, _) in command.match_indices("--workspace") {
|
|
628
|
-
let boundary_before = start == 0
|
|
629
|
-
|| command
|
|
630
|
-
.get(..start)
|
|
631
|
-
.and_then(|prefix| prefix.chars().next_back())
|
|
632
|
-
.is_some_and(char::is_whitespace);
|
|
633
|
-
if !boundary_before {
|
|
634
|
-
continue;
|
|
635
|
-
}
|
|
636
|
-
let after = &command[start + "--workspace".len()..];
|
|
637
|
-
if let Some(value) = after.strip_prefix('=') {
|
|
638
|
-
return parse_workspace_value(value);
|
|
639
|
-
}
|
|
640
|
-
if after.chars().next().is_some_and(char::is_whitespace) {
|
|
641
|
-
return parse_workspace_value(after);
|
|
642
|
-
}
|
|
643
|
-
}
|
|
644
|
-
None
|
|
645
|
-
}
|
|
646
|
-
|
|
647
|
-
fn parse_workspace_value(value: &str) -> Option<PathBuf> {
|
|
648
|
-
let value = value.trim_start();
|
|
649
|
-
if value.is_empty() {
|
|
650
|
-
return None;
|
|
651
|
-
}
|
|
652
|
-
let value = value
|
|
653
|
-
.split_once(" --")
|
|
654
|
-
.map(|(workspace, _)| workspace)
|
|
655
|
-
.unwrap_or(value)
|
|
656
|
-
.trim_end();
|
|
657
|
-
if value.is_empty() {
|
|
658
|
-
None
|
|
659
|
-
} else {
|
|
660
|
-
Some(PathBuf::from(value))
|
|
661
|
-
}
|
|
662
|
-
}
|
|
663
|
-
|
|
664
|
-
fn classify_workspace_orphan(workspace: &Path, pid: Pid) -> Option<OrphanReason> {
|
|
665
|
-
if !workspace.is_absolute() {
|
|
666
|
-
return None;
|
|
667
|
-
}
|
|
668
|
-
if let Some(hint) = ephemeral_workspace_hint(workspace) {
|
|
669
|
-
return Some(OrphanReason::EphemeralTempdirPattern { hint });
|
|
670
|
-
}
|
|
671
|
-
if !workspace.exists() {
|
|
672
|
-
return Some(OrphanReason::WorkspacePathMissing);
|
|
673
|
-
}
|
|
674
|
-
let workspace_path = WorkspacePath::new(workspace.to_path_buf());
|
|
675
|
-
let metadata = read_coordinator_metadata(&workspace_path);
|
|
676
|
-
if coordinator_process_metadata_mismatch(metadata.as_ref(), pid) {
|
|
677
|
-
return Some(OrphanReason::MetadataMismatch);
|
|
678
|
-
}
|
|
679
|
-
if pid_is_running(pid).ok() == Some(false) {
|
|
680
|
-
return Some(OrphanReason::PidNotRunning);
|
|
681
|
-
}
|
|
682
|
-
None
|
|
683
|
-
}
|
|
684
|
-
|
|
685
|
-
fn coordinator_process_metadata_mismatch(metadata: Option<&CoordinatorMetadata>, pid: Pid) -> bool {
|
|
686
|
-
let Some(metadata) = metadata else {
|
|
687
|
-
return false;
|
|
688
|
-
};
|
|
689
|
-
metadata.pid != pid
|
|
690
|
-
|| metadata.protocol_version != PROTOCOL_VERSION
|
|
691
|
-
|| metadata.message_store_schema_version != crate::db::schema::SCHEMA_VERSION
|
|
692
|
-
}
|
|
693
|
-
|
|
694
|
-
fn classify_workspace_without_pid(workspace: &Path) -> Option<OrphanReason> {
|
|
695
|
-
if !workspace.is_absolute() {
|
|
696
|
-
return None;
|
|
697
|
-
}
|
|
698
|
-
if let Some(hint) = ephemeral_workspace_hint(workspace) {
|
|
699
|
-
return Some(OrphanReason::EphemeralTempdirPattern { hint });
|
|
700
|
-
}
|
|
701
|
-
if !workspace.exists() {
|
|
702
|
-
return Some(OrphanReason::WorkspacePathMissing);
|
|
703
|
-
}
|
|
704
|
-
None
|
|
705
|
-
}
|
|
706
|
-
|
|
707
|
-
fn ephemeral_workspace_hint(workspace: &Path) -> Option<String> {
|
|
708
|
-
let text = workspace.to_string_lossy();
|
|
709
|
-
let patterns = ["ta_doctor_comms_orphans-", "team-agent-watcher-dedupe"];
|
|
710
|
-
patterns
|
|
711
|
-
.iter()
|
|
712
|
-
.find(|pattern| text.contains(**pattern))
|
|
713
|
-
.map(|pattern| (*pattern).to_string())
|
|
714
|
-
}
|
|
715
|
-
|
|
716
|
-
fn is_orphan_marker_workspace(workspace: &Path) -> bool {
|
|
717
|
-
ephemeral_workspace_hint(workspace).is_some()
|
|
718
|
-
}
|
|
719
|
-
|
|
720
|
-
fn protected_pids() -> BTreeSet<u32> {
|
|
721
|
-
let mut protected = BTreeSet::new();
|
|
722
|
-
let current = std::process::id();
|
|
723
|
-
protected.insert(current);
|
|
724
|
-
let parents = ps_parent_map();
|
|
725
|
-
let mut cursor = current;
|
|
726
|
-
while let Some(parent) = parents.get(&cursor).copied() {
|
|
727
|
-
if parent == 0 || !protected.insert(parent) {
|
|
728
|
-
break;
|
|
729
|
-
}
|
|
730
|
-
cursor = parent;
|
|
731
|
-
}
|
|
732
|
-
protected
|
|
733
|
-
}
|
|
734
|
-
|
|
735
|
-
fn ps_parent_map() -> BTreeMap<u32, u32> {
|
|
736
|
-
let output = match crate::os_probe::bounded_command_output_with_probe(
|
|
737
|
-
Command::new("ps").args(["-axo", "pid=,ppid="]),
|
|
738
|
-
"ps_parent",
|
|
739
|
-
None,
|
|
740
|
-
) {
|
|
741
|
-
Ok(output) if output.status.success() => output,
|
|
742
|
-
_ => return BTreeMap::new(),
|
|
743
|
-
};
|
|
744
|
-
String::from_utf8_lossy(&output.stdout)
|
|
745
|
-
.lines()
|
|
746
|
-
.filter_map(|line| {
|
|
747
|
-
let mut parts = line.split_whitespace();
|
|
748
|
-
let pid = parts.next()?.parse::<u32>().ok()?;
|
|
749
|
-
let ppid = parts.next()?.parse::<u32>().ok()?;
|
|
750
|
-
Some((pid, ppid))
|
|
751
|
-
})
|
|
752
|
-
.collect()
|
|
753
|
-
}
|
|
754
|
-
|
|
755
|
-
fn orphan_values(orphans: &[OrphanRecord]) -> Vec<Value> {
|
|
756
|
-
orphans
|
|
757
|
-
.iter()
|
|
758
|
-
.map(|orphan| orphan_value(orphan, orphan.action))
|
|
759
|
-
.collect()
|
|
760
|
-
}
|
|
761
|
-
|
|
762
|
-
fn with_ignored_foreign(mut value: Value, report: &ScanReport) -> Value {
|
|
763
|
-
if !report.ignored_foreign.is_empty() {
|
|
764
|
-
value["ignored_foreign"] = Value::Array(
|
|
765
|
-
report
|
|
766
|
-
.ignored_foreign
|
|
767
|
-
.iter()
|
|
768
|
-
.map(|orphan| orphan_value(orphan, "none"))
|
|
769
|
-
.collect(),
|
|
770
|
-
);
|
|
771
|
-
}
|
|
772
|
-
value
|
|
773
|
-
}
|
|
774
|
-
|
|
775
|
-
fn orphan_value(orphan: &OrphanRecord, action: &str) -> Value {
|
|
776
|
-
let mut value = json!({
|
|
777
|
-
"kind": orphan.kind,
|
|
778
|
-
"reason": if action == "none" { "foreign_workspace" } else { reason_key(&orphan.reason) },
|
|
779
|
-
"action": action,
|
|
780
|
-
});
|
|
781
|
-
if let Some(pid) = orphan.pid {
|
|
782
|
-
value["pid"] = json!(pid.get());
|
|
783
|
-
}
|
|
784
|
-
if let Some(session) = &orphan.session {
|
|
785
|
-
value["session"] = json!(session);
|
|
786
|
-
}
|
|
787
|
-
if let Some(socket) = &orphan.tmux_socket {
|
|
788
|
-
value["tmux_socket"] = json!(socket);
|
|
789
|
-
}
|
|
790
|
-
if let Some(workspace) = &orphan.workspace {
|
|
791
|
-
value["workspace"] = json!(workspace.to_string_lossy().to_string());
|
|
792
|
-
}
|
|
793
|
-
if let Some(command) = &orphan.command {
|
|
794
|
-
value["command"] = json!(command);
|
|
795
|
-
}
|
|
796
|
-
if let OrphanReason::EphemeralTempdirPattern { hint } = &orphan.reason {
|
|
797
|
-
value["hint"] = json!(hint);
|
|
798
|
-
}
|
|
799
|
-
value
|
|
800
|
-
}
|
|
801
|
-
|
|
802
|
-
fn kill_tmux_session(orphan: &OrphanRecord, audit_workspace: &Path) -> bool {
|
|
803
|
-
let (Some(socket), Some(session)) = (&orphan.tmux_socket, &orphan.session) else {
|
|
804
|
-
return false;
|
|
805
|
-
};
|
|
806
|
-
// Phase 1d Batch 6: factory tmux-socket-name helper. Explicit
|
|
807
|
-
// tmux-only kill; conpty shim orphans are NOT routed here (design
|
|
808
|
-
// §Batch 6).
|
|
809
|
-
let transport = crate::transport_factory::tmux_socket_name_transport(socket);
|
|
810
|
-
let targets = vec![session.clone()];
|
|
811
|
-
if crate::kill_audit::pre_kill_audit(
|
|
812
|
-
&crate::event_log::EventLog::new(audit_workspace),
|
|
813
|
-
&transport,
|
|
814
|
-
"diagnose.orphans.tmux_session",
|
|
815
|
-
crate::kill_audit::KILL_SESSION,
|
|
816
|
-
&targets,
|
|
817
|
-
)
|
|
818
|
-
.is_err()
|
|
819
|
-
{
|
|
820
|
-
return false;
|
|
821
|
-
}
|
|
822
|
-
transport
|
|
823
|
-
.kill_session(&SessionName::new(session.clone()))
|
|
824
|
-
.is_ok()
|
|
825
|
-
}
|
|
826
|
-
|
|
827
|
-
fn reason_key(reason: &OrphanReason) -> &'static str {
|
|
828
|
-
match reason {
|
|
829
|
-
OrphanReason::WorkspacePathMissing => "workspace_path_missing",
|
|
830
|
-
OrphanReason::EphemeralTempdirPattern { .. } => "ephemeral_tempdir_pattern",
|
|
831
|
-
OrphanReason::WorkspaceAlive => "workspace_alive",
|
|
832
|
-
OrphanReason::CmdlineUnparsed => "cmdline_unparsed",
|
|
833
|
-
OrphanReason::MetadataMismatch => "metadata_mismatch",
|
|
834
|
-
OrphanReason::PidNotRunning => "pid_not_running",
|
|
835
|
-
}
|
|
836
|
-
}
|
|
837
|
-
|
|
838
|
-
#[cfg(test)]
|
|
839
|
-
mod tests {
|
|
840
|
-
use super::*;
|
|
841
|
-
|
|
842
|
-
#[test]
|
|
843
|
-
fn parse_workspace_arg_keeps_trailing_path_with_spaces() {
|
|
844
|
-
let command = "/tmp/team-agent coordinator --workspace /Volumes/projects/My Agent";
|
|
845
|
-
|
|
846
|
-
assert_eq!(
|
|
847
|
-
parse_workspace_arg(command),
|
|
848
|
-
Some(PathBuf::from("/Volumes/projects/My Agent"))
|
|
849
|
-
);
|
|
850
|
-
}
|
|
851
|
-
|
|
852
|
-
#[test]
|
|
853
|
-
fn parse_workspace_arg_stops_at_next_flag() {
|
|
854
|
-
let command = "/tmp/team-agent coordinator --workspace /tmp/My Agent --once";
|
|
855
|
-
|
|
856
|
-
assert_eq!(
|
|
857
|
-
parse_workspace_arg(command),
|
|
858
|
-
Some(PathBuf::from("/tmp/My Agent"))
|
|
859
|
-
);
|
|
860
|
-
}
|
|
861
|
-
|
|
862
|
-
#[test]
|
|
863
|
-
fn parse_workspace_arg_supports_equals_form_with_spaces() {
|
|
864
|
-
let command = "/tmp/team-agent coordinator --workspace=/tmp/My Agent --once";
|
|
865
|
-
|
|
866
|
-
assert_eq!(
|
|
867
|
-
parse_workspace_arg(command),
|
|
868
|
-
Some(PathBuf::from("/tmp/My Agent"))
|
|
869
|
-
);
|
|
870
|
-
}
|
|
871
|
-
|
|
872
|
-
#[test]
|
|
873
|
-
fn process_orphan_metadata_ignores_binary_identity_rotation() {
|
|
874
|
-
let metadata = CoordinatorMetadata {
|
|
875
|
-
pid: Pid::new(123),
|
|
876
|
-
protocol_version: PROTOCOL_VERSION,
|
|
877
|
-
message_store_schema_version: crate::db::schema::SCHEMA_VERSION,
|
|
878
|
-
binary_path: Some("/old/team-agent".to_string()),
|
|
879
|
-
binary_version: Some("0.5.17".to_string()),
|
|
880
|
-
source: crate::coordinator::MetadataSource::Boot,
|
|
881
|
-
updated_at: "2026-07-09T00:00:00+00:00".to_string(),
|
|
882
|
-
};
|
|
883
|
-
|
|
884
|
-
assert!(
|
|
885
|
-
!coordinator_process_metadata_mismatch(Some(&metadata), Pid::new(123)),
|
|
886
|
-
"binary identity drift is a rotation signal, not orphan cleanup proof"
|
|
887
|
-
);
|
|
888
|
-
}
|
|
889
|
-
}
|