@team-agent/installer 0.5.127 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (421) hide show
  1. package/README.md +15 -4
  2. package/README.zh.md +1 -1
  3. package/package.json +4 -8
  4. package/skills/team-agent/SKILL.md +41 -26
  5. package/skills/team-agent/command-coverage.json +170 -184
  6. package/skills/team-agent/docs/reference/team-agent-operator.md +66 -32
  7. package/skills/team-agent/references/recovery-runbook.md +1 -1
  8. package/skills/team-agent/references/team-agent-operator.md +66 -32
  9. package/templates/team_state.md +1 -1
  10. package/Cargo.lock +0 -1063
  11. package/Cargo.toml +0 -36
  12. package/crates/team-agent/Cargo.toml +0 -69
  13. package/crates/team-agent/src/app_server_test_support.rs +0 -258
  14. package/crates/team-agent/src/cli/adapters.rs +0 -1298
  15. package/crates/team-agent/src/cli/arguments.rs +0 -401
  16. package/crates/team-agent/src/cli/attach_app_server_leader.rs +0 -98
  17. package/crates/team-agent/src/cli/diagnose.rs +0 -1675
  18. package/crates/team-agent/src/cli/emit.rs +0 -2898
  19. package/crates/team-agent/src/cli/grok_slot.rs +0 -384
  20. package/crates/team-agent/src/cli/helpers.rs +0 -91
  21. package/crates/team-agent/src/cli/intent/runtime.rs +0 -1189
  22. package/crates/team-agent/src/cli/intent/runtime_tests.rs +0 -821
  23. package/crates/team-agent/src/cli/intent/tests.rs +0 -691
  24. package/crates/team-agent/src/cli/intent.rs +0 -664
  25. package/crates/team-agent/src/cli/leader.rs +0 -300
  26. package/crates/team-agent/src/cli/leader_prompt.rs +0 -261
  27. package/crates/team-agent/src/cli/leaders.rs +0 -418
  28. package/crates/team-agent/src/cli/mod.rs +0 -6528
  29. package/crates/team-agent/src/cli/models.rs +0 -449
  30. package/crates/team-agent/src/cli/named_address.rs +0 -1651
  31. package/crates/team-agent/src/cli/profile.rs +0 -342
  32. package/crates/team-agent/src/cli/route.rs +0 -212
  33. package/crates/team-agent/src/cli/send/coordinator.rs +0 -164
  34. package/crates/team-agent/src/cli/send/mailbox.rs +0 -145
  35. package/crates/team-agent/src/cli/send/persist.rs +0 -192
  36. package/crates/team-agent/src/cli/send/presentation.rs +0 -370
  37. package/crates/team-agent/src/cli/send/resolve.rs +0 -573
  38. package/crates/team-agent/src/cli/send.rs +0 -201
  39. package/crates/team-agent/src/cli/shutdown_socket.rs +0 -288
  40. package/crates/team-agent/src/cli/spec.rs +0 -159
  41. package/crates/team-agent/src/cli/status.rs +0 -280
  42. package/crates/team-agent/src/cli/status_port/agents.rs +0 -358
  43. package/crates/team-agent/src/cli/status_port/approvals.rs +0 -79
  44. package/crates/team-agent/src/cli/status_port/brief.rs +0 -2043
  45. package/crates/team-agent/src/cli/status_port/compact.rs +0 -240
  46. package/crates/team-agent/src/cli/status_port/format.rs +0 -146
  47. package/crates/team-agent/src/cli/status_port/inbox.rs +0 -62
  48. package/crates/team-agent/src/cli/status_port/runtime.rs +0 -197
  49. package/crates/team-agent/src/cli/status_port/snapshot.rs +0 -208
  50. package/crates/team-agent/src/cli/status_port/store.rs +0 -416
  51. package/crates/team-agent/src/cli/status_port/tests.rs +0 -90
  52. package/crates/team-agent/src/cli/status_port.rs +0 -92
  53. package/crates/team-agent/src/cli/tests/base.rs +0 -885
  54. package/crates/team-agent/src/cli/tests/divergence.rs +0 -518
  55. package/crates/team-agent/src/cli/tests/lane_c.rs +0 -453
  56. package/crates/team-agent/src/cli/tests/leader_watch.rs +0 -372
  57. package/crates/team-agent/src/cli/tests/main_preserved.rs +0 -430
  58. package/crates/team-agent/src/cli/tests/missing_subcommands.rs +0 -336
  59. package/crates/team-agent/src/cli/tests/mod.rs +0 -137
  60. package/crates/team-agent/src/cli/tests/named_address.rs +0 -760
  61. package/crates/team-agent/src/cli/tests/parser_safety.rs +0 -383
  62. package/crates/team-agent/src/cli/tests/run_delegation.rs +0 -481
  63. package/crates/team-agent/src/cli/tests/shutdown_kill_plan.rs +0 -2179
  64. package/crates/team-agent/src/cli/tests/status_brief.rs +0 -1514
  65. package/crates/team-agent/src/cli/tests/status_send.rs +0 -1091
  66. package/crates/team-agent/src/cli/tests/verb_install_skill.rs +0 -93
  67. package/crates/team-agent/src/cli/tests/verb_profile.rs +0 -392
  68. package/crates/team-agent/src/cli/triage.rs +0 -234
  69. package/crates/team-agent/src/cli/types.rs +0 -591
  70. package/crates/team-agent/src/codex_app_server.rs +0 -546
  71. package/crates/team-agent/src/communication_mode/mod.rs +0 -56
  72. package/crates/team-agent/src/compiler/tests.rs +0 -842
  73. package/crates/team-agent/src/compiler.rs +0 -691
  74. package/crates/team-agent/src/conpty/backend.rs +0 -829
  75. package/crates/team-agent/src/conpty/mod.rs +0 -33
  76. package/crates/team-agent/src/contract_runtime/backend.rs +0 -1610
  77. package/crates/team-agent/src/contract_runtime/commands.rs +0 -671
  78. package/crates/team-agent/src/contract_runtime/config.rs +0 -354
  79. package/crates/team-agent/src/contract_runtime/config_tests.rs +0 -56
  80. package/crates/team-agent/src/contract_runtime/discovery.rs +0 -438
  81. package/crates/team-agent/src/contract_runtime/fork.rs +0 -368
  82. package/crates/team-agent/src/contract_runtime/forward.rs +0 -288
  83. package/crates/team-agent/src/contract_runtime/framework.rs +0 -350
  84. package/crates/team-agent/src/contract_runtime/mcp.rs +0 -399
  85. package/crates/team-agent/src/contract_runtime/mod.rs +0 -17
  86. package/crates/team-agent/src/contract_runtime/prompt.rs +0 -216
  87. package/crates/team-agent/src/contract_runtime/pump.rs +0 -271
  88. package/crates/team-agent/src/contract_runtime/registry.rs +0 -589
  89. package/crates/team-agent/src/contract_runtime/workspace.rs +0 -228
  90. package/crates/team-agent/src/coordinator/backoff.rs +0 -741
  91. package/crates/team-agent/src/coordinator/conpty_shim.rs +0 -805
  92. package/crates/team-agent/src/coordinator/health.rs +0 -1185
  93. package/crates/team-agent/src/coordinator/mod.rs +0 -119
  94. package/crates/team-agent/src/coordinator/orphan.rs +0 -110
  95. package/crates/team-agent/src/coordinator/runtime_detectors.rs +0 -798
  96. package/crates/team-agent/src/coordinator/runtime_observation.rs +0 -84
  97. package/crates/team-agent/src/coordinator/steps/abnormal.rs +0 -2309
  98. package/crates/team-agent/src/coordinator/steps/delivery.rs +0 -15
  99. package/crates/team-agent/src/coordinator/steps/health_sync.rs +0 -15
  100. package/crates/team-agent/src/coordinator/steps/mod.rs +0 -126
  101. package/crates/team-agent/src/coordinator/steps/persist.rs +0 -15
  102. package/crates/team-agent/src/coordinator/steps/runtime_prompts.rs +0 -15
  103. package/crates/team-agent/src/coordinator/steps/session_gate.rs +0 -16
  104. package/crates/team-agent/src/coordinator/tests/a0_lostupdate.rs +0 -158
  105. package/crates/team-agent/src/coordinator/tests/abnormal.rs +0 -312
  106. package/crates/team-agent/src/coordinator/tests/api_error_recovery.rs +0 -338
  107. package/crates/team-agent/src/coordinator/tests/basics.rs +0 -211
  108. package/crates/team-agent/src/coordinator/tests/daemon.rs +0 -514
  109. package/crates/team-agent/src/coordinator/tests/energy.rs +0 -549
  110. package/crates/team-agent/src/coordinator/tests/health_sync.rs +0 -461
  111. package/crates/team-agent/src/coordinator/tests/main_preserved.rs +0 -186
  112. package/crates/team-agent/src/coordinator/tests/mod.rs +0 -295
  113. package/crates/team-agent/src/coordinator/tests/s3_bounded.rs +0 -207
  114. package/crates/team-agent/src/coordinator/tests/spine.rs +0 -308
  115. package/crates/team-agent/src/coordinator/tests/takeover.rs +0 -286
  116. package/crates/team-agent/src/coordinator/tests/tick_core.rs +0 -237
  117. package/crates/team-agent/src/coordinator/tick.rs +0 -3112
  118. package/crates/team-agent/src/coordinator/types.rs +0 -540
  119. package/crates/team-agent/src/db/agent_health_capture.rs +0 -126
  120. package/crates/team-agent/src/db/message_store.rs +0 -1585
  121. package/crates/team-agent/src/db/migration.rs +0 -984
  122. package/crates/team-agent/src/db/mod.rs +0 -26
  123. package/crates/team-agent/src/db/schema.rs +0 -663
  124. package/crates/team-agent/src/diagnose/comms.rs +0 -242
  125. package/crates/team-agent/src/diagnose/mod.rs +0 -44
  126. package/crates/team-agent/src/diagnose/orphans.rs +0 -889
  127. package/crates/team-agent/src/event_log.rs +0 -502
  128. package/crates/team-agent/src/fake_worker.rs +0 -303
  129. package/crates/team-agent/src/kill_audit.rs +0 -106
  130. package/crates/team-agent/src/layout/manager.rs +0 -248
  131. package/crates/team-agent/src/layout/mod.rs +0 -36
  132. package/crates/team-agent/src/layout/overlay.rs +0 -134
  133. package/crates/team-agent/src/layout/placement.rs +0 -52
  134. package/crates/team-agent/src/layout/recovery.rs +0 -106
  135. package/crates/team-agent/src/layout/runtime_sessions.rs +0 -317
  136. package/crates/team-agent/src/layout/sessions.rs +0 -294
  137. package/crates/team-agent/src/layout/tmux_endpoint.rs +0 -165
  138. package/crates/team-agent/src/layout/worker_env.rs +0 -721
  139. package/crates/team-agent/src/layout/worker_window_helpers.rs +0 -37
  140. package/crates/team-agent/src/leader/helpers.rs +0 -178
  141. package/crates/team-agent/src/leader/incident.rs +0 -6
  142. package/crates/team-agent/src/leader/lease.rs +0 -3356
  143. package/crates/team-agent/src/leader/mod.rs +0 -104
  144. package/crates/team-agent/src/leader/owner_bind.rs +0 -400
  145. package/crates/team-agent/src/leader/prompt.rs +0 -905
  146. package/crates/team-agent/src/leader/provider_attribution.rs +0 -247
  147. package/crates/team-agent/src/leader/rediscover/tests.rs +0 -689
  148. package/crates/team-agent/src/leader/rediscover.rs +0 -1192
  149. package/crates/team-agent/src/leader/registry.rs +0 -883
  150. package/crates/team-agent/src/leader/start.rs +0 -4500
  151. package/crates/team-agent/src/leader/takeover.rs +0 -65
  152. package/crates/team-agent/src/leader/tests/basics.rs +0 -337
  153. package/crates/team-agent/src/leader/tests/byte_findings.rs +0 -355
  154. package/crates/team-agent/src/leader/tests/claim_leader_mailbox_flush_contract.rs +0 -544
  155. package/crates/team-agent/src/leader/tests/historical_inventory_upgrade_gate_red.rs +0 -624
  156. package/crates/team-agent/src/leader/tests/identity.rs +0 -465
  157. package/crates/team-agent/src/leader/tests/identity_session_names.rs +0 -42
  158. package/crates/team-agent/src/leader/tests/idle.rs +0 -113
  159. package/crates/team-agent/src/leader/tests/lease_api.rs +0 -520
  160. package/crates/team-agent/src/leader/tests/lease_claim.rs +0 -629
  161. package/crates/team-agent/src/leader/tests/mod.rs +0 -106
  162. package/crates/team-agent/src/leader/tests/prompt_contract.rs +0 -267
  163. package/crates/team-agent/src/leader/tests/rediscover.rs +0 -403
  164. package/crates/team-agent/src/leader/tests/rehomed_env.rs +0 -83
  165. package/crates/team-agent/src/leader/tests/team_in_team_state_scope_red.rs +0 -1273
  166. package/crates/team-agent/src/leader/tests/terminal_and_replay_vs_rerender_invariants_red.rs +0 -417
  167. package/crates/team-agent/src/leader/tests/wake_start_owner.rs +0 -168
  168. package/crates/team-agent/src/leader/types.rs +0 -534
  169. package/crates/team-agent/src/lib.rs +0 -145
  170. package/crates/team-agent/src/lifecycle/helpers.rs +0 -212
  171. package/crates/team-agent/src/lifecycle/launch/add_agent.rs +0 -848
  172. package/crates/team-agent/src/lifecycle/launch/add_agent_state.rs +0 -393
  173. package/crates/team-agent/src/lifecycle/launch/agent_state.rs +0 -332
  174. package/crates/team-agent/src/lifecycle/launch/clone_agent.rs +0 -178
  175. package/crates/team-agent/src/lifecycle/launch/fork_agent.rs +0 -82
  176. package/crates/team-agent/src/lifecycle/launch/fork_entry.rs +0 -63
  177. package/crates/team-agent/src/lifecycle/launch/identity.rs +0 -674
  178. package/crates/team-agent/src/lifecycle/launch/layout.rs +0 -350
  179. package/crates/team-agent/src/lifecycle/launch/leader_context.rs +0 -589
  180. package/crates/team-agent/src/lifecycle/launch/mcp_config.rs +0 -152
  181. package/crates/team-agent/src/lifecycle/launch/ownership.rs +0 -105
  182. package/crates/team-agent/src/lifecycle/launch/pi_mcp.rs +0 -629
  183. package/crates/team-agent/src/lifecycle/launch/pi_mcp_extension.js +0 -226
  184. package/crates/team-agent/src/lifecycle/launch/plan.rs +0 -269
  185. package/crates/team-agent/src/lifecycle/launch/quick_start.rs +0 -5176
  186. package/crates/team-agent/src/lifecycle/launch/quick_start_transport.rs +0 -368
  187. package/crates/team-agent/src/lifecycle/launch/readiness.rs +0 -519
  188. package/crates/team-agent/src/lifecycle/launch/role_source.rs +0 -287
  189. package/crates/team-agent/src/lifecycle/launch/spawn.rs +0 -450
  190. package/crates/team-agent/src/lifecycle/launch/spec_state.rs +0 -801
  191. package/crates/team-agent/src/lifecycle/launch/state_projection.rs +0 -624
  192. package/crates/team-agent/src/lifecycle/launch/worker_env.rs +0 -558
  193. package/crates/team-agent/src/lifecycle/launch.rs +0 -534
  194. package/crates/team-agent/src/lifecycle/lock.rs +0 -350
  195. package/crates/team-agent/src/lifecycle/mod.rs +0 -79
  196. package/crates/team-agent/src/lifecycle/pane_input_lock.rs +0 -239
  197. package/crates/team-agent/src/lifecycle/profile_launch.rs +0 -757
  198. package/crates/team-agent/src/lifecycle/profile_smoke.rs +0 -557
  199. package/crates/team-agent/src/lifecycle/restart/agent.rs +0 -2198
  200. package/crates/team-agent/src/lifecycle/restart/common.rs +0 -2052
  201. package/crates/team-agent/src/lifecycle/restart/orchestrator.rs +0 -65
  202. package/crates/team-agent/src/lifecycle/restart/preflight.rs +0 -113
  203. package/crates/team-agent/src/lifecycle/restart/rebuild.rs +0 -5135
  204. package/crates/team-agent/src/lifecycle/restart/remove.rs +0 -1504
  205. package/crates/team-agent/src/lifecycle/restart/selection.rs +0 -559
  206. package/crates/team-agent/src/lifecycle/restart/team_state.rs +0 -329
  207. package/crates/team-agent/src/lifecycle/restart.rs +0 -223
  208. package/crates/team-agent/src/lifecycle/role_config.rs +0 -1205
  209. package/crates/team-agent/src/lifecycle/tests/acceptance_b_batch_red.rs +0 -1021
  210. package/crates/team-agent/src/lifecycle/tests/agent_ops.rs +0 -1205
  211. package/crates/team-agent/src/lifecycle/tests/b0_legacy_snapshot_nonauthority_contract.rs +0 -265
  212. package/crates/team-agent/src/lifecycle/tests/b0_reader_hideone_audit_contract.rs +0 -490
  213. package/crates/team-agent/src/lifecycle/tests/behavioral_diff_264_red.rs +0 -656
  214. package/crates/team-agent/src/lifecycle/tests/claude_profile_launch_red.rs +0 -135
  215. package/crates/team-agent/src/lifecycle/tests/cli_argv_routing_red.rs +0 -1415
  216. package/crates/team-agent/src/lifecycle/tests/clone_agent_preserves_source_tools.rs +0 -427
  217. package/crates/team-agent/src/lifecycle/tests/clone_fork_copilot_perms_red.rs +0 -396
  218. package/crates/team-agent/src/lifecycle/tests/communication_mode_runtime_contract_red.rs +0 -418
  219. package/crates/team-agent/src/lifecycle/tests/copilot_provider_red.rs +0 -2039
  220. package/crates/team-agent/src/lifecycle/tests/core.rs +0 -1298
  221. package/crates/team-agent/src/lifecycle/tests/f032_startup_prompt_best_effort_red.rs +0 -315
  222. package/crates/team-agent/src/lifecycle/tests/fixtures/pi_list_models_g0.stdout.txt +0 -222
  223. package/crates/team-agent/src/lifecycle/tests/fixtures/pi_list_models_spaced_ids.stdout.txt +0 -9
  224. package/crates/team-agent/src/lifecycle/tests/fixtures/pi_native_mcp_host.mjs +0 -71
  225. package/crates/team-agent/src/lifecycle/tests/gate_fixtures.rs +0 -562
  226. package/crates/team-agent/src/lifecycle/tests/grok_require_explicit_model_red.rs +0 -110
  227. package/crates/team-agent/src/lifecycle/tests/harvest2_a_batch_red.rs +0 -472
  228. package/crates/team-agent/src/lifecycle/tests/host_cotenant_death_p0_contract.rs +0 -921
  229. package/crates/team-agent/src/lifecycle/tests/issue238_codex_effort_contract.rs +0 -68
  230. package/crates/team-agent/src/lifecycle/tests/lane_ops.rs +0 -1851
  231. package/crates/team-agent/src/lifecycle/tests/launch_spawn.rs +0 -3981
  232. package/crates/team-agent/src/lifecycle/tests/lifecycle_lock.rs +0 -339
  233. package/crates/team-agent/src/lifecycle/tests/lifecycle_rollback_red.rs +0 -596
  234. package/crates/team-agent/src/lifecycle/tests/main_preserved.rs +0 -513
  235. package/crates/team-agent/src/lifecycle/tests/mcp_tool_name_format_red.rs +0 -69
  236. package/crates/team-agent/src/lifecycle/tests/phase_b_contracts.rs +0 -824
  237. package/crates/team-agent/src/lifecycle/tests/phase_golden.rs +0 -723
  238. package/crates/team-agent/src/lifecycle/tests/pi_catalog_red.rs +0 -152
  239. package/crates/team-agent/src/lifecycle/tests/pi_command_red.rs +0 -182
  240. package/crates/team-agent/src/lifecycle/tests/pi_dual_entry_red.rs +0 -374
  241. package/crates/team-agent/src/lifecycle/tests/pi_executable_mcp_red.rs +0 -546
  242. package/crates/team-agent/src/lifecycle/tests/pi_lifecycle_doctor_red.rs +0 -31
  243. package/crates/team-agent/src/lifecycle/tests/pi_native_mcp_capability_red.rs +0 -528
  244. package/crates/team-agent/src/lifecycle/tests/pi_session_delivery_red.rs +0 -134
  245. package/crates/team-agent/src/lifecycle/tests/quick_start_worker_readiness_red.rs +0 -333
  246. package/crates/team-agent/src/lifecycle/tests/realmachine_clusters_1_6_red.rs +0 -786
  247. package/crates/team-agent/src/lifecycle/tests/realmachine_residual_g1_g4_red.rs +0 -648
  248. package/crates/team-agent/src/lifecycle/tests/restart.rs +0 -185
  249. package/crates/team-agent/src/lifecycle/tests/restart_build_before_destroy_0540_contract.rs +0 -1053
  250. package/crates/team-agent/src/lifecycle/tests/restart_liveness_red.rs +0 -679
  251. package/crates/team-agent/src/lifecycle/tests/restart_rebind_hotfix_252_red.rs +0 -1126
  252. package/crates/team-agent/src/lifecycle/tests/restart_session_capture_red.rs +0 -153
  253. package/crates/team-agent/src/lifecycle/tests/resume_recover_red.rs +0 -427
  254. package/crates/team-agent/src/lifecycle/tests/stale_team_saveconflict_contract.rs +0 -431
  255. package/crates/team-agent/src/lifecycle/tests/startup_latency_contract.rs +0 -1066
  256. package/crates/team-agent/src/lifecycle/tests/status_credential_redaction_contract.rs +0 -876
  257. package/crates/team-agent/src/lifecycle/tests/subprep_codex_trust_roundtrip_red.rs +0 -1026
  258. package/crates/team-agent/src/lifecycle/tests/swallow_batch4_semantics_red.rs +0 -90
  259. package/crates/team-agent/src/lifecycle/tests/team_in_team_identity_scope_red.rs +0 -543
  260. package/crates/team-agent/src/lifecycle/tests/team_in_team_sibling_quick_start_red.rs +0 -1103
  261. package/crates/team-agent/src/lifecycle/tests/team_in_team_state_scope_red.rs +0 -1276
  262. package/crates/team-agent/src/lifecycle/tests/team_key_retirement_roster_red.rs +0 -145
  263. package/crates/team-agent/src/lifecycle/tests/team_key_retirement_txn_red.rs +0 -603
  264. package/crates/team-agent/src/lifecycle/tests/test_isolation_escape_contract.rs +0 -936
  265. package/crates/team-agent/src/lifecycle/tests/upgrade_compat_0211_red.rs +0 -970
  266. package/crates/team-agent/src/lifecycle/tests/verify_rs031_window_consistency_red.rs +0 -996
  267. package/crates/team-agent/src/lifecycle/tests/worker_spawn_env_red.rs +0 -827
  268. package/crates/team-agent/src/lifecycle/tests.rs +0 -102
  269. package/crates/team-agent/src/lifecycle/types.rs +0 -861
  270. package/crates/team-agent/src/lifecycle/worker_command_context.rs +0 -370
  271. package/crates/team-agent/src/main.rs +0 -52
  272. package/crates/team-agent/src/mcp_server/helpers.rs +0 -510
  273. package/crates/team-agent/src/mcp_server/lifecycle_tools/mod.rs +0 -6
  274. package/crates/team-agent/src/mcp_server/lifecycle_tools/state_status.rs +0 -43
  275. package/crates/team-agent/src/mcp_server/mod.rs +0 -119
  276. package/crates/team-agent/src/mcp_server/normalize.rs +0 -485
  277. package/crates/team-agent/src/mcp_server/readiness.rs +0 -546
  278. package/crates/team-agent/src/mcp_server/readiness_tests.rs +0 -369
  279. package/crates/team-agent/src/mcp_server/tests/golden.rs +0 -285
  280. package/crates/team-agent/src/mcp_server/tests/normalize.rs +0 -247
  281. package/crates/team-agent/src/mcp_server/tests/scoped.rs +0 -168
  282. package/crates/team-agent/src/mcp_server/tests/send.rs +0 -388
  283. package/crates/team-agent/src/mcp_server/tests/tools.rs +0 -343
  284. package/crates/team-agent/src/mcp_server/tests/wire.rs +0 -254
  285. package/crates/team-agent/src/mcp_server/tests.rs +0 -43
  286. package/crates/team-agent/src/mcp_server/tools.rs +0 -1015
  287. package/crates/team-agent/src/mcp_server/types.rs +0 -396
  288. package/crates/team-agent/src/mcp_server/wire.rs +0 -867
  289. package/crates/team-agent/src/messaging/activity.rs +0 -461
  290. package/crates/team-agent/src/messaging/address.rs +0 -87
  291. package/crates/team-agent/src/messaging/delivery.rs +0 -3785
  292. package/crates/team-agent/src/messaging/delivery_consumption_tests.rs +0 -234
  293. package/crates/team-agent/src/messaging/enter_rescue.rs +0 -362
  294. package/crates/team-agent/src/messaging/enter_rescue_tests.rs +0 -633
  295. package/crates/team-agent/src/messaging/helpers.rs +0 -354
  296. package/crates/team-agent/src/messaging/leader_channel.rs +0 -287
  297. package/crates/team-agent/src/messaging/leader_receiver.rs +0 -786
  298. package/crates/team-agent/src/messaging/mod.rs +0 -166
  299. package/crates/team-agent/src/messaging/persist.rs +0 -377
  300. package/crates/team-agent/src/messaging/presentation.rs +0 -417
  301. package/crates/team-agent/src/messaging/results/collection_tests.rs +0 -719
  302. package/crates/team-agent/src/messaging/results.rs +0 -1415
  303. package/crates/team-agent/src/messaging/scheduler.rs +0 -217
  304. package/crates/team-agent/src/messaging/selftest.rs +0 -315
  305. package/crates/team-agent/src/messaging/send.rs +0 -981
  306. package/crates/team-agent/src/messaging/tests/basic.rs +0 -346
  307. package/crates/team-agent/src/messaging/tests/dup_inject.rs +0 -551
  308. package/crates/team-agent/src/messaging/tests/e23.rs +0 -49
  309. package/crates/team-agent/src/messaging/tests/leader_channel.rs +0 -169
  310. package/crates/team-agent/src/messaging/tests/leader_inject_acceptance.rs +0 -817
  311. package/crates/team-agent/src/messaging/tests/main_preserved.rs +0 -85
  312. package/crates/team-agent/src/messaging/tests/mod.rs +0 -306
  313. package/crates/team-agent/src/messaging/tests/runtime.rs +0 -3655
  314. package/crates/team-agent/src/messaging/tests/spine.rs +0 -837
  315. package/crates/team-agent/src/messaging/tests/wave2.rs +0 -381
  316. package/crates/team-agent/src/messaging/trust.rs +0 -215
  317. package/crates/team-agent/src/messaging/types.rs +0 -471
  318. package/crates/team-agent/src/messaging/wait.rs +0 -366
  319. package/crates/team-agent/src/messaging/watchers.rs +0 -916
  320. package/crates/team-agent/src/model/enums.rs +0 -356
  321. package/crates/team-agent/src/model/errors.rs +0 -18
  322. package/crates/team-agent/src/model/ids.rs +0 -165
  323. package/crates/team-agent/src/model/mod.rs +0 -29
  324. package/crates/team-agent/src/model/name_similarity.rs +0 -252
  325. package/crates/team-agent/src/model/pane_authority_refusal.rs +0 -359
  326. package/crates/team-agent/src/model/paths.rs +0 -257
  327. package/crates/team-agent/src/model/routing.rs +0 -387
  328. package/crates/team-agent/src/model/spec.rs +0 -1184
  329. package/crates/team-agent/src/model/task_graph.rs +0 -321
  330. package/crates/team-agent/src/model/testdata/fuzz.golden.yaml +0 -43
  331. package/crates/team-agent/src/model/testdata/fuzz.yaml +0 -43
  332. package/crates/team-agent/src/model/testdata/spec_invalid_a.yaml +0 -209
  333. package/crates/team-agent/src/model/testdata/team.spec.golden.yaml +0 -208
  334. package/crates/team-agent/src/model/testdata/team.spec.yaml +0 -208
  335. package/crates/team-agent/src/model/yaml/tests.rs +0 -188
  336. package/crates/team-agent/src/model/yaml.rs +0 -802
  337. package/crates/team-agent/src/os_probe.rs +0 -280
  338. package/crates/team-agent/src/packaging/install.rs +0 -219
  339. package/crates/team-agent/src/packaging/migrate.rs +0 -38
  340. package/crates/team-agent/src/packaging/mod.rs +0 -91
  341. package/crates/team-agent/src/packaging/repair.rs +0 -33
  342. package/crates/team-agent/src/packaging/tests.rs +0 -822
  343. package/crates/team-agent/src/packaging/types.rs +0 -417
  344. package/crates/team-agent/src/platform/argv.rs +0 -331
  345. package/crates/team-agent/src/platform/errors.rs +0 -104
  346. package/crates/team-agent/src/platform/file_lock.rs +0 -279
  347. package/crates/team-agent/src/platform/mod.rs +0 -5
  348. package/crates/team-agent/src/platform/process.rs +0 -545
  349. package/crates/team-agent/src/provider/adapter.rs +0 -898
  350. package/crates/team-agent/src/provider/adapters/copilot.rs +0 -75
  351. package/crates/team-agent/src/provider/adapters/copilot_fork.rs +0 -307
  352. package/crates/team-agent/src/provider/adapters/fake.rs +0 -18
  353. package/crates/team-agent/src/provider/adapters/mod.rs +0 -28
  354. package/crates/team-agent/src/provider/approvals/mod.rs +0 -3
  355. package/crates/team-agent/src/provider/approvals/parsing.rs +0 -586
  356. package/crates/team-agent/src/provider/approvals/runtime_prompts.rs +0 -205
  357. package/crates/team-agent/src/provider/argv_route.rs +0 -405
  358. package/crates/team-agent/src/provider/bypass_flags.rs +0 -116
  359. package/crates/team-agent/src/provider/classify.rs +0 -773
  360. package/crates/team-agent/src/provider/command_helpers.rs +0 -45
  361. package/crates/team-agent/src/provider/faults.rs +0 -165
  362. package/crates/team-agent/src/provider/helpers.rs +0 -52
  363. package/crates/team-agent/src/provider/mod.rs +0 -78
  364. package/crates/team-agent/src/provider/model_catalog.rs +0 -722
  365. package/crates/team-agent/src/provider/session/capture.rs +0 -2631
  366. package/crates/team-agent/src/provider/session/context_fork/outcome.rs +0 -168
  367. package/crates/team-agent/src/provider/session/context_fork.rs +0 -264
  368. package/crates/team-agent/src/provider/session/mod.rs +0 -36
  369. package/crates/team-agent/src/provider/session/resume.rs +0 -269
  370. package/crates/team-agent/src/provider/session_scan/common/tests.rs +0 -316
  371. package/crates/team-agent/src/provider/session_scan/common.rs +0 -618
  372. package/crates/team-agent/src/provider/session_scan/copilot.rs +0 -280
  373. package/crates/team-agent/src/provider/session_scan/pi.rs +0 -152
  374. package/crates/team-agent/src/provider/session_scan.rs +0 -61
  375. package/crates/team-agent/src/provider/startup_prompt.rs +0 -757
  376. package/crates/team-agent/src/provider/submit_now.rs +0 -71
  377. package/crates/team-agent/src/provider/testdata/copilot-ready-marker.txt +0 -5
  378. package/crates/team-agent/src/provider/testdata/copilot-trust-prompt.txt +0 -19
  379. package/crates/team-agent/src/provider/testdata/grok-models-authenticated.stdout +0 -9
  380. package/crates/team-agent/src/provider/testdata/grok-models-unauthenticated.stdout +0 -7
  381. package/crates/team-agent/src/provider/tests/adapter.rs +0 -354
  382. package/crates/team-agent/src/provider/tests/classify.rs +0 -201
  383. package/crates/team-agent/src/provider/tests/command_helpers.rs +0 -26
  384. package/crates/team-agent/src/provider/tests/copilot_fork.rs +0 -191
  385. package/crates/team-agent/src/provider/tests/faults.rs +0 -200
  386. package/crates/team-agent/src/provider/tests/idle.rs +0 -140
  387. package/crates/team-agent/src/provider/tests/wire.rs +0 -213
  388. package/crates/team-agent/src/provider/tests.rs +0 -32
  389. package/crates/team-agent/src/provider/types.rs +0 -529
  390. package/crates/team-agent/src/provider/wire.rs +0 -406
  391. package/crates/team-agent/src/redaction.rs +0 -259
  392. package/crates/team-agent/src/state/abnormal_watch/tests/mod.rs +0 -248
  393. package/crates/team-agent/src/state/abnormal_watch.rs +0 -144
  394. package/crates/team-agent/src/state/identity.rs +0 -914
  395. package/crates/team-agent/src/state/identity_keys.rs +0 -132
  396. package/crates/team-agent/src/state/mod.rs +0 -74
  397. package/crates/team-agent/src/state/owner_gate.rs +0 -482
  398. package/crates/team-agent/src/state/ownership.rs +0 -563
  399. package/crates/team-agent/src/state/paths.rs +0 -395
  400. package/crates/team-agent/src/state/persist.rs +0 -3811
  401. package/crates/team-agent/src/state/projection.rs +0 -1508
  402. package/crates/team-agent/src/state/repository/intent.rs +0 -14
  403. package/crates/team-agent/src/state/repository/tests.rs +0 -184
  404. package/crates/team-agent/src/state/repository.rs +0 -866
  405. package/crates/team-agent/src/state/selector.rs +0 -160
  406. package/crates/team-agent/src/state/testdata/state-rich.canonical.json +0 -133
  407. package/crates/team-agent/src/tmux_backend/enter_rescue.rs +0 -325
  408. package/crates/team-agent/src/tmux_backend/enter_rescue_tests.rs +0 -432
  409. package/crates/team-agent/src/tmux_backend/native_input.rs +0 -513
  410. package/crates/team-agent/src/tmux_backend/native_input_tests.rs +0 -742
  411. package/crates/team-agent/src/tmux_backend/tests.rs +0 -4254
  412. package/crates/team-agent/src/tmux_backend.rs +0 -4527
  413. package/crates/team-agent/src/topology.rs +0 -537
  414. package/crates/team-agent/src/transport/enter_rescue.rs +0 -166
  415. package/crates/team-agent/src/transport/native_input.rs +0 -491
  416. package/crates/team-agent/src/transport/test_support.rs +0 -743
  417. package/crates/team-agent/src/transport/tests/behavior.rs +0 -326
  418. package/crates/team-agent/src/transport/tests/mod.rs +0 -194
  419. package/crates/team-agent/src/transport/tests/wire.rs +0 -574
  420. package/crates/team-agent/src/transport.rs +0 -1655
  421. package/crates/team-agent/src/transport_factory.rs +0 -819
