@team-agent/installer 0.2.10 → 0.3.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 (326) hide show
  1. package/Cargo.lock +744 -0
  2. package/Cargo.toml +34 -0
  3. package/crates/team-agent/Cargo.toml +33 -0
  4. package/crates/team-agent/src/cli/adapters.rs +1343 -0
  5. package/crates/team-agent/src/cli/diagnose.rs +554 -0
  6. package/crates/team-agent/src/cli/emit.rs +1077 -0
  7. package/crates/team-agent/src/cli/helpers.rs +88 -0
  8. package/crates/team-agent/src/cli/leader.rs +216 -0
  9. package/crates/team-agent/src/cli/mod.rs +1141 -0
  10. package/crates/team-agent/src/cli/profile.rs +306 -0
  11. package/crates/team-agent/src/cli/send.rs +215 -0
  12. package/crates/team-agent/src/cli/status.rs +179 -0
  13. package/crates/team-agent/src/cli/status_port.rs +502 -0
  14. package/crates/team-agent/src/cli/tests/base.rs +616 -0
  15. package/crates/team-agent/src/cli/tests/compile.rs +96 -0
  16. package/crates/team-agent/src/cli/tests/divergence.rs +509 -0
  17. package/crates/team-agent/src/cli/tests/lane_c.rs +333 -0
  18. package/crates/team-agent/src/cli/tests/leader_watch.rs +395 -0
  19. package/crates/team-agent/src/cli/tests/main_preserved.rs +675 -0
  20. package/crates/team-agent/src/cli/tests/missing_subcommands.rs +390 -0
  21. package/crates/team-agent/src/cli/tests/mod.rs +97 -0
  22. package/crates/team-agent/src/cli/tests/peer_allow.rs +137 -0
  23. package/crates/team-agent/src/cli/tests/repair_state_byte_lock.rs +302 -0
  24. package/crates/team-agent/src/cli/tests/run_delegation.rs +305 -0
  25. package/crates/team-agent/src/cli/tests/status_send.rs +385 -0
  26. package/crates/team-agent/src/cli/tests/verb_profile.rs +182 -0
  27. package/crates/team-agent/src/cli/tests/verb_settle.rs +236 -0
  28. package/crates/team-agent/src/cli/tests/verb_validate.rs +184 -0
  29. package/crates/team-agent/src/cli/types.rs +605 -0
  30. package/crates/team-agent/src/compiler/tests.rs +701 -0
  31. package/crates/team-agent/src/compiler.rs +489 -0
  32. package/crates/team-agent/src/coordinator/backoff.rs +153 -0
  33. package/crates/team-agent/src/coordinator/health.rs +436 -0
  34. package/crates/team-agent/src/coordinator/mod.rs +80 -0
  35. package/crates/team-agent/src/coordinator/orphan.rs +179 -0
  36. package/crates/team-agent/src/coordinator/tests/abnormal.rs +255 -0
  37. package/crates/team-agent/src/coordinator/tests/basics.rs +262 -0
  38. package/crates/team-agent/src/coordinator/tests/daemon.rs +323 -0
  39. package/crates/team-agent/src/coordinator/tests/health_sync.rs +263 -0
  40. package/crates/team-agent/src/coordinator/tests/main_preserved.rs +136 -0
  41. package/crates/team-agent/src/coordinator/tests/mod.rs +310 -0
  42. package/crates/team-agent/src/coordinator/tests/spine.rs +261 -0
  43. package/crates/team-agent/src/coordinator/tests/takeover.rs +227 -0
  44. package/crates/team-agent/src/coordinator/tests/tick_core.rs +256 -0
  45. package/crates/team-agent/src/coordinator/tests/watch.rs +167 -0
  46. package/crates/team-agent/src/coordinator/tick.rs +2032 -0
  47. package/crates/team-agent/src/coordinator/types.rs +584 -0
  48. package/crates/team-agent/src/db/migration.rs +716 -0
  49. package/crates/team-agent/src/db/mod.rs +23 -0
  50. package/crates/team-agent/src/db/schema.rs +378 -0
  51. package/crates/team-agent/src/event_log.rs +375 -0
  52. package/crates/team-agent/src/fake_worker.rs +253 -0
  53. package/crates/team-agent/src/leader/helpers.rs +190 -0
  54. package/crates/team-agent/src/leader/inject.rs +33 -0
  55. package/crates/team-agent/src/leader/lease.rs +1063 -0
  56. package/crates/team-agent/src/leader/mod.rs +99 -0
  57. package/crates/team-agent/src/leader/owner_bind.rs +292 -0
  58. package/crates/team-agent/src/leader/rediscover/tests.rs +525 -0
  59. package/crates/team-agent/src/leader/rediscover.rs +1099 -0
  60. package/crates/team-agent/src/leader/start.rs +273 -0
  61. package/crates/team-agent/src/leader/takeover.rs +235 -0
  62. package/crates/team-agent/src/leader/tests/basics.rs +183 -0
  63. package/crates/team-agent/src/leader/tests/byte_findings.rs +234 -0
  64. package/crates/team-agent/src/leader/tests/identity.rs +206 -0
  65. package/crates/team-agent/src/leader/tests/idle.rs +271 -0
  66. package/crates/team-agent/src/leader/tests/lease_api.rs +225 -0
  67. package/crates/team-agent/src/leader/tests/lease_claim.rs +253 -0
  68. package/crates/team-agent/src/leader/tests/mod.rs +125 -0
  69. package/crates/team-agent/src/leader/tests/rediscover.rs +351 -0
  70. package/crates/team-agent/src/leader/tests/wake_start_owner.rs +204 -0
  71. package/crates/team-agent/src/leader/types.rs +487 -0
  72. package/crates/team-agent/src/lib.rs +85 -0
  73. package/crates/team-agent/src/lifecycle/display.rs +228 -0
  74. package/crates/team-agent/src/lifecycle/helpers.rs +112 -0
  75. package/crates/team-agent/src/lifecycle/launch/plan.rs +227 -0
  76. package/crates/team-agent/src/lifecycle/launch.rs +1833 -0
  77. package/crates/team-agent/src/lifecycle/mod.rs +62 -0
  78. package/crates/team-agent/src/lifecycle/restart/agent.rs +533 -0
  79. package/crates/team-agent/src/lifecycle/restart/common.rs +517 -0
  80. package/crates/team-agent/src/lifecycle/restart/orchestrator.rs +41 -0
  81. package/crates/team-agent/src/lifecycle/restart/rebuild.rs +268 -0
  82. package/crates/team-agent/src/lifecycle/restart/remove.rs +780 -0
  83. package/crates/team-agent/src/lifecycle/restart/selection.rs +208 -0
  84. package/crates/team-agent/src/lifecycle/restart/team_state.rs +242 -0
  85. package/crates/team-agent/src/lifecycle/restart.rs +76 -0
  86. package/crates/team-agent/src/lifecycle/tests/agent_ops.rs +455 -0
  87. package/crates/team-agent/src/lifecycle/tests/core.rs +989 -0
  88. package/crates/team-agent/src/lifecycle/tests/lane_ops.rs +583 -0
  89. package/crates/team-agent/src/lifecycle/tests/launch_spawn.rs +933 -0
  90. package/crates/team-agent/src/lifecycle/tests/main_preserved.rs +265 -0
  91. package/crates/team-agent/src/lifecycle/tests.rs +27 -0
  92. package/crates/team-agent/src/lifecycle/types.rs +685 -0
  93. package/crates/team-agent/src/main.rs +41 -0
  94. package/crates/team-agent/src/mcp_server/helpers.rs +228 -0
  95. package/crates/team-agent/src/mcp_server/mod.rs +183 -0
  96. package/crates/team-agent/src/mcp_server/normalize.rs +312 -0
  97. package/crates/team-agent/src/mcp_server/tests/golden.rs +283 -0
  98. package/crates/team-agent/src/mcp_server/tests/normalize.rs +244 -0
  99. package/crates/team-agent/src/mcp_server/tests/scoped.rs +189 -0
  100. package/crates/team-agent/src/mcp_server/tests/send.rs +222 -0
  101. package/crates/team-agent/src/mcp_server/tests/tools.rs +158 -0
  102. package/crates/team-agent/src/mcp_server/tests/wire.rs +159 -0
  103. package/crates/team-agent/src/mcp_server/tests.rs +38 -0
  104. package/crates/team-agent/src/mcp_server/tools.rs +603 -0
  105. package/crates/team-agent/src/mcp_server/types.rs +421 -0
  106. package/crates/team-agent/src/mcp_server/wire.rs +388 -0
  107. package/crates/team-agent/src/message_store.rs +767 -0
  108. package/crates/team-agent/src/messaging/activity.rs +433 -0
  109. package/crates/team-agent/src/messaging/delivery.rs +542 -0
  110. package/crates/team-agent/src/messaging/helpers.rs +209 -0
  111. package/crates/team-agent/src/messaging/leader_receiver.rs +340 -0
  112. package/crates/team-agent/src/messaging/mod.rs +147 -0
  113. package/crates/team-agent/src/messaging/peers.rs +32 -0
  114. package/crates/team-agent/src/messaging/results.rs +537 -0
  115. package/crates/team-agent/src/messaging/scheduler.rs +344 -0
  116. package/crates/team-agent/src/messaging/selftest.rs +100 -0
  117. package/crates/team-agent/src/messaging/send.rs +582 -0
  118. package/crates/team-agent/src/messaging/tests/basic.rs +357 -0
  119. package/crates/team-agent/src/messaging/tests/main_preserved.rs +122 -0
  120. package/crates/team-agent/src/messaging/tests/mod.rs +293 -0
  121. package/crates/team-agent/src/messaging/tests/runtime.rs +1422 -0
  122. package/crates/team-agent/src/messaging/tests/spine.rs +437 -0
  123. package/crates/team-agent/src/messaging/trust.rs +192 -0
  124. package/crates/team-agent/src/messaging/types.rs +355 -0
  125. package/crates/team-agent/src/messaging/watchers.rs +591 -0
  126. package/crates/team-agent/src/model/enums.rs +311 -0
  127. package/crates/team-agent/src/model/errors.rs +17 -0
  128. package/crates/team-agent/src/model/ids.rs +155 -0
  129. package/crates/team-agent/src/model/mod.rs +22 -0
  130. package/crates/team-agent/src/model/paths.rs +228 -0
  131. package/crates/team-agent/src/model/permissions.rs +567 -0
  132. package/crates/team-agent/src/model/routing.rs +340 -0
  133. package/crates/team-agent/src/model/spec.rs +680 -0
  134. package/crates/team-agent/src/model/task_graph.rs +380 -0
  135. package/crates/team-agent/src/model/testdata/fuzz.golden.yaml +43 -0
  136. package/crates/team-agent/src/model/testdata/fuzz.yaml +43 -0
  137. package/crates/team-agent/src/model/testdata/spec_invalid_a.yaml +207 -0
  138. package/crates/team-agent/src/model/testdata/team.spec.golden.yaml +206 -0
  139. package/crates/team-agent/src/model/testdata/team.spec.yaml +206 -0
  140. package/crates/team-agent/src/model/yaml/tests.rs +288 -0
  141. package/crates/team-agent/src/model/yaml.rs +800 -0
  142. package/crates/team-agent/src/packaging/install.rs +305 -0
  143. package/crates/team-agent/src/packaging/migrate.rs +30 -0
  144. package/crates/team-agent/src/packaging/mod.rs +82 -0
  145. package/crates/team-agent/src/packaging/repair.rs +24 -0
  146. package/crates/team-agent/src/packaging/tests.rs +829 -0
  147. package/crates/team-agent/src/packaging/types.rs +369 -0
  148. package/crates/team-agent/src/provider/adapter.rs +801 -0
  149. package/crates/team-agent/src/provider/approvals/mod.rs +2 -0
  150. package/crates/team-agent/src/provider/approvals/parsing.rs +452 -0
  151. package/crates/team-agent/src/provider/approvals/runtime_prompts.rs +163 -0
  152. package/crates/team-agent/src/provider/classify.rs +456 -0
  153. package/crates/team-agent/src/provider/faults.rs +136 -0
  154. package/crates/team-agent/src/provider/helpers.rs +41 -0
  155. package/crates/team-agent/src/provider/mod.rs +53 -0
  156. package/crates/team-agent/src/provider/startup_prompt.rs +423 -0
  157. package/crates/team-agent/src/provider/tests/adapter.rs +239 -0
  158. package/crates/team-agent/src/provider/tests/classify.rs +240 -0
  159. package/crates/team-agent/src/provider/tests/faults.rs +120 -0
  160. package/crates/team-agent/src/provider/tests/idle.rs +208 -0
  161. package/crates/team-agent/src/provider/tests/wire.rs +213 -0
  162. package/crates/team-agent/src/provider/tests.rs +31 -0
  163. package/crates/team-agent/src/provider/types.rs +424 -0
  164. package/crates/team-agent/src/state/identity.rs +656 -0
  165. package/crates/team-agent/src/state/mod.rs +58 -0
  166. package/crates/team-agent/src/state/owner_gate.rs +423 -0
  167. package/crates/team-agent/src/state/persist.rs +712 -0
  168. package/crates/team-agent/src/state/projection.rs +657 -0
  169. package/crates/team-agent/src/state/selector.rs +105 -0
  170. package/crates/team-agent/src/state/testdata/state-rich.canonical.json +133 -0
  171. package/crates/team-agent/src/tmux_backend/tests.rs +586 -0
  172. package/crates/team-agent/src/tmux_backend.rs +758 -0
  173. package/crates/team-agent/src/transport/test_support.rs +252 -0
  174. package/crates/team-agent/src/transport/tests/behavior.rs +327 -0
  175. package/crates/team-agent/src/transport/tests/mod.rs +199 -0
  176. package/crates/team-agent/src/transport/tests/wire.rs +527 -0
  177. package/crates/team-agent/src/transport.rs +774 -0
  178. package/npm/install.mjs +90 -106
  179. package/package.json +15 -13
  180. package/crates/team-agent-core/Cargo.toml +0 -12
  181. package/crates/team-agent-core/src/lib.rs +0 -332
  182. package/crates/team-agent-core/src/main.rs +0 -152
  183. package/pyproject.toml +0 -18
  184. package/scripts/install.py +0 -88
  185. package/scripts/run_regression_tests.py +0 -83
  186. package/src/team_agent/__init__.py +0 -3
  187. package/src/team_agent/__main__.py +0 -5
  188. package/src/team_agent/_legacy_pane_discovery.py +0 -186
  189. package/src/team_agent/abnormal_track.py +0 -253
  190. package/src/team_agent/approvals/__init__.py +0 -65
  191. package/src/team_agent/approvals/constants.py +0 -6
  192. package/src/team_agent/approvals/parsing.py +0 -176
  193. package/src/team_agent/approvals/runtime_prompts.py +0 -171
  194. package/src/team_agent/approvals/status.py +0 -176
  195. package/src/team_agent/cli/__init__.py +0 -137
  196. package/src/team_agent/cli/commands.py +0 -481
  197. package/src/team_agent/cli/e2e.py +0 -202
  198. package/src/team_agent/cli/helpers.py +0 -226
  199. package/src/team_agent/cli/parser.py +0 -540
  200. package/src/team_agent/compiler.py +0 -334
  201. package/src/team_agent/coordinator/__init__.py +0 -53
  202. package/src/team_agent/coordinator/__main__.py +0 -83
  203. package/src/team_agent/coordinator/lifecycle.py +0 -363
  204. package/src/team_agent/coordinator/metadata.py +0 -61
  205. package/src/team_agent/coordinator/paths.py +0 -17
  206. package/src/team_agent/diagnose/__init__.py +0 -48
  207. package/src/team_agent/diagnose/checks.py +0 -101
  208. package/src/team_agent/diagnose/comms.py +0 -213
  209. package/src/team_agent/diagnose/health.py +0 -241
  210. package/src/team_agent/diagnose/orphan_cleanup.py +0 -364
  211. package/src/team_agent/diagnose/preflight.py +0 -194
  212. package/src/team_agent/diagnose/quick_start.py +0 -324
  213. package/src/team_agent/display/__init__.py +0 -92
  214. package/src/team_agent/display/adaptive.py +0 -511
  215. package/src/team_agent/display/backend.py +0 -46
  216. package/src/team_agent/display/close.py +0 -154
  217. package/src/team_agent/display/ghostty.py +0 -77
  218. package/src/team_agent/display/rebuild.py +0 -102
  219. package/src/team_agent/display/tiling.py +0 -156
  220. package/src/team_agent/display/worker_window.py +0 -114
  221. package/src/team_agent/display/workspace.py +0 -382
  222. package/src/team_agent/errors.py +0 -10
  223. package/src/team_agent/events.py +0 -84
  224. package/src/team_agent/fake_worker.py +0 -80
  225. package/src/team_agent/idle_predicate.py +0 -200
  226. package/src/team_agent/idle_takeover.py +0 -59
  227. package/src/team_agent/idle_takeover_wiring.py +0 -111
  228. package/src/team_agent/launch/__init__.py +0 -41
  229. package/src/team_agent/launch/bootstrap.py +0 -85
  230. package/src/team_agent/launch/config.py +0 -106
  231. package/src/team_agent/launch/core.py +0 -301
  232. package/src/team_agent/launch/requirements.py +0 -57
  233. package/src/team_agent/leader/__init__.py +0 -926
  234. package/src/team_agent/leader_binding.py +0 -183
  235. package/src/team_agent/lifecycle/__init__.py +0 -5
  236. package/src/team_agent/lifecycle/agents.py +0 -278
  237. package/src/team_agent/lifecycle/operations.py +0 -411
  238. package/src/team_agent/lifecycle/paste_buffer_hygiene.py +0 -39
  239. package/src/team_agent/lifecycle/start.py +0 -363
  240. package/src/team_agent/mcp_server/__init__.py +0 -42
  241. package/src/team_agent/mcp_server/__main__.py +0 -7
  242. package/src/team_agent/mcp_server/contracts.py +0 -148
  243. package/src/team_agent/mcp_server/normalize.py +0 -257
  244. package/src/team_agent/mcp_server/server.py +0 -150
  245. package/src/team_agent/mcp_server/tools.py +0 -352
  246. package/src/team_agent/message_store/__init__.py +0 -23
  247. package/src/team_agent/message_store/agent_health.py +0 -113
  248. package/src/team_agent/message_store/core.py +0 -497
  249. package/src/team_agent/message_store/leader_notification_log.py +0 -198
  250. package/src/team_agent/message_store/result_watchers.py +0 -251
  251. package/src/team_agent/message_store/schema.py +0 -308
  252. package/src/team_agent/message_store/schema_migration.py +0 -448
  253. package/src/team_agent/messaging/__init__.py +0 -1
  254. package/src/team_agent/messaging/activity_detector.py +0 -254
  255. package/src/team_agent/messaging/delivery.py +0 -473
  256. package/src/team_agent/messaging/deps.py +0 -247
  257. package/src/team_agent/messaging/idle_alerts.py +0 -423
  258. package/src/team_agent/messaging/internal_delivery.py +0 -46
  259. package/src/team_agent/messaging/leader.py +0 -497
  260. package/src/team_agent/messaging/leader_api_errors.py +0 -216
  261. package/src/team_agent/messaging/leader_panes.py +0 -673
  262. package/src/team_agent/messaging/owner_bypass.py +0 -29
  263. package/src/team_agent/messaging/result_delivery.py +0 -539
  264. package/src/team_agent/messaging/results.py +0 -447
  265. package/src/team_agent/messaging/scheduler.py +0 -450
  266. package/src/team_agent/messaging/send.py +0 -532
  267. package/src/team_agent/messaging/session_drift.py +0 -94
  268. package/src/team_agent/messaging/tmux_io.py +0 -506
  269. package/src/team_agent/messaging/tmux_prompt.py +0 -338
  270. package/src/team_agent/messaging/trust_auto_answer.py +0 -52
  271. package/src/team_agent/orchestrator/__init__.py +0 -376
  272. package/src/team_agent/orchestrator/plan.py +0 -122
  273. package/src/team_agent/orchestrator/state.py +0 -128
  274. package/src/team_agent/paths.py +0 -45
  275. package/src/team_agent/permissions.py +0 -123
  276. package/src/team_agent/profiles/__init__.py +0 -82
  277. package/src/team_agent/profiles/constants.py +0 -19
  278. package/src/team_agent/profiles/core.py +0 -407
  279. package/src/team_agent/profiles/helpers.py +0 -69
  280. package/src/team_agent/profiles/provider_env.py +0 -188
  281. package/src/team_agent/profiles/smoke.py +0 -201
  282. package/src/team_agent/provider_cli/__init__.py +0 -43
  283. package/src/team_agent/provider_cli/adapter.py +0 -172
  284. package/src/team_agent/provider_cli/base.py +0 -48
  285. package/src/team_agent/provider_cli/claude.py +0 -457
  286. package/src/team_agent/provider_cli/codex.py +0 -336
  287. package/src/team_agent/provider_cli/copilot.py +0 -8
  288. package/src/team_agent/provider_cli/fake.py +0 -39
  289. package/src/team_agent/provider_cli/gemini.py +0 -95
  290. package/src/team_agent/provider_cli/opencode.py +0 -8
  291. package/src/team_agent/provider_cli/prompt.py +0 -62
  292. package/src/team_agent/provider_cli/registry.py +0 -18
  293. package/src/team_agent/provider_cli/unsupported.py +0 -32
  294. package/src/team_agent/provider_state/README.md +0 -78
  295. package/src/team_agent/provider_state/__init__.py +0 -86
  296. package/src/team_agent/provider_state/claude.py +0 -86
  297. package/src/team_agent/provider_state/codex.py +0 -84
  298. package/src/team_agent/provider_state/common.py +0 -207
  299. package/src/team_agent/provider_state/registry.py +0 -118
  300. package/src/team_agent/providers.py +0 -163
  301. package/src/team_agent/quality_gates.py +0 -104
  302. package/src/team_agent/restart/__init__.py +0 -34
  303. package/src/team_agent/restart/orchestration.py +0 -554
  304. package/src/team_agent/restart/selection.py +0 -89
  305. package/src/team_agent/restart/snapshot.py +0 -70
  306. package/src/team_agent/routing.py +0 -84
  307. package/src/team_agent/runtime.py +0 -1239
  308. package/src/team_agent/rust_core.py +0 -327
  309. package/src/team_agent/sessions/__init__.py +0 -25
  310. package/src/team_agent/sessions/capture.py +0 -143
  311. package/src/team_agent/sessions/inventory.py +0 -44
  312. package/src/team_agent/sessions/resume.py +0 -135
  313. package/src/team_agent/simple_yaml.py +0 -236
  314. package/src/team_agent/spec.py +0 -370
  315. package/src/team_agent/state.py +0 -602
  316. package/src/team_agent/status/__init__.py +0 -63
  317. package/src/team_agent/status/approvals.py +0 -52
  318. package/src/team_agent/status/compact.py +0 -158
  319. package/src/team_agent/status/constants.py +0 -18
  320. package/src/team_agent/status/inbox.py +0 -58
  321. package/src/team_agent/status/peek.py +0 -117
  322. package/src/team_agent/status/queries.py +0 -199
  323. package/src/team_agent/task_graph.py +0 -80
  324. package/src/team_agent/terminal.py +0 -57
  325. package/src/team_agent/wake.py +0 -58
  326. package/src/team_agent/watch/__init__.py +0 -145
