@team-agent/installer 0.5.126 → 0.5.127

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 (107) hide show
  1. package/Cargo.lock +1 -1
  2. package/Cargo.toml +1 -1
  3. package/crates/team-agent/src/cli/diagnose.rs +0 -69
  4. package/crates/team-agent/src/cli/emit.rs +10 -9
  5. package/crates/team-agent/src/cli/grok_slot.rs +88 -3
  6. package/crates/team-agent/src/cli/intent/runtime.rs +6 -4
  7. package/crates/team-agent/src/cli/intent/runtime_tests.rs +45 -0
  8. package/crates/team-agent/src/cli/mod.rs +13 -1
  9. package/crates/team-agent/src/cli/models.rs +27 -181
  10. package/crates/team-agent/src/cli/tests/leader_watch.rs +1 -1
  11. package/crates/team-agent/src/cli/tests/mod.rs +2 -2
  12. package/crates/team-agent/src/cli/tests/run_delegation.rs +3 -3
  13. package/crates/team-agent/src/cli/tests/status_send.rs +2 -2
  14. package/crates/team-agent/src/compiler/tests.rs +36 -9
  15. package/crates/team-agent/src/compiler.rs +3 -2
  16. package/crates/team-agent/src/contract_runtime/backend.rs +36 -0
  17. package/crates/team-agent/src/contract_runtime/commands.rs +335 -4
  18. package/crates/team-agent/src/contract_runtime/config.rs +6 -5
  19. package/crates/team-agent/src/contract_runtime/framework.rs +2 -5
  20. package/crates/team-agent/src/contract_runtime/registry.rs +66 -67
  21. package/crates/team-agent/src/coordinator/steps/abnormal.rs +45 -5
  22. package/crates/team-agent/src/coordinator/tests/api_error_recovery.rs +27 -10
  23. package/crates/team-agent/src/coordinator/tests/energy.rs +4 -4
  24. package/crates/team-agent/src/coordinator/tests/health_sync.rs +2 -2
  25. package/crates/team-agent/src/coordinator/tests/main_preserved.rs +2 -2
  26. package/crates/team-agent/src/coordinator/tests/spine.rs +1 -1
  27. package/crates/team-agent/src/coordinator/tests/takeover.rs +3 -3
  28. package/crates/team-agent/src/lifecycle/launch/fork_agent.rs +17 -185
  29. package/crates/team-agent/src/lifecycle/launch/mcp_config.rs +4 -487
  30. package/crates/team-agent/src/lifecycle/launch/quick_start.rs +2 -2
  31. package/crates/team-agent/src/lifecycle/launch/spawn.rs +8 -21
  32. package/crates/team-agent/src/lifecycle/launch.rs +3 -11
  33. package/crates/team-agent/src/lifecycle/profile_launch.rs +8 -64
  34. package/crates/team-agent/src/lifecycle/restart/common.rs +6 -151
  35. package/crates/team-agent/src/lifecycle/restart/remove.rs +129 -0
  36. package/crates/team-agent/src/lifecycle/role_config.rs +40 -13
  37. package/crates/team-agent/src/lifecycle/tests/acceptance_b_batch_red.rs +1 -1
  38. package/crates/team-agent/src/lifecycle/tests/agent_ops.rs +8 -12
  39. package/crates/team-agent/src/lifecycle/tests/behavioral_diff_264_red.rs +37 -240
  40. package/crates/team-agent/src/lifecycle/tests/cli_argv_routing_red.rs +95 -59
  41. package/crates/team-agent/src/lifecycle/tests/communication_mode_runtime_contract_red.rs +20 -35
  42. package/crates/team-agent/src/lifecycle/tests/copilot_provider_red.rs +2 -2
  43. package/crates/team-agent/src/lifecycle/tests/core.rs +22 -48
  44. package/crates/team-agent/src/lifecycle/tests/f032_startup_prompt_best_effort_red.rs +22 -8
  45. package/crates/team-agent/src/lifecycle/tests/grok_require_explicit_model_red.rs +6 -124
  46. package/crates/team-agent/src/lifecycle/tests/host_cotenant_death_p0_contract.rs +30 -67
  47. package/crates/team-agent/src/lifecycle/tests/issue238_codex_effort_contract.rs +3 -31
  48. package/crates/team-agent/src/lifecycle/tests/lane_ops.rs +194 -169
  49. package/crates/team-agent/src/lifecycle/tests/launch_spawn.rs +136 -256
  50. package/crates/team-agent/src/lifecycle/tests/lifecycle_rollback_red.rs +15 -78
  51. package/crates/team-agent/src/lifecycle/tests/main_preserved.rs +7 -7
  52. package/crates/team-agent/src/lifecycle/tests/phase_b_contracts.rs +75 -69
  53. package/crates/team-agent/src/lifecycle/tests/phase_golden.rs +2 -10
  54. package/crates/team-agent/src/lifecycle/tests/quick_start_worker_readiness_red.rs +7 -7
  55. package/crates/team-agent/src/lifecycle/tests/restart.rs +12 -153
  56. package/crates/team-agent/src/lifecycle/tests/restart_build_before_destroy_0540_contract.rs +27 -5
  57. package/crates/team-agent/src/lifecycle/tests/restart_liveness_red.rs +59 -10
  58. package/crates/team-agent/src/lifecycle/tests/restart_rebind_hotfix_252_red.rs +47 -6
  59. package/crates/team-agent/src/lifecycle/tests/restart_session_capture_red.rs +3 -1374
  60. package/crates/team-agent/src/lifecycle/tests/resume_recover_red.rs +27 -10
  61. package/crates/team-agent/src/lifecycle/tests/status_credential_redaction_contract.rs +5 -5
  62. package/crates/team-agent/src/lifecycle/tests/subprep_codex_trust_roundtrip_red.rs +67 -313
  63. package/crates/team-agent/src/lifecycle/tests/team_in_team_identity_scope_red.rs +2 -2
  64. package/crates/team-agent/src/lifecycle/tests/team_in_team_sibling_quick_start_red.rs +1 -1
  65. package/crates/team-agent/src/lifecycle/tests/team_in_team_state_scope_red.rs +2 -2
  66. package/crates/team-agent/src/lifecycle/tests/team_key_retirement_txn_red.rs +4 -4
  67. package/crates/team-agent/src/lifecycle/tests/upgrade_compat_0211_red.rs +70 -15
  68. package/crates/team-agent/src/lifecycle/tests/verify_rs031_window_consistency_red.rs +35 -35
  69. package/crates/team-agent/src/lifecycle/tests/worker_spawn_env_red.rs +36 -82
  70. package/crates/team-agent/src/lifecycle/tests.rs +0 -4
  71. package/crates/team-agent/src/lifecycle/types.rs +2 -5
  72. package/crates/team-agent/src/mcp_server/readiness_tests.rs +15 -17
  73. package/crates/team-agent/src/messaging/delivery.rs +9 -61
  74. package/crates/team-agent/src/messaging/tests/dup_inject.rs +67 -68
  75. package/crates/team-agent/src/messaging/tests/main_preserved.rs +2 -2
  76. package/crates/team-agent/src/messaging/tests/runtime.rs +5 -5
  77. package/crates/team-agent/src/messaging/tests/spine.rs +5 -1
  78. package/crates/team-agent/src/messaging/tests/wave2.rs +13 -20
  79. package/crates/team-agent/src/provider/adapter.rs +58 -356
  80. package/crates/team-agent/src/provider/adapters/mod.rs +5 -7
  81. package/crates/team-agent/src/provider/session/capture.rs +5 -105
  82. package/crates/team-agent/src/provider/session/context_fork/outcome.rs +8 -20
  83. package/crates/team-agent/src/provider/session/context_fork.rs +23 -142
  84. package/crates/team-agent/src/provider/session/mod.rs +2 -3
  85. package/crates/team-agent/src/provider/session_scan/common.rs +21 -57
  86. package/crates/team-agent/src/provider/session_scan.rs +6 -16
  87. package/crates/team-agent/src/provider/tests/adapter.rs +37 -118
  88. package/crates/team-agent/src/provider/tests/command_helpers.rs +1 -18
  89. package/crates/team-agent/src/provider/tests/idle.rs +0 -43
  90. package/crates/team-agent/src/provider/types.rs +0 -4
  91. package/crates/team-agent/src/provider/wire.rs +34 -8
  92. package/crates/team-agent/src/tmux_backend.rs +4 -3
  93. package/package.json +4 -4
  94. package/skills/team-agent/SKILL.md +3 -2
  95. package/skills/team-agent/command-coverage.json +14 -0
  96. package/skills/team-agent/docs/reference/team-agent-operator.md +3 -1
  97. package/skills/team-agent/references/team-agent-operator.md +3 -1
  98. package/crates/team-agent/src/lifecycle/launch/grok_per_seat.rs +0 -260
  99. package/crates/team-agent/src/lifecycle/tests/codex_weak_window_attribution_red.rs +0 -683
  100. package/crates/team-agent/src/lifecycle/tests/grok_effort_argv_red.rs +0 -247
  101. package/crates/team-agent/src/lifecycle/tests/grok_mcp_overlay_red.rs +0 -507
  102. package/crates/team-agent/src/lifecycle/tests/grok_restart_resume_red.rs +0 -300
  103. package/crates/team-agent/src/provider/adapters/codex.rs +0 -101
  104. package/crates/team-agent/src/provider/adapters/grok.rs +0 -67
  105. package/crates/team-agent/src/provider/session/context_fork/codex.rs +0 -514
  106. package/crates/team-agent/src/provider/session_scan/codex.rs +0 -326
  107. package/crates/team-agent/src/provider/session_scan/grok.rs +0 -288
