@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,1015 +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::state::persist::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
- // A worker without a spawn-time identity cannot safely emit a message.
223
- self.require_captured_identity("send_message")?;
224
- let normalized =
225
- crate::messaging::presentation::normalize_send_presentation(mailbox, presentation)
226
- .map_err(|error| {
227
- ToolError::new(
228
- ToolErrorReason::InvalidToolArguments,
229
- format!("invalid send routing: {error}"),
230
- "PresentationError",
231
- )
232
- })?;
233
- let presentation = normalized.request;
234
- let deprecation = normalized.deprecation;
235
- let canonical_owner_team = self.canonical_owner_team_key()?;
236
- if matches!(scope_override, Some(Scope::Workspace)) {
237
- return Err(self.rpc_scope_refused(
238
- "send_message",
239
- None,
240
- scope_override.and_then(scope_override_name),
241
- ));
242
- }
243
- if let Some(err) = self.refuse_cross_team_peer(to, None) {
244
- return Err(err);
245
- }
246
- let sender = self.agent_id.clone().ok_or_else(|| {
247
- ToolError::new(
248
- ToolErrorReason::McpScopeRefused,
249
- "send_message requires framework-injected TEAM_AGENT_ID",
250
- "IdentityError",
251
- )
252
- })?;
253
- let sender = TrustedSender::from_runtime_identity(sender);
254
- let ack = requires_ack.unwrap_or_else(|| requires_ack_for_target(to));
255
- // C14/C15/C17 scope audit (#230 I-2/I-6 contract): emit mcp.scope_resolved
256
- // for every worker-origin send before any routing/delivery — the funnel
257
- // assertions grep this event to verify the worker call was scoped under the
258
- // spawn-time owner-team env, not a back-inferred default.
259
- EventLog::new(&self.workspace)
260
- .write(
261
- "mcp.scope_resolved",
262
- serde_json::json!({
263
- "tool": "send_message",
264
- "sender": sender.as_str(),
265
- "owner_team_id": canonical_owner_team.as_ref().map(TeamKey::as_str),
266
- "to": match to {
267
- MessageTarget::Single(t) => serde_json::Value::String(t.clone()),
268
- MessageTarget::Broadcast => serde_json::Value::String("*".to_string()),
269
- MessageTarget::Fanout(list) => serde_json::Value::Array(
270
- list.iter().map(|s| serde_json::Value::String(s.clone())).collect(),
271
- ),
272
- },
273
- "requires_ack": ack,
274
- }),
275
- )
276
- .map_err(tool_runtime_error)?;
277
- let opts = SendOptions {
278
- origin: crate::messaging::SendOrigin::Mcp,
279
- task_id: task_id.map(TaskId::new),
280
- route_task_id: true,
281
- sender,
282
- requires_ack: ack,
283
- team: canonical_owner_team,
284
- presentation,
285
- ..SendOptions::default()
286
- };
287
- if is_worker_recipient(to) {
288
- let out = messaging::send_message(&self.workspace, to, content, &opts)
289
- .map_err(tool_runtime_error)?;
290
- if matches!(out.status, DeliveryStatus::StoredOnly) {
291
- let value = delivery_outcome_value(&out);
292
- let mut ok = compact_tool_result(&value)?;
293
- if let Some(verification) = out.verification.as_deref() {
294
- ok.fields.insert(
295
- "verification".to_string(),
296
- Value::String(verification.to_string()),
297
- );
298
- }
299
- if let Some(deprecation) = deprecation {
300
- ok.fields
301
- .insert("warning".to_string(), Value::String(deprecation));
302
- }
303
- return Ok(SendOutcome::Direct(ok));
304
- }
305
- // tools.py:175-181 — accepted+poll_via ONLY for a REAL message_id; any other
306
- // outcome falls back to the compacted direct result. Never invent an
307
- // `mcp_<timestamp>` id: it does not exist in the store and makes the
308
- // advertised `team-agent inbox <id>` poll a dead end.
309
- let message_id = match out.message_id {
310
- Some(message_id) if out.ok => message_id,
311
- _ => {
312
- let value = delivery_outcome_value(&out);
313
- let ok = compact_tool_result(&value)?;
314
- return Ok(SendOutcome::Direct(ok));
315
- }
316
- };
317
- return Ok(SendOutcome::WorkerAccepted {
318
- poll_via: format!("team-agent inbox {message_id}"),
319
- message_id,
320
- warning: deprecation,
321
- });
322
- }
323
- let out = messaging::send_message(&self.workspace, to, content, &opts)
324
- .map_err(tool_runtime_error)?;
325
- let value = delivery_outcome_value(&out);
326
- let mut ok = compact_tool_result(&value)?;
327
- if matches!(out.status, DeliveryStatus::StoredOnly) {
328
- if let Some(verification) = out.verification.as_deref() {
329
- ok.fields.insert(
330
- "verification".to_string(),
331
- Value::String(verification.to_string()),
332
- );
333
- }
334
- }
335
- if let Some(deprecation) = deprecation {
336
- ok.fields
337
- .insert("warning".to_string(), Value::String(deprecation));
338
- }
339
- Ok(SendOutcome::Direct(ok))
340
- }
341
-
342
- pub(crate) fn refuse_scope_override(&self) -> ToolError {
343
- self.rpc_scope_refused("unknown", None, None)
344
- }
345
-
346
- pub(crate) fn validate_rpc_scope_args(
347
- &self,
348
- tool: &str,
349
- args: &Value,
350
- ) -> Result<(), ToolError> {
351
- if let Some(nested) = args.get("task").or_else(|| args.get("envelope")) {
352
- self.validate_rpc_scope_args(tool, nested)?;
353
- }
354
- let owner_team = self.canonical_owner_team_key()?;
355
- let requested_team = requested_team_arg(args);
356
- let requested_scope = requested_scope_arg(args);
357
- let workspace_override = args.get("workspace").is_some();
358
- let scope_widens = requested_scope
359
- .as_deref()
360
- .is_some_and(|scope| !scope.eq_ignore_ascii_case("team"));
361
- let team_widens = match (owner_team.as_ref(), requested_team.as_deref()) {
362
- (_, None) => false,
363
- (Some(owner), Some(requested)) => {
364
- // swallow batch 4 C6: an unreadable state cannot verify the requested
365
- // team — fail closed (structured transient refusal), never compare
366
- // against an empty substitute.
367
- let state = match load_runtime_state(&self.workspace) {
368
- Ok(state) => state,
369
- Err(error) => return Err(self.scope_unverifiable(&error.to_string())),
370
- };
371
- let requested_canonical =
372
- crate::state::projection::resolve_owner_team_id(&state, requested)
373
- .canonical_key()
374
- .unwrap_or(requested)
375
- .to_string();
376
- requested_canonical != owner.as_str()
377
- }
378
- (None, Some(_)) => true,
379
- };
380
- if workspace_override || scope_widens || team_widens {
381
- return Err(self.rpc_scope_refused(
382
- tool,
383
- requested_team.as_deref(),
384
- requested_scope
385
- .as_deref()
386
- .or_else(|| workspace_override.then_some("workspace")),
387
- ));
388
- }
389
- Ok(())
390
- }
391
-
392
- /// `report_result` (`tools.py:249-279`): build & normalize the result envelope
393
- /// (inferring `task_id`/`agent_id` with byte-stable `"manual"`/`"unknown"`
394
- /// fallbacks), then delegate to [`messaging::report_result`] and compact.
395
- #[allow(clippy::too_many_arguments)]
396
- pub fn report_result(
397
- &self,
398
- envelope: Option<&Value>,
399
- summary: Option<&str>,
400
- status: ResultStatus,
401
- changes: Option<&[Value]>,
402
- tests: Option<&[Value]>,
403
- risks: Option<&[Value]>,
404
- artifacts: Option<&[Value]>,
405
- next_actions: Option<&[Value]>,
406
- task_id: Option<&str>,
407
- agent_id: Option<&str>,
408
- ) -> ToolResult {
409
- let status = enum_value(status);
410
- self.report_result_with_presentation(
411
- envelope,
412
- summary,
413
- status.as_str(),
414
- changes,
415
- tests,
416
- risks,
417
- artifacts,
418
- next_actions,
419
- task_id,
420
- agent_id,
421
- None,
422
- )
423
- }
424
-
425
- #[allow(clippy::too_many_arguments)]
426
- pub fn report_result_with_presentation(
427
- &self,
428
- envelope: Option<&Value>,
429
- summary: Option<&str>,
430
- status: Option<&str>,
431
- changes: Option<&[Value]>,
432
- tests: Option<&[Value]>,
433
- risks: Option<&[Value]>,
434
- artifacts: Option<&[Value]>,
435
- next_actions: Option<&[Value]>,
436
- task_id: Option<&str>,
437
- agent_id: Option<&str>,
438
- presentation: Option<&Value>,
439
- ) -> ToolResult {
440
- // Validate before scope reads, envelope normalization, or result persistence.
441
- self.validate_report_identity_text(envelope, agent_id)?;
442
- if let Some(envelope) = envelope {
443
- self.validate_rpc_scope_args("report_result", envelope)?;
444
- }
445
- let mut base = envelope
446
- .cloned()
447
- .unwrap_or_else(|| Value::Object(serde_json::Map::new()));
448
- ensure_object(&mut base);
449
- if let Some(obj) = base.as_object_mut() {
450
- if !obj.contains_key("presentation") {
451
- if let Some(presentation) = presentation {
452
- obj.insert("presentation".to_string(), presentation.clone());
453
- }
454
- }
455
- if !obj.contains_key("summary") {
456
- obj.insert(
457
- "summary".to_string(),
458
- Value::String(
459
- summary.map_or_else(|| "completed".to_string(), ToString::to_string),
460
- ),
461
- );
462
- }
463
- if !obj.contains_key("status") {
464
- obj.insert(
465
- "status".to_string(),
466
- Value::String(status.unwrap_or("success").to_string()),
467
- );
468
- }
469
- if !obj.contains_key("task_id") {
470
- // Blocker-1 (prerelease 0.4.0): scoped-team task inference +
471
- // message-scoped fallback, before defaulting to "manual".
472
- // 1. explicit arg
473
- // 2. current physical direct turn for this agent
474
- // 3. bounded latest reportable direct message with no result yet
475
- // 4. latest nonterminal assigned task in teams.<owner>.tasks,
476
- // only when no newer failed/refused/blocked direct turn blocks fallback
477
- // 5. "manual" — truly uncorrelated; collect still rejects
478
- let owner_team_id_str = self.owner_team_id.as_ref().map(|t| t.as_str().to_string());
479
- let mut attributed_message_id = None;
480
- let mut attribution_scope = None;
481
- let mut task_id_source = None;
482
- let resolved = if let Some(task_id) = task_id {
483
- task_id.to_string()
484
- } else if let Some(agent) = self.agent_id.as_ref() {
485
- if let Some(message_id) = current_reportable_message_for(
486
- &self.workspace,
487
- agent.as_str(),
488
- owner_team_id_str.as_deref(),
489
- ) {
490
- attributed_message_id = Some(message_id.clone());
491
- attribution_scope = Some("message");
492
- task_id_source = Some("current_turn_message");
493
- message_id
494
- } else {
495
- match direct_message_attribution_for(
496
- &self.workspace,
497
- agent.as_str(),
498
- owner_team_id_str.as_deref(),
499
- ) {
500
- DirectMessageAttribution::Reportable(message_id) => {
501
- attributed_message_id = Some(message_id.clone());
502
- attribution_scope = Some("message");
503
- task_id_source = Some("direct_message");
504
- message_id
505
- }
506
- DirectMessageAttribution::BlockedByNewer {
507
- message_id,
508
- status,
509
- error,
510
- } => {
511
- push_report_warning(
512
- obj,
513
- serde_json::json!({
514
- "code": "result_attribution_blocked_by_newer_direct_message",
515
- "field": "task_id",
516
- "severity": "warning",
517
- "advisory": true,
518
- "message_id": message_id,
519
- "message_status": status,
520
- "message_error": error,
521
- }),
522
- );
523
- "manual".to_string()
524
- }
525
- DirectMessageAttribution::None => latest_task_for_assignee(
526
- &self.workspace,
527
- agent.as_str(),
528
- owner_team_id_str.as_deref(),
529
- )
530
- .unwrap_or_else(|| "manual".to_string()),
531
- }
532
- }
533
- } else {
534
- "manual".to_string()
535
- };
536
- obj.insert("task_id".to_string(), Value::String(resolved));
537
- if let Some(message_id) = attributed_message_id {
538
- obj.entry("attributed_message_id")
539
- .or_insert(Value::String(message_id));
540
- }
541
- if let Some(scope) = attribution_scope {
542
- obj.entry("attribution_scope")
543
- .or_insert(Value::String(scope.to_string()));
544
- }
545
- if let Some(source) = task_id_source {
546
- obj.entry("task_id_source")
547
- .or_insert(Value::String(source.to_string()));
548
- }
549
- }
550
- // The framework capture is authoritative even when a matching request
551
- // value was supplied; this also canonicalizes surrounding whitespace.
552
- let resolved = self
553
- .agent_id
554
- .as_ref()
555
- .map(|env_agent| env_agent.as_str().to_string())
556
- .unwrap_or_else(|| "unknown".to_string());
557
- obj.insert("agent_id".to_string(), Value::String(resolved));
558
- if !obj.contains_key("changes") {
559
- obj.insert(
560
- "changes".to_string(),
561
- Value::Array(changes.unwrap_or(&[]).to_vec()),
562
- );
563
- }
564
- if !obj.contains_key("tests") {
565
- obj.insert(
566
- "tests".to_string(),
567
- Value::Array(tests.unwrap_or(&[]).to_vec()),
568
- );
569
- }
570
- if !obj.contains_key("risks") {
571
- obj.insert(
572
- "risks".to_string(),
573
- Value::Array(risks.unwrap_or(&[]).to_vec()),
574
- );
575
- }
576
- if !obj.contains_key("artifacts") {
577
- obj.insert(
578
- "artifacts".to_string(),
579
- Value::Array(artifacts.unwrap_or(&[]).to_vec()),
580
- );
581
- }
582
- if !obj.contains_key("next_actions") {
583
- obj.insert(
584
- "next_actions".to_string(),
585
- Value::Array(next_actions.unwrap_or(&[]).to_vec()),
586
- );
587
- }
588
- }
589
- if let Err(error) = validate_test_evidence_schema(base.get("tests")) {
590
- return Err(ToolError::new(
591
- ToolErrorReason::InvalidToolArguments,
592
- error,
593
- "UnsupportedTestEvidenceSchema",
594
- ));
595
- }
596
- let normalized = normalize_report_envelope(&base);
597
- if let Some(error) = normalized.presentation_error.as_deref() {
598
- return Err(ToolError::new(
599
- ToolErrorReason::InvalidToolArguments,
600
- format!("invalid presentation: {error}"),
601
- "PresentationError",
602
- ));
603
- }
604
- let warnings = report_result_integrity_warnings(&base, &normalized);
605
- let mut env_value = base;
606
- if let Some(obj) = env_value.as_object_mut() {
607
- obj.entry("schema_version")
608
- .or_insert_with(|| Value::String("result_envelope_v1".to_string()));
609
- obj.insert(
610
- "presentation".to_string(),
611
- serde_json::to_value(&normalized.presentation).unwrap_or(Value::Null),
612
- );
613
- }
614
- if !warnings.is_empty() {
615
- if let Some(obj) = env_value.as_object_mut() {
616
- obj.insert("warnings".to_string(), Value::Array(warnings));
617
- }
618
- }
619
- let owner_team = self.canonical_owner_team_key()?;
620
- messaging::report_result_for_owner_team(
621
- &self.workspace,
622
- &env_value,
623
- owner_team.as_ref().map(TeamKey::as_str),
624
- )
625
- .map_err(tool_runtime_error)
626
- .and_then(|value| compact_tool_result(&value))
627
- }
628
-
629
- /// `get_team_status`: return the owner-team-scoped machine-readable status.
630
- pub fn get_team_status(&self) -> ToolResult {
631
- let owner_team = self.canonical_owner_team_key()?;
632
- super::lifecycle_tools::get_team_status(&self.workspace, owner_team.as_ref())
633
- }
634
-
635
- /// `get_visible_peers` (`tools.py:226-247`): C16 scope-filtered peer list — live
636
- /// agents within the spawn-time owner-team scope only; other teams and dead/stopped
637
- /// agents are filtered server-side and never named.
638
- pub fn get_visible_peers(&self) -> Result<VisiblePeers, ToolError> {
639
- let mut peers = Vec::new();
640
- if let Some(team) = self.canonical_owner_team_key_for_mcp()? {
641
- let state = load_runtime_state(&self.workspace).map_err(tool_runtime_error)?;
642
- if let Some(agents) = state
643
- .get("teams")
644
- .and_then(|v| v.get(team.as_str()))
645
- .and_then(|v| v.get("agents"))
646
- .and_then(Value::as_object)
647
- {
648
- for (agent_id, info) in agents {
649
- let status = info
650
- .as_object()
651
- .and_then(|obj| obj.get("status"))
652
- .and_then(Value::as_str)
653
- .unwrap_or("")
654
- .to_ascii_lowercase();
655
- if status == "dead" || status == "stopped" {
656
- continue;
657
- }
658
- peers.push(AgentId::new(agent_id.clone()));
659
- }
660
- }
661
- }
662
- peers.sort_by(|a, b| a.as_str().cmp(b.as_str()));
663
- Ok(VisiblePeers {
664
- peers,
665
- sender_team_id: self.canonical_owner_team_key_for_mcp()?,
666
- scope: Scope::Team,
667
- })
668
- }
669
-
670
- /// `_refuse_cross_team_peer` (`tools.py:185-213`): server-side C23 pre-refusal. A
671
- /// non-`*`/non-leader string target NOT in the visible-peer scope and not the
672
- /// sender itself, with `scope != workspace`, → `Some(ToolError{PeerNotInScope})`
673
- /// (also writes `mcp.send_message_refused`). `None` = allowed to proceed.
674
- pub fn refuse_cross_team_peer(
675
- &self,
676
- to: &MessageTarget,
677
- scope_override: Option<Scope>,
678
- ) -> Option<ToolError> {
679
- let owner_team = match self.canonical_owner_team_key() {
680
- Ok(team) => team,
681
- Err(error) => return Some(error),
682
- };
683
- if matches!(scope_override, Some(Scope::Workspace)) {
684
- return Some(self.rpc_scope_refused(
685
- "send_message",
686
- None,
687
- scope_override.and_then(scope_override_name),
688
- ));
689
- }
690
- if owner_team.is_none() {
691
- return None;
692
- }
693
- let MessageTarget::Single(target) = to else {
694
- return None;
695
- };
696
- if target.is_empty()
697
- || target == "*"
698
- || target == "leader"
699
- || target == "Leader"
700
- || self
701
- .agent_id
702
- .as_ref()
703
- .is_some_and(|id| id.as_str() == target)
704
- {
705
- return None;
706
- }
707
- // 0.5.45 naming-addressing (design §3.6, RED-2 MCP): compute
708
- // the visible peers ONCE and reuse for both exact-match check
709
- // AND scope-safe candidate ranking. Peers come from
710
- // `get_visible_peers()` (owner-team only) so sibling teams,
711
- // host registry, and workspace reverse scans cannot leak.
712
- let visible_peers: Vec<String> = self
713
- .get_visible_peers()
714
- .map(|visible| {
715
- visible
716
- .peers
717
- .iter()
718
- .map(|peer| peer.as_str().to_string())
719
- .collect()
720
- })
721
- .unwrap_or_default();
722
- if visible_peers.iter().any(|peer| peer == target) {
723
- return None;
724
- }
725
- let owner_team_key = owner_team
726
- .as_ref()
727
- .map(TeamKey::as_str)
728
- .unwrap_or("")
729
- .to_string();
730
- // Rank the typo against owner-scope peers.
731
- let ranked = {
732
- use crate::model::name_similarity::{rank, Candidate};
733
- let candidates: Vec<Candidate<String>> = visible_peers
734
- .iter()
735
- .map(|peer| Candidate {
736
- match_key: peer.clone(),
737
- stable_key: peer.clone(),
738
- payload: peer.clone(),
739
- })
740
- .collect();
741
- rank(target, &candidates)
742
- };
743
- let candidate_values: Vec<Value> = ranked
744
- .iter()
745
- .map(|peer| {
746
- serde_json::json!({
747
- "name": peer,
748
- "team_key": owner_team_key,
749
- "agent_id": peer,
750
- "advisory": true,
751
- })
752
- })
753
- .collect();
754
- let best = ranked.first().cloned();
755
- let hint = if let Some(best) = best.as_deref() {
756
- format!("the requested peer is not in your owner team; did you mean `{best}`?")
757
- } else {
758
- "the requested peer is not part of your team; worker-origin MCP cannot widen team scope.".to_string()
759
- };
760
- let _ = EventLog::new(&self.workspace).write(
761
- "mcp.send_message_refused",
762
- serde_json::json!({
763
- "reason": "peer_not_in_scope",
764
- "sender_team_id": owner_team_key,
765
- "scope": "team",
766
- "hint": hint,
767
- }),
768
- );
769
- let mut extra = serde_json::Map::new();
770
- extra.insert("status".to_string(), Value::String("refused".to_string()));
771
- extra.insert("hint".to_string(), Value::String(hint.clone()));
772
- // 0.5.45 naming-addressing (design §3.6, RED-2 MCP): additive
773
- // scope-safe suggestions inside the existing ToolError.extra
774
- // JSON envelope — no struct/schema change, no event log
775
- // widening. Advisory only: `isError=true` and
776
- // reason=peer_not_in_scope stay unchanged.
777
- extra.insert("requested_name".to_string(), Value::String(target.clone()));
778
- if let Some(best) = best {
779
- extra.insert("suggested_name".to_string(), Value::String(best));
780
- }
781
- extra.insert("candidates".to_string(), Value::Array(candidate_values));
782
- Some(ToolError {
783
- reason: ToolErrorReason::PeerNotInScope,
784
- exc_type: "PeerNotInScope".to_string(),
785
- message: format!("peer '{target}' is not in scope"),
786
- extra,
787
- })
788
- }
789
-
790
- fn canonical_owner_team_key(&self) -> Result<Option<TeamKey>, ToolError> {
791
- // Single worker MCP owner resolver: TEAM_AGENT_OWNER_TEAM_ID must resolve
792
- // through state::projection::resolve_owner_team_id to the runtime team key.
793
- // Unresolved/ambiguous owner scope emits mcp.scope_refused; never fallback
794
- // to active/top-level/sibling teams in a multi-team state.
795
- let Some(owner_team_id) = &self.owner_team_id else {
796
- // swallow batch 4 C5-C8 (MUST-16 fail-closed): the runtime state is the
797
- // scope truth source — when it cannot be read, the gate REFUSES with a
798
- // structured transient scope_unverifiable instead of silently treating
799
- // the workspace as legacy single-team (silent privilege widening).
800
- let state = load_runtime_state(&self.workspace)
801
- .map_err(|error| self.scope_unverifiable(&error.to_string()))?;
802
- if state
803
- .get("teams")
804
- .and_then(Value::as_object)
805
- .is_some_and(|teams| !teams.is_empty())
806
- {
807
- return Err(
808
- self.scope_refused("TEAM_AGENT_OWNER_TEAM_ID is required for multi-team MCP")
809
- );
810
- }
811
- return Ok(None);
812
- };
813
- let state = load_runtime_state(&self.workspace)
814
- .map_err(|error| self.scope_unverifiable(&error.to_string()))?;
815
- match canonicalize_owner_team_id(&state, owner_team_id.as_str()) {
816
- Some(team) => Ok(Some(TeamKey::new(team))),
817
- None => Err(self.scope_refused("owner team could not be resolved")),
818
- }
819
- }
820
-
821
- fn canonical_owner_team_key_for_mcp(&self) -> Result<Option<TeamKey>, ToolError> {
822
- let Some(owner_team_id) = &self.owner_team_id else {
823
- // swallow batch 4 C5-C8 (MUST-16 fail-closed): the runtime state is the
824
- // scope truth source — when it cannot be read, the gate REFUSES with a
825
- // structured transient scope_unverifiable instead of silently treating
826
- // the workspace as legacy single-team (silent privilege widening).
827
- let state = load_runtime_state(&self.workspace)
828
- .map_err(|error| self.scope_unverifiable(&error.to_string()))?;
829
- if state
830
- .get("teams")
831
- .and_then(Value::as_object)
832
- .is_some_and(|teams| !teams.is_empty())
833
- {
834
- return Err(
835
- self.scope_refused("TEAM_AGENT_OWNER_TEAM_ID is required for multi-team MCP")
836
- );
837
- }
838
- return Ok(None);
839
- };
840
- let state = load_runtime_state(&self.workspace)
841
- .map_err(|error| self.scope_unverifiable(&error.to_string()))?;
842
- match canonicalize_owner_team_id(&state, owner_team_id.as_str()) {
843
- Some(team) => Ok(Some(TeamKey::new(team))),
844
- None => Err(self.scope_refused("owner team could not be resolved")),
845
- }
846
- }
847
-
848
- /// swallow batch 4 C5/C6/N38: the structured FAIL-CLOSED refusal for "the scope
849
- /// could not be verified" (state read failed). Transient by design — the same call
850
- /// passes once the state is readable again; the caller's self-reported scope is
851
- /// never trusted as a fallback (MUST-16 ceiling).
852
- fn scope_unverifiable(&self, io_error: &str) -> ToolError {
853
- let _ = EventLog::new(&self.workspace).write(
854
- "mcp.scope_state_read_failed",
855
- serde_json::json!({
856
- "reason": "scope_unverifiable",
857
- "requested_owner_team_id": self.owner_team_id.as_ref().map(TeamKey::as_str),
858
- "error": io_error,
859
- }),
860
- );
861
- let mut extra = serde_json::Map::new();
862
- extra.insert("status".to_string(), Value::String("refused".to_string()));
863
- extra.insert(
864
- "kind".to_string(),
865
- Value::String("scope_unverifiable".to_string()),
866
- );
867
- extra.insert(
868
- "next_action".to_string(),
869
- Value::String("retry shortly or check the runtime state path".to_string()),
870
- );
871
- ToolError {
872
- reason: ToolErrorReason::McpScopeRefused,
873
- exc_type: "McpScopeUnverifiable".to_string(),
874
- message: format!("scope_unverifiable: state read failed: {io_error}"),
875
- extra,
876
- }
877
- }
878
-
879
- fn scope_refused(&self, message: &str) -> ToolError {
880
- let canonical_owner_team_id = self.canonical_owner_team_key_for_event();
881
- let _ = EventLog::new(&self.workspace).write(
882
- "mcp.scope_refused",
883
- serde_json::json!({
884
- "reason": "scope_refused",
885
- "requested_owner_team_id": self.owner_team_id.as_ref().map(TeamKey::as_str),
886
- "owner_team_id": canonical_owner_team_id,
887
- "canonical_owner_team_id": canonical_owner_team_id,
888
- "message": message,
889
- }),
890
- );
891
- let mut extra = serde_json::Map::new();
892
- extra.insert("status".to_string(), Value::String("refused".to_string()));
893
- extra.insert("hint".to_string(), Value::String(message.to_string()));
894
- ToolError {
895
- reason: ToolErrorReason::McpScopeRefused,
896
- exc_type: "McpScopeRefused".to_string(),
897
- message: "mcp.scope_refused".to_string(),
898
- extra,
899
- }
900
- }
901
-
902
- fn rpc_scope_refused(
903
- &self,
904
- tool: &str,
905
- requested_team: Option<&str>,
906
- requested_scope: Option<&str>,
907
- ) -> ToolError {
908
- let owner_team_id = self.canonical_owner_team_key_for_event();
909
- let agent_id = self
910
- .agent_id
911
- .as_ref()
912
- .map(AgentId::as_str)
913
- .unwrap_or("unknown");
914
- let _ = EventLog::new(&self.workspace).write(
915
- "mcp.scope_refused",
916
- serde_json::json!({
917
- "reason": "rpc_scope_override",
918
- "tool": tool,
919
- "agent_id": agent_id,
920
- "owner_team_id": owner_team_id,
921
- "requested_team": requested_team,
922
- "requested_scope": requested_scope,
923
- }),
924
- );
925
- let mut extra = serde_json::Map::new();
926
- extra.insert("status".to_string(), Value::String("refused".to_string()));
927
- extra.insert("tool".to_string(), Value::String(tool.to_string()));
928
- extra.insert("agent_id".to_string(), Value::String(agent_id.to_string()));
929
- extra.insert(
930
- "owner_team_id".to_string(),
931
- owner_team_id.map_or(Value::Null, Value::String),
932
- );
933
- extra.insert(
934
- "requested_team".to_string(),
935
- requested_team.map_or(Value::Null, |team| Value::String(team.to_string())),
936
- );
937
- extra.insert(
938
- "requested_scope".to_string(),
939
- requested_scope.map_or(Value::Null, |scope| Value::String(scope.to_string())),
940
- );
941
- ToolError {
942
- reason: ToolErrorReason::McpScopeRefused,
943
- exc_type: "McpScopeRefused".to_string(),
944
- message: "mcp.scope_refused".to_string(),
945
- extra,
946
- }
947
- }
948
-
949
- fn canonical_owner_team_key_for_event(&self) -> Option<String> {
950
- let owner_team_id = self.owner_team_id.as_ref()?;
951
- let state = load_runtime_state(&self.workspace).ok()?;
952
- canonicalize_owner_team_id(&state, owner_team_id.as_str())
953
- }
954
- }
955
-
956
- fn canonicalize_owner_team_id(state: &Value, owner_team_id: &str) -> Option<String> {
957
- crate::state::projection::resolve_owner_team_id(state, owner_team_id)
958
- .canonical_key()
959
- .map(ToString::to_string)
960
- }
961
-
962
- fn requested_team_arg(args: &Value) -> Option<String> {
963
- [
964
- "team",
965
- "team_id",
966
- "owner_team_id",
967
- "owner_team",
968
- "target_team",
969
- ]
970
- .iter()
971
- .find_map(|key| {
972
- args.get(*key)
973
- .and_then(Value::as_str)
974
- .filter(|s| !s.is_empty())
975
- })
976
- .map(ToString::to_string)
977
- }
978
-
979
- fn requested_scope_arg(args: &Value) -> Option<String> {
980
- args.get("scope")
981
- .and_then(Value::as_str)
982
- .filter(|s| !s.is_empty())
983
- .map(ToString::to_string)
984
- .or_else(|| args.get("workspace").map(|_| "workspace".to_string()))
985
- }
986
-
987
- fn push_report_warning(obj: &mut serde_json::Map<String, Value>, warning: Value) {
988
- let Some(code) = warning.get("code").and_then(Value::as_str) else {
989
- return;
990
- };
991
- let Some(field) = warning.get("field").and_then(Value::as_str) else {
992
- return;
993
- };
994
- match obj.get_mut("warnings") {
995
- Some(Value::Array(warnings)) => {
996
- let exists = warnings.iter().any(|existing| {
997
- existing.get("code").and_then(Value::as_str) == Some(code)
998
- && existing.get("field").and_then(Value::as_str) == Some(field)
999
- });
1000
- if !exists {
1001
- warnings.push(warning);
1002
- }
1003
- }
1004
- _ => {
1005
- obj.insert("warnings".to_string(), Value::Array(vec![warning]));
1006
- }
1007
- }
1008
- }
1009
-
1010
- fn scope_override_name(scope: Scope) -> Option<&'static str> {
1011
- match scope {
1012
- Scope::Team => Some("team"),
1013
- Scope::Workspace => Some("workspace"),
1014
- }
1015
- }