@@ -0,0 +1,1141 @@
1
+ //! step 14b · cli — `team-agent <subcommand>` clap 命令面(真相源 `cli/`)。
2
+ //!
3
+ //! Card: `docs/phase0/subsystems/14-mcp_cli.md`(CLI 半边)。
4
+ //! Python 真相源(team-agent-public @ v0.2.11, 439bef8):
5
+ //! - `cli/parser.py` — argparse 顶层:`main(argv)`、`codex`/`claude` passthrough 早返回、
6
+ //! 约 40 子命令注册、`func(args)` + 统一异常→`_emit_cli_error`+`SystemExit(1)`、
7
+ //! `consume_leader_inbox_summary` 命令后吐 leader fallback inbox 摘要、
8
+ //! `TeamAgentArgumentParser.error` 给 send 加顺序提示。
9
+ //! - `cli/commands.py` — 每子命令一个 `cmd_*`(薄壳),含逻辑的:`cmd_status`(--summary/--json/--detail
10
+ //! 三态互斥 + 五行 summary 渲染)、`cmd_doctor`(gate/comms/fix-schema/cleanup-orphans 分派)。
11
+ //! - `cli/helpers.py` — `emit`(--json vs 人读)、`_emit_cli_error`/`_cli_error_payload`(错误落
12
+ //! `.team/logs/cli-error-<ts>.log` + tmux session 冲突富化)、`_provider_args`/
13
+ //! `_leader_launcher_args`(`--`/`--attach`/`--attach-session` 解析)、
14
+ //! `consume_leader_inbox_summary`(游标 + 字节预算截断的 fallback inbox 摘要)。
15
+ //!
16
+ //! 本子系统是"最薄的壳":几乎不拥有耐久数据,subcommand 全部委派给 step 5/6/7/11/12/13。
17
+ //! 自身只拥有:CLI 参数形状、`--json` 稳定输出形状、错误信封 + 退出码、五行 triage 渲染规则、
18
+ //! leader inbox 摘要游标 + 字节预算截断。
19
+ //!
20
+ //! §10/§12:本层是 bin 边界,**非** daemon/coordinator/lifecycle,故顶层**不**强加
21
+ //! `#![deny(unwrap/expect/panic)]`(leader 集成时不会给本文件加 deny)。CLI 顶层错误最终
22
+ //! 用 `anyhow`(bin main),但本 lib-side surface 用 `thiserror` 的 [`CliError`] 返回。
23
+ //!
24
+ //! 所有 fn body = `unimplemented!("step14b port: ...")`。RED 契约据此 NAME 类型 + CALL 真 fn。
25
+
26
+ // ROUND-0 skeleton:fn body 全 unimplemented!() → import/field/param/大 Err 暂未落地;P2 porter 实现时移除。
27
+ #![allow(dead_code, unused_imports, unused_variables, clippy::result_large_err, clippy::doc_overindented_list_items, clippy::doc_lazy_continuation, clippy::io_other_error)]
28
+ // §10:CLI 命令实现层禁 unwrap/expect/panic(unimplemented!() stub 不被拦);tests 子模块各自 allow。
29
+ #![deny(clippy::unwrap_used, clippy::expect_used, clippy::panic)]
30
+
31
+ use std::path::{Path, PathBuf};
32
+
33
+ use serde::{Deserialize, Serialize};
34
+ use serde_json::{json, Map, Value};
35
+ use thiserror::Error;
36
+
37
+ // REUSE in-tree(只 import,不 redefine):
38
+ use crate::model::ids::{TaskId, TeamKey};
39
+ use crate::messaging::{self, AlertType, MessageTarget, SendOptions};
40
+
41
+ pub(crate) const COMMS_BOUNDARY_TEXT: &str = "validates live pane binding consistency. Does NOT perform live runtime message round-trip. comms contract suite deferred to 0.2.9 (test files not shipped). (zero token, zero pollution)";
42
+
43
+ pub mod adapters;
44
+ pub mod diagnose;
45
+ pub mod emit;
46
+ pub mod helpers;
47
+ pub mod leader;
48
+ pub mod profile;
49
+ pub mod send;
50
+ pub mod status;
51
+ pub mod types;
52
+
53
+ pub use adapters::*;
54
+ pub use diagnose::*;
55
+ pub use emit::*;
56
+ pub use leader::*;
57
+ pub use profile::*;
58
+ pub use send::*;
59
+ pub use status::*;
60
+ pub use types::*;
61
+
62
+ pub(crate) use helpers::*;
63
+
64
+ #[cfg(test)]
65
+ mod tests;
66
+
67
+ // =============================================================================
68
+ // CROSS-LANE PLACEHOLDERS(sibling 14a-mcp / status / diagnose / step13-lifecycle
69
+ // 尚未落地;leader 集成时收口到真模块。本层只声明 CLI 调用面所需的最小占位,
70
+ // **不猜** sibling 内部命名 —— 见 cross_deps_or_placeholders)。
71
+ // =============================================================================
72
+
73
+ /// PLACEHOLDER → status lane(`status/queries.py`/`compact.py`)。`cmd_status`/`cmd_approvals`/
74
+ /// `cmd_inbox` 委派的只读投影面。返回 serde `Value`(稳定 JSON 形状由 status lane 拥有)。
75
+ pub mod status_port;
76
+
77
+
78
+ /// PLACEHOLDER → step13 lifecycle(`runtime.{quick_start,start_agent,add_agent,fork_agent,
79
+ /// remove_agent,start_agent,stop_agent,reset_agent,restart,shutdown,start_leader,acknowledge_idle}`)。
80
+ /// `quick_start.py` 物理在本子系统但实现属 step 13(card)。本层只声明委派面。
81
+ pub mod lifecycle_port {
82
+ use super::*;
83
+ use crate::model::enums::Provider;
84
+
85
+ /// `runtime.quick_start`(`cmd_quick_start` 委派)。返回 `{ok, summary, ...}` 稳定形状。
86
+ pub fn quick_start(
87
+ workspace: &Path,
88
+ agents_dir: &Path,
89
+ name: Option<&str>,
90
+ team_id: Option<&str>,
91
+ yes: bool,
92
+ fresh: bool,
93
+ ) -> Result<Value, CliError> {
94
+ let _ = workspace;
95
+ match crate::lifecycle::quick_start(agents_dir, name, yes, fresh, team_id) {
96
+ Ok(report) => Ok(quick_start_value(report)),
97
+ Err(e) => Ok(error_value(e)),
98
+ }
99
+ }
100
+ /// `runtime.start_leader`(`codex`/`claude` passthrough + `cmd_codex`/`cmd_claude`)。
101
+ pub fn start_leader(
102
+ provider: Provider,
103
+ provider_args: &[String],
104
+ cwd: &Path,
105
+ attach: &LeaderLauncherArgs,
106
+ ) -> Result<Value, CliError> {
107
+ let _ = (provider_args, cwd);
108
+ let provider_name = match provider {
109
+ Provider::Codex => "codex",
110
+ Provider::ClaudeCode | Provider::Claude => "claude_code",
111
+ Provider::GeminiCli => "gemini_cli",
112
+ Provider::Fake => "fake",
113
+ };
114
+ Ok(json!({
115
+ "ok": true,
116
+ "provider": provider_name,
117
+ "attach_existing": attach.attach_existing,
118
+ "confirm_attach": attach.confirm_attach,
119
+ "attach_session": attach.attach_session,
120
+ }))
121
+ }
122
+ /// `runtime.shutdown`(`cmd_shutdown`)。
123
+ pub fn shutdown(workspace: &Path, keep_logs: bool, team: Option<&str>) -> Result<Value, CliError> {
124
+ // CP-1: workspace-bound backend so kill-session hits the per-team `tmux -L <socket>` server,
125
+ // then tear that server down so the per-team socket does not orphan (best-effort).
126
+ let run_ws = crate::model::paths::canonical_run_workspace(workspace)
127
+ .map_err(|e| CliError::Runtime(e.to_string()))?;
128
+ let transport = crate::tmux_backend::TmuxBackend::for_workspace(&run_ws);
129
+ let result = shutdown_with_transport(workspace, keep_logs, team, &transport);
130
+ transport.kill_server();
131
+ result
132
+ }
133
+
134
+ pub fn shutdown_with_transport(
135
+ workspace: &Path,
136
+ keep_logs: bool,
137
+ team: Option<&str>,
138
+ transport: &dyn crate::transport::Transport,
139
+ ) -> Result<Value, CliError> {
140
+ let wp = crate::coordinator::WorkspacePath::new(workspace.to_path_buf());
141
+ let stopped = crate::coordinator::stop_coordinator(&wp)
142
+ .map_err(|e| CliError::Runtime(e.to_string()))?;
143
+ let mut state = crate::state::persist::load_runtime_state(workspace)?;
144
+ let session_name = state
145
+ .get("session_name")
146
+ .and_then(Value::as_str)
147
+ .filter(|s| !s.is_empty())
148
+ .map(crate::transport::SessionName::new);
149
+ let session_killed = if let Some(session) = session_name.as_ref() {
150
+ match transport.kill_session(session) {
151
+ Ok(()) => true,
152
+ Err(error) if tmux_absent_error(&error.to_string()) => false,
153
+ Err(error) => return Err(CliError::Runtime(error.to_string())),
154
+ }
155
+ } else {
156
+ false
157
+ };
158
+ mark_agents_stopped(&mut state);
159
+ crate::state::persist::save_runtime_state(workspace, &state)?;
160
+ let _event = crate::event_log::EventLog::new(workspace)
161
+ .write(
162
+ "lifecycle.shutdown",
163
+ json!({
164
+ "keep_logs": keep_logs,
165
+ "team": team,
166
+ "session_name": session_name.as_ref().map(|s| s.as_str().to_string()),
167
+ "session_killed": session_killed,
168
+ "coordinator_status": stop_status_wire(stopped.status),
169
+ }),
170
+ )
171
+ .map_err(|e| CliError::Runtime(e.to_string()))?;
172
+ Ok(json!({
173
+ "ok": stopped.ok,
174
+ "keep_logs": keep_logs,
175
+ "team": team,
176
+ "session_name": session_name.map(|s| s.as_str().to_string()),
177
+ "session_killed": session_killed,
178
+ "coordinator": {
179
+ "status": stop_status_wire(stopped.status),
180
+ "pid": stopped.pid.map(|p| p.get()),
181
+ }
182
+ }))
183
+ }
184
+ /// `runtime.restart`(`cmd_restart`)。
185
+ pub fn restart(workspace: &Path, allow_fresh: bool, team: Option<&str>) -> Result<Value, CliError> {
186
+ match crate::lifecycle::restart(workspace, allow_fresh, team) {
187
+ Ok(report) => Ok(restart_value(report)),
188
+ Err(e) => Ok(error_value(e)),
189
+ }
190
+ }
191
+ /// `runtime.start_agent`(`cmd_start_agent`)。
192
+ pub fn start_agent(
193
+ workspace: &Path,
194
+ agent: &str,
195
+ force: bool,
196
+ open_display: bool,
197
+ allow_fresh: bool,
198
+ team: Option<&str>,
199
+ ) -> Result<Value, CliError> {
200
+ let agent_id = crate::model::ids::AgentId::new(agent);
201
+ match crate::lifecycle::start_agent(
202
+ workspace,
203
+ &agent_id,
204
+ force,
205
+ open_display,
206
+ allow_fresh,
207
+ team,
208
+ ) {
209
+ Ok(report) => Ok(json!({"ok": true, "agent_id": agent, "report": format!("{report:?}")})),
210
+ Err(e) => Ok(error_value(e)),
211
+ }
212
+ }
213
+ /// `runtime.stop_agent`(`cmd_stop_agent`)。
214
+ pub fn stop_agent(workspace: &Path, agent: &str, team: Option<&str>) -> Result<Value, CliError> {
215
+ let agent_id = crate::model::ids::AgentId::new(agent);
216
+ match crate::lifecycle::stop_agent(workspace, &agent_id, team) {
217
+ Ok(report) => Ok(json!({"ok": true, "agent_id": agent, "stopped": report.stopped})),
218
+ Err(e) => Ok(error_value(e)),
219
+ }
220
+ }
221
+ /// `runtime.reset_agent`(`cmd_reset_agent`;`--discard-session` 必需)。
222
+ pub fn reset_agent(
223
+ workspace: &Path,
224
+ agent: &str,
225
+ discard_session: bool,
226
+ open_display: bool,
227
+ team: Option<&str>,
228
+ ) -> Result<Value, CliError> {
229
+ let agent_id = crate::model::ids::AgentId::new(agent);
230
+ match crate::lifecycle::reset_agent(
231
+ workspace,
232
+ &agent_id,
233
+ discard_session,
234
+ open_display,
235
+ team,
236
+ ) {
237
+ Ok(report) => Ok(json!({"ok": true, "agent_id": agent, "report": format!("{report:?}")})),
238
+ Err(e) => Ok(error_value(e)),
239
+ }
240
+ }
241
+ /// `runtime.add_agent`(`cmd_add_agent`;`--role-file` 必需)。
242
+ pub fn add_agent(
243
+ workspace: &Path,
244
+ agent: &str,
245
+ role_file: &str,
246
+ open_display: bool,
247
+ team: Option<&str>,
248
+ ) -> Result<Value, CliError> {
249
+ let agent_id = crate::model::ids::AgentId::new(agent);
250
+ match crate::lifecycle::add_agent(
251
+ workspace,
252
+ &agent_id,
253
+ Path::new(role_file),
254
+ open_display,
255
+ team,
256
+ ) {
257
+ Ok(report) => Ok(json!({
258
+ "ok": true,
259
+ "agent_id": agent,
260
+ "role_file": report.role_file.to_string_lossy(),
261
+ })),
262
+ Err(e) => Ok(error_value(e)),
263
+ }
264
+ }
265
+ /// `runtime.fork_agent`(`cmd_fork_agent`;`--as` 必需)。
266
+ pub fn fork_agent(
267
+ workspace: &Path,
268
+ source_agent: &str,
269
+ as_agent_id: &str,
270
+ label: Option<&str>,
271
+ open_display: bool,
272
+ team: Option<&str>,
273
+ ) -> Result<Value, CliError> {
274
+ let _ = label;
275
+ let source = crate::model::ids::AgentId::new(source_agent);
276
+ let dest = crate::model::ids::AgentId::new(as_agent_id);
277
+ match crate::lifecycle::fork_agent(workspace, &source, &dest, open_display, team) {
278
+ Ok(report) => Ok(json!({
279
+ "ok": true,
280
+ "source_agent_id": report.source_agent_id.as_str(),
281
+ "new_agent_id": report.new_agent_id.as_str(),
282
+ })),
283
+ Err(e) => Ok(error_value(e)),
284
+ }
285
+ }
286
+ /// `runtime.remove_agent`(`cmd_remove_agent`;`--from-spec` 须配 `--confirm`)。
287
+ pub fn remove_agent(
288
+ workspace: &Path,
289
+ agent: &str,
290
+ from_spec: bool,
291
+ confirm: bool,
292
+ force: bool,
293
+ team: Option<&str>,
294
+ ) -> Result<Value, CliError> {
295
+ if !confirm {
296
+ return Ok(json!({"ok": false, "agent_id": agent, "error": "remove-agent requires --confirm"}));
297
+ }
298
+ let agent_id = crate::model::ids::AgentId::new(agent);
299
+ match crate::lifecycle::remove_agent(workspace, &agent_id, from_spec, force, team) {
300
+ Ok(report) => Ok(json!({"ok": true, "agent_id": agent, "report": format!("{report:?}")})),
301
+ Err(e) => Ok(error_value(e)),
302
+ }
303
+ }
304
+ /// `runtime.acknowledge_idle`(`cmd_acknowledge_idle`)。
305
+ pub fn acknowledge_idle(workspace: &Path, team: Option<&str>) -> Result<Value, CliError> {
306
+ let mut state = crate::state::persist::load_runtime_state(workspace)
307
+ .map_err(|e| CliError::Runtime(e.to_string()))?;
308
+ let team = team
309
+ .map(ToString::to_string)
310
+ .or_else(|| state.get("active_team_key").and_then(Value::as_str).map(ToString::to_string))
311
+ .filter(|s| !s.is_empty())
312
+ .or_else(|| workspace.file_name().map(|name| name.to_string_lossy().to_string()))
313
+ .unwrap_or_else(|| "current".to_string());
314
+ let now = chrono::Utc::now().to_rfc3339();
315
+ let ttl_seconds = 1800;
316
+ let expires_at = (chrono::Utc::now() + chrono::Duration::seconds(ttl_seconds)).to_rfc3339();
317
+ record_idle_acknowledged(&mut state, &team, &now, &expires_at, ttl_seconds);
318
+ suppress_team_idle_fallbacks(&mut state, &team, &now, &expires_at, ttl_seconds);
319
+ let agent_id = state
320
+ .get("agents")
321
+ .and_then(Value::as_object)
322
+ .and_then(|agents| agents.keys().next().cloned())
323
+ .map(Value::String)
324
+ .unwrap_or(Value::Null);
325
+ crate::state::persist::save_runtime_state(workspace, &state)
326
+ .map_err(|e| CliError::Runtime(e.to_string()))?;
327
+ crate::event_log::EventLog::new(workspace)
328
+ .write("coordinator.idle_acknowledged", json!({"team": team, "ttl_seconds": ttl_seconds}))
329
+ .map_err(|e| CliError::Runtime(e.to_string()))?;
330
+ Ok(json!({
331
+ "ok": true,
332
+ "team": team,
333
+ "agent_id": agent_id,
334
+ "acknowledged_at": now,
335
+ "expires_at": expires_at,
336
+ "ttl_seconds": ttl_seconds,
337
+ }))
338
+ }
339
+
340
+ fn error_value(error: crate::lifecycle::LifecycleError) -> Value {
341
+ json!({"ok": false, "error": error.to_string()})
342
+ }
343
+
344
+ fn record_idle_acknowledged(
345
+ state: &mut Value,
346
+ team: &str,
347
+ acknowledged_at: &str,
348
+ expires_at: &str,
349
+ ttl_seconds: i64,
350
+ ) {
351
+ let Some(root) = state.as_object_mut() else {
352
+ return;
353
+ };
354
+ let coordinator = root
355
+ .entry("coordinator")
356
+ .or_insert_with(|| json!({}))
357
+ .as_object_mut();
358
+ let Some(coordinator) = coordinator else {
359
+ return;
360
+ };
361
+ let idle = coordinator
362
+ .entry("idle_acknowledged")
363
+ .or_insert_with(|| json!({}))
364
+ .as_object_mut();
365
+ let Some(idle) = idle else {
366
+ return;
367
+ };
368
+ idle.insert(
369
+ team.to_string(),
370
+ json!({"acknowledged_at": acknowledged_at, "expires_at": expires_at, "ttl_seconds": ttl_seconds}),
371
+ );
372
+ }
373
+
374
+ fn suppress_team_idle_fallbacks(
375
+ state: &mut Value,
376
+ team: &str,
377
+ suppressed_at: &str,
378
+ expires_at: &str,
379
+ ttl_seconds: i64,
380
+ ) {
381
+ let agents = state
382
+ .get("agents")
383
+ .and_then(Value::as_object)
384
+ .map(|obj| obj.keys().cloned().collect::<Vec<_>>())
385
+ .unwrap_or_default();
386
+ for agent in agents {
387
+ upsert_suppression(
388
+ state,
389
+ SuppressionRecord {
390
+ team,
391
+ agent_id: &agent,
392
+ alert_type: "idle_fallback",
393
+ suppressed_by: "manual_acknowledge",
394
+ suppressed_at,
395
+ expires_at,
396
+ ttl_seconds,
397
+ },
398
+ );
399
+ }
400
+ }
401
+
402
+ struct SuppressionRecord<'a> {
403
+ team: &'a str,
404
+ agent_id: &'a str,
405
+ alert_type: &'a str,
406
+ suppressed_by: &'a str,
407
+ suppressed_at: &'a str,
408
+ expires_at: &'a str,
409
+ ttl_seconds: i64,
410
+ }
411
+
412
+ fn upsert_suppression(state: &mut Value, record: SuppressionRecord<'_>) {
413
+ let Some(root) = state.as_object_mut() else {
414
+ return;
415
+ };
416
+ let Some(coordinator) = root
417
+ .entry("coordinator")
418
+ .or_insert_with(|| json!({}))
419
+ .as_object_mut()
420
+ else {
421
+ return;
422
+ };
423
+ let Some(all) = coordinator
424
+ .entry("suppressed_idle_alerts")
425
+ .or_insert_with(|| json!({}))
426
+ .as_object_mut()
427
+ else {
428
+ return;
429
+ };
430
+ let Some(team_map) = all
431
+ .entry(record.team.to_string())
432
+ .or_insert_with(|| json!({}))
433
+ .as_object_mut()
434
+ else {
435
+ return;
436
+ };
437
+ let Some(agent_map) = team_map
438
+ .entry(record.agent_id.to_string())
439
+ .or_insert_with(|| json!({}))
440
+ .as_object_mut()
441
+ else {
442
+ return;
443
+ };
444
+ agent_map.insert(
445
+ record.alert_type.to_string(),
446
+ json!({
447
+ "suppressed_at": record.suppressed_at,
448
+ "suppressed_by": record.suppressed_by,
449
+ "manual_acknowledge": true,
450
+ "expires_at": record.expires_at,
451
+ "ttl_seconds": record.ttl_seconds,
452
+ }),
453
+ );
454
+ }
455
+
456
+ fn quick_start_value(report: crate::lifecycle::QuickStartReport) -> Value {
457
+ match report {
458
+ crate::lifecycle::QuickStartReport::Ready {
459
+ session_name,
460
+ launch,
461
+ next_actions,
462
+ } => json!({
463
+ "ok": true,
464
+ "summary": format!("quick-start ready: {}", session_name.as_str()),
465
+ "session_name": session_name.as_str(),
466
+ "dry_run": launch.dry_run,
467
+ "next_actions": next_actions,
468
+ }),
469
+ crate::lifecycle::QuickStartReport::ExistingRuntime {
470
+ team,
471
+ session_name,
472
+ state_path,
473
+ next_actions,
474
+ } => json!({
475
+ "ok": false,
476
+ "summary": "existing runtime",
477
+ "team": team,
478
+ "session_name": session_name.map(|s| s.as_str().to_string()),
479
+ "state_path": state_path.map(|p| p.to_string_lossy().to_string()),
480
+ "next_actions": next_actions,
481
+ }),
482
+ crate::lifecycle::QuickStartReport::PreflightBlocked {
483
+ summary,
484
+ blockers,
485
+ next_actions,
486
+ } => json!({
487
+ "ok": false,
488
+ "summary": summary,
489
+ "blockers": blockers,
490
+ "next_actions": next_actions,
491
+ }),
492
+ }
493
+ }
494
+
495
+ fn restart_value(report: crate::lifecycle::RestartReport) -> Value {
496
+ match report {
497
+ crate::lifecycle::RestartReport::Restarted {
498
+ session_name,
499
+ agents,
500
+ coordinator_started,
501
+ } => json!({
502
+ "ok": true,
503
+ "status": "restarted",
504
+ "session_name": session_name.as_str(),
505
+ "agents": agents.iter().map(|a| a.agent_id.as_str()).collect::<Vec<_>>(),
506
+ "coordinator_started": coordinator_started,
507
+ }),
508
+ crate::lifecycle::RestartReport::RefusedResumeAtomicity {
509
+ unresumable,
510
+ allow_fresh,
511
+ error,
512
+ } => json!({
513
+ "ok": false,
514
+ "status": "refused_resume_atomicity",
515
+ "allow_fresh": allow_fresh,
516
+ "error": error,
517
+ "unresumable": unresumable.iter().map(|w| w.agent_id.as_str()).collect::<Vec<_>>(),
518
+ }),
519
+ crate::lifecycle::RestartReport::RefusedInvalidFirstSendAt {
520
+ invalid,
521
+ allow_fresh,
522
+ error,
523
+ } => json!({
524
+ "ok": false,
525
+ "status": "refused_invalid_first_send_at",
526
+ "allow_fresh": allow_fresh,
527
+ "error": error,
528
+ "invalid": invalid.iter().map(|w| w.worker_id.as_str()).collect::<Vec<_>>(),
529
+ }),
530
+ }
531
+ }
532
+
533
+ fn stop_status_wire(status: crate::coordinator::StopOutcome) -> &'static str {
534
+ match status {
535
+ crate::coordinator::StopOutcome::Missing => "missing",
536
+ crate::coordinator::StopOutcome::InvalidPidRemoved => "invalid_pid_removed",
537
+ crate::coordinator::StopOutcome::KillFailed => "kill_failed",
538
+ crate::coordinator::StopOutcome::Stopped => "stopped",
539
+ }
540
+ }
541
+
542
+ fn tmux_absent_error(message: &str) -> bool {
543
+ let lower = message.to_ascii_lowercase();
544
+ lower.contains("no server running")
545
+ || lower.contains("no such file")
546
+ || lower.contains("can't find session")
547
+ || lower.contains("can't find pane")
548
+ || lower.contains("can't find window")
549
+ }
550
+
551
+ fn mark_agents_stopped(state: &mut Value) {
552
+ let Some(agents) = state.get_mut("agents").and_then(Value::as_object_mut) else {
553
+ return;
554
+ };
555
+ for agent in agents.values_mut() {
556
+ if let Some(obj) = agent.as_object_mut() {
557
+ obj.insert("status".to_string(), json!("stopped"));
558
+ }
559
+ }
560
+ }
561
+ }
562
+
563
+ /// PLACEHOLDER → diagnose lane(`diagnose/health.py` `doctor`、`diagnose/comms.py`
564
+ /// `run_comms_selftest`、`diagnose/orphan_cleanup.py` `orphan_gate`/`cleanup_orphan_coordinators`、
565
+ /// `message_store/schema_migration.py` `schema_diagnosis`/`fix_schema_layout`)。
566
+ /// `cmd_doctor` 的所有分支委派点。返回 `Value`(稳定 JSON 形状由 diagnose lane 拥有)。
567
+ pub mod diagnose_port {
568
+ use super::*;
569
+
570
+ /// `runtime.doctor(spec)` + schema 注入(`cmd_doctor` 默认分支)。
571
+ pub fn doctor(workspace: &Path, spec: Option<&Path>) -> Result<Value, CliError> {
572
+ let _ = spec;
573
+ let tmux_path = which_path("tmux");
574
+ let tmux_installed = tmux_path.is_some();
575
+ let health = crate::coordinator::coordinator_health(
576
+ &crate::coordinator::WorkspacePath::new(workspace.to_path_buf()),
577
+ );
578
+ Ok(json!({
579
+ "tmux": {
580
+ "installed": tmux_installed,
581
+ "path": tmux_path,
582
+ },
583
+ "workspace": workspace.to_string_lossy().to_string(),
584
+ "workspace_is_git_repo": workspace.join(".git").exists(),
585
+ "providers": {},
586
+ "mcp": {
587
+ "server_command": which_path("team_orchestrator"),
588
+ "local_module": true,
589
+ },
590
+ "secret_scan": secret_scan(workspace),
591
+ "coordinator": coordinator_health_value(health),
592
+ "ok": true,
593
+ }))
594
+ }
595
+
596
+ fn secret_scan(workspace: &Path) -> Value {
597
+ let mut findings = Vec::new();
598
+ scan_secret_dir(workspace, workspace, &mut findings);
599
+ json!({
600
+ "ok": findings.is_empty(),
601
+ "findings": findings,
602
+ })
603
+ }
604
+
605
+ fn scan_secret_dir(root: &Path, dir: &Path, findings: &mut Vec<Value>) {
606
+ let Ok(entries) = std::fs::read_dir(dir) else {
607
+ return;
608
+ };
609
+ for entry in entries.flatten() {
610
+ let path = entry.path();
611
+ let name = path.file_name().map(|s| s.to_string_lossy());
612
+ if name.as_deref() == Some(".team") || name.as_deref() == Some(".git") {
613
+ continue;
614
+ }
615
+ if path.is_dir() {
616
+ scan_secret_dir(root, &path, findings);
617
+ continue;
618
+ }
619
+ scan_secret_file(root, &path, findings);
620
+ }
621
+ }
622
+
623
+ fn scan_secret_file(root: &Path, path: &Path, findings: &mut Vec<Value>) {
624
+ let Ok(text) = std::fs::read_to_string(path) else {
625
+ return;
626
+ };
627
+ for (idx, line) in text.lines().enumerate() {
628
+ if line.contains("OPENAI_API_KEY=") || line.contains("ANTHROPIC_API_KEY=") {
629
+ let rel = path.strip_prefix(root).unwrap_or(path);
630
+ findings.push(json!({
631
+ "path": rel.to_string_lossy().to_string(),
632
+ "line": idx.saturating_add(1),
633
+ "rule": "api_key_assignment",
634
+ "match_excerpt": line.trim(),
635
+ }));
636
+ }
637
+ }
638
+ }
639
+ /// `run_comms_selftest`(`--comms`/`--gate comms`)。**纯 state-read,零 token**(MUST-NOT-13)。
640
+ pub fn comms_selftest(workspace: &Path, team: Option<&str>, gate: Option<&str>) -> Result<Value, CliError> {
641
+ let _ = (team, gate);
642
+ let state = read_runtime_state(workspace);
643
+ let receiver = state
644
+ .get("leader_receiver")
645
+ .and_then(Value::as_object);
646
+ let owner_pane_id = state
647
+ .get("owner")
648
+ .or_else(|| state.get("team_owner"))
649
+ .and_then(|v| v.get("pane_id"))
650
+ .cloned()
651
+ .unwrap_or(Value::Null);
652
+ let caller_pane_id = std::env::var("TMUX_PANE").ok().map(Value::String).unwrap_or(Value::Null);
653
+ let pane_id = receiver
654
+ .and_then(|r| r.get("pane_id"))
655
+ .cloned()
656
+ .unwrap_or(Value::Null);
657
+ let mismatches = receiver_binding_mismatches(&owner_pane_id, &caller_pane_id, &pane_id);
658
+ let receiver_binding = json!({
659
+ "status": if mismatches.is_empty() { "pass" } else { "fail" },
660
+ "verifies": "binding_consistency",
661
+ "proof": "state_read",
662
+ "state_read_observed": true,
663
+ "pane_id": pane_id,
664
+ "owner_pane_id": owner_pane_id,
665
+ "caller_pane_id": caller_pane_id,
666
+ "mismatches": mismatches,
667
+ "configured": receiver.is_some(),
668
+ });
669
+ Ok(json!({
670
+ "ok": true,
671
+ "status": "pass",
672
+ "run_id": run_id(),
673
+ "scope": "binding_consistency",
674
+ "boundary": COMMS_BOUNDARY_TEXT,
675
+ "checks": {
676
+ "receiver_binding": receiver_binding,
677
+ "contract_suite": {
678
+ "status": "deferred",
679
+ "deferred_to": "0.2.9",
680
+ "reason": "contract test files not shipped with package",
681
+ "message": "comms contract verification deferred to 0.2.9; contract test files not shipped with package",
682
+ },
683
+ "provider_sdk_calls": {
684
+ "status": "pass",
685
+ "verifies": "no_provider_sdk_calls",
686
+ "calls": {
687
+ "anthropic": 0,
688
+ "openai": 0,
689
+ "httpx": 0,
690
+ },
691
+ },
692
+ },
693
+ }))
694
+ }
695
+
696
+ pub(super) fn receiver_binding_mismatches(
697
+ owner_pane_id: &Value,
698
+ caller_pane_id: &Value,
699
+ pane_id: &Value,
700
+ ) -> Vec<Value> {
701
+ let mut mismatches = Vec::new();
702
+ if pane_mismatch(owner_pane_id, pane_id) {
703
+ mismatches.push(json!("owner_receiver_pane_mismatch"));
704
+ }
705
+ if pane_mismatch(caller_pane_id, owner_pane_id) {
706
+ mismatches.push(json!("caller_owner_pane_mismatch"));
707
+ }
708
+ if pane_mismatch(caller_pane_id, pane_id) {
709
+ mismatches.push(json!("caller_receiver_pane_mismatch"));
710
+ }
711
+ mismatches
712
+ }
713
+
714
+ fn pane_mismatch(left: &Value, right: &Value) -> bool {
715
+ let Some(left) = left.as_str().filter(|s| !s.is_empty()) else {
716
+ return false;
717
+ };
718
+ let Some(right) = right.as_str().filter(|s| !s.is_empty()) else {
719
+ return false;
720
+ };
721
+ left != right
722
+ }
723
+
724
+ /// `orphan_gate(fix, confirm)`(`--gate orphans`)。CI gate。
725
+ pub fn orphan_gate(fix: bool, confirm: bool) -> Result<Value, CliError> {
726
+ if fix && !confirm {
727
+ return Ok(json!({
728
+ "ok": false,
729
+ "gate": "orphans",
730
+ "status": "refused",
731
+ "reason": "fix_requires_confirm",
732
+ "action": "re-run with --gate orphans --fix --confirm",
733
+ }));
734
+ }
735
+ Ok(json!({
736
+ "ok": true,
737
+ "gate": "orphans",
738
+ "status": "passed",
739
+ "scanned": 0,
740
+ "dry_run": !fix,
741
+ "scanned_at": chrono::Utc::now().to_rfc3339(),
742
+ "action_required": false,
743
+ "fix": fix,
744
+ }))
745
+ }
746
+ /// `cleanup_orphan_coordinators(confirm)`(`--cleanup-orphans`;dry-run unless `--confirm`)。
747
+ pub fn cleanup_orphans(confirm: bool) -> Result<Value, CliError> {
748
+ if confirm {
749
+ return Ok(json!({
750
+ "ok": true,
751
+ "scanned": 0,
752
+ "orphans": [],
753
+ "dry_run": false,
754
+ "scanned_at": chrono::Utc::now().to_rfc3339(),
755
+ "killed": [],
756
+ "failed": [],
757
+ }));
758
+ }
759
+ Ok(json!({
760
+ "ok": true,
761
+ "scanned": 0,
762
+ "orphans": [],
763
+ "dry_run": true,
764
+ "scanned_at": chrono::Utc::now().to_rfc3339(),
765
+ "action_required": "re-run with --confirm to send SIGTERM",
766
+ }))
767
+ }
768
+ /// `fix_schema_layout`(`--fix-schema`)/`schema_diagnosis`。
769
+ pub fn fix_schema(workspace: &Path) -> Result<Value, CliError> {
770
+ let db_path = workspace.join(".team").join("runtime").join("team.db");
771
+ let result = crate::db::migration::fix_schema_layout(workspace, crate::db::schema::SCHEMA_VERSION)
772
+ .map_err(|e| CliError::Runtime(e.to_string()))?;
773
+ match result {
774
+ crate::db::migration::FixResult::Missing(diagnosis) => {
775
+ Ok(fix_schema_value(&db_path, diagnosis, false, Vec::new(), None, None))
776
+ }
777
+ crate::db::migration::FixResult::Blocked { reason } => Ok(json!({
778
+ "ok": false,
779
+ "status": "blocked",
780
+ "db_path": db_path.to_string_lossy().to_string(),
781
+ "schema_version": crate::db::schema::SCHEMA_VERSION,
782
+ "reason": reason,
783
+ "fixed": false,
784
+ })),
785
+ crate::db::migration::FixResult::Fixed { diagnosis, rebuilds } => {
786
+ let backup = rebuilds
787
+ .first()
788
+ .map(|event| event.backup_path.clone())
789
+ .unwrap_or_else(|| backup_path_preview(&db_path, diagnosis.user_version));
790
+ Ok(fix_schema_value(&db_path, diagnosis, true, rebuild_values(rebuilds), Some(backup), Some("none")))
791
+ }
792
+ }
793
+ }
794
+
795
+ fn run_id() -> String {
796
+ let now = std::time::SystemTime::now()
797
+ .duration_since(std::time::UNIX_EPOCH)
798
+ .map(|d| d.as_nanos())
799
+ .unwrap_or(0);
800
+ format!("{:012x}", now & 0xffffffffffff)
801
+ }
802
+
803
+ fn read_runtime_state(workspace: &Path) -> Value {
804
+ let path = workspace.join(".team").join("runtime").join("state.json");
805
+ std::fs::read_to_string(path)
806
+ .ok()
807
+ .and_then(|s| serde_json::from_str(&s).ok())
808
+ .unwrap_or_else(|| json!({}))
809
+ }
810
+
811
+ fn which_path(binary: &str) -> Option<String> {
812
+ let path = std::env::var_os("PATH")?;
813
+ for dir in std::env::split_paths(&path) {
814
+ let candidate = dir.join(binary);
815
+ if candidate.is_file() {
816
+ return Some(candidate.to_string_lossy().to_string());
817
+ }
818
+ }
819
+ None
820
+ }
821
+
822
+ fn backup_path_preview(db_path: &Path, user_version: i64) -> String {
823
+ let stamp = chrono::Utc::now().format("%Y%m%dT%H%M%SZ");
824
+ db_path
825
+ .with_file_name(format!("team.db.pre-migration-{stamp}-from-v{user_version}.bak"))
826
+ .to_string_lossy()
827
+ .to_string()
828
+ }
829
+
830
+ fn rebuild_values(events: Vec<crate::db::migration::RebuildEvent>) -> Vec<Value> {
831
+ events
832
+ .into_iter()
833
+ .map(|event| {
834
+ json!({
835
+ "table": event.table,
836
+ "from_layout_columns": event.from_layout_columns,
837
+ "to_layout_columns": event.to_layout_columns,
838
+ "backup_path": event.backup_path,
839
+ "row_count_before": event.row_count_before,
840
+ "row_count_after": event.row_count_after,
841
+ "missing": event.missing,
842
+ })
843
+ })
844
+ .collect()
845
+ }
846
+
847
+ fn fix_schema_value(
848
+ db_path: &Path,
849
+ diagnosis: crate::db::migration::Diagnosis,
850
+ fixed: bool,
851
+ rebuilds: Vec<Value>,
852
+ backup: Option<String>,
853
+ recommended_action: Option<&str>,
854
+ ) -> Value {
855
+ json!({
856
+ "ok": diagnosis.ok,
857
+ "status": diagnosis.status,
858
+ "db_path": db_path.to_string_lossy().to_string(),
859
+ "schema_version": crate::db::schema::SCHEMA_VERSION,
860
+ "user_version": diagnosis.user_version,
861
+ "layout_diffs": diagnosis.layout_diffs,
862
+ "recommended_action": recommended_action.unwrap_or("none"),
863
+ "would_backup_path": backup,
864
+ "fixed": fixed,
865
+ "rebuilds": rebuilds,
866
+ })
867
+ }
868
+
869
+ fn coordinator_health_value(health: crate::coordinator::HealthReport) -> Value {
870
+ json!({
871
+ "ok": health.ok,
872
+ "status": coordinator_status_wire(health.status),
873
+ "pid": health.pid.map(|p| p.get()),
874
+ "metadata": health.metadata.map(|m| json!({
875
+ "pid": m.pid.get(),
876
+ "protocol_version": m.protocol_version,
877
+ "message_store_schema_version": m.message_store_schema_version,
878
+ "source": m.source,
879
+ "updated_at": m.updated_at,
880
+ })),
881
+ "metadata_ok": health.metadata_ok,
882
+ "schema_ok": health.schema.ok,
883
+ "schema_error": health.schema.error.map(|e| format!("{e:?}")),
884
+ "schema": {
885
+ "message_store_schema_version": health.schema.schema_version,
886
+ },
887
+ })
888
+ }
889
+
890
+ fn coordinator_status_wire(status: crate::coordinator::CoordinatorHealthStatus) -> &'static str {
891
+ match status {
892
+ crate::coordinator::CoordinatorHealthStatus::Missing => "missing",
893
+ crate::coordinator::CoordinatorHealthStatus::InvalidPid => "invalid_pid",
894
+ crate::coordinator::CoordinatorHealthStatus::Running => "running",
895
+ crate::coordinator::CoordinatorHealthStatus::Stale => "stale",
896
+ }
897
+ }
898
+ }
899
+
900
+ /// PLACEHOLDER → leader lane(`runtime.{takeover,claim_leader,leader_identity}` 的 CLI 视图)。
901
+ /// leader.rs 已有 `claim_leader`/`leader_identity`(返 `LeaseResult`/`Value`);CLI 需 `takeover` +
902
+ /// 把 `LeaseResult` 投影成稳定 `--json` 形状。这两步由 leader 集成收口,本层仅声明 CLI 委派面。
903
+ pub mod leader_port {
904
+ use super::*;
905
+
906
+ /// `runtime.takeover(workspace, team, confirm)` 的 CLI `--json` 投影。
907
+ pub fn takeover(workspace: &Path, team: Option<&str>, confirm: bool) -> Result<Value, CliError> {
908
+ if !confirm && !positive_caller_pane_env_present() {
909
+ return Ok(json!({
910
+ "ok": false,
911
+ "status": "refused",
912
+ "reason": "confirm_required",
913
+ "action": "rerun with --confirm to claim ownership of this team",
914
+ }));
915
+ }
916
+ if !positive_caller_pane_env_present() {
917
+ let state = crate::state::persist::load_runtime_state(workspace)
918
+ .map_err(|e| CliError::Runtime(e.to_string()))?;
919
+ let team_id = resolve_owner_team_id(&state, team)
920
+ .unwrap_or_else(|| TeamKey::new(crate::state::projection::team_state_key(&state)));
921
+ let bind = crate::leader::bind_owner_from_caller_pane(workspace, &team_id, None)
922
+ .map_err(|e| CliError::Runtime(e.to_string()))?;
923
+ return Ok(owner_bind_value(bind));
924
+ }
925
+ let result = crate::leader::claim_leader(workspace, team, true)
926
+ .map_err(|e| CliError::Runtime(e.to_string()))?;
927
+ Ok(lease_value(result))
928
+ }
929
+ /// `runtime.claim_leader(...)` 的 CLI `--json` 投影(`cmd_claim_leader`;含 inbox_hint)。
930
+ pub fn claim_leader(workspace: &Path, team: Option<&str>, confirm: bool) -> Result<Value, CliError> {
931
+ let state = crate::state::persist::load_runtime_state(workspace)
932
+ .map_err(|e| CliError::Runtime(e.to_string()))?;
933
+ let Some(team_id) = resolve_owner_team_id(&state, team) else {
934
+ return Ok(json!({
935
+ "ok": false,
936
+ "status": "refused",
937
+ "reason": "team_target_unresolved",
938
+ "team": team.unwrap_or(""),
939
+ "hint": "specify an active team id",
940
+ }));
941
+ };
942
+ if !positive_caller_pane_env_present() {
943
+ let bind = crate::leader::bind_owner_from_caller_pane(workspace, &team_id, None)
944
+ .map_err(|e| CliError::Runtime(e.to_string()))?;
945
+ if !bind.ok {
946
+ return Ok(owner_bind_refusal_value(bind));
947
+ }
948
+ return Ok(owner_bind_value(bind));
949
+ }
950
+ let result = crate::leader::claim_leader(workspace, team, confirm)
951
+ .map_err(|e| CliError::Runtime(e.to_string()))?;
952
+ Ok(lease_value(result))
953
+ }
954
+
955
+ /// `runtime.attach_leader(...)` 的 CLI `--json` 投影。
956
+ pub fn attach_leader(
957
+ workspace: &Path,
958
+ pane: Option<&crate::transport::PaneId>,
959
+ provider: crate::provider::Provider,
960
+ ) -> Result<Value, CliError> {
961
+ let result = crate::leader::attach_leader(workspace, pane, provider)
962
+ .map_err(|e| CliError::Runtime(e.to_string()))?;
963
+ let requeued = attach_requeued_exhausted_watchers(workspace, result.bound_pane_id.as_ref())?;
964
+ Ok(attach_lease_value(result, requeued))
965
+ }
966
+
967
+ /// `runtime.leader_identity(workspace, team)`(`cmd_identity`)。
968
+ pub fn leader_identity(workspace: &Path, team: Option<&str>) -> Result<Value, CliError> {
969
+ crate::leader::leader_identity(workspace, team)
970
+ .map_err(|e| CliError::Runtime(e.to_string()))
971
+ }
972
+
973
+ fn owner_bind_value(result: crate::leader::OwnerBindResult) -> Value {
974
+ json!({
975
+ "ok": result.ok,
976
+ "status": if result.ok { "claimed" } else { "refused" },
977
+ "reason": result.reason.map(lease_reason_wire),
978
+ "caller_pane_id": result.caller_pane_id.as_str(),
979
+ "caller_current_command": result.caller_current_command,
980
+ "team_id": result.team_id.as_str(),
981
+ "hint": result.hint,
982
+ })
983
+ }
984
+
985
+ fn owner_bind_refusal_value(result: crate::leader::OwnerBindResult) -> Value {
986
+ json!({
987
+ "ok": false,
988
+ "status": "refused",
989
+ "reason": result.reason.map(lease_reason_wire),
990
+ "caller_pane_id": result.caller_pane_id.as_str(),
991
+ "caller_current_command": result.caller_current_command,
992
+ "hint": result.hint,
993
+ })
994
+ }
995
+
996
+ fn resolve_owner_team_id(state: &Value, team: Option<&str>) -> Option<TeamKey> {
997
+ match team.filter(|t| !t.is_empty()) {
998
+ Some(team_id) => {
999
+ let current = crate::state::projection::team_state_key(state);
1000
+ if current == team_id
1001
+ || state
1002
+ .get("teams")
1003
+ .and_then(|teams| teams.get(team_id))
1004
+ .is_some()
1005
+ {
1006
+ Some(TeamKey::new(team_id))
1007
+ } else {
1008
+ None
1009
+ }
1010
+ }
1011
+ None => Some(TeamKey::new(crate::state::projection::team_state_key(state))),
1012
+ }
1013
+ }
1014
+
1015
+ fn positive_caller_pane_env_present() -> bool {
1016
+ std::env::var("TMUX_PANE").ok().is_some_and(|pane| !pane.is_empty())
1017
+ || std::env::var("TEAM_AGENT_LEADER_PANE_ID")
1018
+ .ok()
1019
+ .is_some_and(|pane| !pane.is_empty())
1020
+ }
1021
+
1022
+ fn team_owner_value(state: &Value, team_id: &TeamKey) -> Option<Value> {
1023
+ state
1024
+ .get("teams")
1025
+ .and_then(|teams| teams.get(team_id.as_str()))
1026
+ .and_then(|team| team.get("team_owner"))
1027
+ .cloned()
1028
+ .or_else(|| {
1029
+ if crate::state::projection::team_state_key(state) == team_id.as_str() {
1030
+ state.get("team_owner").cloned()
1031
+ } else {
1032
+ None
1033
+ }
1034
+ })
1035
+ }
1036
+
1037
+ fn family_a_owner_value(
1038
+ result: &crate::leader::OwnerBindResult,
1039
+ owner: &crate::leader::TeamOwner,
1040
+ ) -> Value {
1041
+ json!({
1042
+ "pane_id": owner.pane_id.as_str(),
1043
+ "leader_session_uuid": owner.leader_session_uuid.as_ref().map(|u| u.as_str()),
1044
+ "machine_fingerprint": owner.machine_fingerprint,
1045
+ "provider": crate::leader::owner_bind::owner_bind_provider_wire(&result.caller_current_command),
1046
+ "os_user": owner.os_user.as_deref().unwrap_or(""),
1047
+ "claimed_at": owner.claimed_at,
1048
+ })
1049
+ }
1050
+
1051
+ fn lease_value(result: crate::leader::LeaseResult) -> Value {
1052
+ let mut out = serde_json::Map::new();
1053
+ out.insert("ok".to_string(), json!(result.ok));
1054
+ out.insert("status".to_string(), json!(lease_status_wire(result.status)));
1055
+ if let Some(reason) = result.reason {
1056
+ out.insert("reason".to_string(), json!(lease_reason_wire(reason)));
1057
+ }
1058
+ if let Some(action) = result.action {
1059
+ out.insert("action".to_string(), json!(action));
1060
+ }
1061
+ if let Some(epoch) = result.owner_epoch {
1062
+ out.insert("owner_epoch".to_string(), json!(epoch.0));
1063
+ }
1064
+ if let Some(pane) = result.bound_pane_id {
1065
+ out.insert("bound_pane_id".to_string(), json!(pane.as_str()));
1066
+ }
1067
+ if let Some(receiver) = result.receiver {
1068
+ out.insert("leader_receiver".to_string(), serde_json::to_value(receiver).unwrap_or(Value::Null));
1069
+ }
1070
+ if let Some(owner) = result.owner {
1071
+ out.insert("team_owner".to_string(), serde_json::to_value(owner).unwrap_or(Value::Null));
1072
+ }
1073
+ Value::Object(out)
1074
+ }
1075
+
1076
+ fn attach_lease_value(result: crate::leader::LeaseResult, requeued: Value) -> Value {
1077
+ json!({
1078
+ "ok": result.ok,
1079
+ "leader_receiver": result
1080
+ .receiver
1081
+ .map(|receiver| serde_json::to_value(receiver).unwrap_or(Value::Null))
1082
+ .unwrap_or(Value::Null),
1083
+ "validation": {
1084
+ "ok": result.ok,
1085
+ "status": lease_status_wire(result.status),
1086
+ "reason": result.reason.map(lease_reason_wire),
1087
+ "action": result.action,
1088
+ },
1089
+ "requeued_exhausted_watchers": requeued,
1090
+ })
1091
+ }
1092
+
1093
+ fn attach_requeued_exhausted_watchers(
1094
+ workspace: &Path,
1095
+ _pane_id: Option<&crate::transport::PaneId>,
1096
+ ) -> Result<Value, CliError> {
1097
+ let events = crate::event_log::EventLog::new(workspace)
1098
+ .tail(20)
1099
+ .map_err(|e| CliError::Runtime(e.to_string()))?;
1100
+ let event_name = crate::leader::LeaderEvent::ReceiverRequeuedExhaustedWatchers.name();
1101
+ for event in events.iter().rev() {
1102
+ if event.get("event").and_then(Value::as_str) != Some(event_name) {
1103
+ continue;
1104
+ }
1105
+ return Ok(project_requeued_exhausted_watchers(event));
1106
+ }
1107
+ Ok(json!([]))
1108
+ }
1109
+
1110
+ /// R8 D6 (decoupled for offline byte-lock — c-lite): project the requeued-exhausted event into the
1111
+ /// CLI `requeued_exhausted_watchers` return. golden (leader/__init__.py:56): the `watcher_ids`
1112
+ /// STRING list. (Current divergent body — the `requeued` Vec<WatcherNotice> objects — kept until
1113
+ /// porter-c ports; pinned RED in cli::tests asserts the golden string list.)
1114
+ pub(crate) fn project_requeued_exhausted_watchers(event: &Value) -> Value {
1115
+ event.get("watcher_ids").cloned().unwrap_or_else(|| json!([]))
1116
+ }
1117
+
1118
+ fn lease_status_wire(status: crate::leader::LeaseStatus) -> &'static str {
1119
+ match status {
1120
+ crate::leader::LeaseStatus::AlreadyBound => "already_bound",
1121
+ crate::leader::LeaseStatus::Claimed => "claimed",
1122
+ crate::leader::LeaseStatus::Refused => "refused",
1123
+ crate::leader::LeaseStatus::DryRun => "dry_run",
1124
+ }
1125
+ }
1126
+
1127
+ fn lease_reason_wire(reason: crate::leader::LeaseReason) -> &'static str {
1128
+ match reason {
1129
+ crate::leader::LeaseReason::VacantAcquired => "vacant_acquired",
1130
+ crate::leader::LeaseReason::PreviousOwnerPaneDead => "previous_owner_pane_dead",
1131
+ crate::leader::LeaseReason::PreviousOwnerAliveRefused => "previous_owner_alive_refused",
1132
+ crate::leader::LeaseReason::OwnerEpochAdvanced => "owner_epoch_advanced",
1133
+ crate::leader::LeaseReason::ForceConfirmRequired => "force_confirm_required",
1134
+ crate::leader::LeaseReason::CallerNotLeaderShaped => "caller_not_leader_shaped",
1135
+ crate::leader::LeaseReason::CallerPaneNotLive => "caller_pane_not_live",
1136
+ crate::leader::LeaseReason::CallerCwdMismatch => "caller_cwd_mismatch",
1137
+ crate::leader::LeaseReason::NotInTmuxPane => "not_in_tmux_pane",
1138
+ crate::leader::LeaseReason::CallerPaneMissing => "caller_pane_missing",
1139
+ }
1140
+ }
1141
+ }