@@ -1,44 +1,25 @@
1
1
  //! ---
2
- //! purpose: 各 provider 的 MCP 配置落盘与 argv 指向,含 grok 目录作用域配置的清洗与前置检查
2
+ //! purpose: 各 provider 的 MCP 配置落盘与 argv 指向
3
3
  //! contract:
4
4
  //! provides:
5
5
  //! - name: resolve_mcp_config
6
6
  //! what: 把 MCP 配置里的 workspace、agent_id 与 team_id 占位符替换掉
7
7
  //! - name: write_worker_mcp_config_for_provider
8
8
  //! what: 写出 per-agent 的 MCP 配置文件,copilot 走字段名翻译
9
- //! - name: apply_grok_mcp_overlay
10
- //! what: 写 workspace 下 grok 的项目作用域配置,是该文件的唯一写者
11
- //! - name: reconcile_grok_toml_per_seat_keys
12
- //! what: 起 grok 席前清掉共享 toml 里遗留的 per-seat 键并留审计事件
13
- //! - name: ensure_grok_login_and_folder_trust
14
- //! what: grok 未登录或目录未信任时拒绝起席
15
9
  //! - name: point_native_mcp_config_at_file
16
10
  //! what: 把 argv 里的 MCP 配置参数改指到已落盘的文件
