@team-agent/installer 0.5.125 → 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 (96) hide show
  1. package/Cargo.lock +1 -1
  2. package/Cargo.toml +1 -1
  3. package/crates/team-agent/src/cli/diagnose.rs +0 -68
  4. package/crates/team-agent/src/cli/emit.rs +6 -2
  5. package/crates/team-agent/src/cli/intent/runtime_tests.rs +10 -10
  6. package/crates/team-agent/src/cli/mod.rs +22 -28
  7. package/crates/team-agent/src/cli/models.rs +7 -764
  8. package/crates/team-agent/src/cli/tests/mod.rs +1 -1
  9. package/crates/team-agent/src/cli/tests/run_delegation.rs +5 -4
  10. package/crates/team-agent/src/compiler/tests.rs +18 -3
  11. package/crates/team-agent/src/compiler.rs +4 -203
  12. package/crates/team-agent/src/contract_runtime/backend.rs +61 -38
  13. package/crates/team-agent/src/contract_runtime/config.rs +7 -4
  14. package/crates/team-agent/src/contract_runtime/fork.rs +368 -0
  15. package/crates/team-agent/src/contract_runtime/framework.rs +8 -10
  16. package/crates/team-agent/src/contract_runtime/mod.rs +1 -0
  17. package/crates/team-agent/src/contract_runtime/registry.rs +60 -19
  18. package/crates/team-agent/src/coordinator/tests/api_error_recovery.rs +29 -8
  19. package/crates/team-agent/src/coordinator/tests/health_sync.rs +0 -42
  20. package/crates/team-agent/src/leader/start.rs +1 -1
  21. package/crates/team-agent/src/lifecycle/launch/add_agent_state.rs +2 -195
  22. package/crates/team-agent/src/lifecycle/launch/clone_agent.rs +11 -27
  23. package/crates/team-agent/src/lifecycle/launch/fork_agent.rs +18 -28
  24. package/crates/team-agent/src/lifecycle/launch/fork_entry.rs +6 -87
  25. package/crates/team-agent/src/lifecycle/launch/mcp_config.rs +1 -9
  26. package/crates/team-agent/src/lifecycle/launch/pi_mcp.rs +74 -244
  27. package/crates/team-agent/src/lifecycle/launch/quick_start.rs +0 -24
  28. package/crates/team-agent/src/lifecycle/launch/role_source.rs +5 -0
  29. package/crates/team-agent/src/lifecycle/launch/spawn.rs +21 -33
  30. package/crates/team-agent/src/lifecycle/launch.rs +0 -23
  31. package/crates/team-agent/src/lifecycle/profile_launch.rs +18 -317
  32. package/crates/team-agent/src/lifecycle/restart/common.rs +42 -315
  33. package/crates/team-agent/src/lifecycle/restart/selection.rs +5 -5
  34. package/crates/team-agent/src/lifecycle/restart.rs +0 -2
  35. package/crates/team-agent/src/lifecycle/tests/behavioral_diff_264_red.rs +11 -6
  36. package/crates/team-agent/src/lifecycle/tests/claude_profile_launch_red.rs +8 -320
  37. package/crates/team-agent/src/lifecycle/tests/cli_argv_routing_red.rs +22 -138
  38. package/crates/team-agent/src/lifecycle/tests/clone_fork_copilot_perms_red.rs +4 -334
  39. package/crates/team-agent/src/lifecycle/tests/communication_mode_runtime_contract_red.rs +30 -11
  40. package/crates/team-agent/src/lifecycle/tests/copilot_provider_red.rs +2 -2
  41. package/crates/team-agent/src/lifecycle/tests/core.rs +17 -16
  42. package/crates/team-agent/src/lifecycle/tests/grok_require_explicit_model_red.rs +12 -12
  43. package/crates/team-agent/src/lifecycle/tests/harvest2_a_batch_red.rs +3 -51
  44. package/crates/team-agent/src/lifecycle/tests/launch_spawn.rs +26 -28
  45. package/crates/team-agent/src/lifecycle/tests/pi_catalog_red.rs +6 -18
  46. package/crates/team-agent/src/lifecycle/tests/pi_command_red.rs +52 -70
  47. package/crates/team-agent/src/lifecycle/tests/pi_dual_entry_red.rs +4 -157
  48. package/crates/team-agent/src/lifecycle/tests/pi_executable_mcp_red.rs +10 -302
  49. package/crates/team-agent/src/lifecycle/tests/pi_lifecycle_doctor_red.rs +1 -68
  50. package/crates/team-agent/src/lifecycle/tests/pi_native_mcp_capability_red.rs +1 -19
  51. package/crates/team-agent/src/lifecycle/tests/pi_session_delivery_red.rs +2 -100
  52. package/crates/team-agent/src/lifecycle/tests/quick_start_worker_readiness_red.rs +11 -10
  53. package/crates/team-agent/src/lifecycle/tests/restart_session_capture_red.rs +2 -106
  54. package/crates/team-agent/src/lifecycle/tests/status_credential_redaction_contract.rs +2 -2
  55. package/crates/team-agent/src/lifecycle/tests/swallow_batch4_semantics_red.rs +2 -254
  56. package/crates/team-agent/src/lifecycle/tests/upgrade_compat_0211_red.rs +4 -4
  57. package/crates/team-agent/src/lifecycle/tests/verify_rs031_window_consistency_red.rs +6 -5
  58. package/crates/team-agent/src/lifecycle/tests/worker_spawn_env_red.rs +7 -16
  59. package/crates/team-agent/src/lifecycle/tests.rs +0 -3
  60. package/crates/team-agent/src/lifecycle/types.rs +2 -18
  61. package/crates/team-agent/src/mcp_server/readiness_tests.rs +1 -1
  62. package/crates/team-agent/src/messaging/delivery.rs +12 -141
  63. package/crates/team-agent/src/messaging/delivery_consumption_tests.rs +5 -5
  64. package/crates/team-agent/src/messaging/tests/dup_inject.rs +3 -3
  65. package/crates/team-agent/src/messaging/tests/spine.rs +26 -32
  66. package/crates/team-agent/src/provider/adapter.rs +35 -238
  67. package/crates/team-agent/src/provider/adapters/mod.rs +4 -4
  68. package/crates/team-agent/src/provider/model_catalog.rs +13 -201
  69. package/crates/team-agent/src/provider/session/capture.rs +6 -106
  70. package/crates/team-agent/src/provider/session/context_fork/outcome.rs +0 -4
  71. package/crates/team-agent/src/provider/session/context_fork.rs +15 -107
  72. package/crates/team-agent/src/provider/session_scan/common.rs +10 -34
  73. package/crates/team-agent/src/provider/session_scan/pi.rs +1 -34
  74. package/crates/team-agent/src/provider/session_scan.rs +4 -10
  75. package/crates/team-agent/src/provider/tests/adapter.rs +34 -91
  76. package/crates/team-agent/src/provider/tests/command_helpers.rs +3 -12
  77. package/crates/team-agent/src/provider/tests/idle.rs +0 -25
  78. package/crates/team-agent/src/provider/wire.rs +51 -23
  79. package/crates/team-agent/src/state/abnormal_watch/tests/mod.rs +1 -1
  80. package/crates/team-agent/src/state/persist.rs +6 -6
  81. package/crates/team-agent/src/state/repository/tests.rs +2 -2
  82. package/package.json +4 -4
  83. package/skills/team-agent/SKILL.md +6 -4
  84. package/skills/team-agent/command-coverage.json +15 -1
  85. package/skills/team-agent/docs/reference/team-agent-operator.md +5 -3
  86. package/skills/team-agent/references/team-agent-operator.md +5 -3
  87. package/crates/team-agent/src/lifecycle/restart/avatar.rs +0 -1805
  88. package/crates/team-agent/src/lifecycle/tests/claude_compatible_config_red.rs +0 -325
  89. package/crates/team-agent/src/lifecycle/tests/pi_compiler_red.rs +0 -210
  90. package/crates/team-agent/src/lifecycle/tests/pi_fork_session_inheritance_red.rs +0 -1409
  91. package/crates/team-agent/src/provider/adapters/claude.rs +0 -78
  92. package/crates/team-agent/src/provider/adapters/claude_fork.rs +0 -131
  93. package/crates/team-agent/src/provider/adapters/pi.rs +0 -100
  94. package/crates/team-agent/src/provider/session/context_fork/claude.rs +0 -123
  95. package/crates/team-agent/src/provider/session_scan/claude.rs +0 -523
  96. 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"
