@team-agent/installer 0.5.61 → 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 (250) hide show
  1. package/Cargo.lock +1 -1
  2. package/Cargo.toml +1 -1
  3. package/crates/team-agent/src/cli/adapters.rs +5 -2
  4. package/crates/team-agent/src/cli/attach_app_server_leader.rs +1 -0
  5. package/crates/team-agent/src/cli/diagnose.rs +1 -0
  6. package/crates/team-agent/src/cli/emit.rs +41 -7
  7. package/crates/team-agent/src/cli/helpers.rs +1 -0
  8. package/crates/team-agent/src/cli/leader.rs +6 -1
  9. package/crates/team-agent/src/cli/leaders.rs +2 -0
  10. package/crates/team-agent/src/cli/mod.rs +33 -3
  11. package/crates/team-agent/src/cli/named_address.rs +8 -1
  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 +1 -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 +1 -0
  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/tests/verb_profile.rs +38 -0
  25. package/crates/team-agent/src/cli/types.rs +3 -2
  26. package/crates/team-agent/src/communication_mode/mod.rs +1 -0
  27. package/crates/team-agent/src/compiler.rs +1 -0
  28. package/crates/team-agent/src/conpty/backend.rs +1 -0
  29. package/crates/team-agent/src/conpty/mod.rs +1 -0
  30. package/crates/team-agent/src/coordinator/backoff.rs +5 -8
  31. package/crates/team-agent/src/coordinator/conpty_shim.rs +3 -2
  32. package/crates/team-agent/src/coordinator/health.rs +1 -0
  33. package/crates/team-agent/src/coordinator/mod.rs +2 -2
  34. package/crates/team-agent/src/coordinator/orphan.rs +4 -116
  35. package/crates/team-agent/src/coordinator/runtime_detectors.rs +1 -0
  36. package/crates/team-agent/src/coordinator/runtime_observation.rs +1 -0
  37. package/crates/team-agent/src/coordinator/steps/abnormal.rs +6 -5
  38. package/crates/team-agent/src/coordinator/steps/delivery.rs +1 -0
  39. package/crates/team-agent/src/coordinator/steps/health_sync.rs +1 -0
  40. package/crates/team-agent/src/coordinator/steps/mod.rs +2 -0
  41. package/crates/team-agent/src/coordinator/steps/persist.rs +1 -0
  42. package/crates/team-agent/src/coordinator/steps/runtime_prompts.rs +1 -0
  43. package/crates/team-agent/src/coordinator/steps/session_gate.rs +1 -0
  44. package/crates/team-agent/src/coordinator/tests/abnormal.rs +0 -174
  45. package/crates/team-agent/src/coordinator/tests/api_error_recovery.rs +0 -9
  46. package/crates/team-agent/src/coordinator/tests/basics.rs +0 -184
  47. package/crates/team-agent/src/coordinator/tests/mod.rs +2 -17
  48. package/crates/team-agent/src/coordinator/tests/tick_core.rs +0 -42
  49. package/crates/team-agent/src/coordinator/tick.rs +24 -28
  50. package/crates/team-agent/src/coordinator/types.rs +3 -176
  51. package/crates/team-agent/src/db/agent_health_capture.rs +1 -0
  52. package/crates/team-agent/src/db/message_store.rs +2 -1
  53. package/crates/team-agent/src/db/migration.rs +5 -4
  54. package/crates/team-agent/src/db/mod.rs +1 -0
  55. package/crates/team-agent/src/db/schema.rs +1 -0
  56. package/crates/team-agent/src/diagnose/comms.rs +2 -1
  57. package/crates/team-agent/src/diagnose/mod.rs +1 -0
  58. package/crates/team-agent/src/diagnose/orphans.rs +1 -0
  59. package/crates/team-agent/src/layout/manager.rs +3 -7
  60. package/crates/team-agent/src/layout/mod.rs +2 -2
  61. package/crates/team-agent/src/layout/overlay.rs +6 -1
  62. package/crates/team-agent/src/layout/placement.rs +1 -0
  63. package/crates/team-agent/src/layout/recovery.rs +3 -0
  64. package/crates/team-agent/src/layout/runtime_sessions.rs +8 -3
  65. package/crates/team-agent/src/layout/sessions.rs +8 -1
  66. package/crates/team-agent/src/layout/tmux_endpoint.rs +3 -0
  67. package/crates/team-agent/src/layout/worker_env.rs +3 -0
  68. package/crates/team-agent/src/layout/worker_window_helpers.rs +2 -0
  69. package/crates/team-agent/src/leader/helpers.rs +1 -0
  70. package/crates/team-agent/src/leader/incident.rs +1 -0
  71. package/crates/team-agent/src/leader/lease.rs +27 -22
  72. package/crates/team-agent/src/leader/mod.rs +2 -3
  73. package/crates/team-agent/src/leader/owner_bind.rs +13 -3
  74. package/crates/team-agent/src/leader/provider_attribution.rs +1 -0
  75. package/crates/team-agent/src/leader/rediscover.rs +4 -17
  76. package/crates/team-agent/src/leader/registry.rs +3 -15
  77. package/crates/team-agent/src/leader/start.rs +373 -125
  78. package/crates/team-agent/src/leader/takeover.rs +10 -232
  79. package/crates/team-agent/src/leader/tests/claim_leader_mailbox_flush_contract.rs +544 -0
  80. package/crates/team-agent/src/leader/tests/historical_inventory_upgrade_gate_red.rs +624 -0
  81. package/crates/team-agent/src/leader/tests/identity.rs +7 -2
  82. package/crates/team-agent/src/leader/tests/idle.rs +0 -193
  83. package/crates/team-agent/src/leader/tests/lease_api.rs +0 -45
  84. package/crates/team-agent/src/leader/tests/mod.rs +4 -41
  85. package/crates/team-agent/src/leader/tests/rehomed_env.rs +83 -0
  86. package/crates/team-agent/src/leader/tests/team_in_team_state_scope_red.rs +1273 -0
  87. package/crates/team-agent/src/leader/tests/terminal_and_replay_vs_rerender_invariants_red.rs +417 -0
  88. package/crates/team-agent/src/leader/tests/wake_start_owner.rs +22 -103
  89. package/crates/team-agent/src/leader/types.rs +1 -28
  90. package/crates/team-agent/src/lib.rs +3 -0
  91. package/crates/team-agent/src/lifecycle/display.rs +7 -1
  92. package/crates/team-agent/src/lifecycle/helpers.rs +3 -1
  93. package/crates/team-agent/src/lifecycle/launch/add_agent.rs +2 -2
  94. package/crates/team-agent/src/lifecycle/launch/fork_agent/completion.rs +1 -0
  95. package/crates/team-agent/src/lifecycle/launch/fork_entry.rs +1 -0
  96. package/crates/team-agent/src/lifecycle/launch/fork_finalize.rs +1 -0
  97. package/crates/team-agent/src/lifecycle/launch/plan.rs +2 -2
  98. package/crates/team-agent/src/lifecycle/launch/quick_start.rs +4 -26
  99. package/crates/team-agent/src/lifecycle/launch/readiness.rs +0 -27
  100. package/crates/team-agent/src/lifecycle/launch/spawn.rs +1 -27
  101. package/crates/team-agent/src/lifecycle/launch/spec_state.rs +4 -32
  102. package/crates/team-agent/src/lifecycle/launch/state_projection.rs +1 -0
  103. package/crates/team-agent/src/lifecycle/launch.rs +11 -12
  104. package/crates/team-agent/src/lifecycle/mod.rs +2 -1
  105. package/crates/team-agent/src/lifecycle/restart/agent.rs +3 -3
  106. package/crates/team-agent/src/lifecycle/restart/orchestrator.rs +2 -2
  107. package/crates/team-agent/src/lifecycle/restart/rebuild.rs +13 -5
  108. package/crates/team-agent/src/lifecycle/restart/remove.rs +1 -1
  109. package/crates/team-agent/src/lifecycle/restart/selection.rs +3 -3
  110. package/crates/team-agent/src/lifecycle/restart.rs +13 -11
  111. package/crates/team-agent/src/lifecycle/tests/acceptance_b_batch_red.rs +1007 -0
  112. package/crates/team-agent/src/lifecycle/tests/b0_legacy_snapshot_nonauthority_contract.rs +265 -0
  113. package/crates/team-agent/src/lifecycle/tests/b0_reader_hideone_audit_contract.rs +459 -0
  114. package/crates/team-agent/src/lifecycle/tests/behavioral_diff_264_red.rs +849 -0
  115. package/crates/team-agent/src/lifecycle/tests/claude_compatible_config_red.rs +323 -0
  116. package/crates/team-agent/src/lifecycle/tests/claude_profile_launch_red.rs +423 -0
  117. package/crates/team-agent/src/lifecycle/tests/clone_fork_copilot_perms_red.rs +737 -0
  118. package/crates/team-agent/src/lifecycle/tests/codex_mcp_approval_inheritance_red.rs +1187 -0
  119. package/crates/team-agent/src/lifecycle/tests/codex_weak_window_attribution_red.rs +683 -0
  120. package/crates/team-agent/src/lifecycle/tests/communication_mode_runtime_contract_red.rs +394 -0
  121. package/crates/team-agent/src/lifecycle/tests/copilot_provider_red.rs +1856 -0
  122. package/crates/team-agent/src/lifecycle/tests/core_034_real_red.rs +917 -0
  123. package/crates/team-agent/src/lifecycle/tests/display_adaptive_red.rs +481 -0
  124. package/crates/team-agent/src/lifecycle/tests/f032_startup_prompt_best_effort_red.rs +301 -0
  125. package/crates/team-agent/src/lifecycle/tests/harvest2_a_batch_red.rs +516 -0
  126. package/crates/team-agent/src/lifecycle/tests/host_cotenant_death_p0_contract.rs +986 -0
  127. package/crates/team-agent/src/lifecycle/tests/lifecycle_rollback_red.rs +651 -0
  128. package/crates/team-agent/src/lifecycle/tests/main_preserved.rs +2 -0
  129. package/crates/team-agent/src/lifecycle/tests/quick_start_worker_readiness_red.rs +332 -0
  130. package/crates/team-agent/src/lifecycle/tests/realmachine_clusters_1_6_red.rs +846 -0
  131. package/crates/team-agent/src/lifecycle/tests/realmachine_residual_g1_g4_red.rs +648 -0
  132. package/crates/team-agent/src/lifecycle/tests/restart_build_before_destroy_0540_contract.rs +910 -0
  133. package/crates/team-agent/src/lifecycle/tests/restart_liveness_red.rs +630 -0
  134. package/crates/team-agent/src/lifecycle/tests/restart_rebind_hotfix_252_red.rs +1083 -0
  135. package/crates/team-agent/src/lifecycle/tests/restart_session_capture_red.rs +1677 -0
  136. package/crates/team-agent/src/lifecycle/tests/resume_recover_red.rs +410 -0
  137. package/crates/team-agent/src/lifecycle/tests/stale_team_saveconflict_contract.rs +428 -0
  138. package/crates/team-agent/src/lifecycle/tests/startup_latency_contract.rs +1032 -0
  139. package/crates/team-agent/src/lifecycle/tests/status_credential_redaction_contract.rs +869 -0
  140. package/crates/team-agent/src/lifecycle/tests/subprep_codex_trust_roundtrip_red.rs +1249 -0
  141. package/crates/team-agent/src/lifecycle/tests/swallow_batch4_semantics_red.rs +342 -0
  142. package/crates/team-agent/src/lifecycle/tests/team_in_team_identity_scope_red.rs +542 -0
  143. package/crates/team-agent/src/lifecycle/tests/team_in_team_sibling_quick_start_red.rs +1103 -0
  144. package/crates/team-agent/src/lifecycle/tests/team_in_team_state_scope_red.rs +1276 -0
  145. package/crates/team-agent/src/lifecycle/tests/team_key_retirement_roster_red.rs +145 -0
  146. package/crates/team-agent/src/lifecycle/tests/team_key_retirement_txn_red.rs +603 -0
  147. package/crates/team-agent/src/lifecycle/tests/test_isolation_escape_contract.rs +837 -0
  148. package/crates/team-agent/src/lifecycle/tests/upgrade_compat_0211_red.rs +928 -0
  149. package/crates/team-agent/src/lifecycle/tests/verify_rs031_window_consistency_red.rs +951 -0
  150. package/crates/team-agent/src/lifecycle/tests/worker_dangerous_bypass_argv_red.rs +327 -0
  151. package/crates/team-agent/src/lifecycle/tests/worker_spawn_env_red.rs +760 -0
  152. package/crates/team-agent/src/lifecycle/tests.rs +59 -0
  153. package/crates/team-agent/src/lifecycle/types.rs +0 -9
  154. package/crates/team-agent/src/mcp_server/helpers.rs +1 -0
  155. package/crates/team-agent/src/mcp_server/lifecycle_tools/mod.rs +1 -0
  156. package/crates/team-agent/src/mcp_server/lifecycle_tools/state_status.rs +1 -0
  157. package/crates/team-agent/src/mcp_server/mod.rs +1 -0
  158. package/crates/team-agent/src/mcp_server/normalize.rs +4 -3
  159. package/crates/team-agent/src/mcp_server/tools.rs +1 -0
  160. package/crates/team-agent/src/mcp_server/types.rs +1 -18
  161. package/crates/team-agent/src/mcp_server/wire.rs +5 -5
  162. package/crates/team-agent/src/messaging/activity.rs +1 -0
  163. package/crates/team-agent/src/messaging/address.rs +1 -0
  164. package/crates/team-agent/src/messaging/delivery.rs +4 -3
  165. package/crates/team-agent/src/messaging/helpers.rs +2 -1
  166. package/crates/team-agent/src/messaging/leader_channel.rs +1 -0
  167. package/crates/team-agent/src/messaging/leader_receiver.rs +2 -1
  168. package/crates/team-agent/src/messaging/mod.rs +10 -14
  169. package/crates/team-agent/src/messaging/peers.rs +2 -0
  170. package/crates/team-agent/src/messaging/persist.rs +3 -1
  171. package/crates/team-agent/src/messaging/presentation.rs +2 -1
  172. package/crates/team-agent/src/messaging/results.rs +1 -0
  173. package/crates/team-agent/src/messaging/scheduler.rs +1 -0
  174. package/crates/team-agent/src/messaging/selftest.rs +1 -1
  175. package/crates/team-agent/src/messaging/send.rs +41 -8
  176. package/crates/team-agent/src/messaging/tests/mod.rs +5 -0
  177. package/crates/team-agent/src/messaging/types.rs +2 -2
  178. package/crates/team-agent/src/messaging/watchers.rs +19 -13
  179. package/crates/team-agent/src/model/enums.rs +1 -0
  180. package/crates/team-agent/src/model/errors.rs +1 -0
  181. package/crates/team-agent/src/model/ids.rs +1 -0
  182. package/crates/team-agent/src/model/mod.rs +1 -0
  183. package/crates/team-agent/src/model/name_similarity.rs +1 -0
  184. package/crates/team-agent/src/model/pane_authority_refusal.rs +1 -0
  185. package/crates/team-agent/src/model/paths.rs +1 -0
  186. package/crates/team-agent/src/model/permissions.rs +3 -2
  187. package/crates/team-agent/src/model/routing.rs +1 -0
  188. package/crates/team-agent/src/model/spec.rs +1 -0
  189. package/crates/team-agent/src/model/task_graph.rs +1 -0
  190. package/crates/team-agent/src/model/yaml/tests.rs +1 -0
  191. package/crates/team-agent/src/model/yaml.rs +1 -0
  192. package/crates/team-agent/src/packaging/install.rs +9 -147
  193. package/crates/team-agent/src/packaging/migrate.rs +2 -0
  194. package/crates/team-agent/src/packaging/mod.rs +1 -0
  195. package/crates/team-agent/src/packaging/repair.rs +2 -0
  196. package/crates/team-agent/src/packaging/tests.rs +29 -218
  197. package/crates/team-agent/src/packaging/types.rs +8 -15
  198. package/crates/team-agent/src/platform/argv.rs +4 -0
  199. package/crates/team-agent/src/platform/errors.rs +10 -1
  200. package/crates/team-agent/src/platform/file_lock.rs +4 -157
  201. package/crates/team-agent/src/platform/mod.rs +0 -61
  202. package/crates/team-agent/src/platform/process.rs +1 -0
  203. package/crates/team-agent/src/provider/adapter.rs +1 -0
  204. package/crates/team-agent/src/provider/adapters/claude.rs +1 -0
  205. package/crates/team-agent/src/provider/adapters/claude_fork.rs +1 -0
  206. package/crates/team-agent/src/provider/adapters/codex.rs +1 -0
  207. package/crates/team-agent/src/provider/adapters/copilot.rs +1 -0
  208. package/crates/team-agent/src/provider/adapters/copilot_fork.rs +1 -0
  209. package/crates/team-agent/src/provider/adapters/fake.rs +1 -0
  210. package/crates/team-agent/src/provider/adapters/mod.rs +1 -0
  211. package/crates/team-agent/src/provider/approvals/mod.rs +1 -0
  212. package/crates/team-agent/src/provider/approvals/parsing.rs +2 -5
  213. package/crates/team-agent/src/provider/approvals/runtime_prompts.rs +6 -5
  214. package/crates/team-agent/src/provider/classify.rs +1 -0
  215. package/crates/team-agent/src/provider/faults.rs +1 -26
  216. package/crates/team-agent/src/provider/helpers.rs +1 -0
  217. package/crates/team-agent/src/provider/mod.rs +1 -1
  218. package/crates/team-agent/src/provider/session/capture.rs +1 -4
  219. package/crates/team-agent/src/provider/session/context_fork/claude.rs +1 -0
  220. package/crates/team-agent/src/provider/session/context_fork/codex.rs +1 -0
  221. package/crates/team-agent/src/provider/session/context_fork/outcome.rs +1 -0
  222. package/crates/team-agent/src/provider/session/context_fork.rs +1 -0
  223. package/crates/team-agent/src/provider/session/mod.rs +2 -4
  224. package/crates/team-agent/src/provider/session/resume.rs +2 -209
  225. package/crates/team-agent/src/provider/session_scan/claude.rs +1 -0
  226. package/crates/team-agent/src/provider/session_scan/codex.rs +1 -0
  227. package/crates/team-agent/src/provider/session_scan/common.rs +1 -0
  228. package/crates/team-agent/src/provider/session_scan/copilot.rs +1 -0
  229. package/crates/team-agent/src/provider/session_scan.rs +1 -42
  230. package/crates/team-agent/src/provider/startup_prompt.rs +1 -0
  231. package/crates/team-agent/src/provider/types.rs +1 -0
  232. package/crates/team-agent/src/provider/wire.rs +1 -0
  233. package/crates/team-agent/src/state/identity.rs +16 -5
  234. package/crates/team-agent/src/state/identity_keys.rs +1 -0
  235. package/crates/team-agent/src/state/mod.rs +2 -0
  236. package/crates/team-agent/src/state/owner_gate.rs +5 -0
  237. package/crates/team-agent/src/state/ownership.rs +10 -4
  238. package/crates/team-agent/src/state/paths.rs +12 -0
  239. package/crates/team-agent/src/state/persist.rs +9 -3
  240. package/crates/team-agent/src/state/projection.rs +15 -2
  241. package/crates/team-agent/src/state/repository/intent.rs +1 -0
  242. package/crates/team-agent/src/state/repository/tests.rs +1 -0
  243. package/crates/team-agent/src/state/repository.rs +7 -0
  244. package/crates/team-agent/src/state/selector.rs +1 -0
  245. package/crates/team-agent/src/tmux_backend/tests.rs +39 -0
  246. package/crates/team-agent/src/tmux_backend.rs +63 -0
  247. package/crates/team-agent/src/transport.rs +15 -0
  248. package/package.json +4 -4
  249. package/crates/team-agent/src/leader/inject.rs +0 -33
  250. package/crates/team-agent/src/provider/command.rs +0 -80
