@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.
- 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 +30 -54
- package/crates/team-agent/src/cli/intent/runtime_tests.rs +59 -118
- 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 +93 -128
- 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 +30 -6
- package/crates/team-agent/src/contract_runtime/config.rs +34 -24
- package/crates/team-agent/src/contract_runtime/discovery.rs +79 -56
- package/crates/team-agent/src/contract_runtime/framework.rs +89 -34
- package/crates/team-agent/src/contract_runtime/registry.rs +299 -24
- 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/pi_mcp.rs +19 -101
- 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 +43 -13
- package/crates/team-agent/src/lifecycle/tests/clone_fork_copilot_perms_red.rs +6 -2
- package/crates/team-agent/src/lifecycle/tests/pi_catalog_red.rs +1 -3
- package/crates/team-agent/src/lifecycle/tests/pi_command_red.rs +4 -16
- package/crates/team-agent/src/lifecycle/tests/pi_compiler_red.rs +1 -3
- package/crates/team-agent/src/lifecycle/tests/pi_executable_mcp_red.rs +84 -53
- package/crates/team-agent/src/lifecycle/tests/pi_fork_session_inheritance_red.rs +19 -1
- package/crates/team-agent/src/lifecycle/tests/pi_session_delivery_red.rs +21 -0
- 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 +186 -38
- 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/adapters/pi.rs +4 -4
- 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/pi.rs +32 -19
- 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 +3 -6
- 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/npm/install.mjs +40 -3
- 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
|
@@ -87,6 +87,9 @@ pub struct NotificationClaimParams<'a> {
|
|
|
87
87
|
pub pane_id: Option<&'a str>,
|
|
88
88
|
}
|
|
89
89
|
|
|
90
|
+
/// Error of a row parked by [`MessageStore::park_delivery_before_input`] (#372).
|
|
91
|
+
pub(crate) const MCP_HANDSHAKE_TIMEOUT: &str = "mcp_handshake_timeout";
|
|
92
|
+
|
|
90
93
|
/// Canonical initial message-row statuses shared by persistence, presentation,
|
|
91
94
|
/// claiming and recovery. New durable dispositions must be added here first.
|
|
92
95
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
|
@@ -609,6 +612,46 @@ impl MessageStore {
|
|
|
609
612
|
Ok(rows == 1)
|
|
610
613
|
}
|
|
611
614
|
|
|
615
|
+
/// Park an owned pre-input claim whose readiness wait reached its bound.
|
|
616
|
+
/// `queued_until_start` is claimable but never polled by `deliver_pending`;
|
|
617
|
+
/// only [`Self::requeue_parked_deliveries`] or a seat restart resumes it.
|
|
618
|
+
pub(crate) fn park_delivery_before_input(
|
|
619
|
+
&self,
|
|
620
|
+
message_id: &str,
|
|
621
|
+
attempt: u32,
|
|
622
|
+
) -> Result<bool, MessageStoreError> {
|
|
623
|
+
if attempt == 0 {
|
|
624
|
+
return Ok(false);
|
|
625
|
+
}
|
|
626
|
+
let conn = crate::db::schema::open_db(&self.path)?;
|
|
627
|
+
let rows = conn.execute(
|
|
628
|
+
"update messages
|
|
629
|
+
set status = 'queued_until_start',
|
|
630
|
+
delivery_attempts = delivery_attempts - 1,
|
|
631
|
+
error = ?3, updated_at = ?4
|
|
632
|
+
where message_id = ?1 and status = 'target_resolved'
|
|
633
|
+
and error is null and delivery_attempts = ?2",
|
|
634
|
+
params![message_id, attempt, MCP_HANDSHAKE_TIMEOUT, now_ts()],
|
|
635
|
+
)?;
|
|
636
|
+
Ok(rows == 1)
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
/// Return one seat's parked rows to the normal delivery queue.
|
|
640
|
+
pub(crate) fn requeue_parked_deliveries(
|
|
641
|
+
&self,
|
|
642
|
+
recipient: &str,
|
|
643
|
+
owner_team_id: &str,
|
|
644
|
+
) -> Result<usize, MessageStoreError> {
|
|
645
|
+
let conn = crate::db::schema::open_db(&self.path)?;
|
|
646
|
+
Ok(conn.execute(
|
|
647
|
+
"update messages
|
|
648
|
+
set status = 'accepted', error = null, updated_at = ?4
|
|
649
|
+
where recipient = ?1 and status = 'queued_until_start' and error = ?3
|
|
650
|
+
and (owner_team_id = ?2 or owner_team_id is null)",
|
|
651
|
+
params![recipient, owner_team_id, MCP_HANDSHAKE_TIMEOUT, now_ts()],
|
|
652
|
+
)?)
|
|
653
|
+
}
|
|
654
|
+
|
|
612
655
|
/// Read inbox rows through [`Self::inbox`]; recovery transitions below are
|
|
613
656
|
/// separate repository owners and are not claim eligibility.
|
|
614
657
|
pub fn requeue_blocked_leader_messages(
|
|
@@ -657,8 +700,8 @@ impl MessageStore {
|
|
|
657
700
|
let mut stmt = tx.prepare(
|
|
658
701
|
"select message_id from messages
|
|
659
702
|
where recipient = ?1
|
|
660
|
-
and status = ?2
|
|
661
|
-
|
|
703
|
+
and ((status = ?2 and error = 'tmux_target_missing')
|
|
704
|
+
or (status = 'queued_until_start' and error = ?4))
|
|
662
705
|
and (
|
|
663
706
|
(?3 is null and owner_team_id is null)
|
|
664
707
|
or owner_team_id = ?3
|
|
@@ -670,7 +713,8 @@ impl MessageStore {
|
|
|
670
713
|
params![
|
|
671
714
|
agent_id,
|
|
672
715
|
MessageRowStatus::QueuedPaneMissing.as_str(),
|
|
673
|
-
owner_team_id
|
|
716
|
+
owner_team_id,
|
|
717
|
+
MCP_HANDSHAKE_TIMEOUT
|
|
674
718
|
],
|
|
675
719
|
|row| row.get::<_, String>(0),
|
|
676
720
|
)?
|
|
@@ -1233,6 +1277,37 @@ mod tests {
|
|
|
1233
1277
|
}
|
|
1234
1278
|
}
|
|
1235
1279
|
|
|
1280
|
+
#[test]
|
|
1281
|
+
fn issue372_parked_handshake_claim_is_exact_and_resumes_per_seat() {
|
|
1282
|
+
let s = store();
|
|
1283
|
+
let mid = s.create_message(Some("t"), "s", "r", "c", None, true, Some("team-a")).unwrap();
|
|
1284
|
+
assert!(!s.park_delivery_before_input(&mid, 1).unwrap(), "unclaimed rows never park");
|
|
1285
|
+
assert!(s.claim_for_delivery(&mid).unwrap());
|
|
1286
|
+
assert!(!s.park_delivery_before_input(&mid, 2).unwrap(), "a stale claim cannot park");
|
|
1287
|
+
assert!(s.park_delivery_before_input(&mid, 1).unwrap());
|
|
1288
|
+
assert!(!s.park_delivery_before_input(&mid, 1).unwrap(), "single winner");
|
|
1289
|
+
let c = read(&s);
|
|
1290
|
+
assert_eq!(status_of(&c, &mid), "queued_until_start");
|
|
1291
|
+
assert_eq!(col_str(&c, &mid, "error").as_deref(), Some(MCP_HANDSHAKE_TIMEOUT));
|
|
1292
|
+
assert_eq!(col_i64(&c, &mid, "delivery_attempts"), 0, "waiting spends no input attempt");
|
|
1293
|
+
assert_eq!(s.requeue_parked_deliveries("other", "team-a").unwrap(), 0);
|
|
1294
|
+
assert_eq!(s.requeue_parked_deliveries("r", "team-b").unwrap(), 0);
|
|
1295
|
+
assert_eq!(s.requeue_parked_deliveries("r", "team-a").unwrap(), 1);
|
|
1296
|
+
let c = read(&s);
|
|
1297
|
+
assert_eq!(status_of(&c, &mid), "accepted");
|
|
1298
|
+
assert_eq!(col_str(&c, &mid, "error"), None);
|
|
1299
|
+
}
|
|
1300
|
+
|
|
1301
|
+
#[test]
|
|
1302
|
+
fn issue372_seat_restart_also_resumes_parked_handshake_rows() {
|
|
1303
|
+
let s = store();
|
|
1304
|
+
let mid = s.create_message(Some("t"), "s", "r", "c", None, true, Some("team-a")).unwrap();
|
|
1305
|
+
assert!(s.claim_for_delivery(&mid).unwrap());
|
|
1306
|
+
assert!(s.park_delivery_before_input(&mid, 1).unwrap());
|
|
1307
|
+
assert_eq!(s.recover_worker_pane_available("r", Some("team-a")).unwrap(), vec![mid.clone()]);
|
|
1308
|
+
assert_eq!(status_of(&read(&s), &mid), "accepted");
|
|
1309
|
+
}
|
|
1310
|
+
|
|
1236
1311
|
#[test]
|
|
1237
1312
|
fn claim_for_delivery_never_claims_stored_only_presentation() {
|
|
1238
1313
|
let s = store();
|
|
@@ -442,7 +442,7 @@ pub(crate) fn inject(
|
|
|
442
442
|
Some(path),
|
|
443
443
|
)
|
|
444
444
|
.for_provider(provider);
|
|
445
|
-
error.action = "Use pi, claude, codex or grok, or clear leader-prompt
|
|
445
|
+
error.action = "Use pi, claude, codex or grok, or clear leader-prompt";
|
|
446
446
|
return Err(error);
|
|
447
447
|
}
|
|
448
448
|
};
|
|
@@ -890,7 +890,6 @@ mod tests {
|
|
|
890
890
|
fn leader_prompt_unadmitted_providers_fail_without_argv_mutation() {
|
|
891
891
|
let path = Path::new("/home/example/.team-agent/leader-prompt.txt");
|
|
892
892
|
for provider in [
|
|
893
|
-
Provider::CursorAgent,
|
|
894
893
|
Provider::Copilot,
|
|
895
894
|
Provider::GeminiCli,
|
|
896
895
|
Provider::Fake,
|
|
@@ -18,10 +18,6 @@ const COMMAND_GRAMMAR_PROVIDER_COMMANDS: &[(&str, Provider)] = &[
|
|
|
18
18
|
("copilot", Provider::Copilot),
|
|
19
19
|
("gemini", Provider::GeminiCli),
|
|
20
20
|
("grok", Provider::Grok),
|
|
21
|
-
// NOTE: Cursor `agent` binary is NOT added here — command-text attribution
|
|
22
|
-
// is a substring contains() match in table order; `"agent"` would also
|
|
23
|
-
// match the framework's own `team-agent` binary and mis-attribute leader
|
|
24
|
-
// panes. CursorAgent panes need env/argv-based attribution (TODO 0.5.67).
|
|
25
21
|
("fake", Provider::Fake),
|
|
26
22
|
];
|
|
27
23
|
|
|
@@ -99,9 +95,6 @@ fn provider_from_command_text(text: &str) -> Option<Provider> {
|
|
|
99
95
|
if pi_command_text(&lower) {
|
|
100
96
|
return Some(Provider::Pi);
|
|
101
97
|
}
|
|
102
|
-
if cursor_agent_command_text(&lower) {
|
|
103
|
-
return Some(Provider::CursorAgent);
|
|
104
|
-
}
|
|
105
98
|
COMMAND_GRAMMAR_PROVIDER_COMMANDS
|
|
106
99
|
.iter()
|
|
107
100
|
.find_map(|(needle, provider)| lower.contains(needle).then_some(*provider))
|
|
@@ -119,29 +112,6 @@ fn pi_command_text(lower: &str) -> bool {
|
|
|
119
112
|
})
|
|
120
113
|
}
|
|
121
114
|
|
|
122
|
-
/// Cursor 二进制名为 `agent`,不能做 substring contains(会误伤 `team-agent`)。
|
|
123
|
-
/// 认精确 token `cursor-agent` / `…/agent`,且必须带 `--sandbox` 或 `--trust`。
|
|
124
|
-
fn cursor_agent_command_text(lower: &str) -> bool {
|
|
125
|
-
let tokens: Vec<&str> = lower.split_whitespace().collect();
|
|
126
|
-
if tokens.iter().any(|tok| {
|
|
127
|
-
*tok == "team-agent"
|
|
128
|
-
|| tok.ends_with("/team-agent")
|
|
129
|
-
|| tok.ends_with("\\team-agent")
|
|
130
|
-
}) {
|
|
131
|
-
return false;
|
|
132
|
-
}
|
|
133
|
-
let is_cursor_bin = tokens.iter().any(|tok| {
|
|
134
|
-
*tok == "cursor-agent"
|
|
135
|
-
|| *tok == "agent"
|
|
136
|
-
|| tok.ends_with("/cursor-agent")
|
|
137
|
-
|| tok.ends_with("/agent")
|
|
138
|
-
|| tok.ends_with("\\cursor-agent")
|
|
139
|
-
|| tok.ends_with("\\agent")
|
|
140
|
-
});
|
|
141
|
-
let has_cursor_flag = tokens.iter().any(|tok| *tok == "--sandbox" || *tok == "--trust");
|
|
142
|
-
is_cursor_bin && has_cursor_flag
|
|
143
|
-
}
|
|
144
|
-
|
|
145
115
|
fn provider_from_env_text(text: &str) -> Option<Provider> {
|
|
146
116
|
text.split(|ch: char| ch == '\0' || ch.is_ascii_whitespace())
|
|
147
117
|
.find_map(|part| part.strip_prefix("TEAM_AGENT_LEADER_PROVIDER="))
|
|
@@ -236,28 +206,6 @@ mod tests {
|
|
|
236
206
|
);
|
|
237
207
|
}
|
|
238
208
|
|
|
239
|
-
#[test]
|
|
240
|
-
fn cursor_agent_basename_with_trust_is_attributed() {
|
|
241
|
-
assert_eq!(
|
|
242
|
-
attribute_command_provider("cursor-agent --trust --sandbox disabled --workspace /ws"),
|
|
243
|
-
Some(Provider::CursorAgent)
|
|
244
|
-
);
|
|
245
|
-
assert_eq!(
|
|
246
|
-
attribute_command_provider("agent --trust --sandbox disabled --workspace /ws"),
|
|
247
|
-
Some(Provider::CursorAgent)
|
|
248
|
-
);
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
#[test]
|
|
252
|
-
fn team_agent_binary_is_not_cursor() {
|
|
253
|
-
assert_ne!(
|
|
254
|
-
attribute_command_provider("team-agent --trust claude"),
|
|
255
|
-
Some(Provider::CursorAgent)
|
|
256
|
-
);
|
|
257
|
-
assert_eq!(attribute_command_provider("team-agent status"), None);
|
|
258
|
-
assert_eq!(attribute_command_provider("agent"), None);
|
|
259
|
-
}
|
|
260
|
-
|
|
261
209
|
#[test]
|
|
262
210
|
fn pane_env_provider_wins_over_command() {
|
|
263
211
|
let mut pane = pane("codex", None);
|
|
@@ -2951,7 +2951,6 @@ fn provider_command_name(provider: Provider) -> &'static str {
|
|
|
2951
2951
|
Provider::Copilot => "copilot",
|
|
2952
2952
|
Provider::GeminiCli => "gemini",
|
|
2953
2953
|
Provider::Grok => "grok",
|
|
2954
|
-
Provider::CursorAgent => "agent",
|
|
2955
2954
|
Provider::Pi => "pi",
|
|
2956
2955
|
Provider::Fake => "fake",
|
|
2957
2956
|
}
|
|
@@ -112,7 +112,7 @@ fn leader_prompt_plans_preserve_absent_baseline_append_only_leaders_and_never_ma
|
|
|
112
112
|
let _routing = h.with_env("TEAM_AGENT_CLI_ARGV_ROUTING", "off");
|
|
113
113
|
let config = crate::leader::prompt::config_path().unwrap();
|
|
114
114
|
let providers = [Provider::Pi, Provider::Claude, Provider::ClaudeCode, Provider::Codex,
|
|
115
|
-
Provider::Grok, Provider::
|
|
115
|
+
Provider::Grok, Provider::Copilot];
|
|
116
116
|
for provider in providers {
|
|
117
117
|
let workspace = h.workspace(&format!("provider-{}", crate::provider::wire::provider_wire(provider)));
|
|
118
118
|
let baseline = plan(provider, &workspace, &[], false).unwrap();
|
|
@@ -122,7 +122,7 @@ fn leader_prompt_plans_preserve_absent_baseline_append_only_leaders_and_never_ma
|
|
|
122
122
|
assert_eq!(stable_argv(&empty), stable_argv(&baseline), "empty configuration changed argv for {provider:?}");
|
|
123
123
|
assert_eq!(empty.leader_env, baseline.leader_env);
|
|
124
124
|
fs::write(&config, SENTINEL).unwrap();
|
|
125
|
-
if matches!(provider, Provider::
|
|
125
|
+
if matches!(provider, Provider::Copilot) {
|
|
126
126
|
let LeaderError::Prompt(error) = plan(provider, &workspace, &[], false).unwrap_err() else { panic!("typed unsupported") };
|
|
127
127
|
assert_eq!(error.reason, "leader_prompt_unsupported");
|
|
128
128
|
} else {
|
|
@@ -177,7 +177,6 @@ fn leader_prompt_attach_skips_corrupt_configuration_and_all_injection_for_every_
|
|
|
177
177
|
Provider::ClaudeCode,
|
|
178
178
|
Provider::Codex,
|
|
179
179
|
Provider::Grok,
|
|
180
|
-
Provider::CursorAgent,
|
|
181
180
|
Provider::Copilot,
|
|
182
181
|
] {
|
|
183
182
|
let workspace = h.workspace(&format!("attach-{provider:?}"));
|
|
@@ -632,6 +632,14 @@ fn add_agent_with_transport_at_paths_reserved(
|
|
|
632
632
|
compiled.id, agent_id
|
|
633
633
|
)));
|
|
634
634
|
}
|
|
635
|
+
// The compiled spec carries a contract leaf's canonical id (`agent` → `cursor`).
|
|
636
|
+
#[cfg(unix)]
|
|
637
|
+
let contract_provider = compiled
|
|
638
|
+
.agent
|
|
639
|
+
.get("provider")
|
|
640
|
+
.and_then(Value::as_str)
|
|
641
|
+
.filter(|provider| crate::contract_runtime::registry::descriptor(provider).is_some())
|
|
642
|
+
.map(str::to_owned);
|
|
635
643
|
let compiled_agent = compiled.agent.clone();
|
|
636
644
|
inject_agent_into_spec(&mut spec, compiled_agent.clone(), &compiled.id)?;
|
|
637
645
|
// E5 spec 迁移:重编译的 spec 原子写到 .team/runtime/<team_key>/(不落用户目录 team_dir)。
|
|
@@ -666,6 +674,20 @@ fn add_agent_with_transport_at_paths_reserved(
|
|
|
666
674
|
inject_agent_into_spec(&mut latest_spec, compiled_agent, &compiled.id)?;
|
|
667
675
|
write_spec_atomic(&spec_path, &latest_spec)?;
|
|
668
676
|
drop(reservation_lock);
|
|
677
|
+
#[cfg(unix)]
|
|
678
|
+
if let Some(provider) = contract_provider {
|
|
679
|
+
return add_contract_seat(
|
|
680
|
+
run_workspace,
|
|
681
|
+
team_dir,
|
|
682
|
+
&spec_path,
|
|
683
|
+
pre_spec_text.as_deref(),
|
|
684
|
+
&canonical_team_key,
|
|
685
|
+
agent_id,
|
|
686
|
+
&provider,
|
|
687
|
+
role_file_path,
|
|
688
|
+
reservation,
|
|
689
|
+
);
|
|
690
|
+
}
|
|
669
691
|
let (meta, _) = crate::compiler::read_front_matter(role_file_path)
|
|
670
692
|
.map_err(|e| LifecycleError::Compile(e.to_string()))?;
|
|
671
693
|
// upsert writes status="starting" (E42) — start_agent_at_paths::mark_agent_started
|
|
@@ -755,3 +777,72 @@ fn add_agent_with_transport_at_paths_reserved(
|
|
|
755
777
|
role_file: role_file_path.to_path_buf(),
|
|
756
778
|
})
|
|
757
779
|
}
|
|
780
|
+
|
|
781
|
+
/// A contract seat starts in the native framework, never the legacy transport:
|
|
782
|
+
/// the seeded row is what the framework's start/publish path projects onto.
|
|
783
|
+
/// Its role must live in `<team_dir>/agents`, where the contract config reads.
|
|
784
|
+
#[cfg(unix)]
|
|
785
|
+
#[allow(clippy::too_many_arguments)]
|
|
786
|
+
fn add_contract_seat(
|
|
787
|
+
run_workspace: &Path,
|
|
788
|
+
team_dir: &Path,
|
|
789
|
+
spec_path: &Path,
|
|
790
|
+
pre_spec_text: Option<&str>,
|
|
791
|
+
team_key: &str,
|
|
792
|
+
agent_id: &AgentId,
|
|
793
|
+
provider: &str,
|
|
794
|
+
role_file_path: &Path,
|
|
795
|
+
reservation: Option<AgentReservation>,
|
|
796
|
+
) -> Result<AddAgentReport, LifecycleError> {
|
|
797
|
+
let rollback = |reason: &str| {
|
|
798
|
+
rollback_add_agent_atomic(
|
|
799
|
+
run_workspace,
|
|
800
|
+
spec_path,
|
|
801
|
+
pre_spec_text,
|
|
802
|
+
None,
|
|
803
|
+
Some(team_key),
|
|
804
|
+
agent_id,
|
|
805
|
+
reason,
|
|
806
|
+
)
|
|
807
|
+
};
|
|
808
|
+
let seed = serde_json::json!({
|
|
809
|
+
"agent_id": agent_id.as_str(), "provider": provider, "runtime_family": "contract",
|
|
810
|
+
"status": "starting", "contract_instance": null, "pane_id": null,
|
|
811
|
+
});
|
|
812
|
+
if let Err(error) = upsert_agent_entry(run_workspace, team_key, agent_id, seed) {
|
|
813
|
+
rollback("state_upsert_failed");
|
|
814
|
+
return Err(error);
|
|
815
|
+
}
|
|
816
|
+
let started = team_agent_contract::contract::types::SeatId::new(agent_id.as_str())
|
|
817
|
+
.map_err(|error| error.to_string())
|
|
818
|
+
.and_then(|seat| {
|
|
819
|
+
crate::contract_runtime::framework::start_new_seat(
|
|
820
|
+
run_workspace,
|
|
821
|
+
team_dir,
|
|
822
|
+
team_key,
|
|
823
|
+
&seat,
|
|
824
|
+
)
|
|
825
|
+
.map_err(|error| error.to_string())
|
|
826
|
+
});
|
|
827
|
+
if let Err(error) = started {
|
|
828
|
+
rollback("start_agent_failed");
|
|
829
|
+
return Err(LifecycleError::Provider(error));
|
|
830
|
+
}
|
|
831
|
+
let coordinator = crate::coordinator::start_coordinator_with_team(
|
|
832
|
+
&crate::coordinator::WorkspacePath::new(run_workspace.to_path_buf()),
|
|
833
|
+
Some(team_key),
|
|
834
|
+
)
|
|
835
|
+
.map_err(|error| LifecycleError::StatePersist(error.to_string()))?;
|
|
836
|
+
if let Some(reservation) = reservation {
|
|
837
|
+
reservation.commit();
|
|
838
|
+
}
|
|
839
|
+
Ok(AddAgentReport {
|
|
840
|
+
env: AgentActionEnvelope {
|
|
841
|
+
agent_id: agent_id.clone(),
|
|
842
|
+
state_file: crate::state::persist::runtime_state_path(run_workspace),
|
|
843
|
+
coordinator_started: coordinator.ok,
|
|
844
|
+
},
|
|
845
|
+
start_mode: StartMode::Fresh,
|
|
846
|
+
role_file: role_file_path.to_path_buf(),
|
|
847
|
+
})
|
|
848
|
+
}
|
|
@@ -156,6 +156,20 @@ pub(super) fn upsert_agent_state_from_role(
|
|
|
156
156
|
agent_id: &AgentId,
|
|
157
157
|
meta: &Value,
|
|
158
158
|
dynamic_role_file: &Path,
|
|
159
|
+
) -> Result<(), LifecycleError> {
|
|
160
|
+
let entry = starting_agent_entry(workspace, agent_id, meta, dynamic_role_file);
|
|
161
|
+
upsert_agent_entry(workspace, canonical_team_key, agent_id, entry)
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/// ---
|
|
165
|
+
/// purpose: 把一席的 starting 行写进团队 state 并落盘
|
|
166
|
+
/// errors: 读或写 runtime state 失败时返回 StatePersist
|
|
167
|
+
/// ---
|
|
168
|
+
pub(super) fn upsert_agent_entry(
|
|
169
|
+
workspace: &Path,
|
|
170
|
+
canonical_team_key: &str,
|
|
171
|
+
agent_id: &AgentId,
|
|
172
|
+
entry: serde_json::Value,
|
|
159
173
|
) -> Result<(), LifecycleError> {
|
|
160
174
|
let mut state =
|
|
161
175
|
crate::state::projection::select_runtime_state(workspace, Some(canonical_team_key))
|
|
@@ -179,7 +193,6 @@ pub(super) fn upsert_agent_state_from_role(
|
|
|
179
193
|
"runtime state agents is not an object".to_string(),
|
|
180
194
|
));
|
|
181
195
|
};
|
|
182
|
-
let entry = starting_agent_entry(workspace, agent_id, meta, dynamic_role_file);
|
|
183
196
|
agent_map.insert(agent_id.as_str().to_string(), entry);
|
|
184
197
|
crate::lifecycle::restart::remove::clear_agent_retirement_in_state(&mut state, agent_id);
|
|
185
198
|
save_launched_team_state_for_key(
|
|
@@ -129,14 +129,6 @@ pub(super) fn running_agent_state(
|
|
|
129
129
|
if let Some(started_agent) = started_agent {
|
|
130
130
|
persist_started_agent_plan_state(&mut state, started_agent);
|
|
131
131
|
}
|
|
132
|
-
// Cursor chdirs to its native --workspace primary. Session archives are
|
|
133
|
-
// keyed by this directory, not the real project supplied via --add-dir.
|
|
134
|
-
let cursor_cwd = if provider == Provider::CursorAgent && cursor_mcp_isolation_enabled() {
|
|
135
|
-
Some(cursor_mcp_project_dir(workspace, id)?)
|
|
136
|
-
} else {
|
|
137
|
-
None
|
|
138
|
-
};
|
|
139
|
-
let spawn_cwd = cursor_cwd.as_deref().unwrap_or(spawn_cwd);
|
|
140
132
|
state.insert(
|
|
141
133
|
"spawn_cwd".to_string(),
|
|
142
134
|
serde_json::json!(spawn_cwd.to_string_lossy().to_string()),
|
|
@@ -240,7 +232,6 @@ fn provider_wire_str(provider: Provider) -> &'static str {
|
|
|
240
232
|
Provider::Copilot => "copilot",
|
|
241
233
|
Provider::GeminiCli => "gemini_cli",
|
|
242
234
|
Provider::Grok => "grok",
|
|
243
|
-
Provider::CursorAgent => "cursor_agent",
|
|
244
235
|
Provider::Pi => "pi",
|
|
245
236
|
Provider::Fake => "fake",
|
|
246
237
|
}
|
|
@@ -472,8 +472,8 @@ fn grok_trusted_folders(text: &str) -> Vec<PathBuf> {
|
|
|
472
472
|
/// returns: 成功返回空值;写前先清 per-seat 键,已有表里的未知环境键会被保留
|
|
473
473
|
/// errors: 缺条目或缺 command 时返回 StatePersist,清洗失败透传 RequirementUnmet,写文件失败返回 StatePersist
|
|
474
474
|
/// ---
|
|
475
|
-
/// Grok CLI 没有 `--mcp-config
|
|
476
|
-
///
|
|
475
|
+
/// Grok CLI 没有 `--mcp-config`。launch 路径写一份 provider 实际会读的文件。
|
|
476
|
+
/// Grok 只认项目作用域
|
|
477
477
|
/// `<cwd>/.grok/config.toml`(`grok mcp add --scope project` 的产物)。
|
|
478
478
|
///
|
|
479
479
|
/// Unique writer of `<cwd>/.grok/config.toml`. Reconcile leftover per-seat
|
|
@@ -29,19 +29,11 @@ use crate::model::enums::{Provider, ProviderEffort};
|
|
|
29
29
|
use crate::provider::adapters::pi::{build_pi_command_argv, PiCommandRequest, PiSessionSelector};
|
|
30
30
|
use crate::provider::{CommandPlan, McpConfig, ProviderError, SessionId};
|
|
31
31
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
Wrapper,
|
|
35
|
-
Symlink,
|
|
36
|
-
Binary,
|
|
37
|
-
}
|
|
38
|
-
|
|
32
|
+
/// The first executable `pi` on PATH, exactly what the worker's bare `pi`
|
|
33
|
+
/// runs: a wrapper, npm symlink or plain binary alike. No inner binary is probed.
|
|
39
34
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
|
40
35
|
pub(crate) struct PiExecutableChain {
|
|
41
36
|
pub path_entry: PathBuf,
|
|
42
|
-
pub path_entry_type: PiExecutableFileType,
|
|
43
|
-
pub launch_executable: PathBuf,
|
|
44
|
-
pub real_binary: PathBuf,
|
|
45
37
|
pub pi_version: String,
|
|
46
38
|
pub catalog_sha256: String,
|
|
47
39
|
}
|
|
@@ -169,20 +161,13 @@ pub(crate) fn verify_started_pi_model(selected: &str, observed: &str) -> Result<
|
|
|
169
161
|
}
|
|
170
162
|
|
|
171
163
|
/// ---
|
|
172
|
-
/// purpose: 校验 Pi
|
|
173
|
-
/// returns:
|
|
164
|
+
/// purpose: 校验 Pi PATH entry 与 live catalog;MCP 能力在实际 Pi context 验证
|
|
165
|
+
/// returns: PATH entry 与 catalog receipt 完整时成功
|
|
174
166
|
/// errors: 缺路径或 catalog receipt 时返回 ProviderError
|
|
175
167
|
/// ---
|
|
176
168
|
pub(crate) fn validate_pi_executable_chain(chain: &PiExecutableChain) -> Result<(), ProviderError> {
|
|
177
169
|
if !chain.path_entry.is_absolute()
|
|
178
|
-
||
|
|
179
|
-
|| !chain.real_binary.is_absolute()
|
|
180
|
-
|| !matches!(
|
|
181
|
-
chain.path_entry_type,
|
|
182
|
-
PiExecutableFileType::Wrapper | PiExecutableFileType::Symlink
|
|
183
|
-
)
|
|
184
|
-
|| chain.launch_executable != chain.path_entry
|
|
185
|
-
|| chain.real_binary == chain.launch_executable
|
|
170
|
+
|| chain.path_entry.file_name().is_none_or(|name| name != "pi")
|
|
186
171
|
|| chain.catalog_sha256.len() != 64
|
|
187
172
|
|| !chain
|
|
188
173
|
.catalog_sha256
|
|
@@ -479,21 +464,6 @@ fn sha256(bytes: &[u8]) -> String {
|
|
|
479
464
|
format!("{:x}", Sha256::digest(bytes))
|
|
480
465
|
}
|
|
481
466
|
|
|
482
|
-
fn executable_file_type(path: &Path) -> Result<PiExecutableFileType, ProviderError> {
|
|
483
|
-
let metadata = std::fs::symlink_metadata(path)
|
|
484
|
-
.map_err(|error| ProviderError::Io(format!("{}: {error}", path.display())))?;
|
|
485
|
-
if metadata.file_type().is_symlink() {
|
|
486
|
-
return Ok(PiExecutableFileType::Symlink);
|
|
487
|
-
}
|
|
488
|
-
let bytes = std::fs::read(path)
|
|
489
|
-
.map_err(|error| ProviderError::Io(format!("{}: {error}", path.display())))?;
|
|
490
|
-
if bytes.starts_with(b"#!") {
|
|
491
|
-
Ok(PiExecutableFileType::Wrapper)
|
|
492
|
-
} else {
|
|
493
|
-
Ok(PiExecutableFileType::Binary)
|
|
494
|
-
}
|
|
495
|
-
}
|
|
496
|
-
|
|
497
467
|
#[cfg(test)]
|
|
498
468
|
#[derive(Debug, Default)]
|
|
499
469
|
pub(crate) struct PiCatalogTestObservation {
|
|
@@ -610,12 +580,7 @@ impl crate::provider::model_catalog::CatalogObserver for PiCatalogObserver {
|
|
|
610
580
|
}
|
|
611
581
|
|
|
612
582
|
pub(crate) fn pi_model_candidates(requested: &str) -> Result<Vec<String>, ProviderError> {
|
|
613
|
-
let
|
|
614
|
-
.ok_or_else(|| ProviderError::Command("PATH is not set".to_string()))?;
|
|
615
|
-
let executable = std::env::split_paths(&path)
|
|
616
|
-
.map(|directory| directory.join("pi"))
|
|
617
|
-
.find(|candidate| candidate.is_file())
|
|
618
|
-
.ok_or_else(|| ProviderError::Command("Pi executable not found on PATH".to_string()))?;
|
|
583
|
+
let executable = pi_path_entry()?;
|
|
619
584
|
let catalog = run_pi_catalog(&executable, Duration::from_secs(10), 1024 * 1024)
|
|
620
585
|
.map_err(ProviderError::Command)?;
|
|
621
586
|
let models = parse_pi_list_models_table(&catalog)?;
|
|
@@ -629,21 +594,13 @@ pub(crate) fn pi_model_candidates(requested: &str) -> Result<Vec<String>, Provid
|
|
|
629
594
|
.collect())
|
|
630
595
|
}
|
|
631
596
|
|
|
632
|
-
|
|
597
|
+
/// The shell's own PATH choice: the first executable `pi`, kept as found.
|
|
598
|
+
fn pi_path_entry() -> Result<PathBuf, ProviderError> {
|
|
633
599
|
let path = std::env::var_os("PATH")
|
|
634
600
|
.ok_or_else(|| ProviderError::Command("PATH is not set".to_string()))?;
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
.
|
|
638
|
-
.filter(|candidate| candidate.is_file())
|
|
639
|
-
.filter(|candidate| seen.insert(candidate.clone()))
|
|
640
|
-
.collect::<Vec<_>>();
|
|
641
|
-
if entries.is_empty() {
|
|
642
|
-
return Err(ProviderError::Command(
|
|
643
|
-
"Pi executable not found on PATH".to_string(),
|
|
644
|
-
));
|
|
645
|
-
}
|
|
646
|
-
Ok(entries)
|
|
601
|
+
team_agent_contract::host::command::PublicCommand::resolve("pi", &path)
|
|
602
|
+
.map(|command| command.entry)
|
|
603
|
+
.map_err(|_| ProviderError::Command("Pi executable not found on PATH".to_string()))
|
|
647
604
|
}
|
|
648
605
|
|
|
649
606
|
fn command_stdout(executable: &Path, args: &[&str]) -> Result<Vec<u8>, ProviderError> {
|
|
@@ -675,53 +632,17 @@ fn command_stdout(executable: &Path, args: &[&str]) -> Result<Vec<u8>, ProviderE
|
|
|
675
632
|
/// ---
|
|
676
633
|
pub(crate) fn resolve_pi_executable_chain(
|
|
677
634
|
) -> Result<(PiExecutableChain, Vec<String>), ProviderError> {
|
|
678
|
-
|
|
679
|
-
let path_entry =
|
|
680
|
-
let path_entry_type = executable_file_type(&path_entry)?;
|
|
681
|
-
if !matches!(
|
|
682
|
-
path_entry_type,
|
|
683
|
-
PiExecutableFileType::Wrapper | PiExecutableFileType::Symlink
|
|
684
|
-
) {
|
|
685
|
-
return Err(ProviderError::Command(
|
|
686
|
-
"the direct Pi PATH entry is not a verified wrapper or npm symlink".to_string(),
|
|
687
|
-
));
|
|
688
|
-
}
|
|
635
|
+
// Probe through the PATH entry itself so a user wrapper sees every probe.
|
|
636
|
+
let path_entry = pi_path_entry()?;
|
|
689
637
|
let version =
|
|
690
638
|
String::from_utf8(command_stdout(&path_entry, &["--version"])?).map_err(|error| {
|
|
691
639
|
ProviderError::Command(format!("Pi version output is not UTF-8: {error}"))
|
|
692
640
|
})?;
|
|
693
|
-
let version = version.trim().to_string();
|
|
694
|
-
let launch_identity = std::fs::canonicalize(&path_entry)
|
|
695
|
-
.map_err(|error| ProviderError::Io(format!("{}: {error}", path_entry.display())))?;
|
|
696
|
-
let real_binary = if path_entry_type == PiExecutableFileType::Symlink {
|
|
697
|
-
launch_identity
|
|
698
|
-
} else {
|
|
699
|
-
path_entries
|
|
700
|
-
.iter()
|
|
701
|
-
.find_map(|candidate| {
|
|
702
|
-
let real = std::fs::canonicalize(candidate).ok()?;
|
|
703
|
-
(real != launch_identity).then_some(real)
|
|
704
|
-
})
|
|
705
|
-
.ok_or_else(|| {
|
|
706
|
-
ProviderError::Command(
|
|
707
|
-
"Pi PATH wrapper has no independently resolved real executable".to_string(),
|
|
708
|
-
)
|
|
709
|
-
})?
|
|
710
|
-
};
|
|
711
|
-
let _real_version =
|
|
712
|
-
String::from_utf8(command_stdout(&real_binary, &["--version"])?).map_err(|error| {
|
|
713
|
-
ProviderError::Command(format!(
|
|
714
|
-
"Pi real binary version output is not UTF-8: {error}"
|
|
715
|
-
))
|
|
716
|
-
})?;
|
|
717
641
|
let catalog = command_stdout(&path_entry, &["--list-models"])?;
|
|
718
642
|
let models = parse_pi_list_models_table(&catalog)?;
|
|
719
643
|
let chain = PiExecutableChain {
|
|
720
|
-
path_entry
|
|
721
|
-
|
|
722
|
-
launch_executable: path_entry,
|
|
723
|
-
real_binary,
|
|
724
|
-
pi_version: version,
|
|
644
|
+
path_entry,
|
|
645
|
+
pi_version: version.trim().to_string(),
|
|
725
646
|
catalog_sha256: sha256(&catalog),
|
|
726
647
|
};
|
|
727
648
|
validate_pi_executable_chain(&chain)?;
|
|
@@ -762,8 +683,8 @@ pub(crate) struct PiMaterializeRequest<'a> {
|
|
|
762
683
|
}
|
|
763
684
|
|
|
764
685
|
/// ---
|
|
765
|
-
/// purpose: 共享物化 Pi leader 与 TeamMate 的 wrapper
|
|
766
|
-
/// returns: fresh Pi CommandPlan;isolated seats carry their session root, while the
|
|
686
|
+
/// purpose: 共享物化 Pi leader 与 TeamMate 的 wrapper 和 CommandPlan
|
|
687
|
+
/// returns: fresh Pi CommandPlan 不传 --session-id;isolated seats carry their session root, while the
|
|
767
688
|
/// interactive leader preserves Pi's native default root
|
|
768
689
|
/// errors: resolver、exact model、wrapper 或 argv 构造失败时返回 ProviderError
|
|
769
690
|
/// ---
|
|
@@ -858,19 +779,16 @@ fn materialize_pi_plan_with_session(
|
|
|
858
779
|
})?;
|
|
859
780
|
(argv, None)
|
|
860
781
|
} else {
|
|
861
|
-
let session_id = new_pi_session_id();
|
|
862
782
|
let argv = build_pi_command_argv(PiCommandRequest {
|
|
863
783
|
extension: &wrapper,
|
|
864
784
|
model: model.as_deref(),
|
|
865
785
|
effort: request.effort,
|
|
866
786
|
system_prompt: request.system_prompt,
|
|
867
787
|
session_dir,
|
|
868
|
-
session: PiSessionSelector::Fresh
|
|
869
|
-
session_id: session_id.as_str(),
|
|
870
|
-
},
|
|
788
|
+
session: PiSessionSelector::Fresh,
|
|
871
789
|
agent_id: request.agent_id,
|
|
872
790
|
})?;
|
|
873
|
-
(argv,
|
|
791
|
+
(argv, None)
|
|
874
792
|
};
|
|
875
793
|
Ok(CommandPlan {
|
|
876
794
|
argv,
|