@team-agent/installer 0.5.126 → 0.5.128

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 (187) hide show
  1. package/Cargo.lock +1 -1
  2. package/Cargo.toml +1 -1
  3. package/README.md +11 -0
  4. package/crates/team-agent/src/cli/adapters.rs +3 -13
  5. package/crates/team-agent/src/cli/arguments.rs +4 -0
  6. package/crates/team-agent/src/cli/diagnose.rs +68 -91
  7. package/crates/team-agent/src/cli/emit.rs +61 -28
  8. package/crates/team-agent/src/cli/grok_slot.rs +88 -3
  9. package/crates/team-agent/src/cli/intent/runtime.rs +38 -9
  10. package/crates/team-agent/src/cli/intent/runtime_tests.rs +147 -11
  11. package/crates/team-agent/src/cli/intent/tests.rs +10 -12
  12. package/crates/team-agent/src/cli/intent.rs +1 -1
  13. package/crates/team-agent/src/cli/mod.rs +38 -9
  14. package/crates/team-agent/src/cli/models.rs +789 -186
  15. package/crates/team-agent/src/cli/schedule.rs +175 -0
  16. package/crates/team-agent/src/cli/send/persist.rs +0 -36
  17. package/crates/team-agent/src/cli/send/presentation.rs +1 -1
  18. package/crates/team-agent/src/cli/send.rs +108 -110
  19. package/crates/team-agent/src/cli/spec.rs +6 -0
  20. package/crates/team-agent/src/cli/status_port/brief.rs +5 -67
  21. package/crates/team-agent/src/cli/tests/leader_watch.rs +12 -62
  22. package/crates/team-agent/src/cli/tests/mod.rs +3 -3
  23. package/crates/team-agent/src/cli/tests/named_address.rs +11 -10
  24. package/crates/team-agent/src/cli/tests/run_delegation.rs +12 -9
  25. package/crates/team-agent/src/cli/tests/status_send.rs +70 -273
  26. package/crates/team-agent/src/compiler/tests.rs +39 -27
  27. package/crates/team-agent/src/compiler.rs +206 -6
  28. package/crates/team-agent/src/contract_runtime/backend.rs +181 -11
  29. package/crates/team-agent/src/contract_runtime/commands.rs +338 -7
  30. package/crates/team-agent/src/contract_runtime/config.rs +30 -19
  31. package/crates/team-agent/src/contract_runtime/config_tests.rs +24 -4
  32. package/crates/team-agent/src/contract_runtime/discovery.rs +12 -1
  33. package/crates/team-agent/src/contract_runtime/fork.rs +3 -10
  34. package/crates/team-agent/src/contract_runtime/framework.rs +28 -14
  35. package/crates/team-agent/src/contract_runtime/mcp.rs +19 -24
  36. package/crates/team-agent/src/contract_runtime/prompt.rs +2 -2
  37. package/crates/team-agent/src/contract_runtime/registry.rs +93 -130
  38. package/crates/team-agent/src/coordinator/steps/abnormal.rs +45 -5
  39. package/crates/team-agent/src/coordinator/tests/api_error_recovery.rs +8 -29
  40. package/crates/team-agent/src/coordinator/tests/energy.rs +4 -4
  41. package/crates/team-agent/src/coordinator/tests/health_sync.rs +44 -2
  42. package/crates/team-agent/src/coordinator/tests/main_preserved.rs +2 -2
  43. package/crates/team-agent/src/coordinator/tests/spine.rs +1 -1
  44. package/crates/team-agent/src/coordinator/tests/takeover.rs +3 -3
  45. package/crates/team-agent/src/coordinator/tick.rs +1 -89
  46. package/crates/team-agent/src/db/message_store.rs +7 -65
  47. package/crates/team-agent/src/direct_delivery.rs +368 -0
  48. package/crates/team-agent/src/inbox_store.rs +169 -0
  49. package/crates/team-agent/src/leader/registry.rs +5 -0
  50. package/crates/team-agent/src/leader/start.rs +2 -1
  51. package/crates/team-agent/src/leader/tests/lease_api.rs +2 -2
  52. package/crates/team-agent/src/leader/tests/prompt_contract.rs +1 -0
  53. package/crates/team-agent/src/lib.rs +2 -0
  54. package/crates/team-agent/src/lifecycle/launch/add_agent.rs +33 -0
  55. package/crates/team-agent/src/lifecycle/launch/add_agent_state.rs +206 -1
  56. package/crates/team-agent/src/lifecycle/launch/clone_agent.rs +28 -2
  57. package/crates/team-agent/src/lifecycle/launch/fork_agent.rs +36 -179
  58. package/crates/team-agent/src/lifecycle/launch/fork_entry.rs +87 -6
  59. package/crates/team-agent/src/lifecycle/launch/mcp_config.rs +13 -488
  60. package/crates/team-agent/src/lifecycle/launch/pi_mcp.rs +351 -81
  61. package/crates/team-agent/src/lifecycle/launch/pi_mcp_extension.js +3 -4
  62. package/crates/team-agent/src/lifecycle/launch/quick_start.rs +26 -2
  63. package/crates/team-agent/src/lifecycle/launch/spawn.rs +41 -31
  64. package/crates/team-agent/src/lifecycle/launch.rs +27 -12
  65. package/crates/team-agent/src/lifecycle/profile_launch.rs +318 -64
  66. package/crates/team-agent/src/lifecycle/restart/agent.rs +1 -0
  67. package/crates/team-agent/src/lifecycle/restart/avatar.rs +1798 -0
  68. package/crates/team-agent/src/lifecycle/restart/claude_fork.rs +163 -0
  69. package/crates/team-agent/src/lifecycle/restart/common.rs +298 -133
  70. package/crates/team-agent/src/lifecycle/restart/remove.rs +129 -0
  71. package/crates/team-agent/src/lifecycle/restart/selection.rs +5 -5
  72. package/crates/team-agent/src/lifecycle/restart.rs +4 -0
  73. package/crates/team-agent/src/lifecycle/role_config.rs +79 -27
  74. package/crates/team-agent/src/lifecycle/tests/acceptance_b_batch_red.rs +1 -1
  75. package/crates/team-agent/src/lifecycle/tests/agent_ops.rs +8 -12
  76. package/crates/team-agent/src/lifecycle/tests/behavioral_diff_264_red.rs +37 -240
  77. package/crates/team-agent/src/lifecycle/tests/claude_compatible_config_red.rs +325 -0
  78. package/crates/team-agent/src/lifecycle/tests/claude_profile_launch_red.rs +320 -8
  79. package/crates/team-agent/src/lifecycle/tests/cli_argv_routing_red.rs +329 -70
  80. package/crates/team-agent/src/lifecycle/tests/clone_fork_copilot_perms_red.rs +378 -4
  81. package/crates/team-agent/src/lifecycle/tests/communication_mode_runtime_contract_red.rs +25 -39
  82. package/crates/team-agent/src/lifecycle/tests/copilot_provider_red.rs +7 -11
  83. package/crates/team-agent/src/lifecycle/tests/core.rs +39 -36
  84. package/crates/team-agent/src/lifecycle/tests/f032_startup_prompt_best_effort_red.rs +22 -8
  85. package/crates/team-agent/src/lifecycle/tests/fixtures/pi_native_mcp_host.mjs +2 -1
  86. package/crates/team-agent/src/lifecycle/tests/grok_require_explicit_model_red.rs +15 -133
  87. package/crates/team-agent/src/lifecycle/tests/harvest2_a_batch_red.rs +60 -20
  88. package/crates/team-agent/src/lifecycle/tests/host_cotenant_death_p0_contract.rs +30 -67
  89. package/crates/team-agent/src/lifecycle/tests/issue238_codex_effort_contract.rs +3 -31
  90. package/crates/team-agent/src/lifecycle/tests/lane_ops.rs +194 -169
  91. package/crates/team-agent/src/lifecycle/tests/launch_spawn.rs +164 -282
  92. package/crates/team-agent/src/lifecycle/tests/lifecycle_rollback_red.rs +15 -78
  93. package/crates/team-agent/src/lifecycle/tests/main_preserved.rs +7 -7
  94. package/crates/team-agent/src/lifecycle/tests/mcp_tool_name_format_red.rs +6 -6
  95. package/crates/team-agent/src/lifecycle/tests/phase_b_contracts.rs +75 -69
  96. package/crates/team-agent/src/lifecycle/tests/phase_golden.rs +2 -10
  97. package/crates/team-agent/src/lifecycle/tests/pi_catalog_red.rs +18 -6
  98. package/crates/team-agent/src/lifecycle/tests/pi_command_red.rs +70 -52
  99. package/crates/team-agent/src/lifecycle/tests/pi_compiler_red.rs +210 -0
  100. package/crates/team-agent/src/lifecycle/tests/pi_dual_entry_red.rs +157 -4
  101. package/crates/team-agent/src/lifecycle/tests/pi_executable_mcp_red.rs +526 -10
  102. package/crates/team-agent/src/lifecycle/tests/pi_fork_session_inheritance_red.rs +1419 -0
  103. package/crates/team-agent/src/lifecycle/tests/pi_lifecycle_doctor_red.rs +68 -1
  104. package/crates/team-agent/src/lifecycle/tests/pi_native_mcp_capability_red.rs +34 -12
  105. package/crates/team-agent/src/lifecycle/tests/pi_session_delivery_red.rs +94 -2
  106. package/crates/team-agent/src/lifecycle/tests/quick_start_worker_readiness_red.rs +14 -15
  107. package/crates/team-agent/src/lifecycle/tests/restart.rs +12 -153
  108. package/crates/team-agent/src/lifecycle/tests/restart_build_before_destroy_0540_contract.rs +27 -5
  109. package/crates/team-agent/src/lifecycle/tests/restart_liveness_red.rs +59 -10
  110. package/crates/team-agent/src/lifecycle/tests/restart_rebind_hotfix_252_red.rs +47 -6
  111. package/crates/team-agent/src/lifecycle/tests/restart_session_capture_red.rs +3 -1374
  112. package/crates/team-agent/src/lifecycle/tests/resume_recover_red.rs +27 -10
  113. package/crates/team-agent/src/lifecycle/tests/status_credential_redaction_contract.rs +7 -7
  114. package/crates/team-agent/src/lifecycle/tests/subprep_codex_trust_roundtrip_red.rs +67 -313
  115. package/crates/team-agent/src/lifecycle/tests/swallow_batch4_semantics_red.rs +254 -2
  116. package/crates/team-agent/src/lifecycle/tests/team_in_team_identity_scope_red.rs +2 -2
  117. package/crates/team-agent/src/lifecycle/tests/team_in_team_sibling_quick_start_red.rs +1 -1
  118. package/crates/team-agent/src/lifecycle/tests/team_in_team_state_scope_red.rs +2 -2
  119. package/crates/team-agent/src/lifecycle/tests/team_key_retirement_txn_red.rs +4 -4
  120. package/crates/team-agent/src/lifecycle/tests/upgrade_compat_0211_red.rs +74 -19
  121. package/crates/team-agent/src/lifecycle/tests/verify_rs031_window_consistency_red.rs +38 -39
  122. package/crates/team-agent/src/lifecycle/tests/worker_spawn_env_red.rs +51 -88
  123. package/crates/team-agent/src/lifecycle/tests.rs +3 -4
  124. package/crates/team-agent/src/lifecycle/types.rs +18 -5
  125. package/crates/team-agent/src/lifecycle/worker_command_context.rs +43 -50
  126. package/crates/team-agent/src/mcp_server/readiness.rs +130 -149
  127. package/crates/team-agent/src/mcp_server/readiness_tests.rs +86 -109
  128. package/crates/team-agent/src/mcp_server/tests/scoped.rs +21 -31
  129. package/crates/team-agent/src/mcp_server/tests/send.rs +72 -107
  130. package/crates/team-agent/src/mcp_server/tests/tools.rs +10 -12
  131. package/crates/team-agent/src/mcp_server/tools.rs +70 -196
  132. package/crates/team-agent/src/messaging/delivery.rs +143 -253
  133. package/crates/team-agent/src/messaging/delivery_consumption_tests.rs +5 -5
  134. package/crates/team-agent/src/messaging/helpers.rs +1 -19
  135. package/crates/team-agent/src/messaging/mod.rs +1 -0
  136. package/crates/team-agent/src/messaging/reminders.rs +316 -0
  137. package/crates/team-agent/src/messaging/scheduler.rs +7 -1
  138. package/crates/team-agent/src/messaging/tests/dup_inject.rs +255 -150
  139. package/crates/team-agent/src/messaging/tests/main_preserved.rs +2 -2
  140. package/crates/team-agent/src/messaging/tests/runtime.rs +9 -115
  141. package/crates/team-agent/src/messaging/tests/spine.rs +44 -24
  142. package/crates/team-agent/src/messaging/tests/wave2.rs +13 -20
  143. package/crates/team-agent/src/messaging/types.rs +1 -0
  144. package/crates/team-agent/src/provider/adapter.rs +208 -254
  145. package/crates/team-agent/src/provider/adapters/claude.rs +78 -0
  146. package/crates/team-agent/src/provider/adapters/claude_fork.rs +131 -0
  147. package/crates/team-agent/src/provider/adapters/mod.rs +7 -7
  148. package/crates/team-agent/src/provider/adapters/pi.rs +106 -0
  149. package/crates/team-agent/src/provider/classify.rs +1 -66
  150. package/crates/team-agent/src/provider/model_catalog.rs +201 -13
  151. package/crates/team-agent/src/provider/session/capture.rs +111 -111
  152. package/crates/team-agent/src/provider/session/context_fork/claude.rs +123 -0
  153. package/crates/team-agent/src/provider/session/context_fork/outcome.rs +10 -18
  154. package/crates/team-agent/src/provider/session/context_fork.rs +87 -74
  155. package/crates/team-agent/src/provider/session/mod.rs +2 -3
  156. package/crates/team-agent/src/provider/session_scan/claude.rs +523 -0
  157. package/crates/team-agent/src/provider/session_scan/common.rs +47 -47
  158. package/crates/team-agent/src/provider/session_scan/pi.rs +34 -1
  159. package/crates/team-agent/src/provider/session_scan.rs +13 -13
  160. package/crates/team-agent/src/provider/tests/adapter.rs +127 -121
  161. package/crates/team-agent/src/provider/tests/classify.rs +0 -53
  162. package/crates/team-agent/src/provider/tests/command_helpers.rs +11 -19
  163. package/crates/team-agent/src/provider/tests/idle.rs +13 -19
  164. package/crates/team-agent/src/provider/types.rs +0 -4
  165. package/crates/team-agent/src/provider/wire.rs +34 -20
  166. package/crates/team-agent/src/state/abnormal_watch/tests/mod.rs +1 -1
  167. package/crates/team-agent/src/state/persist.rs +6 -6
  168. package/crates/team-agent/src/state/projection.rs +1 -1
  169. package/crates/team-agent/src/state/repository/tests.rs +2 -2
  170. package/crates/team-agent/src/test_support/models_timeout_fixture.rs +144 -0
  171. package/crates/team-agent/src/tmux_backend/tests.rs +0 -151
  172. package/crates/team-agent/src/tmux_backend.rs +9 -43
  173. package/package.json +4 -4
  174. package/skills/team-agent/SKILL.md +7 -8
  175. package/skills/team-agent/command-coverage.json +15 -1
  176. package/skills/team-agent/docs/reference/team-agent-operator.md +5 -3
  177. package/skills/team-agent/references/team-agent-operator.md +5 -3
  178. package/crates/team-agent/src/lifecycle/launch/grok_per_seat.rs +0 -260
  179. package/crates/team-agent/src/lifecycle/tests/codex_weak_window_attribution_red.rs +0 -683
  180. package/crates/team-agent/src/lifecycle/tests/grok_effort_argv_red.rs +0 -247
  181. package/crates/team-agent/src/lifecycle/tests/grok_mcp_overlay_red.rs +0 -507
  182. package/crates/team-agent/src/lifecycle/tests/grok_restart_resume_red.rs +0 -300
  183. package/crates/team-agent/src/provider/adapters/codex.rs +0 -101
  184. package/crates/team-agent/src/provider/adapters/grok.rs +0 -67
  185. package/crates/team-agent/src/provider/session/context_fork/codex.rs +0 -514
  186. package/crates/team-agent/src/provider/session_scan/codex.rs +0 -326
  187. package/crates/team-agent/src/provider/session_scan/grok.rs +0 -288