17
11
  //! depends:
18
12
  //! - crate::provider::McpConfig
19
- //! - crate::event_log::EventLog
20
- //! - crate::lifecycle::profile_launch
21
13
  //! - std::fs
22
14
  //! boundary:
23
- //! - 不读也不写 provider 的凭据文件,只判断登录态文件是否存在且非空
24
- //! - 审计事件只落键名,不落键值
25
- //! - 清洗共享 toml 时不删未知键,未知不等于可删
26
- //! - 清洗后校验失败一律拒绝起席,不带着脏配置继续
15
+ //! - 不读也不写 provider 的凭据文件
16
+ //! - Grok 的目录作用域 `.grok/config.toml` 写者已随 legacy grok worker 退役;grok_build 叶子自带 MCP 注入
27
17
  //! maturity: wired
28
18
  //! ---
29
- use std::collections::{BTreeMap, BTreeSet};
30
19
  use std::path::{Path, PathBuf};
31
- use std::process::Command;
32
20
 
33
21
  use crate::lifecycle::*;
34
- use crate::model::enums::{AuthMode, PaneLiveness, Provider, ProviderEffort};
35
- use crate::model::yaml::{self, Value};
36
- use crate::state::persist::load_runtime_state;
37
- use crate::transport::{PaneId, SessionName, Target, Transport, WindowName};
38
-
39
- use crate::lifecycle::lock::{acquire_agent_lifecycle_lock, LifecycleLockRequest};
40
-
41
- use super::*;
22
+ use crate::model::enums::Provider;
42
23
 
43
24
  /// ---
44
25
  /// purpose: 把 MCP 配置里的占位符替换成本次 workspace、席位与团队
@@ -143,470 +124,6 @@ pub(crate) fn write_worker_mcp_config_for_provider(
143
124
  Ok(path)
144
125
  }
145
126
 
