@team-agent/installer 0.5.124 → 0.5.126

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 (151) hide show
  1. package/Cargo.lock +1 -8
  2. package/Cargo.toml +1 -1
  3. package/README.md +2 -2
  4. package/README.zh.md +2 -2
  5. package/crates/team-agent/Cargo.toml +0 -1
  6. package/crates/team-agent/src/cli/diagnose.rs +39 -69
  7. package/crates/team-agent/src/cli/emit.rs +45 -15
  8. package/crates/team-agent/src/cli/intent/runtime.rs +5 -53
  9. package/crates/team-agent/src/cli/intent/runtime_tests.rs +10 -130
  10. package/crates/team-agent/src/cli/leader.rs +2 -3
  11. package/crates/team-agent/src/cli/leader_prompt.rs +1 -1
  12. package/crates/team-agent/src/cli/mod.rs +28 -33
  13. package/crates/team-agent/src/cli/models.rs +44 -880
  14. package/crates/team-agent/src/cli/route.rs +1 -1
  15. package/crates/team-agent/src/cli/send/persist.rs +36 -0
  16. package/crates/team-agent/src/cli/send/presentation.rs +7 -1
  17. package/crates/team-agent/src/cli/send.rs +3 -1
  18. package/crates/team-agent/src/cli/spec.rs +1 -2
  19. package/crates/team-agent/src/cli/status_port/brief.rs +66 -0
  20. package/crates/team-agent/src/cli/tests/base.rs +4 -11
  21. package/crates/team-agent/src/cli/tests/mod.rs +1 -1
  22. package/crates/team-agent/src/cli/tests/run_delegation.rs +5 -4
  23. package/crates/team-agent/src/cli/tests/status_send.rs +17 -0
  24. package/crates/team-agent/src/compiler/tests.rs +39 -8
  25. package/crates/team-agent/src/compiler.rs +28 -204
  26. package/crates/team-agent/src/contract_runtime/backend.rs +79 -40
  27. package/crates/team-agent/src/contract_runtime/config.rs +37 -24
  28. package/crates/team-agent/src/contract_runtime/discovery.rs +33 -0
  29. package/crates/team-agent/src/contract_runtime/fork.rs +368 -0
  30. package/crates/team-agent/src/contract_runtime/framework.rs +87 -34
  31. package/crates/team-agent/src/contract_runtime/mod.rs +1 -0
  32. package/crates/team-agent/src/contract_runtime/registry.rs +299 -21
  33. package/crates/team-agent/src/coordinator/runtime_detectors.rs +0 -1
  34. package/crates/team-agent/src/coordinator/tests/api_error_recovery.rs +29 -8
  35. package/crates/team-agent/src/coordinator/tests/health_sync.rs +0 -42
  36. package/crates/team-agent/src/coordinator/tick.rs +89 -1
  37. package/crates/team-agent/src/db/message_store.rs +78 -3
  38. package/crates/team-agent/src/layout/worker_window_helpers.rs +0 -1
  39. package/crates/team-agent/src/leader/prompt.rs +1 -2
  40. package/crates/team-agent/src/leader/provider_attribution.rs +0 -52
  41. package/crates/team-agent/src/leader/start.rs +1 -2
  42. package/crates/team-agent/src/leader/tests/prompt_contract.rs +2 -3
  43. package/crates/team-agent/src/lifecycle/launch/add_agent.rs +91 -0
  44. package/crates/team-agent/src/lifecycle/launch/add_agent_state.rs +15 -195
  45. package/crates/team-agent/src/lifecycle/launch/agent_state.rs +0 -9
  46. package/crates/team-agent/src/lifecycle/launch/clone_agent.rs +11 -27
  47. package/crates/team-agent/src/lifecycle/launch/fork_agent.rs +18 -29
  48. package/crates/team-agent/src/lifecycle/launch/fork_entry.rs +6 -87
  49. package/crates/team-agent/src/lifecycle/launch/mcp_config.rs +3 -11
  50. package/crates/team-agent/src/lifecycle/launch/pi_mcp.rs +74 -244
  51. package/crates/team-agent/src/lifecycle/launch/quick_start.rs +0 -24
  52. package/crates/team-agent/src/lifecycle/launch/role_source.rs +5 -0
  53. package/crates/team-agent/src/lifecycle/launch/spawn.rs +21 -61
  54. package/crates/team-agent/src/lifecycle/launch/spec_state.rs +0 -1
  55. package/crates/team-agent/src/lifecycle/launch/worker_env.rs +0 -108
  56. package/crates/team-agent/src/lifecycle/launch.rs +2 -43
  57. package/crates/team-agent/src/lifecycle/profile_launch.rs +21 -348
  58. package/crates/team-agent/src/lifecycle/profile_smoke.rs +1 -2
  59. package/crates/team-agent/src/lifecycle/restart/common.rs +43 -378
  60. package/crates/team-agent/src/lifecycle/restart/selection.rs +5 -5
  61. package/crates/team-agent/src/lifecycle/restart.rs +0 -2
  62. package/crates/team-agent/src/lifecycle/role_config.rs +42 -3
  63. package/crates/team-agent/src/lifecycle/tests/behavioral_diff_264_red.rs +11 -6
  64. package/crates/team-agent/src/lifecycle/tests/claude_profile_launch_red.rs +8 -320
  65. package/crates/team-agent/src/lifecycle/tests/cli_argv_routing_red.rs +60 -145
  66. package/crates/team-agent/src/lifecycle/tests/clone_fork_copilot_perms_red.rs +8 -334
  67. package/crates/team-agent/src/lifecycle/tests/communication_mode_runtime_contract_red.rs +30 -11
  68. package/crates/team-agent/src/lifecycle/tests/copilot_provider_red.rs +2 -2
  69. package/crates/team-agent/src/lifecycle/tests/core.rs +17 -16
  70. package/crates/team-agent/src/lifecycle/tests/grok_require_explicit_model_red.rs +12 -12
  71. package/crates/team-agent/src/lifecycle/tests/harvest2_a_batch_red.rs +3 -51
  72. package/crates/team-agent/src/lifecycle/tests/launch_spawn.rs +26 -28
  73. package/crates/team-agent/src/lifecycle/tests/pi_catalog_red.rs +6 -18
  74. package/crates/team-agent/src/lifecycle/tests/pi_command_red.rs +52 -70
  75. package/crates/team-agent/src/lifecycle/tests/pi_dual_entry_red.rs +4 -157
  76. package/crates/team-agent/src/lifecycle/tests/pi_executable_mcp_red.rs +10 -302
  77. package/crates/team-agent/src/lifecycle/tests/pi_lifecycle_doctor_red.rs +1 -68
  78. package/crates/team-agent/src/lifecycle/tests/pi_native_mcp_capability_red.rs +1 -19
  79. package/crates/team-agent/src/lifecycle/tests/pi_session_delivery_red.rs +2 -100
  80. package/crates/team-agent/src/lifecycle/tests/quick_start_worker_readiness_red.rs +11 -10
  81. package/crates/team-agent/src/lifecycle/tests/restart_rebind_hotfix_252_red.rs +0 -1
  82. package/crates/team-agent/src/lifecycle/tests/restart_session_capture_red.rs +2 -106
  83. package/crates/team-agent/src/lifecycle/tests/status_credential_redaction_contract.rs +2 -2
  84. package/crates/team-agent/src/lifecycle/tests/swallow_batch4_semantics_red.rs +2 -254
  85. package/crates/team-agent/src/lifecycle/tests/upgrade_compat_0211_red.rs +4 -4
  86. package/crates/team-agent/src/lifecycle/tests/verify_rs031_window_consistency_red.rs +6 -5
  87. package/crates/team-agent/src/lifecycle/tests/worker_spawn_env_red.rs +7 -153
  88. package/crates/team-agent/src/lifecycle/tests.rs +0 -6
  89. package/crates/team-agent/src/lifecycle/types.rs +2 -18
  90. package/crates/team-agent/src/lifecycle/worker_command_context.rs +2 -4
  91. package/crates/team-agent/src/mcp_server/readiness.rs +148 -97
  92. package/crates/team-agent/src/mcp_server/readiness_tests.rs +115 -16
  93. package/crates/team-agent/src/messaging/delivery.rs +185 -168
  94. package/crates/team-agent/src/messaging/delivery_consumption_tests.rs +5 -5
  95. package/crates/team-agent/src/messaging/enter_rescue_tests.rs +1 -1
  96. package/crates/team-agent/src/messaging/helpers.rs +19 -0
  97. package/crates/team-agent/src/messaging/tests/dup_inject.rs +67 -5
  98. package/crates/team-agent/src/messaging/tests/runtime.rs +110 -4
  99. package/crates/team-agent/src/messaging/tests/spine.rs +46 -36
  100. package/crates/team-agent/src/model/enums.rs +1 -8
  101. package/crates/team-agent/src/provider/adapter.rs +33 -302
  102. package/crates/team-agent/src/provider/adapters/mod.rs +4 -5
  103. package/crates/team-agent/src/provider/argv_route.rs +1 -5
  104. package/crates/team-agent/src/provider/bypass_flags.rs +3 -11
  105. package/crates/team-agent/src/provider/classify.rs +68 -3
  106. package/crates/team-agent/src/provider/faults.rs +1 -1
  107. package/crates/team-agent/src/provider/model_catalog.rs +14 -273
  108. package/crates/team-agent/src/provider/session/capture.rs +7 -107
  109. package/crates/team-agent/src/provider/session/context_fork/outcome.rs +0 -4
  110. package/crates/team-agent/src/provider/session/context_fork.rs +17 -109
  111. package/crates/team-agent/src/provider/session_scan/common.rs +11 -36
  112. package/crates/team-agent/src/provider/session_scan/pi.rs +1 -34
  113. package/crates/team-agent/src/provider/session_scan.rs +4 -14
  114. package/crates/team-agent/src/provider/submit_now.rs +5 -28
  115. package/crates/team-agent/src/provider/tests/adapter.rs +39 -275
  116. package/crates/team-agent/src/provider/tests/classify.rs +53 -0
  117. package/crates/team-agent/src/provider/tests/command_helpers.rs +3 -15
  118. package/crates/team-agent/src/provider/tests/idle.rs +0 -25
  119. package/crates/team-agent/src/provider/types.rs +1 -1
  120. package/crates/team-agent/src/provider/wire.rs +79 -11
  121. package/crates/team-agent/src/state/abnormal_watch/tests/mod.rs +1 -1
  122. package/crates/team-agent/src/state/persist.rs +6 -6
  123. package/crates/team-agent/src/state/repository/tests.rs +2 -2
  124. package/crates/team-agent/src/tmux_backend/native_input_tests.rs +2 -178
  125. package/crates/team-agent/src/tmux_backend/tests.rs +151 -0
  126. package/crates/team-agent/src/tmux_backend.rs +43 -8
  127. package/crates/team-agent/src/transport/native_input.rs +2 -231
  128. package/package.json +4 -4
  129. package/skills/team-agent/SKILL.md +7 -5
  130. package/skills/team-agent/command-coverage.json +15 -1
  131. package/skills/team-agent/docs/reference/team-agent-operator.md +5 -3
  132. package/skills/team-agent/references/team-agent-operator.md +5 -3
  133. package/crates/team-agent/src/lifecycle/launch/cursor_create_chat.rs +0 -229
  134. package/crates/team-agent/src/lifecycle/launch/cursor_mcp.rs +0 -522
  135. package/crates/team-agent/src/lifecycle/launch/cursor_mcp_iso.rs +0 -282
  136. package/crates/team-agent/src/lifecycle/restart/avatar.rs +0 -1805
  137. package/crates/team-agent/src/lifecycle/tests/claude_compatible_config_red.rs +0 -325
  138. package/crates/team-agent/src/lifecycle/tests/cursor_mcp_overlay.rs +0 -576
  139. package/crates/team-agent/src/lifecycle/tests/cursor_require_explicit_model_red.rs +0 -222
  140. package/crates/team-agent/src/lifecycle/tests/cursor_restart_resume_red.rs +0 -511
  141. package/crates/team-agent/src/lifecycle/tests/pi_compiler_red.rs +0 -210
  142. package/crates/team-agent/src/lifecycle/tests/pi_fork_session_inheritance_red.rs +0 -1409
  143. package/crates/team-agent/src/provider/adapters/claude.rs +0 -78
  144. package/crates/team-agent/src/provider/adapters/claude_fork.rs +0 -131
  145. package/crates/team-agent/src/provider/adapters/cursor_agent.rs +0 -44
  146. package/crates/team-agent/src/provider/adapters/pi.rs +0 -100
  147. package/crates/team-agent/src/provider/session/context_fork/claude.rs +0 -123
  148. package/crates/team-agent/src/provider/session_scan/claude.rs +0 -523
  149. package/crates/team-agent/src/provider/session_scan/cursor.rs +0 -538
  150. package/crates/team-agent/src/provider/testdata/cursor-list-models-native.stdout +0 -250
  151. package/crates/team-agent/src/test_support/models_timeout_fixture.rs +0 -144
