@team-agent/installer 0.5.127 → 0.5.128
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Cargo.lock +1 -1
- package/Cargo.toml +1 -1
- package/README.md +11 -0
- package/crates/team-agent/src/cli/adapters.rs +3 -13
- package/crates/team-agent/src/cli/arguments.rs +4 -0
- package/crates/team-agent/src/cli/diagnose.rs +68 -22
- package/crates/team-agent/src/cli/emit.rs +58 -26
- package/crates/team-agent/src/cli/intent/runtime.rs +32 -5
- package/crates/team-agent/src/cli/intent/runtime_tests.rs +102 -11
- package/crates/team-agent/src/cli/intent/tests.rs +10 -12
- package/crates/team-agent/src/cli/intent.rs +1 -1
- package/crates/team-agent/src/cli/mod.rs +25 -8
- package/crates/team-agent/src/cli/models.rs +764 -7
- package/crates/team-agent/src/cli/schedule.rs +175 -0
- package/crates/team-agent/src/cli/send/persist.rs +0 -36
- package/crates/team-agent/src/cli/send/presentation.rs +1 -1
- package/crates/team-agent/src/cli/send.rs +108 -110
- package/crates/team-agent/src/cli/spec.rs +6 -0
- package/crates/team-agent/src/cli/status_port/brief.rs +5 -67
- package/crates/team-agent/src/cli/tests/leader_watch.rs +12 -62
- package/crates/team-agent/src/cli/tests/mod.rs +1 -1
- package/crates/team-agent/src/cli/tests/named_address.rs +11 -10
- package/crates/team-agent/src/cli/tests/run_delegation.rs +9 -6
- package/crates/team-agent/src/cli/tests/status_send.rs +68 -271
- package/crates/team-agent/src/compiler/tests.rs +3 -18
- package/crates/team-agent/src/compiler.rs +205 -6
- package/crates/team-agent/src/contract_runtime/backend.rs +145 -11
- package/crates/team-agent/src/contract_runtime/commands.rs +7 -7
- package/crates/team-agent/src/contract_runtime/config.rs +26 -16
- package/crates/team-agent/src/contract_runtime/config_tests.rs +24 -4
- package/crates/team-agent/src/contract_runtime/discovery.rs +12 -1
- package/crates/team-agent/src/contract_runtime/fork.rs +3 -10
- package/crates/team-agent/src/contract_runtime/framework.rs +28 -11
- package/crates/team-agent/src/contract_runtime/mcp.rs +19 -24
- package/crates/team-agent/src/contract_runtime/prompt.rs +2 -2
- package/crates/team-agent/src/contract_runtime/registry.rs +56 -92
- package/crates/team-agent/src/coordinator/steps/abnormal.rs +11 -11
- package/crates/team-agent/src/coordinator/tests/api_error_recovery.rs +16 -54
- package/crates/team-agent/src/coordinator/tests/health_sync.rs +42 -0
- package/crates/team-agent/src/coordinator/tick.rs +1 -89
- package/crates/team-agent/src/db/message_store.rs +7 -65
- package/crates/team-agent/src/direct_delivery.rs +368 -0
- package/crates/team-agent/src/inbox_store.rs +169 -0
- package/crates/team-agent/src/leader/registry.rs +5 -0
- package/crates/team-agent/src/leader/start.rs +2 -1
- package/crates/team-agent/src/leader/tests/lease_api.rs +2 -2
- package/crates/team-agent/src/leader/tests/prompt_contract.rs +1 -0
- package/crates/team-agent/src/lib.rs +2 -0
- package/crates/team-agent/src/lifecycle/launch/add_agent.rs +33 -0
- package/crates/team-agent/src/lifecycle/launch/add_agent_state.rs +206 -1
- package/crates/team-agent/src/lifecycle/launch/clone_agent.rs +28 -2
- package/crates/team-agent/src/lifecycle/launch/fork_agent.rs +38 -13
- package/crates/team-agent/src/lifecycle/launch/fork_entry.rs +87 -6
- package/crates/team-agent/src/lifecycle/launch/mcp_config.rs +9 -1
- package/crates/team-agent/src/lifecycle/launch/pi_mcp.rs +351 -81
- package/crates/team-agent/src/lifecycle/launch/pi_mcp_extension.js +3 -4
- package/crates/team-agent/src/lifecycle/launch/quick_start.rs +24 -0
- package/crates/team-agent/src/lifecycle/launch/spawn.rs +36 -13
- package/crates/team-agent/src/lifecycle/launch.rs +24 -1
- package/crates/team-agent/src/lifecycle/profile_launch.rs +321 -11
- package/crates/team-agent/src/lifecycle/restart/agent.rs +1 -0
- package/crates/team-agent/src/lifecycle/restart/avatar.rs +1798 -0
- package/crates/team-agent/src/lifecycle/restart/claude_fork.rs +163 -0
- package/crates/team-agent/src/lifecycle/restart/common.rs +345 -35
- package/crates/team-agent/src/lifecycle/restart/selection.rs +5 -5
- package/crates/team-agent/src/lifecycle/restart.rs +4 -0
- package/crates/team-agent/src/lifecycle/role_config.rs +39 -14
- package/crates/team-agent/src/lifecycle/tests/claude_compatible_config_red.rs +325 -0
- package/crates/team-agent/src/lifecycle/tests/claude_profile_launch_red.rs +320 -8
- package/crates/team-agent/src/lifecycle/tests/cli_argv_routing_red.rs +236 -13
- package/crates/team-agent/src/lifecycle/tests/clone_fork_copilot_perms_red.rs +378 -4
- package/crates/team-agent/src/lifecycle/tests/communication_mode_runtime_contract_red.rs +5 -4
- package/crates/team-agent/src/lifecycle/tests/copilot_provider_red.rs +7 -11
- package/crates/team-agent/src/lifecycle/tests/core.rs +47 -18
- package/crates/team-agent/src/lifecycle/tests/fixtures/pi_native_mcp_host.mjs +2 -1
- package/crates/team-agent/src/lifecycle/tests/grok_require_explicit_model_red.rs +14 -14
- package/crates/team-agent/src/lifecycle/tests/harvest2_a_batch_red.rs +60 -20
- package/crates/team-agent/src/lifecycle/tests/launch_spawn.rs +28 -26
- package/crates/team-agent/src/lifecycle/tests/mcp_tool_name_format_red.rs +6 -6
- package/crates/team-agent/src/lifecycle/tests/pi_catalog_red.rs +18 -6
- package/crates/team-agent/src/lifecycle/tests/pi_command_red.rs +70 -52
- package/crates/team-agent/src/lifecycle/tests/pi_compiler_red.rs +210 -0
- package/crates/team-agent/src/lifecycle/tests/pi_dual_entry_red.rs +157 -4
- package/crates/team-agent/src/lifecycle/tests/pi_executable_mcp_red.rs +526 -10
- package/crates/team-agent/src/lifecycle/tests/pi_fork_session_inheritance_red.rs +1419 -0
- package/crates/team-agent/src/lifecycle/tests/pi_lifecycle_doctor_red.rs +68 -1
- package/crates/team-agent/src/lifecycle/tests/pi_native_mcp_capability_red.rs +34 -12
- package/crates/team-agent/src/lifecycle/tests/pi_session_delivery_red.rs +94 -2
- package/crates/team-agent/src/lifecycle/tests/quick_start_worker_readiness_red.rs +10 -11
- 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 +254 -2
- 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 +5 -6
- package/crates/team-agent/src/lifecycle/tests/worker_spawn_env_red.rs +16 -7
- package/crates/team-agent/src/lifecycle/tests.rs +3 -0
- package/crates/team-agent/src/lifecycle/types.rs +18 -2
- package/crates/team-agent/src/lifecycle/worker_command_context.rs +43 -50
- package/crates/team-agent/src/mcp_server/readiness.rs +130 -149
- package/crates/team-agent/src/mcp_server/readiness_tests.rs +98 -119
- package/crates/team-agent/src/mcp_server/tests/scoped.rs +21 -31
- package/crates/team-agent/src/mcp_server/tests/send.rs +72 -107
- package/crates/team-agent/src/mcp_server/tests/tools.rs +10 -12
- package/crates/team-agent/src/mcp_server/tools.rs +70 -196
- package/crates/team-agent/src/messaging/delivery.rs +160 -218
- package/crates/team-agent/src/messaging/delivery_consumption_tests.rs +5 -5
- package/crates/team-agent/src/messaging/helpers.rs +1 -19
- package/crates/team-agent/src/messaging/mod.rs +1 -0
- package/crates/team-agent/src/messaging/reminders.rs +316 -0
- package/crates/team-agent/src/messaging/scheduler.rs +7 -1
- package/crates/team-agent/src/messaging/tests/dup_inject.rs +191 -85
- package/crates/team-agent/src/messaging/tests/runtime.rs +4 -110
- package/crates/team-agent/src/messaging/tests/spine.rs +40 -24
- package/crates/team-agent/src/messaging/types.rs +1 -0
- package/crates/team-agent/src/provider/adapter.rs +303 -51
- package/crates/team-agent/src/provider/adapters/claude.rs +78 -0
- package/crates/team-agent/src/provider/adapters/claude_fork.rs +131 -0
- package/crates/team-agent/src/provider/adapters/mod.rs +7 -5
- package/crates/team-agent/src/provider/adapters/pi.rs +106 -0
- package/crates/team-agent/src/provider/classify.rs +1 -66
- package/crates/team-agent/src/provider/model_catalog.rs +201 -13
- package/crates/team-agent/src/provider/session/capture.rs +106 -6
- package/crates/team-agent/src/provider/session/context_fork/claude.rs +123 -0
- package/crates/team-agent/src/provider/session/context_fork/outcome.rs +4 -0
- package/crates/team-agent/src/provider/session/context_fork.rs +150 -18
- package/crates/team-agent/src/provider/session_scan/claude.rs +523 -0
- package/crates/team-agent/src/provider/session_scan/common.rs +44 -8
- package/crates/team-agent/src/provider/session_scan/pi.rs +34 -1
- package/crates/team-agent/src/provider/session_scan.rs +16 -6
- package/crates/team-agent/src/provider/tests/adapter.rs +104 -17
- package/crates/team-agent/src/provider/tests/classify.rs +0 -53
- package/crates/team-agent/src/provider/tests/command_helpers.rs +12 -3
- package/crates/team-agent/src/provider/tests/idle.rs +37 -0
- package/crates/team-agent/src/provider/wire.rs +22 -34
- 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/projection.rs +1 -1
- package/crates/team-agent/src/state/repository/tests.rs +2 -2
- package/crates/team-agent/src/test_support/models_timeout_fixture.rs +144 -0
- package/crates/team-agent/src/tmux_backend/tests.rs +0 -151
- package/crates/team-agent/src/tmux_backend.rs +5 -40
- package/package.json +4 -4
- package/skills/team-agent/SKILL.md +5 -7
- package/skills/team-agent/command-coverage.json +1 -1
- package/skills/team-agent/docs/reference/team-agent-operator.md +3 -3
- package/skills/team-agent/references/team-agent-operator.md +3 -3
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
//!
|
|
2
|
-
//!
|
|
1
|
+
//! Flushed MCP handshakes are diagnostic evidence, not admission to pane input.
|
|
2
|
+
//! Each server owns a receipt; foreign writers cannot replace a live server's evidence.
|
|
3
3
|
|
|
4
4
|
use std::fs::{File, OpenOptions};
|
|
5
5
|
use std::io::{Read, Write};
|
|
6
6
|
use std::os::unix::fs::{DirBuilderExt, MetadataExt, OpenOptionsExt};
|
|
7
7
|
use std::path::{Path, PathBuf};
|
|
8
|
-
use std::time::Duration;
|
|
8
|
+
use std::time::{Duration, Instant};
|
|
9
9
|
|
|
10
10
|
use chrono::{DateTime, Utc};
|
|
11
11
|
use serde::{Deserialize, Serialize};
|
|
@@ -105,30 +105,38 @@ fn read_json(path: &Path, require_private: bool) -> Result<Value> {
|
|
|
105
105
|
serde_json::from_slice(&data).map_err(|_| "mcp_handshake_invalid")
|
|
106
106
|
}
|
|
107
107
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
}
|
|
113
|
-
entries
|
|
114
|
-
.flatten()
|
|
115
|
-
.filter_map(|entry| {
|
|
116
|
-
let file = entry.file_name().into_string().ok()?;
|
|
117
|
-
let rest = file.strip_prefix(name)?.strip_suffix(".json")?;
|
|
118
|
-
let per_server = rest
|
|
119
|
-
.strip_prefix('.')
|
|
120
|
-
.is_some_and(|pid| pid.parse::<u32>().is_ok());
|
|
121
|
-
(rest.is_empty() || per_server).then(|| entry.path())
|
|
122
|
-
})
|
|
123
|
-
.collect()
|
|
108
|
+
struct ReceiptLock(File);
|
|
109
|
+
impl Drop for ReceiptLock {
|
|
110
|
+
fn drop(&mut self) {
|
|
111
|
+
let _ = crate::platform::file_lock::unlock(&self.0);
|
|
112
|
+
}
|
|
124
113
|
}
|
|
125
114
|
|
|
126
|
-
fn
|
|
127
|
-
|
|
115
|
+
fn lock(path: &Path) -> Result<ReceiptLock> {
|
|
116
|
+
let file = OpenOptions::new()
|
|
117
|
+
.create(true)
|
|
118
|
+
.truncate(false)
|
|
119
|
+
.read(true)
|
|
120
|
+
.write(true)
|
|
121
|
+
.mode(0o600)
|
|
122
|
+
.custom_flags(libc::O_NOFOLLOW)
|
|
123
|
+
.open(path)
|
|
124
|
+
.map_err(|_| "mcp_handshake_lock")?;
|
|
125
|
+
private_metadata(path, false)?;
|
|
126
|
+
let start = Instant::now();
|
|
127
|
+
loop {
|
|
128
|
+
match crate::platform::file_lock::try_lock_once_nonblocking(&file) {
|
|
129
|
+
Ok(true) => return Ok(ReceiptLock(file)),
|
|
130
|
+
Ok(false) if start.elapsed() < Duration::from_millis(500) => {
|
|
131
|
+
std::thread::sleep(Duration::from_millis(10));
|
|
132
|
+
}
|
|
133
|
+
_ => return Err("mcp_handshake_lock"),
|
|
134
|
+
}
|
|
135
|
+
}
|
|
128
136
|
}
|
|
129
137
|
|
|
130
138
|
/// Only the actual stdio writer calls this after initialize and tools/list flush.
|
|
131
|
-
///
|
|
139
|
+
/// Publication failure affects readiness evidence only, not message delivery.
|
|
132
140
|
pub(crate) fn publish(
|
|
133
141
|
workspace: &Path,
|
|
134
142
|
owner: &str,
|
|
@@ -189,29 +197,31 @@ pub(crate) fn publish(
|
|
|
189
197
|
};
|
|
190
198
|
let dir = directory(&workspace, true)?;
|
|
191
199
|
let before = private_metadata(&dir, true)?;
|
|
192
|
-
let name = key(owner, agent);
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
let path = dir.join(format!("{name}.{}.json", std::process::id()));
|
|
200
|
+
let name = format!("{}.{}", key(owner, agent), std::process::id());
|
|
201
|
+
let path = dir.join(format!("{name}.json"));
|
|
202
|
+
let _lock = lock(&dir.join(format!("{name}.lock")))?;
|
|
196
203
|
match std::fs::symlink_metadata(&path) {
|
|
197
204
|
Ok(_) => {
|
|
198
|
-
|
|
205
|
+
let old: Handshake = serde_json::from_value(read_json(&path, true)?)
|
|
206
|
+
.map_err(|_| "mcp_handshake_invalid")?;
|
|
207
|
+
if old.workspace != workspace
|
|
208
|
+
|| old.owner != owner
|
|
209
|
+
|| old.agent != agent
|
|
210
|
+
|| old.schema != 1
|
|
211
|
+
{
|
|
212
|
+
return Err("mcp_handshake_scope_mismatch");
|
|
213
|
+
}
|
|
214
|
+
let old_started = DateTime::parse_from_rfc3339(&old.started_at)
|
|
215
|
+
.map_err(|_| "mcp_handshake_invalid")?;
|
|
216
|
+
if old.server.identity.birth_identity == receipt.server.identity.birth_identity
|
|
217
|
+
&& old_started > started_at
|
|
218
|
+
{
|
|
219
|
+
return Ok(());
|
|
220
|
+
}
|
|
199
221
|
}
|
|
200
222
|
Err(error) if error.kind() == std::io::ErrorKind::NotFound => {}
|
|
201
223
|
Err(_) => return Err("mcp_handshake_invalid"),
|
|
202
224
|
}
|
|
203
|
-
for sibling in receipt_paths(&dir, &name) {
|
|
204
|
-
let exited = sibling != path
|
|
205
|
-
&& read_receipt(&sibling).is_ok_and(|old| {
|
|
206
|
-
matches!(
|
|
207
|
-
sample_process(&old.server),
|
|
208
|
-
ProcessState::Exited | ProcessState::Replaced
|
|
209
|
-
)
|
|
210
|
-
});
|
|
211
|
-
if exited {
|
|
212
|
-
let _ = std::fs::remove_file(&sibling);
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
225
|
let temp = dir.join(format!(
|
|
216
226
|
"{name}.{}-{}.tmp",
|
|
217
227
|
std::process::id(),
|
|
@@ -239,23 +249,10 @@ pub(crate) fn publish(
|
|
|
239
249
|
})();
|
|
240
250
|
if result.is_err() {
|
|
241
251
|
let _ = std::fs::remove_file(&temp);
|
|
242
|
-
return result;
|
|
243
252
|
}
|
|
244
|
-
resume_parked(&workspace, owner, agent);
|
|
245
253
|
result
|
|
246
254
|
}
|
|
247
255
|
|
|
248
|
-
/// A fresh receipt resumes this seat's parked messages. A foreign server's
|
|
249
|
-
/// receipt only causes one cheap re-park: delivery re-runs full preflight.
|
|
250
|
-
fn resume_parked(workspace: &Path, owner: &str, agent: &str) {
|
|
251
|
-
if !workspace.join(".team/runtime/team.db").exists() {
|
|
252
|
-
return;
|
|
253
|
-
}
|
|
254
|
-
if let Ok(store) = crate::message_store::MessageStore::open(workspace) {
|
|
255
|
-
let _ = store.requeue_parked_deliveries(agent, owner);
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
|
|
259
256
|
#[derive(Debug)]
|
|
260
257
|
pub(crate) struct Admission {
|
|
261
258
|
server: ProcessStamp,
|
|
@@ -264,8 +261,7 @@ pub(crate) struct Admission {
|
|
|
264
261
|
pane_id: String,
|
|
265
262
|
}
|
|
266
263
|
|
|
267
|
-
///
|
|
268
|
-
/// perform no input; the delivery owner releases only its exact claim for retry.
|
|
264
|
+
/// Observe readiness without gating delivery. A bad candidate never hides a good one.
|
|
269
265
|
pub(crate) fn preflight(
|
|
270
266
|
workspace: &Path,
|
|
271
267
|
owner: Option<&str>,
|
|
@@ -298,11 +294,62 @@ pub(crate) fn preflight(
|
|
|
298
294
|
.canonicalize()
|
|
299
295
|
.map_err(|_| "mcp_handshake_workspace")?;
|
|
300
296
|
let dir = directory(&workspace, false)?;
|
|
297
|
+
let name = key(owner, agent_id);
|
|
298
|
+
// Older servers publish one slot per seat. Keep it readable during upgrades.
|
|
299
|
+
let mut paths = vec![dir.join(format!("{name}.json"))];
|
|
300
|
+
let prefix = format!("{name}.");
|
|
301
|
+
for entry in std::fs::read_dir(&dir).map_err(|_| "mcp_handshake_directory")? {
|
|
302
|
+
let entry = entry.map_err(|_| "mcp_handshake_directory")?;
|
|
303
|
+
let filename = entry.file_name();
|
|
304
|
+
let filename = filename.to_string_lossy();
|
|
305
|
+
if filename
|
|
306
|
+
.strip_prefix(&prefix)
|
|
307
|
+
.and_then(|suffix| suffix.strip_suffix(".json"))
|
|
308
|
+
.and_then(|pid| pid.parse::<u32>().ok())
|
|
309
|
+
.is_some()
|
|
310
|
+
{
|
|
311
|
+
paths.push(entry.path());
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
let mut error = "mcp_handshake_missing";
|
|
315
|
+
for path in paths {
|
|
316
|
+
match validate_receipt(&path, &workspace, owner, agent_id, agent, config) {
|
|
317
|
+
Ok(admission) => return Ok(Some(admission)),
|
|
318
|
+
Err(reason) => error = reason,
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
Err(error)
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
fn validate_receipt(
|
|
325
|
+
path: &Path,
|
|
326
|
+
workspace: &Path,
|
|
327
|
+
owner: &str,
|
|
328
|
+
agent_id: &str,
|
|
329
|
+
agent: &Value,
|
|
330
|
+
config: &str,
|
|
331
|
+
) -> Result<Admission> {
|
|
332
|
+
let receipt: Handshake =
|
|
333
|
+
serde_json::from_value(read_json(path, true)?).map_err(|_| "mcp_handshake_invalid")?;
|
|
334
|
+
if receipt.schema != 1
|
|
335
|
+
|| receipt.workspace != workspace
|
|
336
|
+
|| receipt.owner != owner
|
|
337
|
+
|| receipt.agent != agent_id
|
|
338
|
+
{
|
|
339
|
+
return Err("mcp_handshake_scope_mismatch");
|
|
340
|
+
}
|
|
301
341
|
let spawned_at = agent
|
|
302
342
|
.get("spawned_at")
|
|
303
343
|
.and_then(Value::as_str)
|
|
304
344
|
.and_then(|s| DateTime::parse_from_rfc3339(s).ok())
|
|
305
345
|
.ok_or("mcp_handshake_spawn_missing")?;
|
|
346
|
+
let started_at =
|
|
347
|
+
DateTime::parse_from_rfc3339(&receipt.started_at).map_err(|_| "mcp_handshake_invalid")?;
|
|
348
|
+
let flushed_at =
|
|
349
|
+
DateTime::parse_from_rfc3339(&receipt.flushed_at).map_err(|_| "mcp_handshake_invalid")?;
|
|
350
|
+
if started_at < spawned_at || flushed_at < started_at {
|
|
351
|
+
return Err("mcp_handshake_stale_spawn");
|
|
352
|
+
}
|
|
306
353
|
let expected_config = workspace
|
|
307
354
|
.join(".team/runtime/mcp")
|
|
308
355
|
.join(format!("{agent_id}.json"));
|
|
@@ -327,12 +374,14 @@ pub(crate) fn preflight(
|
|
|
327
374
|
.get("command")
|
|
328
375
|
.and_then(Value::as_str)
|
|
329
376
|
.ok_or("mcp_handshake_config_missing")?;
|
|
330
|
-
if !Path::new(expected).is_absolute()
|
|
377
|
+
if !Path::new(expected).is_absolute()
|
|
378
|
+
|| Path::new(expected)
|
|
379
|
+
.canonicalize()
|
|
380
|
+
.map_err(|_| "mcp_handshake_image")?
|
|
381
|
+
!= receipt.server.identity.executable
|
|
382
|
+
{
|
|
331
383
|
return Err("mcp_handshake_image");
|
|
332
384
|
}
|
|
333
|
-
let expected = Path::new(expected)
|
|
334
|
-
.canonicalize()
|
|
335
|
-
.map_err(|_| "mcp_handshake_image")?;
|
|
336
385
|
let env = server_config
|
|
337
386
|
.get("env")
|
|
338
387
|
.ok_or("mcp_handshake_config_missing")?;
|
|
@@ -342,8 +391,8 @@ pub(crate) fn preflight(
|
|
|
342
391
|
.get("TEAM_AGENT_WORKSPACE")
|
|
343
392
|
.and_then(Value::as_str)
|
|
344
393
|
.and_then(|s| Path::new(s).canonicalize().ok())
|
|
345
|
-
.
|
|
346
|
-
!= Some(
|
|
394
|
+
.as_deref()
|
|
395
|
+
!= Some(workspace)
|
|
347
396
|
{
|
|
348
397
|
return Err("mcp_handshake_config_scope");
|
|
349
398
|
}
|
|
@@ -359,99 +408,32 @@ pub(crate) fn preflight(
|
|
|
359
408
|
.ok_or("mcp_handshake_carrier_missing")?;
|
|
360
409
|
let carrier_birth =
|
|
361
410
|
process_birth_identity(carrier).map_err(|_| "mcp_handshake_carrier_missing")?;
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
411
|
+
if sample_process(&receipt.server) != ProcessState::Alive {
|
|
412
|
+
return Err("mcp_handshake_server_not_live");
|
|
413
|
+
}
|
|
414
|
+
let mut parent = receipt.server.parent;
|
|
415
|
+
let mut matched = false;
|
|
416
|
+
for ancestor in receipt.ancestors.iter().take(MAX_NATIVE_PARENT_HOPS) {
|
|
417
|
+
if ancestor.pid != parent
|
|
418
|
+
|| process_birth_identity(parent).ok().as_deref() != Some(ancestor.birth.as_str())
|
|
367
419
|
{
|
|
368
|
-
return Err("mcp_handshake_scope_mismatch");
|
|
369
|
-
}
|
|
370
|
-
let started_at = DateTime::parse_from_rfc3339(&receipt.started_at)
|
|
371
|
-
.map_err(|_| "mcp_handshake_invalid")?;
|
|
372
|
-
let flushed_at = DateTime::parse_from_rfc3339(&receipt.flushed_at)
|
|
373
|
-
.map_err(|_| "mcp_handshake_invalid")?;
|
|
374
|
-
if started_at < spawned_at || flushed_at < started_at {
|
|
375
|
-
return Err("mcp_handshake_stale_spawn");
|
|
376
|
-
}
|
|
377
|
-
if receipt.server.identity.executable != expected {
|
|
378
|
-
return Err("mcp_handshake_image");
|
|
379
|
-
}
|
|
380
|
-
if sample_process(&receipt.server) != ProcessState::Alive {
|
|
381
|
-
return Err("mcp_handshake_server_not_live");
|
|
382
|
-
}
|
|
383
|
-
let mut parent = receipt.server.parent;
|
|
384
|
-
let mut matched = false;
|
|
385
|
-
for ancestor in receipt.ancestors.iter().take(MAX_NATIVE_PARENT_HOPS) {
|
|
386
|
-
if ancestor.pid != parent
|
|
387
|
-
|| process_birth_identity(parent).ok().as_deref() != Some(ancestor.birth.as_str())
|
|
388
|
-
{
|
|
389
|
-
return Err("mcp_handshake_ancestry");
|
|
390
|
-
}
|
|
391
|
-
if parent == carrier {
|
|
392
|
-
matched = true;
|
|
393
|
-
break;
|
|
394
|
-
}
|
|
395
|
-
parent = crate::platform::argv::parent_pid(parent).unwrap_or(0);
|
|
396
|
-
}
|
|
397
|
-
if !matched || sample_process(&receipt.server) != ProcessState::Alive {
|
|
398
420
|
return Err("mcp_handshake_ancestry");
|
|
399
421
|
}
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
// Receipts of foreign servers (inherited identity, other process trees)
|
|
404
|
-
// are dropped before any process probe; they cannot mask the seat's own.
|
|
405
|
-
let mut receipts: Vec<_> = receipt_paths(&dir, &key(owner, agent_id))
|
|
406
|
-
.into_iter()
|
|
407
|
-
.map(|path| read_receipt(&path))
|
|
408
|
-
.collect();
|
|
409
|
-
receipts.sort_by_key(|receipt| {
|
|
410
|
-
std::cmp::Reverse(
|
|
411
|
-
receipt
|
|
412
|
-
.as_ref()
|
|
413
|
-
.ok()
|
|
414
|
-
.and_then(|r| DateTime::parse_from_rfc3339(&r.started_at).ok()),
|
|
415
|
-
)
|
|
416
|
-
});
|
|
417
|
-
let (mut own_refusal, mut refusal) = (None, None);
|
|
418
|
-
for receipt in receipts {
|
|
419
|
-
let receipt = match receipt {
|
|
420
|
-
Ok(receipt) => receipt,
|
|
421
|
-
Err(reason) => {
|
|
422
|
-
refusal = refusal.or(Some(reason));
|
|
423
|
-
continue;
|
|
424
|
-
}
|
|
425
|
-
};
|
|
426
|
-
if !receipt.ancestors.iter().any(|ancestor| ancestor.pid == carrier) {
|
|
427
|
-
refusal = refusal.or(Some("mcp_handshake_ancestry"));
|
|
428
|
-
continue;
|
|
429
|
-
}
|
|
430
|
-
match admit(&receipt) {
|
|
431
|
-
Ok(()) => {
|
|
432
|
-
return Ok(Some(Admission {
|
|
433
|
-
server: receipt.server,
|
|
434
|
-
carrier,
|
|
435
|
-
carrier_birth,
|
|
436
|
-
pane_id: pane_id.to_string(),
|
|
437
|
-
}))
|
|
438
|
-
}
|
|
439
|
-
Err(reason) => own_refusal = own_refusal.or(Some(reason)),
|
|
422
|
+
if parent == carrier {
|
|
423
|
+
matched = true;
|
|
424
|
+
break;
|
|
440
425
|
}
|
|
426
|
+
parent = crate::platform::argv::parent_pid(parent).unwrap_or(0);
|
|
441
427
|
}
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
.
|
|
450
|
-
|
|
451
|
-
crate::platform::argv::argv_tokens(*pid)
|
|
452
|
-
.is_some_and(|argv| argv.iter().any(|arg| arg == "mcp-server"))
|
|
453
|
-
})
|
|
454
|
-
.collect()
|
|
428
|
+
if !matched || sample_process(&receipt.server) != ProcessState::Alive {
|
|
429
|
+
return Err("mcp_handshake_ancestry");
|
|
430
|
+
}
|
|
431
|
+
Ok(Admission {
|
|
432
|
+
server: receipt.server,
|
|
433
|
+
carrier,
|
|
434
|
+
carrier_birth,
|
|
435
|
+
pane_id: pane_id.to_string(),
|
|
436
|
+
})
|
|
455
437
|
}
|
|
456
438
|
|
|
457
439
|
/// Recheck against the actual resolved target immediately before the input path.
|
|
@@ -529,7 +511,6 @@ pub(crate) fn test_ready_worker(
|
|
|
529
511
|
pane_pid: Some(carrier),
|
|
530
512
|
leader_env: Default::default(),
|
|
531
513
|
};
|
|
532
|
-
// Like delivery, a provider without a worker handshake gate has nothing to revalidate.
|
|
533
514
|
if let Some(admission) = preflight(&workspace, Some(owner), agent, state).unwrap() {
|
|
534
515
|
revalidate(
|
|
535
516
|
&admission,
|
|
@@ -66,27 +66,11 @@ impl Case {
|
|
|
66
66
|
}
|
|
67
67
|
|
|
68
68
|
fn path(&self) -> PathBuf {
|
|
69
|
-
self.
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
let name = key("owner", "worker");
|
|
75
|
-
let file = if suffix.is_empty() {
|
|
76
|
-
format!("{name}.json")
|
|
77
|
-
} else {
|
|
78
|
-
format!("{name}.{suffix}.json")
|
|
79
|
-
};
|
|
80
|
-
self.ws.join(".team/runtime/mcp-handshakes").join(file)
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
fn write_private(&self, path: &Path, value: &Value) {
|
|
84
|
-
std::fs::write(path, serde_json::to_vec(value).unwrap()).unwrap();
|
|
85
|
-
std::fs::set_permissions(path, std::fs::Permissions::from_mode(0o600)).unwrap();
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
fn receipt(&self) -> Value {
|
|
89
|
-
serde_json::from_slice(&std::fs::read(self.path()).unwrap()).unwrap()
|
|
69
|
+
self.ws.join(".team/runtime/mcp-handshakes").join(format!(
|
|
70
|
+
"{}.{}.json",
|
|
71
|
+
key("owner", "worker"),
|
|
72
|
+
std::process::id()
|
|
73
|
+
))
|
|
90
74
|
}
|
|
91
75
|
|
|
92
76
|
fn publish(&self) {
|
|
@@ -114,27 +98,29 @@ impl Drop for Case {
|
|
|
114
98
|
|
|
115
99
|
#[test]
|
|
116
100
|
fn issue345_missing_mcp_config_does_not_disable_eager_admission() {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
.
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
case.admission().is_err(),
|
|
125
|
-
"missing config cannot disable copilot admission"
|
|
126
|
-
);
|
|
127
|
-
for value in [Value::Null, json!(false), json!(""), json!(" ")] {
|
|
128
|
-
case.state["agents"]["worker"]["mcp_config"] = value;
|
|
101
|
+
for provider in ["copilot"] {
|
|
102
|
+
let mut case = Case::new();
|
|
103
|
+
case.state["agents"]["worker"]["provider"] = json!(provider);
|
|
104
|
+
case.state["agents"]["worker"]
|
|
105
|
+
.as_object_mut()
|
|
106
|
+
.unwrap()
|
|
107
|
+
.remove("mcp_config");
|
|
129
108
|
assert!(
|
|
130
109
|
case.admission().is_err(),
|
|
131
|
-
"
|
|
110
|
+
"missing config cannot disable {provider} admission"
|
|
132
111
|
);
|
|
112
|
+
for value in [Value::Null, json!(false), json!(""), json!(" ")] {
|
|
113
|
+
case.state["agents"]["worker"]["mcp_config"] = value;
|
|
114
|
+
assert!(
|
|
115
|
+
case.admission().is_err(),
|
|
116
|
+
"invalid config cannot disable {provider} admission"
|
|
117
|
+
);
|
|
118
|
+
}
|
|
133
119
|
}
|
|
134
120
|
}
|
|
135
121
|
|
|
136
122
|
#[test]
|
|
137
|
-
fn
|
|
123
|
+
fn missing_handshake_is_unready_then_a_live_scoped_receipt_is_recognized() {
|
|
138
124
|
let case = Case::new();
|
|
139
125
|
assert!(case.admission().is_err());
|
|
140
126
|
case.publish();
|
|
@@ -145,6 +131,68 @@ fn missing_handshake_defers_then_a_live_scoped_receipt_admits() {
|
|
|
145
131
|
revalidate(&admission, &case.target, &case.panes).unwrap();
|
|
146
132
|
}
|
|
147
133
|
|
|
134
|
+
#[test]
|
|
135
|
+
#[ignore = "subprocess helper for PID-isolated publication"]
|
|
136
|
+
fn issue372_child_publisher() {
|
|
137
|
+
let ws = PathBuf::from(std::env::var_os("ISSUE372_WORKSPACE").unwrap());
|
|
138
|
+
publish(&ws, "owner", "worker", Utc::now()).unwrap();
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
#[test]
|
|
142
|
+
fn issue372_child_publication_and_exit_cannot_clobber_live_server() {
|
|
143
|
+
let case = Case::new();
|
|
144
|
+
case.publish();
|
|
145
|
+
let original = std::fs::read(case.path()).unwrap();
|
|
146
|
+
let mut child = std::process::Command::new(std::env::current_exe().unwrap())
|
|
147
|
+
.args([
|
|
148
|
+
"--ignored",
|
|
149
|
+
"--exact",
|
|
150
|
+
"mcp_server::readiness::tests::issue372_child_publisher",
|
|
151
|
+
])
|
|
152
|
+
.env("ISSUE372_WORKSPACE", &case.ws)
|
|
153
|
+
.spawn()
|
|
154
|
+
.unwrap();
|
|
155
|
+
let child_path = case.path().parent().unwrap().join(format!(
|
|
156
|
+
"{}.{}.json",
|
|
157
|
+
key("owner", "worker"),
|
|
158
|
+
child.id()
|
|
159
|
+
));
|
|
160
|
+
assert!(child.wait().unwrap().success());
|
|
161
|
+
assert!(
|
|
162
|
+
child_path.is_file(),
|
|
163
|
+
"child must really publish its own receipt"
|
|
164
|
+
);
|
|
165
|
+
assert_eq!(std::fs::read(case.path()).unwrap(), original);
|
|
166
|
+
assert_eq!(
|
|
167
|
+
case.admission().unwrap().unwrap().server.identity.pid,
|
|
168
|
+
std::process::id()
|
|
169
|
+
);
|
|
170
|
+
// A dead foreign writer in the old shared slot cannot hide the live receipt either.
|
|
171
|
+
let legacy = case
|
|
172
|
+
.path()
|
|
173
|
+
.parent()
|
|
174
|
+
.unwrap()
|
|
175
|
+
.join(format!("{}.json", key("owner", "worker")));
|
|
176
|
+
std::fs::copy(&child_path, &legacy).unwrap();
|
|
177
|
+
assert!(case.admission().unwrap().is_some());
|
|
178
|
+
std::fs::write(child_path, b"{broken").unwrap();
|
|
179
|
+
std::fs::write(legacy, b"{broken").unwrap();
|
|
180
|
+
assert!(case.admission().unwrap().is_some());
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
#[test]
|
|
184
|
+
fn issue372_live_legacy_receipt_is_still_recognized() {
|
|
185
|
+
let case = Case::new();
|
|
186
|
+
case.publish();
|
|
187
|
+
let legacy = case
|
|
188
|
+
.path()
|
|
189
|
+
.parent()
|
|
190
|
+
.unwrap()
|
|
191
|
+
.join(format!("{}.json", key("owner", "worker")));
|
|
192
|
+
std::fs::rename(case.path(), &legacy).unwrap();
|
|
193
|
+
assert!(case.admission().unwrap().is_some());
|
|
194
|
+
}
|
|
195
|
+
|
|
148
196
|
#[test]
|
|
149
197
|
fn receipt_cannot_cross_workspace_owner_or_seat() {
|
|
150
198
|
let case = Case::new();
|
|
@@ -209,102 +257,33 @@ fn changed_current_target_and_new_spawn_do_not_reuse_a_handshake() {
|
|
|
209
257
|
assert!(case.admission().is_err());
|
|
210
258
|
}
|
|
211
259
|
|
|
212
|
-
// Receipt pids beyond any real pid_max, so they never collide with this test.
|
|
213
|
-
const EXITED: &str = "4000000001";
|
|
214
|
-
const FOREIGN: &str = "4000000002";
|
|
215
|
-
|
|
216
|
-
/// A server outside the seat pane (inherited TEAM_AGENT_ID) or an exited one
|
|
217
|
-
/// may hold a newer receipt; neither can mask the seat's live server (#372).
|
|
218
|
-
fn foreign_and_exited(case: &Case) -> (Value, Value) {
|
|
219
|
-
let newer = (case.started + chrono::Duration::seconds(5)).to_rfc3339();
|
|
220
|
-
let mut foreign = case.receipt();
|
|
221
|
-
foreign["started_at"] = json!(newer);
|
|
222
|
-
foreign["flushed_at"] = json!(newer);
|
|
223
|
-
foreign["ancestors"] = json!([{"pid": 1_000_000_001_u32, "birth": "fixture-tmux"}]);
|
|
224
|
-
let mut exited = case.receipt();
|
|
225
|
-
exited["started_at"] = json!(newer);
|
|
226
|
-
exited["flushed_at"] = json!(newer);
|
|
227
|
-
exited["server"]["identity"]["birth_identity"] = json!("exited-server");
|
|
228
|
-
(foreign, exited)
|
|
229
|
-
}
|
|
230
|
-
|
|
231
260
|
#[test]
|
|
232
|
-
fn
|
|
261
|
+
fn older_helper_cannot_overwrite_a_newer_handshake() {
|
|
233
262
|
let case = Case::new();
|
|
234
263
|
case.publish();
|
|
235
|
-
let
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
assert_eq!(case.
|
|
244
|
-
std::fs::remove_file(case.sibling(EXITED)).unwrap();
|
|
245
|
-
assert_eq!(case.admission().unwrap_err(), "mcp_handshake_ancestry");
|
|
246
|
-
std::fs::remove_file(case.sibling(FOREIGN)).unwrap();
|
|
247
|
-
assert_eq!(case.admission().unwrap_err(), "mcp_handshake_missing");
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
#[test]
|
|
251
|
-
fn issue372_pre_upgrade_single_slot_receipt_still_admits() {
|
|
252
|
-
let case = Case::new();
|
|
253
|
-
case.publish();
|
|
254
|
-
std::fs::rename(case.path(), case.sibling("")).unwrap();
|
|
255
|
-
assert!(case.admission().unwrap().is_some());
|
|
264
|
+
let original = std::fs::read(case.path()).unwrap();
|
|
265
|
+
publish(
|
|
266
|
+
&case.ws,
|
|
267
|
+
"owner",
|
|
268
|
+
"worker",
|
|
269
|
+
case.started - chrono::Duration::seconds(1),
|
|
270
|
+
)
|
|
271
|
+
.unwrap();
|
|
272
|
+
assert_eq!(std::fs::read(case.path()).unwrap(), original);
|
|
256
273
|
}
|
|
257
274
|
|
|
258
275
|
#[test]
|
|
259
|
-
fn
|
|
276
|
+
fn issue372_reused_pid_can_replace_an_older_process_receipt() {
|
|
260
277
|
let case = Case::new();
|
|
261
278
|
case.publish();
|
|
262
|
-
let
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
279
|
+
let mut receipt = read_json(&case.path(), true).unwrap();
|
|
280
|
+
receipt["server"]["identity"]["birth_identity"] = json!("previous-process");
|
|
281
|
+
receipt["started_at"] = json!((Utc::now() + chrono::Duration::hours(1)).to_rfc3339());
|
|
282
|
+
std::fs::write(case.path(), serde_json::to_vec(&receipt).unwrap()).unwrap();
|
|
266
283
|
case.publish();
|
|
267
|
-
assert!(!case.sibling("").exists());
|
|
268
|
-
assert!(!case.sibling(EXITED).exists());
|
|
269
|
-
assert!(case.sibling(FOREIGN).exists(), "a live foreign receipt is only ignored");
|
|
270
284
|
assert!(case.admission().unwrap().is_some());
|
|
271
285
|
}
|
|
272
286
|
|
|
273
|
-
#[test]
|
|
274
|
-
fn issue372_publish_resumes_only_this_seats_parked_messages() {
|
|
275
|
-
let case = Case::new();
|
|
276
|
-
let store = crate::message_store::MessageStore::open(&case.ws).unwrap();
|
|
277
|
-
let parked = store
|
|
278
|
-
.create_message(None, "leader", "worker", "parked", None, false, Some("owner"))
|
|
279
|
-
.unwrap();
|
|
280
|
-
let other = store
|
|
281
|
-
.create_message(None, "leader", "worker", "other team", None, false, Some("other"))
|
|
282
|
-
.unwrap();
|
|
283
|
-
for id in [&parked, &other] {
|
|
284
|
-
assert!(store.claim_for_delivery(id).unwrap());
|
|
285
|
-
assert!(store.park_delivery_before_input(id, 1).unwrap());
|
|
286
|
-
}
|
|
287
|
-
case.publish();
|
|
288
|
-
let row = |id: &str| -> (String, Option<String>) {
|
|
289
|
-
rusqlite::Connection::open(store.db_path())
|
|
290
|
-
.unwrap()
|
|
291
|
-
.query_row(
|
|
292
|
-
"select status, error from messages where message_id = ?1",
|
|
293
|
-
[id],
|
|
294
|
-
|r| Ok((r.get(0)?, r.get(1)?)),
|
|
295
|
-
)
|
|
296
|
-
.unwrap()
|
|
297
|
-
};
|
|
298
|
-
assert_eq!(row(parked.as_str()), ("accepted".to_string(), None));
|
|
299
|
-
assert_eq!(
|
|
300
|
-
row(other.as_str()),
|
|
301
|
-
(
|
|
302
|
-
"queued_until_start".to_string(),
|
|
303
|
-
Some("mcp_handshake_timeout".to_string())
|
|
304
|
-
)
|
|
305
|
-
);
|
|
306
|
-
}
|
|
307
|
-
|
|
308
287
|
#[test]
|
|
309
288
|
fn symlink_and_writable_evidence_are_not_adopted_or_overwritten() {
|
|
310
289
|
let case = Case::new();
|