@@ -0,0 +1,325 @@
1
+ //! Claude compatible-api managed config contracts for Batch A Lane 2.
2
+ //!
3
+ //! The profile resolver owns file artifacts; the provider only consumes `managed_mcp_config`.
4
+ //! These tests verify the public files/env/argv shape expected by Python 0.2.11 parity.
5
+
6
+ #![allow(clippy::unwrap_used, clippy::expect_used, clippy::panic)]
7
+
8
+ #[path = "../../../tests/support/hermetic.rs"]
9
+ mod hermetic_guard;
10
+ #[allow(dead_code)]
11
+ fn _hermetic_boundary_marker(_: &hermetic_guard::HermeticTestEnv) {}
12
+
13
+ use std::collections::{BTreeMap, BTreeSet};
14
+ use std::path::{Path, PathBuf};
15
+ use std::sync::atomic::{AtomicU64, Ordering};
16
+ use std::sync::Mutex;
17
+
18
+ use serde_json::{json, Value};
19
+ use serial_test::serial;
20
+ use team_agent::lifecycle::quick_start_with_transport_in_workspace;
21
+ use team_agent::model::enums::{AuthMode, Provider};
22
+ use team_agent::provider::{
23
+ get_adapter, McpConfig, ProviderCommandContext, ProviderCommandOverrides, ProviderProfileLaunch,
24
+ };
25
+ use team_agent::transport::{
26
+ AttachOutcome, BackendKind, CaptureRange, CapturedText, InjectPayload, InjectReport,
27
+ InjectStage, InjectVerification, Key, PaneField, PaneId, PaneInfo, SessionName, SetEnvOutcome,
28
+ SpawnResult, SubmitVerification, Target, Transport, TransportError, TurnVerification,
29
+ WindowName,
30
+ };
31
+
32
+ #[test]
33
+ #[serial(env)]
34
+ fn compatible_api_profile_writes_claude_settings_and_project_state_with_mcp_servers() {
35
+ let _hermetic = hermetic_guard::HermeticTestEnv::enter_with_leader("claude-compatible-config");
36
+ let ws = tmp_dir("compatible-config-files");
37
+ super::launch_spawn::seed_healthy_coordinator(&ws);
38
+ let team = write_claude_profile_team(&ws, "cfgteam", "clauder");
39
+ let transport = RecordingTransport::default();
40
+
41
+ quick_start_with_transport_in_workspace(&ws, &team, None, true, Some("cfgteam"), &transport)
42
+ .expect("quick-start through recording transport should resolve compatible profile config");
43
+
44
+ let spawn = transport.single_spawn();
45
+ let config_dir = spawn
46
+ .env
47
+ .get("CLAUDE_CONFIG_DIR")
48
+ .map(PathBuf::from)
49
+ .expect("CLAUDE_CONFIG_DIR must be injected");
50
+ let settings = read_json(&config_dir.join("settings.json"));
51
+ let project_state = read_json(&config_dir.join(".claude.json"));
52
+
53
+ assert!(
54
+ settings_contains_trust_onboarding_and_theme(&settings),
55
+ "settings.json must pre-accept workspace trust/onboarding/theme for managed compatible_api Claude; path={} settings={settings}",
56
+ config_dir.join("settings.json").display()
57
+ );
58
+ assert!(
59
+ project_state
60
+ .pointer("/mcpServers/team_orchestrator")
61
+ .or_else(|| project_state.pointer("/projects/cfgteam/mcpServers/team_orchestrator"))
62
+ .is_some(),
63
+ ".claude.json must contain the Team Agent MCP server project state; path={} project_state={project_state}",
64
+ config_dir.join(".claude.json").display()
65
+ );
66
+ assert!(
67
+ !argv_has_flag(&spawn.argv, "--mcp-config"),
68
+ "managed compatible_api launch uses CLAUDE_CONFIG_DIR artifacts, not provider argv --mcp-config; argv={:?}",
69
+ spawn.argv
70
+ );
71
+ }
72
+
73
+ #[test]
74
+ fn managed_profile_command_plan_omits_mcp_config_even_when_mcp_config_is_available() {
75
+ let root = tmp_dir("managed-plan-config");
76
+ let profile = ProviderProfileLaunch {
77
+ env_overlay: BTreeMap::from([(
78
+ "CLAUDE_CONFIG_DIR".to_string(),
79
+ root.join("claude-config").display().to_string(),
80
+ )]),
81
+ env_unset: BTreeSet::from(["ANTHROPIC_API_KEY".to_string()]),
82
+ command_overrides: ProviderCommandOverrides {
83
+ model: Some("profile-effective-haiku".to_string()),
84
+ ..ProviderCommandOverrides::default()
85
+ },
86
+ claude_config_dir: Some(root.join("claude-config")),
87
+ claude_projects_root: Some(root.join("claude-config").join("projects")),
88
+ managed_mcp_config: true,
89
+ };
90
+ let config = McpConfig {
91
+ raw: json!({
92
+ "team_orchestrator": {
93
+ "type": "stdio",
94
+ "command": "team-agent",
95
+ "args": ["mcp-server", "--workspace", "{workspace}"]
96
+ }
97
+ }),
98
+ };
99
+ let plan = get_adapter(Provider::Claude)
100
+ .build_command_plan(ProviderCommandContext {
101
+ auth_mode: AuthMode::CompatibleApi,
102
+ mcp_config: Some(&config),
103
+ system_prompt: Some("worker prompt requiring native MCP"),
104
+ model: Some("profile-effective-haiku"),
105
+ dangerously_skip_permissions: false,
106
+ profile_launch: Some(&profile),
107
+ agent_id_hint: None,
108
+ effort: None,
109
+ })
110
+ .expect("managed compatible_api command plan should build");
111
+
112
+ assert!(
113
+ plan.managed_mcp_config,
114
+ "CommandPlan.managed_mcp_config must reflect ProviderProfileLaunch.managed_mcp_config; plan={plan:?}"
115
+ );
116
+ assert!(
117
+ !argv_has_flag(&plan.argv, "--mcp-config"),
118
+ "managed mode must not pass --mcp-config JSON/string in argv; config is materialized under CLAUDE_CONFIG_DIR; argv={:?}",
119
+ plan.argv
120
+ );
121
+ }
122
+
123
+ fn settings_contains_trust_onboarding_and_theme(settings: &Value) -> bool {
124
+ let text = settings.to_string();
125
+ ["trust", "onboarding", "theme"]
126
+ .iter()
127
+ .all(|needle| text.to_ascii_lowercase().contains(needle))
128
+ }
129
+
130
+ fn read_json(path: &Path) -> Value {
131
+ let text = std::fs::read_to_string(path).unwrap_or_else(|err| {
132
+ panic!(
133
+ "expected managed Claude config file {}: {err}",
134
+ path.display()
135
+ )
136
+ });
137
+ serde_json::from_str(&text).unwrap_or_else(|err| {
138
+ panic!(
139
+ "managed Claude config file must be JSON {}: {err}; text={text}",
140
+ path.display()
141
+ )
142
+ })
143
+ }
144
+
145
+ fn write_claude_profile_team(ws: &Path, team_key: &str, agent_id: &str) -> PathBuf {
146
+ let team = ws.join(team_key);
147
+ std::fs::create_dir_all(team.join("agents")).unwrap();
148
+ std::fs::create_dir_all(ws.join(".team").join("current").join("profiles")).unwrap();
149
+ std::fs::write(
150
+ ws.join(".team").join("current").join("profiles").join("local.env"),
151
+ "ANTHROPIC_BASE_URL=https://llm.local/v1\nANTHROPIC_AUTH_TOKEN=local-secret\nANTHROPIC_MODEL=profile-effective-haiku\n",
152
+ )
153
+ .unwrap();
154
+ std::fs::write(
155
+ team.join("TEAM.md"),
156
+ format!(
157
+ "---\nname: {team_key}\nobjective: Claude compatible config contract.\nprovider: claude\nauth_mode: compatible_api\ndangerously_skip_permissions: false\n---\n\nTeam.\n"
158
+ ),
159
+ )
160
+ .unwrap();
161
+ std::fs::write(
162
+ team.join("agents").join(format!("{agent_id}.md")),
163
+ format!(
164
+ "---\nname: {agent_id}\nrole: Claude Worker\nprovider: claude\nauth_mode: compatible_api\ndangerously_skip_permissions: false\nprofile: local\nmodel: null\ntools:\n - mcp_team\n---\n\nWorker.\n"
165
+ ),
166
+ )
167
+ .unwrap();
168
+ team
169
+ }
170
+
171
+ fn argv_has_flag(argv: &[String], flag: &str) -> bool {
172
+ argv.iter().any(|arg| arg == flag)
173
+ }
174
+
175
+ fn tmp_dir(tag: &str) -> PathBuf {
176
+ static N: AtomicU64 = AtomicU64::new(0);
177
+ let dir = std::env::temp_dir().join(format!(
178
+ "ta-rs-claude-compatible-config-{tag}-{}-{}",
179
+ std::process::id(),
180
+ N.fetch_add(1, Ordering::Relaxed)
181
+ ));
182
+ let _ = std::fs::remove_dir_all(&dir);
183
+ std::fs::create_dir_all(&dir).unwrap();
184
+ std::fs::canonicalize(dir).unwrap()
185
+ }
186
+
187
+ #[derive(Debug, Clone)]
188
+ struct RecordedSpawn {
189
+ argv: Vec<String>,
190
+ env: BTreeMap<String, String>,
191
+ }
192
+
193
+ #[derive(Debug, Default)]
194
+ struct RecordingTransport {
195
+ spawns: Mutex<Vec<RecordedSpawn>>,
196
+ }
197
+
198
+ impl RecordingTransport {
199
+ fn single_spawn(&self) -> RecordedSpawn {
200
+ let spawns = self.spawns.lock().unwrap();
201
+ assert_eq!(
202
+ spawns.len(),
203
+ 1,
204
+ "fixture should record one Claude worker spawn; spawns={spawns:?}"
205
+ );
206
+ spawns[0].clone()
207
+ }
208
+ }
209
+
210
+ impl Transport for RecordingTransport {
211
+ fn kind(&self) -> BackendKind {
212
+ BackendKind::Tmux
213
+ }
214
+
215
+ fn spawn_first(
216
+ &self,
217
+ session: &SessionName,
218
+ window: &WindowName,
219
+ argv: &[String],
220
+ _cwd: &Path,
221
+ env: &BTreeMap<String, String>,
222
+ ) -> Result<SpawnResult, TransportError> {
223
+ self.spawn_into(session, window, argv, _cwd, env)
224
+ }
225
+
226
+ fn spawn_into(
227
+ &self,
228
+ session: &SessionName,
229
+ window: &WindowName,
230
+ argv: &[String],
231
+ _cwd: &Path,
232
+ env: &BTreeMap<String, String>,
233
+ ) -> Result<SpawnResult, TransportError> {
234
+ let mut spawns = self.spawns.lock().unwrap();
235
+ spawns.push(RecordedSpawn {
236
+ argv: argv.to_vec(),
237
+ env: env.clone(),
238
+ });
239
+ Ok(SpawnResult {
240
+ pane_id: PaneId::new(format!("%{}", spawns.len())),
241
+ session: session.clone(),
242
+ window: window.clone(),
243
+ child_pid: Some(20_000 + spawns.len() as u32),
244
+ })
245
+ }
246
+
247
+ fn inject(
248
+ &self,
249
+ _target: &Target,
250
+ _payload: &InjectPayload,
251
+ _submit: Key,
252
+ _bracketed: bool,
253
+ ) -> Result<InjectReport, TransportError> {
254
+ Ok(InjectReport {
255
+ stage_reached: InjectStage::Submit,
256
+ inject_verification: InjectVerification::CaptureContainsToken,
257
+ submit_verification: SubmitVerification::EnterSentWithoutPlaceholderCheck,
258
+ turn_verification: TurnVerification::NotYetObserved,
259
+ attempts: 1,
260
+ submit_diagnostics: None,
261
+ })
262
+ }
263
+
264
+ fn send_keys(&self, _target: &Target, _keys: &[Key]) -> Result<(), TransportError> {
265
+ Ok(())
266
+ }
267
+
268
+ fn capture(
269
+ &self,
270
+ _target: &Target,
271
+ range: CaptureRange,
272
+ ) -> Result<CapturedText, TransportError> {
273
+ Ok(CapturedText {
274
+ text: String::new(),
275
+ range,
276
+ })
277
+ }
278
+
279
+ fn query(&self, _target: &Target, field: PaneField) -> Result<Option<String>, TransportError> {
280
+ match field {
281
+ PaneField::PaneWidth => Ok(Some("120".to_string())),
282
+ _ => Ok(None),
283
+ }
284
+ }
285
+
286
+ fn liveness(
287
+ &self,
288
+ _pane: &PaneId,
289
+ ) -> Result<team_agent::transport::PaneLiveness, TransportError> {
290
+ Ok(team_agent::transport::PaneLiveness::Live)
291
+ }
292
+
293
+ fn list_targets(&self) -> Result<Vec<PaneInfo>, TransportError> {
294
+ Ok(Vec::new())
295
+ }
296
+
297
+ fn has_session(&self, _session: &SessionName) -> Result<bool, TransportError> {
298
+ Ok(false)
299
+ }
300
+
301
+ fn list_windows(&self, _session: &SessionName) -> Result<Vec<WindowName>, TransportError> {
302
+ Ok(Vec::new())
303
+ }
304
+
305
+ fn set_session_env(
306
+ &self,
307
+ _session: &SessionName,
308
+ _key: &str,
309
+ _value: &str,
310
+ ) -> Result<SetEnvOutcome, TransportError> {
311
+ Ok(SetEnvOutcome::Applied)
312
+ }
313
+
314
+ fn kill_session(&self, _session: &SessionName) -> Result<(), TransportError> {
315
+ Ok(())
316
+ }
317
+
318
+ fn kill_window(&self, _target: &Target) -> Result<(), TransportError> {
319
+ Ok(())
320
+ }
321
+
322
+ fn attach_session(&self, _session: &SessionName) -> Result<AttachOutcome, TransportError> {
323
+ Ok(AttachOutcome::Attached)
324
+ }
325
+ }
@@ -1,7 +1,8 @@
1
- //! Profile launch contracts for Batch A Lane 2.
1
+ //! Claude compatible-api profile launch contracts for Batch A Lane 2.
2
2
  //!