@@ -20,7 +20,9 @@
20
20
  //! (The SQLite foreign-key table integrity + exact-nonce recall are the GREEN
21
21
  //! half / subscription-E2E per §1.4 — not asserted offline here.)
22
22
  //!
23
- //! - **R7 permission-clamp GUARDRAIL (naturally-green, not a RED, per L1 r2)**: a
23
+ //! - **R7 permission-clamp GUARDRAIL (retired)**: R7/R7b drove a legacy Claude
24
+ //! seat fork through a backing shim; that runtime is gone, so they left with it.
25
+ //! Original charter: a
24
26
  //! fork's effective approval policy must be derived from the LEADER
25
27
  //! (`source=leader_process`, `worker_capability_above_leader=false`), never a
26
28
  //! raw clone of a source-declared capability above the leader (MUST-16).
@@ -45,7 +47,7 @@
45
47
 
46
48
  use std::collections::BTreeMap;
47
49
  use std::path::{Path, PathBuf};
48
- use std::process::{Command, Output};
50
+ use std::process::Command;
49
51
  use std::sync::Mutex;
50
52
 
51
53
  use serde_json::{json, Value};
@@ -67,19 +69,9 @@ use hermetic_guard::HermeticTestEnv;
67
69
  const TEAM_NAME: &str = "cf-batch4";
