@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,848 +0,0 @@
1
- //! ---
2
- //! purpose: 动态角色文档加一席,失败按快照回滚;force 变体先摘旧席再加
3
- //! contract:
4
- //! provides:
5
- //! - name: add_agent
6
- //! what: 编译角色进 runtime spec 并起席,失败回滚 spec 与 state
7
- //! - name: add_agent_force
8
- //! what: 先快照并摘除同名旧席,再走正常加席,失败按快照恢复
9
- //! - name: add_agent_with_transport_at_paths
10
- //! what: 加席的实体实现,含 owner 门、重名拒绝、原子写 spec 与起席
11
- //! depends:
12
- //! - crate::lifecycle::lock
13
- //! - crate::lifecycle::restart
14
- //! - crate::lifecycle::restart::remove
15
- //! - crate::compiler
16
- //! - crate::state::selector
17
- //! - crate::state::projection
18
- //! - crate::state::persist
19
- //! - crate::tmux_backend
20
- //! boundary:
21
- //! - 不拷贝外部角色文件进 team 目录,就地读取编译
22
- //! - 起席一律走 restart 的 start_agent_at_paths,本文件不直接 spawn
23
- //! - 回滚只恢复 spec 字节与 runtime state,不回收已 spawn 的 pane
24
- //! maturity: wired
25
- //! ---
26
- use std::collections::{BTreeMap, BTreeSet};
27
- use std::path::{Path, PathBuf};
28
- use std::process::Command;
29
- use std::time::{SystemTime, UNIX_EPOCH};
30
-
31
- use crate::lifecycle::*;
32
- use crate::model::enums::{AuthMode, PaneLiveness, Provider, ProviderEffort};
33
- use crate::model::ids::AgentId;
34
- use crate::model::yaml::{self, Value};
35
- use crate::state::persist::load_runtime_state;
36
- use crate::transport::{PaneId, SessionName, Target, Transport, WindowName};
37
-
38
- use crate::lifecycle::lock::{acquire_agent_lifecycle_lock, LifecycleLockRequest};
39
-
40
- use super::*;
41
-
42
- struct AgentReservation {
43
- workspace: PathBuf,
44
- team_key: String,
45
- agent_id: AgentId,
46
- owner: String,
47
- active: bool,
48
- }
49
-
50
- impl AgentReservation {
51
- fn commit(mut self) {
52
- self.active = false;
53
- }
54
- }
55
-
56
- impl Drop for AgentReservation {
57
- fn drop(&mut self) {
58
- if !self.active {
59
- return;
60
- }
61
- let request = LifecycleLockRequest {
62
- workspace: &self.workspace,
63
- operation: "agent-reservation-rollback",
64
- team: Some(self.team_key.as_str()),
65
- agent_id: Some(&self.agent_id),
66
- };
67
- let Ok(_lock) = acquire_agent_lifecycle_lock(request) else {
68
- let _ = crate::event_log::EventLog::new(&self.workspace).write(
69
- "lifecycle.clone_reservation_rollback_failed",
70
- serde_json::json!({
71
- "agent_id": self.agent_id.as_str(),
72
- "reservation_owner": self.owner,
73
- "reason": "lifecycle lock unavailable",
74
- }),
75
- );
76
- return;
77
- };
78
- let result =
79
- release_agent_reservation(&self.workspace, &self.team_key, &self.agent_id, &self.owner);
80
- let _ = crate::event_log::EventLog::new(&self.workspace).write(
81
- if result.is_ok() {
82
- "lifecycle.clone_reservation_rolled_back"
83
- } else {
84
- "lifecycle.clone_reservation_rollback_failed"
85
- },
86
- serde_json::json!({
87
- "agent_id": self.agent_id.as_str(),
88
- "reservation_owner": self.owner,
89
- "result": result.as_ref().err().map(ToString::to_string),
90
- }),
91
- );
92
- }
93
- }
94
-
95
- fn reserve_agent_slot(
96
- workspace: &Path,
97
- team: Option<&str>,
98
- agent_id: &AgentId,
99
- ) -> Result<AgentReservation, LifecycleError> {
100
- let state = crate::state::projection::select_runtime_state(workspace, team)
101
- .map_err(|error| LifecycleError::TeamSelect(error.to_string()))?;
102
- let team_key = team
103
- .filter(|key| !key.is_empty())
104
- .map(str::to_string)
105
- .or_else(|| explicit_active_team_key(&state))
106
- .unwrap_or_else(|| crate::state::projection::team_state_key(&state));
107
- let owner = format!(
108
- "{}-{}",
109
- std::process::id(),
110
- SystemTime::now()
111
- .duration_since(UNIX_EPOCH)
112
- .map_err(|error| LifecycleError::StatePersist(error.to_string()))?
113
- .as_nanos()
114
- );
115
- let mut latest = crate::state::projection::select_runtime_state(workspace, Some(&team_key))
116
- .map_err(|error| LifecycleError::TeamSelect(error.to_string()))?;
117
- ensure_owner_allowed_for_state(&latest, Some(agent_id))?;
118
- if runtime_agent_exists(&latest, agent_id) {
119
- return Err(LifecycleError::RequirementUnmet(format!(
120
- "agent id already exists: {agent_id}"
121
- )));
122
- }
123
- latest
124
- .as_object_mut()
125
- .ok_or_else(|| LifecycleError::StatePersist("runtime state root is not an object".into()))?
126
- .entry("agents")
127
- .or_insert_with(|| serde_json::json!({}));
128
- let agents = latest
129
- .get_mut("agents")
130
- .and_then(serde_json::Value::as_object_mut)
131
- .ok_or_else(|| {
132
- LifecycleError::StatePersist("runtime state agents is not an object".into())
133
- })?;
134
- agents.insert(
135
- agent_id.as_str().to_string(),
136
- serde_json::json!({
137
- "agent_id": agent_id.as_str(),
138
- "status": "reserved",
139
- "reservation_owner": owner,
140
- }),
141
- );
142
- save_launched_team_state_for_key(
143
- workspace,
144
- &latest,
145
- Some(team_key.as_str()),
146
- Some(agent_id.as_str()),
147
- )?;
148
- let _ = crate::event_log::EventLog::new(workspace).write(
149
- "lifecycle.clone_reservation_acquired",
150
- serde_json::json!({
151
- "agent_id": agent_id.as_str(),
152
- "reservation_owner": owner,
153
- "team": team_key,
154
- }),
155
- );
156
- Ok(AgentReservation {
157
- workspace: workspace.to_path_buf(),
158
- team_key,
159
- agent_id: agent_id.clone(),
160
- owner,
161
- active: true,
162
- })
163
- }
164
-
165
- fn release_agent_reservation(
166
- workspace: &Path,
167
- team_key: &str,
168
- agent_id: &AgentId,
169
- owner: &str,
170
- ) -> Result<(), LifecycleError> {
171
- let mut state = crate::state::projection::select_runtime_state(workspace, Some(team_key))
172
- .map_err(|error| LifecycleError::TeamSelect(error.to_string()))?;
173
- let matches = state
174
- .get("agents")
175
- .and_then(|agents| agents.get(agent_id.as_str()))
176
- .and_then(|agent| agent.get("reservation_owner"))
177
- .and_then(serde_json::Value::as_str)
178
- == Some(owner);
179
- if !matches {
180
- return Ok(());
181
- }
182
- state
183
- .get_mut("agents")
184
- .and_then(serde_json::Value::as_object_mut)
185
- .ok_or_else(|| {
186
- LifecycleError::StatePersist("runtime state agents is not an object".into())
187
- })?
188
- .remove(agent_id.as_str());
189
- save_launched_team_state_for_key(workspace, &state, Some(team_key), Some(agent_id.as_str()))
190
- }
191
-
192
- /// ---
193
- /// purpose: 加一席的默认入口,解析活跃 team、拿生命周期锁、路由到该 team 实际使用的 tmux socket
194
- /// params:
195
- /// role_file_path: 外部角色文档路径,就地读取不拷贝
196
- /// open_display: 是否为新席开显示
197
- /// returns: 新席的环境与启动模式
198
- /// errors: 选不到 team 返回 TeamSelect,角色文件缺失或编译失败返回 Compile,重名返回 RequirementUnmet
199
- /// contract_id: lifecycle.add_agent.entry
200
- /// ---
201
- /// `add_agent(workspace, agent_id, role_file_path, open_display, team)`
202
- /// (`lifecycle/operations.py:143`)。动态 role doc 编译进 spec + 起 worker;失败**字节级回滚**
203
- /// spec_yaml / workspace_state / **team_state.md** / role_file(Gap 15.11),每步发
204
- /// `lifecycle.add_step_*` 事件(顺序被测试锁死)。
205
- pub fn add_agent(
206
- workspace: &Path,
207
- agent_id: &AgentId,
208
- role_file_path: &Path,
209
- open_display: bool,
210
- team: Option<&str>,
211
- ) -> Result<AddAgentReport, LifecycleError> {
212
- let selected = match crate::state::selector::resolve_active_team(
213
- workspace,
214
- team,
215
- crate::state::selector::SelectorMode::RequireSpec,
216
- ) {
217
- Ok(selected) => selected,
218
- Err(_) if workspace.join("TEAM.md").exists() => {
219
- // TEAM.md lives in the run workspace. `team_workspace()` always walks
220
- // to the parent and would spawn on a hash socket of the scratch parent.
221
- // Use the idempotent run-workspace so persisted `tmux_endpoint` wins.
222
- let run_workspace = crate::model::paths::canonical_run_workspace(workspace)
223
- .map_err(|e| LifecycleError::StatePersist(e.to_string()))?;
224
- let transport =
225
- crate::lifecycle::restart::lifecycle_worker_tmux_backend_for_selected_state(
226
- &run_workspace, team,
227
- )
228
- .unwrap_or_else(|_| {
229
- crate::tmux_backend::TmuxBackend::for_workspace(&run_workspace)
230
- });
231
- return add_agent_with_transport(
232
- workspace,
233
- agent_id,
234
- role_file_path,
235
- open_display,
236
- team,
237
- &transport,
238
- );
239
- }
240
- Err(error) => return Err(LifecycleError::TeamSelect(error.to_string())),
241
- };
242
- let lifecycle_lock = acquire_agent_lifecycle_lock(LifecycleLockRequest {
243
- workspace: &selected.run_workspace,
244
- operation: "add-agent",
245
- team: Some(selected.team_key.as_str()),
246
- agent_id: Some(agent_id),
247
- })?;
248
- let reservation = reserve_agent_slot(
249
- &selected.run_workspace,
250
- Some(selected.team_key.as_str()),
251
- agent_id,
252
- )?;
253
- drop(lifecycle_lock);
254
- // E5 §3:compile_team 要角色定义目录(team_dir),不是 spec 落点(spec_workspace=runtime)。
255
- let team_dir = selected.team_dir;
256
- // **0.3.24 add-agent socket drift fix**: route to the live team's persisted
257
- // tmux endpoint (NOT the workspace-hash for_workspace socket). Without this,
258
- // `add-agent` spawns into an orphan socket (e.g. `ta-<hash>/termclaud`) while
259
- // the live team runs on its persisted default socket — the leader can't see
260
- // the new window, state never registers, and the orphaned `claude` process
261
- // floats forever (macmini repro: `demo-director` startup blocker).
262
- let transport = crate::lifecycle::restart::lifecycle_worker_tmux_backend_for_selected_state(
263
- &selected.run_workspace,
264
- Some(selected.team_key.as_str()),
265
- )
266
- .unwrap_or_else(|_| crate::tmux_backend::TmuxBackend::for_workspace(&selected.run_workspace));
267
- add_agent_with_transport_at_paths_reserved(
268
- &selected.run_workspace,
269
- &team_dir,
270
- agent_id,
271
- role_file_path,
272
- open_display,
273
- Some(selected.team_key.as_str()),
274
- &transport,
275
- Some(reservation),
276
- false,
277
- )
278
- }
279
-
280
- /// ---
281
- /// purpose: 强制重建一席,先快照旧席再摘除再加回
282
- /// params:
283
- /// force: 为假时直接退回普通 add_agent
284
- /// returns: 新席的环境与启动模式
285
- /// errors: 任一步失败都按快照恢复,恢复本身再出错时错误里附 rollback_errors
286
- /// contract_id: lifecycle.add_agent.force_entry
287
- /// ---
288
- /// Reconcile a single existing/inconsistent seat, then reuse the normal add
289
- /// path. The external role source is preserved by remove-agent ownership
290
- /// checks, so this is a one-command force-recreate rather than a team restart.
291
- pub fn add_agent_force(
292
- workspace: &Path,
293
- agent_id: &AgentId,
294
- role_file_path: &Path,
295
- open_display: bool,
296
- team: Option<&str>,
297
- force: bool,
298
- ) -> Result<AddAgentReport, LifecycleError> {
299
- if !force {
300
- return add_agent(workspace, agent_id, role_file_path, open_display, team);
301
- }
302
- let selected = crate::state::selector::resolve_active_team(
303
- workspace,
304
- team,
305
- crate::state::selector::SelectorMode::RequireSpec,
306
- )
307
- .map_err(|error| LifecycleError::TeamSelect(error.to_string()))?;
308
- let canonical_team_key = selected.team_key.clone();
309
- let _lock = acquire_agent_lifecycle_lock(LifecycleLockRequest {
310
- workspace: &selected.run_workspace,
311
- operation: "add-agent-force",
312
- team: Some(canonical_team_key.as_str()),
313
- agent_id: Some(agent_id),
314
- })?;
315
- let transport = crate::lifecycle::restart::lifecycle_worker_tmux_backend_for_selected_state(
316
- &selected.run_workspace,
317
- Some(canonical_team_key.as_str()),
318
- )
319
- .unwrap_or_else(|_| crate::tmux_backend::TmuxBackend::for_workspace(&selected.run_workspace));
320
- force_recreate_with_transport_locked(
321
- &selected.run_workspace,
322
- &selected.team_dir,
323
- agent_id,
324
- role_file_path,
325
- open_display,
326
- Some(canonical_team_key.as_str()),
327
- &transport,
328
- )
329
- }
330
-
331
- /// ---
332
- /// purpose: 带注入 transport 的加席入口,归一 workspace 并拿锁后转实体实现
333
- /// returns: 新席的环境与启动模式
334
- /// errors: 归一 workspace 失败返回 StatePersist,其余透传
335
- /// contract_id: lifecycle.add_agent.entry
336
- /// ---
337
- /// `add_agent` with an injected transport — after the recompile+write, wires the new worker spawn
338
- /// (via start_agent_with_transport) + start_coordinator (rt-host-a sweep: recompiled but never spawned).
339
- pub(crate) fn add_agent_with_transport(
340
- workspace: &Path,
341
- agent_id: &AgentId,
342
- role_file_path: &Path,
343
- open_display: bool,
344
- team: Option<&str>,
345
- transport: &dyn Transport,
346
- ) -> Result<AddAgentReport, LifecycleError> {
347
- let run_workspace = crate::model::paths::canonical_run_workspace(workspace)
348
- .map_err(|e| LifecycleError::StatePersist(e.to_string()))?;
349
- let lifecycle_lock = acquire_agent_lifecycle_lock(LifecycleLockRequest {
350
- workspace: &run_workspace,
351
- operation: "add-agent",
352
- team,
353
- agent_id: Some(agent_id),
354
- })?;
355
- let reservation = reserve_agent_slot(&run_workspace, team, agent_id)?;
356
- drop(lifecycle_lock);
357
- add_agent_with_transport_at_paths_reserved(
358
- &run_workspace,
359
- workspace,
360
- agent_id,
361
- role_file_path,
362
- open_display,
363
- team,
364
- transport,
365
- Some(reservation),
366
- false,
367
- )
368
- }
369
-
370
- /// ---
371
- /// purpose: 带注入 transport 的强制重建入口
372
- /// params:
373
- /// force: 为假时退回普通 add_agent_with_transport
374
- /// returns: 新席的环境与启动模式
375
- /// errors: 归一 workspace 失败返回 StatePersist,其余透传
376
- /// contract_id: lifecycle.add_agent.force_entry
377
- /// ---
378
- pub(crate) fn add_agent_with_transport_force(
379
- workspace: &Path,
380
- agent_id: &AgentId,
381
- role_file_path: &Path,
382
- open_display: bool,
383
- team: Option<&str>,
384
- force: bool,
385
- transport: &dyn Transport,
386
- ) -> Result<AddAgentReport, LifecycleError> {
387
- if !force {
388
- return add_agent_with_transport(
389
- workspace,
390
- agent_id,
391
- role_file_path,
392
- open_display,
393
- team,
394
- transport,
395
- );
396
- }
397
- let run_workspace = crate::model::paths::canonical_run_workspace(workspace)
398
- .map_err(|error| LifecycleError::StatePersist(error.to_string()))?;
399
- let _lock = acquire_agent_lifecycle_lock(LifecycleLockRequest {
400
- workspace: &run_workspace,
401
- operation: "add-agent-force",
402
- team,
403
- agent_id: Some(agent_id),
404
- })?;
405
- force_recreate_with_transport_locked(
406
- &run_workspace,
407
- workspace,
408
- agent_id,
409
- role_file_path,
410
- open_display,
411
- team,
412
- transport,
413
- )
414
- }
415
-
416
- /// ---
417
- /// purpose: 已持锁状态下的强制重建,先校验替换源可用再消费旧席
418
- /// returns: 新席报告;成功后还要过快照的一致性校验
419
- /// errors: 角色文件不存在先行返回 Compile;摘除、加回或一致性校验失败时按快照恢复并返回错误
420
- /// ---
421
- pub(crate) fn force_recreate_with_transport_locked(
422
- run_workspace: &Path,
423
- team_dir: &Path,
424
- agent_id: &AgentId,
425
- role_file_path: &Path,
426
- open_display: bool,
427
- team: Option<&str>,
428
- transport: &dyn Transport,
429
- ) -> Result<AddAgentReport, LifecycleError> {
430
- // Reject an unusable replacement source before consuming the old seat.
431
- // Deeper compile/spawn failures remain covered by the transaction snapshot.
432
- if !role_file_path.exists() {
433
- return Err(LifecycleError::Compile(format!(
434
- "role file not found: {}",
435
- role_file_path.display()
436
- )));
437
- }
438
- let snapshot = crate::lifecycle::restart::remove::ForceRecreateSnapshot::capture(
439
- run_workspace,
440
- agent_id,
441
- team,
442
- transport,
443
- )?;
444
- let remove = crate::lifecycle::restart::remove::remove_agent_with_transport_locked(
445
- run_workspace,
446
- agent_id,
447
- true,
448
- true,
449
- team,
450
- transport,
451
- );
452
- if let Err(error) = remove {
453
- let restore_errors = snapshot.restore(team, transport);
454
- return force_recreate_rollback_error(agent_id, error, restore_errors);
455
- }
456
- let operation = add_agent_with_transport_at_paths_locked(
457
- run_workspace,
458
- team_dir,
459
- agent_id,
460
- role_file_path,
461
- open_display,
462
- team,
463
- transport,
464
- )
465
- .and_then(|report| {
466
- maybe_fail_force_recreate_after_spawn()?;
467
- Ok(report)
468
- })
469
- .and_then(|report| {
470
- snapshot.require_coherent(agent_id, team, transport)?;
471
- Ok(report)
472
- });
473
- match operation {
474
- Ok(report) => Ok(report),
475
- Err(error) => {
476
- let restore_errors = snapshot.restore_after_consumption(transport);
477
- force_recreate_rollback_error(agent_id, error, restore_errors)
478
- }
479
- }
480
- }
481
-
482
- /// ---
483
- /// purpose: 把原始错误与回滚过程中的错误合成一个对外错误
484
- /// returns: 回滚干净时原样返回原始错误;否则包成 StatePersist 并附 rollback_errors
485
- /// ---
486
- pub(super) fn force_recreate_rollback_error<T>(
487
- agent_id: &AgentId,
488
- error: LifecycleError,
489
- restore_errors: Vec<String>,
490
- ) -> Result<T, LifecycleError> {
491
- if restore_errors.is_empty() {
492
- Err(error)
493
- } else {
494
- Err(LifecycleError::StatePersist(format!(
495
- "force-recreate failed for {agent_id}: {error}; rollback_errors={}",
496
- restore_errors.join("|")
497
- )))
498
- }
499
- }
500
-
501
- /// ---
502
- /// purpose: 测试用注入点,按环境变量在 spawn 之后制造一次失败
503
- /// returns: 环境变量未设或为空时直接成功
504
- /// errors: 设了非空值时返回 StatePersist
505
- /// ---
506
- pub(super) fn maybe_fail_force_recreate_after_spawn() -> Result<(), LifecycleError> {
507
- let Ok(reason) = std::env::var("TEAM_AGENT_TEST_FAIL_FORCE_RECREATE_AFTER_SPAWN") else {
508
- return Ok(());
509
- };
510
- if reason.is_empty() {
511
- return Ok(());
512
- }
513
- Err(LifecycleError::StatePersist(format!(
514
- "injected force-recreate failure after spawn: {reason}"
515
- )))
516
- }
517
-
518
- /// ---
519
- /// purpose: 加席的实体实现,含 owner 门、重名拒绝、重编译 spec 原子写、席位 state upsert 与起席
520
- /// params:
521
- /// run_workspace: 已归一的 run workspace
522
- /// team_dir: 角色定义所在目录,编译 team 用它
523
- /// returns: 新席的环境与启动模式
524
- /// errors: owner 门不过或重名返回 RequirementUnmet,角色文件缺失或编译不一致返回 Compile,state 与 spawn 失败先回滚再透传原错
525
- /// ---
526
- pub(super) fn add_agent_with_transport_at_paths(
527
- run_workspace: &Path,
528
- team_dir: &Path,
529
- agent_id: &AgentId,
530
- role_file_path: &Path,
531
- open_display: bool,
532
- team: Option<&str>,
533
- transport: &dyn Transport,
534
- ) -> Result<AddAgentReport, LifecycleError> {
535
- add_agent_with_transport_at_paths_reserved(
536
- run_workspace,
537
- team_dir,
538
- agent_id,
539
- role_file_path,
540
- open_display,
541
- team,
542
- transport,
543
- None,
544
- false,
545
- )
546
- }
547
-
548
- #[allow(clippy::too_many_arguments)]
549
- pub(crate) fn add_agent_with_transport_at_paths_locked(
550
- run_workspace: &Path,
551
- team_dir: &Path,
552
- agent_id: &AgentId,
553
- role_file_path: &Path,
554
- open_display: bool,
555
- team: Option<&str>,
556
- transport: &dyn Transport,
557
- ) -> Result<AddAgentReport, LifecycleError> {
558
- add_agent_with_transport_at_paths_reserved(
559
- run_workspace,
560
- team_dir,
561
- agent_id,
562
- role_file_path,
563
- open_display,
564
- team,
565
- transport,
566
- None,
567
- true,
568
- )
569
- }
570
-
571
- #[allow(clippy::too_many_arguments)]
572
- fn add_agent_with_transport_at_paths_reserved(
573
- run_workspace: &Path,
574
- team_dir: &Path,
575
- agent_id: &AgentId,
576
- role_file_path: &Path,
577
- open_display: bool,
578
- team: Option<&str>,
579
- transport: &dyn Transport,
580
- reservation: Option<AgentReservation>,
581
- lifecycle_lock_held: bool,
582
- ) -> Result<AddAgentReport, LifecycleError> {
583
- let runtime_state = crate::state::persist::load_runtime_state(run_workspace)
584
- .map_err(|e| LifecycleError::StatePersist(e.to_string()))?;
585
- let canonical_team_key = team
586
- .filter(|key| !key.is_empty())
587
- .map(str::to_string)
588
- .or_else(|| explicit_active_team_key(&runtime_state))
589
- .unwrap_or_else(|| crate::state::projection::team_state_key(&runtime_state));
590
- let owner_state =
591
- crate::state::projection::select_runtime_state(run_workspace, Some(&canonical_team_key))
592
- .map_err(|e| LifecycleError::TeamSelect(e.to_string()))?;
593
- ensure_owner_allowed_for_state(&owner_state, Some(agent_id))?;
594
- if !role_file_path.exists() {
595
- return Err(LifecycleError::Compile(format!(
596
- "role file not found: {}",
597
- role_file_path.display()
598
- )));
599
- }
600
- let reservation_owned = reservation.as_ref().is_some_and(|reservation| {
601
- owner_state
602
- .get("agents")
603
- .and_then(|agents| agents.get(agent_id.as_str()))
604
- .and_then(|agent| agent.get("reservation_owner"))
605
- .and_then(serde_json::Value::as_str)
606
- == Some(reservation.owner.as_str())
607
- });
608
- if runtime_agent_exists(&owner_state, agent_id) && !reservation_owned {
609
- return Err(LifecycleError::RequirementUnmet(format!(
610
- "agent id already exists: {agent_id}"
611
- )));
612
- }
613
- // E5 Bug1:不再 copy role 文件进 <team_dir>/agents(自拷贝 O_TRUNC 截断反模式)。
614
- // 就地读外部 role 文档编译,注入 base team spec 的 agents/routing。role 文件留在原处。
615
- let mut spec = crate::compiler::compile_team(team_dir)
616
- .map_err(|e| LifecycleError::Compile(e.to_string()))?;
617
- override_spec_workspace(&mut spec, run_workspace);
618
- let workspace_s = spec
619
- .get("team")
620
- .and_then(|team| team.get("workspace"))
621
- .and_then(Value::as_str)
622
- .unwrap_or_else(|| team_dir.to_str().unwrap_or_default())
623
- .to_string();
624
- let team_meta = crate::compiler::read_front_matter(&team_dir.join("TEAM.md"))
625
- .map(|(meta, _)| meta)
626
- .unwrap_or(Value::Null);
627
- let compiled = crate::compiler::compile_role_agent(role_file_path, &team_meta, &workspace_s)
628
- .map_err(|e| LifecycleError::Compile(e.to_string()))?;
629
- if compiled.id != agent_id.as_str() {
630
- return Err(LifecycleError::Compile(format!(
631
- "role file declares name '{}' but add-agent id is '{}'",
632
- compiled.id, agent_id
633
- )));
634
- }
635
- // The compiled spec carries a contract leaf's canonical id (`agent` → `cursor`).
636
- #[cfg(unix)]
637
- let contract_provider = compiled
638
- .agent
639
- .get("provider")
640
- .and_then(Value::as_str)
641
- .filter(|provider| crate::contract_runtime::registry::descriptor(provider).is_some())
642
- .map(str::to_owned);
643
- let compiled_agent = compiled.agent.clone();
644
- inject_agent_into_spec(&mut spec, compiled_agent.clone(), &compiled.id)?;
645
- // E5 spec 迁移:重编译的 spec 原子写到 .team/runtime/<team_key>/(不落用户目录 team_dir)。
646
- let spec_path = crate::model::paths::runtime_spec_path(run_workspace, &canonical_team_key);
647
- // E42 (0.3.24 P0): capture pre-write bytes for atomic rollback. If anything
648
- // downstream of write_spec_atomic + upsert_agent_state_from_role + spawn
649
- // fails, restore the prior bytes so the canonical spec / runtime state never
650
- // get a half-written row that disagrees with what remove-agent can see.
651
- let reservation_lock = if lifecycle_lock_held {
652
- None
653
- } else {
654
- Some(acquire_agent_lifecycle_lock(LifecycleLockRequest {
655
- workspace: run_workspace,
656
- operation: "add-agent",
657
- team,
658
- agent_id: Some(agent_id),
659
- })?)
660
- };
661
- let pre_spec_text = match std::fs::read_to_string(&spec_path) {
662
- Ok(text) => Some(text),
663
- Err(e) if e.kind() == std::io::ErrorKind::NotFound => None,
664
- Err(e) => return Err(LifecycleError::StatePersist(format!("read spec: {e}"))),
665
- };
666
- // Merge against the latest runtime spec while holding only the short
667
- // filesystem critical section. Role compilation happened before this lock;
668
- // peer reservations therefore remain visible instead of being overwritten
669
- // by a stale base-spec snapshot.
670
- let mut latest_spec = pre_spec_text
671
- .as_deref()
672
- .and_then(|text| crate::model::yaml::loads(text).ok())
673
- .unwrap_or(spec);
674
- inject_agent_into_spec(&mut latest_spec, compiled_agent, &compiled.id)?;
675
- write_spec_atomic(&spec_path, &latest_spec)?;
676
- drop(reservation_lock);
677
- #[cfg(unix)]
678
- if let Some(provider) = contract_provider {
679
- return add_contract_seat(
680
- run_workspace,
681
- team_dir,
682
- &spec_path,
683
- pre_spec_text.as_deref(),
684
- &canonical_team_key,
685
- agent_id,
686
- &provider,
687
- role_file_path,
688
- reservation,
689
- );
690
- }
691
- let (meta, _) = crate::compiler::read_front_matter(role_file_path)
692
- .map_err(|e| LifecycleError::Compile(e.to_string()))?;
693
- // upsert writes status="starting" (E42) — start_agent_at_paths::mark_agent_started
694
- // promotes to "running" on Ok. If anything fails between here and the Ok
695
- // return below, rollback restores the captured pre-bytes.
696
- if let Err(error) = upsert_agent_state_from_role(
697
- run_workspace,
698
- &canonical_team_key,
699
- agent_id,
700
- &meta,
701
- role_file_path,
702
- ) {
703
- rollback_add_agent_atomic(
704
- run_workspace,
705
- &spec_path,
706
- pre_spec_text.as_deref(),
707
- None,
708
- Some(&canonical_team_key),
709
- agent_id,
710
- "state_upsert_failed",
711
- );
712
- return Err(error);
713
- }
714
- let started = match crate::lifecycle::restart::start_agent_at_paths(
715
- run_workspace,
716
- spec_path.parent().unwrap_or(team_dir),
717
- agent_id,
718
- false,
719
- open_display,
720
- true,
721
- Some(&canonical_team_key),
722
- transport,
723
- ) {
724
- Ok(started) => started,
725
- Err(error) => {
726
- rollback_add_agent_atomic(
727
- run_workspace,
728
- &spec_path,
729
- pre_spec_text.as_deref(),
730
- None,
731
- Some(&canonical_team_key),
732
- agent_id,
733
- "start_agent_failed",
734
- );
735
- return Err(error);
736
- }
737
- };
738
- let (env, start_mode) = match started {
739
- StartAgentOutcome::Running {
740
- env, start_mode, ..
741
- } => (env, start_mode),
742
- StartAgentOutcome::Noop { .. } => {
743
- rollback_add_agent_atomic(
744
- run_workspace,
745
- &spec_path,
746
- pre_spec_text.as_deref(),
747
- None,
748
- Some(&canonical_team_key),
749
- agent_id,
750
- "start_agent_noop",
751
- );
752
- return Err(LifecycleError::RequirementUnmet(format!(
753
- "start_agent.noop: newly added agent {agent_id} must spawn, not reuse a live window"
754
- )));
755
- }
756
- StartAgentOutcome::Paused { .. } => {
757
- rollback_add_agent_atomic(
758
- run_workspace,
759
- &spec_path,
760
- pre_spec_text.as_deref(),
761
- None,
762
- Some(&canonical_team_key),
763
- agent_id,
764
- "added_agent_paused",
765
- );
766
- return Err(LifecycleError::RequirementUnmet(format!(
767
- "added agent {agent_id} is paused"
768
- )));
769
- }
770
- };
771
- if let Some(reservation) = reservation {
772
- reservation.commit();
773
- }
774
- Ok(AddAgentReport {
775
- env,
776
- start_mode,
777
- role_file: role_file_path.to_path_buf(),
778
- })
779
- }
780
-
781
- /// A contract seat starts in the native framework, never the legacy transport:
782
- /// the seeded row is what the framework's start/publish path projects onto.
783
- /// Its role must live in `<team_dir>/agents`, where the contract config reads.
784
- #[cfg(unix)]
785
- #[allow(clippy::too_many_arguments)]
786
- fn add_contract_seat(
787
- run_workspace: &Path,
788
- team_dir: &Path,
789
- spec_path: &Path,
790
- pre_spec_text: Option<&str>,
791
- team_key: &str,
792
- agent_id: &AgentId,
793
- provider: &str,
794
- role_file_path: &Path,
795
- reservation: Option<AgentReservation>,
796
- ) -> Result<AddAgentReport, LifecycleError> {
797
- let rollback = |reason: &str| {
798
- rollback_add_agent_atomic(
799
- run_workspace,
800
- spec_path,
801
- pre_spec_text,
802
- None,
803
- Some(team_key),
804
- agent_id,
805
- reason,
806
- )
807
- };
808
- let seed = serde_json::json!({
809
- "agent_id": agent_id.as_str(), "provider": provider, "runtime_family": "contract",
810
- "status": "starting", "contract_instance": null, "pane_id": null,
811
- });
812
- if let Err(error) = upsert_agent_entry(run_workspace, team_key, agent_id, seed) {
813
- rollback("state_upsert_failed");
814
- return Err(error);
815
- }
816
- let started = team_agent_contract::contract::types::SeatId::new(agent_id.as_str())
817
- .map_err(|error| error.to_string())
818
- .and_then(|seat| {
819
- crate::contract_runtime::framework::start_new_seat(
820
- run_workspace,
821
- team_dir,
822
- team_key,
823
- &seat,
824
- )
825
- .map_err(|error| error.to_string())
826
- });
827
- if let Err(error) = started {
828
- rollback("start_agent_failed");
829
- return Err(LifecycleError::Provider(error));
830
- }
831
- let coordinator = crate::coordinator::start_coordinator_with_team(
832
- &crate::coordinator::WorkspacePath::new(run_workspace.to_path_buf()),
833
- Some(team_key),
834
- )
835
- .map_err(|error| LifecycleError::StatePersist(error.to_string()))?;
836
- if let Some(reservation) = reservation {
837
- reservation.commit();
838
- }
839
- Ok(AddAgentReport {
840
- env: AgentActionEnvelope {
841
- agent_id: agent_id.clone(),
842
- state_file: crate::state::persist::runtime_state_path(run_workspace),
843
- coordinator_started: coordinator.ok,
844
- },
845
- start_mode: StartMode::Fresh,
846
- role_file: role_file_path.to_path_buf(),
847
- })
848
- }