@@ -0,0 +1,423 @@
1
+ //! Claude compatible-api profile launch contracts for Batch A Lane 2.
2
+ //!
3
+ //! The entrypoints are lifecycle/CLI surfaces with a recording transport, plus the S0 public
4
+ //! `ProviderProfileLaunch` shape. Before S0 lands this file compile-reds on the shared type; after
5
+ //! S0 it behavior-reds on lifecycle/profile wiring.
6
+
7
+ #![allow(clippy::unwrap_used, clippy::expect_used, clippy::panic)]
8
+
9
+ #[path = "../../../tests/support/hermetic.rs"]
10
+ mod hermetic_guard;
11
+ #[allow(dead_code)]
12
+ fn _hermetic_boundary_marker(_: &hermetic_guard::HermeticTestEnv) {}
13
+
14
+ #[path = "../../../tests/support/composite_source.rs"]
15
+ mod composite_source;
16
+ use std::collections::{BTreeMap, BTreeSet};
17
+ use std::path::{Path, PathBuf};
18
+ use std::process::Command;
19
+ use std::sync::atomic::{AtomicU64, Ordering};
20
+ use std::sync::Mutex;
21
+
22
+ use serde_json::{json, Value};
23
+ use serial_test::serial;
24
+ use team_agent::lifecycle::quick_start_with_transport_in_workspace;
25
+ use team_agent::provider::{ProviderCommandOverrides, ProviderProfileLaunch};
26
+ use team_agent::state::persist::load_runtime_state;
27
+ use team_agent::transport::{
28
+ AttachOutcome, BackendKind, CaptureRange, CapturedText, InjectPayload, InjectReport,
29
+ InjectStage, InjectVerification, Key, PaneField, PaneId, PaneInfo, SessionName, SetEnvOutcome,
30
+ SpawnResult, SubmitVerification, Target, Transport, TransportError, TurnVerification,
31
+ WindowName,
32
+ };
33
+
34
+ #[test]
35
+ #[serial(env)]
36
+ fn compatible_api_profile_quick_start_spawns_claude_with_profile_env_and_state_metadata() {
37
+ assert_s0_profile_launch_shape();
38
+
39
+ let ws = tmp_dir("profile-launch");
40
+ let team = write_claude_profile_team(&ws, "claudeprof", "clauder");
41
+ let transport = RecordingTransport::default();
42
+
43
+ quick_start_with_transport_in_workspace(&ws, &team, None, true, Some("claudeprof"), &transport)
44
+ .expect(
45
+ "quick-start through recording transport should reach the real lifecycle spawn path",
46
+ );
47
+
48
+ let spawn = transport.single_spawn();
49
+ for (key, expected) in [
50
+ ("CLAUDE_CONFIG_DIR", None),
51
+ ("ANTHROPIC_BASE_URL", Some("https://llm.local/v1")),
52
+ ("ANTHROPIC_AUTH_TOKEN", Some("local-secret")),
53
+ ("ANTHROPIC_MODEL", Some("profile-effective-haiku")),
54
+ ] {
55
+ let got = spawn.env.get(key).map(String::as_str);
56
+ match expected {
57
+ Some(expected) => assert_eq!(
58
+ got,
59
+ Some(expected),
60
+ "Claude compatible_api profile launch must inject {key} from .team/current/profiles/local.env; env={:?}",
61
+ spawn.env
62
+ ),
63
+ None => assert!(
64
+ got.is_some_and(|value| !value.is_empty()),
65
+ "Claude compatible_api profile launch must inject non-empty {key}; env={:?}",
66
+ spawn.env
67
+ ),
68
+ }
69
+ }
70
+ assert!(
71
+ !spawn.env.contains_key("ANTHROPIC_API_KEY"),
72
+ "compatible_api must unset ANTHROPIC_API_KEY and use ANTHROPIC_AUTH_TOKEN instead; env={:?}",
73
+ spawn.env
74
+ );
75
+ assert!(
76
+ argv_contains_adjacent(&spawn.argv, &["--model", "profile-effective-haiku"]),
77
+ "profile model must become the effective Claude model when role model is null; argv={:?}",
78
+ spawn.argv
79
+ );
80
+
81
+ let state = load_runtime_state(&ws).unwrap();
82
+ let agent = &state["teams"]["claudeprof"]["agents"]["clauder"];
83
+ assert!(
84
+ agent["_pending_session_id"].as_str().is_some_and(|value| !value.is_empty()),
85
+ "lifecycle must persist CommandPlan.expected_session_id as agents[*]._pending_session_id; state={state}"
86
+ );
87
+ assert!(
88
+ agent["claude_projects_root"].as_str().is_some_and(|value| !value.is_empty()),
89
+ "lifecycle must persist CommandPlan.provider_projects_root/profile claude_projects_root for capture; state={state}"
90
+ );
91
+ }
92
+
93
+ #[ignore = "flaky under parallel suite, tracked"]
94
+ #[test]
95
+ #[serial(env)]
96
+ fn subscription_profile_keeps_default_claude_config_dir_for_logged_in_quota() {
97
+ let ws = tmp_dir("subscription-config");
98
+ let team = write_claude_subscription_profile_team(&ws, "subteam", "clauder");
99
+ let transport = RecordingTransport::default();
100
+
101
+ quick_start_with_transport_in_workspace(&ws, &team, None, true, Some("subteam"), &transport)
102
+ .expect("subscription profile should launch without managed config isolation");
103
+
104
+ let spawn = transport.single_spawn();
105
+ assert!(
106
+ !spawn.env.contains_key("CLAUDE_CONFIG_DIR"),
107
+ "subscription Claude workers must inherit the user's default ~/.claude login state; env={:?}",
108
+ spawn.env
109
+ );
110
+ assert!(
111
+ !spawn.env.contains_key("ANTHROPIC_API_KEY")
112
+ && !spawn.env.contains_key("ANTHROPIC_AUTH_TOKEN"),
113
+ "subscription launch must not switch into API-token auth via profile env; env={:?}",
114
+ spawn.env
115
+ );
116
+
117
+ let state = load_runtime_state(&ws).unwrap();
118
+ let agent = &state["teams"]["subteam"]["agents"]["clauder"];
119
+ assert_eq!(
120
+ agent.get("claude_projects_root"),
121
+ None,
122
+ "without a supported fine-grained Claude projects-root env, subscription workers must not fake an isolated transcript root; state={state}"
123
+ );
124
+ }
125
+
126
+ #[test]
127
+ fn launch_restart_start_add_and_fork_all_delegate_to_the_profile_launch_resolver() {
128
+ let launch = source("src/lifecycle/launch.rs");
129
+ let restart_common = source("src/lifecycle/restart/common.rs");
130
+ let restart_agent = source("src/lifecycle/restart/agent.rs");
131
+
132
+ let surfaces = [
133
+ ("launch quick-start", &launch, "spawn_agents"),
134
+ ("add-agent", &launch, "add_agent_with_transport"),
135
+ ("fork-agent", &launch, "fork_agent_with_transport"),
136
+ ("restart", &restart_common, "restart_with_transport"),
137
+ ("start-agent", &restart_agent, "start_agent_at_paths"),
138
+ ];
139
+ for (surface, source, entry) in surfaces {
140
+ let section = source
141
+ .find(entry)
142
+ .map(|idx| &source[idx..])
143
+ .unwrap_or(source.as_str());
144
+ assert!(
145
+ section.contains("prepare_provider_profile_launch"),
146
+ "{surface} must call the single profile resolver before building/spawning provider argv; entry={entry}"
147
+ );
148
+ }
149
+ }
150
+
151
+ #[test]
152
+ fn diagnose_missing_profile_is_rc1_ok_false_and_zero_token() {
153
+ let ws = tmp_dir("diagnose-missing-profile");
154
+ let team = write_claude_profile_team(&ws, "diagteam", "clauder");
155
+ std::fs::remove_file(
156
+ ws.join(".team")
157
+ .join("current")
158
+ .join("profiles")
159
+ .join("local.env"),
160
+ )
161
+ .unwrap();
162
+
163
+ let output = Command::new(crate::lifecycle::tests::test_binary_path())
164
+ .args(["diagnose", "--workspace", ws.to_str().unwrap(), "--json"])
165
+ .current_dir(&team)
166
+ .output()
167
+ .expect("diagnose subprocess should run");
168
+ let stdout = String::from_utf8_lossy(&output.stdout);
169
+ let stderr = String::from_utf8_lossy(&output.stderr);
170
+ let json = serde_json::from_str::<Value>(stdout.trim()).unwrap_or_else(|_| json!({}));
171
+
172
+ assert!(
173
+ !output.status.success(),
174
+ "diagnose with missing referenced profile must exit non-zero before any token/provider call; stdout={stdout} stderr={stderr}"
175
+ );
176
+ assert_eq!(
177
+ json["ok"],
178
+ json!(false),
179
+ "diagnose missing profile must emit ok:false JSON; stdout={stdout} stderr={stderr}"
180
+ );
181
+ assert!(
182
+ stdout.contains("profile") || stderr.contains("profile"),
183
+ "diagnose missing profile must name the profile problem without invoking Claude; stdout={stdout} stderr={stderr}"
184
+ );
185
+ assert!(
186
+ !stdout.contains("tokens") && !stderr.contains("tokens"),
187
+ "diagnose dry-run must not consume provider tokens or report token usage; stdout={stdout} stderr={stderr}"
188
+ );
189
+ }
190
+
191
+ fn assert_s0_profile_launch_shape() {
192
+ let profile = ProviderProfileLaunch {
193
+ env_overlay: BTreeMap::from([(
194
+ "ANTHROPIC_MODEL".to_string(),
195
+ "profile-effective-haiku".to_string(),
196
+ )]),
197
+ env_unset: BTreeSet::from(["ANTHROPIC_API_KEY".to_string()]),
198
+ command_overrides: ProviderCommandOverrides {
199
+ model: Some("profile-effective-haiku".to_string()),
200
+ ..ProviderCommandOverrides::default()
201
+ },
202
+ claude_config_dir: Some(PathBuf::from("/tmp/claude-config")),
203
+ claude_projects_root: Some(PathBuf::from("/tmp/claude-config/projects")),
204
+ managed_mcp_config: true,
205
+ };
206
+ assert!(profile.managed_mcp_config);
207
+ }
208
+
209
+ fn write_claude_profile_team(ws: &Path, team_key: &str, agent_id: &str) -> PathBuf {
210
+ let team = ws.join(team_key);
211
+ std::fs::create_dir_all(team.join("agents")).unwrap();
212
+ std::fs::create_dir_all(ws.join(".team").join("current").join("profiles")).unwrap();
213
+ std::fs::write(
214
+ ws.join(".team").join("current").join("profiles").join("local.env"),
215
+ "ANTHROPIC_BASE_URL=https://llm.local/v1\nANTHROPIC_AUTH_TOKEN=local-secret\nANTHROPIC_MODEL=profile-effective-haiku\nANTHROPIC_API_KEY=\n",
216
+ )
217
+ .unwrap();
218
+ std::fs::write(
219
+ team.join("TEAM.md"),
220
+ format!(
221
+ "---\nname: {team_key}\nobjective: Claude compatible profile launch contract.\nprovider: claude\nauth_mode: compatible_api\n---\n\nTeam.\n"
222
+ ),
223
+ )
224
+ .unwrap();
225
+ std::fs::write(
226
+ team.join("agents").join(format!("{agent_id}.md")),
227
+ format!(
228
+ "---\nname: {agent_id}\nrole: Claude Worker\nprovider: claude\nauth_mode: compatible_api\nprofile: local\nmodel: null\ntools:\n - mcp_team\n---\n\nWorker.\n"
229
+ ),
230
+ )
231
+ .unwrap();
232
+ team
233
+ }
234
+
235
+ fn write_claude_subscription_profile_team(ws: &Path, team_key: &str, agent_id: &str) -> PathBuf {
236
+ let team = ws.join(team_key);
237
+ std::fs::create_dir_all(team.join("agents")).unwrap();
238
+ std::fs::create_dir_all(ws.join(".team").join("current").join("profiles")).unwrap();
239
+ std::fs::write(
240
+ ws.join(".team")
241
+ .join("current")
242
+ .join("profiles")
243
+ .join("local.env"),
244
+ "AUTH_MODE=subscription\nMODEL=claude-sonnet-4-6\n",
245
+ )
246
+ .unwrap();
247
+ std::fs::write(
248
+ team.join("TEAM.md"),
249
+ format!(
250
+ "---\nname: {team_key}\nobjective: Claude subscription profile launch contract.\nprovider: claude\nauth_mode: subscription\n---\n\nTeam.\n"
251
+ ),
252
+ )
253
+ .unwrap();
254
+ std::fs::write(
255
+ team.join("agents").join(format!("{agent_id}.md")),
256
+ format!(
257
+ "---\nname: {agent_id}\nrole: Claude Worker\nprovider: claude\nauth_mode: subscription\nprofile: local\nmodel: null\ntools:\n - mcp_team\n---\n\nWorker.\n"
258
+ ),
259
+ )
260
+ .unwrap();
261
+ team
262
+ }
263
+
264
+ fn source(path: &str) -> String {
265
+ composite_source::composite_source(path)
266
+ }
267
+
268
+ fn argv_contains_adjacent(hay: &[String], needle: &[&str]) -> bool {
269
+ hay.windows(needle.len())
270
+ .any(|window| window.iter().map(String::as_str).eq(needle.iter().copied()))
271
+ }
272
+
273
+ fn tmp_dir(tag: &str) -> PathBuf {
274
+ static N: AtomicU64 = AtomicU64::new(0);
275
+ let dir = std::env::temp_dir().join(format!(
276
+ "ta-rs-claude-profile-launch-{tag}-{}-{}",
277
+ std::process::id(),
278
+ N.fetch_add(1, Ordering::Relaxed)
279
+ ));
280
+ let _ = std::fs::remove_dir_all(&dir);
281
+ std::fs::create_dir_all(&dir).unwrap();
282
+ std::fs::canonicalize(dir).unwrap()
283
+ }
284
+
285
+ #[derive(Debug, Clone)]
286
+ struct RecordedSpawn {
287
+ argv: Vec<String>,
288
+ env: BTreeMap<String, String>,
289
+ }
290
+
291
+ #[derive(Debug, Default)]
292
+ struct RecordingTransport {
293
+ spawns: Mutex<Vec<RecordedSpawn>>,
294
+ }
295
+
296
+ impl RecordingTransport {
297
+ fn single_spawn(&self) -> RecordedSpawn {
298
+ let spawns = self.spawns.lock().unwrap();
299
+ assert_eq!(
300
+ spawns.len(),
301
+ 1,
302
+ "fixture should record one Claude worker spawn; spawns={spawns:?}"
303
+ );
304
+ spawns[0].clone()
305
+ }
306
+ }
307
+
308
+ impl Transport for RecordingTransport {
309
+ fn kind(&self) -> BackendKind {
310
+ BackendKind::Tmux
311
+ }
312
+
313
+ fn spawn_first(
314
+ &self,
315
+ session: &SessionName,
316
+ window: &WindowName,
317
+ argv: &[String],
318
+ _cwd: &Path,
319
+ env: &BTreeMap<String, String>,
320
+ ) -> Result<SpawnResult, TransportError> {
321
+ self.spawn_into(session, window, argv, _cwd, env)
322
+ }
323
+
324
+ fn spawn_into(
325
+ &self,
326
+ session: &SessionName,
327
+ window: &WindowName,
328
+ argv: &[String],
329
+ _cwd: &Path,
330
+ env: &BTreeMap<String, String>,
331
+ ) -> Result<SpawnResult, TransportError> {
332
+ let mut spawns = self.spawns.lock().unwrap();
333
+ spawns.push(RecordedSpawn {
334
+ argv: argv.to_vec(),
335
+ env: env.clone(),
336
+ });
337
+ Ok(SpawnResult {
338
+ pane_id: PaneId::new(format!("%{}", spawns.len())),
339
+ session: session.clone(),
340
+ window: window.clone(),
341
+ child_pid: Some(10_000 + spawns.len() as u32),
342
+ })
343
+ }
344
+
345
+ fn inject(
346
+ &self,
347
+ _target: &Target,
348
+ _payload: &InjectPayload,
349
+ _submit: Key,
350
+ _bracketed: bool,
351
+ ) -> Result<InjectReport, TransportError> {
352
+ Ok(InjectReport {
353
+ stage_reached: InjectStage::Submit,
354
+ inject_verification: InjectVerification::CaptureContainsToken,
355
+ submit_verification: SubmitVerification::EnterSentWithoutPlaceholderCheck,
356
+ turn_verification: TurnVerification::NotYetObserved,
357
+ attempts: 1,
358
+ submit_diagnostics: None,
359
+ })
360
+ }
361
+
362
+ fn send_keys(&self, _target: &Target, _keys: &[Key]) -> Result<(), TransportError> {
363
+ Ok(())
364
+ }
365
+
366
+ fn capture(
367
+ &self,
368
+ _target: &Target,
369
+ range: CaptureRange,
370
+ ) -> Result<CapturedText, TransportError> {
371
+ Ok(CapturedText {
372
+ text: String::new(),
373
+ range,
374
+ })
375
+ }
376
+
377
+ fn query(&self, _target: &Target, field: PaneField) -> Result<Option<String>, TransportError> {
378
+ match field {
379
+ PaneField::PaneWidth => Ok(Some("120".to_string())),
380
+ _ => Ok(None),
381
+ }
382
+ }
383
+
384
+ fn liveness(
385
+ &self,
386
+ _pane: &PaneId,
387
+ ) -> Result<team_agent::transport::PaneLiveness, TransportError> {
388
+ Ok(team_agent::transport::PaneLiveness::Live)
389
+ }
390
+
391
+ fn list_targets(&self) -> Result<Vec<PaneInfo>, TransportError> {
392
+ Ok(Vec::new())
393
+ }
394
+
395
+ fn has_session(&self, _session: &SessionName) -> Result<bool, TransportError> {
396
+ Ok(false)
397
+ }
398
+
399
+ fn list_windows(&self, _session: &SessionName) -> Result<Vec<WindowName>, TransportError> {
400
+ Ok(Vec::new())
401
+ }
402
+
403
+ fn set_session_env(
404
+ &self,
405
+ _session: &SessionName,
406
+ _key: &str,
407
+ _value: &str,
408
+ ) -> Result<SetEnvOutcome, TransportError> {
409
+ Ok(SetEnvOutcome::Applied)
410
+ }
411
+
412
+ fn kill_session(&self, _session: &SessionName) -> Result<(), TransportError> {
413
+ Ok(())
414
+ }
415
+
416
+ fn kill_window(&self, _target: &Target) -> Result<(), TransportError> {
417
+ Ok(())
418
+ }
419
+
420
+ fn attach_session(&self, _session: &SessionName) -> Result<AttachOutcome, TransportError> {
421
+ Ok(AttachOutcome::Attached)
422
+ }
423
+ }