@@ -129,247 +121,6 @@ fn copilot_clone_fork_env_fixtures_run_outside_parent_process() {
129
121
  });
130
122
  }
131
123
 
132
- /// Gate6 CI-hermeticity revision: the R7 fixture must pin the process-ancestry
133
- /// seam explicitly (`TEAM_AGENT_TEST_PROCESS_ANCESTRY_ARGV_JSON`) instead of
134
- /// depending on the REAL ancestry of the test-runner host. Unpinned, a local
135
- /// runner descending from a dangerous-bypass leader yields
136
- /// `source=leader_process` (historical local green) while a clean CI runner
137
- /// correctly yields `source=disabled` — a non-hermetic assertion, not a product
138
- /// regression. Precedent: `codex_mcp_approval_inheritance_red.rs` `MockAncestry`
139
- /// (pins both bypass and restricted leader argv).
140
- const ANCESTRY_ENV: &str = "TEAM_AGENT_TEST_PROCESS_ANCESTRY_ARGV_JSON";
141
- const CODEX_BYPASS: &str = "--dangerously-bypass-approvals-and-sandbox";
142
- const RESTRICTED_LEADER_ARGV: &[&str] = &[
143
- "codex",
144
- "--sandbox",
145
- "read-only",
146
- "--ask-for-approval",
147
- "on-request",
148
- ];
149
-
150
- struct Case {
151
- env: HermeticTestEnv,
152
- workspace: PathBuf,
153
- shim_path: String,
154
- ancestry_json: String,
155
- socket: Option<PathBuf>,
156
- }
157
-
158
- impl Case {
159
- /// R7 (permission-clamp guardrail) uses a claude source with a success-path
160
- /// backing shim so the fork actually produces a NEW row whose permission clamp
161
- /// can be inspected — without a real fork the guardrail would read no row and
162
- /// pass vacuously. (R8 does not use Case: it exercises the library entry with
163
- /// an in-process RecordingTransport — see `r8_...`.)
164
- fn start(tag: &str) -> Self {
165
- Self::start_with_ancestry(tag, &["codex", CODEX_BYPASS])
166
- }
167
-
168
- /// Every CLI invocation of this Case pins `ancestry_argv` through the
169
- /// product's existing test seam so the derived approval policy is a
170
- /// function of the FIXTURE, never of the host process tree.
171
- fn start_with_ancestry(tag: &str, ancestry_argv: &[&str]) -> Self {
172
- let env = HermeticTestEnv::enter_with_leader(tag);
173
- let workspace = env.workspace("ws");
174
- write_team_docs(&workspace, "claude");
175
- let shim_dir = write_claude_backing_shim(&workspace);
176
- let shim_path = format!(
177
- "{}:{}",
178
- shim_dir.display(),
179
- std::env::var("PATH").expect("PATH present")
180
- );
181
- let mut case = Self {
182
- env,
183
- workspace,
184
- shim_path,
185
- ancestry_json: serde_json::to_string(ancestry_argv).expect("ancestry argv json"),
186
- socket: None,
187
- };
188
- case.quick_start();
189
- case.seed_source_session_tuple();
190
- case
191
- }
192
-
193
- fn ws(&self) -> &str {
194
- self.workspace.to_str().expect("ws utf8")
195
- }
196
-
197
- fn state_path(&self) -> PathBuf {
198
- self.workspace
199
- .join(".team")
200
- .join("runtime")
201
- .join("state.json")
202
- }
203
-
204
- fn run(&self, args: &[&str]) -> Output {
205
- self.env.run_cli_env(
206
- &self.workspace,
207
- args,
208
- &[
209
- ("PATH", self.shim_path.as_str()),
210
- (ANCESTRY_ENV, self.ancestry_json.as_str()),
211
- ],
212
- )
213
- }
214
-
215
- fn quick_start(&mut self) {
216
- let out = self.run(&[
217
- "quick-start",
218
- self.ws(),
219
- "--workspace",
220
- self.ws(),
221
- "--name",
222
- TEAM_NAME,
223
- "--yes",
224
- "--json",
225
- ]);
226
- if let Ok(v) = serde_json::from_slice::<Value>(&out.stdout) {
227
- if let Some(cmd) = v
228
- .get("attach_commands")
229
- .and_then(|a| a.as_array())
230
- .and_then(|a| a.first())
231
- .and_then(|c| c.as_str())
232
- .or_else(|| v.get("leader_attach_command").and_then(|c| c.as_str()))
233
- {
234
- let toks: Vec<&str> = cmd.split_whitespace().collect();
235
- if let Some(i) = toks.iter().position(|t| *t == "-S") {
236
- if let Some(sock) = toks.get(i + 1) {
237
- self.socket = Some(PathBuf::from(*sock));
238
- }
239
- }
240
- }
241
- }
242
- }
243
-
244
- /// Seed the SOURCE session tuple so the fork reaches the capability gate
245
- /// (not a missing-session gate) — mirrors the old refusal contract's
246
- /// `seed_session_id`, which existed precisely so "the capability gate is what
247
- /// fires".
248
- fn seed_source_session_tuple(&self) {
249
- // A real rollout file the source tuple points at.
250
- let rollout_file = self.workspace.join("fixture-source-rollout.jsonl");
251
- let _ = std::fs::write(&rollout_file, "{\"type\":\"fixture-source\"}\n");
252
- let Ok(raw) = std::fs::read_to_string(self.state_path()) else {
253
- return;
254
- };
255
- let Ok(mut state) = serde_json::from_str::<Value>(&raw) else {
256
- return;
257
- };
258
- let tuple = json!({
259
- "session_id": "sess-cf-batch4-source",
260
- "rollout_path": rollout_file.to_string_lossy(),
261
- "captured_at": "2026-07-21T00:00:00Z",
262
- "captured_via": "contract-fixture"
263
- });
264
- let mut patch = |row: &mut Value| {
265
- if let Some(obj) = row.as_object_mut() {
266
- for (k, v) in tuple.as_object().unwrap() {
267
- obj.insert(k.clone(), v.clone());
268
- }
269
- }
270
- };
271
- if let Some(row) = state.get_mut("agents").and_then(|a| a.get_mut(SOURCE)) {
272
- patch(row);
273
- }
274
- if let Some(teams) = state.get_mut("teams").and_then(Value::as_object_mut) {
275
- for team in teams.values_mut() {
276
- if let Some(row) = team.get_mut("agents").and_then(|a| a.get_mut(SOURCE)) {
277
- patch(row);
278
- }
279
- }
280
- }
281
- let _ = std::fs::write(
282
- self.state_path(),
283
- serde_json::to_string_pretty(&state).unwrap(),
284
- );
285
- }
286
-
287
- fn fork(&self, as_name: &str) -> Value {
288
- let out = self.run(&[
289
- "fork-agent",
290
- SOURCE,
291
- "--as",
292
- as_name,
293
- "--workspace",
294
- self.ws(),
295
- "--team",
296
- TEAM_NAME,
297
- "--json",
298
- ]);
299
- let stderr = String::from_utf8_lossy(&out.stderr).to_string();
300
- serde_json::from_slice::<Value>(&out.stdout).unwrap_or_else(|_| {
301
- json!({
302
- "ok": out.status.success(),
303
- "_exit": out.status.code(),
304
- "_stderr": stderr,
305
- })
306
- })
307
- }
308
-
309
- fn team_agent_rows(&self) -> serde_json::Map<String, Value> {
310
- let Ok(raw) = std::fs::read_to_string(self.state_path()) else {
311
- return serde_json::Map::new();
312
- };
313
- let Ok(v) = serde_json::from_str::<Value>(&raw) else {
314
- return serde_json::Map::new();
315
- };
316
- if let Some(teams) = v.get("teams").and_then(Value::as_object) {
317
- for team in teams.values() {
318
- if let Some(agents) = team.get("agents").and_then(Value::as_object) {
319
- if agents.contains_key(SOURCE) {
320
- return agents.clone();
321
- }
322
- }
323
- }
324
- }
325
- serde_json::Map::new()
326
- }
327
- }
328
-
329
- impl Drop for Case {
330
- fn drop(&mut self) {
331
- if let Some(sock) = &self.socket {
332
- let _ = std::process::Command::new("tmux")
333
- .args(["-S", sock.to_str().unwrap_or(""), "kill-server"])
334
- .output();
335
- }
336
- let ws = self.workspace.to_string_lossy().to_string();
337
- if let Ok(out) = std::process::Command::new("ps")
338
- .args(["-axo", "pid=,command="])
339
- .output()
340
- {
341
- for line in String::from_utf8_lossy(&out.stdout).lines() {
342
- if line.contains(&ws) {
343
- if let Some(pid) = line.split_whitespace().next() {
344
- let _ = std::process::Command::new("kill")
345
- .args(["-TERM", pid])
346
- .output();
347
- }
348
- }
349
- }
350
- }
351
- let _ = &self.env;
352
- }
353
- }
354
-
355
- fn write_team_docs(workspace: &Path, provider: &str) {
356
- std::fs::create_dir_all(workspace.join("agents")).expect("create agents dir");
357
- std::fs::write(
358
- workspace.join("TEAM.md"),
359
- format!(
360
- "---\nname: {TEAM_NAME}\nobjective: clone-fork batch4.\nprovider: {provider}\n---\n"
361
- ),
362
- )
363
- .expect("write TEAM.md");
364
- std::fs::write(
365
- workspace.join("agents").join(format!("{SOURCE}.md")),
366
- format!(
367
- "---\nname: {SOURCE}\nrole: {SOURCE}\nprovider: {provider}\nauth_mode: subscription\ndangerously_skip_permissions: false\ntools:\n - mcp_team\n---\n\n{SOURCE} body.\n"
368
- ),
369
- )
370
- .expect("write source role doc");
371
- }
372
-
373
124
  /// Copilot team docs for the library-entry R8 (a separate agents dir so the
