@team-agent/installer 0.5.128 → 0.6.0

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