@team-agent/installer 0.5.127 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (421) hide show
  1. package/README.md +15 -4
  2. package/README.zh.md +1 -1
  3. package/package.json +4 -8
  4. package/skills/team-agent/SKILL.md +41 -26
  5. package/skills/team-agent/command-coverage.json +170 -184
  6. package/skills/team-agent/docs/reference/team-agent-operator.md +66 -32
  7. package/skills/team-agent/references/recovery-runbook.md +1 -1
  8. package/skills/team-agent/references/team-agent-operator.md +66 -32
  9. package/templates/team_state.md +1 -1
  10. package/Cargo.lock +0 -1063
  11. package/Cargo.toml +0 -36
  12. package/crates/team-agent/Cargo.toml +0 -69
  13. package/crates/team-agent/src/app_server_test_support.rs +0 -258
  14. package/crates/team-agent/src/cli/adapters.rs +0 -1298
  15. package/crates/team-agent/src/cli/arguments.rs +0 -401
  16. package/crates/team-agent/src/cli/attach_app_server_leader.rs +0 -98
  17. package/crates/team-agent/src/cli/diagnose.rs +0 -1675
  18. package/crates/team-agent/src/cli/emit.rs +0 -2898
  19. package/crates/team-agent/src/cli/grok_slot.rs +0 -384
  20. package/crates/team-agent/src/cli/helpers.rs +0 -91
  21. package/crates/team-agent/src/cli/intent/runtime.rs +0 -1189
  22. package/crates/team-agent/src/cli/intent/runtime_tests.rs +0 -821
  23. package/crates/team-agent/src/cli/intent/tests.rs +0 -691
  24. package/crates/team-agent/src/cli/intent.rs +0 -664
  25. package/crates/team-agent/src/cli/leader.rs +0 -300
  26. package/crates/team-agent/src/cli/leader_prompt.rs +0 -261
  27. package/crates/team-agent/src/cli/leaders.rs +0 -418
  28. package/crates/team-agent/src/cli/mod.rs +0 -6528
  29. package/crates/team-agent/src/cli/models.rs +0 -449
  30. package/crates/team-agent/src/cli/named_address.rs +0 -1651
  31. package/crates/team-agent/src/cli/profile.rs +0 -342
  32. package/crates/team-agent/src/cli/route.rs +0 -212
  33. package/crates/team-agent/src/cli/send/coordinator.rs +0 -164
  34. package/crates/team-agent/src/cli/send/mailbox.rs +0 -145
  35. package/crates/team-agent/src/cli/send/persist.rs +0 -192
  36. package/crates/team-agent/src/cli/send/presentation.rs +0 -370
  37. package/crates/team-agent/src/cli/send/resolve.rs +0 -573
  38. package/crates/team-agent/src/cli/send.rs +0 -201
  39. package/crates/team-agent/src/cli/shutdown_socket.rs +0 -288
  40. package/crates/team-agent/src/cli/spec.rs +0 -159
  41. package/crates/team-agent/src/cli/status.rs +0 -280
  42. package/crates/team-agent/src/cli/status_port/agents.rs +0 -358
  43. package/crates/team-agent/src/cli/status_port/approvals.rs +0 -79
  44. package/crates/team-agent/src/cli/status_port/brief.rs +0 -2043
  45. package/crates/team-agent/src/cli/status_port/compact.rs +0 -240
  46. package/crates/team-agent/src/cli/status_port/format.rs +0 -146
  47. package/crates/team-agent/src/cli/status_port/inbox.rs +0 -62
  48. package/crates/team-agent/src/cli/status_port/runtime.rs +0 -197
  49. package/crates/team-agent/src/cli/status_port/snapshot.rs +0 -208
  50. package/crates/team-agent/src/cli/status_port/store.rs +0 -416
  51. package/crates/team-agent/src/cli/status_port/tests.rs +0 -90
  52. package/crates/team-agent/src/cli/status_port.rs +0 -92
  53. package/crates/team-agent/src/cli/tests/base.rs +0 -885
  54. package/crates/team-agent/src/cli/tests/divergence.rs +0 -518
  55. package/crates/team-agent/src/cli/tests/lane_c.rs +0 -453
  56. package/crates/team-agent/src/cli/tests/leader_watch.rs +0 -372
  57. package/crates/team-agent/src/cli/tests/main_preserved.rs +0 -430
  58. package/crates/team-agent/src/cli/tests/missing_subcommands.rs +0 -336
  59. package/crates/team-agent/src/cli/tests/mod.rs +0 -137
  60. package/crates/team-agent/src/cli/tests/named_address.rs +0 -760
  61. package/crates/team-agent/src/cli/tests/parser_safety.rs +0 -383
  62. package/crates/team-agent/src/cli/tests/run_delegation.rs +0 -481
  63. package/crates/team-agent/src/cli/tests/shutdown_kill_plan.rs +0 -2179
  64. package/crates/team-agent/src/cli/tests/status_brief.rs +0 -1514
  65. package/crates/team-agent/src/cli/tests/status_send.rs +0 -1091
  66. package/crates/team-agent/src/cli/tests/verb_install_skill.rs +0 -93
  67. package/crates/team-agent/src/cli/tests/verb_profile.rs +0 -392
  68. package/crates/team-agent/src/cli/triage.rs +0 -234
  69. package/crates/team-agent/src/cli/types.rs +0 -591
  70. package/crates/team-agent/src/codex_app_server.rs +0 -546
  71. package/crates/team-agent/src/communication_mode/mod.rs +0 -56
  72. package/crates/team-agent/src/compiler/tests.rs +0 -842
  73. package/crates/team-agent/src/compiler.rs +0 -691
  74. package/crates/team-agent/src/conpty/backend.rs +0 -829
  75. package/crates/team-agent/src/conpty/mod.rs +0 -33
  76. package/crates/team-agent/src/contract_runtime/backend.rs +0 -1610
  77. package/crates/team-agent/src/contract_runtime/commands.rs +0 -671
  78. package/crates/team-agent/src/contract_runtime/config.rs +0 -354
  79. package/crates/team-agent/src/contract_runtime/config_tests.rs +0 -56
  80. package/crates/team-agent/src/contract_runtime/discovery.rs +0 -438
  81. package/crates/team-agent/src/contract_runtime/fork.rs +0 -368
  82. package/crates/team-agent/src/contract_runtime/forward.rs +0 -288
  83. package/crates/team-agent/src/contract_runtime/framework.rs +0 -350
  84. package/crates/team-agent/src/contract_runtime/mcp.rs +0 -399
  85. package/crates/team-agent/src/contract_runtime/mod.rs +0 -17
  86. package/crates/team-agent/src/contract_runtime/prompt.rs +0 -216
  87. package/crates/team-agent/src/contract_runtime/pump.rs +0 -271
  88. package/crates/team-agent/src/contract_runtime/registry.rs +0 -589
  89. package/crates/team-agent/src/contract_runtime/workspace.rs +0 -228
  90. package/crates/team-agent/src/coordinator/backoff.rs +0 -741
  91. package/crates/team-agent/src/coordinator/conpty_shim.rs +0 -805
  92. package/crates/team-agent/src/coordinator/health.rs +0 -1185
  93. package/crates/team-agent/src/coordinator/mod.rs +0 -119
  94. package/crates/team-agent/src/coordinator/orphan.rs +0 -110
  95. package/crates/team-agent/src/coordinator/runtime_detectors.rs +0 -798
  96. package/crates/team-agent/src/coordinator/runtime_observation.rs +0 -84
  97. package/crates/team-agent/src/coordinator/steps/abnormal.rs +0 -2309
  98. package/crates/team-agent/src/coordinator/steps/delivery.rs +0 -15
  99. package/crates/team-agent/src/coordinator/steps/health_sync.rs +0 -15
  100. package/crates/team-agent/src/coordinator/steps/mod.rs +0 -126
  101. package/crates/team-agent/src/coordinator/steps/persist.rs +0 -15
  102. package/crates/team-agent/src/coordinator/steps/runtime_prompts.rs +0 -15
  103. package/crates/team-agent/src/coordinator/steps/session_gate.rs +0 -16
  104. package/crates/team-agent/src/coordinator/tests/a0_lostupdate.rs +0 -158
  105. package/crates/team-agent/src/coordinator/tests/abnormal.rs +0 -312
  106. package/crates/team-agent/src/coordinator/tests/api_error_recovery.rs +0 -338
  107. package/crates/team-agent/src/coordinator/tests/basics.rs +0 -211
  108. package/crates/team-agent/src/coordinator/tests/daemon.rs +0 -514
  109. package/crates/team-agent/src/coordinator/tests/energy.rs +0 -549
  110. package/crates/team-agent/src/coordinator/tests/health_sync.rs +0 -461
  111. package/crates/team-agent/src/coordinator/tests/main_preserved.rs +0 -186
  112. package/crates/team-agent/src/coordinator/tests/mod.rs +0 -295
  113. package/crates/team-agent/src/coordinator/tests/s3_bounded.rs +0 -207
  114. package/crates/team-agent/src/coordinator/tests/spine.rs +0 -308
  115. package/crates/team-agent/src/coordinator/tests/takeover.rs +0 -286
  116. package/crates/team-agent/src/coordinator/tests/tick_core.rs +0 -237
  117. package/crates/team-agent/src/coordinator/tick.rs +0 -3112
  118. package/crates/team-agent/src/coordinator/types.rs +0 -540
  119. package/crates/team-agent/src/db/agent_health_capture.rs +0 -126
  120. package/crates/team-agent/src/db/message_store.rs +0 -1585
  121. package/crates/team-agent/src/db/migration.rs +0 -984
  122. package/crates/team-agent/src/db/mod.rs +0 -26
  123. package/crates/team-agent/src/db/schema.rs +0 -663
  124. package/crates/team-agent/src/diagnose/comms.rs +0 -242
  125. package/crates/team-agent/src/diagnose/mod.rs +0 -44
  126. package/crates/team-agent/src/diagnose/orphans.rs +0 -889
  127. package/crates/team-agent/src/event_log.rs +0 -502
  128. package/crates/team-agent/src/fake_worker.rs +0 -303
  129. package/crates/team-agent/src/kill_audit.rs +0 -106
  130. package/crates/team-agent/src/layout/manager.rs +0 -248
  131. package/crates/team-agent/src/layout/mod.rs +0 -36
  132. package/crates/team-agent/src/layout/overlay.rs +0 -134
  133. package/crates/team-agent/src/layout/placement.rs +0 -52
  134. package/crates/team-agent/src/layout/recovery.rs +0 -106
  135. package/crates/team-agent/src/layout/runtime_sessions.rs +0 -317
  136. package/crates/team-agent/src/layout/sessions.rs +0 -294
  137. package/crates/team-agent/src/layout/tmux_endpoint.rs +0 -165
  138. package/crates/team-agent/src/layout/worker_env.rs +0 -721
  139. package/crates/team-agent/src/layout/worker_window_helpers.rs +0 -37
  140. package/crates/team-agent/src/leader/helpers.rs +0 -178
  141. package/crates/team-agent/src/leader/incident.rs +0 -6
  142. package/crates/team-agent/src/leader/lease.rs +0 -3356
  143. package/crates/team-agent/src/leader/mod.rs +0 -104
  144. package/crates/team-agent/src/leader/owner_bind.rs +0 -400
  145. package/crates/team-agent/src/leader/prompt.rs +0 -905
  146. package/crates/team-agent/src/leader/provider_attribution.rs +0 -247
  147. package/crates/team-agent/src/leader/rediscover/tests.rs +0 -689
  148. package/crates/team-agent/src/leader/rediscover.rs +0 -1192
  149. package/crates/team-agent/src/leader/registry.rs +0 -883
  150. package/crates/team-agent/src/leader/start.rs +0 -4500
  151. package/crates/team-agent/src/leader/takeover.rs +0 -65
  152. package/crates/team-agent/src/leader/tests/basics.rs +0 -337
  153. package/crates/team-agent/src/leader/tests/byte_findings.rs +0 -355
  154. package/crates/team-agent/src/leader/tests/claim_leader_mailbox_flush_contract.rs +0 -544
  155. package/crates/team-agent/src/leader/tests/historical_inventory_upgrade_gate_red.rs +0 -624
  156. package/crates/team-agent/src/leader/tests/identity.rs +0 -465
  157. package/crates/team-agent/src/leader/tests/identity_session_names.rs +0 -42
  158. package/crates/team-agent/src/leader/tests/idle.rs +0 -113
  159. package/crates/team-agent/src/leader/tests/lease_api.rs +0 -520
  160. package/crates/team-agent/src/leader/tests/lease_claim.rs +0 -629
  161. package/crates/team-agent/src/leader/tests/mod.rs +0 -106
  162. package/crates/team-agent/src/leader/tests/prompt_contract.rs +0 -267
  163. package/crates/team-agent/src/leader/tests/rediscover.rs +0 -403
  164. package/crates/team-agent/src/leader/tests/rehomed_env.rs +0 -83
  165. package/crates/team-agent/src/leader/tests/team_in_team_state_scope_red.rs +0 -1273
  166. package/crates/team-agent/src/leader/tests/terminal_and_replay_vs_rerender_invariants_red.rs +0 -417
  167. package/crates/team-agent/src/leader/tests/wake_start_owner.rs +0 -168
  168. package/crates/team-agent/src/leader/types.rs +0 -534
  169. package/crates/team-agent/src/lib.rs +0 -145
  170. package/crates/team-agent/src/lifecycle/helpers.rs +0 -212
  171. package/crates/team-agent/src/lifecycle/launch/add_agent.rs +0 -848
  172. package/crates/team-agent/src/lifecycle/launch/add_agent_state.rs +0 -393
  173. package/crates/team-agent/src/lifecycle/launch/agent_state.rs +0 -332
  174. package/crates/team-agent/src/lifecycle/launch/clone_agent.rs +0 -178
  175. package/crates/team-agent/src/lifecycle/launch/fork_agent.rs +0 -82
  176. package/crates/team-agent/src/lifecycle/launch/fork_entry.rs +0 -63
  177. package/crates/team-agent/src/lifecycle/launch/identity.rs +0 -674
  178. package/crates/team-agent/src/lifecycle/launch/layout.rs +0 -350
  179. package/crates/team-agent/src/lifecycle/launch/leader_context.rs +0 -589
  180. package/crates/team-agent/src/lifecycle/launch/mcp_config.rs +0 -152
  181. package/crates/team-agent/src/lifecycle/launch/ownership.rs +0 -105
  182. package/crates/team-agent/src/lifecycle/launch/pi_mcp.rs +0 -629
  183. package/crates/team-agent/src/lifecycle/launch/pi_mcp_extension.js +0 -226
  184. package/crates/team-agent/src/lifecycle/launch/plan.rs +0 -269
  185. package/crates/team-agent/src/lifecycle/launch/quick_start.rs +0 -5176
  186. package/crates/team-agent/src/lifecycle/launch/quick_start_transport.rs +0 -368
  187. package/crates/team-agent/src/lifecycle/launch/readiness.rs +0 -519
  188. package/crates/team-agent/src/lifecycle/launch/role_source.rs +0 -287
  189. package/crates/team-agent/src/lifecycle/launch/spawn.rs +0 -450
  190. package/crates/team-agent/src/lifecycle/launch/spec_state.rs +0 -801
  191. package/crates/team-agent/src/lifecycle/launch/state_projection.rs +0 -624
  192. package/crates/team-agent/src/lifecycle/launch/worker_env.rs +0 -558
  193. package/crates/team-agent/src/lifecycle/launch.rs +0 -534
  194. package/crates/team-agent/src/lifecycle/lock.rs +0 -350
  195. package/crates/team-agent/src/lifecycle/mod.rs +0 -79
  196. package/crates/team-agent/src/lifecycle/pane_input_lock.rs +0 -239
  197. package/crates/team-agent/src/lifecycle/profile_launch.rs +0 -757
  198. package/crates/team-agent/src/lifecycle/profile_smoke.rs +0 -557
  199. package/crates/team-agent/src/lifecycle/restart/agent.rs +0 -2198
  200. package/crates/team-agent/src/lifecycle/restart/common.rs +0 -2052
  201. package/crates/team-agent/src/lifecycle/restart/orchestrator.rs +0 -65
  202. package/crates/team-agent/src/lifecycle/restart/preflight.rs +0 -113
  203. package/crates/team-agent/src/lifecycle/restart/rebuild.rs +0 -5135
  204. package/crates/team-agent/src/lifecycle/restart/remove.rs +0 -1504
  205. package/crates/team-agent/src/lifecycle/restart/selection.rs +0 -559
  206. package/crates/team-agent/src/lifecycle/restart/team_state.rs +0 -329
  207. package/crates/team-agent/src/lifecycle/restart.rs +0 -223
  208. package/crates/team-agent/src/lifecycle/role_config.rs +0 -1205
  209. package/crates/team-agent/src/lifecycle/tests/acceptance_b_batch_red.rs +0 -1021
  210. package/crates/team-agent/src/lifecycle/tests/agent_ops.rs +0 -1205
  211. package/crates/team-agent/src/lifecycle/tests/b0_legacy_snapshot_nonauthority_contract.rs +0 -265
  212. package/crates/team-agent/src/lifecycle/tests/b0_reader_hideone_audit_contract.rs +0 -490
  213. package/crates/team-agent/src/lifecycle/tests/behavioral_diff_264_red.rs +0 -656
  214. package/crates/team-agent/src/lifecycle/tests/claude_profile_launch_red.rs +0 -135
  215. package/crates/team-agent/src/lifecycle/tests/cli_argv_routing_red.rs +0 -1415
  216. package/crates/team-agent/src/lifecycle/tests/clone_agent_preserves_source_tools.rs +0 -427
  217. package/crates/team-agent/src/lifecycle/tests/clone_fork_copilot_perms_red.rs +0 -396
  218. package/crates/team-agent/src/lifecycle/tests/communication_mode_runtime_contract_red.rs +0 -418
  219. package/crates/team-agent/src/lifecycle/tests/copilot_provider_red.rs +0 -2039
  220. package/crates/team-agent/src/lifecycle/tests/core.rs +0 -1298
  221. package/crates/team-agent/src/lifecycle/tests/f032_startup_prompt_best_effort_red.rs +0 -315
  222. package/crates/team-agent/src/lifecycle/tests/fixtures/pi_list_models_g0.stdout.txt +0 -222
  223. package/crates/team-agent/src/lifecycle/tests/fixtures/pi_list_models_spaced_ids.stdout.txt +0 -9
  224. package/crates/team-agent/src/lifecycle/tests/fixtures/pi_native_mcp_host.mjs +0 -71
  225. package/crates/team-agent/src/lifecycle/tests/gate_fixtures.rs +0 -562
  226. package/crates/team-agent/src/lifecycle/tests/grok_require_explicit_model_red.rs +0 -110
  227. package/crates/team-agent/src/lifecycle/tests/harvest2_a_batch_red.rs +0 -472
  228. package/crates/team-agent/src/lifecycle/tests/host_cotenant_death_p0_contract.rs +0 -921
  229. package/crates/team-agent/src/lifecycle/tests/issue238_codex_effort_contract.rs +0 -68
  230. package/crates/team-agent/src/lifecycle/tests/lane_ops.rs +0 -1851
  231. package/crates/team-agent/src/lifecycle/tests/launch_spawn.rs +0 -3981
  232. package/crates/team-agent/src/lifecycle/tests/lifecycle_lock.rs +0 -339
  233. package/crates/team-agent/src/lifecycle/tests/lifecycle_rollback_red.rs +0 -596
  234. package/crates/team-agent/src/lifecycle/tests/main_preserved.rs +0 -513
  235. package/crates/team-agent/src/lifecycle/tests/mcp_tool_name_format_red.rs +0 -69
  236. package/crates/team-agent/src/lifecycle/tests/phase_b_contracts.rs +0 -824
  237. package/crates/team-agent/src/lifecycle/tests/phase_golden.rs +0 -723
  238. package/crates/team-agent/src/lifecycle/tests/pi_catalog_red.rs +0 -152
  239. package/crates/team-agent/src/lifecycle/tests/pi_command_red.rs +0 -182
  240. package/crates/team-agent/src/lifecycle/tests/pi_dual_entry_red.rs +0 -374
  241. package/crates/team-agent/src/lifecycle/tests/pi_executable_mcp_red.rs +0 -546
  242. package/crates/team-agent/src/lifecycle/tests/pi_lifecycle_doctor_red.rs +0 -31
  243. package/crates/team-agent/src/lifecycle/tests/pi_native_mcp_capability_red.rs +0 -528
  244. package/crates/team-agent/src/lifecycle/tests/pi_session_delivery_red.rs +0 -134
  245. package/crates/team-agent/src/lifecycle/tests/quick_start_worker_readiness_red.rs +0 -333
  246. package/crates/team-agent/src/lifecycle/tests/realmachine_clusters_1_6_red.rs +0 -786
  247. package/crates/team-agent/src/lifecycle/tests/realmachine_residual_g1_g4_red.rs +0 -648
  248. package/crates/team-agent/src/lifecycle/tests/restart.rs +0 -185
  249. package/crates/team-agent/src/lifecycle/tests/restart_build_before_destroy_0540_contract.rs +0 -1053
  250. package/crates/team-agent/src/lifecycle/tests/restart_liveness_red.rs +0 -679
  251. package/crates/team-agent/src/lifecycle/tests/restart_rebind_hotfix_252_red.rs +0 -1126
  252. package/crates/team-agent/src/lifecycle/tests/restart_session_capture_red.rs +0 -153
  253. package/crates/team-agent/src/lifecycle/tests/resume_recover_red.rs +0 -427
  254. package/crates/team-agent/src/lifecycle/tests/stale_team_saveconflict_contract.rs +0 -431
  255. package/crates/team-agent/src/lifecycle/tests/startup_latency_contract.rs +0 -1066
  256. package/crates/team-agent/src/lifecycle/tests/status_credential_redaction_contract.rs +0 -876
  257. package/crates/team-agent/src/lifecycle/tests/subprep_codex_trust_roundtrip_red.rs +0 -1026
  258. package/crates/team-agent/src/lifecycle/tests/swallow_batch4_semantics_red.rs +0 -90
  259. package/crates/team-agent/src/lifecycle/tests/team_in_team_identity_scope_red.rs +0 -543
  260. package/crates/team-agent/src/lifecycle/tests/team_in_team_sibling_quick_start_red.rs +0 -1103
  261. package/crates/team-agent/src/lifecycle/tests/team_in_team_state_scope_red.rs +0 -1276
  262. package/crates/team-agent/src/lifecycle/tests/team_key_retirement_roster_red.rs +0 -145
  263. package/crates/team-agent/src/lifecycle/tests/team_key_retirement_txn_red.rs +0 -603
  264. package/crates/team-agent/src/lifecycle/tests/test_isolation_escape_contract.rs +0 -936
  265. package/crates/team-agent/src/lifecycle/tests/upgrade_compat_0211_red.rs +0 -970
  266. package/crates/team-agent/src/lifecycle/tests/verify_rs031_window_consistency_red.rs +0 -996
  267. package/crates/team-agent/src/lifecycle/tests/worker_spawn_env_red.rs +0 -827
  268. package/crates/team-agent/src/lifecycle/tests.rs +0 -102
  269. package/crates/team-agent/src/lifecycle/types.rs +0 -861
  270. package/crates/team-agent/src/lifecycle/worker_command_context.rs +0 -370
  271. package/crates/team-agent/src/main.rs +0 -52
  272. package/crates/team-agent/src/mcp_server/helpers.rs +0 -510
  273. package/crates/team-agent/src/mcp_server/lifecycle_tools/mod.rs +0 -6
  274. package/crates/team-agent/src/mcp_server/lifecycle_tools/state_status.rs +0 -43
  275. package/crates/team-agent/src/mcp_server/mod.rs +0 -119
  276. package/crates/team-agent/src/mcp_server/normalize.rs +0 -485
  277. package/crates/team-agent/src/mcp_server/readiness.rs +0 -546
  278. package/crates/team-agent/src/mcp_server/readiness_tests.rs +0 -369
  279. package/crates/team-agent/src/mcp_server/tests/golden.rs +0 -285
  280. package/crates/team-agent/src/mcp_server/tests/normalize.rs +0 -247
  281. package/crates/team-agent/src/mcp_server/tests/scoped.rs +0 -168
  282. package/crates/team-agent/src/mcp_server/tests/send.rs +0 -388
  283. package/crates/team-agent/src/mcp_server/tests/tools.rs +0 -343
  284. package/crates/team-agent/src/mcp_server/tests/wire.rs +0 -254
  285. package/crates/team-agent/src/mcp_server/tests.rs +0 -43
  286. package/crates/team-agent/src/mcp_server/tools.rs +0 -1015
  287. package/crates/team-agent/src/mcp_server/types.rs +0 -396
  288. package/crates/team-agent/src/mcp_server/wire.rs +0 -867
  289. package/crates/team-agent/src/messaging/activity.rs +0 -461
  290. package/crates/team-agent/src/messaging/address.rs +0 -87
  291. package/crates/team-agent/src/messaging/delivery.rs +0 -3785
  292. package/crates/team-agent/src/messaging/delivery_consumption_tests.rs +0 -234
  293. package/crates/team-agent/src/messaging/enter_rescue.rs +0 -362
  294. package/crates/team-agent/src/messaging/enter_rescue_tests.rs +0 -633
  295. package/crates/team-agent/src/messaging/helpers.rs +0 -354
  296. package/crates/team-agent/src/messaging/leader_channel.rs +0 -287
  297. package/crates/team-agent/src/messaging/leader_receiver.rs +0 -786
  298. package/crates/team-agent/src/messaging/mod.rs +0 -166
  299. package/crates/team-agent/src/messaging/persist.rs +0 -377
  300. package/crates/team-agent/src/messaging/presentation.rs +0 -417
  301. package/crates/team-agent/src/messaging/results/collection_tests.rs +0 -719
  302. package/crates/team-agent/src/messaging/results.rs +0 -1415
  303. package/crates/team-agent/src/messaging/scheduler.rs +0 -217
  304. package/crates/team-agent/src/messaging/selftest.rs +0 -315
  305. package/crates/team-agent/src/messaging/send.rs +0 -981
  306. package/crates/team-agent/src/messaging/tests/basic.rs +0 -346
  307. package/crates/team-agent/src/messaging/tests/dup_inject.rs +0 -551
  308. package/crates/team-agent/src/messaging/tests/e23.rs +0 -49
  309. package/crates/team-agent/src/messaging/tests/leader_channel.rs +0 -169
  310. package/crates/team-agent/src/messaging/tests/leader_inject_acceptance.rs +0 -817
  311. package/crates/team-agent/src/messaging/tests/main_preserved.rs +0 -85
  312. package/crates/team-agent/src/messaging/tests/mod.rs +0 -306
  313. package/crates/team-agent/src/messaging/tests/runtime.rs +0 -3655
  314. package/crates/team-agent/src/messaging/tests/spine.rs +0 -837
  315. package/crates/team-agent/src/messaging/tests/wave2.rs +0 -381
  316. package/crates/team-agent/src/messaging/trust.rs +0 -215
  317. package/crates/team-agent/src/messaging/types.rs +0 -471
  318. package/crates/team-agent/src/messaging/wait.rs +0 -366
  319. package/crates/team-agent/src/messaging/watchers.rs +0 -916
  320. package/crates/team-agent/src/model/enums.rs +0 -356
  321. package/crates/team-agent/src/model/errors.rs +0 -18
  322. package/crates/team-agent/src/model/ids.rs +0 -165
  323. package/crates/team-agent/src/model/mod.rs +0 -29
  324. package/crates/team-agent/src/model/name_similarity.rs +0 -252
  325. package/crates/team-agent/src/model/pane_authority_refusal.rs +0 -359
  326. package/crates/team-agent/src/model/paths.rs +0 -257
  327. package/crates/team-agent/src/model/routing.rs +0 -387
  328. package/crates/team-agent/src/model/spec.rs +0 -1184
  329. package/crates/team-agent/src/model/task_graph.rs +0 -321
  330. package/crates/team-agent/src/model/testdata/fuzz.golden.yaml +0 -43
  331. package/crates/team-agent/src/model/testdata/fuzz.yaml +0 -43
  332. package/crates/team-agent/src/model/testdata/spec_invalid_a.yaml +0 -209
  333. package/crates/team-agent/src/model/testdata/team.spec.golden.yaml +0 -208
  334. package/crates/team-agent/src/model/testdata/team.spec.yaml +0 -208
  335. package/crates/team-agent/src/model/yaml/tests.rs +0 -188
  336. package/crates/team-agent/src/model/yaml.rs +0 -802
  337. package/crates/team-agent/src/os_probe.rs +0 -280
  338. package/crates/team-agent/src/packaging/install.rs +0 -219
  339. package/crates/team-agent/src/packaging/migrate.rs +0 -38
  340. package/crates/team-agent/src/packaging/mod.rs +0 -91
  341. package/crates/team-agent/src/packaging/repair.rs +0 -33
  342. package/crates/team-agent/src/packaging/tests.rs +0 -822
  343. package/crates/team-agent/src/packaging/types.rs +0 -417
  344. package/crates/team-agent/src/platform/argv.rs +0 -331
  345. package/crates/team-agent/src/platform/errors.rs +0 -104
  346. package/crates/team-agent/src/platform/file_lock.rs +0 -279
  347. package/crates/team-agent/src/platform/mod.rs +0 -5
  348. package/crates/team-agent/src/platform/process.rs +0 -545
  349. package/crates/team-agent/src/provider/adapter.rs +0 -898
  350. package/crates/team-agent/src/provider/adapters/copilot.rs +0 -75
  351. package/crates/team-agent/src/provider/adapters/copilot_fork.rs +0 -307
  352. package/crates/team-agent/src/provider/adapters/fake.rs +0 -18
  353. package/crates/team-agent/src/provider/adapters/mod.rs +0 -28
  354. package/crates/team-agent/src/provider/approvals/mod.rs +0 -3
  355. package/crates/team-agent/src/provider/approvals/parsing.rs +0 -586
  356. package/crates/team-agent/src/provider/approvals/runtime_prompts.rs +0 -205
  357. package/crates/team-agent/src/provider/argv_route.rs +0 -405
  358. package/crates/team-agent/src/provider/bypass_flags.rs +0 -116
  359. package/crates/team-agent/src/provider/classify.rs +0 -773
  360. package/crates/team-agent/src/provider/command_helpers.rs +0 -45
  361. package/crates/team-agent/src/provider/faults.rs +0 -165
  362. package/crates/team-agent/src/provider/helpers.rs +0 -52
  363. package/crates/team-agent/src/provider/mod.rs +0 -78
  364. package/crates/team-agent/src/provider/model_catalog.rs +0 -722
  365. package/crates/team-agent/src/provider/session/capture.rs +0 -2631
  366. package/crates/team-agent/src/provider/session/context_fork/outcome.rs +0 -168
  367. package/crates/team-agent/src/provider/session/context_fork.rs +0 -264
  368. package/crates/team-agent/src/provider/session/mod.rs +0 -36
  369. package/crates/team-agent/src/provider/session/resume.rs +0 -269
  370. package/crates/team-agent/src/provider/session_scan/common/tests.rs +0 -316
  371. package/crates/team-agent/src/provider/session_scan/common.rs +0 -618
  372. package/crates/team-agent/src/provider/session_scan/copilot.rs +0 -280
  373. package/crates/team-agent/src/provider/session_scan/pi.rs +0 -152
  374. package/crates/team-agent/src/provider/session_scan.rs +0 -61
  375. package/crates/team-agent/src/provider/startup_prompt.rs +0 -757
  376. package/crates/team-agent/src/provider/submit_now.rs +0 -71
  377. package/crates/team-agent/src/provider/testdata/copilot-ready-marker.txt +0 -5
  378. package/crates/team-agent/src/provider/testdata/copilot-trust-prompt.txt +0 -19
  379. package/crates/team-agent/src/provider/testdata/grok-models-authenticated.stdout +0 -9
  380. package/crates/team-agent/src/provider/testdata/grok-models-unauthenticated.stdout +0 -7
  381. package/crates/team-agent/src/provider/tests/adapter.rs +0 -354
  382. package/crates/team-agent/src/provider/tests/classify.rs +0 -201
  383. package/crates/team-agent/src/provider/tests/command_helpers.rs +0 -26
  384. package/crates/team-agent/src/provider/tests/copilot_fork.rs +0 -191
  385. package/crates/team-agent/src/provider/tests/faults.rs +0 -200
  386. package/crates/team-agent/src/provider/tests/idle.rs +0 -140
  387. package/crates/team-agent/src/provider/tests/wire.rs +0 -213
  388. package/crates/team-agent/src/provider/tests.rs +0 -32
  389. package/crates/team-agent/src/provider/types.rs +0 -529
  390. package/crates/team-agent/src/provider/wire.rs +0 -406
  391. package/crates/team-agent/src/redaction.rs +0 -259
  392. package/crates/team-agent/src/state/abnormal_watch/tests/mod.rs +0 -248
  393. package/crates/team-agent/src/state/abnormal_watch.rs +0 -144
  394. package/crates/team-agent/src/state/identity.rs +0 -914
  395. package/crates/team-agent/src/state/identity_keys.rs +0 -132
  396. package/crates/team-agent/src/state/mod.rs +0 -74
  397. package/crates/team-agent/src/state/owner_gate.rs +0 -482
  398. package/crates/team-agent/src/state/ownership.rs +0 -563
  399. package/crates/team-agent/src/state/paths.rs +0 -395
  400. package/crates/team-agent/src/state/persist.rs +0 -3811
  401. package/crates/team-agent/src/state/projection.rs +0 -1508
  402. package/crates/team-agent/src/state/repository/intent.rs +0 -14
  403. package/crates/team-agent/src/state/repository/tests.rs +0 -184
  404. package/crates/team-agent/src/state/repository.rs +0 -866
  405. package/crates/team-agent/src/state/selector.rs +0 -160
  406. package/crates/team-agent/src/state/testdata/state-rich.canonical.json +0 -133
  407. package/crates/team-agent/src/tmux_backend/enter_rescue.rs +0 -325
  408. package/crates/team-agent/src/tmux_backend/enter_rescue_tests.rs +0 -432
  409. package/crates/team-agent/src/tmux_backend/native_input.rs +0 -513
  410. package/crates/team-agent/src/tmux_backend/native_input_tests.rs +0 -742
  411. package/crates/team-agent/src/tmux_backend/tests.rs +0 -4254
  412. package/crates/team-agent/src/tmux_backend.rs +0 -4527
  413. package/crates/team-agent/src/topology.rs +0 -537
  414. package/crates/team-agent/src/transport/enter_rescue.rs +0 -166
  415. package/crates/team-agent/src/transport/native_input.rs +0 -491
  416. package/crates/team-agent/src/transport/test_support.rs +0 -743
  417. package/crates/team-agent/src/transport/tests/behavior.rs +0 -326
  418. package/crates/team-agent/src/transport/tests/mod.rs +0 -194
  419. package/crates/team-agent/src/transport/tests/wire.rs +0 -574
  420. package/crates/team-agent/src/transport.rs +0 -1655
  421. package/crates/team-agent/src/transport_factory.rs +0 -819
