@team-agent/installer 0.5.127 → 0.6.0

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