@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,247 +0,0 @@
1
- //! ---
2
- //! purpose: grok 席位角色 effort 必须进入 argv;缺字段不发 flag
3
- //! contract:
4
- //! provides:
5
- //! - name: grok-effort-medium-reaches-argv
6
- //! what: effort: medium ⇒ 相邻 `--effort medium`
7
- //! - name: grok-effort-absent-omits-flag
8
- //! what: 角色无 effort 字段 ⇒ argv 中 `--effort` 次数为 0
9
- //! - name: grok-effort-survives-restart
10
- //! what: restart 后仍带同一档
11
- //! - name: grok-effort-no-longer-silently-dropped
12
- //! what: 已废除「grok effort 被静默丢弃 + effort_unsupported」
13
- //! boundary: 只钉 Provider::Grok 的 effort 启动契约;不改 claude/codex/cursor
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 serial_test::serial;
32
- use team_agent::lifecycle::{quick_start_with_transport_in_workspace, restart_with_transport};
33
- use team_agent::transport::test_support::OfflineTransport;
34
-
35
- #[test]
36
- #[serial(env)]
37
- fn grok_role_effort_medium_reaches_argv() {
38
- let _hermetic = enter_hermetic("grok-effort-medium");
39
- let (ws, _home, _guard, team) = seed_grok("effort-medium", Some("medium"));
40
- let transport = OfflineTransport::new();
41
- quick_start_with_transport_in_workspace(&ws, &team, None, true, Some("grokteam"), &transport)
42
- .expect("grok role with effort: medium must start");
43
- let argv = first_spawn_argv(&transport);
44
- assert!(
45
- argv_contains_adjacent(&argv, &["--effort", "medium"]),
46
- "declared effort must appear as adjacent `--effort medium`; argv={argv:?}"
47
- );
48
- }
49
-
50
- #[test]
51
- #[serial(env)]
52
- fn grok_role_without_effort_emits_zero_effort_flags() {
53
- let _hermetic = enter_hermetic("grok-effort-absent");
54
- let (ws, _home, _guard, team) = seed_grok("effort-absent", None);
55
- let transport = OfflineTransport::new();
56
- quick_start_with_transport_in_workspace(&ws, &team, None, true, Some("grokteam"), &transport)
57
- .expect("grok role without effort must start");
58
- let argv = first_spawn_argv(&transport);
59
- let count = argv.iter().filter(|a| *a == "--effort").count();
60
- assert_eq!(
61
- count, 0,
62
- "absent effort must not invent a default flag; argv={argv:?}"
63
- );
64
- }
65
-
66
- #[test]
67
- #[serial(env)]
68
- fn grok_restart_keeps_declared_effort_medium() {
69
- let _hermetic = enter_hermetic("grok-effort-restart");
70
- let (ws, _home, _guard, team) = seed_grok("effort-restart", Some("medium"));
71
- let first = OfflineTransport::new();
72
- quick_start_with_transport_in_workspace(&ws, &team, None, true, Some("grokteam"), &first)
73
- .expect("initial grok start");
74
- assert!(
75
- argv_contains_adjacent(&first_spawn_argv(&first), &["--effort", "medium"]),
76
- "precondition: first start must carry medium; argv={:?}",
77
- first_spawn_argv(&first)
78
- );
79
-
80
- seed_healthy_coordinator(&ws);
81
-
82
- let restart = OfflineTransport::new();
83
- restart_with_transport(&ws, true, Some("grokteam"), &restart)
84
- .expect("restart --allow-fresh must start the grok seat");
85
- let argv = first_spawn_argv(&restart);
86
- assert!(
87
- argv_contains_adjacent(&argv, &["--effort", "medium"]),
88
- "restart must keep the persisted effort; argv={argv:?}"
89
- );
90
- }
91
-
92
- #[test]
93
- #[serial(env)]
94
- fn grok_role_effort_max_is_rejected_at_compile() {
95
- let (ws, _home, _guard, team) = seed_grok("effort-max", Some("max"));
96
- let err =
97
- team_agent::compiler::compile_team(&team).expect_err("grok + effort:max must not compile");
98
- let text = err.to_string();
99
- assert!(
100
- text.contains("max") && (text.contains("claude") || text.contains("only supported")),
101
- "max must stay claude-only at compile; err={text}"
102
- );
103
- }
104
-
105
- #[test]
106
- #[serial(env)]
107
- fn grok_medium_effort_no_longer_emits_unsupported_event() {
108
- // 已废除的行为:旧实现把 grok 的 effort 静默丢掉并写 provider.effort_unsupported,
109
- // 此断言证明它确实没了。
110
- let (ws, _home, _guard, team) = seed_grok("effort-tombstone", Some("medium"));
111
- let transport = OfflineTransport::new();
112
- quick_start_with_transport_in_workspace(&ws, &team, None, true, Some("grokteam"), &transport)
113
- .expect("grok role with effort: medium must start");
114
- let events = team_agent::event_log::EventLog::new(&ws)
115
- .tail(0)
116
- .expect("events");
117
- let dropped = events.iter().any(|event| {
118
- event.get("event").and_then(serde_json::Value::as_str)
119
- == Some("provider.effort_unsupported")
120
- });
121
- assert!(
122
- !dropped,
123
- "grok medium must not emit provider.effort_unsupported; events={events:?}"
124
- );
125
- }
126
-
127
- /// restart 的就绪门要求 `coordinator_health().ok`,而单测里 `start_coordinator`
128
- /// spawn 的是 `std::env::current_exe()` —— 也就是 libtest 测试二进制本身,它一启动
129
- /// 就以 `Unrecognized option: 'workspace'` 退出并变成僵尸,`pid_is_running` 的
130
- /// `ps stat=` 一看到 `Z` 就判 not running。于是就绪门只能靠「抢在死婴被看到之前
131
- /// 探到它」这个竞态过关,慢机/高负载上必然超时。这里按本仓既有写法(见
132
- /// `copilot_provider_red.rs` / `restart_build_before_destroy_0540_contract.rs`)
133
- /// 预先把 pid 文件与 metadata 指向测试进程自己,让 `start_coordinator` 走
134
- /// `AlreadyRunning` 早返回,竞态被删掉而不是被调宽。
135
- fn seed_healthy_coordinator(workspace: &Path) {
136
- let workspace = crate::coordinator::WorkspacePath::new(workspace.to_path_buf());
137
- let pid = crate::coordinator::Pid::new(std::process::id());
138
- std::fs::create_dir_all(
139
- crate::coordinator::coordinator_pid_path(&workspace)
140
- .parent()
141
- .unwrap(),
142
- )
143
- .unwrap();
144
- crate::coordinator::write_coordinator_metadata(
145
- &workspace,
146
- pid,
147
- crate::coordinator::MetadataSource::Boot,
148
- )
149
- .expect("write coordinator metadata");
150
- std::fs::write(
151
- crate::coordinator::coordinator_pid_path(&workspace),
152
- pid.to_string(),
153
- )
154
- .expect("write coordinator pid");
155
- }
156
-
157
- fn seed_grok(tag: &str, effort: Option<&str>) -> (PathBuf, PathBuf, HomeGuard, PathBuf) {
158
- let ws = tmp_dir(tag);
159
- super::launch_spawn::seed_healthy_coordinator(&ws);
160
- let home = tmp_dir(&format!("{tag}-home"));
161
- seed_grok_home(&home, Some(&ws));
162
- let guard = HomeGuard::set(&home);
163
- let team = write_grok_role(&ws, effort);
164
- (ws, home, guard, team)
165
- }
166
-
167
- fn first_spawn_argv(transport: &OfflineTransport) -> Vec<String> {
168
- let records = transport.spawn_records();
169
- assert!(
170
- !records.is_empty(),
171
- "expected a worker spawn so argv can be inspected; records={records:?}"
172
- );
173
- records[0].1.clone()
174
- }
175
-
176
- fn argv_contains_adjacent(hay: &[String], needle: &[&str]) -> bool {
177
- hay.windows(needle.len())
178
- .any(|window| window.iter().map(String::as_str).eq(needle.iter().copied()))
179
- }
180
-
181
- fn write_grok_role(ws: &Path, effort: Option<&str>) -> PathBuf {
182
- let team = ws.join("grokteam");
183
- std::fs::create_dir_all(team.join("agents")).unwrap();
184
- std::fs::write(
185
- team.join("TEAM.md"),
186
- "---\nname: grokteam\nobjective: grok effort argv.\nprovider: grok\ndangerously_skip_permissions: false\n---\n\nTeam.\n",
187
- )
188
- .unwrap();
189
- let effort_line = match effort {
190
- Some(value) => format!("effort: {value}\n"),
191
- None => String::new(),
192
- };
193
- std::fs::write(
194
- team.join("agents").join("grok_writer.md"),
195
- format!(
196
- "---\nname: grok_writer\nrole: Grok Writer\nprovider: grok\nmodel: grok-4.6\n{effort_line}auth_mode: subscription\ndangerously_skip_permissions: false\ntools:\n - mcp_team\n---\n\nWorker.\n"
197
- ),
198
- )
199
- .unwrap();
200
- team
201
- }
202
-
203
- fn seed_grok_home(home: &Path, trusted_cwd: Option<&Path>) {
204
- let grok = home.join(".grok");
205
- std::fs::create_dir_all(&grok).unwrap();
206
- std::fs::write(grok.join("auth.json"), r#"{"test":"ok"}"#).unwrap();
207
- if let Some(cwd) = trusted_cwd {
208
- std::fs::write(
209
- grok.join("trusted_folders.toml"),
210
- format!("[folders.\"{}\"]\ntrusted = true\n", cwd.display()),
211
- )
212
- .unwrap();
213
- }
214
- }
215
-
216
- struct HomeGuard {
217
- prev: Option<String>,
218
- }
219
-
220
- impl HomeGuard {
221
- fn set(home: &Path) -> Self {
222
- let prev = std::env::var("HOME").ok();
223
- std::env::set_var("HOME", home);
224
- Self { prev }
225
- }
226
- }
227
-
228
- impl Drop for HomeGuard {
229
- fn drop(&mut self) {
230
- match &self.prev {
231
- Some(value) => std::env::set_var("HOME", value),
232
- None => std::env::remove_var("HOME"),
233
- }
234
- }
235
- }
236
-
237
- fn tmp_dir(tag: &str) -> PathBuf {
238
- static N: AtomicU64 = AtomicU64::new(0);
239
- let dir = std::env::temp_dir().join(format!(
240
- "ta-rs-grok-effort-{tag}-{}-{}",
241
- std::process::id(),
242
- N.fetch_add(1, Ordering::Relaxed)
243
- ));
244
- let _ = std::fs::remove_dir_all(&dir);
245
- std::fs::create_dir_all(&dir).unwrap();
246
- std::fs::canonicalize(dir).unwrap()
247
- }