374
125
  /// OfflineTransport quick-start compiles a copilot source).
375
126
  fn write_copilot_team_docs(workspace: &Path) -> PathBuf {
@@ -446,43 +197,6 @@ fn seed_source_tuple_in_state(workspace: &Path, agent: &str) {
446
197
  save_runtime_state(workspace, &state).expect("save seeded state");
447
198
  }
448
199
 
449
- /// Claude success-path shim producing a NEW backing keyed to the predetermined
450
- /// `--session-id` (same mechanism as batch3): the R7 fork must actually complete
451
- /// so a NEW state row exists to inspect for the permission clamp — otherwise the
452
- /// guardrail reads no row and passes vacuously (false-green-hole type 8).
453
- fn write_claude_backing_shim(workspace: &Path) -> PathBuf {
454
- let bin_dir = workspace.join("shim-bin");
455
- std::fs::create_dir_all(&bin_dir).expect("create shim dir");
456
- let shim = bin_dir.join("claude");
457
- std::fs::write(
458
- &shim,
459
- r#"#!/bin/sh
460
- sid=""
461
- prev=""
462
- for a in "$@"; do
463
- if [ "$prev" = "--session-id" ]; then sid="$a"; fi
464
- prev="$a"
465
- done
466
- if [ -n "$sid" ]; then
467
- enc=$(printf '%s' "$PWD" | sed 's/[^a-zA-Z0-9]/-/g')
468
- dir="$HOME/.claude/projects/$enc"
469
- mkdir -p "$dir"
470
- printf '{"sessionId":"%s","type":"fork-backing"}\n' "$sid" > "$dir/$sid.jsonl"
471
- fi
472
- echo 'claude shim ready'
473
- exec sleep 3600
474
- "#,
475
- )
476
- .expect("write claude shim");
477
- #[cfg(unix)]
478
- {
479
- use std::os::unix::fs::PermissionsExt;
480
- std::fs::set_permissions(&shim, std::fs::Permissions::from_mode(0o755))
481
- .expect("chmod claude shim");
482
- }
483
- bin_dir
484
- }
485
-
486
200
  /// R8 Copilot fork caps RE-CHARTER — a Copilot fork must no longer be refused by a
487
201
  /// blanket capability gate (§1.4 proves the directory-copy + SQLite-transaction
488
202
  /// primitive is feasible under an isolated COPILOT_HOME). Baseline red: the fork
@@ -545,50 +259,6 @@ fn r8_copilot_fork_is_no_longer_capability_refused() {
545
259
  });
