@team-agent/installer 0.5.124 → 0.5.125

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 (97) hide show
  1. package/Cargo.lock +1 -8
  2. package/Cargo.toml +1 -1
  3. package/README.md +2 -2
  4. package/README.zh.md +2 -2
  5. package/crates/team-agent/Cargo.toml +0 -1
  6. package/crates/team-agent/src/cli/diagnose.rs +39 -1
  7. package/crates/team-agent/src/cli/emit.rs +41 -15
  8. package/crates/team-agent/src/cli/intent/runtime.rs +5 -53
  9. package/crates/team-agent/src/cli/intent/runtime_tests.rs +0 -120
  10. package/crates/team-agent/src/cli/leader.rs +2 -3
  11. package/crates/team-agent/src/cli/leader_prompt.rs +1 -1
  12. package/crates/team-agent/src/cli/mod.rs +6 -5
  13. package/crates/team-agent/src/cli/models.rs +40 -119
  14. package/crates/team-agent/src/cli/route.rs +1 -1
  15. package/crates/team-agent/src/cli/send/persist.rs +36 -0
  16. package/crates/team-agent/src/cli/send/presentation.rs +7 -1
  17. package/crates/team-agent/src/cli/send.rs +3 -1
  18. package/crates/team-agent/src/cli/spec.rs +1 -2
  19. package/crates/team-agent/src/cli/status_port/brief.rs +66 -0
  20. package/crates/team-agent/src/cli/tests/base.rs +4 -11
  21. package/crates/team-agent/src/cli/tests/status_send.rs +17 -0
  22. package/crates/team-agent/src/compiler/tests.rs +21 -5
  23. package/crates/team-agent/src/compiler.rs +24 -1
  24. package/crates/team-agent/src/contract_runtime/backend.rs +22 -6
  25. package/crates/team-agent/src/contract_runtime/config.rs +34 -24
  26. package/crates/team-agent/src/contract_runtime/discovery.rs +33 -0
  27. package/crates/team-agent/src/contract_runtime/framework.rs +89 -34
  28. package/crates/team-agent/src/contract_runtime/registry.rs +258 -21
  29. package/crates/team-agent/src/coordinator/runtime_detectors.rs +0 -1
  30. package/crates/team-agent/src/coordinator/tick.rs +89 -1
  31. package/crates/team-agent/src/db/message_store.rs +78 -3
  32. package/crates/team-agent/src/layout/worker_window_helpers.rs +0 -1
  33. package/crates/team-agent/src/leader/prompt.rs +1 -2
  34. package/crates/team-agent/src/leader/provider_attribution.rs +0 -52
  35. package/crates/team-agent/src/leader/start.rs +0 -1
  36. package/crates/team-agent/src/leader/tests/prompt_contract.rs +2 -3
  37. package/crates/team-agent/src/lifecycle/launch/add_agent.rs +91 -0
  38. package/crates/team-agent/src/lifecycle/launch/add_agent_state.rs +14 -1
  39. package/crates/team-agent/src/lifecycle/launch/agent_state.rs +0 -9
  40. package/crates/team-agent/src/lifecycle/launch/fork_agent.rs +0 -1
  41. package/crates/team-agent/src/lifecycle/launch/mcp_config.rs +2 -2
  42. package/crates/team-agent/src/lifecycle/launch/spawn.rs +0 -28
  43. package/crates/team-agent/src/lifecycle/launch/spec_state.rs +0 -1
  44. package/crates/team-agent/src/lifecycle/launch/worker_env.rs +0 -108
  45. package/crates/team-agent/src/lifecycle/launch.rs +2 -20
  46. package/crates/team-agent/src/lifecycle/profile_launch.rs +11 -39
  47. package/crates/team-agent/src/lifecycle/profile_smoke.rs +1 -2
  48. package/crates/team-agent/src/lifecycle/restart/common.rs +1 -63
  49. package/crates/team-agent/src/lifecycle/role_config.rs +42 -3
  50. package/crates/team-agent/src/lifecycle/tests/cli_argv_routing_red.rs +38 -7
  51. package/crates/team-agent/src/lifecycle/tests/clone_fork_copilot_perms_red.rs +6 -2
  52. package/crates/team-agent/src/lifecycle/tests/restart_rebind_hotfix_252_red.rs +0 -1
  53. package/crates/team-agent/src/lifecycle/tests/worker_spawn_env_red.rs +0 -137
  54. package/crates/team-agent/src/lifecycle/tests.rs +0 -3
  55. package/crates/team-agent/src/lifecycle/worker_command_context.rs +2 -4
  56. package/crates/team-agent/src/mcp_server/readiness.rs +148 -97
  57. package/crates/team-agent/src/mcp_server/readiness_tests.rs +115 -16
  58. package/crates/team-agent/src/messaging/delivery.rs +181 -35
  59. package/crates/team-agent/src/messaging/delivery_consumption_tests.rs +4 -4
  60. package/crates/team-agent/src/messaging/enter_rescue_tests.rs +1 -1
  61. package/crates/team-agent/src/messaging/helpers.rs +19 -0
  62. package/crates/team-agent/src/messaging/tests/dup_inject.rs +66 -4
  63. package/crates/team-agent/src/messaging/tests/runtime.rs +110 -4
  64. package/crates/team-agent/src/messaging/tests/spine.rs +22 -6
  65. package/crates/team-agent/src/model/enums.rs +1 -8
  66. package/crates/team-agent/src/provider/adapter.rs +1 -67
  67. package/crates/team-agent/src/provider/adapters/mod.rs +0 -1
  68. package/crates/team-agent/src/provider/argv_route.rs +1 -5
  69. package/crates/team-agent/src/provider/bypass_flags.rs +3 -11
  70. package/crates/team-agent/src/provider/classify.rs +68 -3
  71. package/crates/team-agent/src/provider/faults.rs +1 -1
  72. package/crates/team-agent/src/provider/model_catalog.rs +2 -73
  73. package/crates/team-agent/src/provider/session/capture.rs +1 -1
  74. package/crates/team-agent/src/provider/session/context_fork.rs +4 -4
  75. package/crates/team-agent/src/provider/session_scan/common.rs +1 -2
  76. package/crates/team-agent/src/provider/session_scan.rs +0 -4
  77. package/crates/team-agent/src/provider/submit_now.rs +5 -28
  78. package/crates/team-agent/src/provider/tests/adapter.rs +5 -184
  79. package/crates/team-agent/src/provider/tests/classify.rs +53 -0
  80. package/crates/team-agent/src/provider/tests/command_helpers.rs +1 -4
  81. package/crates/team-agent/src/provider/types.rs +1 -1
  82. package/crates/team-agent/src/provider/wire.rs +48 -8
  83. package/crates/team-agent/src/tmux_backend/native_input_tests.rs +2 -178
  84. package/crates/team-agent/src/tmux_backend/tests.rs +151 -0
  85. package/crates/team-agent/src/tmux_backend.rs +43 -8
  86. package/crates/team-agent/src/transport/native_input.rs +2 -231
  87. package/package.json +4 -4
  88. package/skills/team-agent/SKILL.md +1 -1
  89. package/crates/team-agent/src/lifecycle/launch/cursor_create_chat.rs +0 -229
  90. package/crates/team-agent/src/lifecycle/launch/cursor_mcp.rs +0 -522
  91. package/crates/team-agent/src/lifecycle/launch/cursor_mcp_iso.rs +0 -282
  92. package/crates/team-agent/src/lifecycle/tests/cursor_mcp_overlay.rs +0 -576
  93. package/crates/team-agent/src/lifecycle/tests/cursor_require_explicit_model_red.rs +0 -222
  94. package/crates/team-agent/src/lifecycle/tests/cursor_restart_resume_red.rs +0 -511
  95. package/crates/team-agent/src/provider/adapters/cursor_agent.rs +0 -44
  96. package/crates/team-agent/src/provider/session_scan/cursor.rs +0 -538
  97. package/crates/team-agent/src/provider/testdata/cursor-list-models-native.stdout +0 -250