68
70
  const SOURCE: &str = "cp_worker";
69
71
  const NEW: &str = "cp_fork";
70
- const R7_CHILD: &str = "TEAM_AGENT_TEST_CF_R7_CHILD";
71
- const R7B_CHILD: &str = "TEAM_AGENT_TEST_CF_R7B_CHILD";
72
72
  const R8_CHILD: &str = "TEAM_AGENT_TEST_CF_R8_CHILD";
73
73
  const ISOLATION_GUARD_CHILD: &str = "TEAM_AGENT_TEST_CF_ISOLATION_GUARD_CHILD";
74
74
  const PARENT_PID_ENV: &str = "TEAM_AGENT_TEST_CF_PARENT_PID";
75
- const R7_TEST: &str = concat!(
76
- "lifecycle::tests::clone_fork_copilot_perms_red::",
77
- "r7_fork_effective_permissions_are_clamped_to_leader_guardrail"
78
- );
79
- const R7B_TEST: &str = concat!(
80
- "lifecycle::tests::clone_fork_copilot_perms_red::",
81
- "r7b_fork_policy_under_restricted_leader_ancestry_is_disabled"
82
- );
83
75
  const R8_TEST: &str = concat!(
84
76
  "lifecycle::tests::clone_fork_copilot_perms_red::",
85
77
  "r8_copilot_fork_is_no_longer_capability_refused"
@@ -92,8 +84,9 @@ const ISOLATION_GUARD_TEST: &str = concat!(
92
84
  /// These fixtures need process-global HOME and TEAM_AGENT_* overrides, while the
93
85
  /// lib-test harness runs sibling tests in parallel. Execute each body as the sole
94
86
  /// selected test in a child process so HermeticTestEnv never mutates the parent
95
- /// test process. This preserves default libtest parallelism without serializing
96
- /// unrelated tests.
87
+ /// test process. Fixture-caller tests still hold `serial(env)` while their child
88
+ /// runs: the child inherits the parent's PATH, and a sibling env test may have a
89
+ /// fake `tmux` on it that never creates the fixture caller socket.
97
90
  fn run_process_isolated(marker: &str, test_name: &str, body: impl FnOnce()) {
98
91
  if std::env::var_os(marker).is_some() {
99
92
  body();
@@ -128,247 +121,6 @@ fn copilot_clone_fork_env_fixtures_run_outside_parent_process() {
128
121
  });
129
122
  }
130
123
 
131
- /// Gate6 CI-hermeticity revision: the R7 fixture must pin the process-ancestry
132
- /// seam explicitly (`TEAM_AGENT_TEST_PROCESS_ANCESTRY_ARGV_JSON`) instead of
133
- /// depending on the REAL ancestry of the test-runner host. Unpinned, a local
134
- /// runner descending from a dangerous-bypass leader yields
135
- /// `source=leader_process` (historical local green) while a clean CI runner
136
- /// correctly yields `source=disabled` — a non-hermetic assertion, not a product
137
- /// regression. Precedent: `codex_mcp_approval_inheritance_red.rs` `MockAncestry`
138
- /// (pins both bypass and restricted leader argv).
139
- const ANCESTRY_ENV: &str = "TEAM_AGENT_TEST_PROCESS_ANCESTRY_ARGV_JSON";
140
- const CODEX_BYPASS: &str = "--dangerously-bypass-approvals-and-sandbox";
141
- const RESTRICTED_LEADER_ARGV: &[&str] = &[
142
- "codex",
143
- "--sandbox",
144
- "read-only",
145
- "--ask-for-approval",
146
- "on-request",
147
- ];
148
-
149
- struct Case {
150
- env: HermeticTestEnv,
151
- workspace: PathBuf,
152
- shim_path: String,
153
- ancestry_json: String,
154
- socket: Option<PathBuf>,
155
- }
156
-
157
- impl Case {
158
- /// R7 (permission-clamp guardrail) uses a claude source with a success-path
159
- /// backing shim so the fork actually produces a NEW row whose permission clamp
160
- /// can be inspected — without a real fork the guardrail would read no row and
161
- /// pass vacuously. (R8 does not use Case: it exercises the library entry with
162
- /// an in-process RecordingTransport — see `r8_...`.)
163
- fn start(tag: &str) -> Self {
164
- Self::start_with_ancestry(tag, &["codex", CODEX_BYPASS])
165
- }
166
-
167
- /// Every CLI invocation of this Case pins `ancestry_argv` through the
168
- /// product's existing test seam so the derived approval policy is a
169
- /// function of the FIXTURE, never of the host process tree.
170
- fn start_with_ancestry(tag: &str, ancestry_argv: &[&str]) -> Self {
171
- let env = HermeticTestEnv::enter_with_leader(tag);
172
- let workspace = env.workspace("ws");
173
- write_team_docs(&workspace, "claude");
174
- let shim_dir = write_claude_backing_shim(&workspace);
175
- let shim_path = format!(
176
- "{}:{}",
177
- shim_dir.display(),
178
- std::env::var("PATH").expect("PATH present")
179
- );
180
- let mut case = Self {
181
- env,
182
- workspace,
183
- shim_path,
184
- ancestry_json: serde_json::to_string(ancestry_argv).expect("ancestry argv json"),
185
- socket: None,
186
- };
187
- case.quick_start();
188
- case.seed_source_session_tuple();
189
- case
190
- }
191
-
192
- fn ws(&self) -> &str {
193
- self.workspace.to_str().expect("ws utf8")
194
- }
195
-
196
- fn state_path(&self) -> PathBuf {
197
- self.workspace
198
- .join(".team")
199
- .join("runtime")
200
- .join("state.json")
201
- }
202
-
203
- fn run(&self, args: &[&str]) -> Output {
204
- self.env.run_cli_env(
205
- &self.workspace,
206
- args,
207
- &[
208
- ("PATH", self.shim_path.as_str()),
209
- (ANCESTRY_ENV, self.ancestry_json.as_str()),
210
- ],
211
- )
212
- }
213
-
214
- fn quick_start(&mut self) {
215
- let out = self.run(&[
216
- "quick-start",
217
- self.ws(),
218
- "--workspace",
219
- self.ws(),
220
- "--name",
221
- TEAM_NAME,
222
- "--yes",
223
- "--json",
224
- ]);
225
- if let Ok(v) = serde_json::from_slice::<Value>(&out.stdout) {
226
- if let Some(cmd) = v
227
- .get("attach_commands")
228
- .and_then(|a| a.as_array())
229
- .and_then(|a| a.first())
230
- .and_then(|c| c.as_str())
231
- .or_else(|| v.get("leader_attach_command").and_then(|c| c.as_str()))
232
- {
233
- let toks: Vec<&str> = cmd.split_whitespace().collect();
234
- if let Some(i) = toks.iter().position(|t| *t == "-S") {
235
- if let Some(sock) = toks.get(i + 1) {
236
- self.socket = Some(PathBuf::from(*sock));
237
- }
238
- }
239
- }
240
- }
241
- }
242
-
243
- /// Seed the SOURCE session tuple so the fork reaches the capability gate
244
- /// (not a missing-session gate) — mirrors the old refusal contract's
245
- /// `seed_session_id`, which existed precisely so "the capability gate is what
246
- /// fires".
247
- fn seed_source_session_tuple(&self) {
248
- // A real rollout file the source tuple points at.
249
- let rollout_file = self.workspace.join("fixture-source-rollout.jsonl");
250
- let _ = std::fs::write(&rollout_file, "{\"type\":\"fixture-source\"}\n");
251
- let Ok(raw) = std::fs::read_to_string(self.state_path()) else {
252
- return;
253
- };
254
- let Ok(mut state) = serde_json::from_str::<Value>(&raw) else {
255
- return;
256
- };
257
- let tuple = json!({
258
- "session_id": "sess-cf-batch4-source",
259
- "rollout_path": rollout_file.to_string_lossy(),
260
- "captured_at": "2026-07-21T00:00:00Z",
261
- "captured_via": "contract-fixture"
262
- });
263
- let mut patch = |row: &mut Value| {
264
- if let Some(obj) = row.as_object_mut() {
265
- for (k, v) in tuple.as_object().unwrap() {
266
- obj.insert(k.clone(), v.clone());
267
- }
268
- }
269
- };
270
- if let Some(row) = state.get_mut("agents").and_then(|a| a.get_mut(SOURCE)) {
271
- patch(row);
272
- }
273
- if let Some(teams) = state.get_mut("teams").and_then(Value::as_object_mut) {
274
- for team in teams.values_mut() {
275
- if let Some(row) = team.get_mut("agents").and_then(|a| a.get_mut(SOURCE)) {
276
- patch(row);
277
- }
278
- }
279
- }
280
- let _ = std::fs::write(
281
- self.state_path(),
282
- serde_json::to_string_pretty(&state).unwrap(),
283
- );
284
- }
285
-
286
- fn fork(&self, as_name: &str) -> Value {
287
- let out = self.run(&[
288
- "fork-agent",
289
- SOURCE,
290
- "--as",
291
- as_name,
292
- "--workspace",
293
- self.ws(),
294
- "--team",
295
- TEAM_NAME,
296
- "--json",
297
- ]);
298
- let stderr = String::from_utf8_lossy(&out.stderr).to_string();
299
- serde_json::from_slice::<Value>(&out.stdout).unwrap_or_else(|_| {
300
- json!({
301
- "ok": out.status.success(),
302
- "_exit": out.status.code(),
303
- "_stderr": stderr,
304
- })
305
- })
306
- }
307
-
308
- fn team_agent_rows(&self) -> serde_json::Map<String, Value> {
309
- let Ok(raw) = std::fs::read_to_string(self.state_path()) else {
310
- return serde_json::Map::new();
311
- };
312
- let Ok(v) = serde_json::from_str::<Value>(&raw) else {
313
- return serde_json::Map::new();
314
- };
315
- if let Some(teams) = v.get("teams").and_then(Value::as_object) {
316
- for team in teams.values() {
317
- if let Some(agents) = team.get("agents").and_then(Value::as_object) {
318
- if agents.contains_key(SOURCE) {
319
- return agents.clone();
320
- }
321
- }
322
- }
323
- }
324
- serde_json::Map::new()
325
- }
326
- }
327
-
328
- impl Drop for Case {
329
- fn drop(&mut self) {
330
- if let Some(sock) = &self.socket {
331
- let _ = std::process::Command::new("tmux")
332
- .args(["-S", sock.to_str().unwrap_or(""), "kill-server"])
333
- .output();
334
- }
335
- let ws = self.workspace.to_string_lossy().to_string();
336
- if let Ok(out) = std::process::Command::new("ps")
337
- .args(["-axo", "pid=,command="])
338
- .output()
339
- {
340
- for line in String::from_utf8_lossy(&out.stdout).lines() {
341
- if line.contains(&ws) {
342
- if let Some(pid) = line.split_whitespace().next() {
343
- let _ = std::process::Command::new("kill")
344
- .args(["-TERM", pid])
345
- .output();
346
- }
347
- }
348
- }
349
- }
350
- let _ = &self.env;
351
- }
352
- }
353
-
354
- fn write_team_docs(workspace: &Path, provider: &str) {
355
- std::fs::create_dir_all(workspace.join("agents")).expect("create agents dir");
356
- std::fs::write(
357
- workspace.join("TEAM.md"),
358
- format!(
359
- "---\nname: {TEAM_NAME}\nobjective: clone-fork batch4.\nprovider: {provider}\n---\n"
360
- ),
361
- )
362
- .expect("write TEAM.md");
363
- std::fs::write(
364
- workspace.join("agents").join(format!("{SOURCE}.md")),
365
- format!(
366
- "---\nname: {SOURCE}\nrole: {SOURCE}\nprovider: {provider}\nauth_mode: subscription\ndangerously_skip_permissions: false\ntools:\n - mcp_team\n---\n\n{SOURCE} body.\n"
367
- ),
368
- )
369
- .expect("write source role doc");
370
- }
371
-
372
124
  /// Copilot team docs for the library-entry R8 (a separate agents dir so the
373
125
  /// OfflineTransport quick-start compiles a copilot source).
374
126
  fn write_copilot_team_docs(workspace: &Path) -> PathBuf {
@@ -445,43 +197,6 @@ fn seed_source_tuple_in_state(workspace: &Path, agent: &str) {
445
197
  save_runtime_state(workspace, &state).expect("save seeded state");
446
198
  }
447
199
 
448
- /// Claude success-path shim producing a NEW backing keyed to the predetermined
449
- /// `--session-id` (same mechanism as batch3): the R7 fork must actually complete
450
- /// so a NEW state row exists to inspect for the permission clamp — otherwise the
451
- /// guardrail reads no row and passes vacuously (false-green-hole type 8).
452
- fn write_claude_backing_shim(workspace: &Path) -> PathBuf {
453
- let bin_dir = workspace.join("shim-bin");
454
- std::fs::create_dir_all(&bin_dir).expect("create shim dir");
455
- let shim = bin_dir.join("claude");
456
- std::fs::write(
457
- &shim,
458
- r#"#!/bin/sh
459
- sid=""
460
- prev=""
461
- for a in "$@"; do
462
- if [ "$prev" = "--session-id" ]; then sid="$a"; fi
463
- prev="$a"
464
- done
465
- if [ -n "$sid" ]; then
466
- enc=$(printf '%s' "$PWD" | sed 's/[^a-zA-Z0-9]/-/g')
467
- dir="$HOME/.claude/projects/$enc"
468
- mkdir -p "$dir"
469
- printf '{"sessionId":"%s","type":"fork-backing"}\n' "$sid" > "$dir/$sid.jsonl"
470
- fi
471
- echo 'claude shim ready'
472
- exec sleep 3600
473
- "#,
474
- )
475
- .expect("write claude shim");
476
- #[cfg(unix)]
477
- {
478
- use std::os::unix::fs::PermissionsExt;
479
- std::fs::set_permissions(&shim, std::fs::Permissions::from_mode(0o755))
480
- .expect("chmod claude shim");
481
- }
482
- bin_dir
483
- }
484
-
485
200
  /// R8 Copilot fork caps RE-CHARTER — a Copilot fork must no longer be refused by a
486
201
  /// blanket capability gate (§1.4 proves the directory-copy + SQLite-transaction
487
202
  /// primitive is feasible under an isolated COPILOT_HOME). Baseline red: the fork
@@ -492,6 +207,7 @@ exec sleep 3600
492
207
  /// `verifier-r8-caps-recharter-signoff.md`. The SQLite FK-table integrity and
493
208
  /// exact-nonce recall remain the GREEN half / subscription-E2E (§1.4).
494
209
  #[test]
210
+ #[serial_test::serial(env)]
495
211
  fn r8_copilot_fork_is_no_longer_capability_refused() {
496
212
  run_process_isolated(R8_CHILD, R8_TEST, || {
497
213
  // R8 uses the LIBRARY entry `fork_agent_with_transport` (the same entry the old
@@ -543,48 +259,6 @@ fn r8_copilot_fork_is_no_longer_capability_refused() {
543
259
  });
544
260
  }
545
261
 
546
- /// R7 permission-clamp GUARDRAIL — a fork's effective approval policy is derived
547
- /// from the LEADER and never escalates above it (MUST-16). 0.5.66 bypass 单源:
548
- /// fork 的 approval policy 由源角色的 `dangerously_skip_permissions` 派生
549
- /// (本 fixture = false → `source=disabled`),不再依赖 leader argv 继承。任何
550
- /// fork 都不得出现 `source=leader_process`(旧模型已删)或 capability 高于源。
551
- #[test]
552
- fn r7_fork_effective_permissions_are_clamped_to_leader_guardrail() {
553
- run_process_isolated(R7_CHILD, R7_TEST, || {
554
- // Claude source + success-path backing shim so the fork COMPLETES and a NEW
555
- // row exists to inspect — no vacuous pass on a refused fork. The source role
556
- // declares `dangerously_skip_permissions: false`, so the fork's policy must
557
- // resolve to `disabled` (fail-closed) — the new single-source model.
558
- let case = Case::start("cf-r7");
559
- let fork = case.fork(NEW);
560
- let err = fork.to_string();
561
- assert!(
562
- err.contains("refuses --as")
563
- || err.contains("in-place")
564
- || fork.get("ok") == Some(&json!(false)),
565
- "in-place fork refuses --as {NEW}; no NEW row to clamp. fork={fork}"
566
- );
567
- });
568
- }
569
-
570
- /// R7b reverse positive control — same source role (dangerously_skip_permissions:
571
- /// false) must also resolve to `source=disabled` under any ancestry seam. 0.5.66
572
- /// 起 policy 与 leader argv 无关:source 恒 `disabled`,fork 恒不升级(MUST-16)。
573
- #[test]
574
- fn r7b_fork_policy_under_restricted_leader_ancestry_is_disabled() {
575
- run_process_isolated(R7B_CHILD, R7B_TEST, || {
576
- let case = Case::start_with_ancestry("cf-r7b", RESTRICTED_LEADER_ARGV);
577
- let fork = case.fork(NEW);
578
- let err = fork.to_string();
579
- assert!(
580
- err.contains("refuses --as")
581
- || err.contains("in-place")
582
- || fork.get("ok") == Some(&json!(false)),
583
- "in-place fork refuses --as {NEW}; no NEW row. fork={fork}"
584
- );
585
- });
586
- }
587
-
588
262
  // ---------------------------------------------------------------------------
589
263
  // Minimal in-process Transport for the R8 library-entry test (mirrors the
590
264
  // RecordingTransport the existing copilot refusal contract uses). Kept local so
@@ -57,7 +57,7 @@ fn t06_each_official_mode_selects_one_runtime_contract_in_real_spawn_prompt() {
57
57
  .iter()
58
58
  .find(|spawn| spawn.window.as_str().contains(id))
59
59
  .unwrap_or_else(|| panic!("T06/{id}: no spawn recorded for product-catalog mode"));
60
- let prompt = flag_value(&spawn.argv, "--append-system-prompt");
60
+ let prompt = spawn_prompt(&spawn.argv);
61
61
  let own_heading = format!("{CONTRACT_HEADING_PREFIX}{id}");
62
62
  assert!(
63
63
  prompt.contains(&own_heading),
@@ -106,7 +106,7 @@ fn t06_selected_templates_project_the_two_signed_communication_boundaries() {
106
106
  .iter()
107
107
  .find(|spawn| spawn.window.as_str().contains(id))
108
108
  .unwrap_or_else(|| panic!("T06/{id}: missing recorded spawn"));
109
- flag_value(&spawn.argv, "--append-system-prompt")
109
+ spawn_prompt(&spawn.argv)
110
110
  };
111
111
 
112
112
  let leader = prompt(CommunicationMode::LeaderCentric);
@@ -161,7 +161,7 @@ fn t07_final_spawn_prompt_does_not_leak_leader_centric_obligations_into_orchestr
161
161
  .as_str()
162
162
  .contains(CommunicationMode::Orchestrated.as_str())
163
163
  })
164
- .map(|spawn| flag_value(&spawn.argv, "--append-system-prompt"))
164
+ .map(|spawn| spawn_prompt(&spawn.argv))
165
165
  .expect("T07/orchestrated: missing recorded spawn");
166
166
 
167
167
  for required in [
@@ -189,7 +189,7 @@ fn t07_final_spawn_prompt_does_not_leak_leader_centric_obligations_into_orchestr
189
189
  let default_spawns = default_transport.spawns.lock().unwrap();
190
190
  let default_prompt = default_spawns
191
191
  .first()
192
- .map(|spawn| flag_value(&spawn.argv, "--append-system-prompt"))
192
+ .map(|spawn| spawn_prompt(&spawn.argv))
193
193
  .expect("T07/leader_centric positive control: missing recorded default spawn");
194
194
  for required in [
195
195
  "Progress, blockers, questions:",
@@ -266,7 +266,7 @@ fn fixture(tag: &str, team_mode: Option<&str>) -> PathBuf {
266
266
  std::fs::write(
267
267
  root.join("agents").join(format!("worker_{id}.md")),
268
268
  format!(
269
- "---\nname: worker_{id}\nrole: Communication Worker\nprovider: claude\ndangerously_skip_permissions: false\ncommunication_mode: {id}\ntools:\n - mcp_team\n---\n\nROLE BODY SENTINEL {id}\n"
269
+ "---\nname: worker_{id}\nrole: Communication Worker\nprovider: codex\nmodel: gpt-5.5\ndangerously_skip_permissions: false\ncommunication_mode: {id}\ntools:\n - mcp_team\n---\n\nROLE BODY SENTINEL {id}\n"
270
270
  ),
271
271
  )
272
272
  .unwrap();
@@ -285,17 +285,36 @@ fn default_fixture(tag: &str) -> PathBuf {
285
285
  }
286
286
  std::fs::write(
287
287
  root.join("agents").join("worker_default.md"),
288
- "---\nname: worker_default\nrole: Communication Worker\nprovider: claude\ndangerously_skip_permissions: false\ntools:\n - mcp_team\n---\n\nROLE BODY SENTINEL default\n",
288
+ "---\nname: worker_default\nrole: Communication Worker\nprovider: codex\nmodel: gpt-5.5\ndangerously_skip_permissions: false\ntools:\n - mcp_team\n---\n\nROLE BODY SENTINEL default\n",
289
289
  )
290
290
  .unwrap();
291
291
  root
292
292
  }
293
293
 
294
- fn flag_value(argv: &[String], flag: &str) -> String {
295
- argv.windows(2)
296
- .find(|pair| pair[0] == flag)
297
- .map(|pair| pair[1].clone())
298
- .unwrap_or_default()
294
+ /// The Codex worker carries the assembled prompt as one escaped
295
+ /// `-c developer_instructions="..."` override; undo that escaping.
296
+ fn spawn_prompt(argv: &[String]) -> String {
297
+ let Some(escaped) = argv
298
+ .iter()
299
+ .find_map(|arg| arg.strip_prefix("developer_instructions=\""))
300
+ .and_then(|value| value.strip_suffix('"'))
301
+ else {
302
+ return String::new();
303
+ };
304
+ let mut prompt = String::with_capacity(escaped.len());
305
+ let mut chars = escaped.chars();
306
+ while let Some(ch) = chars.next() {
307
+ if ch != '\\' {
308
+ prompt.push(ch);
309
+ continue;
310
+ }
311
+ match chars.next() {
312
+ Some('n') => prompt.push('\n'),
313
+ Some(other) => prompt.push(other),
314
+ None => prompt.push('\\'),
315
+ }
316
+ }
317
+ prompt
299
318
  }
300
319
 
301
320
  #[derive(Debug, Clone)]
@@ -1101,14 +1101,14 @@ fn rules_t02_inline_server_map_preserves_unknown_and_non_object_values() {
1101
1101
  fn rules_t02_non_copilot_writer_keeps_canonical_schema() {
1102
1102
  let hermetic = enter_hermetic("rules-t02-canonical");
1103
1103
  let ws = hermetic.workspace("canonical");
1104
- let config = team_agent::provider::get_adapter(Provider::ClaudeCode)
1104
+ let config = team_agent::provider::get_adapter(Provider::Codex)
1105
1105
  .mcp_config(team_agent::provider::AuthMode::Subscription)
1106
1106
  .unwrap();
1107
1107
  let path = team_agent::lifecycle::launch::write_worker_mcp_config_for_provider(
1108
1108
  &ws,
1109
1109
  "synthetic",
1110
1110
  &config,
1111
- Some(Provider::ClaudeCode),
1111
+ Some(Provider::Codex),
1112
1112
  )
1113
1113
  .unwrap();
1114
1114
  let written: serde_json::Value =
@@ -235,8 +235,8 @@ fn start_mode_serde_names_match_python_start_mode_strings() {
235
235
  // codex sess backing-MISSING !allow_fresh -> noop/refuse (绝不静默 resume 死 session)
236
236
  // codex sess backing-MISSING allow_fresh -> fresh_after_missing_rollout
237
237
  // codex no-sess any -> fresh
238
- // claude/copilot sess backing-missing -> fresh_after_missing_rollout 或 noop/refuse
239
- // claude no-sess -> fresh
238
+ // copilot/grok sess backing-missing -> fresh_after_missing_rollout 或 noop/refuse
239
+ // copilot no-sess -> fresh
240
240
  // 这是 bug-085 把 start_mode 分类从 start_agent 的 lock+spawn 全路径剥离出来的命门。
241
241
  // ───────────────────────────────────────────────────────────────────────
242
242
 
@@ -308,7 +308,7 @@ fn decide_start_mode_no_session_is_fresh() {
308
308
 
309
309
  #[test]
310
310
  fn decide_start_mode_checks_backing_for_all_resumable_providers() {
311
- for provider in ["claude", "claude_code", "copilot"] {
311
+ for provider in ["copilot", "grok"] {
312
312
  assert_eq!(
313
313
  decide_start_mode(provider, Some(&sid("s1")), None, false, true),
314
314
  StartMode::FreshAfterMissingRollout,
@@ -326,14 +326,15 @@ fn decide_start_mode_checks_backing_for_all_resumable_providers() {
326
326
  );
327
327
  }
328
328
  assert_eq!(
329
- decide_start_mode("claude", None, None, false, true),
329
+ decide_start_mode("copilot", None, None, false, true),
330
330
  StartMode::Fresh
331
331
  );
332
332
  }
333
333
 
334
334
  #[test]
335
335
  fn decide_start_mode_refuses_session_id_for_nonresumable_providers() {
336
- for provider in ["fake", "gemini_cli"] {
336
+ // A persisted legacy Claude Code / Pi worker row is no longer resumable.
337
+ for provider in ["fake", "gemini_cli", "claude", "claude_code", "pi"] {
337
338
  assert_eq!(
338
339
  decide_start_mode(provider, Some(&sid("s1")), None, true, false),
339
340
  StartMode::Noop,
@@ -384,7 +385,7 @@ fn classify_restart_plan_interacted_unresumable_no_allow_fresh_yields_refuse() {
384
385
  "session_name": "team-a",
385
386
  "agents": {
386
387
  "w1": {
387
- "provider": "claude",
388
+ "provider": "copilot",
388
389
  "first_send_at": "2026-05-27T10:00:00+00:00",
389
390
  "session_id": null
390
391
  }
@@ -437,7 +438,7 @@ fn classify_restart_plan_interacted_unresumable_with_allow_fresh_yields_fresh_st
437
438
  let state = json!({
438
439
  "agents": {
439
440
  "w1": {
440
- "provider": "claude",
441
+ "provider": "copilot",
441
442
  "first_send_at": "2026-05-27T10:00:00+00:00",
442
443
  "session_id": null
443
444
  }
@@ -467,7 +468,7 @@ fn classify_restart_plan_never_captured_null_session_auto_fresh_partial_resume()
467
468
  // not captured" bug state) — see the OTHER refuse-interacted test below
468
469
  // and upgrade_restart_refuses_interacted_worker_without_session_id.
469
470
  let state = json!({
470
- "agents": { "w1": { "provider": "claude", "session_id": null } }
471
+ "agents": { "w1": { "provider": "copilot", "session_id": null } }
471
472
  });
472
473
  let plan = classify_restart_plan(&state, false).expect("纯验证不应 Err");
473
474
  assert_eq!(plan.decisions.len(), 1);
@@ -493,7 +494,7 @@ fn restart_required_missing_skips_never_captured_workers() {
493
494
  use crate::lifecycle::restart::restart_required_missing_session_agent_ids;
494
495
  let state = json!({
495
496
  "agents": {
496
- "w1": { "provider": "claude", "session_id": null, "status": "running" }
497
+ "w1": { "provider": "copilot", "session_id": null, "status": "running" }
497
498
  }
498
499
  });
499
500
  let missing = restart_required_missing_session_agent_ids(&state);
@@ -513,7 +514,7 @@ fn restart_required_missing_keeps_null_session_with_first_send_at() {
513
514
  let state = json!({
514
515
  "agents": {
515
516
  "w1": {
516
- "provider": "claude",
517
+ "provider": "copilot",
517
518
  "session_id": null,
518
519
  "status": "running",
519
520
  "spawn_cwd": "/tmp/ws",
@@ -539,7 +540,7 @@ fn restart_required_missing_keeps_null_session_with_last_result_at() {
539
540
  let state = json!({
540
541
  "agents": {
541
542
  "w1": {
542
- "provider": "claude",
543
+ "provider": "copilot",
543
544
  "session_id": null,
544
545
  "status": "running",
545
546
  "spawn_cwd": "/tmp/ws",
@@ -565,7 +566,7 @@ fn classify_restart_plan_null_session_with_last_result_at_refuses_without_allow_
565
566
  let state = json!({
566
567
  "agents": {
567
568
  "w1": {
568
- "provider": "claude",
569
+ "provider": "copilot",
569
570
  "session_id": null,
570
571
  "last_result_at": "2026-01-01T00:00:00+00:00",
571
572
  }
@@ -586,7 +587,7 @@ fn classify_restart_plan_null_session_with_last_result_at_refuses_without_allow_
586
587
  fn classify_restart_plan_never_interacted_null_session_with_allow_fresh_marks_forced_fresh() {
587
588
  // E6 层2: 同上自启动 null-session worker,但显式 --allow-fresh → 用户主动认账丢上下文 → FreshStart。
588
589
  let state = json!({
589
- "agents": { "w1": { "provider": "claude", "session_id": null } }
590
+ "agents": { "w1": { "provider": "copilot", "session_id": null } }
590
591
  });
591
592
  let plan = classify_restart_plan(&state, true).expect("纯验证不应 Err");
592
593
  assert_eq!(plan.decisions.len(), 1);
@@ -748,9 +749,9 @@ fn classify_restart_plan_produces_corrupt_entries_with_python_type_names() {
748
749
  // ("str"/"int"/"list") —— 锁跨语言 type-name 映射,不是手设字段。
749
750
  let state = json!({
750
751
  "agents": {
751
- "w_str": { "provider": "claude", "first_send_at": "" },
752
- "w_int": { "provider": "claude", "first_send_at": 0 },
753
- "w_list": { "provider": "claude", "first_send_at": [] }
752
+ "w_str": { "provider": "copilot", "first_send_at": "" },
753
+ "w_int": { "provider": "copilot", "first_send_at": 0 },
754
+ "w_list": { "provider": "copilot", "first_send_at": [] }
754
755
  }
755
756
  });
756
757
  // corrupt 非空 → restart 在 teardown 之前 hard refuse(决策前)。