@@ -1,757 +0,0 @@
1
- //! ---
2
- //! purpose: 由 agent 的 profile 声明推出 provider 启动所需的环境覆盖、环境清除与命令覆写
3
- //! contract:
4
- //! provides:
5
- //! - name: prepare_provider_profile_launch
6
- //! what: 从 YAML agent 节点算出 ProviderProfileLaunch
7
- //! - name: prepare_provider_profile_launch_from_json
8
- //! what: 从 runtime state 的 JSON agent 节点算出同一结果
9
- //! - name: load_profile
10
- //! what: 按查找顺序找到 profile env 文件并解析成键值
11
- //! - name: provider_env_unsets
12
- //! what: 该 provider 与 auth_mode 下必须清除的环境变量集,worker 与 leader 共用这一份
13
- //! - name: profile_proxy_mode
14
- //! what: 读出 profile 的代理模式,缺省 inherit
15
- //! - name: parse_auth_mode
16
- //! what: 把 auth_mode 字符串解析成枚举,未知值返回 None
17
- //! depends:
18
- //! - crate::provider
19
- //! - crate::model::enums
20
- //! - std::fs
21
- //! boundary:
22
- //! - 只读 profile 文件,不改写也不创建 profile
23
- //! - 不把密钥值写进事件或错误消息
24
- //! - provider 的环境清除集只此一份,leader 侧不得另建
25
- //! maturity: wired
26
- //! ---
27
- use std::collections::{BTreeMap, BTreeSet};
28
- use std::path::{Path, PathBuf};
29
-
30
- use crate::lifecycle::LifecycleError;
31
- use crate::model::enums::{AuthMode, Provider};
32
- use crate::model::yaml::Value as YamlValue;
33
- use crate::provider::{McpConfig, ProviderCommandOverrides, ProviderProfileLaunch};
34
- use crate::provider::command_helpers::append_env_pair;
35
-
36
- const COMPATIBLE_NETWORK_ENV_KEYS: &[&str] = &[
37
- "HTTPS_PROXY",
38
- "HTTP_PROXY",
39
- "ALL_PROXY",
40
- "https_proxy",
41
- "http_proxy",
42
- "all_proxy",
43
- "NO_PROXY",
44
- "no_proxy",
45
- "NODE_EXTRA_CA_CERTS",
46
- "SSL_CERT_FILE",
47
- "REQUESTS_CA_BUNDLE",
48
- ];
49
-
50
- #[derive(Debug, Clone)]
51
- pub(crate) struct ProfileValues {
52
- pub(crate) path: PathBuf,
53
- pub(crate) values: BTreeMap<String, String>,
54
- }
55
-
56
- #[derive(Debug, Clone)]
57
- struct AgentProfileInput {
58
- id: String,
59
- provider: Provider,
60
- auth_mode: AuthMode,
61
- profile: Option<String>,
62
- profile_dir: Option<PathBuf>,
63
- model: Option<String>,
64
- model_source: Option<String>,
65
- }
66
-
67
- /// ---
68
- /// purpose: 从 YAML agent 节点准备 provider 启动参数,profile 目录用默认查找顺序
69
- /// params:
70
- /// agent_id: agent 节点没写 id 时的兜底 id
71
- /// mcp_config: 需要托管 MCP 配置时传入,否则 None
72
- /// returns: 环境覆盖、环境清除、命令覆写与 claude 配置目录
73
- /// errors: profile 找不到、必填键缺失或写 runtime env 文件失败时返回 LifecycleError
74
- /// contract_id: lifecycle.profile_launch.prepare
75
- /// ---
76
- pub(crate) fn prepare_provider_profile_launch(
77
- workspace: &Path,
78
- agent_id: &str,
79
- agent: &YamlValue,
80
- mcp_config: Option<&McpConfig>,
81
- ) -> Result<ProviderProfileLaunch, LifecycleError> {
82
- prepare_provider_profile_launch_with_profile_dir(workspace, agent_id, agent, None, mcp_config)
83
- }
84
-
85
- /// ---
86
- /// purpose: 同上,但允许指定优先查找的 profile 目录
87
- /// params:
88
- /// profile_dir: 优先查找目录;agent 节点里的 _profile_dir 优先于它
89
- /// returns: 环境覆盖、环境清除、命令覆写与 claude 配置目录
90
- /// errors: 同 prepare_provider_profile_launch
91
- /// contract_id: lifecycle.profile_launch.prepare
92
- /// ---
93
- pub(crate) fn prepare_provider_profile_launch_with_profile_dir(
94
- workspace: &Path,
95
- agent_id: &str,
96
- agent: &YamlValue,
97
- profile_dir: Option<&Path>,
98
- mcp_config: Option<&McpConfig>,
99
- ) -> Result<ProviderProfileLaunch, LifecycleError> {
100
- if let Some(retired) = agent.get("provider").and_then(YamlValue::as_str).filter(|provider| crate::provider::wire::is_retired_provider(provider)) {
101
- return Err(LifecycleError::Provider(crate::provider::wire::retired_provider_error(retired).into()));
102
- }
103
- let input = AgentProfileInput {
104
- id: agent
105
- .get("id")
106
- .and_then(YamlValue::as_str)
107
- .unwrap_or(agent_id)
108
- .to_string(),
109
- provider: agent
110
- .get("provider")
111
- .and_then(YamlValue::as_str)
112
- .and_then(parse_provider)
113
- .unwrap_or(Provider::Codex),
114
- auth_mode: agent
115
- .get("auth_mode")
116
- .and_then(YamlValue::as_str)
117
- .and_then(parse_auth_mode)
118
- .unwrap_or(AuthMode::Subscription),
119
- profile: agent
120
- .get("profile")
121
- .and_then(YamlValue::as_str)
122
- .filter(|value| !value.is_empty())
123
- .map(str::to_string),
124
- profile_dir: agent
125
- .get("_profile_dir")
126
- .and_then(YamlValue::as_str)
127
- .filter(|value| !value.is_empty())
128
- .map(PathBuf::from)
129
- .or_else(|| profile_dir.map(Path::to_path_buf)),
130
- model: agent
131
- .get("model")
132
- .and_then(YamlValue::as_str)
133
- .filter(|value| !value.is_empty())
134
- .map(str::to_string),
135
- model_source: agent
136
- .get("model_source")
137
- .and_then(YamlValue::as_str)
138
- .filter(|value| !value.is_empty())
139
- .map(str::to_string),
140
- };
141
- prepare_profile_launch(workspace, input, mcp_config)
142
- }
143
-
144
- /// ---
145
- /// purpose: 从 runtime state 的 JSON agent 节点准备 provider 启动参数
146
- /// returns: 环境覆盖、环境清除、命令覆写与 claude 配置目录
147
- /// errors: 同 prepare_provider_profile_launch
148
- /// contract_id: lifecycle.profile_launch.prepare
149
- /// ---
150
- pub(crate) fn prepare_provider_profile_launch_from_json(
151
- workspace: &Path,
152
- agent_id: &str,
153
- agent: &serde_json::Value,
154
- mcp_config: Option<&McpConfig>,
155
- ) -> Result<ProviderProfileLaunch, LifecycleError> {
156
- if let Some(retired) = agent.get("provider").and_then(serde_json::Value::as_str).filter(|provider| crate::provider::wire::is_retired_provider(provider)) {
157
- return Err(LifecycleError::Provider(crate::provider::wire::retired_provider_error(retired).into()));
158
- }
159
- let input = AgentProfileInput {
160
- id: agent
161
- .get("id")
162
- .and_then(serde_json::Value::as_str)
163
- .unwrap_or(agent_id)
164
- .to_string(),
165
- provider: agent
166
- .get("provider")
167
- .and_then(serde_json::Value::as_str)
168
- .and_then(parse_provider)
169
- .unwrap_or(Provider::Codex),
170
- auth_mode: agent
171
- .get("auth_mode")
172
- .and_then(serde_json::Value::as_str)
173
- .and_then(parse_auth_mode)
174
- .unwrap_or(AuthMode::Subscription),
175
- profile: agent
176
- .get("profile")
177
- .and_then(serde_json::Value::as_str)
178
- .filter(|value| !value.is_empty())
179
- .map(str::to_string),
180
- profile_dir: agent
181
- .get("_profile_dir")
182
- .and_then(serde_json::Value::as_str)
183
- .filter(|value| !value.is_empty())
184
- .map(PathBuf::from),
185
- model: agent
186
- .get("model")
187
- .and_then(serde_json::Value::as_str)
188
- .filter(|value| !value.is_empty())
189
- .map(str::to_string),
190
- model_source: agent
191
- .get("model_source")
192
- .and_then(serde_json::Value::as_str)
193
- .filter(|value| !value.is_empty())
194
- .map(str::to_string),
195
- };
196
- prepare_profile_launch(workspace, input, mcp_config)
197
- }
198
-
199
- fn prepare_profile_launch(
200
- workspace: &Path,
201
- agent: AgentProfileInput,
202
- mcp_config: Option<&McpConfig>,
203
- ) -> Result<ProviderProfileLaunch, LifecycleError> {
204
- let Some(profile) = agent.profile.as_deref() else {
205
- return Ok(ProviderProfileLaunch::default());
206
- };
207
- let Some(path) = find_profile_file(workspace, profile, agent.profile_dir.as_deref()) else {
208
- return Err(profile_not_found(profile));
209
- };
210
- let loaded = read_profile_file(path)?;
211
- validate_profile(&agent, profile, &loaded)?;
212
-
213
- let mut env_overlay = provider_env_exports(agent.provider, agent.auth_mode, &loaded.values);
214
- let mut env_unset = provider_env_unsets(agent.provider, agent.auth_mode);
215
- // Claude Code's compatible-API config dir went with its legacy worker runtime.
216
- let _ = mcp_config;
217
-
218
- env_overlay.extend(compatible_api_network_exports(
219
- agent.auth_mode,
220
- &loaded.values,
221
- ));
222
- if agent.auth_mode == AuthMode::CompatibleApi && profile_proxy_mode(&loaded.values) == "direct"
223
- {
224
- for key in COMPATIBLE_NETWORK_ENV_KEYS {
225
- env_unset.insert((*key).to_string());
226
- env_overlay.remove(*key);
227
- }
228
- }
229
- let command_overrides = provider_command_overrides(&agent, &loaded.values);
230
- write_runtime_env_file(workspace, &agent.id, &env_overlay, &env_unset)?;
231
-
232
- Ok(ProviderProfileLaunch {
233
- env_overlay,
234
- env_unset,
235
- command_overrides,
236
- claude_config_dir: None,
237
- claude_projects_root: None,
238
- managed_mcp_config: false,
239
- })
240
- }
241
-
242
- /// ---
243
- /// purpose: 按查找目录顺序定位 profile env 文件并解析成键值表
244
- /// params:
245
- /// name: profile 名,先找 name.env 再找 name.example.env
246
- /// profile_dir: 优先查找目录,None 表示只用默认顺序
247
- /// returns: 命中的文件路径与解析出的键值
248
- /// errors: 所有目录都没命中返回 RequirementUnmet,读文件失败返回 StatePersist
249
- /// ---
250
- pub(crate) fn load_profile(
251
- workspace: &Path,
252
- name: &str,
253
- profile_dir: Option<&Path>,
254
- ) -> Result<ProfileValues, LifecycleError> {
255
- let path =
256
- find_profile_file(workspace, name, profile_dir).ok_or_else(|| profile_not_found(name))?;
257
- read_profile_file(path)
258
- }
259
-
260
- fn find_profile_file(workspace: &Path, name: &str, profile_dir: Option<&Path>) -> Option<PathBuf> {
261
- let dirs = profile_lookup_dirs(workspace, profile_dir);
262
- dirs.iter()
263
- .map(|directory| directory.join(format!("{name}.env")))
264
- .find(|path| path.exists())
265
- .or_else(|| {
266
- dirs.iter()
267
- .map(|directory| directory.join(format!("{name}.example.env")))
268
- .find(|path| path.exists())
269
- })
270
- }
271
-
272
- fn profile_not_found(name: &str) -> LifecycleError {
273
- LifecycleError::RequirementUnmet(format!(
274
- "profile {name} not found; run team-agent profile init {name} --auth-mode subscription"
275
- ))
276
- }
277
-
278
- fn read_profile_file(path: PathBuf) -> Result<ProfileValues, LifecycleError> {
279
- let text = std::fs::read_to_string(&path)
280
- .map_err(|e| LifecycleError::StatePersist(format!("{}: {e}", path.display())))?;
281
- Ok(ProfileValues {
282
- path,
283
- values: parse_env_text(&text),
284
- })
285
- }
286
-
287
- fn profile_lookup_dirs(workspace: &Path, profile_dir: Option<&Path>) -> Vec<PathBuf> {
288
- let mut dirs = Vec::new();
289
- if let Some(dir) = profile_dir {
290
- push_unique_path(&mut dirs, dir.to_path_buf());
291
- }
292
- push_unique_path(&mut dirs, workspace.join(".team/current/profiles"));
293
- push_unique_path(&mut dirs, workspace.join("profiles"));
294
- push_unique_path(&mut dirs, workspace.join(".team/profiles"));
295
- if workspace.file_name().and_then(|name| name.to_str()) == Some(".team") {
296
- push_unique_path(&mut dirs, workspace.join("current/profiles"));
297
- }
298
- dirs
299
- }
300
-
301
- fn push_unique_path(paths: &mut Vec<PathBuf>, path: PathBuf) {
302
- if !paths.iter().any(|existing| existing == &path) {
303
- paths.push(path);
304
- }
305
- }
306
-
307
- pub(crate) fn parse_env_text(text: &str) -> BTreeMap<String, String> {
308
- let mut values = BTreeMap::new();
309
- for raw in text.lines() {
310
- let mut line = raw.trim();
311
- if line.is_empty() || line.starts_with('#') {
312
- continue;
313
- }
314
- if let Some(rest) = line.strip_prefix("export ") {
315
- line = rest.trim();
316
- }
317
- let Some((key, value)) = line.split_once('=') else {
318
- continue;
319
- };
320
- let key = key.trim();
321
- if !is_profile_key(key) {
322
- continue;
323
- }
324
- values.insert(key.to_string(), strip_env_value(value.trim()));
325
- }
326
- values
327
- }
328
-
329
- fn strip_env_value(raw: &str) -> String {
330
- let value = raw.trim();
331
- if value.len() >= 2 {
332
- if let Some(inner) = value.strip_prefix('"').and_then(|v| v.strip_suffix('"')) {
333
- return inner.to_string();
334
- }
335
- if let Some(inner) = value.strip_prefix('\'').and_then(|v| v.strip_suffix('\'')) {
336
- return inner.to_string();
337
- }
338
- }
339
- value.to_string()
340
- }
341
-
342
- fn is_profile_key(key: &str) -> bool {
343
- let mut chars = key.chars();
344
- match chars.next() {
345
- Some(c) if c.is_ascii_alphabetic() || c == '_' => {}
346
- _ => return false,
347
- }
348
- chars.all(|c| c.is_ascii_alphanumeric() || c == '_')
349
- }
350
-
351
- fn validate_profile(
352
- agent: &AgentProfileInput,
353
- profile: &str,
354
- loaded: &ProfileValues,
355
- ) -> Result<(), LifecycleError> {
356
- let proxy_mode = profile_proxy_mode(&loaded.values);
357
- if !matches!(proxy_mode.as_str(), "direct" | "inherit") {
358
- return Err(LifecycleError::RequirementUnmet(format!(
359
- "profile {profile} has invalid proxy mode {proxy_mode}; expected direct|inherit"
360
- )));
361
- }
362
- if loaded
363
- .values
364
- .get("AUTH_MODE")
365
- .is_some_and(|mode| parse_auth_mode(mode) != Some(agent.auth_mode))
366
- {
367
- return Err(LifecycleError::RequirementUnmet(format!(
368
- "profile {profile} AUTH_MODE does not match agent auth_mode"
369
- )));
370
- }
371
- if agent.auth_mode == AuthMode::CompatibleApi
372
- && matches!(agent.model_source.as_deref(), Some("role" | "team"))
373
- {
374
- let profile_model = profile_model(&loaded.values);
375
- if let Some(profile_model) = profile_model {
376
- if agent
377
- .model
378
- .as_deref()
379
- .is_some_and(|model| model != profile_model)
380
- {
381
- return Err(LifecycleError::RequirementUnmet(format!(
382
- "role/team model does not match profile MODEL in {}",
383
- loaded.path.display()
384
- )));
385
- }
386
- }
387
- }
388
- let mut missing: Vec<&str> = Vec::new();
389
- for key in required_profile_keys(agent.provider, agent.auth_mode) {
390
- if key == &"API_KEY" {
391
- continue;
392
- }
393
- if !profile_value_or_alternate(&loaded.values, key).is_some_and(|value| !value.is_empty()) {
394
- missing.push(*key);
395
- }
396
- }
397
- if agent.auth_mode == AuthMode::CompatibleApi
398
- && effective_profile_or_agent_model(agent, &loaded.values).is_none()
399
- {
400
- missing.push("MODEL");
401
- }
402
- if !missing.is_empty() {
403
- return Err(LifecycleError::RequirementUnmet(format!(
404
- "profile {profile} missing required values: {}",
405
- missing.join(", ")
406
- )));
407
- }
408
- Ok(())
409
- }
410
-
411
- fn provider_env_exports(
412
- provider: Provider,
413
- auth_mode: AuthMode,
414
- values: &BTreeMap<String, String>,
415
- ) -> BTreeMap<String, String> {
416
- let mut exports = BTreeMap::new();
417
- if auth_mode == AuthMode::Subscription {
418
- return exports;
419
- }
420
- match provider {
421
- Provider::GeminiCli => {
422
- append_env_pair(&mut exports, "GEMINI_API_KEY", value_or_alternate(values, "GEMINI_API_KEY", "API_KEY"));
423
- }
424
- // C-A-4 cr verdict v2 — copilot BYOK(== compatible_api 档,help-providers 原文
425
- // "GitHub authentication is not required" when COPILOT_PROVIDER_BASE_URL set):
426
- // profile 值经 env_overlay 落 COPILOT_PROVIDER_BASE_URL/TYPE/API_KEY/WIRE_API
427
- // + COPILOT_MODEL。BYOK 必须含 MODEL("A model is required for BYOK")—
428
- // 这一硬性校验在 launch 路径处理(profile compile 时无法判别 model 来源)。
429
- // Subscription/OfficialApi 不导出 COPILOT_PROVIDER_*(避免误改 auth 通道)。
430
- Provider::Copilot => {
431
- if auth_mode == AuthMode::CompatibleApi {
432
- for (key, alternate) in [
433
- ("COPILOT_PROVIDER_BASE_URL", "BASE_URL"),
434
- ("COPILOT_PROVIDER_TYPE", "PROVIDER_TYPE"),
435
- ("COPILOT_PROVIDER_API_KEY", "API_KEY"),
436
- ("COPILOT_PROVIDER_WIRE_API", "WIRE_API"),
437
- ("COPILOT_MODEL", "MODEL"),
438
- ] {
439
- append_env_pair(&mut exports, key, value_or_alternate(values, key, alternate));
440
- }
441
- }
442
- }
443
- // Claude Code, Codex, Grok and Pi workers run only through their
444
- // subscription-only contract leaves.
445
- Provider::Claude | Provider::ClaudeCode | Provider::Codex | Provider::Grok | Provider::Pi => {}
446
- Provider::Fake => {}
447
- }
448
- exports
449
- }
450
-
451
- #[cfg(test)]
452
- mod append_env_contract {
453
- use super::*;
454
-
455
- #[test]
456
- fn profile_append_keeps_native_keys_alternates_and_auth_gates() {
457
- let values: BTreeMap<String, String> = [
458
- ("API_KEY", "dummy"), ("BASE_URL", " raw\nbase "),
459
- ("AUTH_TOKEN", "dummy-token"), ("MODEL", " raw model "),
460
- ("PROVIDER_TYPE", "custom"), ("WIRE_API", "responses"),
461
- ("OPENAI_API_KEY", "native-dummy"),
462
- ].into_iter().map(|(k, v)| (k.to_string(), v.to_string())).collect();
463
- let map = |pairs: &[(&str, &str)]| -> BTreeMap<String, String> {
464
- pairs.iter().map(|(k, v)| (k.to_string(), v.to_string())).collect()
465
- };
466
- for provider in [Provider::Claude, Provider::ClaudeCode, Provider::Codex, Provider::Grok, Provider::Pi] {
467
- assert!(provider_env_exports(provider, AuthMode::OfficialApi, &values).is_empty());
468
- assert!(provider_env_exports(provider, AuthMode::CompatibleApi, &values).is_empty());
469
- }
470
- assert_eq!(provider_env_exports(Provider::GeminiCli, AuthMode::OfficialApi, &values), map(&[("GEMINI_API_KEY", "dummy")]));
471
- assert_eq!(provider_env_exports(Provider::Copilot, AuthMode::CompatibleApi, &values), map(&[
472
- ("COPILOT_PROVIDER_BASE_URL", " raw\nbase "), ("COPILOT_PROVIDER_TYPE", "custom"),
473
- ("COPILOT_PROVIDER_API_KEY", "dummy"), ("COPILOT_PROVIDER_WIRE_API", "responses"),
474
- ("COPILOT_MODEL", " raw model "),
475
- ]));
476
- assert!(provider_env_exports(Provider::Copilot, AuthMode::OfficialApi, &values).is_empty());
477
- for provider in crate::provider::wire::all_providers() {
478
- assert!(provider_env_exports(*provider, AuthMode::Subscription, &values).is_empty());
479
- assert!(provider_env_exports(*provider, AuthMode::CompatibleApi, &BTreeMap::new()).is_empty());
480
- }
481
- }
482
- }
483
-
484
- /// ---
485
- /// purpose: 给出该 provider 与 auth_mode 下必须从子进程环境里清掉的变量名集
486
- /// returns: 变量名集合;claude 系清掉会让子进程并入父会话的那组标识
487
- /// ---
488
- /// 0.4.x (CR C-1): exposed as `pub(crate)` so the leader launcher
489
- /// (leader/start.rs) can reuse the SAME Claude/Codex/Copilot env-unset set
490
- /// used by worker spawn. Single source of truth — adding a new provider env
491
- /// var to clean up means changing this one function. Audit grep guard in
492
- /// `crates/team-agent/src/leader/start.rs::leader_env_unset_for_provider`
493
- /// confirms the leader path imports from here and does not maintain its own
494
- /// duplicate list.
495
- pub(crate) fn provider_env_unsets(provider: Provider, auth_mode: AuthMode) -> BTreeSet<String> {
496
- let mut unsets = BTreeSet::new();
497
- match provider {
498
- Provider::Claude | Provider::ClaudeCode => {
499
- // E57 (0.3.27 P0): unset CLAUDE_CODE_SESSION_ID inherited from the
500
- // leader's environment. When a Claude leader spawns a Claude worker,
501
- // the worker inherits the leader's CLAUDE_CODE_SESSION_ID; Claude
502
- // Code then routes the worker's transcript to the leader's session
503
- // file (~/.claude/projects/<hash>/<leader-session-uuid>.jsonl),
504
- // corrupting attribution and transcripts. Always unset so Claude
505
- // Code generates a fresh session id per worker.
506
- //
507
- // S1-CAPTURE (0.4.x P0): also unset the rest of the Claude Code
508
- // child/team env block. These variables make the spawned process
509
- // believe it is a CHILD of the parent Claude (CLAUDE_CODE_CHILD_SESSION),
510
- // a TEAM member (CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS), or otherwise
511
- // inherit the parent's invocation identity (ENTRYPOINT / EXECPATH /
512
- // CLAUDECODE marker). Without unsetting these, a Claude worker
513
- // spawned from a Claude leader is not an INDEPENDENT process — it
514
- // joins the leader's session tree and its transcript / state /
515
- // billing are attributed to the leader. CLAUDE_EFFORT is preserved
516
- // (effort preference does not affect session attribution).
517
- unsets.insert("CLAUDE_CODE_SESSION_ID".to_string());
518
- unsets.insert("CLAUDE_CODE_CHILD_SESSION".to_string());
519
- unsets.insert("CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS".to_string());
520
- unsets.insert("CLAUDE_CODE_ENTRYPOINT".to_string());
521
- unsets.insert("CLAUDE_CODE_EXECPATH".to_string());
522
- unsets.insert("CLAUDECODE".to_string());
523
- if auth_mode == AuthMode::CompatibleApi {
524
- unsets.insert("ANTHROPIC_API_KEY".to_string());
525
- }
526
- if auth_mode == AuthMode::OfficialApi {
527
- unsets.insert("ANTHROPIC_AUTH_TOKEN".to_string());
528
- }
529
- }
530
- Provider::Codex => {
531
- if auth_mode == AuthMode::CompatibleApi {
532
- unsets.insert("OPENAI_API_KEY".to_string());
533
- unsets.insert("OPENAI_BASE_URL".to_string());
534
- }
535
- }
536
- Provider::GeminiCli => {
537
- if auth_mode == AuthMode::CompatibleApi {
538
- unsets.insert("GEMINI_API_KEY".to_string());
539
- }
540
- }
541
- // C-7-1 cr verdict: 一期 subscription-only(已登录态),exports/unsets 空;
542
- // BYOK(COPILOT_PROVIDER_*)二期立项时单独 cr verdict 再开。
543
- Provider::Copilot => {}
544
- // Grok has no provider-specific environment to unset.
545
- Provider::Grok => {}
546
- Provider::Pi => {}
547
- Provider::Fake => {}
548
- }
549
- unsets
550
- }
551
-
552
- fn provider_command_overrides(
553
- agent: &AgentProfileInput,
554
- values: &BTreeMap<String, String>,
555
- ) -> ProviderCommandOverrides {
556
- let model = match agent.model_source.as_deref() {
557
- Some("role" | "team") => agent.model.clone(),
558
- Some("default") => profile_model(values)
559
- .map(str::to_string)
560
- .or_else(|| agent.model.clone()),
561
- _ if agent.model.is_some() => agent.model.clone(),
562
- _ => profile_model(values).map(str::to_string),
563
- };
564
- ProviderCommandOverrides { model }
565
- }
566
-
567
- fn write_runtime_env_file(
568
- workspace: &Path,
569
- agent_id: &str,
570
- exports: &BTreeMap<String, String>,
571
- unsets: &BTreeSet<String>,
572
- ) -> Result<(), LifecycleError> {
573
- if exports.is_empty() && unsets.is_empty() {
574
- return Ok(());
575
- }
576
- let dir = workspace.join(".team/runtime/provider-env");
577
- std::fs::create_dir_all(&dir)
578
- .map_err(|e| LifecycleError::StatePersist(format!("{}: {e}", dir.display())))?;
579
- let path = dir.join(format!("{agent_id}.env"));
580
- let mut lines = Vec::new();
581
- for key in unsets {
582
- lines.push(format!("unset {key}"));
583
- }
584
- for (key, value) in exports {
585
- lines.push(format!("export {key}={}", shell_quote(value)));
586
- }
587
- std::fs::write(&path, format!("{}\n", lines.join("\n")))
588
- .map_err(|e| LifecycleError::StatePersist(format!("{}: {e}", path.display())))?;
589
- set_owner_only_permissions(&path)?;
590
- Ok(())
591
- }
592
-
593
- #[cfg(unix)]
594
- fn set_owner_only_permissions(path: &Path) -> Result<(), LifecycleError> {
595
- use std::os::unix::fs::PermissionsExt;
596
-
597
- std::fs::set_permissions(path, std::fs::Permissions::from_mode(0o600))
598
- .map_err(|e| LifecycleError::StatePersist(format!("{}: {e}", path.display())))
599
- }
600
-
601
- #[cfg(not(unix))]
602
- fn set_owner_only_permissions(path: &Path) -> Result<(), LifecycleError> {
603
- let _ = path;
604
- Ok(())
605
- }
606
-
607
- fn shell_quote(value: &str) -> String {
608
- if value.is_empty() {
609
- return "''".to_string();
610
- }
611
- if value
612
- .chars()
613
- .all(|c| c.is_ascii_alphanumeric() || "-_./:@%+=".contains(c))
614
- {
615
- return value.to_string();
616
- }
617
- format!("'{}'", value.replace('\'', "'\"'\"'"))
618
- }
619
-
620
- fn compatible_api_network_exports(
621
- auth_mode: AuthMode,
622
- values: &BTreeMap<String, String>,
623
- ) -> BTreeMap<String, String> {
624
- if auth_mode != AuthMode::CompatibleApi || profile_proxy_mode(values) == "direct" {
625
- return BTreeMap::new();
626
- }
627
- COMPATIBLE_NETWORK_ENV_KEYS
628
- .iter()
629
- .filter_map(|key| {
630
- values
631
- .get(*key)
632
- .filter(|value| !value.is_empty())
633
- .map(|value| ((*key).to_string(), value.clone()))
634
- })
635
- .collect()
636
- }
637
-
638
- /// ---
639
- /// purpose: 读出 profile 声明的代理模式
640
- /// params:
641
- /// values: 已解析的 profile 键值,先看 PROXY_MODE 再看 NETWORK_MODE
642
- /// returns: 小写去空白后的模式串,两个键都没有时为 inherit
643
- /// ---
644
- pub(crate) fn profile_proxy_mode(values: &BTreeMap<String, String>) -> String {
645
- values
646
- .get("PROXY_MODE")
647
- .or_else(|| values.get("NETWORK_MODE"))
648
- .map(|value| value.trim().to_ascii_lowercase())
649
- .unwrap_or_else(|| "inherit".to_string())
650
- }
651
-
652
- fn required_profile_keys(provider: Provider, auth_mode: AuthMode) -> &'static [&'static str] {
653
- if auth_mode == AuthMode::Subscription {
654
- return &[];
655
- }
656
- match provider {
657
- Provider::GeminiCli => &["API_KEY"],
658
- // C-7-1 cr verdict: copilot 一期 subscription-only,无 BYOK required key 集合;
659
- // 二期 BYOK 立项时填(向后兼容字段保留)。
660
- Provider::Copilot => &[],
661
- // Claude Code/Codex/Grok/Pi worker 只走 subscription-only contract leaf。
662
- Provider::Claude | Provider::ClaudeCode | Provider::Codex | Provider::Grok | Provider::Pi => &[],
663
- Provider::Fake => &[],
664
- }
665
- }
666
-
667
- /// ---
668
- /// purpose: 取 profile 里某个规范键,取不到时按该键的已知别名回退
669
- /// params:
670
- /// key: 规范键名,API_KEY BASE_URL MODEL 各有一组别名,其余键不回退
671
- /// returns: 命中的非空值
672
- /// ---
673
- pub(crate) fn profile_value_or_alternate<'a>(
674
- values: &'a BTreeMap<String, String>,
675
- key: &str,
676
- ) -> Option<&'a str> {
677
- values
678
- .get(key)
679
- .filter(|value| !value.is_empty())
680
- .map(String::as_str)
681
- .or_else(|| {
682
- match key {
683
- "API_KEY" => values
684
- .get("ANTHROPIC_API_KEY")
685
- .or_else(|| values.get("ANTHROPIC_AUTH_TOKEN"))
686
- .or_else(|| values.get("AUTH_TOKEN"))
687
- .or_else(|| values.get("CLAUDE_API_KEY"))
688
- .or_else(|| values.get("CLAUDE_AUTH_TOKEN"))
689
- .or_else(|| values.get("BEARER_TOKEN"))
690
- .or_else(|| values.get("TEAM_AGENT_PROVIDER_API_KEY"))
691
- .or_else(|| values.get("OPENAI_API_KEY")),
692
- "BASE_URL" => values
693
- .get("ANTHROPIC_BASE_URL")
694
- .or_else(|| values.get("OPENAI_BASE_URL")),
695
- "MODEL" => values.get("ANTHROPIC_MODEL"),
696
- _ => None,
697
- }
698
- .filter(|value| !value.is_empty())
699
- .map(String::as_str)
700
- })
701
- }
702
-
703
- /// ---
704
- /// purpose: 在两个显式给定的键之间取第一个非空值
705
- /// returns: 命中的非空值,两个都空则 None
706
- /// ---
707
- pub(crate) fn value_or_alternate<'a>(
708
- values: &'a BTreeMap<String, String>,
709
- primary: &str,
710
- alternate: &str,
711
- ) -> Option<&'a str> {
712
- values
713
- .get(primary)
714
- .filter(|value| !value.is_empty())
715
- .or_else(|| values.get(alternate).filter(|value| !value.is_empty()))
716
- .map(String::as_str)
717
- }
718
-
719
- /// ---
720
- /// purpose: 取 profile 里声明的模型名
721
- /// returns: MODEL 的非空值,没有时取 ANTHROPIC_MODEL
722
- /// ---
723
- pub(crate) fn profile_model(values: &BTreeMap<String, String>) -> Option<&str> {
724
- values
725
- .get("MODEL")
726
- .filter(|value| !value.is_empty())
727
- .or_else(|| {
728
- values
729
- .get("ANTHROPIC_MODEL")
730
- .filter(|value| !value.is_empty())
731
- })
732
- .map(String::as_str)
733
- }
734
-
735
- fn effective_profile_or_agent_model<'a>(
736
- agent: &'a AgentProfileInput,
737
- values: &'a BTreeMap<String, String>,
738
- ) -> Option<&'a str> {
739
- agent.model.as_deref().or_else(|| profile_model(values))
740
- }
741
-
742
- pub(crate) use crate::provider::wire::parse_provider;
743
-
744
- /// ---
745
- /// purpose: 把 auth_mode 字符串解析成枚举
746
- /// params:
747
- /// raw: 只接受 subscription、official_api、compatible_api
748
- /// returns: 对应枚举;未知取值返回 None,由调用方决定兜底
749
- /// ---
750
- pub(crate) fn parse_auth_mode(raw: &str) -> Option<AuthMode> {
751
- match raw {
752
- "subscription" => Some(AuthMode::Subscription),
753
- "official_api" => Some(AuthMode::OfficialApi),
754
- "compatible_api" => Some(AuthMode::CompatibleApi),
755
- _ => None,
756
- }
757
- }