@team-agent/installer 0.5.128 → 0.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (436) hide show
  1. package/README.md +4 -4
  2. package/README.zh.md +1 -1
  3. package/package.json +4 -8
  4. package/skills/team-agent/SKILL.md +37 -20
  5. package/skills/team-agent/command-coverage.json +169 -183
  6. package/skills/team-agent/docs/reference/team-agent-operator.md +64 -30
  7. package/skills/team-agent/references/recovery-runbook.md +1 -1
  8. package/skills/team-agent/references/team-agent-operator.md +64 -30
  9. package/templates/team_state.md +1 -1
  10. package/Cargo.lock +0 -1063
  11. package/Cargo.toml +0 -36
  12. package/crates/team-agent/Cargo.toml +0 -69
  13. package/crates/team-agent/src/app_server_test_support.rs +0 -258
  14. package/crates/team-agent/src/cli/adapters.rs +0 -1288
  15. package/crates/team-agent/src/cli/arguments.rs +0 -405
  16. package/crates/team-agent/src/cli/attach_app_server_leader.rs +0 -98
  17. package/crates/team-agent/src/cli/diagnose.rs +0 -1721
  18. package/crates/team-agent/src/cli/emit.rs +0 -2930
  19. package/crates/team-agent/src/cli/grok_slot.rs +0 -384
  20. package/crates/team-agent/src/cli/helpers.rs +0 -91
  21. package/crates/team-agent/src/cli/intent/runtime.rs +0 -1216
  22. package/crates/team-agent/src/cli/intent/runtime_tests.rs +0 -912
  23. package/crates/team-agent/src/cli/intent/tests.rs +0 -689
  24. package/crates/team-agent/src/cli/intent.rs +0 -664
  25. package/crates/team-agent/src/cli/leader.rs +0 -300
  26. package/crates/team-agent/src/cli/leader_prompt.rs +0 -261
  27. package/crates/team-agent/src/cli/leaders.rs +0 -418
  28. package/crates/team-agent/src/cli/mod.rs +0 -6545
  29. package/crates/team-agent/src/cli/models.rs +0 -1206
  30. package/crates/team-agent/src/cli/named_address.rs +0 -1651
  31. package/crates/team-agent/src/cli/profile.rs +0 -342
  32. package/crates/team-agent/src/cli/route.rs +0 -212
  33. package/crates/team-agent/src/cli/schedule.rs +0 -175
  34. package/crates/team-agent/src/cli/send/coordinator.rs +0 -164
  35. package/crates/team-agent/src/cli/send/mailbox.rs +0 -145
  36. package/crates/team-agent/src/cli/send/persist.rs +0 -156
  37. package/crates/team-agent/src/cli/send/presentation.rs +0 -370
  38. package/crates/team-agent/src/cli/send/resolve.rs +0 -573
  39. package/crates/team-agent/src/cli/send.rs +0 -199
  40. package/crates/team-agent/src/cli/shutdown_socket.rs +0 -288
  41. package/crates/team-agent/src/cli/spec.rs +0 -165
  42. package/crates/team-agent/src/cli/status.rs +0 -280
  43. package/crates/team-agent/src/cli/status_port/agents.rs +0 -358
  44. package/crates/team-agent/src/cli/status_port/approvals.rs +0 -79
  45. package/crates/team-agent/src/cli/status_port/brief.rs +0 -1981
  46. package/crates/team-agent/src/cli/status_port/compact.rs +0 -240
  47. package/crates/team-agent/src/cli/status_port/format.rs +0 -146
  48. package/crates/team-agent/src/cli/status_port/inbox.rs +0 -62
  49. package/crates/team-agent/src/cli/status_port/runtime.rs +0 -197
  50. package/crates/team-agent/src/cli/status_port/snapshot.rs +0 -208
  51. package/crates/team-agent/src/cli/status_port/store.rs +0 -416
  52. package/crates/team-agent/src/cli/status_port/tests.rs +0 -90
  53. package/crates/team-agent/src/cli/status_port.rs +0 -92
  54. package/crates/team-agent/src/cli/tests/base.rs +0 -885
  55. package/crates/team-agent/src/cli/tests/divergence.rs +0 -518
  56. package/crates/team-agent/src/cli/tests/lane_c.rs +0 -453
  57. package/crates/team-agent/src/cli/tests/leader_watch.rs +0 -322
  58. package/crates/team-agent/src/cli/tests/main_preserved.rs +0 -430
  59. package/crates/team-agent/src/cli/tests/missing_subcommands.rs +0 -336
  60. package/crates/team-agent/src/cli/tests/mod.rs +0 -137
  61. package/crates/team-agent/src/cli/tests/named_address.rs +0 -761
  62. package/crates/team-agent/src/cli/tests/parser_safety.rs +0 -383
  63. package/crates/team-agent/src/cli/tests/run_delegation.rs +0 -484
  64. package/crates/team-agent/src/cli/tests/shutdown_kill_plan.rs +0 -2179
  65. package/crates/team-agent/src/cli/tests/status_brief.rs +0 -1514
  66. package/crates/team-agent/src/cli/tests/status_send.rs +0 -888
  67. package/crates/team-agent/src/cli/tests/verb_install_skill.rs +0 -93
  68. package/crates/team-agent/src/cli/tests/verb_profile.rs +0 -392
  69. package/crates/team-agent/src/cli/triage.rs +0 -234
  70. package/crates/team-agent/src/cli/types.rs +0 -591
  71. package/crates/team-agent/src/codex_app_server.rs +0 -546
  72. package/crates/team-agent/src/communication_mode/mod.rs +0 -56
  73. package/crates/team-agent/src/compiler/tests.rs +0 -827
  74. package/crates/team-agent/src/compiler.rs +0 -890
  75. package/crates/team-agent/src/conpty/backend.rs +0 -829
  76. package/crates/team-agent/src/conpty/mod.rs +0 -33
  77. package/crates/team-agent/src/contract_runtime/backend.rs +0 -1744
  78. package/crates/team-agent/src/contract_runtime/commands.rs +0 -671
  79. package/crates/team-agent/src/contract_runtime/config.rs +0 -364
  80. package/crates/team-agent/src/contract_runtime/config_tests.rs +0 -76
  81. package/crates/team-agent/src/contract_runtime/discovery.rs +0 -449
  82. package/crates/team-agent/src/contract_runtime/fork.rs +0 -361
  83. package/crates/team-agent/src/contract_runtime/forward.rs +0 -288
  84. package/crates/team-agent/src/contract_runtime/framework.rs +0 -367
  85. package/crates/team-agent/src/contract_runtime/mcp.rs +0 -394
  86. package/crates/team-agent/src/contract_runtime/mod.rs +0 -17
  87. package/crates/team-agent/src/contract_runtime/prompt.rs +0 -216
  88. package/crates/team-agent/src/contract_runtime/pump.rs +0 -271
  89. package/crates/team-agent/src/contract_runtime/registry.rs +0 -553
  90. package/crates/team-agent/src/contract_runtime/workspace.rs +0 -228
  91. package/crates/team-agent/src/coordinator/backoff.rs +0 -741
  92. package/crates/team-agent/src/coordinator/conpty_shim.rs +0 -805
  93. package/crates/team-agent/src/coordinator/health.rs +0 -1185
  94. package/crates/team-agent/src/coordinator/mod.rs +0 -119
  95. package/crates/team-agent/src/coordinator/orphan.rs +0 -110
  96. package/crates/team-agent/src/coordinator/runtime_detectors.rs +0 -798
  97. package/crates/team-agent/src/coordinator/runtime_observation.rs +0 -84
  98. package/crates/team-agent/src/coordinator/steps/abnormal.rs +0 -2309
  99. package/crates/team-agent/src/coordinator/steps/delivery.rs +0 -15
  100. package/crates/team-agent/src/coordinator/steps/health_sync.rs +0 -15
  101. package/crates/team-agent/src/coordinator/steps/mod.rs +0 -126
  102. package/crates/team-agent/src/coordinator/steps/persist.rs +0 -15
  103. package/crates/team-agent/src/coordinator/steps/runtime_prompts.rs +0 -15
  104. package/crates/team-agent/src/coordinator/steps/session_gate.rs +0 -16
  105. package/crates/team-agent/src/coordinator/tests/a0_lostupdate.rs +0 -158
  106. package/crates/team-agent/src/coordinator/tests/abnormal.rs +0 -312
  107. package/crates/team-agent/src/coordinator/tests/api_error_recovery.rs +0 -300
  108. package/crates/team-agent/src/coordinator/tests/basics.rs +0 -211
  109. package/crates/team-agent/src/coordinator/tests/daemon.rs +0 -514
  110. package/crates/team-agent/src/coordinator/tests/energy.rs +0 -549
  111. package/crates/team-agent/src/coordinator/tests/health_sync.rs +0 -503
  112. package/crates/team-agent/src/coordinator/tests/main_preserved.rs +0 -186
  113. package/crates/team-agent/src/coordinator/tests/mod.rs +0 -295
  114. package/crates/team-agent/src/coordinator/tests/s3_bounded.rs +0 -207
  115. package/crates/team-agent/src/coordinator/tests/spine.rs +0 -308
  116. package/crates/team-agent/src/coordinator/tests/takeover.rs +0 -286
  117. package/crates/team-agent/src/coordinator/tests/tick_core.rs +0 -237
  118. package/crates/team-agent/src/coordinator/tick.rs +0 -3024
  119. package/crates/team-agent/src/coordinator/types.rs +0 -540
  120. package/crates/team-agent/src/db/agent_health_capture.rs +0 -126
  121. package/crates/team-agent/src/db/message_store.rs +0 -1527
  122. package/crates/team-agent/src/db/migration.rs +0 -984
  123. package/crates/team-agent/src/db/mod.rs +0 -26
  124. package/crates/team-agent/src/db/schema.rs +0 -663
  125. package/crates/team-agent/src/diagnose/comms.rs +0 -242
  126. package/crates/team-agent/src/diagnose/mod.rs +0 -44
  127. package/crates/team-agent/src/diagnose/orphans.rs +0 -889
  128. package/crates/team-agent/src/direct_delivery.rs +0 -368
  129. package/crates/team-agent/src/event_log.rs +0 -502
  130. package/crates/team-agent/src/fake_worker.rs +0 -303
  131. package/crates/team-agent/src/inbox_store.rs +0 -169
  132. package/crates/team-agent/src/kill_audit.rs +0 -106
  133. package/crates/team-agent/src/layout/manager.rs +0 -248
  134. package/crates/team-agent/src/layout/mod.rs +0 -36
  135. package/crates/team-agent/src/layout/overlay.rs +0 -134
  136. package/crates/team-agent/src/layout/placement.rs +0 -52
  137. package/crates/team-agent/src/layout/recovery.rs +0 -106
  138. package/crates/team-agent/src/layout/runtime_sessions.rs +0 -317
  139. package/crates/team-agent/src/layout/sessions.rs +0 -294
  140. package/crates/team-agent/src/layout/tmux_endpoint.rs +0 -165
  141. package/crates/team-agent/src/layout/worker_env.rs +0 -721
  142. package/crates/team-agent/src/layout/worker_window_helpers.rs +0 -37
  143. package/crates/team-agent/src/leader/helpers.rs +0 -178
  144. package/crates/team-agent/src/leader/incident.rs +0 -6
  145. package/crates/team-agent/src/leader/lease.rs +0 -3356
  146. package/crates/team-agent/src/leader/mod.rs +0 -104
  147. package/crates/team-agent/src/leader/owner_bind.rs +0 -400
  148. package/crates/team-agent/src/leader/prompt.rs +0 -905
  149. package/crates/team-agent/src/leader/provider_attribution.rs +0 -247
  150. package/crates/team-agent/src/leader/rediscover/tests.rs +0 -689
  151. package/crates/team-agent/src/leader/rediscover.rs +0 -1192
  152. package/crates/team-agent/src/leader/registry.rs +0 -888
  153. package/crates/team-agent/src/leader/start.rs +0 -4501
  154. package/crates/team-agent/src/leader/takeover.rs +0 -65
  155. package/crates/team-agent/src/leader/tests/basics.rs +0 -337
  156. package/crates/team-agent/src/leader/tests/byte_findings.rs +0 -355
  157. package/crates/team-agent/src/leader/tests/claim_leader_mailbox_flush_contract.rs +0 -544
  158. package/crates/team-agent/src/leader/tests/historical_inventory_upgrade_gate_red.rs +0 -624
  159. package/crates/team-agent/src/leader/tests/identity.rs +0 -465
  160. package/crates/team-agent/src/leader/tests/identity_session_names.rs +0 -42
  161. package/crates/team-agent/src/leader/tests/idle.rs +0 -113
  162. package/crates/team-agent/src/leader/tests/lease_api.rs +0 -520
  163. package/crates/team-agent/src/leader/tests/lease_claim.rs +0 -629
  164. package/crates/team-agent/src/leader/tests/mod.rs +0 -106
  165. package/crates/team-agent/src/leader/tests/prompt_contract.rs +0 -268
  166. package/crates/team-agent/src/leader/tests/rediscover.rs +0 -403
  167. package/crates/team-agent/src/leader/tests/rehomed_env.rs +0 -83
  168. package/crates/team-agent/src/leader/tests/team_in_team_state_scope_red.rs +0 -1273
  169. package/crates/team-agent/src/leader/tests/terminal_and_replay_vs_rerender_invariants_red.rs +0 -417
  170. package/crates/team-agent/src/leader/tests/wake_start_owner.rs +0 -168
  171. package/crates/team-agent/src/leader/types.rs +0 -534
  172. package/crates/team-agent/src/lib.rs +0 -147
  173. package/crates/team-agent/src/lifecycle/helpers.rs +0 -212
  174. package/crates/team-agent/src/lifecycle/launch/add_agent.rs +0 -881
  175. package/crates/team-agent/src/lifecycle/launch/add_agent_state.rs +0 -598
  176. package/crates/team-agent/src/lifecycle/launch/agent_state.rs +0 -332
  177. package/crates/team-agent/src/lifecycle/launch/clone_agent.rs +0 -204
  178. package/crates/team-agent/src/lifecycle/launch/fork_agent.rs +0 -107
  179. package/crates/team-agent/src/lifecycle/launch/fork_entry.rs +0 -144
  180. package/crates/team-agent/src/lifecycle/launch/identity.rs +0 -674
  181. package/crates/team-agent/src/lifecycle/launch/layout.rs +0 -350
  182. package/crates/team-agent/src/lifecycle/launch/leader_context.rs +0 -589
  183. package/crates/team-agent/src/lifecycle/launch/mcp_config.rs +0 -160
  184. package/crates/team-agent/src/lifecycle/launch/ownership.rs +0 -105
  185. package/crates/team-agent/src/lifecycle/launch/pi_mcp.rs +0 -899
  186. package/crates/team-agent/src/lifecycle/launch/pi_mcp_extension.js +0 -225
  187. package/crates/team-agent/src/lifecycle/launch/plan.rs +0 -269
  188. package/crates/team-agent/src/lifecycle/launch/quick_start.rs +0 -5200
  189. package/crates/team-agent/src/lifecycle/launch/quick_start_transport.rs +0 -368
  190. package/crates/team-agent/src/lifecycle/launch/readiness.rs +0 -519
  191. package/crates/team-agent/src/lifecycle/launch/role_source.rs +0 -287
  192. package/crates/team-agent/src/lifecycle/launch/spawn.rs +0 -473
  193. package/crates/team-agent/src/lifecycle/launch/spec_state.rs +0 -801
  194. package/crates/team-agent/src/lifecycle/launch/state_projection.rs +0 -624
  195. package/crates/team-agent/src/lifecycle/launch/worker_env.rs +0 -558
  196. package/crates/team-agent/src/lifecycle/launch.rs +0 -557
  197. package/crates/team-agent/src/lifecycle/lock.rs +0 -350
  198. package/crates/team-agent/src/lifecycle/mod.rs +0 -79
  199. package/crates/team-agent/src/lifecycle/pane_input_lock.rs +0 -239
  200. package/crates/team-agent/src/lifecycle/profile_launch.rs +0 -1067
  201. package/crates/team-agent/src/lifecycle/profile_smoke.rs +0 -557
  202. package/crates/team-agent/src/lifecycle/restart/agent.rs +0 -2199
  203. package/crates/team-agent/src/lifecycle/restart/avatar.rs +0 -1798
  204. package/crates/team-agent/src/lifecycle/restart/claude_fork.rs +0 -163
  205. package/crates/team-agent/src/lifecycle/restart/common.rs +0 -2362
  206. package/crates/team-agent/src/lifecycle/restart/orchestrator.rs +0 -65
  207. package/crates/team-agent/src/lifecycle/restart/preflight.rs +0 -113
  208. package/crates/team-agent/src/lifecycle/restart/rebuild.rs +0 -5135
  209. package/crates/team-agent/src/lifecycle/restart/remove.rs +0 -1504
  210. package/crates/team-agent/src/lifecycle/restart/selection.rs +0 -559
  211. package/crates/team-agent/src/lifecycle/restart/team_state.rs +0 -329
  212. package/crates/team-agent/src/lifecycle/restart.rs +0 -227
  213. package/crates/team-agent/src/lifecycle/role_config.rs +0 -1230
  214. package/crates/team-agent/src/lifecycle/tests/acceptance_b_batch_red.rs +0 -1021
  215. package/crates/team-agent/src/lifecycle/tests/agent_ops.rs +0 -1205
  216. package/crates/team-agent/src/lifecycle/tests/b0_legacy_snapshot_nonauthority_contract.rs +0 -265
  217. package/crates/team-agent/src/lifecycle/tests/b0_reader_hideone_audit_contract.rs +0 -490
  218. package/crates/team-agent/src/lifecycle/tests/behavioral_diff_264_red.rs +0 -656
  219. package/crates/team-agent/src/lifecycle/tests/claude_compatible_config_red.rs +0 -325
  220. package/crates/team-agent/src/lifecycle/tests/claude_profile_launch_red.rs +0 -447
  221. package/crates/team-agent/src/lifecycle/tests/cli_argv_routing_red.rs +0 -1638
  222. package/crates/team-agent/src/lifecycle/tests/clone_agent_preserves_source_tools.rs +0 -427
  223. package/crates/team-agent/src/lifecycle/tests/clone_fork_copilot_perms_red.rs +0 -770
  224. package/crates/team-agent/src/lifecycle/tests/communication_mode_runtime_contract_red.rs +0 -419
  225. package/crates/team-agent/src/lifecycle/tests/copilot_provider_red.rs +0 -2035
  226. package/crates/team-agent/src/lifecycle/tests/core.rs +0 -1327
  227. package/crates/team-agent/src/lifecycle/tests/f032_startup_prompt_best_effort_red.rs +0 -315
  228. package/crates/team-agent/src/lifecycle/tests/fixtures/pi_list_models_g0.stdout.txt +0 -222
  229. package/crates/team-agent/src/lifecycle/tests/fixtures/pi_list_models_spaced_ids.stdout.txt +0 -9
  230. package/crates/team-agent/src/lifecycle/tests/fixtures/pi_native_mcp_host.mjs +0 -72
  231. package/crates/team-agent/src/lifecycle/tests/gate_fixtures.rs +0 -562
  232. package/crates/team-agent/src/lifecycle/tests/grok_require_explicit_model_red.rs +0 -110
  233. package/crates/team-agent/src/lifecycle/tests/harvest2_a_batch_red.rs +0 -512
  234. package/crates/team-agent/src/lifecycle/tests/host_cotenant_death_p0_contract.rs +0 -921
  235. package/crates/team-agent/src/lifecycle/tests/issue238_codex_effort_contract.rs +0 -68
  236. package/crates/team-agent/src/lifecycle/tests/lane_ops.rs +0 -1851
  237. package/crates/team-agent/src/lifecycle/tests/launch_spawn.rs +0 -3983
  238. package/crates/team-agent/src/lifecycle/tests/lifecycle_lock.rs +0 -339
  239. package/crates/team-agent/src/lifecycle/tests/lifecycle_rollback_red.rs +0 -596
  240. package/crates/team-agent/src/lifecycle/tests/main_preserved.rs +0 -513
  241. package/crates/team-agent/src/lifecycle/tests/mcp_tool_name_format_red.rs +0 -69
  242. package/crates/team-agent/src/lifecycle/tests/phase_b_contracts.rs +0 -824
  243. package/crates/team-agent/src/lifecycle/tests/phase_golden.rs +0 -723
  244. package/crates/team-agent/src/lifecycle/tests/pi_catalog_red.rs +0 -164
  245. package/crates/team-agent/src/lifecycle/tests/pi_command_red.rs +0 -200
  246. package/crates/team-agent/src/lifecycle/tests/pi_compiler_red.rs +0 -210
  247. package/crates/team-agent/src/lifecycle/tests/pi_dual_entry_red.rs +0 -527
  248. package/crates/team-agent/src/lifecycle/tests/pi_executable_mcp_red.rs +0 -1062
  249. package/crates/team-agent/src/lifecycle/tests/pi_fork_session_inheritance_red.rs +0 -1419
  250. package/crates/team-agent/src/lifecycle/tests/pi_lifecycle_doctor_red.rs +0 -98
  251. package/crates/team-agent/src/lifecycle/tests/pi_native_mcp_capability_red.rs +0 -550
  252. package/crates/team-agent/src/lifecycle/tests/pi_session_delivery_red.rs +0 -226
  253. package/crates/team-agent/src/lifecycle/tests/quick_start_worker_readiness_red.rs +0 -332
  254. package/crates/team-agent/src/lifecycle/tests/realmachine_clusters_1_6_red.rs +0 -786
  255. package/crates/team-agent/src/lifecycle/tests/realmachine_residual_g1_g4_red.rs +0 -648
  256. package/crates/team-agent/src/lifecycle/tests/restart.rs +0 -185
  257. package/crates/team-agent/src/lifecycle/tests/restart_build_before_destroy_0540_contract.rs +0 -1053
  258. package/crates/team-agent/src/lifecycle/tests/restart_liveness_red.rs +0 -679
  259. package/crates/team-agent/src/lifecycle/tests/restart_rebind_hotfix_252_red.rs +0 -1126
  260. package/crates/team-agent/src/lifecycle/tests/restart_session_capture_red.rs +0 -153
  261. package/crates/team-agent/src/lifecycle/tests/resume_recover_red.rs +0 -427
  262. package/crates/team-agent/src/lifecycle/tests/stale_team_saveconflict_contract.rs +0 -431
  263. package/crates/team-agent/src/lifecycle/tests/startup_latency_contract.rs +0 -1066
  264. package/crates/team-agent/src/lifecycle/tests/status_credential_redaction_contract.rs +0 -876
  265. package/crates/team-agent/src/lifecycle/tests/subprep_codex_trust_roundtrip_red.rs +0 -1026
  266. package/crates/team-agent/src/lifecycle/tests/swallow_batch4_semantics_red.rs +0 -342
  267. package/crates/team-agent/src/lifecycle/tests/team_in_team_identity_scope_red.rs +0 -543
  268. package/crates/team-agent/src/lifecycle/tests/team_in_team_sibling_quick_start_red.rs +0 -1103
  269. package/crates/team-agent/src/lifecycle/tests/team_in_team_state_scope_red.rs +0 -1276
  270. package/crates/team-agent/src/lifecycle/tests/team_key_retirement_roster_red.rs +0 -145
  271. package/crates/team-agent/src/lifecycle/tests/team_key_retirement_txn_red.rs +0 -603
  272. package/crates/team-agent/src/lifecycle/tests/test_isolation_escape_contract.rs +0 -936
  273. package/crates/team-agent/src/lifecycle/tests/upgrade_compat_0211_red.rs +0 -970
  274. package/crates/team-agent/src/lifecycle/tests/verify_rs031_window_consistency_red.rs +0 -995
  275. package/crates/team-agent/src/lifecycle/tests/worker_spawn_env_red.rs +0 -836
  276. package/crates/team-agent/src/lifecycle/tests.rs +0 -105
  277. package/crates/team-agent/src/lifecycle/types.rs +0 -877
  278. package/crates/team-agent/src/lifecycle/worker_command_context.rs +0 -363
  279. package/crates/team-agent/src/main.rs +0 -52
  280. package/crates/team-agent/src/mcp_server/helpers.rs +0 -510
  281. package/crates/team-agent/src/mcp_server/lifecycle_tools/mod.rs +0 -6
  282. package/crates/team-agent/src/mcp_server/lifecycle_tools/state_status.rs +0 -43
  283. package/crates/team-agent/src/mcp_server/mod.rs +0 -119
  284. package/crates/team-agent/src/mcp_server/normalize.rs +0 -485
  285. package/crates/team-agent/src/mcp_server/readiness.rs +0 -527
  286. package/crates/team-agent/src/mcp_server/readiness_tests.rs +0 -348
  287. package/crates/team-agent/src/mcp_server/tests/golden.rs +0 -285
  288. package/crates/team-agent/src/mcp_server/tests/normalize.rs +0 -247
  289. package/crates/team-agent/src/mcp_server/tests/scoped.rs +0 -158
  290. package/crates/team-agent/src/mcp_server/tests/send.rs +0 -353
  291. package/crates/team-agent/src/mcp_server/tests/tools.rs +0 -341
  292. package/crates/team-agent/src/mcp_server/tests/wire.rs +0 -254
  293. package/crates/team-agent/src/mcp_server/tests.rs +0 -43
  294. package/crates/team-agent/src/mcp_server/tools.rs +0 -889
  295. package/crates/team-agent/src/mcp_server/types.rs +0 -396
  296. package/crates/team-agent/src/mcp_server/wire.rs +0 -867
  297. package/crates/team-agent/src/messaging/activity.rs +0 -461
  298. package/crates/team-agent/src/messaging/address.rs +0 -87
  299. package/crates/team-agent/src/messaging/delivery.rs +0 -3727
  300. package/crates/team-agent/src/messaging/delivery_consumption_tests.rs +0 -234
  301. package/crates/team-agent/src/messaging/enter_rescue.rs +0 -362
  302. package/crates/team-agent/src/messaging/enter_rescue_tests.rs +0 -633
  303. package/crates/team-agent/src/messaging/helpers.rs +0 -336
  304. package/crates/team-agent/src/messaging/leader_channel.rs +0 -287
  305. package/crates/team-agent/src/messaging/leader_receiver.rs +0 -786
  306. package/crates/team-agent/src/messaging/mod.rs +0 -167
  307. package/crates/team-agent/src/messaging/persist.rs +0 -377
  308. package/crates/team-agent/src/messaging/presentation.rs +0 -417
  309. package/crates/team-agent/src/messaging/reminders.rs +0 -316
  310. package/crates/team-agent/src/messaging/results/collection_tests.rs +0 -719
  311. package/crates/team-agent/src/messaging/results.rs +0 -1415
  312. package/crates/team-agent/src/messaging/scheduler.rs +0 -223
  313. package/crates/team-agent/src/messaging/selftest.rs +0 -315
  314. package/crates/team-agent/src/messaging/send.rs +0 -981
  315. package/crates/team-agent/src/messaging/tests/basic.rs +0 -346
  316. package/crates/team-agent/src/messaging/tests/dup_inject.rs +0 -657
  317. package/crates/team-agent/src/messaging/tests/e23.rs +0 -49
  318. package/crates/team-agent/src/messaging/tests/leader_channel.rs +0 -169
  319. package/crates/team-agent/src/messaging/tests/leader_inject_acceptance.rs +0 -817
  320. package/crates/team-agent/src/messaging/tests/main_preserved.rs +0 -85
  321. package/crates/team-agent/src/messaging/tests/mod.rs +0 -306
  322. package/crates/team-agent/src/messaging/tests/runtime.rs +0 -3549
  323. package/crates/team-agent/src/messaging/tests/spine.rs +0 -853
  324. package/crates/team-agent/src/messaging/tests/wave2.rs +0 -381
  325. package/crates/team-agent/src/messaging/trust.rs +0 -215
  326. package/crates/team-agent/src/messaging/types.rs +0 -472
  327. package/crates/team-agent/src/messaging/wait.rs +0 -366
  328. package/crates/team-agent/src/messaging/watchers.rs +0 -916
  329. package/crates/team-agent/src/model/enums.rs +0 -356
  330. package/crates/team-agent/src/model/errors.rs +0 -18
  331. package/crates/team-agent/src/model/ids.rs +0 -165
  332. package/crates/team-agent/src/model/mod.rs +0 -29
  333. package/crates/team-agent/src/model/name_similarity.rs +0 -252
  334. package/crates/team-agent/src/model/pane_authority_refusal.rs +0 -359
  335. package/crates/team-agent/src/model/paths.rs +0 -257
  336. package/crates/team-agent/src/model/routing.rs +0 -387
  337. package/crates/team-agent/src/model/spec.rs +0 -1184
  338. package/crates/team-agent/src/model/task_graph.rs +0 -321
  339. package/crates/team-agent/src/model/testdata/fuzz.golden.yaml +0 -43
  340. package/crates/team-agent/src/model/testdata/fuzz.yaml +0 -43
  341. package/crates/team-agent/src/model/testdata/spec_invalid_a.yaml +0 -209
  342. package/crates/team-agent/src/model/testdata/team.spec.golden.yaml +0 -208
  343. package/crates/team-agent/src/model/testdata/team.spec.yaml +0 -208
  344. package/crates/team-agent/src/model/yaml/tests.rs +0 -188
  345. package/crates/team-agent/src/model/yaml.rs +0 -802
  346. package/crates/team-agent/src/os_probe.rs +0 -280
  347. package/crates/team-agent/src/packaging/install.rs +0 -219
  348. package/crates/team-agent/src/packaging/migrate.rs +0 -38
  349. package/crates/team-agent/src/packaging/mod.rs +0 -91
  350. package/crates/team-agent/src/packaging/repair.rs +0 -33
  351. package/crates/team-agent/src/packaging/tests.rs +0 -822
  352. package/crates/team-agent/src/packaging/types.rs +0 -417
  353. package/crates/team-agent/src/platform/argv.rs +0 -331
  354. package/crates/team-agent/src/platform/errors.rs +0 -104
  355. package/crates/team-agent/src/platform/file_lock.rs +0 -279
  356. package/crates/team-agent/src/platform/mod.rs +0 -5
  357. package/crates/team-agent/src/platform/process.rs +0 -545
  358. package/crates/team-agent/src/provider/adapter.rs +0 -1150
  359. package/crates/team-agent/src/provider/adapters/claude.rs +0 -78
  360. package/crates/team-agent/src/provider/adapters/claude_fork.rs +0 -131
  361. package/crates/team-agent/src/provider/adapters/copilot.rs +0 -75
  362. package/crates/team-agent/src/provider/adapters/copilot_fork.rs +0 -307
  363. package/crates/team-agent/src/provider/adapters/fake.rs +0 -18
  364. package/crates/team-agent/src/provider/adapters/mod.rs +0 -30
  365. package/crates/team-agent/src/provider/adapters/pi.rs +0 -106
  366. package/crates/team-agent/src/provider/approvals/mod.rs +0 -3
  367. package/crates/team-agent/src/provider/approvals/parsing.rs +0 -586
  368. package/crates/team-agent/src/provider/approvals/runtime_prompts.rs +0 -205
  369. package/crates/team-agent/src/provider/argv_route.rs +0 -405
  370. package/crates/team-agent/src/provider/bypass_flags.rs +0 -116
  371. package/crates/team-agent/src/provider/classify.rs +0 -708
  372. package/crates/team-agent/src/provider/command_helpers.rs +0 -45
  373. package/crates/team-agent/src/provider/faults.rs +0 -165
  374. package/crates/team-agent/src/provider/helpers.rs +0 -52
  375. package/crates/team-agent/src/provider/mod.rs +0 -78
  376. package/crates/team-agent/src/provider/model_catalog.rs +0 -910
  377. package/crates/team-agent/src/provider/session/capture.rs +0 -2731
  378. package/crates/team-agent/src/provider/session/context_fork/claude.rs +0 -123
  379. package/crates/team-agent/src/provider/session/context_fork/outcome.rs +0 -172
  380. package/crates/team-agent/src/provider/session/context_fork.rs +0 -396
  381. package/crates/team-agent/src/provider/session/mod.rs +0 -36
  382. package/crates/team-agent/src/provider/session/resume.rs +0 -269
  383. package/crates/team-agent/src/provider/session_scan/claude.rs +0 -523
  384. package/crates/team-agent/src/provider/session_scan/common/tests.rs +0 -316
  385. package/crates/team-agent/src/provider/session_scan/common.rs +0 -654
  386. package/crates/team-agent/src/provider/session_scan/copilot.rs +0 -280
  387. package/crates/team-agent/src/provider/session_scan/pi.rs +0 -185
  388. package/crates/team-agent/src/provider/session_scan.rs +0 -71
  389. package/crates/team-agent/src/provider/startup_prompt.rs +0 -757
  390. package/crates/team-agent/src/provider/submit_now.rs +0 -71
  391. package/crates/team-agent/src/provider/testdata/copilot-ready-marker.txt +0 -5
  392. package/crates/team-agent/src/provider/testdata/copilot-trust-prompt.txt +0 -19
  393. package/crates/team-agent/src/provider/testdata/grok-models-authenticated.stdout +0 -9
  394. package/crates/team-agent/src/provider/testdata/grok-models-unauthenticated.stdout +0 -7
  395. package/crates/team-agent/src/provider/tests/adapter.rs +0 -441
  396. package/crates/team-agent/src/provider/tests/classify.rs +0 -148
  397. package/crates/team-agent/src/provider/tests/command_helpers.rs +0 -35
  398. package/crates/team-agent/src/provider/tests/copilot_fork.rs +0 -191
  399. package/crates/team-agent/src/provider/tests/faults.rs +0 -200
  400. package/crates/team-agent/src/provider/tests/idle.rs +0 -177
  401. package/crates/team-agent/src/provider/tests/wire.rs +0 -213
  402. package/crates/team-agent/src/provider/tests.rs +0 -32
  403. package/crates/team-agent/src/provider/types.rs +0 -529
  404. package/crates/team-agent/src/provider/wire.rs +0 -394
  405. package/crates/team-agent/src/redaction.rs +0 -259
  406. package/crates/team-agent/src/state/abnormal_watch/tests/mod.rs +0 -248
  407. package/crates/team-agent/src/state/abnormal_watch.rs +0 -144
  408. package/crates/team-agent/src/state/identity.rs +0 -914
  409. package/crates/team-agent/src/state/identity_keys.rs +0 -132
  410. package/crates/team-agent/src/state/mod.rs +0 -74
  411. package/crates/team-agent/src/state/owner_gate.rs +0 -482
  412. package/crates/team-agent/src/state/ownership.rs +0 -563
  413. package/crates/team-agent/src/state/paths.rs +0 -395
  414. package/crates/team-agent/src/state/persist.rs +0 -3811
  415. package/crates/team-agent/src/state/projection.rs +0 -1508
  416. package/crates/team-agent/src/state/repository/intent.rs +0 -14
  417. package/crates/team-agent/src/state/repository/tests.rs +0 -184
  418. package/crates/team-agent/src/state/repository.rs +0 -866
  419. package/crates/team-agent/src/state/selector.rs +0 -160
  420. package/crates/team-agent/src/state/testdata/state-rich.canonical.json +0 -133
  421. package/crates/team-agent/src/test_support/models_timeout_fixture.rs +0 -144
  422. package/crates/team-agent/src/tmux_backend/enter_rescue.rs +0 -325
  423. package/crates/team-agent/src/tmux_backend/enter_rescue_tests.rs +0 -432
  424. package/crates/team-agent/src/tmux_backend/native_input.rs +0 -513
  425. package/crates/team-agent/src/tmux_backend/native_input_tests.rs +0 -742
  426. package/crates/team-agent/src/tmux_backend/tests.rs +0 -4103
  427. package/crates/team-agent/src/tmux_backend.rs +0 -4492
  428. package/crates/team-agent/src/topology.rs +0 -537
  429. package/crates/team-agent/src/transport/enter_rescue.rs +0 -166
  430. package/crates/team-agent/src/transport/native_input.rs +0 -491
  431. package/crates/team-agent/src/transport/test_support.rs +0 -743
  432. package/crates/team-agent/src/transport/tests/behavior.rs +0 -326
  433. package/crates/team-agent/src/transport/tests/mod.rs +0 -194
  434. package/crates/team-agent/src/transport/tests/wire.rs +0 -574
  435. package/crates/team-agent/src/transport.rs +0 -1655
  436. package/crates/team-agent/src/transport_factory.rs +0 -819
