@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,723 +0,0 @@
1
- use super::launch_spawn::seed_healthy_coordinator;
2
- use super::*;
3
- use crate::cli::{cmd_doctor, CmdOutput, CmdResult, DoctorArgs};
4
- use crate::transport::test_support::OfflineTransport;
5
- use serde_json::{json, Map, Value};
6
- use std::collections::BTreeMap;
7
- use std::path::{Path, PathBuf};
8
- use std::sync::atomic::{AtomicU64, Ordering};
9
-
10
- const ANCESTRY_ENV: &str = "TEAM_AGENT_TEST_PROCESS_ANCESTRY_ARGV_JSON";
11
-
12
- static HERMETIC_COUNTER: AtomicU64 = AtomicU64::new(0);
13
-
14
- struct HermeticTestEnv {
15
- root: PathBuf,
16
- previous: Vec<(&'static str, Option<String>)>,
17
- }
18
-
19
- impl HermeticTestEnv {
20
- fn enter(tag: &str) -> Self {
21
- let base = std::env::var_os("TEAM_AGENT_TEST_TMP")
22
- .map(PathBuf::from)
23
- .unwrap_or_else(std::env::temp_dir);
24
- std::fs::create_dir_all(&base).expect("create hermetic test tmp root");
25
- let root = base.join(format!(
26
- "ta-phase-golden-{tag}-{}-{}",
27
- std::process::id(),
28
- HERMETIC_COUNTER.fetch_add(1, Ordering::Relaxed)
29
- ));
30
- let _ = std::fs::remove_dir_all(&root);
31
- std::fs::create_dir_all(root.join("home/.team-agent/leaders"))
32
- .expect("create phase golden hermetic root");
33
- let root = std::fs::canonicalize(root).expect("canonicalize phase golden hermetic root");
34
- let home = root.join("home");
35
- let mut previous = Vec::new();
36
- for key in std::iter::once("HOME").chain(hermetic_caller_envs().iter().copied()) {
37
- previous.push((key, std::env::var(key).ok()));
38
- }
39
- unsafe {
40
- std::env::set_var("HOME", &home);
41
- for key in hermetic_caller_envs() {
42
- std::env::remove_var(key);
43
- }
44
- }
45
- Self { root, previous }
46
- }
47
-
48
- fn workspace(&self, tag: &str) -> PathBuf {
49
- let path = self.root.join(format!(
50
- "workspace-{tag}-{}",
51
- HERMETIC_COUNTER.fetch_add(1, Ordering::Relaxed)
52
- ));
53
- std::fs::create_dir_all(&path).expect("create phase golden workspace");
54
- std::fs::canonicalize(path).expect("canonicalize phase golden workspace")
55
- }
56
- }
57
-
58
- impl Drop for HermeticTestEnv {
59
- fn drop(&mut self) {
60
- for (key, value) in self.previous.drain(..).rev() {
61
- unsafe {
62
- if let Some(value) = value {
63
- std::env::set_var(key, value);
64
- } else {
65
- std::env::remove_var(key);
66
- }
67
- }
68
- }
69
- if std::env::var("TEAM_AGENT_KEEP_TEST_TMP").as_deref() != Ok("1") {
70
- let _ = std::fs::remove_dir_all(&self.root);
71
- }
72
- }
73
- }
74
-
75
- fn hermetic_caller_envs() -> &'static [&'static str] {
76
- &[
77
- "TMUX",
78
- "TMUX_PANE",
79
- "TEAM_AGENT_LEADER_PANE_ID",
80
- "TEAM_AGENT_LEADER_SESSION_UUID",
81
- "TEAM_AGENT_LEADER_SESSION_UUID_OVERRIDE",
82
- "TEAM_AGENT_LEADER_PROVIDER",
83
- "TEAM_AGENT_MACHINE_FINGERPRINT",
84
- "TEAM_AGENT_WORKSPACE",
85
- "TEAM_AGENT_TEAM_ID",
86
- "TEAM_AGENT_OWNER_TEAM_ID",
87
- "TEAM_AGENT_ACTIVE_TEAM",
88
- "TEAM_AGENT_ID",
89
- "TEAM_AGENT_CALLER_PROVIDER",
90
- "TEAM_AGENT_CALLER_PANE_ID",
91
- "TEAM_AGENT_CALLER_TMUX_ENDPOINT",
92
- ]
93
- }
94
-
95
- #[test]
96
- #[serial_test::serial(env)]
97
- fn phase_golden_missing_registry_requires_index_publication_not_claim() {
98
- let diagnose = run_diagnose_after_unbound_state_fixture();
99
- let issues = diagnose
100
- .get("issues")
101
- .and_then(Value::as_array)
102
- .cloned()
103
- .unwrap_or_default();
104
- let issue_ids: Vec<&str> = issues
105
- .iter()
106
- .filter_map(|issue| issue.as_str())
107
- .collect();
108
- assert_eq!(
109
- issue_ids
110
- .iter()
111
- .copied()
112
- .filter(|id| *id == "leader_registry_index_missing")
113
- .count(),
114
- 1,
115
- "tombstone after seeded owner without registry must be exactly index-missing; diagnose={diagnose}"
116
- );
117
- assert!(
118
- !issue_ids.contains(&"leader_receiver_not_committed"),
119
- "parallel not_committed bool must not appear; diagnose={diagnose}"
120
- );
121
- let repairs = diagnose
122
- .get("suggested_repairs")
123
- .map(Value::to_string)
124
- .unwrap_or_default();
125
- assert!(
126
- repairs.contains("publish the leader registry index"),
127
- "index-missing repair must publish the index; diagnose={diagnose}"
128
- );
129
- assert!(
130
- !repairs.contains("team-agent claim-leader --confirm"),
131
- "index-missing must not recommend claim-leader --confirm; diagnose={diagnose}"
132
- );
133
- }
134
-
135
- fn two_worker_team_dir(hermetic: &HermeticTestEnv) -> PathBuf {
136
- let team = hermetic.workspace("team").join("teamdir");
137
- std::fs::create_dir_all(team.join("agents")).unwrap();
138
- std::fs::write(
139
- team.join("TEAM.md"),
140
- "---\nname: teamdir\nobjective: Phase golden.\nprovider: codex\nsession_name: team-phasegolden\n---\n\nPhase golden team.\n",
141
- )
142
- .unwrap();
143
- for id in ["w1", "w2"] {
144
- std::fs::write(team.join("agents").join(format!("{id}.md")), role_doc(id)).unwrap();
145
- }
146
- team
147
- }
148
-
149
- fn role_doc(id: &str) -> String {
150
- format!(
151
- "---\nname: {id}\nrole: {id} Worker\nprovider: fake\nmodel: fake\nauth_mode: subscription\ndangerously_skip_permissions: false\ntools:\n - mcp_team\n---\n\n{id} worker.\n"
152
- )
153
- }
154
-
155
- fn cmd_value(result: Result<CmdResult, crate::cli::CliError>) -> Value {
156
- match result {
157
- Ok(cmd) => json!({
158
- "exit_code": cmd.exit.code(),
159
- "output": match cmd.output {
160
- CmdOutput::Json(value) => value,
161
- CmdOutput::Human(text) => json!({"human": text}),
162
- CmdOutput::None => Value::Null,
163
- },
164
- }),
165
- Err(error) => json!({
166
- "exit_code": 1,
167
- "error": error.to_string(),
168
- }),
169
- }
170
- }
171
-
172
- fn run_diagnose_after_unbound_state_fixture() -> Value {
173
- let hermetic = HermeticTestEnv::enter("tombstone-claim-leader");
174
- let _permission_mode = EnvVarGuard::set(ANCESTRY_ENV, "[]");
175
- let team = two_worker_team_dir(&hermetic);
176
- let workspace = team.parent().expect("workspace").to_path_buf();
177
- seed_healthy_coordinator(&workspace);
178
- let launch_transport = OfflineTransport::new();
179
- crate::lifecycle::launch::materialize_unbound_state_for_test(
180
- &workspace, &team, "teamdir", &launch_transport,
181
- ).expect("materialize the recording-only tombstone fixture, not a callerless public start");
182
- let mut state = crate::state::persist::load_runtime_state(&workspace)
183
- .expect("tombstone fixture must persist runtime state");
184
- crate::lifecycle::launch::seed_launched_owner_from_caller_with_provider_lookup(
185
- &mut state,
186
- crate::state::owner_gate::CallerIdentity {
187
- pane_id: "%1".to_string(),
188
- provider: "codex".to_string(),
189
- machine_fingerprint: "fp".to_string(),
190
- leader_session_uuid: "uuid-tombstone".to_string(),
191
- leader_session_uuid_source: "env".to_string(),
192
- },
193
- |_| None,
194
- );
195
- crate::state::persist::save_runtime_state(&workspace, &state)
196
- .expect("persist seeded owner without registry");
197
- if let Some(dir) = crate::leader::registry::registry_dir() {
198
- if let Ok(entries) = std::fs::read_dir(&dir) {
199
- for entry in entries.flatten() {
200
- let _ = std::fs::remove_file(entry.path());
201
- }
202
- }
203
- }
204
- assert!(
205
- state
206
- .pointer("/teams/teamdir/team_owner/pane_id")
207
- .or_else(|| state.pointer("/team_owner/pane_id"))
208
- .and_then(Value::as_str)
209
- .is_some(),
210
- "index-missing diagnose requires a persisted seeded owner"
211
- );
212
- let diagnose = cmd_doctor(&DoctorArgs {
213
- workspace,
214
- json: true,
215
- team: Some("teamdir".to_string()),
216
- spec: None,
217
- gate: None,
218
- comms: false,
219
- fix: false,
220
- fix_schema: false,
221
- cleanup_orphans: false,
222
- confirm: false,
223
- });
224
- match cmd_value(diagnose) {
225
- Value::Object(map) => map
226
- .get("output")
227
- .cloned()
228
- .unwrap_or_else(|| panic!("diagnose missing output")),
229
- other => panic!("diagnose must be a JSON object, got {other}"),
230
- }
231
- }
232
-
233
- struct EnvVarGuard {
234
- key: &'static str,
235
- previous: Option<String>,
236
- }
237
-
238
- impl EnvVarGuard {
239
- fn set(key: &'static str, value: &str) -> Self {
240
- let previous = std::env::var(key).ok();
241
- unsafe {
242
- std::env::set_var(key, value);
243
- }
244
- Self { key, previous }
245
- }
246
- }
247
-
248
- impl Drop for EnvVarGuard {
249
- fn drop(&mut self) {
250
- unsafe {
251
- if let Some(value) = self.previous.take() {
252
- std::env::set_var(self.key, value);
253
- } else {
254
- std::env::remove_var(self.key);
255
- }
256
- }
257
- }
258
- }
259
-
260
- struct NormalizeCtx {
261
- workspace_aliases: Vec<String>,
262
- temp_aliases: Vec<String>,
263
- pane_ids: BTreeMap<String, String>,
264
- }
265
-
266
- impl NormalizeCtx {
267
- fn new(workspace: &Path) -> Self {
268
- Self {
269
- workspace_aliases: path_aliases(workspace),
270
- temp_aliases: path_aliases(&std::env::temp_dir()),
271
- pane_ids: BTreeMap::new(),
272
- }
273
- }
274
-
275
- fn pane_token(&mut self, pane: &str) -> String {
276
- if let Some(token) = self.pane_ids.get(pane) {
277
- return token.clone();
278
- }
279
- let token = format!("<PANE:{}>", self.pane_ids.len());
280
- self.pane_ids.insert(pane.to_string(), token.clone());
281
- token
282
- }
283
- }
284
-
285
- fn path_aliases(path: &Path) -> Vec<String> {
286
- let mut aliases = Vec::new();
287
- push_path_alias(&mut aliases, path.to_path_buf());
288
- if let Ok(canonical) = std::fs::canonicalize(path) {
289
- push_path_alias(&mut aliases, canonical);
290
- }
291
- aliases.sort_by(|a, b| b.len().cmp(&a.len()).then_with(|| a.cmp(b)));
292
- aliases.dedup();
293
- aliases
294
- }
295
-
296
- fn push_path_alias(aliases: &mut Vec<String>, path: PathBuf) {
297
- let path = path.to_string_lossy().to_string();
298
- if path.is_empty() {
299
- return;
300
- }
301
- aliases.push(path.clone());
302
- if let Some(stripped) = path.strip_prefix("/private/") {
303
- aliases.push(format!("/{stripped}"));
304
- } else if path.starts_with('/') {
305
- aliases.push(format!("/private{path}"));
306
- }
307
- }
308
-
309
- fn normalize_value(value: Value, ctx: &mut NormalizeCtx, key: Option<&str>) -> Value {
310
- if matches!(key, Some("env_overlay_keys" | "env_unset_keys")) {
311
- return json!("<ENV_KEYS>");
312
- }
313
- if matches!(key, Some("env_unset")) {
314
- return json!([]);
315
- }
316
- match value {
317
- Value::Object(map) => {
318
- let sorted = map.into_iter().collect::<BTreeMap<_, _>>();
319
- let mut out = Map::new();
320
- for (child_key, child) in sorted {
321
- if matches!(child_key.as_str(), "model_source" | "provider_source") {
322
- continue;
323
- }
324
- out.insert(
325
- child_key.clone(),
326
- normalize_value(child, ctx, Some(child_key.as_str())),
327
- );
328
- }
329
- Value::Object(out)
330
- }
331
- Value::Array(items) => Value::Array(
332
- items
333
- .into_iter()
334
- .map(|item| normalize_value(item, ctx, key))
335
- .collect(),
336
- ),
337
- Value::String(text) => normalize_string(text, ctx, key),
338
- Value::Number(number) if key_is_pid_or_duration(key) => {
339
- if number.is_u64() || number.is_i64() {
340
- json!(0)
341
- } else {
342
- Value::Number(number)
343
- }
344
- }
345
- other => other,
346
- }
347
- }
348
-
349
- fn normalize_string(text: String, ctx: &mut NormalizeCtx, key: Option<&str>) -> Value {
350
- let key = key.unwrap_or_default();
351
- if key_is_timestamp(key) || key == "generation" {
352
- return json!("<TS>");
353
- }
354
- if key == "workspace_hash" {
355
- return json!("<ID>");
356
- }
357
- if text == crate::packaging::Version::current().as_str() {
358
- return json!("<VERSION>");
359
- }
360
- if key.contains("endpoint") && value_looks_like_endpoint_path(&text) {
361
- return json!("<SOCKET>");
362
- }
363
- if key_is_id(key, &text) {
364
- return json!("<ID>");
365
- }
366
- if key_contains_path(key) {
367
- return json!(normalize_path_string(&text, ctx));
368
- }
369
- if text.starts_with('%') && text[1..].chars().all(|c| c.is_ascii_digit()) {
370
- return json!(ctx.pane_token(&text));
371
- }
372
- let normalized = normalize_path_string(&text, ctx);
373
- if normalized != text {
374
- return json!(normalized);
375
- }
376
- json!(text)
377
- }
378
-
379
- fn normalize_path_string(text: &str, ctx: &NormalizeCtx) -> String {
380
- let mut out = text.to_string();
381
- out = normalize_team_agent_binary_path(&out);
382
- for alias in &ctx.workspace_aliases {
383
- out = out.replace(alias, "<WORKSPACE>");
384
- }
385
- out = out.replace("/private<WORKSPACE>", "<WORKSPACE>");
386
- for alias in &ctx.temp_aliases {
387
- out = out.replace(alias, "<TMP>");
388
- }
389
- out = normalize_tmux_socket_dir(&out);
390
- out = normalize_hermetic_root(&out);
391
- out = normalize_registry_hash(&out);
392
- normalize_socket_token(&out)
393
- }
394
-
395
- fn normalize_registry_hash(text: &str) -> String {
396
- let Some(start) = text.rfind("/leaders/") else {
397
- return text.to_string();
398
- };
399
- let file_start = start + "/leaders/".len();
400
- let Some(separator) = text[file_start..].find("__") else {
401
- return text.to_string();
402
- };
403
- let separator = file_start + separator;
404
- text[..file_start].to_owned() + "<ID>" + &text[separator..]
405
- }
406
-
407
- fn normalize_hermetic_root(text: &str) -> String {
408
- let marker = "ta-phase-golden-";
409
- let Some(start) = text.find(marker) else {
410
- return text.to_string();
411
- };
412
- let end = text[start..]
413
- .find('/')
414
- .map(|offset| start + offset)
415
- .unwrap_or(text.len());
416
- let segment = &text[start..end];
417
- let Some(phase) = text[start + marker.len()..end].split('-').next() else {
418
- return text.to_string();
419
- };
420
- text.replacen(segment, &format!("{marker}{phase}"), 1)
421
- }
422
-
423
- fn value_looks_like_endpoint_path(text: &str) -> bool {
424
- text.starts_with('/')
425
- || text.starts_with("ta-")
426
- || text.contains("/tmux-")
427
- || text.contains("tmux-")
428
- }
429
-
430
- fn normalize_team_agent_binary_path(text: &str) -> String {
431
- let mut out = replace_known_team_agent_binary_paths(text);
432
- // 0.5.0 hermetic 教训「环境路径类 token 化」的直接延伸
433
- // (leader msg_6ee04cf5aee8):归一化改为结构判据,不绑路径前缀。
434
- // 用户 CARGO_TARGET_DIR 可以指到任意目录(默认 `<repo>/target`,
435
- // 全局改道时是 `/Volumes/nvme/cargo-target`,CI 时可能是别的)。
436
- // 结构判据:任意绝对路径下的 `/deps/team_agent-<hex>`(可选 `.exe`)
437
- // → `<TEAM_AGENT_BIN>`。同时保留旧 marker 兼容(处理旧固定字符串
438
- // 出现在 output 里,以及 `debug/team-agent` / `release/team-agent`
439
- // 这两个非 `/deps/` 分支)。
440
- out = normalize_deps_team_agent_by_structure(&out);
441
- for marker in [
442
- "/target/debug/deps/team_agent-",
443
- "/target/debug/team-agent",
444
- "/target/release/team-agent",
445
- ] {
446
- out = replace_path_with_marker(out, marker, "<TEAM_AGENT_BIN>");
447
- }
448
- out
449
- }
450
-
451
- fn replace_known_team_agent_binary_paths(text: &str) -> String {
452
- let mut out = text.to_string();
453
- for alias in known_team_agent_binary_path_aliases() {
454
- out = out.replace(&alias, "<TEAM_AGENT_BIN>");
455
- }
456
- out
457
- }
458
-
459
- fn known_team_agent_binary_path_aliases() -> Vec<String> {
460
- let mut aliases = Vec::new();
461
- if let Some(path) = option_env!("CARGO_BIN_EXE_team-agent") {
462
- push_path_alias(&mut aliases, PathBuf::from(path));
463
- }
464
- if let Some(path) = std::env::var_os("CARGO_BIN_EXE_team-agent") {
465
- push_path_alias(&mut aliases, PathBuf::from(path));
466
- }
467
- if let Ok(path) = std::env::current_exe() {
468
- push_path_alias(&mut aliases, path);
469
- }
470
- aliases.sort_by(|a, b| b.len().cmp(&a.len()).then_with(|| a.cmp(b)));
471
- aliases.dedup();
472
- aliases
473
- }
474
-
475
- /// Structural (path-prefix-independent) normalization for
476
- /// `/…/deps/team_agent-<hex>(.exe)?` occurrences. Scans the input for
477
- /// every `/deps/team_agent-` marker and rewrites the containing
478
- /// absolute path token to `<TEAM_AGENT_BIN>`, no matter which
479
- /// `CARGO_TARGET_DIR` produced it.
480
- fn normalize_deps_team_agent_by_structure(text: &str) -> String {
481
- const MARKER: &str = "/deps/team_agent-";
482
- let mut out = String::with_capacity(text.len());
483
- let bytes = text.as_bytes();
484
- let mut i = 0usize;
485
- while i < bytes.len() {
486
- let Some(rel) = text[i..].find(MARKER) else {
487
- out.push_str(&text[i..]);
488
- break;
489
- };
490
- let marker_idx = i + rel;
491
- // Locate the start of the absolute path token: walk back from
492
- // `marker_idx` while the byte is not one of a small set of
493
- // delimiters (quote, whitespace, `[`, `(`, `,`, `:` after
494
- // whitespace). The absolute-path anchor MUST also start with
495
- // `/` — if the containing token is not absolute, skip
496
- // rewriting so we don't eat unrelated text.
497
- let path_start = text[..marker_idx]
498
- .rfind(|c: char| matches!(c, '"' | '\'' | ' ' | '[' | '(' | ',' | '\n' | '\t'))
499
- .map(|idx| idx + 1)
500
- .unwrap_or(0);
501
- // Confirm the token starts with `/` (absolute path).
502
- if !text[path_start..].starts_with('/') {
503
- // Not an absolute path — leave alone.
504
- out.push_str(&text[i..marker_idx + MARKER.len()]);
505
- i = marker_idx + MARKER.len();
506
- continue;
507
- }
508
- // Extend the end past the hex hash + optional `.exe`. Same
509
- // continuation rule as `replace_path_with_marker`: alnum + `-`
510
- // + `_` + `.`.
511
- let mut path_end = marker_idx + MARKER.len();
512
- while path_end < text.len() {
513
- let ch = text[path_end..].chars().next().expect("char at boundary");
514
- if ch.is_ascii_alphanumeric() || matches!(ch, '-' | '_' | '.') {
515
- path_end += ch.len_utf8();
516
- } else {
517
- break;
518
- }
519
- }
520
- // Emit everything up to the path start, then the token, then
521
- // continue past the eaten span.
522
- out.push_str(&text[i..path_start]);
523
- out.push_str("<TEAM_AGENT_BIN>");
524
- i = path_end;
525
- }
526
- out
527
- }
528
-
529
- fn replace_path_with_marker(mut text: String, marker: &str, token: &str) -> String {
530
- let mut search_from = 0;
531
- while let Some(offset) = text[search_from..].find(marker) {
532
- let marker_idx = search_from + offset;
533
- let start = text[..marker_idx]
534
- .rfind(|c: char| matches!(c, '"' | '\'' | ' ' | '[' | '('))
535
- .map(|idx| idx + 1)
536
- .unwrap_or(0);
537
- let mut end = marker_idx + marker.len();
538
- while end < text.len() {
539
- let ch = text[end..].chars().next().expect("char at boundary");
540
- if ch.is_ascii_alphanumeric() || matches!(ch, '-' | '_' | '.') {
541
- end += ch.len_utf8();
542
- } else {
543
- break;
544
- }
545
- }
546
- text.replace_range(start..end, token);
547
- search_from = start + token.len();
548
- }
549
- text
550
- }
551
-
552
- fn normalize_tmux_socket_dir(text: &str) -> String {
553
- let out = text
554
- .replace("/private/tmp/tmux-", "<TMP>/tmux-")
555
- .replace("/tmp/tmux-", "<TMP>/tmux-");
556
- normalize_tmux_uid_with_prefix(out, "<TMP>/tmux-")
557
- }
558
-
559
- fn normalize_tmux_uid_with_prefix(mut text: String, prefix: &str) -> String {
560
- let mut search_from = 0;
561
- while let Some(offset) = text[search_from..].find(prefix) {
562
- let start = search_from + offset + prefix.len();
563
- let mut end = start;
564
- while end < text.len() {
565
- let ch = text[end..].chars().next().expect("char at boundary");
566
- if ch.is_ascii_digit() {
567
- end += ch.len_utf8();
568
- } else {
569
- break;
570
- }
571
- }
572
- if end == start {
573
- search_from = start;
574
- continue;
575
- }
576
- text.replace_range(start..end, "<UID>");
577
- search_from = start + "<UID>".len();
578
- }
579
- text
580
- }
581
-
582
- fn normalize_socket_token(text: &str) -> String {
583
- const CONTEXT: &str = "/tmux-<UID>/";
584
- let mut out = String::with_capacity(text.len());
585
- let mut search_from = 0;
586
- while let Some(offset) = text[search_from..].find(CONTEXT) {
587
- let context_start = search_from + offset;
588
- let token_start = context_start + CONTEXT.len();
589
- if !text[token_start..].starts_with("ta-") {
590
- out.push_str(&text[search_from..token_start]);
591
- search_from = token_start;
592
- continue;
593
- }
594
- let end = text[token_start..]
595
- .find(|c: char| !(c.is_ascii_alphanumeric() || c == '-'))
596
- .map(|offset| token_start + offset)
597
- .unwrap_or_else(|| text.len());
598
- if end == token_start + 3 {
599
- out.push_str(&text[search_from..end]);
600
- search_from = end;
601
- continue;
602
- }
603
- out.push_str(&text[search_from..token_start]);
604
- out.push_str("ta-<SOCKET>");
605
- search_from = end;
606
- }
607
- out.push_str(&text[search_from..]);
608
- out
609
- }
610
-
611
- fn key_is_timestamp(key: &str) -> bool {
612
- key == "ts" || key.ends_with("_at") || key.contains("timestamp")
613
- }
614
-
615
- fn key_is_pid_or_duration(key: Option<&str>) -> bool {
616
- let Some(key) = key else {
617
- return false;
618
- };
619
- key.contains("pid")
620
- || key.ends_with("_ms")
621
- || key.contains("duration")
622
- || key.contains("elapsed")
623
- }
624
-
625
- fn key_contains_path(key: &str) -> bool {
626
- key.contains("path")
627
- || key.contains("workspace")
628
- || key.contains("file")
629
- || key.contains("socket")
630
- || key.contains("endpoint")
631
- || key == "log"
632
- }
633
-
634
- fn key_is_id(key: &str, text: &str) -> bool {
635
- key == "message_id"
636
- || key == "result_id"
637
- || key == "watcher_id"
638
- || key.ends_with("_message_id")
639
- || key.ends_with("_result_id")
640
- || text.starts_with("msg_")
641
- }
642
-
643
- #[test]
644
- fn phase_golden_normalizer_maps_custom_cargo_target_deps_binary_before_tmp_aliasing() {
645
- let ctx = NormalizeCtx {
646
- workspace_aliases: Vec::new(),
647
- temp_aliases: vec!["/Volumes/nvme/tmp".to_string()],
648
- pane_ids: BTreeMap::new(),
649
- };
650
- let input = concat!(
651
- "mcp_servers.team_orchestrator.command=\"",
652
- "/Volumes/nvme/tmp/ta-0517-target/debug/deps/team_agent-c924abc123",
653
- "\""
654
- );
655
-
656
- assert_eq!(
657
- normalize_path_string(input, &ctx),
658
- "mcp_servers.team_orchestrator.command=\"<TEAM_AGENT_BIN>\"",
659
- "custom CARGO_TARGET_DIR binary paths must normalize to <TEAM_AGENT_BIN> before tmp/socket tokenization"
660
- );
661
- }
662
-
663
- #[test]
664
- fn phase_golden_normalizer_maps_current_test_binary_to_team_agent_marker() {
665
- let ctx = NormalizeCtx {
666
- workspace_aliases: Vec::new(),
667
- temp_aliases: vec!["/Volumes/nvme/tmp".to_string()],
668
- pane_ids: BTreeMap::new(),
669
- };
670
- let input = format!(
671
- "mcp_servers.team_orchestrator.command=\"{}\"",
672
- std::env::current_exe()
673
- .expect("current test binary path")
674
- .display()
675
- );
676
-
677
- assert_eq!(
678
- normalize_path_string(&input, &ctx),
679
- "mcp_servers.team_orchestrator.command=\"<TEAM_AGENT_BIN>\"",
680
- "actual test argv0/current_exe path must normalize to <TEAM_AGENT_BIN>"
681
- );
682
- }
683
-
684
- #[test]
685
- fn phase_golden_normalizer_does_not_treat_cargo_target_dir_as_socket_token() {
686
- let ctx = NormalizeCtx {
687
- workspace_aliases: Vec::new(),
688
- temp_aliases: vec!["/Volumes/nvme/tmp".to_string()],
689
- pane_ids: BTreeMap::new(),
690
- };
691
-
692
- assert_eq!(
693
- normalize_path_string("/Volumes/nvme/tmp/ta-0517-target/build.log", &ctx),
694
- "<TMP>/ta-0517-target/build.log",
695
- "ta-* directory names outside tmux socket context must not be rewritten as ta-<SOCKET>"
696
- );
697
- assert_eq!(
698
- normalize_path_string("tmux -S /tmp/tmux-501/ta-a60d10b25edd attach", &ctx),
699
- "tmux -S <TMP>/tmux-<UID>/ta-<SOCKET> attach",
700
- "real tmux socket paths still need stable socket tokenization"
701
- );
702
- }
703
-
704
- #[test]
705
- fn phase_golden_normalizer_maps_current_version_by_value_only() {
706
- let mut ctx = NormalizeCtx {
707
- workspace_aliases: Vec::new(),
708
- temp_aliases: Vec::new(),
709
- pane_ids: BTreeMap::new(),
710
- };
711
- let current = crate::packaging::Version::current().as_str().to_string();
712
-
713
- assert_eq!(
714
- normalize_string(current.clone(), &mut ctx, Some("arbitrary_field")),
715
- json!("<VERSION>"),
716
- "current binary version values must normalize without depending on field names"
717
- );
718
- assert_eq!(
719
- normalize_string(format!("version={current}"), &mut ctx, Some("binary_version")),
720
- json!(format!("version={current}")),
721
- "version normalization must be exact-value based, not a broad substring or field-name rewrite"
722
- );
723
- }