146
- /// Grok MCP 是**目录作用域**(`mcp_injection: dir_scoped`):CLI 只读
147
- /// `<cwd>/.grok/config.toml`。同目录后起席位会覆盖这份文件,先起席位的
148
- /// 身份被回溯性改写且不报错。本版 worker cwd 恒为 workspace(D5),
149
- /// exclusive 检查也不读 per-agent cwd ⇒ 一个 workspace 只支持一个 grok 席。
150
- /// 这是 grok 的 provider 能力边界,不是框架通则(claude/codex 走 argv
151
- /// `--mcp-config`,同目录多席没有这个问题)。
152
- struct GrokOccupant {
153
- id: String,
154
- spawned_at: Option<String>,
155
- status: String,
156
- }
157
-
158
- fn agent_is_grok(agent: &Value) -> bool {
159
- agent
160
- .get("provider")
161
- .and_then(Value::as_str)
162
- .and_then(crate::lifecycle::profile_launch::parse_provider)
163
- == Some(Provider::Grok)
164
- }
165
-
166
- fn status_is_live(status: &str) -> bool {
167
- !matches!(
168
- status,
169
- "stopped" | "stopping" | "removed" | "spawn_failed" | "failed"
170
- )
171
- }
172
-
173
- fn occupant_from_state_row(id: &str, agent: &serde_json::Value) -> Option<GrokOccupant> {
174
- let provider = agent
175
- .get("provider")
176
- .and_then(serde_json::Value::as_str)
177
- .and_then(crate::lifecycle::profile_launch::parse_provider);
178
- if provider != Some(Provider::Grok) {
179
- return None;
180
- }
181
- let status = agent
182
- .get("status")
183
- .and_then(serde_json::Value::as_str)
184
- .unwrap_or("running");
185
- if !status_is_live(status) {
186
- return None;
187
- }
188
- Some(GrokOccupant {
189
- id: id.to_string(),
190
- spawned_at: agent
191
- .get("spawned_at")
192
- .and_then(serde_json::Value::as_str)
193
- .map(str::to_string),
194
- status: status.to_string(),
195
- })
196
- }
197
-
198
- fn live_grok_occupants_from_state(workspace: &Path) -> Result<Vec<GrokOccupant>, LifecycleError> {
199
- let path = crate::state::persist::runtime_state_path(workspace);
200
- if !path.exists() {
201
- return Ok(Vec::new());
202
- }
203
- let state = crate::state::persist::load_runtime_state(workspace).map_err(|e| {
204
- LifecycleError::StatePersist(format!(
205
- "cannot count live grok seats (state unreadable): {e}"
206
- ))
207
- })?;
208
- let mut out = Vec::new();
209
- if let Some(agents) = state.get("agents").and_then(serde_json::Value::as_object) {
210
- for (id, agent) in agents {
211
- if let Some(row) = occupant_from_state_row(id, agent) {
212
- out.push(row);
213
- }
214
- }
215
- }
216
- if let Some(teams) = state.get("teams").and_then(serde_json::Value::as_object) {
217
- for team in teams.values() {
218
- let Some(agents) = team.get("agents").and_then(serde_json::Value::as_object) else {
219
- continue;
220
- };
221
- for (id, agent) in agents {
222
- if out.iter().any(|o| o.id == *id) {
223
- continue;
224
- }
225
- if let Some(row) = occupant_from_state_row(id, agent) {
226
- out.push(row);
227
- }
228
- }
229
- }
230
- }
231
- Ok(out)
232
- }
233
-
234
- fn spec_grok_ids(spec: &Value) -> Vec<String> {
235
- let mut ids = Vec::new();
236
- for agent in spec_agent_values(spec) {
237
- if agent_is_paused(agent) || !agent_is_grok(agent) {
238
- continue;
239
- }
240
- if let Some(id) = agent.get("id").and_then(Value::as_str) {
241
- if !ids.iter().any(|existing| existing == id) {
242
- ids.push(id.to_string());
243
- }
244
- }
245
- }
246
- ids
247
- }
248
-
249
- /// ---
250
- /// purpose: 清掉 grok 共享 toml 里遗留的 per-seat 键,并写一条只含键名的审计事件
251
- /// returns: 文件不存在或本就没有 per-seat 键时直接成功
252
- /// errors: 文件读不出、清洗后仍残留或审计事件写不出时返回 RequirementUnmet
253
- /// ---
254
- /// Reconcile `<cwd>/.grok/config.toml` before any grok start: drop leftover
255
- /// framework per-seat keys (`is_per_seat_env_key`), leave user/shared keys,
256
- /// emit an audit event with names only. Hung only from
257
- /// [`apply_grok_mcp_overlay`] — the unique writer, so launch/restart/resume
258
- /// all pass through. Clean-failure keeps the previous refuse shape.
259
- pub(crate) fn reconcile_grok_toml_per_seat_keys(workspace: &Path) -> Result<(), LifecycleError> {
260
- let path = workspace.join(".grok").join("config.toml");
261
- if !path.exists() {
262
- return Ok(());
263
- }
264
- let text = std::fs::read_to_string(&path).map_err(|error| {
265
- LifecycleError::RequirementUnmet(format!(
266
- "error: cannot judge grok shared slot (unreadable {})\n\
267
- reason: {error}\n\
268
- action: fix permissions on that file before adding another grok seat",
269
- path.display()
270
- ))
271
- })?;
272
- let keys = super::per_seat_keys_in_toml(&text);
273
- if keys.is_empty() {
274
- return Ok(());
275
- }
276
- let (cleaned, removed) = super::strip_per_seat_keys_from_toml(&text);
277
- let dir = workspace.join(".grok");
278
- if let Err(_error) = write_grok_config_toml(&dir, &cleaned) {
279
- return Err(refuse_dirty_grok_toml(workspace, &keys));
280
- }
281
- let after =
282
- std::fs::read_to_string(&path).map_err(|_| refuse_dirty_grok_toml(workspace, &keys))?;
283
- if !super::per_seat_keys_in_toml(&after).is_empty() {
284
- return Err(refuse_dirty_grok_toml(workspace, &keys));
285
- }
286
- crate::event_log::EventLog::new(workspace)
287
- .write(
288
- crate::lifecycle::types::event_names::GROK_TOML_PER_SEAT_KEYS_CLEARED,
289
- serde_json::json!({
290
- "path": path.display().to_string(),
291
- "keys": removed,
292
- }),
293
- )
294
- .map_err(|error| {
295
- LifecycleError::RequirementUnmet(format!(
296
- "error: cannot audit grok shared-slot cleanup ({})\n\
297
- reason: {error}\n\
298
- action: fix permissions on .team/logs then retry",
299
- path.display()
300
- ))
301
- })?;
302
- Ok(())
303
- }
304
-
305
- fn refuse_dirty_grok_toml(workspace: &Path, keys: &[(String, String)]) -> LifecycleError {
306
- let named = keys
307
- .iter()
308
- .map(|(key, _value)| key.as_str())
309
- .collect::<Vec<_>>()
310
- .join(", ");
311
- LifecycleError::RequirementUnmet(format!(
312
- "error: grok shared slot still carries per-seat keys ({named})\n\
313
- reason: .grok/config.toml is directory-scoped; per-seat keys would be inherited by every grok seat\n\
314
- workspace: {}\n\
315
- action: remove per-seat keys from the toml (identity belongs on pane env)",
316
- workspace.display()
317
- ))
318
- }
319
-
320
- fn write_grok_config_toml(dir: &Path, body: &str) -> Result<PathBuf, std::io::Error> {
321
- std::fs::create_dir_all(dir)?;
322
- let path = dir.join("config.toml");
323
- let tmp = dir.join("config.toml.tmp");
324
- std::fs::write(&tmp, body.as_bytes())?;
325
- std::fs::rename(&tmp, &path)?;
326
- Ok(path)
327
- }
328
-
329
- /// ---
330
- /// purpose: 构造同一 workspace 已被别的 grok 席占用的拒绝错误
331
- /// params:
332
- /// seats: 已占用该目录的席位名,写进错误正文
333
- /// returns: 带 error/reason/workspace/grok_seats 的 RequirementUnmet
334
- /// ---
335
- pub(crate) fn grok_shared_cwd_error(cwd: &Path, seats: &[String]) -> LifecycleError {
336
- LifecycleError::RequirementUnmet(format!(
337
- "error: grok seat already occupies this workspace\n\
338
- reason: grok MCP is directory-scoped (<cwd>/.grok/config.toml); a second seat overwrites TEAM_AGENT_ID\n\
339
- workspace: {}\n\
340
- grok_seats: {}",
341
- cwd.display(),
342
- seats.join(", "),
343
- ))
344
- }
345
-
346
- fn grok_occupied_cwd_error(
347
- cwd: &Path,
348
- incoming: &str,
349
- occupants: &[GrokOccupant],
350
- ) -> LifecycleError {
351
- let holder = occupants
352
- .iter()
353
- .find(|o| o.id != incoming)
354
- .or_else(|| occupants.first());
355
- let holder_id = holder.map(|o| o.id.as_str()).unwrap_or("unknown");
356
- let started = holder
357
- .and_then(|o| o.spawned_at.as_deref())
358
- .unwrap_or("unknown");
359
- let names = occupants
360
- .iter()
361
- .map(|o| {
362
- if let Some(at) = &o.spawned_at {
363
- format!("{} (status={}, started {})", o.id, o.status, at)
364
- } else {
365
- format!("{} (status={})", o.id, o.status)
366
- }
367
- })
368
- .collect::<Vec<_>>()
369
- .join(", ");
370
- LifecycleError::RequirementUnmet(format!(
371
- "error: grok seat {holder_id} already occupies this workspace (started {started})\n\
372
- incoming: {incoming}\n\
373
- reason: grok MCP is directory-scoped (<cwd>/.grok/config.toml); a second seat overwrites TEAM_AGENT_ID and the first seat's first turn would inherit the wrong identity\n\
374
- workspace: {}\n\
375
- grok_seats: {names}",
376
- cwd.display(),
377
- ))
378
- }
379
-
380
- /// ---
381
- /// purpose: 起 grok 席前确认已登录且该目录已被信任
382
- /// params:
383
- /// cwd: 席位的工作目录,用于判断目录信任
384
- /// returns: 通过返回空值;关闭 folder-trust 的环境变量下跳过信任检查
385
- /// errors: HOME 未设、登录态文件缺失或为空、目录未被信任时返回 RequirementUnmet
386
- /// ---
387
- /// 未登录 / 目录未信任时不许起出「能收信、没有手」的 grok 席。
388
- /// 登录态看 `$HOME/.grok/auth.json`;目录信任看 `$HOME/.grok/trusted_folders.toml`
389
- /// (与 grok `--trust` / `/hooks-trust` 同一份;未信任则项目作用域 MCP 不生效)。
390
- /// `GROK_FOLDER_TRUST=0` 时 grok 自己关掉 folder-trust,本检查跟着放行。
391
- pub(crate) fn ensure_grok_login_and_folder_trust(cwd: &Path) -> Result<(), LifecycleError> {
392
- let home = std::env::var_os("HOME").map(PathBuf::from).ok_or_else(|| {
393
- LifecycleError::RequirementUnmet(
394
- "error: HOME is unset; cannot verify grok login or folder trust\n\
395
- action: export HOME and retry"
396
- .to_string(),
397
- )
398
- })?;
399
- let grok_home = home.join(".grok");
400
- if !grok_auth_present(&grok_home) {
401
- return Err(LifecycleError::RequirementUnmet(format!(
402
- "error: grok is not logged in (missing or empty {})\n\
403
- action: run `grok login` then retry add-agent/launch",
404
- grok_home.join("auth.json").display()
405
- )));
406
- }
407
- if folder_trust_required() && !grok_folder_is_trusted(&grok_home, cwd) {
408
- return Err(LifecycleError::RequirementUnmet(format!(
409
- "error: grok folder is not trusted; project-scope MCP at {}/.grok/config.toml will not load\n\
410
- cwd: {}\n\
411
- action: from that directory run `grok --trust` (or `/hooks-trust` in a grok session), then retry",
412
- cwd.display(),
413
- cwd.display()
414
- )));
415
- }
416
- Ok(())
417
- }
418
-
419
- fn grok_auth_present(grok_home: &Path) -> bool {
420
- let path = grok_home.join("auth.json");
421
- let Ok(text) = std::fs::read_to_string(path) else {
422
- return false;
423
- };
424
- let Ok(value) = serde_json::from_str::<serde_json::Value>(&text) else {
425
- return false;
426
- };
427
- value.as_object().is_some_and(|map| !map.is_empty())
428
- }
429
-
430
- fn folder_trust_required() -> bool {
431
- !matches!(
432
- std::env::var("GROK_FOLDER_TRUST").ok().as_deref(),
433
- Some("0") | Some("false") | Some("off")
434
- )
435
- }
436
-
437
- fn grok_folder_is_trusted(grok_home: &Path, cwd: &Path) -> bool {
438
- let text = std::fs::read_to_string(grok_home.join("trusted_folders.toml")).unwrap_or_default();
439
- let cwd = std::fs::canonicalize(cwd).unwrap_or_else(|_| cwd.to_path_buf());
440
- grok_trusted_folders(&text).into_iter().any(|trusted| {
441
- let trusted = std::fs::canonicalize(&trusted).unwrap_or(trusted);
442
- cwd == trusted || cwd.starts_with(&trusted)
443
- })
444
- }
445
-
446
- fn grok_trusted_folders(text: &str) -> Vec<PathBuf> {
447
- let mut current = None;
448
- let mut out = Vec::new();
449
- for line in text.lines() {
450
- let trimmed = line.trim();
451
- if let Some(rest) = trimmed.strip_prefix("[folders.\"") {
452
- current = rest.strip_suffix("\"]").map(str::to_string);
453
- continue;
454
- }
455
- if trimmed.starts_with('[') {
456
- current = None;
457
- continue;
458
- }
459
- if trimmed == "trusted = true" {
460
- if let Some(path) = current.take() {
461
- out.push(PathBuf::from(path));
462
- }
463
- }
464
- }
465
- out
466
- }
467
-
468
- /// ---
469
- /// purpose: 写 workspace 下 grok 的项目作用域 MCP 配置,服务名固定为 team_orchestrator
470
- /// params:
471
- /// mcp_config: 已解析的 MCP 配置,须含 team_orchestrator 条目与 command
472
- /// returns: 成功返回空值;写前先清 per-seat 键,已有表里的未知环境键会被保留
473
- /// errors: 缺条目或缺 command 时返回 StatePersist,清洗失败透传 RequirementUnmet,写文件失败返回 StatePersist
474
- /// ---
475
- /// Grok CLI 没有 `--mcp-config`。launch 路径写一份 provider 实际会读的文件。
476
- /// Grok 只认项目作用域
477
- /// `<cwd>/.grok/config.toml`(`grok mcp add --scope project` 的产物)。
478
- ///
479
- /// Unique writer of `<cwd>/.grok/config.toml`. Reconcile leftover per-seat
480
- /// keys here so restart/resume cannot skip the upgrade migration.
481
- ///
482
- /// `McpConfig.raw` 与写出的 grok 表名都必须是 `team_orchestrator`,与
483
- /// `worker_command_context` 契约(grok: `team_orchestrator__send_message`)对齐。
484
- /// grok 按 server 名给工具加命名空间,写成 `team-agent` 会变成 `team-agent__*`。
485
- pub fn apply_grok_mcp_overlay(
486
- workspace: &Path,
487
- mcp_config: &crate::provider::McpConfig,
488
- ) -> Result<(), LifecycleError> {
489
- // adapter.rs 只产出 team_orchestrator。team-agent 是 0.5.67 overlay
490
- // 误用的旧 inbound key,读侧留一版以免夹具还带旧名;0.5.68 若无引用再删。
491
- let server = mcp_config
492
- .raw
493
- .get("team_orchestrator")
494
- .or_else(|| mcp_config.raw.get("team-agent"))
495
- .ok_or_else(|| {
496
- LifecycleError::StatePersist(
497
- "grok MCP overlay requires team_orchestrator in resolved mcp config".to_string(),
498
- )
499
- })?;
500
- let command = server
501
- .get("command")
502
- .and_then(serde_json::Value::as_str)
503
- .filter(|value| !value.is_empty())
504
- .ok_or_else(|| {
505
- LifecycleError::StatePersist("grok MCP overlay missing command".to_string())
506
- })?;
507
- let args = server
508
- .get("args")
509
- .and_then(serde_json::Value::as_array)
510
- .map(|items| {
511
- items
512
- .iter()
513
- .filter_map(serde_json::Value::as_str)
514
- .map(str::to_string)
515
- .collect::<Vec<_>>()
516
- })
517
- .unwrap_or_default();
518
- let env = server
519
- .get("env")
520
- .and_then(serde_json::Value::as_object)
521
- .map(|map| {
522
- map.iter()
523
- .filter_map(|(key, value)| {
524
- value.as_str().map(|text| (key.clone(), text.to_string()))
525
- })
526
- .collect::<BTreeMap<_, _>>()
527
- })
528
- .unwrap_or_default();
529
-
530
- // Per-seat keys live on the pane env. Unknown keys on the existing
531
- // table stay: a full stanza rewrite must not treat "not in our list"
532
- // as permission to delete.
533
- reconcile_grok_toml_per_seat_keys(workspace)?;
534
- let dir = workspace.join(".grok");
535
- let path = dir.join("config.toml");
536
- let existing = std::fs::read_to_string(&path).unwrap_or_default();
537
- let preserved = super::non_per_seat_env_in_tables(
538
- &existing,
539
- &["mcp_servers.team_orchestrator", "mcp_servers.team-agent"],
540
- );
541
- let mut env = env;
542
- env.retain(|key, value| !super::is_per_seat_env_key(key) && !value.trim().is_empty());
543
- for (key, value) in preserved {
544
- env.entry(key).or_insert(value);
545
- }
546
-
547
- let stanza = render_grok_team_agent_stanza(command, &args, &env);
548
- // 同时摘掉新表和 0.5.67 误写的 [mcp_servers.team-agent],否则改名后两套
549
- // team MCP 并存,grok 会列出两份指向同一进程的工具。
550
- let body = upsert_toml_table_prefixes(
551
- &existing,
552
- &["mcp_servers.team_orchestrator", "mcp_servers.team-agent"],
553
- &stanza,
554
- );
555
- write_grok_config_toml(&dir, &body)
556
- .map_err(|e| LifecycleError::StatePersist(format!("{}: {e}", path.display())))?;
557
- Ok(())
558
- }
559
-
560
- fn render_grok_team_agent_stanza(
561
- command: &str,
562
- args: &[String],
563
- env: &BTreeMap<String, String>,
564
- ) -> String {
565
- let mut out = String::from("[mcp_servers.team_orchestrator]\n");
566
- out.push_str(&format!("command = {}\n", toml_quote(command)));
567
- out.push_str("args = [\n");
568
- for arg in args {
569
- out.push_str(&format!(" {},\n", toml_quote(arg)));
570
- }
571
- out.push_str("]\n");
572
- out.push_str("enabled = true\n");
573
- if !env.is_empty() {
574
- out.push_str("\n[mcp_servers.team_orchestrator.env]\n");
575
- for (key, value) in env {
576
- out.push_str(&format!("{key} = {}\n", toml_quote(value)));
577
- }
578
- }
579
- out
580
- }
581
-
582
- fn toml_quote(value: &str) -> String {
583
- format!("\"{}\"", value.replace('\\', "\\\\").replace('"', "\\\""))
584
- }
585
-
586
- fn upsert_toml_table_prefixes(existing: &str, tables: &[&str], stanza: &str) -> String {
587
- let mut out = String::new();
588
- let mut skip = false;
589
- for line in existing.lines() {
590
- let trimmed = line.trim();
591
- if trimmed.starts_with('[') && trimmed.ends_with(']') {
592
- let name = &trimmed[1..trimmed.len() - 1];
593
- skip = tables
594
- .iter()
595
- .any(|table| name == *table || name.starts_with(&format!("{table}.")));
596
- }
597
- if !skip {
598
- out.push_str(line);
599
- out.push('\n');
600
- }
601
- }
602
- let trimmed = out.trim_end();
603
- if trimmed.is_empty() {
604
- stanza.to_string()
605
- } else {
606
- format!("{trimmed}\n\n{stanza}")
607
- }
608
- }
609
-
610
127
  /// ---