3
- //! The Claude compatible-api worker launch these contracts were written for is gone with the
4
- //! legacy Claude worker runtime; the provider-neutral resolver wiring and doctor contracts remain.
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.
5
6
 
6
7
  #![allow(clippy::unwrap_used, clippy::expect_used, clippy::panic)]
7
8
 
@@ -12,10 +13,117 @@ fn _hermetic_boundary_marker(_: &hermetic_guard::HermeticTestEnv) {}
12
13
 
13
14
  #[path = "../../../tests/support/composite_source.rs"]
14
15
  mod composite_source;
16
+ use std::collections::{BTreeMap, BTreeSet};
15
17
  use std::path::{Path, PathBuf};
16
18
  use std::process::Command;
19
+ use std::sync::atomic::{AtomicU64, Ordering};
20
+ use std::sync::Mutex;
17
21
 
18
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
+ let _hermetic = hermetic_guard::HermeticTestEnv::enter_with_leader("claude-profile-quick-start");
38
+ assert_s0_profile_launch_shape();
39
+
40
+ let ws = tmp_dir("profile-launch");
41
+ super::launch_spawn::seed_healthy_coordinator(&ws);
42
+ let team = write_claude_profile_team(&ws, "claudeprof", "clauder");
43
+ let transport = RecordingTransport::default();
44
+
45
+ quick_start_with_transport_in_workspace(&ws, &team, None, true, Some("claudeprof"), &transport)
46
+ .expect(
47
+ "quick-start through recording transport should reach the real lifecycle spawn path",
48
+ );
49
+
50
+ let spawn = transport.single_spawn();
51
+ for (key, expected) in [
52
+ ("CLAUDE_CONFIG_DIR", None),
53
+ ("ANTHROPIC_BASE_URL", Some("https://llm.local/v1")),
54
+ ("ANTHROPIC_AUTH_TOKEN", Some("local-secret")),
55
+ ("ANTHROPIC_MODEL", Some("profile-effective-haiku")),
56
+ ] {
57
+ let got = spawn.env.get(key).map(String::as_str);
58
+ match expected {
59
+ Some(expected) => assert_eq!(
60
+ got,
61
+ Some(expected),
62
+ "Claude compatible_api profile launch must inject {key} from .team/current/profiles/local.env; env={:?}",
63
+ spawn.env
64
+ ),
65
+ None => assert!(
66
+ got.is_some_and(|value| !value.is_empty()),
67
+ "Claude compatible_api profile launch must inject non-empty {key}; env={:?}",
68
+ spawn.env
69
+ ),
70
+ }
71
+ }
72
+ assert!(
73
+ !spawn.env.contains_key("ANTHROPIC_API_KEY"),
74
+ "compatible_api must unset ANTHROPIC_API_KEY and use ANTHROPIC_AUTH_TOKEN instead; env={:?}",
75
+ spawn.env
76
+ );
77
+ assert!(
78
+ argv_contains_adjacent(&spawn.argv, &["--model", "profile-effective-haiku"]),
79
+ "profile model must become the effective Claude model when role model is null; argv={:?}",
80
+ spawn.argv
81
+ );
82
+
83
+ let state = load_runtime_state(&ws).unwrap();
84
+ let agent = &state["teams"]["claudeprof"]["agents"]["clauder"];
85
+ assert!(
86
+ agent["_pending_session_id"].as_str().is_some_and(|value| !value.is_empty()),
87
+ "lifecycle must persist CommandPlan.expected_session_id as agents[*]._pending_session_id; state={state}"
88
+ );
89
+ assert!(
90
+ agent["claude_projects_root"].as_str().is_some_and(|value| !value.is_empty()),
91
+ "lifecycle must persist CommandPlan.provider_projects_root/profile claude_projects_root for capture; state={state}"
92
+ );
93
+ }
94
+
95
+ #[ignore = "flaky under parallel suite, tracked"]
96
+ #[test]
97
+ #[serial(env)]
98
+ fn subscription_profile_keeps_default_claude_config_dir_for_logged_in_quota() {
99
+ let ws = tmp_dir("subscription-config");
100
+ let team = write_claude_subscription_profile_team(&ws, "subteam", "clauder");
101
+ let transport = RecordingTransport::default();
102
+
103
+ quick_start_with_transport_in_workspace(&ws, &team, None, true, Some("subteam"), &transport)
104
+ .expect("subscription profile should launch without managed config isolation");
105
+
106
+ let spawn = transport.single_spawn();
107
+ assert!(
108
+ !spawn.env.contains_key("CLAUDE_CONFIG_DIR"),
109
+ "subscription Claude workers must inherit the user's default ~/.claude login state; env={:?}",
110
+ spawn.env
111
+ );
112
+ assert!(
113
+ !spawn.env.contains_key("ANTHROPIC_API_KEY")
114
+ && !spawn.env.contains_key("ANTHROPIC_AUTH_TOKEN"),
115
+ "subscription launch must not switch into API-token auth via profile env; env={:?}",
116
+ spawn.env
117
+ );
118
+
119
+ let state = load_runtime_state(&ws).unwrap();
120
+ let agent = &state["teams"]["subteam"]["agents"]["clauder"];
121
+ assert_eq!(
122
+ agent.get("claude_projects_root"),
123
+ None,
124
+ "without a supported fine-grained Claude projects-root env, subscription workers must not fake an isolated transcript root; state={state}"
125
+ );
126
+ }
19
127
 