@@ -1,1150 +0,0 @@
1
- //!
2
- //! ProviderAdapter trait(per-provider 命令构造 + 能力面)+ registry facade + 占位实现。
3
-
4
- use std::path::{Path, PathBuf};
5
- use std::process::Command;
6
-
7
- use super::helpers::patterns;
8
- use super::types::{
9
- AuthHintStatus, CapturedSession, CommandPlan, McpConfig, ProviderCaps, ProviderCommandContext,
10
- ProviderError, SessionId, StatusPatterns,
11
- };
12
- use super::{AuthMode, Provider};
13
-
14
- pub use crate::provider::session_scan::{CaptureSessionContext, CapturedSessionCandidate};
15
-
16
- // ===========================================================================
17
- // TRAIT: ProviderAdapter (method SIGNATURES only — 无 body)
18
- // ===========================================================================
19
-
20
- /// 单一真相 per-provider 命令构造器 + 能力面(`provider_cli/adapter.py` `ProviderAdapter`
21
- /// 基类的 Rust 等价)。claude/codex/gemini/fake 各一 impl;copilot/opencode 占位 impl
22
- /// 调用即返 `ProviderError::CapabilityUnsupported`。
23
- ///
24
- /// fallible 边界(§10):任何触碰 fs / 子进程 / provider 日志的方法返 `Result`;
25
- /// 纯查询(caps)返值。**MUST-NOT-13**:trait 实现绝不调 provider client / network SDK。
26
- pub trait ProviderAdapter {
27
- /// 此 adapter 对应的 provider(claude_code 归一后单变体)。
28
- fn provider(&self) -> Provider;
29
-
30
- /// 静态能力声明(doc §59)。
31
- fn caps(&self) -> ProviderCaps;
32
-
33
- /// CLI 是否已安装(doctor;`adapter.py` is_installed)。
34
- fn is_installed(&self) -> bool;
35
-
36
- /// CLI 版本字符串(doctor;`adapter.py` version)。I/O → Result。
37
- fn version(&self) -> Result<String, ProviderError>;
38
-
39
- /// auth 状态提示(doctor;`adapter.py:38` auth_hint)。
40
- fn auth_hint(&self, auth_mode: AuthMode) -> AuthHintStatus;
41
-
42
- /// 构造 launch 命令(含 MCP 注入 / 权限模式 / system prompt / model)。
43
- /// 返回可 exec 的 argv(`adapter.py` build_command;`providers.py:54`)。
44
- fn build_command(
45
- &self,
46
- auth_mode: AuthMode,
47
- mcp_config: Option<&McpConfig>,
48
- system_prompt: Option<&str>,
49
- model: Option<&str>,
50
- ) -> Result<Vec<String>, ProviderError>;
51
-
52
- /// Same as [`ProviderAdapter::build_command`], with the explicit bypass flag.
53
- fn build_command_with_permissions(
54
- &self,
55
- auth_mode: AuthMode,
56
- mcp_config: Option<&McpConfig>,
57
- system_prompt: Option<&str>,
58
- model: Option<&str>,
59
- dangerously_skip_permissions: bool,
60
- ) -> Result<Vec<String>, ProviderError>;
61
-
62
- fn build_command_plan(
63
- &self,
64
- ctx: ProviderCommandContext<'_>,
65
- ) -> Result<CommandPlan, ProviderError> {
66
- self.build_command_with_permissions(
67
- ctx.auth_mode,
68
- ctx.mcp_config,
69
- ctx.system_prompt,
70
- ctx.model,
71
- ctx.dangerously_skip_permissions,
72
- )
73
- .map(CommandPlan::argv_only)
74
- }
75
-
76
- /// 启动后从 provider session 日志捕获 session_id + rollout_path
77
- /// (`claude.py:73`/`codex.py:62`)。fs watch / mtime fallback / repair。
78
- fn capture_session_id(
79
- &self,
80
- agent_id: &str,
81
- spawn_cwd: &std::path::Path,
82
- timeout_s: u64,
83
- ) -> Result<Option<CapturedSession>, ProviderError>;
84
-
85
- /// Internal capture surface for same-team multi-agent attribution: enumerate every
86
- /// cwd-matching provider transcript candidate, then let the runtime allocate them
87
- /// once per tick/restart pass using per-agent context.
88
- fn capture_session_candidates(
89
- &self,
90
- context: &CaptureSessionContext,
91
- timeout_s: u64,
92
- ) -> Result<Vec<CapturedSessionCandidate>, ProviderError> {
93
- Ok(self
94
- .capture_session_id(&context.agent_id, &context.spawn_cwd, timeout_s)?
95
- .into_iter()
96
- .map(|captured| CapturedSessionCandidate {
97
- captured,
98
- embedded_agent_id: None,
99
- positive_agent_id_match: false,
100
- agent_path_match: false,
101
- })
102
- .collect())
103
- }
104
-
105
- /// restart/reset 路径:从已存 transcript/rollout 回收 session_id
106
- /// (`claude.py:115`)。`None` 合法(找不到)。
107
- fn recover_session_id(
108
- &self,
109
- agent_id: &str,
110
- spawn_cwd: &std::path::Path,
111
- ) -> Result<Option<SessionId>, ProviderError>;
112
-
113
- /// 给定 session 是否可 resume(`claude.py:143`)。bug-085:compatible_api
114
- /// `session_id=None` → 不可 resume(`false`,不崩)。
115
- fn session_is_resumable(
116
- &self,
117
- session_id: Option<&SessionId>,
118
- auth_mode: AuthMode,
119
- ) -> Result<bool, ProviderError>;
120
-
121
- /// 构造 resume 命令(`providers.py:74`)。不可 resume → `Err(ResumeUnavailable)`。
122
- fn build_resume_command(
123
- &self,
124
- session_id: Option<&SessionId>,
125
- auth_mode: AuthMode,
126
- mcp_config: Option<&McpConfig>,
127
- ) -> Result<Vec<String>, ProviderError>;
128
-
129
- fn build_resume_command_with_context(
130
- &self,
131
- session_id: Option<&SessionId>,
132
- auth_mode: AuthMode,
133
- mcp_config: Option<&McpConfig>,
134
- system_prompt: Option<&str>,
135
- model: Option<&str>,
136
- dangerously_skip_permissions: bool,
137
- ) -> Result<Vec<String>, ProviderError>;
138
-
139
- fn build_resume_command_plan(
140
- &self,
141
- session_id: Option<&SessionId>,
142
- ctx: ProviderCommandContext<'_>,
143
- ) -> Result<CommandPlan, ProviderError> {
144
- self.build_resume_command_with_context(
145
- session_id,
146
- ctx.auth_mode,
147
- ctx.mcp_config,
148
- ctx.system_prompt,
149
- ctx.model,
150
- ctx.dangerously_skip_permissions,
151
- )
152
- .map(CommandPlan::argv_only)
153
- }
154
-
155
- /// 构造 fork 命令(`providers.py:99`)。fork 需 caps.fork ∧ auth_mode!=compatible_api;
156
- /// 不支持 → `Err`。
157
- fn fork(
158
- &self,
159
- session_id: Option<&SessionId>,
160
- auth_mode: AuthMode,
161
- mcp_config: Option<&McpConfig>,
162
- ) -> Result<Vec<String>, ProviderError>;
163
-
164
- fn fork_with_context(
165
- &self,
166
- session_id: Option<&SessionId>,
167
- auth_mode: AuthMode,
168
- mcp_config: Option<&McpConfig>,
169
- system_prompt: Option<&str>,
170
- model: Option<&str>,
171
- dangerously_skip_permissions: bool,
172
- ) -> Result<Vec<String>, ProviderError>;
173
-
174
- fn fork_plan(
175
- &self,
176
- session_id: Option<&SessionId>,
177
- ctx: ProviderCommandContext<'_>,
178
- ) -> Result<CommandPlan, ProviderError> {
179
- self.fork_with_context(
180
- session_id,
181
- ctx.auth_mode,
182
- ctx.mcp_config,
183
- ctx.system_prompt,
184
- ctx.model,
185
- ctx.dangerously_skip_permissions,
186
- )
187
- .map(CommandPlan::argv_only)
188
- }
189
-
190
- /// 计算本 provider 该用的 MCP server 配置(`adapter.py` mcp_config;claude
191
- /// compatible_api 走 `ensure_compatible_claude_mcp_config`)。
192
- fn mcp_config(&self, auth_mode: AuthMode) -> Result<McpConfig, ProviderError>;
193
-
194
- /// Eager stdio clients must publish their initial MCP handshake before input.
195
- /// Pi owns admission in its runtime registry hooks; Fake has no MCP client.
196
- /// The process-stamp receipt port is currently POSIX-only, not a Windows claim.
197
- fn requires_worker_mcp_handshake(&self) -> bool {
198
- cfg!(unix) && !matches!(self.provider(), Provider::Fake | Provider::Pi)
199
- }
200
-
201
- /// 安装 MCP server。gemini 写全局 `~/.gemini/settings.json` 并备份/还原
202
- /// (`gemini.py:40-78`)——有副作用 I/O,失败可还原 → Result。
203
- fn install_mcp(&self, config: &McpConfig) -> Result<(), ProviderError>;
204
-
205
- /// idle/processing/trust 识别正则集(`claude.py`/`codex.py` status_patterns)。
206
- /// pane→status 检测用。返编译失败可能 → Result(`re.error` 容错)。
207
- fn status_patterns(&self) -> Result<StatusPatterns, ProviderError>;
208
-
209
- /// 校验 model 名对本 provider 合法(`codex debug models` 等;doctor)。
210
- fn validate_model(&self, model: &str) -> Result<bool, ProviderError>;
211
-
212
- /// Provider-specific startup prompt handling. Codex and Claude delegate to
213
- /// provider-layer recognizers; providers without startup prompts return an
214
- /// empty list.
215
- fn handle_startup_prompts(
216
- &self,
217
- transport: &dyn crate::transport::Transport,
218
- target: &crate::transport::Target,
219
- checks: usize,
220
- sleep_s: f64,
221
- ) -> Vec<crate::provider::HandledPrompt> {
222
- self.handle_startup_prompts_outcome(transport, target, checks, sleep_s)
223
- .handled
224
- }
225
-
226
- /// swallow batch 2 ② (A1): the structured variant — `capture_error` surfaces a pane
227
- /// that could not even be captured, so callers can log the failure instead of
228
- /// silently treating it as "no prompts" (CLAUDE.md §5).
229
- fn handle_startup_prompts_outcome(
230
- &self,
231
- transport: &dyn crate::transport::Transport,
232
- target: &crate::transport::Target,
233
- checks: usize,
234
- sleep_s: f64,
235
- ) -> super::startup_prompt::StartupPromptOutcome {
236
- std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| match self.provider() {
237
- Provider::Codex => super::startup_prompt::codex_handle_startup_prompts(
238
- transport, target, checks, sleep_s,
239
- ),
240
- Provider::Claude | Provider::ClaudeCode => {
241
- super::startup_prompt::claude_handle_startup_prompts(
242
- transport, target, checks, sleep_s,
243
- )
244
- }
245
- Provider::Copilot => super::startup_prompt::copilot_handle_startup_prompts(
246
- transport, target, checks, sleep_s,
247
- ),
248
- _ => super::startup_prompt::StartupPromptOutcome::default(),
249
- }))
250
- .unwrap_or_default()
251
- }
252
- }
253
-
254
- // ===========================================================================
255
- // FACADE 自由函数 (doc §71 providers.get_adapter — body unimplemented)
256
- // ===========================================================================
257
-
258
- /// `providers.get_adapter(provider)`(`providers.py:47`)——拿某 provider 的命令构造器。
259
- /// `claude`/`claude_code` 指向同一 adapter(`Provider::ClaudeCode` 单变体已归一);
260
- /// copilot/opencode 返占位 adapter(调用即 `CapabilityUnsupported`)。
261
- pub fn get_adapter(p: Provider) -> Box<dyn ProviderAdapter> {
262
- Box::new(BasicProviderAdapter { provider: p })
263
- }
264
-
265
- #[cfg(test)]
266
- #[path = "tests/command_helpers.rs"]
267
- mod command_helpers_tests;
268
-
269
- #[derive(Debug, Clone, Copy)]
270
- pub(crate) struct BasicProviderAdapter {
271
- provider: Provider,
272
- }
273
-
274
- impl ProviderAdapter for BasicProviderAdapter {
275
- fn provider(&self) -> Provider {
276
- self.provider
277
- }
278
-
279
- fn caps(&self) -> ProviderCaps {
280
- match self.provider {
281
- Provider::Claude | Provider::ClaudeCode => ProviderCaps {
282
- resume: true,
283
- fork: true,
284
- native_mcp_config: true,
285
- writes_global_settings: false,
286
- },
287
- // Copilot resume 走 --resume <sid>;store fork 在隔离 COPILOT_HOME
288
- // 复制并重键 session backing 后以 --resume <new sid> 启动。
289
- // native_mcp_config=true(`--additional-mcp-config` 接 inline JSON 或 @file);
290
- // writes_global_settings=false(session 走 --session-id 预定 UUID,不污染
291
- // ~/.copilot/mcp-config.json,help 原文 "augments config for this session")。
292
- Provider::Copilot => ProviderCaps {
293
- resume: true,
294
- fork: true,
295
- native_mcp_config: true,
296
- writes_global_settings: false,
297
- },
298
- Provider::GeminiCli => ProviderCaps {
299
- resume: false,
300
- fork: false,
301
- native_mcp_config: false,
302
- writes_global_settings: true,
303
- },
304
- // Codex and Grok workers run only through their contract leaves. A
305
- // persisted legacy row is neither resumable nor capture-pending.
306
- Provider::Codex | Provider::Grok => ProviderCaps {
307
- resume: false,
308
- fork: false,
309
- native_mcp_config: false,
310
- writes_global_settings: false,
311
- },
312
- Provider::Pi => ProviderCaps {
313
- resume: true,
314
- fork: false,
315
- native_mcp_config: false,
316
- writes_global_settings: false,
317
- },
318
- Provider::Fake => ProviderCaps {
319
- resume: false,
320
- fork: false,
321
- native_mcp_config: false,
322
- writes_global_settings: false,
323
- },
324
- }
325
- }
326
-
327
- fn is_installed(&self) -> bool {
328
- if matches!(self.provider, Provider::Fake) {
329
- return true;
330
- }
331
- command_on_path(command_name(self.provider))
332
- }
333
-
334
- fn version(&self) -> Result<String, ProviderError> {
335
- if matches!(self.provider, Provider::Fake) {
336
- return Ok("fake".to_string());
337
- }
338
- let output = Command::new(command_name(self.provider))
339
- .arg("--version")
340
- .output()
341
- .map_err(|e| {
342
- ProviderError::Io(format!("{} --version: {e}", command_name(self.provider)))
343
- })?;
344
- if !output.status.success() {
345
- return Ok("unknown".to_string());
346
- }
347
- let text = String::from_utf8_lossy(&output.stdout).trim().to_string();
348
- if text.is_empty() {
349
- Ok("unknown".to_string())
350
- } else {
351
- Ok(text)
352
- }
353
- }
354
-
355
- fn auth_hint(&self, auth_mode: AuthMode) -> AuthHintStatus {
356
- match self.provider {
357
- Provider::Claude | Provider::ClaudeCode => claude_auth_hint(auth_mode),
358
- // C-A-5 cr verdict v2(诚实 MUST-NOT-13) — copilot 无 auth status 子命令
359
- // (main-help Commands 节仅 completion/help/init/login/mcp/plugin/update/
360
- // version)。framework 只能弱检测(命令在 PATH + ~/.copilot/config.json
361
- // 存在),不能假报强 Present;Subscription 档返 PresentWeak,doctor 文案
362
- // 标"weak / no auth-status command available";Compatible/Official 走 BYOK
363
- // 路径,有 COPILOT_PROVIDER_BASE_URL 时已脱离 GitHub 登录通道。
364
- Provider::Copilot => copilot_auth_hint(auth_mode),
365
- // No legacy worker probe remains for Codex or Grok.
366
- Provider::Codex | Provider::Grok | Provider::Pi => AuthHintStatus::Unknown,
367
- _ => match auth_mode {
368
- AuthMode::Subscription => AuthHintStatus::Present,
369
- AuthMode::OfficialApi | AuthMode::CompatibleApi => AuthHintStatus::MissingOrUnknown,
370
- },
371
- }
372
- }
373
-
374
- fn build_command(
375
- &self,
376
- auth_mode: AuthMode,
377
- mcp_config: Option<&McpConfig>,
378
- system_prompt: Option<&str>,
379
- model: Option<&str>,
380
- ) -> Result<Vec<String>, ProviderError> {
381
- self.build_command_with_permissions(auth_mode, mcp_config, system_prompt, model, false)
382
- }
383
-
384
- fn build_command_with_permissions(
385
- &self,
386
- auth_mode: AuthMode,
387
- mcp_config: Option<&McpConfig>,
388
- system_prompt: Option<&str>,
389
- model: Option<&str>,
390
- dangerously_skip_permissions: bool,
391
- ) -> Result<Vec<String>, ProviderError> {
392
- match self.provider {
393
- Provider::Claude | Provider::ClaudeCode => Ok(claude_launch_command(
394
- self,
395
- auth_mode,
396
- mcp_config,
397
- system_prompt,
398
- model,
399
- dangerously_skip_permissions,
400
- )?),
401
- // §C1 worker argv 形态 + C-1/C-5/C-6 cr verdict:
402
- // copilot --no-color --no-auto-update [<dangerous|granular>] [--model]
403
- // --additional-mcp-config <inline json> --session-id <expected_uuid> -C <cwd>
404
- // system_prompt 经 spawn env(COPILOT_CUSTOM_INSTRUCTIONS_DIRS)+ per-worker
405
- // AGENTS.md(launch 路径写文件,见 lifecycle/launch.rs)注入,**不入 argv**
406
- // (B2 灵魂件降级,C-1-2 禁 silent 写全局)。
407
- Provider::Copilot => Ok(copilot_base_command(
408
- auth_mode,
409
- mcp_config,
410
- system_prompt,
411
- model,
412
- dangerously_skip_permissions,
413
- )),
414
- Provider::GeminiCli => {
415
- let mut argv = vec!["gemini".to_string()];
416
- if let Some(model) = model {
417
- argv.push("--model".to_string());
418
- argv.push(model.to_string());
419
- }
420
- Ok(argv)
421
- }
422
- Provider::Codex | Provider::Grok => {
423
- Err(ProviderError::Command(retired_worker(self.provider)))
424
- }
425
- Provider::Pi => Err(ProviderError::Command(
426
- "Pi commands require the shared lifecycle materializer".to_string(),
427
- )),
428
- Provider::Fake => Ok(fake_worker_command()),
429
- }
430
- }
431
-
432
- fn build_command_plan(
433
- &self,
434
- ctx: ProviderCommandContext<'_>,
435
- ) -> Result<CommandPlan, ProviderError> {
436
- match self.provider {
437
- Provider::Claude | Provider::ClaudeCode => {
438
- // 0.4.7 (B1 verified, restart partial resume): RESTORE
439
- // `--session-id <uuid>` on Claude fresh spawn. B1 confirmed
440
- // Claude ≥ 2.1.185 honours the framework-supplied --session-id
441
- // and creates a transcript at that id. The earlier 0.4.6
442
- // P0 removal (commit 9feafc31) is reverted; the actual issue
443
- // it tried to fix (leader-marker pollution) is addressed
444
- // separately in commit d39b5104 (leader session exclusion
445
- // in capture/repair).
446
- //
447
- // Fresh path: --session-id <expected> → Claude writes
448
- // transcript at that id → capture/restart restore use the
449
- // SAME id we predicted, so apply-time backing-store check
450
- // passes immediately (no cwd+spawned_at attribution race).
451
- //
452
- // Resume path unchanged — `build_resume_command_plan` uses
453
- // `--resume <existing_id>` on a session id that already has
454
- // a real transcript.
455
- let expected = next_session_token();
456
- let managed = ctx
457
- .profile_launch
458
- .is_some_and(|profile| profile.managed_mcp_config);
459
- let projects_root = ctx
460
- .profile_launch
461
- .and_then(|profile| profile.claude_projects_root.clone());
462
- let model = claude_context_model(ctx);
463
- let mut argv = claude_base_command(
464
- self,
465
- ctx.auth_mode,
466
- ctx.mcp_config,
467
- ctx.system_prompt,
468
- model,
469
- ctx.dangerously_skip_permissions,
470
- managed,
471
- ctx.effort,
472
- )?;
473
- argv.push("--session-id".to_string());
474
- argv.push(expected.clone());
475
- // Layer 1 self-healing (architect probe 2026-06-22, claude help
476
- // `-n, --name <name>`): pass `--name <agent_id>` so the
477
- // resume picker and on-disk `~/.claude/sessions/*.json name`
478
- // field carry our role label.
479
- if let Some(agent_id) = ctx.agent_id_hint {
480
- if !agent_id.is_empty() {
481
- argv.push("--name".to_string());
482
- argv.push(agent_id.to_string());
483
- }
484
- }
485
- Ok(CommandPlan {
486
- argv,
487
- expected_session_id: Some(SessionId::new(expected)),
488
- provider_projects_root: projects_root,
489
- managed_mcp_config: managed,
490
- })
491
- }
492
- // §C1 + §C4 cr verdict — copilot plan 端预定 UUID + workspace `-C` 双保险:
493
- // * `--session-id <uuid>`(claude 同法,捕获免目录扫描,sqlite 仅校验)
494
- // * `-C <workspace>`(双保险,即便 spawn cwd 漂移也能锚定)
495
- // mcp_config inline 形态由 build_command 写入,launch 路径会用
496
- // point_native_mcp_config_at_file 重写为 @<file> 形(§C1 note)。
497
- Provider::Copilot => {
498
- let expected = next_session_token();
499
- let mut argv = copilot_base_command(
500
- ctx.auth_mode,
501
- ctx.mcp_config,
502
- ctx.system_prompt,
503
- ctx.model,
504
- ctx.dangerously_skip_permissions,
505
- );
506
- argv.push("--session-id".to_string());
507
- argv.push(expected.clone());
508
- Ok(CommandPlan {
509
- argv,
510
- expected_session_id: Some(SessionId::new(expected)),
511
- provider_projects_root: None,
512
- managed_mcp_config: false,
513
- })
514
- }
515
- Provider::Codex | Provider::Grok => {
516
- Err(ProviderError::Command(retired_worker(self.provider)))
517
- }
518
- Provider::Pi => Err(ProviderError::Command(
519
- "Pi commands require the shared lifecycle materializer".to_string(),
520
- )),
521
- _ => self
522
- .build_command_with_permissions(
523
- ctx.auth_mode,
524
- ctx.mcp_config,
525
- ctx.system_prompt,
526
- ctx.model,
527
- ctx.dangerously_skip_permissions,
528
- )
529
- .map(CommandPlan::argv_only),
530
- }
531
- }
532
-
533
- fn capture_session_id(
534
- &self,
535
- agent_id: &str,
536
- spawn_cwd: &Path,
537
- timeout_s: u64,
538
- ) -> Result<Option<CapturedSession>, ProviderError> {
539
- let context = CaptureSessionContext {
540
- agent_id: agent_id.to_string(),
541
- spawn_cwd: spawn_cwd.to_path_buf(),
542
- pane_id: None,
543
- pane_pid: None,
544
- spawned_at: None,
545
- expected_session_id: None,
546
- provider_projects_root: None,
547
- };
548
- Ok(self
549
- .capture_session_candidates(&context, timeout_s)?
550
- .into_iter()
551
- .next()
552
- .map(|candidate| candidate.captured))
553
- }
554
-
555
- fn capture_session_candidates(
556
- &self,
557
- context: &CaptureSessionContext,
558
- timeout_s: u64,
559
- ) -> Result<Vec<CapturedSessionCandidate>, ProviderError> {
560
- let deadline = std::time::Instant::now() + std::time::Duration::from_secs(timeout_s);
561
- loop {
562
- let out = crate::provider::session_scan::scan_session_candidates_once(
563
- self.provider,
564
- context,
565
- )?;
566
- if !out.is_empty() || timeout_s == 0 || std::time::Instant::now() >= deadline {
567
- return Ok(out);
568
- }
569
- std::thread::sleep(std::time::Duration::from_millis(100));
570
- }
571
- }
572
-
573
- fn recover_session_id(
574
- &self,
575
- agent_id: &str,
576
- spawn_cwd: &Path,
577
- ) -> Result<Option<SessionId>, ProviderError> {
578
- Ok(self
579
- .capture_session_id(agent_id, spawn_cwd, 0)?
580
- .and_then(|captured| captured.session_id))
581
- }
582
-
583
- fn session_is_resumable(
584
- &self,
585
- session_id: Option<&SessionId>,
586
- auth_mode: AuthMode,
587
- ) -> Result<bool, ProviderError> {
588
- if session_id.is_none() || auth_mode == AuthMode::CompatibleApi {
589
- return Ok(false);
590
- }
591
- Ok(self.caps().resume)
592
- }
593
-
594
- fn build_resume_command(
595
- &self,
596
- session_id: Option<&SessionId>,
597
- auth_mode: AuthMode,
598
- mcp_config: Option<&McpConfig>,
599
- ) -> Result<Vec<String>, ProviderError> {
600
- self.build_resume_command_with_context(session_id, auth_mode, mcp_config, None, None, false)
601
- }
602
-
603
- fn build_resume_command_with_context(
604
- &self,
605
- session_id: Option<&SessionId>,
606
- auth_mode: AuthMode,
607
- mcp_config: Option<&McpConfig>,
608
- system_prompt: Option<&str>,
609
- model: Option<&str>,
610
- dangerously_skip_permissions: bool,
611
- ) -> Result<Vec<String>, ProviderError> {
612
- if !self.session_is_resumable(session_id, auth_mode)? {
613
- return Err(ProviderError::ResumeUnavailable(format!(
614
- "{} resume requires session_id",
615
- provider_wire(self.provider)
616
- )));
617
- }
618
- let Some(session_id) = session_id else {
619
- return Err(ProviderError::ResumeUnavailable(
620
- "resume requires session_id".to_string(),
621
- ));
622
- };
623
- match self.provider {
624
- Provider::Claude | Provider::ClaudeCode => {
625
- let mut argv = claude_base_command(
626
- self,
627
- auth_mode,
628
- mcp_config,
629
- system_prompt,
630
- model,
631
- dangerously_skip_permissions,
632
- false,
633
- None,
634
- )?;
635
- argv.push("--resume".to_string());
636
- argv.push(session_id.as_str().to_string());
637
- Ok(argv)
638
- }
639
- // §C1 cr verdict:resume 同 base + `--resume <sid>`(去 --session-id,
640
- // copilot --resume 接受 id|name)。
641
- Provider::Copilot => {
642
- let mut argv =
643
- copilot_base_command(auth_mode, mcp_config, system_prompt, model, dangerously_skip_permissions);
644
- argv.push("--resume".to_string());
645
- argv.push(session_id.as_str().to_string());
646
- Ok(argv)
647
- }
648
- Provider::Codex | Provider::Grok => {
649
- Err(ProviderError::ResumeUnavailable(retired_worker(self.provider)))
650
- }
651
- Provider::Pi => Err(ProviderError::ResumeUnavailable(
652
- "pi resume requires the captured exact session path".to_string(),
653
- )),
654
- Provider::GeminiCli | Provider::Fake => Err(ProviderError::ResumeUnavailable(format!(
655
- "{} resume requires session_id",
656
- provider_wire(self.provider)
657
- ))),
658
- }
659
- }
660
-
661
- fn build_resume_command_plan(
662
- &self,
663
- session_id: Option<&SessionId>,
664
- ctx: ProviderCommandContext<'_>,
665
- ) -> Result<CommandPlan, ProviderError> {
666
- match self.provider {
667
- Provider::Claude | Provider::ClaudeCode => {
668
- let Some(session_id) = session_id else {
669
- return Err(ProviderError::ResumeUnavailable(
670
- "resume requires session_id".to_string(),
671
- ));
672
- };
673
- let managed = ctx
674
- .profile_launch
675
- .is_some_and(|profile| profile.managed_mcp_config);
676
- let model = claude_context_model(ctx);
677
- let mut argv = claude_base_command(
678
- self,
679
- ctx.auth_mode,
680
- ctx.mcp_config,
681
- ctx.system_prompt,
682
- model,
683
- ctx.dangerously_skip_permissions,
684
- managed,
685
- ctx.effort,
686
- )?;
687
- argv.push("--resume".to_string());
688
- argv.push(session_id.as_str().to_string());
689
- // Layer 1 self-healing: keep the role name on resume too —
690
- // makes resumed sessions findable in the picker by agent_id
691
- // when state.json drifts.
692
- if let Some(agent_id) = ctx.agent_id_hint {
693
- if !agent_id.is_empty() {
694
- argv.push("--name".to_string());
695
- argv.push(agent_id.to_string());
696
- }
697
- }
698
- let mut plan = CommandPlan::argv_only(argv);
699
- plan.provider_projects_root = ctx
700
- .profile_launch
701
- .and_then(|profile| profile.claude_projects_root.clone());
702
- plan.managed_mcp_config = managed;
703
- Ok(plan)
704
- }
705
- _ => self
706
- .build_resume_command_with_context(
707
- session_id,
708
- ctx.auth_mode,
709
- ctx.mcp_config,
710
- ctx.system_prompt,
711
- ctx.model,
712
- ctx.dangerously_skip_permissions,
713
- )
714
- .map(CommandPlan::argv_only),
715
- }
716
- }
717
-
718
- fn fork(
719
- &self,
720
- session_id: Option<&SessionId>,
721
- auth_mode: AuthMode,
722
- mcp_config: Option<&McpConfig>,
723
- ) -> Result<Vec<String>, ProviderError> {
724
- self.fork_with_context(session_id, auth_mode, mcp_config, None, None, false)
725
- }
726
-
727
- fn fork_with_context(
728
- &self,
729
- session_id: Option<&SessionId>,
730
- auth_mode: AuthMode,
731
- mcp_config: Option<&McpConfig>,
732
- system_prompt: Option<&str>,
733
- model: Option<&str>,
734
- dangerously_skip_permissions: bool,
735
- ) -> Result<Vec<String>, ProviderError> {
736
- if !self.caps().fork || auth_mode == AuthMode::CompatibleApi {
737
- return Err(ProviderError::CapabilityUnsupported(format!(
738
- "{} does not support native session fork",
739
- provider_wire(self.provider)
740
- )));
741
- }
742
- let Some(session_id) = session_id else {
743
- return Err(ProviderError::ResumeUnavailable(
744
- "fork requires session_id".to_string(),
745
- ));
746
- };
747
- match self.provider {
748
- Provider::Claude | Provider::ClaudeCode => {
749
- let mut argv = claude_base_command(
750
- self,
751
- auth_mode,
752
- mcp_config,
753
- system_prompt,
754
- model,
755
- dangerously_skip_permissions,
756
- false,
757
- None,
758
- )?;
759
- argv.push("--session-id".to_string());
760
- argv.push(next_session_token());
761
- argv.push("--resume".to_string());
762
- argv.push(session_id.as_str().to_string());
763
- argv.push("--fork-session".to_string());
764
- Ok(argv)
765
- }
766
- // Context-free adapter calls cannot materialize the Copilot store fork.
767
- // The lifecycle path uses `fork_plan`, which receives the prepared isolated
768
- // backing; never degrade this context-free call to a fresh spawn.
769
- Provider::Copilot => Err(ProviderError::CapabilityUnsupported(
770
- "copilot CLI 无 fork 旗标,session-store 不支持 branched continuation".to_string(),
771
- )),
772
- Provider::Codex | Provider::Grok => {
773
- Err(ProviderError::CapabilityUnsupported(retired_worker(self.provider)))
774
- }
775
- Provider::Pi | Provider::GeminiCli | Provider::Fake => {
776
- Err(ProviderError::CapabilityUnsupported(format!(
777
- "{} does not support native session fork",
778
- provider_wire(self.provider)
779
- )))
780
- }
781
- }
782
- }
783
-
784
- fn fork_plan(
785
- &self,
786
- session_id: Option<&SessionId>,
787
- ctx: ProviderCommandContext<'_>,
788
- ) -> Result<CommandPlan, ProviderError> {
789
- match self.provider {
790
- Provider::Claude | Provider::ClaudeCode => {
791
- if !self.caps().fork || ctx.auth_mode == AuthMode::CompatibleApi {
792
- return Err(ProviderError::CapabilityUnsupported(format!(
793
- "{} does not support native session fork",
794
- provider_wire(self.provider)
795
- )));
796
- }
797
- let Some(session_id) = session_id else {
798
- return Err(ProviderError::ResumeUnavailable(
799
- "fork requires session_id".to_string(),
800
- ));
801
- };
802
- let expected = next_session_token();
803
- let managed = ctx
804
- .profile_launch
805
- .is_some_and(|profile| profile.managed_mcp_config);
806
- let projects_root = ctx
807
- .profile_launch
808
- .and_then(|profile| profile.claude_projects_root.clone());
809
- let model = claude_context_model(ctx);
810
- let mut argv = claude_base_command(
811
- self,
812
- ctx.auth_mode,
813
- ctx.mcp_config,
814
- ctx.system_prompt,
815
- model,
816
- ctx.dangerously_skip_permissions,
817
- managed,
818
- ctx.effort,
819
- )?;
820
- // Native new-seat fork: Claude copies the parent (only read)
821
- // into the preassigned child, so capture binds the child
822
- // exactly as a fresh spawn. `--session-id` with `--resume` is
823
- // admitted only together with `--fork-session`.
824
- argv.push("--session-id".to_string());
825
- argv.push(expected.clone());
826
- argv.push("--resume".to_string());
827
- argv.push(session_id.as_str().to_string());
828
- argv.push("--fork-session".to_string());
829
- if let Some(agent_id) = ctx.agent_id_hint {
830
- if !agent_id.is_empty() {
831
- argv.push("--name".to_string());
832
- argv.push(agent_id.to_string());
833
- }
834
- }
835
- Ok(CommandPlan {
836
- argv,
837
- expected_session_id: Some(SessionId::new(expected)),
838
- provider_projects_root: projects_root,
839
- managed_mcp_config: managed,
840
- })
841
- }
842
- Provider::Copilot => {
843
- if ctx.auth_mode == AuthMode::CompatibleApi {
844
- return Err(ProviderError::CapabilityUnsupported(
845
- "copilot does not support session fork in compatible_api mode".to_string(),
846
- ));
847
- }
848
- let profile = ctx.profile_launch.ok_or_else(|| {
849
- ProviderError::Command(
850
- "copilot fork requires a prepared provider profile".to_string(),
851
- )
852
- })?;
853
- let expected = profile
854
- .env_overlay
855
- .get("TEAM_AGENT_INTERNAL_COPILOT_FORK_SESSION_ID")
856
- .filter(|value| !value.is_empty())
857
- .map(SessionId::new)
858
- .ok_or_else(|| {
859
- ProviderError::Command(
860
- "copilot fork session backing was not materialized".to_string(),
861
- )
862
- })?;
863
- let root = profile
864
- .env_overlay
865
- .get("COPILOT_HOME")
866
- .filter(|value| !value.is_empty())
867
- .map(PathBuf::from)
868
- .ok_or_else(|| {
869
- ProviderError::Command("copilot fork root was not materialized".to_string())
870
- })?;
871
- let mut argv = copilot_base_command(
872
- ctx.auth_mode,
873
- ctx.mcp_config,
874
- ctx.system_prompt,
875
- ctx.model,
876
- ctx.dangerously_skip_permissions,
877
- );
878
- argv.push("--resume".to_string());
879
- argv.push(expected.as_str().to_string());
880
- Ok(CommandPlan {
881
- argv,
882
- expected_session_id: Some(expected),
883
- provider_projects_root: Some(root),
884
- managed_mcp_config: profile.managed_mcp_config,
885
- })
886
- }
887
- _ => self
888
- .fork_with_context(
889
- session_id,
890
- ctx.auth_mode,
891
- ctx.mcp_config,
892
- ctx.system_prompt,
893
- ctx.model,
894
- ctx.dangerously_skip_permissions,
895
- )
896
- .map(CommandPlan::argv_only),
897
- }
898
- }
899
-
900
- fn mcp_config(&self, auth_mode: AuthMode) -> Result<McpConfig, ProviderError> {
901
- let server = mcp_server_config(auth_mode);
902
- Ok(McpConfig {
903
- raw: serde_json::json!({
904
- "team_orchestrator": server
905
- }),
906
- })
907
- }
908
-
909
- fn install_mcp(&self, config: &McpConfig) -> Result<(), ProviderError> {
910
- if !matches!(self.provider, Provider::GeminiCli) {
911
- return Ok(());
912
- }
913
- let Some(home) = std::env::var_os("HOME").map(PathBuf::from) else {
914
- return Err(ProviderError::Io("HOME is not set".to_string()));
915
- };
916
- let dir = home.join(".gemini");
917
- std::fs::create_dir_all(&dir)
918
- .map_err(|e| ProviderError::Io(format!("{}: {e}", dir.display())))?;
919
- let path = dir.join("settings.json");
920
- let text = serde_json::to_string_pretty(&config.raw)
921
- .map_err(|e| ProviderError::Command(format!("serialize mcp config: {e}")))?;
922
- std::fs::write(&path, text)
923
- .map_err(|e| ProviderError::Io(format!("{}: {e}", path.display())))?;
924
- Ok(())
925
- }
926
-
927
- fn status_patterns(&self) -> Result<StatusPatterns, ProviderError> {
928
- match self.provider {
929
- Provider::Claude | Provider::ClaudeCode => {
930
- patterns(r"[>❯]\s", r"[✶✢✽✻✳·].*…", r"Error|Traceback")
931
- }
932
- Provider::Copilot => patterns(
933
- r"(?m)^\s*❯\s*$| / commands · \? help",
934
- r"working|processing",
935
- r"Error|panic",
936
- ),
937
- // Codex and Grok workers run only through their contract leaves;
938
- // these placeholders never match real pane chrome.
939
- Provider::Codex | Provider::Grok => patterns(
940
- r"legacy-worker-idle-retired",
941
- r"legacy-worker-busy-retired",
942
- r"legacy-worker-error-retired",
943
- ),
944
- // Pi: 无已验证 turn-state 检测;占位串不会匹配真实 pane chrome。
945
- Provider::Pi => patterns(
946
- r"pi-idle-unset-until-turn-state",
947
- r"pi-busy-unset-until-turn-state",
948
- r"pi-error-unset-until-turn-state",
949
- ),
950
- Provider::GeminiCli | Provider::Fake => {
951
- patterns(r">", r"working|processing", r"Error|Traceback")
952
- }
953
- }
954
- }
955
-
956
- fn validate_model(&self, model: &str) -> Result<bool, ProviderError> {
957
- if self.provider != Provider::Pi {
958
- return Ok(true);
959
- }
960
- let (_, catalog) = crate::lifecycle::launch::pi_mcp::resolve_pi_executable_chain()?;
961
- Ok(crate::lifecycle::launch::pi_mcp::select_exact_pi_model(&catalog, model).is_ok())
962
- }
963
- }
964
-
965
- use crate::provider::wire::{command_name, provider_wire};
966
-
967
- /// Codex and Grok workers run only through their contract leaves
968
- /// (`provider: codex|grok`); their legacy worker builders were excised. Only a
969
- /// pre-upgrade state row can still name the legacy key.
970
- fn retired_worker(provider: Provider) -> String {
971
- format!(
972
- "legacy {} worker runtime was excised; workers run only through the contract leaf",
973
- provider_wire(provider)
974
- )
975
- }
976
-
977
- fn auth_mode_wire(auth_mode: AuthMode) -> &'static str {
978
- match auth_mode {
979
- AuthMode::Subscription => "subscription",
980
- AuthMode::OfficialApi => "official_api",
981
- AuthMode::CompatibleApi => "compatible_api",
982
- }
983
- }
984
-
985
- /// C-A-5 cr verdict v2 — copilot 弱检测(无 auth status 子命令)。
986
- /// 当 copilot 命令在 PATH 且 `~/.copilot/config.json` 存在 → PresentWeak;否则 Missing
987
- /// (PATH 缺)或 MissingOrUnknown(无 config 文件)。Compatible/Official 走 BYOK,
988
- /// 由 profile_launch 端校验(COPILOT_PROVIDER_BASE_URL 等),hint 层报 Unknown。
989
- fn copilot_auth_hint(auth_mode: AuthMode) -> AuthHintStatus {
990
- if !matches!(auth_mode, AuthMode::Subscription) {
991
- return AuthHintStatus::Unknown;
992
- }
993
- if !command_on_path("copilot") {
994
- return AuthHintStatus::Missing;
995
- }
996
- let Some(home) = std::env::var_os("HOME").map(PathBuf::from) else {
997
- return AuthHintStatus::MissingOrUnknown;
998
- };
999
- if home.join(".copilot").join("config.json").exists() {
1000
- AuthHintStatus::PresentWeak
1001
- } else {
1002
- AuthHintStatus::MissingOrUnknown
1003
- }
1004
- }
1005
-
1006
- fn claude_auth_hint(auth_mode: AuthMode) -> AuthHintStatus {
1007
- if auth_mode != AuthMode::Subscription {
1008
- return AuthHintStatus::MissingOrUnknown;
1009
- }
1010
- if !command_on_path("claude") {
1011
- return AuthHintStatus::Missing;
1012
- }
1013
- let output = match Command::new("claude").args(["auth", "status"]).output() {
1014
- Ok(output) => output,
1015
- Err(_) => return AuthHintStatus::MissingOrUnknown,
1016
- };
1017
- let text = if output.stdout.is_empty() {
1018
- String::from_utf8_lossy(&output.stderr).to_string()
1019
- } else {
1020
- String::from_utf8_lossy(&output.stdout).to_string()
1021
- };
1022
- let status = serde_json::from_str::<serde_json::Value>(text.trim()).unwrap_or_default();
1023
- if status.get("loggedIn").and_then(serde_json::Value::as_bool) == Some(true)
1024
- || output.status.success()
1025
- {
1026
- AuthHintStatus::Present
1027
- } else {
1028
- AuthHintStatus::Missing
1029
- }
1030
- }
1031
-
1032
- fn claude_context_model(ctx: ProviderCommandContext<'_>) -> Option<&str> {
1033
- ctx.profile_launch
1034
- .and_then(|profile| profile.command_overrides.model.as_deref())
1035
- .or(ctx.model)
1036
- }
1037
-
1038
- fn command_on_path(name: &str) -> bool {
1039
- let Some(path) = std::env::var_os("PATH") else {
1040
- return false;
1041
- };
1042
- std::env::split_paths(&path).any(|dir| dir.join(name).is_file())
1043
- }
1044
-
1045
- pub(crate) fn prompt_needs_native_mcp(prompt: &str) -> bool {
1046
- prompt.contains('\n') || prompt.contains('"')
1047
- }
1048
-
1049
- // 0.4.x decoupling step 2: provider-local command builders moved to provider/adapters/.
1050
- // Only the entry points the trait impl actually calls are re-imported here;
1051
- // The per-provider command helpers and MCP renderers are called from within
1052
- // the extracted base-command functions, not directly by this file.
1053
- use super::adapters::claude::{claude_base_command, claude_launch_command};
1054
- use super::adapters::copilot::copilot_base_command;
1055
- use super::adapters::fake::fake_worker_command;
1056
-
1057
- /// Contract C / MUST-8: the per-worker Team Agent MCP server config used by the
1058
- /// remaining legacy workers (Copilot `--additional-mcp-config`). Placeholders
1059
- /// `{workspace}` / `{agent_id}` / `{team_id}` are substituted at spawn time by
1060
- /// [`crate::lifecycle::launch::fill_spawn_placeholders`]; this template MUST NOT
1061
- /// contain hardcoded paths or agent/team ids — the probe5 RED probe burned that.
1062
- ///
1063
- /// step3/rt finding (binary c5d22208): bare `command="team-agent"` lets the worker
1064
- /// process's PATH resolve to a stale Python CLI install (e.g. `~/.local/bin/team-agent`)
1065
- /// that lacks the `mcp-server` subcommand → handshake fails (`MCP startup failed:
1066
- /// connection closed: initialize response`). Pin to the absolute path of the CURRENT
1067
- /// running binary via `std::env::current_exe()` so the spawned MCP server is the same
1068
- /// build that produced this config.
1069
- fn mcp_server_config(auth_mode: AuthMode) -> serde_json::Value {
1070
- serde_json::json!({
1071
- "type": "stdio",
1072
- "command": current_team_agent_command(),
1073
- "args": ["mcp-server", "--workspace", "{workspace}"],
1074
- "env": {
1075
- "TEAM_AGENT_WORKSPACE": "{workspace}",
1076
- "TEAM_AGENT_ID": "{agent_id}",
1077
- "TEAM_AGENT_OWNER_TEAM_ID": "{team_id}",
1078
- "TEAM_AGENT_AUTH_MODE": auth_mode_wire(auth_mode),
1079
- }
1080
- })
1081
- }
1082
-
1083
- /// Absolute path of the running `team-agent` binary, suitable for an MCP `command`
1084
- /// field that must not be PATH-resolved. Uses `std::env::current_exe()`, canonicalizes
1085
- /// to drop `/proc/self/exe`-style indirection where supported. Falls back to a
1086
- /// well-known absolute install path only if both lookups fail (CI sandboxes); the
1087
- /// contract requires `Path::is_absolute(command) == true`, which the fallback honors.
1088
- fn current_team_agent_command() -> String {
1089
- if let Ok(exe) = std::env::current_exe() {
1090
- if let Ok(canon) = std::fs::canonicalize(&exe) {
1091
- return canon.to_string_lossy().to_string();
1092
- }
1093
- return exe.to_string_lossy().to_string();
1094
- }
1095
- "/usr/local/bin/team-agent".to_string()
1096
- }
1097
-
1098
- pub(crate) fn next_session_token() -> String {
1099
- use sha2::Digest;
1100
-
1101
- static COUNTER: std::sync::atomic::AtomicU64 = std::sync::atomic::AtomicU64::new(0);
1102
-
1103
- let nanos = std::time::SystemTime::now()
1104
- .duration_since(std::time::UNIX_EPOCH)
1105
- .map_or(0, |d| d.as_nanos());
1106
- let counter = COUNTER.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
1107
- let mut hasher = sha2::Sha256::new();
1108
- hasher.update(nanos.to_le_bytes());
1109
- hasher.update(std::process::id().to_le_bytes());
1110
- hasher.update(counter.to_le_bytes());
1111
- let digest = hasher.finalize();
1112
- let mut bytes = [0u8; 16];
1113
- bytes.copy_from_slice(&digest[..16]);
1114
- bytes[6] = (bytes[6] & 0x0f) | 0x40;
1115
- bytes[8] = (bytes[8] & 0x3f) | 0x80;
1116
- format!(
1117
- "{:02x}{:02x}{:02x}{:02x}-{:02x}{:02x}-{:02x}{:02x}-{:02x}{:02x}-{:02x}{:02x}{:02x}{:02x}{:02x}{:02x}",
1118
- bytes[0],
1119
- bytes[1],
1120
- bytes[2],
1121
- bytes[3],
1122
- bytes[4],
1123
- bytes[5],
1124
- bytes[6],
1125
- bytes[7],
1126
- bytes[8],
1127
- bytes[9],
1128
- bytes[10],
1129
- bytes[11],
1130
- bytes[12],
1131
- bytes[13],
1132
- bytes[14],
1133
- bytes[15],
1134
- )
1135
- }
1136
-
1137
- #[cfg(test)]
1138
- mod fork_materialization_source_guard {
1139
- #[test]
1140
- fn legacy_fork_neither_materializes_backing_nor_injects_into_the_source_pane() {
1141
- let source = include_str!("../lifecycle/launch/fork_agent.rs");
1142
- assert!(
1143
- source.contains("is_retired_provider") && source.contains("unverified (未验证)"),
1144
- "legacy fork must refuse retired rows and unverified providers"
1145
- );
1146
- for gone in [".materialize_fork_backing(", "materialize_codex_fork", "codex_fork", ".inject(", "send_keys"] {
1147
- assert!(!source.contains(gone), "legacy fork must not use {gone}");
1148
- }
1149
- }
1150
- }