@team-agent/installer 0.5.128 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (436) hide show
  1. package/README.md +4 -4
  2. package/README.zh.md +1 -1
  3. package/package.json +4 -8
  4. package/skills/team-agent/SKILL.md +37 -20
  5. package/skills/team-agent/command-coverage.json +169 -183
  6. package/skills/team-agent/docs/reference/team-agent-operator.md +64 -30
  7. package/skills/team-agent/references/recovery-runbook.md +1 -1
  8. package/skills/team-agent/references/team-agent-operator.md +64 -30
  9. package/templates/team_state.md +1 -1
  10. package/Cargo.lock +0 -1063
  11. package/Cargo.toml +0 -36
  12. package/crates/team-agent/Cargo.toml +0 -69
  13. package/crates/team-agent/src/app_server_test_support.rs +0 -258
  14. package/crates/team-agent/src/cli/adapters.rs +0 -1288
  15. package/crates/team-agent/src/cli/arguments.rs +0 -405
  16. package/crates/team-agent/src/cli/attach_app_server_leader.rs +0 -98
  17. package/crates/team-agent/src/cli/diagnose.rs +0 -1721
  18. package/crates/team-agent/src/cli/emit.rs +0 -2930
  19. package/crates/team-agent/src/cli/grok_slot.rs +0 -384
  20. package/crates/team-agent/src/cli/helpers.rs +0 -91
  21. package/crates/team-agent/src/cli/intent/runtime.rs +0 -1216
  22. package/crates/team-agent/src/cli/intent/runtime_tests.rs +0 -912
  23. package/crates/team-agent/src/cli/intent/tests.rs +0 -689
  24. package/crates/team-agent/src/cli/intent.rs +0 -664
  25. package/crates/team-agent/src/cli/leader.rs +0 -300
  26. package/crates/team-agent/src/cli/leader_prompt.rs +0 -261
  27. package/crates/team-agent/src/cli/leaders.rs +0 -418
  28. package/crates/team-agent/src/cli/mod.rs +0 -6545
  29. package/crates/team-agent/src/cli/models.rs +0 -1206
  30. package/crates/team-agent/src/cli/named_address.rs +0 -1651
  31. package/crates/team-agent/src/cli/profile.rs +0 -342
  32. package/crates/team-agent/src/cli/route.rs +0 -212
  33. package/crates/team-agent/src/cli/schedule.rs +0 -175
  34. package/crates/team-agent/src/cli/send/coordinator.rs +0 -164
  35. package/crates/team-agent/src/cli/send/mailbox.rs +0 -145
  36. package/crates/team-agent/src/cli/send/persist.rs +0 -156
  37. package/crates/team-agent/src/cli/send/presentation.rs +0 -370
  38. package/crates/team-agent/src/cli/send/resolve.rs +0 -573
  39. package/crates/team-agent/src/cli/send.rs +0 -199
  40. package/crates/team-agent/src/cli/shutdown_socket.rs +0 -288
  41. package/crates/team-agent/src/cli/spec.rs +0 -165
  42. package/crates/team-agent/src/cli/status.rs +0 -280
  43. package/crates/team-agent/src/cli/status_port/agents.rs +0 -358
  44. package/crates/team-agent/src/cli/status_port/approvals.rs +0 -79
  45. package/crates/team-agent/src/cli/status_port/brief.rs +0 -1981
  46. package/crates/team-agent/src/cli/status_port/compact.rs +0 -240
  47. package/crates/team-agent/src/cli/status_port/format.rs +0 -146
  48. package/crates/team-agent/src/cli/status_port/inbox.rs +0 -62
  49. package/crates/team-agent/src/cli/status_port/runtime.rs +0 -197
  50. package/crates/team-agent/src/cli/status_port/snapshot.rs +0 -208
  51. package/crates/team-agent/src/cli/status_port/store.rs +0 -416
  52. package/crates/team-agent/src/cli/status_port/tests.rs +0 -90
  53. package/crates/team-agent/src/cli/status_port.rs +0 -92
  54. package/crates/team-agent/src/cli/tests/base.rs +0 -885
  55. package/crates/team-agent/src/cli/tests/divergence.rs +0 -518
  56. package/crates/team-agent/src/cli/tests/lane_c.rs +0 -453
  57. package/crates/team-agent/src/cli/tests/leader_watch.rs +0 -322
  58. package/crates/team-agent/src/cli/tests/main_preserved.rs +0 -430
  59. package/crates/team-agent/src/cli/tests/missing_subcommands.rs +0 -336
  60. package/crates/team-agent/src/cli/tests/mod.rs +0 -137
  61. package/crates/team-agent/src/cli/tests/named_address.rs +0 -761
  62. package/crates/team-agent/src/cli/tests/parser_safety.rs +0 -383
  63. package/crates/team-agent/src/cli/tests/run_delegation.rs +0 -484
  64. package/crates/team-agent/src/cli/tests/shutdown_kill_plan.rs +0 -2179
  65. package/crates/team-agent/src/cli/tests/status_brief.rs +0 -1514
  66. package/crates/team-agent/src/cli/tests/status_send.rs +0 -888
  67. package/crates/team-agent/src/cli/tests/verb_install_skill.rs +0 -93
  68. package/crates/team-agent/src/cli/tests/verb_profile.rs +0 -392
  69. package/crates/team-agent/src/cli/triage.rs +0 -234
  70. package/crates/team-agent/src/cli/types.rs +0 -591
  71. package/crates/team-agent/src/codex_app_server.rs +0 -546
  72. package/crates/team-agent/src/communication_mode/mod.rs +0 -56
  73. package/crates/team-agent/src/compiler/tests.rs +0 -827
  74. package/crates/team-agent/src/compiler.rs +0 -890
  75. package/crates/team-agent/src/conpty/backend.rs +0 -829
  76. package/crates/team-agent/src/conpty/mod.rs +0 -33
  77. package/crates/team-agent/src/contract_runtime/backend.rs +0 -1744
  78. package/crates/team-agent/src/contract_runtime/commands.rs +0 -671
  79. package/crates/team-agent/src/contract_runtime/config.rs +0 -364
  80. package/crates/team-agent/src/contract_runtime/config_tests.rs +0 -76
  81. package/crates/team-agent/src/contract_runtime/discovery.rs +0 -449
  82. package/crates/team-agent/src/contract_runtime/fork.rs +0 -361
  83. package/crates/team-agent/src/contract_runtime/forward.rs +0 -288
  84. package/crates/team-agent/src/contract_runtime/framework.rs +0 -367
  85. package/crates/team-agent/src/contract_runtime/mcp.rs +0 -394
  86. package/crates/team-agent/src/contract_runtime/mod.rs +0 -17
  87. package/crates/team-agent/src/contract_runtime/prompt.rs +0 -216
  88. package/crates/team-agent/src/contract_runtime/pump.rs +0 -271
  89. package/crates/team-agent/src/contract_runtime/registry.rs +0 -553
  90. package/crates/team-agent/src/contract_runtime/workspace.rs +0 -228
  91. package/crates/team-agent/src/coordinator/backoff.rs +0 -741
  92. package/crates/team-agent/src/coordinator/conpty_shim.rs +0 -805
  93. package/crates/team-agent/src/coordinator/health.rs +0 -1185
  94. package/crates/team-agent/src/coordinator/mod.rs +0 -119
  95. package/crates/team-agent/src/coordinator/orphan.rs +0 -110
  96. package/crates/team-agent/src/coordinator/runtime_detectors.rs +0 -798
  97. package/crates/team-agent/src/coordinator/runtime_observation.rs +0 -84
  98. package/crates/team-agent/src/coordinator/steps/abnormal.rs +0 -2309
  99. package/crates/team-agent/src/coordinator/steps/delivery.rs +0 -15
  100. package/crates/team-agent/src/coordinator/steps/health_sync.rs +0 -15
  101. package/crates/team-agent/src/coordinator/steps/mod.rs +0 -126
  102. package/crates/team-agent/src/coordinator/steps/persist.rs +0 -15
  103. package/crates/team-agent/src/coordinator/steps/runtime_prompts.rs +0 -15
  104. package/crates/team-agent/src/coordinator/steps/session_gate.rs +0 -16
  105. package/crates/team-agent/src/coordinator/tests/a0_lostupdate.rs +0 -158
  106. package/crates/team-agent/src/coordinator/tests/abnormal.rs +0 -312
  107. package/crates/team-agent/src/coordinator/tests/api_error_recovery.rs +0 -300
  108. package/crates/team-agent/src/coordinator/tests/basics.rs +0 -211
  109. package/crates/team-agent/src/coordinator/tests/daemon.rs +0 -514
  110. package/crates/team-agent/src/coordinator/tests/energy.rs +0 -549
  111. package/crates/team-agent/src/coordinator/tests/health_sync.rs +0 -503
  112. package/crates/team-agent/src/coordinator/tests/main_preserved.rs +0 -186
  113. package/crates/team-agent/src/coordinator/tests/mod.rs +0 -295
  114. package/crates/team-agent/src/coordinator/tests/s3_bounded.rs +0 -207
  115. package/crates/team-agent/src/coordinator/tests/spine.rs +0 -308
  116. package/crates/team-agent/src/coordinator/tests/takeover.rs +0 -286
  117. package/crates/team-agent/src/coordinator/tests/tick_core.rs +0 -237
  118. package/crates/team-agent/src/coordinator/tick.rs +0 -3024
  119. package/crates/team-agent/src/coordinator/types.rs +0 -540
  120. package/crates/team-agent/src/db/agent_health_capture.rs +0 -126
  121. package/crates/team-agent/src/db/message_store.rs +0 -1527
  122. package/crates/team-agent/src/db/migration.rs +0 -984
  123. package/crates/team-agent/src/db/mod.rs +0 -26
  124. package/crates/team-agent/src/db/schema.rs +0 -663
  125. package/crates/team-agent/src/diagnose/comms.rs +0 -242
  126. package/crates/team-agent/src/diagnose/mod.rs +0 -44
  127. package/crates/team-agent/src/diagnose/orphans.rs +0 -889
  128. package/crates/team-agent/src/direct_delivery.rs +0 -368
  129. package/crates/team-agent/src/event_log.rs +0 -502
  130. package/crates/team-agent/src/fake_worker.rs +0 -303
  131. package/crates/team-agent/src/inbox_store.rs +0 -169
  132. package/crates/team-agent/src/kill_audit.rs +0 -106
  133. package/crates/team-agent/src/layout/manager.rs +0 -248
  134. package/crates/team-agent/src/layout/mod.rs +0 -36
  135. package/crates/team-agent/src/layout/overlay.rs +0 -134
  136. package/crates/team-agent/src/layout/placement.rs +0 -52
  137. package/crates/team-agent/src/layout/recovery.rs +0 -106
  138. package/crates/team-agent/src/layout/runtime_sessions.rs +0 -317
  139. package/crates/team-agent/src/layout/sessions.rs +0 -294
  140. package/crates/team-agent/src/layout/tmux_endpoint.rs +0 -165
  141. package/crates/team-agent/src/layout/worker_env.rs +0 -721
  142. package/crates/team-agent/src/layout/worker_window_helpers.rs +0 -37
  143. package/crates/team-agent/src/leader/helpers.rs +0 -178
  144. package/crates/team-agent/src/leader/incident.rs +0 -6
  145. package/crates/team-agent/src/leader/lease.rs +0 -3356
  146. package/crates/team-agent/src/leader/mod.rs +0 -104
  147. package/crates/team-agent/src/leader/owner_bind.rs +0 -400
  148. package/crates/team-agent/src/leader/prompt.rs +0 -905
  149. package/crates/team-agent/src/leader/provider_attribution.rs +0 -247
  150. package/crates/team-agent/src/leader/rediscover/tests.rs +0 -689
  151. package/crates/team-agent/src/leader/rediscover.rs +0 -1192
  152. package/crates/team-agent/src/leader/registry.rs +0 -888
  153. package/crates/team-agent/src/leader/start.rs +0 -4501
  154. package/crates/team-agent/src/leader/takeover.rs +0 -65
  155. package/crates/team-agent/src/leader/tests/basics.rs +0 -337
  156. package/crates/team-agent/src/leader/tests/byte_findings.rs +0 -355
  157. package/crates/team-agent/src/leader/tests/claim_leader_mailbox_flush_contract.rs +0 -544
  158. package/crates/team-agent/src/leader/tests/historical_inventory_upgrade_gate_red.rs +0 -624
  159. package/crates/team-agent/src/leader/tests/identity.rs +0 -465
  160. package/crates/team-agent/src/leader/tests/identity_session_names.rs +0 -42
  161. package/crates/team-agent/src/leader/tests/idle.rs +0 -113
  162. package/crates/team-agent/src/leader/tests/lease_api.rs +0 -520
  163. package/crates/team-agent/src/leader/tests/lease_claim.rs +0 -629
  164. package/crates/team-agent/src/leader/tests/mod.rs +0 -106
  165. package/crates/team-agent/src/leader/tests/prompt_contract.rs +0 -268
  166. package/crates/team-agent/src/leader/tests/rediscover.rs +0 -403
  167. package/crates/team-agent/src/leader/tests/rehomed_env.rs +0 -83
  168. package/crates/team-agent/src/leader/tests/team_in_team_state_scope_red.rs +0 -1273
  169. package/crates/team-agent/src/leader/tests/terminal_and_replay_vs_rerender_invariants_red.rs +0 -417
  170. package/crates/team-agent/src/leader/tests/wake_start_owner.rs +0 -168
  171. package/crates/team-agent/src/leader/types.rs +0 -534
  172. package/crates/team-agent/src/lib.rs +0 -147
  173. package/crates/team-agent/src/lifecycle/helpers.rs +0 -212
  174. package/crates/team-agent/src/lifecycle/launch/add_agent.rs +0 -881
  175. package/crates/team-agent/src/lifecycle/launch/add_agent_state.rs +0 -598
  176. package/crates/team-agent/src/lifecycle/launch/agent_state.rs +0 -332
  177. package/crates/team-agent/src/lifecycle/launch/clone_agent.rs +0 -204
  178. package/crates/team-agent/src/lifecycle/launch/fork_agent.rs +0 -107
  179. package/crates/team-agent/src/lifecycle/launch/fork_entry.rs +0 -144
  180. package/crates/team-agent/src/lifecycle/launch/identity.rs +0 -674
  181. package/crates/team-agent/src/lifecycle/launch/layout.rs +0 -350
  182. package/crates/team-agent/src/lifecycle/launch/leader_context.rs +0 -589
  183. package/crates/team-agent/src/lifecycle/launch/mcp_config.rs +0 -160
  184. package/crates/team-agent/src/lifecycle/launch/ownership.rs +0 -105
  185. package/crates/team-agent/src/lifecycle/launch/pi_mcp.rs +0 -899
  186. package/crates/team-agent/src/lifecycle/launch/pi_mcp_extension.js +0 -225
  187. package/crates/team-agent/src/lifecycle/launch/plan.rs +0 -269
  188. package/crates/team-agent/src/lifecycle/launch/quick_start.rs +0 -5200
  189. package/crates/team-agent/src/lifecycle/launch/quick_start_transport.rs +0 -368
  190. package/crates/team-agent/src/lifecycle/launch/readiness.rs +0 -519
  191. package/crates/team-agent/src/lifecycle/launch/role_source.rs +0 -287
  192. package/crates/team-agent/src/lifecycle/launch/spawn.rs +0 -473
  193. package/crates/team-agent/src/lifecycle/launch/spec_state.rs +0 -801
  194. package/crates/team-agent/src/lifecycle/launch/state_projection.rs +0 -624
  195. package/crates/team-agent/src/lifecycle/launch/worker_env.rs +0 -558
  196. package/crates/team-agent/src/lifecycle/launch.rs +0 -557
  197. package/crates/team-agent/src/lifecycle/lock.rs +0 -350
  198. package/crates/team-agent/src/lifecycle/mod.rs +0 -79
  199. package/crates/team-agent/src/lifecycle/pane_input_lock.rs +0 -239
  200. package/crates/team-agent/src/lifecycle/profile_launch.rs +0 -1067
  201. package/crates/team-agent/src/lifecycle/profile_smoke.rs +0 -557
  202. package/crates/team-agent/src/lifecycle/restart/agent.rs +0 -2199
  203. package/crates/team-agent/src/lifecycle/restart/avatar.rs +0 -1798
  204. package/crates/team-agent/src/lifecycle/restart/claude_fork.rs +0 -163
  205. package/crates/team-agent/src/lifecycle/restart/common.rs +0 -2362
  206. package/crates/team-agent/src/lifecycle/restart/orchestrator.rs +0 -65
  207. package/crates/team-agent/src/lifecycle/restart/preflight.rs +0 -113
  208. package/crates/team-agent/src/lifecycle/restart/rebuild.rs +0 -5135
  209. package/crates/team-agent/src/lifecycle/restart/remove.rs +0 -1504
  210. package/crates/team-agent/src/lifecycle/restart/selection.rs +0 -559
  211. package/crates/team-agent/src/lifecycle/restart/team_state.rs +0 -329
  212. package/crates/team-agent/src/lifecycle/restart.rs +0 -227
  213. package/crates/team-agent/src/lifecycle/role_config.rs +0 -1230
  214. package/crates/team-agent/src/lifecycle/tests/acceptance_b_batch_red.rs +0 -1021
  215. package/crates/team-agent/src/lifecycle/tests/agent_ops.rs +0 -1205
  216. package/crates/team-agent/src/lifecycle/tests/b0_legacy_snapshot_nonauthority_contract.rs +0 -265
  217. package/crates/team-agent/src/lifecycle/tests/b0_reader_hideone_audit_contract.rs +0 -490
  218. package/crates/team-agent/src/lifecycle/tests/behavioral_diff_264_red.rs +0 -656
  219. package/crates/team-agent/src/lifecycle/tests/claude_compatible_config_red.rs +0 -325
  220. package/crates/team-agent/src/lifecycle/tests/claude_profile_launch_red.rs +0 -447
  221. package/crates/team-agent/src/lifecycle/tests/cli_argv_routing_red.rs +0 -1638
  222. package/crates/team-agent/src/lifecycle/tests/clone_agent_preserves_source_tools.rs +0 -427
  223. package/crates/team-agent/src/lifecycle/tests/clone_fork_copilot_perms_red.rs +0 -770
  224. package/crates/team-agent/src/lifecycle/tests/communication_mode_runtime_contract_red.rs +0 -419
  225. package/crates/team-agent/src/lifecycle/tests/copilot_provider_red.rs +0 -2035
  226. package/crates/team-agent/src/lifecycle/tests/core.rs +0 -1327
  227. package/crates/team-agent/src/lifecycle/tests/f032_startup_prompt_best_effort_red.rs +0 -315
  228. package/crates/team-agent/src/lifecycle/tests/fixtures/pi_list_models_g0.stdout.txt +0 -222
  229. package/crates/team-agent/src/lifecycle/tests/fixtures/pi_list_models_spaced_ids.stdout.txt +0 -9
  230. package/crates/team-agent/src/lifecycle/tests/fixtures/pi_native_mcp_host.mjs +0 -72
  231. package/crates/team-agent/src/lifecycle/tests/gate_fixtures.rs +0 -562
  232. package/crates/team-agent/src/lifecycle/tests/grok_require_explicit_model_red.rs +0 -110
  233. package/crates/team-agent/src/lifecycle/tests/harvest2_a_batch_red.rs +0 -512
  234. package/crates/team-agent/src/lifecycle/tests/host_cotenant_death_p0_contract.rs +0 -921
  235. package/crates/team-agent/src/lifecycle/tests/issue238_codex_effort_contract.rs +0 -68
  236. package/crates/team-agent/src/lifecycle/tests/lane_ops.rs +0 -1851
  237. package/crates/team-agent/src/lifecycle/tests/launch_spawn.rs +0 -3983
  238. package/crates/team-agent/src/lifecycle/tests/lifecycle_lock.rs +0 -339
  239. package/crates/team-agent/src/lifecycle/tests/lifecycle_rollback_red.rs +0 -596
  240. package/crates/team-agent/src/lifecycle/tests/main_preserved.rs +0 -513
  241. package/crates/team-agent/src/lifecycle/tests/mcp_tool_name_format_red.rs +0 -69
  242. package/crates/team-agent/src/lifecycle/tests/phase_b_contracts.rs +0 -824
  243. package/crates/team-agent/src/lifecycle/tests/phase_golden.rs +0 -723
  244. package/crates/team-agent/src/lifecycle/tests/pi_catalog_red.rs +0 -164
  245. package/crates/team-agent/src/lifecycle/tests/pi_command_red.rs +0 -200
  246. package/crates/team-agent/src/lifecycle/tests/pi_compiler_red.rs +0 -210
  247. package/crates/team-agent/src/lifecycle/tests/pi_dual_entry_red.rs +0 -527
  248. package/crates/team-agent/src/lifecycle/tests/pi_executable_mcp_red.rs +0 -1062
  249. package/crates/team-agent/src/lifecycle/tests/pi_fork_session_inheritance_red.rs +0 -1419
  250. package/crates/team-agent/src/lifecycle/tests/pi_lifecycle_doctor_red.rs +0 -98
  251. package/crates/team-agent/src/lifecycle/tests/pi_native_mcp_capability_red.rs +0 -550
  252. package/crates/team-agent/src/lifecycle/tests/pi_session_delivery_red.rs +0 -226
  253. package/crates/team-agent/src/lifecycle/tests/quick_start_worker_readiness_red.rs +0 -332
  254. package/crates/team-agent/src/lifecycle/tests/realmachine_clusters_1_6_red.rs +0 -786
  255. package/crates/team-agent/src/lifecycle/tests/realmachine_residual_g1_g4_red.rs +0 -648
  256. package/crates/team-agent/src/lifecycle/tests/restart.rs +0 -185
  257. package/crates/team-agent/src/lifecycle/tests/restart_build_before_destroy_0540_contract.rs +0 -1053
  258. package/crates/team-agent/src/lifecycle/tests/restart_liveness_red.rs +0 -679
  259. package/crates/team-agent/src/lifecycle/tests/restart_rebind_hotfix_252_red.rs +0 -1126
  260. package/crates/team-agent/src/lifecycle/tests/restart_session_capture_red.rs +0 -153
  261. package/crates/team-agent/src/lifecycle/tests/resume_recover_red.rs +0 -427
  262. package/crates/team-agent/src/lifecycle/tests/stale_team_saveconflict_contract.rs +0 -431
  263. package/crates/team-agent/src/lifecycle/tests/startup_latency_contract.rs +0 -1066
  264. package/crates/team-agent/src/lifecycle/tests/status_credential_redaction_contract.rs +0 -876
  265. package/crates/team-agent/src/lifecycle/tests/subprep_codex_trust_roundtrip_red.rs +0 -1026
  266. package/crates/team-agent/src/lifecycle/tests/swallow_batch4_semantics_red.rs +0 -342
  267. package/crates/team-agent/src/lifecycle/tests/team_in_team_identity_scope_red.rs +0 -543
  268. package/crates/team-agent/src/lifecycle/tests/team_in_team_sibling_quick_start_red.rs +0 -1103
  269. package/crates/team-agent/src/lifecycle/tests/team_in_team_state_scope_red.rs +0 -1276
  270. package/crates/team-agent/src/lifecycle/tests/team_key_retirement_roster_red.rs +0 -145
  271. package/crates/team-agent/src/lifecycle/tests/team_key_retirement_txn_red.rs +0 -603
  272. package/crates/team-agent/src/lifecycle/tests/test_isolation_escape_contract.rs +0 -936
  273. package/crates/team-agent/src/lifecycle/tests/upgrade_compat_0211_red.rs +0 -970
  274. package/crates/team-agent/src/lifecycle/tests/verify_rs031_window_consistency_red.rs +0 -995
  275. package/crates/team-agent/src/lifecycle/tests/worker_spawn_env_red.rs +0 -836
  276. package/crates/team-agent/src/lifecycle/tests.rs +0 -105
  277. package/crates/team-agent/src/lifecycle/types.rs +0 -877
  278. package/crates/team-agent/src/lifecycle/worker_command_context.rs +0 -363
  279. package/crates/team-agent/src/main.rs +0 -52
  280. package/crates/team-agent/src/mcp_server/helpers.rs +0 -510
  281. package/crates/team-agent/src/mcp_server/lifecycle_tools/mod.rs +0 -6
  282. package/crates/team-agent/src/mcp_server/lifecycle_tools/state_status.rs +0 -43
  283. package/crates/team-agent/src/mcp_server/mod.rs +0 -119
  284. package/crates/team-agent/src/mcp_server/normalize.rs +0 -485
  285. package/crates/team-agent/src/mcp_server/readiness.rs +0 -527
  286. package/crates/team-agent/src/mcp_server/readiness_tests.rs +0 -348
  287. package/crates/team-agent/src/mcp_server/tests/golden.rs +0 -285
  288. package/crates/team-agent/src/mcp_server/tests/normalize.rs +0 -247
  289. package/crates/team-agent/src/mcp_server/tests/scoped.rs +0 -158
  290. package/crates/team-agent/src/mcp_server/tests/send.rs +0 -353
  291. package/crates/team-agent/src/mcp_server/tests/tools.rs +0 -341
  292. package/crates/team-agent/src/mcp_server/tests/wire.rs +0 -254
  293. package/crates/team-agent/src/mcp_server/tests.rs +0 -43
  294. package/crates/team-agent/src/mcp_server/tools.rs +0 -889
  295. package/crates/team-agent/src/mcp_server/types.rs +0 -396
  296. package/crates/team-agent/src/mcp_server/wire.rs +0 -867
  297. package/crates/team-agent/src/messaging/activity.rs +0 -461
  298. package/crates/team-agent/src/messaging/address.rs +0 -87
  299. package/crates/team-agent/src/messaging/delivery.rs +0 -3727
  300. package/crates/team-agent/src/messaging/delivery_consumption_tests.rs +0 -234
  301. package/crates/team-agent/src/messaging/enter_rescue.rs +0 -362
  302. package/crates/team-agent/src/messaging/enter_rescue_tests.rs +0 -633
  303. package/crates/team-agent/src/messaging/helpers.rs +0 -336
  304. package/crates/team-agent/src/messaging/leader_channel.rs +0 -287
  305. package/crates/team-agent/src/messaging/leader_receiver.rs +0 -786
  306. package/crates/team-agent/src/messaging/mod.rs +0 -167
  307. package/crates/team-agent/src/messaging/persist.rs +0 -377
  308. package/crates/team-agent/src/messaging/presentation.rs +0 -417
  309. package/crates/team-agent/src/messaging/reminders.rs +0 -316
  310. package/crates/team-agent/src/messaging/results/collection_tests.rs +0 -719
  311. package/crates/team-agent/src/messaging/results.rs +0 -1415
  312. package/crates/team-agent/src/messaging/scheduler.rs +0 -223
  313. package/crates/team-agent/src/messaging/selftest.rs +0 -315
  314. package/crates/team-agent/src/messaging/send.rs +0 -981
  315. package/crates/team-agent/src/messaging/tests/basic.rs +0 -346
  316. package/crates/team-agent/src/messaging/tests/dup_inject.rs +0 -657
  317. package/crates/team-agent/src/messaging/tests/e23.rs +0 -49
  318. package/crates/team-agent/src/messaging/tests/leader_channel.rs +0 -169
  319. package/crates/team-agent/src/messaging/tests/leader_inject_acceptance.rs +0 -817
  320. package/crates/team-agent/src/messaging/tests/main_preserved.rs +0 -85
  321. package/crates/team-agent/src/messaging/tests/mod.rs +0 -306
  322. package/crates/team-agent/src/messaging/tests/runtime.rs +0 -3549
  323. package/crates/team-agent/src/messaging/tests/spine.rs +0 -853
  324. package/crates/team-agent/src/messaging/tests/wave2.rs +0 -381
  325. package/crates/team-agent/src/messaging/trust.rs +0 -215
  326. package/crates/team-agent/src/messaging/types.rs +0 -472
  327. package/crates/team-agent/src/messaging/wait.rs +0 -366
  328. package/crates/team-agent/src/messaging/watchers.rs +0 -916
  329. package/crates/team-agent/src/model/enums.rs +0 -356
  330. package/crates/team-agent/src/model/errors.rs +0 -18
  331. package/crates/team-agent/src/model/ids.rs +0 -165
  332. package/crates/team-agent/src/model/mod.rs +0 -29
  333. package/crates/team-agent/src/model/name_similarity.rs +0 -252
  334. package/crates/team-agent/src/model/pane_authority_refusal.rs +0 -359
  335. package/crates/team-agent/src/model/paths.rs +0 -257
  336. package/crates/team-agent/src/model/routing.rs +0 -387
  337. package/crates/team-agent/src/model/spec.rs +0 -1184
  338. package/crates/team-agent/src/model/task_graph.rs +0 -321
  339. package/crates/team-agent/src/model/testdata/fuzz.golden.yaml +0 -43
  340. package/crates/team-agent/src/model/testdata/fuzz.yaml +0 -43
  341. package/crates/team-agent/src/model/testdata/spec_invalid_a.yaml +0 -209
  342. package/crates/team-agent/src/model/testdata/team.spec.golden.yaml +0 -208
  343. package/crates/team-agent/src/model/testdata/team.spec.yaml +0 -208
  344. package/crates/team-agent/src/model/yaml/tests.rs +0 -188
  345. package/crates/team-agent/src/model/yaml.rs +0 -802
  346. package/crates/team-agent/src/os_probe.rs +0 -280
  347. package/crates/team-agent/src/packaging/install.rs +0 -219
  348. package/crates/team-agent/src/packaging/migrate.rs +0 -38
  349. package/crates/team-agent/src/packaging/mod.rs +0 -91
  350. package/crates/team-agent/src/packaging/repair.rs +0 -33
  351. package/crates/team-agent/src/packaging/tests.rs +0 -822
  352. package/crates/team-agent/src/packaging/types.rs +0 -417
  353. package/crates/team-agent/src/platform/argv.rs +0 -331
  354. package/crates/team-agent/src/platform/errors.rs +0 -104
  355. package/crates/team-agent/src/platform/file_lock.rs +0 -279
  356. package/crates/team-agent/src/platform/mod.rs +0 -5
  357. package/crates/team-agent/src/platform/process.rs +0 -545
  358. package/crates/team-agent/src/provider/adapter.rs +0 -1150
  359. package/crates/team-agent/src/provider/adapters/claude.rs +0 -78
  360. package/crates/team-agent/src/provider/adapters/claude_fork.rs +0 -131
  361. package/crates/team-agent/src/provider/adapters/copilot.rs +0 -75
  362. package/crates/team-agent/src/provider/adapters/copilot_fork.rs +0 -307
  363. package/crates/team-agent/src/provider/adapters/fake.rs +0 -18
  364. package/crates/team-agent/src/provider/adapters/mod.rs +0 -30
  365. package/crates/team-agent/src/provider/adapters/pi.rs +0 -106
  366. package/crates/team-agent/src/provider/approvals/mod.rs +0 -3
  367. package/crates/team-agent/src/provider/approvals/parsing.rs +0 -586
  368. package/crates/team-agent/src/provider/approvals/runtime_prompts.rs +0 -205
  369. package/crates/team-agent/src/provider/argv_route.rs +0 -405
  370. package/crates/team-agent/src/provider/bypass_flags.rs +0 -116
  371. package/crates/team-agent/src/provider/classify.rs +0 -708
  372. package/crates/team-agent/src/provider/command_helpers.rs +0 -45
  373. package/crates/team-agent/src/provider/faults.rs +0 -165
  374. package/crates/team-agent/src/provider/helpers.rs +0 -52
  375. package/crates/team-agent/src/provider/mod.rs +0 -78
  376. package/crates/team-agent/src/provider/model_catalog.rs +0 -910
  377. package/crates/team-agent/src/provider/session/capture.rs +0 -2731
  378. package/crates/team-agent/src/provider/session/context_fork/claude.rs +0 -123
  379. package/crates/team-agent/src/provider/session/context_fork/outcome.rs +0 -172
  380. package/crates/team-agent/src/provider/session/context_fork.rs +0 -396
  381. package/crates/team-agent/src/provider/session/mod.rs +0 -36
  382. package/crates/team-agent/src/provider/session/resume.rs +0 -269
  383. package/crates/team-agent/src/provider/session_scan/claude.rs +0 -523
  384. package/crates/team-agent/src/provider/session_scan/common/tests.rs +0 -316
  385. package/crates/team-agent/src/provider/session_scan/common.rs +0 -654
  386. package/crates/team-agent/src/provider/session_scan/copilot.rs +0 -280
  387. package/crates/team-agent/src/provider/session_scan/pi.rs +0 -185
  388. package/crates/team-agent/src/provider/session_scan.rs +0 -71
  389. package/crates/team-agent/src/provider/startup_prompt.rs +0 -757
  390. package/crates/team-agent/src/provider/submit_now.rs +0 -71
  391. package/crates/team-agent/src/provider/testdata/copilot-ready-marker.txt +0 -5
  392. package/crates/team-agent/src/provider/testdata/copilot-trust-prompt.txt +0 -19
  393. package/crates/team-agent/src/provider/testdata/grok-models-authenticated.stdout +0 -9
  394. package/crates/team-agent/src/provider/testdata/grok-models-unauthenticated.stdout +0 -7
  395. package/crates/team-agent/src/provider/tests/adapter.rs +0 -441
  396. package/crates/team-agent/src/provider/tests/classify.rs +0 -148
  397. package/crates/team-agent/src/provider/tests/command_helpers.rs +0 -35
  398. package/crates/team-agent/src/provider/tests/copilot_fork.rs +0 -191
  399. package/crates/team-agent/src/provider/tests/faults.rs +0 -200
  400. package/crates/team-agent/src/provider/tests/idle.rs +0 -177
  401. package/crates/team-agent/src/provider/tests/wire.rs +0 -213
  402. package/crates/team-agent/src/provider/tests.rs +0 -32
  403. package/crates/team-agent/src/provider/types.rs +0 -529
  404. package/crates/team-agent/src/provider/wire.rs +0 -394
  405. package/crates/team-agent/src/redaction.rs +0 -259
  406. package/crates/team-agent/src/state/abnormal_watch/tests/mod.rs +0 -248
  407. package/crates/team-agent/src/state/abnormal_watch.rs +0 -144
  408. package/crates/team-agent/src/state/identity.rs +0 -914
  409. package/crates/team-agent/src/state/identity_keys.rs +0 -132
  410. package/crates/team-agent/src/state/mod.rs +0 -74
  411. package/crates/team-agent/src/state/owner_gate.rs +0 -482
  412. package/crates/team-agent/src/state/ownership.rs +0 -563
  413. package/crates/team-agent/src/state/paths.rs +0 -395
  414. package/crates/team-agent/src/state/persist.rs +0 -3811
  415. package/crates/team-agent/src/state/projection.rs +0 -1508
  416. package/crates/team-agent/src/state/repository/intent.rs +0 -14
  417. package/crates/team-agent/src/state/repository/tests.rs +0 -184
  418. package/crates/team-agent/src/state/repository.rs +0 -866
  419. package/crates/team-agent/src/state/selector.rs +0 -160
  420. package/crates/team-agent/src/state/testdata/state-rich.canonical.json +0 -133
  421. package/crates/team-agent/src/test_support/models_timeout_fixture.rs +0 -144
  422. package/crates/team-agent/src/tmux_backend/enter_rescue.rs +0 -325
  423. package/crates/team-agent/src/tmux_backend/enter_rescue_tests.rs +0 -432
  424. package/crates/team-agent/src/tmux_backend/native_input.rs +0 -513
  425. package/crates/team-agent/src/tmux_backend/native_input_tests.rs +0 -742
  426. package/crates/team-agent/src/tmux_backend/tests.rs +0 -4103
  427. package/crates/team-agent/src/tmux_backend.rs +0 -4492
  428. package/crates/team-agent/src/topology.rs +0 -537
  429. package/crates/team-agent/src/transport/enter_rescue.rs +0 -166
  430. package/crates/team-agent/src/transport/native_input.rs +0 -491
  431. package/crates/team-agent/src/transport/test_support.rs +0 -743
  432. package/crates/team-agent/src/transport/tests/behavior.rs +0 -326
  433. package/crates/team-agent/src/transport/tests/mod.rs +0 -194
  434. package/crates/team-agent/src/transport/tests/wire.rs +0 -574
  435. package/crates/team-agent/src/transport.rs +0 -1655
  436. package/crates/team-agent/src/transport_factory.rs +0 -819
