@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,867 +0,0 @@
1
- //!
2
- //! step 14a · mcp_server::wire — stdio loop + JSON-RPC route + tool dispatch + contracts.
3
-
4
- use std::io::{BufRead, Write};
5
- use std::path::Path;
6
-
7
- use serde_json::Value;
8
-
9
- use crate::event_log::EventLog;
10
- use crate::messaging::MessageTarget;
11
-
12
- use super::helpers::{json_dumps_default, object_fields};
13
- use super::tools::TeamOrchestratorTools;
14
- use super::types::{
15
- McpError, McpTool, RpcError, RpcId, RpcMethod, RpcResponse, Scope, SendOutcome,
16
- ServerRunReport, ToolError, ToolErrorReason, ToolOk, ToolResult,
17
- };
18
-
19
- // ═══════════════════════════════════════════════════════════════════════════
20
- // CONTRACTS — TOOLS wire list (contracts.py), derived from McpTool.
21
- // ═══════════════════════════════════════════════════════════════════════════
22
-
23
- /// `TOOLS` (`contracts.py:4`): the `tools/list` payload — name/description/inputSchema
24
- /// per tool. **Byte-stable wire single-truth**, derived from [`McpTool`] so name and
25
- /// schema cannot drift from the enum. Returned verbatim by `tools/list`.
26
- pub fn tools_contract() -> Vec<Value> {
27
- let tools = [
28
- McpTool::SendMessage,
29
- McpTool::ReportResult,
30
- McpTool::GetTeamStatus,
31
- ];
32
- tools.into_iter().map(tool_contract).collect()
33
- }
34
-
35
- // ═══════════════════════════════════════════════════════════════════════════
36
- // SERVER — stdio loop + JSON-RPC route. THE single external MCP entry surface
37
- // (boundary tests lock handle_mcp / dispatch / TOOLS).
38
- // ═══════════════════════════════════════════════════════════════════════════
39
-
40
- /// `dispatch(tools, request)` (`server.py:16-43`): route a `{tool, arguments}` (or
41
- /// `{method, params}`) request to the matching [`TeamOrchestratorTools`] handler.
42
- /// Unknown tool → `Err(ToolError{reason: UnknownTool})`. Argument/runtime errors
43
- /// from the handler propagate as the handler's own [`ToolResult`]; the
44
- /// argument-vs-internal exception split happens in [`handle_mcp`].
45
- pub fn dispatch(tools: &TeamOrchestratorTools, request: &Value) -> ToolResult {
46
- let tool_value = request
47
- .get("tool")
48
- .filter(|v| !v.as_str().is_some_and(str::is_empty))
49
- .or_else(|| {
50
- request
51
- .get("name")
52
- .filter(|v| !v.as_str().is_some_and(str::is_empty))
53
- })
54
- .or_else(|| request.get("method"));
55
- let name = tool_value.and_then(Value::as_str);
56
- let args = request
57
- .get("arguments")
58
- .or_else(|| request.get("params"))
59
- .unwrap_or(&Value::Null);
60
- let Some(name) = name else {
61
- return Err(ToolError::new(
62
- ToolErrorReason::UnknownTool,
63
- "unknown tool None",
64
- "UnknownTool",
65
- ));
66
- };
67
- let Some(tool) = McpTool::parse(name) else {
68
- return Err(ToolError::new(
69
- ToolErrorReason::UnknownTool,
70
- format!("unknown tool {}", python_repr(name)),
71
- "UnknownTool",
72
- ));
73
- };
74
- dispatch_tool(tools, tool, args)
75
- }
76
-
77
- /// `handle_mcp(tools, request)` (`server.py:46-91`): the JSON-RPC router.
78
- /// - `initialize` → serverInfo `team_orchestrator` v0.1.4 + echoed protocolVersion.
79
- /// - `tools/list` → `{tools: TOOLS}`.
80
- /// - `tools/call` → run [`dispatch`], wrap through the live
81
- /// `tool_call_result_value` path (`isError` = dispatch returned `Err`); the
82
- /// arg-vs-runtime exception split (`server.py:69-72`) classifies a caught
83
- /// failure into `InvalidToolArguments` vs `InternalRuntimeError`.
84
- /// - `notifications/*` → `Ok(None)` (no frame; **must not** emit to stdout).
85
- /// - unknown method → `-32601` error frame.
86
- /// Returns `Ok(None)` only for the notifications path; every other branch yields a
87
- /// frame.
88
- ///
89
- pub fn handle_mcp(
90
- tools: &TeamOrchestratorTools,
91
- request: &Value,
92
- ) -> Result<Option<RpcResponse>, McpError> {
93
- let id = rpc_id_from_request(request);
94
- let method = request.get("method").and_then(Value::as_str).unwrap_or("");
95
- match RpcMethod::classify(method) {
96
- RpcMethod::Initialize => {
97
- let protocol = request
98
- .get("params")
99
- .and_then(|p| p.get("protocolVersion"))
100
- .and_then(Value::as_str)
101
- .unwrap_or("2024-11-05");
102
- let mut result = serde_json::Map::new();
103
- result.insert(
104
- "protocolVersion".to_string(),
105
- Value::String(protocol.to_string()),
106
- );
107
- result.insert("capabilities".to_string(), serde_json::json!({"tools": {}}));
108
- result.insert(
109
- "serverInfo".to_string(),
110
- serde_json::json!({"name": "team_orchestrator", "version": "0.1.4"}),
111
- );
112
- Ok(Some(RpcResponse {
113
- jsonrpc: "2.0".to_string(),
114
- id,
115
- result: Some(Value::Object(result)),
116
- error: None,
117
- }))
118
- }
119
- RpcMethod::ToolsList => Ok(Some(RpcResponse {
120
- jsonrpc: "2.0".to_string(),
121
- id,
122
- result: Some(serde_json::json!({ "tools": tools_contract() })),
123
- error: None,
124
- })),
125
- RpcMethod::ToolsCall => {
126
- let params = request.get("params").unwrap_or(&Value::Null);
127
- let body = match dispatch(tools, params) {
128
- Ok(ok) => {
129
- let value = Value::Object(ok.fields);
130
- tool_call_result_value(
131
- value.get("ok").and_then(Value::as_bool) == Some(false),
132
- &value,
133
- )
134
- }
135
- Err(err) => tool_call_result_value(true, &err.to_envelope()),
136
- };
137
- Ok(Some(RpcResponse {
138
- jsonrpc: "2.0".to_string(),
139
- id,
140
- result: Some(body),
141
- error: None,
142
- }))
143
- }
144
- RpcMethod::Notification(_) => Ok(None),
145
- RpcMethod::Unknown(method) => Ok(Some(RpcResponse {
146
- jsonrpc: "2.0".to_string(),
147
- id,
148
- result: None,
149
- error: Some(RpcError {
150
- code: -32601,
151
- message: format!("unknown method '{method}'"),
152
- }),
153
- })),
154
- }
155
- }
156
-
157
- /// `main(argv)` (`server.py:114-151`): the stdio process entry. Reads stdin line by
158
- /// line; for `jsonrpc:"2.0"` lines routes via [`handle_mcp`] and writes the response
159
- /// frame (skipping `None`); legacy `{tool,...}` lines go straight to [`dispatch`].
160
- /// **All errors surface as JSON-RPC frames on stdout**; the loop never crashes the
161
- /// process. Returns a [`ServerRunReport`] summarizing the session for tests/daemon.
162
- pub fn main(workspace: &Path, argv: &[String]) -> Result<ServerRunReport, McpError> {
163
- let _ = argv;
164
- let stdin = std::io::stdin();
165
- let stdout = std::io::stdout();
166
- run_stdio_loop(workspace, stdin.lock(), stdout.lock())
167
- }
168
-
169
- fn run_stdio_loop<R: BufRead, W: Write>(
170
- workspace: &Path,
171
- reader: R,
172
- mut writer: W,
173
- ) -> Result<ServerRunReport, McpError> {
174
- let tools = TeamOrchestratorTools::new(workspace);
175
- let mut report = ServerRunReport::default();
176
- let marker = McpServerLifecycleMarker::from_env(workspace);
177
- marker.write_started();
178
- let result = run_stdio_loop_inner(&tools, reader, &mut writer, &mut report, &marker);
179
- match &result {
180
- Ok(_) => marker.write_exit("stdin_eof", None),
181
- Err(error) => marker.write_exit("fatal_error", Some(&error.to_string())),
182
- }
183
- result
184
- }
185
-
186
- fn run_stdio_loop_inner<R: BufRead, W: Write>(
187
- tools: &TeamOrchestratorTools,
188
- reader: R,
189
- writer: &mut W,
190
- report: &mut ServerRunReport,
191
- marker: &McpServerLifecycleMarker,
192
- ) -> Result<ServerRunReport, McpError> {
193
- let mut initialized = false;
194
- for line in reader.lines() {
195
- let line = line?;
196
- report.requests_read = report.requests_read.saturating_add(1);
197
- let (frame, response_kind) = handle_stdin_line(tools, &line, report)?;
198
- if let Some(value) = frame {
199
- let value = crate::redaction::redact_external_value(&value);
200
- serde_json::to_writer(&mut *writer, &value)?;
201
- writer.write_all(b"\n")?;
202
- writer.flush()?;
203
- match response_kind {
204
- ResponseKind::Initialize => initialized = true,
205
- ResponseKind::ToolsList => marker.write_tools_list_response_written(initialized),
206
- ResponseKind::Other => {}
207
- }
208
- report.responses_written = report.responses_written.saturating_add(1);
209
- }
210
- }
211
- report.clean_eof = true;
212
- Ok(report.clone())
213
- }
214
-
215
- enum ResponseKind {
216
- Initialize,
217
- ToolsList,
218
- Other,
219
- }
220
-
221
- fn handle_stdin_line(
222
- tools: &TeamOrchestratorTools,
223
- line: &str,
224
- report: &mut ServerRunReport,
225
- ) -> Result<(Option<Value>, ResponseKind), McpError> {
226
- let request: Value = match serde_json::from_str(line) {
227
- Ok(value) => value,
228
- Err(err) => {
229
- report.error_frames = report.error_frames.saturating_add(1);
230
- return Ok((
231
- Some(error_response_value(
232
- RpcId::Null,
233
- -32700,
234
- format!("parse error: {err}"),
235
- )),
236
- ResponseKind::Other,
237
- ));
238
- }
239
- };
240
- if request.get("jsonrpc").and_then(Value::as_str) == Some("2.0") {
241
- let method = request.get("method").and_then(Value::as_str);
242
- let valid_id = request.get("id").is_some_and(|id| id.is_string() || id.is_number());
243
- match handle_mcp(tools, &request)? {
244
- Some(response) => {
245
- let kind = match (method, valid_id && response.error.is_none()) {
246
- (Some("initialize"), true) => ResponseKind::Initialize,
247
- (Some("tools/list"), true) => ResponseKind::ToolsList,
248
- _ => ResponseKind::Other,
249
- };
250
- if response.error.is_some() {
251
- report.error_frames = report.error_frames.saturating_add(1);
252
- }
253
- Ok((Some(serde_json::to_value(response)?), kind))
254
- }
255
- None => {
256
- report.notifications_skipped = report.notifications_skipped.saturating_add(1);
257
- Ok((None, ResponseKind::Other))
258
- }
259
- }
260
- } else {
261
- let value = match dispatch(tools, &request) {
262
- Ok(ok) => Value::Object(ok.fields),
263
- Err(err) => {
264
- report.error_frames = report.error_frames.saturating_add(1);
265
- err.to_envelope()
266
- }
267
- };
268
- Ok((Some(value), ResponseKind::Other))
269
- }
270
- }
271
-
272
- fn rpc_id_from_request(request: &Value) -> RpcId {
273
- match request.get("id") {
274
- Some(Value::Number(n)) => n
275
- .as_i64()
276
- .map_or_else(|| RpcId::Number(n.clone()), RpcId::Int),
277
- Some(Value::String(s)) => RpcId::Str(s.clone()),
278
- _ => RpcId::Null,
279
- }
280
- }
281
-
282
- fn tool_call_result_value(is_error: bool, body: &Value) -> Value {
283
- let body = crate::redaction::redact_external_value(body);
284
- let text = json_dumps_default(&body);
285
- let mut content = serde_json::Map::new();
286
- content.insert("type".to_string(), Value::String("text".to_string()));
287
- content.insert("text".to_string(), Value::String(text));
288
- serde_json::json!({
289
- "content": [Value::Object(content)],
290
- "isError": is_error
291
- })
292
- }
293
-
294
- struct McpServerLifecycleMarker {
295
- workspace: std::path::PathBuf,
296
- agent_id: Option<String>,
297
- owner_team_id: Option<String>,
298
- started_at: chrono::DateTime<chrono::Utc>,
299
- pid: u32,
300
- ppid: u32,
301
- }
302
-
303
- impl McpServerLifecycleMarker {
304
- fn from_env(workspace: &Path) -> Self {
305
- Self {
306
- workspace: workspace.to_path_buf(),
307
- agent_id: non_empty_env("TEAM_AGENT_ID"),
308
- owner_team_id: non_empty_env("TEAM_AGENT_OWNER_TEAM_ID"),
309
- started_at: chrono::Utc::now(),
310
- pid: std::process::id(),
311
- ppid: parent_pid(),
312
- }
313
- }
314
-
315
- fn write_started(&self) {
316
- self.write("mcp.server_started", None, None);
317
- }
318
-
319
- fn write_tools_list_response_written(&self, initialized: bool) {
320
- let _ = EventLog::new(&self.workspace).write(
321
- "mcp.tools_list_response_written",
322
- serde_json::json!({
323
- "method": "tools/list",
324
- "success": true,
325
- "agent_id": self.agent_id.as_deref(),
326
- "owner_team_id": self.owner_team_id.as_deref(),
327
- "workspace": self.workspace.display().to_string(),
328
- "pid": self.pid,
329
- "ppid": self.ppid,
330
- "spawn_epoch": null,
331
- "spawn_epoch_source": "unavailable",
332
- "initialize_response_flushed": initialized,
333
- }),
334
- );
335
- #[cfg(unix)]
336
- if initialized {
337
- if let (Some(owner), Some(agent)) = (&self.owner_team_id, &self.agent_id) {
338
- if let Err(reason) = super::readiness::publish(&self.workspace, owner, agent, self.started_at) {
339
- self.write("mcp.handshake_receipt_failed", Some(reason), None);
340
- }
341
- }
342
- }
343
- }
344
-
345
- fn write_exit(&self, reason: &str, error: Option<&str>) {
346
- self.write("mcp.server_exit", Some(reason), error);
347
- }
348
-
349
- fn write(&self, event: &str, reason: Option<&str>, error: Option<&str>) {
350
- let _ = EventLog::new(&self.workspace).write(
351
- event,
352
- serde_json::json!({
353
- "agent_id": self.agent_id.as_deref(),
354
- "owner_team_id": self.owner_team_id.as_deref(),
355
- "workspace": self.workspace.display().to_string(),
356
- "pid": self.pid,
357
- "ppid": self.ppid,
358
- "reason": reason,
359
- "error": error,
360
- }),
361
- );
362
- }
363
- }
364
-
365
- fn non_empty_env(key: &str) -> Option<String> {
366
- std::env::var(key)
367
- .ok()
368
- .map(|value| value.trim().to_string())
369
- .filter(|value| !value.is_empty())
370
- }
371
-
372
- // 0.5.x Windows portability Batch 3: parent-pid probe routes through
373
- // `crate::platform::process::current_parent_pid`. Unix uses
374
- // `libc::getppid`; Windows uses Toolhelp32Snapshot. Both return
375
- // `Option<u32>`; the legacy `0` fallback (which would have silently
376
- // degraded MCP metadata + orphan detection on Windows) is gone.
377
- fn parent_pid() -> u32 {
378
- crate::platform::process::current_parent_pid().unwrap_or(0)
379
- }
380
-
381
- fn error_response_value(id: RpcId, code: i64, message: String) -> Value {
382
- let response = RpcResponse {
383
- jsonrpc: "2.0".to_string(),
384
- id,
385
- result: None,
386
- error: Some(RpcError { code, message }),
387
- };
388
- match serde_json::to_value(response) {
389
- Ok(value) => value,
390
- Err(_) => serde_json::json!({
391
- "jsonrpc": "2.0",
392
- "id": null,
393
- "error": {
394
- "code": -32000,
395
- "message": "internal runtime error"
396
- }
397
- }),
398
- }
399
- }
400
-
401
- fn python_repr(value: &str) -> String {
402
- if value.contains('\'') && !value.contains('"') {
403
- format!("\"{}\"", value.replace('"', "\\\""))
404
- } else {
405
- format!("'{}'", value.replace('\'', "\\'"))
406
- }
407
- }
408
-
409
- fn tool_contract(tool: McpTool) -> Value {
410
- let (description, required) = match tool {
411
- McpTool::SendMessage => (
412
- "Send a message to a teammate, the leader, or '*' for all other team members. mailbox=true stores durably without live injection; the default is live delivery.",
413
- vec!["to", "content"],
414
- ),
415
- McpTool::ReportResult => (
416
- "Report task completion with a durable result envelope. Optional presentation routing controls live leader display, not persistence.",
417
- Vec::new(),
418
- ),
419
- McpTool::GetTeamStatus => ("Return machine-readable team status.", Vec::new()),
420
- };
421
- serde_json::json!({
422
- "name": tool.wire_name(),
423
- "description": description,
424
- "inputSchema": {
425
- "type": "object",
426
- "properties": tool_properties(tool),
427
- "required": required,
428
- "additionalProperties": false
429
- }
430
- })
431
- }
432
-
433
- fn tool_properties(tool: McpTool) -> serde_json::Map<String, Value> {
434
- let mut properties = serde_json::Map::new();
435
- match tool {
436
- McpTool::SendMessage => {
437
- insert_property(
438
- &mut properties,
439
- "to",
440
- string_property("Target agent id, 'leader', or '*' for broadcast."),
441
- );
442
- insert_property(&mut properties, "content", string_property("Message body."));
443
- insert_property(
444
- &mut properties,
445
- "mailbox",
446
- boolean_property(
447
- "Set true to store durably without live injection; omit for default live delivery.",
448
- ),
449
- );
450
- }
451
- McpTool::ReportResult => {
452
- insert_property(
453
- &mut properties,
454
- "envelope",
455
- object_property("Optional full result envelope."),
456
- );
457
- insert_property(
458
- &mut properties,
459
- "summary",
460
- string_property("Short result summary."),
461
- );
462
- insert_property(&mut properties, "status", string_property("Result status."));
463
- insert_property(
464
- &mut properties,
465
- "changes",
466
- array_property("Changed files or artifacts."),
467
- );
468
- insert_property(
469
- &mut properties,
470
- "tests",
471
- array_property("Tests or checks performed."),
472
- );
473
- insert_property(
474
- &mut properties,
475
- "risks",
476
- array_property("Risks or blockers."),
477
- );
478
- insert_property(
479
- &mut properties,
480
- "artifacts",
481
- array_property("Artifact references."),
482
- );
483
- insert_property(
484
- &mut properties,
485
- "next_actions",
486
- array_property("Suggested next actions."),
487
- );
488
- insert_property(
489
- &mut properties,
490
- "task_id",
491
- string_property("Optional task id override."),
492
- );
493
- insert_property(
494
- &mut properties,
495
- "agent_id",
496
- string_property(
497
- "Optional reporting agent id; must match framework-injected TEAM_AGENT_ID.",
498
- ),
499
- );
500
- insert_property(
501
- &mut properties,
502
- "presentation",
503
- presentation_property("Optional durable presentation routing."),
504
- );
505
- }
506
- McpTool::GetTeamStatus => {}
507
- }
508
- properties
509
- }
510
-
511
- fn insert_property(properties: &mut serde_json::Map<String, Value>, name: &str, schema: Value) {
512
- properties.insert(name.to_string(), schema);
513
- }
514
-
515
- fn string_property(description: &str) -> Value {
516
- serde_json::json!({"type": "string", "description": description})
517
- }
518
-
519
- fn boolean_property(description: &str) -> Value {
520
- serde_json::json!({"type": "boolean", "description": description})
521
- }
522
-
523
- fn object_property(description: &str) -> Value {
524
- serde_json::json!({"type": "object", "description": description, "additionalProperties": true})
525
- }
526
-
527
- fn presentation_property(description: &str) -> Value {
528
- serde_json::json!({
529
- "type": "object",
530
- "description": description,
531
- "properties": {
532
- "sink": {"type": "string", "enum": ["leader", "casefile", "silent"]},
533
- "class": {"type": "string", "enum": [
534
- "message", "progress", "stage_result", "stage_pass", "bounce",
535
- "blocking", "final_review", "timeout"
536
- ]},
537
- "case_id": {"type": "string"}
538
- },
539
- "required": ["sink", "class"],
540
- "additionalProperties": false
541
- })
542
- }
543
-
544
- fn array_property(description: &str) -> Value {
545
- serde_json::json!({"type": "array", "description": description, "items": {"type": "object", "additionalProperties": true}})
546
- }
547
-
548
- pub(crate) fn dispatch_tool(
549
- tools: &TeamOrchestratorTools,
550
- tool: McpTool,
551
- args: &Value,
552
- ) -> ToolResult {
553
- // Check framework-bound identity before scope resolution or any tool side effect.
554
- match tool {
555
- McpTool::SendMessage => {
556
- tools.validate_identity_argument("send_message", args.get("agent_id"))?;
557
- if let Some(value) = args
558
- .get("envelope")
559
- .and_then(Value::as_object)
560
- .and_then(|object| object.get("agent_id"))
561
- {
562
- tools.validate_identity_argument("send_message", Some(value))?;
563
- }
564
- }
565
- McpTool::ReportResult => {
566
- tools.validate_report_identity_request(args.get("envelope"), args.get("agent_id"))?
567
- }
568
- _ => {}
569
- }
570
- tools.validate_rpc_scope_args(tool.wire_name(), args)?;
571
- match tool {
572
- McpTool::SendMessage => {
573
- let target = message_target_from_value(args.get("to"));
574
- let content = args.get("content").and_then(Value::as_str).unwrap_or("");
575
- let outcome = tools.send_message_with_presentation(
576
- &target,
577
- content,
578
- None,
579
- None,
580
- None,
581
- args.get("mailbox"),
582
- args.get("presentation"),
583
- )?;
584
- match outcome {
585
- SendOutcome::WorkerAccepted { .. } => Ok(ToolOk {
586
- fields: object_fields(outcome.to_value()),
587
- }),
588
- SendOutcome::Direct(ok) => Ok(ok),
589
- }
590
- }
591
- McpTool::ReportResult => tools.report_result_with_presentation(
592
- args.get("envelope"),
593
- args.get("summary").and_then(Value::as_str),
594
- args.get("status").and_then(Value::as_str),
595
- args.get("changes")
596
- .and_then(Value::as_array)
597
- .map(Vec::as_slice),
598
- args.get("tests")
599
- .and_then(Value::as_array)
600
- .map(Vec::as_slice),
601
- args.get("risks")
602
- .and_then(Value::as_array)
603
- .map(Vec::as_slice),
604
- args.get("artifacts")
605
- .and_then(Value::as_array)
606
- .map(Vec::as_slice),
607
- args.get("next_actions")
608
- .and_then(Value::as_array)
609
- .map(Vec::as_slice),
610
- args.get("task_id").and_then(Value::as_str),
611
- args.get("agent_id").and_then(Value::as_str),
612
- args.get("presentation"),
613
- ),
614
- McpTool::GetTeamStatus => tools.get_team_status(),
615
- }
616
- }
617
-
618
- fn message_target_from_value(value: Option<&Value>) -> MessageTarget {
619
- match value {
620
- Some(Value::String(s)) if s == "*" => MessageTarget::Broadcast,
621
- Some(Value::String(s)) => MessageTarget::Single(s.clone()),
622
- Some(Value::Array(items)) => MessageTarget::Fanout(
623
- items
624
- .iter()
625
- .filter_map(Value::as_str)
626
- .map(ToString::to_string)
627
- .collect(),
628
- ),
629
- _ => MessageTarget::Single(String::new()),
630
- }
631
- }
632
-
633
- #[cfg(test)]
634
- #[allow(clippy::unwrap_used, clippy::expect_used, clippy::panic)]
635
- mod e23_lifecycle_marker_tests {
636
- use super::*;
637
-
638
- fn marker_ws(tag: &str) -> std::path::PathBuf {
639
- use std::sync::atomic::{AtomicU64, Ordering};
640
- static N: AtomicU64 = AtomicU64::new(0);
641
- let path = std::env::temp_dir().join(format!(
642
- "ta-rs-mcp-marker-{tag}-{}-{}",
643
- std::process::id(),
644
- N.fetch_add(1, Ordering::Relaxed)
645
- ));
646
- std::fs::create_dir_all(&path).unwrap();
647
- path
648
- }
649
-
650
- #[test]
651
- fn stdio_loop_logs_tools_list_after_flush_once_per_response() {
652
- let ws = marker_ws("tools-list-success");
653
- let input = std::io::Cursor::new(
654
- br#"{"jsonrpc":"2.0","id":1,"method":"tools/list"}
655
- {"jsonrpc":"2.0","id":2,"method":"tools/list"}
656
- "#.to_vec(),
657
- );
658
- let mut output = Vec::new();
659
-
660
- let report = run_stdio_loop(&ws, input, &mut output).unwrap();
661
-
662
- assert_eq!(report.responses_written, 2);
663
- assert_eq!(output.iter().filter(|byte| **byte == b'\n').count(), 2);
664
- let events = EventLog::new(&ws).tail(0).unwrap();
665
- let tool_events: Vec<_> = events
666
- .iter()
667
- .filter(|event| event["event"] == serde_json::json!("mcp.tools_list_response_written"))
668
- .collect();
669
- assert_eq!(tool_events.len(), 2, "one event per successful tools/list response");
670
- for event in tool_events {
671
- assert_eq!(event["method"], serde_json::json!("tools/list"));
672
- assert_eq!(event["success"], serde_json::json!(true));
673
- assert_eq!(event["workspace"], serde_json::json!(ws.display().to_string()));
674
- assert_eq!(event["pid"], serde_json::json!(std::process::id()));
675
- assert_eq!(event["spawn_epoch"], serde_json::Value::Null);
676
- }
677
- let _ = std::fs::remove_dir_all(&ws);
678
- }
679
-
680
- #[test]
681
- fn stdio_loop_does_not_log_tools_list_when_write_fails() {
682
- struct FailingWriter;
683
- impl Write for FailingWriter {
684
- fn write(&mut self, _buf: &[u8]) -> std::io::Result<usize> {
685
- Err(std::io::Error::other("simulated stdout write failure"))
686
- }
687
-
688
- fn flush(&mut self) -> std::io::Result<()> {
689
- Ok(())
690
- }
691
- }
692
-
693
- let ws = marker_ws("tools-list-write-fail");
694
- let input = std::io::Cursor::new(
695
- br#"{"jsonrpc":"2.0","id":1,"method":"tools/list"}"#.to_vec(),
696
- );
697
- let error = run_stdio_loop(&ws, input, FailingWriter).expect_err("write must fail");
698
- assert!(error.to_string().contains("simulated stdout write failure"));
699
- let events = EventLog::new(&ws).tail(0).unwrap();
700
- assert!(!events
701
- .iter()
702
- .any(|event| event["event"] == serde_json::json!("mcp.tools_list_response_written")));
703
- let _ = std::fs::remove_dir_all(&ws);
704
- }
705
-
706
- #[test]
707
- fn stdio_loop_does_not_log_tools_list_when_flush_fails() {
708
- struct FlushFailWriter(Vec<u8>);
709
- impl Write for FlushFailWriter {
710
- fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> {
711
- self.0.extend_from_slice(buf);
712
- Ok(buf.len())
713
- }
714
-
715
- fn flush(&mut self) -> std::io::Result<()> {
716
- Err(std::io::Error::other("simulated stdout flush failure"))
717
- }
718
- }
719
-
720
- let ws = marker_ws("tools-list-flush-fail");
721
- let input = std::io::Cursor::new(
722
- br#"{"jsonrpc":"2.0","id":1,"method":"tools/list"}"#.to_vec(),
723
- );
724
- let error = run_stdio_loop(&ws, input, FlushFailWriter(Vec::new()))
725
- .expect_err("flush must fail");
726
- assert!(error.to_string().contains("simulated stdout flush failure"));
727
- let events = EventLog::new(&ws).tail(0).unwrap();
728
- assert!(!events
729
- .iter()
730
- .any(|event| event["event"] == serde_json::json!("mcp.tools_list_response_written")));
731
- let _ = std::fs::remove_dir_all(&ws);
732
- }
733
-
734
- #[test]
735
- fn stdio_loop_does_not_log_tools_list_for_initialize_or_notification() {
736
- let ws = marker_ws("tools-list-not-applicable");
737
- let input = std::io::Cursor::new(
738
- br#"{"jsonrpc":"2.0","id":1,"method":"initialize"}
739
- {"jsonrpc":"2.0","method":"notifications/initialized"}
740
- "#.to_vec(),
741
- );
742
- let mut output = Vec::new();
743
-
744
- run_stdio_loop(&ws, input, &mut output).unwrap();
745
-
746
- let events = EventLog::new(&ws).tail(0).unwrap();
747
- assert!(!events
748
- .iter()
749
- .any(|event| event["event"] == serde_json::json!("mcp.tools_list_response_written")));
750
- let _ = std::fs::remove_dir_all(&ws);
751
- }
752
-
753
- #[cfg(unix)]
754
- fn run_bound_handshake<W: Write>(ws: &Path, input: &str, writer: &mut W) -> Result<ServerRunReport, McpError> {
755
- let marker = McpServerLifecycleMarker {
756
- workspace: ws.to_path_buf(), agent_id: Some("worker".into()),
757
- owner_team_id: Some("owner".into()), started_at: chrono::Utc::now(),
758
- pid: std::process::id(), ppid: parent_pid(),
759
- };
760
- run_stdio_loop_inner(&TeamOrchestratorTools::new(ws), std::io::Cursor::new(input.as_bytes()),
761
- writer, &mut ServerRunReport::default(), &marker)
762
- }
763
-
764
- #[cfg(unix)]
765
- fn handshake_receipts(ws: &Path) -> usize {
766
- std::fs::read_dir(ws.join(".team/runtime/mcp-handshakes"))
767
- .map(|files| files.filter_map(Result::ok)
768
- .filter(|file| file.path().extension().is_some_and(|ext| ext == "json")).count())
769
- .unwrap_or(0)
770
- }
771
-
772
- #[test]
773
- #[cfg(unix)]
774
- fn stdio_handshake_receipt_requires_initialize_and_tools_list_flush() {
775
- let initialize = r#"{"jsonrpc":"2.0","id":1,"method":"initialize"}"#;
776
- let tools = r#"{"jsonrpc":"2.0","id":2,"method":"tools/list"}"#;
777
- let invalid_initialize = r#"{"jsonrpc":"2.0","method":"initialize"}"#;
778
- let invalid_tools = r#"{"jsonrpc":"2.0","method":"tools/list"}"#;
779
- for (tag, requests, expected) in [
780
- ("init-only", vec![initialize], 0),
781
- ("list-only", vec![tools], 0),
782
- ("invalid-init", vec![invalid_initialize, tools], 0),
783
- ("invalid-list", vec![initialize, invalid_tools], 0),
784
- ("ready", vec![initialize, tools], 1),
785
- ] {
786
- let ws = marker_ws(tag);
787
- let mut output = Vec::new();
788
- run_bound_handshake(&ws, &(requests.join("\n") + "\n"), &mut output).unwrap();
789
- assert_eq!(handshake_receipts(&ws), expected, "{tag}");
790
- let _ = std::fs::remove_dir_all(ws);
791
- }
792
- }
793
-
794
- #[test]
795
- #[cfg(unix)]
796
- fn stdio_failed_tools_list_flush_cannot_publish_a_handshake() {
797
- struct FailSecondFlush(usize);
798
- impl Write for FailSecondFlush {
799
- fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> { Ok(buf.len()) }
800
- fn flush(&mut self) -> std::io::Result<()> {
801
- self.0 += 1;
802
- if self.0 == 2 { Err(std::io::Error::other("controlled tools/list flush failure")) }
803
- else { Ok(()) }
804
- }
805
- }
806
- let ws = marker_ws("handshake-flush-failure");
807
- let input = "{\"jsonrpc\":\"2.0\",\"id\":1,\"method\":\"initialize\"}\n{\"jsonrpc\":\"2.0\",\"id\":2,\"method\":\"tools/list\"}\n";
808
- assert!(run_bound_handshake(&ws, input, &mut FailSecondFlush(0)).is_err());
809
- assert_eq!(handshake_receipts(&ws), 0);
810
- let _ = std::fs::remove_dir_all(ws);
811
- }
812
-
813
- #[test]
814
- fn stdio_loop_writes_started_and_stdin_eof_exit_markers() {
815
- let ws = marker_ws("eof");
816
- let input = std::io::Cursor::new(Vec::<u8>::new());
817
- let mut output = Vec::new();
818
-
819
- let report = run_stdio_loop(&ws, input, &mut output).unwrap();
820
-
821
- assert!(report.clean_eof);
822
- assert!(output.is_empty(), "empty stdin must not write stdout");
823
- let events = EventLog::new(&ws).tail(0).unwrap();
824
- assert_eq!(events.len(), 2, "started + stdin_eof exit events");
825
- assert_eq!(events[0]["event"], serde_json::json!("mcp.server_started"));
826
- assert_eq!(events[1]["event"], serde_json::json!("mcp.server_exit"));
827
- assert_eq!(events[1]["reason"], serde_json::json!("stdin_eof"));
828
- assert_eq!(
829
- events[1]["workspace"],
830
- serde_json::json!(ws.display().to_string())
831
- );
832
- assert_eq!(events[1]["pid"], serde_json::json!(std::process::id()));
833
- assert!(events[1].get("ppid").is_some());
834
- let _ = std::fs::remove_dir_all(&ws);
835
- }
836
-
837
- #[test]
838
- fn stdio_loop_writes_fatal_error_marker_before_returning_io_error() {
839
- struct FailingWriter;
840
- impl Write for FailingWriter {
841
- fn write(&mut self, _buf: &[u8]) -> std::io::Result<usize> {
842
- Err(std::io::Error::other("simulated stdout failure"))
843
- }
844
-
845
- fn flush(&mut self) -> std::io::Result<()> {
846
- Ok(())
847
- }
848
- }
849
-
850
- let ws = marker_ws("fatal");
851
- let input =
852
- std::io::Cursor::new(br#"{"jsonrpc":"2.0","id":1,"method":"initialize"}"#.to_vec());
853
-
854
- let err = run_stdio_loop(&ws, input, FailingWriter).expect_err("writer failure");
855
-
856
- assert!(err.to_string().contains("simulated stdout failure"));
857
- let events = EventLog::new(&ws).tail(0).unwrap();
858
- assert_eq!(events[0]["event"], serde_json::json!("mcp.server_started"));
859
- assert_eq!(events[1]["event"], serde_json::json!("mcp.server_exit"));
860
- assert_eq!(events[1]["reason"], serde_json::json!("fatal_error"));
861
- assert!(events[1]["error"]
862
- .as_str()
863
- .unwrap_or_default()
864
- .contains("simulated stdout failure"));
865
- let _ = std::fs::remove_dir_all(&ws);
866
- }
867
- }