@team-agent/installer 0.5.128 → 0.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (436) hide show
  1. package/README.md +4 -4
  2. package/README.zh.md +1 -1
  3. package/package.json +4 -8
  4. package/skills/team-agent/SKILL.md +37 -20
  5. package/skills/team-agent/command-coverage.json +169 -183
  6. package/skills/team-agent/docs/reference/team-agent-operator.md +64 -30
  7. package/skills/team-agent/references/recovery-runbook.md +1 -1
  8. package/skills/team-agent/references/team-agent-operator.md +64 -30
  9. package/templates/team_state.md +1 -1
  10. package/Cargo.lock +0 -1063
  11. package/Cargo.toml +0 -36
  12. package/crates/team-agent/Cargo.toml +0 -69
  13. package/crates/team-agent/src/app_server_test_support.rs +0 -258
  14. package/crates/team-agent/src/cli/adapters.rs +0 -1288
  15. package/crates/team-agent/src/cli/arguments.rs +0 -405
  16. package/crates/team-agent/src/cli/attach_app_server_leader.rs +0 -98
  17. package/crates/team-agent/src/cli/diagnose.rs +0 -1721
  18. package/crates/team-agent/src/cli/emit.rs +0 -2930
  19. package/crates/team-agent/src/cli/grok_slot.rs +0 -384
  20. package/crates/team-agent/src/cli/helpers.rs +0 -91
  21. package/crates/team-agent/src/cli/intent/runtime.rs +0 -1216
  22. package/crates/team-agent/src/cli/intent/runtime_tests.rs +0 -912
  23. package/crates/team-agent/src/cli/intent/tests.rs +0 -689
  24. package/crates/team-agent/src/cli/intent.rs +0 -664
  25. package/crates/team-agent/src/cli/leader.rs +0 -300
  26. package/crates/team-agent/src/cli/leader_prompt.rs +0 -261
  27. package/crates/team-agent/src/cli/leaders.rs +0 -418
  28. package/crates/team-agent/src/cli/mod.rs +0 -6545
  29. package/crates/team-agent/src/cli/models.rs +0 -1206
  30. package/crates/team-agent/src/cli/named_address.rs +0 -1651
  31. package/crates/team-agent/src/cli/profile.rs +0 -342
  32. package/crates/team-agent/src/cli/route.rs +0 -212
  33. package/crates/team-agent/src/cli/schedule.rs +0 -175
  34. package/crates/team-agent/src/cli/send/coordinator.rs +0 -164
  35. package/crates/team-agent/src/cli/send/mailbox.rs +0 -145
  36. package/crates/team-agent/src/cli/send/persist.rs +0 -156
  37. package/crates/team-agent/src/cli/send/presentation.rs +0 -370
  38. package/crates/team-agent/src/cli/send/resolve.rs +0 -573
  39. package/crates/team-agent/src/cli/send.rs +0 -199
  40. package/crates/team-agent/src/cli/shutdown_socket.rs +0 -288
  41. package/crates/team-agent/src/cli/spec.rs +0 -165
  42. package/crates/team-agent/src/cli/status.rs +0 -280
  43. package/crates/team-agent/src/cli/status_port/agents.rs +0 -358
  44. package/crates/team-agent/src/cli/status_port/approvals.rs +0 -79
  45. package/crates/team-agent/src/cli/status_port/brief.rs +0 -1981
  46. package/crates/team-agent/src/cli/status_port/compact.rs +0 -240
  47. package/crates/team-agent/src/cli/status_port/format.rs +0 -146
  48. package/crates/team-agent/src/cli/status_port/inbox.rs +0 -62
  49. package/crates/team-agent/src/cli/status_port/runtime.rs +0 -197
  50. package/crates/team-agent/src/cli/status_port/snapshot.rs +0 -208
  51. package/crates/team-agent/src/cli/status_port/store.rs +0 -416
  52. package/crates/team-agent/src/cli/status_port/tests.rs +0 -90
  53. package/crates/team-agent/src/cli/status_port.rs +0 -92
  54. package/crates/team-agent/src/cli/tests/base.rs +0 -885
  55. package/crates/team-agent/src/cli/tests/divergence.rs +0 -518
  56. package/crates/team-agent/src/cli/tests/lane_c.rs +0 -453
  57. package/crates/team-agent/src/cli/tests/leader_watch.rs +0 -322
  58. package/crates/team-agent/src/cli/tests/main_preserved.rs +0 -430
  59. package/crates/team-agent/src/cli/tests/missing_subcommands.rs +0 -336
  60. package/crates/team-agent/src/cli/tests/mod.rs +0 -137
  61. package/crates/team-agent/src/cli/tests/named_address.rs +0 -761
  62. package/crates/team-agent/src/cli/tests/parser_safety.rs +0 -383
  63. package/crates/team-agent/src/cli/tests/run_delegation.rs +0 -484
  64. package/crates/team-agent/src/cli/tests/shutdown_kill_plan.rs +0 -2179
  65. package/crates/team-agent/src/cli/tests/status_brief.rs +0 -1514
  66. package/crates/team-agent/src/cli/tests/status_send.rs +0 -888
  67. package/crates/team-agent/src/cli/tests/verb_install_skill.rs +0 -93
  68. package/crates/team-agent/src/cli/tests/verb_profile.rs +0 -392
  69. package/crates/team-agent/src/cli/triage.rs +0 -234
  70. package/crates/team-agent/src/cli/types.rs +0 -591
  71. package/crates/team-agent/src/codex_app_server.rs +0 -546
  72. package/crates/team-agent/src/communication_mode/mod.rs +0 -56
  73. package/crates/team-agent/src/compiler/tests.rs +0 -827
  74. package/crates/team-agent/src/compiler.rs +0 -890
  75. package/crates/team-agent/src/conpty/backend.rs +0 -829
  76. package/crates/team-agent/src/conpty/mod.rs +0 -33
  77. package/crates/team-agent/src/contract_runtime/backend.rs +0 -1744
  78. package/crates/team-agent/src/contract_runtime/commands.rs +0 -671
  79. package/crates/team-agent/src/contract_runtime/config.rs +0 -364
  80. package/crates/team-agent/src/contract_runtime/config_tests.rs +0 -76
  81. package/crates/team-agent/src/contract_runtime/discovery.rs +0 -449
  82. package/crates/team-agent/src/contract_runtime/fork.rs +0 -361
  83. package/crates/team-agent/src/contract_runtime/forward.rs +0 -288
  84. package/crates/team-agent/src/contract_runtime/framework.rs +0 -367
  85. package/crates/team-agent/src/contract_runtime/mcp.rs +0 -394
  86. package/crates/team-agent/src/contract_runtime/mod.rs +0 -17
  87. package/crates/team-agent/src/contract_runtime/prompt.rs +0 -216
  88. package/crates/team-agent/src/contract_runtime/pump.rs +0 -271
  89. package/crates/team-agent/src/contract_runtime/registry.rs +0 -553
  90. package/crates/team-agent/src/contract_runtime/workspace.rs +0 -228
  91. package/crates/team-agent/src/coordinator/backoff.rs +0 -741
  92. package/crates/team-agent/src/coordinator/conpty_shim.rs +0 -805
  93. package/crates/team-agent/src/coordinator/health.rs +0 -1185
  94. package/crates/team-agent/src/coordinator/mod.rs +0 -119
  95. package/crates/team-agent/src/coordinator/orphan.rs +0 -110
  96. package/crates/team-agent/src/coordinator/runtime_detectors.rs +0 -798
  97. package/crates/team-agent/src/coordinator/runtime_observation.rs +0 -84
  98. package/crates/team-agent/src/coordinator/steps/abnormal.rs +0 -2309
  99. package/crates/team-agent/src/coordinator/steps/delivery.rs +0 -15
  100. package/crates/team-agent/src/coordinator/steps/health_sync.rs +0 -15
  101. package/crates/team-agent/src/coordinator/steps/mod.rs +0 -126
  102. package/crates/team-agent/src/coordinator/steps/persist.rs +0 -15
  103. package/crates/team-agent/src/coordinator/steps/runtime_prompts.rs +0 -15
  104. package/crates/team-agent/src/coordinator/steps/session_gate.rs +0 -16
  105. package/crates/team-agent/src/coordinator/tests/a0_lostupdate.rs +0 -158
  106. package/crates/team-agent/src/coordinator/tests/abnormal.rs +0 -312
  107. package/crates/team-agent/src/coordinator/tests/api_error_recovery.rs +0 -300
  108. package/crates/team-agent/src/coordinator/tests/basics.rs +0 -211
  109. package/crates/team-agent/src/coordinator/tests/daemon.rs +0 -514
  110. package/crates/team-agent/src/coordinator/tests/energy.rs +0 -549
  111. package/crates/team-agent/src/coordinator/tests/health_sync.rs +0 -503
  112. package/crates/team-agent/src/coordinator/tests/main_preserved.rs +0 -186
  113. package/crates/team-agent/src/coordinator/tests/mod.rs +0 -295
  114. package/crates/team-agent/src/coordinator/tests/s3_bounded.rs +0 -207
  115. package/crates/team-agent/src/coordinator/tests/spine.rs +0 -308
  116. package/crates/team-agent/src/coordinator/tests/takeover.rs +0 -286
  117. package/crates/team-agent/src/coordinator/tests/tick_core.rs +0 -237
  118. package/crates/team-agent/src/coordinator/tick.rs +0 -3024
  119. package/crates/team-agent/src/coordinator/types.rs +0 -540
  120. package/crates/team-agent/src/db/agent_health_capture.rs +0 -126
  121. package/crates/team-agent/src/db/message_store.rs +0 -1527
  122. package/crates/team-agent/src/db/migration.rs +0 -984
  123. package/crates/team-agent/src/db/mod.rs +0 -26
  124. package/crates/team-agent/src/db/schema.rs +0 -663
  125. package/crates/team-agent/src/diagnose/comms.rs +0 -242
  126. package/crates/team-agent/src/diagnose/mod.rs +0 -44
  127. package/crates/team-agent/src/diagnose/orphans.rs +0 -889
  128. package/crates/team-agent/src/direct_delivery.rs +0 -368
  129. package/crates/team-agent/src/event_log.rs +0 -502
  130. package/crates/team-agent/src/fake_worker.rs +0 -303
  131. package/crates/team-agent/src/inbox_store.rs +0 -169
  132. package/crates/team-agent/src/kill_audit.rs +0 -106
  133. package/crates/team-agent/src/layout/manager.rs +0 -248
  134. package/crates/team-agent/src/layout/mod.rs +0 -36
  135. package/crates/team-agent/src/layout/overlay.rs +0 -134
  136. package/crates/team-agent/src/layout/placement.rs +0 -52
  137. package/crates/team-agent/src/layout/recovery.rs +0 -106
  138. package/crates/team-agent/src/layout/runtime_sessions.rs +0 -317
  139. package/crates/team-agent/src/layout/sessions.rs +0 -294
  140. package/crates/team-agent/src/layout/tmux_endpoint.rs +0 -165
  141. package/crates/team-agent/src/layout/worker_env.rs +0 -721
  142. package/crates/team-agent/src/layout/worker_window_helpers.rs +0 -37
  143. package/crates/team-agent/src/leader/helpers.rs +0 -178
  144. package/crates/team-agent/src/leader/incident.rs +0 -6
  145. package/crates/team-agent/src/leader/lease.rs +0 -3356
  146. package/crates/team-agent/src/leader/mod.rs +0 -104
  147. package/crates/team-agent/src/leader/owner_bind.rs +0 -400
  148. package/crates/team-agent/src/leader/prompt.rs +0 -905
  149. package/crates/team-agent/src/leader/provider_attribution.rs +0 -247
  150. package/crates/team-agent/src/leader/rediscover/tests.rs +0 -689
  151. package/crates/team-agent/src/leader/rediscover.rs +0 -1192
  152. package/crates/team-agent/src/leader/registry.rs +0 -888
  153. package/crates/team-agent/src/leader/start.rs +0 -4501
  154. package/crates/team-agent/src/leader/takeover.rs +0 -65
  155. package/crates/team-agent/src/leader/tests/basics.rs +0 -337
  156. package/crates/team-agent/src/leader/tests/byte_findings.rs +0 -355
  157. package/crates/team-agent/src/leader/tests/claim_leader_mailbox_flush_contract.rs +0 -544
  158. package/crates/team-agent/src/leader/tests/historical_inventory_upgrade_gate_red.rs +0 -624
  159. package/crates/team-agent/src/leader/tests/identity.rs +0 -465
  160. package/crates/team-agent/src/leader/tests/identity_session_names.rs +0 -42
  161. package/crates/team-agent/src/leader/tests/idle.rs +0 -113
  162. package/crates/team-agent/src/leader/tests/lease_api.rs +0 -520
  163. package/crates/team-agent/src/leader/tests/lease_claim.rs +0 -629
  164. package/crates/team-agent/src/leader/tests/mod.rs +0 -106
  165. package/crates/team-agent/src/leader/tests/prompt_contract.rs +0 -268
  166. package/crates/team-agent/src/leader/tests/rediscover.rs +0 -403
  167. package/crates/team-agent/src/leader/tests/rehomed_env.rs +0 -83
  168. package/crates/team-agent/src/leader/tests/team_in_team_state_scope_red.rs +0 -1273
  169. package/crates/team-agent/src/leader/tests/terminal_and_replay_vs_rerender_invariants_red.rs +0 -417
  170. package/crates/team-agent/src/leader/tests/wake_start_owner.rs +0 -168
  171. package/crates/team-agent/src/leader/types.rs +0 -534
  172. package/crates/team-agent/src/lib.rs +0 -147
  173. package/crates/team-agent/src/lifecycle/helpers.rs +0 -212
  174. package/crates/team-agent/src/lifecycle/launch/add_agent.rs +0 -881
  175. package/crates/team-agent/src/lifecycle/launch/add_agent_state.rs +0 -598
  176. package/crates/team-agent/src/lifecycle/launch/agent_state.rs +0 -332
  177. package/crates/team-agent/src/lifecycle/launch/clone_agent.rs +0 -204
  178. package/crates/team-agent/src/lifecycle/launch/fork_agent.rs +0 -107
  179. package/crates/team-agent/src/lifecycle/launch/fork_entry.rs +0 -144
  180. package/crates/team-agent/src/lifecycle/launch/identity.rs +0 -674
  181. package/crates/team-agent/src/lifecycle/launch/layout.rs +0 -350
  182. package/crates/team-agent/src/lifecycle/launch/leader_context.rs +0 -589
  183. package/crates/team-agent/src/lifecycle/launch/mcp_config.rs +0 -160
  184. package/crates/team-agent/src/lifecycle/launch/ownership.rs +0 -105
  185. package/crates/team-agent/src/lifecycle/launch/pi_mcp.rs +0 -899
  186. package/crates/team-agent/src/lifecycle/launch/pi_mcp_extension.js +0 -225
  187. package/crates/team-agent/src/lifecycle/launch/plan.rs +0 -269
  188. package/crates/team-agent/src/lifecycle/launch/quick_start.rs +0 -5200
  189. package/crates/team-agent/src/lifecycle/launch/quick_start_transport.rs +0 -368
  190. package/crates/team-agent/src/lifecycle/launch/readiness.rs +0 -519
  191. package/crates/team-agent/src/lifecycle/launch/role_source.rs +0 -287
  192. package/crates/team-agent/src/lifecycle/launch/spawn.rs +0 -473
  193. package/crates/team-agent/src/lifecycle/launch/spec_state.rs +0 -801
  194. package/crates/team-agent/src/lifecycle/launch/state_projection.rs +0 -624
  195. package/crates/team-agent/src/lifecycle/launch/worker_env.rs +0 -558
  196. package/crates/team-agent/src/lifecycle/launch.rs +0 -557
  197. package/crates/team-agent/src/lifecycle/lock.rs +0 -350
  198. package/crates/team-agent/src/lifecycle/mod.rs +0 -79
  199. package/crates/team-agent/src/lifecycle/pane_input_lock.rs +0 -239
  200. package/crates/team-agent/src/lifecycle/profile_launch.rs +0 -1067
  201. package/crates/team-agent/src/lifecycle/profile_smoke.rs +0 -557
  202. package/crates/team-agent/src/lifecycle/restart/agent.rs +0 -2199
  203. package/crates/team-agent/src/lifecycle/restart/avatar.rs +0 -1798
  204. package/crates/team-agent/src/lifecycle/restart/claude_fork.rs +0 -163
  205. package/crates/team-agent/src/lifecycle/restart/common.rs +0 -2362
  206. package/crates/team-agent/src/lifecycle/restart/orchestrator.rs +0 -65
  207. package/crates/team-agent/src/lifecycle/restart/preflight.rs +0 -113
  208. package/crates/team-agent/src/lifecycle/restart/rebuild.rs +0 -5135
  209. package/crates/team-agent/src/lifecycle/restart/remove.rs +0 -1504
  210. package/crates/team-agent/src/lifecycle/restart/selection.rs +0 -559
  211. package/crates/team-agent/src/lifecycle/restart/team_state.rs +0 -329
  212. package/crates/team-agent/src/lifecycle/restart.rs +0 -227
  213. package/crates/team-agent/src/lifecycle/role_config.rs +0 -1230
  214. package/crates/team-agent/src/lifecycle/tests/acceptance_b_batch_red.rs +0 -1021
  215. package/crates/team-agent/src/lifecycle/tests/agent_ops.rs +0 -1205
  216. package/crates/team-agent/src/lifecycle/tests/b0_legacy_snapshot_nonauthority_contract.rs +0 -265
  217. package/crates/team-agent/src/lifecycle/tests/b0_reader_hideone_audit_contract.rs +0 -490
  218. package/crates/team-agent/src/lifecycle/tests/behavioral_diff_264_red.rs +0 -656
  219. package/crates/team-agent/src/lifecycle/tests/claude_compatible_config_red.rs +0 -325
  220. package/crates/team-agent/src/lifecycle/tests/claude_profile_launch_red.rs +0 -447
  221. package/crates/team-agent/src/lifecycle/tests/cli_argv_routing_red.rs +0 -1638
  222. package/crates/team-agent/src/lifecycle/tests/clone_agent_preserves_source_tools.rs +0 -427
  223. package/crates/team-agent/src/lifecycle/tests/clone_fork_copilot_perms_red.rs +0 -770
  224. package/crates/team-agent/src/lifecycle/tests/communication_mode_runtime_contract_red.rs +0 -419
  225. package/crates/team-agent/src/lifecycle/tests/copilot_provider_red.rs +0 -2035
  226. package/crates/team-agent/src/lifecycle/tests/core.rs +0 -1327
  227. package/crates/team-agent/src/lifecycle/tests/f032_startup_prompt_best_effort_red.rs +0 -315
  228. package/crates/team-agent/src/lifecycle/tests/fixtures/pi_list_models_g0.stdout.txt +0 -222
  229. package/crates/team-agent/src/lifecycle/tests/fixtures/pi_list_models_spaced_ids.stdout.txt +0 -9
  230. package/crates/team-agent/src/lifecycle/tests/fixtures/pi_native_mcp_host.mjs +0 -72
  231. package/crates/team-agent/src/lifecycle/tests/gate_fixtures.rs +0 -562
  232. package/crates/team-agent/src/lifecycle/tests/grok_require_explicit_model_red.rs +0 -110
  233. package/crates/team-agent/src/lifecycle/tests/harvest2_a_batch_red.rs +0 -512
  234. package/crates/team-agent/src/lifecycle/tests/host_cotenant_death_p0_contract.rs +0 -921
  235. package/crates/team-agent/src/lifecycle/tests/issue238_codex_effort_contract.rs +0 -68
  236. package/crates/team-agent/src/lifecycle/tests/lane_ops.rs +0 -1851
  237. package/crates/team-agent/src/lifecycle/tests/launch_spawn.rs +0 -3983
  238. package/crates/team-agent/src/lifecycle/tests/lifecycle_lock.rs +0 -339
  239. package/crates/team-agent/src/lifecycle/tests/lifecycle_rollback_red.rs +0 -596
  240. package/crates/team-agent/src/lifecycle/tests/main_preserved.rs +0 -513
  241. package/crates/team-agent/src/lifecycle/tests/mcp_tool_name_format_red.rs +0 -69
  242. package/crates/team-agent/src/lifecycle/tests/phase_b_contracts.rs +0 -824
  243. package/crates/team-agent/src/lifecycle/tests/phase_golden.rs +0 -723
  244. package/crates/team-agent/src/lifecycle/tests/pi_catalog_red.rs +0 -164
  245. package/crates/team-agent/src/lifecycle/tests/pi_command_red.rs +0 -200
  246. package/crates/team-agent/src/lifecycle/tests/pi_compiler_red.rs +0 -210
  247. package/crates/team-agent/src/lifecycle/tests/pi_dual_entry_red.rs +0 -527
  248. package/crates/team-agent/src/lifecycle/tests/pi_executable_mcp_red.rs +0 -1062
  249. package/crates/team-agent/src/lifecycle/tests/pi_fork_session_inheritance_red.rs +0 -1419
  250. package/crates/team-agent/src/lifecycle/tests/pi_lifecycle_doctor_red.rs +0 -98
  251. package/crates/team-agent/src/lifecycle/tests/pi_native_mcp_capability_red.rs +0 -550
  252. package/crates/team-agent/src/lifecycle/tests/pi_session_delivery_red.rs +0 -226
  253. package/crates/team-agent/src/lifecycle/tests/quick_start_worker_readiness_red.rs +0 -332
  254. package/crates/team-agent/src/lifecycle/tests/realmachine_clusters_1_6_red.rs +0 -786
  255. package/crates/team-agent/src/lifecycle/tests/realmachine_residual_g1_g4_red.rs +0 -648
  256. package/crates/team-agent/src/lifecycle/tests/restart.rs +0 -185
  257. package/crates/team-agent/src/lifecycle/tests/restart_build_before_destroy_0540_contract.rs +0 -1053
  258. package/crates/team-agent/src/lifecycle/tests/restart_liveness_red.rs +0 -679
  259. package/crates/team-agent/src/lifecycle/tests/restart_rebind_hotfix_252_red.rs +0 -1126
  260. package/crates/team-agent/src/lifecycle/tests/restart_session_capture_red.rs +0 -153
  261. package/crates/team-agent/src/lifecycle/tests/resume_recover_red.rs +0 -427
  262. package/crates/team-agent/src/lifecycle/tests/stale_team_saveconflict_contract.rs +0 -431
  263. package/crates/team-agent/src/lifecycle/tests/startup_latency_contract.rs +0 -1066
  264. package/crates/team-agent/src/lifecycle/tests/status_credential_redaction_contract.rs +0 -876
  265. package/crates/team-agent/src/lifecycle/tests/subprep_codex_trust_roundtrip_red.rs +0 -1026
  266. package/crates/team-agent/src/lifecycle/tests/swallow_batch4_semantics_red.rs +0 -342
  267. package/crates/team-agent/src/lifecycle/tests/team_in_team_identity_scope_red.rs +0 -543
  268. package/crates/team-agent/src/lifecycle/tests/team_in_team_sibling_quick_start_red.rs +0 -1103
  269. package/crates/team-agent/src/lifecycle/tests/team_in_team_state_scope_red.rs +0 -1276
  270. package/crates/team-agent/src/lifecycle/tests/team_key_retirement_roster_red.rs +0 -145
  271. package/crates/team-agent/src/lifecycle/tests/team_key_retirement_txn_red.rs +0 -603
  272. package/crates/team-agent/src/lifecycle/tests/test_isolation_escape_contract.rs +0 -936
  273. package/crates/team-agent/src/lifecycle/tests/upgrade_compat_0211_red.rs +0 -970
  274. package/crates/team-agent/src/lifecycle/tests/verify_rs031_window_consistency_red.rs +0 -995
  275. package/crates/team-agent/src/lifecycle/tests/worker_spawn_env_red.rs +0 -836
  276. package/crates/team-agent/src/lifecycle/tests.rs +0 -105
  277. package/crates/team-agent/src/lifecycle/types.rs +0 -877
  278. package/crates/team-agent/src/lifecycle/worker_command_context.rs +0 -363
  279. package/crates/team-agent/src/main.rs +0 -52
  280. package/crates/team-agent/src/mcp_server/helpers.rs +0 -510
  281. package/crates/team-agent/src/mcp_server/lifecycle_tools/mod.rs +0 -6
  282. package/crates/team-agent/src/mcp_server/lifecycle_tools/state_status.rs +0 -43
  283. package/crates/team-agent/src/mcp_server/mod.rs +0 -119
  284. package/crates/team-agent/src/mcp_server/normalize.rs +0 -485
  285. package/crates/team-agent/src/mcp_server/readiness.rs +0 -527
  286. package/crates/team-agent/src/mcp_server/readiness_tests.rs +0 -348
  287. package/crates/team-agent/src/mcp_server/tests/golden.rs +0 -285
  288. package/crates/team-agent/src/mcp_server/tests/normalize.rs +0 -247
  289. package/crates/team-agent/src/mcp_server/tests/scoped.rs +0 -158
  290. package/crates/team-agent/src/mcp_server/tests/send.rs +0 -353
  291. package/crates/team-agent/src/mcp_server/tests/tools.rs +0 -341
  292. package/crates/team-agent/src/mcp_server/tests/wire.rs +0 -254
  293. package/crates/team-agent/src/mcp_server/tests.rs +0 -43
  294. package/crates/team-agent/src/mcp_server/tools.rs +0 -889
  295. package/crates/team-agent/src/mcp_server/types.rs +0 -396
  296. package/crates/team-agent/src/mcp_server/wire.rs +0 -867
  297. package/crates/team-agent/src/messaging/activity.rs +0 -461
  298. package/crates/team-agent/src/messaging/address.rs +0 -87
  299. package/crates/team-agent/src/messaging/delivery.rs +0 -3727
  300. package/crates/team-agent/src/messaging/delivery_consumption_tests.rs +0 -234
  301. package/crates/team-agent/src/messaging/enter_rescue.rs +0 -362
  302. package/crates/team-agent/src/messaging/enter_rescue_tests.rs +0 -633
  303. package/crates/team-agent/src/messaging/helpers.rs +0 -336
  304. package/crates/team-agent/src/messaging/leader_channel.rs +0 -287
  305. package/crates/team-agent/src/messaging/leader_receiver.rs +0 -786
  306. package/crates/team-agent/src/messaging/mod.rs +0 -167
  307. package/crates/team-agent/src/messaging/persist.rs +0 -377
  308. package/crates/team-agent/src/messaging/presentation.rs +0 -417
  309. package/crates/team-agent/src/messaging/reminders.rs +0 -316
  310. package/crates/team-agent/src/messaging/results/collection_tests.rs +0 -719
  311. package/crates/team-agent/src/messaging/results.rs +0 -1415
  312. package/crates/team-agent/src/messaging/scheduler.rs +0 -223
  313. package/crates/team-agent/src/messaging/selftest.rs +0 -315
  314. package/crates/team-agent/src/messaging/send.rs +0 -981
  315. package/crates/team-agent/src/messaging/tests/basic.rs +0 -346
  316. package/crates/team-agent/src/messaging/tests/dup_inject.rs +0 -657
  317. package/crates/team-agent/src/messaging/tests/e23.rs +0 -49
  318. package/crates/team-agent/src/messaging/tests/leader_channel.rs +0 -169
  319. package/crates/team-agent/src/messaging/tests/leader_inject_acceptance.rs +0 -817
  320. package/crates/team-agent/src/messaging/tests/main_preserved.rs +0 -85
  321. package/crates/team-agent/src/messaging/tests/mod.rs +0 -306
  322. package/crates/team-agent/src/messaging/tests/runtime.rs +0 -3549
  323. package/crates/team-agent/src/messaging/tests/spine.rs +0 -853
  324. package/crates/team-agent/src/messaging/tests/wave2.rs +0 -381
  325. package/crates/team-agent/src/messaging/trust.rs +0 -215
  326. package/crates/team-agent/src/messaging/types.rs +0 -472
  327. package/crates/team-agent/src/messaging/wait.rs +0 -366
  328. package/crates/team-agent/src/messaging/watchers.rs +0 -916
  329. package/crates/team-agent/src/model/enums.rs +0 -356
  330. package/crates/team-agent/src/model/errors.rs +0 -18
  331. package/crates/team-agent/src/model/ids.rs +0 -165
  332. package/crates/team-agent/src/model/mod.rs +0 -29
  333. package/crates/team-agent/src/model/name_similarity.rs +0 -252
  334. package/crates/team-agent/src/model/pane_authority_refusal.rs +0 -359
  335. package/crates/team-agent/src/model/paths.rs +0 -257
  336. package/crates/team-agent/src/model/routing.rs +0 -387
  337. package/crates/team-agent/src/model/spec.rs +0 -1184
  338. package/crates/team-agent/src/model/task_graph.rs +0 -321
  339. package/crates/team-agent/src/model/testdata/fuzz.golden.yaml +0 -43
  340. package/crates/team-agent/src/model/testdata/fuzz.yaml +0 -43
  341. package/crates/team-agent/src/model/testdata/spec_invalid_a.yaml +0 -209
  342. package/crates/team-agent/src/model/testdata/team.spec.golden.yaml +0 -208
  343. package/crates/team-agent/src/model/testdata/team.spec.yaml +0 -208
  344. package/crates/team-agent/src/model/yaml/tests.rs +0 -188
  345. package/crates/team-agent/src/model/yaml.rs +0 -802
  346. package/crates/team-agent/src/os_probe.rs +0 -280
  347. package/crates/team-agent/src/packaging/install.rs +0 -219
  348. package/crates/team-agent/src/packaging/migrate.rs +0 -38
  349. package/crates/team-agent/src/packaging/mod.rs +0 -91
  350. package/crates/team-agent/src/packaging/repair.rs +0 -33
  351. package/crates/team-agent/src/packaging/tests.rs +0 -822
  352. package/crates/team-agent/src/packaging/types.rs +0 -417
  353. package/crates/team-agent/src/platform/argv.rs +0 -331
  354. package/crates/team-agent/src/platform/errors.rs +0 -104
  355. package/crates/team-agent/src/platform/file_lock.rs +0 -279
  356. package/crates/team-agent/src/platform/mod.rs +0 -5
  357. package/crates/team-agent/src/platform/process.rs +0 -545
  358. package/crates/team-agent/src/provider/adapter.rs +0 -1150
  359. package/crates/team-agent/src/provider/adapters/claude.rs +0 -78
  360. package/crates/team-agent/src/provider/adapters/claude_fork.rs +0 -131
  361. package/crates/team-agent/src/provider/adapters/copilot.rs +0 -75
  362. package/crates/team-agent/src/provider/adapters/copilot_fork.rs +0 -307
  363. package/crates/team-agent/src/provider/adapters/fake.rs +0 -18
  364. package/crates/team-agent/src/provider/adapters/mod.rs +0 -30
  365. package/crates/team-agent/src/provider/adapters/pi.rs +0 -106
  366. package/crates/team-agent/src/provider/approvals/mod.rs +0 -3
  367. package/crates/team-agent/src/provider/approvals/parsing.rs +0 -586
  368. package/crates/team-agent/src/provider/approvals/runtime_prompts.rs +0 -205
  369. package/crates/team-agent/src/provider/argv_route.rs +0 -405
  370. package/crates/team-agent/src/provider/bypass_flags.rs +0 -116
  371. package/crates/team-agent/src/provider/classify.rs +0 -708
  372. package/crates/team-agent/src/provider/command_helpers.rs +0 -45
  373. package/crates/team-agent/src/provider/faults.rs +0 -165
  374. package/crates/team-agent/src/provider/helpers.rs +0 -52
  375. package/crates/team-agent/src/provider/mod.rs +0 -78
  376. package/crates/team-agent/src/provider/model_catalog.rs +0 -910
  377. package/crates/team-agent/src/provider/session/capture.rs +0 -2731
  378. package/crates/team-agent/src/provider/session/context_fork/claude.rs +0 -123
  379. package/crates/team-agent/src/provider/session/context_fork/outcome.rs +0 -172
  380. package/crates/team-agent/src/provider/session/context_fork.rs +0 -396
  381. package/crates/team-agent/src/provider/session/mod.rs +0 -36
  382. package/crates/team-agent/src/provider/session/resume.rs +0 -269
  383. package/crates/team-agent/src/provider/session_scan/claude.rs +0 -523
  384. package/crates/team-agent/src/provider/session_scan/common/tests.rs +0 -316
  385. package/crates/team-agent/src/provider/session_scan/common.rs +0 -654
  386. package/crates/team-agent/src/provider/session_scan/copilot.rs +0 -280
  387. package/crates/team-agent/src/provider/session_scan/pi.rs +0 -185
  388. package/crates/team-agent/src/provider/session_scan.rs +0 -71
  389. package/crates/team-agent/src/provider/startup_prompt.rs +0 -757
  390. package/crates/team-agent/src/provider/submit_now.rs +0 -71
  391. package/crates/team-agent/src/provider/testdata/copilot-ready-marker.txt +0 -5
  392. package/crates/team-agent/src/provider/testdata/copilot-trust-prompt.txt +0 -19
  393. package/crates/team-agent/src/provider/testdata/grok-models-authenticated.stdout +0 -9
  394. package/crates/team-agent/src/provider/testdata/grok-models-unauthenticated.stdout +0 -7
  395. package/crates/team-agent/src/provider/tests/adapter.rs +0 -441
  396. package/crates/team-agent/src/provider/tests/classify.rs +0 -148
  397. package/crates/team-agent/src/provider/tests/command_helpers.rs +0 -35
  398. package/crates/team-agent/src/provider/tests/copilot_fork.rs +0 -191
  399. package/crates/team-agent/src/provider/tests/faults.rs +0 -200
  400. package/crates/team-agent/src/provider/tests/idle.rs +0 -177
  401. package/crates/team-agent/src/provider/tests/wire.rs +0 -213
  402. package/crates/team-agent/src/provider/tests.rs +0 -32
  403. package/crates/team-agent/src/provider/types.rs +0 -529
  404. package/crates/team-agent/src/provider/wire.rs +0 -394
  405. package/crates/team-agent/src/redaction.rs +0 -259
  406. package/crates/team-agent/src/state/abnormal_watch/tests/mod.rs +0 -248
  407. package/crates/team-agent/src/state/abnormal_watch.rs +0 -144
  408. package/crates/team-agent/src/state/identity.rs +0 -914
  409. package/crates/team-agent/src/state/identity_keys.rs +0 -132
  410. package/crates/team-agent/src/state/mod.rs +0 -74
  411. package/crates/team-agent/src/state/owner_gate.rs +0 -482
  412. package/crates/team-agent/src/state/ownership.rs +0 -563
  413. package/crates/team-agent/src/state/paths.rs +0 -395
  414. package/crates/team-agent/src/state/persist.rs +0 -3811
  415. package/crates/team-agent/src/state/projection.rs +0 -1508
  416. package/crates/team-agent/src/state/repository/intent.rs +0 -14
  417. package/crates/team-agent/src/state/repository/tests.rs +0 -184
  418. package/crates/team-agent/src/state/repository.rs +0 -866
  419. package/crates/team-agent/src/state/selector.rs +0 -160
  420. package/crates/team-agent/src/state/testdata/state-rich.canonical.json +0 -133
  421. package/crates/team-agent/src/test_support/models_timeout_fixture.rs +0 -144
  422. package/crates/team-agent/src/tmux_backend/enter_rescue.rs +0 -325
  423. package/crates/team-agent/src/tmux_backend/enter_rescue_tests.rs +0 -432
  424. package/crates/team-agent/src/tmux_backend/native_input.rs +0 -513
  425. package/crates/team-agent/src/tmux_backend/native_input_tests.rs +0 -742
  426. package/crates/team-agent/src/tmux_backend/tests.rs +0 -4103
  427. package/crates/team-agent/src/tmux_backend.rs +0 -4492
  428. package/crates/team-agent/src/topology.rs +0 -537
  429. package/crates/team-agent/src/transport/enter_rescue.rs +0 -166
  430. package/crates/team-agent/src/transport/native_input.rs +0 -491
  431. package/crates/team-agent/src/transport/test_support.rs +0 -743
  432. package/crates/team-agent/src/transport/tests/behavior.rs +0 -326
  433. package/crates/team-agent/src/transport/tests/mod.rs +0 -194
  434. package/crates/team-agent/src/transport/tests/wire.rs +0 -574
  435. package/crates/team-agent/src/transport.rs +0 -1655
  436. package/crates/team-agent/src/transport_factory.rs +0 -819
