@team-agent/installer 0.5.123 → 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 (107) 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 +30 -54
  9. package/crates/team-agent/src/cli/intent/runtime_tests.rs +59 -118
  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 +93 -128
  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 +30 -6
  25. package/crates/team-agent/src/contract_runtime/config.rs +34 -24
  26. package/crates/team-agent/src/contract_runtime/discovery.rs +79 -56
  27. package/crates/team-agent/src/contract_runtime/framework.rs +89 -34
  28. package/crates/team-agent/src/contract_runtime/registry.rs +299 -24
  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/pi_mcp.rs +19 -101
  43. package/crates/team-agent/src/lifecycle/launch/spawn.rs +0 -28
  44. package/crates/team-agent/src/lifecycle/launch/spec_state.rs +0 -1
  45. package/crates/team-agent/src/lifecycle/launch/worker_env.rs +0 -108
  46. package/crates/team-agent/src/lifecycle/launch.rs +2 -20
  47. package/crates/team-agent/src/lifecycle/profile_launch.rs +11 -39
  48. package/crates/team-agent/src/lifecycle/profile_smoke.rs +1 -2
  49. package/crates/team-agent/src/lifecycle/restart/common.rs +1 -63
  50. package/crates/team-agent/src/lifecycle/role_config.rs +42 -3
  51. package/crates/team-agent/src/lifecycle/tests/cli_argv_routing_red.rs +43 -13
  52. package/crates/team-agent/src/lifecycle/tests/clone_fork_copilot_perms_red.rs +6 -2
  53. package/crates/team-agent/src/lifecycle/tests/pi_catalog_red.rs +1 -3
  54. package/crates/team-agent/src/lifecycle/tests/pi_command_red.rs +4 -16
  55. package/crates/team-agent/src/lifecycle/tests/pi_compiler_red.rs +1 -3
  56. package/crates/team-agent/src/lifecycle/tests/pi_executable_mcp_red.rs +84 -53
  57. package/crates/team-agent/src/lifecycle/tests/pi_fork_session_inheritance_red.rs +19 -1
  58. package/crates/team-agent/src/lifecycle/tests/pi_session_delivery_red.rs +21 -0
  59. package/crates/team-agent/src/lifecycle/tests/restart_rebind_hotfix_252_red.rs +0 -1
  60. package/crates/team-agent/src/lifecycle/tests/worker_spawn_env_red.rs +0 -137
  61. package/crates/team-agent/src/lifecycle/tests.rs +0 -3
  62. package/crates/team-agent/src/lifecycle/worker_command_context.rs +2 -4
  63. package/crates/team-agent/src/mcp_server/readiness.rs +148 -97
  64. package/crates/team-agent/src/mcp_server/readiness_tests.rs +115 -16
  65. package/crates/team-agent/src/messaging/delivery.rs +186 -38
  66. package/crates/team-agent/src/messaging/delivery_consumption_tests.rs +4 -4
  67. package/crates/team-agent/src/messaging/enter_rescue_tests.rs +1 -1
  68. package/crates/team-agent/src/messaging/helpers.rs +19 -0
  69. package/crates/team-agent/src/messaging/tests/dup_inject.rs +66 -4
  70. package/crates/team-agent/src/messaging/tests/runtime.rs +110 -4
  71. package/crates/team-agent/src/messaging/tests/spine.rs +22 -6
  72. package/crates/team-agent/src/model/enums.rs +1 -8
  73. package/crates/team-agent/src/provider/adapter.rs +1 -67
  74. package/crates/team-agent/src/provider/adapters/mod.rs +0 -1
  75. package/crates/team-agent/src/provider/adapters/pi.rs +4 -4
  76. package/crates/team-agent/src/provider/argv_route.rs +1 -5
  77. package/crates/team-agent/src/provider/bypass_flags.rs +3 -11
  78. package/crates/team-agent/src/provider/classify.rs +68 -3
  79. package/crates/team-agent/src/provider/faults.rs +1 -1
  80. package/crates/team-agent/src/provider/model_catalog.rs +2 -73
  81. package/crates/team-agent/src/provider/session/capture.rs +1 -1
  82. package/crates/team-agent/src/provider/session/context_fork.rs +4 -4
  83. package/crates/team-agent/src/provider/session_scan/common.rs +1 -2
  84. package/crates/team-agent/src/provider/session_scan/pi.rs +32 -19
  85. package/crates/team-agent/src/provider/session_scan.rs +0 -4
  86. package/crates/team-agent/src/provider/submit_now.rs +5 -28
  87. package/crates/team-agent/src/provider/tests/adapter.rs +5 -184
  88. package/crates/team-agent/src/provider/tests/classify.rs +53 -0
  89. package/crates/team-agent/src/provider/tests/command_helpers.rs +3 -6
  90. package/crates/team-agent/src/provider/types.rs +1 -1
  91. package/crates/team-agent/src/provider/wire.rs +48 -8
  92. package/crates/team-agent/src/tmux_backend/native_input_tests.rs +2 -178
  93. package/crates/team-agent/src/tmux_backend/tests.rs +151 -0
  94. package/crates/team-agent/src/tmux_backend.rs +43 -8
  95. package/crates/team-agent/src/transport/native_input.rs +2 -231
  96. package/npm/install.mjs +40 -3
  97. package/package.json +4 -4
  98. package/skills/team-agent/SKILL.md +1 -1
  99. package/crates/team-agent/src/lifecycle/launch/cursor_create_chat.rs +0 -229
  100. package/crates/team-agent/src/lifecycle/launch/cursor_mcp.rs +0 -522
  101. package/crates/team-agent/src/lifecycle/launch/cursor_mcp_iso.rs +0 -282
  102. package/crates/team-agent/src/lifecycle/tests/cursor_mcp_overlay.rs +0 -576
  103. package/crates/team-agent/src/lifecycle/tests/cursor_require_explicit_model_red.rs +0 -222
  104. package/crates/team-agent/src/lifecycle/tests/cursor_restart_resume_red.rs +0 -511
  105. package/crates/team-agent/src/provider/adapters/cursor_agent.rs +0 -44
  106. package/crates/team-agent/src/provider/session_scan/cursor.rs +0 -538
  107. package/crates/team-agent/src/provider/testdata/cursor-list-models-native.stdout +0 -250
