@team-agent/installer 0.5.128 → 0.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (436) hide show
  1. package/README.md +4 -4
  2. package/README.zh.md +1 -1
  3. package/package.json +4 -8
  4. package/skills/team-agent/SKILL.md +37 -20
  5. package/skills/team-agent/command-coverage.json +169 -183
  6. package/skills/team-agent/docs/reference/team-agent-operator.md +64 -30
  7. package/skills/team-agent/references/recovery-runbook.md +1 -1
  8. package/skills/team-agent/references/team-agent-operator.md +64 -30
  9. package/templates/team_state.md +1 -1
  10. package/Cargo.lock +0 -1063
  11. package/Cargo.toml +0 -36
  12. package/crates/team-agent/Cargo.toml +0 -69
  13. package/crates/team-agent/src/app_server_test_support.rs +0 -258
  14. package/crates/team-agent/src/cli/adapters.rs +0 -1288
  15. package/crates/team-agent/src/cli/arguments.rs +0 -405
  16. package/crates/team-agent/src/cli/attach_app_server_leader.rs +0 -98
  17. package/crates/team-agent/src/cli/diagnose.rs +0 -1721
  18. package/crates/team-agent/src/cli/emit.rs +0 -2930
  19. package/crates/team-agent/src/cli/grok_slot.rs +0 -384
  20. package/crates/team-agent/src/cli/helpers.rs +0 -91
  21. package/crates/team-agent/src/cli/intent/runtime.rs +0 -1216
  22. package/crates/team-agent/src/cli/intent/runtime_tests.rs +0 -912
  23. package/crates/team-agent/src/cli/intent/tests.rs +0 -689
  24. package/crates/team-agent/src/cli/intent.rs +0 -664
  25. package/crates/team-agent/src/cli/leader.rs +0 -300
  26. package/crates/team-agent/src/cli/leader_prompt.rs +0 -261
  27. package/crates/team-agent/src/cli/leaders.rs +0 -418
  28. package/crates/team-agent/src/cli/mod.rs +0 -6545
  29. package/crates/team-agent/src/cli/models.rs +0 -1206
  30. package/crates/team-agent/src/cli/named_address.rs +0 -1651
  31. package/crates/team-agent/src/cli/profile.rs +0 -342
  32. package/crates/team-agent/src/cli/route.rs +0 -212
  33. package/crates/team-agent/src/cli/schedule.rs +0 -175
  34. package/crates/team-agent/src/cli/send/coordinator.rs +0 -164
  35. package/crates/team-agent/src/cli/send/mailbox.rs +0 -145
  36. package/crates/team-agent/src/cli/send/persist.rs +0 -156
  37. package/crates/team-agent/src/cli/send/presentation.rs +0 -370
  38. package/crates/team-agent/src/cli/send/resolve.rs +0 -573
  39. package/crates/team-agent/src/cli/send.rs +0 -199
  40. package/crates/team-agent/src/cli/shutdown_socket.rs +0 -288
  41. package/crates/team-agent/src/cli/spec.rs +0 -165
  42. package/crates/team-agent/src/cli/status.rs +0 -280
  43. package/crates/team-agent/src/cli/status_port/agents.rs +0 -358
  44. package/crates/team-agent/src/cli/status_port/approvals.rs +0 -79
  45. package/crates/team-agent/src/cli/status_port/brief.rs +0 -1981
  46. package/crates/team-agent/src/cli/status_port/compact.rs +0 -240
  47. package/crates/team-agent/src/cli/status_port/format.rs +0 -146
  48. package/crates/team-agent/src/cli/status_port/inbox.rs +0 -62
  49. package/crates/team-agent/src/cli/status_port/runtime.rs +0 -197
  50. package/crates/team-agent/src/cli/status_port/snapshot.rs +0 -208
  51. package/crates/team-agent/src/cli/status_port/store.rs +0 -416
  52. package/crates/team-agent/src/cli/status_port/tests.rs +0 -90
  53. package/crates/team-agent/src/cli/status_port.rs +0 -92
  54. package/crates/team-agent/src/cli/tests/base.rs +0 -885
  55. package/crates/team-agent/src/cli/tests/divergence.rs +0 -518
  56. package/crates/team-agent/src/cli/tests/lane_c.rs +0 -453
  57. package/crates/team-agent/src/cli/tests/leader_watch.rs +0 -322
  58. package/crates/team-agent/src/cli/tests/main_preserved.rs +0 -430
  59. package/crates/team-agent/src/cli/tests/missing_subcommands.rs +0 -336
  60. package/crates/team-agent/src/cli/tests/mod.rs +0 -137
  61. package/crates/team-agent/src/cli/tests/named_address.rs +0 -761
  62. package/crates/team-agent/src/cli/tests/parser_safety.rs +0 -383
  63. package/crates/team-agent/src/cli/tests/run_delegation.rs +0 -484
  64. package/crates/team-agent/src/cli/tests/shutdown_kill_plan.rs +0 -2179
  65. package/crates/team-agent/src/cli/tests/status_brief.rs +0 -1514
  66. package/crates/team-agent/src/cli/tests/status_send.rs +0 -888
  67. package/crates/team-agent/src/cli/tests/verb_install_skill.rs +0 -93
  68. package/crates/team-agent/src/cli/tests/verb_profile.rs +0 -392
  69. package/crates/team-agent/src/cli/triage.rs +0 -234
  70. package/crates/team-agent/src/cli/types.rs +0 -591
  71. package/crates/team-agent/src/codex_app_server.rs +0 -546
  72. package/crates/team-agent/src/communication_mode/mod.rs +0 -56
  73. package/crates/team-agent/src/compiler/tests.rs +0 -827
  74. package/crates/team-agent/src/compiler.rs +0 -890
  75. package/crates/team-agent/src/conpty/backend.rs +0 -829
  76. package/crates/team-agent/src/conpty/mod.rs +0 -33
  77. package/crates/team-agent/src/contract_runtime/backend.rs +0 -1744
  78. package/crates/team-agent/src/contract_runtime/commands.rs +0 -671
  79. package/crates/team-agent/src/contract_runtime/config.rs +0 -364
  80. package/crates/team-agent/src/contract_runtime/config_tests.rs +0 -76
  81. package/crates/team-agent/src/contract_runtime/discovery.rs +0 -449
  82. package/crates/team-agent/src/contract_runtime/fork.rs +0 -361
  83. package/crates/team-agent/src/contract_runtime/forward.rs +0 -288
  84. package/crates/team-agent/src/contract_runtime/framework.rs +0 -367
  85. package/crates/team-agent/src/contract_runtime/mcp.rs +0 -394
  86. package/crates/team-agent/src/contract_runtime/mod.rs +0 -17
  87. package/crates/team-agent/src/contract_runtime/prompt.rs +0 -216
  88. package/crates/team-agent/src/contract_runtime/pump.rs +0 -271
  89. package/crates/team-agent/src/contract_runtime/registry.rs +0 -553
  90. package/crates/team-agent/src/contract_runtime/workspace.rs +0 -228
  91. package/crates/team-agent/src/coordinator/backoff.rs +0 -741
  92. package/crates/team-agent/src/coordinator/conpty_shim.rs +0 -805
  93. package/crates/team-agent/src/coordinator/health.rs +0 -1185
  94. package/crates/team-agent/src/coordinator/mod.rs +0 -119
  95. package/crates/team-agent/src/coordinator/orphan.rs +0 -110
  96. package/crates/team-agent/src/coordinator/runtime_detectors.rs +0 -798
  97. package/crates/team-agent/src/coordinator/runtime_observation.rs +0 -84
  98. package/crates/team-agent/src/coordinator/steps/abnormal.rs +0 -2309
  99. package/crates/team-agent/src/coordinator/steps/delivery.rs +0 -15
  100. package/crates/team-agent/src/coordinator/steps/health_sync.rs +0 -15
  101. package/crates/team-agent/src/coordinator/steps/mod.rs +0 -126
  102. package/crates/team-agent/src/coordinator/steps/persist.rs +0 -15
  103. package/crates/team-agent/src/coordinator/steps/runtime_prompts.rs +0 -15
  104. package/crates/team-agent/src/coordinator/steps/session_gate.rs +0 -16
  105. package/crates/team-agent/src/coordinator/tests/a0_lostupdate.rs +0 -158
  106. package/crates/team-agent/src/coordinator/tests/abnormal.rs +0 -312
  107. package/crates/team-agent/src/coordinator/tests/api_error_recovery.rs +0 -300
  108. package/crates/team-agent/src/coordinator/tests/basics.rs +0 -211
  109. package/crates/team-agent/src/coordinator/tests/daemon.rs +0 -514
  110. package/crates/team-agent/src/coordinator/tests/energy.rs +0 -549
  111. package/crates/team-agent/src/coordinator/tests/health_sync.rs +0 -503
  112. package/crates/team-agent/src/coordinator/tests/main_preserved.rs +0 -186
  113. package/crates/team-agent/src/coordinator/tests/mod.rs +0 -295
  114. package/crates/team-agent/src/coordinator/tests/s3_bounded.rs +0 -207
  115. package/crates/team-agent/src/coordinator/tests/spine.rs +0 -308
  116. package/crates/team-agent/src/coordinator/tests/takeover.rs +0 -286
  117. package/crates/team-agent/src/coordinator/tests/tick_core.rs +0 -237
  118. package/crates/team-agent/src/coordinator/tick.rs +0 -3024
  119. package/crates/team-agent/src/coordinator/types.rs +0 -540
  120. package/crates/team-agent/src/db/agent_health_capture.rs +0 -126
  121. package/crates/team-agent/src/db/message_store.rs +0 -1527
  122. package/crates/team-agent/src/db/migration.rs +0 -984
  123. package/crates/team-agent/src/db/mod.rs +0 -26
  124. package/crates/team-agent/src/db/schema.rs +0 -663
  125. package/crates/team-agent/src/diagnose/comms.rs +0 -242
  126. package/crates/team-agent/src/diagnose/mod.rs +0 -44
  127. package/crates/team-agent/src/diagnose/orphans.rs +0 -889
  128. package/crates/team-agent/src/direct_delivery.rs +0 -368
  129. package/crates/team-agent/src/event_log.rs +0 -502
  130. package/crates/team-agent/src/fake_worker.rs +0 -303
  131. package/crates/team-agent/src/inbox_store.rs +0 -169
  132. package/crates/team-agent/src/kill_audit.rs +0 -106
  133. package/crates/team-agent/src/layout/manager.rs +0 -248
  134. package/crates/team-agent/src/layout/mod.rs +0 -36
  135. package/crates/team-agent/src/layout/overlay.rs +0 -134
  136. package/crates/team-agent/src/layout/placement.rs +0 -52
  137. package/crates/team-agent/src/layout/recovery.rs +0 -106
  138. package/crates/team-agent/src/layout/runtime_sessions.rs +0 -317
  139. package/crates/team-agent/src/layout/sessions.rs +0 -294
  140. package/crates/team-agent/src/layout/tmux_endpoint.rs +0 -165
  141. package/crates/team-agent/src/layout/worker_env.rs +0 -721
  142. package/crates/team-agent/src/layout/worker_window_helpers.rs +0 -37
  143. package/crates/team-agent/src/leader/helpers.rs +0 -178
  144. package/crates/team-agent/src/leader/incident.rs +0 -6
  145. package/crates/team-agent/src/leader/lease.rs +0 -3356
  146. package/crates/team-agent/src/leader/mod.rs +0 -104
  147. package/crates/team-agent/src/leader/owner_bind.rs +0 -400
  148. package/crates/team-agent/src/leader/prompt.rs +0 -905
  149. package/crates/team-agent/src/leader/provider_attribution.rs +0 -247
  150. package/crates/team-agent/src/leader/rediscover/tests.rs +0 -689
  151. package/crates/team-agent/src/leader/rediscover.rs +0 -1192
  152. package/crates/team-agent/src/leader/registry.rs +0 -888
  153. package/crates/team-agent/src/leader/start.rs +0 -4501
  154. package/crates/team-agent/src/leader/takeover.rs +0 -65
  155. package/crates/team-agent/src/leader/tests/basics.rs +0 -337
  156. package/crates/team-agent/src/leader/tests/byte_findings.rs +0 -355
  157. package/crates/team-agent/src/leader/tests/claim_leader_mailbox_flush_contract.rs +0 -544
  158. package/crates/team-agent/src/leader/tests/historical_inventory_upgrade_gate_red.rs +0 -624
  159. package/crates/team-agent/src/leader/tests/identity.rs +0 -465
  160. package/crates/team-agent/src/leader/tests/identity_session_names.rs +0 -42
  161. package/crates/team-agent/src/leader/tests/idle.rs +0 -113
  162. package/crates/team-agent/src/leader/tests/lease_api.rs +0 -520
  163. package/crates/team-agent/src/leader/tests/lease_claim.rs +0 -629
  164. package/crates/team-agent/src/leader/tests/mod.rs +0 -106
  165. package/crates/team-agent/src/leader/tests/prompt_contract.rs +0 -268
  166. package/crates/team-agent/src/leader/tests/rediscover.rs +0 -403
  167. package/crates/team-agent/src/leader/tests/rehomed_env.rs +0 -83
  168. package/crates/team-agent/src/leader/tests/team_in_team_state_scope_red.rs +0 -1273
  169. package/crates/team-agent/src/leader/tests/terminal_and_replay_vs_rerender_invariants_red.rs +0 -417
  170. package/crates/team-agent/src/leader/tests/wake_start_owner.rs +0 -168
  171. package/crates/team-agent/src/leader/types.rs +0 -534
  172. package/crates/team-agent/src/lib.rs +0 -147
  173. package/crates/team-agent/src/lifecycle/helpers.rs +0 -212
  174. package/crates/team-agent/src/lifecycle/launch/add_agent.rs +0 -881
  175. package/crates/team-agent/src/lifecycle/launch/add_agent_state.rs +0 -598
  176. package/crates/team-agent/src/lifecycle/launch/agent_state.rs +0 -332
  177. package/crates/team-agent/src/lifecycle/launch/clone_agent.rs +0 -204
  178. package/crates/team-agent/src/lifecycle/launch/fork_agent.rs +0 -107
  179. package/crates/team-agent/src/lifecycle/launch/fork_entry.rs +0 -144
  180. package/crates/team-agent/src/lifecycle/launch/identity.rs +0 -674
  181. package/crates/team-agent/src/lifecycle/launch/layout.rs +0 -350
  182. package/crates/team-agent/src/lifecycle/launch/leader_context.rs +0 -589
  183. package/crates/team-agent/src/lifecycle/launch/mcp_config.rs +0 -160
  184. package/crates/team-agent/src/lifecycle/launch/ownership.rs +0 -105
  185. package/crates/team-agent/src/lifecycle/launch/pi_mcp.rs +0 -899
  186. package/crates/team-agent/src/lifecycle/launch/pi_mcp_extension.js +0 -225
  187. package/crates/team-agent/src/lifecycle/launch/plan.rs +0 -269
  188. package/crates/team-agent/src/lifecycle/launch/quick_start.rs +0 -5200
  189. package/crates/team-agent/src/lifecycle/launch/quick_start_transport.rs +0 -368
  190. package/crates/team-agent/src/lifecycle/launch/readiness.rs +0 -519
  191. package/crates/team-agent/src/lifecycle/launch/role_source.rs +0 -287
  192. package/crates/team-agent/src/lifecycle/launch/spawn.rs +0 -473
  193. package/crates/team-agent/src/lifecycle/launch/spec_state.rs +0 -801
  194. package/crates/team-agent/src/lifecycle/launch/state_projection.rs +0 -624
  195. package/crates/team-agent/src/lifecycle/launch/worker_env.rs +0 -558
  196. package/crates/team-agent/src/lifecycle/launch.rs +0 -557
  197. package/crates/team-agent/src/lifecycle/lock.rs +0 -350
  198. package/crates/team-agent/src/lifecycle/mod.rs +0 -79
  199. package/crates/team-agent/src/lifecycle/pane_input_lock.rs +0 -239
  200. package/crates/team-agent/src/lifecycle/profile_launch.rs +0 -1067
  201. package/crates/team-agent/src/lifecycle/profile_smoke.rs +0 -557
  202. package/crates/team-agent/src/lifecycle/restart/agent.rs +0 -2199
  203. package/crates/team-agent/src/lifecycle/restart/avatar.rs +0 -1798
  204. package/crates/team-agent/src/lifecycle/restart/claude_fork.rs +0 -163
  205. package/crates/team-agent/src/lifecycle/restart/common.rs +0 -2362
  206. package/crates/team-agent/src/lifecycle/restart/orchestrator.rs +0 -65
  207. package/crates/team-agent/src/lifecycle/restart/preflight.rs +0 -113
  208. package/crates/team-agent/src/lifecycle/restart/rebuild.rs +0 -5135
  209. package/crates/team-agent/src/lifecycle/restart/remove.rs +0 -1504
  210. package/crates/team-agent/src/lifecycle/restart/selection.rs +0 -559
  211. package/crates/team-agent/src/lifecycle/restart/team_state.rs +0 -329
  212. package/crates/team-agent/src/lifecycle/restart.rs +0 -227
  213. package/crates/team-agent/src/lifecycle/role_config.rs +0 -1230
  214. package/crates/team-agent/src/lifecycle/tests/acceptance_b_batch_red.rs +0 -1021
  215. package/crates/team-agent/src/lifecycle/tests/agent_ops.rs +0 -1205
  216. package/crates/team-agent/src/lifecycle/tests/b0_legacy_snapshot_nonauthority_contract.rs +0 -265
  217. package/crates/team-agent/src/lifecycle/tests/b0_reader_hideone_audit_contract.rs +0 -490
  218. package/crates/team-agent/src/lifecycle/tests/behavioral_diff_264_red.rs +0 -656
  219. package/crates/team-agent/src/lifecycle/tests/claude_compatible_config_red.rs +0 -325
  220. package/crates/team-agent/src/lifecycle/tests/claude_profile_launch_red.rs +0 -447
  221. package/crates/team-agent/src/lifecycle/tests/cli_argv_routing_red.rs +0 -1638
  222. package/crates/team-agent/src/lifecycle/tests/clone_agent_preserves_source_tools.rs +0 -427
  223. package/crates/team-agent/src/lifecycle/tests/clone_fork_copilot_perms_red.rs +0 -770
  224. package/crates/team-agent/src/lifecycle/tests/communication_mode_runtime_contract_red.rs +0 -419
  225. package/crates/team-agent/src/lifecycle/tests/copilot_provider_red.rs +0 -2035
  226. package/crates/team-agent/src/lifecycle/tests/core.rs +0 -1327
  227. package/crates/team-agent/src/lifecycle/tests/f032_startup_prompt_best_effort_red.rs +0 -315
  228. package/crates/team-agent/src/lifecycle/tests/fixtures/pi_list_models_g0.stdout.txt +0 -222
  229. package/crates/team-agent/src/lifecycle/tests/fixtures/pi_list_models_spaced_ids.stdout.txt +0 -9
  230. package/crates/team-agent/src/lifecycle/tests/fixtures/pi_native_mcp_host.mjs +0 -72
  231. package/crates/team-agent/src/lifecycle/tests/gate_fixtures.rs +0 -562
  232. package/crates/team-agent/src/lifecycle/tests/grok_require_explicit_model_red.rs +0 -110
  233. package/crates/team-agent/src/lifecycle/tests/harvest2_a_batch_red.rs +0 -512
  234. package/crates/team-agent/src/lifecycle/tests/host_cotenant_death_p0_contract.rs +0 -921
  235. package/crates/team-agent/src/lifecycle/tests/issue238_codex_effort_contract.rs +0 -68
  236. package/crates/team-agent/src/lifecycle/tests/lane_ops.rs +0 -1851
  237. package/crates/team-agent/src/lifecycle/tests/launch_spawn.rs +0 -3983
  238. package/crates/team-agent/src/lifecycle/tests/lifecycle_lock.rs +0 -339
  239. package/crates/team-agent/src/lifecycle/tests/lifecycle_rollback_red.rs +0 -596
  240. package/crates/team-agent/src/lifecycle/tests/main_preserved.rs +0 -513
  241. package/crates/team-agent/src/lifecycle/tests/mcp_tool_name_format_red.rs +0 -69
  242. package/crates/team-agent/src/lifecycle/tests/phase_b_contracts.rs +0 -824
  243. package/crates/team-agent/src/lifecycle/tests/phase_golden.rs +0 -723
  244. package/crates/team-agent/src/lifecycle/tests/pi_catalog_red.rs +0 -164
  245. package/crates/team-agent/src/lifecycle/tests/pi_command_red.rs +0 -200
  246. package/crates/team-agent/src/lifecycle/tests/pi_compiler_red.rs +0 -210
  247. package/crates/team-agent/src/lifecycle/tests/pi_dual_entry_red.rs +0 -527
  248. package/crates/team-agent/src/lifecycle/tests/pi_executable_mcp_red.rs +0 -1062
  249. package/crates/team-agent/src/lifecycle/tests/pi_fork_session_inheritance_red.rs +0 -1419
  250. package/crates/team-agent/src/lifecycle/tests/pi_lifecycle_doctor_red.rs +0 -98
  251. package/crates/team-agent/src/lifecycle/tests/pi_native_mcp_capability_red.rs +0 -550
  252. package/crates/team-agent/src/lifecycle/tests/pi_session_delivery_red.rs +0 -226
  253. package/crates/team-agent/src/lifecycle/tests/quick_start_worker_readiness_red.rs +0 -332
  254. package/crates/team-agent/src/lifecycle/tests/realmachine_clusters_1_6_red.rs +0 -786
  255. package/crates/team-agent/src/lifecycle/tests/realmachine_residual_g1_g4_red.rs +0 -648
  256. package/crates/team-agent/src/lifecycle/tests/restart.rs +0 -185
  257. package/crates/team-agent/src/lifecycle/tests/restart_build_before_destroy_0540_contract.rs +0 -1053
  258. package/crates/team-agent/src/lifecycle/tests/restart_liveness_red.rs +0 -679
  259. package/crates/team-agent/src/lifecycle/tests/restart_rebind_hotfix_252_red.rs +0 -1126
  260. package/crates/team-agent/src/lifecycle/tests/restart_session_capture_red.rs +0 -153
  261. package/crates/team-agent/src/lifecycle/tests/resume_recover_red.rs +0 -427
  262. package/crates/team-agent/src/lifecycle/tests/stale_team_saveconflict_contract.rs +0 -431
  263. package/crates/team-agent/src/lifecycle/tests/startup_latency_contract.rs +0 -1066
  264. package/crates/team-agent/src/lifecycle/tests/status_credential_redaction_contract.rs +0 -876
  265. package/crates/team-agent/src/lifecycle/tests/subprep_codex_trust_roundtrip_red.rs +0 -1026
  266. package/crates/team-agent/src/lifecycle/tests/swallow_batch4_semantics_red.rs +0 -342
  267. package/crates/team-agent/src/lifecycle/tests/team_in_team_identity_scope_red.rs +0 -543
  268. package/crates/team-agent/src/lifecycle/tests/team_in_team_sibling_quick_start_red.rs +0 -1103
  269. package/crates/team-agent/src/lifecycle/tests/team_in_team_state_scope_red.rs +0 -1276
  270. package/crates/team-agent/src/lifecycle/tests/team_key_retirement_roster_red.rs +0 -145
  271. package/crates/team-agent/src/lifecycle/tests/team_key_retirement_txn_red.rs +0 -603
  272. package/crates/team-agent/src/lifecycle/tests/test_isolation_escape_contract.rs +0 -936
  273. package/crates/team-agent/src/lifecycle/tests/upgrade_compat_0211_red.rs +0 -970
  274. package/crates/team-agent/src/lifecycle/tests/verify_rs031_window_consistency_red.rs +0 -995
  275. package/crates/team-agent/src/lifecycle/tests/worker_spawn_env_red.rs +0 -836
  276. package/crates/team-agent/src/lifecycle/tests.rs +0 -105
  277. package/crates/team-agent/src/lifecycle/types.rs +0 -877
  278. package/crates/team-agent/src/lifecycle/worker_command_context.rs +0 -363
  279. package/crates/team-agent/src/main.rs +0 -52
  280. package/crates/team-agent/src/mcp_server/helpers.rs +0 -510
  281. package/crates/team-agent/src/mcp_server/lifecycle_tools/mod.rs +0 -6
  282. package/crates/team-agent/src/mcp_server/lifecycle_tools/state_status.rs +0 -43
  283. package/crates/team-agent/src/mcp_server/mod.rs +0 -119
  284. package/crates/team-agent/src/mcp_server/normalize.rs +0 -485
  285. package/crates/team-agent/src/mcp_server/readiness.rs +0 -527
  286. package/crates/team-agent/src/mcp_server/readiness_tests.rs +0 -348
  287. package/crates/team-agent/src/mcp_server/tests/golden.rs +0 -285
  288. package/crates/team-agent/src/mcp_server/tests/normalize.rs +0 -247
  289. package/crates/team-agent/src/mcp_server/tests/scoped.rs +0 -158
  290. package/crates/team-agent/src/mcp_server/tests/send.rs +0 -353
  291. package/crates/team-agent/src/mcp_server/tests/tools.rs +0 -341
  292. package/crates/team-agent/src/mcp_server/tests/wire.rs +0 -254
  293. package/crates/team-agent/src/mcp_server/tests.rs +0 -43
  294. package/crates/team-agent/src/mcp_server/tools.rs +0 -889
  295. package/crates/team-agent/src/mcp_server/types.rs +0 -396
  296. package/crates/team-agent/src/mcp_server/wire.rs +0 -867
  297. package/crates/team-agent/src/messaging/activity.rs +0 -461
  298. package/crates/team-agent/src/messaging/address.rs +0 -87
  299. package/crates/team-agent/src/messaging/delivery.rs +0 -3727
  300. package/crates/team-agent/src/messaging/delivery_consumption_tests.rs +0 -234
  301. package/crates/team-agent/src/messaging/enter_rescue.rs +0 -362
  302. package/crates/team-agent/src/messaging/enter_rescue_tests.rs +0 -633
  303. package/crates/team-agent/src/messaging/helpers.rs +0 -336
  304. package/crates/team-agent/src/messaging/leader_channel.rs +0 -287
  305. package/crates/team-agent/src/messaging/leader_receiver.rs +0 -786
  306. package/crates/team-agent/src/messaging/mod.rs +0 -167
  307. package/crates/team-agent/src/messaging/persist.rs +0 -377
  308. package/crates/team-agent/src/messaging/presentation.rs +0 -417
  309. package/crates/team-agent/src/messaging/reminders.rs +0 -316
  310. package/crates/team-agent/src/messaging/results/collection_tests.rs +0 -719
  311. package/crates/team-agent/src/messaging/results.rs +0 -1415
  312. package/crates/team-agent/src/messaging/scheduler.rs +0 -223
  313. package/crates/team-agent/src/messaging/selftest.rs +0 -315
  314. package/crates/team-agent/src/messaging/send.rs +0 -981
  315. package/crates/team-agent/src/messaging/tests/basic.rs +0 -346
  316. package/crates/team-agent/src/messaging/tests/dup_inject.rs +0 -657
  317. package/crates/team-agent/src/messaging/tests/e23.rs +0 -49
  318. package/crates/team-agent/src/messaging/tests/leader_channel.rs +0 -169
  319. package/crates/team-agent/src/messaging/tests/leader_inject_acceptance.rs +0 -817
  320. package/crates/team-agent/src/messaging/tests/main_preserved.rs +0 -85
  321. package/crates/team-agent/src/messaging/tests/mod.rs +0 -306
  322. package/crates/team-agent/src/messaging/tests/runtime.rs +0 -3549
  323. package/crates/team-agent/src/messaging/tests/spine.rs +0 -853
  324. package/crates/team-agent/src/messaging/tests/wave2.rs +0 -381
  325. package/crates/team-agent/src/messaging/trust.rs +0 -215
  326. package/crates/team-agent/src/messaging/types.rs +0 -472
  327. package/crates/team-agent/src/messaging/wait.rs +0 -366
  328. package/crates/team-agent/src/messaging/watchers.rs +0 -916
  329. package/crates/team-agent/src/model/enums.rs +0 -356
  330. package/crates/team-agent/src/model/errors.rs +0 -18
  331. package/crates/team-agent/src/model/ids.rs +0 -165
  332. package/crates/team-agent/src/model/mod.rs +0 -29
  333. package/crates/team-agent/src/model/name_similarity.rs +0 -252
  334. package/crates/team-agent/src/model/pane_authority_refusal.rs +0 -359
  335. package/crates/team-agent/src/model/paths.rs +0 -257
  336. package/crates/team-agent/src/model/routing.rs +0 -387
  337. package/crates/team-agent/src/model/spec.rs +0 -1184
  338. package/crates/team-agent/src/model/task_graph.rs +0 -321
  339. package/crates/team-agent/src/model/testdata/fuzz.golden.yaml +0 -43
  340. package/crates/team-agent/src/model/testdata/fuzz.yaml +0 -43
  341. package/crates/team-agent/src/model/testdata/spec_invalid_a.yaml +0 -209
  342. package/crates/team-agent/src/model/testdata/team.spec.golden.yaml +0 -208
  343. package/crates/team-agent/src/model/testdata/team.spec.yaml +0 -208
  344. package/crates/team-agent/src/model/yaml/tests.rs +0 -188
  345. package/crates/team-agent/src/model/yaml.rs +0 -802
  346. package/crates/team-agent/src/os_probe.rs +0 -280
  347. package/crates/team-agent/src/packaging/install.rs +0 -219
  348. package/crates/team-agent/src/packaging/migrate.rs +0 -38
  349. package/crates/team-agent/src/packaging/mod.rs +0 -91
  350. package/crates/team-agent/src/packaging/repair.rs +0 -33
  351. package/crates/team-agent/src/packaging/tests.rs +0 -822
  352. package/crates/team-agent/src/packaging/types.rs +0 -417
  353. package/crates/team-agent/src/platform/argv.rs +0 -331
  354. package/crates/team-agent/src/platform/errors.rs +0 -104
  355. package/crates/team-agent/src/platform/file_lock.rs +0 -279
  356. package/crates/team-agent/src/platform/mod.rs +0 -5
  357. package/crates/team-agent/src/platform/process.rs +0 -545
  358. package/crates/team-agent/src/provider/adapter.rs +0 -1150
  359. package/crates/team-agent/src/provider/adapters/claude.rs +0 -78
  360. package/crates/team-agent/src/provider/adapters/claude_fork.rs +0 -131
  361. package/crates/team-agent/src/provider/adapters/copilot.rs +0 -75
  362. package/crates/team-agent/src/provider/adapters/copilot_fork.rs +0 -307
  363. package/crates/team-agent/src/provider/adapters/fake.rs +0 -18
  364. package/crates/team-agent/src/provider/adapters/mod.rs +0 -30
  365. package/crates/team-agent/src/provider/adapters/pi.rs +0 -106
  366. package/crates/team-agent/src/provider/approvals/mod.rs +0 -3
  367. package/crates/team-agent/src/provider/approvals/parsing.rs +0 -586
  368. package/crates/team-agent/src/provider/approvals/runtime_prompts.rs +0 -205
  369. package/crates/team-agent/src/provider/argv_route.rs +0 -405
  370. package/crates/team-agent/src/provider/bypass_flags.rs +0 -116
  371. package/crates/team-agent/src/provider/classify.rs +0 -708
  372. package/crates/team-agent/src/provider/command_helpers.rs +0 -45
  373. package/crates/team-agent/src/provider/faults.rs +0 -165
  374. package/crates/team-agent/src/provider/helpers.rs +0 -52
  375. package/crates/team-agent/src/provider/mod.rs +0 -78
  376. package/crates/team-agent/src/provider/model_catalog.rs +0 -910
  377. package/crates/team-agent/src/provider/session/capture.rs +0 -2731
  378. package/crates/team-agent/src/provider/session/context_fork/claude.rs +0 -123
  379. package/crates/team-agent/src/provider/session/context_fork/outcome.rs +0 -172
  380. package/crates/team-agent/src/provider/session/context_fork.rs +0 -396
  381. package/crates/team-agent/src/provider/session/mod.rs +0 -36
  382. package/crates/team-agent/src/provider/session/resume.rs +0 -269
  383. package/crates/team-agent/src/provider/session_scan/claude.rs +0 -523
  384. package/crates/team-agent/src/provider/session_scan/common/tests.rs +0 -316
  385. package/crates/team-agent/src/provider/session_scan/common.rs +0 -654
  386. package/crates/team-agent/src/provider/session_scan/copilot.rs +0 -280
  387. package/crates/team-agent/src/provider/session_scan/pi.rs +0 -185
  388. package/crates/team-agent/src/provider/session_scan.rs +0 -71
  389. package/crates/team-agent/src/provider/startup_prompt.rs +0 -757
  390. package/crates/team-agent/src/provider/submit_now.rs +0 -71
  391. package/crates/team-agent/src/provider/testdata/copilot-ready-marker.txt +0 -5
  392. package/crates/team-agent/src/provider/testdata/copilot-trust-prompt.txt +0 -19
  393. package/crates/team-agent/src/provider/testdata/grok-models-authenticated.stdout +0 -9
  394. package/crates/team-agent/src/provider/testdata/grok-models-unauthenticated.stdout +0 -7
  395. package/crates/team-agent/src/provider/tests/adapter.rs +0 -441
  396. package/crates/team-agent/src/provider/tests/classify.rs +0 -148
  397. package/crates/team-agent/src/provider/tests/command_helpers.rs +0 -35
  398. package/crates/team-agent/src/provider/tests/copilot_fork.rs +0 -191
  399. package/crates/team-agent/src/provider/tests/faults.rs +0 -200
  400. package/crates/team-agent/src/provider/tests/idle.rs +0 -177
  401. package/crates/team-agent/src/provider/tests/wire.rs +0 -213
  402. package/crates/team-agent/src/provider/tests.rs +0 -32
  403. package/crates/team-agent/src/provider/types.rs +0 -529
  404. package/crates/team-agent/src/provider/wire.rs +0 -394
  405. package/crates/team-agent/src/redaction.rs +0 -259
  406. package/crates/team-agent/src/state/abnormal_watch/tests/mod.rs +0 -248
  407. package/crates/team-agent/src/state/abnormal_watch.rs +0 -144
  408. package/crates/team-agent/src/state/identity.rs +0 -914
  409. package/crates/team-agent/src/state/identity_keys.rs +0 -132
  410. package/crates/team-agent/src/state/mod.rs +0 -74
  411. package/crates/team-agent/src/state/owner_gate.rs +0 -482
  412. package/crates/team-agent/src/state/ownership.rs +0 -563
  413. package/crates/team-agent/src/state/paths.rs +0 -395
  414. package/crates/team-agent/src/state/persist.rs +0 -3811
  415. package/crates/team-agent/src/state/projection.rs +0 -1508
  416. package/crates/team-agent/src/state/repository/intent.rs +0 -14
  417. package/crates/team-agent/src/state/repository/tests.rs +0 -184
  418. package/crates/team-agent/src/state/repository.rs +0 -866
  419. package/crates/team-agent/src/state/selector.rs +0 -160
  420. package/crates/team-agent/src/state/testdata/state-rich.canonical.json +0 -133
  421. package/crates/team-agent/src/test_support/models_timeout_fixture.rs +0 -144
  422. package/crates/team-agent/src/tmux_backend/enter_rescue.rs +0 -325
  423. package/crates/team-agent/src/tmux_backend/enter_rescue_tests.rs +0 -432
  424. package/crates/team-agent/src/tmux_backend/native_input.rs +0 -513
  425. package/crates/team-agent/src/tmux_backend/native_input_tests.rs +0 -742
  426. package/crates/team-agent/src/tmux_backend/tests.rs +0 -4103
  427. package/crates/team-agent/src/tmux_backend.rs +0 -4492
  428. package/crates/team-agent/src/topology.rs +0 -537
  429. package/crates/team-agent/src/transport/enter_rescue.rs +0 -166
  430. package/crates/team-agent/src/transport/native_input.rs +0 -491
  431. package/crates/team-agent/src/transport/test_support.rs +0 -743
  432. package/crates/team-agent/src/transport/tests/behavior.rs +0 -326
  433. package/crates/team-agent/src/transport/tests/mod.rs +0 -194
  434. package/crates/team-agent/src/transport/tests/wire.rs +0 -574
  435. package/crates/team-agent/src/transport.rs +0 -1655
  436. package/crates/team-agent/src/transport_factory.rs +0 -819
