@team-agent/installer 0.5.128 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (436) hide show
  1. package/README.md +4 -4
  2. package/README.zh.md +1 -1
  3. package/package.json +4 -8
  4. package/skills/team-agent/SKILL.md +37 -20
  5. package/skills/team-agent/command-coverage.json +169 -183
  6. package/skills/team-agent/docs/reference/team-agent-operator.md +64 -30
  7. package/skills/team-agent/references/recovery-runbook.md +1 -1
  8. package/skills/team-agent/references/team-agent-operator.md +64 -30
  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 -1288
  15. package/crates/team-agent/src/cli/arguments.rs +0 -405
  16. package/crates/team-agent/src/cli/attach_app_server_leader.rs +0 -98
  17. package/crates/team-agent/src/cli/diagnose.rs +0 -1721
  18. package/crates/team-agent/src/cli/emit.rs +0 -2930
  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 -1216
  22. package/crates/team-agent/src/cli/intent/runtime_tests.rs +0 -912
  23. package/crates/team-agent/src/cli/intent/tests.rs +0 -689
  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 -6545
  29. package/crates/team-agent/src/cli/models.rs +0 -1206
  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/schedule.rs +0 -175
  34. package/crates/team-agent/src/cli/send/coordinator.rs +0 -164
  35. package/crates/team-agent/src/cli/send/mailbox.rs +0 -145
  36. package/crates/team-agent/src/cli/send/persist.rs +0 -156
  37. package/crates/team-agent/src/cli/send/presentation.rs +0 -370
  38. package/crates/team-agent/src/cli/send/resolve.rs +0 -573
  39. package/crates/team-agent/src/cli/send.rs +0 -199
  40. package/crates/team-agent/src/cli/shutdown_socket.rs +0 -288
  41. package/crates/team-agent/src/cli/spec.rs +0 -165
  42. package/crates/team-agent/src/cli/status.rs +0 -280
  43. package/crates/team-agent/src/cli/status_port/agents.rs +0 -358
  44. package/crates/team-agent/src/cli/status_port/approvals.rs +0 -79
  45. package/crates/team-agent/src/cli/status_port/brief.rs +0 -1981
  46. package/crates/team-agent/src/cli/status_port/compact.rs +0 -240
  47. package/crates/team-agent/src/cli/status_port/format.rs +0 -146
  48. package/crates/team-agent/src/cli/status_port/inbox.rs +0 -62
  49. package/crates/team-agent/src/cli/status_port/runtime.rs +0 -197
  50. package/crates/team-agent/src/cli/status_port/snapshot.rs +0 -208
  51. package/crates/team-agent/src/cli/status_port/store.rs +0 -416
  52. package/crates/team-agent/src/cli/status_port/tests.rs +0 -90
  53. package/crates/team-agent/src/cli/status_port.rs +0 -92
  54. package/crates/team-agent/src/cli/tests/base.rs +0 -885
  55. package/crates/team-agent/src/cli/tests/divergence.rs +0 -518
  56. package/crates/team-agent/src/cli/tests/lane_c.rs +0 -453
  57. package/crates/team-agent/src/cli/tests/leader_watch.rs +0 -322
  58. package/crates/team-agent/src/cli/tests/main_preserved.rs +0 -430
  59. package/crates/team-agent/src/cli/tests/missing_subcommands.rs +0 -336
  60. package/crates/team-agent/src/cli/tests/mod.rs +0 -137
  61. package/crates/team-agent/src/cli/tests/named_address.rs +0 -761
  62. package/crates/team-agent/src/cli/tests/parser_safety.rs +0 -383
  63. package/crates/team-agent/src/cli/tests/run_delegation.rs +0 -484
  64. package/crates/team-agent/src/cli/tests/shutdown_kill_plan.rs +0 -2179
  65. package/crates/team-agent/src/cli/tests/status_brief.rs +0 -1514
  66. package/crates/team-agent/src/cli/tests/status_send.rs +0 -888
  67. package/crates/team-agent/src/cli/tests/verb_install_skill.rs +0 -93
  68. package/crates/team-agent/src/cli/tests/verb_profile.rs +0 -392
  69. package/crates/team-agent/src/cli/triage.rs +0 -234
  70. package/crates/team-agent/src/cli/types.rs +0 -591
  71. package/crates/team-agent/src/codex_app_server.rs +0 -546
  72. package/crates/team-agent/src/communication_mode/mod.rs +0 -56
  73. package/crates/team-agent/src/compiler/tests.rs +0 -827
  74. package/crates/team-agent/src/compiler.rs +0 -890
  75. package/crates/team-agent/src/conpty/backend.rs +0 -829
  76. package/crates/team-agent/src/conpty/mod.rs +0 -33
  77. package/crates/team-agent/src/contract_runtime/backend.rs +0 -1744
  78. package/crates/team-agent/src/contract_runtime/commands.rs +0 -671
  79. package/crates/team-agent/src/contract_runtime/config.rs +0 -364
  80. package/crates/team-agent/src/contract_runtime/config_tests.rs +0 -76
  81. package/crates/team-agent/src/contract_runtime/discovery.rs +0 -449
  82. package/crates/team-agent/src/contract_runtime/fork.rs +0 -361
  83. package/crates/team-agent/src/contract_runtime/forward.rs +0 -288
  84. package/crates/team-agent/src/contract_runtime/framework.rs +0 -367
  85. package/crates/team-agent/src/contract_runtime/mcp.rs +0 -394
  86. package/crates/team-agent/src/contract_runtime/mod.rs +0 -17
  87. package/crates/team-agent/src/contract_runtime/prompt.rs +0 -216
  88. package/crates/team-agent/src/contract_runtime/pump.rs +0 -271
  89. package/crates/team-agent/src/contract_runtime/registry.rs +0 -553
  90. package/crates/team-agent/src/contract_runtime/workspace.rs +0 -228
  91. package/crates/team-agent/src/coordinator/backoff.rs +0 -741
  92. package/crates/team-agent/src/coordinator/conpty_shim.rs +0 -805
  93. package/crates/team-agent/src/coordinator/health.rs +0 -1185
  94. package/crates/team-agent/src/coordinator/mod.rs +0 -119
  95. package/crates/team-agent/src/coordinator/orphan.rs +0 -110
  96. package/crates/team-agent/src/coordinator/runtime_detectors.rs +0 -798
  97. package/crates/team-agent/src/coordinator/runtime_observation.rs +0 -84
  98. package/crates/team-agent/src/coordinator/steps/abnormal.rs +0 -2309
  99. package/crates/team-agent/src/coordinator/steps/delivery.rs +0 -15
  100. package/crates/team-agent/src/coordinator/steps/health_sync.rs +0 -15
  101. package/crates/team-agent/src/coordinator/steps/mod.rs +0 -126
  102. package/crates/team-agent/src/coordinator/steps/persist.rs +0 -15
  103. package/crates/team-agent/src/coordinator/steps/runtime_prompts.rs +0 -15
  104. package/crates/team-agent/src/coordinator/steps/session_gate.rs +0 -16
  105. package/crates/team-agent/src/coordinator/tests/a0_lostupdate.rs +0 -158
  106. package/crates/team-agent/src/coordinator/tests/abnormal.rs +0 -312
  107. package/crates/team-agent/src/coordinator/tests/api_error_recovery.rs +0 -300
  108. package/crates/team-agent/src/coordinator/tests/basics.rs +0 -211
  109. package/crates/team-agent/src/coordinator/tests/daemon.rs +0 -514
  110. package/crates/team-agent/src/coordinator/tests/energy.rs +0 -549
  111. package/crates/team-agent/src/coordinator/tests/health_sync.rs +0 -503
  112. package/crates/team-agent/src/coordinator/tests/main_preserved.rs +0 -186
  113. package/crates/team-agent/src/coordinator/tests/mod.rs +0 -295
  114. package/crates/team-agent/src/coordinator/tests/s3_bounded.rs +0 -207
  115. package/crates/team-agent/src/coordinator/tests/spine.rs +0 -308
  116. package/crates/team-agent/src/coordinator/tests/takeover.rs +0 -286
  117. package/crates/team-agent/src/coordinator/tests/tick_core.rs +0 -237
  118. package/crates/team-agent/src/coordinator/tick.rs +0 -3024
  119. package/crates/team-agent/src/coordinator/types.rs +0 -540
  120. package/crates/team-agent/src/db/agent_health_capture.rs +0 -126
  121. package/crates/team-agent/src/db/message_store.rs +0 -1527
  122. package/crates/team-agent/src/db/migration.rs +0 -984
  123. package/crates/team-agent/src/db/mod.rs +0 -26
  124. package/crates/team-agent/src/db/schema.rs +0 -663
  125. package/crates/team-agent/src/diagnose/comms.rs +0 -242
  126. package/crates/team-agent/src/diagnose/mod.rs +0 -44
  127. package/crates/team-agent/src/diagnose/orphans.rs +0 -889
  128. package/crates/team-agent/src/direct_delivery.rs +0 -368
  129. package/crates/team-agent/src/event_log.rs +0 -502
  130. package/crates/team-agent/src/fake_worker.rs +0 -303
  131. package/crates/team-agent/src/inbox_store.rs +0 -169
  132. package/crates/team-agent/src/kill_audit.rs +0 -106
  133. package/crates/team-agent/src/layout/manager.rs +0 -248
  134. package/crates/team-agent/src/layout/mod.rs +0 -36
  135. package/crates/team-agent/src/layout/overlay.rs +0 -134
  136. package/crates/team-agent/src/layout/placement.rs +0 -52
  137. package/crates/team-agent/src/layout/recovery.rs +0 -106
  138. package/crates/team-agent/src/layout/runtime_sessions.rs +0 -317
  139. package/crates/team-agent/src/layout/sessions.rs +0 -294
  140. package/crates/team-agent/src/layout/tmux_endpoint.rs +0 -165
  141. package/crates/team-agent/src/layout/worker_env.rs +0 -721
  142. package/crates/team-agent/src/layout/worker_window_helpers.rs +0 -37
  143. package/crates/team-agent/src/leader/helpers.rs +0 -178
  144. package/crates/team-agent/src/leader/incident.rs +0 -6
  145. package/crates/team-agent/src/leader/lease.rs +0 -3356
  146. package/crates/team-agent/src/leader/mod.rs +0 -104
  147. package/crates/team-agent/src/leader/owner_bind.rs +0 -400
  148. package/crates/team-agent/src/leader/prompt.rs +0 -905
  149. package/crates/team-agent/src/leader/provider_attribution.rs +0 -247
  150. package/crates/team-agent/src/leader/rediscover/tests.rs +0 -689
  151. package/crates/team-agent/src/leader/rediscover.rs +0 -1192
  152. package/crates/team-agent/src/leader/registry.rs +0 -888
  153. package/crates/team-agent/src/leader/start.rs +0 -4501
  154. package/crates/team-agent/src/leader/takeover.rs +0 -65
  155. package/crates/team-agent/src/leader/tests/basics.rs +0 -337
  156. package/crates/team-agent/src/leader/tests/byte_findings.rs +0 -355
  157. package/crates/team-agent/src/leader/tests/claim_leader_mailbox_flush_contract.rs +0 -544
  158. package/crates/team-agent/src/leader/tests/historical_inventory_upgrade_gate_red.rs +0 -624
  159. package/crates/team-agent/src/leader/tests/identity.rs +0 -465
  160. package/crates/team-agent/src/leader/tests/identity_session_names.rs +0 -42
  161. package/crates/team-agent/src/leader/tests/idle.rs +0 -113
  162. package/crates/team-agent/src/leader/tests/lease_api.rs +0 -520
  163. package/crates/team-agent/src/leader/tests/lease_claim.rs +0 -629
  164. package/crates/team-agent/src/leader/tests/mod.rs +0 -106
  165. package/crates/team-agent/src/leader/tests/prompt_contract.rs +0 -268
  166. package/crates/team-agent/src/leader/tests/rediscover.rs +0 -403
  167. package/crates/team-agent/src/leader/tests/rehomed_env.rs +0 -83
  168. package/crates/team-agent/src/leader/tests/team_in_team_state_scope_red.rs +0 -1273
  169. package/crates/team-agent/src/leader/tests/terminal_and_replay_vs_rerender_invariants_red.rs +0 -417
  170. package/crates/team-agent/src/leader/tests/wake_start_owner.rs +0 -168
  171. package/crates/team-agent/src/leader/types.rs +0 -534
  172. package/crates/team-agent/src/lib.rs +0 -147
  173. package/crates/team-agent/src/lifecycle/helpers.rs +0 -212
  174. package/crates/team-agent/src/lifecycle/launch/add_agent.rs +0 -881
  175. package/crates/team-agent/src/lifecycle/launch/add_agent_state.rs +0 -598
  176. package/crates/team-agent/src/lifecycle/launch/agent_state.rs +0 -332
  177. package/crates/team-agent/src/lifecycle/launch/clone_agent.rs +0 -204
  178. package/crates/team-agent/src/lifecycle/launch/fork_agent.rs +0 -107
  179. package/crates/team-agent/src/lifecycle/launch/fork_entry.rs +0 -144
  180. package/crates/team-agent/src/lifecycle/launch/identity.rs +0 -674
  181. package/crates/team-agent/src/lifecycle/launch/layout.rs +0 -350
  182. package/crates/team-agent/src/lifecycle/launch/leader_context.rs +0 -589
  183. package/crates/team-agent/src/lifecycle/launch/mcp_config.rs +0 -160
  184. package/crates/team-agent/src/lifecycle/launch/ownership.rs +0 -105
  185. package/crates/team-agent/src/lifecycle/launch/pi_mcp.rs +0 -899
  186. package/crates/team-agent/src/lifecycle/launch/pi_mcp_extension.js +0 -225
  187. package/crates/team-agent/src/lifecycle/launch/plan.rs +0 -269
  188. package/crates/team-agent/src/lifecycle/launch/quick_start.rs +0 -5200
  189. package/crates/team-agent/src/lifecycle/launch/quick_start_transport.rs +0 -368
  190. package/crates/team-agent/src/lifecycle/launch/readiness.rs +0 -519
  191. package/crates/team-agent/src/lifecycle/launch/role_source.rs +0 -287
  192. package/crates/team-agent/src/lifecycle/launch/spawn.rs +0 -473
  193. package/crates/team-agent/src/lifecycle/launch/spec_state.rs +0 -801
  194. package/crates/team-agent/src/lifecycle/launch/state_projection.rs +0 -624
  195. package/crates/team-agent/src/lifecycle/launch/worker_env.rs +0 -558
  196. package/crates/team-agent/src/lifecycle/launch.rs +0 -557
  197. package/crates/team-agent/src/lifecycle/lock.rs +0 -350
  198. package/crates/team-agent/src/lifecycle/mod.rs +0 -79
  199. package/crates/team-agent/src/lifecycle/pane_input_lock.rs +0 -239
  200. package/crates/team-agent/src/lifecycle/profile_launch.rs +0 -1067
  201. package/crates/team-agent/src/lifecycle/profile_smoke.rs +0 -557
  202. package/crates/team-agent/src/lifecycle/restart/agent.rs +0 -2199
  203. package/crates/team-agent/src/lifecycle/restart/avatar.rs +0 -1798
  204. package/crates/team-agent/src/lifecycle/restart/claude_fork.rs +0 -163
  205. package/crates/team-agent/src/lifecycle/restart/common.rs +0 -2362
  206. package/crates/team-agent/src/lifecycle/restart/orchestrator.rs +0 -65
  207. package/crates/team-agent/src/lifecycle/restart/preflight.rs +0 -113
  208. package/crates/team-agent/src/lifecycle/restart/rebuild.rs +0 -5135
  209. package/crates/team-agent/src/lifecycle/restart/remove.rs +0 -1504
  210. package/crates/team-agent/src/lifecycle/restart/selection.rs +0 -559
  211. package/crates/team-agent/src/lifecycle/restart/team_state.rs +0 -329
  212. package/crates/team-agent/src/lifecycle/restart.rs +0 -227
  213. package/crates/team-agent/src/lifecycle/role_config.rs +0 -1230
  214. package/crates/team-agent/src/lifecycle/tests/acceptance_b_batch_red.rs +0 -1021
  215. package/crates/team-agent/src/lifecycle/tests/agent_ops.rs +0 -1205
  216. package/crates/team-agent/src/lifecycle/tests/b0_legacy_snapshot_nonauthority_contract.rs +0 -265
  217. package/crates/team-agent/src/lifecycle/tests/b0_reader_hideone_audit_contract.rs +0 -490
  218. package/crates/team-agent/src/lifecycle/tests/behavioral_diff_264_red.rs +0 -656
  219. package/crates/team-agent/src/lifecycle/tests/claude_compatible_config_red.rs +0 -325
  220. package/crates/team-agent/src/lifecycle/tests/claude_profile_launch_red.rs +0 -447
  221. package/crates/team-agent/src/lifecycle/tests/cli_argv_routing_red.rs +0 -1638
  222. package/crates/team-agent/src/lifecycle/tests/clone_agent_preserves_source_tools.rs +0 -427
  223. package/crates/team-agent/src/lifecycle/tests/clone_fork_copilot_perms_red.rs +0 -770
  224. package/crates/team-agent/src/lifecycle/tests/communication_mode_runtime_contract_red.rs +0 -419
  225. package/crates/team-agent/src/lifecycle/tests/copilot_provider_red.rs +0 -2035
  226. package/crates/team-agent/src/lifecycle/tests/core.rs +0 -1327
  227. package/crates/team-agent/src/lifecycle/tests/f032_startup_prompt_best_effort_red.rs +0 -315
  228. package/crates/team-agent/src/lifecycle/tests/fixtures/pi_list_models_g0.stdout.txt +0 -222
  229. package/crates/team-agent/src/lifecycle/tests/fixtures/pi_list_models_spaced_ids.stdout.txt +0 -9
  230. package/crates/team-agent/src/lifecycle/tests/fixtures/pi_native_mcp_host.mjs +0 -72
  231. package/crates/team-agent/src/lifecycle/tests/gate_fixtures.rs +0 -562
  232. package/crates/team-agent/src/lifecycle/tests/grok_require_explicit_model_red.rs +0 -110
  233. package/crates/team-agent/src/lifecycle/tests/harvest2_a_batch_red.rs +0 -512
  234. package/crates/team-agent/src/lifecycle/tests/host_cotenant_death_p0_contract.rs +0 -921
  235. package/crates/team-agent/src/lifecycle/tests/issue238_codex_effort_contract.rs +0 -68
  236. package/crates/team-agent/src/lifecycle/tests/lane_ops.rs +0 -1851
  237. package/crates/team-agent/src/lifecycle/tests/launch_spawn.rs +0 -3983
  238. package/crates/team-agent/src/lifecycle/tests/lifecycle_lock.rs +0 -339
  239. package/crates/team-agent/src/lifecycle/tests/lifecycle_rollback_red.rs +0 -596
  240. package/crates/team-agent/src/lifecycle/tests/main_preserved.rs +0 -513
  241. package/crates/team-agent/src/lifecycle/tests/mcp_tool_name_format_red.rs +0 -69
  242. package/crates/team-agent/src/lifecycle/tests/phase_b_contracts.rs +0 -824
  243. package/crates/team-agent/src/lifecycle/tests/phase_golden.rs +0 -723
  244. package/crates/team-agent/src/lifecycle/tests/pi_catalog_red.rs +0 -164
  245. package/crates/team-agent/src/lifecycle/tests/pi_command_red.rs +0 -200
  246. package/crates/team-agent/src/lifecycle/tests/pi_compiler_red.rs +0 -210
  247. package/crates/team-agent/src/lifecycle/tests/pi_dual_entry_red.rs +0 -527
  248. package/crates/team-agent/src/lifecycle/tests/pi_executable_mcp_red.rs +0 -1062
  249. package/crates/team-agent/src/lifecycle/tests/pi_fork_session_inheritance_red.rs +0 -1419
  250. package/crates/team-agent/src/lifecycle/tests/pi_lifecycle_doctor_red.rs +0 -98
  251. package/crates/team-agent/src/lifecycle/tests/pi_native_mcp_capability_red.rs +0 -550
  252. package/crates/team-agent/src/lifecycle/tests/pi_session_delivery_red.rs +0 -226
  253. package/crates/team-agent/src/lifecycle/tests/quick_start_worker_readiness_red.rs +0 -332
  254. package/crates/team-agent/src/lifecycle/tests/realmachine_clusters_1_6_red.rs +0 -786
  255. package/crates/team-agent/src/lifecycle/tests/realmachine_residual_g1_g4_red.rs +0 -648
  256. package/crates/team-agent/src/lifecycle/tests/restart.rs +0 -185
  257. package/crates/team-agent/src/lifecycle/tests/restart_build_before_destroy_0540_contract.rs +0 -1053
  258. package/crates/team-agent/src/lifecycle/tests/restart_liveness_red.rs +0 -679
  259. package/crates/team-agent/src/lifecycle/tests/restart_rebind_hotfix_252_red.rs +0 -1126
  260. package/crates/team-agent/src/lifecycle/tests/restart_session_capture_red.rs +0 -153
  261. package/crates/team-agent/src/lifecycle/tests/resume_recover_red.rs +0 -427
  262. package/crates/team-agent/src/lifecycle/tests/stale_team_saveconflict_contract.rs +0 -431
  263. package/crates/team-agent/src/lifecycle/tests/startup_latency_contract.rs +0 -1066
  264. package/crates/team-agent/src/lifecycle/tests/status_credential_redaction_contract.rs +0 -876
  265. package/crates/team-agent/src/lifecycle/tests/subprep_codex_trust_roundtrip_red.rs +0 -1026
  266. package/crates/team-agent/src/lifecycle/tests/swallow_batch4_semantics_red.rs +0 -342
  267. package/crates/team-agent/src/lifecycle/tests/team_in_team_identity_scope_red.rs +0 -543
  268. package/crates/team-agent/src/lifecycle/tests/team_in_team_sibling_quick_start_red.rs +0 -1103
  269. package/crates/team-agent/src/lifecycle/tests/team_in_team_state_scope_red.rs +0 -1276
  270. package/crates/team-agent/src/lifecycle/tests/team_key_retirement_roster_red.rs +0 -145
  271. package/crates/team-agent/src/lifecycle/tests/team_key_retirement_txn_red.rs +0 -603
  272. package/crates/team-agent/src/lifecycle/tests/test_isolation_escape_contract.rs +0 -936
  273. package/crates/team-agent/src/lifecycle/tests/upgrade_compat_0211_red.rs +0 -970
  274. package/crates/team-agent/src/lifecycle/tests/verify_rs031_window_consistency_red.rs +0 -995
  275. package/crates/team-agent/src/lifecycle/tests/worker_spawn_env_red.rs +0 -836
  276. package/crates/team-agent/src/lifecycle/tests.rs +0 -105
  277. package/crates/team-agent/src/lifecycle/types.rs +0 -877
  278. package/crates/team-agent/src/lifecycle/worker_command_context.rs +0 -363
  279. package/crates/team-agent/src/main.rs +0 -52
  280. package/crates/team-agent/src/mcp_server/helpers.rs +0 -510
  281. package/crates/team-agent/src/mcp_server/lifecycle_tools/mod.rs +0 -6
  282. package/crates/team-agent/src/mcp_server/lifecycle_tools/state_status.rs +0 -43
  283. package/crates/team-agent/src/mcp_server/mod.rs +0 -119
  284. package/crates/team-agent/src/mcp_server/normalize.rs +0 -485
  285. package/crates/team-agent/src/mcp_server/readiness.rs +0 -527
  286. package/crates/team-agent/src/mcp_server/readiness_tests.rs +0 -348
  287. package/crates/team-agent/src/mcp_server/tests/golden.rs +0 -285
  288. package/crates/team-agent/src/mcp_server/tests/normalize.rs +0 -247
  289. package/crates/team-agent/src/mcp_server/tests/scoped.rs +0 -158
  290. package/crates/team-agent/src/mcp_server/tests/send.rs +0 -353
  291. package/crates/team-agent/src/mcp_server/tests/tools.rs +0 -341
  292. package/crates/team-agent/src/mcp_server/tests/wire.rs +0 -254
  293. package/crates/team-agent/src/mcp_server/tests.rs +0 -43
  294. package/crates/team-agent/src/mcp_server/tools.rs +0 -889
  295. package/crates/team-agent/src/mcp_server/types.rs +0 -396
  296. package/crates/team-agent/src/mcp_server/wire.rs +0 -867
  297. package/crates/team-agent/src/messaging/activity.rs +0 -461
  298. package/crates/team-agent/src/messaging/address.rs +0 -87
  299. package/crates/team-agent/src/messaging/delivery.rs +0 -3727
  300. package/crates/team-agent/src/messaging/delivery_consumption_tests.rs +0 -234
  301. package/crates/team-agent/src/messaging/enter_rescue.rs +0 -362
  302. package/crates/team-agent/src/messaging/enter_rescue_tests.rs +0 -633
  303. package/crates/team-agent/src/messaging/helpers.rs +0 -336
  304. package/crates/team-agent/src/messaging/leader_channel.rs +0 -287
  305. package/crates/team-agent/src/messaging/leader_receiver.rs +0 -786
  306. package/crates/team-agent/src/messaging/mod.rs +0 -167
  307. package/crates/team-agent/src/messaging/persist.rs +0 -377
  308. package/crates/team-agent/src/messaging/presentation.rs +0 -417
  309. package/crates/team-agent/src/messaging/reminders.rs +0 -316
  310. package/crates/team-agent/src/messaging/results/collection_tests.rs +0 -719
  311. package/crates/team-agent/src/messaging/results.rs +0 -1415
  312. package/crates/team-agent/src/messaging/scheduler.rs +0 -223
  313. package/crates/team-agent/src/messaging/selftest.rs +0 -315
  314. package/crates/team-agent/src/messaging/send.rs +0 -981
  315. package/crates/team-agent/src/messaging/tests/basic.rs +0 -346
  316. package/crates/team-agent/src/messaging/tests/dup_inject.rs +0 -657
  317. package/crates/team-agent/src/messaging/tests/e23.rs +0 -49
  318. package/crates/team-agent/src/messaging/tests/leader_channel.rs +0 -169
  319. package/crates/team-agent/src/messaging/tests/leader_inject_acceptance.rs +0 -817
  320. package/crates/team-agent/src/messaging/tests/main_preserved.rs +0 -85
  321. package/crates/team-agent/src/messaging/tests/mod.rs +0 -306
  322. package/crates/team-agent/src/messaging/tests/runtime.rs +0 -3549
  323. package/crates/team-agent/src/messaging/tests/spine.rs +0 -853
  324. package/crates/team-agent/src/messaging/tests/wave2.rs +0 -381
  325. package/crates/team-agent/src/messaging/trust.rs +0 -215
  326. package/crates/team-agent/src/messaging/types.rs +0 -472
  327. package/crates/team-agent/src/messaging/wait.rs +0 -366
  328. package/crates/team-agent/src/messaging/watchers.rs +0 -916
  329. package/crates/team-agent/src/model/enums.rs +0 -356
  330. package/crates/team-agent/src/model/errors.rs +0 -18
  331. package/crates/team-agent/src/model/ids.rs +0 -165
  332. package/crates/team-agent/src/model/mod.rs +0 -29
  333. package/crates/team-agent/src/model/name_similarity.rs +0 -252
  334. package/crates/team-agent/src/model/pane_authority_refusal.rs +0 -359
  335. package/crates/team-agent/src/model/paths.rs +0 -257
  336. package/crates/team-agent/src/model/routing.rs +0 -387
  337. package/crates/team-agent/src/model/spec.rs +0 -1184
  338. package/crates/team-agent/src/model/task_graph.rs +0 -321
  339. package/crates/team-agent/src/model/testdata/fuzz.golden.yaml +0 -43
  340. package/crates/team-agent/src/model/testdata/fuzz.yaml +0 -43
  341. package/crates/team-agent/src/model/testdata/spec_invalid_a.yaml +0 -209
  342. package/crates/team-agent/src/model/testdata/team.spec.golden.yaml +0 -208
  343. package/crates/team-agent/src/model/testdata/team.spec.yaml +0 -208
  344. package/crates/team-agent/src/model/yaml/tests.rs +0 -188
  345. package/crates/team-agent/src/model/yaml.rs +0 -802
  346. package/crates/team-agent/src/os_probe.rs +0 -280
  347. package/crates/team-agent/src/packaging/install.rs +0 -219
  348. package/crates/team-agent/src/packaging/migrate.rs +0 -38
  349. package/crates/team-agent/src/packaging/mod.rs +0 -91
  350. package/crates/team-agent/src/packaging/repair.rs +0 -33
  351. package/crates/team-agent/src/packaging/tests.rs +0 -822
  352. package/crates/team-agent/src/packaging/types.rs +0 -417
  353. package/crates/team-agent/src/platform/argv.rs +0 -331
  354. package/crates/team-agent/src/platform/errors.rs +0 -104
  355. package/crates/team-agent/src/platform/file_lock.rs +0 -279
  356. package/crates/team-agent/src/platform/mod.rs +0 -5
  357. package/crates/team-agent/src/platform/process.rs +0 -545
  358. package/crates/team-agent/src/provider/adapter.rs +0 -1150
  359. package/crates/team-agent/src/provider/adapters/claude.rs +0 -78
  360. package/crates/team-agent/src/provider/adapters/claude_fork.rs +0 -131
  361. package/crates/team-agent/src/provider/adapters/copilot.rs +0 -75
  362. package/crates/team-agent/src/provider/adapters/copilot_fork.rs +0 -307
  363. package/crates/team-agent/src/provider/adapters/fake.rs +0 -18
  364. package/crates/team-agent/src/provider/adapters/mod.rs +0 -30
  365. package/crates/team-agent/src/provider/adapters/pi.rs +0 -106
  366. package/crates/team-agent/src/provider/approvals/mod.rs +0 -3
  367. package/crates/team-agent/src/provider/approvals/parsing.rs +0 -586
  368. package/crates/team-agent/src/provider/approvals/runtime_prompts.rs +0 -205
  369. package/crates/team-agent/src/provider/argv_route.rs +0 -405
  370. package/crates/team-agent/src/provider/bypass_flags.rs +0 -116
  371. package/crates/team-agent/src/provider/classify.rs +0 -708
  372. package/crates/team-agent/src/provider/command_helpers.rs +0 -45
  373. package/crates/team-agent/src/provider/faults.rs +0 -165
  374. package/crates/team-agent/src/provider/helpers.rs +0 -52
  375. package/crates/team-agent/src/provider/mod.rs +0 -78
  376. package/crates/team-agent/src/provider/model_catalog.rs +0 -910
  377. package/crates/team-agent/src/provider/session/capture.rs +0 -2731
  378. package/crates/team-agent/src/provider/session/context_fork/claude.rs +0 -123
  379. package/crates/team-agent/src/provider/session/context_fork/outcome.rs +0 -172
  380. package/crates/team-agent/src/provider/session/context_fork.rs +0 -396
  381. package/crates/team-agent/src/provider/session/mod.rs +0 -36
  382. package/crates/team-agent/src/provider/session/resume.rs +0 -269
  383. package/crates/team-agent/src/provider/session_scan/claude.rs +0 -523
  384. package/crates/team-agent/src/provider/session_scan/common/tests.rs +0 -316
  385. package/crates/team-agent/src/provider/session_scan/common.rs +0 -654
  386. package/crates/team-agent/src/provider/session_scan/copilot.rs +0 -280
  387. package/crates/team-agent/src/provider/session_scan/pi.rs +0 -185
  388. package/crates/team-agent/src/provider/session_scan.rs +0 -71
  389. package/crates/team-agent/src/provider/startup_prompt.rs +0 -757
  390. package/crates/team-agent/src/provider/submit_now.rs +0 -71
  391. package/crates/team-agent/src/provider/testdata/copilot-ready-marker.txt +0 -5
  392. package/crates/team-agent/src/provider/testdata/copilot-trust-prompt.txt +0 -19
  393. package/crates/team-agent/src/provider/testdata/grok-models-authenticated.stdout +0 -9
  394. package/crates/team-agent/src/provider/testdata/grok-models-unauthenticated.stdout +0 -7
  395. package/crates/team-agent/src/provider/tests/adapter.rs +0 -441
  396. package/crates/team-agent/src/provider/tests/classify.rs +0 -148
  397. package/crates/team-agent/src/provider/tests/command_helpers.rs +0 -35
  398. package/crates/team-agent/src/provider/tests/copilot_fork.rs +0 -191
  399. package/crates/team-agent/src/provider/tests/faults.rs +0 -200
  400. package/crates/team-agent/src/provider/tests/idle.rs +0 -177
  401. package/crates/team-agent/src/provider/tests/wire.rs +0 -213
  402. package/crates/team-agent/src/provider/tests.rs +0 -32
  403. package/crates/team-agent/src/provider/types.rs +0 -529
  404. package/crates/team-agent/src/provider/wire.rs +0 -394
  405. package/crates/team-agent/src/redaction.rs +0 -259
  406. package/crates/team-agent/src/state/abnormal_watch/tests/mod.rs +0 -248
  407. package/crates/team-agent/src/state/abnormal_watch.rs +0 -144
  408. package/crates/team-agent/src/state/identity.rs +0 -914
  409. package/crates/team-agent/src/state/identity_keys.rs +0 -132
  410. package/crates/team-agent/src/state/mod.rs +0 -74
  411. package/crates/team-agent/src/state/owner_gate.rs +0 -482
  412. package/crates/team-agent/src/state/ownership.rs +0 -563
  413. package/crates/team-agent/src/state/paths.rs +0 -395
  414. package/crates/team-agent/src/state/persist.rs +0 -3811
  415. package/crates/team-agent/src/state/projection.rs +0 -1508
  416. package/crates/team-agent/src/state/repository/intent.rs +0 -14
  417. package/crates/team-agent/src/state/repository/tests.rs +0 -184
  418. package/crates/team-agent/src/state/repository.rs +0 -866
  419. package/crates/team-agent/src/state/selector.rs +0 -160
  420. package/crates/team-agent/src/state/testdata/state-rich.canonical.json +0 -133
  421. package/crates/team-agent/src/test_support/models_timeout_fixture.rs +0 -144
  422. package/crates/team-agent/src/tmux_backend/enter_rescue.rs +0 -325
  423. package/crates/team-agent/src/tmux_backend/enter_rescue_tests.rs +0 -432
  424. package/crates/team-agent/src/tmux_backend/native_input.rs +0 -513
  425. package/crates/team-agent/src/tmux_backend/native_input_tests.rs +0 -742
  426. package/crates/team-agent/src/tmux_backend/tests.rs +0 -4103
  427. package/crates/team-agent/src/tmux_backend.rs +0 -4492
  428. package/crates/team-agent/src/topology.rs +0 -537
  429. package/crates/team-agent/src/transport/enter_rescue.rs +0 -166
  430. package/crates/team-agent/src/transport/native_input.rs +0 -491
  431. package/crates/team-agent/src/transport/test_support.rs +0 -743
  432. package/crates/team-agent/src/transport/tests/behavior.rs +0 -326
  433. package/crates/team-agent/src/transport/tests/mod.rs +0 -194
  434. package/crates/team-agent/src/transport/tests/wire.rs +0 -574
  435. package/crates/team-agent/src/transport.rs +0 -1655
  436. package/crates/team-agent/src/transport_factory.rs +0 -819