@@ -1,229 +0,0 @@
1
- //! ---
2
- //! purpose: cursor 候选 A——`agent create-chat` 解析首行 chatId 后按记录 PID 杀
3
- //! contract:
4
- //! provides:
5
- //! - name: apply_cursor_create_chat_plan
6
- //! what: 无 pending 时把 CLI chatId 写入 expected_session_id 并 `--resume` 该 id
7
- //! - name: create_cursor_chat_id
8
- //! what: 跑 create-chat,读第一行 UUID,只杀本调用记录的 PID
9
- //! requires:
10
- //! - name: cursor-agent-cli
11
- //! what: PATH 上的 `agent`;不存在或首行非法则返回 None(降级候选 B)
12
- //! boundary:
13
- //! - 不发明 --session-id;不 pkill/killall;不 wait 子进程自行退出
14
- //! - 不读 chats 正文、不打印 proxy 值
15
- //! - 已有 expected_session_id 或 argv 已含 --resume 则不动
16
- //! - 2026-08-21 活体:create-chat 后 `--resume` 的存档在 pane stop 后被清;
17
- //! TUI 自建会话能留盘。fresh 路径不调用本函数(走 scan 唯一 hex)。
18
- //! maturity: wired
19
- //! ---
20
-
21
- use std::io::{BufRead, BufReader};
22
- use std::path::Path;
23
- use std::process::{Command, Stdio};
24
- use std::sync::mpsc;
25
- use std::thread;
26
- use std::time::Duration;
27
-
28
- use crate::provider::types::{CommandPlan, SessionId};
29
-
30
- const FIRST_LINE_TIMEOUT: Duration = Duration::from_secs(5);
31
- const TERM_GRACE: Duration = Duration::from_millis(200);
32
-
33
- /// ---
34
- /// purpose: 冷启/无 session 的 cursor 计划绑定 create-chat 得到的 chatId
35
- /// params:
36
- /// plan: build_command_plan 产出;workspace: 物理 cwd
37
- /// returns: 成功则 expected_session_id 与 argv `--resume <id>` 齐;失败则计划不变
38
- /// contract:
39
- /// provides:
40
- /// - name: apply_cursor_create_chat_plan
41
- /// what: 只在无 pending 且 argv 无 --resume 时写入 CLI chatId
42
- /// boundary:
43
- /// - 库测试(cfg(test))不调真实 agent,避免订阅/挂起;具名测试打 create_cursor_chat_id
44
- /// - 不在 launch/restart fresh 调用:活体证实 `--resume` 空聊存档停 pane 后消失
45
- /// ---
46
- pub(crate) fn apply_cursor_create_chat_plan(plan: &mut CommandPlan, workspace: &Path) {
47
- if cfg!(test) {
48
- return;
49
- }
50
- if plan.expected_session_id.is_some() {
51
- return;
52
- }
53
- if plan.argv.iter().any(|flag| flag == "--resume") {
54
- return;
55
- }
56
- let Some(chat_id) = create_cursor_chat_id(workspace) else {
57
- return;
58
- };
59
- plan.expected_session_id = Some(SessionId::new(chat_id.clone()));
60
- plan.argv.push("--resume".to_string());
61
- plan.argv.push(chat_id);
62
- }
63
-
64
- /// ---
65
- /// purpose: 跑 `agent create-chat`,解析首行 UUID,按记录 PID 终止挂起进程
66
- /// params:
67
- /// workspace: create-chat 的 cwd(物理 workspace)
68
- /// returns: 合法 UUID;命令缺失/超时/非法首行则 None
69
- /// contract:
70
- /// provides:
71
- /// - name: create_cursor_chat_id
72
- /// what: 读一行就停;不 wait 退出;只杀本 Child.id()
73
- /// boundary:
74
- /// - 禁 pkill/killall;pid 0/1 不杀
75
- /// ---
76
- pub(crate) fn create_cursor_chat_id(workspace: &Path) -> Option<String> {
77
- create_cursor_chat_id_with_command("agent", workspace)
78
- }
79
-
80
- fn create_cursor_chat_id_with_command(program: &str, workspace: &Path) -> Option<String> {
81
- let mut child = Command::new(program)
82
- .arg("create-chat")
83
- .current_dir(workspace)
84
- .stdin(Stdio::null())
85
- .stdout(Stdio::piped())
86
- .stderr(Stdio::null())
87
- .spawn()
88
- .ok()?;
89
- let pid = child.id();
90
- let stdout = child.stdout.take()?;
91
- let (tx, rx) = mpsc::channel();
92
- thread::spawn(move || {
93
- let mut reader = BufReader::new(stdout);
94
- let mut line = String::new();
95
- let result = reader.read_line(&mut line).ok().and_then(|_| parse_chat_id_line(&line));
96
- let _ = tx.send(result);
97
- });
98
- let parsed = match rx.recv_timeout(FIRST_LINE_TIMEOUT) {
99
- Ok(value) => value,
100
- Err(_) => None,
101
- };
102
- kill_recorded_pid(pid);
103
- let _ = child.wait();
104
- parsed
105
- }
106
-
107
- fn parse_chat_id_line(line: &str) -> Option<String> {
108
- let token = line
109
- .trim()
110
- .split_whitespace()
111
- .next()
112
- .unwrap_or("")
113
- .trim_matches(['"', '\'']);
114
- is_chat_uuid(token).then(|| token.to_string())
115
- }
116
-
117
- fn is_chat_uuid(value: &str) -> bool {
118
- let bytes = value.as_bytes();
119
- if bytes.len() != 36 {
120
- return false;
121
- }
122
- for (i, b) in bytes.iter().enumerate() {
123
- if i == 8 || i == 13 || i == 18 || i == 23 {
124
- if *b != b'-' {
125
- return false;
126
- }
127
- } else if !b.is_ascii_hexdigit() {
128
- return false;
129
- }
130
- }
131
- true
132
- }
133
-
134
- fn kill_recorded_pid(pid: u32) {
135
- if pid == 0 || pid == 1 {
136
- return;
137
- }
138
- #[cfg(unix)]
139
- {
140
- let raw = pid as i32;
141
- unsafe {
142
- libc::kill(raw, libc::SIGTERM);
143
- }
144
- thread::sleep(TERM_GRACE);
145
- unsafe {
146
- libc::kill(raw, libc::SIGKILL);
147
- }
148
- }
149
- #[cfg(not(unix))]
150
- {
151
- let _ = pid;
152
- }
153
- }
154
-
155
- #[cfg(test)]
156
- mod tests {
157
- #![allow(clippy::unwrap_used)]
158
-
159
- use super::*;
160
- use std::os::unix::fs::PermissionsExt;
161
- use std::sync::atomic::{AtomicU64, Ordering};
162
-
163
- fn tmp_root(tag: &str) -> std::path::PathBuf {
164
- static CTR: AtomicU64 = AtomicU64::new(0);
165
- let dir = std::env::temp_dir().join(format!(
166
- "ta-d117-create-chat-{}-{}-{}",
167
- tag,
168
- std::process::id(),
169
- CTR.fetch_add(1, Ordering::Relaxed)
170
- ));
171
- let _ = std::fs::remove_dir_all(&dir);
172
- std::fs::create_dir_all(&dir).unwrap();
173
- dir
174
- }
175
-
176
- fn write_stub(dir: &Path, body: &str) -> std::path::PathBuf {
177
- let path = dir.join("agent");
178
- std::fs::write(&path, body).unwrap();
179
- let mut perm = std::fs::metadata(&path).unwrap().permissions();
180
- perm.set_mode(0o755);
181
- std::fs::set_permissions(&path, perm).unwrap();
182
- path
183
- }
184
-
185
- #[test]
186
- fn create_chat_reads_first_line_and_kills_recorded_pid() {
187
- let base = tmp_root("ok");
188
- let ws = base.join("ws");
189
- std::fs::create_dir_all(&ws).unwrap();
190
- let bin = write_stub(
191
- &base,
192
- "#!/bin/sh\necho '681c8837-d564-44fa-98bf-4ff5a66592e2'\nkill -STOP $$\n",
193
- );
194
- let got = create_cursor_chat_id_with_command(bin.to_str().unwrap(), &ws);
195
- assert_eq!(
196
- got.as_deref(),
197
- Some("681c8837-d564-44fa-98bf-4ff5a66592e2")
198
- );
199
- let _ = std::fs::remove_dir_all(&base);
200
- }
201
-
202
- #[test]
203
- fn create_chat_rejects_non_uuid_first_line() {
204
- let base = tmp_root("bad");
205
- let ws = base.join("ws");
206
- std::fs::create_dir_all(&ws).unwrap();
207
- let bin = write_stub(&base, "#!/bin/sh\necho not-a-uuid\nkill -STOP $$\n");
208
- let got = create_cursor_chat_id_with_command(bin.to_str().unwrap(), &ws);
209
- assert!(got.is_none());
210
- let _ = std::fs::remove_dir_all(&base);
211
- }
212
-
213
- #[test]
214
- fn apply_is_noop_when_resume_already_present() {
215
- let mut plan = CommandPlan {
216
- argv: vec![
217
- "agent".into(),
218
- "--resume".into(),
219
- "already-bound".into(),
220
- ],
221
- expected_session_id: None,
222
- provider_projects_root: None,
223
- managed_mcp_config: false,
224
- };
225
- apply_cursor_create_chat_plan(&mut plan, Path::new("/tmp"));
226
- assert!(plan.expected_session_id.is_none());
227
- assert_eq!(plan.argv.iter().filter(|a| *a == "--resume").count(), 1);
228
- }
229
- }