@@ -1,1189 +0,0 @@
1
- //! Read-only planning; execution remains in the original typed lifecycle ports.
2
- use super::*;
3
- use crate::model::yaml::{self, Value as Yaml};
4
- use crate::state::selector::{resolve_active_team_readonly, SelectedTeam, SelectorMode};
5
- use crate::transport::{PaneId, Target, Transport};
6
- use std::collections::BTreeSet;
7
- #[cfg(test)]
8
- #[path = "runtime_tests.rs"]
9
- mod tests;
10
-
11
- fn checked<T, E: std::fmt::Display>(result: Result<T, E>) -> Result<T, CliError> {
12
- result.map_err(|e| refusal(e.to_string()))
13
- }
14
- fn complete(path: &Path) -> bool {
15
- path.join("TEAM.md").is_file() && path.join("agents").is_dir()
16
- }
17
- fn discover(
18
- workspace: &Path,
19
- explicit: Option<&Path>,
20
- selected: Option<&SelectedTeam>,
21
- ) -> Result<PathBuf, CliError> {
22
- if let Some(path) = explicit {
23
- return if complete(path) {
24
- Ok(path.to_owned())
25
- } else {
26
- Err(usage("source requires TEAM.md and agents/"))
27
- };
28
- }
29
- if let Some(selected) = selected {
30
- return if complete(&selected.team_dir) {
31
- Ok(selected.team_dir.clone())
32
- } else {
33
- Err(refusal(
34
- "selected role source is incomplete; repair it before start",
35
- ))
36
- };
37
- }
38
- if complete(workspace) {
39
- return Ok(workspace.to_owned());
40
- }
41
- let dir = workspace.join(".team");
42
- let mut candidates = BTreeSet::new();
43
- if dir.is_dir() {
44
- for entry in std::fs::read_dir(dir)? {
45
- let path = entry?.path();
46
- if path.is_dir() && complete(&path) {
47
- candidates.insert(path.canonicalize()?);
48
- }
49
- }
50
- }
51
- if candidates.is_empty() {
52
- return Err(usage(format!(
53
- "action_required: prepare {}/TEAM.md and {}/agents/<id>.md, then use --from TEAMDIR. Nothing was written or started. Role template (fill your decisions): provider: <choose>; dangerously_skip_permissions: <true|false>; model/effort: <optional>.",
54
- workspace.display(), workspace.display()
55
- )));
56
- }
57
- if candidates.len() != 1 {
58
- return Err(usage(format!(
59
- "action_required: multiple complete team sources {candidates:?}; supply --from TEAMDIR"
60
- )));
61
- }
62
- candidates
63
- .into_iter()
64
- .next()
65
- .ok_or_else(|| usage("missing team source"))
66
- }
67
- fn validate_roster(spec: &Yaml, directory: &Path) -> Result<(), CliError> {
68
- checked(crate::model::spec::validate_spec(spec, directory))?;
69
- if let Some(agents) = spec.get("agents").and_then(Yaml::as_list) {
70
- for agent in agents {
71
- if let Some(id) = agent.get("id").and_then(Yaml::as_str) {
72
- logical_agent_id(id)
73
- .map_err(|_| refusal("invalid agent identity in selected roster"))?;
74
- }
75
- }
76
- }
77
- Ok(())
78
- }
79
- fn remember(plan: &mut Plan, path: &Path) -> Result<(), CliError> {
80
- if !plan.files.iter().any(|(p, _)| p == path) {
81
- plan.files.push((path.to_owned(), std::fs::read(path)?));
82
- }
83
- Ok(())
84
- }
85
- fn json_yaml(value: &Yaml) -> Value {
86
- match value {
87
- Yaml::Null => Value::Null,
88
- Yaml::Bool(b) => json!(b),
89
- Yaml::Int(n) => json!(n),
90
- Yaml::Float(n) => json!(n),
91
- Yaml::Str(s) => json!(s),
92
- Yaml::List(values) => Value::Array(values.iter().map(json_yaml).collect()),
93
- Yaml::Map(values) => Value::Object(
94
- values
95
- .iter()
96
- .map(|(k, v)| (k.clone(), json_yaml(v)))
97
- .collect(),
98
- ),
99
- }
100
- }
101
- fn role(
102
- plan: &mut Plan,
103
- selected: &SelectedTeam,
104
- id: &str,
105
- source: Option<&Path>,
106
- ) -> Result<(PathBuf, Value), CliError> {
107
- let path = match source {
108
- Some(path) => path.to_owned(),
109
- None => checked(crate::lifecycle::launch::role_source::resolve_role_source(
110
- &selected.run_workspace,
111
- &selected.team_dir,
112
- &selected.state,
113
- &AgentId::new(id),
114
- ))?,
115
- };
116
- let team_path = selected.team_dir.join("TEAM.md");
117
- remember(plan, &team_path)?;
118
- remember(plan, &path)?;
119
- let (team, _) = checked(crate::compiler::read_front_matter(&team_path))?;
120
- let compiled = checked(crate::compiler::compile_role_agent(
121
- &path,
122
- &team,
123
- &selected.run_workspace.to_string_lossy(),
124
- ))?;
125
- if compiled.id != id {
126
- return Err(refusal(format!("role identity mismatch for {id}")));
127
- }
128
- Ok((path, json_yaml(&compiled.agent)))
129
- }
130
- fn provider(row: &Value) -> &str {
131
- row.get("provider").and_then(Value::as_str).unwrap_or("pi")
132
- }
133
- fn topology(state: &Value) -> Value {
134
- let mut owner = serde_json::Map::new();
135
- for key in ["pane_id", "provider", "owner_epoch", "machine_fingerprint"] {
136
- owner.insert(
137
- key.into(),
138
- state
139
- .get("team_owner")
140
- .and_then(|o| o.get(key))
141
- .cloned()
142
- .unwrap_or(Value::Null),
143
- );
144
- }
145
- json!({"tmux_socket": state.get("tmux_socket"), "transport": state.get("transport"), "owner": owner, "owner_epoch": state.get("owner_epoch")})
146
- }
147
- fn relevant(row: &Value) -> Value {
148
- let mut object = serde_json::Map::new();
149
- for key in [
150
- "provider",
151
- "status",
152
- "explicit_stop",
153
- "pane_id",
154
- "pane_pid",
155
- "window",
156
- "session_id",
157
- "contract_instance",
158
- "generation",
159
- "dynamic_role_file",
160
- "owner_team_id",
161
- "spawn_epoch",
162
- "spawned_at",
163
- ] {
164
- object.insert(key.into(), row.get(key).cloned().unwrap_or(Value::Null));
165
- }
166
- Value::Object(object)
167
- }
168
- fn same_provider(left: &str, right: &str) -> bool {
169
- match (
170
- crate::provider::wire::parse_provider(left),
171
- crate::provider::wire::parse_provider(right),
172
- ) {
173
- (Some(left), Some(right)) => left == right,
174
- _ => left == right,
175
- }
176
- }
177
- fn drift(row: &Value, compiled: &Value) -> bool {
178
- !same_provider(provider(row), provider(compiled))
179
- || row
180
- .get("as_launched_dangerously_skip_permissions")
181
- .and_then(Value::as_bool)
182
- .zip(
183
- compiled
184
- .get("dangerously_skip_permissions")
185
- .and_then(Value::as_bool),
186
- )
187
- .is_some_and(|(old, new)| old != new)
188
- || row
189
- .get("model")
190
- .filter(|v| !v.is_null())
191
- .zip(compiled.get("model").filter(|v| !v.is_null()))
192
- .is_some_and(|(old, new)| old != new)
193
- }
194
- #[cfg(unix)]
195
- fn native_settings_changed(
196
- old: &crate::contract_runtime::config::RoleConfig,
197
- current: &crate::contract_runtime::config::RoleConfig,
198
- ) -> bool {
199
- old.provider != current.provider
200
- || old.model != current.model
201
- || old.effort != current.effort
202
- || old.bypass != current.bypass
203
- || old.paused != current.paused
204
- }
205
-
206
- fn check_native_noop_settings(
207
- selected: &SelectedTeam,
208
- id: &str,
209
- row: &Value,
210
- ) -> Result<(), CliError> {
211
- #[cfg(unix)]
212
- if crate::contract_runtime::framework::is_contract(row) {
213
- use team_agent_contract::contract::types::SeatId;
214
- let backend = checked(crate::contract_runtime::backend::Backend::open_readonly(
215
- &selected.run_workspace,
216
- &selected.team_key,
217
- ))?;
218
- let seat = checked(backend.store.seat(&checked(SeatId::new(id))?))?
219
- .ok_or_else(|| refusal("missing native snapshot identity"))?;
220
- if row.get("contract_instance").and_then(Value::as_str)
221
- != Some(seat.identity.instance.as_str())
222
- || row.get("generation").and_then(Value::as_u64) != Some(seat.identity.generation.0)
223
- {
224
- return Err(refusal("native incarnation changed during no-op planning"));
225
- }
226
- let old = checked(crate::contract_runtime::backend::read_role(
227
- &backend.binding,
228
- &seat.identity,
229
- ))?;
230
- let config = checked(crate::contract_runtime::framework::team_config(
231
- &selected.run_workspace,
232
- &selected.team_dir,
233
- &selected.team_key,
234
- ))?
235
- .ok_or_else(|| refusal("missing native configuration"))?;
236
- let current = config
237
- .roles
238
- .iter()
239
- .find(|role| role.id.as_str() == id)
240
- .ok_or_else(|| refusal("native role no longer configured"))?;
241
- if native_settings_changed(&old, current) {
242
- return Err(refusal(format!(
243
- "native launch configuration drift for {id}; stop before applying settings"
244
- )));
245
- }
246
- checked(crate::contract_runtime::backend::preflight_start_role(
247
- &selected.run_workspace,
248
- &selected.team_key,
249
- current,
250
- ))?;
251
- }
252
- Ok(())
253
- }
254
-
255
- fn paused(row: &Value) -> bool {
256
- row.get("status")
257
- .and_then(Value::as_str)
258
- .is_some_and(|status| status.eq_ignore_ascii_case("paused"))
259
- }
260
-
261
- #[cfg(unix)]
262
- fn native_observation(
263
- status: team_agent_contract::orchestration::store::SeatStatus,
264
- process: team_agent_contract::host::process::ProcessState,
265
- root_status: Option<&str>,
266
- ) -> Observation {
267
- use team_agent_contract::{host::process::ProcessState, orchestration::store::SeatStatus};
268
- match (status, process) {
269
- (SeatStatus::Ready, ProcessState::Alive) if root_status == Some("running") => {
270
- Observation::Live
271
- }
272
- (SeatStatus::Ready, ProcessState::Exited) => Observation::StoppedVerified,
273
- (SeatStatus::Stopped, ProcessState::Exited) if root_status == Some("stopped") => {
274
- Observation::StoppedVerified
275
- }
276
- _ => Observation::Unknown,
277
- }
278
- }
279
-
280
- fn shell_carrier(command: &str) -> bool {
281
- matches!(command, "sh" | "bash" | "zsh" | "fish")
282
- }
283
- fn surface_liveness(command: &str, native_frame: bool, live_child: bool) -> bool {
284
- !command.is_empty() && native_frame && (!shell_carrier(command) || live_child)
285
- }
286
- fn argv0_names(argv0: &str, native: crate::provider::Provider) -> bool {
287
- Path::new(argv0).file_name().and_then(|name| name.to_str())
288
- == Some(crate::provider::wire::command_name(native))
289
- }
290
- /// Native installers may exec a version-named file (Claude Code:
291
- /// `~/.local/bin/claude` -> `versions/<semver>`), so tmux reports the version
292
- /// as the pane command. The exact argv[0] of the pane process, or of a live
293
- /// child under its carrier, still names the provider. Unobservable is not
294
- /// positive evidence.
295
- fn launched_as_provider(pid: u32, native: crate::provider::Provider) -> bool {
296
- let named = |pid: u32| {
297
- crate::platform::argv::argv_tokens(pid)
298
- .and_then(|argv| argv.into_iter().next())
299
- .is_some_and(|argv0| argv0_names(&argv0, native))
300
- };
301
- named(pid)
302
- || crate::platform::process::process_tree(pid)
303
- .unwrap_or_default()
304
- .into_iter()
305
- .any(|child| {
306
- child != pid && named(child) && crate::platform::process::pid_is_alive(child)
307
- })
308
- }
309
-
310
- /// Positive native/store or exact carrier+pane+provider observations only.
311
- fn observe(selected: &SelectedTeam, id: &str, row: &Value) -> Result<Observation, CliError> {
312
- if !row.is_object()
313
- || row
314
- .get("provider")
315
- .is_some_and(|value| !value.is_null() && !value.is_string())
316
- {
317
- return Err(refusal("invalid persisted provider metadata"));
318
- }
319
- #[cfg(unix)]
320
- if crate::contract_runtime::framework::is_contract(row) {
321
- use team_agent_contract::{contract::types::SeatId, host::process::sample_process};
322
- if crate::contract_runtime::framework::is_paused_unstarted(row) {
323
- return Ok(Observation::Unstarted);
324
- }
325
- if checked(
326
- crate::contract_runtime::backend::start_needs_reconciliation(
327
- &selected.run_workspace,
328
- &selected.team_key,
329
- &checked(SeatId::new(id))?,
330
- row,
331
- ),
332
- )? {
333
- return Ok(Observation::NativeReconcile);
334
- }
335
- let backend = checked(crate::contract_runtime::backend::Backend::open_readonly(
336
- &selected.run_workspace,
337
- &selected.team_key,
338
- ))?;
339
- let seat = checked(backend.store.seat(&checked(SeatId::new(id))?))?
340
- .ok_or_else(|| refusal("missing canonical native seat"))?;
341
- if provider(row) != seat.provider.as_str()
342
- || row.get("contract_scope").and_then(Value::as_str)
343
- != Some(seat.identity.scope.as_str())
344
- || row.get("contract_instance").and_then(Value::as_str)
345
- != Some(seat.identity.instance.as_str())
346
- || row.get("generation").and_then(Value::as_u64) != Some(seat.identity.generation.0)
347
- {
348
- return Ok(Observation::Unknown);
349
- }
350
- let Some(target) = seat.physical.as_ref() else {
351
- return Ok(Observation::Unknown);
352
- };
353
- return Ok(native_observation(
354
- seat.status,
355
- sample_process(&target.process),
356
- row.get("status").and_then(Value::as_str),
357
- ));
358
- }
359
- let native = crate::provider::wire::parse_provider(provider(row))
360
- .ok_or_else(|| refusal("unknown provider"))?;
361
- let status = row.get("status").and_then(Value::as_str).unwrap_or("");
362
- if !["running", "stopped", "dead"]
363
- .iter()
364
- .any(|known| status.eq_ignore_ascii_case(known))
365
- {
366
- return Ok(Observation::Unknown);
367
- }
368
- let Some(pid) = row
369
- .get("pane_pid")
370
- .and_then(Value::as_u64)
371
- .and_then(|p| u32::try_from(p).ok())
372
- .filter(|p| *p > 1)
373
- else {
374
- return Ok(Observation::Unknown);
375
- };
376
- match checked(crate::platform::process::pid_liveness(pid))? {
377
- crate::platform::process::ProcessLiveness::Dead => return Ok(Observation::StoppedVerified),
378
- crate::platform::process::ProcessLiveness::Unknown { .. } => {
379
- return Ok(Observation::Unknown)
380
- }
381
- crate::platform::process::ProcessLiveness::Live => (),
382
- }
383
- if !status.eq_ignore_ascii_case("running") {
384
- return Ok(Observation::Unknown);
385
- }
386
- #[cfg(unix)]
387
- let carrier_birth = checked(team_agent_contract::host::process::process_birth_identity(
388
- pid,
389
- ))?;
390
- let backend = checked(
391
- crate::lifecycle::restart::lifecycle_worker_tmux_backend_selection_for_state(
392
- &selected.run_workspace,
393
- &selected.state,
394
- ),
395
- )?
396
- .backend;
397
- let panes = checked(backend.list_targets())?;
398
- let pane = row.get("pane_id").and_then(Value::as_str);
399
- let session = selected.state.get("session_name").and_then(Value::as_str);
400
- let window = row.get("window").and_then(Value::as_str);
401
- let matches: Vec<_> = panes
402
- .iter()
403
- .filter(|p| {
404
- Some(p.pane_id.as_str()) == pane
405
- && p.pane_pid == Some(pid)
406
- && Some(p.session.as_str()) == session
407
- && p.window_name.as_ref().map(|w| w.as_str()) == window
408
- })
409
- .collect();
410
- if matches.len() != 1 {
411
- return Ok(Observation::Unknown);
412
- }
413
- let Some(session) = session else {
414
- return Ok(Observation::Unknown);
415
- };
416
- let owner = checked(backend.session_owner(&crate::transport::SessionName::new(session)))?;
417
- let generation = crate::state::projection::session_generation(&selected.state);
418
- if owner.as_ref().is_none_or(|owner| {
419
- Path::new(&owner.workspace) != selected.run_workspace
420
- || owner.team != selected.team_key
421
- || Some(owner.generation.as_str()) != generation
422
- }) {
423
- return Ok(Observation::Unknown);
424
- }
425
- let command = matches[0].current_command.as_deref().unwrap_or("");
426
- let positive_command = command == crate::provider::wire::command_name(native)
427
- || crate::leader::provider_attribution::command_matches_provider(native, command)
428
- || (!command.is_empty() && !shell_carrier(command) && launched_as_provider(pid, native));
429
- let positive_surface = if !positive_command && !command.is_empty() {
430
- let frame = checked(
431
- backend.observe_native_input(&Target::Pane(PaneId::new(pane.unwrap_or(""))), native),
432
- )?;
433
- // Original start/restart supervises the native child with a shell carrier.
434
- // A shell alone (including its inert post-exit tail) is never Live.
435
- let mut live_child = false;
436
- if frame.is_some() && shell_carrier(command) {
437
- for child in checked(crate::platform::process::process_tree(pid))? {
438
- if child != pid
439
- && matches!(
440
- checked(crate::platform::process::pid_liveness(child))?,
441
- crate::platform::process::ProcessLiveness::Live
442
- )
443
- {
444
- live_child = true;
445
- break;
446
- }
447
- }
448
- }
449
- surface_liveness(command, frame.is_some(), live_child)
450
- } else {
451
- false
452
- };
453
- if !positive_command && !positive_surface {
454
- return Ok(Observation::Unknown);
455
- }
456
- #[cfg(unix)]
457
- if checked(team_agent_contract::host::process::process_birth_identity(
458
- pid,
459
- ))? != carrier_birth
460
- {
461
- return Ok(Observation::Unknown);
462
- }
463
- Ok(Observation::Live)
464
- }
465
- fn start_args(plan: &Plan, id: &str, patch: RoleConfigPatch) -> StartAgentArgs {
466
- StartAgentArgs {
467
- agent: id.into(),
468
- workspace: plan.scope.workspace.clone(),
469
- team: plan.scope.team.clone(),
470
- role_config: patch,
471
- force: false,
472
- allow_fresh: plan.intent.session == SessionPolicy::Auto,
473
- json: true,
474
- }
475
- }
476
- fn stop_args(plan: &Plan, id: &str) -> StopAgentArgs {
477
- StopAgentArgs {
478
- agent: id.into(),
479
- workspace: plan.scope.workspace.clone(),
480
- team: plan.scope.team.clone(),
481
- json: true,
482
- }
483
- }
484
- fn check_incarnation_cwd(selected: &SelectedTeam, row: &Value) -> Result<(), CliError> {
485
- if let Some(cwd) = row
486
- .get("spawn_cwd")
487
- .and_then(Value::as_str)
488
- .filter(|cwd| !cwd.is_empty())
489
- {
490
- let cwd = checked(Path::new(cwd).canonicalize())?;
491
- if !cwd.is_dir() || !cwd.starts_with(&selected.run_workspace) {
492
- return Err(refusal("legacy incarnation cwd is outside the selected workspace; no context or scope fallback"));
493
- }
494
- }
495
- Ok(())
496
- }
497
- fn preflight_start(
498
- selected: &SelectedTeam,
499
- id: &str,
500
- row: &Value,
501
- session_policy: SessionPolicy,
502
- ) -> Result<(), CliError> {
503
- #[cfg(unix)]
504
- if crate::contract_runtime::framework::is_contract(row) {
505
- let config = checked(crate::contract_runtime::framework::team_config(
506
- &selected.run_workspace,
507
- &selected.team_dir,
508
- &selected.team_key,
509
- ))?
510
- .ok_or_else(|| refusal("missing native role config"))?;
511
- let role = config
512
- .roles
513
- .iter()
514
- .find(|r| r.id.as_str() == id)
515
- .ok_or_else(|| refusal("missing native role"))?;
516
- if crate::contract_runtime::framework::is_paused_unstarted(row) {
517
- checked(crate::contract_runtime::backend::preflight(&config))?;
518
- } else {
519
- if checked(crate::contract_runtime::backend::preflight_start_role(
520
- &selected.run_workspace,
521
- &selected.team_key,
522
- role,
523
- ))? {
524
- checked(crate::contract_runtime::backend::preflight(&config))?;
525
- }
526
- }
527
- return Ok(());
528
- }
529
- let provider = crate::provider::wire::parse_provider(provider(row))
530
- .ok_or_else(|| refusal("unknown provider before restart"))?;
531
- for field in ["session_id", "rollout_path", "last_result_at", "spawn_cwd"] {
532
- if row
533
- .get(field)
534
- .is_some_and(|value| !value.is_null() && !value.is_string())
535
- {
536
- return Err(refusal(format!("invalid resume metadata: {field}")));
537
- }
538
- }
539
- if crate::lifecycle::restart::classify_first_send_at(
540
- row.get("first_send_at").unwrap_or(&Value::Null),
541
- ) == crate::lifecycle::FirstSendAtState::Corrupt
542
- {
543
- return Err(refusal("invalid first_send_at metadata before stop"));
544
- }
545
- let session = row
546
- .get("session_id")
547
- .and_then(Value::as_str)
548
- .filter(|s| !s.is_empty())
549
- .map(crate::provider::SessionId::new);
550
- if session_policy == SessionPolicy::Preserve
551
- && !crate::lifecycle::restart::restart_agent_never_captured(
552
- row,
553
- session.as_ref().map(|sid| sid.as_str()),
554
- )
555
- && session.is_none()
556
- {
557
- return Err(refusal(
558
- "resume_not_ready before stop: captured session is missing for existing task context",
559
- ));
560
- }
561
- let rollout = row
562
- .get("rollout_path")
563
- .and_then(Value::as_str)
564
- .filter(|s| !s.is_empty())
565
- .map(crate::provider::RolloutPath::new);
566
- if session.is_some()
567
- && row
568
- .get("spawn_cwd")
569
- .and_then(Value::as_str)
570
- .is_none_or(|cwd| cwd.is_empty())
571
- {
572
- return Err(refusal("resume metadata lacks the scoped spawn cwd"));
573
- }
574
- check_incarnation_cwd(selected, row)?;
575
- if row
576
- .get("task_prompt_delivered")
577
- .is_some_and(|value| !value.is_null() && !value.is_boolean())
578
- {
579
- return Err(refusal("invalid task context metadata before stop"));
580
- }
581
- let (exists, checked_paths) = session
582
- .as_ref()
583
- .map(|session| {
584
- crate::lifecycle::restart::surface_resume_backing_probe(
585
- &selected.run_workspace,
586
- &AgentId::new(id),
587
- row,
588
- provider,
589
- session,
590
- rollout.as_ref(),
591
- )
592
- })
593
- .unwrap_or_default();
594
- let mode = crate::lifecycle::restart::decide_start_mode(
595
- crate::provider::wire::provider_wire(provider),
596
- session.as_ref(),
597
- rollout.as_ref(),
598
- exists,
599
- session_policy == SessionPolicy::Auto,
600
- );
601
- if mode == crate::lifecycle::StartMode::Noop {
602
- return Err(refusal(format!("resume_not_ready before stop: {id}; backing_checked={checked_paths:?}; choose --session auto only if fresh fallback is acceptable")));
603
- }
604
- Ok(())
605
- }
606
- fn add(
607
- plan: &mut Plan,
608
- selected: &SelectedTeam,
609
- id: &str,
610
- source: Option<PathBuf>,
611
- ) -> Result<(), CliError> {
612
- // An explicit start re-admits a removed seat: the add consumes its retired
613
- // tombstone. Only lifecycle history this planner cannot classify is refused.
614
- if selected
615
- .state
616
- .get("agent_lifecycle")
617
- .and_then(|lifecycle| lifecycle.get(id))
618
- .is_some_and(|entry| entry.get("state").and_then(Value::as_str) != Some("retired"))
619
- {
620
- return Err(refusal(format!(
621
- "agent {id} has unrecognized lifecycle history; refusing to re-admit it"
622
- )));
623
- }
624
- let patch = plan.intent.patch.clone();
625
- let role_file = match source {
626
- Some(path) => {
627
- let (meta, _) = checked(crate::compiler::read_front_matter(&path))?;
628
- if (meta.get("provider").and_then(Yaml::as_str).is_none() && patch.provider.is_none())
629
- || (!matches!(
630
- meta.get("dangerously_skip_permissions"),
631
- Some(Yaml::Bool(_))
632
- ) && patch.bypass.is_none())
633
- {
634
- return Err(usage("role creation requires explicit provider and dangerously_skip_permissions decisions"));
635
- }
636
- role(plan, selected, id, Some(&path))?;
637
- path.to_string_lossy().into_owned()
638
- }
639
- None => {
640
- if patch.provider.is_none() || patch.bypass.is_none() {
641
- return Err(usage(
642
- "unknown agent: supply a complete --role-file or --provider and --bypass",
643
- ));
644
- }
645
- String::new()
646
- }
647
- };
648
- plan.steps.push(Step::AddAgent(AddAgentArgs {
649
- agent: id.into(),
650
- workspace: plan.scope.workspace.clone(),
651
- team: plan.scope.team.clone(),
652
- role_config: patch,
653
- role_file,
654
- force: false,
655
- json: true,
656
- }));
657
- Ok(())
658
- }
659
-
660
- pub(super) fn plan(intent: Intent) -> Result<Plan, CliError> {
661
- plan_with_observer(intent, observe)
662
- }
663
- fn no_eligible(mut plan: Plan, reason: &'static str) -> Plan {
664
- plan.steps.clear();
665
- plan.no_eligible = Some(reason);
666
- plan
667
- }
668
-
669
- fn plan_with_observer(
670
- intent: Intent,
671
- observe: impl Fn(&SelectedTeam, &str, &Value) -> Result<Observation, CliError>,
672
- ) -> Result<Plan, CliError> {
673
- let mut plan = Plan {
674
- scope: ResolvedScope {
675
- workspace: intent.workspace.clone(),
676
- team: intent.team.clone(),
677
- },
678
- intent,
679
- steps: vec![],
680
- skipped: vec![],
681
- no_eligible: None,
682
- files: vec![],
683
- expected: BTreeMap::new(),
684
- topology: None,
685
- };
686
- let runtime_workspace = if plan.intent.pinned_workspace {
687
- plan.scope.workspace.clone()
688
- } else {
689
- checked(crate::model::paths::canonical_run_workspace(
690
- &plan.scope.workspace,
691
- ))?
692
- };
693
- let has_state = crate::state::persist::runtime_state_path(&runtime_workspace).is_file();
694
- if has_state {
695
- plan.scope.workspace = runtime_workspace;
696
- }
697
- if !has_state {
698
- let runtime = plan.scope.workspace.join(".team/runtime");
699
- let mut spec_only = plan.scope.workspace.join("team.spec.yaml").is_file();
700
- if runtime.is_dir() {
701
- for entry in std::fs::read_dir(runtime)? {
702
- spec_only |= entry?.path().join("team.spec.yaml").is_file();
703
- }
704
- }
705
- if spec_only {
706
- return Err(refusal("runtime spec exists without its state; select the owning workspace or repair it explicitly"));
707
- }
708
- }
709
- let raw = if has_state {
710
- Some(crate::state::persist::load_runtime_state_without_migrations(&plan.scope.workspace)?)
711
- } else {
712
- None
713
- };
714
- if raw.as_ref().is_some_and(|state| {
715
- !state.is_object() || state.get("teams").is_some_and(|teams| !teams.is_object())
716
- }) {
717
- return Err(refusal(
718
- "invalid runtime state; creation is not a repair fallback",
719
- ));
720
- }
721
- let new_named_team =
722
- raw.as_ref()
723
- .zip(plan.intent.team.as_deref())
724
- .is_some_and(|(raw, team)| {
725
- team != "current"
726
- && !crate::lifecycle::launch::surface_has_runtime_team(raw, team)
727
- && !(crate::state::projection::team_state_key(raw) == team
728
- && crate::lifecycle::launch::surface_is_leader_bootstrap(raw))
729
- && !raw
730
- .get("teams")
731
- .and_then(|t| t.get(team))
732
- .is_some_and(crate::lifecycle::launch::surface_is_leader_bootstrap)
733
- });
734
- let selected = if has_state && !new_named_team {
735
- Some(resolve_active_team_readonly(
736
- &plan.scope.workspace,
737
- plan.intent.team.as_deref(),
738
- SelectorMode::RuntimeOnly,
739
- )?)
740
- } else {
741
- None
742
- };
743
- let initialized = selected
744
- .as_ref()
745
- .is_some_and(|s| crate::lifecycle::launch::surface_has_runtime_team(&s.state, &s.team_key));
746
- if !initialized {
747
- if plan.intent.verb != Verb::Start || !matches!(plan.intent.subject, Subject::Team { .. }) {
748
- return Err(refusal("no initialized team; use start --from TEAMDIR"));
749
- }
750
- let explicit = match &plan.intent.subject {
751
- Subject::Team { source } => source.as_deref(),
752
- _ => None,
753
- };
754
- if new_named_team && explicit.is_none() {
755
- return Err(usage(
756
- "new --team requires explicit --from; existing runtime is not a creation source",
757
- ));
758
- }
759
- let source = discover(&plan.scope.workspace, explicit, None)?;
760
- let compiled = checked(crate::compiler::compile_team(&source))?;
761
- validate_roster(&compiled, &source)?;
762
- let create = QuickStartArgs {
763
- workspace: plan.scope.workspace.clone(),
764
- agents_dir: source.clone(),
765
- name: None,
766
- team_id: plan.intent.team.clone(),
767
- yes: false,
768
- json: true,
769
- detail: true,
770
- backend: None,
771
- };
772
- #[cfg(unix)]
773
- if let Some(config) = checked(crate::contract_runtime::config::read_team(&create))? {
774
- if config.roles.len() == config.members.len()
775
- && config.roles.iter().all(|role| role.paused)
776
- {
777
- plan.skipped.extend(
778
- config
779
- .roles
780
- .iter()
781
- .map(|role| json!({"agent":role.id.as_str(),"reason":"paused"})),
782
- );
783
- return Ok(no_eligible(plan, "all configured native roles are paused"));
784
- }
785
- }
786
- remember(&mut plan, &source.join("TEAM.md"))?;
787
- for entry in std::fs::read_dir(source.join("agents"))? {
788
- let path = entry?.path();
789
- if path.extension().is_some_and(|s| s == "md") {
790
- remember(&mut plan, &path)?;
791
- }
792
- }
793
- plan.steps.push(Step::CreateTeam(create));
794
- return Ok(plan);
795
- }
796
- let selected = selected.ok_or_else(|| refusal("missing selected runtime"))?;
797
- plan.scope = ResolvedScope {
798
- workspace: selected.run_workspace.clone(),
799
- team: Some(selected.team_key.clone()),
800
- };
801
- plan.topology = Some(topology(&selected.state));
802
- if let Subject::Team {
803
- source: Some(source),
804
- } = &plan.intent.subject
805
- {
806
- if source.canonicalize()? != selected.team_dir.canonicalize()? {
807
- return Err(refusal("source differs from selected team's role source"));
808
- }
809
- }
810
- let target = match &plan.intent.subject {
811
- Subject::Agent(id) => Some(id.clone()),
812
- _ => None,
813
- };
814
- checked(crate::lifecycle::launch::ensure_owner_allowed_for_state(
815
- &selected.state,
816
- target.as_ref(),
817
- ))?;
818
- if plan.intent.verb == Verb::Stop && target.is_none() {
819
- plan.steps.push(Step::Shutdown(ShutdownArgs {
820
- workspace: plan.scope.workspace.clone(),
821
- team: plan.scope.team.clone(),
822
- keep_logs: true,
823
- json: true,
824
- }));
825
- return Ok(plan);
826
- }
827
- let spec = selected.spec_path.as_ref().filter(|p| p.is_file());
828
- let missing_spec = spec.is_none();
829
- if missing_spec && plan.intent.verb == Verb::Restart && target.is_none() {
830
- // Keep restart's stopped-roster fence ahead of spec/source admission.
831
- // Its original locked handler owns reconstruction for active rosters.
832
- let rows = selected
833
- .state
834
- .get("agents")
835
- .and_then(Value::as_object)
836
- .ok_or_else(|| refusal("missing agents"))?;
837
- let mut active = false;
838
- for (id, row) in rows {
839
- if !paused(row)
840
- && !crate::state::projection::agent_explicit_stop(row)
841
- && !crate::state::projection::agent_stopped_for_restart(row)
842
- {
843
- if observe(&selected, id, row)? == Observation::Unknown {
844
- return Err(refusal("unknown physical identity"));
845
- }
846
- active = true;
847
- } else {
848
- plan.skipped.push(json!({"agent":id,"reason":if paused(row){"paused"}else if crate::state::projection::agent_explicit_stop(row){"explicit_stop"}else{"stopped_preserved_by_original_restart"}}));
849
- }
850
- }
851
- if !active {
852
- return Ok(no_eligible(
853
- plan,
854
- "stopped roster requires explicit team start",
855
- ));
856
- }
857
- plan.steps.push(Step::RestartTeam(restart_args(&plan)));
858
- return Ok(plan);
859
- }
860
- let runtime_spec =
861
- crate::model::paths::runtime_spec_path(&selected.run_workspace, &selected.team_key);
862
- let spec_value = match spec {
863
- Some(path) => checked(yaml::loads(&std::fs::read_to_string(path)?))?,
864
- None if plan.intent.verb != Verb::Stop => checked(
865
- crate::lifecycle::restart::compile_runtime_spec_from_roles(
866
- &selected.run_workspace, &selected.team_key, &selected.state,
867
- ),
868
- )?,
869
- None => return Err(refusal("runtime spec missing; team stop can inspect and stop the selected runtime without rebuilding it")),
870
- };
871
- validate_roster(
872
- &spec_value,
873
- spec.unwrap_or(&runtime_spec)
874
- .parent()
875
- .unwrap_or(&selected.run_workspace),
876
- )?;
877
- let spec_ids: BTreeSet<String> = spec_value
878
- .get("agents")
879
- .and_then(Yaml::as_list)
880
- .ok_or_else(|| refusal("invalid runtime roster"))?
881
- .iter()
882
- .map(|a| {
883
- a.get("id")
884
- .and_then(Yaml::as_str)
885
- .map(str::to_string)
886
- .ok_or_else(|| refusal("invalid runtime role ID"))
887
- })
888
- .collect::<Result<_, _>>()?;
889
- let rows = selected
890
- .state
891
- .get("agents")
892
- .and_then(Value::as_object)
893
- .ok_or_else(|| refusal("missing runtime agents"))?;
894
- let ids = if let Some(id) = target.as_ref() {
895
- vec![id.as_str().to_owned()]
896
- } else {
897
- let source = discover(&plan.scope.workspace, None, Some(&selected))?;
898
- let compiled = checked(crate::compiler::compile_team(&source))?;
899
- validate_roster(&compiled, &source)?;
900
- let mut ids: BTreeSet<String> = rows.keys().cloned().collect();
901
- if let Some(agents) = compiled.get("agents").and_then(Yaml::as_list) {
902
- for agent in agents {
903
- if let Some(id) = agent.get("id").and_then(Yaml::as_str) {
904
- ids.insert(id.into());
905
- }
906
- }
907
- }
908
- for id in &spec_ids {
909
- if !rows.contains_key(id) {
910
- return Err(refusal(format!("SpecOnly {id}: state/spec mismatch")));
911
- }
912
- }
913
- ids.into_iter().collect()
914
- };
915
- let team = target.is_none();
916
- let mut observations = Vec::new();
917
- for id in ids {
918
- let row = rows.get(&id);
919
- if row.is_some() != spec_ids.contains(&id) {
920
- return Err(refusal(format!("state/spec mismatch for {id}")));
921
- }
922
- let Some(row) = row else {
923
- if team
924
- && selected
925
- .state
926
- .pointer(&format!("/agent_lifecycle/{id}/state"))
927
- .and_then(Value::as_str)
928
- == Some("retired")
929
- {
930
- plan.skipped.push(json!({"agent":id,"reason":"retired"}));
931
- continue;
932
- }
933
- if plan.intent.verb != Verb::Start {
934
- return Err(refusal("restart/stop never implicitly add agents"));
935
- }
936
- let source = plan.intent.role_file.clone().or_else(|| {
937
- let p = selected.team_dir.join("agents").join(format!("{id}.md"));
938
- p.is_file().then_some(p)
939
- });
940
- add(&mut plan, &selected, &id, source)?;
941
- continue;
942
- };
943
- if let Some(source) = plan.intent.role_file.as_ref() {
944
- let expected = checked(crate::lifecycle::launch::role_source::resolve_role_source(
945
- &selected.run_workspace,
946
- &selected.team_dir,
947
- &selected.state,
948
- &AgentId::new(&id),
949
- ))?;
950
- if source.canonicalize()? != expected.canonicalize()? {
951
- return Err(refusal("registered agent cannot replace its role source"));
952
- }
953
- }
954
- let explicit = crate::state::projection::agent_explicit_stop(row);
955
- let obs = if paused(row) || (team && plan.intent.verb == Verb::Restart && explicit) {
956
- Observation::Unstarted
957
- } else {
958
- observe(&selected, &id, row)?
959
- };
960
- let actions = seat_actions(
961
- plan.intent.verb,
962
- obs,
963
- paused(row),
964
- explicit,
965
- plan.intent.patch != RoleConfigPatch::default() || plan.intent.role_file.is_some(),
966
- team,
967
- )?;
968
- if actions.is_empty() {
969
- if obs == Observation::Live && plan.intent.verb == Verb::Start {
970
- let (_, compiled) = role(&mut plan, &selected, &id, None)?;
971
- check_native_noop_settings(&selected, &id, row)?;
972
- if drift(row, &compiled) {
973
- return Err(refusal(format!(
974
- "known launch configuration drift for running {id}; stop before applying"
975
- )));
976
- }
977
- }
978
- plan.skipped.push(json!({"agent":id,"reason":if paused(row){"paused"}else if team&&plan.intent.verb==Verb::Restart&&explicit{"explicit_stop"}else if obs==Observation::Live{"already_running"}else{"already_stopped"},"observation":obs}));
979
- } else {
980
- if plan.intent.verb != Verb::Stop {
981
- let (_, compiled) = role(&mut plan, &selected, &id, None)?;
982
- if !same_provider(provider(row), provider(&compiled)) {
983
- return Err(refusal("registered provider cannot change"));
984
- }
985
- preflight_start(&selected, &id, row, plan.intent.session)?;
986
- }
987
- for action in actions {
988
- match action {
989
- "stop" => plan.steps.push(Step::StopAgent(stop_args(&plan, &id))),
990
- _ => plan.steps.push(Step::StartAgent(start_args(
991
- &plan,
992
- &id,
993
- plan.intent.patch.clone(),
994
- ))),
995
- }
996
- }
997
- }
998
- let mut expected = relevant(row);
999
- #[cfg(unix)]
1000
- if obs == Observation::Live {
1001
- if let Some(pid) = row
1002
- .get("pane_pid")
1003
- .and_then(Value::as_u64)
1004
- .and_then(|p| u32::try_from(p).ok())
1005
- {
1006
- expected["_birth"] = json!(checked(
1007
- team_agent_contract::host::process::process_birth_identity(pid)
1008
- )?);
1009
- }
1010
- }
1011
- plan.expected.insert(id.clone(), expected);
1012
- observations.push((id, obs, explicit, paused(row)));
1013
- }
1014
- if team && plan.intent.verb == Verb::Restart {
1015
- let eligible: Vec<_> = observations
1016
- .iter()
1017
- .filter(|(_, _, explicit, paused)| !explicit && !paused)
1018
- .collect();
1019
- if eligible.is_empty() {
1020
- return Ok(no_eligible(
1021
- plan,
1022
- "use team start to explicitly activate a nonpaused roster",
1023
- ));
1024
- }
1025
- let shutdown = selected.state.get("status").and_then(Value::as_str) == Some("shutdown");
1026
- if !shutdown
1027
- && !eligible.iter().any(|(id, _, _, _)| {
1028
- rows.get(id.as_str())
1029
- .is_some_and(|row| !crate::state::projection::agent_stopped_for_restart(row))
1030
- })
1031
- {
1032
- plan.skipped.extend(eligible.iter().map(|(id,obs,_,_)| json!({"agent":id,"observation":obs,"reason":"stopped_preserved_by_original_restart"})));
1033
- return Ok(no_eligible(
1034
- plan,
1035
- "stopped roster requires explicit team start",
1036
- ));
1037
- }
1038
- if !shutdown
1039
- || eligible
1040
- .iter()
1041
- .any(|(_, obs, _, _)| *obs == Observation::Live)
1042
- {
1043
- for (id, obs, _, _) in &eligible {
1044
- if rows
1045
- .get(id.as_str())
1046
- .is_some_and(crate::state::projection::agent_stopped_for_restart)
1047
- {
1048
- plan.skipped.push(json!({"agent":id,"observation":obs,"reason":"stopped_preserved_by_original_restart"}));
1049
- }
1050
- }
1051
- plan.steps.clear();
1052
- plan.steps.push(Step::RestartTeam(restart_args(&plan)));
1053
- }
1054
- }
1055
- if team
1056
- && plan.steps.is_empty()
1057
- && !plan
1058
- .skipped
1059
- .iter()
1060
- .any(|s| s.get("reason").and_then(Value::as_str) == Some("already_running"))
1061
- {
1062
- return Ok(no_eligible(plan, "no eligible nonpaused roster"));
1063
- }
1064
- if missing_spec {
1065
- plan.steps.insert(
1066
- 0,
1067
- Step::RestoreSpec {
1068
- workspace: selected.run_workspace,
1069
- team: selected.team_key,
1070
- compiled: spec_value,
1071
- },
1072
- );
1073
- }
1074
- Ok(plan)
1075
- }
1076
- fn restart_args(plan: &Plan) -> RestartArgs {
1077
- RestartArgs {
1078
- workspace: plan.scope.workspace.clone(),
1079
- team: plan.scope.team.clone(),
1080
- allow_fresh: plan.intent.session == SessionPolicy::Auto,
1081
- session_converge_deadline_ms: plan.intent.session_converge_deadline_ms,
1082
- json: true,
1083
- detail: true,
1084
- }
1085
- }
1086
-
1087
- pub(super) fn recheck(plan: &Plan, step: &Step, after_stop: bool) -> Result<(), CliError> {
1088
- for (path, bytes) in &plan.files {
1089
- if std::fs::read(path)? != *bytes {
1090
- return Err(refusal(format!(
1091
- "role/spec changed since planning: {}",
1092
- path.display()
1093
- )));
1094
- }
1095
- }
1096
- if let Step::CreateTeam(args) = step {
1097
- let role_dir = args.agents_dir.join("agents");
1098
- let current: BTreeSet<_> = std::fs::read_dir(&role_dir)?
1099
- .map(|entry| entry.map(|e| e.path()))
1100
- .collect::<Result<Vec<_>, _>>()?
1101
- .into_iter()
1102
- .filter(|path| path.extension().is_some_and(|s| s == "md"))
1103
- .collect();
1104
- let planned: BTreeSet<_> = plan
1105
- .files
1106
- .iter()
1107
- .map(|(path, _)| path)
1108
- .filter(|path| path.parent() == Some(role_dir.as_path()))
1109
- .cloned()
1110
- .collect();
1111
- if current != planned {
1112
- return Err(refusal("creation roster changed since planning"));
1113
- }
1114
- return Ok(());
1115
- }
1116
- let selected = resolve_active_team_readonly(
1117
- &plan.scope.workspace,
1118
- plan.scope.team.as_deref(),
1119
- SelectorMode::RuntimeOnly,
1120
- )?;
1121
- if Some(selected.team_key.as_str()) != plan.scope.team.as_deref()
1122
- || selected.run_workspace != plan.scope.workspace
1123
- {
1124
- return Err(refusal("canonical scope changed"));
1125
- }
1126
- if plan
1127
- .topology
1128
- .as_ref()
1129
- .is_some_and(|expected| topology(&selected.state) != *expected)
1130
- {
1131
- return Err(refusal("owner or transport binding changed since planning"));
1132
- }
1133
- let id = step.agent().map(AgentId::new);
1134
- checked(crate::lifecycle::launch::ensure_owner_allowed_for_state(
1135
- &selected.state,
1136
- id.as_ref(),
1137
- ))?;
1138
- let targets: Vec<_> = if let Some(id) = step.agent() {
1139
- vec![id]
1140
- } else {
1141
- plan.expected.keys().map(String::as_str).collect()
1142
- };
1143
- for id in targets {
1144
- let row = selected.state.get("agents").and_then(|a| a.get(id));
1145
- if matches!(step, Step::AddAgent(_)) {
1146
- if row.is_some() {
1147
- return Err(refusal("agent was registered after planning"));
1148
- }
1149
- continue;
1150
- }
1151
- let row = row.ok_or_else(|| refusal("planned agent disappeared"))?;
1152
- let expected = plan
1153
- .expected
1154
- .get(id)
1155
- .ok_or_else(|| refusal("missing original incarnation"))?;
1156
- if after_stop && plan.intent.verb == Verb::Restart && matches!(step, Step::StartAgent(_)) {
1157
- if !same_provider(provider(row), provider(expected))
1158
- || row.get("generation").unwrap_or(&Value::Null)
1159
- != expected.get("generation").unwrap_or(&Value::Null)
1160
- || observe(&selected, id, row)? != Observation::StoppedVerified
1161
- {
1162
- return Err(refusal(
1163
- "post-stop incarnation is not the planned stopped agent",
1164
- ));
1165
- }
1166
- } else {
1167
- let mut expected = expected.clone();
1168
- let birth = expected.as_object_mut().and_then(|o| o.remove("_birth"));
1169
- if relevant(row) != expected {
1170
- return Err(refusal("planned agent incarnation changed"));
1171
- }
1172
- #[cfg(unix)]
1173
- if let Some(birth) = birth {
1174
- let pid = row
1175
- .get("pane_pid")
1176
- .and_then(Value::as_u64)
1177
- .and_then(|p| u32::try_from(p).ok())
1178
- .ok_or_else(|| refusal("missing original carrier"))?;
1179
- if json!(checked(
1180
- team_agent_contract::host::process::process_birth_identity(pid)
1181
- )?) != birth
1182
- {
1183
- return Err(refusal("carrier replaced since planning"));
1184
- }
1185
- }
1186
- }
1187
- }
1188
- Ok(())
1189
- }