@@ -1,889 +0,0 @@
1
- //!
2
- //! step 14a · mcp_server::tools — `TeamOrchestratorTools`, the three MCP handlers.
3
-
4
- use std::path::{Path, PathBuf};
5
-
6
- use serde_json::Value;
7
-
8
- // ── REUSE: step 2 model (ids + normalized-envelope value enums) ─────────────
9
- use crate::model::enums::ResultStatus;
10
- use crate::model::ids::{AgentId, TaskId, TeamKey};
11
-
12
- // ── REUSE: step 4 event_log / step 7 message_store ──────────────────────────
13
- use crate::event_log::EventLog;
14
-
15
- // ── REUSE: step 5 state persist / projection ────────────────────────────────
16
- use crate::direct_delivery::snapshot as load_runtime_state;
17
-
18
- // ── REUSE: step 11 messaging delegate surface ───────────────────────────────
19
- use crate::messaging::{self, DeliveryStatus, MessageTarget, SendOptions, TrustedSender};
20
-
21
- use super::helpers::{
22
- current_reportable_message_for, delivery_outcome_value, direct_message_attribution_for,
23
- ensure_object, enum_value, is_worker_recipient, latest_task_for_assignee,
24
- non_empty_string, object_fields, requires_ack_for_target, tool_runtime_error,
25
- DirectMessageAttribution,
26
- };
27
- use super::normalize::{
28
- compact_tool_result, normalize_report_envelope, report_result_integrity_warnings,
29
- validate_test_evidence_schema,
30
- };
31
- use super::types::{
32
- Scope, SendOutcome, ToolError, ToolErrorReason, ToolOk, ToolResult, VisiblePeers,
33
- };
34
-
35
- // ═══════════════════════════════════════════════════════════════════════════
36
- // TeamOrchestratorTools — the three typed MCP handlers.
37
- // Identity/scope anchored on spawn-time env (TEAM_AGENT_ID / TEAM_AGENT_OWNER_TEAM_ID);
38
- // every handler delegates to runtime/MessageStore/EventLog. These ARE the
39
- // contract-callable behavioral entry fns.
40
- // ═══════════════════════════════════════════════════════════════════════════
41
-
42
- /// `TeamOrchestratorTools` (`tools.py:72-82`). Scope anchored on spawn-time env: no
43
- /// candidate scan of state/messages/runtime agents (C13-C17). Constructed with the
44
- /// workspace; `agent_id`/`owner_team_id` are captured from env at construction.
45
- pub struct TeamOrchestratorTools {
46
- /// Resolved (`workspace.resolve()`) workspace root.
47
- workspace: PathBuf,
48
- /// `TEAM_AGENT_ID` — the sender identity anchor (`None` when absent → `"unknown"`).
49
- agent_id: Option<AgentId>,
50
- /// `TEAM_AGENT_OWNER_TEAM_ID` — the scope anchor (`None` → legacy single-team).
51
- owner_team_id: Option<TeamKey>,
52
- }
53
-
54
- impl TeamOrchestratorTools {
55
- /// `__init__(workspace)` (`tools.py:79-82`): resolve workspace, read identity/scope
56
- /// from `TEAM_AGENT_ID` / `TEAM_AGENT_OWNER_TEAM_ID` env (`_text` empties → None).
57
- pub fn new(workspace: &Path) -> Self {
58
- let agent_id = std::env::var("TEAM_AGENT_ID")
59
- .ok()
60
- .and_then(|s| non_empty_string(&s).map(ToString::to_string))
61
- .map(AgentId::new);
62
- let owner_team_id = std::env::var("TEAM_AGENT_OWNER_TEAM_ID")
63
- .ok()
64
- .and_then(|s| non_empty_string(&s).map(ToString::to_string))
65
- .map(TeamKey::new);
66
- Self::with_identity(workspace, agent_id, owner_team_id)
67
- }
68
-
69
- /// Test/explicit-injection constructor: bind identity/scope directly instead of
70
- /// reading env (so contracts can exercise scoped behavior deterministically).
71
- pub fn with_identity(
72
- workspace: &Path,
73
- agent_id: Option<AgentId>,
74
- owner_team_id: Option<TeamKey>,
75
- ) -> Self {
76
- Self {
77
- workspace: std::fs::canonicalize(workspace).unwrap_or_else(|_| workspace.to_path_buf()),
78
- agent_id,
79
- owner_team_id,
80
- }
81
- }
82
-
83
- /// Validate an identity supplied by an MCP request against the identity captured
84
- /// when this worker server started. Missing request fields are intentionally valid;
85
- /// the captured identity is the only fallback. Present values must be non-empty and
86
- /// equal to that capture, otherwise reject before routing or persistence.
87
- pub(crate) fn validate_identity_argument(
88
- &self,
89
- tool: &str,
90
- value: Option<&Value>,
91
- ) -> Result<(), ToolError> {
92
- let expected = self.require_captured_identity(tool)?;
93
- let Some(value) = value else {
94
- return Ok(());
95
- };
96
- let Some(provided) = value.as_str().and_then(non_empty_string) else {
97
- return Err(self.identity_mismatch(tool, expected.as_str(), None));
98
- };
99
- if provided != expected.as_str() {
100
- return Err(self.identity_mismatch(tool, expected.as_str(), Some(provided)));
101
- }
102
- Ok(())
103
- }
104
-
105
- /// Report requests can carry identity in both the top-level argument and the
106
- /// envelope. Validate both independently so an envelope cannot overwrite the
107
- /// framework-bound sender after the top-level check.
108
- pub(crate) fn validate_report_identity_request(
109
- &self,
110
- envelope: Option<&Value>,
111
- explicit_agent_id: Option<&Value>,
112
- ) -> Result<(), ToolError> {
113
- self.validate_identity_argument("report_result", explicit_agent_id)?;
114
- if let Some(value) = envelope
115
- .and_then(Value::as_object)
116
- .and_then(|obj| obj.get("agent_id"))
117
- {
118
- self.validate_identity_argument("report_result", Some(value))?;
119
- }
120
- Ok(())
121
- }
122
-
123
- fn require_captured_identity(&self, tool: &str) -> Result<&AgentId, ToolError> {
124
- self.agent_id
125
- .as_ref()
126
- .filter(|agent| non_empty_string(agent.as_str()).is_some())
127
- .ok_or_else(|| self.identity_mismatch(tool, "<missing>", None))
128
- }
129
-
130
- fn validate_report_identity_text(
131
- &self,
132
- envelope: Option<&Value>,
133
- explicit_agent_id: Option<&str>,
134
- ) -> Result<(), ToolError> {
135
- let expected = self.require_captured_identity("report_result")?;
136
- if let Some(provided) = explicit_agent_id.and_then(non_empty_string) {
137
- if provided != expected.as_str() {
138
- return Err(self.identity_mismatch(
139
- "report_result",
140
- expected.as_str(),
141
- Some(provided),
142
- ));
143
- }
144
- } else if explicit_agent_id.is_some() {
145
- return Err(self.identity_mismatch("report_result", expected.as_str(), None));
146
- }
147
- if let Some(value) = envelope
148
- .and_then(Value::as_object)
149
- .and_then(|obj| obj.get("agent_id"))
150
- {
151
- self.validate_identity_argument("report_result", Some(value))?;
152
- }
153
- Ok(())
154
- }
155
-
156
- fn identity_mismatch(&self, tool: &str, expected: &str, provided: Option<&str>) -> ToolError {
157
- let mut error = ToolError::new(
158
- ToolErrorReason::McpScopeRefused,
159
- format!(
160
- "identity_mismatch: {tool} agent_id must match framework-injected TEAM_AGENT_ID"
161
- ),
162
- "IdentityError",
163
- );
164
- error
165
- .extra
166
- .insert("status".to_string(), Value::String("refused".to_string()));
167
- error
168
- .extra
169
- .insert("identity_mismatch".to_string(), Value::Bool(true));
170
- error
171
- .extra
172
- .insert("tool".to_string(), Value::String(tool.to_string()));
173
- error.extra.insert(
174
- "expected_agent_id".to_string(),
175
- Value::String(expected.to_string()),
176
- );
177
- error.extra.insert(
178
- "provided_agent_id".to_string(),
179
- provided.map_or(Value::Null, |value| Value::String(value.to_string())),
180
- );
181
- error
182
- }
183
-
184
- /// `send_message` (`tools.py:135-183`): C14/C15/C17 scope resolution.
185
- /// - sender = immutable `TEAM_AGENT_ID` captured when the MCP server starts.
186
- /// - `requires_ack` defaults from target (`_requires_ack_for_target`).
187
- /// - C23 cross-team pre-refusal ([`Self::refuse_cross_team_peer`]) before any
188
- /// runtime call.
189
- /// - delegates to [`messaging::send_message`], writes `mcp.scope_resolved`.
190
- /// - worker recipient + message_id → [`SendOutcome::WorkerAccepted`]; else
191
- /// [`SendOutcome::Direct`].
192
- /// Returns `Err(ToolError{PeerNotInScope})` on a refused cross-team peer.
193
- pub fn send_message(
194
- &self,
195
- to: &MessageTarget,
196
- content: &str,
197
- task_id: Option<&str>,
198
- requires_ack: Option<bool>,
199
- scope_override: Option<Scope>,
200
- ) -> Result<SendOutcome, ToolError> {
201
- self.send_message_with_presentation(
202
- to,
203
- content,
204
- task_id,
205
- requires_ack,
206
- scope_override,
207
- None,
208
- None,
209
- )
210
- }
211
-
212
- pub fn send_message_with_presentation(
213
- &self,
214
- to: &MessageTarget,
215
- content: &str,
216
- task_id: Option<&str>,
217
- requires_ack: Option<bool>,
218
- scope_override: Option<Scope>,
219
- mailbox: Option<&Value>,
220
- presentation: Option<&Value>,
221
- ) -> Result<SendOutcome, ToolError> {
222
- self.require_captured_identity("send_message")?;
223
- let _ = (task_id, requires_ack);
224
- if matches!(scope_override, Some(Scope::Workspace)) {
225
- return Err(self.rpc_scope_refused("send_message", None, Some("workspace")));
226
- }
227
- let normalized = crate::messaging::presentation::normalize_send_presentation(mailbox, presentation)
228
- .map_err(tool_runtime_error)?;
229
- let owner_team = self.canonical_owner_team_key()?;
230
- let directory = crate::direct_delivery::directory(&self.workspace, owner_team.as_ref().map(TeamKey::as_str))
231
- .map_err(tool_runtime_error)?;
232
- let sender = self.require_captured_identity("send_message")?.as_str();
233
- let targets = match to {
234
- MessageTarget::Single(target) if target == "*" => directory.agents().into_iter().filter(|agent| agent != sender).collect(),
235
- MessageTarget::Single(target) => vec![target.clone()],
236
- MessageTarget::Fanout(targets) => targets.clone(),
237
- MessageTarget::Broadcast => directory.agents().into_iter().filter(|agent| agent != sender).collect(),
238
- };
239
- if targets.is_empty() { return Err(tool_runtime_error("no recipients")); }
240
- let stored_only = normalized.request.sink != crate::messaging::presentation::PresentationSink::Leader;
241
- let mut destinations = Vec::new();
242
- for target in targets {
243
- if target != "leader" && !directory.agents().contains(&target) {
244
- return Err(ToolError::new(ToolErrorReason::PeerNotInScope,
245
- format!("recipient is not in the captured team: {target}"), "ScopeError"));
246
- }
247
- let endpoint = directory.endpoint(&target);
248
- if !stored_only && target != "leader" {
249
- endpoint.as_ref().map_err(tool_runtime_error)?;
250
- }
251
- if !destinations.iter().any(|(agent, _)| agent == &target) {
252
- destinations.push((target, endpoint));
253
- }
254
- }
255
- let mut results = Vec::new();
256
- for (agent, endpoint) in destinations {
257
- let mut message_id = None;
258
- if stored_only || agent == "leader" {
259
- let record = crate::inbox_store::record(sender, &agent, content, directory.team.as_deref(), "message");
260
- message_id = record.get("message_id").cloned();
261
- crate::inbox_store::append(&directory.workspace, &agent, &record).map_err(tool_runtime_error)?;
262
- }
263
- let mut value = if stored_only {
264
- serde_json::json!({"status": "stored", "recipient": agent, "mailbox": true})
265
- } else {
266
- let text = format!("Team Agent message from {sender}:\n\n{content}");
267
- match endpoint.and_then(|_| directory.send(&agent, &text)) {
268
- Ok(value) => value,
269
- Err(error) if message_id.is_some() => serde_json::json!({"status": "stored", "recipient": agent, "delivery_error": error}),
270
- Err(error) => return Err(tool_runtime_error(error)),
271
- }
272
- };
273
- if let Some(id) = message_id { value["message_id"] = id; }
274
- results.push(value);
275
- }
276
- let mut value = if results.len() == 1 { results.remove(0) } else {
277
- serde_json::json!({"status": "sent", "results": results})
278
- };
279
- value["ok"] = Value::Bool(true);
280
- if let Some(warning) = normalized.deprecation { value["warning"] = Value::String(warning); }
281
- Ok(SendOutcome::Direct(ToolOk { fields: object_fields(value) }))
282
- }
283
-
284
- pub(crate) fn refuse_scope_override(&self) -> ToolError {
285
- self.rpc_scope_refused("unknown", None, None)
286
- }
287
-
288
- pub(crate) fn validate_rpc_scope_args(
289
- &self,
290
- tool: &str,
291
- args: &Value,
292
- ) -> Result<(), ToolError> {
293
- if let Some(nested) = args.get("task").or_else(|| args.get("envelope")) {
294
- self.validate_rpc_scope_args(tool, nested)?;
295
- }
296
- let owner_team = self.canonical_owner_team_key()?;
297
- let requested_team = requested_team_arg(args);
298
- let requested_scope = requested_scope_arg(args);
299
- let workspace_override = args.get("workspace").is_some();
300
- let scope_widens = requested_scope
301
- .as_deref()
302
- .is_some_and(|scope| !scope.eq_ignore_ascii_case("team"));
303
- let team_widens = match (owner_team.as_ref(), requested_team.as_deref()) {
304
- (_, None) => false,
305
- (Some(owner), Some(requested)) => {
306
- // swallow batch 4 C6: an unreadable state cannot verify the requested
307
- // team — fail closed (structured transient refusal), never compare
308
- // against an empty substitute.
309
- let state = match load_runtime_state(&self.workspace) {
310
- Ok(state) => state,
311
- Err(error) => return Err(self.scope_unverifiable(&error.to_string())),
312
- };
313
- let requested_canonical =
314
- crate::state::projection::resolve_owner_team_id(&state, requested)
315
- .canonical_key()
316
- .unwrap_or(requested)
317
- .to_string();
318
- requested_canonical != owner.as_str()
319
- }
320
- (None, Some(_)) => true,
321
- };
322
- if workspace_override || scope_widens || team_widens {
323
- return Err(self.rpc_scope_refused(
324
- tool,
325
- requested_team.as_deref(),
326
- requested_scope
327
- .as_deref()
328
- .or_else(|| workspace_override.then_some("workspace")),
329
- ));
330
- }
331
- Ok(())
332
- }
333
-
334
- /// `report_result` (`tools.py:249-279`): build & normalize the result envelope
335
- /// (inferring `task_id`/`agent_id` with byte-stable `"manual"`/`"unknown"`
336
- /// fallbacks), then delegate to [`messaging::report_result`] and compact.
337
- #[allow(clippy::too_many_arguments)]
338
- pub fn report_result(
339
- &self,
340
- envelope: Option<&Value>,
341
- summary: Option<&str>,
342
- status: ResultStatus,
343
- changes: Option<&[Value]>,
344
- tests: Option<&[Value]>,
345
- risks: Option<&[Value]>,
346
- artifacts: Option<&[Value]>,
347
- next_actions: Option<&[Value]>,
348
- task_id: Option<&str>,
349
- agent_id: Option<&str>,
350
- ) -> ToolResult {
351
- let status = enum_value(status);
352
- self.report_result_with_presentation(
353
- envelope,
354
- summary,
355
- status.as_str(),
356
- changes,
357
- tests,
358
- risks,
359
- artifacts,
360
- next_actions,
361
- task_id,
362
- agent_id,
363
- None,
364
- )
365
- }
366
-
367
- #[allow(clippy::too_many_arguments)]
368
- pub fn report_result_with_presentation(
369
- &self,
370
- envelope: Option<&Value>,
371
- summary: Option<&str>,
372
- status: Option<&str>,
373
- changes: Option<&[Value]>,
374
- tests: Option<&[Value]>,
375
- risks: Option<&[Value]>,
376
- artifacts: Option<&[Value]>,
377
- next_actions: Option<&[Value]>,
378
- task_id: Option<&str>,
379
- agent_id: Option<&str>,
380
- presentation: Option<&Value>,
381
- ) -> ToolResult {
382
- // Validate before scope reads, envelope normalization, or result persistence.
383
- self.validate_report_identity_text(envelope, agent_id)?;
384
- if let Some(envelope) = envelope {
385
- self.validate_rpc_scope_args("report_result", envelope)?;
386
- }
387
- let mut base = envelope
388
- .cloned()
389
- .unwrap_or_else(|| Value::Object(serde_json::Map::new()));
390
- ensure_object(&mut base);
391
- if let Some(obj) = base.as_object_mut() {
392
- if !obj.contains_key("presentation") {
393
- if let Some(presentation) = presentation {
394
- obj.insert("presentation".to_string(), presentation.clone());
395
- }
396
- }
397
- if !obj.contains_key("summary") {
398
- obj.insert(
399
- "summary".to_string(),
400
- Value::String(
401
- summary.map_or_else(|| "completed".to_string(), ToString::to_string),
402
- ),
403
- );
404
- }
405
- if !obj.contains_key("status") {
406
- obj.insert(
407
- "status".to_string(),
408
- Value::String(status.unwrap_or("success").to_string()),
409
- );
410
- }
411
- if !obj.contains_key("task_id") {
412
- obj.insert("task_id".to_string(), Value::String(task_id.unwrap_or("manual").to_string()));
413
- }
414
- // The framework capture is authoritative even when a matching request
415
- // value was supplied; this also canonicalizes surrounding whitespace.
416
- let resolved = self
417
- .agent_id
418
- .as_ref()
419
- .map(|env_agent| env_agent.as_str().to_string())
420
- .unwrap_or_else(|| "unknown".to_string());
421
- obj.insert("agent_id".to_string(), Value::String(resolved));
422
- if !obj.contains_key("changes") {
423
- obj.insert(
424
- "changes".to_string(),
425
- Value::Array(changes.unwrap_or(&[]).to_vec()),
426
- );
427
- }
428
- if !obj.contains_key("tests") {
429
- obj.insert(
430
- "tests".to_string(),
431
- Value::Array(tests.unwrap_or(&[]).to_vec()),
432
- );
433
- }
434
- if !obj.contains_key("risks") {
435
- obj.insert(
436
- "risks".to_string(),
437
- Value::Array(risks.unwrap_or(&[]).to_vec()),
438
- );
439
- }
440
- if !obj.contains_key("artifacts") {
441
- obj.insert(
442
- "artifacts".to_string(),
443
- Value::Array(artifacts.unwrap_or(&[]).to_vec()),
444
- );
445
- }
446
- if !obj.contains_key("next_actions") {
447
- obj.insert(
448
- "next_actions".to_string(),
449
- Value::Array(next_actions.unwrap_or(&[]).to_vec()),
450
- );
451
- }
452
- }
453
- if let Err(error) = validate_test_evidence_schema(base.get("tests")) {
454
- return Err(ToolError::new(
455
- ToolErrorReason::InvalidToolArguments,
456
- error,
457
- "UnsupportedTestEvidenceSchema",
458
- ));
459
- }
460
- let normalized = normalize_report_envelope(&base);
461
- if let Some(error) = normalized.presentation_error.as_deref() {
462
- return Err(ToolError::new(
463
- ToolErrorReason::InvalidToolArguments,
464
- format!("invalid presentation: {error}"),
465
- "PresentationError",
466
- ));
467
- }
468
- let warnings = report_result_integrity_warnings(&base, &normalized);
469
- let mut env_value = base;
470
- if let Some(obj) = env_value.as_object_mut() {
471
- obj.entry("schema_version")
472
- .or_insert_with(|| Value::String("result_envelope_v1".to_string()));
473
- obj.insert(
474
- "presentation".to_string(),
475
- serde_json::to_value(&normalized.presentation).unwrap_or(Value::Null),
476
- );
477
- }
478
- if !warnings.is_empty() {
479
- if let Some(obj) = env_value.as_object_mut() {
480
- obj.insert("warnings".to_string(), Value::Array(warnings));
481
- }
482
- }
483
- let owner_team = self.canonical_owner_team_key()?;
484
- let team = owner_team.as_ref().map(TeamKey::as_str);
485
- let sender = self.require_captured_identity("report_result")?.as_str();
486
- let summary = env_value.get("summary").and_then(Value::as_str).unwrap_or("");
487
- let mut record = crate::inbox_store::record(sender, "leader", summary, team, "result");
488
- record["envelope"] = env_value.clone();
489
- crate::inbox_store::append(&self.workspace, "leader", &record).map_err(tool_runtime_error)?;
490
- let mut value = serde_json::json!({"ok": true, "status": "stored", "message_id": record["message_id"],
491
- "task_id": env_value["task_id"], "agent_id": sender});
492
- if normalized.presentation.sink == crate::messaging::presentation::PresentationSink::Leader {
493
- let delivery = crate::direct_delivery::directory(&self.workspace, team)
494
- .and_then(|directory| directory.send("leader", &format!("Team Agent result from {sender}:\n\n{summary}")));
495
- match delivery {
496
- Ok(_) => { value["status"] = Value::String("reported".into()); }
497
- Err(error) => { value["delivery_error"] = Value::String(error); }
498
- }
499
- }
500
- Ok(ToolOk { fields: object_fields(value) })
501
- }
502
-
503
- /// `get_team_status`: return the owner-team-scoped machine-readable status.
504
- pub fn get_team_status(&self) -> ToolResult {
505
- let owner_team = self.canonical_owner_team_key()?;
506
- super::lifecycle_tools::get_team_status(&self.workspace, owner_team.as_ref())
507
- }
508
-
509
- /// `get_visible_peers` (`tools.py:226-247`): C16 scope-filtered peer list — live
510
- /// agents within the spawn-time owner-team scope only; other teams and dead/stopped
511
- /// agents are filtered server-side and never named.
512
- pub fn get_visible_peers(&self) -> Result<VisiblePeers, ToolError> {
513
- let mut peers = Vec::new();
514
- if let Some(team) = self.canonical_owner_team_key_for_mcp()? {
515
- let state = load_runtime_state(&self.workspace).map_err(tool_runtime_error)?;
516
- if let Some(agents) = state
517
- .get("teams")
518
- .and_then(|v| v.get(team.as_str()))
519
- .and_then(|v| v.get("agents"))
520
- .and_then(Value::as_object)
521
- {
522
- for (agent_id, info) in agents {
523
- let status = info
524
- .as_object()
525
- .and_then(|obj| obj.get("status"))
526
- .and_then(Value::as_str)
527
- .unwrap_or("")
528
- .to_ascii_lowercase();
529
- if status == "dead" || status == "stopped" {
530
- continue;
531
- }
532
- peers.push(AgentId::new(agent_id.clone()));
533
- }
534
- }
535
- }
536
- peers.sort_by(|a, b| a.as_str().cmp(b.as_str()));
537
- Ok(VisiblePeers {
538
- peers,
539
- sender_team_id: self.canonical_owner_team_key_for_mcp()?,
540
- scope: Scope::Team,
541
- })
542
- }
543
-
544
- /// `_refuse_cross_team_peer` (`tools.py:185-213`): server-side C23 pre-refusal. A
545
- /// non-`*`/non-leader string target NOT in the visible-peer scope and not the
546
- /// sender itself, with `scope != workspace`, → `Some(ToolError{PeerNotInScope})`
547
- /// (also writes `mcp.send_message_refused`). `None` = allowed to proceed.
548
- pub fn refuse_cross_team_peer(
549
- &self,
550
- to: &MessageTarget,
551
- scope_override: Option<Scope>,
552
- ) -> Option<ToolError> {
553
- let owner_team = match self.canonical_owner_team_key() {
554
- Ok(team) => team,
555
- Err(error) => return Some(error),
556
- };
557
- if matches!(scope_override, Some(Scope::Workspace)) {
558
- return Some(self.rpc_scope_refused(
559
- "send_message",
560
- None,
561
- scope_override.and_then(scope_override_name),
562
- ));
563
- }
564
- if owner_team.is_none() {
565
- return None;
566
- }
567
- let MessageTarget::Single(target) = to else {
568
- return None;
569
- };
570
- if target.is_empty()
571
- || target == "*"
572
- || target == "leader"
573
- || target == "Leader"
574
- || self
575
- .agent_id
576
- .as_ref()
577
- .is_some_and(|id| id.as_str() == target)
578
- {
579
- return None;
580
- }
581
- // 0.5.45 naming-addressing (design §3.6, RED-2 MCP): compute
582
- // the visible peers ONCE and reuse for both exact-match check
583
- // AND scope-safe candidate ranking. Peers come from
584
- // `get_visible_peers()` (owner-team only) so sibling teams,
585
- // host registry, and workspace reverse scans cannot leak.
586
- let visible_peers: Vec<String> = self
587
- .get_visible_peers()
588
- .map(|visible| {
589
- visible
590
- .peers
591
- .iter()
592
- .map(|peer| peer.as_str().to_string())
593
- .collect()
594
- })
595
- .unwrap_or_default();
596
- if visible_peers.iter().any(|peer| peer == target) {
597
- return None;
598
- }
599
- let owner_team_key = owner_team
600
- .as_ref()
601
- .map(TeamKey::as_str)
602
- .unwrap_or("")
603
- .to_string();
604
- // Rank the typo against owner-scope peers.
605
- let ranked = {
606
- use crate::model::name_similarity::{rank, Candidate};
607
- let candidates: Vec<Candidate<String>> = visible_peers
608
- .iter()
609
- .map(|peer| Candidate {
610
- match_key: peer.clone(),
611
- stable_key: peer.clone(),
612
- payload: peer.clone(),
613
- })
614
- .collect();
615
- rank(target, &candidates)
616
- };
617
- let candidate_values: Vec<Value> = ranked
618
- .iter()
619
- .map(|peer| {
620
- serde_json::json!({
621
- "name": peer,
622
- "team_key": owner_team_key,
623
- "agent_id": peer,
624
- "advisory": true,
625
- })
626
- })
627
- .collect();
628
- let best = ranked.first().cloned();
629
- let hint = if let Some(best) = best.as_deref() {
630
- format!("the requested peer is not in your owner team; did you mean `{best}`?")
631
- } else {
632
- "the requested peer is not part of your team; worker-origin MCP cannot widen team scope.".to_string()
633
- };
634
- let _ = EventLog::new(&self.workspace).write(
635
- "mcp.send_message_refused",
636
- serde_json::json!({
637
- "reason": "peer_not_in_scope",
638
- "sender_team_id": owner_team_key,
639
- "scope": "team",
640
- "hint": hint,
641
- }),
642
- );
643
- let mut extra = serde_json::Map::new();
644
- extra.insert("status".to_string(), Value::String("refused".to_string()));
645
- extra.insert("hint".to_string(), Value::String(hint.clone()));
646
- // 0.5.45 naming-addressing (design §3.6, RED-2 MCP): additive
647
- // scope-safe suggestions inside the existing ToolError.extra
648
- // JSON envelope — no struct/schema change, no event log
649
- // widening. Advisory only: `isError=true` and
650
- // reason=peer_not_in_scope stay unchanged.
651
- extra.insert("requested_name".to_string(), Value::String(target.clone()));
652
- if let Some(best) = best {
653
- extra.insert("suggested_name".to_string(), Value::String(best));
654
- }
655
- extra.insert("candidates".to_string(), Value::Array(candidate_values));
656
- Some(ToolError {
657
- reason: ToolErrorReason::PeerNotInScope,
658
- exc_type: "PeerNotInScope".to_string(),
659
- message: format!("peer '{target}' is not in scope"),
660
- extra,
661
- })
662
- }
663
-
664
- fn canonical_owner_team_key(&self) -> Result<Option<TeamKey>, ToolError> {
665
- // Single worker MCP owner resolver: TEAM_AGENT_OWNER_TEAM_ID must resolve
666
- // through state::projection::resolve_owner_team_id to the runtime team key.
667
- // Unresolved/ambiguous owner scope emits mcp.scope_refused; never fallback
668
- // to active/top-level/sibling teams in a multi-team state.
669
- let Some(owner_team_id) = &self.owner_team_id else {
670
- // swallow batch 4 C5-C8 (MUST-16 fail-closed): the runtime state is the
671
- // scope truth source — when it cannot be read, the gate REFUSES with a
672
- // structured transient scope_unverifiable instead of silently treating
673
- // the workspace as legacy single-team (silent privilege widening).
674
- let state = load_runtime_state(&self.workspace)
675
- .map_err(|error| self.scope_unverifiable(&error.to_string()))?;
676
- if state
677
- .get("teams")
678
- .and_then(Value::as_object)
679
- .is_some_and(|teams| !teams.is_empty())
680
- {
681
- return Err(
682
- self.scope_refused("TEAM_AGENT_OWNER_TEAM_ID is required for multi-team MCP")
683
- );
684
- }
685
- return Ok(None);
686
- };
687
- let state = load_runtime_state(&self.workspace)
688
- .map_err(|error| self.scope_unverifiable(&error.to_string()))?;
689
- match canonicalize_owner_team_id(&state, owner_team_id.as_str()) {
690
- Some(team) => Ok(Some(TeamKey::new(team))),
691
- None => Err(self.scope_refused("owner team could not be resolved")),
692
- }
693
- }
694
-
695
- fn canonical_owner_team_key_for_mcp(&self) -> Result<Option<TeamKey>, ToolError> {
696
- let Some(owner_team_id) = &self.owner_team_id else {
697
- // swallow batch 4 C5-C8 (MUST-16 fail-closed): the runtime state is the
698
- // scope truth source — when it cannot be read, the gate REFUSES with a
699
- // structured transient scope_unverifiable instead of silently treating
700
- // the workspace as legacy single-team (silent privilege widening).
701
- let state = load_runtime_state(&self.workspace)
702
- .map_err(|error| self.scope_unverifiable(&error.to_string()))?;
703
- if state
704
- .get("teams")
705
- .and_then(Value::as_object)
706
- .is_some_and(|teams| !teams.is_empty())
707
- {
708
- return Err(
709
- self.scope_refused("TEAM_AGENT_OWNER_TEAM_ID is required for multi-team MCP")
710
- );
711
- }
712
- return Ok(None);
713
- };
714
- let state = load_runtime_state(&self.workspace)
715
- .map_err(|error| self.scope_unverifiable(&error.to_string()))?;
716
- match canonicalize_owner_team_id(&state, owner_team_id.as_str()) {
717
- Some(team) => Ok(Some(TeamKey::new(team))),
718
- None => Err(self.scope_refused("owner team could not be resolved")),
719
- }
720
- }
721
-
722
- /// swallow batch 4 C5/C6/N38: the structured FAIL-CLOSED refusal for "the scope
723
- /// could not be verified" (state read failed). Transient by design — the same call
724
- /// passes once the state is readable again; the caller's self-reported scope is
725
- /// never trusted as a fallback (MUST-16 ceiling).
726
- fn scope_unverifiable(&self, io_error: &str) -> ToolError {
727
- let _ = EventLog::new(&self.workspace).write(
728
- "mcp.scope_state_read_failed",
729
- serde_json::json!({
730
- "reason": "scope_unverifiable",
731
- "requested_owner_team_id": self.owner_team_id.as_ref().map(TeamKey::as_str),
732
- "error": io_error,
733
- }),
734
- );
735
- let mut extra = serde_json::Map::new();
736
- extra.insert("status".to_string(), Value::String("refused".to_string()));
737
- extra.insert(
738
- "kind".to_string(),
739
- Value::String("scope_unverifiable".to_string()),
740
- );
741
- extra.insert(
742
- "next_action".to_string(),
743
- Value::String("retry shortly or check the runtime state path".to_string()),
744
- );
745
- ToolError {
746
- reason: ToolErrorReason::McpScopeRefused,
747
- exc_type: "McpScopeUnverifiable".to_string(),
748
- message: format!("scope_unverifiable: state read failed: {io_error}"),
749
- extra,
750
- }
751
- }
752
-
753
- fn scope_refused(&self, message: &str) -> ToolError {
754
- let canonical_owner_team_id = self.canonical_owner_team_key_for_event();
755
- let _ = EventLog::new(&self.workspace).write(
756
- "mcp.scope_refused",
757
- serde_json::json!({
758
- "reason": "scope_refused",
759
- "requested_owner_team_id": self.owner_team_id.as_ref().map(TeamKey::as_str),
760
- "owner_team_id": canonical_owner_team_id,
761
- "canonical_owner_team_id": canonical_owner_team_id,
762
- "message": message,
763
- }),
764
- );
765
- let mut extra = serde_json::Map::new();
766
- extra.insert("status".to_string(), Value::String("refused".to_string()));
767
- extra.insert("hint".to_string(), Value::String(message.to_string()));
768
- ToolError {
769
- reason: ToolErrorReason::McpScopeRefused,
770
- exc_type: "McpScopeRefused".to_string(),
771
- message: "mcp.scope_refused".to_string(),
772
- extra,
773
- }
774
- }
775
-
776
- fn rpc_scope_refused(
777
- &self,
778
- tool: &str,
779
- requested_team: Option<&str>,
780
- requested_scope: Option<&str>,
781
- ) -> ToolError {
782
- let owner_team_id = self.canonical_owner_team_key_for_event();
783
- let agent_id = self
784
- .agent_id
785
- .as_ref()
786
- .map(AgentId::as_str)
787
- .unwrap_or("unknown");
788
- let _ = EventLog::new(&self.workspace).write(
789
- "mcp.scope_refused",
790
- serde_json::json!({
791
- "reason": "rpc_scope_override",
792
- "tool": tool,
793
- "agent_id": agent_id,
794
- "owner_team_id": owner_team_id,
795
- "requested_team": requested_team,
796
- "requested_scope": requested_scope,
797
- }),
798
- );
799
- let mut extra = serde_json::Map::new();
800
- extra.insert("status".to_string(), Value::String("refused".to_string()));
801
- extra.insert("tool".to_string(), Value::String(tool.to_string()));
802
- extra.insert("agent_id".to_string(), Value::String(agent_id.to_string()));
803
- extra.insert(
804
- "owner_team_id".to_string(),
805
- owner_team_id.map_or(Value::Null, Value::String),
806
- );
807
- extra.insert(
808
- "requested_team".to_string(),
809
- requested_team.map_or(Value::Null, |team| Value::String(team.to_string())),
810
- );
811
- extra.insert(
812
- "requested_scope".to_string(),
813
- requested_scope.map_or(Value::Null, |scope| Value::String(scope.to_string())),
814
- );
815
- ToolError {
816
- reason: ToolErrorReason::McpScopeRefused,
817
- exc_type: "McpScopeRefused".to_string(),
818
- message: "mcp.scope_refused".to_string(),
819
- extra,
820
- }
821
- }
822
-
823
- fn canonical_owner_team_key_for_event(&self) -> Option<String> {
824
- let owner_team_id = self.owner_team_id.as_ref()?;
825
- let state = load_runtime_state(&self.workspace).ok()?;
826
- canonicalize_owner_team_id(&state, owner_team_id.as_str())
827
- }
828
- }
829
-
830
- fn canonicalize_owner_team_id(state: &Value, owner_team_id: &str) -> Option<String> {
831
- crate::state::projection::resolve_owner_team_id(state, owner_team_id)
832
- .canonical_key()
833
- .map(ToString::to_string)
834
- }
835
-
836
- fn requested_team_arg(args: &Value) -> Option<String> {
837
- [
838
- "team",
839
- "team_id",
840
- "owner_team_id",
841
- "owner_team",
842
- "target_team",
843
- ]
844
- .iter()
845
- .find_map(|key| {
846
- args.get(*key)
847
- .and_then(Value::as_str)
848
- .filter(|s| !s.is_empty())
849
- })
850
- .map(ToString::to_string)
851
- }
852
-
853
- fn requested_scope_arg(args: &Value) -> Option<String> {
854
- args.get("scope")
855
- .and_then(Value::as_str)
856
- .filter(|s| !s.is_empty())
857
- .map(ToString::to_string)
858
- .or_else(|| args.get("workspace").map(|_| "workspace".to_string()))
859
- }
860
-
861
- fn push_report_warning(obj: &mut serde_json::Map<String, Value>, warning: Value) {
862
- let Some(code) = warning.get("code").and_then(Value::as_str) else {
863
- return;
864
- };
865
- let Some(field) = warning.get("field").and_then(Value::as_str) else {
866
- return;
867
- };
868
- match obj.get_mut("warnings") {
869
- Some(Value::Array(warnings)) => {
870
- let exists = warnings.iter().any(|existing| {
871
- existing.get("code").and_then(Value::as_str) == Some(code)
872
- && existing.get("field").and_then(Value::as_str) == Some(field)
873
- });
874
- if !exists {
875
- warnings.push(warning);
876
- }
877
- }
878
- _ => {
879
- obj.insert("warnings".to_string(), Value::Array(vec![warning]));
880
- }
881
- }
882
- }
883
-
884
- fn scope_override_name(scope: Scope) -> Option<&'static str> {
885
- match scope {
886
- Scope::Team => Some("team"),
887
- Scope::Workspace => Some("workspace"),
888
- }
889
- }