@@ -1,888 +0,0 @@
1
- //!
2
- //! Phase-DX E7 (0.5.9 host-leader-registry-design): file-per-leader discovery index.
3
- //!
4
- //! Location: `~/.team-agent/leaders/<workspace_hash>__<team_key>.json`.
5
- //!
6
- //! Registry entries are a **derived** discovery index — never a source of
7
- //! authority. Read paths must always canonical-validate a resolved entry
8
- //! against the target workspace's runtime state (leader_receiver,
9
- //! owner_epoch, transport_kind) before delivering. Ambiguous short names
10
- //! are refused (`name_ambiguous`) rather than resolved by any priority
11
- //! heuristic.
12
- //!
13
- //! Design constraints (host-leader-registry-design.md §§3, 9):
14
- //! - No shared/global relational store (file-per-team on the host filesystem).
15
- //! - No identity writes on read/send paths — write only happens from
16
- //! `claim-leader`/`attach-leader`/`takeover`/`attach-app-server-leader`
17
- //! canonical success hooks and shutdown/unregister on canonical success.
18
- //! - Registry write failure never fails the underlying binding command;
19
- //! it is discoverability degradation, not binding failure.
20
-
21
- #![deny(clippy::unwrap_used, clippy::expect_used, clippy::panic)]
22
-
23
- use std::fmt;
24
- use std::path::{Path, PathBuf};
25
- use std::time::{Duration, Instant};
26
-
27
- use serde::{Deserialize, Serialize};
28
- use serde_json::{json, Value};
29
- use sha2::{Digest, Sha256};
30
-
31
- use crate::transport::Transport;
32
-
33
- /// Current file schema_version for `~/.team-agent/leaders/*.json`.
34
- pub const REGISTRY_SCHEMA_VERSION: u32 = 1;
35
-
36
- /// Event name emitted after a successful atomic temp+rename write.
37
- pub const EVENT_REGISTERED: &str = "leader_registry.registered";
38
-
39
- /// Event name emitted when the write step (fs::write / rename / dir create)
40
- /// failed — the binding command still returns ok, but discoverability
41
- /// degrades until the next successful canonical hook.
42
- pub const EVENT_WRITE_FAILED: &str = "leader_registry.write_failed";
43
-
44
- /// Event name emitted when a canonical shutdown/unbind removed the entry.
45
- pub const EVENT_UNREGISTERED: &str = "leader_registry.unregistered";
46
-
47
- /// v1 file schema. Fields are copied verbatim from `LeaderRegistryEntry`
48
- /// during atomic writes; readers deserialize the same shape then validate
49
- /// against canonical state before using any field for routing.
50
- #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
51
- pub struct LeaderRegistryEntry {
52
- pub schema_version: u32,
53
- /// Default delivery name — the runtime `team_key`. Never the display or
54
- /// spec name (host-leader-registry-design.md §5.1).
55
- pub delivery_name: String,
56
- /// Human-friendly qualified name: `<workspace_short>/<team_key>`.
57
- pub qualified_name: String,
58
- /// Stable qualified name: `<workspace_hash>/<team_key>`. Always accepted
59
- /// by resolvers even when the human form is ambiguous.
60
- pub stable_qualified_name: String,
61
- /// Explicit aliases attached at binding time. Alias collisions follow
62
- /// the same `name_ambiguous` rule as delivery_name collisions.
63
- pub aliases: Vec<String>,
64
- pub workspace: PathBuf,
65
- /// sha256-prefix of canonical realpath workspace; used only as a file
66
- /// name component and stable identifier — never an authority key.
67
- pub workspace_hash: String,
68
- pub workspace_short: String,
69
- pub team_key: String,
70
- pub transport_kind: String,
71
- pub channel: serde_json::Value,
72
- pub owner_epoch: u64,
73
- pub attached_at: String,
74
- pub updated_at: String,
75
- pub source: String,
76
- pub status: String,
77
- }
78
-
79
- impl LeaderRegistryEntry {
80
- /// Ambiguous-name refusal semantics (host-leader-registry-design.md §5.2):
81
- /// two entries with the same `delivery_name` remain visible in
82
- /// `leaders` under `ambiguous_names`, and `send --to-leader <short>`
83
- /// refuses `name_ambiguous`. Callers surface the ambiguity via
84
- /// candidates rather than choosing a winner. The design explicitly
85
- /// forbids priority heuristics based on write order, modification
86
- /// time, or ambient state — see host-leader-registry-design.md §5.2
87
- /// for the enumerated exclusions.
88
- #[must_use]
89
- pub fn short_name_collision_refuses() -> &'static str {
90
- "ambiguous"
91
- }
92
- }
93
-
94
- /// Payload key for the list of short-name collisions surfaced by
95
- /// `team-agent leaders` — kept as a top-level constant so both `leaders`
96
- /// and `send --to-leader` refer to the same wire name.
97
- pub const AMBIGUOUS_NAMES_FIELD: &str = "ambiguous_names";
98
-
99
- /// Wire reason used by both `leaders` and `send --to-leader` when a name
100
- /// resolves to multiple canonical-live entries. Candidates carry
101
- /// `workspace_hash` + `stable_qualified_name` so the caller can retry with
102
- /// a fully-qualified form.
103
- pub const REASON_AMBIGUOUS: &str = "name_ambiguous";
104
-
105
- #[derive(Debug, Clone, Copy, PartialEq, Eq)]
106
- pub enum RegistryRollback {
107
- Restored,
108
- Superseded,
109
- }
110
-
111
- #[derive(Debug, Clone, Copy, PartialEq, Eq)]
112
- pub enum RegistryRollbackError {
113
- InvalidReceipt,
114
- LockUnavailable,
115
- ReadFailed,
116
- RestoreFailed,
117
- DeleteFailed,
118
- }
119
-
120
- impl fmt::Display for RegistryRollbackError {
121
- fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
122
- let reason = match self {
123
- Self::InvalidReceipt => "invalid receipt",
124
- Self::LockUnavailable => "registry lock unavailable",
125
- Self::ReadFailed => "registry receipt read failed",
126
- Self::RestoreFailed => "registry restore failed",
127
- Self::DeleteFailed => "registry delete failed",
128
- };
129
- f.write_str(reason)
130
- }
131
- }
132
-
133
- #[derive(Debug, Clone, PartialEq, Eq)]
134
- pub struct RegistryWriteReceipt {
135
- pub path: PathBuf,
136
- pub bytes: Vec<u8>,
137
- }
138
-
139
- #[derive(Debug, Clone, PartialEq, Eq)]
140
- pub struct RegistryWriteOutcome {
141
- pub status: &'static str,
142
- pub path: Option<PathBuf>,
143
- pub receipt: Option<RegistryWriteReceipt>,
144
- pub team_key: String,
145
- pub workspace_hash: String,
146
- pub source: String,
147
- pub owner_epoch: u64,
148
- }
149
-
150
- impl RegistryWriteOutcome {
151
- #[must_use]
152
- pub fn response_json(&self) -> Value {
153
- match &self.path {
154
- Some(path) => json!({"status": self.status, "path": path.display().to_string()}),
155
- None => json!({"status": self.status}),
156
- }
157
- }
158
- }
159
-
160
- /// Absolute path to `~/.team-agent/leaders`. Returns `None` when the
161
- /// caller has no HOME (e.g. some CI shells) — callers should treat this as
162
- /// "no registry" rather than an error, since registry is derived.
163
- #[must_use]
164
- pub fn registry_dir() -> Option<PathBuf> {
165
- let home = std::env::var_os("HOME").map(PathBuf::from)?;
166
- Some(home.join(".team-agent").join("leaders"))
167
- }
168
-
169
- /// Compute the sha256 hex prefix (12 chars) of a canonical workspace path.
170
- /// The canonical form is used so equivalent paths (symlinks, `.`, etc.)
171
- /// map to the same discovery id. If canonicalize fails the input path is
172
- /// used verbatim — the hash is a stable label, not an authority key.
173
- #[must_use]
174
- pub fn workspace_hash(workspace: &Path) -> String {
175
- let canonical = std::fs::canonicalize(workspace).unwrap_or_else(|_| workspace.to_path_buf());
176
- let mut hasher = Sha256::new();
177
- hasher.update(canonical.to_string_lossy().as_bytes());
178
- let digest = hasher.finalize();
179
- digest[..6]
180
- .iter()
181
- .map(|byte| format!("{byte:02x}"))
182
- .collect()
183
- }
184
-
185
- /// Compute the discovery-visible short label for a workspace path —
186
- /// basename by default, "workspace" when the path has no name component.
187
- #[must_use]
188
- fn workspace_short(workspace: &Path) -> String {
189
- workspace
190
- .file_name()
191
- .and_then(|s| s.to_str())
192
- .map(str::to_string)
193
- .unwrap_or_else(|| "workspace".to_string())
194
- }
195
-
196
- /// Assemble a schema-v1 entry from canonical binding fields. Callers use
197
- /// this from the binding-command success hooks; the entry then flows into
198
- /// [`write_entry_best_effort`].
199
- #[must_use]
200
- #[allow(clippy::too_many_arguments)]
201
- pub fn build_entry(
202
- workspace: &Path,
203
- team_key: &str,
204
- transport_kind: &str,
205
- channel: serde_json::Value,
206
- owner_epoch: u64,
207
- source: &str,
208
- now_rfc3339: String,
209
- ) -> LeaderRegistryEntry {
210
- let hash = workspace_hash(workspace);
211
- let short = workspace_short(workspace);
212
- LeaderRegistryEntry {
213
- schema_version: REGISTRY_SCHEMA_VERSION,
214
- delivery_name: team_key.to_string(),
215
- qualified_name: format!("{short}/{team_key}"),
216
- stable_qualified_name: format!("{hash}/{team_key}"),
217
- aliases: Vec::new(),
218
- workspace: std::fs::canonicalize(workspace).unwrap_or_else(|_| workspace.to_path_buf()),
219
- workspace_hash: hash,
220
- workspace_short: short,
221
- team_key: team_key.to_string(),
222
- transport_kind: transport_kind.to_string(),
223
- channel,
224
- owner_epoch,
225
- attached_at: now_rfc3339.clone(),
226
- updated_at: now_rfc3339,
227
- source: source.to_string(),
228
- status: "attached".to_string(),
229
- }
230
- }
231
-
232
- /// After a canonical leader binding succeeds, write the derived host
233
- /// discovery entry from the just-persisted state. Registry failure is
234
- /// non-fatal: callers get a write_failed outcome and the binding remains
235
- /// successful.
236
- pub fn register_binding_from_state_best_effort(
237
- workspace: &Path,
238
- team: Option<&str>,
239
- source: &str,
240
- ) -> Option<RegistryWriteOutcome> {
241
- let Ok(state) = crate::state::persist::load_runtime_state_without_migrations(workspace) else {
242
- return None;
243
- };
244
- let team_key = match team.filter(|team| !team.is_empty()) {
245
- Some(team) => team.to_string(),
246
- None => crate::state::projection::team_state_key(&state),
247
- };
248
- let receiver = state
249
- .get("teams")
250
- .and_then(|value| value.as_object())
251
- .and_then(|teams| teams.get(&team_key))
252
- .and_then(|team| team.get("leader_receiver"))
253
- .or_else(|| state.get("leader_receiver"))
254
- .cloned()?;
255
- let transport_kind = receiver
256
- .get("transport_kind")
257
- .and_then(Value::as_str)
258
- .unwrap_or("direct_tmux")
259
- .to_string();
260
- let owner_epoch = receiver
261
- .get("owner_epoch")
262
- .and_then(Value::as_u64)
263
- .or_else(|| {
264
- state
265
- .get("teams")
266
- .and_then(|value| value.as_object())
267
- .and_then(|teams| teams.get(&team_key))
268
- .and_then(|team| team.get("owner_epoch"))
269
- .and_then(Value::as_u64)
270
- })
271
- .unwrap_or(0);
272
- let entry = build_entry(
273
- workspace,
274
- &team_key,
275
- &transport_kind,
276
- receiver,
277
- owner_epoch,
278
- source,
279
- chrono::Utc::now().to_rfc3339(),
280
- );
281
- let event_log = crate::event_log::EventLog::new(workspace);
282
- let write_receipt = write_entry_best_effort_with_receipt(&entry);
283
- let write_result = write_receipt.as_ref().map(|receipt| receipt.path.clone());
284
- let status = if let Some(path) = &write_result {
285
- let _ = event_log.write(
286
- EVENT_REGISTERED,
287
- json!({
288
- "path": path.display().to_string(),
289
- "team_key": team_key,
290
- "workspace_hash": entry.workspace_hash,
291
- "source": source,
292
- }),
293
- );
294
- "registered"
295
- } else {
296
- let _ = event_log.write(
297
- EVENT_WRITE_FAILED,
298
- json!({
299
- "team_key": team_key,
300
- "workspace_hash": entry.workspace_hash,
301
- "source": source,
302
- }),
303
- );
304
- "write_failed"
305
- };
306
- Some(RegistryWriteOutcome {
307
- status,
308
- path: write_result,
309
- receipt: write_receipt,
310
- team_key,
311
- workspace_hash: entry.workspace_hash,
312
- source: source.to_string(),
313
- owner_epoch: entry.owner_epoch,
314
- })
315
- }
316
-
317
- fn entry_filename(entry: &LeaderRegistryEntry) -> String {
318
- format!("{}__{}.json", entry.workspace_hash, entry.team_key)
319
- }
320
-
321
- /// Registry write is best-effort. Writes to `.<file>.tmp-<pid>-<counter>`
322
- /// first, then atomically renames to `<workspace_hash>__<team_key>.json`.
323
- /// Every writer uses the registry lock so conditional rollback can compare
324
- /// and restore without racing a concurrent publish.
325
- pub fn write_entry_best_effort(entry: &LeaderRegistryEntry) -> Option<PathBuf> {
326
- write_entry_best_effort_with_receipt(entry).map(|receipt| receipt.path)
327
- }
328
-
329
- fn write_entry_best_effort_with_receipt(
330
- entry: &LeaderRegistryEntry,
331
- ) -> Option<RegistryWriteReceipt> {
332
- with_registry_lock(|dir| write_entry_locked(dir, entry)).flatten()
333
- }
334
-
335
- fn write_entry_locked(dir: &Path, entry: &LeaderRegistryEntry) -> Option<RegistryWriteReceipt> {
336
- let final_path = dir.join(entry_filename(entry));
337
- let tmp_name = format!(
338
- ".{}.tmp-{}-{}",
339
- entry_filename(entry),
340
- std::process::id(),
341
- rand_suffix()
342
- );
343
- let tmp_path = dir.join(tmp_name);
344
- let serialized = serde_json::to_vec_pretty(entry).ok()?;
345
- if std::fs::write(&tmp_path, &serialized).is_err() {
346
- let _ = std::fs::remove_file(&tmp_path);
347
- return None;
348
- }
349
- if std::fs::rename(&tmp_path, &final_path).is_err() {
350
- let _ = std::fs::remove_file(&tmp_path);
351
- return None;
352
- }
353
- Some(RegistryWriteReceipt {
354
- path: final_path,
355
- bytes: serialized,
356
- })
357
- }
358
-
359
- /// Restore one registry path only when it still contains this writer's exact
360
- /// receipt. The comparison and restore/delete are held under the same lock as
361
- /// ordinary registry writers, so a winner cannot slip in between them.
362
- pub fn restore_entry_if_current_matches(
363
- receipt: &RegistryWriteReceipt,
364
- previous: Option<&[u8]>,
365
- ) -> Result<RegistryRollback, RegistryRollbackError> {
366
- with_registry_lock_result(|dir| {
367
- if receipt.path.parent() != Some(dir) {
368
- return Err(RegistryRollbackError::InvalidReceipt);
369
- }
370
- let current =
371
- std::fs::read(&receipt.path).map_err(|_| RegistryRollbackError::ReadFailed)?;
372
- if current != receipt.bytes {
373
- return Ok(RegistryRollback::Superseded);
374
- }
375
- match previous {
376
- Some(bytes) if replace_entry_bytes_locked(&receipt.path, bytes) => {
377
- Ok(RegistryRollback::Restored)
378
- }
379
- Some(_) => Err(RegistryRollbackError::RestoreFailed),
380
- None if std::fs::remove_file(&receipt.path).is_ok() => Ok(RegistryRollback::Restored),
381
- None => Err(RegistryRollbackError::DeleteFailed),
382
- }
383
- })
384
- }
385
-
386
- #[derive(Debug, Clone, PartialEq, Eq)]
387
- pub struct RegistryPruneItem {
388
- pub workspace: PathBuf,
389
- pub team_key: String,
390
- pub reason: String,
391
- }
392
-
393
- #[derive(Debug, Clone, PartialEq, Eq)]
394
- pub struct RegistryPruneReport {
395
- pub dry_run: bool,
396
- pub candidates: Vec<RegistryPruneItem>,
397
- pub removed: Vec<RegistryPruneItem>,
398
- pub kept: Vec<RegistryPruneItem>,
399
- pub skipped: Vec<RegistryPruneItem>,
400
- pub errors: Vec<RegistryPruneItem>,
401
- }
402
-
403
- #[derive(Debug, Clone, Copy, PartialEq, Eq)]
404
- enum PruneAttempt {
405
- Removed,
406
- Skipped(&'static str),
407
- Error,
408
- }
409
-
410
- fn prune_item(entry: &LeaderRegistryEntry, reason: impl Into<String>) -> RegistryPruneItem {
411
- RegistryPruneItem {
412
- workspace: entry.workspace.clone(),
413
- team_key: entry.team_key.clone(),
414
- reason: reason.into(),
415
- }
416
- }
417
-
418
- fn prune_reason_from_state(entry: &LeaderRegistryEntry, state: &Value) -> Option<&'static str> {
419
- let (status, reason) = classify_loaded(entry, state);
420
- if status != "STALE" {
421
- return None;
422
- }
423
- match reason.as_deref() {
424
- Some("team_key_not_found") => Some("team_key_not_found"),
425
- Some("team_not_alive") => Some("team_not_alive"),
426
- _ => None,
427
- }
428
- }
429
-
430
- fn prune_reason(
431
- entry: &LeaderRegistryEntry,
432
- status: &str,
433
- reason: Option<&str>,
434
- ) -> Option<&'static str> {
435
- if status != "STALE" || !crate::state::persist::runtime_state_path(&entry.workspace).is_file() {
436
- // A missing state file is unavailable rather than proof that the
437
- // workspace was retired. Only an existing, readable canonical state
438
- // can authorize the team-key cleanup below.
439
- return None;
440
- }
441
- match reason {
442
- Some("team_key_not_found") => Some("team_key_not_found"),
443
- Some("team_not_alive") => Some("team_not_alive"),
444
- _ => None,
445
- }
446
- }
447
-
448
- fn prune_entry_if_current(
449
- path: &Path,
450
- expected: &LeaderRegistryEntry,
451
- snapshot: &[u8],
452
- ) -> PruneAttempt {
453
- let result = crate::state::persist::with_runtime_state_lock_without_migrations(
454
- &expected.workspace,
455
- |state| {
456
- let Some(state) = state.as_ref() else {
457
- return PruneAttempt::Skipped("canonical_state_unavailable");
458
- };
459
- // Lock ordering is canonical state -> host registry. The state
460
- // remains unchanged while the exact registry bytes are checked.
461
- with_registry_lock(|_| {
462
- let Ok(bytes) = std::fs::read(path) else {
463
- return PruneAttempt::Skipped("registry_entry_missing");
464
- };
465
- if bytes != snapshot {
466
- return PruneAttempt::Skipped("registry_entry_changed");
467
- }
468
- let Ok(current) = serde_json::from_slice::<LeaderRegistryEntry>(&bytes) else {
469
- return PruneAttempt::Skipped("registry_entry_changed");
470
- };
471
- if current != *expected {
472
- return PruneAttempt::Skipped("registry_entry_changed");
473
- }
474
- if prune_reason_from_state(&current, state).is_none() {
475
- return PruneAttempt::Skipped("canonical_state_changed");
476
- }
477
- if std::fs::remove_file(path).is_ok() {
478
- PruneAttempt::Removed
479
- } else {
480
- PruneAttempt::Error
481
- }
482
- })
483
- .unwrap_or(PruneAttempt::Skipped("registry_lock_unavailable"))
484
- },
485
- );
486
- result.unwrap_or(PruneAttempt::Skipped("canonical_state_unavailable"))
487
- }
488
-
489
- fn replace_entry_bytes_locked(path: &Path, bytes: &[u8]) -> bool {
490
- let tmp = path.with_extension(format!("rollback-{}-{}", std::process::id(), rand_suffix()));
491
- if std::fs::write(&tmp, bytes).is_err() {
492
- let _ = std::fs::remove_file(&tmp);
493
- return false;
494
- }
495
- if std::fs::rename(&tmp, path).is_err() {
496
- let _ = std::fs::remove_file(&tmp);
497
- return false;
498
- }
499
- true
500
- }
501
-
502
- struct RegistryLock {
503
- file: std::fs::File,
504
- }
505
-
506
- impl RegistryLock {
507
- fn acquire(dir: &Path) -> Option<Self> {
508
- let path = dir.join(".registry.lock");
509
- let file = std::fs::OpenOptions::new()
510
- .create(true)
511
- .read(true)
512
- .write(true)
513
- .truncate(false)
514
- .open(path)
515
- .ok()?;
516
- let started = Instant::now();
517
- loop {
518
- match crate::platform::file_lock::try_lock_once_nonblocking(&file) {
519
- Ok(true) => return Some(Self { file }),
520
- Ok(false) if started.elapsed() < Duration::from_secs(2) => {
521
- std::thread::sleep(Duration::from_millis(10));
522
- }
523
- Ok(false) | Err(_) => return None,
524
- }
525
- }
526
- }
527
- }
528
-
529
- impl Drop for RegistryLock {
530
- fn drop(&mut self) {
531
- let _ = crate::platform::file_lock::unlock(&self.file);
532
- }
533
- }
534
-
535
- fn with_registry_lock<T>(f: impl FnOnce(&Path) -> T) -> Option<T> {
536
- let dir = registry_dir()?;
537
- std::fs::create_dir_all(&dir).ok()?;
538
- let _lock = RegistryLock::acquire(&dir)?;
539
- Some(f(&dir))
540
- }
541
-
542
- fn with_registry_lock_result<T>(
543
- f: impl FnOnce(&Path) -> Result<T, RegistryRollbackError>,
544
- ) -> Result<T, RegistryRollbackError> {
545
- let dir = registry_dir().ok_or(RegistryRollbackError::LockUnavailable)?;
546
- std::fs::create_dir_all(&dir).map_err(|_| RegistryRollbackError::LockUnavailable)?;
547
- let _lock = RegistryLock::acquire(&dir).ok_or(RegistryRollbackError::LockUnavailable)?;
548
- f(&dir)
549
- }
550
-
551
- fn rand_suffix() -> String {
552
- // Non-cryptographic uniqueness: a process-local monotonic counter is
553
- // enough because the tmp name only needs to be unique within one
554
- // process lifetime (we also embed the pid).
555
- use std::sync::atomic::{AtomicU64, Ordering};
556
- static COUNTER: AtomicU64 = AtomicU64::new(0);
557
- let n = COUNTER.fetch_add(1, Ordering::Relaxed);
558
- format!("{n:x}")
559
- }
560
-
561
- /// Remove the registry entry for `(workspace, team_key)` if it exists.
562
- /// Called from shutdown/unbind success hooks after canonical state
563
- /// reflects the leader as no longer bound. Missing files are treated as
564
- /// success — the invariant is "no registry entry after unbind", not
565
- /// "must have found something to delete".
566
- pub fn unregister_entry(workspace: &Path, team_key: &str) -> Option<PathBuf> {
567
- with_registry_lock(|dir| {
568
- let hash = workspace_hash(workspace);
569
- let path = dir.join(format!("{hash}__{team_key}.json"));
570
- if path.exists() {
571
- std::fs::remove_file(&path).ok()?;
572
- return Some(path);
573
- }
574
- None
575
- })
576
- .flatten()
577
- }
578
-
579
- /// Read and deserialize every `*.json` file under the registry directory.
580
- /// Skips unreadable / malformed files silently (returns fewer entries) —
581
- /// registry is a derived discovery index and unreadable files are the
582
- /// "STALE / UNREADABLE" dirty class rather than an error.
583
- #[must_use]
584
- fn read_all_entries_with_bytes() -> Vec<(PathBuf, LeaderRegistryEntry, Vec<u8>)> {
585
- let Some(dir) = registry_dir() else {
586
- return Vec::new();
587
- };
588
- let Ok(read_dir) = std::fs::read_dir(&dir) else {
589
- return Vec::new();
590
- };
591
- let mut out = Vec::new();
592
- for entry in read_dir.flatten() {
593
- let path = entry.path();
594
- if path
595
- .file_name()
596
- .and_then(|s| s.to_str())
597
- .is_some_and(|name| name.starts_with('.'))
598
- {
599
- continue;
600
- }
601
- if path.extension().and_then(|s| s.to_str()) != Some("json") {
602
- continue;
603
- }
604
- let Ok(bytes) = std::fs::read(&path) else {
605
- continue;
606
- };
607
- let Ok(entry) = serde_json::from_slice::<LeaderRegistryEntry>(&bytes) else {
608
- continue;
609
- };
610
- out.push((path, entry, bytes));
611
- }
612
- out.sort_by(|a, b| a.0.cmp(&b.0));
613
- out
614
- }
615
-
616
- #[must_use]
617
- fn read_all_entries() -> Vec<(PathBuf, LeaderRegistryEntry)> {
618
- read_all_entries_with_bytes()
619
- .into_iter()
620
- .map(|(path, entry, _bytes)| (path, entry))
621
- .collect()
622
- }
623
-
624
- /// Read discovery records without classifying or mutating canonical runtime state.
625
- pub(crate) fn snapshots() -> Vec<LeaderRegistryEntry> {
626
- read_all_entries().into_iter().map(|(_, entry)| entry).collect()
627
- }
628
-
629
- /// Validate a registry entry against its canonical workspace state.
630
- /// Returns the wire status label — LIVE when canonical `leader_receiver`
631
- /// matches, STALE otherwise. This is the pruning gate for GC and the
632
- /// per-entry classification the `leaders` CLI reports.
633
- #[must_use]
634
- pub fn classify(entry: &LeaderRegistryEntry) -> (&'static str, Option<String>) {
635
- let Ok(state) = crate::state::persist::load_runtime_state(&entry.workspace) else {
636
- return ("STALE", Some("workspace_no_state".to_string()));
637
- };
638
- classify_loaded(entry, &state)
639
- }
640
-
641
- fn classify_loaded(entry: &LeaderRegistryEntry, state: &Value) -> (&'static str, Option<String>) {
642
- // A missing or malformed `teams` root is an unavailable/legacy state,
643
- // not proof that this registry entry's team was retired. Keep it out of
644
- // the prune candidate set unless a valid map was independently found.
645
- let Some(teams) = state.get("teams").and_then(Value::as_object) else {
646
- return ("STALE", Some("teams_invalid".to_string()));
647
- };
648
- let team = match teams.get(&entry.team_key) {
649
- Some(t) => t,
650
- None => return ("STALE", Some("team_key_not_found".to_string())),
651
- };
652
- // Team status must indicate liveness. Empty / missing counts as
653
- // alive for pre-status states; explicit down/stopped/archived is
654
- // terminal STALE.
655
- let team_status = team
656
- .get("status")
657
- .and_then(|v| v.as_str())
658
- .unwrap_or("alive");
659
- if team_status == "down" || team_status == "stopped" || team_status == "archived" {
660
- return ("STALE", Some("team_not_alive".to_string()));
661
- }
662
- let receiver = team.get("leader_receiver");
663
- let receiver = match receiver {
664
- Some(r) if !r.is_null() => r,
665
- _ => return ("STALE", Some("leader_not_attached".to_string())),
666
- };
667
- let canonical_epoch = receiver
668
- .get("owner_epoch")
669
- .and_then(|v| v.as_u64())
670
- .or_else(|| team.get("owner_epoch").and_then(|v| v.as_u64()))
671
- .unwrap_or(0);
672
- if canonical_epoch != entry.owner_epoch {
673
- return (
674
- "STALE",
675
- Some(format!(
676
- "owner_epoch_mismatch:registry={},canonical={}",
677
- entry.owner_epoch, canonical_epoch
678
- )),
679
- );
680
- }
681
- // Verify the recorded leader pane is actually live on its recorded
682
- // tmux endpoint. A killed tmux session (test's kill_session) means
683
- // the receiver is stale even though the state hasn't been updated.
684
- let pane_id = receiver.get("pane_id").and_then(|v| v.as_str());
685
- let socket = receiver.get("tmux_socket").and_then(|v| v.as_str());
686
- if let (Some(pane), Some(sock)) = (pane_id, socket) {
687
- if !tmux_pane_live(sock, pane) {
688
- return ("STALE", Some("leader_pane_dead".to_string()));
689
- }
690
- }
691
- ("LIVE", None)
692
- }
693
-
694
- fn tmux_pane_live(socket: &str, pane_id: &str) -> bool {
695
- // Best-effort tmux liveness check via the same transport factory the
696
- // main runtime uses. On error we treat the pane as NOT live so a
697
- // send never routes through a socket we could not verify.
698
- let backend = crate::transport_factory::tmux_endpoint_transport(socket);
699
- match backend.list_targets() {
700
- Ok(targets) => targets.iter().any(|t| t.pane_id.as_str() == pane_id),
701
- Err(_) => false,
702
- }
703
- }
704
-
705
- /// Explicitly prune only entries whose readable canonical state proves that
706
- /// the team is gone or terminal. Dead panes, old epochs, unattached leaders,
707
- /// missing/unreadable state, and probe failures remain untouched.
708
- #[must_use]
709
- pub fn prune_registry(dry_run: bool) -> RegistryPruneReport {
710
- let mut report = RegistryPruneReport {
711
- dry_run,
712
- candidates: Vec::new(),
713
- removed: Vec::new(),
714
- kept: Vec::new(),
715
- skipped: Vec::new(),
716
- errors: Vec::new(),
717
- };
718
- let mut registry_lock_unavailable = false;
719
- for (path, entry, snapshot) in read_all_entries_with_bytes() {
720
- let (status, classified_reason) = classify(&entry);
721
- let reason = prune_reason(&entry, status, classified_reason.as_deref());
722
- let kept_reason = classified_reason.as_deref().unwrap_or("LIVE");
723
- let Some(reason) = reason else {
724
- report.kept.push(prune_item(&entry, kept_reason));
725
- continue;
726
- };
727
- let candidate = prune_item(&entry, reason);
728
- report.candidates.push(candidate.clone());
729
- if dry_run {
730
- continue;
731
- }
732
- if registry_lock_unavailable {
733
- report
734
- .skipped
735
- .push(prune_item(&entry, "registry_lock_unavailable"));
736
- continue;
737
- }
738
- match prune_entry_if_current(&path, &entry, &snapshot) {
739
- PruneAttempt::Removed => report.removed.push(candidate),
740
- PruneAttempt::Skipped(reason) => {
741
- if reason == "registry_lock_unavailable" {
742
- registry_lock_unavailable = true;
743
- }
744
- report.skipped.push(prune_item(&entry, reason));
745
- }
746
- PruneAttempt::Error => report.errors.push(prune_item(&entry, "remove_failed")),
747
- }
748
- }
749
- report
750
- }
751
-
752
- /// Read all entries and classify each without mutating the derived index.
753
- /// `send --to-leader` needs to see stale entries so it can refuse with
754
- /// `registry_stale` (and never silently fall through to
755
- /// `leader_name_not_found` just because a listing ran first).
756
- #[must_use]
757
- pub fn list_validated_no_gc() -> Vec<(LeaderRegistryEntry, &'static str, Option<String>)> {
758
- read_all_entries()
759
- .into_iter()
760
- .map(|(_path, entry)| {
761
- let (status, reason) = classify(&entry);
762
- (entry, status, reason)
763
- })
764
- .collect()
765
- }
766
-
767
- #[cfg(test)]
768
- mod tests {
769
- #![allow(clippy::expect_used, clippy::panic, clippy::unwrap_used)]
770
-
771
- use super::*;
772
- use serde_json::json;
773
- use serial_test::serial;
774
- use std::sync::atomic::{AtomicU64, Ordering};
775
-
776
- static TEST_SEQ: AtomicU64 = AtomicU64::new(0);
777
-
778
- struct HomeGuard(Option<std::ffi::OsString>);
779
-
780
- impl Drop for HomeGuard {
781
- fn drop(&mut self) {
782
- if let Some(home) = self.0.take() {
783
- std::env::set_var("HOME", home);
784
- } else {
785
- std::env::remove_var("HOME");
786
- }
787
- }
788
- }
789
-
790
- fn test_home(label: &str) -> (HomeGuard, PathBuf, PathBuf) {
791
- let n = TEST_SEQ.fetch_add(1, Ordering::Relaxed);
792
- let home =
793
- std::env::temp_dir().join(format!("ta-registry-{label}-{}-{n}", std::process::id()));
794
- let workspace = home.join("workspace");
795
- std::fs::create_dir_all(&workspace).expect("create workspace");
796
- let previous = std::env::var_os("HOME");
797
- std::env::set_var("HOME", &home);
798
- (HomeGuard(previous), home, workspace)
799
- }
800
-
801
- fn write_state(workspace: &Path, state: Value) {
802
- let path = crate::state::persist::runtime_state_path(workspace);
803
- std::fs::create_dir_all(path.parent().expect("runtime parent")).expect("create runtime");
804
- std::fs::write(
805
- path,
806
- serde_json::to_vec_pretty(&state).expect("serialize state"),
807
- )
808
- .expect("write state");
809
- }
810
-
811
- fn entry(workspace: &Path, team_key: &str) -> LeaderRegistryEntry {
812
- build_entry(
813
- workspace,
814
- team_key,
815
- "direct_tmux",
816
- json!({"pane_id": "%fixture"}),
817
- 1,
818
- "test",
819
- "2026-09-16T00:00:00Z".to_string(),
820
- )
821
- }
822
-
823
- #[test]
824
- #[serial(env)]
825
- fn prune_removes_team_proven_terminal() {
826
- let (_home_guard, _home, workspace) = test_home("terminal");
827
- write_state(
828
- &workspace,
829
- json!({"teams": {"retired": {"status": "stopped"}}}),
830
- );
831
- let registered = entry(&workspace, "retired");
832
- let path = write_entry_best_effort(&registered).expect("register terminal team");
833
-
834
- let report = prune_registry(false);
835
- assert_eq!(report.candidates.len(), 1);
836
- assert_eq!(report.removed.len(), 1);
837
- assert!(report.skipped.is_empty());
838
- assert!(!path.exists(), "terminal registry entry must be removed");
839
- }
840
-
841
- #[test]
842
- #[serial(env)]
843
- fn prune_removes_missing_key_only_from_valid_teams_map() {
844
- let (_home_guard, _home, workspace) = test_home("missing-key");
845
- write_state(&workspace, json!({"teams": {"other": {"status": "alive"}}}));
846
- let registered = entry(&workspace, "gone");
847
- let path = write_entry_best_effort(&registered).expect("register missing team");
848
-
849
- let report = prune_registry(false);
850
- assert_eq!(report.removed.len(), 1);
851
- assert!(
852
- !path.exists(),
853
- "missing key in valid teams map is removable"
854
- );
855
- }
856
-
857
- #[test]
858
- #[serial(env)]
859
- fn prune_keeps_null_nonobject_and_legacy_teams_shapes() {
860
- for (label, state) in [
861
- ("null", json!({"teams": null})),
862
- ("array", json!({"teams": []})),
863
- ("string", json!({"teams": "legacy"})),
864
- (
865
- "single",
866
- json!({"team_key": "retired", "status": "stopped"}),
867
- ),
868
- ] {
869
- let (_home_guard, _home, workspace) = test_home(label);
870
- write_state(&workspace, state);
871
- let registered = entry(&workspace, "retired");
872
- let path = write_entry_best_effort(&registered).expect("register malformed state");
873
-
874
- let report = prune_registry(false);
875
- assert!(
876
- report.candidates.is_empty(),
877
- "malformed shape became candidate: {label}"
878
- );
879
- assert_eq!(
880
- report.kept.len(),
881
- 1,
882
- "malformed shape must be retained: {label}"
883
- );
884
- assert_eq!(report.kept[0].reason, "teams_invalid");
885
- assert!(path.exists(), "malformed state entry must remain: {label}");
886
- }
887
- }
888
- }