@@ -1,482 +0,0 @@
1
- //!
2
- //! owner-gate:trust own-vs-foreign(§11 / bug-064 / bug-082 血泪;真相源 `state.py`)。
3
- //!
4
- //! 三核心纯判定(集成 send_message/MCP 是 step 11/14):
5
- //! - `check_team_owner`:pane-id / uuid / **tmux-liveness** 身份门(pane-as-identity 模型)。
6
- //! liveness 依赖经 [`PaneLiveness`] trait 注入,真 tmux 探测延 step 9。
7
- //! - `apply_first_time_leader_binding` 的 **realpath own-vs-foreign**(`state.py:449`):
8
- //! `canonicalize(pane_cwd) == canonicalize(workspace)` —— **两边都 canonical 化**,这正是
9
- //! macOS `/tmp → /private/tmp` 软链不对称(0.2.11 真机抓出、单测漏掉的 bug)的正解。
10
- //! **禁 basename / startswith / 子串 / 反推 cwd**(§11)。
11
- //! - `worker_sender_bypasses_owner_gate`:worker peer-send 绕过 owner 门(sender 白名单 + env 一致)。
12
- //!
13
- //! own→自动答(本地 tmux 机械动作,MUST-NOT-13 零 provider 调用)+ trust 截断匹配是 **step 11**
14
- //! messaging delivery(`attempt_trust_auto_answer` / `_tmux_pane_width`),不在此 slice。
15
- //!
16
- //! §10:纯判定无 unwrap/expect/panic;realpath 比对 canonicalize 失败时退化为词法绝对路径比较。
17
-
18
- use std::path::Path;
19
-
20
- use serde_json::{json, Value};
21
-
22
- use crate::model::enums::PaneLiveness;
23
-
24
- /// tmux pane 存活探测(`state.py:_tmux_pane_liveness`)。真实现走 tmux(step 9 transport);
25
- /// owner-gate 单测用 mock 注入。
26
- pub trait PaneLivenessProbe {
27
- fn liveness(&self, pane_id: &str) -> PaneLiveness;
28
- }
29
-
30
- /// 调用方身份(`_caller_identity_from_env` 的产物;此处作为注入参数保持判定纯净)。
31
- #[derive(Debug, Clone, Default)]
32
- pub struct CallerIdentity {
33
- pub pane_id: String,
34
- pub provider: String,
35
- pub machine_fingerprint: String,
36
- pub leader_session_uuid: String,
37
- /// `explicit-override` | `env` | `derived`(Python caller dict 的第 5 字段)。
38
- pub leader_session_uuid_source: String,
39
- }
40
-
41
- ///
42
- /// `check_team_owner`(`state.py:366`)的纯判定版:caller 身份 + 是否有 TEAM_AGENT_ID + liveness 注入。
43
- /// 返回 `None`=允许(own / 无 owner / 死 owner pane 可接管);`Some(dict)`=拒绝(team_owner_mismatch)。
44
- ///
45
- /// Stage 2 (identity-boundary unified plan, architect direction 2026-06-23):
46
- /// the owner is now looked up through `state::ownership::read_owner_value`
47
- /// instead of `state::projection::read_owner` directly. The two are
48
- /// equivalent today for the gate's `None` (empty team_key) path — both
49
- /// resolve to top-level `state.team_owner` — but routing through the
50
- /// repository means Stage 5 can swap the data source (per-team canonical
51
- /// `state.json`) without touching this gate. The empty-team-key argument
52
- /// preserves the pre-Stage-2 shape: gate callers feed an
53
- /// already-team-projected state and expect top-level reads.
54
- pub fn check_team_owner(
55
- state: &Value,
56
- caller: &CallerIdentity,
57
- has_team_agent_id: bool,
58
- liveness: &dyn PaneLivenessProbe,
59
- ) -> Option<Value> {
60
- let owner = crate::state::ownership::read_owner_value(state, "")?;
61
- if !owner.is_object() || owner.as_object().is_none_or(serde_json::Map::is_empty) {
62
- return None;
63
- }
64
- let owner_uuid = owner
65
- .get("leader_session_uuid")
66
- .and_then(Value::as_str)
67
- .unwrap_or("");
68
- let owner_pane = owner.get("pane_id").and_then(Value::as_str).unwrap_or("");
69
- let caller_uuid = caller.leader_session_uuid.as_str();
70
- let caller_pane = caller.pane_id.as_str();
71
-
72
- // 同 pane → own。
73
- if !caller_pane.is_empty() && caller_pane == owner_pane {
74
- return None;
75
- }
76
- // 死 owner pane + 新 live caller(非 worker)→ 接管(pane-as-identity:死 pane 不锁活 caller)。
77
- if !caller_pane.is_empty()
78
- && !has_team_agent_id
79
- && !owner_pane.is_empty()
80
- && liveness.liveness(owner_pane) != PaneLiveness::Live
81
- {
82
- return None;
83
- }
84
- // 同 uuid 且(无 caller_pane 或同 pane)→ own。
85
- // 安全守卫(对抗 P0-A):**两边非空**才算同 uuid —— 堵住 owner_uuid=="" && caller_uuid=="" 的
86
- // "" == "" allow-flip(否则缺 uuid 的 owner 会把外来空-uuid caller 误判为 own)。
87
- // 注(对抗 verifier 确认的 P2 parity gap,安全侧):Python check_team_owner 开头调
88
- // _migrate_team_identity 把缺 uuid 的 owner 填成 derived(故其 owner_uuid 恒非空);该迁移需
89
- // env+workspace+可变 state,而本纯判定签名(`&Value` + 注入 liveness)尚不持有这些。
90
- // identity::migrate_team_identity 已实现,但 check_team_owner 的实际 caller(env/workspace 来源)
91
- // 在 step 11 messaging 才落地 —— 届时在此先 migrate owner identity 再判定,收口该 gap。
92
- // 在此之前本守卫**偏严**:缺-uuid owner + 同-identity 异-pane caller 会被判 takeover(Python 判
93
- // sticky/own)。**只过严不过松**(宁拒不误放),无安全洞。
94
- let same_uuid = !owner_uuid.is_empty() && !caller_uuid.is_empty() && caller_uuid == owner_uuid;
95
- if same_uuid && (caller_pane.is_empty() || caller_pane == owner_pane) {
96
- return None;
97
- }
98
- // 否则拒绝。reason_kind / action 按 same_uuid 分流(sticky_bind vs takeover)。
99
- let (reason_kind, action) = if same_uuid {
100
- ("sticky_bind_collision", "team-agent claim-leader --confirm")
101
- } else {
102
- ("owner_takeover_required", "team-agent takeover --confirm")
103
- };
104
- // 键序对齐 Python dict 字面(preserve_order)。
105
- Some(json!({
106
- "ok": false,
107
- "status": "refused",
108
- "reason": "team_owner_mismatch",
109
- "reason_kind": reason_kind,
110
- "error": "not_owner",
111
- "action": action,
112
- "team_owner": owner.clone(),
113
- "caller": caller_to_value(caller),
114
- }))
115
- }
116
-
117
- fn caller_to_value(c: &CallerIdentity) -> Value {
118
- // 字段集对齐 Python `_caller_identity_from_env`(5 键含 leader_session_uuid_source)。
119
- json!({
120
- "pane_id": c.pane_id,
121
- "provider": c.provider,
122
- "machine_fingerprint": c.machine_fingerprint,
123
- "leader_session_uuid": c.leader_session_uuid,
124
- "leader_session_uuid_source": c.leader_session_uuid_source,
125
- })
126
- }
127
-
128
- ///
129
- /// `worker_sender_bypasses_owner_gate`(`state.py:400`):worker peer-send 绕过 owner 门。
130
- /// 返回 `Some(agent_id)`=绕过;`None`=不绕过(走 owner 门)。
131
- pub fn worker_sender_bypasses_owner_gate(
132
- state: &Value,
133
- sender: Option<&str>,
134
- env_agent_id: Option<&str>,
135
- ) -> Option<String> {
136
- let sender = sender.filter(|s| !s.is_empty())?;
137
- let leader_id = state
138
- .get("leader")
139
- .and_then(|l| l.get("id"))
140
- .and_then(Value::as_str)
141
- .filter(|s| !s.is_empty())
142
- .unwrap_or("leader");
143
- // leader 不绕过(走 owner 门)。
144
- if sender == leader_id || sender == "leader" || sender == "Leader" {
145
- return None;
146
- }
147
- // 必须是已注册 agent。
148
- let is_agent = state
149
- .get("agents")
150
- .and_then(Value::as_object)
151
- .is_some_and(|a| a.contains_key(sender));
152
- if !is_agent {
153
- return None;
154
- }
155
- // env TEAM_AGENT_ID 若存在必须与 sender 一致(防伪造)。
156
- let env_agent_id = env_agent_id.filter(|s| !s.is_empty());
157
- if let Some(env_id) = env_agent_id {
158
- if env_id != sender {
159
- return None;
160
- }
161
- return Some(env_id.to_string());
162
- }
163
- Some(sender.to_string())
164
- }
165
-
166
- ///
167
- /// §11 realpath own-vs-foreign(`state.py:449`):**两边 canonicalize** 后全等才判 own。
168
- /// macOS `/tmp → /private/tmp` 软链不对称由「两边 canonicalize」消除。canonicalize 失败(路径不存在)
169
- /// → 退化为词法绝对比较(此时无软链可解,等价)。**禁 basename/startswith/子串/反推**。
170
- ///
171
- /// **有意分歧(cr 裁决 2026-06-02,见 `contracts-rust-native.yaml` DECISIONS)**:Python 比的是
172
- /// 供给的路径**串**(FS-无关、恒大小写敏感),在 case-insensitive FS 上把同一目录的大小写变体误判
173
- /// 为 foreign(过严)。Rust 用 `canonicalize` 尊重 FS 真实大小写敏感性,两种 FS 下都正确:
174
- /// - case-insensitive FS(macOS APFS 默认 / Windows NTFS):`Workspace`==`workspace`(同 inode)→ own;
175
- /// - case-sensitive FS(Linux ext4 / case-sensitive APFS 卷):是两个目录 → foreign(与 Python 同)。
176
- ///
177
- /// 安全无洞:自己 workspace 的大小写变体本就是自己;runtime 用精确大小写启动 worker 不触发该场景;
178
- /// §11 红线仍守(只 realpath 后**全等**才判 own,绝不前缀/子串/反推)。
179
- /// 双 FS 正确性由 `tests::case_sensitivity_ruling_correct_on_both_fs` 运行时探测 FS 后各自钉死。
180
- pub fn workspace_paths_match(a: &Path, b: &Path) -> bool {
181
- realpath_like(a) == realpath_like(b)
182
- }
183
-
184
- fn lexical_abs(p: &Path) -> std::path::PathBuf {
185
- if p.is_absolute() {
186
- p.to_path_buf()
187
- } else {
188
- std::env::current_dir()
189
- .map(|cwd| cwd.join(p))
190
- .unwrap_or_else(|_| p.to_path_buf())
191
- }
192
- }
193
-
194
- ///
195
- /// `os.path.realpath` 等价(对抗 P0-B):全路径存在 → `canonicalize`;否则对**最长存在前缀**
196
- /// canonicalize(解析其软链)再拼回缺失末段(规范化 `..`/`.`)。这复刻 Python「解析存在部分的
197
- /// 软链 + 保留不存在末段」,修掉「父目录是软链 + 末段不存在 → 漏判 own」的 §11 血泪。
198
- pub(crate) fn realpath_like(p: &Path) -> std::path::PathBuf {
199
- use std::path::{Component, PathBuf};
200
- if let Ok(c) = std::fs::canonicalize(p) {
201
- return c; // 全路径存在(canonicalize 已解析所有软链 + 规范化 ..)
202
- }
203
- let abs = lexical_abs(p);
204
- let comps: Vec<Component> = abs.components().collect();
205
- // 从最长前缀往短试,找第一个可 canonicalize 的存在前缀。
206
- for split in (1..=comps.len()).rev() {
207
- let prefix: PathBuf = comps[..split].iter().collect();
208
- if prefix.as_os_str().is_empty() {
209
- continue;
210
- }
211
- if let Ok(canon) = std::fs::canonicalize(&prefix) {
212
- let mut result = canon;
213
- for comp in &comps[split..] {
214
- match comp {
215
- Component::ParentDir => {
216
- result.pop();
217
- }
218
- Component::Normal(n) => result.push(n),
219
- Component::CurDir => {}
220
- Component::RootDir | Component::Prefix(_) => {}
221
- }
222
- }
223
- return result;
224
- }
225
- }
226
- abs // 无任何存在前缀(极少)→ 词法绝对(已含 lexical 形)
227
- }
228
-
229
- // 注:`apply_first_time_leader_binding` 的 realpath+命令双门由 `identity::apply_first_time_leader_binding`
230
- // 字节对齐实现(含 `pane` 字段 + `repr()` 错误串)。早期此处曾有一个简化抽取 `first_time_binding_gate`
231
- // (拒绝串用 `{:?}` 非 repr、缺 `pane`/workspace 字段),与 Python 不对拍且无生产 caller —— 对抗 verifier
232
- // 确认为冗余分歧陷阱,已删除。`workspace_paths_match`/`realpath_like` 作为 §11 realpath 原语保留
233
- // (step 11 messaging trust auto-answer 复用)。
234
-
235
- #[cfg(test)]
236
- mod tests {
237
- #![allow(clippy::unwrap_used, clippy::panic, clippy::expect_used)]
238
- use super::*;
239
-
240
- struct MockLiveness(PaneLiveness);
241
- impl PaneLivenessProbe for MockLiveness {
242
- fn liveness(&self, _pane_id: &str) -> PaneLiveness {
243
- self.0
244
- }
245
- }
246
- fn caller(pane: &str, uuid: &str) -> CallerIdentity {
247
- CallerIdentity {
248
- pane_id: pane.to_string(),
249
- provider: "codex".to_string(),
250
- machine_fingerprint: "m".to_string(),
251
- leader_session_uuid: uuid.to_string(),
252
- leader_session_uuid_source: "derived".to_string(),
253
- }
254
- }
255
- const LIVE: MockLiveness = MockLiveness(PaneLiveness::Live);
256
- const DEAD: MockLiveness = MockLiveness(PaneLiveness::Dead);
257
- const UNKNOWN: MockLiveness = MockLiveness(PaneLiveness::Unknown);
258
-
259
- fn state_owned(pane: &str, uuid: &str) -> Value {
260
- json!({"team_owner": {"pane_id": pane, "leader_session_uuid": uuid, "provider": "codex"}})
261
- }
262
-
263
- #[test]
264
- fn no_owner_allows() {
265
- assert!(check_team_owner(&json!({}), &caller("%c", "u"), true, &LIVE).is_none());
266
- assert!(
267
- check_team_owner(&json!({"team_owner": {}}), &caller("%c", "u"), true, &LIVE).is_none()
268
- );
269
- }
270
-
271
- #[test]
272
- fn same_pane_is_own() {
273
- let s = state_owned("%owner", "uuid-owner");
274
- assert!(check_team_owner(&s, &caller("%owner", "different-uuid"), true, &LIVE).is_none());
275
- }
276
-
277
- #[test]
278
- fn foreign_pane_live_owner_refuses() {
279
- let s = state_owned("%owner", "uuid-owner");
280
- let r = check_team_owner(&s, &caller("%intruder", "uuid-intruder"), true, &LIVE).unwrap();
281
- assert_eq!(r["reason"], json!("team_owner_mismatch"));
282
- assert_eq!(r["reason_kind"], json!("owner_takeover_required"));
283
- assert_eq!(r["action"], json!("team-agent takeover --confirm"));
284
- assert_eq!(r["error"], json!("not_owner"));
285
- assert_eq!(r["ok"], json!(false));
286
- }
287
-
288
- #[test]
289
- fn dead_owner_pane_lets_new_live_caller_take_over() {
290
- // bug:死 owner pane 不该锁住新 live caller(pane-as-identity)。
291
- let s = state_owned("%owner", "uuid-owner");
292
- // 非 worker(has_team_agent_id=false)+ 死 owner pane → 允许。
293
- assert!(check_team_owner(&s, &caller("%new", "uuid-new"), false, &DEAD).is_none());
294
- // 但 worker(has_team_agent_id=true)即使 owner pane 死也不接管 → 拒绝。
295
- assert!(check_team_owner(&s, &caller("%new", "uuid-new"), true, &DEAD).is_some());
296
- }
297
-
298
- #[test]
299
- fn same_uuid_no_pane_is_own_sticky_bind_when_pane_differs() {
300
- let s = state_owned("%owner", "uuid-shared");
301
- // 同 uuid 无 caller_pane → own。
302
- assert!(check_team_owner(&s, &caller("", "uuid-shared"), true, &LIVE).is_none());
303
- // 同 uuid 但不同 live pane → sticky_bind_collision 拒绝。
304
- let r = check_team_owner(&s, &caller("%other", "uuid-shared"), true, &LIVE).unwrap();
305
- assert_eq!(r["reason_kind"], json!("sticky_bind_collision"));
306
- assert_eq!(r["action"], json!("team-agent claim-leader --confirm"));
307
- }
308
-
309
- #[test]
310
- fn worker_bypass_rules() {
311
- let s = json!({"leader": {"id": "leader"}, "agents": {"worker_a": {}, "worker_b": {}}});
312
- // worker_a + env worker_a → 绕过。
313
- assert_eq!(
314
- worker_sender_bypasses_owner_gate(&s, Some("worker_a"), Some("worker_a")),
315
- Some("worker_a".to_string())
316
- );
317
- // leader → 不绕过(走 owner 门)。
318
- assert_eq!(
319
- worker_sender_bypasses_owner_gate(&s, Some("leader"), Some("leader")),
320
- None
321
- );
322
- // 未注册 agent → 不绕过。
323
- assert_eq!(
324
- worker_sender_bypasses_owner_gate(&s, Some("ghost"), Some("ghost")),
325
- None
326
- );
327
- // sender/env 不一致(伪造)→ 不绕过。
328
- assert_eq!(
329
- worker_sender_bypasses_owner_gate(&s, Some("worker_b"), Some("worker_a")),
330
- None
331
- );
332
- // 无 env_agent_id + 已注册 → 绕过(返回 sender)。
333
- assert_eq!(
334
- worker_sender_bypasses_owner_gate(&s, Some("worker_a"), None),
335
- Some("worker_a".to_string())
336
- );
337
- }
338
-
339
- // §11 血泪:/tmp → /private/tmp 软链不对称(macOS 真机 bug)。两边 canonicalize → match。
340
- #[test]
341
- fn realpath_tmp_symlink_asymmetry_matches() {
342
- // 真实存在的目录(canonicalize 需要路径存在)。
343
- let dir = std::env::temp_dir().join(format!("ta_rs_og_{}", std::process::id()));
344
- std::fs::create_dir_all(&dir).unwrap();
345
- // /tmp/x 与 /private/tmp/x:macOS 上 /tmp 是 /private/tmp 的软链。
346
- let raw = Path::new("/tmp").join(dir.file_name().unwrap());
347
- let private = Path::new("/private/tmp").join(dir.file_name().unwrap());
348
- if raw.exists() && private.exists() {
349
- assert!(
350
- workspace_paths_match(&raw, &private),
351
- "/tmp 与 /private/tmp 应 canonicalize 相等"
352
- );
353
- }
354
- // 自反:同路径 match。
355
- assert!(workspace_paths_match(&dir, &dir));
356
- }
357
-
358
- #[test]
359
- fn realpath_sibling_prefix_does_not_match() {
360
- // §11 禁前缀:/repo 与 /repo-backup 共享前缀但是不同目录 → 不 match。
361
- let base = std::env::temp_dir().join(format!("ta_rs_sib_{}", std::process::id()));
362
- let repo = base.join("repo");
363
- let repo_backup = base.join("repo-backup");
364
- std::fs::create_dir_all(&repo).unwrap();
365
- std::fs::create_dir_all(&repo_backup).unwrap();
366
- assert!(
367
- !workspace_paths_match(&repo, &repo_backup),
368
- "共享前缀的兄弟目录不得 match"
369
- );
370
- // 子目录也不 match(禁子串/反推)。
371
- let sub = repo.join("sub");
372
- std::fs::create_dir_all(&sub).unwrap();
373
- assert!(!workspace_paths_match(&repo, &sub));
374
- }
375
-
376
- // 对抗 P1:拒绝 dict 的 caller 含 5 字段(含 leader_session_uuid_source)。
377
- #[test]
378
- fn refusal_caller_has_five_fields() {
379
- let s = state_owned("%owner", "uuid-owner");
380
- let r = check_team_owner(&s, &caller("%intruder", "uuid-x"), true, &LIVE).unwrap();
381
- let c = r["caller"].as_object().unwrap();
382
- assert_eq!(c.len(), 5);
383
- assert_eq!(r["caller"]["leader_session_uuid_source"], json!("derived"));
384
- }
385
-
386
- // 对抗 P0-A(security):owner 无 uuid + caller 无 uuid 不得 "" == "" allow-flip → 必拒绝。
387
- #[test]
388
- fn empty_uuids_do_not_allow_flip() {
389
- // owner 缺 uuid(未迁移形),caller 也缺 uuid,pane 不同 → 必须拒绝(不得误判 own)。
390
- let s = json!({"team_owner": {"pane_id": "%owner", "provider": "codex"}});
391
- let mut c = caller("%intruder", "");
392
- c.leader_session_uuid_source = "derived".to_string();
393
- let r = check_team_owner(&s, &c, true, &LIVE);
394
- assert!(r.is_some(), "两边空 uuid 不得 allow;必落拒绝");
395
- assert_eq!(
396
- r.unwrap()["reason_kind"],
397
- json!("owner_takeover_required"),
398
- "非 sticky_bind(空 uuid 不算同)"
399
- );
400
- }
401
-
402
- // 对抗 P2:owner pane liveness == Unknown 时,非 worker caller 也接管;worker 不接管。
403
- #[test]
404
- fn unknown_owner_pane_allows_nonworker_takeover() {
405
- let s = state_owned("%owner", "uuid-owner");
406
- assert!(
407
- check_team_owner(&s, &caller("%new", "uuid-new"), false, &UNKNOWN).is_none(),
408
- "Unknown owner pane + 非 worker → 接管"
409
- );
410
- assert!(
411
- check_team_owner(&s, &caller("%new", "uuid-new"), true, &UNKNOWN).is_some(),
412
- "worker 即便 Unknown 也不接管"
413
- );
414
- }
415
-
416
- // 空 caller_pane + 异 uuid + 死 owner:死-owner 接管分支需 caller_pane 非空,故落拒绝。
417
- #[test]
418
- fn empty_caller_pane_diff_uuid_refuses_even_dead_owner() {
419
- let s = state_owned("%owner", "uuid-owner");
420
- let r = check_team_owner(&s, &caller("", "uuid-diff"), false, &DEAD);
421
- assert!(
422
- r.is_some(),
423
- "空 caller_pane 不触发死-owner 接管;异 uuid → 拒绝"
424
- );
425
- }
426
-
427
- // 对抗 P0-B(§11 血泪):父目录是软链 + 末段不存在 → realpath_like 解析父软链 → 判 own。
428
- #[test]
429
- fn parent_symlink_with_missing_leaf_matches() {
430
- let base = std::env::temp_dir().join(format!("ta_rs_plink_{}", std::process::id()));
431
- let real = base.join("real");
432
- std::fs::create_dir_all(&real).unwrap();
433
- let link = base.join("link");
434
- let _ = std::fs::remove_file(&link);
435
- #[cfg(unix)]
436
- std::os::unix::fs::symlink(&real, &link).unwrap();
437
- #[cfg(unix)]
438
- {
439
- // link/ghost 与 real/ghost:ghost 不存在,但 link 是 real 的软链 → 两边 realpath 相等。
440
- assert!(
441
- workspace_paths_match(&link.join("ghost"), &real.join("ghost")),
442
- "父软链 + 缺失末段应判 own(realpath_like 解析父软链)"
443
- );
444
- // 不同末段仍不 match。
445
- assert!(!workspace_paths_match(
446
- &link.join("ghostA"),
447
- &real.join("ghostB")
448
- ));
449
- }
450
- }
451
-
452
- // cr 裁决(2026-06-02)双 FS 正确性钉死(见 contracts-rust-native.yaml DECISIONS):
453
- // 运行时探测当前 FS 大小写敏感性,对该 FS 断言对应的正确行为 —— 同一测试在两种 FS 都自证,
454
- // 防「保留 canonicalize」这个有意分歧静默漂移。
455
- #[test]
456
- fn case_sensitivity_ruling_correct_on_both_fs() {
457
- let base = std::env::temp_dir().join(format!("ta_rs_case_{}", std::process::id()));
458
- let _ = std::fs::remove_dir_all(&base);
459
- let upper = base.join("Workspace");
460
- std::fs::create_dir_all(&upper).unwrap();
461
- let lower_variant = base.join("workspace"); // 仅大小写不同
462
-
463
- // 探测:小写变体能否解析到已建的大写目录?能 → case-insensitive FS。
464
- let fs_case_insensitive = lower_variant.exists();
465
-
466
- if fs_case_insensitive {
467
- // case-insensitive FS(macOS APFS 默认 / Windows NTFS):同一 inode → 须判 own。
468
- assert!(
469
- workspace_paths_match(&upper, &lower_variant),
470
- "case-insensitive FS:大小写变体是同一目录,canonicalize 须相等 → own"
471
- );
472
- } else {
473
- // case-sensitive FS(Linux ext4 / case-sensitive APFS 卷):真造出第二个目录 → 须判 foreign。
474
- std::fs::create_dir_all(&lower_variant).unwrap();
475
- assert!(
476
- !workspace_paths_match(&upper, &lower_variant),
477
- "case-sensitive FS:大小写不同是两个目录 → foreign"
478
- );
479
- }
480
- let _ = std::fs::remove_dir_all(&base);
481
- }
482
- }