@@ -1,511 +0,0 @@
1
- //! ---
2
- //! purpose: cursor 无假 pending;有 chatId+磁盘 marker 时 restart 走 --resume
3
- //! contract:
4
- //! provides:
5
- //! - name: cursor-fresh-no-fake-session-id
6
- //! what: fresh spawn 不写 --session-id,_pending 空,session_id 空
7
- //! - name: cursor-restart-resume-argv
8
- //! what: session_id + store.db 齐时 restart 发 `--resume <chatId>`
9
- //! - name: cursor-classify-resume-when-archive-present
10
- //! what: classify 在 marker 存在时 Resume,缺失时 Refuse 而非静默 fresh
11
- //! boundary:
12
- //! - 不改 reset-agent --discard-session
13
- //! - 不覆盖 grok/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
- use std::path::{Path, PathBuf};
25
- use std::sync::atomic::{AtomicU64, Ordering};
26
-
27
- use crate::lifecycle::restart::classify_restart_plan_with_resume_validation;
28
- use crate::lifecycle::types::ResumeDecision;
29
- use crate::model::ids::AgentId;
30
- use crate::provider::session_scan::cursor::{cursor_session_archive_present, cursor_session_dir};
31
- use crate::state::persist::{load_runtime_state, save_runtime_state};
32
- use serial_test::serial;
33
- use team_agent::lifecycle::{
34
- cursor_mcp_project_dir, fork_agent_with_transport, quick_start_with_transport_in_workspace,
35
- restart_with_transport,
36
- };
37
- use team_agent::transport::test_support::OfflineTransport;
38
-
39
- #[test]
40
- #[serial(env)]
41
- fn issue345_dynamic_cursor_start_persists_its_generated_mcp_path() {
42
- let _hermetic = hermetic_guard::HermeticTestEnv::enter_with_leader("cursor-dynamic-mcp");
43
- let (ws, _home, _guard, team) = seed_cursor("dynamic-mcp");
44
- std::fs::write(
45
- team.join("agents/cursor_writer.md"),
46
- "---\nprovider: fake\ndangerously_skip_permissions: true\n---\nControl seat.\n",
47
- )
48
- .unwrap();
49
- let transport = OfflineTransport::new();
50
- quick_start_with_transport_in_workspace(&ws, &team, None, true, Some("cursortm"), &transport)
51
- .unwrap();
52
- let role = team.join("cursor_dynamic.md");
53
- std::fs::write(&role, "---\nprovider: cursor_agent\nmodel: grok-4.7-high\nauth_mode: subscription\ndangerously_skip_permissions: true\n---\nDynamic Cursor seat.\n").unwrap();
54
- crate::lifecycle::add_agent_with_transport(
55
- &team,
56
- &AgentId::new("cursor_dynamic"),
57
- &role,
58
- false,
59
- Some("cursortm"),
60
- &transport,
61
- )
62
- .unwrap();
63
- let state = load_runtime_state(&ws).unwrap();
64
- let expected = ws.join(".team/runtime/mcp/cursor_dynamic.json");
65
- assert!(
66
- expected.is_file(),
67
- "positive control: spawn generated the real config"
68
- );
69
- assert_eq!(
70
- state["agents"]["cursor_dynamic"]["mcp_config"].as_str(),
71
- expected.to_str()
72
- );
73
- assert_eq!(
74
- state["teams"]["cursortm"]["agents"]["cursor_dynamic"]["mcp_config"].as_str(),
75
- expected.to_str()
76
- );
77
- let config: serde_json::Value =
78
- serde_json::from_slice(&std::fs::read(&expected).unwrap()).unwrap();
79
- assert_eq!(
80
- config["mcpServers"]["team_orchestrator"]["env"]["TEAM_AGENT_ID"],
81
- "cursor_dynamic"
82
- );
83
- assert_eq!(
84
- config["mcpServers"]["team_orchestrator"]["env"]["TEAM_AGENT_OWNER_TEAM_ID"],
85
- "cursortm"
86
- );
87
- }
88
-
89
- #[test]
90
- #[serial(env)]
91
- fn issue345_cursor_wakeup_restores_missing_derived_mcp_path() {
92
- let _hermetic = hermetic_guard::HermeticTestEnv::enter_with_leader("cursor-wakeup-mcp");
93
- let (ws, _home, _guard, team) = seed_cursor("wakeup-mcp");
94
- let transport = OfflineTransport::new();
95
- quick_start_with_transport_in_workspace(&ws, &team, None, true, Some("cursortm"), &transport)
96
- .unwrap();
97
- crate::lifecycle::restart::stop_agent_with_transport(
98
- &ws,
99
- &AgentId::new("cursor_writer"),
100
- Some("cursortm"),
101
- &transport,
102
- )
103
- .unwrap();
104
- let mut state = load_runtime_state(&ws).unwrap();
105
- state["agents"]["cursor_writer"]
106
- .as_object_mut()
107
- .unwrap()
108
- .remove("mcp_config");
109
- state["teams"]["cursortm"]["agents"]["cursor_writer"]
110
- .as_object_mut()
111
- .unwrap()
112
- .remove("mcp_config");
113
- // Plant an actual legacy row; ordinary state saves intentionally backfill fields.
114
- std::fs::write(
115
- crate::state::persist::runtime_state_path(&ws),
116
- serde_json::to_vec(&state).unwrap(),
117
- )
118
- .unwrap();
119
- assert!(load_runtime_state(&ws).unwrap()["agents"]["cursor_writer"]
120
- .get("mcp_config")
121
- .is_none());
122
- crate::lifecycle::restart::start_agent_with_transport(
123
- &ws,
124
- &AgentId::new("cursor_writer"),
125
- false,
126
- false,
127
- true,
128
- Some("cursortm"),
129
- &transport,
130
- )
131
- .unwrap();
132
- let after = load_runtime_state(&ws).unwrap();
133
- let expected = ws.join(".team/runtime/mcp/cursor_writer.json");
134
- assert!(expected.is_file());
135
- assert_eq!(
136
- after["agents"]["cursor_writer"]["mcp_config"].as_str(),
137
- expected.to_str()
138
- );
139
- assert_eq!(
140
- after["teams"]["cursortm"]["agents"]["cursor_writer"]["mcp_config"].as_str(),
141
- expected.to_str()
142
- );
143
- }
144
-
145
- #[test]
146
- #[serial(env)]
147
- fn cursor_fresh_spawn_does_not_invent_session_id() {
148
- let _hermetic = hermetic_guard::HermeticTestEnv::enter_with_leader("cursor-fresh");
149
- let (ws, _home, _guard, team) = seed_cursor("pending");
150
- let transport = OfflineTransport::new();
151
- quick_start_with_transport_in_workspace(&ws, &team, None, true, Some("cursortm"), &transport)
152
- .expect("cursor fresh start");
153
- let argv = first_spawn_argv(&transport);
154
- assert!(
155
- argv_flag(&argv, "--session-id").is_none(),
156
- "cursor must not invent --session-id; argv={argv:?}"
157
- );
158
- assert!(
159
- argv_flag(&argv, "--resume").is_none(),
160
- "fresh spawn must not --resume; argv={argv:?}"
161
- );
162
- assert!(
163
- !argv.iter().any(|a| a == "--continue"),
164
- "fresh spawn must not --continue; argv={argv:?}"
165
- );
166
- let state = load_runtime_state(&ws).expect("state");
167
- assert_eq!(
168
- state
169
- .pointer("/agents/cursor_writer/_pending_session_id")
170
- .and_then(|v| v.as_str()),
171
- None,
172
- "no fake pending; agent={:?}",
173
- state.pointer("/agents/cursor_writer")
174
- );
175
- assert_eq!(
176
- state
177
- .pointer("/agents/cursor_writer/session_id")
178
- .and_then(|v| v.as_str()),
179
- None,
180
- "session_id stays null until capture; agent={:?}",
181
- state.pointer("/agents/cursor_writer")
182
- );
183
- }
184
-
185
- #[test]
186
- #[serial(env)]
187
- fn cursor_restart_uses_resume_when_session_captured_and_archive_present() {
188
- let _hermetic = hermetic_guard::HermeticTestEnv::enter_with_leader("cursor-resume");
189
- let (ws, home, _guard, team) = seed_cursor("resume");
190
- let first = OfflineTransport::new();
191
- quick_start_with_transport_in_workspace(&ws, &team, None, true, Some("cursortm"), &first)
192
- .expect("initial cursor start");
193
- let sid = "502896a1-72ba-4c53-9a86-b2da28780806";
194
- let primary = cursor_mcp_project_dir(&ws, "cursor_writer").unwrap();
195
- let primary_before = std::fs::canonicalize(&primary).unwrap();
196
- let dir = {
197
- let path = home
198
- .join(".cursor")
199
- .join("chats")
200
- .join(format!(
201
- "{:x}",
202
- md5::compute(primary.to_string_lossy().as_bytes())
203
- ))
204
- .join(sid);
205
- std::fs::create_dir_all(&path).unwrap();
206
- std::fs::write(path.join("store.db"), b"").unwrap();
207
- path
208
- };
209
- assert!(cursor_session_archive_present(&dir));
210
- assert_eq!(cursor_session_dir(sid).as_deref(), Some(dir.as_path()));
211
-
212
- let mut state = load_runtime_state(&ws).expect("load");
213
- assert_eq!(
214
- state["agents"]["cursor_writer"]["spawn_cwd"],
215
- primary.to_string_lossy().as_ref()
216
- );
217
- patch_cursor_writer(&mut state, sid, &dir, &primary);
218
- state["agents"]["cursor_writer"]
219
- .as_object_mut()
220
- .unwrap()
221
- .remove("mcp_config");
222
- state["teams"]["cursortm"]["agents"]["cursor_writer"]
223
- .as_object_mut()
224
- .unwrap()
225
- .remove("mcp_config");
226
- // Preserve the real captured SID while removing only the derived config path.
227
- std::fs::write(
228
- crate::state::persist::runtime_state_path(&ws),
229
- serde_json::to_vec(&state).unwrap(),
230
- )
231
- .unwrap();
232
- assert!(load_runtime_state(&ws).unwrap()["agents"]["cursor_writer"]
233
- .get("mcp_config")
234
- .is_none());
235
-
236
- seed_healthy_coordinator(&ws);
237
-
238
- let restart = OfflineTransport::new();
239
- restart_with_transport(&ws, false, Some("cursortm"), &restart)
240
- .expect("restart without --allow-fresh must resume cursor");
241
- let argv = first_spawn_argv(&restart);
242
- assert!(
243
- argv_contains_adjacent(&argv, &["--resume", sid]),
244
- "captured cursor must restart with --resume <chatId>; argv={argv:?}"
245
- );
246
- assert!(
247
- argv_flag(&argv, "--session-id").is_none(),
248
- "resume argv must not mint --session-id; argv={argv:?}"
249
- );
250
- assert!(
251
- !argv.iter().any(|a| a == "--continue"),
252
- "resume argv must not use --continue; argv={argv:?}"
253
- );
254
- let after = load_runtime_state(&ws).unwrap();
255
- assert_eq!(
256
- after["agents"]["cursor_writer"]["spawn_cwd"],
257
- primary.to_string_lossy().as_ref()
258
- );
259
- assert_eq!(after["agents"]["cursor_writer"]["session_id"], sid);
260
- let expected_config = ws.join(".team/runtime/mcp/cursor_writer.json");
261
- assert_eq!(
262
- after["agents"]["cursor_writer"]["mcp_config"].as_str(),
263
- expected_config.to_str()
264
- );
265
- assert_eq!(
266
- after["teams"]["cursortm"]["agents"]["cursor_writer"]["mcp_config"].as_str(),
267
- expected_config.to_str()
268
- );
269
- assert_eq!(
270
- cursor_mcp_project_dir(&ws, "cursor_writer").unwrap(),
271
- primary_before
272
- );
273
- assert_eq!(argv_flag(&argv, "--workspace").as_deref(), primary.to_str());
274
- assert!(argv_contains_adjacent(
275
- &argv,
276
- &["--add-dir", ws.to_str().unwrap()]
277
- ));
278
- }
279
-
280
- #[test]
281
- #[serial(env)]
282
- fn cursor_classify_resumes_when_archive_present_and_refuses_when_missing() {
283
- let base = tmp_dir("classify");
284
- let home = tmp_dir("classify-home");
285
- let ws = base.join("ws");
286
- std::fs::create_dir_all(&ws).unwrap();
287
- let _guard = HomeGuard::set(&home);
288
- let sid = "502896a1-72ba-4c53-9a86-b2da28780806";
289
- let dir = home.join(".cursor").join("chats").join(sid);
290
- std::fs::create_dir_all(&dir).unwrap();
291
- std::fs::write(dir.join("meta.json"), b"{}").unwrap();
292
-
293
- let present = serde_json::json!({
294
- "agents": {
295
- "w1": {
296
- "provider": "cursor_agent",
297
- "status": "running",
298
- "session_id": sid,
299
- "spawn_cwd": ws.to_string_lossy(),
300
- "rollout_path": dir.to_string_lossy(),
301
- }
302
- }
303
- });
304
- let plan = classify_restart_plan_with_resume_validation(Some(&ws), &present, false)
305
- .expect("classify present");
306
- assert_eq!(plan.decisions.len(), 1);
307
- assert_eq!(
308
- plan.decisions[0].decision,
309
- ResumeDecision::Resume,
310
- "archive present must Resume; unresumable={:?}",
311
- plan.unresumable
312
- );
313
-
314
- let missing_sid = "aaaaaaaa-aaaa-4aaa-8aaa-aaaaaaaaaaaa";
315
- let missing = serde_json::json!({
316
- "agents": {
317
- "w1": {
318
- "provider": "cursor_agent",
319
- "status": "running",
320
- "session_id": missing_sid,
321
- "spawn_cwd": ws.to_string_lossy(),
322
- }
323
- }
324
- });
325
- let refuse = classify_restart_plan_with_resume_validation(Some(&ws), &missing, false)
326
- .expect("classify missing");
327
- assert_eq!(refuse.decisions.len(), 1);
328
- assert_eq!(
329
- refuse.decisions[0].decision,
330
- ResumeDecision::Refuse,
331
- "missing cursor archive must Refuse, not silent fresh; got {:?}",
332
- refuse.decisions[0].decision
333
- );
334
- }
335
-
336
- #[test]
337
- #[serial(env)]
338
- fn cursor_fork_agent_refuses_as_unsupported_not_unverified() {
339
- let _hermetic = hermetic_guard::HermeticTestEnv::enter_with_leader("cursor-fork");
340
- let (ws, _home, _guard, team) = seed_cursor("fork");
341
- let transport = OfflineTransport::new();
342
- quick_start_with_transport_in_workspace(&ws, &team, None, true, Some("cursortm"), &transport)
343
- .expect("cursor start");
344
- let result = fork_agent_with_transport(
345
- &ws,
346
- &AgentId::new("cursor_writer"),
347
- &AgentId::new("cursor_fork"),
348
- None,
349
- false,
350
- Some("cursortm"),
351
- &transport,
352
- );
353
- let err = match result {
354
- Ok(report) => panic!("cursor fork must refuse; report={report:?}"),
355
- Err(error) => error.to_string(),
356
- };
357
- let lower = err.to_ascii_lowercase();
358
- assert!(
359
- lower.contains("does not support") || err.contains("不支持"),
360
- "fork error must be unsupported; err={err}"
361
- );
362
- assert!(
363
- !lower.contains("unverified") && !err.contains("未验证"),
364
- "must not call unverified slash fork; err={err}"
365
- );
366
- }
367
-
368
- fn patch_cursor_writer(state: &mut serde_json::Value, sid: &str, dir: &Path, ws: &Path) {
369
- let mut patched = 0u32;
370
- let mut patch = |agent: &mut serde_json::Value| {
371
- if let Some(obj) = agent.as_object_mut() {
372
- obj.insert("session_id".to_string(), serde_json::json!(sid));
373
- obj.insert(
374
- "rollout_path".to_string(),
375
- serde_json::json!(dir.to_string_lossy()),
376
- );
377
- obj.insert(
378
- "spawn_cwd".to_string(),
379
- serde_json::json!(ws.to_string_lossy()),
380
- );
381
- obj.insert("capture_state".to_string(), serde_json::json!("captured"));
382
- patched += 1;
383
- }
384
- };
385
- if let Some(agent) = state.pointer_mut("/agents/cursor_writer") {
386
- patch(agent);
387
- }
388
- if let Some(teams) = state.get_mut("teams").and_then(|v| v.as_object_mut()) {
389
- for team in teams.values_mut() {
390
- if let Some(agent) = team
391
- .get_mut("agents")
392
- .and_then(|v| v.get_mut("cursor_writer"))
393
- {
394
- patch(agent);
395
- }
396
- }
397
- }
398
- assert!(
399
- patched > 0,
400
- "cursor_writer missing in state; keys={:?}",
401
- state.as_object().map(|o| o.keys().collect::<Vec<_>>())
402
- );
403
- }
404
-
405
- /// restart 的就绪门要求 `coordinator_health().ok`,而单测里 `start_coordinator`
406
- /// spawn 的是 `std::env::current_exe()` —— 也就是 libtest 测试二进制本身,它一启动
407
- /// 就以 `Unrecognized option: 'workspace'` 退出并变成僵尸,`pid_is_running` 的
408
- /// `ps stat=` 一看到 `Z` 就判 not running。于是就绪门只能靠「抢在死婴被看到之前
409
- /// 探到它」这个竞态过关,慢机/高负载上必然超时。这里按本仓既有写法(见
410
- /// `copilot_provider_red.rs` / `restart_build_before_destroy_0540_contract.rs`)
411
- /// 预先把 pid 文件与 metadata 指向测试进程自己,让 `start_coordinator` 走
412
- /// `AlreadyRunning` 早返回,竞态被删掉而不是被调宽。
413
- fn seed_healthy_coordinator(workspace: &Path) {
414
- let workspace = crate::coordinator::WorkspacePath::new(workspace.to_path_buf());
415
- let pid = crate::coordinator::Pid::new(std::process::id());
416
- std::fs::create_dir_all(
417
- crate::coordinator::coordinator_pid_path(&workspace)
418
- .parent()
419
- .unwrap(),
420
- )
421
- .unwrap();
422
- crate::coordinator::write_coordinator_metadata(
423
- &workspace,
424
- pid,
425
- crate::coordinator::MetadataSource::Boot,
426
- )
427
- .expect("write coordinator metadata");
428
- std::fs::write(
429
- crate::coordinator::coordinator_pid_path(&workspace),
430
- pid.to_string(),
431
- )
432
- .expect("write coordinator pid");
433
- }
434
-
435
- fn seed_cursor(tag: &str) -> (PathBuf, PathBuf, HomeGuard, PathBuf) {
436
- let ws = tmp_dir(tag);
437
- super::launch_spawn::seed_healthy_coordinator(&ws);
438
- let home = tmp_dir(&format!("{tag}-home"));
439
- let guard = HomeGuard::set(&home);
440
- let team = write_cursor_role(&ws);
441
- (ws, home, guard, team)
442
- }
443
-
444
- fn first_spawn_argv(transport: &OfflineTransport) -> Vec<String> {
445
- let records = transport.spawn_records();
446
- assert!(
447
- !records.is_empty(),
448
- "expected a worker spawn; records={records:?}"
449
- );
450
- records[0].1.clone()
451
- }
452
-
453
- fn argv_flag(argv: &[String], flag: &str) -> Option<String> {
454
- argv.windows(2)
455
- .find(|pair| pair[0] == flag)
456
- .map(|pair| pair[1].clone())
457
- }
458
-
459
- fn argv_contains_adjacent(hay: &[String], needle: &[&str]) -> bool {
460
- hay.windows(needle.len())
461
- .any(|window| window.iter().map(String::as_str).eq(needle.iter().copied()))
462
- }
463
-
464
- fn write_cursor_role(ws: &Path) -> PathBuf {
465
- let team = ws.join("cursortm");
466
- std::fs::create_dir_all(team.join("agents")).unwrap();
467
- std::fs::write(
468
- team.join("TEAM.md"),
469
- "---\nname: cursortm\nobjective: cursor resume.\nprovider: cursor_agent\ndangerously_skip_permissions: true\n---\n\nTeam.\n",
470
- )
471
- .unwrap();
472
- std::fs::write(
473
- team.join("agents").join("cursor_writer.md"),
474
- "---\nname: cursor_writer\nrole: Cursor Writer\nprovider: cursor_agent\nmodel: sonnet-4-thinking\nauth_mode: subscription\ndangerously_skip_permissions: true\ntools:\n - mcp_team\n---\n\nWorker.\n",
475
- )
476
- .unwrap();
477
- team
478
- }
479
-
480
- struct HomeGuard {
481
- prev: Option<String>,
482
- }
483
-
484
- impl HomeGuard {
485
- fn set(home: &Path) -> Self {
486
- let prev = std::env::var("HOME").ok();
487
- std::env::set_var("HOME", home);
488
- Self { prev }
489
- }
490
- }
491
-
492
- impl Drop for HomeGuard {
493
- fn drop(&mut self) {
494
- match &self.prev {
495
- Some(value) => std::env::set_var("HOME", value),
496
- None => std::env::remove_var("HOME"),
497
- }
498
- }
499
- }
500
-
501
- fn tmp_dir(tag: &str) -> PathBuf {
502
- static N: AtomicU64 = AtomicU64::new(0);
503
- let dir = std::env::temp_dir().join(format!(
504
- "ta-rs-cursor-resume-{tag}-{}-{}",
505
- std::process::id(),
506
- N.fetch_add(1, Ordering::Relaxed)
507
- ));
508
- let _ = std::fs::remove_dir_all(&dir);
509
- std::fs::create_dir_all(&dir).unwrap();
510
- std::fs::canonicalize(dir).unwrap()
511
- }
@@ -1,44 +0,0 @@
1
- //! ---
2
- //! purpose: Cursor agent CLI argv;role 走 .cursor/rules,MCP 走 mcp.json overlay
3
- //! contract:
4
- //! provides:
5
- //! - name: cursor_agent_base_command
6
- //! what: 只组已实测文档化 flag;MCP 由 launch overlay 写盘
7
- //! boundary:
8
- //! - 不调未文档化 flag(--system-prompt / --allowed-tools)
9
- //! - 不写 grok 那种 cwd 独占闸
10
- //! - 不打印代理值
11
- //! maturity: wired
12
- //! ---
13
- //!
14
- //! Cursor `agent` CLI(与 `cursor-agent` 同二进制)。默认不跳过信任或沙箱设置。
15
- //! 显式 bypass 时才使用 `.team/scripts/cursor_seat.sh` 的 trusted/unsandboxed 选项:
16
- //! `--workspace <物理路径> [--trust --sandbox disabled --force] [--model]`
17
- //! Role 不入 argv,写 `<workspace>/.cursor/rules/*.mdc` + `alwaysApply: true`。
18
- //! MCP 无 `--mcp-config`;身份必须写进 `.cursor/mcp.json` 的 env 表
19
- //! (cursor 不把父进程 TEAM_AGENT_* 传给 MCP 子进程)。
20
- //!
21
- //! 隐藏 flag `--system-prompt` / `--allowed-tools` 实测存在但 help 未列,
22
- //! 随时可能消失。可以在注释里记录,代码里不许调。
23
- //! `--allowed-tools` 正反行为未验证,不写「支持工具白名单」。
24
-
25
- use crate::provider::ProviderError;
26
- use crate::provider::command_helpers::{append_opt_pair, append_pair};
27
-
28
- pub(crate) fn cursor_agent_base_command(
29
- model: Option<&str>,
30
- dangerously_skip_permissions: bool,
31
- ) -> Result<Vec<String>, ProviderError> {
32
- let mut argv = vec!["agent".to_string()];
33
- if dangerously_skip_permissions {
34
- // Explicit bypass also opts into Cursor's trusted, unsandboxed launch.
35
- argv.push("--trust".to_string());
36
- append_pair(&mut argv, "--sandbox", "disabled");
37
- argv.push("--force".to_string());
38
- }
39
- append_opt_pair(&mut argv, "--model", model);
40
- // Cursor has no `--effort`, system-prompt, or MCP config flag.
41
- // Launch materializes role rules and the `.cursor/mcp.json` overlay.
42
- append_pair(&mut argv, "--workspace", "{workspace}");
43
- Ok(argv)
44
- }