@team-agent/installer 0.5.60 → 0.5.62

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 (265) hide show
  1. package/Cargo.lock +1 -1
  2. package/Cargo.toml +1 -1
  3. package/crates/team-agent/src/cli/adapters.rs +49 -3
  4. package/crates/team-agent/src/cli/attach_app_server_leader.rs +1 -0
  5. package/crates/team-agent/src/cli/diagnose.rs +184 -0
  6. package/crates/team-agent/src/cli/emit.rs +104 -21
  7. package/crates/team-agent/src/cli/helpers.rs +1 -0
  8. package/crates/team-agent/src/cli/leader.rs +14 -2
  9. package/crates/team-agent/src/cli/leaders.rs +2 -0
  10. package/crates/team-agent/src/cli/mod.rs +296 -8
  11. package/crates/team-agent/src/cli/named_address.rs +26 -2
  12. package/crates/team-agent/src/cli/profile.rs +2 -1
  13. package/crates/team-agent/src/cli/send/coordinator.rs +1 -0
  14. package/crates/team-agent/src/cli/send/mailbox.rs +3 -0
  15. package/crates/team-agent/src/cli/send/persist.rs +1 -0
  16. package/crates/team-agent/src/cli/send/presentation.rs +3 -0
  17. package/crates/team-agent/src/cli/send/resolve.rs +206 -1
  18. package/crates/team-agent/src/cli/send.rs +2 -1
  19. package/crates/team-agent/src/cli/spec.rs +5 -1
  20. package/crates/team-agent/src/cli/status.rs +2 -1
  21. package/crates/team-agent/src/cli/status_port/compact.rs +1 -0
  22. package/crates/team-agent/src/cli/status_port/format.rs +1 -0
  23. package/crates/team-agent/src/cli/status_port/inbox.rs +1 -0
  24. package/crates/team-agent/src/cli/status_port/store.rs +7 -3
  25. package/crates/team-agent/src/cli/tests/named_address.rs +65 -0
  26. package/crates/team-agent/src/cli/tests/verb_profile.rs +38 -0
  27. package/crates/team-agent/src/cli/types.rs +36 -2
  28. package/crates/team-agent/src/communication_mode/mod.rs +54 -0
  29. package/crates/team-agent/src/compiler/tests.rs +5 -5
  30. package/crates/team-agent/src/compiler.rs +54 -1
  31. package/crates/team-agent/src/conpty/backend.rs +1 -0
  32. package/crates/team-agent/src/conpty/mod.rs +1 -0
  33. package/crates/team-agent/src/coordinator/backoff.rs +5 -8
  34. package/crates/team-agent/src/coordinator/conpty_shim.rs +3 -2
  35. package/crates/team-agent/src/coordinator/health.rs +1 -0
  36. package/crates/team-agent/src/coordinator/mod.rs +2 -2
  37. package/crates/team-agent/src/coordinator/orphan.rs +4 -116
  38. package/crates/team-agent/src/coordinator/runtime_detectors.rs +1 -0
  39. package/crates/team-agent/src/coordinator/runtime_observation.rs +1 -0
  40. package/crates/team-agent/src/coordinator/steps/abnormal.rs +6 -5
  41. package/crates/team-agent/src/coordinator/steps/delivery.rs +1 -0
  42. package/crates/team-agent/src/coordinator/steps/health_sync.rs +1 -0
  43. package/crates/team-agent/src/coordinator/steps/mod.rs +2 -0
  44. package/crates/team-agent/src/coordinator/steps/persist.rs +1 -0
  45. package/crates/team-agent/src/coordinator/steps/runtime_prompts.rs +1 -0
  46. package/crates/team-agent/src/coordinator/steps/session_gate.rs +1 -0
  47. package/crates/team-agent/src/coordinator/tests/abnormal.rs +0 -174
  48. package/crates/team-agent/src/coordinator/tests/api_error_recovery.rs +0 -9
  49. package/crates/team-agent/src/coordinator/tests/basics.rs +0 -184
  50. package/crates/team-agent/src/coordinator/tests/mod.rs +2 -17
  51. package/crates/team-agent/src/coordinator/tests/tick_core.rs +0 -42
  52. package/crates/team-agent/src/coordinator/tick.rs +24 -28
  53. package/crates/team-agent/src/coordinator/types.rs +3 -176
  54. package/crates/team-agent/src/db/agent_health_capture.rs +1 -0
  55. package/crates/team-agent/src/db/message_store.rs +47 -2
  56. package/crates/team-agent/src/db/migration.rs +5 -4
  57. package/crates/team-agent/src/db/mod.rs +1 -0
  58. package/crates/team-agent/src/db/schema.rs +1 -0
  59. package/crates/team-agent/src/diagnose/comms.rs +2 -1
  60. package/crates/team-agent/src/diagnose/mod.rs +1 -0
  61. package/crates/team-agent/src/diagnose/orphans.rs +1 -0
  62. package/crates/team-agent/src/fake_worker.rs +21 -1
  63. package/crates/team-agent/src/layout/manager.rs +3 -7
  64. package/crates/team-agent/src/layout/mod.rs +2 -2
  65. package/crates/team-agent/src/layout/overlay.rs +6 -1
  66. package/crates/team-agent/src/layout/placement.rs +1 -0
  67. package/crates/team-agent/src/layout/recovery.rs +3 -0
  68. package/crates/team-agent/src/layout/runtime_sessions.rs +8 -3
  69. package/crates/team-agent/src/layout/sessions.rs +8 -1
  70. package/crates/team-agent/src/layout/tmux_endpoint.rs +3 -0
  71. package/crates/team-agent/src/layout/worker_env.rs +3 -0
  72. package/crates/team-agent/src/layout/worker_window_helpers.rs +2 -0
  73. package/crates/team-agent/src/leader/helpers.rs +1 -0
  74. package/crates/team-agent/src/leader/incident.rs +1 -0
  75. package/crates/team-agent/src/leader/lease.rs +27 -22
  76. package/crates/team-agent/src/leader/mod.rs +2 -3
  77. package/crates/team-agent/src/leader/owner_bind.rs +13 -3
  78. package/crates/team-agent/src/leader/provider_attribution.rs +1 -0
  79. package/crates/team-agent/src/leader/rediscover.rs +4 -17
  80. package/crates/team-agent/src/leader/registry.rs +3 -15
  81. package/crates/team-agent/src/leader/start.rs +1072 -186
  82. package/crates/team-agent/src/leader/takeover.rs +10 -232
  83. package/crates/team-agent/src/leader/tests/claim_leader_mailbox_flush_contract.rs +544 -0
  84. package/crates/team-agent/src/leader/tests/historical_inventory_upgrade_gate_red.rs +624 -0
  85. package/crates/team-agent/src/leader/tests/identity.rs +71 -59
  86. package/crates/team-agent/src/leader/tests/identity_session_names.rs +42 -0
  87. package/crates/team-agent/src/leader/tests/idle.rs +0 -193
  88. package/crates/team-agent/src/leader/tests/lease_api.rs +0 -45
  89. package/crates/team-agent/src/leader/tests/mod.rs +4 -41
  90. package/crates/team-agent/src/leader/tests/rehomed_env.rs +83 -0
  91. package/crates/team-agent/src/leader/tests/team_in_team_state_scope_red.rs +1273 -0
  92. package/crates/team-agent/src/leader/tests/terminal_and_replay_vs_rerender_invariants_red.rs +417 -0
  93. package/crates/team-agent/src/leader/tests/wake_start_owner.rs +22 -103
  94. package/crates/team-agent/src/leader/types.rs +1 -28
  95. package/crates/team-agent/src/lib.rs +7 -0
  96. package/crates/team-agent/src/lifecycle/display.rs +7 -1
  97. package/crates/team-agent/src/lifecycle/helpers.rs +3 -1
  98. package/crates/team-agent/src/lifecycle/launch/add_agent.rs +2 -2
  99. package/crates/team-agent/src/lifecycle/launch/fork_agent/completion.rs +1 -0
  100. package/crates/team-agent/src/lifecycle/launch/fork_agent.rs +1 -1
  101. package/crates/team-agent/src/lifecycle/launch/fork_entry.rs +1 -0
  102. package/crates/team-agent/src/lifecycle/launch/fork_finalize.rs +1 -0
  103. package/crates/team-agent/src/lifecycle/launch/plan.rs +2 -2
  104. package/crates/team-agent/src/lifecycle/launch/quick_start.rs +4 -26
  105. package/crates/team-agent/src/lifecycle/launch/readiness.rs +0 -27
  106. package/crates/team-agent/src/lifecycle/launch/spawn.rs +2 -28
  107. package/crates/team-agent/src/lifecycle/launch/spec_state.rs +4 -32
  108. package/crates/team-agent/src/lifecycle/launch/state_projection.rs +1 -0
  109. package/crates/team-agent/src/lifecycle/launch.rs +11 -12
  110. package/crates/team-agent/src/lifecycle/mod.rs +2 -1
  111. package/crates/team-agent/src/lifecycle/restart/agent.rs +4 -4
  112. package/crates/team-agent/src/lifecycle/restart/common.rs +1 -1
  113. package/crates/team-agent/src/lifecycle/restart/orchestrator.rs +2 -2
  114. package/crates/team-agent/src/lifecycle/restart/rebuild.rs +13 -5
  115. package/crates/team-agent/src/lifecycle/restart/remove.rs +1 -1
  116. package/crates/team-agent/src/lifecycle/restart/selection.rs +3 -3
  117. package/crates/team-agent/src/lifecycle/restart.rs +13 -11
  118. package/crates/team-agent/src/lifecycle/tests/acceptance_b_batch_red.rs +1007 -0
  119. package/crates/team-agent/src/lifecycle/tests/b0_legacy_snapshot_nonauthority_contract.rs +265 -0
  120. package/crates/team-agent/src/lifecycle/tests/b0_reader_hideone_audit_contract.rs +459 -0
  121. package/crates/team-agent/src/lifecycle/tests/behavioral_diff_264_red.rs +849 -0
  122. package/crates/team-agent/src/lifecycle/tests/claude_compatible_config_red.rs +323 -0
  123. package/crates/team-agent/src/lifecycle/tests/claude_profile_launch_red.rs +423 -0
  124. package/crates/team-agent/src/lifecycle/tests/clone_fork_copilot_perms_red.rs +737 -0
  125. package/crates/team-agent/src/lifecycle/tests/codex_mcp_approval_inheritance_red.rs +1187 -0
  126. package/crates/team-agent/src/lifecycle/tests/codex_weak_window_attribution_red.rs +683 -0
  127. package/crates/team-agent/src/lifecycle/tests/communication_mode_runtime_contract_red.rs +394 -0
  128. package/crates/team-agent/src/lifecycle/tests/copilot_provider_red.rs +1856 -0
  129. package/crates/team-agent/src/lifecycle/tests/core_034_real_red.rs +917 -0
  130. package/crates/team-agent/src/lifecycle/tests/display_adaptive_red.rs +481 -0
  131. package/crates/team-agent/src/lifecycle/tests/f032_startup_prompt_best_effort_red.rs +301 -0
  132. package/crates/team-agent/src/lifecycle/tests/harvest2_a_batch_red.rs +516 -0
  133. package/crates/team-agent/src/lifecycle/tests/host_cotenant_death_p0_contract.rs +986 -0
  134. package/crates/team-agent/src/lifecycle/tests/lifecycle_rollback_red.rs +651 -0
  135. package/crates/team-agent/src/lifecycle/tests/main_preserved.rs +2 -0
  136. package/crates/team-agent/src/lifecycle/tests/quick_start_worker_readiness_red.rs +332 -0
  137. package/crates/team-agent/src/lifecycle/tests/realmachine_clusters_1_6_red.rs +846 -0
  138. package/crates/team-agent/src/lifecycle/tests/realmachine_residual_g1_g4_red.rs +648 -0
  139. package/crates/team-agent/src/lifecycle/tests/restart_build_before_destroy_0540_contract.rs +910 -0
  140. package/crates/team-agent/src/lifecycle/tests/restart_liveness_red.rs +630 -0
  141. package/crates/team-agent/src/lifecycle/tests/restart_rebind_hotfix_252_red.rs +1083 -0
  142. package/crates/team-agent/src/lifecycle/tests/restart_session_capture_red.rs +1677 -0
  143. package/crates/team-agent/src/lifecycle/tests/resume_recover_red.rs +410 -0
  144. package/crates/team-agent/src/lifecycle/tests/stale_team_saveconflict_contract.rs +428 -0
  145. package/crates/team-agent/src/lifecycle/tests/startup_latency_contract.rs +1032 -0
  146. package/crates/team-agent/src/lifecycle/tests/status_credential_redaction_contract.rs +869 -0
  147. package/crates/team-agent/src/lifecycle/tests/subprep_codex_trust_roundtrip_red.rs +1249 -0
  148. package/crates/team-agent/src/lifecycle/tests/swallow_batch4_semantics_red.rs +342 -0
  149. package/crates/team-agent/src/lifecycle/tests/team_in_team_identity_scope_red.rs +542 -0
  150. package/crates/team-agent/src/lifecycle/tests/team_in_team_sibling_quick_start_red.rs +1103 -0
  151. package/crates/team-agent/src/lifecycle/tests/team_in_team_state_scope_red.rs +1276 -0
  152. package/crates/team-agent/src/lifecycle/tests/team_key_retirement_roster_red.rs +145 -0
  153. package/crates/team-agent/src/lifecycle/tests/team_key_retirement_txn_red.rs +603 -0
  154. package/crates/team-agent/src/lifecycle/tests/test_isolation_escape_contract.rs +837 -0
  155. package/crates/team-agent/src/lifecycle/tests/upgrade_compat_0211_red.rs +928 -0
  156. package/crates/team-agent/src/lifecycle/tests/verify_rs031_window_consistency_red.rs +951 -0
  157. package/crates/team-agent/src/lifecycle/tests/worker_dangerous_bypass_argv_red.rs +327 -0
  158. package/crates/team-agent/src/lifecycle/tests/worker_spawn_env_red.rs +760 -0
  159. package/crates/team-agent/src/lifecycle/tests.rs +59 -0
  160. package/crates/team-agent/src/lifecycle/types.rs +0 -9
  161. package/crates/team-agent/src/lifecycle/worker_command_context.rs +29 -11
  162. package/crates/team-agent/src/mcp_server/helpers.rs +1 -0
  163. package/crates/team-agent/src/mcp_server/lifecycle_tools/mod.rs +1 -0
  164. package/crates/team-agent/src/mcp_server/lifecycle_tools/state_status.rs +1 -0
  165. package/crates/team-agent/src/mcp_server/mod.rs +1 -0
  166. package/crates/team-agent/src/mcp_server/normalize.rs +5 -3
  167. package/crates/team-agent/src/mcp_server/tests/send.rs +26 -0
  168. package/crates/team-agent/src/mcp_server/tests/wire.rs +1 -1
  169. package/crates/team-agent/src/mcp_server/tools.rs +101 -66
  170. package/crates/team-agent/src/mcp_server/types.rs +6 -18
  171. package/crates/team-agent/src/mcp_server/wire.rs +32 -26
  172. package/crates/team-agent/src/messaging/activity.rs +1 -0
  173. package/crates/team-agent/src/messaging/address.rs +1 -0
  174. package/crates/team-agent/src/messaging/delivery.rs +109 -41
  175. package/crates/team-agent/src/messaging/helpers.rs +2 -1
  176. package/crates/team-agent/src/messaging/leader_channel.rs +34 -10
  177. package/crates/team-agent/src/messaging/leader_receiver.rs +42 -24
  178. package/crates/team-agent/src/messaging/mod.rs +10 -14
  179. package/crates/team-agent/src/messaging/peers.rs +2 -0
  180. package/crates/team-agent/src/messaging/persist.rs +3 -1
  181. package/crates/team-agent/src/messaging/presentation.rs +111 -1
  182. package/crates/team-agent/src/messaging/results.rs +166 -17
  183. package/crates/team-agent/src/messaging/scheduler.rs +1 -0
  184. package/crates/team-agent/src/messaging/selftest.rs +1 -1
  185. package/crates/team-agent/src/messaging/send.rs +135 -89
  186. package/crates/team-agent/src/messaging/tests/leader_channel.rs +6 -6
  187. package/crates/team-agent/src/messaging/tests/leader_inject_acceptance.rs +187 -0
  188. package/crates/team-agent/src/messaging/tests/mod.rs +5 -0
  189. package/crates/team-agent/src/messaging/tests/runtime.rs +13 -6
  190. package/crates/team-agent/src/messaging/types.rs +7 -2
  191. package/crates/team-agent/src/messaging/watchers.rs +24 -13
  192. package/crates/team-agent/src/model/enums.rs +1 -0
  193. package/crates/team-agent/src/model/errors.rs +1 -0
  194. package/crates/team-agent/src/model/ids.rs +1 -0
  195. package/crates/team-agent/src/model/mod.rs +2 -0
  196. package/crates/team-agent/src/model/name_similarity.rs +1 -0
  197. package/crates/team-agent/src/model/pane_authority_refusal.rs +359 -0
  198. package/crates/team-agent/src/model/paths.rs +1 -0
  199. package/crates/team-agent/src/model/permissions.rs +3 -2
  200. package/crates/team-agent/src/model/routing.rs +1 -0
  201. package/crates/team-agent/src/model/spec.rs +17 -0
  202. package/crates/team-agent/src/model/task_graph.rs +1 -0
  203. package/crates/team-agent/src/model/yaml/tests.rs +1 -0
  204. package/crates/team-agent/src/model/yaml.rs +1 -0
  205. package/crates/team-agent/src/packaging/install.rs +9 -147
  206. package/crates/team-agent/src/packaging/migrate.rs +2 -0
  207. package/crates/team-agent/src/packaging/mod.rs +1 -0
  208. package/crates/team-agent/src/packaging/repair.rs +2 -0
  209. package/crates/team-agent/src/packaging/tests.rs +29 -218
  210. package/crates/team-agent/src/packaging/types.rs +8 -15
  211. package/crates/team-agent/src/platform/argv.rs +4 -0
  212. package/crates/team-agent/src/platform/errors.rs +10 -1
  213. package/crates/team-agent/src/platform/file_lock.rs +4 -157
  214. package/crates/team-agent/src/platform/mod.rs +0 -61
  215. package/crates/team-agent/src/platform/process.rs +1 -0
  216. package/crates/team-agent/src/provider/adapter.rs +1 -0
  217. package/crates/team-agent/src/provider/adapters/claude.rs +1 -0
  218. package/crates/team-agent/src/provider/adapters/claude_fork.rs +1 -0
  219. package/crates/team-agent/src/provider/adapters/codex.rs +1 -0
  220. package/crates/team-agent/src/provider/adapters/copilot.rs +1 -0
  221. package/crates/team-agent/src/provider/adapters/copilot_fork.rs +1 -0
  222. package/crates/team-agent/src/provider/adapters/fake.rs +1 -0
  223. package/crates/team-agent/src/provider/adapters/mod.rs +1 -0
  224. package/crates/team-agent/src/provider/approvals/mod.rs +1 -0
  225. package/crates/team-agent/src/provider/approvals/parsing.rs +2 -5
  226. package/crates/team-agent/src/provider/approvals/runtime_prompts.rs +6 -5
  227. package/crates/team-agent/src/provider/classify.rs +1 -0
  228. package/crates/team-agent/src/provider/faults.rs +1 -26
  229. package/crates/team-agent/src/provider/helpers.rs +1 -0
  230. package/crates/team-agent/src/provider/mod.rs +1 -1
  231. package/crates/team-agent/src/provider/session/capture.rs +41 -22
  232. package/crates/team-agent/src/provider/session/context_fork/claude.rs +1 -0
  233. package/crates/team-agent/src/provider/session/context_fork/codex.rs +1 -0
  234. package/crates/team-agent/src/provider/session/context_fork/outcome.rs +1 -0
  235. package/crates/team-agent/src/provider/session/context_fork.rs +1 -0
  236. package/crates/team-agent/src/provider/session/mod.rs +2 -4
  237. package/crates/team-agent/src/provider/session/resume.rs +2 -209
  238. package/crates/team-agent/src/provider/session_scan/claude.rs +93 -3
  239. package/crates/team-agent/src/provider/session_scan/codex.rs +1 -0
  240. package/crates/team-agent/src/provider/session_scan/common.rs +24 -7
  241. package/crates/team-agent/src/provider/session_scan/copilot.rs +1 -0
  242. package/crates/team-agent/src/provider/session_scan.rs +6 -42
  243. package/crates/team-agent/src/provider/startup_prompt.rs +1 -0
  244. package/crates/team-agent/src/provider/types.rs +1 -0
  245. package/crates/team-agent/src/provider/wire.rs +1 -0
  246. package/crates/team-agent/src/state/identity.rs +16 -5
  247. package/crates/team-agent/src/state/identity_keys.rs +1 -0
  248. package/crates/team-agent/src/state/mod.rs +2 -0
  249. package/crates/team-agent/src/state/owner_gate.rs +5 -0
  250. package/crates/team-agent/src/state/ownership.rs +10 -4
  251. package/crates/team-agent/src/state/paths.rs +12 -0
  252. package/crates/team-agent/src/state/persist.rs +9 -3
  253. package/crates/team-agent/src/state/projection.rs +15 -2
  254. package/crates/team-agent/src/state/repository/intent.rs +1 -0
  255. package/crates/team-agent/src/state/repository/tests.rs +1 -0
  256. package/crates/team-agent/src/state/repository.rs +7 -0
  257. package/crates/team-agent/src/state/selector.rs +1 -0
  258. package/crates/team-agent/src/tmux_backend/tests.rs +39 -0
  259. package/crates/team-agent/src/tmux_backend.rs +63 -0
  260. package/crates/team-agent/src/topology.rs +3 -0
  261. package/crates/team-agent/src/transport.rs +15 -0
  262. package/package.json +4 -4
  263. package/skills/team-agent/command-coverage.json +379 -0
  264. package/crates/team-agent/src/leader/inject.rs +0 -33
  265. package/crates/team-agent/src/provider/command.rs +0 -80
