@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,1721 +0,0 @@
|
|
|
1
|
-
//!
|
|
2
|
-
//! diagnose/doctor CLI helpers.
|
|
3
|
-
use super::*;
|
|
4
|
-
use crate::model::pane_authority_refusal::{
|
|
5
|
-
PaneAuthorityRecoveryAction, PaneAuthorityRecoveryHint, PaneAuthorityRefusal,
|
|
6
|
-
PaneAuthorityRefusalFacts, PaneAuthorityRefusalField, ACTION_FIELD, ACTION_REQUIRED_FIELD,
|
|
7
|
-
HINT_ACTION_FIELD, REASON_FIELD,
|
|
8
|
-
};
|
|
9
|
-
use crate::provider::wire::{command_name, parse_provider, provider_wire};
|
|
10
|
-
use crate::transport::Transport;
|
|
11
|
-
|
|
12
|
-
#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize)]
|
|
13
|
-
#[serde(rename_all = "snake_case")]
|
|
14
|
-
pub(crate) enum PiBackingStatus {
|
|
15
|
-
Pending,
|
|
16
|
-
Captured,
|
|
17
|
-
Missing,
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize)]
|
|
21
|
-
#[serde(rename_all = "snake_case")]
|
|
22
|
-
pub(crate) enum PiMcpStatus {
|
|
23
|
-
Unavailable,
|
|
24
|
-
ConfiguredLazy,
|
|
25
|
-
RoundtripVerified,
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
pub(crate) struct PiDoctorInput {
|
|
29
|
-
pub executable_chain_verified: bool,
|
|
30
|
-
pub pi_version: Option<String>,
|
|
31
|
-
pub adapter_version: Option<String>,
|
|
32
|
-
pub catalog_sha256: Option<String>,
|
|
33
|
-
pub selected_model: Option<String>,
|
|
34
|
-
pub candidate_executable: Option<std::path::PathBuf>,
|
|
35
|
-
pub wrapper: Option<std::path::PathBuf>,
|
|
36
|
-
pub mcp_roundtrip_at: Option<String>,
|
|
37
|
-
pub backing: PiBackingStatus,
|
|
38
|
-
pub activity: crate::provider::TurnState,
|
|
39
|
-
pub activity_source: crate::provider::ClassifySource,
|
|
40
|
-
pub env_key_names: Vec<String>,
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize)]
|
|
44
|
-
pub(crate) struct PiDoctorFacts {
|
|
45
|
-
pub mcp: PiMcpStatus,
|
|
46
|
-
pub mcp_connected: bool,
|
|
47
|
-
pub backing: PiBackingStatus,
|
|
48
|
-
pub activity: crate::provider::TurnState,
|
|
49
|
-
pub activity_source: crate::provider::ClassifySource,
|
|
50
|
-
pub auth_hint: crate::provider::AuthHintStatus,
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
pub(crate) fn pi_doctor_facts(input: PiDoctorInput) -> PiDoctorFacts {
|
|
54
|
-
let mcp = if input.mcp_roundtrip_at.is_some() {
|
|
55
|
-
PiMcpStatus::RoundtripVerified
|
|
56
|
-
} else if input.wrapper.is_some() {
|
|
57
|
-
PiMcpStatus::ConfiguredLazy
|
|
58
|
-
} else {
|
|
59
|
-
PiMcpStatus::Unavailable
|
|
60
|
-
};
|
|
61
|
-
let _ = (
|
|
62
|
-
input.executable_chain_verified,
|
|
63
|
-
input.pi_version,
|
|
64
|
-
input.adapter_version,
|
|
65
|
-
input.catalog_sha256,
|
|
66
|
-
input.selected_model,
|
|
67
|
-
input.candidate_executable,
|
|
68
|
-
input.env_key_names,
|
|
69
|
-
);
|
|
70
|
-
PiDoctorFacts {
|
|
71
|
-
mcp,
|
|
72
|
-
mcp_connected: mcp == PiMcpStatus::RoundtripVerified,
|
|
73
|
-
backing: input.backing,
|
|
74
|
-
activity: input.activity,
|
|
75
|
-
activity_source: input.activity_source,
|
|
76
|
-
auth_hint: crate::provider::AuthHintStatus::Unknown,
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/// 0.5.39 Slice 1 (tmux-server-death-locate §11.1 B): classify a tmux
|
|
81
|
-
/// transport error string into a diagnose issue id. When the underlying
|
|
82
|
-
/// tmux subprocess stderr contains `server exited unexpectedly`, the
|
|
83
|
-
/// tmux server itself crashed (upstream tmux 3.6a control-mode +
|
|
84
|
-
/// broadcast attach/detach jitter is one known trigger) — the physical
|
|
85
|
-
/// layer that disappeared is the whole server, not just this team's
|
|
86
|
-
/// session. Otherwise, callers keep the legacy `tmux_session_missing`
|
|
87
|
-
/// classification.
|
|
88
|
-
pub(crate) fn classify_tmux_server_error(error_text: &str) -> &'static str {
|
|
89
|
-
if error_text.contains("server exited unexpectedly") {
|
|
90
|
-
"tmux_server_crashed"
|
|
91
|
-
} else {
|
|
92
|
-
"tmux_session_missing"
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
fn recorded_mux_pane(agent_state: &Value) -> Option<&str> {
|
|
97
|
-
["pane_id", "native_pane"].iter().find_map(|key| {
|
|
98
|
-
agent_state
|
|
99
|
-
.get(*key)
|
|
100
|
-
.and_then(Value::as_str)
|
|
101
|
-
.filter(|value| !value.is_empty())
|
|
102
|
-
})
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
fn explicit_window_name(agent_state: &Value) -> Option<&str> {
|
|
106
|
-
["window", "window_name"].iter().find_map(|key| {
|
|
107
|
-
agent_state
|
|
108
|
-
.get(*key)
|
|
109
|
-
.and_then(Value::as_str)
|
|
110
|
-
.filter(|value| !value.is_empty())
|
|
111
|
-
})
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
fn is_public_window_name(provider: &str, window: &str) -> bool {
|
|
115
|
-
// Contract ids such as grok_build are not legacy Provider aliases, but
|
|
116
|
-
// their tmux title is the public command, not the seat id.
|
|
117
|
-
if provider == "grok_build" && window == "grok" {
|
|
118
|
-
return true;
|
|
119
|
-
}
|
|
120
|
-
// An npm-installed Codex runs its vendor launcher under PATH's `node`, so
|
|
121
|
-
// tmux names the pane after that process instead of `codex`.
|
|
122
|
-
if provider == "codex_tui" && matches!(window, "codex" | "node") {
|
|
123
|
-
return true;
|
|
124
|
-
}
|
|
125
|
-
// The same holds for npm-installed Pi; legacy `pi` keeps its own rule.
|
|
126
|
-
if provider == "pi_tui" && matches!(window, "pi" | "node") {
|
|
127
|
-
return true;
|
|
128
|
-
}
|
|
129
|
-
parse_provider(provider).is_some_and(|parsed| {
|
|
130
|
-
command_name(parsed) == window
|
|
131
|
-
|| crate::layout::worker_window_helpers::provider_window_name(parsed) == window
|
|
132
|
-
})
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
fn window_name_reconciles(
|
|
136
|
-
agent_id: &str,
|
|
137
|
-
agent_state: &Value,
|
|
138
|
-
windows: &[crate::transport::WindowName],
|
|
139
|
-
) -> bool {
|
|
140
|
-
let explicit = explicit_window_name(agent_state);
|
|
141
|
-
let provider = agent_state
|
|
142
|
-
.get("provider")
|
|
143
|
-
.and_then(Value::as_str)
|
|
144
|
-
.unwrap_or("");
|
|
145
|
-
windows.iter().any(|window| {
|
|
146
|
-
let name = window.as_str();
|
|
147
|
-
explicit.is_some_and(|expected| expected == name)
|
|
148
|
-
|| is_public_window_name(provider, name)
|
|
149
|
-
|| name == agent_id
|
|
150
|
-
})
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
/// A native CLI owns its window title. Seat presence is the recorded pane id
|
|
154
|
-
/// on this transport; display names are only a fallback.
|
|
155
|
-
fn worker_window_is_missing(
|
|
156
|
-
agent_id: &str,
|
|
157
|
-
agent_state: &Value,
|
|
158
|
-
windows: &[crate::transport::WindowName],
|
|
159
|
-
panes: &[crate::transport::PaneInfo],
|
|
160
|
-
backend: &dyn Transport,
|
|
161
|
-
) -> bool {
|
|
162
|
-
if let Some(pane_id) = recorded_mux_pane(agent_state) {
|
|
163
|
-
if panes.iter().any(|pane| pane.pane_id.as_str() == pane_id) {
|
|
164
|
-
return false;
|
|
165
|
-
}
|
|
166
|
-
if !panes.is_empty() {
|
|
167
|
-
return true;
|
|
168
|
-
}
|
|
169
|
-
match backend.has_pane(&crate::transport::PaneId::new(pane_id)) {
|
|
170
|
-
Ok(Some(true)) => return false,
|
|
171
|
-
Ok(Some(false)) => return true,
|
|
172
|
-
_ => {}
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
!window_name_reconciles(agent_id, agent_state, windows)
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
pub(crate) fn diagnose_runtime(state: &Value, backend: &dyn Transport) -> (Value, Value) {
|
|
179
|
-
diagnose_runtime_with_workspace(None, state, backend)
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
fn diagnose_runtime_with_workspace(
|
|
183
|
-
workspace: Option<&std::path::Path>,
|
|
184
|
-
state: &Value,
|
|
185
|
-
backend: &dyn Transport,
|
|
186
|
-
) -> (Value, Value) {
|
|
187
|
-
let mut issues = Vec::new();
|
|
188
|
-
let mut repairs = Vec::new();
|
|
189
|
-
|
|
190
|
-
if state
|
|
191
|
-
.get("leader_receiver")
|
|
192
|
-
.is_some_and(receiver_has_empty_attached_pane)
|
|
193
|
-
{
|
|
194
|
-
issues.push(json!(LEADER_NOT_ATTACHED));
|
|
195
|
-
repairs.push(recovery_hint(
|
|
196
|
-
state
|
|
197
|
-
.get("session_name")
|
|
198
|
-
.and_then(Value::as_str)
|
|
199
|
-
.unwrap_or("unknown"),
|
|
200
|
-
LEADER_NOT_ATTACHED,
|
|
201
|
-
LEADER_NOT_ATTACHED_REPAIR,
|
|
202
|
-
));
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
// Probe the session before any topology enumeration. A missing session is
|
|
206
|
-
// terminal for all window/pane/socket probes; repeating those tmux calls
|
|
207
|
-
// only pays the dead-socket timeout again on every layer. The persisted
|
|
208
|
-
// endpoint/socket split is state-only, so preserve that fact before the
|
|
209
|
-
// short-circuit without probing either dead endpoint.
|
|
210
|
-
let persisted_socket_conflict = crate::topology::endpoint_socket_conflict(state);
|
|
211
|
-
let session_unavailable = state
|
|
212
|
-
.get("session_name")
|
|
213
|
-
.and_then(Value::as_str)
|
|
214
|
-
.filter(|s| !s.is_empty())
|
|
215
|
-
.is_some_and(|session_name| {
|
|
216
|
-
match backend.has_session(&crate::transport::SessionName::new(
|
|
217
|
-
session_name.to_string(),
|
|
218
|
-
)) {
|
|
219
|
-
Ok(true) => false,
|
|
220
|
-
Ok(false) => {
|
|
221
|
-
issues.push(json!("tmux_session_missing"));
|
|
222
|
-
repairs.push(recovery_hint(
|
|
223
|
-
session_name,
|
|
224
|
-
"tmux_session_missing",
|
|
225
|
-
"team-agent restart",
|
|
226
|
-
));
|
|
227
|
-
true
|
|
228
|
-
}
|
|
229
|
-
Err(error) => {
|
|
230
|
-
// 0.5.39 Slice 1 (tmux-server-death-locate §11.1 B):
|
|
231
|
-
// when the transport error stderr matches "server exited
|
|
232
|
-
// unexpectedly", the physical layer that disappeared is
|
|
233
|
-
// the tmux server itself — not just this team's session.
|
|
234
|
-
let error_str = error.to_string();
|
|
235
|
-
let issue_id = classify_tmux_server_error(&error_str);
|
|
236
|
-
issues.push(json!(issue_id));
|
|
237
|
-
let mut hint = recovery_hint(session_name, issue_id, "team-agent doctor");
|
|
238
|
-
if let Some(obj) = hint.as_object_mut() {
|
|
239
|
-
obj.insert("reason".to_string(), Value::String(error_str));
|
|
240
|
-
}
|
|
241
|
-
repairs.push(hint);
|
|
242
|
-
true
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
});
|
|
246
|
-
|
|
247
|
-
if session_unavailable {
|
|
248
|
-
if let Some(issue) = persisted_socket_conflict {
|
|
249
|
-
if let Some(id) = crate::topology::issue_id(&issue) {
|
|
250
|
-
repairs.push(topology_repair_hint(id));
|
|
251
|
-
}
|
|
252
|
-
issues.push(issue);
|
|
253
|
-
}
|
|
254
|
-
// Preserve distinct worker failures even when the shared session probe
|
|
255
|
-
// short-circuits pane enumeration. This keeps scope evidence without
|
|
256
|
-
// issuing another transport probe per worker.
|
|
257
|
-
if let Some(agents) = state.get("agents").and_then(Value::as_object) {
|
|
258
|
-
for agent_id in agents.keys() {
|
|
259
|
-
let issue = format!("worker_window_missing:{agent_id}");
|
|
260
|
-
issues.push(json!(issue.clone()));
|
|
261
|
-
repairs.push(json!({
|
|
262
|
-
"issue": issue,
|
|
263
|
-
"action": "team-agent restart",
|
|
264
|
-
}));
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
return (Value::Array(issues), Value::Array(repairs));
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
for issue in crate::topology::diagnose_topology_issues(state, backend) {
|
|
271
|
-
if let Some(id) = crate::topology::issue_id(&issue) {
|
|
272
|
-
repairs.push(topology_repair_hint(id));
|
|
273
|
-
}
|
|
274
|
-
issues.push(issue);
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
if leader_receiver_attached(state) {
|
|
278
|
-
// 0.4.x (CR R2 P0): leader provider health reconciliation. The
|
|
279
|
-
// leader_receiver may be marked `attached` (pane addressable) but the
|
|
280
|
-
// provider process has exited — pane fell back to shell with the exit
|
|
281
|
-
// marker. Distinguish `leader_provider_exited` from `attached` so
|
|
282
|
-
// status/diagnose surfaces the real state.
|
|
283
|
-
if let Some((pane_id, provider_label)) = leader_pane_and_provider(state) {
|
|
284
|
-
let health = crate::leader::leader_provider_health(
|
|
285
|
-
backend,
|
|
286
|
-
&crate::transport::PaneId::new(pane_id),
|
|
287
|
-
&provider_label,
|
|
288
|
-
);
|
|
289
|
-
match health {
|
|
290
|
-
crate::leader::LeaderProviderHealth::ProviderExited => {
|
|
291
|
-
issues.push(json!("leader_provider_exited"));
|
|
292
|
-
repairs.push(json!({
|
|
293
|
-
"issue": "leader_provider_exited",
|
|
294
|
-
"action_required": true,
|
|
295
|
-
"advisory": true,
|
|
296
|
-
"broken_class": "leader_provider_exited",
|
|
297
|
-
"hint_action": "team-agent restart",
|
|
298
|
-
"dedupe_key": "leader_provider_exited",
|
|
299
|
-
"action": format!(
|
|
300
|
-
"leader pane fell back to shell — provider `{provider_label}` exited; \
|
|
301
|
-
relaunch with `team-agent {provider_label}` to restart the provider"
|
|
302
|
-
),
|
|
303
|
-
}));
|
|
304
|
-
}
|
|
305
|
-
crate::leader::LeaderProviderHealth::Unreachable => {
|
|
306
|
-
issues.push(json!("leader_provider_unreachable"));
|
|
307
|
-
repairs.push(recovery_hint(
|
|
308
|
-
state
|
|
309
|
-
.get("session_name")
|
|
310
|
-
.and_then(Value::as_str)
|
|
311
|
-
.unwrap_or("unknown"),
|
|
312
|
-
"leader_provider_unreachable",
|
|
313
|
-
"leader pane provider is unreachable; restart the provider in the bound pane",
|
|
314
|
-
));
|
|
315
|
-
}
|
|
316
|
-
crate::leader::LeaderProviderHealth::Alive => {}
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
if let Some(session_name) = state
|
|
322
|
-
.get("session_name")
|
|
323
|
-
.and_then(Value::as_str)
|
|
324
|
-
.filter(|s| !s.is_empty())
|
|
325
|
-
{
|
|
326
|
-
if let Ok(windows) = backend.list_windows(&crate::transport::SessionName::new(
|
|
327
|
-
session_name.to_string(),
|
|
328
|
-
)) {
|
|
329
|
-
let panes = backend.list_targets().unwrap_or_default();
|
|
330
|
-
if let Some(agents) = state.get("agents").and_then(Value::as_object) {
|
|
331
|
-
for (agent_id, agent_state) in agents {
|
|
332
|
-
let provider = agent_state
|
|
333
|
-
.get("provider")
|
|
334
|
-
.and_then(Value::as_str)
|
|
335
|
-
.and_then(parse_provider)
|
|
336
|
-
.unwrap_or(crate::provider::Provider::Codex);
|
|
337
|
-
let rollout_path = agent_state
|
|
338
|
-
.get("rollout_path")
|
|
339
|
-
.and_then(Value::as_str)
|
|
340
|
-
.filter(|path| !path.is_empty())
|
|
341
|
-
.map(crate::provider::RolloutPath::new);
|
|
342
|
-
let agent_identity = crate::model::ids::AgentId::new(agent_id.clone());
|
|
343
|
-
let identity_probe = workspace
|
|
344
|
-
.map(|workspace| {
|
|
345
|
-
crate::lifecycle::restart::session_identity_probe_for_agent_with_fork_ancestry(
|
|
346
|
-
workspace,
|
|
347
|
-
state,
|
|
348
|
-
&agent_identity,
|
|
349
|
-
agent_state,
|
|
350
|
-
provider,
|
|
351
|
-
rollout_path.as_ref(),
|
|
352
|
-
)
|
|
353
|
-
})
|
|
354
|
-
.unwrap_or_else(|| {
|
|
355
|
-
crate::lifecycle::restart::session_identity_probe_for_agent(
|
|
356
|
-
&agent_identity,
|
|
357
|
-
provider,
|
|
358
|
-
rollout_path.as_ref(),
|
|
359
|
-
)
|
|
360
|
-
});
|
|
361
|
-
if identity_probe.identity_ok == Some(false) {
|
|
362
|
-
let issue = format!("session_identity_mismatch:{agent_id}");
|
|
363
|
-
issues.push(json!(issue));
|
|
364
|
-
repairs.push(json!({
|
|
365
|
-
"issue": format!("session_identity_mismatch:{agent_id}"),
|
|
366
|
-
"action": format!(
|
|
367
|
-
"run `team-agent restart --allow-fresh` to discard the poisoned session tuple for `{agent_id}`"
|
|
368
|
-
),
|
|
369
|
-
"expected_agent_id": agent_id,
|
|
370
|
-
"embedded_agent_id": identity_probe.embedded_agent_id,
|
|
371
|
-
"rollout_path": identity_probe
|
|
372
|
-
.rollout_path
|
|
373
|
-
.map(|path| path.to_string_lossy().to_string()),
|
|
374
|
-
}));
|
|
375
|
-
}
|
|
376
|
-
if worker_window_is_missing(agent_id, agent_state, &windows, &panes, backend) {
|
|
377
|
-
issues.push(json!(format!("worker_window_missing:{agent_id}")));
|
|
378
|
-
}
|
|
379
|
-
if agent_state
|
|
380
|
-
.get("approval")
|
|
381
|
-
.or_else(|| agent_state.get("approval_status"))
|
|
382
|
-
.and_then(Value::as_str)
|
|
383
|
-
.is_some_and(|s| s == "pending" || s == "awaiting_trust_prompt")
|
|
384
|
-
{
|
|
385
|
-
issues.push(json!(format!("worker_approval_pending:{agent_id}")));
|
|
386
|
-
}
|
|
387
|
-
}
|
|
388
|
-
}
|
|
389
|
-
}
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
(Value::Array(issues), Value::Array(repairs))
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
pub(crate) fn diagnose_runtime_for_workspace(
|
|
396
|
-
workspace: &std::path::Path,
|
|
397
|
-
state: &Value,
|
|
398
|
-
backend: &dyn Transport,
|
|
399
|
-
selected_team_key: Option<&str>,
|
|
400
|
-
coordinator_health: &crate::coordinator::HealthReport,
|
|
401
|
-
) -> (Value, Value) {
|
|
402
|
-
let (mut issues, mut repairs) =
|
|
403
|
-
diagnose_runtime_with_workspace(Some(workspace), state, backend);
|
|
404
|
-
append_live_leader_workspace_mismatch_issue(
|
|
405
|
-
workspace,
|
|
406
|
-
state,
|
|
407
|
-
backend,
|
|
408
|
-
&mut issues,
|
|
409
|
-
&mut repairs,
|
|
410
|
-
);
|
|
411
|
-
append_registry_channel_unbound_issue(
|
|
412
|
-
workspace,
|
|
413
|
-
state,
|
|
414
|
-
selected_team_key,
|
|
415
|
-
&mut issues,
|
|
416
|
-
&mut repairs,
|
|
417
|
-
);
|
|
418
|
-
append_legacy_snapshot_issue(workspace, state, &mut issues);
|
|
419
|
-
append_coordinator_health_issue(
|
|
420
|
-
workspace,
|
|
421
|
-
state,
|
|
422
|
-
coordinator_health,
|
|
423
|
-
&mut issues,
|
|
424
|
-
&mut repairs,
|
|
425
|
-
);
|
|
426
|
-
append_runtime_bindings_stale_after_boot_issue(workspace, state, &mut issues, &mut repairs);
|
|
427
|
-
(issues, repairs)
|
|
428
|
-
}
|
|
429
|
-
|
|
430
|
-
const TEAM_SPEC_OR_RUNTIME_MISSING: &str = "team_spec_or_runtime_missing";
|
|
431
|
-
const TEAM_SPEC_OR_RUNTIME_MISSING_REPAIR: &str = concat!(
|
|
432
|
-
"no team spec or runtime was found in this workspace. ",
|
|
433
|
-
"Run `team-agent quick-start <workspace>` for first launch, ",
|
|
434
|
-
"or restart from a workspace that already contains `.team`.",
|
|
435
|
-
);
|
|
436
|
-
|
|
437
|
-
pub(crate) fn workspace_has_existing_team_runtime(
|
|
438
|
-
workspace: &std::path::Path,
|
|
439
|
-
team_key: &str,
|
|
440
|
-
) -> bool {
|
|
441
|
-
// A source TEAM.md/team.spec.yaml is install/configuration context, not a
|
|
442
|
-
// live runtime. Only persisted runtime state/specs make topology checks
|
|
443
|
-
// applicable; an empty workspace therefore remains a healthy no-runtime
|
|
444
|
-
// report instead of a fabricated missing-session issue.
|
|
445
|
-
if let Ok(state) = crate::state::persist::load_runtime_state_without_migrations(workspace) {
|
|
446
|
-
// The workspace's top-level view may describe a stopped sibling.
|
|
447
|
-
// Preserve the top-level fallback for legacy single-team state only
|
|
448
|
-
// when there is no selected team entry.
|
|
449
|
-
let team_state = state
|
|
450
|
-
.get("teams")
|
|
451
|
-
.and_then(|teams| teams.get(team_key))
|
|
452
|
-
.unwrap_or(&state);
|
|
453
|
-
let terminal = team_state
|
|
454
|
-
.get("status")
|
|
455
|
-
.and_then(Value::as_str)
|
|
456
|
-
.is_some_and(|status| {
|
|
457
|
-
matches!(status, "stopped" | "shutdown" | "archived" | "terminal")
|
|
458
|
-
});
|
|
459
|
-
if terminal {
|
|
460
|
-
return false;
|
|
461
|
-
}
|
|
462
|
-
}
|
|
463
|
-
crate::model::paths::runtime_spec_path(workspace, team_key).is_file()
|
|
464
|
-
|| crate::state::persist::runtime_state_path(workspace).is_file()
|
|
465
|
-
}
|
|
466
|
-
|
|
467
|
-
pub(crate) fn missing_team_runtime_issues_and_repairs(team_key: &str) -> (Value, Value) {
|
|
468
|
-
let mut issues = json!([]);
|
|
469
|
-
let mut repairs = json!([]);
|
|
470
|
-
push_issue_repair(
|
|
471
|
-
&mut issues,
|
|
472
|
-
&mut repairs,
|
|
473
|
-
team_key,
|
|
474
|
-
TEAM_SPEC_OR_RUNTIME_MISSING,
|
|
475
|
-
TEAM_SPEC_OR_RUNTIME_MISSING_REPAIR,
|
|
476
|
-
);
|
|
477
|
-
(issues, repairs)
|
|
478
|
-
}
|
|
479
|
-
|
|
480
|
-
fn push_issue_repair(
|
|
481
|
-
issues: &mut Value,
|
|
482
|
-
repairs: &mut Value,
|
|
483
|
-
team: &str,
|
|
484
|
-
issue_id: &str,
|
|
485
|
-
repair: &str,
|
|
486
|
-
) {
|
|
487
|
-
if let Some(items) = issues.as_array_mut() {
|
|
488
|
-
if !items.iter().any(|item| {
|
|
489
|
-
item.as_str() == Some(issue_id)
|
|
490
|
-
|| item.get("id").and_then(Value::as_str) == Some(issue_id)
|
|
491
|
-
}) {
|
|
492
|
-
items.push(json!(issue_id));
|
|
493
|
-
}
|
|
494
|
-
}
|
|
495
|
-
if let Some(items) = repairs.as_array_mut() {
|
|
496
|
-
items.push(recovery_hint(team, issue_id, repair));
|
|
497
|
-
}
|
|
498
|
-
}
|
|
499
|
-
|
|
500
|
-
fn append_registry_channel_unbound_issue(
|
|
501
|
-
workspace: &std::path::Path,
|
|
502
|
-
state: &Value,
|
|
503
|
-
selected_team_key: Option<&str>,
|
|
504
|
-
issues: &mut Value,
|
|
505
|
-
repairs: &mut Value,
|
|
506
|
-
) {
|
|
507
|
-
let team_key = selected_team_key
|
|
508
|
-
.filter(|team| !team.is_empty())
|
|
509
|
-
.map(str::to_string)
|
|
510
|
-
.unwrap_or_else(|| crate::state::projection::team_state_key(state));
|
|
511
|
-
if team_key.is_empty() {
|
|
512
|
-
return;
|
|
513
|
-
}
|
|
514
|
-
// RuntimeOnly diagnose synthesizes team_key=current from empty default
|
|
515
|
-
// state. That is not an existing unbound team; do not emit claim.
|
|
516
|
-
if !workspace_has_existing_team_runtime(workspace, &team_key) {
|
|
517
|
-
push_issue_repair(
|
|
518
|
-
issues,
|
|
519
|
-
repairs,
|
|
520
|
-
&team_key,
|
|
521
|
-
TEAM_SPEC_OR_RUNTIME_MISSING,
|
|
522
|
-
TEAM_SPEC_OR_RUNTIME_MISSING_REPAIR,
|
|
523
|
-
);
|
|
524
|
-
return;
|
|
525
|
-
}
|
|
526
|
-
let class = crate::lifecycle::launch::classify_leader_binding(workspace, &team_key);
|
|
527
|
-
if class == crate::lifecycle::launch::LeaderBindingClass::Attached {
|
|
528
|
-
return;
|
|
529
|
-
}
|
|
530
|
-
let (issue_id, repair) = existing_team_binding_issue(state, &team_key, class);
|
|
531
|
-
push_issue_repair(
|
|
532
|
-
issues,
|
|
533
|
-
repairs,
|
|
534
|
-
state
|
|
535
|
-
.get("session_name")
|
|
536
|
-
.and_then(Value::as_str)
|
|
537
|
-
.unwrap_or(team_key.as_str()),
|
|
538
|
-
issue_id,
|
|
539
|
-
repair,
|
|
540
|
-
);
|
|
541
|
-
}
|
|
542
|
-
|
|
543
|
-
const LEADER_NOT_ATTACHED: &str = "leader_not_attached";
|
|
544
|
-
const LEADER_NOT_ATTACHED_REPAIR: &str =
|
|
545
|
-
"run from the intended leader tmux pane; do not run claim-leader";
|
|
546
|
-
|
|
547
|
-
fn receiver_has_empty_attached_pane(receiver: &Value) -> bool {
|
|
548
|
-
receiver.get("status").and_then(Value::as_str) == Some("attached")
|
|
549
|
-
&& receiver
|
|
550
|
-
.get("pane_id")
|
|
551
|
-
.and_then(Value::as_str)
|
|
552
|
-
.is_none_or(|pane| pane.is_empty())
|
|
553
|
-
}
|
|
554
|
-
|
|
555
|
-
fn selected_or_top_receiver<'a>(state: &'a Value, team_key: &str) -> Option<&'a Value> {
|
|
556
|
-
crate::lifecycle::launch::selected_team_leader_receiver(state, team_key)
|
|
557
|
-
.or_else(|| state.get("leader_receiver"))
|
|
558
|
-
}
|
|
559
|
-
|
|
560
|
-
fn team_has_initialized_runtime(state: &Value, team_key: &str) -> bool {
|
|
561
|
-
let team = state
|
|
562
|
-
.get("teams")
|
|
563
|
-
.and_then(Value::as_object)
|
|
564
|
-
.and_then(|teams| teams.get(team_key))
|
|
565
|
-
.unwrap_or(state);
|
|
566
|
-
let has_agents = team
|
|
567
|
-
.get("agents")
|
|
568
|
-
.and_then(Value::as_object)
|
|
569
|
-
.is_some_and(|agents| !agents.is_empty())
|
|
570
|
-
|| state
|
|
571
|
-
.get("agents")
|
|
572
|
-
.and_then(Value::as_object)
|
|
573
|
-
.is_some_and(|agents| !agents.is_empty());
|
|
574
|
-
let has_owner = team.get("team_owner").is_some() || state.get("team_owner").is_some();
|
|
575
|
-
let has_receiver = selected_or_top_receiver(state, team_key).is_some();
|
|
576
|
-
has_agents || has_owner || has_receiver
|
|
577
|
-
}
|
|
578
|
-
|
|
579
|
-
fn existing_team_binding_issue(
|
|
580
|
-
state: &Value,
|
|
581
|
-
team_key: &str,
|
|
582
|
-
class: crate::lifecycle::launch::LeaderBindingClass,
|
|
583
|
-
) -> (&'static str, &'static str) {
|
|
584
|
-
if selected_or_top_receiver(state, team_key).is_some_and(receiver_has_empty_attached_pane)
|
|
585
|
-
|| (class == crate::lifecycle::launch::LeaderBindingClass::Unbound
|
|
586
|
-
&& team_has_initialized_runtime(state, team_key))
|
|
587
|
-
{
|
|
588
|
-
return (LEADER_NOT_ATTACHED, LEADER_NOT_ATTACHED_REPAIR);
|
|
589
|
-
}
|
|
590
|
-
(class.issue_id(), class.repair())
|
|
591
|
-
}
|
|
592
|
-
|
|
593
|
-
fn append_live_leader_workspace_mismatch_issue(
|
|
594
|
-
workspace: &std::path::Path,
|
|
595
|
-
state: &Value,
|
|
596
|
-
backend: &dyn Transport,
|
|
597
|
-
issues: &mut Value,
|
|
598
|
-
repairs: &mut Value,
|
|
599
|
-
) {
|
|
600
|
-
let Some((issue, repair)) = live_leader_workspace_mismatch(workspace, state, backend) else {
|
|
601
|
-
return;
|
|
602
|
-
};
|
|
603
|
-
if let Some(items) = issues.as_array_mut() {
|
|
604
|
-
items.push(issue);
|
|
605
|
-
}
|
|
606
|
-
if let Some(items) = repairs.as_array_mut() {
|
|
607
|
-
items.push(repair);
|
|
608
|
-
}
|
|
609
|
-
}
|
|
610
|
-
|
|
611
|
-
fn live_leader_workspace_mismatch(
|
|
612
|
-
workspace: &std::path::Path,
|
|
613
|
-
state: &Value,
|
|
614
|
-
backend: &dyn Transport,
|
|
615
|
-
) -> Option<(Value, Value)> {
|
|
616
|
-
let receiver = state.get("leader_receiver")?;
|
|
617
|
-
let facts = match crate::messaging::resolve_live_leader_channel(workspace, receiver, backend) {
|
|
618
|
-
crate::messaging::LeaderChannelResolution::Unbound(
|
|
619
|
-
crate::messaging::LeaderChannelUnbound::PaneWorkspaceMismatch(facts),
|
|
620
|
-
) => facts,
|
|
621
|
-
_ => return None,
|
|
622
|
-
};
|
|
623
|
-
let team = state
|
|
624
|
-
.get("team_key")
|
|
625
|
-
.and_then(Value::as_str)
|
|
626
|
-
.filter(|team| !team.is_empty())
|
|
627
|
-
.unwrap_or("current");
|
|
628
|
-
let provider = receiver
|
|
629
|
-
.get("provider")
|
|
630
|
-
.and_then(Value::as_str)
|
|
631
|
-
.filter(|provider| !provider.is_empty());
|
|
632
|
-
let refusal =
|
|
633
|
-
PaneAuthorityRefusal::new(PaneAuthorityRefusalFacts::PaneWorkspaceMismatch(facts));
|
|
634
|
-
let PaneAuthorityRefusalFacts::PaneWorkspaceMismatch(facts) = &refusal.facts else {
|
|
635
|
-
return None;
|
|
636
|
-
};
|
|
637
|
-
let mut fields = serde_json::Map::new();
|
|
638
|
-
fields.insert(
|
|
639
|
-
REASON_FIELD.to_string(),
|
|
640
|
-
Value::String(refusal.reason().as_str().to_string()),
|
|
641
|
-
);
|
|
642
|
-
fields.insert(
|
|
643
|
-
PaneAuthorityRefusalField::RequestedWorkspace
|
|
644
|
-
.as_str()
|
|
645
|
-
.to_string(),
|
|
646
|
-
Value::String(facts.requested_workspace.to_string_lossy().into_owned()),
|
|
647
|
-
);
|
|
648
|
-
fields.insert(
|
|
649
|
-
PaneAuthorityRefusalField::ObservedPaneId
|
|
650
|
-
.as_str()
|
|
651
|
-
.to_string(),
|
|
652
|
-
Value::String(facts.observed_pane_id.clone()),
|
|
653
|
-
);
|
|
654
|
-
fields.insert(
|
|
655
|
-
PaneAuthorityRefusalField::ObservedPaneWorkspace
|
|
656
|
-
.as_str()
|
|
657
|
-
.to_string(),
|
|
658
|
-
Value::String(facts.observed_pane_workspace.to_string_lossy().into_owned()),
|
|
659
|
-
);
|
|
660
|
-
fields.insert(
|
|
661
|
-
PaneAuthorityRefusalField::Endpoint.as_str().to_string(),
|
|
662
|
-
Value::String(facts.endpoint.clone()),
|
|
663
|
-
);
|
|
664
|
-
let mut issue = Value::Object(fields.clone());
|
|
665
|
-
if let Some(object) = issue.as_object_mut() {
|
|
666
|
-
object.insert(
|
|
667
|
-
"id".to_string(),
|
|
668
|
-
Value::String("leader_channel_workspace_mismatch".to_string()),
|
|
669
|
-
);
|
|
670
|
-
}
|
|
671
|
-
let mut repair = Value::Object(fields);
|
|
672
|
-
if let Some(object) = repair.as_object_mut() {
|
|
673
|
-
object.insert(
|
|
674
|
-
"issue".to_string(),
|
|
675
|
-
Value::String("leader_channel_workspace_mismatch".to_string()),
|
|
676
|
-
);
|
|
677
|
-
object.insert(
|
|
678
|
-
ACTION_REQUIRED_FIELD.to_string(),
|
|
679
|
-
Value::Bool(refusal.recovery.action_required),
|
|
680
|
-
);
|
|
681
|
-
object.insert("advisory".to_string(), Value::Bool(true));
|
|
682
|
-
object.insert(
|
|
683
|
-
"broken_class".to_string(),
|
|
684
|
-
Value::String("leader_channel_workspace_mismatch".to_string()),
|
|
685
|
-
);
|
|
686
|
-
object.insert(
|
|
687
|
-
HINT_ACTION_FIELD.to_string(),
|
|
688
|
-
Value::String(
|
|
689
|
-
match refusal.recovery.hint_action {
|
|
690
|
-
PaneAuthorityRecoveryHint::AttachLeader => {
|
|
691
|
-
"open a matching workspace pane bound for this workspace"
|
|
692
|
-
}
|
|
693
|
-
}
|
|
694
|
-
.to_string(),
|
|
695
|
-
),
|
|
696
|
-
);
|
|
697
|
-
object.insert(
|
|
698
|
-
"dedupe_key".to_string(),
|
|
699
|
-
Value::String(format!("{team}:leader_channel_workspace_mismatch")),
|
|
700
|
-
);
|
|
701
|
-
object.insert(
|
|
702
|
-
ACTION_FIELD.to_string(),
|
|
703
|
-
Value::String(match (refusal.recovery.action, provider) {
|
|
704
|
-
(
|
|
705
|
-
PaneAuthorityRecoveryAction::OpenTerminalOutsideCurrentTmuxPaneOrAttachFromMatchingPane,
|
|
706
|
-
Some(provider),
|
|
707
|
-
) => format!(
|
|
708
|
-
"open a matching workspace pane already bound as {provider}"
|
|
709
|
-
),
|
|
710
|
-
(
|
|
711
|
-
PaneAuthorityRecoveryAction::OpenTerminalOutsideCurrentTmuxPaneOrAttachFromMatchingPane,
|
|
712
|
-
None,
|
|
713
|
-
) => {
|
|
714
|
-
"open a matching workspace pane with the recorded leader provider; do not default claude"
|
|
715
|
-
.to_string()
|
|
716
|
-
}
|
|
717
|
-
}),
|
|
718
|
-
);
|
|
719
|
-
}
|
|
720
|
-
Some((issue, repair))
|
|
721
|
-
}
|
|
722
|
-
|
|
723
|
-
pub(crate) fn append_registry_channel_unbound_to_report(
|
|
724
|
-
workspace: &std::path::Path,
|
|
725
|
-
team: Option<&str>,
|
|
726
|
-
report: &mut Value,
|
|
727
|
-
) {
|
|
728
|
-
let team_key = team
|
|
729
|
-
.filter(|team| !team.is_empty())
|
|
730
|
-
.map(str::to_string)
|
|
731
|
-
.or_else(|| {
|
|
732
|
-
crate::state::persist::load_runtime_state(workspace)
|
|
733
|
-
.ok()
|
|
734
|
-
.map(|state| crate::state::projection::team_state_key(&state))
|
|
735
|
-
})
|
|
736
|
-
.unwrap_or_default();
|
|
737
|
-
if team_key.is_empty() {
|
|
738
|
-
return;
|
|
739
|
-
}
|
|
740
|
-
let Some(object) = report.as_object_mut() else {
|
|
741
|
-
return;
|
|
742
|
-
};
|
|
743
|
-
let mut issues = object
|
|
744
|
-
.get("issues")
|
|
745
|
-
.and_then(Value::as_array)
|
|
746
|
-
.cloned()
|
|
747
|
-
.unwrap_or_default();
|
|
748
|
-
let mut repairs = object
|
|
749
|
-
.get("suggested_repairs")
|
|
750
|
-
.and_then(Value::as_array)
|
|
751
|
-
.cloned()
|
|
752
|
-
.unwrap_or_default();
|
|
753
|
-
if !workspace_has_existing_team_runtime(workspace, &team_key) {
|
|
754
|
-
let mut issues_value = Value::Array(issues);
|
|
755
|
-
let mut repairs_value = Value::Array(repairs);
|
|
756
|
-
push_issue_repair(
|
|
757
|
-
&mut issues_value,
|
|
758
|
-
&mut repairs_value,
|
|
759
|
-
&team_key,
|
|
760
|
-
TEAM_SPEC_OR_RUNTIME_MISSING,
|
|
761
|
-
TEAM_SPEC_OR_RUNTIME_MISSING_REPAIR,
|
|
762
|
-
);
|
|
763
|
-
object.insert("issues".to_string(), issues_value);
|
|
764
|
-
object.insert("suggested_repairs".to_string(), repairs_value);
|
|
765
|
-
object.insert("ok".to_string(), Value::Bool(false));
|
|
766
|
-
return;
|
|
767
|
-
}
|
|
768
|
-
let class = crate::lifecycle::launch::classify_leader_binding(workspace, &team_key);
|
|
769
|
-
if class == crate::lifecycle::launch::LeaderBindingClass::Attached {
|
|
770
|
-
return;
|
|
771
|
-
}
|
|
772
|
-
let state = crate::state::persist::load_runtime_state(workspace).unwrap_or(json!({}));
|
|
773
|
-
let (issue_id, repair) = existing_team_binding_issue(&state, &team_key, class);
|
|
774
|
-
if !issues.iter().any(|item| item.as_str() == Some(issue_id)) {
|
|
775
|
-
issues.push(json!(issue_id));
|
|
776
|
-
}
|
|
777
|
-
repairs.push(recovery_hint(&team_key, issue_id, repair));
|
|
778
|
-
object.insert("issues".to_string(), Value::Array(issues));
|
|
779
|
-
object.insert("suggested_repairs".to_string(), Value::Array(repairs));
|
|
780
|
-
let is_healthy_unattached_host = class == crate::lifecycle::launch::LeaderBindingClass::Unbound
|
|
781
|
-
&& object.get("ok").and_then(Value::as_bool) == Some(true)
|
|
782
|
-
&& object
|
|
783
|
-
.get("profile_smoke")
|
|
784
|
-
.and_then(|profile| profile.get("checks"))
|
|
785
|
-
.and_then(Value::as_array)
|
|
786
|
-
.is_some_and(|checks| !checks.is_empty());
|
|
787
|
-
if !is_healthy_unattached_host {
|
|
788
|
-
object.insert("ok".to_string(), Value::Bool(false));
|
|
789
|
-
}
|
|
790
|
-
}
|
|
791
|
-
|
|
792
|
-
pub(crate) fn append_selected_live_leader_workspace_mismatch(
|
|
793
|
-
workspace: &std::path::Path,
|
|
794
|
-
team: Option<&str>,
|
|
795
|
-
report: &mut Value,
|
|
796
|
-
) {
|
|
797
|
-
let Some((issue, repair)) = selected_live_leader_workspace_mismatch(workspace, team) else {
|
|
798
|
-
return;
|
|
799
|
-
};
|
|
800
|
-
let Some(object) = report.as_object_mut() else {
|
|
801
|
-
return;
|
|
802
|
-
};
|
|
803
|
-
object.insert("issues".to_string(), Value::Array(vec![issue]));
|
|
804
|
-
object.insert("suggested_repairs".to_string(), Value::Array(vec![repair]));
|
|
805
|
-
object.insert("ok".to_string(), Value::Bool(false));
|
|
806
|
-
if object.get("error").is_none_or(Value::is_null) {
|
|
807
|
-
object.insert(
|
|
808
|
-
"error".to_string(),
|
|
809
|
-
Value::String("PaneWorkspaceMismatch".to_string()),
|
|
810
|
-
);
|
|
811
|
-
}
|
|
812
|
-
}
|
|
813
|
-
|
|
814
|
-
fn selected_live_leader_workspace_mismatch(
|
|
815
|
-
workspace: &std::path::Path,
|
|
816
|
-
team: Option<&str>,
|
|
817
|
-
) -> Option<(Value, Value)> {
|
|
818
|
-
let selected = crate::state::selector::resolve_active_team_readonly(
|
|
819
|
-
workspace,
|
|
820
|
-
team,
|
|
821
|
-
crate::state::selector::SelectorMode::RuntimeOnly,
|
|
822
|
-
)
|
|
823
|
-
.ok()?;
|
|
824
|
-
let backend: Box<dyn crate::transport::Transport> =
|
|
825
|
-
match crate::transport_factory::resolve_read_only_transport(
|
|
826
|
-
&selected.run_workspace,
|
|
827
|
-
Some(&selected.state),
|
|
828
|
-
crate::transport_factory::TransportPurpose::Diagnose,
|
|
829
|
-
) {
|
|
830
|
-
Ok(resolved) => resolved.backend,
|
|
831
|
-
Err(_) => Box::new(crate::tmux_backend::TmuxBackend::for_workspace(
|
|
832
|
-
&selected.run_workspace,
|
|
833
|
-
)),
|
|
834
|
-
};
|
|
835
|
-
live_leader_workspace_mismatch(&selected.run_workspace, &selected.state, backend.as_ref())
|
|
836
|
-
}
|
|
837
|
-
|
|
838
|
-
/// 0.5.41 Slice 1 (fault-invisibility-locate.md §5/§6.2): read the
|
|
839
|
-
/// coordinator heartbeat sidecar for the last-observed host boot
|
|
840
|
-
/// identity and compare it against the current host boot. If they
|
|
841
|
-
/// differ, the pane/pid/session bindings in state predate the current
|
|
842
|
-
/// boot — surface `runtime_bindings_stale_after_boot` with a reused
|
|
843
|
-
/// `team-agent restart` hint. Read-only: no mutation. When the
|
|
844
|
-
/// heartbeat is missing OR the current host boot cannot be probed,
|
|
845
|
-
/// stay silent (per §8 risk note — do not guess).
|
|
846
|
-
fn append_runtime_bindings_stale_after_boot_issue(
|
|
847
|
-
workspace: &std::path::Path,
|
|
848
|
-
state: &Value,
|
|
849
|
-
issues: &mut Value,
|
|
850
|
-
repairs: &mut Value,
|
|
851
|
-
) {
|
|
852
|
-
let workspace_path = crate::coordinator::WorkspacePath::new(workspace.to_path_buf());
|
|
853
|
-
let Some(heartbeat) = crate::coordinator::read_coordinator_heartbeat(&workspace_path) else {
|
|
854
|
-
return;
|
|
855
|
-
};
|
|
856
|
-
let Some(recorded_host_boot) = heartbeat
|
|
857
|
-
.get("host_boot_id")
|
|
858
|
-
.and_then(Value::as_str)
|
|
859
|
-
.filter(|s| !s.is_empty() && *s != "unknown")
|
|
860
|
-
else {
|
|
861
|
-
return;
|
|
862
|
-
};
|
|
863
|
-
let Some(current_host_boot) = crate::coordinator::probe_host_boot_id() else {
|
|
864
|
-
return;
|
|
865
|
-
};
|
|
866
|
-
if current_host_boot == recorded_host_boot {
|
|
867
|
-
return;
|
|
868
|
-
}
|
|
869
|
-
// Only surface when state actually has pane/session bindings that
|
|
870
|
-
// matter — otherwise there's nothing to be stale about.
|
|
871
|
-
let has_bindings = state
|
|
872
|
-
.get("agents")
|
|
873
|
-
.and_then(Value::as_object)
|
|
874
|
-
.is_some_and(|agents| {
|
|
875
|
-
agents.values().any(|agent| {
|
|
876
|
-
agent
|
|
877
|
-
.get("pane_id")
|
|
878
|
-
.and_then(Value::as_str)
|
|
879
|
-
.is_some_and(|s| !s.is_empty())
|
|
880
|
-
})
|
|
881
|
-
});
|
|
882
|
-
if !has_bindings {
|
|
883
|
-
return;
|
|
884
|
-
}
|
|
885
|
-
let session_name = state
|
|
886
|
-
.get("session_name")
|
|
887
|
-
.and_then(Value::as_str)
|
|
888
|
-
.unwrap_or("unknown");
|
|
889
|
-
if let Some(items) = issues.as_array_mut() {
|
|
890
|
-
items.push(json!({
|
|
891
|
-
"id": "runtime_bindings_stale_after_boot",
|
|
892
|
-
"session_name": session_name,
|
|
893
|
-
"recorded_host_boot_id": recorded_host_boot,
|
|
894
|
-
"current_host_boot_id": current_host_boot,
|
|
895
|
-
"details": "cached pane/pid/session bindings predate the current host boot; runtime facts are stale",
|
|
896
|
-
}));
|
|
897
|
-
}
|
|
898
|
-
if let Some(items) = repairs.as_array_mut() {
|
|
899
|
-
items.push(json!({
|
|
900
|
-
"issue": "runtime_bindings_stale_after_boot",
|
|
901
|
-
"action_required": true,
|
|
902
|
-
"advisory": false,
|
|
903
|
-
"hint_action": "team-agent restart",
|
|
904
|
-
"action": format!(
|
|
905
|
-
"runtime bindings for `{session_name}` predate the current host boot \
|
|
906
|
-
(recorded {recorded_host_boot}, current {current_host_boot}); rerun \
|
|
907
|
-
`team-agent restart` to rebuild the pane/pid/session tuple"
|
|
908
|
-
),
|
|
909
|
-
"dedupe_key": "runtime_bindings_stale_after_boot",
|
|
910
|
-
}));
|
|
911
|
-
}
|
|
912
|
-
}
|
|
913
|
-
|
|
914
|
-
fn append_legacy_snapshot_issue(workspace: &std::path::Path, state: &Value, issues: &mut Value) {
|
|
915
|
-
let Ok(Some(details)) = crate::leader::detect_dual_state_divergence(workspace, state) else {
|
|
916
|
-
return;
|
|
917
|
-
};
|
|
918
|
-
if let Some(items) = issues.as_array_mut() {
|
|
919
|
-
items.push(json!({
|
|
920
|
-
"id": "legacy_snapshot_stale",
|
|
921
|
-
"details": details,
|
|
922
|
-
}));
|
|
923
|
-
}
|
|
924
|
-
}
|
|
925
|
-
|
|
926
|
-
fn append_coordinator_health_issue(
|
|
927
|
-
workspace: &std::path::Path,
|
|
928
|
-
state: &Value,
|
|
929
|
-
health: &crate::coordinator::HealthReport,
|
|
930
|
-
issues: &mut Value,
|
|
931
|
-
repairs: &mut Value,
|
|
932
|
-
) {
|
|
933
|
-
let Some(id) = coordinator_issue_id(state, health) else {
|
|
934
|
-
return;
|
|
935
|
-
};
|
|
936
|
-
if let Some(items) = issues.as_array_mut() {
|
|
937
|
-
items.push(coordinator_issue_value(id, health, workspace));
|
|
938
|
-
}
|
|
939
|
-
if let Some(items) = repairs.as_array_mut() {
|
|
940
|
-
items.push(coordinator_repair_hint(id, health));
|
|
941
|
-
}
|
|
942
|
-
}
|
|
943
|
-
|
|
944
|
-
fn coordinator_issue_id(
|
|
945
|
-
state: &Value,
|
|
946
|
-
health: &crate::coordinator::HealthReport,
|
|
947
|
-
) -> Option<&'static str> {
|
|
948
|
-
match health.status {
|
|
949
|
-
crate::coordinator::CoordinatorHealthStatus::Stale
|
|
950
|
-
| crate::coordinator::CoordinatorHealthStatus::InvalidPid => {
|
|
951
|
-
Some("coordinator_unavailable")
|
|
952
|
-
}
|
|
953
|
-
crate::coordinator::CoordinatorHealthStatus::Running => {
|
|
954
|
-
if !health.metadata_ok {
|
|
955
|
-
if health.service_available
|
|
956
|
-
&& matches!(
|
|
957
|
-
health.binary_identity_relation,
|
|
958
|
-
crate::coordinator::CoordinatorBinaryIdentityRelation::DaemonNewerThanCaller
|
|
959
|
-
)
|
|
960
|
-
{
|
|
961
|
-
return None;
|
|
962
|
-
}
|
|
963
|
-
return match health.metadata_mismatch_reason.as_deref() {
|
|
964
|
-
Some(
|
|
965
|
-
"binary_identity_missing"
|
|
966
|
-
| "binary_version_mismatch"
|
|
967
|
-
| "binary_path_mismatch",
|
|
968
|
-
) => Some("coordinator_stale_identity"),
|
|
969
|
-
Some(_) | None => Some("coordinator_unavailable"),
|
|
970
|
-
};
|
|
971
|
-
}
|
|
972
|
-
if !health.schema.ok {
|
|
973
|
-
Some("coordinator_schema_incompatible")
|
|
974
|
-
} else {
|
|
975
|
-
None
|
|
976
|
-
}
|
|
977
|
-
}
|
|
978
|
-
crate::coordinator::CoordinatorHealthStatus::Missing => {
|
|
979
|
-
coordinator_expected(state).then_some("coordinator_unavailable")
|
|
980
|
-
}
|
|
981
|
-
}
|
|
982
|
-
}
|
|
983
|
-
|
|
984
|
-
fn coordinator_issue_value(
|
|
985
|
-
id: &str,
|
|
986
|
-
health: &crate::coordinator::HealthReport,
|
|
987
|
-
workspace: &std::path::Path,
|
|
988
|
-
) -> Value {
|
|
989
|
-
json!({
|
|
990
|
-
"id": id,
|
|
991
|
-
"status": coordinator_status_wire(health.status),
|
|
992
|
-
"pid": health.pid.map(|pid| pid.get()),
|
|
993
|
-
"metadata_ok": health.metadata_ok,
|
|
994
|
-
"metadata_mismatch_reason": health.metadata_mismatch_reason.clone(),
|
|
995
|
-
"process_running": health.process_running,
|
|
996
|
-
"wire_metadata_ok": health.wire_metadata_ok,
|
|
997
|
-
"binary_identity_ok": health.binary_identity_ok,
|
|
998
|
-
"binary_identity_relation": health.binary_identity_relation.as_str(),
|
|
999
|
-
"service_available": health.service_available,
|
|
1000
|
-
"binary_path": health.current_binary_identity.binary_path.clone(),
|
|
1001
|
-
"binary_version": health.current_binary_identity.binary_version.clone(),
|
|
1002
|
-
"schema_ok": health.schema.ok,
|
|
1003
|
-
"coordinator_log": crate::coordinator::coordinator_log_path(
|
|
1004
|
-
&crate::coordinator::WorkspacePath::new(workspace.to_path_buf())
|
|
1005
|
-
)
|
|
1006
|
-
.to_string_lossy()
|
|
1007
|
-
.to_string(),
|
|
1008
|
-
})
|
|
1009
|
-
}
|
|
1010
|
-
|
|
1011
|
-
fn coordinator_repair_hint(id: &str, _health: &crate::coordinator::HealthReport) -> Value {
|
|
1012
|
-
let hint_action = match id {
|
|
1013
|
-
"coordinator_schema_incompatible" => "team-agent doctor --fix-schema --json",
|
|
1014
|
-
_ => "team-agent restart",
|
|
1015
|
-
};
|
|
1016
|
-
json!({
|
|
1017
|
-
"issue": id,
|
|
1018
|
-
"action_required": true,
|
|
1019
|
-
"advisory": true,
|
|
1020
|
-
"broken_class": id,
|
|
1021
|
-
"hint_action": hint_action,
|
|
1022
|
-
"dedupe_key": id,
|
|
1023
|
-
"action": format!("{hint_action} # diagnose only reports coordinator health; it does not start, stop, or rotate the coordinator"),
|
|
1024
|
-
})
|
|
1025
|
-
}
|
|
1026
|
-
|
|
1027
|
-
fn coordinator_expected(state: &Value) -> bool {
|
|
1028
|
-
state
|
|
1029
|
-
.get("session_name")
|
|
1030
|
-
.and_then(Value::as_str)
|
|
1031
|
-
.is_some_and(|session| !session.is_empty())
|
|
1032
|
-
|| state
|
|
1033
|
-
.get("agents")
|
|
1034
|
-
.and_then(Value::as_object)
|
|
1035
|
-
.is_some_and(|agents| !agents.is_empty())
|
|
1036
|
-
}
|
|
1037
|
-
|
|
1038
|
-
fn coordinator_status_wire(status: crate::coordinator::CoordinatorHealthStatus) -> &'static str {
|
|
1039
|
-
match status {
|
|
1040
|
-
crate::coordinator::CoordinatorHealthStatus::Missing => "missing",
|
|
1041
|
-
crate::coordinator::CoordinatorHealthStatus::InvalidPid => "invalid_pid",
|
|
1042
|
-
crate::coordinator::CoordinatorHealthStatus::Running => "running",
|
|
1043
|
-
crate::coordinator::CoordinatorHealthStatus::Stale => "stale",
|
|
1044
|
-
}
|
|
1045
|
-
}
|
|
1046
|
-
|
|
1047
|
-
fn topology_repair_hint(issue: &str) -> Value {
|
|
1048
|
-
json!({
|
|
1049
|
-
"issue": issue,
|
|
1050
|
-
"action_required": true,
|
|
1051
|
-
"advisory": true,
|
|
1052
|
-
"broken_class": issue,
|
|
1053
|
-
"hint_action": "team-agent doctor --json",
|
|
1054
|
-
"dedupe_key": issue,
|
|
1055
|
-
"action": "repair the tmux topology mismatch, then rerun team-agent restart",
|
|
1056
|
-
})
|
|
1057
|
-
}
|
|
1058
|
-
|
|
1059
|
-
/// 0.4.x (CR R2): pull (pane_id, provider_label) from leader_receiver. Used
|
|
1060
|
-
/// by `leader_provider_health` reconcile in diagnose. Returns None when the
|
|
1061
|
-
/// leader is not attached or any field is missing.
|
|
1062
|
-
fn leader_pane_and_provider(state: &Value) -> Option<(String, String)> {
|
|
1063
|
-
let receiver = state.get("leader_receiver")?;
|
|
1064
|
-
let pane_id = receiver
|
|
1065
|
-
.get("pane_id")
|
|
1066
|
-
.and_then(Value::as_str)
|
|
1067
|
-
.filter(|s| !s.is_empty())?
|
|
1068
|
-
.to_string();
|
|
1069
|
-
let provider = receiver
|
|
1070
|
-
.get("provider")
|
|
1071
|
-
.and_then(Value::as_str)
|
|
1072
|
-
.filter(|s| !s.is_empty())
|
|
1073
|
-
.unwrap_or("claude")
|
|
1074
|
-
.to_string();
|
|
1075
|
-
Some((pane_id, provider))
|
|
1076
|
-
}
|
|
1077
|
-
|
|
1078
|
-
fn leader_receiver_attached(state: &Value) -> bool {
|
|
1079
|
-
let Some(receiver) = state.get("leader_receiver") else {
|
|
1080
|
-
return false;
|
|
1081
|
-
};
|
|
1082
|
-
let mode_direct = receiver
|
|
1083
|
-
.get("mode")
|
|
1084
|
-
.and_then(Value::as_str)
|
|
1085
|
-
.is_some_and(|mode| mode == "direct_tmux" || mode == "direct");
|
|
1086
|
-
let status_attached = receiver.get("status").and_then(Value::as_str) == Some("attached");
|
|
1087
|
-
let pane_present = receiver
|
|
1088
|
-
.get("pane_id")
|
|
1089
|
-
.and_then(Value::as_str)
|
|
1090
|
-
.is_some_and(|pane| !pane.is_empty());
|
|
1091
|
-
mode_direct && status_attached && pane_present
|
|
1092
|
-
}
|
|
1093
|
-
|
|
1094
|
-
fn recovery_hint(team: &str, broken_class: &str, hint_action: &str) -> Value {
|
|
1095
|
-
json!({
|
|
1096
|
-
"issue": broken_class,
|
|
1097
|
-
"action_required": true,
|
|
1098
|
-
"advisory": true,
|
|
1099
|
-
"broken_class": broken_class,
|
|
1100
|
-
"hint_action": hint_action,
|
|
1101
|
-
"dedupe_key": format!("{team}:{broken_class}"),
|
|
1102
|
-
"action": hint_action,
|
|
1103
|
-
})
|
|
1104
|
-
}
|
|
1105
|
-
|
|
1106
|
-
#[cfg(test)]
|
|
1107
|
-
mod tests {
|
|
1108
|
-
use super::*;
|
|
1109
|
-
|
|
1110
|
-
#[test]
|
|
1111
|
-
fn hint_action_does_not_emit_attach_leader() {
|
|
1112
|
-
let workspace = std::path::PathBuf::from("/tmp/ta-hint-ws");
|
|
1113
|
-
let endpoint = "/tmp/ta-hint.sock";
|
|
1114
|
-
let state = json!({
|
|
1115
|
-
"team_key": "alpha",
|
|
1116
|
-
"leader_receiver": {
|
|
1117
|
-
"status": "attached",
|
|
1118
|
-
"pane_id": "%1",
|
|
1119
|
-
"provider": "codex",
|
|
1120
|
-
"tmux_socket": endpoint
|
|
1121
|
-
}
|
|
1122
|
-
});
|
|
1123
|
-
let transport = crate::transport::test_support::OfflineTransport::default()
|
|
1124
|
-
.with_tmux_endpoint(endpoint)
|
|
1125
|
-
.with_targets(vec![crate::transport::PaneInfo {
|
|
1126
|
-
pane_id: crate::transport::PaneId::new("%1"),
|
|
1127
|
-
session: crate::transport::SessionName::new("s"),
|
|
1128
|
-
window_index: None,
|
|
1129
|
-
window_name: None,
|
|
1130
|
-
pane_index: None,
|
|
1131
|
-
tty: None,
|
|
1132
|
-
current_command: Some("codex".to_string()),
|
|
1133
|
-
current_path: Some(std::path::PathBuf::from("/tmp/other-ws")),
|
|
1134
|
-
active: true,
|
|
1135
|
-
pane_pid: None,
|
|
1136
|
-
leader_env: Default::default(),
|
|
1137
|
-
}]);
|
|
1138
|
-
let Some((_, repair)) = live_leader_workspace_mismatch(&workspace, &state, &transport)
|
|
1139
|
-
else {
|
|
1140
|
-
panic!("workspace mismatch repair required");
|
|
1141
|
-
};
|
|
1142
|
-
let hint = repair
|
|
1143
|
-
.get(HINT_ACTION_FIELD)
|
|
1144
|
-
.and_then(Value::as_str)
|
|
1145
|
-
.unwrap_or("");
|
|
1146
|
-
let action = repair
|
|
1147
|
-
.get(ACTION_FIELD)
|
|
1148
|
-
.and_then(Value::as_str)
|
|
1149
|
-
.unwrap_or("");
|
|
1150
|
-
for field in [hint, action] {
|
|
1151
|
-
assert!(
|
|
1152
|
-
!field.contains("attach-leader"),
|
|
1153
|
-
"mismatch repair must not emit attach-leader; got {field}"
|
|
1154
|
-
);
|
|
1155
|
-
assert!(
|
|
1156
|
-
!field.contains("claim-leader"),
|
|
1157
|
-
"mismatch repair must not emit claim-leader; got {field}"
|
|
1158
|
-
);
|
|
1159
|
-
assert!(
|
|
1160
|
-
!field.contains("takeover"),
|
|
1161
|
-
"mismatch repair must not emit takeover; got {field}"
|
|
1162
|
-
);
|
|
1163
|
-
}
|
|
1164
|
-
}
|
|
1165
|
-
|
|
1166
|
-
#[test]
|
|
1167
|
-
fn recovery_hint_does_not_bundle_unrelated_bind_commands() {
|
|
1168
|
-
let hint = recovery_hint("alpha", "tmux_session_missing", "team-agent restart");
|
|
1169
|
-
let action = hint.get("action").and_then(Value::as_str).unwrap_or("");
|
|
1170
|
-
assert_eq!(action, "team-agent restart");
|
|
1171
|
-
assert!(
|
|
1172
|
-
!action.contains("claim-leader"),
|
|
1173
|
-
"shotgun alternatives must not appear; action={action}"
|
|
1174
|
-
);
|
|
1175
|
-
assert!(
|
|
1176
|
-
!action.contains("takeover"),
|
|
1177
|
-
"shotgun alternatives must not appear; action={action}"
|
|
1178
|
-
);
|
|
1179
|
-
}
|
|
1180
|
-
|
|
1181
|
-
#[test]
|
|
1182
|
-
fn missing_workspace_does_not_classify_as_unbound_claim() {
|
|
1183
|
-
let workspace = std::env::temp_dir().join(format!(
|
|
1184
|
-
"ta-diagnose-missing-{}-{}",
|
|
1185
|
-
std::process::id(),
|
|
1186
|
-
std::time::SystemTime::now()
|
|
1187
|
-
.duration_since(std::time::UNIX_EPOCH)
|
|
1188
|
-
.unwrap()
|
|
1189
|
-
.as_nanos()
|
|
1190
|
-
));
|
|
1191
|
-
std::fs::create_dir_all(&workspace).unwrap();
|
|
1192
|
-
let state =
|
|
1193
|
-
json!({"agents": {}, "tasks": [], "session_name": null, "active_team_key": null});
|
|
1194
|
-
let mut issues = json!([]);
|
|
1195
|
-
let mut repairs = json!([]);
|
|
1196
|
-
append_registry_channel_unbound_issue(
|
|
1197
|
-
&workspace,
|
|
1198
|
-
&state,
|
|
1199
|
-
Some("current"),
|
|
1200
|
-
&mut issues,
|
|
1201
|
-
&mut repairs,
|
|
1202
|
-
);
|
|
1203
|
-
let _ = std::fs::remove_dir_all(&workspace);
|
|
1204
|
-
let issues_text = issues.to_string();
|
|
1205
|
-
let repairs_text = repairs.to_string();
|
|
1206
|
-
assert!(
|
|
1207
|
-
issues_text.contains(TEAM_SPEC_OR_RUNTIME_MISSING),
|
|
1208
|
-
"issues={issues_text}"
|
|
1209
|
-
);
|
|
1210
|
-
assert!(
|
|
1211
|
-
!issues_text.contains("leader_receiver_unbound"),
|
|
1212
|
-
"missing team must not be unbound; issues={issues_text}"
|
|
1213
|
-
);
|
|
1214
|
-
assert!(
|
|
1215
|
-
repairs_text.contains("quick-start"),
|
|
1216
|
-
"repairs={repairs_text}"
|
|
1217
|
-
);
|
|
1218
|
-
assert!(
|
|
1219
|
-
!repairs_text.contains("claim-leader"),
|
|
1220
|
-
"missing team must not induce claim; repairs={repairs_text}"
|
|
1221
|
-
);
|
|
1222
|
-
}
|
|
1223
|
-
|
|
1224
|
-
#[test]
|
|
1225
|
-
fn diagnose_runtime_does_not_emit_not_committed_parallel() {
|
|
1226
|
-
let state = json!({
|
|
1227
|
-
"leader_receiver": {"status": "pending", "pane_id": "%1"}
|
|
1228
|
-
});
|
|
1229
|
-
let transport = crate::transport::test_support::OfflineTransport::default();
|
|
1230
|
-
let (issues, repairs) = diagnose_runtime(&state, &transport);
|
|
1231
|
-
let issues_text = issues.to_string();
|
|
1232
|
-
let repairs_text = repairs.to_string();
|
|
1233
|
-
assert!(
|
|
1234
|
-
!issues_text.contains("leader_receiver_not_committed"),
|
|
1235
|
-
"issues={issues_text}"
|
|
1236
|
-
);
|
|
1237
|
-
assert!(
|
|
1238
|
-
!repairs_text.contains("leader_receiver_not_committed"),
|
|
1239
|
-
"repairs={repairs_text}"
|
|
1240
|
-
);
|
|
1241
|
-
}
|
|
1242
|
-
|
|
1243
|
-
fn coordinator_health_fixture(
|
|
1244
|
-
status: crate::coordinator::CoordinatorHealthStatus,
|
|
1245
|
-
metadata_mismatch_reason: Option<&str>,
|
|
1246
|
-
schema_ok: bool,
|
|
1247
|
-
) -> crate::coordinator::HealthReport {
|
|
1248
|
-
crate::coordinator::HealthReport {
|
|
1249
|
-
ok: matches!(status, crate::coordinator::CoordinatorHealthStatus::Running)
|
|
1250
|
-
&& metadata_mismatch_reason.is_none()
|
|
1251
|
-
&& schema_ok,
|
|
1252
|
-
status,
|
|
1253
|
-
pid: Some(crate::coordinator::Pid::new(std::process::id())),
|
|
1254
|
-
metadata: None,
|
|
1255
|
-
metadata_ok: metadata_mismatch_reason.is_none(),
|
|
1256
|
-
process_running: matches!(status, crate::coordinator::CoordinatorHealthStatus::Running),
|
|
1257
|
-
wire_metadata_ok: metadata_mismatch_reason.is_none(),
|
|
1258
|
-
binary_identity_ok: metadata_mismatch_reason.is_none(),
|
|
1259
|
-
binary_identity_relation: crate::coordinator::CoordinatorBinaryIdentityRelation::Same,
|
|
1260
|
-
service_available: matches!(
|
|
1261
|
-
status,
|
|
1262
|
-
crate::coordinator::CoordinatorHealthStatus::Running
|
|
1263
|
-
) && metadata_mismatch_reason.is_none()
|
|
1264
|
-
&& schema_ok,
|
|
1265
|
-
metadata_mismatch_reason: metadata_mismatch_reason.map(ToString::to_string),
|
|
1266
|
-
current_binary_identity: crate::coordinator::CoordinatorBinaryIdentity {
|
|
1267
|
-
binary_path: "/current/team-agent".to_string(),
|
|
1268
|
-
binary_version: env!("CARGO_PKG_VERSION").to_string(),
|
|
1269
|
-
},
|
|
1270
|
-
schema: crate::coordinator::SchemaHealth {
|
|
1271
|
-
ok: schema_ok,
|
|
1272
|
-
schema_version: crate::db::schema::SCHEMA_VERSION,
|
|
1273
|
-
error: None,
|
|
1274
|
-
action: None,
|
|
1275
|
-
},
|
|
1276
|
-
}
|
|
1277
|
-
}
|
|
1278
|
-
|
|
1279
|
-
#[test]
|
|
1280
|
-
fn coordinator_issue_id_maps_stale_pid_to_unavailable() {
|
|
1281
|
-
let health = coordinator_health_fixture(
|
|
1282
|
-
crate::coordinator::CoordinatorHealthStatus::Stale,
|
|
1283
|
-
None,
|
|
1284
|
-
true,
|
|
1285
|
-
);
|
|
1286
|
-
assert_eq!(
|
|
1287
|
-
coordinator_issue_id(&json!({"session_name": "team-fixture"}), &health),
|
|
1288
|
-
Some("coordinator_unavailable")
|
|
1289
|
-
);
|
|
1290
|
-
}
|
|
1291
|
-
|
|
1292
|
-
#[test]
|
|
1293
|
-
fn coordinator_issue_id_maps_binary_identity_to_stale_identity() {
|
|
1294
|
-
let health = coordinator_health_fixture(
|
|
1295
|
-
crate::coordinator::CoordinatorHealthStatus::Running,
|
|
1296
|
-
Some("binary_version_mismatch"),
|
|
1297
|
-
true,
|
|
1298
|
-
);
|
|
1299
|
-
assert_eq!(
|
|
1300
|
-
coordinator_issue_id(&json!({"session_name": "team-fixture"}), &health),
|
|
1301
|
-
Some("coordinator_stale_identity")
|
|
1302
|
-
);
|
|
1303
|
-
}
|
|
1304
|
-
|
|
1305
|
-
#[test]
|
|
1306
|
-
fn coordinator_issue_id_maps_schema_failure_to_schema_incompatible() {
|
|
1307
|
-
let health = coordinator_health_fixture(
|
|
1308
|
-
crate::coordinator::CoordinatorHealthStatus::Running,
|
|
1309
|
-
None,
|
|
1310
|
-
false,
|
|
1311
|
-
);
|
|
1312
|
-
assert_eq!(
|
|
1313
|
-
coordinator_issue_id(&json!({"session_name": "team-fixture"}), &health),
|
|
1314
|
-
Some("coordinator_schema_incompatible")
|
|
1315
|
-
);
|
|
1316
|
-
}
|
|
1317
|
-
|
|
1318
|
-
fn pane(session: &str, pane_id: &str, window: &str) -> crate::transport::PaneInfo {
|
|
1319
|
-
crate::transport::PaneInfo {
|
|
1320
|
-
pane_id: crate::transport::PaneId::new(pane_id),
|
|
1321
|
-
session: crate::transport::SessionName::new(session),
|
|
1322
|
-
window_index: None,
|
|
1323
|
-
window_name: Some(crate::transport::WindowName::new(window)),
|
|
1324
|
-
pane_index: None,
|
|
1325
|
-
tty: None,
|
|
1326
|
-
current_command: Some(window.to_string()),
|
|
1327
|
-
current_path: None,
|
|
1328
|
-
active: true,
|
|
1329
|
-
pane_pid: Some(1),
|
|
1330
|
-
leader_env: Default::default(),
|
|
1331
|
-
}
|
|
1332
|
-
}
|
|
1333
|
-
|
|
1334
|
-
fn has_issue(issues: &Value, issue: &str) -> bool {
|
|
1335
|
-
issues
|
|
1336
|
-
.as_array()
|
|
1337
|
-
.is_some_and(|items| items.iter().any(|item| item.as_str() == Some(issue)))
|
|
1338
|
-
}
|
|
1339
|
-
|
|
1340
|
-
fn grok_state(extra: Value) -> Value {
|
|
1341
|
-
let mut agent = json!({
|
|
1342
|
-
"provider": "grok_build",
|
|
1343
|
-
"status": "running",
|
|
1344
|
-
"runtime_family": "contract",
|
|
1345
|
-
"window": null,
|
|
1346
|
-
"pane_id": null,
|
|
1347
|
-
"session_name": null
|
|
1348
|
-
});
|
|
1349
|
-
if let (Some(agent), Some(extra)) = (agent.as_object_mut(), extra.as_object()) {
|
|
1350
|
-
for (key, value) in extra {
|
|
1351
|
-
agent.insert(key.clone(), value.clone());
|
|
1352
|
-
}
|
|
1353
|
-
}
|
|
1354
|
-
json!({
|
|
1355
|
-
"session_name": "team-current",
|
|
1356
|
-
"agents": { "grok-seat": agent }
|
|
1357
|
-
})
|
|
1358
|
-
}
|
|
1359
|
-
|
|
1360
|
-
#[test]
|
|
1361
|
-
fn doctor_accepts_live_native_pane_when_window_title_is_not_agent_id() {
|
|
1362
|
-
let state = grok_state(json!({"native_pane": "%1"}));
|
|
1363
|
-
let backend = crate::transport::test_support::OfflineTransport::new()
|
|
1364
|
-
.with_session_present(true)
|
|
1365
|
-
.with_windows(vec![crate::transport::WindowName::new("grok")])
|
|
1366
|
-
.with_targets(vec![pane("team-current", "%1", "renamed-by-cli")]);
|
|
1367
|
-
let (issues, _) = diagnose_runtime(&state, &backend);
|
|
1368
|
-
assert!(
|
|
1369
|
-
!has_issue(&issues, "worker_window_missing:grok-seat"),
|
|
1370
|
-
"live pane id must prove the seat without the agent-id window name; issues={issues}"
|
|
1371
|
-
);
|
|
1372
|
-
}
|
|
1373
|
-
|
|
1374
|
-
#[test]
|
|
1375
|
-
fn doctor_does_not_treat_another_public_window_as_a_missing_pane() {
|
|
1376
|
-
let state = grok_state(json!({"native_pane": "%1"}));
|
|
1377
|
-
let backend = crate::transport::test_support::OfflineTransport::new()
|
|
1378
|
-
.with_session_present(true)
|
|
1379
|
-
.with_windows(vec![crate::transport::WindowName::new("grok")])
|
|
1380
|
-
.with_targets(vec![pane("team-current", "%9", "grok")]);
|
|
1381
|
-
let (issues, _) = diagnose_runtime(&state, &backend);
|
|
1382
|
-
assert!(
|
|
1383
|
-
has_issue(&issues, "worker_window_missing:grok-seat"),
|
|
1384
|
-
"a same-named window must not hide a different pane id; issues={issues}"
|
|
1385
|
-
);
|
|
1386
|
-
}
|
|
1387
|
-
|
|
1388
|
-
#[test]
|
|
1389
|
-
fn codex_contract_window_may_carry_its_public_or_node_launcher_name() {
|
|
1390
|
-
assert!(is_public_window_name("codex_tui", "codex"));
|
|
1391
|
-
assert!(is_public_window_name("codex_tui", "node"));
|
|
1392
|
-
assert!(!is_public_window_name("codex_tui", "grok"));
|
|
1393
|
-
assert!(!is_public_window_name("grok_build", "node"));
|
|
1394
|
-
}
|
|
1395
|
-
|
|
1396
|
-
#[test]
|
|
1397
|
-
fn doctor_accepts_public_window_name_when_no_pane_id_is_recorded() {
|
|
1398
|
-
let state = grok_state(json!({}));
|
|
1399
|
-
let backend = crate::transport::test_support::OfflineTransport::new()
|
|
1400
|
-
.with_session_present(true)
|
|
1401
|
-
.with_windows(vec![crate::transport::WindowName::new("grok")]);
|
|
1402
|
-
let (issues, _) = diagnose_runtime(&state, &backend);
|
|
1403
|
-
assert!(
|
|
1404
|
-
!has_issue(&issues, "worker_window_missing:grok-seat"),
|
|
1405
|
-
"public command title is a valid fallback; issues={issues}"
|
|
1406
|
-
);
|
|
1407
|
-
}
|
|
1408
|
-
|
|
1409
|
-
#[test]
|
|
1410
|
-
fn doctor_still_accepts_legacy_agent_id_window_name() {
|
|
1411
|
-
let state = json!({
|
|
1412
|
-
"session_name": "team-current",
|
|
1413
|
-
"agents": {
|
|
1414
|
-
"worker-a": { "provider": "pi", "status": "running" }
|
|
1415
|
-
}
|
|
1416
|
-
});
|
|
1417
|
-
let backend = crate::transport::test_support::OfflineTransport::new()
|
|
1418
|
-
.with_session_present(true)
|
|
1419
|
-
.with_windows(vec![crate::transport::WindowName::new("worker-a")]);
|
|
1420
|
-
let (issues, _) = diagnose_runtime(&state, &backend);
|
|
1421
|
-
assert!(
|
|
1422
|
-
!has_issue(&issues, "worker_window_missing:worker-a"),
|
|
1423
|
-
"legacy agent-id windows remain present; issues={issues}"
|
|
1424
|
-
);
|
|
1425
|
-
}
|
|
1426
|
-
}
|
|
1427
|
-
|
|
1428
|
-
pub(crate) fn build_profile_smoke_check_for_team(
|
|
1429
|
-
team: &std::path::Path,
|
|
1430
|
-
) -> Result<Value, CliError> {
|
|
1431
|
-
let workspace = crate::model::paths::team_workspace(team)
|
|
1432
|
-
.map_err(|error| CliError::Runtime(error.to_string()))?;
|
|
1433
|
-
let spec = match crate::compiler::compile_team(team) {
|
|
1434
|
-
Ok(spec) => spec,
|
|
1435
|
-
Err(error) => {
|
|
1436
|
-
// SMOKE-1 (locate.md §"Smallest likely code touch" item 2):compile
|
|
1437
|
-
// 失败时把 team_dir + next_action 带上,operator 才有可下手的诊断
|
|
1438
|
-
// (不是只贴一行 reason)。
|
|
1439
|
-
return Ok(json!({
|
|
1440
|
-
"name": "profile_smoke",
|
|
1441
|
-
"ok": false,
|
|
1442
|
-
"status": "profile_invalid",
|
|
1443
|
-
"team_dir": team.to_string_lossy().to_string(),
|
|
1444
|
-
"reason": error.to_string(),
|
|
1445
|
-
"next_action": format!(
|
|
1446
|
-
"fix the team spec at `{}` (see reason above) or re-run \
|
|
1447
|
-
doctor with a different `<team-dir>`",
|
|
1448
|
-
team.display()
|
|
1449
|
-
),
|
|
1450
|
-
"secret_values_printed": false,
|
|
1451
|
-
"checks": [],
|
|
1452
|
-
}));
|
|
1453
|
-
}
|
|
1454
|
-
};
|
|
1455
|
-
let agents = spec
|
|
1456
|
-
.get("agents")
|
|
1457
|
-
.and_then(crate::model::yaml::Value::as_list)
|
|
1458
|
-
.unwrap_or(&[]);
|
|
1459
|
-
let checks = crate::lifecycle::profile_smoke::profile_smoke_checks_for_agents_with_profile_dir(
|
|
1460
|
-
&workspace,
|
|
1461
|
-
agents,
|
|
1462
|
-
Some(&team.join("profiles")),
|
|
1463
|
-
crate::lifecycle::profile_smoke::DEFAULT_PROFILE_SMOKE_TIMEOUT,
|
|
1464
|
-
);
|
|
1465
|
-
Ok(aggregate_profile_smoke_checks(checks))
|
|
1466
|
-
}
|
|
1467
|
-
|
|
1468
|
-
fn aggregate_profile_smoke_checks(checks: Vec<Value>) -> Value {
|
|
1469
|
-
let failed = checks
|
|
1470
|
-
.iter()
|
|
1471
|
-
.filter(|check| check.get("ok").and_then(Value::as_bool) == Some(false))
|
|
1472
|
-
.cloned()
|
|
1473
|
-
.collect::<Vec<_>>();
|
|
1474
|
-
let ok = failed.is_empty();
|
|
1475
|
-
let status = if !ok {
|
|
1476
|
-
failed
|
|
1477
|
-
.first()
|
|
1478
|
-
.and_then(|check| check.get("status").and_then(Value::as_str))
|
|
1479
|
-
.unwrap_or("smoke_failed")
|
|
1480
|
-
} else if checks
|
|
1481
|
-
.iter()
|
|
1482
|
-
.any(|check| check.get("status").and_then(Value::as_str) == Some("smoke_passed"))
|
|
1483
|
-
{
|
|
1484
|
-
"smoke_passed"
|
|
1485
|
-
} else if checks
|
|
1486
|
-
.iter()
|
|
1487
|
-
.any(|check| check.get("status").and_then(Value::as_str) == Some("skipped_by_profile"))
|
|
1488
|
-
{
|
|
1489
|
-
"skipped_by_profile"
|
|
1490
|
-
} else {
|
|
1491
|
-
"not_required"
|
|
1492
|
-
};
|
|
1493
|
-
let mut out = json!({
|
|
1494
|
-
"name": "profile_smoke",
|
|
1495
|
-
"ok": ok,
|
|
1496
|
-
"status": status,
|
|
1497
|
-
"checks": checks,
|
|
1498
|
-
"secret_values_printed": false,
|
|
1499
|
-
});
|
|
1500
|
-
if let Some(first) = failed.first() {
|
|
1501
|
-
copy_optional_field(first, &mut out, "reason");
|
|
1502
|
-
copy_optional_field(first, &mut out, "http_status");
|
|
1503
|
-
copy_optional_field(first, &mut out, "endpoint");
|
|
1504
|
-
copy_optional_field(first, &mut out, "error");
|
|
1505
|
-
} else if let Some(first_passed) = checks
|
|
1506
|
-
.iter()
|
|
1507
|
-
.find(|check| check.get("status").and_then(Value::as_str) == Some("smoke_passed"))
|
|
1508
|
-
{
|
|
1509
|
-
copy_optional_field(first_passed, &mut out, "http_status");
|
|
1510
|
-
copy_optional_field(first_passed, &mut out, "endpoint");
|
|
1511
|
-
}
|
|
1512
|
-
out
|
|
1513
|
-
}
|
|
1514
|
-
|
|
1515
|
-
fn copy_optional_field(from: &Value, to: &mut Value, key: &str) {
|
|
1516
|
-
let Some(value) = from.get(key).cloned() else {
|
|
1517
|
-
return;
|
|
1518
|
-
};
|
|
1519
|
-
let Some(obj) = to.as_object_mut() else {
|
|
1520
|
-
return;
|
|
1521
|
-
};
|
|
1522
|
-
obj.insert(key.to_string(), value);
|
|
1523
|
-
}
|
|
1524
|
-
|
|
1525
|
-
/// Shared status facts, independent of any polling command.
|
|
1526
|
-
pub(crate) fn wait_readiness(state: &Value) -> Value {
|
|
1527
|
-
let agents = state.get("agents").and_then(Value::as_object);
|
|
1528
|
-
let mut process_started = false;
|
|
1529
|
-
let mut cli_prompt_ready = false;
|
|
1530
|
-
let mut mcp_ready = false;
|
|
1531
|
-
let mut task_prompt_delivered = false;
|
|
1532
|
-
let mut awaiting_trust_prompt = false;
|
|
1533
|
-
let mut incomplete_sessions = Vec::new();
|
|
1534
|
-
// A-5: a missing/unreadable leader_receiver must NOT count as attached —
|
|
1535
|
-
// "unreadable is never ready" (doctor/wait-ready truthfulness rule).
|
|
1536
|
-
let all_attached_receiver = state
|
|
1537
|
-
.get("leader_receiver")
|
|
1538
|
-
.and_then(Value::as_object)
|
|
1539
|
-
.is_some_and(|receiver| {
|
|
1540
|
-
receiver.get("status").and_then(Value::as_str) == Some("attached")
|
|
1541
|
-
|| receiver
|
|
1542
|
-
.get("pane_id")
|
|
1543
|
-
.and_then(Value::as_str)
|
|
1544
|
-
.is_some_and(|pane| !pane.is_empty() && pane != "__team_agent_unbound__")
|
|
1545
|
-
});
|
|
1546
|
-
|
|
1547
|
-
if let Some(agents) = agents {
|
|
1548
|
-
process_started = state
|
|
1549
|
-
.get("tmux_session_present")
|
|
1550
|
-
.map(crate::cli::helpers::python_truthy)
|
|
1551
|
-
.map(|present| present || fake_process_started(agents))
|
|
1552
|
-
.unwrap_or_else(|| legacy_process_started(agents));
|
|
1553
|
-
cli_prompt_ready = !agents.is_empty()
|
|
1554
|
-
&& agents.values().all(|agent| {
|
|
1555
|
-
agent.get("cli_prompt_ready").and_then(Value::as_bool) == Some(true)
|
|
1556
|
-
|| agent.get("startup_prompts").and_then(Value::as_str) == Some("complete")
|
|
1557
|
-
|| matches!(
|
|
1558
|
-
agent.get("status").and_then(Value::as_str),
|
|
1559
|
-
Some("running" | "busy" | "ready")
|
|
1560
|
-
)
|
|
1561
|
-
});
|
|
1562
|
-
mcp_ready = !agents.is_empty() && agents.values().all(agent_mcp_ready);
|
|
1563
|
-
task_prompt_delivered = !agents.is_empty()
|
|
1564
|
-
&& (message_counts_positive(state.get("messages"))
|
|
1565
|
-
|| agents.values().all(|agent| {
|
|
1566
|
-
agent.get("task_prompt_delivered").and_then(Value::as_bool) == Some(true)
|
|
1567
|
-
|| agent.get("first_send_at").is_some_and(|v| !v.is_null())
|
|
1568
|
-
}));
|
|
1569
|
-
awaiting_trust_prompt = agents.values().any(|agent| {
|
|
1570
|
-
agent
|
|
1571
|
-
.get("startup_prompt_status")
|
|
1572
|
-
.or_else(|| agent.get("startup_prompts"))
|
|
1573
|
-
.or_else(|| agent.get("status"))
|
|
1574
|
-
.and_then(Value::as_str)
|
|
1575
|
-
== Some("awaiting_trust_prompt")
|
|
1576
|
-
});
|
|
1577
|
-
incomplete_sessions =
|
|
1578
|
-
crate::session_capture::incomplete_interacted_resumable_agent_ids(state);
|
|
1579
|
-
}
|
|
1580
|
-
let all_resumable_have_session = incomplete_sessions.is_empty();
|
|
1581
|
-
let session_capture_incomplete = !all_resumable_have_session;
|
|
1582
|
-
let all_spawned = process_started && cli_prompt_ready && mcp_ready;
|
|
1583
|
-
let ready = all_spawned && all_attached_receiver && all_resumable_have_session;
|
|
1584
|
-
json!({
|
|
1585
|
-
"all_attached_receiver": all_attached_receiver,
|
|
1586
|
-
"all_resumable_have_session": all_resumable_have_session,
|
|
1587
|
-
"all_spawned": all_spawned,
|
|
1588
|
-
"awaiting_trust_prompt": awaiting_trust_prompt,
|
|
1589
|
-
"cli_prompt_ready": cli_prompt_ready,
|
|
1590
|
-
"incomplete_session_capture_agents": incomplete_sessions.clone(),
|
|
1591
|
-
"mcp_ready": mcp_ready,
|
|
1592
|
-
"process_started": process_started,
|
|
1593
|
-
"ready": ready,
|
|
1594
|
-
"session_capture_complete": all_resumable_have_session,
|
|
1595
|
-
"session_capture_incomplete": session_capture_incomplete,
|
|
1596
|
-
"pending_session_agent_ids": incomplete_sessions,
|
|
1597
|
-
"task_prompt_delivered": task_prompt_delivered,
|
|
1598
|
-
})
|
|
1599
|
-
}
|
|
1600
|
-
|
|
1601
|
-
fn message_counts_positive(value: Option<&Value>) -> bool {
|
|
1602
|
-
let Some(Value::Object(counts)) = value else {
|
|
1603
|
-
return false;
|
|
1604
|
-
};
|
|
1605
|
-
counts.values().any(|count| {
|
|
1606
|
-
count
|
|
1607
|
-
.as_i64()
|
|
1608
|
-
.or_else(|| count.as_u64().and_then(|n| i64::try_from(n).ok()))
|
|
1609
|
-
.is_some_and(|n| n > 0)
|
|
1610
|
-
})
|
|
1611
|
-
}
|
|
1612
|
-
|
|
1613
|
-
fn legacy_process_started(agents: &serde_json::Map<String, Value>) -> bool {
|
|
1614
|
-
!agents.is_empty()
|
|
1615
|
-
&& agents.values().all(|agent| {
|
|
1616
|
-
agent
|
|
1617
|
-
.get("pane_id")
|
|
1618
|
-
.and_then(Value::as_str)
|
|
1619
|
-
.is_some_and(|s| !s.is_empty())
|
|
1620
|
-
|| agent.get("pid").and_then(Value::as_i64).is_some()
|
|
1621
|
-
|| agent.get("process_started").and_then(Value::as_bool) == Some(true)
|
|
1622
|
-
|| fake_agent_started(agent)
|
|
1623
|
-
})
|
|
1624
|
-
}
|
|
1625
|
-
|
|
1626
|
-
fn fake_process_started(agents: &serde_json::Map<String, Value>) -> bool {
|
|
1627
|
-
!agents.is_empty() && agents.values().all(fake_agent_started)
|
|
1628
|
-
}
|
|
1629
|
-
|
|
1630
|
-
fn fake_agent_started(agent: &Value) -> bool {
|
|
1631
|
-
agent.get("provider").and_then(Value::as_str) == Some("fake")
|
|
1632
|
-
&& matches!(
|
|
1633
|
-
agent.get("status").and_then(Value::as_str),
|
|
1634
|
-
Some("running" | "busy" | "ready")
|
|
1635
|
-
)
|
|
1636
|
-
}
|
|
1637
|
-
|
|
1638
|
-
fn agent_mcp_ready(agent: &Value) -> bool {
|
|
1639
|
-
agent
|
|
1640
|
-
.get("mcp_config")
|
|
1641
|
-
.and_then(Value::as_str)
|
|
1642
|
-
.filter(|path| !path.is_empty())
|
|
1643
|
-
.map(|path| std::path::Path::new(path).exists())
|
|
1644
|
-
.unwrap_or_else(|| {
|
|
1645
|
-
agent.get("mcp_ready").and_then(Value::as_bool) == Some(true)
|
|
1646
|
-
|| agent.get("mcp").and_then(Value::as_str) == Some("ready")
|
|
1647
|
-
})
|
|
1648
|
-
}
|
|
1649
|
-
|
|
1650
|
-
fn yaml_path_str<'a>(value: &'a crate::model::yaml::Value, keys: &[&str]) -> Option<&'a str> {
|
|
1651
|
-
let mut current = value;
|
|
1652
|
-
for key in keys {
|
|
1653
|
-
current = current.get(key)?;
|
|
1654
|
-
}
|
|
1655
|
-
current.as_str()
|
|
1656
|
-
}
|
|
1657
|
-
|
|
1658
|
-
pub(crate) fn count_dir_entries(path: &std::path::Path) -> usize {
|
|
1659
|
-
std::fs::read_dir(path)
|
|
1660
|
-
.map(|entries| entries.filter_map(std::result::Result::ok).count())
|
|
1661
|
-
.unwrap_or(0)
|
|
1662
|
-
}
|
|
1663
|
-
|
|
1664
|
-
pub(crate) fn provider_doctor_checks() -> Value {
|
|
1665
|
-
let mut providers = serde_json::Map::new();
|
|
1666
|
-
for provider in [
|
|
1667
|
-
crate::provider::Provider::Claude,
|
|
1668
|
-
crate::provider::Provider::ClaudeCode,
|
|
1669
|
-
crate::provider::Provider::Codex,
|
|
1670
|
-
crate::provider::Provider::GeminiCli,
|
|
1671
|
-
crate::provider::Provider::Grok,
|
|
1672
|
-
crate::provider::Provider::Fake,
|
|
1673
|
-
] {
|
|
1674
|
-
let adapter = crate::provider::get_adapter(provider);
|
|
1675
|
-
let name = provider_wire(provider);
|
|
1676
|
-
let fake = matches!(provider, crate::provider::Provider::Fake);
|
|
1677
|
-
let (auth, version) = if fake {
|
|
1678
|
-
(crate::provider::AuthHintStatus::Present, "fake".to_string())
|
|
1679
|
-
} else {
|
|
1680
|
-
(
|
|
1681
|
-
crate::provider::AuthHintStatus::Unknown,
|
|
1682
|
-
"unknown".to_string(),
|
|
1683
|
-
)
|
|
1684
|
-
};
|
|
1685
|
-
providers.insert(
|
|
1686
|
-
name.to_string(),
|
|
1687
|
-
json!({
|
|
1688
|
-
"auth": auth,
|
|
1689
|
-
"command": provider_command(provider),
|
|
1690
|
-
"installed": adapter.is_installed(),
|
|
1691
|
-
"version": version,
|
|
1692
|
-
"probe_status": "not_run",
|
|
1693
|
-
"provider_probe_status": "not_run",
|
|
1694
|
-
}),
|
|
1695
|
-
);
|
|
1696
|
-
}
|
|
1697
|
-
#[cfg(unix)]
|
|
1698
|
-
for descriptor in crate::contract_runtime::registry::descriptors() {
|
|
1699
|
-
let identity = &descriptor.identity;
|
|
1700
|
-
// Inventory only: finding the launcher is not an engine, auth or readiness probe.
|
|
1701
|
-
providers.insert(
|
|
1702
|
-
identity.id.to_string(),
|
|
1703
|
-
json!({
|
|
1704
|
-
"auth": crate::provider::AuthHintStatus::Unknown,
|
|
1705
|
-
"command": identity.binary,
|
|
1706
|
-
"installed": crate::contract_runtime::discovery::executable(identity.binary).is_ok(),
|
|
1707
|
-
"version": "unknown",
|
|
1708
|
-
"probe_status": "not_run",
|
|
1709
|
-
"provider_probe_status": "not_run",
|
|
1710
|
-
}),
|
|
1711
|
-
);
|
|
1712
|
-
}
|
|
1713
|
-
Value::Object(providers)
|
|
1714
|
-
}
|
|
1715
|
-
|
|
1716
|
-
fn provider_command(provider: crate::provider::Provider) -> &'static str {
|
|
1717
|
-
match provider {
|
|
1718
|
-
crate::provider::Provider::Fake => "team-agent fake-worker",
|
|
1719
|
-
other => command_name(other),
|
|
1720
|
-
}
|
|
1721
|
-
}
|