@team-agent/installer 0.5.128 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +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,1185 +0,0 @@
|
|
|
1
|
-
//! ---
|
|
2
|
-
//! purpose: coordinator daemon 的健康判定、幂等启停与只读观测面——pid/metadata/schema 三合一健康、spawn 与终止与 runtime 路径
|
|
3
|
-
//! contract:
|
|
4
|
-
//! provides:
|
|
5
|
-
//! - name: coordinator_health
|
|
6
|
-
//! what: 由 pid 文件、coordinator.json 与 message store schema 合成 HealthReport,ok 与 service_available 分开表达
|
|
7
|
-
//! - name: start_coordinator
|
|
8
|
-
//! what: 幂等启动:已健康则 no-op,metadata 不兼容先停再起,schema 不兼容拒启并给修复 hint
|
|
9
|
-
//! - name: start_coordinator_with_team
|
|
10
|
-
//! what: 同上,并把 team_key 以 --team 传给子进程,免得 daemon 自己从 state 推
|
|
11
|
-
//! - name: stop_coordinator
|
|
12
|
-
//! what: 终止 daemon 并清 pid/meta;pid 文件缺失时用 ps 扫描发现流浪 coordinator
|
|
13
|
-
//! - name: coordinator_pid_path
|
|
14
|
-
//! what: coordinator.pid 的位置
|
|
15
|
-
//! - name: coordinator_meta_path
|
|
16
|
-
//! what: coordinator.json 的位置
|
|
17
|
-
//! - name: coordinator_log_path
|
|
18
|
-
//! what: coordinator.log 的位置
|
|
19
|
-
//! depends:
|
|
20
|
-
//! - super::types
|
|
21
|
-
//! - crate::message_store
|
|
22
|
-
//! - crate::db::schema
|
|
23
|
-
//! - crate::event_log
|
|
24
|
-
//! - crate::model::paths
|
|
25
|
-
//! - crate::packaging
|
|
26
|
-
//! - crate::platform::process
|
|
27
|
-
//! - crate::os_probe
|
|
28
|
-
//! boundary:
|
|
29
|
-
//! - 不做 tick 编排,也不投递任何消息
|
|
30
|
-
//! - 不读 provider 凭据、不碰 .env;身份只取自当前可执行文件与已落盘 metadata
|
|
31
|
-
//! - 终止进程限定本 workspace:优先按本次判定拿到的精确 pid;pid 文件缺失时的流浪回收会按 ps 命令行匹配「coordinator --workspace <本 ws>」发现目标,仍不做跨 workspace 的 pkill/killall 泛清
|
|
32
|
-
//! maturity: wired
|
|
33
|
-
//! ---
|
|
34
|
-
//!
|
|
35
|
-
//! coordinator 健康/身份 & 只读可观测面:metadata 身份原语 + coordinator 路径。
|
|
36
|
-
|
|
37
|
-
#[cfg(unix)]
|
|
38
|
-
use std::os::unix::process::CommandExt;
|
|
39
|
-
use std::path::{Path, PathBuf};
|
|
40
|
-
use std::process::{Command, Stdio};
|
|
41
|
-
use std::time::Duration;
|
|
42
|
-
|
|
43
|
-
use crate::message_store::MessageStore;
|
|
44
|
-
|
|
45
|
-
use super::types::{
|
|
46
|
-
CoordinatorBinaryIdentity, CoordinatorBinaryIdentityRelation, CoordinatorHealthStatus,
|
|
47
|
-
CoordinatorMetadata, CoordinatorMetadataMismatchReason, HealthReport, MetadataSource, Pid,
|
|
48
|
-
SchemaError, SchemaHealth, StartError, StartOutcome, StartReport, StopError, StopOutcome,
|
|
49
|
-
StopReport, WorkspacePath, PROTOCOL_VERSION,
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
// ===========================================================================
|
|
53
|
-
// coordinator daemon lifecycle (lifecycle.py:38-247).
|
|
54
|
-
// start_coordinator spawns the `team-agent coordinator --workspace <ws>` daemon subprocess;
|
|
55
|
-
// the actual spawn is the #[ignore] real-machine boundary, the idempotent decision is testable.
|
|
56
|
-
// ===========================================================================
|
|
57
|
-
|
|
58
|
-
/// `coordinator_health`(`lifecycle.py:38-46`):`running ∧ metadata_ok ∧ schema_ok` → typed report.
|
|
59
|
-
/// ---
|
|
60
|
-
/// purpose: 一次性判定本 workspace 的 coordinator daemon 是否健康
|
|
61
|
-
/// params:
|
|
62
|
-
/// workspace: workspace 根;pid/metadata 路径与 message store 都由它派生
|
|
63
|
-
/// returns: HealthReport。ok = 进程在跑 ∧ metadata 三元全等 ∧ 二进制身份一致 ∧ schema 兼容;service_available 刻意排除二进制身份,表示「这个 daemon 还能处理本队队列」;status 区分 Missing / InvalidPid / Running / Stale
|
|
64
|
-
/// ---
|
|
65
|
-
pub fn coordinator_health(workspace: &WorkspacePath) -> HealthReport {
|
|
66
|
-
coordinator_health_with_schema(workspace, message_store_schema_health(workspace))
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/// Read-only coordinator health for diagnose. Unlike the lifecycle path, this
|
|
70
|
-
/// never opens MessageStore and therefore cannot initialize or rewrite team.db.
|
|
71
|
-
pub fn coordinator_health_read_only(workspace: &WorkspacePath) -> HealthReport {
|
|
72
|
-
coordinator_health_with_schema(workspace, message_store_schema_health_read_only(workspace))
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
fn coordinator_health_with_schema(
|
|
76
|
-
workspace: &WorkspacePath,
|
|
77
|
-
schema: SchemaHealth,
|
|
78
|
-
) -> HealthReport {
|
|
79
|
-
let current_binary_identity = current_coordinator_binary_identity();
|
|
80
|
-
let pid_path = coordinator_pid_path(workspace);
|
|
81
|
-
let pid = read_pid_file(&pid_path);
|
|
82
|
-
let status = match pid {
|
|
83
|
-
Some(pid) => match pid_is_running(pid) {
|
|
84
|
-
Ok(true) => CoordinatorHealthStatus::Running,
|
|
85
|
-
Ok(false) | Err(_) => CoordinatorHealthStatus::Stale,
|
|
86
|
-
},
|
|
87
|
-
None if pid_path.exists() => CoordinatorHealthStatus::InvalidPid,
|
|
88
|
-
None => CoordinatorHealthStatus::Missing,
|
|
89
|
-
};
|
|
90
|
-
let metadata = read_coordinator_metadata(workspace);
|
|
91
|
-
let wire_metadata_mismatch = pid
|
|
92
|
-
.map(|p| coordinator_wire_metadata_mismatch_reason(metadata.as_ref(), p))
|
|
93
|
-
.unwrap_or(Some(CoordinatorMetadataMismatchReason::MetadataMissing));
|
|
94
|
-
let binary_identity_mismatch =
|
|
95
|
-
coordinator_binary_identity_mismatch_reason(metadata.as_ref(), ¤t_binary_identity);
|
|
96
|
-
let wire_metadata_ok = wire_metadata_mismatch.is_none();
|
|
97
|
-
let binary_identity_ok = binary_identity_mismatch.is_none();
|
|
98
|
-
let metadata_mismatch = wire_metadata_mismatch.or(binary_identity_mismatch);
|
|
99
|
-
let metadata_ok = wire_metadata_ok && binary_identity_ok;
|
|
100
|
-
let process_running = matches!(status, CoordinatorHealthStatus::Running);
|
|
101
|
-
let binary_identity_relation =
|
|
102
|
-
coordinator_binary_identity_relation(metadata.as_ref(), ¤t_binary_identity);
|
|
103
|
-
let service_available = process_running && wire_metadata_ok && schema.ok;
|
|
104
|
-
HealthReport {
|
|
105
|
-
ok: process_running && metadata_ok && schema.ok,
|
|
106
|
-
status,
|
|
107
|
-
pid,
|
|
108
|
-
metadata,
|
|
109
|
-
metadata_ok,
|
|
110
|
-
process_running,
|
|
111
|
-
wire_metadata_ok,
|
|
112
|
-
binary_identity_ok,
|
|
113
|
-
binary_identity_relation,
|
|
114
|
-
service_available,
|
|
115
|
-
metadata_mismatch_reason: metadata_mismatch.map(|reason| reason.as_str().to_string()),
|
|
116
|
-
current_binary_identity,
|
|
117
|
-
schema,
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
/// `start_coordinator`(`lifecycle.py:49-121`):幂等 — 已健康 no-op(AlreadyRunning);metadata 不兼容
|
|
122
|
-
/// 先 stop 再起;schema 不兼容拒启 + hint;否则 spawn `team-agent coordinator --workspace <ws>`。
|
|
123
|
-
/// ---
|
|
124
|
-
/// purpose: 不带 team_key 的幂等启动入口
|
|
125
|
-
/// params:
|
|
126
|
-
/// workspace: workspace 根
|
|
127
|
-
/// returns: 与 start_coordinator_with_team(workspace, None) 完全一致
|
|
128
|
-
/// errors: 同 start_coordinator_with_team
|
|
129
|
-
/// ---
|
|
130
|
-
pub fn start_coordinator(workspace: &WorkspacePath) -> Result<StartReport, StartError> {
|
|
131
|
-
start_coordinator_with_team(workspace, None)
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
/// 0.5.x Windows portability Batch 9 F8 (leader msg_2a4cc1fa54c0):
|
|
135
|
-
/// forward `--team` to the spawned coord daemon so it doesn't have
|
|
136
|
-
/// to derive team_key from `state.active_team_key` at boot. The
|
|
137
|
-
/// derivation stays as fallback (see `coordinator::backoff::run_daemon`),
|
|
138
|
-
/// so Unix daemons and pre-existing test harnesses are byte-preserving.
|
|
139
|
-
///
|
|
140
|
-
/// Callers that CAN pass team_key (Batch 9 quick-start Windows path)
|
|
141
|
-
/// SHOULD — that avoids Batch 8's F8 seed-state trap.
|
|
142
|
-
/// ---
|
|
143
|
-
/// purpose: 幂等启动 coordinator daemon 子进程,并把不兼容/需轮换的情形分成互不折叠的结局
|
|
144
|
-
/// params:
|
|
145
|
-
/// workspace: workspace 根
|
|
146
|
-
/// team_key: 传给子进程的 --team;None 或空串时子进程回落到 state.active_team_key
|
|
147
|
-
/// returns: StartReport。已健康 → AlreadyRunning(含「daemon 比调用方新,保留不动」这一支,rotation_reason=daemon_newer_than_caller);schema 不兼容 → SchemaIncompatible 且 ok=false 并带修复 hint;在跑但 wire metadata 不兼容、或 metadata 指向调用方自身、或先停失败 → RestartIncompatibleStopFailed;成功 spawn → Started,因身份轮换而重起则为 StartedAfterRotation
|
|
148
|
-
/// errors: 建目录、开日志、spawn、写 pid/metadata 或写事件失败时返回 StartError;「拒启」不是 Err,而是 ok=false 的报告
|
|
149
|
-
/// ---
|
|
150
|
-
pub fn start_coordinator_with_team(
|
|
151
|
-
workspace: &WorkspacePath,
|
|
152
|
-
team_key: Option<&str>,
|
|
153
|
-
) -> Result<StartReport, StartError> {
|
|
154
|
-
let health = coordinator_health(workspace);
|
|
155
|
-
let identity = health.current_binary_identity.clone();
|
|
156
|
-
if health.ok {
|
|
157
|
-
return Ok(StartReport {
|
|
158
|
-
ok: true,
|
|
159
|
-
pid: health.pid,
|
|
160
|
-
status: StartOutcome::AlreadyRunning,
|
|
161
|
-
previous_pid: None,
|
|
162
|
-
binary_path: Some(identity.binary_path),
|
|
163
|
-
binary_version: Some(identity.binary_version),
|
|
164
|
-
rotation_reason: None,
|
|
165
|
-
binary_identity_relation: health.binary_identity_relation,
|
|
166
|
-
log: Some(coordinator_log_path(workspace)),
|
|
167
|
-
schema_error: None,
|
|
168
|
-
action: None,
|
|
169
|
-
});
|
|
170
|
-
}
|
|
171
|
-
if !health.schema.ok {
|
|
172
|
-
return Ok(StartReport {
|
|
173
|
-
ok: false,
|
|
174
|
-
pid: health.pid,
|
|
175
|
-
status: StartOutcome::SchemaIncompatible,
|
|
176
|
-
previous_pid: None,
|
|
177
|
-
binary_path: Some(identity.binary_path),
|
|
178
|
-
binary_version: Some(identity.binary_version),
|
|
179
|
-
rotation_reason: health.metadata_mismatch_reason,
|
|
180
|
-
binary_identity_relation: health.binary_identity_relation,
|
|
181
|
-
log: None,
|
|
182
|
-
schema_error: health.schema.error,
|
|
183
|
-
action: health.schema.action,
|
|
184
|
-
});
|
|
185
|
-
}
|
|
186
|
-
if matches!(health.status, CoordinatorHealthStatus::Running) && !health.wire_metadata_ok {
|
|
187
|
-
return Ok(StartReport {
|
|
188
|
-
ok: false,
|
|
189
|
-
pid: health.pid,
|
|
190
|
-
status: StartOutcome::RestartIncompatibleStopFailed,
|
|
191
|
-
previous_pid: health.pid,
|
|
192
|
-
binary_path: Some(identity.binary_path),
|
|
193
|
-
binary_version: Some(identity.binary_version),
|
|
194
|
-
rotation_reason: health.metadata_mismatch_reason,
|
|
195
|
-
binary_identity_relation: health.binary_identity_relation,
|
|
196
|
-
log: None,
|
|
197
|
-
schema_error: None,
|
|
198
|
-
action: Some(
|
|
199
|
-
"refusing to rotate a coordinator with incompatible protocol or schema metadata"
|
|
200
|
-
.to_string(),
|
|
201
|
-
),
|
|
202
|
-
});
|
|
203
|
-
}
|
|
204
|
-
if matches!(health.status, CoordinatorHealthStatus::Running)
|
|
205
|
-
&& health.wire_metadata_ok
|
|
206
|
-
&& !health.binary_identity_ok
|
|
207
|
-
&& matches!(
|
|
208
|
-
health.binary_identity_relation,
|
|
209
|
-
CoordinatorBinaryIdentityRelation::DaemonNewerThanCaller
|
|
210
|
-
)
|
|
211
|
-
{
|
|
212
|
-
crate::event_log::EventLog::new(workspace.as_path()).write(
|
|
213
|
-
"coordinator.newer_daemon_preserved",
|
|
214
|
-
serde_json::json!({
|
|
215
|
-
"pid": health.pid.map(|pid| pid.get()),
|
|
216
|
-
"binary_identity_relation": health.binary_identity_relation.as_str(),
|
|
217
|
-
"reason": "daemon_newer_than_caller",
|
|
218
|
-
"daemon_binary_path": health
|
|
219
|
-
.metadata
|
|
220
|
-
.as_ref()
|
|
221
|
-
.and_then(|metadata| metadata.binary_path.clone()),
|
|
222
|
-
"daemon_binary_version": health
|
|
223
|
-
.metadata
|
|
224
|
-
.as_ref()
|
|
225
|
-
.and_then(|metadata| metadata.binary_version.clone()),
|
|
226
|
-
"caller_binary_path": identity.binary_path.clone(),
|
|
227
|
-
"caller_binary_version": identity.binary_version.clone(),
|
|
228
|
-
}),
|
|
229
|
-
)?;
|
|
230
|
-
return Ok(StartReport {
|
|
231
|
-
ok: true,
|
|
232
|
-
pid: health.pid,
|
|
233
|
-
status: StartOutcome::AlreadyRunning,
|
|
234
|
-
previous_pid: None,
|
|
235
|
-
binary_path: Some(identity.binary_path),
|
|
236
|
-
binary_version: Some(identity.binary_version),
|
|
237
|
-
rotation_reason: Some("daemon_newer_than_caller".to_string()),
|
|
238
|
-
binary_identity_relation: health.binary_identity_relation,
|
|
239
|
-
log: Some(coordinator_log_path(workspace)),
|
|
240
|
-
schema_error: None,
|
|
241
|
-
action: None,
|
|
242
|
-
});
|
|
243
|
-
}
|
|
244
|
-
let rotation_reason =
|
|
245
|
-
if matches!(health.status, CoordinatorHealthStatus::Running) && !health.metadata_ok {
|
|
246
|
-
health.metadata_mismatch_reason.clone()
|
|
247
|
-
} else {
|
|
248
|
-
None
|
|
249
|
-
};
|
|
250
|
-
if matches!(health.status, CoordinatorHealthStatus::Running) && !health.metadata_ok {
|
|
251
|
-
crate::event_log::EventLog::new(workspace.as_path()).write(
|
|
252
|
-
"coordinator.rotation_required",
|
|
253
|
-
serde_json::json!({
|
|
254
|
-
"old_pid": health.pid.map(|pid| pid.get()),
|
|
255
|
-
"reason": rotation_reason.clone(),
|
|
256
|
-
"old_binary_path": health
|
|
257
|
-
.metadata
|
|
258
|
-
.as_ref()
|
|
259
|
-
.and_then(|metadata| metadata.binary_path.clone()),
|
|
260
|
-
"old_binary_version": health
|
|
261
|
-
.metadata
|
|
262
|
-
.as_ref()
|
|
263
|
-
.and_then(|metadata| metadata.binary_version.clone()),
|
|
264
|
-
"current_binary_path": identity.binary_path.clone(),
|
|
265
|
-
"current_binary_version": identity.binary_version.clone(),
|
|
266
|
-
}),
|
|
267
|
-
)?;
|
|
268
|
-
if health.pid.map(|pid| pid.get()) == Some(std::process::id()) {
|
|
269
|
-
return Ok(StartReport {
|
|
270
|
-
ok: false,
|
|
271
|
-
pid: health.pid,
|
|
272
|
-
status: StartOutcome::RestartIncompatibleStopFailed,
|
|
273
|
-
previous_pid: health.pid,
|
|
274
|
-
binary_path: Some(identity.binary_path),
|
|
275
|
-
binary_version: Some(identity.binary_version),
|
|
276
|
-
rotation_reason,
|
|
277
|
-
binary_identity_relation: health.binary_identity_relation,
|
|
278
|
-
log: None,
|
|
279
|
-
schema_error: None,
|
|
280
|
-
action: Some(
|
|
281
|
-
"refusing to rotate coordinator metadata that points at the caller process"
|
|
282
|
-
.to_string(),
|
|
283
|
-
),
|
|
284
|
-
});
|
|
285
|
-
}
|
|
286
|
-
match stop_coordinator(workspace) {
|
|
287
|
-
Ok(stop) if stop.ok => {}
|
|
288
|
-
Ok(_) | Err(_) => {
|
|
289
|
-
return Ok(StartReport {
|
|
290
|
-
ok: false,
|
|
291
|
-
pid: health.pid,
|
|
292
|
-
status: StartOutcome::RestartIncompatibleStopFailed,
|
|
293
|
-
previous_pid: health.pid,
|
|
294
|
-
binary_path: Some(identity.binary_path),
|
|
295
|
-
binary_version: Some(identity.binary_version),
|
|
296
|
-
rotation_reason,
|
|
297
|
-
binary_identity_relation: health.binary_identity_relation,
|
|
298
|
-
log: None,
|
|
299
|
-
schema_error: None,
|
|
300
|
-
action: None,
|
|
301
|
-
});
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
let runtime_dir = crate::model::paths::runtime_dir(workspace.as_path());
|
|
307
|
-
std::fs::create_dir_all(&runtime_dir)?;
|
|
308
|
-
let log_path = coordinator_log_path(workspace);
|
|
309
|
-
let log = std::fs::OpenOptions::new()
|
|
310
|
-
.create(true)
|
|
311
|
-
.append(true)
|
|
312
|
-
.open(&log_path)?;
|
|
313
|
-
let log_err = log.try_clone()?;
|
|
314
|
-
let mut command = Command::new(std::env::current_exe()?);
|
|
315
|
-
command
|
|
316
|
-
.args(["coordinator", "--workspace"])
|
|
317
|
-
.arg(workspace.as_path());
|
|
318
|
-
if let Some(tk) = team_key {
|
|
319
|
-
if !tk.is_empty() {
|
|
320
|
-
command.args(["--team", tk]);
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
|
-
command
|
|
324
|
-
.current_dir(workspace.as_path())
|
|
325
|
-
.stdin(Stdio::null())
|
|
326
|
-
.stdout(Stdio::from(log))
|
|
327
|
-
.stderr(Stdio::from(log_err));
|
|
328
|
-
detach_daemon_child(&mut command);
|
|
329
|
-
let child = command.spawn()?;
|
|
330
|
-
let pid = Pid::new(child.id());
|
|
331
|
-
std::fs::write(coordinator_pid_path(workspace), pid.to_string())?;
|
|
332
|
-
write_coordinator_metadata(workspace, pid, MetadataSource::Start)?;
|
|
333
|
-
let status = if rotation_reason.is_some() {
|
|
334
|
-
StartOutcome::StartedAfterRotation
|
|
335
|
-
} else {
|
|
336
|
-
StartOutcome::Started
|
|
337
|
-
};
|
|
338
|
-
Ok(StartReport {
|
|
339
|
-
ok: true,
|
|
340
|
-
pid: Some(pid),
|
|
341
|
-
status,
|
|
342
|
-
previous_pid: health.pid,
|
|
343
|
-
binary_path: Some(identity.binary_path),
|
|
344
|
-
binary_version: Some(identity.binary_version),
|
|
345
|
-
rotation_reason,
|
|
346
|
-
binary_identity_relation: health.binary_identity_relation,
|
|
347
|
-
log: Some(log_path),
|
|
348
|
-
schema_error: None,
|
|
349
|
-
action: None,
|
|
350
|
-
})
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
#[cfg(unix)]
|
|
354
|
-
fn detach_daemon_child(command: &mut Command) {
|
|
355
|
-
// The coordinator is a daemon: it must not remain in the launcher's process
|
|
356
|
-
// group, otherwise bare SSH command teardown can SIGHUP it after quick-start exits.
|
|
357
|
-
unsafe {
|
|
358
|
-
command.pre_exec(|| {
|
|
359
|
-
if libc::setsid() == -1 {
|
|
360
|
-
Err(std::io::Error::last_os_error())
|
|
361
|
-
} else {
|
|
362
|
-
Ok(())
|
|
363
|
-
}
|
|
364
|
-
});
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
#[cfg(windows)]
|
|
369
|
-
fn detach_daemon_child(command: &mut Command) {
|
|
370
|
-
// 0.5.x Windows portability Batch 8 F7 (leader msg_590b4dce0f68):
|
|
371
|
-
// detach the coordinator daemon on Windows via
|
|
372
|
-
// `DETACHED_PROCESS | CREATE_BREAKAWAY_FROM_JOB` creation flags,
|
|
373
|
-
// matching what `coordinator::conpty_shim::spawn_shim_and_handshake`
|
|
374
|
-
// does for the shim. Without these flags, an SSH-launched
|
|
375
|
-
// quick-start blocks waiting for the coord daemon's process
|
|
376
|
-
// tree to exit (never happens — daemon runs forever), and the
|
|
377
|
-
// quick-start caller sees a hung command.
|
|
378
|
-
use std::os::windows::process::CommandExt;
|
|
379
|
-
const DETACHED_PROCESS: u32 = 0x00000008;
|
|
380
|
-
const CREATE_BREAKAWAY_FROM_JOB: u32 = 0x01000000;
|
|
381
|
-
command.creation_flags(DETACHED_PROCESS | CREATE_BREAKAWAY_FROM_JOB);
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
#[cfg(not(any(unix, windows)))]
|
|
385
|
-
fn detach_daemon_child(_command: &mut Command) {}
|
|
386
|
-
|
|
387
|
-
/// `stop_coordinator`(`lifecycle.py:228-247`):SIGTERM pid + 清 pid/meta → typed report。
|
|
388
|
-
/// ---
|
|
389
|
-
/// purpose: 停掉本 workspace 的 coordinator daemon 并清掉 pid/meta 文件
|
|
390
|
-
/// params:
|
|
391
|
-
/// workspace: workspace 根
|
|
392
|
-
/// returns: StopReport。pid 文件不存在时先尝试按 ps 发现流浪 coordinator,仍没有则 Missing;pid 文件内容非法 → 清文件并报 InvalidPidRemoved;终止成功 → Stopped;信号发不出去 → KillFailed
|
|
393
|
-
/// errors: 删 pid/meta 文件失败时返回 StopError;本函数不写事件(EventLog 变体在此路径无产生点)
|
|
394
|
-
/// ---
|
|
395
|
-
pub fn stop_coordinator(workspace: &WorkspacePath) -> Result<StopReport, StopError> {
|
|
396
|
-
let pid_path = coordinator_pid_path(workspace);
|
|
397
|
-
if !pid_path.exists() {
|
|
398
|
-
if let Some(report) = stop_discovered_coordinators(workspace)? {
|
|
399
|
-
return Ok(report);
|
|
400
|
-
}
|
|
401
|
-
return Ok(StopReport {
|
|
402
|
-
ok: true,
|
|
403
|
-
status: StopOutcome::Missing,
|
|
404
|
-
pid: None,
|
|
405
|
-
});
|
|
406
|
-
}
|
|
407
|
-
let Some(pid) = read_pid_file(&pid_path) else {
|
|
408
|
-
remove_file_if_exists(&pid_path)?;
|
|
409
|
-
remove_file_if_exists(&coordinator_meta_path(workspace))?;
|
|
410
|
-
return Ok(StopReport {
|
|
411
|
-
ok: true,
|
|
412
|
-
status: StopOutcome::InvalidPidRemoved,
|
|
413
|
-
pid: None,
|
|
414
|
-
});
|
|
415
|
-
};
|
|
416
|
-
if pid_is_running(pid).ok() == Some(false) {
|
|
417
|
-
remove_file_if_exists(&pid_path)?;
|
|
418
|
-
remove_file_if_exists(&coordinator_meta_path(workspace))?;
|
|
419
|
-
return Ok(StopReport {
|
|
420
|
-
ok: true,
|
|
421
|
-
status: StopOutcome::Missing,
|
|
422
|
-
pid: Some(pid),
|
|
423
|
-
});
|
|
424
|
-
}
|
|
425
|
-
let metadata_owned = read_coordinator_metadata(workspace)
|
|
426
|
-
.as_ref()
|
|
427
|
-
.is_some_and(|metadata| metadata.pid == pid);
|
|
428
|
-
if !metadata_owned || !coordinator_pid_owned_by_workspace(workspace, pid) {
|
|
429
|
-
return Ok(StopReport {
|
|
430
|
-
ok: false,
|
|
431
|
-
status: StopOutcome::NotOwned,
|
|
432
|
-
pid: Some(pid),
|
|
433
|
-
});
|
|
434
|
-
}
|
|
435
|
-
if pid.get() == std::process::id() {
|
|
436
|
-
remove_file_if_exists(&pid_path)?;
|
|
437
|
-
remove_file_if_exists(&coordinator_meta_path(workspace))?;
|
|
438
|
-
return Ok(StopReport {
|
|
439
|
-
ok: true,
|
|
440
|
-
status: StopOutcome::Stopped,
|
|
441
|
-
pid: Some(pid),
|
|
442
|
-
});
|
|
443
|
-
}
|
|
444
|
-
if !terminate_pid_for_workspace(pid, workspace.as_path()) {
|
|
445
|
-
return Ok(StopReport {
|
|
446
|
-
ok: false,
|
|
447
|
-
status: StopOutcome::KillFailed,
|
|
448
|
-
pid: Some(pid),
|
|
449
|
-
});
|
|
450
|
-
}
|
|
451
|
-
remove_file_if_exists(&pid_path)?;
|
|
452
|
-
remove_file_if_exists(&coordinator_meta_path(workspace))?;
|
|
453
|
-
Ok(StopReport {
|
|
454
|
-
ok: true,
|
|
455
|
-
status: StopOutcome::Stopped,
|
|
456
|
-
pid: Some(pid),
|
|
457
|
-
})
|
|
458
|
-
}
|
|
459
|
-
|
|
460
|
-
fn stop_discovered_coordinators(
|
|
461
|
-
workspace: &WorkspacePath,
|
|
462
|
-
) -> Result<Option<StopReport>, StopError> {
|
|
463
|
-
let pids = discover_coordinator_pids(workspace);
|
|
464
|
-
if pids.is_empty() {
|
|
465
|
-
return Ok(None);
|
|
466
|
-
}
|
|
467
|
-
|
|
468
|
-
let mut stopped = None;
|
|
469
|
-
let mut failed = None;
|
|
470
|
-
for pid in pids {
|
|
471
|
-
if terminate_pid_for_workspace(pid, workspace.as_path()) {
|
|
472
|
-
stopped.get_or_insert(pid);
|
|
473
|
-
} else {
|
|
474
|
-
failed.get_or_insert(pid);
|
|
475
|
-
}
|
|
476
|
-
}
|
|
477
|
-
remove_file_if_exists(&coordinator_meta_path(workspace))?;
|
|
478
|
-
|
|
479
|
-
if let Some(pid) = stopped {
|
|
480
|
-
Ok(Some(StopReport {
|
|
481
|
-
ok: true,
|
|
482
|
-
status: StopOutcome::Stopped,
|
|
483
|
-
pid: Some(pid),
|
|
484
|
-
}))
|
|
485
|
-
} else {
|
|
486
|
-
Ok(Some(StopReport {
|
|
487
|
-
ok: false,
|
|
488
|
-
status: StopOutcome::KillFailed,
|
|
489
|
-
pid: failed,
|
|
490
|
-
}))
|
|
491
|
-
}
|
|
492
|
-
}
|
|
493
|
-
|
|
494
|
-
fn discover_coordinator_pids(workspace: &WorkspacePath) -> Vec<Pid> {
|
|
495
|
-
let output = match crate::os_probe::bounded_command_output_with_probe(
|
|
496
|
-
Command::new("ps").args(["-axo", "pid=,command="]),
|
|
497
|
-
"ps_table",
|
|
498
|
-
None,
|
|
499
|
-
) {
|
|
500
|
-
Ok(output) if output.status.success() => output,
|
|
501
|
-
_ => return Vec::new(),
|
|
502
|
-
};
|
|
503
|
-
let text = String::from_utf8_lossy(&output.stdout);
|
|
504
|
-
let metadata_pid = read_coordinator_metadata(workspace).map(|metadata| metadata.pid.get());
|
|
505
|
-
text.lines()
|
|
506
|
-
.filter_map(|line| parse_ps_command_line(line))
|
|
507
|
-
.filter(|(pid, _command)| {
|
|
508
|
-
metadata_pid == Some(*pid)
|
|
509
|
-
&& *pid != std::process::id()
|
|
510
|
-
&& coordinator_pid_owned_by_workspace(workspace, Pid::new(*pid))
|
|
511
|
-
})
|
|
512
|
-
.map(|(pid, _)| Pid::new(pid))
|
|
513
|
-
.collect()
|
|
514
|
-
}
|
|
515
|
-
|
|
516
|
-
fn coordinator_pid_owned_by_workspace(workspace: &WorkspacePath, pid: Pid) -> bool {
|
|
517
|
-
let workspace = workspace
|
|
518
|
-
.as_path()
|
|
519
|
-
.canonicalize()
|
|
520
|
-
.unwrap_or_else(|_| workspace.as_path().to_path_buf());
|
|
521
|
-
let Some(tokens) = crate::platform::argv::argv_tokens(pid.get()) else {
|
|
522
|
-
return false;
|
|
523
|
-
};
|
|
524
|
-
let is_team_agent = tokens.first().is_some_and(|token| is_team_agent_binary(token));
|
|
525
|
-
let is_coordinator = tokens.iter().any(|token| token == "coordinator");
|
|
526
|
-
let has_workspace = tokens.windows(2).any(|pair| {
|
|
527
|
-
pair[0] == "--workspace"
|
|
528
|
-
&& Path::new(&pair[1])
|
|
529
|
-
.canonicalize()
|
|
530
|
-
.map(|path| path == workspace)
|
|
531
|
-
.unwrap_or(false)
|
|
532
|
-
});
|
|
533
|
-
is_team_agent && is_coordinator && has_workspace
|
|
534
|
-
}
|
|
535
|
-
|
|
536
|
-
fn terminate_pid_for_workspace(pid: Pid, workspace: &Path) -> bool {
|
|
537
|
-
if !coordinator_pid_owned_by_path(workspace, pid) {
|
|
538
|
-
return false;
|
|
539
|
-
}
|
|
540
|
-
let pids = process_tree_pids(pid)
|
|
541
|
-
.into_iter()
|
|
542
|
-
.filter(|candidate| coordinator_pid_owned_by_path(workspace, *candidate))
|
|
543
|
-
.collect::<Vec<_>>();
|
|
544
|
-
if pids.is_empty() {
|
|
545
|
-
return false;
|
|
546
|
-
}
|
|
547
|
-
for child in pids.iter().rev() {
|
|
548
|
-
let _ = crate::platform::process::terminate_pid(
|
|
549
|
-
child.get(),
|
|
550
|
-
crate::platform::process::SignalKind::TerminateGraceful,
|
|
551
|
-
);
|
|
552
|
-
}
|
|
553
|
-
if !wait_until_all_not_running(&pids, Duration::from_secs(5)) {
|
|
554
|
-
for child in pids.iter().rev() {
|
|
555
|
-
let _ = crate::platform::process::terminate_pid(
|
|
556
|
-
child.get(),
|
|
557
|
-
crate::platform::process::SignalKind::TerminateForce,
|
|
558
|
-
);
|
|
559
|
-
}
|
|
560
|
-
}
|
|
561
|
-
wait_until_all_not_running(&pids, Duration::from_secs(5))
|
|
562
|
-
}
|
|
563
|
-
|
|
564
|
-
fn coordinator_pid_owned_by_path(workspace: &Path, pid: Pid) -> bool {
|
|
565
|
-
let workspace = workspace
|
|
566
|
-
.canonicalize()
|
|
567
|
-
.unwrap_or_else(|_| workspace.to_path_buf());
|
|
568
|
-
let Some(tokens) = crate::platform::argv::argv_tokens(pid.get()) else {
|
|
569
|
-
return false;
|
|
570
|
-
};
|
|
571
|
-
let is_team_agent = tokens.first().is_some_and(|token| is_team_agent_binary(token));
|
|
572
|
-
let is_coordinator = tokens.iter().any(|token| token == "coordinator");
|
|
573
|
-
let has_workspace = tokens.windows(2).any(|pair| {
|
|
574
|
-
pair[0] == "--workspace"
|
|
575
|
-
&& Path::new(&pair[1])
|
|
576
|
-
.canonicalize()
|
|
577
|
-
.map(|path| path == workspace)
|
|
578
|
-
.unwrap_or(false)
|
|
579
|
-
});
|
|
580
|
-
is_team_agent && is_coordinator && has_workspace
|
|
581
|
-
}
|
|
582
|
-
|
|
583
|
-
fn is_team_agent_binary(token: &str) -> bool {
|
|
584
|
-
let Some(name) = Path::new(token).file_name().and_then(|name| name.to_str()) else {
|
|
585
|
-
return false;
|
|
586
|
-
};
|
|
587
|
-
name == "team-agent" || name == "team_agent" || name.starts_with("team-agent-")
|
|
588
|
-
}
|
|
589
|
-
|
|
590
|
-
fn parse_ps_command_line(line: &str) -> Option<(u32, &str)> {
|
|
591
|
-
let line = line.trim_start();
|
|
592
|
-
let split = line.find(char::is_whitespace).unwrap_or(line.len());
|
|
593
|
-
let pid = line.get(..split)?.trim().parse::<u32>().ok()?;
|
|
594
|
-
let command = line.get(split..)?.trim();
|
|
595
|
-
Some((pid, command))
|
|
596
|
-
}
|
|
597
|
-
|
|
598
|
-
fn terminate_pid(pid: Pid) -> bool {
|
|
599
|
-
// 0.5.x Windows portability Batch 3: routes signal delivery through
|
|
600
|
-
// `platform::process::terminate_pid`. Unix keeps
|
|
601
|
-
// SIGTERM → 5s grace → SIGKILL semantics byte-for-byte
|
|
602
|
-
// (`SignalKind::TerminateGraceful` → SIGTERM,
|
|
603
|
-
// `SignalKind::TerminateForce` → SIGKILL). Windows performs
|
|
604
|
-
// `TerminateProcess` for both kinds; the `TerminationOutcome::ForceOnly`
|
|
605
|
-
// return on the graceful call is what a future audit-event
|
|
606
|
-
// emitter (CR C-6) will trigger `platform.terminate_force_only`
|
|
607
|
-
// on. For this batch the return value is discarded, matching the
|
|
608
|
-
// current inline `let _ = send_signal(...)` pattern.
|
|
609
|
-
if pid_is_running(pid).ok() == Some(false) {
|
|
610
|
-
return true;
|
|
611
|
-
}
|
|
612
|
-
let pids = process_tree_pids(pid);
|
|
613
|
-
for child in pids.iter().rev() {
|
|
614
|
-
let _ = crate::platform::process::terminate_pid(
|
|
615
|
-
child.get(),
|
|
616
|
-
crate::platform::process::SignalKind::TerminateGraceful,
|
|
617
|
-
);
|
|
618
|
-
}
|
|
619
|
-
if !wait_until_all_not_running(&pids, Duration::from_secs(5)) {
|
|
620
|
-
for child in pids.iter().rev() {
|
|
621
|
-
let _ = crate::platform::process::terminate_pid(
|
|
622
|
-
child.get(),
|
|
623
|
-
crate::platform::process::SignalKind::TerminateForce,
|
|
624
|
-
);
|
|
625
|
-
}
|
|
626
|
-
}
|
|
627
|
-
wait_until_all_not_running(&pids, Duration::from_secs(5))
|
|
628
|
-
}
|
|
629
|
-
|
|
630
|
-
/// Public wrapper for diagnostic cleanup paths that must reuse coordinator
|
|
631
|
-
/// shutdown's SIGTERM-then-SIGKILL semantics.
|
|
632
|
-
/// ---
|
|
633
|
-
/// purpose: 把 coordinator 停机用的「先温和后强制」终止语义暴露给诊断清理路径复用
|
|
634
|
-
/// params:
|
|
635
|
-
/// pid: 要终止的进程;只终止这棵进程树,不做名字匹配的批量清理
|
|
636
|
-
/// returns: 超时窗口内整棵树都不再存活为 true
|
|
637
|
-
/// ---
|
|
638
|
-
pub fn terminate_pid_tree(pid: Pid) -> bool {
|
|
639
|
-
terminate_pid(pid)
|
|
640
|
-
}
|
|
641
|
-
|
|
642
|
-
fn process_tree_pids(root: Pid) -> Vec<Pid> {
|
|
643
|
-
let root_pid = root.get();
|
|
644
|
-
let pairs = crate::os_probe::bounded_command_output_with_probe(
|
|
645
|
-
Command::new("ps").args(["-axo", "pid=,ppid="]),
|
|
646
|
-
"ps_parent",
|
|
647
|
-
None,
|
|
648
|
-
)
|
|
649
|
-
.ok()
|
|
650
|
-
.map(|out| String::from_utf8_lossy(&out.stdout).to_string())
|
|
651
|
-
.unwrap_or_default()
|
|
652
|
-
.lines()
|
|
653
|
-
.filter_map(|line| {
|
|
654
|
-
let mut parts = line.split_whitespace();
|
|
655
|
-
let pid = parts.next()?.parse::<u32>().ok()?;
|
|
656
|
-
let ppid = parts.next()?.parse::<u32>().ok()?;
|
|
657
|
-
Some((pid, ppid))
|
|
658
|
-
})
|
|
659
|
-
.collect::<Vec<_>>();
|
|
660
|
-
let mut out = Vec::new();
|
|
661
|
-
collect_child_pids(root_pid, &pairs, &mut out);
|
|
662
|
-
out.push(root_pid);
|
|
663
|
-
out.sort_unstable();
|
|
664
|
-
out.dedup();
|
|
665
|
-
out.into_iter().map(Pid::new).collect()
|
|
666
|
-
}
|
|
667
|
-
|
|
668
|
-
fn collect_child_pids(parent: u32, pairs: &[(u32, u32)], out: &mut Vec<u32>) {
|
|
669
|
-
for (pid, ppid) in pairs {
|
|
670
|
-
if *ppid == parent && !out.contains(pid) {
|
|
671
|
-
out.push(*pid);
|
|
672
|
-
collect_child_pids(*pid, pairs, out);
|
|
673
|
-
}
|
|
674
|
-
}
|
|
675
|
-
}
|
|
676
|
-
|
|
677
|
-
fn wait_until_all_not_running(pids: &[Pid], timeout: Duration) -> bool {
|
|
678
|
-
let start = std::time::Instant::now();
|
|
679
|
-
loop {
|
|
680
|
-
for pid in pids {
|
|
681
|
-
reap_child_if_possible(*pid);
|
|
682
|
-
}
|
|
683
|
-
if pids
|
|
684
|
-
.iter()
|
|
685
|
-
.all(|pid| pid_is_running(*pid).ok() != Some(true))
|
|
686
|
-
{
|
|
687
|
-
return true;
|
|
688
|
-
}
|
|
689
|
-
if start.elapsed() >= timeout {
|
|
690
|
-
return false;
|
|
691
|
-
}
|
|
692
|
-
std::thread::sleep(Duration::from_millis(25));
|
|
693
|
-
}
|
|
694
|
-
}
|
|
695
|
-
|
|
696
|
-
fn reap_child_if_possible(pid: Pid) {
|
|
697
|
-
// Batch 3: routed through `platform::process`. Unix `waitpid
|
|
698
|
-
// (WNOHANG)`; Windows no-op (no zombie model).
|
|
699
|
-
crate::platform::process::reap_child_if_possible(pid.get());
|
|
700
|
-
}
|
|
701
|
-
|
|
702
|
-
#[cfg(unix)]
|
|
703
|
-
#[allow(dead_code)]
|
|
704
|
-
fn send_signal(pid: Pid, signal: libc::c_int) -> bool {
|
|
705
|
-
// Retained (dead code post-Batch-3) as a Unix-only helper for any
|
|
706
|
-
// future non-standard signal delivery. All product paths now use
|
|
707
|
-
// `crate::platform::process::terminate_pid` with `SignalKind`.
|
|
708
|
-
let Ok(pid_t) = libc::pid_t::try_from(pid.get()) else {
|
|
709
|
-
return false;
|
|
710
|
-
};
|
|
711
|
-
unsafe { libc::kill(pid_t, signal) == 0 }
|
|
712
|
-
}
|
|
713
|
-
|
|
714
|
-
fn wait_until_not_running(pid: Pid, timeout: Duration) -> bool {
|
|
715
|
-
let start = std::time::Instant::now();
|
|
716
|
-
loop {
|
|
717
|
-
if pid_is_running(pid).ok() != Some(true) {
|
|
718
|
-
return true;
|
|
719
|
-
}
|
|
720
|
-
if start.elapsed() >= timeout {
|
|
721
|
-
return false;
|
|
722
|
-
}
|
|
723
|
-
std::thread::sleep(Duration::from_millis(25));
|
|
724
|
-
}
|
|
725
|
-
}
|
|
726
|
-
|
|
727
|
-
// ===========================================================================
|
|
728
|
-
// metadata 身份原语(metadata.py)—— 自由函数面
|
|
729
|
-
// ===========================================================================
|
|
730
|
-
|
|
731
|
-
/// `pid_is_running`(`metadata.py:16-25`):`os.kill(pid, 0)` + `ps -o stat=` 查 zombie(Z* → 不算活)。
|
|
732
|
-
/// §10 fallible:进程探测 I/O 可失败 → Result。
|
|
733
|
-
///
|
|
734
|
-
/// 0.5.x Windows portability Batch 4: this function has UNIQUE
|
|
735
|
-
/// coordinator-metadata semantics — it treats `EPERM` as "not
|
|
736
|
-
/// running" (different from `platform::process::pid_liveness` which
|
|
737
|
-
/// treats `EPERM` as Live) because the coordinator only owns
|
|
738
|
-
/// processes it can signal, and uses `ps -o stat=` for zombie
|
|
739
|
-
/// detection. The `ps` shellout is Unix-only.
|
|
740
|
-
///
|
|
741
|
-
/// On Windows the coordinator-metadata identity check runs through
|
|
742
|
-
/// `platform::process::pid_liveness` instead (Windows has no zombie
|
|
743
|
-
/// state — a process is either Live or Dead — so the additional
|
|
744
|
-
/// `ps stat=` step has no analogue). This preserves the coordinator's
|
|
745
|
-
/// "am I the owner" check without silently reporting stale pids as
|
|
746
|
-
/// alive.
|
|
747
|
-
/// ---
|
|
748
|
-
/// purpose: 判断某 pid 是不是本 coordinator 还能拥有的活进程(Unix 实现)
|
|
749
|
-
/// params:
|
|
750
|
-
/// pid: 待判定进程号
|
|
751
|
-
/// returns: 存活且非僵尸为 true。语义与通用存活探针不同:signal 返回 EPERM 一律判 false,因为 coordinator 只认自己能发信号的进程;另用 ps 的 stat 排掉僵尸
|
|
752
|
-
/// errors: 除 EPERM/ESRCH 外的 signal 错误、以及 ps 探测失败时返回 io::Error
|
|
753
|
-
/// cfg: unix
|
|
754
|
-
/// ---
|
|
755
|
-
#[cfg(unix)]
|
|
756
|
-
pub fn pid_is_running(pid: Pid) -> Result<bool, std::io::Error> {
|
|
757
|
-
let Ok(pid_t) = libc::pid_t::try_from(pid.get()) else {
|
|
758
|
-
return Ok(false);
|
|
759
|
-
};
|
|
760
|
-
let signal_rc = unsafe { libc::kill(pid_t, 0) };
|
|
761
|
-
if signal_rc != 0 {
|
|
762
|
-
let err = std::io::Error::last_os_error();
|
|
763
|
-
return match err.raw_os_error() {
|
|
764
|
-
Some(libc::EPERM) | Some(libc::ESRCH) => Ok(false),
|
|
765
|
-
_ => Err(err),
|
|
766
|
-
};
|
|
767
|
-
}
|
|
768
|
-
let out = crate::os_probe::bounded_command_output_with_probe(
|
|
769
|
-
Command::new("ps").args(["-p", &pid.to_string(), "-o", "stat="]),
|
|
770
|
-
"ps_table",
|
|
771
|
-
Some(pid.get()),
|
|
772
|
-
)?;
|
|
773
|
-
if !out.status.success() {
|
|
774
|
-
return Ok(false);
|
|
775
|
-
}
|
|
776
|
-
let stat = String::from_utf8_lossy(&out.stdout).trim().to_string();
|
|
777
|
-
Ok(!stat.is_empty() && !stat.starts_with('Z'))
|
|
778
|
-
}
|
|
779
|
-
|
|
780
|
-
/// Windows shim: no `ps stat=` zombie detection needed (Windows has
|
|
781
|
-
/// no zombie state — a process is either Live or Dead). Route through
|
|
782
|
-
/// `platform::process::pid_liveness` and map to bool. The EPERM
|
|
783
|
-
/// semantic ("we can't signal → treat as not running") maps to
|
|
784
|
-
/// Windows `ERROR_ACCESS_DENIED` which the platform layer already
|
|
785
|
-
/// treats as `Live`; so on Windows the coordinator sees a process
|
|
786
|
-
/// it can't query as still-running (safer than pretending it's gone
|
|
787
|
-
/// and losing the ownership handle).
|
|
788
|
-
/// ---
|
|
789
|
-
/// purpose: 判断某 pid 是不是本 coordinator 还能拥有的活进程(非 Unix 实现)
|
|
790
|
-
/// params:
|
|
791
|
-
/// pid: 待判定进程号
|
|
792
|
-
/// returns: 平台层报 Live 为 true,Dead 或 Unknown 均为 false。Windows 没有僵尸态,故不做 ps stat 那一步;平台层把拒绝访问算作 Live,于是查不动的进程仍被视为在跑
|
|
793
|
-
/// errors: 平台层存活查询失败时返回 io::Error
|
|
794
|
-
/// cfg: not(unix)
|
|
795
|
-
/// ---
|
|
796
|
-
#[cfg(not(unix))]
|
|
797
|
-
pub fn pid_is_running(pid: Pid) -> Result<bool, std::io::Error> {
|
|
798
|
-
match crate::platform::process::pid_liveness(pid.get())? {
|
|
799
|
-
crate::platform::process::ProcessLiveness::Live => Ok(true),
|
|
800
|
-
crate::platform::process::ProcessLiveness::Dead => Ok(false),
|
|
801
|
-
crate::platform::process::ProcessLiveness::Unknown { .. } => Ok(false),
|
|
802
|
-
}
|
|
803
|
-
}
|
|
804
|
-
|
|
805
|
-
/// `read_coordinator_metadata`(`metadata.py:28-34`)。读 `coordinator.json`;损坏/缺失/非 dict → `None`。
|
|
806
|
-
/// ---
|
|
807
|
-
/// purpose: 读出已落盘的 coordinator.json
|
|
808
|
-
/// params:
|
|
809
|
-
/// workspace: workspace 根
|
|
810
|
-
/// returns: 解析成功才有值;文件缺失、读不动或 JSON 形状不符一律为 None,绝不返回半份 metadata
|
|
811
|
-
/// ---
|
|
812
|
-
pub fn read_coordinator_metadata(workspace: &WorkspacePath) -> Option<CoordinatorMetadata> {
|
|
813
|
-
let text = std::fs::read_to_string(coordinator_meta_path(workspace)).ok()?;
|
|
814
|
-
serde_json::from_str(&text).ok()
|
|
815
|
-
}
|
|
816
|
-
|
|
817
|
-
/// ---
|
|
818
|
-
/// purpose: 给出「当前这个 CLI 二进制」的身份,用于和 daemon 已记录的身份比对
|
|
819
|
-
/// returns: 路径取自当前可执行文件(尽量 canonicalize)而非 PATH 查找,版本取自编译进来的包版本;路径取不到时退化成 <unknown>。测试可用 TEAM_AGENT_TEST_CALLER_BINARY_IDENTITY 覆盖,且只有两字段都非空才采信
|
|
820
|
-
/// ---
|
|
821
|
-
pub fn current_coordinator_binary_identity() -> CoordinatorBinaryIdentity {
|
|
822
|
-
if let Ok(raw) = std::env::var("TEAM_AGENT_TEST_CALLER_BINARY_IDENTITY") {
|
|
823
|
-
if let Ok(identity) = serde_json::from_str::<CoordinatorBinaryIdentity>(&raw) {
|
|
824
|
-
if !identity.binary_path.is_empty() && !identity.binary_version.is_empty() {
|
|
825
|
-
return identity;
|
|
826
|
-
}
|
|
827
|
-
}
|
|
828
|
-
}
|
|
829
|
-
let binary_path = std::env::current_exe()
|
|
830
|
-
.map(|path| path.canonicalize().unwrap_or(path))
|
|
831
|
-
.map(|path| path.to_string_lossy().into_owned())
|
|
832
|
-
.unwrap_or_else(|_| "<unknown>".to_string());
|
|
833
|
-
CoordinatorBinaryIdentity {
|
|
834
|
-
binary_path,
|
|
835
|
-
binary_version: crate::packaging::Version::current().as_str().to_string(),
|
|
836
|
-
}
|
|
837
|
-
}
|
|
838
|
-
|
|
839
|
-
/// `coordinator_metadata_ok` now includes daemon binary identity in addition
|
|
840
|
-
/// to the original pid/protocol/schema tuple.
|
|
841
|
-
/// ---
|
|
842
|
-
/// purpose: 判断已落盘 metadata 是否与当前事实完全一致
|
|
843
|
-
/// params:
|
|
844
|
-
/// metadata: 已读出的 coordinator.json;None 视为不一致
|
|
845
|
-
/// pid: 实际观测到的 daemon pid
|
|
846
|
-
/// returns: pid、协议版本、message store schema 版本、以及 daemon 二进制身份四者全对才为 true
|
|
847
|
-
/// ---
|
|
848
|
-
pub fn coordinator_metadata_ok(metadata: Option<&CoordinatorMetadata>, pid: Pid) -> bool {
|
|
849
|
-
coordinator_metadata_mismatch_reason(metadata, pid).is_none()
|
|
850
|
-
}
|
|
851
|
-
|
|
852
|
-
/// ---
|
|
853
|
-
/// purpose: 给出 metadata 不一致的机器可读原因,而不是只给一个布尔
|
|
854
|
-
/// params:
|
|
855
|
-
/// metadata: 已读出的 coordinator.json;None 时原因为 MetadataMissing
|
|
856
|
-
/// pid: 实际观测到的 daemon pid
|
|
857
|
-
/// returns: 第一个不匹配项对应的原因;全部一致时为 None。先判 pid/协议/schema 这组线协议字段,再判二进制身份
|
|
858
|
-
/// ---
|
|
859
|
-
pub fn coordinator_metadata_mismatch_reason(
|
|
860
|
-
metadata: Option<&CoordinatorMetadata>,
|
|
861
|
-
pid: Pid,
|
|
862
|
-
) -> Option<CoordinatorMetadataMismatchReason> {
|
|
863
|
-
let identity = current_coordinator_binary_identity();
|
|
864
|
-
coordinator_metadata_mismatch_reason_with_identity(metadata, pid, &identity)
|
|
865
|
-
}
|
|
866
|
-
|
|
867
|
-
fn coordinator_metadata_mismatch_reason_with_identity(
|
|
868
|
-
metadata: Option<&CoordinatorMetadata>,
|
|
869
|
-
pid: Pid,
|
|
870
|
-
identity: &CoordinatorBinaryIdentity,
|
|
871
|
-
) -> Option<CoordinatorMetadataMismatchReason> {
|
|
872
|
-
coordinator_wire_metadata_mismatch_reason(metadata, pid)
|
|
873
|
-
.or_else(|| coordinator_binary_identity_mismatch_reason(metadata, identity))
|
|
874
|
-
}
|
|
875
|
-
|
|
876
|
-
fn coordinator_wire_metadata_mismatch_reason(
|
|
877
|
-
metadata: Option<&CoordinatorMetadata>,
|
|
878
|
-
pid: Pid,
|
|
879
|
-
) -> Option<CoordinatorMetadataMismatchReason> {
|
|
880
|
-
let Some(metadata) = metadata else {
|
|
881
|
-
return Some(CoordinatorMetadataMismatchReason::MetadataMissing);
|
|
882
|
-
};
|
|
883
|
-
if metadata.pid != pid {
|
|
884
|
-
return Some(CoordinatorMetadataMismatchReason::PidMismatch);
|
|
885
|
-
}
|
|
886
|
-
if metadata.protocol_version != PROTOCOL_VERSION {
|
|
887
|
-
return Some(CoordinatorMetadataMismatchReason::ProtocolVersionMismatch);
|
|
888
|
-
}
|
|
889
|
-
if metadata.message_store_schema_version != crate::db::schema::SCHEMA_VERSION {
|
|
890
|
-
return Some(CoordinatorMetadataMismatchReason::MessageStoreSchemaVersionMismatch);
|
|
891
|
-
}
|
|
892
|
-
None
|
|
893
|
-
}
|
|
894
|
-
|
|
895
|
-
fn coordinator_binary_identity_mismatch_reason(
|
|
896
|
-
metadata: Option<&CoordinatorMetadata>,
|
|
897
|
-
identity: &CoordinatorBinaryIdentity,
|
|
898
|
-
) -> Option<CoordinatorMetadataMismatchReason> {
|
|
899
|
-
let Some(metadata) = metadata else {
|
|
900
|
-
return Some(CoordinatorMetadataMismatchReason::MetadataMissing);
|
|
901
|
-
};
|
|
902
|
-
let Some(binary_version) = metadata
|
|
903
|
-
.binary_version
|
|
904
|
-
.as_deref()
|
|
905
|
-
.filter(|value| !value.is_empty())
|
|
906
|
-
else {
|
|
907
|
-
return Some(CoordinatorMetadataMismatchReason::BinaryIdentityMissing);
|
|
908
|
-
};
|
|
909
|
-
let Some(binary_path) = metadata
|
|
910
|
-
.binary_path
|
|
911
|
-
.as_deref()
|
|
912
|
-
.filter(|value| !value.is_empty())
|
|
913
|
-
else {
|
|
914
|
-
return Some(CoordinatorMetadataMismatchReason::BinaryIdentityMissing);
|
|
915
|
-
};
|
|
916
|
-
if binary_version != identity.binary_version {
|
|
917
|
-
return Some(CoordinatorMetadataMismatchReason::BinaryVersionMismatch);
|
|
918
|
-
}
|
|
919
|
-
if !binary_path_matches_current_identity(binary_path, &identity.binary_path) {
|
|
920
|
-
return Some(CoordinatorMetadataMismatchReason::BinaryPathMismatch);
|
|
921
|
-
}
|
|
922
|
-
None
|
|
923
|
-
}
|
|
924
|
-
|
|
925
|
-
fn coordinator_binary_identity_relation(
|
|
926
|
-
metadata: Option<&CoordinatorMetadata>,
|
|
927
|
-
identity: &CoordinatorBinaryIdentity,
|
|
928
|
-
) -> CoordinatorBinaryIdentityRelation {
|
|
929
|
-
let Some(metadata) = metadata else {
|
|
930
|
-
return CoordinatorBinaryIdentityRelation::Unknown;
|
|
931
|
-
};
|
|
932
|
-
let Some(daemon_version) = metadata
|
|
933
|
-
.binary_version
|
|
934
|
-
.as_deref()
|
|
935
|
-
.filter(|value| !value.is_empty())
|
|
936
|
-
else {
|
|
937
|
-
return CoordinatorBinaryIdentityRelation::Unknown;
|
|
938
|
-
};
|
|
939
|
-
match compare_version_strings(daemon_version, &identity.binary_version) {
|
|
940
|
-
Some(std::cmp::Ordering::Greater) => {
|
|
941
|
-
return CoordinatorBinaryIdentityRelation::DaemonNewerThanCaller;
|
|
942
|
-
}
|
|
943
|
-
Some(std::cmp::Ordering::Less) => {
|
|
944
|
-
return CoordinatorBinaryIdentityRelation::CallerNewerThanDaemon;
|
|
945
|
-
}
|
|
946
|
-
Some(std::cmp::Ordering::Equal) => {}
|
|
947
|
-
None => return CoordinatorBinaryIdentityRelation::Unknown,
|
|
948
|
-
}
|
|
949
|
-
let Some(daemon_path) = metadata
|
|
950
|
-
.binary_path
|
|
951
|
-
.as_deref()
|
|
952
|
-
.filter(|value| !value.is_empty())
|
|
953
|
-
else {
|
|
954
|
-
return CoordinatorBinaryIdentityRelation::Unknown;
|
|
955
|
-
};
|
|
956
|
-
if binary_path_matches_current_identity(daemon_path, &identity.binary_path) {
|
|
957
|
-
CoordinatorBinaryIdentityRelation::Same
|
|
958
|
-
} else {
|
|
959
|
-
CoordinatorBinaryIdentityRelation::SameVersionPathMismatch
|
|
960
|
-
}
|
|
961
|
-
}
|
|
962
|
-
|
|
963
|
-
fn compare_version_strings(left: &str, right: &str) -> Option<std::cmp::Ordering> {
|
|
964
|
-
let left = parse_numeric_version(left)?;
|
|
965
|
-
let right = parse_numeric_version(right)?;
|
|
966
|
-
Some(left.cmp(&right))
|
|
967
|
-
}
|
|
968
|
-
|
|
969
|
-
fn parse_numeric_version(value: &str) -> Option<Vec<u64>> {
|
|
970
|
-
if value.is_empty() {
|
|
971
|
-
return None;
|
|
972
|
-
}
|
|
973
|
-
value
|
|
974
|
-
.split('.')
|
|
975
|
-
.map(|part| part.parse::<u64>().ok())
|
|
976
|
-
.collect()
|
|
977
|
-
}
|
|
978
|
-
|
|
979
|
-
fn binary_path_matches_current_identity(metadata_path: &str, identity_path: &str) -> bool {
|
|
980
|
-
if metadata_path == identity_path {
|
|
981
|
-
return true;
|
|
982
|
-
}
|
|
983
|
-
test_harness_binary_path_matches(metadata_path)
|
|
984
|
-
}
|
|
985
|
-
|
|
986
|
-
/// Test harness escape hatch for integration tests whose process identity is the
|
|
987
|
-
/// test binary while fixture metadata intentionally points at the built CLI.
|
|
988
|
-
/// Production must not infer this from path shape; callers must set the
|
|
989
|
-
/// `TEAM_AGENT_TEST_HARNESS_BINARY_PATH_MATCH` env explicitly to either the
|
|
990
|
-
/// expected binary path or the target directory containing `team-agent`.
|
|
991
|
-
fn test_harness_binary_path_matches(metadata_path: &str) -> bool {
|
|
992
|
-
let Ok(path) = std::env::var("TEAM_AGENT_TEST_HARNESS_BINARY_PATH_MATCH") else {
|
|
993
|
-
return false;
|
|
994
|
-
};
|
|
995
|
-
let path = PathBuf::from(path);
|
|
996
|
-
path_matches(metadata_path, &path)
|
|
997
|
-
|| path_matches(metadata_path, &path.join("team-agent"))
|
|
998
|
-
|| path
|
|
999
|
-
.parent()
|
|
1000
|
-
.is_some_and(|parent| path_matches(metadata_path, &parent.join("team-agent")))
|
|
1001
|
-
}
|
|
1002
|
-
|
|
1003
|
-
fn path_matches(metadata_path: &str, path: &Path) -> bool {
|
|
1004
|
-
path.to_string_lossy() == metadata_path
|
|
1005
|
-
|| path
|
|
1006
|
-
.canonicalize()
|
|
1007
|
-
.ok()
|
|
1008
|
-
.is_some_and(|path| path.to_string_lossy() == metadata_path)
|
|
1009
|
-
}
|
|
1010
|
-
|
|
1011
|
-
/// `write_coordinator_metadata`(`metadata.py:46-61`)。写 `coordinator.json`(pretty indent=2),
|
|
1012
|
-
/// `updated_at = now(utc).isoformat()`。
|
|
1013
|
-
/// ---
|
|
1014
|
-
/// purpose: 落盘 coordinator.json,把当前 daemon 的身份三元与二进制身份记下来
|
|
1015
|
-
/// params:
|
|
1016
|
-
/// workspace: workspace 根
|
|
1017
|
-
/// pid: 本次要记录的 daemon pid
|
|
1018
|
-
/// source: 这份 metadata 是 daemon 自举时写的还是 CLI start 时写的
|
|
1019
|
-
/// returns: 写成功返回 ()。协议版本与 schema 版本取自当前构建常量,updated_at 是写入时刻的 UTC
|
|
1020
|
-
/// errors: 建目录、序列化或写文件失败时返回 io::Error
|
|
1021
|
-
/// ---
|
|
1022
|
-
pub fn write_coordinator_metadata(
|
|
1023
|
-
workspace: &WorkspacePath,
|
|
1024
|
-
pid: Pid,
|
|
1025
|
-
source: MetadataSource,
|
|
1026
|
-
) -> Result<(), std::io::Error> {
|
|
1027
|
-
let path = coordinator_meta_path(workspace);
|
|
1028
|
-
if let Some(parent) = path.parent() {
|
|
1029
|
-
std::fs::create_dir_all(parent)?;
|
|
1030
|
-
}
|
|
1031
|
-
let metadata = CoordinatorMetadata {
|
|
1032
|
-
pid,
|
|
1033
|
-
protocol_version: PROTOCOL_VERSION,
|
|
1034
|
-
message_store_schema_version: crate::db::schema::SCHEMA_VERSION,
|
|
1035
|
-
binary_path: Some(current_coordinator_binary_identity().binary_path),
|
|
1036
|
-
binary_version: Some(crate::packaging::Version::current().as_str().to_string()),
|
|
1037
|
-
source,
|
|
1038
|
-
updated_at: chrono::Utc::now().to_rfc3339(),
|
|
1039
|
-
};
|
|
1040
|
-
let text = serde_json::to_string_pretty(&metadata)
|
|
1041
|
-
.map_err(|e| std::io::Error::other(e.to_string()))?;
|
|
1042
|
-
std::fs::write(path, text)
|
|
1043
|
-
}
|
|
1044
|
-
|
|
1045
|
-
/// ---
|
|
1046
|
-
/// purpose: 用「能不能真的打开本队 message store」来判 schema 兼容门
|
|
1047
|
-
/// params:
|
|
1048
|
-
/// workspace: workspace 根
|
|
1049
|
-
/// returns: 打开成功则 ok=true 且 error/action 为空;失败则 ok=false,带 InitFailed 原文与修复 hint。schema_version 恒为当前构建的版本号
|
|
1050
|
-
/// ---
|
|
1051
|
-
pub(crate) fn message_store_schema_health(workspace: &WorkspacePath) -> SchemaHealth {
|
|
1052
|
-
match MessageStore::open(workspace.as_path()) {
|
|
1053
|
-
Ok(_) => SchemaHealth {
|
|
1054
|
-
ok: true,
|
|
1055
|
-
schema_version: crate::db::schema::SCHEMA_VERSION,
|
|
1056
|
-
error: None,
|
|
1057
|
-
action: None,
|
|
1058
|
-
},
|
|
1059
|
-
Err(e) => SchemaHealth {
|
|
1060
|
-
ok: false,
|
|
1061
|
-
schema_version: crate::db::schema::SCHEMA_VERSION,
|
|
1062
|
-
error: Some(SchemaError::InitFailed {
|
|
1063
|
-
message: e.to_string(),
|
|
1064
|
-
}),
|
|
1065
|
-
action: Some("run team-agent doctor --fix-schema --json".to_string()),
|
|
1066
|
-
},
|
|
1067
|
-
}
|
|
1068
|
-
}
|
|
1069
|
-
|
|
1070
|
-
fn message_store_schema_health_read_only(workspace: &WorkspacePath) -> SchemaHealth {
|
|
1071
|
-
let action = Some("run team-agent doctor --fix-schema --json".to_string());
|
|
1072
|
-
match crate::db::migration::schema_diagnosis_workspace_read_only(workspace.as_path()) {
|
|
1073
|
-
Ok(diagnosis) if diagnosis.ok && diagnosis.status == "ok" => SchemaHealth {
|
|
1074
|
-
ok: true,
|
|
1075
|
-
schema_version: crate::db::schema::SCHEMA_VERSION,
|
|
1076
|
-
error: None,
|
|
1077
|
-
action: None,
|
|
1078
|
-
},
|
|
1079
|
-
Ok(diagnosis) => SchemaHealth {
|
|
1080
|
-
ok: false,
|
|
1081
|
-
schema_version: crate::db::schema::SCHEMA_VERSION,
|
|
1082
|
-
error: Some(SchemaError::InitFailed {
|
|
1083
|
-
message: format!("team.db status: {}", diagnosis.status),
|
|
1084
|
-
}),
|
|
1085
|
-
action,
|
|
1086
|
-
},
|
|
1087
|
-
Err(error) => SchemaHealth {
|
|
1088
|
-
ok: false,
|
|
1089
|
-
schema_version: crate::db::schema::SCHEMA_VERSION,
|
|
1090
|
-
error: Some(SchemaError::InitFailed {
|
|
1091
|
-
message: error.to_string(),
|
|
1092
|
-
}),
|
|
1093
|
-
action,
|
|
1094
|
-
},
|
|
1095
|
-
}
|
|
1096
|
-
}
|
|
1097
|
-
|
|
1098
|
-
fn read_pid_file(path: &Path) -> Option<Pid> {
|
|
1099
|
-
let text = std::fs::read_to_string(path).ok()?;
|
|
1100
|
-
let raw = text.trim().parse::<u32>().ok()?;
|
|
1101
|
-
Some(Pid::new(raw))
|
|
1102
|
-
}
|
|
1103
|
-
|
|
1104
|
-
fn remove_file_if_exists(path: &Path) -> Result<(), std::io::Error> {
|
|
1105
|
-
match std::fs::remove_file(path) {
|
|
1106
|
-
Ok(()) => Ok(()),
|
|
1107
|
-
Err(e) if e.kind() == std::io::ErrorKind::NotFound => Ok(()),
|
|
1108
|
-
Err(e) => Err(e),
|
|
1109
|
-
}
|
|
1110
|
-
}
|
|
1111
|
-
|
|
1112
|
-
// ===========================================================================
|
|
1113
|
-
// coordinator 路径(paths.py)
|
|
1114
|
-
// ===========================================================================
|
|
1115
|
-
|
|
1116
|
-
/// `coordinator.pid` 路径(`paths.py:8`)= `runtime_dir(workspace)/coordinator.pid`。
|
|
1117
|
-
/// ---
|
|
1118
|
-
/// purpose: 给出 coordinator.pid 的位置
|
|
1119
|
-
/// params:
|
|
1120
|
-
/// workspace: workspace 根
|
|
1121
|
-
/// returns: runtime 目录下的 coordinator.pid;只算路径,不保证文件存在
|
|
1122
|
-
/// ---
|
|
1123
|
-
pub fn coordinator_pid_path(workspace: &WorkspacePath) -> PathBuf {
|
|
1124
|
-
crate::model::paths::runtime_dir(workspace.as_path()).join("coordinator.pid")
|
|
1125
|
-
}
|
|
1126
|
-
|
|
1127
|
-
/// `coordinator.json` 路径(`paths.py:12`)。
|
|
1128
|
-
/// ---
|
|
1129
|
-
/// purpose: 给出 coordinator.json 的位置
|
|
1130
|
-
/// params:
|
|
1131
|
-
/// workspace: workspace 根
|
|
1132
|
-
/// returns: runtime 目录下的 coordinator.json;只算路径,不保证文件存在
|
|
1133
|
-
/// ---
|
|
1134
|
-
pub fn coordinator_meta_path(workspace: &WorkspacePath) -> PathBuf {
|
|
1135
|
-
crate::model::paths::runtime_dir(workspace.as_path()).join("coordinator.json")
|
|
1136
|
-
}
|
|
1137
|
-
|
|
1138
|
-
/// `coordinator.log` 路径(`paths.py:16`)。
|
|
1139
|
-
/// ---
|
|
1140
|
-
/// purpose: 给出 coordinator.log 的位置
|
|
1141
|
-
/// params:
|
|
1142
|
-
/// workspace: workspace 根
|
|
1143
|
-
/// returns: runtime 目录下的 coordinator.log;daemon 子进程的 stdout/stderr 都追加到这里
|
|
1144
|
-
/// ---
|
|
1145
|
-
pub fn coordinator_log_path(workspace: &WorkspacePath) -> PathBuf {
|
|
1146
|
-
crate::model::paths::runtime_dir(workspace.as_path()).join("coordinator.log")
|
|
1147
|
-
}
|
|
1148
|
-
|
|
1149
|
-
#[cfg(all(test, unix))]
|
|
1150
|
-
mod tests {
|
|
1151
|
-
use super::*;
|
|
1152
|
-
|
|
1153
|
-
struct ChildGuard(std::process::Child);
|
|
1154
|
-
|
|
1155
|
-
impl Drop for ChildGuard {
|
|
1156
|
-
fn drop(&mut self) {
|
|
1157
|
-
unsafe {
|
|
1158
|
-
libc::kill(self.0.id() as libc::pid_t, libc::SIGTERM);
|
|
1159
|
-
}
|
|
1160
|
-
let _ = self.0.wait();
|
|
1161
|
-
}
|
|
1162
|
-
}
|
|
1163
|
-
|
|
1164
|
-
#[test]
|
|
1165
|
-
fn coordinator_daemon_spawn_helper_detaches_session() {
|
|
1166
|
-
let mut command = Command::new("/bin/sleep");
|
|
1167
|
-
command
|
|
1168
|
-
.arg("30")
|
|
1169
|
-
.stdin(Stdio::null())
|
|
1170
|
-
.stdout(Stdio::null())
|
|
1171
|
-
.stderr(Stdio::null());
|
|
1172
|
-
detach_daemon_child(&mut command);
|
|
1173
|
-
|
|
1174
|
-
let child = command.spawn().expect("spawn detached child");
|
|
1175
|
-
let guard = ChildGuard(child);
|
|
1176
|
-
let pid = guard.0.id() as libc::pid_t;
|
|
1177
|
-
let sid = unsafe { libc::getsid(pid) };
|
|
1178
|
-
|
|
1179
|
-
assert_ne!(sid, -1, "getsid({pid}) failed");
|
|
1180
|
-
assert_eq!(
|
|
1181
|
-
sid, pid,
|
|
1182
|
-
"detached coordinator children must become session leaders so launcher SIGHUP does not reach them"
|
|
1183
|
-
);
|
|
1184
|
-
}
|
|
1185
|
-
}
|