546
260
  }
547
261
 
548
- /// R7 permission-clamp GUARDRAIL — a fork's effective approval policy is derived
549
- /// from the LEADER and never escalates above it (MUST-16). 0.5.66 bypass 单源:
550
- /// fork 的 approval policy 由源角色的 `dangerously_skip_permissions` 派生
551
- /// (本 fixture = false → `source=disabled`),不再依赖 leader argv 继承。任何
552
- /// fork 都不得出现 `source=leader_process`(旧模型已删)或 capability 高于源。
553
- #[test]
554
- #[serial_test::serial(env)]
555
- fn r7_fork_effective_permissions_are_clamped_to_leader_guardrail() {
556
- run_process_isolated(R7_CHILD, R7_TEST, || {
557
- // Claude source + success-path backing shim so the fork COMPLETES and a NEW
558
- // row exists to inspect — no vacuous pass on a refused fork. The source role
559
- // declares `dangerously_skip_permissions: false`, so the fork's policy must
560
- // resolve to `disabled` (fail-closed) — the new single-source model.
561
- let case = Case::start("cf-r7");
562
- let fork = case.fork(NEW);
563
- let err = fork.to_string();
564
- assert!(
565
- err.contains("refuses --as")
566
- || err.contains("in-place")
567
- || fork.get("ok") == Some(&json!(false)),
568
- "in-place fork refuses --as {NEW}; no NEW row to clamp. fork={fork}"
569
- );
570
- });
571
- }
572
-
573
- /// R7b reverse positive control — same source role (dangerously_skip_permissions:
574
- /// false) must also resolve to `source=disabled` under any ancestry seam. 0.5.66
575
- /// 起 policy 与 leader argv 无关:source 恒 `disabled`,fork 恒不升级(MUST-16)。
576
- #[test]
577
- #[serial_test::serial(env)]
578
- fn r7b_fork_policy_under_restricted_leader_ancestry_is_disabled() {
579
- run_process_isolated(R7B_CHILD, R7B_TEST, || {
580
- let case = Case::start_with_ancestry("cf-r7b", RESTRICTED_LEADER_ARGV);
581
- let fork = case.fork(NEW);
582
- let err = fork.to_string();
583
- assert!(
584
- err.contains("refuses --as")
585
- || err.contains("in-place")
586
- || fork.get("ok") == Some(&json!(false)),
587
- "in-place fork refuses --as {NEW}; no NEW row. fork={fork}"
588
- );
589
- });
590
- }
591
-
592
262
  // ---------------------------------------------------------------------------