20
128
  #[test]
21
129
  fn launch_restart_start_add_and_fork_all_delegate_to_the_profile_launch_resolver() {
@@ -63,7 +171,7 @@ fn launch_restart_start_add_and_fork_all_delegate_to_the_profile_launch_resolver
63
171
  fn diagnose_missing_profile_is_rc1_ok_false_and_zero_token() {
64
172
  let env = hermetic_guard::HermeticTestEnv::enter("diagnose-missing-profile");
65
173
  let ws = env.workspace("missing-profile");
66
- let team = write_compatible_profile_team(&ws, "diagteam", "copiloter");
174
+ let team = write_claude_profile_team(&ws, "diagteam", "clauder");
67
175
  std::fs::remove_file(
68
176
  ws.join(".team")
69
177
  .join("current")
@@ -104,26 +212,73 @@ fn diagnose_missing_profile_is_rc1_ok_false_and_zero_token() {
104
212
  );
105
213
  }
106
214
 
107
- fn write_compatible_profile_team(ws: &Path, team_key: &str, agent_id: &str) -> PathBuf {
215
+ fn assert_s0_profile_launch_shape() {
216
+ let profile = ProviderProfileLaunch {
217
+ env_overlay: BTreeMap::from([(
218
+ "ANTHROPIC_MODEL".to_string(),
219
+ "profile-effective-haiku".to_string(),
220
+ )]),
221
+ env_unset: BTreeSet::from(["ANTHROPIC_API_KEY".to_string()]),
222
+ command_overrides: ProviderCommandOverrides {
223
+ model: Some("profile-effective-haiku".to_string()),
224
+ ..ProviderCommandOverrides::default()
225
+ },
226
+ claude_config_dir: Some(PathBuf::from("/tmp/claude-config")),
227
+ claude_projects_root: Some(PathBuf::from("/tmp/claude-config/projects")),
228
+ managed_mcp_config: true,
229
+ };
230
+ assert!(profile.managed_mcp_config);
231
+ }
232
+
233
+ fn write_claude_profile_team(ws: &Path, team_key: &str, agent_id: &str) -> PathBuf {
108
234
  let team = ws.join(team_key);
109
235
  std::fs::create_dir_all(team.join("agents")).unwrap();
110
236
  std::fs::create_dir_all(ws.join(".team").join("current").join("profiles")).unwrap();
111
237
  std::fs::write(
112
238
  ws.join(".team").join("current").join("profiles").join("local.env"),
113
- "BASE_URL=https://llm.local/v1\nAPI_KEY=local-secret\nMODEL=profile-effective-model\n",
239
+ "ANTHROPIC_BASE_URL=https://llm.local/v1\nANTHROPIC_AUTH_TOKEN=local-secret\nANTHROPIC_MODEL=profile-effective-haiku\nANTHROPIC_API_KEY=\n",
114
240
  )
115
241
  .unwrap();
116
242
  std::fs::write(
117
243
  team.join("TEAM.md"),
118
244
  format!(
119
- "---\nname: {team_key}\nobjective: Compatible profile doctor contract.\nprovider: copilot\nauth_mode: compatible_api\ndangerously_skip_permissions: false\n---\n\nTeam.\n"
245
+ "---\nname: {team_key}\nobjective: Claude compatible profile launch contract.\nprovider: claude\nauth_mode: compatible_api\ndangerously_skip_permissions: false\n---\n\nTeam.\n"
120
246
  ),
121
247
  )
122
248
  .unwrap();
123
249
  std::fs::write(
124
250
  team.join("agents").join(format!("{agent_id}.md")),
125
251
  format!(
126
- "---\nname: {agent_id}\nrole: Copilot Worker\nprovider: copilot\nauth_mode: compatible_api\ndangerously_skip_permissions: false\nprofile: local\nmodel: profile-effective-model\ntools:\n - mcp_team\n---\n\nWorker.\n"
252
+ "---\nname: {agent_id}\nrole: Claude Worker\nprovider: claude\nauth_mode: compatible_api\ndangerously_skip_permissions: false\nprofile: local\nmodel: null\ntools:\n - mcp_team\n---\n\nWorker.\n"
253
+ ),
254
+ )
255
+ .unwrap();
256
+ team
257
+ }
258
+
259
+ fn write_claude_subscription_profile_team(ws: &Path, team_key: &str, agent_id: &str) -> PathBuf {
260
+ let team = ws.join(team_key);
261
+ std::fs::create_dir_all(team.join("agents")).unwrap();
262
+ std::fs::create_dir_all(ws.join(".team").join("current").join("profiles")).unwrap();
263
+ std::fs::write(
264
+ ws.join(".team")
265
+ .join("current")
266
+ .join("profiles")
267
+ .join("local.env"),
268
+ "AUTH_MODE=subscription\nMODEL=claude-sonnet-4-6\n",
269
+ )
270
+ .unwrap();
271
+ std::fs::write(
272
+ team.join("TEAM.md"),
273
+ format!(
274
+ "---\nname: {team_key}\nobjective: Claude subscription profile launch contract.\nprovider: claude\nauth_mode: subscription\ndangerously_skip_permissions: false\n---\n\nTeam.\n"
275
+ ),
276
+ )
277
+ .unwrap();
278
+ std::fs::write(
279
+ team.join("agents").join(format!("{agent_id}.md")),
280
+ format!(
281
+ "---\nname: {agent_id}\nrole: Claude Worker\nprovider: claude\nauth_mode: subscription\ndangerously_skip_permissions: false\nprofile: local\nmodel: null\ntools:\n - mcp_team\n---\n\nWorker.\n"
127
282
  ),
128
283
  )
129
284
  .unwrap();
@@ -133,3 +288,160 @@ fn write_compatible_profile_team(ws: &Path, team_key: &str, agent_id: &str) -> P
133
288
  fn source(path: &str) -> String {
134
289
  composite_source::composite_source(path)
135
290
  }
291
+
292
+ fn argv_contains_adjacent(hay: &[String], needle: &[&str]) -> bool {
293
+ hay.windows(needle.len())
294
+ .any(|window| window.iter().map(String::as_str).eq(needle.iter().copied()))
295
+ }
296
+
297
+ fn tmp_dir(tag: &str) -> PathBuf {
298
+ static N: AtomicU64 = AtomicU64::new(0);
299
+ let dir = std::env::temp_dir().join(format!(
300
+ "ta-rs-claude-profile-launch-{tag}-{}-{}",
301
+ std::process::id(),
302
+ N.fetch_add(1, Ordering::Relaxed)
303
+ ));
304
+ let _ = std::fs::remove_dir_all(&dir);
305
+ std::fs::create_dir_all(&dir).unwrap();
306
+ std::fs::canonicalize(dir).unwrap()
307
+ }
308
+
309
+ #[derive(Debug, Clone)]
310
+ struct RecordedSpawn {
311
+ argv: Vec<String>,
312
+ env: BTreeMap<String, String>,
313
+ }
314
+
315
+ #[derive(Debug, Default)]
316
+ struct RecordingTransport {
317
+ spawns: Mutex<Vec<RecordedSpawn>>,
318
+ }
319
+
320
+ impl RecordingTransport {
321
+ fn single_spawn(&self) -> RecordedSpawn {
322
+ let spawns = self.spawns.lock().unwrap();
323
+ assert_eq!(
324
+ spawns.len(),
325
+ 1,
326
+ "fixture should record one Claude worker spawn; spawns={spawns:?}"
327
+ );
328
+ spawns[0].clone()
329
+ }
330
+ }
331
+
332
+ impl Transport for RecordingTransport {
333
+ fn kind(&self) -> BackendKind {
334
+ BackendKind::Tmux
335
+ }
336
+
337
+ fn spawn_first(
338
+ &self,
339
+ session: &SessionName,
340
+ window: &WindowName,
341
+ argv: &[String],
342
+ _cwd: &Path,
343
+ env: &BTreeMap<String, String>,
344
+ ) -> Result<SpawnResult, TransportError> {
345
+ self.spawn_into(session, window, argv, _cwd, env)
346
+ }
347
+
348
+ fn spawn_into(
349
+ &self,
350
+ session: &SessionName,
351
+ window: &WindowName,
352
+ argv: &[String],
353
+ _cwd: &Path,
354
+ env: &BTreeMap<String, String>,
355
+ ) -> Result<SpawnResult, TransportError> {
356
+ let mut spawns = self.spawns.lock().unwrap();
357
+ spawns.push(RecordedSpawn {
358
+ argv: argv.to_vec(),
359
+ env: env.clone(),
360
+ });
361
+ Ok(SpawnResult {
362
+ pane_id: PaneId::new(format!("%{}", spawns.len())),
363
+ session: session.clone(),
364
+ window: window.clone(),
365
+ child_pid: Some(10_000 + spawns.len() as u32),
366
+ })
367
+ }
368
+
369
+ fn inject(
370
+ &self,
371
+ _target: &Target,
372
+ _payload: &InjectPayload,
373
+ _submit: Key,
374
+ _bracketed: bool,
375
+ ) -> Result<InjectReport, TransportError> {
376
+ Ok(InjectReport {
377
+ stage_reached: InjectStage::Submit,
378
+ inject_verification: InjectVerification::CaptureContainsToken,
379
+ submit_verification: SubmitVerification::EnterSentWithoutPlaceholderCheck,
380
+ turn_verification: TurnVerification::NotYetObserved,
381
+ attempts: 1,
382
+ submit_diagnostics: None,
383
+ })
384
+ }
385
+
386
+ fn send_keys(&self, _target: &Target, _keys: &[Key]) -> Result<(), TransportError> {
387
+ Ok(())
388
+ }
389
+
390
+ fn capture(
391
+ &self,
392
+ _target: &Target,
393
+ range: CaptureRange,
394
+ ) -> Result<CapturedText, TransportError> {
395
+ Ok(CapturedText {
396
+ text: String::new(),
397
+ range,
398
+ })
399
+ }
400
+
401
+ fn query(&self, _target: &Target, field: PaneField) -> Result<Option<String>, TransportError> {
402
+ match field {
403
+ PaneField::PaneWidth => Ok(Some("120".to_string())),
404
+ _ => Ok(None),
405
+ }
406
+ }
407
+
408
+ fn liveness(
409
+ &self,
410
+ _pane: &PaneId,
411
+ ) -> Result<team_agent::transport::PaneLiveness, TransportError> {
412
+ Ok(team_agent::transport::PaneLiveness::Live)
413
+ }
414
+
415
+ fn list_targets(&self) -> Result<Vec<PaneInfo>, TransportError> {
416
+ Ok(Vec::new())
417
+ }
418
+
419
+ fn has_session(&self, _session: &SessionName) -> Result<bool, TransportError> {
420
+ Ok(false)
421
+ }
422
+
423
+ fn list_windows(&self, _session: &SessionName) -> Result<Vec<WindowName>, TransportError> {
424
+ Ok(Vec::new())
425
+ }
426
+
427
+ fn set_session_env(
428
+ &self,
429
+ _session: &SessionName,
430
+ _key: &str,
431
+ _value: &str,
432
+ ) -> Result<SetEnvOutcome, TransportError> {
433
+ Ok(SetEnvOutcome::Applied)
434
+ }
435
+
436
+ fn kill_session(&self, _session: &SessionName) -> Result<(), TransportError> {
437
+ Ok(())
438
+ }
439
+
440
+ fn kill_window(&self, _target: &Target) -> Result<(), TransportError> {
441
+ Ok(())
442
+ }
443
+
444
+ fn attach_session(&self, _session: &SessionName) -> Result<AttachOutcome, TransportError> {
445
+ Ok(AttachOutcome::Attached)
446
+ }
447
+ }