@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.
- package/Cargo.lock +1 -8
- package/Cargo.toml +1 -1
- package/README.md +2 -2
- package/README.zh.md +2 -2
- package/crates/team-agent/Cargo.toml +0 -1
- package/crates/team-agent/src/cli/diagnose.rs +39 -1
- package/crates/team-agent/src/cli/emit.rs +41 -15
- package/crates/team-agent/src/cli/intent/runtime.rs +5 -53
- package/crates/team-agent/src/cli/intent/runtime_tests.rs +0 -120
- package/crates/team-agent/src/cli/leader.rs +2 -3
- package/crates/team-agent/src/cli/leader_prompt.rs +1 -1
- package/crates/team-agent/src/cli/mod.rs +6 -5
- package/crates/team-agent/src/cli/models.rs +40 -119
- package/crates/team-agent/src/cli/route.rs +1 -1
- package/crates/team-agent/src/cli/send/persist.rs +36 -0
- package/crates/team-agent/src/cli/send/presentation.rs +7 -1
- package/crates/team-agent/src/cli/send.rs +3 -1
- package/crates/team-agent/src/cli/spec.rs +1 -2
- package/crates/team-agent/src/cli/status_port/brief.rs +66 -0
- package/crates/team-agent/src/cli/tests/base.rs +4 -11
- package/crates/team-agent/src/cli/tests/status_send.rs +17 -0
- package/crates/team-agent/src/compiler/tests.rs +21 -5
- package/crates/team-agent/src/compiler.rs +24 -1
- package/crates/team-agent/src/contract_runtime/backend.rs +22 -6
- package/crates/team-agent/src/contract_runtime/config.rs +34 -24
- package/crates/team-agent/src/contract_runtime/discovery.rs +33 -0
- package/crates/team-agent/src/contract_runtime/framework.rs +89 -34
- package/crates/team-agent/src/contract_runtime/registry.rs +258 -21
- package/crates/team-agent/src/coordinator/runtime_detectors.rs +0 -1
- package/crates/team-agent/src/coordinator/tick.rs +89 -1
- package/crates/team-agent/src/db/message_store.rs +78 -3
- package/crates/team-agent/src/layout/worker_window_helpers.rs +0 -1
- package/crates/team-agent/src/leader/prompt.rs +1 -2
- package/crates/team-agent/src/leader/provider_attribution.rs +0 -52
- package/crates/team-agent/src/leader/start.rs +0 -1
- package/crates/team-agent/src/leader/tests/prompt_contract.rs +2 -3
- package/crates/team-agent/src/lifecycle/launch/add_agent.rs +91 -0
- package/crates/team-agent/src/lifecycle/launch/add_agent_state.rs +14 -1
- package/crates/team-agent/src/lifecycle/launch/agent_state.rs +0 -9
- package/crates/team-agent/src/lifecycle/launch/fork_agent.rs +0 -1
- package/crates/team-agent/src/lifecycle/launch/mcp_config.rs +2 -2
- package/crates/team-agent/src/lifecycle/launch/spawn.rs +0 -28
- package/crates/team-agent/src/lifecycle/launch/spec_state.rs +0 -1
- package/crates/team-agent/src/lifecycle/launch/worker_env.rs +0 -108
- package/crates/team-agent/src/lifecycle/launch.rs +2 -20
- package/crates/team-agent/src/lifecycle/profile_launch.rs +11 -39
- package/crates/team-agent/src/lifecycle/profile_smoke.rs +1 -2
- package/crates/team-agent/src/lifecycle/restart/common.rs +1 -63
- package/crates/team-agent/src/lifecycle/role_config.rs +42 -3
- package/crates/team-agent/src/lifecycle/tests/cli_argv_routing_red.rs +38 -7
- package/crates/team-agent/src/lifecycle/tests/clone_fork_copilot_perms_red.rs +6 -2
- package/crates/team-agent/src/lifecycle/tests/restart_rebind_hotfix_252_red.rs +0 -1
- package/crates/team-agent/src/lifecycle/tests/worker_spawn_env_red.rs +0 -137
- package/crates/team-agent/src/lifecycle/tests.rs +0 -3
- package/crates/team-agent/src/lifecycle/worker_command_context.rs +2 -4
- package/crates/team-agent/src/mcp_server/readiness.rs +148 -97
- package/crates/team-agent/src/mcp_server/readiness_tests.rs +115 -16
- package/crates/team-agent/src/messaging/delivery.rs +181 -35
- package/crates/team-agent/src/messaging/delivery_consumption_tests.rs +4 -4
- package/crates/team-agent/src/messaging/enter_rescue_tests.rs +1 -1
- package/crates/team-agent/src/messaging/helpers.rs +19 -0
- package/crates/team-agent/src/messaging/tests/dup_inject.rs +66 -4
- package/crates/team-agent/src/messaging/tests/runtime.rs +110 -4
- package/crates/team-agent/src/messaging/tests/spine.rs +22 -6
- package/crates/team-agent/src/model/enums.rs +1 -8
- package/crates/team-agent/src/provider/adapter.rs +1 -67
- package/crates/team-agent/src/provider/adapters/mod.rs +0 -1
- package/crates/team-agent/src/provider/argv_route.rs +1 -5
- package/crates/team-agent/src/provider/bypass_flags.rs +3 -11
- package/crates/team-agent/src/provider/classify.rs +68 -3
- package/crates/team-agent/src/provider/faults.rs +1 -1
- package/crates/team-agent/src/provider/model_catalog.rs +2 -73
- package/crates/team-agent/src/provider/session/capture.rs +1 -1
- package/crates/team-agent/src/provider/session/context_fork.rs +4 -4
- package/crates/team-agent/src/provider/session_scan/common.rs +1 -2
- package/crates/team-agent/src/provider/session_scan.rs +0 -4
- package/crates/team-agent/src/provider/submit_now.rs +5 -28
- package/crates/team-agent/src/provider/tests/adapter.rs +5 -184
- package/crates/team-agent/src/provider/tests/classify.rs +53 -0
- package/crates/team-agent/src/provider/tests/command_helpers.rs +1 -4
- package/crates/team-agent/src/provider/types.rs +1 -1
- package/crates/team-agent/src/provider/wire.rs +48 -8
- package/crates/team-agent/src/tmux_backend/native_input_tests.rs +2 -178
- package/crates/team-agent/src/tmux_backend/tests.rs +151 -0
- package/crates/team-agent/src/tmux_backend.rs +43 -8
- package/crates/team-agent/src/transport/native_input.rs +2 -231
- package/package.json +4 -4
- package/skills/team-agent/SKILL.md +1 -1
- package/crates/team-agent/src/lifecycle/launch/cursor_create_chat.rs +0 -229
- package/crates/team-agent/src/lifecycle/launch/cursor_mcp.rs +0 -522
- package/crates/team-agent/src/lifecycle/launch/cursor_mcp_iso.rs +0 -282
- package/crates/team-agent/src/lifecycle/tests/cursor_mcp_overlay.rs +0 -576
- package/crates/team-agent/src/lifecycle/tests/cursor_require_explicit_model_red.rs +0 -222
- package/crates/team-agent/src/lifecycle/tests/cursor_restart_resume_red.rs +0 -511
- package/crates/team-agent/src/provider/adapters/cursor_agent.rs +0 -44
- package/crates/team-agent/src/provider/session_scan/cursor.rs +0 -538
- package/crates/team-agent/src/provider/testdata/cursor-list-models-native.stdout +0 -250
|
@@ -1,538 +0,0 @@
|
|
|
1
|
-
//! ---
|
|
2
|
-
//! purpose: 捕获 ~/.cursor/chats/ 存档:pending chatId 或 workspace hex 下唯一新目录
|
|
3
|
-
//! contract:
|
|
4
|
-
//! provides:
|
|
5
|
-
//! - name: cursor_session_dir
|
|
6
|
-
//! what: 由 HOME + chatId 派生磁盘存档目录(直达或一层 hex 子目录)
|
|
7
|
-
//! - name: cursor_session_archive_present
|
|
8
|
-
//! what: 只凭 marker 文件存在性判定 backing,不打开正文
|
|
9
|
-
//! - name: scan_session_store
|
|
10
|
-
//! what: pending 命中则返回该 id;否则仅当 spawn_cwd 的 md5 hex 下唯一新 marker 目录才捕获
|
|
11
|
-
//! requires:
|
|
12
|
-
//! - name: workspace-hex-or-pending
|
|
13
|
-
//! what: 无 pending 时只看 ~/.cursor/chats/<md5(canonical cwd)>/,不扫全库
|
|
14
|
-
//! boundary:
|
|
15
|
-
//! - 只服务 Provider::CursorAgent
|
|
16
|
-
//! - 不发明 --session-id;不读 store.db/meta.json 正文
|
|
17
|
-
//! - 0 或 ≥2 个新目录 → 空向量,不拾取邻席
|
|
18
|
-
//! - 不改 grok/claude/codex/copilot 扫描
|
|
19
|
-
//! maturity: wired
|
|
20
|
-
//! ---
|
|
21
|
-
|
|
22
|
-
use std::path::{Path, PathBuf};
|
|
23
|
-
|
|
24
|
-
use crate::provider::types::{CaptureVia, CapturedSession, Confidence, RolloutPath, SessionId};
|
|
25
|
-
|
|
26
|
-
use super::{CaptureSessionContext, CapturedSessionCandidate};
|
|
27
|
-
|
|
28
|
-
fn session_id_legal(session_id: &str) -> bool {
|
|
29
|
-
!session_id.is_empty()
|
|
30
|
-
&& !session_id.contains('/')
|
|
31
|
-
&& !session_id.contains('\\')
|
|
32
|
-
&& !session_id.contains('\0')
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/// Marker names from 2026-08-21 U-02 `ls` of `~/.cursor/chats/<hex>/<uuid>/`
|
|
36
|
-
/// (names only). Existence is backing; contents are not read.
|
|
37
|
-
const MARKERS: &[&str] = &["store.db", "meta.json"];
|
|
38
|
-
|
|
39
|
-
/// ---
|
|
40
|
-
/// purpose: 只凭 marker 文件存在性判断 cursor 会话存档是否可 resume
|
|
41
|
-
/// params:
|
|
42
|
-
/// dir: cursor_session_dir 给出的目录
|
|
43
|
-
/// returns: 目录存在且含 store.db 或 meta.json
|
|
44
|
-
/// contract:
|
|
45
|
-
/// provides:
|
|
46
|
-
/// - name: cursor_session_archive_present
|
|
47
|
-
/// what: 用 is_file 判 backing,不打开正文
|
|
48
|
-
/// boundary:
|
|
49
|
-
/// - 不读 json / sqlite 内容
|
|
50
|
-
/// ---
|
|
51
|
-
pub(crate) fn cursor_session_archive_present(dir: &Path) -> bool {
|
|
52
|
-
if !dir.is_dir() {
|
|
53
|
-
return false;
|
|
54
|
-
}
|
|
55
|
-
MARKERS.iter().any(|name| dir.join(name).is_file())
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
fn first_present_dir(candidates: impl IntoIterator<Item = PathBuf>) -> Option<PathBuf> {
|
|
59
|
-
candidates.into_iter().find(|dir| cursor_session_archive_present(dir))
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/// ---
|
|
63
|
-
/// purpose: 由 chatId 派生 ~/.cursor/chats 下的存档目录
|
|
64
|
-
/// params:
|
|
65
|
-
/// session_id: CLI chatId;空或含路径分隔则拒绝
|
|
66
|
-
/// returns: HOME 下含 marker 的目录;HOME 缺失或 id 非法则 None
|
|
67
|
-
/// contract:
|
|
68
|
-
/// provides:
|
|
69
|
-
/// - name: cursor_session_dir
|
|
70
|
-
/// what: 只派生并核 marker 存在性,不创建目录、不读存档
|
|
71
|
-
/// boundary:
|
|
72
|
-
/// - 无 pending 时不枚举其它 chatId
|
|
73
|
-
/// ---
|
|
74
|
-
pub(crate) fn cursor_session_dir(session_id: &str) -> Option<PathBuf> {
|
|
75
|
-
if !session_id_legal(session_id) {
|
|
76
|
-
return None;
|
|
77
|
-
}
|
|
78
|
-
let home = std::env::var_os("HOME").map(PathBuf::from)?;
|
|
79
|
-
let chats = home.join(".cursor").join("chats");
|
|
80
|
-
let direct = chats.join(session_id);
|
|
81
|
-
if let Some(dir) = first_present_dir([direct.clone()]) {
|
|
82
|
-
return Some(dir);
|
|
83
|
-
}
|
|
84
|
-
// U-02 layout: ~/.cursor/chats/<hex32>/<uuid>/store.db
|
|
85
|
-
if direct.is_dir() {
|
|
86
|
-
if let Ok(entries) = std::fs::read_dir(&direct) {
|
|
87
|
-
for entry in entries.flatten() {
|
|
88
|
-
let child = entry.path();
|
|
89
|
-
if cursor_session_archive_present(&child) {
|
|
90
|
-
return Some(child);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
if let Ok(entries) = std::fs::read_dir(&chats) {
|
|
96
|
-
for entry in entries.flatten() {
|
|
97
|
-
let nested = entry.path().join(session_id);
|
|
98
|
-
if cursor_session_archive_present(&nested) {
|
|
99
|
-
return Some(nested);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
None
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
/// ---
|
|
107
|
-
/// purpose: 由 spawn_cwd 的 md5 hex + chatId 直达存档,避免全库枚举失败
|
|
108
|
-
/// params:
|
|
109
|
-
/// session_id: CLI chatId;spawn_cwd: 席位物理 workspace
|
|
110
|
-
/// returns: hex/uuid 含 marker 则该目录,否则回落 cursor_session_dir
|
|
111
|
-
/// contract:
|
|
112
|
-
/// provides:
|
|
113
|
-
/// - name: cursor_session_dir_for_cwd
|
|
114
|
-
/// what: 优先 ~/.cursor/chats/<md5(cwd)>/<chatId>/,再全库回落
|
|
115
|
-
/// boundary:
|
|
116
|
-
/// - 不读正文;id 非法则 None
|
|
117
|
-
/// ---
|
|
118
|
-
pub(crate) fn cursor_session_dir_for_cwd(session_id: &str, spawn_cwd: &Path) -> Option<PathBuf> {
|
|
119
|
-
if !session_id_legal(session_id) {
|
|
120
|
-
return None;
|
|
121
|
-
}
|
|
122
|
-
let home = std::env::var_os("HOME").map(PathBuf::from)?;
|
|
123
|
-
let hex = workspace_chats_hex(spawn_cwd);
|
|
124
|
-
let nested = home
|
|
125
|
-
.join(".cursor")
|
|
126
|
-
.join("chats")
|
|
127
|
-
.join(hex)
|
|
128
|
-
.join(session_id);
|
|
129
|
-
if cursor_session_archive_present(&nested) {
|
|
130
|
-
return Some(nested);
|
|
131
|
-
}
|
|
132
|
-
cursor_session_dir(session_id)
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
fn candidate_for(
|
|
136
|
-
session_id: SessionId,
|
|
137
|
-
dir: PathBuf,
|
|
138
|
-
spawn_cwd: PathBuf,
|
|
139
|
-
) -> CapturedSessionCandidate {
|
|
140
|
-
CapturedSessionCandidate {
|
|
141
|
-
captured: CapturedSession {
|
|
142
|
-
session_id: Some(session_id),
|
|
143
|
-
rollout_path: Some(RolloutPath::new(dir)),
|
|
144
|
-
captured_via: CaptureVia::FsWatch,
|
|
145
|
-
attribution_confidence: Confidence::High,
|
|
146
|
-
spawn_cwd,
|
|
147
|
-
},
|
|
148
|
-
embedded_agent_id: None,
|
|
149
|
-
positive_agent_id_match: false,
|
|
150
|
-
agent_path_match: false,
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
fn workspace_chats_hex(spawn_cwd: &Path) -> String {
|
|
155
|
-
let canonical = std::fs::canonicalize(spawn_cwd).unwrap_or_else(|_| spawn_cwd.to_path_buf());
|
|
156
|
-
format!("{:x}", md5::compute(canonical.to_string_lossy().as_bytes()))
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
fn dir_mtime_passes(dir: &Path, spawned_at: Option<&str>) -> bool {
|
|
160
|
-
let Some(raw) = spawned_at else {
|
|
161
|
-
return true;
|
|
162
|
-
};
|
|
163
|
-
let Ok(parsed) = chrono::DateTime::parse_from_rfc3339(raw) else {
|
|
164
|
-
return true;
|
|
165
|
-
};
|
|
166
|
-
let threshold = parsed.with_timezone(&chrono::Utc) - chrono::Duration::seconds(2);
|
|
167
|
-
let Ok(meta) = dir.metadata() else {
|
|
168
|
-
return false;
|
|
169
|
-
};
|
|
170
|
-
let Ok(mtime) = meta.modified() else {
|
|
171
|
-
return false;
|
|
172
|
-
};
|
|
173
|
-
chrono::DateTime::<chrono::Utc>::from(mtime) >= threshold
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
/// ---
|
|
177
|
-
/// purpose: 无 pending 时按 spawn_cwd 的 md5 hex 捕获唯一新 cursor 存档
|
|
178
|
-
/// params:
|
|
179
|
-
/// context: spawn_cwd + 可选 spawned_at
|
|
180
|
-
/// returns: hex 下恰好一个通过时间窗的 marker 目录则一条候选,否则空
|
|
181
|
-
/// contract:
|
|
182
|
-
/// provides:
|
|
183
|
-
/// - name: scan_unique_workspace_chat
|
|
184
|
-
/// what: 只枚举 ~/.cursor/chats/<md5(cwd)>/,0 或 ≥2 不拾取
|
|
185
|
-
/// boundary:
|
|
186
|
-
/// - 不扫其它 hex;不读 marker 正文
|
|
187
|
-
/// ---
|
|
188
|
-
fn scan_unique_workspace_chat(context: &CaptureSessionContext) -> Vec<CapturedSessionCandidate> {
|
|
189
|
-
let Some(home) = std::env::var_os("HOME").map(PathBuf::from) else {
|
|
190
|
-
return Vec::new();
|
|
191
|
-
};
|
|
192
|
-
let hex = workspace_chats_hex(&context.spawn_cwd);
|
|
193
|
-
if hex.len() != 32 {
|
|
194
|
-
return Vec::new();
|
|
195
|
-
}
|
|
196
|
-
let root = home.join(".cursor").join("chats").join(&hex);
|
|
197
|
-
if !root.is_dir() {
|
|
198
|
-
return Vec::new();
|
|
199
|
-
}
|
|
200
|
-
let mut hits: Vec<(String, PathBuf)> = Vec::new();
|
|
201
|
-
let Ok(entries) = std::fs::read_dir(&root) else {
|
|
202
|
-
return Vec::new();
|
|
203
|
-
};
|
|
204
|
-
for entry in entries.flatten() {
|
|
205
|
-
let child = entry.path();
|
|
206
|
-
if !child.is_dir() {
|
|
207
|
-
continue;
|
|
208
|
-
}
|
|
209
|
-
let Some(name) = child.file_name().and_then(|n| n.to_str()) else {
|
|
210
|
-
continue;
|
|
211
|
-
};
|
|
212
|
-
if !session_id_legal(name) {
|
|
213
|
-
continue;
|
|
214
|
-
}
|
|
215
|
-
if !cursor_session_archive_present(&child) {
|
|
216
|
-
continue;
|
|
217
|
-
}
|
|
218
|
-
if !dir_mtime_passes(&child, context.spawned_at.as_deref()) {
|
|
219
|
-
continue;
|
|
220
|
-
}
|
|
221
|
-
hits.push((name.to_string(), child));
|
|
222
|
-
}
|
|
223
|
-
if hits.len() != 1 {
|
|
224
|
-
return Vec::new();
|
|
225
|
-
}
|
|
226
|
-
let (sid, dir) = hits.remove(0);
|
|
227
|
-
vec![candidate_for(
|
|
228
|
-
SessionId::new(sid),
|
|
229
|
-
dir,
|
|
230
|
-
context.spawn_cwd.clone(),
|
|
231
|
-
)]
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
/// ---
|
|
235
|
-
/// purpose: 按 pending chatId 或 workspace hex 唯一新目录捕获 cursor 存档
|
|
236
|
-
/// params:
|
|
237
|
-
/// context: 含 spawn_cwd;可选 expected_session_id / spawned_at
|
|
238
|
-
/// returns: 命中则一条 FsWatch 候选,否则空向量
|
|
239
|
-
/// contract:
|
|
240
|
-
/// provides:
|
|
241
|
-
/// - name: scan_session_store
|
|
242
|
-
/// what: pending 优先;否则唯一新 hex 目录
|
|
243
|
-
/// boundary:
|
|
244
|
-
/// - 非唯一不拾取既有 hex 会话
|
|
245
|
-
/// ---
|
|
246
|
-
pub(super) fn scan_session_store(context: &CaptureSessionContext) -> Vec<CapturedSessionCandidate> {
|
|
247
|
-
if let Some(expected) = context.expected_session_id.as_ref() {
|
|
248
|
-
let Some(dir) = cursor_session_dir(expected.as_str()) else {
|
|
249
|
-
return Vec::new();
|
|
250
|
-
};
|
|
251
|
-
return vec![candidate_for(
|
|
252
|
-
expected.clone(),
|
|
253
|
-
dir,
|
|
254
|
-
context.spawn_cwd.clone(),
|
|
255
|
-
)];
|
|
256
|
-
}
|
|
257
|
-
scan_unique_workspace_chat(context)
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
#[cfg(test)]
|
|
261
|
-
mod tests {
|
|
262
|
-
#![allow(clippy::unwrap_used)]
|
|
263
|
-
|
|
264
|
-
use super::*;
|
|
265
|
-
use crate::provider::types::SessionId;
|
|
266
|
-
use std::sync::atomic::{AtomicU64, Ordering};
|
|
267
|
-
|
|
268
|
-
struct HomeGuard {
|
|
269
|
-
prev: Option<std::ffi::OsString>,
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
impl HomeGuard {
|
|
273
|
-
fn set(home: &Path) -> Self {
|
|
274
|
-
let prev = std::env::var_os("HOME");
|
|
275
|
-
std::env::set_var("HOME", home);
|
|
276
|
-
Self { prev }
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
impl Drop for HomeGuard {
|
|
281
|
-
fn drop(&mut self) {
|
|
282
|
-
match &self.prev {
|
|
283
|
-
Some(v) => std::env::set_var("HOME", v),
|
|
284
|
-
None => std::env::remove_var("HOME"),
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
fn tmp_root(tag: &str) -> PathBuf {
|
|
290
|
-
static CTR: AtomicU64 = AtomicU64::new(0);
|
|
291
|
-
let dir = std::env::temp_dir().join(format!(
|
|
292
|
-
"ta-d115-cursor-scan-{}-{}-{}",
|
|
293
|
-
tag,
|
|
294
|
-
std::process::id(),
|
|
295
|
-
CTR.fetch_add(1, Ordering::Relaxed)
|
|
296
|
-
));
|
|
297
|
-
let _ = std::fs::remove_dir_all(&dir);
|
|
298
|
-
std::fs::create_dir_all(&dir).unwrap();
|
|
299
|
-
std::fs::canonicalize(&dir).unwrap()
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
fn seed_direct(home: &Path, session_id: &str) -> PathBuf {
|
|
303
|
-
let dir = home.join(".cursor").join("chats").join(session_id);
|
|
304
|
-
std::fs::create_dir_all(&dir).unwrap();
|
|
305
|
-
std::fs::write(dir.join("store.db"), b"").unwrap();
|
|
306
|
-
dir
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
fn seed_nested(home: &Path, outer: &str, session_id: &str) -> PathBuf {
|
|
310
|
-
let dir = home
|
|
311
|
-
.join(".cursor")
|
|
312
|
-
.join("chats")
|
|
313
|
-
.join(outer)
|
|
314
|
-
.join(session_id);
|
|
315
|
-
std::fs::create_dir_all(&dir).unwrap();
|
|
316
|
-
std::fs::write(dir.join("meta.json"), b"THIS-BODY-MUST-NOT-BE-PARSED\n").unwrap();
|
|
317
|
-
dir
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
fn ctx(cwd: &Path, expected: Option<&str>) -> CaptureSessionContext {
|
|
321
|
-
CaptureSessionContext {
|
|
322
|
-
agent_id: "w1".to_string(),
|
|
323
|
-
spawn_cwd: cwd.to_path_buf(),
|
|
324
|
-
pane_id: None,
|
|
325
|
-
pane_pid: None,
|
|
326
|
-
spawned_at: None,
|
|
327
|
-
expected_session_id: expected.map(SessionId::new),
|
|
328
|
-
provider_projects_root: None,
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
#[test]
|
|
333
|
-
#[serial_test::serial(env)]
|
|
334
|
-
fn cursor_unique_workspace_hex_dir_captures_without_pending() {
|
|
335
|
-
let base = tmp_root("unique-hex");
|
|
336
|
-
let home = base.join("home");
|
|
337
|
-
let cwd = base.join("ws");
|
|
338
|
-
std::fs::create_dir_all(&home).unwrap();
|
|
339
|
-
std::fs::create_dir_all(&cwd).unwrap();
|
|
340
|
-
let cwd = std::fs::canonicalize(&cwd).unwrap();
|
|
341
|
-
let _guard = HomeGuard::set(&home);
|
|
342
|
-
let sid = "09d2aeaa-33ef-4148-a2e6-83a7c3775caa";
|
|
343
|
-
let hex = workspace_chats_hex(&cwd);
|
|
344
|
-
assert_eq!(hex.len(), 32);
|
|
345
|
-
let dir = seed_nested(&home, &hex, sid);
|
|
346
|
-
let out = scan_session_store(&ctx(&cwd, None));
|
|
347
|
-
assert_eq!(out.len(), 1, "unique hex uuid must capture; got {out:?}");
|
|
348
|
-
assert_eq!(out[0].captured.session_id.as_ref().unwrap().as_str(), sid);
|
|
349
|
-
assert_eq!(
|
|
350
|
-
out[0]
|
|
351
|
-
.captured
|
|
352
|
-
.rollout_path
|
|
353
|
-
.as_ref()
|
|
354
|
-
.map(|p| p.as_path().to_path_buf()),
|
|
355
|
-
Some(dir)
|
|
356
|
-
);
|
|
357
|
-
let _ = std::fs::remove_dir_all(&base);
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
#[test]
|
|
361
|
-
#[serial_test::serial(env)]
|
|
362
|
-
fn cursor_two_workspace_hex_dirs_do_not_steal() {
|
|
363
|
-
let base = tmp_root("two-hex");
|
|
364
|
-
let home = base.join("home");
|
|
365
|
-
let cwd = base.join("ws");
|
|
366
|
-
std::fs::create_dir_all(&home).unwrap();
|
|
367
|
-
std::fs::create_dir_all(&cwd).unwrap();
|
|
368
|
-
let cwd = std::fs::canonicalize(&cwd).unwrap();
|
|
369
|
-
let _guard = HomeGuard::set(&home);
|
|
370
|
-
let hex = workspace_chats_hex(&cwd);
|
|
371
|
-
seed_nested(&home, &hex, "aaaaaaaa-aaaa-4aaa-8aaa-aaaaaaaaaaaa");
|
|
372
|
-
seed_nested(&home, &hex, "bbbbbbbb-bbbb-4bbb-8bbb-bbbbbbbbbbbb");
|
|
373
|
-
let out = scan_session_store(&ctx(&cwd, None));
|
|
374
|
-
assert!(
|
|
375
|
-
out.is_empty(),
|
|
376
|
-
"two marker dirs under cwd hex must not bind; got {out:?}"
|
|
377
|
-
);
|
|
378
|
-
let _ = std::fs::remove_dir_all(&base);
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
#[test]
|
|
382
|
-
#[serial_test::serial(env)]
|
|
383
|
-
fn cursor_session_dir_for_cwd_hits_hex_layout() {
|
|
384
|
-
let base = tmp_root("for-cwd");
|
|
385
|
-
let home = base.join("home");
|
|
386
|
-
let cwd = base.join("ws");
|
|
387
|
-
std::fs::create_dir_all(&home).unwrap();
|
|
388
|
-
std::fs::create_dir_all(&cwd).unwrap();
|
|
389
|
-
let cwd = std::fs::canonicalize(&cwd).unwrap();
|
|
390
|
-
let _guard = HomeGuard::set(&home);
|
|
391
|
-
let sid = "09d2aeaa-33ef-4148-a2e6-83a7c3775caa";
|
|
392
|
-
let hex = workspace_chats_hex(&cwd);
|
|
393
|
-
let dir = seed_nested(&home, &hex, sid);
|
|
394
|
-
assert_eq!(
|
|
395
|
-
cursor_session_dir_for_cwd(sid, &cwd).as_deref(),
|
|
396
|
-
Some(dir.as_path())
|
|
397
|
-
);
|
|
398
|
-
let _ = std::fs::remove_dir_all(&base);
|
|
399
|
-
}
|
|
400
|
-
|
|
401
|
-
#[test]
|
|
402
|
-
#[serial_test::serial(env)]
|
|
403
|
-
fn cursor_foreign_hex_is_ignored_when_cwd_hex_empty() {
|
|
404
|
-
let base = tmp_root("foreign-hex");
|
|
405
|
-
let home = base.join("home");
|
|
406
|
-
let cwd = base.join("ws");
|
|
407
|
-
std::fs::create_dir_all(&home).unwrap();
|
|
408
|
-
std::fs::create_dir_all(&cwd).unwrap();
|
|
409
|
-
let cwd = std::fs::canonicalize(&cwd).unwrap();
|
|
410
|
-
let _guard = HomeGuard::set(&home);
|
|
411
|
-
seed_nested(
|
|
412
|
-
&home,
|
|
413
|
-
"ffffffffffffffffffffffffffffffff",
|
|
414
|
-
"cccccccc-cccc-4ccc-8ccc-cccccccccccc",
|
|
415
|
-
);
|
|
416
|
-
let out = scan_session_store(&ctx(&cwd, None));
|
|
417
|
-
assert!(
|
|
418
|
-
out.is_empty(),
|
|
419
|
-
"foreign hex must not bind empty cwd hex; got {out:?}"
|
|
420
|
-
);
|
|
421
|
-
let _ = std::fs::remove_dir_all(&base);
|
|
422
|
-
}
|
|
423
|
-
|
|
424
|
-
#[test]
|
|
425
|
-
#[serial_test::serial(env)]
|
|
426
|
-
fn cursor_expected_id_captures_store_db_without_reading_body() {
|
|
427
|
-
let base = tmp_root("hit");
|
|
428
|
-
let home = base.join("home");
|
|
429
|
-
let cwd = base.join("ws");
|
|
430
|
-
std::fs::create_dir_all(&home).unwrap();
|
|
431
|
-
std::fs::create_dir_all(&cwd).unwrap();
|
|
432
|
-
let sid = "00a437742b92089861da7821a62f232a";
|
|
433
|
-
let _guard = HomeGuard::set(&home);
|
|
434
|
-
let dir = seed_direct(&home, sid);
|
|
435
|
-
std::fs::write(dir.join("store.db"), b"THIS-BODY-MUST-NOT-BE-PARSED\n").unwrap();
|
|
436
|
-
let out = scan_session_store(&ctx(&cwd, Some(sid)));
|
|
437
|
-
assert_eq!(out.len(), 1);
|
|
438
|
-
assert_eq!(out[0].captured.session_id.as_ref().unwrap().as_str(), sid);
|
|
439
|
-
assert_eq!(
|
|
440
|
-
out[0]
|
|
441
|
-
.captured
|
|
442
|
-
.rollout_path
|
|
443
|
-
.as_ref()
|
|
444
|
-
.map(|p| p.as_path().to_path_buf()),
|
|
445
|
-
Some(dir)
|
|
446
|
-
);
|
|
447
|
-
let _ = std::fs::remove_dir_all(&base);
|
|
448
|
-
}
|
|
449
|
-
|
|
450
|
-
#[test]
|
|
451
|
-
#[serial_test::serial(env)]
|
|
452
|
-
fn cursor_nested_hex_uuid_layout_captures_expected_id() {
|
|
453
|
-
let base = tmp_root("nested");
|
|
454
|
-
let home = base.join("home");
|
|
455
|
-
let cwd = base.join("ws");
|
|
456
|
-
std::fs::create_dir_all(&home).unwrap();
|
|
457
|
-
std::fs::create_dir_all(&cwd).unwrap();
|
|
458
|
-
let outer = "00a437742b92089861da7821a62f232a";
|
|
459
|
-
let sid = "502896a1-72ba-4c53-9a86-b2da28780806";
|
|
460
|
-
let _guard = HomeGuard::set(&home);
|
|
461
|
-
let dir = seed_nested(&home, outer, sid);
|
|
462
|
-
let out = scan_session_store(&ctx(&cwd, Some(sid)));
|
|
463
|
-
assert_eq!(out.len(), 1);
|
|
464
|
-
assert_eq!(out[0].captured.session_id.as_ref().unwrap().as_str(), sid);
|
|
465
|
-
assert_eq!(
|
|
466
|
-
out[0]
|
|
467
|
-
.captured
|
|
468
|
-
.rollout_path
|
|
469
|
-
.as_ref()
|
|
470
|
-
.map(|p| p.as_path().to_path_buf()),
|
|
471
|
-
Some(dir)
|
|
472
|
-
);
|
|
473
|
-
let _ = std::fs::remove_dir_all(&base);
|
|
474
|
-
}
|
|
475
|
-
|
|
476
|
-
#[test]
|
|
477
|
-
#[serial_test::serial(env)]
|
|
478
|
-
fn cursor_scan_without_expected_id_does_not_steal_existing_hex() {
|
|
479
|
-
let base = tmp_root("no-pending");
|
|
480
|
-
let home = base.join("home");
|
|
481
|
-
let cwd = base.join("ws");
|
|
482
|
-
std::fs::create_dir_all(&home).unwrap();
|
|
483
|
-
std::fs::create_dir_all(&cwd).unwrap();
|
|
484
|
-
let _guard = HomeGuard::set(&home);
|
|
485
|
-
seed_direct(&home, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
|
|
486
|
-
let out = scan_session_store(&ctx(&cwd, None));
|
|
487
|
-
assert!(
|
|
488
|
-
out.is_empty(),
|
|
489
|
-
"no pending must not pick existing chats; got {out:?}"
|
|
490
|
-
);
|
|
491
|
-
let _ = std::fs::remove_dir_all(&base);
|
|
492
|
-
}
|
|
493
|
-
|
|
494
|
-
#[test]
|
|
495
|
-
#[serial_test::serial(env)]
|
|
496
|
-
fn cursor_expected_id_does_not_steal_foreign_chat() {
|
|
497
|
-
let base = tmp_root("foreign");
|
|
498
|
-
let home = base.join("home");
|
|
499
|
-
let cwd = base.join("ws");
|
|
500
|
-
std::fs::create_dir_all(&home).unwrap();
|
|
501
|
-
std::fs::create_dir_all(&cwd).unwrap();
|
|
502
|
-
let _guard = HomeGuard::set(&home);
|
|
503
|
-
seed_direct(&home, "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb");
|
|
504
|
-
let out = scan_session_store(&ctx(&cwd, Some("cccccccccccccccccccccccccccccccc")));
|
|
505
|
-
assert!(out.is_empty(), "foreign chat must not bind; got {out:?}");
|
|
506
|
-
let _ = std::fs::remove_dir_all(&base);
|
|
507
|
-
}
|
|
508
|
-
|
|
509
|
-
#[test]
|
|
510
|
-
#[serial_test::serial(env)]
|
|
511
|
-
fn cursor_empty_or_path_id_is_rejected() {
|
|
512
|
-
let base = tmp_root("illegal");
|
|
513
|
-
let home = base.join("home");
|
|
514
|
-
std::fs::create_dir_all(&home).unwrap();
|
|
515
|
-
let _guard = HomeGuard::set(&home);
|
|
516
|
-
assert!(cursor_session_dir("").is_none());
|
|
517
|
-
assert!(cursor_session_dir("../escape").is_none());
|
|
518
|
-
assert!(cursor_session_dir("a\\b").is_none());
|
|
519
|
-
let _ = std::fs::remove_dir_all(&base);
|
|
520
|
-
}
|
|
521
|
-
|
|
522
|
-
#[test]
|
|
523
|
-
#[serial_test::serial(env)]
|
|
524
|
-
fn cursor_empty_dir_without_marker_is_not_backing() {
|
|
525
|
-
let base = tmp_root("empty");
|
|
526
|
-
let home = base.join("home");
|
|
527
|
-
let cwd = base.join("ws");
|
|
528
|
-
std::fs::create_dir_all(&home).unwrap();
|
|
529
|
-
std::fs::create_dir_all(&cwd).unwrap();
|
|
530
|
-
let sid = "dddddddddddddddddddddddddddddddd";
|
|
531
|
-
let _guard = HomeGuard::set(&home);
|
|
532
|
-
let dir = home.join(".cursor").join("chats").join(sid);
|
|
533
|
-
std::fs::create_dir_all(&dir).unwrap();
|
|
534
|
-
assert!(!cursor_session_archive_present(&dir));
|
|
535
|
-
assert!(scan_session_store(&ctx(&cwd, Some(sid))).is_empty());
|
|
536
|
-
let _ = std::fs::remove_dir_all(&base);
|
|
537
|
-
}
|
|
538
|
-
}
|