@@ -1,2930 +0,0 @@
1
- //!
2
- //! cli · emit — `emit`(--json vs 人读 dict 逐键)+ 顶层 `run` 调度(parser.py `main`)+
3
- //! 人读标量/集合渲染(`human_value` / `json_dumps_like`)。
4
-
5
- use super::models::cmd_models;
6
- use super::spec::{command_spec, CommandKind, COMMAND_SPECS};
7
- #[cfg(test)]
8
- use super::spec::{CommandTier, ALL_DISPATCH_KINDS};
9
- use super::*;
10
- use std::io::{ErrorKind, Write as _};
11
-
12
- ///
13
- /// `emit`(`helpers.py:12-23`):`--json`→`json.dumps(indent=2, ensure_ascii=False, sort_keys=True)`;
14
- /// 否则 dict 逐键 `key: value`(嵌套 dict/list 内联 compact json,`ensure_ascii=False`)、非 dict 直接 print。
15
- /// 返回应打印到 stdout 的字符串(bin main 负责实际 println)。
16
- pub fn emit(output: &CmdOutput, as_json: bool) -> Option<String> {
17
- emit_with_json_order(output, as_json, false)
18
- }
19
-
20
- fn emit_with_json_order(
21
- output: &CmdOutput,
22
- as_json: bool,
23
- preserve_json_order: bool,
24
- ) -> Option<String> {
25
- match output {
26
- CmdOutput::None => None,
27
- CmdOutput::Human(text) => Some(crate::redaction::redact_external_text(text)),
28
- CmdOutput::Json(value) => {
29
- let value = crate::redaction::redact_external_value(value);
30
- if as_json {
31
- return if preserve_json_order {
32
- serde_json::to_string_pretty(&value).ok()
33
- } else {
34
- serde_json::to_string_pretty(&sort_json(&value)).ok()
35
- };
36
- }
37
- if let Value::Object(obj) = value {
38
- let lines: Vec<String> = obj
39
- .iter()
40
- .map(|(key, value)| format!("{key}: {}", human_value(value)))
41
- .collect();
42
- Some(lines.join("\n"))
43
- } else {
44
- Some(human_value(&value))
45
- }
46
- }
47
- }
48
- }
49
-
50
- ///
51
- /// `main(argv)`(`parser.py:84`):**CLI 唯一进程入口**。codex/claude/copilot/grok passthrough 早返回 →
52
- /// 解析 argv 到 subcommand → 调对应 handler → 异常落盘 + 信封 + `ExitCode::Error` →
53
- /// `consume_leader_inbox_summary` → `emit` → `result.ok is False ? Error : Ok`。
54
- /// **行为入口**:契约可端到端跑 argv→(stdout, exit code)。
55
- pub fn run(argv: &[String], cwd: &Path) -> ExitCode {
56
- let Some(command) = argv.first().map(String::as_str) else {
57
- println!("{}", default_help());
58
- return ExitCode::Ok;
59
- };
60
- if command == "route" {
61
- return super::route::run(&argv[1..]);
62
- }
63
- if command == "leader-prompt" {
64
- return super::leader_prompt::run(&argv[1..]);
65
- }
66
- if is_leader_passthrough_command(command) {
67
- return match cmd_leader_passthrough(command, &argv[1..], cwd) {
68
- Ok(result) => emit_result(result),
69
- Err(error) => emit_cli_error(command, &argv[1..], cwd, &error),
70
- };
71
- }
72
- if matches!(command, "-h" | "--help" | "help") {
73
- println!("{}", command_help(None));
74
- return ExitCode::Ok;
75
- }
76
- if matches!(command, "-V" | "--version") {
77
- println!("team-agent {}", env!("CARGO_PKG_VERSION"));
78
- return ExitCode::Ok;
79
- }
80
- if let Some(result) = super::intent::run(command, &argv[1..], cwd) {
81
- return match result {
82
- Ok(result) => emit_result(result),
83
- Err(error) => emit_cli_error_for_command(command, &argv[1..], cwd, &error),
84
- };
85
- }
86
- // Classify syntax/scope errors before dispatch; contextual status refusals
87
- // retain their existing stderr-only contract. Resolve the scope only once.
88
- if is_machine_command(command)
89
- || matches!(command_spec(command).map(|spec| spec.kind), Some(CommandKind::Dispatch(_)))
90
- {
91
- let checked = match prepare_control_args(command, &argv[1..], cwd) {
92
- Ok(checked) => checked,
93
- Err(error) => return emit_parser_usage(command, &argv[1..], &error),
94
- };
95
- let error_args = checked.tokens.clone();
96
- return match dispatch_prepared(command, checked, cwd) {
97
- Ok(exit) => exit,
98
- Err(error) => emit_cli_error_for_command(command, &error_args, cwd, &error),
99
- };
100
- }
101
- match dispatch(command, &argv[1..], cwd) {
102
- Ok(exit) => exit,
103
- Err(error) => emit_cli_error_for_command(command, &argv[1..], cwd, &error),
104
- }
105
- }
106
-
107
- fn emit_cli_error_for_command(
108
- command: &str,
109
- args: &[String],
110
- cwd: &Path,
111
- error: &CliError,
112
- ) -> ExitCode {
113
- let missing_input = matches!(error, CliError::Usage(message) if message.starts_with("missing ") || message.starts_with("Provide ") || matches!(message.as_str(), "add-agent requires --provider <name>" | "--source is required unless --uninstall"));
114
- if command_spec(command).is_some() && missing_input {
115
- let help = command_help(Some(command));
116
- let explanation = match error {
117
- CliError::Usage(message) => match message.as_str() {
118
- "missing agent" | "missing source_agent" => "Provide an agent name.".to_string(),
119
- "missing profile command" => {
120
- "Provide a profile operation: init, doctor or show.".to_string()
121
- }
122
- "missing profile name" => "Provide an authentication/proxy profile name.".to_string(),
123
- "add-agent requires --provider <name>" => {
124
- "Select a provider with --provider, or supply a role file with --role-file.".to_string()
125
- }
126
- other => other
127
- .strip_prefix("missing ")
128
- .map(|field| format!("Provide the required argument: {field}."))
129
- .unwrap_or_else(|| other.to_string()),
130
- },
131
- _ => error.to_string(),
132
- };
133
- if super::arguments::has_flag(command, args, "--json") {
134
- let payload = error.to_payload(Path::new(""), command);
135
- let mut value = serde_json::to_value(payload)
136
- .unwrap_or_else(|_| serde_json::json!({"ok": false, "error": error.to_string()}));
137
- value["error"] = serde_json::json!(explanation);
138
- value["action"] = serde_json::json!(format!("team-agent {command} --help"));
139
- value["next_actions"] = serde_json::json!([format!(
140
- "Complete the required arguments using the Examples in team-agent {command} --help"
141
- )]);
142
- println!("{}", python_compact_json(&value));
143
- } else {
144
- eprintln!("{explanation}\n\n{help}");
145
- }
146
- ExitCode::Usage
147
- } else if command == "status" {
148
- emit_status_cli_error(error)
149
- } else if matches!(error, CliError::Usage(_)) {
150
- emit_parser_usage(command, args, error)
151
- } else {
152
- emit_cli_error(command, args, cwd, error)
153
- }
154
- }
155
-
156
- #[cfg(test)]
157
- pub(crate) fn __test_runtime_error_emitter(command: &str, cwd: &Path, error: &CliError) -> ExitCode {
158
- emit_cli_error(command, &[], cwd, error)
159
- }
160
-
161
- fn emit_status_cli_error(error: &CliError) -> ExitCode {
162
- let normalized = normalize_cli_error(error);
163
- let payload_error = normalized.as_ref().unwrap_or(error);
164
- let safe_error = crate::redaction::redact_external_text(&payload_error.to_string());
165
- eprintln!("error: {safe_error}");
166
- ExitCode::Error
167
- }
168
-
169
- /// Print a handler's CmdResult to stdout (emit formats json/human), then surface its exit code.
170
- /// (parser.py: `print(emit(result, as_json))` then the ok→exit mapping.)
171
- pub(super) fn emit_result(r: CmdResult) -> ExitCode {
172
- let persisted_message_id = match &r.output {
173
- CmdOutput::Json(value) => value
174
- .get("message_id")
175
- .and_then(Value::as_str)
176
- .map(ToString::to_string),
177
- _ => None,
178
- };
179
- if let Some(text) = emit_with_json_order(&r.output, r.as_json, r.preserve_json_order) {
180
- if let Err(error) = write_stdout_line(&text) {
181
- if let Some(message_id) = persisted_message_id {
182
- let stderr = std::io::stderr();
183
- let mut stderr = stderr.lock();
184
- let _ = writeln!(
185
- stderr,
186
- "Output unavailable; the message was persisted with message_id={message_id}. Use team-agent inbox leader -n 3 for replies; do not resend."
187
- );
188
- }
189
- return if error.kind() == ErrorKind::BrokenPipe {
190
- r.exit
191
- } else {
192
- ExitCode::Error
193
- };
194
- }
195
- }
196
- r.exit
197
- }
198
-
199
- fn write_stdout_line(text: &str) -> std::io::Result<()> {
200
- let stdout = std::io::stdout();
201
- let mut stdout = stdout.lock();
202
- stdout.write_all(text.as_bytes())?;
203
- stdout.write_all(b"\n")
204
- }
205
-
206
- #[cfg(test)]
207
- pub(crate) fn __test_dispatch(
208
- command: &str,
209
- args: &[String],
210
- cwd: &Path,
211
- ) -> Result<ExitCode, CliError> {
212
- dispatch(command, args, cwd)
213
- }
214
-
215
- fn dispatch(command: &str, args: &[String], cwd: &Path) -> Result<ExitCode, CliError> {
216
- if command == "route" {
217
- return Ok(super::route::run(args));
218
- }
219
- if command == "leader-prompt" {
220
- return Ok(super::leader_prompt::run(args));
221
- }
222
- if let Some(result) = super::intent::run(command, args, cwd) {
223
- return result.map(emit_result);
224
- }
225
- let machine = is_machine_command(command);
226
- if !machine && !matches!(command_spec(command).map(|spec| spec.kind), Some(CommandKind::Dispatch(_))) {
227
- return Ok(emit_unknown_subcommand_usage(command));
228
- }
229
- dispatch_prepared(command, prepare_control_args(command, args, cwd)?, cwd)
230
- }
231
-
232
- fn prepare_control_args(command: &str, args: &[String], cwd: &Path) -> Result<super::arguments::CheckedArgs, CliError> {
233
- let mut checked = super::arguments::parse(command, args)?;
234
- let raw_send = command == "send" && checked.tokens.iter().any(|token| token == "--socket");
235
- if !checked.help && !raw_send { checked.tokens = resolve_command_scope(command, checked.tokens, cwd)?; }
236
- Ok(checked)
237
- }
238
-
239
- fn dispatch_prepared(command: &str, checked: super::arguments::CheckedArgs, cwd: &Path) -> Result<ExitCode, CliError> {
240
- let machine = is_machine_command(command);
241
- if checked.help {
242
- if machine {
243
- eprintln!("{HUMAN_NAVIGATION}");
244
- return Ok(ExitCode::Usage);
245
- }
246
- println!("{}", command_help(Some(command)));
247
- return Ok(ExitCode::Ok);
248
- }
249
- let args = checked.tokens.as_slice();
250
- if machine { return dispatch_machine(command, args, cwd); }
251
- if args.iter().all(|arg| arg == "--json")
252
- && matches!(
253
- command,
254
- "send"
255
- | "inbox"
256
- | "add-agent"
257
- | "start-agent"
258
- | "stop-agent"
259
- | "reset-agent"
260
- | "clone-agent"
261
- | "fork-agent"
262
- | "remove-agent"
263
- | "profile"
264
- )
265
- {
266
- return Err(CliError::Usage(
267
- "Provide the agent name, task message or required command settings; see Usage and Examples below".to_string(),
268
- ));
269
- }
270
- match command {
271
- "quick-start" => cmd_quick_start(&quick_start_args(args, cwd)?).map(emit_result),
272
- "send" => {
273
- let parsed = parse_args(args);
274
- if parsed.socket.is_some() || parsed.dialect.is_some() {
275
- let socket = parsed.socket.as_deref().ok_or_else(|| CliError::Usage("raw send requires --socket".into()))?;
276
- let pane = parsed.pane.as_deref().ok_or_else(|| CliError::Usage("raw send requires --pane".into()))?;
277
- let dialect = parsed.dialect.as_deref().ok_or_else(|| CliError::Usage("raw send requires --dialect".into()))?;
278
- if parsed.targets.is_some() || parsed.to_name.is_some() || parsed.to_leader.is_some() || parsed.mailbox {
279
- return Err(CliError::Usage("raw send cannot be combined with semantic addressing or --mailbox".into()));
280
- }
281
- crate::direct_delivery::direct_send(socket, pane, dialect, &parsed.positionals.join(" ")).map_err(CliError::Runtime)?;
282
- Ok(emit_result(CmdResult::from_json(serde_json::json!({"ok": true, "status": "sent", "delivery": "physical", "pane_id": pane, "accepted": null}), parsed.json)))
283
- } else { cmd_send(&send_args(args, cwd)?).map(emit_result) }
284
- },
285
- "locate" => {
286
- let parsed = parse_args(args);
287
- let value = crate::direct_delivery::locate(&workspace(&parsed, cwd), parsed.team.as_deref()).map_err(CliError::Usage)?;
288
- Ok(emit_result(CmdResult::from_json(value, parsed.json)))
289
- },
290
- "schedule" => super::schedule::run(args, cwd).map(emit_result),
291
- "status" => cmd_status_for_team(&status_args(args, cwd), parse_args(args).team.as_deref())
292
- .map(emit_result),
293
- "shutdown" => cmd_shutdown(&shutdown_args(args, cwd)?).map(emit_result),
294
- "restart" => cmd_restart(&restart_args(args, cwd)?).map(emit_result),
295
- "start-agent" => cmd_start_agent(&start_agent_args(args, cwd)?).map(emit_result),
296
- "stop-agent" => cmd_stop_agent(&stop_agent_args(args, cwd)?).map(emit_result),
297
- "reset-agent" => cmd_reset_agent(&reset_agent_args(args, cwd)?).map(emit_result),
298
- "add-agent" => cmd_add_agent(&add_agent_args(args, cwd)?).map(emit_result),
299
- "clone-agent" => cmd_clone_agent(&clone_agent_args(args, cwd)?).map(emit_result),
300
- "fork-agent" => cmd_fork_agent(&fork_agent_args(args, cwd)?).map(emit_result),
301
- "remove-agent" => cmd_remove_agent(&remove_agent_args(args, cwd)?).map(emit_result),
302
- "takeover" => cmd_takeover(&takeover_args(args, cwd)).map(emit_result),
303
- "claim-leader" => cmd_claim_leader(&claim_leader_args(args, cwd)).map(emit_result),
304
- // Real dispatch: `cmd_attach_leader` writes the `leader_receiver` binding.
305
- "attach-leader" => cmd_attach_leader(&attach_leader_args(args, cwd)?).map(emit_result),
306
-
307
- "approvals" => cmd_approvals(&approvals_args(args, cwd)).map(emit_result),
308
- "inbox" => cmd_inbox(&inbox_args(args, cwd)?).map(emit_result),
309
- "doctor" => cmd_doctor(&doctor_args(args, cwd)).map(emit_result),
310
-
311
- // 0.5.9 E7 host-leader-registry: `leaders` is the host-level derived
312
- // discovery command. It reads ~/.team-agent/leaders, validates each
313
- // entry against canonical state, and reports LIVE/STALE/AMBIGUOUS
314
- // status. `--to-leader NAME` on `send` uses the same registry to
315
- // resolve short/qualified/hash-qualified names to a canonical
316
- // (workspace, team_key) tuple and delegates to the E6 named-leader
317
- // delivery path — no separate route authority.
318
- "leaders" => cmd_leaders(&leaders_args(args, cwd)?).map(emit_result),
319
- "models" => cmd_models(&models_args(args)?).map(emit_result),
320
- "kiro" => Ok(emit_result(cmd_kiro_leader(args))),
321
-
322
- "install-skill" => cmd_install_skill(&install_skill_args(args)?).map(emit_result),
323
- "profile" => cmd_profile(&profile_args(args, cwd)?).map(emit_result),
324
-
325
- _ => Ok(emit_unknown_subcommand_usage(command)),
326
- }
327
- }
328
-
329
- // Script compatibility is deliberately outside the human catalog and suggestions.
330
- fn is_machine_command(command: &str) -> bool {
331
- matches!(command, "wait" | "coordinator" | "attach-app-server-leader")
332
- }
333
-
334
- fn dispatch_machine(command: &str, args: &[String], cwd: &Path) -> Result<ExitCode, CliError> {
335
- match command {
336
- "wait" => cmd_wait(&wait_args(args, cwd)?).map(emit_result),
337
- "coordinator" => run_coordinator(args, cwd),
338
- "attach-app-server-leader" => {
339
- cmd_attach_app_server_leader(&attach_app_server_leader_args(args, cwd)?)
340
- .map(emit_result)
341
- }
342
- _ => Ok(emit_unknown_subcommand_usage(command)),
343
- }
344
- }
345
-
346
- // Command grammar, not provider identity parsing: these are top-level CLI
347
- // passthrough verbs for starting a leader under a provider executable.
348
- const LEADER_PASSTHROUGH_COMMANDS: &[&str] =
349
- &["codex", "claude", "copilot", "grok", "pi"];
350
-
351
- pub(crate) fn is_leader_passthrough_command(command: &str) -> bool {
352
- LEADER_PASSTHROUGH_COMMANDS.contains(&command)
353
- && matches!(
354
- command_spec(command).map(|spec| spec.kind),
355
- Some(CommandKind::LeaderPassthrough { .. })
356
- )
357
- }
358
-
359
- /// Registered subcommands (the dispatch table) plus spec-only verbs that have no
360
- /// dispatch arm yet but must still respond to `--help` per CR-063/G4.
361
- /// Used by the `--help` short-circuit gate so unknown commands keep falling through
362
- /// to the argparse invalid-choice path.
363
- fn is_known_subcommand(command: &str) -> bool {
364
- command_spec(command).is_some_and(|spec| spec.command_help)
365
- }
366
-
367
- pub(crate) fn default_help() -> String {
368
- let mut out = String::from("Team Agent: create a team, send tasks, read replies and shut down safely.\n\n1. Prepare agents\n Prepare TEAM.md and agents/*.md with explicit provider and bypass decisions; use --from for an external source.\n2. Open a leader and create the team\n With Pi installed and signed in, run team-agent pi.\n Run team-agent start in that leader's tool context. Verified live members stay unchanged; stopped members are started.\n Use team restart for a deliberate restart (session auto); legacy bare restart retains preserve. Do not take over or delete an existing team.\n3. Send tasks and read replies\n team-agent send worker 'Calculate 245 * 37 and reply to the leader.'\n team-agent inbox leader -n 3\n team-agent status\n Sending is not completion; wait for an actual reply.\n4. Diagnose and stop\n team-agent doctor --workspace .\n team-agent stop --workspace . --json\n Verify this team's residual resources are empty, then diagnose the selected workspace.\n\nSelect workspace/team scope with --workspace/--team. Discover model names with models.\nWindows ConPTY requires a Windows host and an installed shim; tmux commands are not a generic Windows path.\n");
369
- append_help_section(
370
- &mut out,
371
- "Getting started",
372
- &["start", "quick-start", "send", "schedule", "status", "models", "inbox"],
373
- );
374
- append_help_section(&mut out, "Team lifecycle", &["stop", "team", "restart", "shutdown"]);
375
- append_help_section(
376
- &mut out,
377
- "Agent lifecycle",
378
- &[
379
- "agent",
380
- "add-agent",
381
- "start-agent",
382
- "stop-agent",
383
- "reset-agent",
384
- "clone-agent",
385
- "fork-agent",
386
- "remove-agent",
387
- ],
388
- );
389
- append_help_section(
390
- &mut out,
391
- "Observation and collaboration",
392
- &["locate", "leaders", "doctor", "approvals"],
393
- );
394
- append_help_section(
395
- &mut out,
396
- "Configuration",
397
- &["route", "leader-prompt", "profile", "install-skill"],
398
- );
399
- append_help_section(
400
- &mut out,
401
- "Guided recovery",
402
- &["claim-leader", "takeover", "attach-leader"],
403
- );
404
- append_help_section(
405
- &mut out,
406
- "Leader launch",
407
- &["pi", "codex", "claude", "copilot", "grok", "kiro"],
408
- );
409
- out.push_str("\nCommand arguments and examples: team-agent <command> --help");
410
- out
411
- }
412
-
413
- fn append_help_section(out: &mut String, title: &str, names: &[&str]) {
414
- out.push('\n');
415
- out.push_str(title);
416
- out.push_str(":\n");
417
- for name in names {
418
- if let Some(spec) = command_spec(name).filter(|spec| spec.default_help) {
419
- out.push_str(&format!(" {:<13} {}\n", spec.name, spec.summary));
420
- }
421
- }
422
- }
423
-
424
- ///
425
- /// Test-only public accessor for `command_help` — allows integration
426
- /// tests to grep the help copy without depending on internal parser
427
- /// machinery.
428
- pub fn __test_command_help(command: Option<&str>) -> String {
429
- command_help(command)
430
- }
431
-
432
- ///
433
- /// Test-only public accessor for `quick_start_args` — allows
434
- /// integration tests to exercise the parser without going through
435
- /// stdio + the full `main` entrypoint.
436
- pub fn __test_quick_start_args(
437
- args: &[String],
438
- cwd: &std::path::Path,
439
- ) -> Result<crate::cli::types::QuickStartArgs, crate::cli::CliError> {
440
- quick_start_args(args, cwd)
441
- }
442
-
443
- pub(super) const TEAM_TEMPLATE: &str =
444
- "---\nname: current\n---\nA small team for a command-line example.\n";
445
- pub(super) const WORKER_TEMPLATE: &str = "---\nname: worker\nrole: assistant\nprovider: pi\nmodel: openai-codex/gpt-6-luna\nauth_mode: subscription\ndangerously_skip_permissions: false\n---\nComplete the task and send a concise reply to the leader.\n";
446
- const HUMAN_NAVIGATION: &str = "Use team-agent --help to list available commands.";
447
-
448
- pub(super) fn command_help(command: Option<&str>) -> String {
449
- if let Some(name) = command.filter(|name| matches!(*name, "start" | "stop" | "team" | "agent")) {
450
- return super::intent::help(name);
451
- }
452
- let Some(name) = command else {
453
- return default_help();
454
- };
455
- let Some(spec) = command_spec(name) else {
456
- return HUMAN_NAVIGATION.to_string();
457
- };
458
- if name == "route" {
459
- return super::route::HELP.to_string();
460
- }
461
- if name == "leader-prompt" {
462
- return super::leader_prompt::HELP.to_string();
463
- }
464
- let (details, examples, next) = match name {
465
- "quick-start" => (
466
- "TEAMDIR contains TEAM.md and agents/; --workspace selects the runtime project.\n--name sets the team name; --team/--team-id selects the team; --yes retains compatibility; --detail includes full diagnostics.\nProviders must be installed and signed in. Declare provider/model/effort in role files; permission bypass defaults to false.\n--backend tmux is for POSIX; conpty requires a Windows host and an installed ConPTY shim.",
467
- "team-agent quick-start\nteam-agent quick-start ./roles --workspace ./project\nteam-agent quick-start . --json",
468
- "Compatibility bridge only. In the authorized Leader context, prefer team-agent start --from TEAMDIR for complete new configuration and team-agent start for later activation. Check models and native sign-in first; inspect status and actual replies after starting."),
469
- "send" => ("<agent> is an agent name from the read-only endpoint snapshot; MESSAGE is the task text.\nPaste + Enter completes synchronously without coordinator queues or SQLite writes. Physical success is not provider acceptance.\n--socket SOCKET --pane %N --dialect PROVIDER sends directly without a workspace snapshot. Automatic snapshot provider aliases select the native sequence: Claude/Cursor 100ms, Grok 150ms, Pi/Codex no floor, then one Enter.\nExplicit double-enter submits twice; cursor-double-enter retains Cursor\'s 100ms floor. No automatic retry or third Enter.\n--mailbox appends to the independent inbox without injecting into the conversation.",
470
- "team-agent send worker 'Calculate 245 * 37 and reply to the leader.'\nteam-agent send worker 'Review the changes' --workspace . --team help-demo\nteam-agent send worker 'Read this when next available' --mailbox",
471
- "Acceptance is not delivery or completion. Wait for an actual reply; use team-agent inbox leader -n 3. Diagnose with status/doctor rather than repeated sends."),
472
- "locate" => ("Read the endpoint snapshot and list live tmux panes without starting or contacting the coordinator.",
473
- "team-agent locate --workspace . --json\nteam-agent locate --team help-demo", "Use the socket, pane_id and dialect for raw send, or the agent name for workspace-scoped send."),
474
- "schedule" => ("add requires exactly one of --in or --every and non-empty --text. Durations are positive integers followed by ms, s, m, h or d.\nlist shows active reminders; cancel takes the sched_<hex> id returned by add.",
475
- "team-agent schedule add --in 10m --text 'Check progress'\nteam-agent schedule add --every 1h --text 'Review status'\nteam-agent schedule list --json\nteam-agent schedule cancel sched_1",
476
- "Uses the existing coordinator timer; schedules survive daemon restarts. Delivery has tick granularity. Cancellation stops future occurrences, not reminders already firing or queued. A stopped coordinator resumes timers when restarted, without replaying missed intervals."),
477
- "inbox" => ("<agent> is the recipient name; -n/--limit bounds the message count. Reading replies does not resend messages.",
478
- "team-agent inbox leader -n 3\nteam-agent inbox worker --limit 5\nteam-agent inbox leader --workspace . --team help-demo --json", "Wait for a natural reply, then check team-agent status if needed. Do not inspect worker terminal content."),
479
- "status" => ("Optional <agent> selects one agent. --summary/--detail retain compatibility and do not add fields.\nNine fields: name/provider/model/effort/runtime_status/activity/health/session_name/tmux_command.\nRuntime, activity and health are distinct. unknown means insufficient evidence; null means unset. No default model is guessed.",
480
- "team-agent status\nteam-agent status worker\nteam-agent status --workspace . --team help-demo --json", "Read replies with team-agent inbox leader -n 3; diagnose problems with team-agent doctor --workspace ."),
481
- "models" => ("--provider selects the provider, default pi. QUERY or --search performs keyword search; they are mutually exclusive.\nUse cursor (or cursor-agent, agent, cursor_agent) for the contract-native Cursor catalog. Copilot has no model discovery entrypoint here. Results come from the native catalog, not guesses.",
482
- "team-agent models --provider pi\nteam-agent models --provider pi --search luna\nteam-agent models --provider cursor --json", "Use the exact returned model in a role file or team-agent start AGENT --model MODEL; stop a running seat before changing its settings."),
483
- "restart" => ("restart AGENT and team restart default to --session auto; bare/explicit-path restart keeps preserve.\n--session preserve requires continuation evidence; auto permits only the original legal fresh fallback, not guaranteed saved memory.\n--dry-run plans without lifecycle effects. --allow-fresh is the legacy authorized opt-in; --session-converge-deadline is in seconds.",
484
- "team-agent restart worker --dry-run --json\nteam-agent restart worker --session preserve --workspace . --dry-run --json", "Use team-agent team restart for deliberate team recovery; choose --session preserve when context must be retained. Team restart leaves explicitly stopped/paused seats alone; team-agent start intentionally activates the non-paused roster. Inspect partial/unknown outcomes with status/doctor, never blind reset or retry."),
485
- "shutdown" => ("Compatibility bridge: stop only the selected workspace/team. Logs are retained by default; --keep-logs remains compatible.\n--json reports scope, degradation and owned residuals. Success does not mean other teams were shut down.",
486
- "team-agent shutdown --workspace .\nteam-agent shutdown --workspace . --team help-demo --json", "Prefer team-agent stop --workspace . --team KEY --json. Verify this team's owned residuals are empty; use team-agent start for authorized later activation. Do not clean up other teams or shared servers."),
487
- "add-agent" => ("Compatibility add-only entry. <agent> names the new seat; --provider/--model/--effort select intentional launch settings.\n--bypass requires true|false; --prompt sets responsibilities; --profile selects a local profile.\nProvider and bypass must be explicit in arguments or --role-file. Conflicting settings are refused before writes. --force requires explicit authorization, a positively dead old pane and no live cohort;\nfor a removed seat, --force re-adopts the role file it left behind and CLI values override it.",
488
- "team-agent add-agent reviewer --provider pi --model openai-codex/gpt-6-luna --bypass false --prompt 'Review tasks'\nteam-agent add-agent reviewer --role-file ./agents/reviewer.md", "Prefer team-agent start reviewer --role-file FILE for add-or-wake, or team-agent agent add reviewer for strict new-seat behavior. Keep provider/bypass explicit; check status and send a task after actual startup."),
489
- "start-agent" => ("Compatibility entry starts an existing stopped seat only; a running seat is refused.\n--provider/--model/--effort/--bypass select intentional settings; --prompt replaces permanent instructions and --profile selects local authentication.\nA different provider is refused. Use --allow-fresh only after explicit authorization to lose saved context.",
490
- "team-agent start-agent worker\nteam-agent start-agent worker --model openai-codex/gpt-6-luna", "Prefer team-agent start worker for daily add-or-wake or verified live no-op. Use team-agent stop worker before applying changed settings; inspect status and send a task afterward. A no-op is not role synchronization or business readiness."),
491
- "stop-agent" => ("Compatibility single-agent stop; configuration and saved session associations are retained, not removed.",
492
- "team-agent stop-agent worker\nteam-agent stop-agent worker --workspace . --team help-demo --json", "Prefer team-agent stop worker. Verify the stopped result; intentionally wake with team-agent start worker, then check status before sending new work."),
493
- "reset-agent" => ("Compatibility entry requires explicit --discard-session. Stops the old process, clears the saved association and attempts fresh startup. Paused agents stay paused; not all native history is deleted.",
494
- "team-agent reset-agent worker --discard-session\nteam-agent reset-agent worker --discard-session --workspace . --team help-demo --json", "Prefer team-agent agent reset worker --discard-session only after explicit context-loss approval. Never use reset as a resume-refusal fallback; check the actual result/status before sending new work."),
495
- "clone-agent" => ("Compatibility entry: <agent> is the source; --as names the new agent; --label sets a readable label.\nCopies configuration, not a complete conversation.",
496
- "team-agent clone-agent worker --as reviewer\nteam-agent clone-agent worker --as reviewer --label 'Review agent' --workspace .", "Prefer team-agent agent clone worker --as reviewer. Check the new agent with status, then send it an independent task; original capability gates still apply."),
497
- "fork-agent" => ("Compatibility entry: <agent> is the source; --as names the new agent; --label sets a readable label.\nRequires captured context and admitted new-seat fork capability. Unsupported providers refuse without fallback.",
498
- "team-agent fork-agent worker --as experiment\nteam-agent fork-agent worker --as experiment --workspace . --team help-demo --json", "Prefer team-agent agent fork worker --as experiment where admitted. Inspect status before sending work; finish with team-agent stop experiment or the explicit agent remove operation."),
499
- "remove-agent" => ("Compatibility entry requires --confirm. Spec-defined agents also require --from-spec; dynamic agents do not.\nDeletes only the managed role copy, not external user files. Stop a running agent first.\n--force stops/removes a running agent only with explicit authorization and the original safety checks.",
500
- "team-agent remove-agent reviewer --confirm\nteam-agent remove-agent reviewer --from-spec --confirm --workspace . --team help-demo --json", "Prefer team-agent agent remove reviewer --confirm with any required --from-spec. Save replies first and verify the resulting scope/status; do not force-clean other agents."),
501
- "leaders" => ("Lists live leaders by default; --all includes stale registrations and --stale selects stale entries.\nQUERY/--search filters workspace/team/name. --prune removes verified retired registrations; preview with --dry-run.",
502
- "team-agent leaders\nteam-agent leaders --all --json\nteam-agent leaders --prune --dry-run", "Select --workspace/--team from the reported scope. Registry cleanup is not process shutdown."),
503
- "doctor" => ("Read-only diagnosis by default; SPEC is an optional configuration path.\n--comms/--gate comms checks channels, not actual replies; --gate orphans checks residual resources.\nUse --fix/--fix-schema/--cleanup-orphans only within authorized scope. Dangerous repairs require --confirm.",
504
- "team-agent doctor --workspace .\nteam-agent doctor --workspace . --team help-demo --json", "Follow the actual issue and selected-team scope. A suggested repair is not an executed repair."),
505
- "approvals" => ("Optional <agent> selects one agent. Observes permission prompts without granting approval.",
506
- "team-agent approvals\nteam-agent approvals worker --json", "Verify the requested permission, handle it in the actual provider prompt, then check status."),
507
- "profile" => ("init creates a profile; doctor checks it; show displays settings. NAME is the profile name.\n--auth-mode selects authentication; --proxy-mode direct bypasses proxies and inherit uses the environment proxy.\nProfiles belong to the selected workspace, not automatically to an isolated --team. Do not expose credentials.",
508
- "team-agent profile init local --auth-mode subscription\nteam-agent profile doctor local\nteam-agent profile show local", "After validation, use team-agent start AGENT --profile local; stop a running seat before changing settings. Use native sign-in when needed, never copy external credentials."),
509
- "install-skill" => ("--source must be a verified skill directory; --target selects codex/claude/copilot/all.\n--dest overrides the destination; --dry-run previews; --uninstall removes the target skill. Installation is not required to create a team.",
510
- "team-agent install-skill --source \"$SKILL_DIR\" --target codex --dry-run\nteam-agent install-skill --source \"$SKILL_DIR\" --target codex", "Set SKILL_DIR to a verified directory and inspect the preview before installation. Do not overwrite unknown user files."),
511
- "claim-leader" => ("Use only when doctor recommends leader registration and this terminal is the actual leader.\n--confirm authorizes registration; it does not open a new provider.",
512
- "team-agent claim-leader --workspace . --json\nteam-agent claim-leader --workspace . --team help-demo --confirm --json", "Verify doctor findings and terminal ownership first. A refusal without confirmation is not successful registration."),
513
- "takeover" => ("Use only when doctor recommends takeover and the user has authorized it. This changes leader ownership.\nWith a usable team terminal, takeover may execute even without --confirm; it is not a read-only preview. Use team restart --session preserve for normal context-preserving recovery.",
514
- "team-agent takeover --workspace . --team help-demo --confirm\nteam-agent takeover --workspace . --team help-demo --confirm --json", "Verify leader/team ownership before confirmation. Check status/doctor afterwards; do not take over someone else's team."),
515
- "attach-leader" => ("PANE must be a verified leader terminal, not a guessed pane id.\n--provider selects the actual provider; --confirm authorizes attachment to an existing leader. Use only when doctor recommends it.",
516
- "team-agent attach-leader --pane \"$PANE\" --provider pi --workspace .\nteam-agent attach-leader --pane \"$PANE\" --provider pi --workspace . --team help-demo --confirm --json", "Set PANE to the verified terminal. Confirm attachment with doctor before sending a task."),
517
- "kiro" => ("Kiro leader launching is not admitted by this candidate. This entry returns the stable capability refusal kiro_leader_not_admitted (exit 1).\nNo native process, leader binding, attach or provider fallback is attempted. --help/-h is read-only and exits 0.",
518
- "team-agent kiro\nteam-agent kiro --json", "Use provider: kiro in a complete worker role source with team-agent start --from TEAMDIR; worker support does not grant Leader capability."),
519
- _ => ("Install the provider and complete native sign-in first. The current directory is the workspace.\nUse --attach-existing/--confirm only after verifying leader ownership and receiving authorization; --attach-session selects a verified session.\n--external-leader selects an external leader; --allow-nested-attach requires explicit authorization for nested terminals.\nArguments after -- pass through unchanged. Bare --help/-h displays this help without starting the provider.",
520
- "", "Prepare complete TEAM.md/roles with explicit user choices, then run team-agent start in the opened Leader's tool context, never an ordinary worker conversation."),
521
- };
522
- let examples = if matches!(spec.kind, CommandKind::LeaderPassthrough { .. }) {
523
- let native = name;
524
- if name == "pi" {
525
- "team-agent pi\nteam-agent pi -- --model openai-codex/gpt-6-luna\npi --help".to_string()
526
- } else {
527
- format!("team-agent {name}\nteam-agent {name} --help\n{native} --help")
528
- }
529
- } else {
530
- examples.to_string()
531
- };
532
- let scope = if name == "kiro" {
533
- "Use --json for the structured capability refusal. Native arguments and attach options cannot enable this capability."
534
- } else if matches!(spec.kind, CommandKind::LeaderPassthrough { .. }) {
535
- "Use --json for structured output. --workspace/--team are not launcher options here; they pass to the native provider."
536
- } else {
537
- "Use --json for structured output. --workspace selects the project; supported commands use --team to select the team."
538
- };
539
- let mut out = format!(
540
- "Purpose:\n{}.\nUsage: {}\n\nOptions:\n{}\n{}\nExamples:\n{}\n\nNext Action:\n{}",
541
- spec.summary, spec.usage, details, scope, examples, next
542
- );
543
- if name == "quick-start" {
544
- out.push_str(&format!("\n\nMinimal two-file configuration (create manually; not written automatically):\nTEAM.md:\n{TEAM_TEMPLATE}\nagents/worker.md:\n{WORKER_TEMPLATE}"));
545
- }
546
- if name == "restart" {
547
- out.push_str("\nRestart forms: restart AGENT selects one registered agent (default session auto); use agent restart ID to disambiguate a same-named directory. Legacy bare or explicit-path restart retains preserve and original receipts. New team restart defaults to auto. auto never means reset; native capability refusals remain authoritative.");
548
- }
549
- if name == "copilot" {
550
- out.push_str(
551
- "\nCopilot has no team-agent models entrypoint; consult native provider help.",
552
- );
553
- }
554
- out
555
- }
556
-
557
- fn emit_unknown_subcommand_usage(command: &str) -> ExitCode {
558
- emit_usage_error(&format!(
559
- "Unknown command: '{command}'. Use team-agent --help to list available commands."
560
- ));
561
- // E8 (N38): 错路引导 —— 拼写近似时建议最接近的真子命令(additive,不改既有 golden 行)。
562
- if let Some(suggestion) = nearest_subcommand(command) {
563
- eprintln!("Did you mean `{suggestion}`? See team-agent {suggestion} --help for examples.");
564
- }
565
- // 0.5.45 naming-addressing (RED-6): unknown subcommand exits 1
566
- // (Error), aligned with the family of typo refusals throughout
567
- // send/named. Pre-0.5.45 mapped to Usage (2) argparse-style; the
568
- // shared refusal shape ("typo diagnostic + advisory suggestion +
569
- // exit 1") is the invariant callers of `team-agent send` /
570
- // `--to-name` also see, so keeping unknown-subcommand at 2 was
571
- // internal drift.
572
- ExitCode::Error
573
- }
574
-
575
- /// 在已知子命令里找与 `input` 最接近的一个。0.5.45 naming-addressing
576
- /// (design §3.2/§4.1) 抽公 shared `model::name_similarity` — 距离
577
- /// 阈值与排序规则跟 CLI `--to-name` typo suggestion 走同一份纯函数,
578
- /// 避免两套 fuzzy 逻辑漂移。既有 `statu -> status` 行为保留(RED-6
579
- /// grep guard + prefix-hit priority)。
580
- fn nearest_subcommand(input: &str) -> Option<&'static str> {
581
- use crate::model::name_similarity::{rank, Candidate};
582
- let candidates: Vec<Candidate<&'static str>> = COMMAND_SPECS
583
- .iter()
584
- .filter(|spec| spec.suggestion_index)
585
- .map(|spec| Candidate {
586
- match_key: spec.name.to_string(),
587
- stable_key: spec.name.to_string(),
588
- payload: spec.name,
589
- })
590
- .collect();
591
- rank(input, &candidates).into_iter().next()
592
- }
593
-
594
- fn emit_usage_error(message: &str) {
595
- eprintln!("Usage: team-agent <command>; list commands with team-agent --help");
596
- eprintln!("Error: {message}");
597
- }
598
-
599
- /// `install-skill` 参数(RED-1 根治:把 skill 安装单源收敛到二进制,install.mjs 调它)。
600
- struct InstallSkillArgs {
601
- target: crate::packaging::SkillTarget,
602
- dest: Option<PathBuf>,
603
- dry_run: bool,
604
- /// `--uninstall`:删 target 的 skill 目标目录(单源,走同一 SkillTarget 表),不需 --source。
605
- uninstall: bool,
606
- source: Option<PathBuf>,
607
- json: bool,
608
- }
609
-
610
- fn install_skill_args(args: &[String]) -> Result<InstallSkillArgs, CliError> {
611
- let parsed = parse_args(args);
612
- // `--target` 复用 parse_args.targets(codex|claude|copilot|all,默认 all)。
613
- let target = match parsed.targets.as_deref() {
614
- None | Some("all") => crate::packaging::SkillTarget::All,
615
- Some("codex") => crate::packaging::SkillTarget::Codex,
616
- Some("claude") => crate::packaging::SkillTarget::Claude,
617
- Some("copilot") => crate::packaging::SkillTarget::Copilot,
618
- Some(other) => {
619
- return Err(CliError::Usage(format!(
620
- "invalid --target: {other} (choose from codex, claude, copilot, all)"
621
- )))
622
- }
623
- };
624
- let uninstall = args.iter().any(|a| a == "--uninstall");
625
- // `--source <dir>` 安装时必需(npm 包的 skills/team-agent;运行期无 CARGO_MANIFEST_DIR);
626
- // 卸载不需要。
627
- let source = flag_value(args, "--source").map(PathBuf::from);
628
- if !uninstall && source.is_none() {
629
- return Err(CliError::Usage("missing --source <skill dir>".to_string()));
630
- }
631
- let dest = flag_value(args, "--dest").map(PathBuf::from);
632
- let dry_run = args.iter().any(|a| a == "--dry-run");
633
- Ok(InstallSkillArgs {
634
- target,
635
- dest,
636
- dry_run,
637
- uninstall,
638
- source,
639
- json: parsed.json,
640
- })
641
- }
642
-
643
- /// 取 `--flag <value>` 的值(用于 install-skill 的 --source/--dest,parse_args 不覆盖的旗标)。
644
- fn flag_value(args: &[String], flag: &str) -> Option<String> {
645
- for (index, argument) in args.iter().enumerate() {
646
- if argument == "--" { break; }
647
- if argument == flag { return args.get(index + 1).cloned(); }
648
- if let Some((key, value)) = argument.split_once('=') {
649
- if key == flag { return Some(value.to_string()); }
650
- }
651
- }
652
- None
653
- }
654
-
655
- /// `team-agent install-skill`(RED-1 单源):repo `skills/team-agent` → `~/.codex|.claude|.copilot`。
656
- /// install.mjs 删 JS 拷贝逻辑、改调本命令(`--target all --source <pkg>/skills/team-agent`)。
657
- fn cmd_install_skill(args: &InstallSkillArgs) -> Result<CmdResult, CliError> {
658
- // 卸载分支(单源:走同一 SkillTarget 表的 dest_dir;all → SINGLE_TARGETS 全集)。
659
- if args.uninstall {
660
- let home = std::env::var_os("HOME")
661
- .map(PathBuf::from)
662
- .unwrap_or_else(|| PathBuf::from("."));
663
- let targets: Vec<crate::packaging::SkillTarget> = match args.target {
664
- crate::packaging::SkillTarget::All => {
665
- crate::packaging::SkillTarget::SINGLE_TARGETS.to_vec()
666
- }
667
- t => vec![t],
668
- };
669
- let mut removed: Vec<serde_json::Value> = Vec::new();
670
- for t in targets {
671
- if let Some(dest) = t.dest_dir(&home) {
672
- let existed = dest.0.exists();
673
- if existed && !args.dry_run {
674
- std::fs::remove_dir_all(&dest.0)
675
- .map_err(|e| CliError::Runtime(e.to_string()))?;
676
- }
677
- removed.push(serde_json::json!({
678
- "target": t,
679
- "dest": dest.0.to_string_lossy(),
680
- "removed": existed,
681
- "dry_run": args.dry_run,
682
- }));
683
- }
684
- }
685
- return Ok(CmdResult::from_json(
686
- serde_json::json!({"ok": true, "uninstalled": removed}),
687
- args.json,
688
- ));
689
- }
690
- let source = args
691
- .source
692
- .clone()
693
- .ok_or_else(|| CliError::Usage("missing --source <skill dir>".to_string()))?;
694
- let outcomes =
695
- crate::packaging::install::install_skill(&crate::packaging::SkillInstallOptions {
696
- target: args.target,
697
- dest: args.dest.clone(),
698
- dry_run: args.dry_run,
699
- source,
700
- })
701
- .map_err(|e| CliError::Runtime(e.to_string()))?;
702
- let installed: Vec<serde_json::Value> = outcomes
703
- .iter()
704
- .map(|o| {
705
- serde_json::json!({
706
- "target": o.target,
707
- "dest": o.dest.0.to_string_lossy(),
708
- "dry_run": o.dry_run,
709
- "removed_stale": o.removed_stale.len(),
710
- })
711
- })
712
- .collect();
713
- Ok(CmdResult::from_json(
714
- serde_json::json!({"ok": true, "installed": installed}),
715
- args.json,
716
- ))
717
- }
718
-
719
- fn resolve_path(path: &Path) -> PathBuf {
720
- std::fs::canonicalize(path).unwrap_or_else(|_| path.to_path_buf())
721
- }
722
-
723
- fn emit_parser_usage(command: &str, args: &[String], error: &CliError) -> ExitCode {
724
- if super::arguments::has_flag(command, args, "--json") {
725
- let mut payload = error.to_payload(Path::new(""), command);
726
- payload.action = format!("Use team-agent {command} --help to correct the command arguments.");
727
- if let Ok(value) = serde_json::to_value(payload) {
728
- println!("{}", python_compact_json(&crate::redaction::redact_external_value(&value)));
729
- }
730
- } else {
731
- eprintln!("error: {}\nUse team-agent {command} --help.", crate::redaction::redact_external_text(&error.to_string()));
732
- }
733
- ExitCode::Usage
734
- }
735
-
736
- fn emit_cli_error(command: &str, args: &[String], cwd: &Path, error: &CliError) -> ExitCode {
737
- if matches!(error, CliError::Usage(_)) { return emit_parser_usage(command, args, error); }
738
- let parsed = parse_args(args);
739
- let workspace = workspace(&parsed, cwd);
740
- let log_path = cli_error_log_path(&workspace);
741
- if let Some(parent) = log_path.parent() {
742
- let _ = std::fs::create_dir_all(parent);
743
- }
744
- let normalized = normalize_cli_error(error);
745
- let payload_error = normalized.as_ref().unwrap_or(error);
746
- let safe_error = crate::redaction::redact_external_text(&payload_error.to_string());
747
- let _ = std::fs::write(&log_path, format!("{safe_error}\n"));
748
- let mut payload = payload_error.to_payload(&log_path, command);
749
- payload.error = safe_error;
750
- if let CliError::AddressRefusal { error, action, .. } = payload_error {
751
- if !super::arguments::has_flag(command, args, "--json") {
752
- payload.error = crate::redaction::redact_external_text(error);
753
- payload.action = action.clone();
754
- }
755
- } else if let Some(reason) = payload
756
- .error
757
- .strip_prefix("usage error: ")
758
- .unwrap_or(&payload.error)
759
- .strip_prefix("Error: ")
760
- .and_then(|text| text.split_once(':').map(|(reason, _)| reason))
761
- {
762
- if let Some(message) = super::named_address::human_address_reason(reason) {
763
- payload.error = message.to_string();
764
- payload.action = "Run team-agent status and use an agent name from the list. Select scope with --workspace/--team; diagnose channel issues with doctor.".to_string();
765
- }
766
- }
767
- if command_spec(command).is_some()
768
- && payload.action
769
- == "Run team-agent doctor --workspace . for the selected team, or inspect the error log shown here."
770
- {
771
- let mut doctor = format!(
772
- "team-agent doctor --workspace {}",
773
- super::adapters::shell_quote(&workspace.to_string_lossy())
774
- );
775
- if let Some(team) = parsed.team.as_deref() {
776
- doctor.push_str(&format!(" --team {}", super::adapters::shell_quote(team)));
777
- }
778
- payload.action = format!("Run {doctor} for the selected team, or inspect the error log shown here.");
779
- }
780
- payload.action = crate::redaction::redact_external_text(&payload.action);
781
- payload.log = crate::redaction::redact_external_text(&payload.log);
782
- payload.reason = payload
783
- .reason
784
- .map(|value| crate::redaction::redact_external_text(&value));
785
- payload.session_name = payload
786
- .session_name
787
- .map(|value| crate::redaction::redact_external_text(&value));
788
- payload.next_actions = payload.next_actions.map(|values| {
789
- values
790
- .into_iter()
791
- .map(|value| crate::redaction::redact_external_text(&value))
792
- .collect()
793
- });
794
- if super::arguments::has_flag(command, args, "--json") {
795
- if let Ok(value) = serde_json::to_value(payload) {
796
- println!("{}", python_compact_json(&value));
797
- }
798
- } else {
799
- eprintln!("error: {}", payload.error);
800
- eprintln!("action: {}", payload.action);
801
- if matches!(payload_error, CliError::AddressRefusal { .. }) {
802
- eprintln!("log: {:?}", payload.log);
803
- } else {
804
- eprintln!("log: {}", payload.log);
805
- }
806
- }
807
- ExitCode::Error
808
- }
809
-
810
- fn normalize_cli_error(error: &CliError) -> Option<CliError> {
811
- match error {
812
- CliError::Runtime(message) => Some(CliError::Runtime(
813
- message
814
- .strip_prefix("validation error: ")
815
- .unwrap_or(message)
816
- .to_string(),
817
- )),
818
- _ => None,
819
- }
820
- }
821
-
822
- fn cli_error_log_path(workspace: &Path) -> PathBuf {
823
- let stamp = chrono::Utc::now().format("%Y%m%d-%H%M%S%.6f");
824
- workspace
825
- .join(".team")
826
- .join("logs")
827
- .join(format!("cli-error-{stamp}.log"))
828
- }
829
-
830
- struct PythonCompactFormatter;
831
-
832
- impl serde_json::ser::Formatter for PythonCompactFormatter {
833
- fn begin_array_value<W: ?Sized + std::io::Write>(
834
- &mut self,
835
- w: &mut W,
836
- first: bool,
837
- ) -> std::io::Result<()> {
838
- if first {
839
- Ok(())
840
- } else {
841
- w.write_all(b", ")
842
- }
843
- }
844
-
845
- fn begin_object_key<W: ?Sized + std::io::Write>(
846
- &mut self,
847
- w: &mut W,
848
- first: bool,
849
- ) -> std::io::Result<()> {
850
- if first {
851
- Ok(())
852
- } else {
853
- w.write_all(b", ")
854
- }
855
- }
856
-
857
- fn begin_object_value<W: ?Sized + std::io::Write>(&mut self, w: &mut W) -> std::io::Result<()> {
858
- w.write_all(b": ")
859
- }
860
- }
861
-
862
- fn python_compact_json(value: &Value) -> String {
863
- let mut bytes = Vec::new();
864
- let mut ser = serde_json::Serializer::with_formatter(&mut bytes, PythonCompactFormatter);
865
- if value.serialize(&mut ser).is_err() {
866
- return "{}".to_string();
867
- }
868
- String::from_utf8(bytes).unwrap_or_else(|_| "{}".to_string())
869
- }
870
-
871
- fn has_arg(args: &[String], needle: &str) -> bool {
872
- args.iter().take_while(|arg| arg.as_str() != "--").any(|arg| arg == needle)
873
- }
874
-
875
- #[derive(Debug, Default)]
876
- struct ParsedArgs {
877
- positionals: Vec<String>,
878
- workspace: Option<PathBuf>,
879
- team: Option<String>,
880
- json: bool,
881
- yes: bool,
882
- name: Option<String>,
883
- team_id: Option<String>,
884
- targets: Option<String>,
885
- task: Option<String>,
886
- watch_result: bool,
887
- requires_ack: bool,
888
- no_ack: bool,
889
- no_wait: bool,
890
- timeout: Option<f64>,
891
- confirm_human: bool,
892
- detail: bool,
893
- summary: bool,
894
- keep_logs: bool,
895
- allow_fresh: bool,
896
- session_converge_deadline_ms: Option<u64>,
897
- force: bool,
898
- discard_session: bool,
899
- role_file: Option<String>,
900
- as_agent: Option<String>,
901
- label: Option<String>,
902
- from_spec: bool,
903
- confirm: bool,
904
- limit: Option<usize>,
905
- gate: Option<String>,
906
- comms: bool,
907
- fix: bool,
908
- fix_schema: bool,
909
- cleanup_orphans: bool,
910
- once: bool,
911
- tick_interval: Option<f64>,
912
- status_value: Option<String>,
913
- search: Option<String>,
914
- file: Option<PathBuf>,
915
- result: Option<String>,
916
- assignee: Option<String>,
917
- auth_mode: Option<String>,
918
- proxy_mode: Option<String>,
919
- pane: Option<String>,
920
- to_name: Option<String>,
921
- /// E7 (0.5.9 host-leader-registry-design §4.2): `send --to-leader NAME`
922
- /// resolves NAME through `~/.team-agent/leaders` to a canonical target
923
- /// (workspace, team_key) then delegates to the E6 leader delivery path.
924
- /// Mutually exclusive with `--to-name`, TARGET, `--pane`, and `--to`.
925
- to_leader: Option<String>,
926
- provider: Option<String>,
927
- socket: Option<String>,
928
- dialect: Option<String>,
929
- thread_id: Option<String>,
930
- message_id: Option<String>,
931
- mailbox: bool,
932
- presentation_sink: Option<String>,
933
- message_class: Option<String>,
934
- case_id: Option<String>,
935
- content: Option<String>,
936
- primary_error: Option<String>,
937
- agent_id: Option<String>,
938
- task_id: Option<String>,
939
- result_json: Option<String>,
940
- /// 0.5.x Phase 1d Batch 2: quick-start `--backend <tmux|conpty>`.
941
- /// Raw string (validated at the quick-start builder); the factory
942
- /// enforces literal semantics.
943
- backend: Option<String>,
944
- }
945
-
946
- fn parse_args(args: &[String]) -> ParsedArgs {
947
- let mut expanded = Vec::new();
948
- let mut literal = false;
949
- for argument in args {
950
- if argument == "--" { literal = true; }
951
- if !literal && argument.starts_with("--") {
952
- if let Some((flag, value)) = argument.split_once('=') {
953
- expanded.extend([flag.to_string(), value.to_string()]);
954
- continue;
955
- }
956
- }
957
- expanded.push(argument.clone());
958
- }
959
- let args = expanded.as_slice();
960
- let mut parsed = ParsedArgs::default();
961
- let mut i = 0usize;
962
- while i < args.len() {
963
- let Some(arg) = args.get(i) else {
964
- break;
965
- };
966
- match arg.as_str() {
967
- "--" => {
968
- parsed.positionals.extend_from_slice(&args[i + 1..]);
969
- break;
970
- }
971
- "--workspace" => {
972
- parsed.workspace = next_arg(args, &mut i).map(PathBuf::from);
973
- }
974
- "--team" => parsed.team = next_arg(args, &mut i),
975
- "--json" => parsed.json = true,
976
- "--yes" => parsed.yes = true,
977
- "--name" => parsed.name = next_arg(args, &mut i),
978
- "--team-id" => parsed.team_id = next_arg(args, &mut i),
979
- "--targets" | "--target" | "--to" => parsed.targets = next_arg(args, &mut i),
980
- "--task" => parsed.task = next_arg(args, &mut i),
981
- "--task-id" => parsed.task_id = next_arg(args, &mut i),
982
- "--agent-id" => parsed.agent_id = next_arg(args, &mut i),
983
- "--watch-result" => parsed.watch_result = true,
984
- "--requires-ack" => parsed.requires_ack = true,
985
- "--no-ack" => parsed.no_ack = true,
986
- "--no-wait" => parsed.no_wait = true,
987
- "--timeout" => {
988
- parsed.timeout = next_arg(args, &mut i).and_then(|v| v.parse::<f64>().ok())
989
- }
990
- "--confirm-human" => parsed.confirm_human = true,
991
- "--detail" => parsed.detail = true,
992
- "--summary" => parsed.summary = true,
993
- "--keep-logs" => parsed.keep_logs = true,
994
- "--allow-fresh" => parsed.allow_fresh = true,
995
- "--session-converge-deadline" => {
996
- parsed.session_converge_deadline_ms =
997
- next_arg(args, &mut i).and_then(|v| parse_seconds_ms(&v));
998
- }
999
- "--force" => parsed.force = true,
1000
- "--backend" => parsed.backend = next_arg(args, &mut i),
1001
- "--discard-session" => parsed.discard_session = true,
1002
- "--role-file" => parsed.role_file = next_arg(args, &mut i),
1003
- "--as" => parsed.as_agent = next_arg(args, &mut i),
1004
- "--label" => parsed.label = next_arg(args, &mut i),
1005
- "--from-spec" => parsed.from_spec = true,
1006
- "--confirm" => parsed.confirm = true,
1007
- "-n" | "--limit" => {
1008
- parsed.limit = next_arg(args, &mut i).and_then(|v| v.parse::<usize>().ok())
1009
- }
1010
- "--gate" => parsed.gate = next_arg(args, &mut i),
1011
- "--comms" => parsed.comms = true,
1012
- "--fix" => parsed.fix = true,
1013
- "--fix-schema" => parsed.fix_schema = true,
1014
- "--cleanup-orphans" => parsed.cleanup_orphans = true,
1015
- "--once" => parsed.once = true,
1016
- "--tick-interval" => {
1017
- parsed.tick_interval = next_arg(args, &mut i).and_then(|v| v.parse::<f64>().ok())
1018
- }
1019
- "--status" => parsed.status_value = next_arg(args, &mut i),
1020
- "--search" => parsed.search = next_arg(args, &mut i),
1021
- "--file" => parsed.file = next_arg(args, &mut i).map(PathBuf::from),
1022
- "--result" => parsed.result = next_arg(args, &mut i),
1023
- "--assignee" => parsed.assignee = next_arg(args, &mut i),
1024
- "--auth-mode" => parsed.auth_mode = next_arg(args, &mut i),
1025
- "--proxy-mode" => parsed.proxy_mode = next_arg(args, &mut i),
1026
- "--pane" => parsed.pane = next_arg(args, &mut i),
1027
- "--to-name" => parsed.to_name = next_arg(args, &mut i),
1028
- "--to-leader" => parsed.to_leader = next_arg(args, &mut i),
1029
- "--provider" => parsed.provider = next_arg(args, &mut i),
1030
- "--socket" => parsed.socket = next_arg(args, &mut i),
1031
- "--dialect" => parsed.dialect = next_arg(args, &mut i),
1032
- "--thread-id" => parsed.thread_id = next_arg(args, &mut i),
1033
- "--message-id" => parsed.message_id = next_arg(args, &mut i),
1034
- "--mailbox" => parsed.mailbox = true,
1035
- "--presentation-sink" => parsed.presentation_sink = next_arg(args, &mut i),
1036
- "--message-class" => parsed.message_class = next_arg(args, &mut i),
1037
- "--case-id" => parsed.case_id = next_arg(args, &mut i),
1038
- "--content" => parsed.content = next_arg(args, &mut i),
1039
- "--primary-error" => parsed.primary_error = next_arg(args, &mut i),
1040
- "--result-json" => parsed.result_json = next_arg(args, &mut i),
1041
- "-h" | "--help" => {}
1042
- other if other.starts_with("--team=") => {
1043
- parsed.team = Some(other.trim_start_matches("--team=").to_string());
1044
- }
1045
- other if other.starts_with("--proxy-mode=") => {
1046
- parsed.proxy_mode = Some(other.trim_start_matches("--proxy-mode=").to_string());
1047
- }
1048
- other if other.starts_with("--pane=") => {
1049
- parsed.pane = Some(other.trim_start_matches("--pane=").to_string());
1050
- }
1051
- other if other.starts_with("--to-name=") => {
1052
- parsed.to_name = Some(other.trim_start_matches("--to-name=").to_string());
1053
- }
1054
- other if other.starts_with("--to-leader=") => {
1055
- parsed.to_leader = Some(other.trim_start_matches("--to-leader=").to_string());
1056
- }
1057
- other if other.starts_with("--presentation-sink=") => {
1058
- parsed.presentation_sink =
1059
- Some(other.trim_start_matches("--presentation-sink=").to_string());
1060
- }
1061
- other if other.starts_with("--message-class=") => {
1062
- parsed.message_class =
1063
- Some(other.trim_start_matches("--message-class=").to_string());
1064
- }
1065
- other if other.starts_with("--case-id=") => {
1066
- parsed.case_id = Some(other.trim_start_matches("--case-id=").to_string());
1067
- }
1068
- other if other.starts_with("--provider=") => {
1069
- parsed.provider = Some(other.trim_start_matches("--provider=").to_string());
1070
- }
1071
- other if other.starts_with("--search=") => {
1072
- parsed.search = Some(other.trim_start_matches("--search=").to_string());
1073
- }
1074
- other if other.starts_with("--socket=") => {
1075
- parsed.socket = Some(other.trim_start_matches("--socket=").to_string());
1076
- }
1077
- other if other.starts_with("--thread-id=") => {
1078
- parsed.thread_id = Some(other.trim_start_matches("--thread-id=").to_string());
1079
- }
1080
- other if other.starts_with('-') => {}
1081
- other => parsed.positionals.push(other.to_string()),
1082
- }
1083
- i = i.saturating_add(1);
1084
- }
1085
- parsed
1086
- }
1087
-
1088
- fn next_arg(args: &[String], index: &mut usize) -> Option<String> {
1089
- *index = index.saturating_add(1);
1090
- args.get(*index).cloned()
1091
- }
1092
-
1093
- pub(super) fn parse_seconds_ms(raw: &str) -> Option<u64> {
1094
- let seconds = raw.parse::<f64>().ok()?;
1095
- if seconds.is_finite() && seconds >= 0.0 {
1096
- Some((seconds * 1000.0).round() as u64)
1097
- } else {
1098
- None
1099
- }
1100
- }
1101
-
1102
- fn parse_cli_provider(raw: &str) -> Result<crate::provider::Provider, CliError> {
1103
- serde_json::from_value::<crate::provider::Provider>(serde_json::json!(raw))
1104
- .map_err(|_| CliError::Usage(format!("unknown provider: {raw}")))
1105
- }
1106
-
1107
- pub(super) fn explicit_path(value: &str) -> bool {
1108
- value == "." || value == ".." || value.contains('/') || value.contains('\\')
1109
- || Path::new(value).is_absolute()
1110
- || (value.as_bytes().get(1) == Some(&b':') && value.as_bytes().first().is_some_and(u8::is_ascii_alphabetic))
1111
- }
1112
-
1113
- fn checked_workspace(path: &Path, cwd: &Path) -> Result<PathBuf, CliError> {
1114
- let path = resolve_cli_path(cwd, path);
1115
- let canonical = std::fs::canonicalize(&path).map_err(|_| CliError::Usage(format!(
1116
- "workspace does not exist or is unavailable: {}", path.display()
1117
- )))?;
1118
- if !canonical.is_dir() {
1119
- return Err(CliError::Usage(format!("workspace is not a directory: {}", path.display())));
1120
- }
1121
- Ok(canonical)
1122
- }
1123
-
1124
- fn resolve_command_scope(command: &str, mut args: Vec<String>, cwd: &Path) -> Result<Vec<String>, CliError> {
1125
- let mut selected = None;
1126
- for argument in &mut args {
1127
- if argument == "--" { break; }
1128
- if let Some(path) = argument.strip_prefix("--workspace=") {
1129
- let canonical = checked_workspace(Path::new(path), cwd)?;
1130
- *argument = format!("--workspace={}", canonical.display());
1131
- selected = Some(canonical);
1132
- }
1133
- }
1134
- if command == "restart" {
1135
- let index = args.iter().position(|arg| arg == "--")
1136
- .and_then(|index| (index + 1 < args.len()).then_some(index + 1))
1137
- .or_else(|| args.iter().position(|arg| !arg.starts_with('-')));
1138
- if let Some(index) = index {
1139
- if !explicit_path(&args[index]) {
1140
- return Err(CliError::Usage("bare restart targets are ambiguous; use restart --workspace PATH or restart ./PATH for a team".to_string()));
1141
- }
1142
- let canonical = checked_workspace(Path::new(&args[index]), cwd)?;
1143
- if selected.as_ref().is_some_and(|selected| selected != &canonical) {
1144
- return Err(CliError::Usage("restart WORKSPACE conflicts with --workspace".to_string()));
1145
- }
1146
- args[index] = canonical.to_string_lossy().into_owned();
1147
- }
1148
- }
1149
- Ok(args)
1150
- }
1151
-
1152
- fn workspace(parsed: &ParsedArgs, cwd: &Path) -> PathBuf {
1153
- parsed
1154
- .workspace
1155
- .clone()
1156
- .unwrap_or_else(|| cwd.to_path_buf())
1157
- }
1158
-
1159
- fn required_pos(parsed: &ParsedArgs, index: usize, name: &str) -> Result<String, CliError> {
1160
- parsed
1161
- .positionals
1162
- .get(index)
1163
- .cloned()
1164
- .ok_or_else(|| CliError::Usage(format!("missing {name}")))
1165
- }
1166
-
1167
- fn quick_start_args(args: &[String], cwd: &Path) -> Result<QuickStartArgs, CliError> {
1168
- if has_arg(args, "--fresh") {
1169
- return Err(CliError::Usage(
1170
- "quick-start no longer accepts --fresh. Reset semantics moved to \
1171
- `team-agent restart --allow-fresh`, which requires explicit user \
1172
- confirmation."
1173
- .to_string(),
1174
- ));
1175
- }
1176
- let parsed = parse_args(args);
1177
- let explicit_workspace = parsed
1178
- .workspace
1179
- .as_deref()
1180
- .map(|path| resolve_cli_path(cwd, path));
1181
- let positional_agents_dir = parsed.positionals.first().map(PathBuf::from).map(|path| {
1182
- if path.is_absolute() {
1183
- path
1184
- } else if let Some(workspace) = explicit_workspace.as_ref() {
1185
- workspace.join(path)
1186
- } else {
1187
- cwd.join(path)
1188
- }
1189
- });
1190
- let workspace = explicit_workspace
1191
- .or_else(|| {
1192
- let path = positional_agents_dir.as_ref()?;
1193
- if let Some(run_workspace) = path
1194
- .ancestors()
1195
- .find(|ancestor| {
1196
- ancestor.file_name().and_then(|name| name.to_str()) == Some(".team")
1197
- })
1198
- .and_then(Path::parent)
1199
- {
1200
- return Some(run_workspace.to_path_buf());
1201
- }
1202
- path.join("TEAM.md").is_file().then(|| path.to_path_buf())
1203
- })
1204
- .unwrap_or_else(|| cwd.to_path_buf());
1205
- // A positional team directory containing TEAM.md is a complete standalone
1206
- // workspace. Use it as the runtime workspace unless --workspace explicitly
1207
- // selects another root; this prevents host owner context/state leaking into
1208
- // an independent quick-start target.
1209
- let agents_dir = positional_agents_dir.unwrap_or_else(|| workspace.clone());
1210
- // 0.5.x Phase 1d Batch 2: validate the `--backend` literal up-front
1211
- // so users get a fast, actionable error instead of a downstream
1212
- // factory refusal. Accept the same literals as the factory
1213
- // `RequestedTransportBackend::parse_literal`.
1214
- if let Some(literal) = parsed.backend.as_deref() {
1215
- let normalized = literal.trim().to_ascii_lowercase();
1216
- if normalized != "tmux" && normalized != "conpty" {
1217
- return Err(CliError::Usage(format!(
1218
- "--backend must be tmux or conpty; received {literal:?}. Use tmux on POSIX. ConPTY requires a Windows host and an installed shim."
1219
- )));
1220
- }
1221
- }
1222
- Ok(QuickStartArgs {
1223
- workspace,
1224
- agents_dir,
1225
- name: parsed.name,
1226
- team_id: parsed.team_id.or(parsed.team),
1227
- yes: parsed.yes,
1228
- json: parsed.json,
1229
- detail: parsed.detail,
1230
- backend: parsed.backend,
1231
- })
1232
- }
1233
-
1234
- fn models_args(args: &[String]) -> Result<ModelsArgs, CliError> {
1235
- let parsed = parse_args(args);
1236
- let provider = parsed.provider.unwrap_or_else(|| "pi".to_string());
1237
- if parsed.search.is_some() && !parsed.positionals.is_empty() {
1238
- return Err(CliError::Usage(
1239
- "models accepts either QUERY or --search TEXT, not both".to_string(),
1240
- ));
1241
- }
1242
- let search = parsed
1243
- .search
1244
- .or_else(|| (!parsed.positionals.is_empty()).then(|| parsed.positionals.join(" ")))
1245
- .filter(|query| !query.trim().is_empty());
1246
- Ok(ModelsArgs {
1247
- provider,
1248
- search,
1249
- json: parsed.json,
1250
- })
1251
- }
1252
-
1253
- fn resolve_cli_path(cwd: &Path, path: &Path) -> PathBuf {
1254
- if path.is_absolute() {
1255
- path.to_path_buf()
1256
- } else {
1257
- cwd.join(path)
1258
- }
1259
- }
1260
-
1261
- fn send_args(args: &[String], cwd: &Path) -> Result<SendArgs, CliError> {
1262
- validate_send_flags(args)?;
1263
- warn_send_legacy_delivery_flags(args);
1264
- let parsed = parse_args(args);
1265
- if parsed.targets.is_none()
1266
- && parsed.pane.is_none()
1267
- && parsed.to_name.is_none()
1268
- && parsed.to_leader.is_none()
1269
- && parsed.positionals.len() < 2
1270
- {
1271
- return Err(CliError::Usage(
1272
- "Provide a recipient agent name and task message, such as team-agent send worker 'Review the changes'".to_string(),
1273
- ));
1274
- }
1275
- let target = if parsed.targets.is_some()
1276
- || parsed.pane.is_some()
1277
- || parsed.to_name.is_some()
1278
- || parsed.to_leader.is_some()
1279
- {
1280
- None
1281
- } else {
1282
- parsed.positionals.first().cloned()
1283
- };
1284
- let message_start = usize::from(target.is_some());
1285
- let workspace = workspace(&parsed, cwd);
1286
- let sender = trusted_cli_sender(&workspace, parsed.team.as_deref())?;
1287
- let presentation_value = if parsed.presentation_sink.is_some()
1288
- || parsed.message_class.is_some()
1289
- || parsed.case_id.is_some()
1290
- {
1291
- Some(serde_json::json!({
1292
- "sink": parsed.presentation_sink.clone(),
1293
- "class": parsed.message_class.clone(),
1294
- "case_id": parsed.case_id.clone(),
1295
- }))
1296
- } else {
1297
- None
1298
- };
1299
- let mailbox_value = parsed.mailbox.then(|| serde_json::json!(true));
1300
- let normalized = crate::messaging::presentation::normalize_send_presentation(
1301
- mailbox_value.as_ref(),
1302
- presentation_value.as_ref(),
1303
- )
1304
- .map_err(|error| CliError::Usage(format!("invalid send routing: {error}")))?;
1305
- if normalized.deprecation.is_some() {
1306
- eprintln!("Warning: legacy send settings are deprecated. Use team-agent send <agent> 'task message'; add --mailbox for storage without injection.");
1307
- }
1308
- Ok(SendArgs {
1309
- target,
1310
- message: parsed
1311
- .positionals
1312
- .iter()
1313
- .skip(message_start)
1314
- .cloned()
1315
- .collect(),
1316
- targets: parsed.targets,
1317
- workspace,
1318
- team: parsed.team,
1319
- task: None,
1320
- sender,
1321
- no_ack: false,
1322
- no_wait: true,
1323
- watch_result: false,
1324
- timeout: 0.0,
1325
- confirm_human: false,
1326
- json: parsed.json,
1327
- message_id: None,
1328
- presentation: normalized.request,
1329
- pane: parsed.pane.clone(),
1330
- to_name: parsed.to_name.clone(),
1331
- to_leader: parsed.to_leader.clone(),
1332
- })
1333
- }
1334
-
1335
- fn trusted_cli_sender(workspace: &Path, team: Option<&str>) -> Result<TrustedSender, CliError> {
1336
- let agent_id = std::env::var("TEAM_AGENT_ID")
1337
- .ok()
1338
- .map(|value| value.trim().to_string())
1339
- .filter(|value| !value.is_empty());
1340
- let worker_context = ["TEAM_AGENT_OWNER_TEAM_ID", "TEAM_AGENT_AGENT_ID"]
1341
- .into_iter()
1342
- .any(|key| {
1343
- std::env::var(key)
1344
- .ok()
1345
- .is_some_and(|value| !value.trim().is_empty())
1346
- });
1347
- let Some(agent_id) = agent_id else {
1348
- if worker_context {
1349
- return Err(CliError::Usage(
1350
- "send requires framework-injected TEAM_AGENT_ID; refusing leader identity fallback"
1351
- .to_string(),
1352
- ));
1353
- }
1354
- return Ok(TrustedSender::leader());
1355
- };
1356
- let source_workspace = std::env::var("TEAM_AGENT_WORKSPACE")
1357
- .ok()
1358
- .filter(|value| !value.trim().is_empty())
1359
- .unwrap_or_else(|| workspace.display().to_string());
1360
- let source_team = std::env::var("TEAM_AGENT_OWNER_TEAM_ID")
1361
- .ok()
1362
- .or_else(|| std::env::var("TEAM_AGENT_TEAM_ID").ok())
1363
- .or_else(|| team.map(ToOwned::to_owned))
1364
- .filter(|value| !value.trim().is_empty())
1365
- .unwrap_or_else(|| "unknown".to_string());
1366
- Ok(TrustedSender::from_runtime_identity_with_source(
1367
- crate::model::ids::AgentId::new(agent_id),
1368
- source_workspace,
1369
- &source_team,
1370
- ))
1371
- }
1372
-
1373
- fn warn_send_legacy_delivery_flags(args: &[String]) {
1374
- const FLAGS: &[&str] = &[
1375
- "--task",
1376
- "--watch-result",
1377
- "--requires-ack",
1378
- "--no-ack",
1379
- "--no-wait",
1380
- "--timeout",
1381
- "--confirm-human",
1382
- "--message-id",
1383
- ];
1384
- let spec = command_spec("send");
1385
- let sunset = spec
1386
- .and_then(|spec| spec.sunset)
1387
- .unwrap_or("a future compatibility release");
1388
- let action = spec.and_then(|spec| spec.action).unwrap_or(
1389
- "Use team-agent send <agent> 'task message'; select scope with --workspace/--team",
1390
- );
1391
- for flag in FLAGS {
1392
- if args
1393
- .iter()
1394
- .take_while(|arg| arg.as_str() != "--")
1395
- .any(|arg| arg == flag || arg.starts_with(&format!("{flag}=")))
1396
- {
1397
- eprintln!(
1398
- "Warning: {flag} is deprecated and will be removed in {sunset}. Next: {action}"
1399
- );
1400
- }
1401
- }
1402
- }
1403
-
1404
- fn validate_send_flags(args: &[String]) -> Result<(), CliError> {
1405
- super::arguments::parse("send", args).map(|_| ())
1406
- }
1407
-
1408
- /// Stage 4 of identity-boundary unified plan (architect direction
1409
- /// 2026-06-24, .team/artifacts/identity-boundary-unified-plan.md §2 Stage
1410
- /// 4): destructive command ambiguity gate. When the workspace has 2+
1411
- /// alive teams and the caller did not pass `--team`, refuse with a
1412
- /// usage error listing the candidates so the operator picks explicitly.
1413
- /// Single-team workspaces (the 0.4.x baseline) are unaffected — the
1414
- /// `CommandScope::resolve` helper returns `Resolved` and this function
1415
- /// is a no-op.
1416
- fn refuse_if_multi_alive_team_missing_scope(
1417
- command: &str,
1418
- workspace: &Path,
1419
- requested_team: Option<&str>,
1420
- ) -> Result<(), CliError> {
1421
- let scope = crate::state::paths::CommandScope::resolve(workspace, requested_team);
1422
- if scope.is_ambiguous() {
1423
- let candidates = scope.candidates().join(", ");
1424
- return Err(CliError::Usage(format!(
1425
- "{command}: workspace has multiple alive teams ({candidates}); \
1426
- pass `--team <key>` to choose one (refusing to default to any \
1427
- single team — Stage 4 identity-boundary contract)"
1428
- )));
1429
- }
1430
- Ok(())
1431
- }
1432
-
1433
- fn status_args(args: &[String], cwd: &Path) -> StatusArgs {
1434
- let parsed = parse_args(args);
1435
- StatusArgs {
1436
- agent: parsed.positionals.first().cloned(),
1437
- workspace: workspace(&parsed, cwd),
1438
- detail: parsed.detail,
1439
- summary: parsed.summary,
1440
- json: parsed.json,
1441
- team: parsed.team,
1442
- }
1443
- }
1444
-
1445
- fn wait_args(args: &[String], cwd: &Path) -> Result<WaitArgs, CliError> {
1446
- let parsed = parse_args(args);
1447
- let workspace = workspace(&parsed, cwd);
1448
- Ok(WaitArgs {
1449
- task_id: parsed
1450
- .task
1451
- .ok_or_else(|| CliError::Usage("wait requires --task <id>".to_string()))?,
1452
- workspace,
1453
- json: parsed.json,
1454
- })
1455
- }
1456
-
1457
- fn approvals_args(args: &[String], cwd: &Path) -> ApprovalsArgs {
1458
- let parsed = parse_args(args);
1459
- ApprovalsArgs {
1460
- agent: parsed.positionals.first().cloned(),
1461
- workspace: workspace(&parsed, cwd),
1462
- json: parsed.json,
1463
- team: parsed.team,
1464
- }
1465
- }
1466
-
1467
- fn inbox_args(args: &[String], cwd: &Path) -> Result<InboxArgs, CliError> {
1468
- if args
1469
- .iter()
1470
- .any(|arg| arg == "--since" || arg.starts_with("--since="))
1471
- {
1472
- return Err(CliError::Usage(
1473
- "inbox only supports -n/--limit; --since is not supported".to_string(),
1474
- ));
1475
- }
1476
- let parsed = parse_args(args);
1477
- Ok(InboxArgs {
1478
- agent: required_pos(&parsed, 0, "agent")?,
1479
- workspace: workspace(&parsed, cwd),
1480
- limit: parsed.limit.unwrap_or(3),
1481
- json: parsed.json,
1482
- team: parsed.team,
1483
- })
1484
- }
1485
-
1486
- fn takeover_args(args: &[String], cwd: &Path) -> TakeoverArgs {
1487
- let parsed = parse_args(args);
1488
- TakeoverArgs {
1489
- workspace: workspace(&parsed, cwd),
1490
- team: parsed.team,
1491
- confirm: parsed.confirm,
1492
- json: parsed.json,
1493
- }
1494
- }
1495
-
1496
- fn claim_leader_args(args: &[String], cwd: &Path) -> ClaimLeaderArgs {
1497
- let parsed = parse_args(args);
1498
- ClaimLeaderArgs {
1499
- workspace: workspace(&parsed, cwd),
1500
- team: parsed.team,
1501
- confirm: parsed.confirm,
1502
- json: parsed.json,
1503
- detail: parsed.detail,
1504
- }
1505
- }
1506
-
1507
- fn attach_leader_args(args: &[String], cwd: &Path) -> Result<AttachLeaderArgs, CliError> {
1508
- let parsed = parse_args(args);
1509
- Ok(AttachLeaderArgs {
1510
- workspace: workspace(&parsed, cwd),
1511
- team: parsed.team,
1512
- pane: parsed
1513
- .pane
1514
- .filter(|pane| !pane.is_empty())
1515
- .map(crate::transport::PaneId::new),
1516
- provider: parse_cli_provider(parsed.provider.as_deref()
1517
- .filter(|provider| !provider.trim().is_empty())
1518
- .ok_or_else(|| CliError::Usage("attach-leader requires --provider <name>".to_string()))?)?,
1519
- confirm: parsed.confirm,
1520
- json: parsed.json,
1521
- })
1522
- }
1523
-
1524
- fn attach_app_server_leader_args(
1525
- args: &[String],
1526
- cwd: &Path,
1527
- ) -> Result<AttachAppServerLeaderArgs, CliError> {
1528
- let parsed = parse_args(args);
1529
- Ok(AttachAppServerLeaderArgs {
1530
- workspace: workspace(&parsed, cwd),
1531
- team: parsed.team,
1532
- socket: parsed
1533
- .socket
1534
- .filter(|socket| !socket.is_empty())
1535
- .ok_or_else(|| CliError::Usage("missing --socket".to_string()))?,
1536
- thread_id: parsed
1537
- .thread_id
1538
- .filter(|thread_id| !thread_id.is_empty())
1539
- .ok_or_else(|| CliError::Usage("missing --thread-id".to_string()))?,
1540
- json: parsed.json,
1541
- })
1542
- }
1543
-
1544
- fn shutdown_args(args: &[String], cwd: &Path) -> Result<ShutdownArgs, CliError> {
1545
- let parsed = parse_args(args);
1546
- let workspace = workspace(&parsed, cwd);
1547
- refuse_if_multi_alive_team_missing_scope("shutdown", &workspace, parsed.team.as_deref())?;
1548
- Ok(ShutdownArgs {
1549
- workspace,
1550
- team: parsed.team,
1551
- keep_logs: parsed.keep_logs,
1552
- json: parsed.json,
1553
- })
1554
- }
1555
-
1556
- fn restart_args(args: &[String], cwd: &Path) -> Result<RestartArgs, CliError> {
1557
- let parsed = parse_args(args);
1558
- let workspace = if let Some(path) = parsed.positionals.first() {
1559
- if !explicit_path(path) {
1560
- return Err(CliError::Usage("bare restart targets are ambiguous; use restart --workspace PATH or restart ./PATH for a team".to_string()));
1561
- }
1562
- resolve_cli_path(cwd, Path::new(path))
1563
- } else { workspace(&parsed, cwd) };
1564
- refuse_if_multi_alive_team_missing_scope("restart", &workspace, parsed.team.as_deref())?;
1565
- Ok(RestartArgs {
1566
- workspace,
1567
- team: parsed.team,
1568
- allow_fresh: parsed.allow_fresh,
1569
- session_converge_deadline_ms: parsed.session_converge_deadline_ms,
1570
- json: parsed.json,
1571
- detail: parsed.detail,
1572
- })
1573
- }
1574
-
1575
- // Keep strict role CLI parsing separate from the legacy shared parser.
1576
- pub(super) fn intent_source_workspace(source: &Path, cwd: &Path) -> Result<PathBuf, CliError> {
1577
- quick_start_args(&[source.to_string_lossy().into_owned()], cwd).map(|args| args.workspace)
1578
- }
1579
-
1580
- pub(super) fn intent_role_patch(args: &[String]) -> Result<crate::lifecycle::role_config::RoleConfigPatch, CliError> {
1581
- role_agent_args(args, false).map(|(_, patch)| patch)
1582
- }
1583
-
1584
- /// Explicit object aliases reuse the same syntax checks, typed builders and handlers.
1585
- pub(super) fn intent_alias(command: &str, args: &[String], cwd: &Path) -> Result<CmdResult, CliError> {
1586
- let mut checked = prepare_control_args(command, args, cwd)?;
1587
- if checked.help { return Ok(CmdResult::human(command_help(Some(command)))); }
1588
- for token in &mut checked.tokens {
1589
- if let Some(path) = token.strip_prefix("--role-file=") {
1590
- let path = Path::new(path);
1591
- let path = if path.is_absolute() { path.to_path_buf() } else { cwd.join(path) };
1592
- let path = path.canonicalize().map_err(|e| CliError::Usage(format!("invalid explicit role file: {e}")))?;
1593
- *token = format!("--role-file={}", path.display());
1594
- }
1595
- }
1596
- let args = checked.tokens.as_slice();
1597
- match command {
1598
- "status" => {
1599
- let parsed = status_args(args, cwd);
1600
- cmd_status_for_team(&parsed, parsed.team.as_deref())
1601
- }
1602
- "add-agent" => cmd_add_agent(&add_agent_args(args, cwd)?),
1603
- "remove-agent" => cmd_remove_agent(&remove_agent_args(args, cwd)?),
1604
- "reset-agent" => cmd_reset_agent(&reset_agent_args(args, cwd)?),
1605
- "clone-agent" => cmd_clone_agent(&clone_agent_args(args, cwd)?),
1606
- "fork-agent" => cmd_fork_agent(&fork_agent_args(args, cwd)?),
1607
- _ => Err(CliError::Usage("unsupported lifecycle alias".into())),
1608
- }
1609
- }
1610
-
1611
- fn role_agent_args(
1612
- args: &[String],
1613
- add: bool,
1614
- ) -> Result<(ParsedArgs, crate::lifecycle::role_config::RoleConfigPatch), CliError> {
1615
- let mut role = crate::lifecycle::role_config::RoleConfigPatch::default();
1616
- let mut forwarded = Vec::new();
1617
- let mut seen = std::collections::BTreeSet::new();
1618
- let mut index = 0;
1619
- while index < args.len() {
1620
- let argument = &args[index];
1621
- if !argument.starts_with('-') {
1622
- forwarded.push(argument.clone());
1623
- index += 1;
1624
- continue;
1625
- }
1626
- let (flag, inline) = argument
1627
- .split_once('=')
1628
- .map_or((argument.as_str(), None), |(key, value)| (key, Some(value)));
1629
- if !seen.insert(flag.to_string()) {
1630
- return Err(CliError::Usage(format!("duplicate {flag}")));
1631
- }
1632
- if matches!(flag, "--json" | "--allow-fresh" | "--force") {
1633
- if inline.is_some() || (add && flag == "--allow-fresh") {
1634
- return Err(CliError::Usage(format!("unsupported option: {argument}")));
1635
- }
1636
- forwarded.push(flag.to_string());
1637
- index += 1;
1638
- continue;
1639
- }
1640
- if !matches!(
1641
- flag,
1642
- "--provider"
1643
- | "--model"
1644
- | "--effort"
1645
- | "--bypass"
1646
- | "--prompt"
1647
- | "--profile"
1648
- | "--workspace"
1649
- | "--team"
1650
- | "--role-file"
1651
- ) || (!add && flag == "--role-file")
1652
- {
1653
- return Err(CliError::Usage(format!("unknown option: {flag}")));
1654
- }
1655
- let value = if let Some(value) = inline {
1656
- value.to_string()
1657
- } else {
1658
- index += 1;
1659
- args.get(index)
1660
- .filter(|value| flag == "--prompt" || !value.starts_with("--"))
1661
- .ok_or_else(|| CliError::Usage(format!("missing value for {flag}")))?
1662
- .clone()
1663
- };
1664
- if value.trim().is_empty() {
1665
- return Err(CliError::Usage(format!("empty value for {flag}")));
1666
- }
1667
- match flag {
1668
- "--provider" => {
1669
- // A contract name is written as the leaf's public name (`agent` →
1670
- // `cursor`, `codex_cli` → `codex`); it declares the same leaf.
1671
- #[cfg(unix)]
1672
- let contract = crate::contract_runtime::registry::declared(&value)
1673
- .map(crate::contract_runtime::registry::public_name);
1674
- #[cfg(not(unix))]
1675
- let contract: Option<&str> = None;
1676
- let provider = match contract {
1677
- Some(id) => id,
1678
- None => crate::provider::wire::provider_wire(
1679
- crate::provider::wire::parse_provider(&value)
1680
- .ok_or_else(|| CliError::Usage(format!("unknown provider: {value}")))?,
1681
- ),
1682
- };
1683
- role.provider = Some(provider.to_string());
1684
- }
1685
- "--bypass" => {
1686
- role.bypass = Some(match value.as_str() {
1687
- "true" => true,
1688
- "false" => false,
1689
- _ => return Err(CliError::Usage("--bypass requires true or false".into())),
1690
- })
1691
- }
1692
- "--model" => role.model = Some(value),
1693
- "--effort" => {
1694
- if crate::model::enums::ProviderEffort::parse(&value).is_none() {
1695
- return Err(CliError::Usage(format!("unknown effort: {value}")));
1696
- }
1697
- role.effort = Some(value);
1698
- }
1699
- "--prompt" => role.prompt = Some(value),
1700
- "--profile" => role.profile = Some(value),
1701
- _ => {
1702
- forwarded.push(flag.to_string());
1703
- forwarded.push(value);
1704
- }
1705
- }
1706
- index += 1;
1707
- }
1708
- let parsed = parse_args(&forwarded);
1709
- if add && parsed.role_file.is_none() {
1710
- if role.provider.is_none() {
1711
- return Err(CliError::Usage(
1712
- "add-agent requires --provider <name>".into(),
1713
- ));
1714
- }
1715
- }
1716
- if parsed.positionals.len() != 1 {
1717
- return Err(CliError::Usage(
1718
- if parsed.positionals.is_empty() {
1719
- "missing agent"
1720
- } else {
1721
- "expected exactly one agent id"
1722
- }
1723
- .into(),
1724
- ));
1725
- }
1726
- Ok((parsed, role))
1727
- }
1728
-
1729
- #[cfg(test)]
1730
- mod role_cli_tests {
1731
- use super::*;
1732
- fn strings(values: &[&str]) -> Vec<String> {
1733
- values.iter().map(|value| (*value).to_string()).collect()
1734
- }
1735
-
1736
- #[test]
1737
- fn add_requires_provider_without_a_template_but_accepts_file_input() {
1738
- for args in [
1739
- vec!["w"],
1740
- vec!["w", "--bypass", "false"],
1741
- ] {
1742
- assert!(role_agent_args(&strings(&args), true).is_err());
1743
- }
1744
- assert!(role_agent_args(&strings(&["w", "--role-file", "w.md"]), true).is_ok());
1745
- let (parsed, _) =
1746
- role_agent_args(&strings(&["w", "--role-file", "w.md", "--force"]), true).unwrap();
1747
- assert!(parsed.force);
1748
- assert!(role_agent_args(
1749
- &strings(&["w", "--role-file", "w.md", "--force=true"]),
1750
- true
1751
- )
1752
- .is_err());
1753
- assert!(role_agent_args(
1754
- &strings(&["w", "--role-file", "w.md", "--allow-fresh"]),
1755
- true
1756
- )
1757
- .is_err());
1758
- let (_, patch) =
1759
- role_agent_args(&strings(&["w", "--provider=pi", "--bypass=false"]), true).unwrap();
1760
- assert_eq!(patch.provider.as_deref(), Some("pi"));
1761
- assert_eq!(patch.bypass, Some(false));
1762
- }
1763
-
1764
- #[cfg(unix)]
1765
- #[test]
1766
- fn provider_accepts_contract_names_as_their_leaf_id() {
1767
- for (name, leaf) in [
1768
- ("cursor", "cursor"), ("cursor-agent", "cursor"), ("agent", "cursor"),
1769
- ("cursor_agent", "cursor"), ("kiro", "kiro"),
1770
- // Codex and Grok Build keep their public command names, which
1771
- // declare the leaf.
1772
- ("codex", "codex"), ("codex_cli", "codex"), ("codex-cli", "codex"),
1773
- ("codex_tui", "codex"), ("grok", "grok"), ("grok_build", "grok"),
1774
- ] {
1775
- let (_, patch) = role_agent_args(
1776
- &strings(&["w", "--provider", name, "--bypass", "true"]), true,
1777
- ).unwrap_or_else(|error| panic!("{name}: {error}"));
1778
- assert_eq!(patch.provider.as_deref(), Some(leaf), "{name}");
1779
- }
1780
- assert!(role_agent_args(&strings(&["w", "--provider", "Cursor", "--bypass", "true"]), true).is_err());
1781
- }
1782
-
1783
- #[test]
1784
- fn add_accepts_bypass_true_false_or_omission_for_every_provider() {
1785
- for &provider in crate::provider::wire::all_providers() {
1786
- let provider = crate::provider::wire::provider_wire(provider);
1787
- let (_, patch) = role_agent_args(&strings(&["w", "--provider", provider]), true).unwrap();
1788
- assert_eq!(patch.bypass, None);
1789
- for bypass in ["true", "false"] {
1790
- let (_, patch) = role_agent_args(
1791
- &strings(&["w", "--provider", provider, "--bypass", bypass]),
1792
- true,
1793
- )
1794
- .unwrap();
1795
- assert_eq!(patch.bypass, Some(bypass == "true"));
1796
- }
1797
- }
1798
- }
1799
-
1800
- #[test]
1801
- fn strict_role_options_reject_ambiguous_values() {
1802
- for args in [
1803
- vec!["w", "--bypass"],
1804
- vec!["w", "--bypass", "yes"],
1805
- vec!["w", "--no-bypass"],
1806
- vec!["w", "--bypass", "true", "--bypass=false"],
1807
- vec!["w", "--unknown", "x"],
1808
- vec!["w", "extra"],
1809
- ] {
1810
- assert!(role_agent_args(&strings(&args), false).is_err());
1811
- }
1812
- let (_, patch) = role_agent_args(&strings(&["w"]), false).unwrap();
1813
- assert_eq!(
1814
- patch,
1815
- crate::lifecycle::role_config::RoleConfigPatch::default()
1816
- );
1817
- }
1818
- }
1819
-
1820
- fn start_agent_args(args: &[String], cwd: &Path) -> Result<StartAgentArgs, CliError> {
1821
- let (parsed, role_config) = role_agent_args(args, false)?;
1822
- if parsed.force {
1823
- return Err(CliError::Usage("start-agent does not support --force; use stop-agent AGENT followed by start-agent AGENT for a safe restart".to_string()));
1824
- }
1825
- Ok(StartAgentArgs {
1826
- role_config,
1827
- agent: required_pos(&parsed, 0, "agent")?,
1828
- workspace: workspace(&parsed, cwd),
1829
- team: parsed.team,
1830
- force: parsed.force,
1831
- allow_fresh: parsed.allow_fresh,
1832
- json: parsed.json,
1833
- })
1834
- }
1835
-
1836
- fn stop_agent_args(args: &[String], cwd: &Path) -> Result<StopAgentArgs, CliError> {
1837
- let parsed = parse_args(args);
1838
- Ok(StopAgentArgs {
1839
- agent: required_pos(&parsed, 0, "agent")?,
1840
- workspace: workspace(&parsed, cwd),
1841
- team: parsed.team,
1842
- json: parsed.json,
1843
- })
1844
- }
1845
-
1846
- fn reset_agent_args(args: &[String], cwd: &Path) -> Result<ResetAgentArgs, CliError> {
1847
- let parsed = parse_args(args);
1848
- let agent = required_pos(&parsed, 0, "agent")?;
1849
- if !parsed.discard_session {
1850
- return Err(CliError::Usage(
1851
- "missing --discard-session; add this option only after explicit authorization to discard the saved session association".to_string(),
1852
- ));
1853
- }
1854
- let workspace = workspace(&parsed, cwd);
1855
- refuse_if_multi_alive_team_missing_scope("reset-agent", &workspace, parsed.team.as_deref())?;
1856
- Ok(ResetAgentArgs {
1857
- agent,
1858
- workspace,
1859
- team: parsed.team,
1860
- discard_session: parsed.discard_session,
1861
- json: parsed.json,
1862
- })
1863
- }
1864
-
1865
- fn add_agent_args(args: &[String], cwd: &Path) -> Result<AddAgentArgs, CliError> {
1866
- let (parsed, role_config) = role_agent_args(args, true)?;
1867
- Ok(AddAgentArgs {
1868
- role_config,
1869
- agent: required_pos(&parsed, 0, "agent")?,
1870
- workspace: workspace(&parsed, cwd),
1871
- team: parsed.team,
1872
- role_file: parsed.role_file.unwrap_or_default(),
1873
- force: parsed.force,
1874
- json: parsed.json,
1875
- })
1876
- }
1877
-
1878
- fn fork_agent_args(args: &[String], cwd: &Path) -> Result<ForkAgentArgs, CliError> {
1879
- let parsed = parse_args(args);
1880
- Ok(ForkAgentArgs {
1881
- source_agent: required_pos(&parsed, 0, "source_agent")?,
1882
- workspace: workspace(&parsed, cwd),
1883
- team: parsed.team,
1884
- as_agent: parsed
1885
- .as_agent
1886
- .ok_or_else(|| CliError::Usage("missing --as".to_string()))?,
1887
- label: parsed.label,
1888
- json: parsed.json,
1889
- })
1890
- }
1891
-
1892
- fn clone_agent_args(args: &[String], cwd: &Path) -> Result<CloneAgentArgs, CliError> {
1893
- let parsed = parse_args(args);
1894
- Ok(CloneAgentArgs {
1895
- source_agent: required_pos(&parsed, 0, "source_agent")?,
1896
- workspace: workspace(&parsed, cwd),
1897
- team: parsed.team,
1898
- as_agent: parsed
1899
- .as_agent
1900
- .ok_or_else(|| CliError::Usage("missing --as".to_string()))?,
1901
- label: parsed.label,
1902
- json: parsed.json,
1903
- })
1904
- }
1905
-
1906
- fn remove_agent_args(args: &[String], cwd: &Path) -> Result<RemoveAgentArgs, CliError> {
1907
- let parsed = parse_args(args);
1908
- let agent = required_pos(&parsed, 0, "agent")?;
1909
- let workspace = workspace(&parsed, cwd);
1910
- refuse_if_multi_alive_team_missing_scope("remove-agent", &workspace, parsed.team.as_deref())?;
1911
- Ok(RemoveAgentArgs {
1912
- agent,
1913
- workspace,
1914
- team: parsed.team,
1915
- from_spec: parsed.from_spec,
1916
- confirm: parsed.confirm,
1917
- force: parsed.force,
1918
- json: parsed.json,
1919
- })
1920
- }
1921
-
1922
- fn doctor_args(args: &[String], cwd: &Path) -> DoctorArgs {
1923
- let parsed = parse_args(args);
1924
- DoctorArgs {
1925
- spec: parsed.positionals.first().map(PathBuf::from),
1926
- workspace: workspace(&parsed, cwd),
1927
- gate: doctor_gate(parsed.gate.as_deref()),
1928
- comms: parsed.comms,
1929
- team: parsed.team,
1930
- fix: parsed.fix,
1931
- fix_schema: parsed.fix_schema,
1932
- cleanup_orphans: parsed.cleanup_orphans,
1933
- confirm: parsed.confirm,
1934
- json: parsed.json,
1935
- }
1936
- }
1937
-
1938
- fn doctor_gate(raw: Option<&str>) -> Option<DoctorGate> {
1939
- match raw {
1940
- Some("orphans") => Some(DoctorGate::Orphans),
1941
- Some("comms") => Some(DoctorGate::Comms),
1942
- Some(other) => Some(DoctorGate::Unknown(other.to_string())),
1943
- None => None,
1944
- }
1945
- }
1946
-
1947
- fn leaders_args(args: &[String], _cwd: &Path) -> Result<LeadersArgs, CliError> {
1948
- let mut view = None;
1949
- let mut query = None;
1950
- let mut prune = false;
1951
- let mut dry_run = false;
1952
- let mut json = false;
1953
- let mut i = 0usize;
1954
- while i < args.len() {
1955
- let arg = &args[i];
1956
- match arg.as_str() {
1957
- "--json" => json = true,
1958
- "--all" => {
1959
- if view.replace(LeadersView::All).is_some() {
1960
- return Err(CliError::Usage(
1961
- "leaders accepts only one of --all or --stale".to_string(),
1962
- ));
1963
- }
1964
- }
1965
- "--stale" => {
1966
- if view.replace(LeadersView::Stale).is_some() {
1967
- return Err(CliError::Usage(
1968
- "leaders accepts only one of --all or --stale".to_string(),
1969
- ));
1970
- }
1971
- }
1972
- "--prune" => {
1973
- if prune {
1974
- return Err(CliError::Usage(
1975
- "leaders accepts --prune at most once".to_string(),
1976
- ));
1977
- }
1978
- prune = true;
1979
- }
1980
- "--dry-run" => dry_run = true,
1981
- "--search" => {
1982
- let Some(value) = args.get(i.saturating_add(1)) else {
1983
- return Err(CliError::Usage(
1984
- "leaders --search requires TEXT".to_string(),
1985
- ));
1986
- };
1987
- if value.starts_with('-') {
1988
- return Err(CliError::Usage(
1989
- "leaders --search requires TEXT".to_string(),
1990
- ));
1991
- }
1992
- i = i.saturating_add(1);
1993
- if query.replace(value.clone()).is_some() {
1994
- return Err(CliError::Usage(
1995
- "leaders accepts only one QUERY or --search TEXT".to_string(),
1996
- ));
1997
- }
1998
- }
1999
- value if value.starts_with("--search=") => {
2000
- let value = value.trim_start_matches("--search=").to_string();
2001
- if query.replace(value).is_some() {
2002
- return Err(CliError::Usage(
2003
- "leaders accepts only one QUERY or --search TEXT".to_string(),
2004
- ));
2005
- }
2006
- }
2007
- value if value.starts_with('-') => {
2008
- return Err(CliError::Usage(format!(
2009
- "unknown leaders argument: {value}"
2010
- )))
2011
- }
2012
- value => {
2013
- if query.replace(value.to_string()).is_some() {
2014
- return Err(CliError::Usage(
2015
- "leaders accepts only one QUERY or --search TEXT".to_string(),
2016
- ));
2017
- }
2018
- }
2019
- }
2020
- i = i.saturating_add(1);
2021
- }
2022
- if query
2023
- .as_deref()
2024
- .is_some_and(|value| value.trim().is_empty())
2025
- {
2026
- return Err(CliError::Usage("leaders QUERY cannot be blank".to_string()));
2027
- }
2028
- if prune && view.is_some() {
2029
- return Err(CliError::Usage(
2030
- "leaders --prune cannot be combined with --all or --stale".to_string(),
2031
- ));
2032
- }
2033
- if prune && query.is_some() {
2034
- return Err(CliError::Usage(
2035
- "leaders --prune cannot be combined with QUERY or --search".to_string(),
2036
- ));
2037
- }
2038
- if dry_run && !prune {
2039
- return Err(CliError::Usage(
2040
- "leaders --dry-run requires --prune".to_string(),
2041
- ));
2042
- }
2043
- Ok(LeadersArgs {
2044
- view: view.unwrap_or(LeadersView::Live),
2045
- query,
2046
- prune,
2047
- dry_run,
2048
- json,
2049
- })
2050
- }
2051
-
2052
- fn profile_args(args: &[String], cwd: &Path) -> Result<ProfileArgs, CliError> {
2053
- let parsed = parse_args(args);
2054
- let workspace = resolve_cli_path(cwd, &workspace(&parsed, cwd));
2055
- Ok(ProfileArgs {
2056
- command: required_pos(&parsed, 0, "profile command")?,
2057
- name: required_pos(&parsed, 1, "profile name")?,
2058
- workspace: resolve_path(&workspace),
2059
- team: parsed.team,
2060
- auth_mode: parsed.auth_mode,
2061
- proxy_mode: parsed.proxy_mode,
2062
- json: parsed.json,
2063
- })
2064
- }
2065
-
2066
- fn run_coordinator(args: &[String], cwd: &Path) -> Result<ExitCode, CliError> {
2067
- let parsed = parse_args(args);
2068
- let workspace = crate::coordinator::WorkspacePath::new(workspace(&parsed, cwd));
2069
- // 0.5.x Windows portability Batch 9 F8: pass `--team` through
2070
- // to the daemon so it doesn't have to derive from state at
2071
- // boot time. `parse_args` already recognizes `--team`; we just
2072
- // thread the value into `DaemonArgs::team_key`.
2073
- crate::coordinator::run_daemon(crate::coordinator::DaemonArgs {
2074
- workspace,
2075
- once: parsed.once,
2076
- tick_interval_sec: parsed.tick_interval,
2077
- team_key: parsed.team.clone(),
2078
- })
2079
- .map(|()| ExitCode::Ok)
2080
- .map_err(|e| CliError::Runtime(e.to_string()))
2081
- }
2082
-
2083
- fn human_value(value: &Value) -> String {
2084
- match value {
2085
- Value::Null => "None".to_string(),
2086
- Value::Bool(true) => "True".to_string(),
2087
- Value::Bool(false) => "False".to_string(),
2088
- Value::Number(n) => n.to_string(),
2089
- Value::String(s) => s.clone(),
2090
- Value::Array(_) | Value::Object(_) => json_dumps_like(value),
2091
- }
2092
- }
2093
-
2094
- fn json_dumps_like(value: &Value) -> String {
2095
- match value {
2096
- Value::Null => "null".to_string(),
2097
- Value::Bool(b) => b.to_string(),
2098
- Value::Number(n) => n.to_string(),
2099
- Value::String(s) => match serde_json::to_string(s) {
2100
- Ok(text) => text,
2101
- Err(_) => "\"\"".to_string(),
2102
- },
2103
- Value::Array(arr) => {
2104
- let inner = arr
2105
- .iter()
2106
- .map(json_dumps_like)
2107
- .collect::<Vec<_>>()
2108
- .join(", ");
2109
- format!("[{inner}]")
2110
- }
2111
- Value::Object(obj) => {
2112
- let inner = obj
2113
- .iter()
2114
- .map(|(k, v)| {
2115
- format!(
2116
- "{}: {}",
2117
- json_dumps_like(&Value::String(k.clone())),
2118
- json_dumps_like(v)
2119
- )
2120
- })
2121
- .collect::<Vec<_>>()
2122
- .join(", ");
2123
- format!("{{{inner}}}")
2124
- }
2125
- }
2126
- }
2127
-
2128
- #[cfg(test)]
2129
- mod tests {
2130
- #![allow(clippy::unwrap_used)]
2131
-
2132
- use super::*;
2133
-
2134
- fn tmp_workspace() -> PathBuf {
2135
- use std::sync::atomic::{AtomicU64, Ordering};
2136
- static CTR: AtomicU64 = AtomicU64::new(0);
2137
- let dir = std::env::temp_dir().join(format!(
2138
- "ta-cli-emit-test-{}-{}",
2139
- std::process::id(),
2140
- CTR.fetch_add(1, Ordering::Relaxed)
2141
- ));
2142
- std::fs::create_dir_all(&dir).unwrap();
2143
- dir
2144
- }
2145
-
2146
- fn cli_argv(items: &[&str]) -> Vec<String> {
2147
- items.iter().map(|s| (*s).to_string()).collect()
2148
- }
2149
-
2150
- fn visible_help_commands(help: &str) -> Vec<String> {
2151
- help.lines()
2152
- .filter_map(|line| {
2153
- let trimmed = line.strip_prefix(" ")?;
2154
- if trimmed.starts_with("team-agent ") || trimmed.starts_with(char::is_whitespace) {
2155
- return None;
2156
- }
2157
- let command = trimmed.split_whitespace().next()?;
2158
- (command.chars().next()?.is_ascii_lowercase()
2159
- && command
2160
- .chars()
2161
- .all(|ch| ch.is_ascii_lowercase() || ch.is_ascii_digit() || ch == '-'))
2162
- .then(|| command.to_string())
2163
- })
2164
- .collect()
2165
- }
2166
-
2167
- #[test]
2168
- fn leaders_parser_supports_views_and_search() {
2169
- let parsed = leaders_args(
2170
- &cli_argv(&["--all", "--search", "Wiki", "--json"]),
2171
- Path::new("."),
2172
- )
2173
- .unwrap();
2174
- assert_eq!(parsed.view, LeadersView::All);
2175
- assert_eq!(parsed.query.as_deref(), Some("Wiki"));
2176
- assert!(!parsed.prune);
2177
- assert!(!parsed.dry_run);
2178
- assert!(parsed.json);
2179
- }
2180
-
2181
- #[test]
2182
- fn leaders_parser_rejects_invalid_search_and_prune_combinations() {
2183
- for args in [
2184
- cli_argv(&["one", "two"]),
2185
- cli_argv(&["one", "--search", "two"]),
2186
- cli_argv(&["--search", " "]),
2187
- cli_argv(&["--dry-run"]),
2188
- cli_argv(&["--prune", "--stale"]),
2189
- cli_argv(&["--prune", "--search", "x"]),
2190
- ] {
2191
- assert!(
2192
- leaders_args(&args, Path::new(".")).is_err(),
2193
- "args={args:?}"
2194
- );
2195
- }
2196
- }
2197
-
2198
- #[test]
2199
- fn command_specs_have_unique_names() {
2200
- let mut names = std::collections::BTreeSet::new();
2201
- for spec in COMMAND_SPECS {
2202
- assert!(
2203
- names.insert(spec.name),
2204
- "duplicate command spec `{}`",
2205
- spec.name
2206
- );
2207
- }
2208
- }
2209
-
2210
- #[test]
2211
- fn all_dispatch_kinds_have_exactly_one_spec() {
2212
- for kind in ALL_DISPATCH_KINDS {
2213
- let count = COMMAND_SPECS
2214
- .iter()
2215
- .filter(|spec| spec.kind == CommandKind::Dispatch(*kind))
2216
- .count();
2217
- assert_eq!(
2218
- count, 1,
2219
- "dispatch kind `{kind:?}` must appear in exactly one CommandSpec"
2220
- );
2221
- }
2222
- }
2223
-
2224
- #[test]
2225
- fn known_command_gate_uses_specs() {
2226
- for spec in COMMAND_SPECS.iter().filter(|spec| spec.command_help) {
2227
- assert!(
2228
- is_known_subcommand(spec.name),
2229
- "`{}` must be accepted by the known-command help gate",
2230
- spec.name
2231
- );
2232
- }
2233
- assert!(!is_known_subcommand("missing-c1-command"));
2234
- }
2235
-
2236
- #[test]
2237
- fn default_help_lists_only_default_help_specs() {
2238
- let top_help = command_help(None);
2239
- let visible = visible_help_commands(&top_help);
2240
- for command in &visible {
2241
- let spec = command_spec(command).expect("visible command must have a spec");
2242
- assert!(
2243
- spec.default_help,
2244
- "`{command}` appears in default help without default_help=true"
2245
- );
2246
- }
2247
- let expected: Vec<&str> = COMMAND_SPECS
2248
- .iter()
2249
- .filter(|spec| spec.default_help)
2250
- .map(|spec| spec.name)
2251
- .collect();
2252
- assert_eq!(
2253
- expected.len(),
2254
- 36,
2255
- "the public catalog includes endpoint discovery and scheduled leader reminders"
2256
- );
2257
- for spec_name in &expected {
2258
- assert!(
2259
- visible.iter().any(|command| command == spec_name),
2260
- "`{spec_name}` has default_help=true but is missing from top-level help"
2261
- );
2262
- }
2263
- let mut actual = visible.clone();
2264
- actual.sort();
2265
- let mut expected_sorted: Vec<String> =
2266
- expected.iter().map(|name| (*name).to_string()).collect();
2267
- expected_sorted.sort();
2268
- assert_eq!(
2269
- actual, expected_sorted,
2270
- "default help must match the exact public spec set, not a slack threshold; got {visible:?}"
2271
- );
2272
- assert!(
2273
- top_help.contains("copilot"),
2274
- "top-level leader passthrough help must list copilot"
2275
- );
2276
- }
2277
-
2278
- #[test]
2279
- fn hidden_commands_not_in_default_help() {
2280
- let top_help = command_help(None);
2281
- let visible = visible_help_commands(&top_help);
2282
- assert!(visible.iter().any(|command| command == "doctor"));
2283
- assert!(visible.iter().any(|command| command == "leaders"));
2284
- for command in [
2285
- "results",
2286
- "wait",
2287
- "attach-app-server-leader",
2288
- "identity",
2289
- "watch",
2290
- "sessions",
2291
- "validate",
2292
- "preflight",
2293
- "wait-ready",
2294
- "e2e",
2295
- "peek",
2296
- "coordinator",
2297
- ] {
2298
- assert!(
2299
- !visible.iter().any(|visible| visible == command),
2300
- "`{command}` must stay hidden from default help"
2301
- );
2302
- }
2303
- }
2304
-
2305
- #[test]
2306
- fn retired_commands_have_no_catalog_machine_or_help_gate() {
2307
- for command in [
2308
- "e2e",
2309
- "allow-peer-talk",
2310
- "results",
2311
- "validate",
2312
- "identity",
2313
- "sessions",
2314
- "watch",
2315
- "peek",
2316
- "wait-ready",
2317
- "preflight",
2318
- ] {
2319
- assert!(
2320
- command_spec(command).is_none(),
2321
- "retired catalog entry: {command}"
2322
- );
2323
- assert!(
2324
- !is_machine_command(command),
2325
- "retired Machine route: {command}"
2326
- );
2327
- assert!(
2328
- !is_known_subcommand(command),
2329
- "retired help gate: {command}"
2330
- );
2331
- }
2332
- }
2333
-
2334
- #[test]
2335
- fn leaders_help_publishes_selectors_and_prune() {
2336
- let help = command_help(Some("leaders"));
2337
- assert!(help.contains("--all"));
2338
- assert!(help.contains("--stale"));
2339
- assert!(help.contains("--search TEXT"));
2340
- assert!(help.contains("--prune"));
2341
- assert!(help.contains("--dry-run"));
2342
- }
2343
-
2344
- #[test]
2345
- fn observation_a_commands_have_terminal_tiers() {
2346
- for (command, tier) in [
2347
- ("approvals", CommandTier::Core),
2348
- ("profile", CommandTier::Core),
2349
- ("install-skill", CommandTier::Core),
2350
- ] {
2351
- assert_eq!(command_spec(command).map(|spec| spec.tier), Some(tier));
2352
- }
2353
- }
2354
-
2355
- #[test]
2356
- fn suggestion_index_excludes_hidden_commands() {
2357
- assert_eq!(nearest_subcommand("statu"), Some("status"));
2358
- assert_eq!(nearest_subcommand("leader"), Some("leaders"));
2359
- assert_eq!(nearest_subcommand("fallback-send-leade"), None);
2360
- assert_eq!(nearest_subcommand("coordinato"), None);
2361
- }
2362
-
2363
- #[test]
2364
- fn copilot_is_listed_as_leader_passthrough_candidate() {
2365
- assert!(command_help(None).contains("copilot"));
2366
- assert_eq!(nearest_subcommand("copliot"), Some("copilot"));
2367
- }
2368
-
2369
- #[test]
2370
- fn copilot_help_dispatches_as_leader_passthrough() {
2371
- let cwd = tmp_workspace();
2372
- assert_eq!(run(&cli_argv(&["copilot", "--help"]), &cwd), ExitCode::Ok);
2373
- }
2374
-
2375
- #[test]
2376
- fn t0_help_catalog_lists_command_flags() {
2377
- for (command, flags) in [
2378
- (
2379
- "quick-start",
2380
- &["--workspace", "--team-id", "--yes", "--json"][..],
2381
- ),
2382
- ("send", &["--workspace", "--team", "--json"][..]),
2383
- ("schedule", &["--in", "--every", "--text", "--workspace", "--team", "--json"][..]),
2384
- (
2385
- "status",
2386
- &["--workspace", "--team", "--summary", "--json", "--detail"][..],
2387
- ),
2388
- (
2389
- "shutdown",
2390
- &["--workspace", "--team", "--keep-logs", "--json"][..],
2391
- ),
2392
- (
2393
- "restart",
2394
- &[
2395
- "--team",
2396
- "--allow-fresh",
2397
- "--session-converge-deadline",
2398
- "--json",
2399
- ][..],
2400
- ),
2401
- (
2402
- "start-agent",
2403
- &[
2404
- "--model",
2405
- "--effort",
2406
- "--bypass",
2407
- "--prompt",
2408
- "--profile",
2409
- "--provider",
2410
- "--workspace",
2411
- "--team",
2412
- "--allow-fresh",
2413
- "--json",
2414
- ][..],
2415
- ),
2416
- (
2417
- "reset-agent",
2418
- &["--workspace", "--team", "--discard-session", "--json"][..],
2419
- ),
2420
- (
2421
- "add-agent",
2422
- &[
2423
- "--role-file",
2424
- "--provider",
2425
- "--bypass",
2426
- "--model",
2427
- "--effort",
2428
- "--prompt",
2429
- "--profile",
2430
- "--force",
2431
- "--workspace",
2432
- "--team",
2433
- "--json",
2434
- ][..],
2435
- ),
2436
- (
2437
- "fork-agent",
2438
- &["--as", "--label", "--workspace", "--team", "--json"][..],
2439
- ),
2440
- (
2441
- "remove-agent",
2442
- &[
2443
- "--workspace",
2444
- "--team",
2445
- "--from-spec",
2446
- "--confirm",
2447
- "--force",
2448
- "--json",
2449
- ][..],
2450
- ),
2451
- (
2452
- "doctor",
2453
- &[
2454
- "--workspace",
2455
- "--team",
2456
- "--gate",
2457
- "--fix-schema",
2458
- "--cleanup-orphans",
2459
- "--json",
2460
- ][..],
2461
- ),
2462
- (
2463
- "attach-leader",
2464
- &[
2465
- "--workspace",
2466
- "--team",
2467
- "--pane",
2468
- "--provider",
2469
- "--confirm",
2470
- "--json",
2471
- ][..],
2472
- ),
2473
- ("stop-agent", &["--workspace", "--team", "--json"][..]),
2474
- ("approvals", &["--workspace", "--team", "--json"][..]),
2475
- (
2476
- "inbox",
2477
- &["--workspace", "--team", "-n", "--limit", "--json"][..],
2478
- ),
2479
- ] {
2480
- let help = command_help(Some(command));
2481
- for flag in flags {
2482
- assert!(
2483
- help.contains(flag),
2484
- "`team-agent {command} --help` is missing {flag}"
2485
- );
2486
- }
2487
- }
2488
- let cwd = tmp_workspace();
2489
- for command in ["wait", "attach-app-server-leader", "coordinator"] {
2490
- assert_eq!(
2491
- run(&cli_argv(&[command, "--help"]), &cwd),
2492
- ExitCode::Usage,
2493
- "Machine help must be generic Usage2, not a private flag tutorial"
2494
- );
2495
- }
2496
- std::fs::remove_dir_all(cwd).unwrap();
2497
- assert!(
2498
- !command_help(Some("quick-start")).contains("--fresh"),
2499
- "quick-start help must not advertise removed reset semantics"
2500
- );
2501
- }
2502
-
2503
- #[test]
2504
- fn public_help_templates_and_cli_guidance_are_english() {
2505
- fn assert_english(text: &str) {
2506
- assert!(
2507
- !text.chars().any(|ch| matches!(ch, '\u{3400}'..='\u{9fff}')),
2508
- "unauthorized CJK CLI guidance: {text}"
2509
- );
2510
- }
2511
- assert_english(&default_help());
2512
- assert_eq!(TEAM_TEMPLATE.lines().nth(1), Some("name: current"));
2513
- for spec in COMMAND_SPECS {
2514
- assert_english(spec.summary);
2515
- assert_english(&command_help(Some(spec.name)));
2516
- }
2517
- for text in [
2518
- TEAM_TEMPLATE,
2519
- WORKER_TEMPLATE,
2520
- HUMAN_NAVIGATION,
2521
- crate::cli::route::HELP,
2522
- crate::cli::COMMS_BOUNDARY_TEXT,
2523
- crate::cli::QUICK_START_REMINDER,
2524
- crate::cli::SEND_REMINDER,
2525
- crate::cli::STATUS_REMINDER,
2526
- ] {
2527
- assert_english(text);
2528
- }
2529
- for command in ["quick-start", "restart", "send"] {
2530
- let payload = CliError::Runtime("fixture failure".to_string())
2531
- .to_payload(Path::new("/tmp/fixture.log"), command);
2532
- assert_english(&payload.action);
2533
- }
2534
- }
2535
-
2536
- #[test]
2537
- fn worker_lifecycle_help_uses_authoritative_spec_usage_and_summary() {
2538
- for name in ["start-agent", "add-agent"] {
2539
- let spec = command_spec(name).expect("registered worker lifecycle command");
2540
- let help = command_help(Some(name));
2541
- assert!(help.contains(spec.usage));
2542
- assert!(help.contains("Purpose:"));
2543
- for flag in [
2544
- "--model MODEL",
2545
- "--effort LEVEL",
2546
- "--bypass true|false",
2547
- "--prompt TEXT",
2548
- "--profile NAME",
2549
- "--provider TOOL",
2550
- ] {
2551
- assert!(help.contains(flag), "{name} help missing {flag}: {help}");
2552
- }
2553
- assert!(help.contains("Next Action") && help.contains("send"));
2554
- }
2555
- assert!(!command_help(Some("start-agent")).contains("--force"));
2556
- let add = command_help(Some("add-agent"));
2557
- assert!(add.contains("[--role-file FILE]"));
2558
- assert!(add.contains("provider") && add.contains("bypass") && add.contains("--role-file"));
2559
- assert!(add.contains("Conflicting") && add.contains("refused"));
2560
- }
2561
-
2562
- #[test]
2563
- fn status_help_describes_brief_projection_and_unknown_boundary() {
2564
- let help = command_help(Some("status"));
2565
- for marker in [
2566
- "name/provider/model/effort/runtime_status/activity/health/session_name/tmux_command",
2567
- "Use --json for structured output",
2568
- "unknown means insufficient evidence",
2569
- "tmux_command",
2570
- "do not add fields",
2571
- ] {
2572
- assert!(
2573
- help.contains(marker),
2574
- "status help missing {marker}: {help}"
2575
- );
2576
- }
2577
- assert!(!help.contains("error breakdown via status --summary"));
2578
- }
2579
-
2580
- #[test]
2581
- fn models_defaults_provider_and_accepts_one_query_form() {
2582
- let defaulted = models_args(&cli_argv(&["gpt", "5.6", "luna"])).unwrap();
2583
- assert_eq!(defaulted.provider, "pi");
2584
- assert_eq!(defaulted.search.as_deref(), Some("gpt 5.6 luna"));
2585
-
2586
- let cursor = models_args(&cli_argv(&[
2587
- "--provider",
2588
- "cursor",
2589
- "--search",
2590
- "GPT Luna",
2591
- ]))
2592
- .unwrap();
2593
- assert_eq!(cursor.provider, "cursor");
2594
- assert_eq!(cursor.search.as_deref(), Some("GPT Luna"));
2595
-
2596
- let both = models_args(&cli_argv(&["luna", "--search", "gpt"])).unwrap_err();
2597
- assert!(
2598
- matches!(both, CliError::Usage(message) if message.contains("either QUERY or --search TEXT"))
2599
- );
2600
- let blank = models_args(&cli_argv(&["--search", " "])).unwrap();
2601
- assert_eq!(blank.search, None);
2602
- }
2603
-
2604
- #[test]
2605
- fn send_pane_positionals_are_message_not_target() {
2606
- let cwd = tmp_workspace();
2607
- let args = send_args(&cli_argv(&["--pane", "%1596", "hello"]), &cwd).unwrap();
2608
- assert_eq!(args.pane.as_deref(), Some("%1596"));
2609
- assert_eq!(args.target, None);
2610
- assert_eq!(args.targets, None);
2611
- assert_eq!(args.message, vec!["hello".to_string()]);
2612
-
2613
- let args = send_args(
2614
- &cli_argv(&["--pane", "%1596", "multi", "word", "message"]),
2615
- &cwd,
2616
- )
2617
- .unwrap();
2618
- assert_eq!(args.target, None);
2619
- assert_eq!(
2620
- args.message,
2621
- vec![
2622
- "multi".to_string(),
2623
- "word".to_string(),
2624
- "message".to_string()
2625
- ]
2626
- );
2627
-
2628
- let _ = std::fs::remove_dir_all(&cwd);
2629
- }
2630
-
2631
- #[test]
2632
- fn send_mailbox_and_legacy_progress_map_to_the_one_bit_request() {
2633
- let cwd = tmp_workspace();
2634
- let mailbox = send_args(&cli_argv(&["leader", "progress", "--mailbox"]), &cwd).unwrap();
2635
- assert_eq!(
2636
- mailbox.presentation.sink,
2637
- crate::messaging::presentation::PresentationSink::Casefile
2638
- );
2639
-
2640
- let args = send_args(
2641
- &cli_argv(&[
2642
- "leader",
2643
- "progress",
2644
- "--presentation-sink",
2645
- "casefile",
2646
- "--message-class",
2647
- "progress",
2648
- "--case-id",
2649
- "case-9",
2650
- ]),
2651
- &cwd,
2652
- )
2653
- .unwrap();
2654
- assert_eq!(
2655
- args.presentation.sink,
2656
- crate::messaging::presentation::PresentationSink::Casefile
2657
- );
2658
- assert_eq!(
2659
- args.presentation.class,
2660
- crate::messaging::presentation::PresentationClass::Message
2661
- );
2662
- assert_eq!(args.presentation.case_id, None);
2663
- }
2664
-
2665
- #[test]
2666
- fn send_presentation_flags_fail_closed_when_incomplete() {
2667
- let cwd = tmp_workspace();
2668
- let error = send_args(
2669
- &cli_argv(&["leader", "progress", "--presentation-sink", "casefile"]),
2670
- &cwd,
2671
- )
2672
- .unwrap_err();
2673
- assert!(matches!(
2674
- error,
2675
- CliError::Usage(message) if message == "invalid send routing: missing_class"
2676
- ));
2677
- }
2678
-
2679
- #[test]
2680
- fn send_to_name_positionals_are_message_not_target() {
2681
- let cwd = tmp_workspace();
2682
- let args = send_args(&cli_argv(&["--to-name", "team-a/qa", "hello"]), &cwd).unwrap();
2683
- assert_eq!(args.to_name.as_deref(), Some("team-a/qa"));
2684
- assert_eq!(args.target, None);
2685
- assert_eq!(args.targets, None);
2686
- assert_eq!(args.message, vec!["hello".to_string()]);
2687
-
2688
- let args = send_args(
2689
- &cli_argv(&["--to-name=team-a/qa", "multi", "word", "message"]),
2690
- &cwd,
2691
- )
2692
- .unwrap();
2693
- assert_eq!(args.target, None);
2694
- assert_eq!(
2695
- args.message,
2696
- vec![
2697
- "multi".to_string(),
2698
- "word".to_string(),
2699
- "message".to_string()
2700
- ]
2701
- );
2702
-
2703
- let _ = std::fs::remove_dir_all(&cwd);
2704
- }
2705
-
2706
- #[test]
2707
- fn send_pane_still_rejects_to_and_empty_message() {
2708
- let cwd = tmp_workspace();
2709
- let err = send_args(
2710
- &cli_argv(&["--pane", "%1596", "--to", "worker", "hello"]),
2711
- &cwd,
2712
- ).unwrap_err();
2713
- assert!(matches!(err, CliError::Usage(ref message) if message.contains("one recipient addressing mode")));
2714
- // The public parser now refuses first; the typed handler must still
2715
- // reject the same conflict if a non-CLI caller constructs it directly.
2716
- let mut args = send_args(&cli_argv(&["--pane", "%1596", "hello"]), &cwd).unwrap();
2717
- args.targets = Some("worker".to_string());
2718
- let err = cmd_send(&args).unwrap_err();
2719
- assert!(
2720
- matches!(err, CliError::Usage(ref message) if message.contains("--pane") && message.contains("--to") && message.contains("cannot") && message.contains("combined")),
2721
- "expected --pane/--to mutual-exclusion usage error, got {err:?}"
2722
- );
2723
-
2724
- let args = send_args(&cli_argv(&["--pane", "%1596"]), &cwd).unwrap();
2725
- let err = cmd_send(&args).unwrap_err();
2726
- assert!(
2727
- matches!(err, CliError::Usage(ref message) if message.contains("--pane") && message.contains("cannot send an empty message")),
2728
- "expected empty-message usage error, got {err:?}"
2729
- );
2730
-
2731
- let _ = std::fs::remove_dir_all(&cwd);
2732
- }
2733
-
2734
- #[test]
2735
- fn ux_quick_start_workspace_resolves_relative_agents_dir_inside_workspace() {
2736
- let cwd = tmp_workspace();
2737
- let ws = tmp_workspace();
2738
- let args = quick_start_args(
2739
- &cli_argv(&[
2740
- "--workspace",
2741
- &ws.to_string_lossy(),
2742
- "agents",
2743
- "--yes",
2744
- "--json",
2745
- ]),
2746
- &cwd,
2747
- )
2748
- .unwrap();
2749
- assert_eq!(
2750
- args.agents_dir,
2751
- ws.join("agents"),
2752
- "quick-start --workspace <ws> agents must resolve the role-doc dir under <ws>, so team-in-team \
2753
- setup works from any caller cwd"
2754
- );
2755
- let _ = std::fs::remove_dir_all(&cwd);
2756
- let _ = std::fs::remove_dir_all(&ws);
2757
- }
2758
-
2759
- #[test]
2760
- fn ux_quick_start_positional_team_dir_is_standalone_workspace() {
2761
- let cwd = tmp_workspace();
2762
- let ws = tmp_workspace();
2763
- std::fs::write(ws.join("TEAM.md"), "# team\n").unwrap();
2764
- let args = quick_start_args(&cli_argv(&[&ws.to_string_lossy()]), &cwd).unwrap();
2765
- assert_eq!(args.workspace, ws);
2766
- assert_eq!(args.agents_dir, ws);
2767
- let _ = std::fs::remove_dir_all(&cwd);
2768
- let _ = std::fs::remove_dir_all(&ws);
2769
- }
2770
-
2771
- #[test]
2772
- fn ux_quick_start_team_dir_under_dot_team_uses_project_workspace() {
2773
- let cwd = tmp_workspace();
2774
- let team_dir = cwd.join(".team/current");
2775
- std::fs::create_dir_all(&team_dir).unwrap();
2776
- std::fs::write(team_dir.join("TEAM.md"), "# team\n").unwrap();
2777
- let args = quick_start_args(&cli_argv(&[".team/current"]), &cwd).unwrap();
2778
- assert_eq!(args.workspace, cwd);
2779
- assert_eq!(args.agents_dir, team_dir);
2780
- let _ = std::fs::remove_dir_all(&cwd);
2781
- }
2782
-
2783
- // ── E8 (N38): 未知子命令 → 最近似建议(additive,不破坏 golden invalid-choice 行) ──
2784
- #[test]
2785
- fn e8_unknown_subcommand_suggests_nearest_known_command() {
2786
- // 'statu' typo → status; 'add-agen' → add-agent.
2787
- assert_eq!(nearest_subcommand("statu"), Some("status"));
2788
- assert_eq!(nearest_subcommand("add-agen"), Some("add-agent"));
2789
- // Presentation migration: the new canonical short verb is now a
2790
- // prefix candidate in the unchanged shared similarity ranking.
2791
- assert_eq!(nearest_subcommand("start-agnet"), Some("start"));
2792
- }
2793
-
2794
- #[test]
2795
- fn e8_unknown_subcommand_no_suggestion_when_far() {
2796
- // 完全无关的串不应误配出任何建议。
2797
- assert_eq!(nearest_subcommand("zzzzzzzzzz"), None);
2798
- assert_eq!(nearest_subcommand("x"), None);
2799
- }
2800
-
2801
- #[test]
2802
- fn e8_levenshtein_basic() {
2803
- // 0.5.45 naming-addressing: distance function moved to
2804
- // `crate::model::name_similarity` (shared with --to-name typo
2805
- // suggestions). Same math, single source.
2806
- use crate::model::name_similarity::levenshtein;
2807
- assert_eq!(levenshtein("kitten", "sitting"), 3);
2808
- assert_eq!(levenshtein("status", "status"), 0);
2809
- assert_eq!(levenshtein("statu", "status"), 1);
2810
- }
2811
-
2812
- // ─── Stage 4: multi-team ambiguity refusal for destructive commands ───
2813
-
2814
- fn seed_two_alive_teams_in(ws: &std::path::Path) {
2815
- crate::state::persist::save_runtime_state(
2816
- ws,
2817
- &serde_json::json!({
2818
- "teams": {
2819
- "alpha": {"status": "alive"},
2820
- "beta": {"status": "alive"},
2821
- },
2822
- }),
2823
- )
2824
- .unwrap();
2825
- }
2826
-
2827
- #[test]
2828
- fn refuse_helper_passes_on_single_alive_team() {
2829
- let ws = tmp_workspace();
2830
- crate::state::persist::save_runtime_state(
2831
- &ws,
2832
- &serde_json::json!({"teams": {"alpha": {"status": "alive"}}}),
2833
- )
2834
- .unwrap();
2835
- assert!(
2836
- refuse_if_multi_alive_team_missing_scope("stuck-cancel", &ws, None).is_ok(),
2837
- "single-alive-team workspace must not trigger the ambiguity refusal"
2838
- );
2839
- }
2840
-
2841
- #[test]
2842
- fn shutdown_args_builder_refuses_on_multi_alive_team() {
2843
- let ws = tmp_workspace();
2844
- seed_two_alive_teams_in(&ws);
2845
- let argv = cli_argv(&["--workspace", &ws.to_string_lossy()]);
2846
- let err = shutdown_args(&argv, &ws).expect_err("must refuse");
2847
- assert!(
2848
- err.to_string().contains("multiple alive teams"),
2849
- "shutdown args builder must surface the refusal; got: {err}"
2850
- );
2851
- }
2852
-
2853
- #[test]
2854
- fn restart_args_builder_refuses_on_multi_alive_team() {
2855
- let ws = tmp_workspace();
2856
- seed_two_alive_teams_in(&ws);
2857
- let argv = cli_argv(&[&ws.to_string_lossy()]);
2858
- let err = restart_args(&argv, &ws).expect_err("must refuse");
2859
- assert!(
2860
- err.to_string().contains("multiple alive teams"),
2861
- "restart args builder must surface the refusal; got: {err}"
2862
- );
2863
- }
2864
-
2865
- #[test]
2866
- fn reset_agent_complete_input_refuses_multi_alive_team_before_agent_validation() {
2867
- let ws = tmp_workspace();
2868
- seed_two_alive_teams_in(&ws);
2869
- let argv = cli_argv(&[
2870
- "nonexistent-agent",
2871
- "--discard-session",
2872
- "--workspace",
2873
- &ws.to_string_lossy(),
2874
- ]);
2875
- let err = reset_agent_args(&argv, &ws).expect_err("must refuse");
2876
- assert!(
2877
- err.to_string().contains("multiple alive teams"),
2878
- "reset-agent args builder must surface the refusal; got: {err}"
2879
- );
2880
- }
2881
-
2882
- #[test]
2883
- fn remove_agent_complete_input_refuses_multi_alive_team_before_agent_validation() {
2884
- let ws = tmp_workspace();
2885
- seed_two_alive_teams_in(&ws);
2886
- let argv = cli_argv(&["nonexistent-agent", "--workspace", &ws.to_string_lossy()]);
2887
- let err = remove_agent_args(&argv, &ws).expect_err("must refuse");
2888
- assert!(
2889
- err.to_string().contains("multiple alive teams"),
2890
- "remove-agent args builder must surface the refusal; got: {err}"
2891
- );
2892
- }
2893
-
2894
- // ──────────── Stage QR: quick-start/restart separation ────────────
2895
- // Design doc: .team/artifacts/quickstart-restart-separation-design.md
2896
-
2897
- #[test]
2898
- fn quick_start_refuses_fresh_flag_with_restart_guidance() {
2899
- // QR contract: `--fresh` is gone from quick-start. The flag is
2900
- // not advertised or carried in QuickStartArgs, but scripts that
2901
- // still pass it get a clear redirect to restart --allow-fresh.
2902
- let ws = tmp_workspace();
2903
- let argv = cli_argv(&["--workspace", &ws.to_string_lossy(), "--fresh"]);
2904
- let err = quick_start_args(&argv, &ws).expect_err("must refuse --fresh");
2905
- let message = err.to_string();
2906
- assert!(
2907
- message.contains("no longer accepts --fresh"),
2908
- "QR: refusal must say --fresh is gone; got: {message}"
2909
- );
2910
- assert!(
2911
- message.contains("restart --allow-fresh"),
2912
- "QR: refusal must redirect to `restart --allow-fresh`; got: {message}"
2913
- );
2914
- }
2915
-
2916
- #[test]
2917
- fn quick_start_without_fresh_flag_still_builds_args() {
2918
- // Without --fresh, args build normally (the initial-creation path).
2919
- let ws = tmp_workspace();
2920
- let argv = cli_argv(&["--workspace", &ws.to_string_lossy()]);
2921
- let args = quick_start_args(&argv, &ws).expect("must build");
2922
- assert_eq!(args.workspace, ws);
2923
- // No `fresh` field anymore — the struct must compile and round-trip
2924
- // without it.
2925
- }
2926
- }
2927
-
2928
- #[cfg(test)]
2929
- #[path = "tests/parser_safety.rs"]
2930
- mod parser_safety_tests;