593
263
  // Minimal in-process Transport for the R8 library-entry test (mirrors the
594
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(决策前)。
@@ -1,6 +1,6 @@
1
1
  //! purpose: grok 席位角色文件必须显式写 model,缺则拒绝启动
2
2
  //! contract: 缺 model 的 grok 角色启动失败(错误含 model 与原因);写了 model
3
- //! 则该值进入 worker argv 的 `--model <值>`;claude 缺 model 行为不变
3
+ //! 则该值进入 worker argv 的 `--model <值>`;copilot 缺 model 行为不变
4
4
  //! boundary: 只钉 Provider::Grok 的启动契约;不改 claude/codex/copilot 路径
5
5
  //!
6
6
  //! 修之前判红(40e91fba):grok 角色缺 model 仍会成功启动(compiler 填
@@ -97,20 +97,20 @@ fn grok_role_explicit_model_reaches_argv() {
97
97
  );
98
98
  }
99
99
 
100
- /// 3. claude 角色缺 model ⇒ 行为不变(仍能启动,不被 grok 的硬性 model 要求误伤)。
100
+ /// 3. copilot 角色缺 model ⇒ 行为不变(仍能启动,不被 grok 的硬性 model 要求误伤)。
101
101
  #[test]
102
102
  #[serial(env)]
