@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
@@ -1,300 +0,0 @@
1
- //! ---
2
- //! purpose: grok pending id 入 state,捕获后整队 restart 走 --resume
3
- //! contract:
4
- //! provides:
5
- //! - name: grok-fresh-pending-matches-argv
6
- //! what: fresh spawn 的 `_pending_session_id` 等于 argv `--session-id`
7
- //! - name: grok-restart-resume-argv
8
- //! what: session_id + 磁盘存档齐时 restart 发 `--resume <uuid>`
9
- //! - name: grok-classify-resume-when-archive-present
10
- //! what: classify 在存档存在时决策 Resume,缺失时 Refuse 而非静默 fresh
11
- //! boundary:
12
- //! - 不改 reset-agent --discard-session
13
- //! - 不覆盖 claude 三拍
14
- //! maturity: wired
15
- //! ---
16
-
17
- #![allow(clippy::unwrap_used, clippy::expect_used, clippy::panic)]
18
-
19
- #[path = "../../../tests/support/hermetic.rs"]
20
- mod hermetic_guard;
21
- #[allow(dead_code)]
22
- fn _hermetic_boundary_marker(_: &hermetic_guard::HermeticTestEnv) {}
23
-
24
- fn enter_hermetic(tag: &str) -> hermetic_guard::HermeticTestEnv {
25
- hermetic_guard::HermeticTestEnv::enter_with_leader(tag)
26
- }
27
-
28
- use std::path::{Path, PathBuf};
29
- use std::sync::atomic::{AtomicU64, Ordering};
30
-
31
- use crate::lifecycle::restart::classify_restart_plan_with_resume_validation;
32
- use crate::lifecycle::types::ResumeDecision;
33
- use crate::provider::session_scan::grok::{grok_session_archive_present, grok_session_dir};
34
- use crate::state::persist::{load_runtime_state, save_runtime_state};
35
- use serial_test::serial;
36
- use team_agent::lifecycle::{quick_start_with_transport_in_workspace, restart_with_transport};
37
- use team_agent::transport::test_support::OfflineTransport;
38
-
39
- #[test]
40
- #[serial(env)]
41
- fn grok_fresh_spawn_binds_pending_session_id_to_argv_session_id() {
42
- let _hermetic = enter_hermetic("grok-resume-pending");
43
- let (ws, _home, _guard, team) = seed_grok("pending");
44
- let transport = OfflineTransport::new();
45
- quick_start_with_transport_in_workspace(&ws, &team, None, true, Some("grokteam"), &transport)
46
- .expect("grok fresh start");
47
- let argv = first_spawn_argv(&transport);
48
- let sid = argv_flag(&argv, "--session-id").expect("--session-id on grok fresh argv");
49
- assert!(
50
- argv_flag(&argv, "--resume").is_none(),
51
- "fresh spawn must not --resume; argv={argv:?}"
52
- );
53
- let state = load_runtime_state(&ws).expect("state");
54
- let pending = state
55
- .pointer("/agents/grok_writer/_pending_session_id")
56
- .and_then(|v| v.as_str());
57
- assert_eq!(
58
- pending,
59
- Some(sid.as_str()),
60
- "pending must match argv session-id; agent={:?}",
61
- state.pointer("/agents/grok_writer")
62
- );
63
- assert_eq!(
64
- state
65
- .pointer("/agents/grok_writer/session_id")
66
- .and_then(|v| v.as_str()),
67
- None,
68
- "session_id stays null until capture; agent={:?}",
69
- state.pointer("/agents/grok_writer")
70
- );
71
- }
72
-
73
- #[test]
74
- #[serial(env)]
75
- fn grok_restart_uses_resume_when_session_captured_and_archive_present() {
76
- let _hermetic = enter_hermetic("grok-resume-captured");
77
- let (ws, home, _guard, team) = seed_grok("resume");
78
- let first = OfflineTransport::new();
79
- quick_start_with_transport_in_workspace(&ws, &team, None, true, Some("grokteam"), &first)
80
- .expect("initial grok start");
81
- let sid = argv_flag(&first_spawn_argv(&first), "--session-id").expect("fresh session-id");
82
- let dir = grok_session_dir(&ws, &sid).expect("grok session dir");
83
- std::fs::create_dir_all(&dir).unwrap();
84
- std::fs::write(dir.join("events.jsonl"), b"").unwrap();
85
- assert!(grok_session_archive_present(&dir));
86
- let _ = home;
87
-
88
- let mut state = load_runtime_state(&ws).expect("load");
89
- {
90
- let agent = state
91
- .pointer_mut("/agents/grok_writer")
92
- .expect("grok_writer")
93
- .as_object_mut()
94
- .expect("agent object");
95
- agent.insert("session_id".to_string(), serde_json::json!(sid.clone()));
96
- agent.insert(
97
- "rollout_path".to_string(),
98
- serde_json::json!(dir.to_string_lossy()),
99
- );
100
- agent.insert(
101
- "spawn_cwd".to_string(),
102
- serde_json::json!(ws.to_string_lossy()),
103
- );
104
- agent.insert("capture_state".to_string(), serde_json::json!("captured"));
105
- }
106
- save_runtime_state(&ws, &state).expect("save captured");
107
-
108
- seed_healthy_coordinator(&ws);
109
-
110
- let restart = OfflineTransport::new();
111
- restart_with_transport(&ws, false, Some("grokteam"), &restart)
112
- .expect("restart without --allow-fresh must resume grok");
113
- let argv = first_spawn_argv(&restart);
114
- assert!(
115
- argv_contains_adjacent(&argv, &["--resume", sid.as_str()]),
116
- "captured grok must restart with --resume <uuid>; argv={argv:?}"
117
- );
118
- assert!(
119
- argv_flag(&argv, "--session-id").is_none(),
120
- "resume argv must not mint a new --session-id; argv={argv:?}"
121
- );
122
- }
123
-
124
- #[test]
125
- #[serial(env)]
126
- fn grok_classify_resumes_when_archive_present_and_refuses_when_missing() {
127
- let base = tmp_dir("classify");
128
- let home = tmp_dir("classify-home");
129
- let ws = base.join("ws");
130
- std::fs::create_dir_all(&ws).unwrap();
131
- let _guard = HomeGuard::set(&home);
132
- let sid = "cccccccc-cccc-4ccc-8ccc-cccccccccccc";
133
- let dir = grok_session_dir(&ws, sid).expect("dir");
134
- std::fs::create_dir_all(&dir).unwrap();
135
- std::fs::write(dir.join("summary.json"), b"{}").unwrap();
136
-
137
- let present = serde_json::json!({
138
- "agents": {
139
- "w1": {
140
- "provider": "grok",
141
- "status": "running",
142
- "session_id": sid,
143
- "spawn_cwd": ws.to_string_lossy(),
144
- "rollout_path": dir.to_string_lossy(),
145
- }
146
- }
147
- });
148
- let plan = classify_restart_plan_with_resume_validation(Some(&ws), &present, false)
149
- .expect("classify present");
150
- assert_eq!(plan.decisions.len(), 1);
151
- assert_eq!(
152
- plan.decisions[0].decision,
153
- ResumeDecision::Resume,
154
- "archive present must Resume; unresumable={:?}",
155
- plan.unresumable
156
- );
157
-
158
- let missing_sid = "dddddddd-dddd-4ddd-8ddd-dddddddddddd";
159
- let missing = serde_json::json!({
160
- "agents": {
161
- "w1": {
162
- "provider": "grok",
163
- "status": "running",
164
- "session_id": missing_sid,
165
- "spawn_cwd": ws.to_string_lossy(),
166
- }
167
- }
168
- });
169
- let refuse = classify_restart_plan_with_resume_validation(Some(&ws), &missing, false)
170
- .expect("classify missing");
171
- assert_eq!(refuse.decisions.len(), 1);
172
- assert_eq!(
173
- refuse.decisions[0].decision,
174
- ResumeDecision::Refuse,
175
- "missing grok archive must Refuse, not silent fresh; got {:?}",
176
- refuse.decisions[0].decision
177
- );
178
- }
179
-
180
- /// restart 的就绪门要求 `coordinator_health().ok`,而单测里 `start_coordinator`
181
- /// spawn 的是 `std::env::current_exe()` —— 也就是 libtest 测试二进制本身,它一启动
182
- /// 就以 `Unrecognized option: 'workspace'` 退出并变成僵尸,`pid_is_running` 的
183
- /// `ps stat=` 一看到 `Z` 就判 not running。于是就绪门只能靠「抢在死婴被看到之前
184
- /// 探到它」这个竞态过关,慢机/高负载上必然超时。这里按本仓既有写法(见
185
- /// `copilot_provider_red.rs` / `restart_build_before_destroy_0540_contract.rs`)
186
- /// 预先把 pid 文件与 metadata 指向测试进程自己,让 `start_coordinator` 走
187
- /// `AlreadyRunning` 早返回,竞态被删掉而不是被调宽。
188
- fn seed_healthy_coordinator(workspace: &Path) {
189
- let workspace = crate::coordinator::WorkspacePath::new(workspace.to_path_buf());
190
- let pid = crate::coordinator::Pid::new(std::process::id());
191
- std::fs::create_dir_all(
192
- crate::coordinator::coordinator_pid_path(&workspace)
193
- .parent()
194
- .unwrap(),
195
- )
196
- .unwrap();
197
- crate::coordinator::write_coordinator_metadata(
198
- &workspace,
199
- pid,
200
- crate::coordinator::MetadataSource::Boot,
201
- )
202
- .expect("write coordinator metadata");
203
- std::fs::write(
204
- crate::coordinator::coordinator_pid_path(&workspace),
205
- pid.to_string(),
206
- )
207
- .expect("write coordinator pid");
208
- }
209
-
210
- fn seed_grok(tag: &str) -> (PathBuf, PathBuf, HomeGuard, PathBuf) {
211
- let ws = tmp_dir(tag);
212
- super::launch_spawn::seed_healthy_coordinator(&ws);
213
- let home = tmp_dir(&format!("{tag}-home"));
214
- seed_grok_home(&home, Some(&ws));
215
- let guard = HomeGuard::set(&home);
216
- let team = write_grok_role(&ws);
217
- (ws, home, guard, team)
218
- }
219
-
220
- fn first_spawn_argv(transport: &OfflineTransport) -> Vec<String> {
221
- let records = transport.spawn_records();
222
- assert!(
223
- !records.is_empty(),
224
- "expected a worker spawn; records={records:?}"
225
- );
226
- records[0].1.clone()
227
- }
228
-
229
- fn argv_flag(argv: &[String], flag: &str) -> Option<String> {
230
- argv.windows(2)
231
- .find(|pair| pair[0] == flag)
232
- .map(|pair| pair[1].clone())
233
- }
234
-
235
- fn argv_contains_adjacent(hay: &[String], needle: &[&str]) -> bool {
236
- hay.windows(needle.len())
237
- .any(|window| window.iter().map(String::as_str).eq(needle.iter().copied()))
238
- }
239
-
240
- fn write_grok_role(ws: &Path) -> PathBuf {
241
- let team = ws.join("grokteam");
242
- std::fs::create_dir_all(team.join("agents")).unwrap();
243
- std::fs::write(
244
- team.join("TEAM.md"),
245
- "---\nname: grokteam\nobjective: grok resume.\nprovider: grok\ndangerously_skip_permissions: false\n---\n\nTeam.\n",
246
- )
247
- .unwrap();
248
- std::fs::write(
249
- team.join("agents").join("grok_writer.md"),
250
- "---\nname: grok_writer\nrole: Grok Writer\nprovider: grok\nmodel: grok-4.6\nauth_mode: subscription\ndangerously_skip_permissions: false\ntools:\n - mcp_team\n---\n\nWorker.\n",
251
- )
252
- .unwrap();
253
- team
254
- }
255
-
256
- fn seed_grok_home(home: &Path, trusted_cwd: Option<&Path>) {
257
- let grok = home.join(".grok");
258
- std::fs::create_dir_all(&grok).unwrap();
259
- std::fs::write(grok.join("auth.json"), r#"{"test":"ok"}"#).unwrap();
260
- if let Some(cwd) = trusted_cwd {
261
- std::fs::write(
262
- grok.join("trusted_folders.toml"),
263
- format!("[folders.\"{}\"]\ntrusted = true\n", cwd.display()),
264
- )
265
- .unwrap();
266
- }
267
- }
268
-
269
- struct HomeGuard {
270
- prev: Option<String>,
271
- }
272
-
273
- impl HomeGuard {
274
- fn set(home: &Path) -> Self {
275
- let prev = std::env::var("HOME").ok();
276
- std::env::set_var("HOME", home);
277
- Self { prev }
278
- }
279
- }
280
-
281
- impl Drop for HomeGuard {
282
- fn drop(&mut self) {
283
- match &self.prev {
284
- Some(value) => std::env::set_var("HOME", value),
285
- None => std::env::remove_var("HOME"),
286
- }
287
- }
288
- }
289
-
290
- fn tmp_dir(tag: &str) -> PathBuf {
291
- static N: AtomicU64 = AtomicU64::new(0);
292
- let dir = std::env::temp_dir().join(format!(
293
- "ta-rs-grok-resume-{tag}-{}-{}",
294
- std::process::id(),
295
- N.fetch_add(1, Ordering::Relaxed)
296
- ));
297
- let _ = std::fs::remove_dir_all(&dir);
298
- std::fs::create_dir_all(&dir).unwrap();
299
- std::fs::canonicalize(dir).unwrap()
300
- }
@@ -1,101 +0,0 @@
1
- //!
2
- //! Codex provider-local command builder.
3
- //!
4
- //! Extracted from `provider/adapter.rs` (0.4.x decoupling step 2). Pure
5
- //! extraction — byte-identical to the original inline forms. Shared helper
6
- //! `json_inline` stays in `adapter.rs` because it is also used by other
7
- //! sites; this file reaches it via `super::*`.
8
-
9
- use crate::model::enums::AuthMode;
10
- use crate::provider::adapter::json_inline;
11
- use crate::provider::command_helpers::{append_opt_pair, append_pair};
12
- use crate::provider::{McpConfig, ProviderCommandOverrides};
13
-
14
- pub(crate) fn codex_base_command(
15
- subcommand: Option<&str>,
16
- _auth_mode: AuthMode,
17
- mcp_config: Option<&McpConfig>,
18
- system_prompt: Option<&str>,
19
- model: Option<&str>,
20
- dangerously_skip_permissions: bool,
21
- overrides: Option<&ProviderCommandOverrides>,
22
- // 0.4.x provider effort MVP step 6: when Some, inject
23
- // `-c model_reasoning_effort=<level>` AFTER existing profile
24
- // codex_config overrides — explicit launch effort wins over profile.
25
- // Preserve max/ultra verbatim: ultra enables Codex client delegation
26
- // on top of max reasoning, rather than a separate model API effort.
27
- effort: Option<crate::model::enums::ProviderEffort>,
28
- ) -> Vec<String> {
29
- let mut argv = vec!["codex".to_string()];
30
- if let Some(subcommand) = subcommand {
31
- argv.push(subcommand.to_string());
32
- }
33
- argv.extend([
34
- "--no-alt-screen".to_string(),
35
- "--disable".to_string(),
36
- "shell_snapshot".to_string(),
37
- "--disable".to_string(),
38
- "apps".to_string(),
39
- ]);
40
- append_opt_pair(&mut argv, "--profile", overrides.and_then(|o| o.codex_profile.as_deref()));
41
- if dangerously_skip_permissions {
42
- // 0.5.66 bypass 单源:flag 由 provider_bypass_flag 表供给。
43
- let flag = crate::provider::bypass_flags::provider_bypass_flag(crate::model::enums::Provider::Codex)
44
- .expect("codex provider must define a bypass flag");
45
- argv.push(flag.to_string());
46
- }
47
- append_opt_pair(&mut argv, "--model", model);
48
- if let Some(overrides) = overrides {
49
- for config in &overrides.codex_config {
50
- append_pair(&mut argv, "-c", config.clone());
51
- }
52
- }
53
- if let Some(effort) = effort {
54
- argv.push("-c".to_string());
55
- argv.push(format!("model_reasoning_effort={}", effort.as_str()));
56
- }
57
- if let Some(prompt) = system_prompt {
58
- // codex.py:120 — escape order matters: backslash first, then quote, then newline.
59
- let escaped = prompt
60
- .replace('\\', "\\\\")
61
- .replace('"', "\\\"")
62
- .replace('\n', "\\n");
63
- append_pair(&mut argv, "-c", format!("developer_instructions=\"{escaped}\""));
64
- }
65
- if let Some(config) = mcp_config {
66
- append_codex_mcp_overrides(&mut argv, &config.raw);
67
- }
68
- argv
69
- }
70
-
71
- /// Render an `McpConfig::raw` ({ name: { type, command, args, env: {...} } }) into Codex
72
- /// `-c mcp_servers.<name>.<field>=...` overrides. JSON values are stringified with serde
73
- /// so arrays/objects survive (Codex parses the right-hand side as JSON; this is what the
74
- /// Python golden + the live attached Codex panes do).
75
- pub(crate) fn append_codex_mcp_overrides(argv: &mut Vec<String>, raw: &serde_json::Value) {
76
- let Some(servers) = raw.as_object() else {
77
- return;
78
- };
79
- for (name, server) in servers {
80
- let Some(obj) = server.as_object() else {
81
- continue;
82
- };
83
- for (key, value) in obj {
84
- if key == "env" {
85
- if let Some(env) = value.as_object() {
86
- for (env_key, env_value) in env {
87
- append_pair(argv, "-c", format!(
88
- "mcp_servers.{name}.env.{env_key}={}",
89
- json_inline(env_value)
90
- ));
91
- }
92
- }
93
- continue;
94
- }
95
- append_pair(argv, "-c", format!("mcp_servers.{name}.{key}={}", json_inline(value)));
96
- }
97
- // Every MCP server gets a 600s tool timeout so long-running
98
- // team_orchestrator calls (report_result etc.) survive the codex default.
99
- append_pair(argv, "-c", format!("mcp_servers.{name}.tool_timeout_sec=600.0"));
100
- }
101
- }
@@ -1,67 +0,0 @@
1
- //!
2
- //! purpose: Grok CLI argv + permission deny 映射;MCP 不走 CLI flag
3
- //! contract: launch 写 `<cwd>/.grok/config.toml`;未登录 / 目录未信任必须拒绝启动。
4
- //! 未指定 model 时不注入 `--model`,由 Grok CLI 使用原生默认。
5
- //! 未知工具映射记成 Unsupported,不发明 deny 名
6
- //! mcp_injection: dir_scoped —— 每席必须独立工作目录;同 cwd 多席会静默串台,故拒绝。
7
- //! 对照 claude/codex 是 argv 作用域(`--mcp-config`),同目录多席没有这个问题。
8
- //! 本版 exclusive 检查不读 per-agent cwd,一个 workspace 只支持一个 grok 席。
9
- //! 这是 Provider::Grok 的能力边界,不是框架对所有 provider 的限制。
10
- //! boundary: 只服务 Provider::Grok。不改 claude/codex/copilot 路径
11
- //!
12
- //! Grok CLI provider-local command builders.
13
- //!
14
- //! Mirrors `adapters/claude.rs` (0.5.67 provider-adapter step). Pure
15
- //! flag-name adaptation over the claude skeleton — no new abstraction
16
- //! layers, no public-API changes outside the provider dispatch.
17
- //!
18
- //! Grok CLI flag map (亲核 attest 0.5.67 + grok-full-help.txt):
19
- //! bypass → `--always-approve` ("Auto-approve all tool executions")
20
- //! system → `--rules <RULES>` ("Extra rules to append to the system prompt")
21
- //! model → `-m, --model <MODEL>`
22
- //! session → `-s, --session-id <SESSION_ID>` (fresh spawn)
23
- //! resume → `-r, --resume [<ID_OR_TITLE>]` / `-c, --continue`
24
- //! fork → `--fork-session` (with --resume)
25
- //! effort → `--effort <level>` (alias of `--reasoning-effort`)
26
- //! grok accepts low|medium|high|xhigh; CLI rejects `max`
27
- //! cwd → `--cwd <CWD>` / `-w, --worktree [<WORKTREE>]`
28
- //!
29
- //! No native `--mcp-config` flag on the Grok CLI (`grok mcp` is a subcommand)
30
- //! → `native_mcp_config: false`; MCP reaches the worker via launch-path
31
- //! `<cwd>/.grok/config.toml` (`apply_grok_mcp_overlay`).
32
-
33
- use crate::provider::adapter::next_session_token;
34
- use crate::provider::ProviderError;
35
- use crate::provider::command_helpers::{append_opt_pair, append_pair};
36
-
37
- pub(crate) fn grok_launch_command(
38
- system_prompt: Option<&str>,
39
- model: Option<&str>,
40
- dangerously_skip_permissions: bool,
41
- ) -> Result<Vec<String>, ProviderError> {
42
- let mut argv = grok_base_command(system_prompt, model, dangerously_skip_permissions, None)?;
43
- append_pair(&mut argv, "--session-id", next_session_token());
44
- Ok(argv)
45
- }
46
-
47
- pub(crate) fn grok_base_command(
48
- system_prompt: Option<&str>,
49
- model: Option<&str>,
50
- dangerously_skip_permissions: bool,
51
- effort: Option<crate::model::enums::ProviderEffort>,
52
- ) -> Result<Vec<String>, ProviderError> {
53
- let mut argv = vec!["grok".to_string()];
54
- if dangerously_skip_permissions {
55
- argv.push("--always-approve".to_string());
56
- }
57
- append_opt_pair(&mut argv, "--model", model.map(str::trim).filter(|value| !value.is_empty()));
58
- if let Some(effort) = effort {
59
- // Grok accepts `--effort` as alias for `--reasoning-effort`.
60
- argv.push("--effort".to_string());
61
- argv.push(effort.as_str().to_string());
62
- }
63
- append_opt_pair(&mut argv, "--rules", system_prompt);
64
- // Grok CLI has no `--mcp-config` flag — the claude inline-MCP block is
65
- // intentionally absent. Launch writes `<cwd>/.grok/config.toml`.
66
- Ok(argv)
67
- }