@@ -0,0 +1,459 @@
1
+ //! Foundation-0 F0-3 RED contract: B0 legacy snapshot reader/path hide-one audit.
2
+ //!
3
+ //! References:
4
+ //! - `.team/artifacts/foundation-0-slice-design.md` §5 F0-3.
5
+ //! - F0-2 boundary: retained legacy snapshots are diagnostic only via
6
+ //! `_not_authoritative`, `_canonical_state_path`, `_derived_from`,
7
+ //! `_generated_at`, and `B0_DIAGNOSTIC_LEGACY_SNAPSHOT_READ` allowlisted reads.
8
+ //!
9
+ //! User story: when a legacy per-session snapshot disagrees with the current
10
+ //! root/projection state, every runtime reader keeps routing, restart, delivery,
11
+ //! status, and diagnose decisions on the current authority. The snapshot may be
12
+ //! shown only as a labeled diagnostic, never as hidden truth.
13
+
14
+ #![allow(clippy::expect_used, clippy::panic, clippy::unwrap_used)]
15
+
16
+ #[path = "../../../tests/support/hermetic.rs"]
17
+ mod hermetic_guard;
18
+
19
+ #[path = "../../../tests/support/composite_source.rs"]
20
+ mod composite_source;
21
+ use std::path::{Path, PathBuf};
22
+
23
+ use serde_json::{json, Value};
24
+ use serial_test::serial;
25
+ use team_agent::state::persist::{runtime_state_path, save_runtime_state};
26
+
27
+ const TEAM: &str = "team-a";
28
+ const SESSION: &str = "team-b0-hideone";
29
+ const WORKER: &str = "worker";
30
+ const NEW_ENDPOINT: &str = "/private/tmp/tmux-501/ta-b0-new";
31
+ const OLD_ENDPOINT: &str = "/private/tmp/tmux-501/ta-b0-old";
32
+ const READ_MARKER: &str = "B0_DIAGNOSTIC_LEGACY_SNAPSHOT_READ";
33
+
34
+ #[test]
35
+ #[serial(env)]
36
+ fn stale_snapshot_endpoint_does_not_reach_restart_preflight_spawn_attach_or_events() {
37
+ let case = B0HideOneCase::new("restart-endpoint-hide-one");
38
+ case.seed_current_root_and_stale_snapshot();
39
+
40
+ let selected = team_agent::state::projection::select_runtime_state(&case.workspace, Some(TEAM))
41
+ .expect("select runtime state from current authority");
42
+ assert_eq!(
43
+ selected.get("tmux_endpoint").and_then(Value::as_str),
44
+ Some(NEW_ENDPOINT),
45
+ "F0-3 RED1: restart selection must read current root/projection endpoint, not stale legacy snapshot endpoint; selected={selected}"
46
+ );
47
+
48
+ let candidate = team_agent::lifecycle::select_restart_state(&case.workspace, Some(TEAM))
49
+ .expect("restart preflight should select the current team");
50
+ assert_eq!(
51
+ candidate.state_path,
52
+ runtime_state_path(&case.workspace),
53
+ "F0-3 RED1: restart preflight must be rooted at the canonical runtime state file, not a legacy per-session snapshot; candidate={candidate:?}"
54
+ );
55
+
56
+ let offenders = source_lines_under("src/lifecycle/restart")
57
+ .into_iter()
58
+ .filter(|(rel, line_no, line)| legacy_snapshot_authority_read(rel, *line_no, line))
59
+ .collect::<Vec<_>>();
60
+ assert!(
61
+ offenders.is_empty(),
62
+ "F0-3 RED1: lifecycle/restart preflight, spawn metadata, attach_commands, and restart events must not read legacy snapshot paths. Offenders (file:line): {offenders:#?}"
63
+ );
64
+ }
65
+
66
+ #[test]
67
+ #[serial(env)]
68
+ fn stale_snapshot_pane_does_not_reach_delivery_target_resolution() {
69
+ let case = B0HideOneCase::new("delivery-pane-hide-one");
70
+ case.seed_current_root_and_stale_snapshot();
71
+
72
+ let selected = team_agent::state::projection::select_runtime_state(&case.workspace, Some(TEAM))
73
+ .expect("select runtime state from current authority");
74
+ assert_eq!(
75
+ selected.pointer("/agents/worker/pane_id").and_then(Value::as_str),
76
+ Some("%new"),
77
+ "F0-3 RED2: delivery target selection must see the current root/projection worker pane, not stale legacy snapshot pane; selected={selected}"
78
+ );
79
+
80
+ let offenders = source_lines_for(&[
81
+ "src/messaging",
82
+ "src/cli/send.rs",
83
+ "src/cli/named_address.rs",
84
+ ])
85
+ .into_iter()
86
+ .filter(|(rel, line_no, line)| legacy_snapshot_authority_read(rel, *line_no, line))
87
+ .collect::<Vec<_>>();
88
+ assert!(
89
+ offenders.is_empty(),
90
+ "F0-3 RED2: delivery and named-send target resolution must not read legacy snapshot paths, so stale snapshot panes cannot be selected. Offenders (file:line): {offenders:#?}"
91
+ );
92
+ }
93
+
94
+ #[test]
95
+ #[serial(env)]
96
+ fn stale_snapshot_cannot_flip_status_or_diagnose_ok_readiness() {
97
+ let case = B0HideOneCase::new("status-diagnose-hide-one");
98
+ let root = case.current_state();
99
+ save_runtime_state(&case.workspace, &root).expect("seed current root state");
100
+
101
+ let status_before = case.run_json(&[
102
+ "status",
103
+ "--workspace",
104
+ case.workspace_str(),
105
+ "--team",
106
+ TEAM,
107
+ "--detail",
108
+ "--json",
109
+ ]);
110
+ let diagnose_before = case.run_json(&[
111
+ "diagnose",
112
+ "--workspace",
113
+ case.workspace_str(),
114
+ "--team",
115
+ TEAM,
116
+ "--json",
117
+ ]);
118
+
119
+ case.write_stale_snapshot();
120
+
121
+ let status_after = case.run_json(&[
122
+ "status",
123
+ "--workspace",
124
+ case.workspace_str(),
125
+ "--team",
126
+ TEAM,
127
+ "--detail",
128
+ "--json",
129
+ ]);
130
+ let diagnose_after = case.run_json(&[
131
+ "diagnose",
132
+ "--workspace",
133
+ case.workspace_str(),
134
+ "--team",
135
+ TEAM,
136
+ "--json",
137
+ ]);
138
+
139
+ assert_eq!(
140
+ status_after.pointer("/agents/worker/pane_id").and_then(Value::as_str),
141
+ Some("%new"),
142
+ "F0-3 RED3: status must not display the stale snapshot pane as the worker authority; before={status_before} after={status_after}"
143
+ );
144
+ assert_eq!(
145
+ worker_status_tuple(&status_before),
146
+ worker_status_tuple(&status_after),
147
+ "F0-3 RED3: stale legacy snapshot must not flip status/readiness fields except for a labeled diagnostic; before={status_before} after={status_after}"
148
+ );
149
+ assert_eq!(
150
+ diagnose_before.get("ok"),
151
+ diagnose_after.get("ok"),
152
+ "F0-3 RED3: stale legacy snapshot must not flip diagnose ok; before={diagnose_before} after={diagnose_after}"
153
+ );
154
+ let before_issues = issue_ids(&diagnose_before);
155
+ let after_issues = issue_ids(&diagnose_after);
156
+ let new_issues = after_issues
157
+ .iter()
158
+ .filter(|issue| !before_issues.contains(*issue))
159
+ .cloned()
160
+ .collect::<Vec<_>>();
161
+ let bad = new_issues
162
+ .iter()
163
+ .filter(|issue| issue.as_str() != "legacy_snapshot_stale")
164
+ .collect::<Vec<_>>();
165
+ assert!(
166
+ bad.is_empty(),
167
+ "F0-3 RED3: status/diagnose may surface only labeled `legacy_snapshot_stale` for a divergent snapshot; new_issues={new_issues:?} before={diagnose_before} after={diagnose_after}"
168
+ );
169
+ }
170
+
171
+ #[test]
172
+ fn product_authority_paths_do_not_read_legacy_snapshot_without_diagnostic_marker() {
173
+ let offenders = source_lines_under("src")
174
+ .into_iter()
175
+ .filter(|(rel, line_no, line)| legacy_snapshot_authority_read(rel, *line_no, line))
176
+ .collect::<Vec<_>>();
177
+
178
+ assert!(
179
+ offenders.is_empty(),
180
+ "F0-3 RED4: product authority paths must not read legacy per-session snapshots. Only migration/diagnostic/test code, or lines explicitly marked `{READ_MARKER}`, may touch `.team/runtime/teams/<session_name>/state.json`. Offenders (file:line): {offenders:#?}"
181
+ );
182
+ }
183
+
184
+ #[test]
185
+ fn team_runtime_state_path_uses_b3_team_key_layout_not_legacy_runtime_root_layout() {
186
+ let paths = team_agent::state::paths::TeamRuntimePaths::new(PathBuf::from("/ws/proj"), "alpha");
187
+
188
+ assert_eq!(
189
+ paths.state_path(),
190
+ PathBuf::from("/ws/proj/.team/runtime/teams/alpha/state.json"),
191
+ "F0-3 RED5: state/paths.rs must pre-announce the B3 canonical team state path as `.team/runtime/teams/<team_key>/state.json`; `.team/runtime/<team_key>/state.json` collides with runtime spec/coordinator sidecar layout and keeps the old hide-two ambiguity alive"
192
+ );
193
+ }
194
+
195
+ struct B0HideOneCase {
196
+ env: hermetic_guard::HermeticTestEnv,
197
+ workspace: PathBuf,
198
+ workspace_str: String,
199
+ }
200
+
201
+ impl B0HideOneCase {
202
+ fn new(tag: &str) -> Self {
203
+ let env = hermetic_guard::HermeticTestEnv::enter(tag);
204
+ let workspace = env.workspace(tag);
205
+ let workspace_str = workspace.to_string_lossy().to_string();
206
+ Self {
207
+ env,
208
+ workspace,
209
+ workspace_str,
210
+ }
211
+ }
212
+
213
+ fn workspace_str(&self) -> &str {
214
+ &self.workspace_str
215
+ }
216
+
217
+ fn seed_current_root_and_stale_snapshot(&self) {
218
+ save_runtime_state(&self.workspace, &self.current_state())
219
+ .expect("seed current root state");
220
+ self.write_stale_snapshot();
221
+ }
222
+
223
+ fn current_state(&self) -> Value {
224
+ self.state("%new", 24001, 3, NEW_ENDPOINT)
225
+ }
226
+
227
+ fn stale_snapshot_state(&self) -> Value {
228
+ let mut state = self.state("%old", 12001, 1, OLD_ENDPOINT);
229
+ let canonical = runtime_state_path(&self.workspace);
230
+ let obj = state.as_object_mut().expect("state object");
231
+ obj.insert("_not_authoritative".to_string(), json!(true));
232
+ obj.insert(
233
+ "_canonical_state_path".to_string(),
234
+ json!(canonical.to_string_lossy().to_string()),
235
+ );
236
+ obj.insert(
237
+ "_derived_from".to_string(),
238
+ json!("f0-3-test-stale-legacy-snapshot"),
239
+ );
240
+ obj.insert("_generated_at".to_string(), json!("2026-07-11T00:00:00Z"));
241
+ state
242
+ }
243
+
244
+ fn state(&self, pane_id: &str, pane_pid: i64, spawn_epoch: u64, endpoint: &str) -> Value {
245
+ let worker = json!({
246
+ "id": WORKER,
247
+ "agent_id": WORKER,
248
+ "provider": "fake",
249
+ "model": "fake",
250
+ "pane_id": pane_id,
251
+ "pane_pid": pane_pid,
252
+ "tmux_session": SESSION,
253
+ "window": WORKER,
254
+ "last_window": WORKER,
255
+ "spawn_epoch": spawn_epoch,
256
+ "status": "running",
257
+ "auth_mode": "subscription"
258
+ });
259
+ let team = json!({
260
+ "team_key": TEAM,
261
+ "active_team_key": TEAM,
262
+ "session_name": SESSION,
263
+ "team_dir": self.workspace_str,
264
+ "workspace": self.workspace_str,
265
+ "status": "alive",
266
+ "tmux_endpoint": endpoint,
267
+ "tmux_socket": endpoint,
268
+ "tmux_socket_source": "test",
269
+ "transport": {"kind": "tmux", "source": "test"},
270
+ "agents": {
271
+ WORKER: worker.clone()
272
+ },
273
+ "leader_receiver": {
274
+ "status": "attached",
275
+ "pane_id": "%leader-new",
276
+ "provider": "fake",
277
+ "tmux_socket": endpoint,
278
+ "owner_epoch": 3
279
+ },
280
+ "team_owner": {
281
+ "pane_id": "%leader-new",
282
+ "provider": "fake",
283
+ "owner_epoch": 3,
284
+ "leader_session_uuid": "leader-new"
285
+ }
286
+ });
287
+ json!({
288
+ "schema_version": 1,
289
+ "active_team_key": TEAM,
290
+ "team_key": TEAM,
291
+ "session_name": SESSION,
292
+ "team_dir": self.workspace_str,
293
+ "workspace": self.workspace_str,
294
+ "status": "alive",
295
+ "tmux_endpoint": endpoint,
296
+ "tmux_socket": endpoint,
297
+ "tmux_socket_source": "test",
298
+ "transport": {"kind": "tmux", "source": "test"},
299
+ "agents": {
300
+ WORKER: worker
301
+ },
302
+ "leader_receiver": {
303
+ "status": "attached",
304
+ "pane_id": "%leader-new",
305
+ "provider": "fake",
306
+ "tmux_socket": endpoint,
307
+ "owner_epoch": 3
308
+ },
309
+ "team_owner": {
310
+ "pane_id": "%leader-new",
311
+ "provider": "fake",
312
+ "owner_epoch": 3,
313
+ "leader_session_uuid": "leader-new"
314
+ },
315
+ "teams": {
316
+ TEAM: team
317
+ }
318
+ })
319
+ }
320
+
321
+ fn write_stale_snapshot(&self) {
322
+ let path = team_agent::lifecycle::helpers::team_snapshot_path(&self.workspace, SESSION);
323
+ write_json(&path, &self.stale_snapshot_state());
324
+ }
325
+
326
+ fn run_json(&self, args: &[&str]) -> Value {
327
+ let output = self.env.run_cli(&self.workspace, args);
328
+ let stdout = String::from_utf8_lossy(&output.stdout);
329
+ let stderr = String::from_utf8_lossy(&output.stderr);
330
+ parse_json_object(&format!("{stdout}\n{stderr}")).unwrap_or_else(|| {
331
+ panic!("command did not emit JSON: args={args:?} stdout={stdout} stderr={stderr}")
332
+ })
333
+ }
334
+ }
335
+
336
+ fn worker_status_tuple(status: &Value) -> Value {
337
+ let worker = status
338
+ .get("agents")
339
+ .and_then(Value::as_object)
340
+ .and_then(|agents| agents.get(WORKER))
341
+ .cloned()
342
+ .unwrap_or(Value::Null);
343
+ json!({
344
+ "ok": status.get("ok").cloned().unwrap_or(Value::Null),
345
+ "pane_id": worker.get("pane_id").cloned().unwrap_or(Value::Null),
346
+ "status": worker.get("status").cloned().unwrap_or(Value::Null),
347
+ "readiness": status.get("readiness").cloned().unwrap_or(Value::Null),
348
+ })
349
+ }
350
+
351
+ fn issue_ids(value: &Value) -> Vec<String> {
352
+ value
353
+ .get("issues")
354
+ .and_then(Value::as_array)
355
+ .into_iter()
356
+ .flatten()
357
+ .filter_map(|issue| {
358
+ issue.as_str().map(str::to_string).or_else(|| {
359
+ issue
360
+ .get("id")
361
+ .or_else(|| issue.get("code"))
362
+ .and_then(Value::as_str)
363
+ .map(str::to_string)
364
+ })
365
+ })
366
+ .collect()
367
+ }
368
+
369
+ fn write_json(path: &Path, value: &Value) {
370
+ std::fs::create_dir_all(path.parent().expect("json parent")).expect("create json parent");
371
+ std::fs::write(
372
+ path,
373
+ serde_json::to_vec_pretty(value).expect("serialize json"),
374
+ )
375
+ .unwrap_or_else(|error| panic!("write {}: {error}", path.display()));
376
+ }
377
+
378
+ fn parse_json_object(text: &str) -> Option<Value> {
379
+ let start = text.find('{')?;
380
+ let end = text.rfind('}')?;
381
+ serde_json::from_str(&text[start..=end]).ok()
382
+ }
383
+
384
+ fn legacy_snapshot_authority_read(rel: &str, _line_no: usize, line: &str) -> bool {
385
+ let trimmed = line.trim_start();
386
+ if trimmed.starts_with("//") || trimmed.starts_with("///") || trimmed.starts_with("//!") {
387
+ return false;
388
+ }
389
+ if allowed_test_source(rel) || allowed_diagnostic_or_migration_source(rel, line) {
390
+ return false;
391
+ }
392
+ if rel == "src/lifecycle/helpers.rs" {
393
+ return false;
394
+ }
395
+ line.contains("team_snapshot_path(")
396
+ || line.contains("readable_team_snapshot_path(")
397
+ || line.contains("detect_dual_state_divergence(")
398
+ || line.contains("\".team/runtime/teams\"")
399
+ || line.contains("runtime/teams")
400
+ }
401
+
402
+ fn allowed_test_source(rel: &str) -> bool {
403
+ rel.contains("/tests/") || rel.ends_with("/tests.rs")
404
+ }
405
+
406
+ fn allowed_diagnostic_or_migration_source(rel: &str, line: &str) -> bool {
407
+ rel.contains("/migration")
408
+ || rel.contains("/diagnose")
409
+ || rel.contains("diagnose")
410
+ || line.contains(READ_MARKER)
411
+ }
412
+
413
+ fn source_lines_for(paths: &[&str]) -> Vec<(String, usize, String)> {
414
+ paths
415
+ .iter()
416
+ .flat_map(|rel| source_lines_under(rel))
417
+ .collect()
418
+ }
419
+
420
+ fn source_lines_under(rel: &str) -> Vec<(String, usize, String)> {
421
+ let mut out = Vec::new();
422
+ if rel.ends_with(".rs") {
423
+ for (part_rel, text) in composite_source::composite_files(rel) {
424
+ for (index, line) in text.lines().enumerate() {
425
+ out.push((part_rel.clone(), index + 1, line.to_string()));
426
+ }
427
+ }
428
+ return out;
429
+ }
430
+ let root = Path::new(env!("CARGO_MANIFEST_DIR")).join(rel);
431
+ append_source_lines(&root, Path::new(env!("CARGO_MANIFEST_DIR")), &mut out);
432
+ out
433
+ }
434
+
435
+ fn append_source_lines(path: &Path, base: &Path, out: &mut Vec<(String, usize, String)>) {
436
+ if path.is_dir() {
437
+ let mut entries = std::fs::read_dir(path)
438
+ .expect("read source dir")
439
+ .map(|entry| entry.expect("read source entry").path())
440
+ .collect::<Vec<PathBuf>>();
441
+ entries.sort();
442
+ for entry in entries {
443
+ append_source_lines(&entry, base, out);
444
+ }
445
+ return;
446
+ }
447
+ if path.extension().and_then(|v| v.to_str()) != Some("rs") {
448
+ return;
449
+ }
450
+ let rel = path
451
+ .strip_prefix(base)
452
+ .unwrap_or(path)
453
+ .to_string_lossy()
454
+ .to_string();
455
+ let text = std::fs::read_to_string(path).expect("read source file");
456
+ for (idx, line) in text.lines().enumerate() {
457
+ out.push((rel.clone(), idx + 1, line.trim().to_string()));
458
+ }
459
+ }