@team-agent/installer 0.5.124 → 0.5.126
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 -69
- package/crates/team-agent/src/cli/emit.rs +45 -15
- package/crates/team-agent/src/cli/intent/runtime.rs +5 -53
- package/crates/team-agent/src/cli/intent/runtime_tests.rs +10 -130
- 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 +28 -33
- package/crates/team-agent/src/cli/models.rs +44 -880
- 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/mod.rs +1 -1
- package/crates/team-agent/src/cli/tests/run_delegation.rs +5 -4
- package/crates/team-agent/src/cli/tests/status_send.rs +17 -0
- package/crates/team-agent/src/compiler/tests.rs +39 -8
- package/crates/team-agent/src/compiler.rs +28 -204
- package/crates/team-agent/src/contract_runtime/backend.rs +79 -40
- package/crates/team-agent/src/contract_runtime/config.rs +37 -24
- package/crates/team-agent/src/contract_runtime/discovery.rs +33 -0
- package/crates/team-agent/src/contract_runtime/fork.rs +368 -0
- package/crates/team-agent/src/contract_runtime/framework.rs +87 -34
- package/crates/team-agent/src/contract_runtime/mod.rs +1 -0
- package/crates/team-agent/src/contract_runtime/registry.rs +299 -21
- package/crates/team-agent/src/coordinator/runtime_detectors.rs +0 -1
- package/crates/team-agent/src/coordinator/tests/api_error_recovery.rs +29 -8
- package/crates/team-agent/src/coordinator/tests/health_sync.rs +0 -42
- 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 +1 -2
- 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 +15 -195
- package/crates/team-agent/src/lifecycle/launch/agent_state.rs +0 -9
- package/crates/team-agent/src/lifecycle/launch/clone_agent.rs +11 -27
- package/crates/team-agent/src/lifecycle/launch/fork_agent.rs +18 -29
- package/crates/team-agent/src/lifecycle/launch/fork_entry.rs +6 -87
- package/crates/team-agent/src/lifecycle/launch/mcp_config.rs +3 -11
- package/crates/team-agent/src/lifecycle/launch/pi_mcp.rs +74 -244
- package/crates/team-agent/src/lifecycle/launch/quick_start.rs +0 -24
- package/crates/team-agent/src/lifecycle/launch/role_source.rs +5 -0
- package/crates/team-agent/src/lifecycle/launch/spawn.rs +21 -61
- 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 -43
- package/crates/team-agent/src/lifecycle/profile_launch.rs +21 -348
- package/crates/team-agent/src/lifecycle/profile_smoke.rs +1 -2
- package/crates/team-agent/src/lifecycle/restart/common.rs +43 -378
- package/crates/team-agent/src/lifecycle/restart/selection.rs +5 -5
- package/crates/team-agent/src/lifecycle/restart.rs +0 -2
- package/crates/team-agent/src/lifecycle/role_config.rs +42 -3
- package/crates/team-agent/src/lifecycle/tests/behavioral_diff_264_red.rs +11 -6
- package/crates/team-agent/src/lifecycle/tests/claude_profile_launch_red.rs +8 -320
- package/crates/team-agent/src/lifecycle/tests/cli_argv_routing_red.rs +60 -145
- package/crates/team-agent/src/lifecycle/tests/clone_fork_copilot_perms_red.rs +8 -334
- package/crates/team-agent/src/lifecycle/tests/communication_mode_runtime_contract_red.rs +30 -11
- package/crates/team-agent/src/lifecycle/tests/copilot_provider_red.rs +2 -2
- package/crates/team-agent/src/lifecycle/tests/core.rs +17 -16
- package/crates/team-agent/src/lifecycle/tests/grok_require_explicit_model_red.rs +12 -12
- package/crates/team-agent/src/lifecycle/tests/harvest2_a_batch_red.rs +3 -51
- package/crates/team-agent/src/lifecycle/tests/launch_spawn.rs +26 -28
- package/crates/team-agent/src/lifecycle/tests/pi_catalog_red.rs +6 -18
- package/crates/team-agent/src/lifecycle/tests/pi_command_red.rs +52 -70
- package/crates/team-agent/src/lifecycle/tests/pi_dual_entry_red.rs +4 -157
- package/crates/team-agent/src/lifecycle/tests/pi_executable_mcp_red.rs +10 -302
- package/crates/team-agent/src/lifecycle/tests/pi_lifecycle_doctor_red.rs +1 -68
- package/crates/team-agent/src/lifecycle/tests/pi_native_mcp_capability_red.rs +1 -19
- package/crates/team-agent/src/lifecycle/tests/pi_session_delivery_red.rs +2 -100
- package/crates/team-agent/src/lifecycle/tests/quick_start_worker_readiness_red.rs +11 -10
- package/crates/team-agent/src/lifecycle/tests/restart_rebind_hotfix_252_red.rs +0 -1
- package/crates/team-agent/src/lifecycle/tests/restart_session_capture_red.rs +2 -106
- package/crates/team-agent/src/lifecycle/tests/status_credential_redaction_contract.rs +2 -2
- package/crates/team-agent/src/lifecycle/tests/swallow_batch4_semantics_red.rs +2 -254
- package/crates/team-agent/src/lifecycle/tests/upgrade_compat_0211_red.rs +4 -4
- package/crates/team-agent/src/lifecycle/tests/verify_rs031_window_consistency_red.rs +6 -5
- package/crates/team-agent/src/lifecycle/tests/worker_spawn_env_red.rs +7 -153
- package/crates/team-agent/src/lifecycle/tests.rs +0 -6
- package/crates/team-agent/src/lifecycle/types.rs +2 -18
- 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 +185 -168
- package/crates/team-agent/src/messaging/delivery_consumption_tests.rs +5 -5
- 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 +67 -5
- package/crates/team-agent/src/messaging/tests/runtime.rs +110 -4
- package/crates/team-agent/src/messaging/tests/spine.rs +46 -36
- package/crates/team-agent/src/model/enums.rs +1 -8
- package/crates/team-agent/src/provider/adapter.rs +33 -302
- package/crates/team-agent/src/provider/adapters/mod.rs +4 -5
- 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 +14 -273
- package/crates/team-agent/src/provider/session/capture.rs +7 -107
- package/crates/team-agent/src/provider/session/context_fork/outcome.rs +0 -4
- package/crates/team-agent/src/provider/session/context_fork.rs +17 -109
- package/crates/team-agent/src/provider/session_scan/common.rs +11 -36
- package/crates/team-agent/src/provider/session_scan/pi.rs +1 -34
- package/crates/team-agent/src/provider/session_scan.rs +4 -14
- package/crates/team-agent/src/provider/submit_now.rs +5 -28
- package/crates/team-agent/src/provider/tests/adapter.rs +39 -275
- package/crates/team-agent/src/provider/tests/classify.rs +53 -0
- package/crates/team-agent/src/provider/tests/command_helpers.rs +3 -15
- package/crates/team-agent/src/provider/tests/idle.rs +0 -25
- package/crates/team-agent/src/provider/types.rs +1 -1
- package/crates/team-agent/src/provider/wire.rs +79 -11
- package/crates/team-agent/src/state/abnormal_watch/tests/mod.rs +1 -1
- package/crates/team-agent/src/state/persist.rs +6 -6
- package/crates/team-agent/src/state/repository/tests.rs +2 -2
- 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 +7 -5
- package/skills/team-agent/command-coverage.json +15 -1
- package/skills/team-agent/docs/reference/team-agent-operator.md +5 -3
- package/skills/team-agent/references/team-agent-operator.md +5 -3
- 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/restart/avatar.rs +0 -1805
- package/crates/team-agent/src/lifecycle/tests/claude_compatible_config_red.rs +0 -325
- 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/lifecycle/tests/pi_compiler_red.rs +0 -210
- package/crates/team-agent/src/lifecycle/tests/pi_fork_session_inheritance_red.rs +0 -1409
- package/crates/team-agent/src/provider/adapters/claude.rs +0 -78
- package/crates/team-agent/src/provider/adapters/claude_fork.rs +0 -131
- package/crates/team-agent/src/provider/adapters/cursor_agent.rs +0 -44
- package/crates/team-agent/src/provider/adapters/pi.rs +0 -100
- package/crates/team-agent/src/provider/session/context_fork/claude.rs +0 -123
- package/crates/team-agent/src/provider/session_scan/claude.rs +0 -523
- 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
- package/crates/team-agent/src/test_support/models_timeout_fixture.rs +0 -144
|
@@ -1,282 +0,0 @@
|
|
|
1
|
-
//! Cursor's native MCP project root must be an owned primary outside Git ancestry.
|
|
2
|
-
//! Keep the real project as --add-dir; never overwrite its shared MCP config or
|
|
3
|
-
//! silently relocate an existing native session. The persisted directory receipt
|
|
4
|
-
//! is transport ownership, not a canonical Provider/native-session identity.
|
|
5
|
-
|
|
6
|
-
use std::io::{Read, Write};
|
|
7
|
-
use std::os::unix::fs::{DirBuilderExt, MetadataExt, OpenOptionsExt};
|
|
8
|
-
use std::path::{Path, PathBuf};
|
|
9
|
-
|
|
10
|
-
use serde::{Deserialize, Serialize};
|
|
11
|
-
use team_agent_contract::contract::types::{
|
|
12
|
-
Generation, InstanceId, InstanceIdentity, ScopeId, SeatId,
|
|
13
|
-
};
|
|
14
|
-
use team_agent_contract::host::files::{DirectoryReceipt, ScopedDirectory};
|
|
15
|
-
use team_agent_contract::host::{digest, digest_hex};
|
|
16
|
-
|
|
17
|
-
use crate::lifecycle::LifecycleError;
|
|
18
|
-
|
|
19
|
-
const ISOLATION_ENV: &str = "TEAM_AGENT_CURSOR_MCP_ISOLATION";
|
|
20
|
-
|
|
21
|
-
#[derive(Serialize, Deserialize)]
|
|
22
|
-
#[serde(deny_unknown_fields)]
|
|
23
|
-
struct ProjectRecord {
|
|
24
|
-
workspace: PathBuf,
|
|
25
|
-
agent_id: String,
|
|
26
|
-
owner_team_id: String,
|
|
27
|
-
directory: DirectoryReceipt,
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
pub fn cursor_mcp_isolation_enabled() -> bool {
|
|
31
|
-
match std::env::var(ISOLATION_ENV) {
|
|
32
|
-
Ok(value) => !matches!(
|
|
33
|
-
value.trim(),
|
|
34
|
-
"0" | "false" | "FALSE" | "off" | "OFF" | "no" | "NO"
|
|
35
|
-
),
|
|
36
|
-
Err(_) => true,
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
fn failure(reason: impl std::fmt::Display) -> LifecycleError {
|
|
41
|
-
LifecycleError::RequirementUnmet(format!(
|
|
42
|
-
"cursor MCP private project refused: {reason}; do not overwrite shared .cursor/mcp.json or move an existing session"
|
|
43
|
-
))
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
fn record_path(workspace: &Path, agent_id: &str) -> PathBuf {
|
|
47
|
-
workspace
|
|
48
|
-
.join(".team/runtime/provider-config")
|
|
49
|
-
.join(agent_id)
|
|
50
|
-
.join("cursor-project.json")
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
fn project_key(workspace: &Path, agent_id: &str) -> String {
|
|
54
|
-
digest_hex(digest(
|
|
55
|
-
format!("{}\0{agent_id}", workspace.display()).as_bytes(),
|
|
56
|
-
))
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
fn planned_project(workspace: &Path, agent_id: &str) -> Result<PathBuf, LifecycleError> {
|
|
60
|
-
// Do not assume TMPDIR is outside Git, or use an unchecked symlink alias.
|
|
61
|
-
let parent = std::env::temp_dir().canonicalize().map_err(failure)?;
|
|
62
|
-
validate_cursor_mcp_project_root(&parent)?;
|
|
63
|
-
Ok(parent.join(format!(
|
|
64
|
-
"ta-cursor-{}",
|
|
65
|
-
&project_key(workspace, agent_id)[..32]
|
|
66
|
-
)))
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/// Computes a new path without creating it; existing allocations must reopen
|
|
70
|
-
/// their captured receipt, never adopt a replacement directory or a new TMPDIR.
|
|
71
|
-
pub fn cursor_mcp_project_dir(workspace: &Path, agent_id: &str) -> Result<PathBuf, LifecycleError> {
|
|
72
|
-
validate_agent_id(agent_id)?;
|
|
73
|
-
let workspace = workspace.canonicalize().map_err(failure)?;
|
|
74
|
-
match read_record(&workspace, agent_id)? {
|
|
75
|
-
Some(record) => Ok(reopen(&record)?.path().to_path_buf()),
|
|
76
|
-
None => planned_project(&workspace, agent_id),
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
pub fn cursor_mcp_json_path(workspace: &Path, agent_id: &str) -> Result<PathBuf, LifecycleError> {
|
|
81
|
-
Ok(cursor_mcp_project_dir(workspace, agent_id)?.join(".cursor/mcp.json"))
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
/// Read-only scope proof for CLI planning. An external pathname or a matching
|
|
85
|
-
/// directory name is not ownership: the existing selected-team record must pin
|
|
86
|
-
/// this exact physical cwd. Never materialize or repair during preflight.
|
|
87
|
-
pub(crate) fn cursor_mcp_primary_matches_scope(
|
|
88
|
-
workspace: &Path,
|
|
89
|
-
owner_team_id: &str,
|
|
90
|
-
agent_id: &str,
|
|
91
|
-
declared_cwd: &Path,
|
|
92
|
-
) -> Result<bool, LifecycleError> {
|
|
93
|
-
validate_agent_id(agent_id)?;
|
|
94
|
-
let workspace = workspace.canonicalize().map_err(failure)?;
|
|
95
|
-
let Some(record) = read_record(&workspace, agent_id)? else {
|
|
96
|
-
return Ok(false);
|
|
97
|
-
};
|
|
98
|
-
if record.owner_team_id != owner_team_id || record.directory.path != declared_cwd {
|
|
99
|
-
return Ok(false);
|
|
100
|
-
}
|
|
101
|
-
Ok(reopen(&record)?.path() == declared_cwd)
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/// Metadata-only mirror of the measured native project-root boundary. A .git
|
|
105
|
-
/// directory OR worktree file on any ancestor would redirect native MCP loading.
|
|
106
|
-
pub(super) fn validate_cursor_mcp_project_root(project: &Path) -> Result<(), LifecycleError> {
|
|
107
|
-
if project.canonicalize().map_err(failure)? != project {
|
|
108
|
-
return Err(failure("project path is not physical"));
|
|
109
|
-
}
|
|
110
|
-
for ancestor in project.ancestors() {
|
|
111
|
-
match std::fs::symlink_metadata(ancestor.join(".git")) {
|
|
112
|
-
Ok(_) => {
|
|
113
|
-
return Err(failure(
|
|
114
|
-
"Git ancestor would redirect native MCP projectRoot",
|
|
115
|
-
))
|
|
116
|
-
}
|
|
117
|
-
Err(e) if e.kind() == std::io::ErrorKind::NotFound => {}
|
|
118
|
-
Err(e) => return Err(failure(e)),
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
Ok(())
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
pub fn materialize_cursor_mcp_project(
|
|
125
|
-
workspace: &Path,
|
|
126
|
-
agent_id: &str,
|
|
127
|
-
owner_team_id: &str,
|
|
128
|
-
) -> Result<PathBuf, LifecycleError> {
|
|
129
|
-
validate_agent_id(agent_id)?;
|
|
130
|
-
let workspace = workspace.canonicalize().map_err(failure)?;
|
|
131
|
-
if owner_team_id.trim().is_empty() {
|
|
132
|
-
return Err(failure("missing owner team"));
|
|
133
|
-
}
|
|
134
|
-
if let Some(record) = read_record(&workspace, agent_id)? {
|
|
135
|
-
if record.owner_team_id != owner_team_id {
|
|
136
|
-
return Err(failure("record belongs to another owner team"));
|
|
137
|
-
}
|
|
138
|
-
return Ok(reopen(&record)?.path().to_path_buf());
|
|
139
|
-
}
|
|
140
|
-
let legacy = workspace
|
|
141
|
-
.join(".team/runtime/provider-config")
|
|
142
|
-
.join(agent_id)
|
|
143
|
-
.join("cursor");
|
|
144
|
-
match std::fs::symlink_metadata(&legacy) {
|
|
145
|
-
Ok(_) => return Err(failure("unrecorded legacy primary exists; preserve its cwd/SID and explicitly select a fresh seat")),
|
|
146
|
-
Err(e) if e.kind() == std::io::ErrorKind::NotFound => {}
|
|
147
|
-
Err(e) => return Err(failure(e)),
|
|
148
|
-
}
|
|
149
|
-
let path = planned_project(&workspace, agent_id)?;
|
|
150
|
-
let key = project_key(&workspace, agent_id);
|
|
151
|
-
let mut nonce = [0u8; 32];
|
|
152
|
-
std::fs::File::open("/dev/urandom")
|
|
153
|
-
.and_then(|mut f| f.read_exact(&mut nonce))
|
|
154
|
-
.map_err(failure)?;
|
|
155
|
-
let owner = InstanceIdentity {
|
|
156
|
-
scope: ScopeId::new(format!("legacy-cursor-{}", &key[..32])).map_err(failure)?,
|
|
157
|
-
seat: SeatId::new(format!("seat-{}", &key[32..])).map_err(failure)?,
|
|
158
|
-
instance: InstanceId::new(format!("cwd-{}", digest_hex(digest(&nonce))))
|
|
159
|
-
.map_err(failure)?,
|
|
160
|
-
generation: Generation(1),
|
|
161
|
-
};
|
|
162
|
-
let directory = ScopedDirectory::create(&path, owner).map_err(failure)?;
|
|
163
|
-
std::fs::DirBuilder::new()
|
|
164
|
-
.mode(0o700)
|
|
165
|
-
.create(path.join(".cursor"))
|
|
166
|
-
.map_err(failure)?;
|
|
167
|
-
link_workspace_rules(&workspace, &path.join(".cursor"))?;
|
|
168
|
-
let record = ProjectRecord {
|
|
169
|
-
workspace: workspace.clone(),
|
|
170
|
-
agent_id: agent_id.into(),
|
|
171
|
-
owner_team_id: owner_team_id.into(),
|
|
172
|
-
directory: directory.receipt().clone(),
|
|
173
|
-
};
|
|
174
|
-
let record_path = record_path(&workspace, agent_id);
|
|
175
|
-
let parent = record_path
|
|
176
|
-
.parent()
|
|
177
|
-
.ok_or_else(|| failure("missing record parent"))?;
|
|
178
|
-
std::fs::create_dir_all(parent).map_err(failure)?;
|
|
179
|
-
if parent.canonicalize().map_err(failure)? != parent {
|
|
180
|
-
return Err(failure("record parent is a symlink"));
|
|
181
|
-
}
|
|
182
|
-
let bytes = serde_json::to_vec(&record).map_err(failure)?;
|
|
183
|
-
let mut file = std::fs::OpenOptions::new()
|
|
184
|
-
.write(true)
|
|
185
|
-
.create_new(true)
|
|
186
|
-
.mode(0o600)
|
|
187
|
-
.custom_flags(libc::O_NOFOLLOW | libc::O_CLOEXEC)
|
|
188
|
-
.open(record_path)
|
|
189
|
-
.map_err(failure)?;
|
|
190
|
-
file.write_all(&bytes)
|
|
191
|
-
.and_then(|()| file.sync_all())
|
|
192
|
-
.map_err(failure)?;
|
|
193
|
-
directory.check_live().map_err(failure)?;
|
|
194
|
-
validate_cursor_mcp_project_root(&path)?;
|
|
195
|
-
Ok(path)
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
fn read_record(workspace: &Path, agent_id: &str) -> Result<Option<ProjectRecord>, LifecycleError> {
|
|
199
|
-
let path = record_path(workspace, agent_id);
|
|
200
|
-
let metadata = match std::fs::symlink_metadata(&path) {
|
|
201
|
-
Ok(metadata) => metadata,
|
|
202
|
-
Err(e) if e.kind() == std::io::ErrorKind::NotFound => return Ok(None),
|
|
203
|
-
Err(e) => return Err(failure(e)),
|
|
204
|
-
};
|
|
205
|
-
if !metadata.is_file()
|
|
206
|
-
|| metadata.file_type().is_symlink()
|
|
207
|
-
|| metadata.nlink() != 1
|
|
208
|
-
|| metadata.uid() != unsafe { libc::geteuid() }
|
|
209
|
-
|| metadata.mode() & 0o077 != 0
|
|
210
|
-
|| path.parent().and_then(|p| p.canonicalize().ok()).as_deref() != path.parent()
|
|
211
|
-
{
|
|
212
|
-
return Err(failure("unowned or aliased project record"));
|
|
213
|
-
}
|
|
214
|
-
let file = std::fs::OpenOptions::new()
|
|
215
|
-
.read(true)
|
|
216
|
-
.custom_flags(libc::O_NOFOLLOW | libc::O_CLOEXEC)
|
|
217
|
-
.open(&path)
|
|
218
|
-
.map_err(failure)?;
|
|
219
|
-
let opened = file.metadata().map_err(failure)?;
|
|
220
|
-
if opened.dev() != metadata.dev() || opened.ino() != metadata.ino() {
|
|
221
|
-
return Err(failure("project record replaced"));
|
|
222
|
-
}
|
|
223
|
-
let mut bytes = Vec::new();
|
|
224
|
-
file.take(65537).read_to_end(&mut bytes).map_err(failure)?;
|
|
225
|
-
if bytes.len() > 65536 {
|
|
226
|
-
return Err(failure("oversized project record"));
|
|
227
|
-
}
|
|
228
|
-
let record: ProjectRecord = serde_json::from_slice(&bytes).map_err(failure)?;
|
|
229
|
-
if record.workspace != workspace
|
|
230
|
-
|| record.agent_id != agent_id
|
|
231
|
-
|| record.owner_team_id.trim().is_empty()
|
|
232
|
-
{
|
|
233
|
-
return Err(failure("project record identity mismatch"));
|
|
234
|
-
}
|
|
235
|
-
Ok(Some(record))
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
fn reopen(record: &ProjectRecord) -> Result<ScopedDirectory, LifecycleError> {
|
|
239
|
-
let key = project_key(&record.workspace, &record.agent_id);
|
|
240
|
-
if record.directory.path.file_name().and_then(|n| n.to_str())
|
|
241
|
-
!= Some(format!("ta-cursor-{}", &key[..32]).as_str())
|
|
242
|
-
|| record.directory.owner.scope.as_str() != format!("legacy-cursor-{}", &key[..32])
|
|
243
|
-
|| record.directory.owner.seat.as_str() != format!("seat-{}", &key[32..])
|
|
244
|
-
|| record.directory.owner.generation != Generation(1)
|
|
245
|
-
{
|
|
246
|
-
return Err(failure("directory receipt identity mismatch"));
|
|
247
|
-
}
|
|
248
|
-
let directory = ScopedDirectory::reopen(record.directory.clone()).map_err(failure)?;
|
|
249
|
-
validate_cursor_mcp_project_root(directory.path())?;
|
|
250
|
-
let cursor = directory.path().join(".cursor");
|
|
251
|
-
let metadata = std::fs::symlink_metadata(&cursor).map_err(failure)?;
|
|
252
|
-
if !metadata.is_dir()
|
|
253
|
-
|| metadata.file_type().is_symlink()
|
|
254
|
-
|| metadata.uid() != unsafe { libc::geteuid() }
|
|
255
|
-
|| metadata.mode() & 0o077 != 0
|
|
256
|
-
{
|
|
257
|
-
return Err(failure("unowned .cursor directory"));
|
|
258
|
-
}
|
|
259
|
-
Ok(directory)
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
fn validate_agent_id(agent_id: &str) -> Result<(), LifecycleError> {
|
|
263
|
-
if agent_id.is_empty()
|
|
264
|
-
|| agent_id.contains("..")
|
|
265
|
-
|| !agent_id
|
|
266
|
-
.chars()
|
|
267
|
-
.all(|c| c.is_ascii_alphanumeric() || matches!(c, '.' | '_' | '-'))
|
|
268
|
-
{
|
|
269
|
-
return Err(failure(
|
|
270
|
-
"agent id must be a single path segment [A-Za-z0-9._-]+",
|
|
271
|
-
));
|
|
272
|
-
}
|
|
273
|
-
Ok(())
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
fn link_workspace_rules(workspace: &Path, dest_cursor: &Path) -> Result<(), LifecycleError> {
|
|
277
|
-
let source = workspace.join(".cursor/rules");
|
|
278
|
-
if source.exists() {
|
|
279
|
-
std::os::unix::fs::symlink(source, dest_cursor.join("rules")).map_err(failure)?;
|
|
280
|
-
}
|
|
281
|
-
Ok(())
|
|
282
|
-
}
|