103
- fn claude_role_missing_model_still_starts() {
104
- let _hermetic = enter_hermetic("grok-claude-missing-model");
105
- let ws = tmp_dir("claude-no-model");
103
+ fn copilot_role_missing_model_still_starts() {
104
+ let _hermetic = enter_hermetic("grok-copilot-missing-model");
105
+ let ws = tmp_dir("copilot-no-model");
106
106
  super::launch_spawn::seed_healthy_coordinator(&ws);
107
107
  let team = write_role_team(
108
108
  &ws,
109
- "claudeteam",
110
- "clauder",
111
- "claude",
109
+ "copilotteam",
110
+ "copiloter",
111
+ "copilot",
112
112
  None,
113
- "Claude Worker",
113
+ "Copilot Worker",
114
114
  );
115
115
  let transport = OfflineTransport::new();
116
116
 
@@ -119,17 +119,17 @@ fn claude_role_missing_model_still_starts() {
119
119
  &team,
120
120
  None,
121
121
  true,
122
- Some("claudeteam"),
122
+ Some("copilotteam"),
123
123
  &transport,
124
124
  );
125
125
  assert!(
126
126
  result.is_ok(),
127
- "claude role without model must keep starting; grok-only requirement leaked; err={result:?}"
127
+ "copilot role without model must keep starting; grok-only requirement leaked; err={result:?}"
128
128
  );
129
129
  let argv = first_spawn_argv(&transport);
130
130
  assert!(
131
131
  !argv.is_empty(),
132
- "claude seat must still spawn; argv={argv:?}"
132
+ "copilot seat must still spawn; argv={argv:?}"
133
133
  );
134
134
  }
135
135