611
128
  /// purpose: 把 argv 里 provider 原生的 MCP 配置参数改指到已落盘的文件
612
129
  /// params:
@@ -1724,7 +1724,7 @@ mod fresh_quick_start_leader_binding_tests {
1724
1724
  let team = workspace.join("roles");
1725
1725
  std::fs::create_dir_all(team.join("agents")).unwrap();
1726
1726
  std::fs::write(team.join("TEAM.md"), "---\nname: fresh\nobjective: test\nprovider: codex\n---\nTeam.\n").unwrap();
1727
- std::fs::write(team.join("agents/worker.md"), "---\nname: worker\nrole: Worker\nprovider: codex\nmodel: gpt-5.5\nauth_mode: subscription\ndangerously_skip_permissions: false\n---\nTest.\n").unwrap();
1727
+ std::fs::write(team.join("agents/worker.md"), "---\nname: worker\nrole: Worker\nprovider: fake\nmodel: fake\nauth_mode: subscription\ndangerously_skip_permissions: false\n---\nTest.\n").unwrap();
1728
1728
  let transport = OfflineTransport::new();
1729
1729
  let report = quick_start_with_transport_in_workspace(
1730
1730
  &workspace, &team, None, true, Some("fresh"), &transport,
@@ -1849,7 +1849,7 @@ mod fresh_quick_start_leader_binding_tests {
1849
1849
  "---\nname: current\nobjective: Bootstrap fixture.\n---\n",
1850
1850
  )
1851
1851
  .unwrap();
1852
- std::fs::write(team.join("agents/worker.md"), "---\nname: worker\nrole: Worker\nprovider: codex\nauth_mode: subscription\ndangerously_skip_permissions: false\n---\nBounded fixture.\n").unwrap();
1852
+ std::fs::write(team.join("agents/worker.md"), "---\nname: worker\nrole: Worker\nprovider: fake\nmodel: fake\nauth_mode: subscription\ndangerously_skip_permissions: false\n---\nBounded fixture.\n").unwrap();
1853
1853
  let state_path = crate::state::persist::runtime_state_path(&workspace);
1854
1854
  std::fs::create_dir_all(state_path.parent().unwrap()).unwrap();
1855
1855
  let state = json!({
@@ -69,10 +69,6 @@ pub(super) fn spawn_agents(
69
69
  let team_dir = team_dir_buf
70
70
  .as_deref()
71
71
  .unwrap_or_else(|| spec_path.parent().unwrap_or_else(|| Path::new(".")));
72
- let runtime_fast = matches!(
73
- spec.get("runtime").and_then(|v| v.get("fast")),
74
- Some(Value::Bool(true))
75
- );
76
72
  let mut started = Vec::new();
77
73
  #[cfg(unix)]
78
74
  let mut contract_started = Vec::new();
@@ -111,8 +107,9 @@ pub(super) fn spawn_agents(
111
107
  // persist_spawn_agent_state projects the actual K3 seat separately.
112
108
  continue;
113
109
  }
114
- // A pre-upgrade Claude Code or Pi worker spec has no legacy runtime
115
- // left; refuse before any MCP file, profile or pane side effect.
110
+ // A pre-upgrade Claude Code, Codex, Grok or Pi worker spec has no
111
+ // legacy runtime left; refuse before any MCP file, profile or pane
112
+ // side effect.
116
113
  if let Some(retired) = agent
117
114
  .get("provider")
118
115
  .and_then(Value::as_str)
@@ -123,11 +120,11 @@ pub(super) fn spawn_agents(
123
120
  ));
124
121
  }
125
122
  let agent_id = AgentId::new(agent_id_raw);
126
- let provider = agent
127
- .get("provider")
128
- .and_then(Value::as_str)
129
- .and_then(parse_provider)
130
- .unwrap_or(Provider::Codex);
123
+ // No provider silently falls back to a legacy engine.
124
+ let raw_provider = agent.get("provider").and_then(Value::as_str).unwrap_or("");
125
+ let provider = parse_provider(raw_provider).ok_or_else(|| {
126
+ LifecycleError::Provider(format!("unknown worker provider {raw_provider:?}"))
127
+ })?;
131
128
  let auth_mode = agent
132
129
  .get("auth_mode")
133
130
  .and_then(Value::as_str)
@@ -316,11 +313,6 @@ pub(super) fn spawn_agents(
316
313
  );
317
314
  }
318
315
  }
319
- // Grok 无 --mcp-config;写 <cwd>/.grok/config.toml 让 CLI 读到 team-agent。
320
- if matches!(provider, Provider::Grok) {
321
- ensure_grok_login_and_folder_trust(workspace)?;
322
- apply_grok_mcp_overlay(workspace, &mcp_config)?;
323
- }
324
316
  crate::provider::argv_route::apply(provider, &mut plan.argv)
325
317
  .map_err(|error| LifecycleError::Provider(error.to_string()))?;
326
318
  let spawn_epoch = u64::try_from(started.len()).unwrap_or(u64::MAX);
@@ -398,11 +390,6 @@ pub(super) fn spawn_agents(
398
390
  30,
399
391
  0.5,
400
392
  );
401
- // Python launch/core.py:235-237 — runtime.fast toggles the provider's fast mode
402
- // after spawn; provider specifics live behind the adapter (F032).
403
- if runtime_fast {
404
- let _ = adapter.enable_fast_mode(transport, &Target::Pane(spawn.pane_id.clone()));
405
- }
406
393
  if matches!(transport.liveness(&spawn.pane_id), Ok(PaneLiveness::Dead)) {
407
394
  continue;
408
395
  }
@@ -3,7 +3,7 @@
3
3
  //! contract:
4
4
  //! provides:
5
5
  //! - name: fork_agent
6
- //! what: 成员分身入口,grok 走窗口内命令
6
+ //! what: 成员分身入口;legacy 席位一律拒绝,新席位 fork 只走 contract 管道
7
7
  //! boundary:
8
8
  //! - 不读 provider 会话落盘
9
9
  //! maturity: wired
@@ -334,18 +334,10 @@ pub(crate) use agent_state::{
334
334
  persist_effective_approval_policy_from_agent,
335
335
  };
336
336
 
337
- mod grok_per_seat;
338
- pub(crate) use grok_per_seat::{
339
- is_per_seat_env_key, non_per_seat_env_in_tables, per_seat_keys_in_toml,
340
- strip_per_seat_keys_from_toml,
341
- };
342
-
343
337
  mod mcp_config;
344
- pub use mcp_config::apply_grok_mcp_overlay;
345
338
  pub(super) use mcp_config::*;
346
339
  pub(crate) use mcp_config::{
347
- ensure_grok_login_and_folder_trust, grok_shared_cwd_error, point_native_mcp_config_at_file,
348
- reconcile_grok_toml_per_seat_keys, resolve_mcp_config, write_worker_mcp_config,
340
+ point_native_mcp_config_at_file, resolve_mcp_config, write_worker_mcp_config,
349
341
  write_worker_mcp_config_for_provider,
350
342
  };
351
343
 
@@ -418,7 +410,7 @@ pub(super) use add_agent_state::*;
418
410
 
419
411
  mod fork_agent;
420
412
  pub(super) use fork_agent::*;
421
- pub use fork_agent::{fork_agent_with_transport, in_window_fork, in_window_fork_command};
413
+ pub use fork_agent::fork_agent_with_transport;
422
414
 
423
415
  mod fork_entry;
424
416
  pub use fork_entry::fork_agent;