@team-agent/installer 0.5.124 → 0.5.125
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Cargo.lock +1 -8
- package/Cargo.toml +1 -1
- package/README.md +2 -2
- package/README.zh.md +2 -2
- package/crates/team-agent/Cargo.toml +0 -1
- package/crates/team-agent/src/cli/diagnose.rs +39 -1
- package/crates/team-agent/src/cli/emit.rs +41 -15
- package/crates/team-agent/src/cli/intent/runtime.rs +5 -53
- package/crates/team-agent/src/cli/intent/runtime_tests.rs +0 -120
- package/crates/team-agent/src/cli/leader.rs +2 -3
- package/crates/team-agent/src/cli/leader_prompt.rs +1 -1
- package/crates/team-agent/src/cli/mod.rs +6 -5
- package/crates/team-agent/src/cli/models.rs +40 -119
- package/crates/team-agent/src/cli/route.rs +1 -1
- package/crates/team-agent/src/cli/send/persist.rs +36 -0
- package/crates/team-agent/src/cli/send/presentation.rs +7 -1
- package/crates/team-agent/src/cli/send.rs +3 -1
- package/crates/team-agent/src/cli/spec.rs +1 -2
- package/crates/team-agent/src/cli/status_port/brief.rs +66 -0
- package/crates/team-agent/src/cli/tests/base.rs +4 -11
- package/crates/team-agent/src/cli/tests/status_send.rs +17 -0
- package/crates/team-agent/src/compiler/tests.rs +21 -5
- package/crates/team-agent/src/compiler.rs +24 -1
- package/crates/team-agent/src/contract_runtime/backend.rs +22 -6
- package/crates/team-agent/src/contract_runtime/config.rs +34 -24
- package/crates/team-agent/src/contract_runtime/discovery.rs +33 -0
- package/crates/team-agent/src/contract_runtime/framework.rs +89 -34
- package/crates/team-agent/src/contract_runtime/registry.rs +258 -21
- package/crates/team-agent/src/coordinator/runtime_detectors.rs +0 -1
- package/crates/team-agent/src/coordinator/tick.rs +89 -1
- package/crates/team-agent/src/db/message_store.rs +78 -3
- package/crates/team-agent/src/layout/worker_window_helpers.rs +0 -1
- package/crates/team-agent/src/leader/prompt.rs +1 -2
- package/crates/team-agent/src/leader/provider_attribution.rs +0 -52
- package/crates/team-agent/src/leader/start.rs +0 -1
- package/crates/team-agent/src/leader/tests/prompt_contract.rs +2 -3
- package/crates/team-agent/src/lifecycle/launch/add_agent.rs +91 -0
- package/crates/team-agent/src/lifecycle/launch/add_agent_state.rs +14 -1
- package/crates/team-agent/src/lifecycle/launch/agent_state.rs +0 -9
- package/crates/team-agent/src/lifecycle/launch/fork_agent.rs +0 -1
- package/crates/team-agent/src/lifecycle/launch/mcp_config.rs +2 -2
- package/crates/team-agent/src/lifecycle/launch/spawn.rs +0 -28
- package/crates/team-agent/src/lifecycle/launch/spec_state.rs +0 -1
- package/crates/team-agent/src/lifecycle/launch/worker_env.rs +0 -108
- package/crates/team-agent/src/lifecycle/launch.rs +2 -20
- package/crates/team-agent/src/lifecycle/profile_launch.rs +11 -39
- package/crates/team-agent/src/lifecycle/profile_smoke.rs +1 -2
- package/crates/team-agent/src/lifecycle/restart/common.rs +1 -63
- package/crates/team-agent/src/lifecycle/role_config.rs +42 -3
- package/crates/team-agent/src/lifecycle/tests/cli_argv_routing_red.rs +38 -7
- package/crates/team-agent/src/lifecycle/tests/clone_fork_copilot_perms_red.rs +6 -2
- package/crates/team-agent/src/lifecycle/tests/restart_rebind_hotfix_252_red.rs +0 -1
- package/crates/team-agent/src/lifecycle/tests/worker_spawn_env_red.rs +0 -137
- package/crates/team-agent/src/lifecycle/tests.rs +0 -3
- package/crates/team-agent/src/lifecycle/worker_command_context.rs +2 -4
- package/crates/team-agent/src/mcp_server/readiness.rs +148 -97
- package/crates/team-agent/src/mcp_server/readiness_tests.rs +115 -16
- package/crates/team-agent/src/messaging/delivery.rs +181 -35
- package/crates/team-agent/src/messaging/delivery_consumption_tests.rs +4 -4
- package/crates/team-agent/src/messaging/enter_rescue_tests.rs +1 -1
- package/crates/team-agent/src/messaging/helpers.rs +19 -0
- package/crates/team-agent/src/messaging/tests/dup_inject.rs +66 -4
- package/crates/team-agent/src/messaging/tests/runtime.rs +110 -4
- package/crates/team-agent/src/messaging/tests/spine.rs +22 -6
- package/crates/team-agent/src/model/enums.rs +1 -8
- package/crates/team-agent/src/provider/adapter.rs +1 -67
- package/crates/team-agent/src/provider/adapters/mod.rs +0 -1
- package/crates/team-agent/src/provider/argv_route.rs +1 -5
- package/crates/team-agent/src/provider/bypass_flags.rs +3 -11
- package/crates/team-agent/src/provider/classify.rs +68 -3
- package/crates/team-agent/src/provider/faults.rs +1 -1
- package/crates/team-agent/src/provider/model_catalog.rs +2 -73
- package/crates/team-agent/src/provider/session/capture.rs +1 -1
- package/crates/team-agent/src/provider/session/context_fork.rs +4 -4
- package/crates/team-agent/src/provider/session_scan/common.rs +1 -2
- package/crates/team-agent/src/provider/session_scan.rs +0 -4
- package/crates/team-agent/src/provider/submit_now.rs +5 -28
- package/crates/team-agent/src/provider/tests/adapter.rs +5 -184
- package/crates/team-agent/src/provider/tests/classify.rs +53 -0
- package/crates/team-agent/src/provider/tests/command_helpers.rs +1 -4
- package/crates/team-agent/src/provider/types.rs +1 -1
- package/crates/team-agent/src/provider/wire.rs +48 -8
- package/crates/team-agent/src/tmux_backend/native_input_tests.rs +2 -178
- package/crates/team-agent/src/tmux_backend/tests.rs +151 -0
- package/crates/team-agent/src/tmux_backend.rs +43 -8
- package/crates/team-agent/src/transport/native_input.rs +2 -231
- package/package.json +4 -4
- package/skills/team-agent/SKILL.md +1 -1
- package/crates/team-agent/src/lifecycle/launch/cursor_create_chat.rs +0 -229
- package/crates/team-agent/src/lifecycle/launch/cursor_mcp.rs +0 -522
- package/crates/team-agent/src/lifecycle/launch/cursor_mcp_iso.rs +0 -282
- package/crates/team-agent/src/lifecycle/tests/cursor_mcp_overlay.rs +0 -576
- package/crates/team-agent/src/lifecycle/tests/cursor_require_explicit_model_red.rs +0 -222
- package/crates/team-agent/src/lifecycle/tests/cursor_restart_resume_red.rs +0 -511
- package/crates/team-agent/src/provider/adapters/cursor_agent.rs +0 -44
- package/crates/team-agent/src/provider/session_scan/cursor.rs +0 -538
- package/crates/team-agent/src/provider/testdata/cursor-list-models-native.stdout +0 -250
|
@@ -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
|
|
@@ -328,34 +328,6 @@ pub(super) fn spawn_agents(
|
|
|
328
328
|
);
|
|
329
329
|
}
|
|
330
330
|
}
|
|
331
|
-
// Cursor: role 经 .cursor/rules。MCP 身份默认写 provider-config/<id>/cursor
|
|
332
|
-
// (不继承父进程 TEAM_AGENT_*)。--workspace 指该工程根,--add-dir 真 workspace。
|
|
333
|
-
// 隔离关闭时仍拒绝第二席(共用 mcp.json last-writer)。不改 HOME。
|
|
334
|
-
if matches!(provider, Provider::CursorAgent) {
|
|
335
|
-
refuse_second_cursor_occupant(workspace, agent_id_raw, Some(spec))?;
|
|
336
|
-
apply_cursor_agent_rules_overlay(workspace, agent_id_raw, system_prompt.as_str())?;
|
|
337
|
-
let project = crate::lifecycle::launch::prepare_cursor_seat_mcp(
|
|
338
|
-
workspace,
|
|
339
|
-
agent_id_raw,
|
|
340
|
-
&mcp_config,
|
|
341
|
-
)?;
|
|
342
|
-
enable_cursor_workspace_mcp_with_profile(
|
|
343
|
-
workspace,
|
|
344
|
-
project.as_deref(),
|
|
345
|
-
Some(&profile_launch),
|
|
346
|
-
)?;
|
|
347
|
-
apply_cursor_spawn_workspace_pointers(&mut plan.argv, workspace, agent_id_raw)?;
|
|
348
|
-
let proxy = apply_cursor_subscription_proxy_env_with_profile(&mut env, &profile_launch);
|
|
349
|
-
let event_log = crate::event_log::EventLog::new(workspace);
|
|
350
|
-
let _ = event_log.write(
|
|
351
|
-
"provider.cursor.proxy_presence",
|
|
352
|
-
serde_json::json!({
|
|
353
|
-
"agent_id": agent_id_raw,
|
|
354
|
-
"https_proxy": proxy.https_proxy,
|
|
355
|
-
"no_proxy": proxy.no_proxy,
|
|
356
|
-
}),
|
|
357
|
-
);
|
|
358
|
-
}
|
|
359
331
|
// Grok 无 --mcp-config;写 <cwd>/.grok/config.toml 让 CLI 读到 team-agent。
|
|
360
332
|
if matches!(provider, Provider::Grok) {
|
|
361
333
|
ensure_grok_login_and_folder_trust(workspace)?;
|
|
@@ -643,7 +643,6 @@ pub(crate) fn provider_display_str(provider: Provider) -> &'static str {
|
|
|
643
643
|
Provider::Copilot => "copilot",
|
|
644
644
|
Provider::GeminiCli => "gemini_cli",
|
|
645
645
|
Provider::Grok => "grok",
|
|
646
|
-
Provider::CursorAgent => "cursor_agent",
|
|
647
646
|
Provider::Pi => "pi",
|
|
648
647
|
Provider::Fake => "fake",
|
|
649
648
|
}
|
|
@@ -8,8 +8,6 @@
|
|
|
8
8
|
//! what: 按 bypass 结论写或清 MCP 自动放行相关变量
|
|
9
9
|
//! - name: apply_copilot_instructions_overlay
|
|
10
10
|
//! what: 把角色提示词写成 per-agent 的 AGENTS.md 并指向它
|
|
11
|
-
//! - name: apply_cursor_agent_rules_overlay
|
|
12
|
-
//! what: 把角色提示词写成 workspace 内 per-agent 的 cursor rules 文件
|
|
13
11
|
//! - name: fill_spawn_placeholders_full
|
|
14
12
|
//! what: 替换 argv 里的 workspace、agent_id 与 team_id 占位符
|
|
15
13
|
//! depends:
|
|
@@ -254,42 +252,6 @@ pub(crate) fn apply_copilot_instructions_overlay(
|
|
|
254
252
|
Ok(())
|
|
255
253
|
}
|
|
256
254
|
|
|
257
|
-
/// ---
|
|
258
|
-
/// purpose: 把角色提示词写成 workspace 内 per-agent 的 cursor rules 文件
|
|
259
|
-
/// params:
|
|
260
|
-
/// system_prompt: 写入 rules 正文,文件头声明 alwaysApply
|
|
261
|
-
/// returns: 成功返回空值
|
|
262
|
-
/// errors: 建目录或写文件失败时返回 StatePersist
|
|
263
|
-
/// ---
|
|
264
|
-
/// 0.5.67 Cursor append-system-prompt 方案 1 变体(冒烟 PASS, see
|
|
265
|
-
/// .team/artifacts/0.5.67-cursor-rules-smoke.md)— Cursor `agent` CLI 无
|
|
266
|
-
/// append/rule CLI flag, 只从 workspace 静态 rules 文件读:
|
|
267
|
-
/// `.cursor/rules/**/*.mdc` (alwaysApply: true) / `AGENTS.md` / `.cursorrules`。
|
|
268
|
-
///
|
|
269
|
-
/// 这里在 launch 路径写 `<workspace>/.cursor/rules/team-agent-role-<agent_id>.mdc`
|
|
270
|
-
/// 并把 role(= compile_worker_system_prompt 输出)放进去, argv 只带
|
|
271
|
-
/// `--workspace <workspace>`(cursor_agent.rs)。cursor CLI 读取该目录即加载 role。
|
|
272
|
-
///
|
|
273
|
-
/// 目录布局为 workspace 内 `.cursor/rules/`(Cursor 唯一 rules 通道; 无法像 copilot
|
|
274
|
-
/// 那样放 `.team/runtime/` —— 那是 Cursor 不读的路径)。文件名含 `<agent_id>`
|
|
275
|
-
/// 保证 per-agent 隔离, 不互相污染。
|
|
276
|
-
pub(crate) fn apply_cursor_agent_rules_overlay(
|
|
277
|
-
workspace: &Path,
|
|
278
|
-
agent_id: &str,
|
|
279
|
-
system_prompt: &str,
|
|
280
|
-
) -> Result<(), LifecycleError> {
|
|
281
|
-
let dir = workspace.join(".cursor").join("rules");
|
|
282
|
-
std::fs::create_dir_all(&dir)
|
|
283
|
-
.map_err(|e| LifecycleError::StatePersist(format!("{}: {e}", dir.display())))?;
|
|
284
|
-
let rules = dir.join(format!("team-agent-role-{agent_id}.mdc"));
|
|
285
|
-
let content = format!(
|
|
286
|
-
"---\ndescription: Team Agent role injection (auto-generated)\nalwaysApply: true\n---\n\n{system_prompt}\n"
|
|
287
|
-
);
|
|
288
|
-
std::fs::write(&rules, content.as_bytes())
|
|
289
|
-
.map_err(|e| LifecycleError::StatePersist(format!("{}: {e}", rules.display())))?;
|
|
290
|
-
Ok(())
|
|
291
|
-
}
|
|
292
|
-
|
|
293
255
|
/// ---
|
|
294
256
|
/// purpose: 扫出 copilot 侧残留的 MCP server,对非本框架的逐个追加禁用参数
|
|
295
257
|
/// params:
|
|
@@ -450,76 +412,6 @@ pub(super) fn parse_copilot_mcp_list_server_names(text: &str) -> Vec<String> {
|
|
|
450
412
|
out
|
|
451
413
|
}
|
|
452
414
|
|
|
453
|
-
/// Subscription seats inherit parent env, but that is implicit. Cursor cloud
|
|
454
|
-
/// on this host is blocked without a proxy; `profile_launch` copies these
|
|
455
|
-
/// keys only on the compatible-api path. Copy them explicitly here so a
|
|
456
|
-
/// subscription cursor seat sees the same keys. Values may contain
|
|
457
|
-
/// credentials — callers must only log presence/length, never the value.
|
|
458
|
-
const CURSOR_PROXY_KEYS: &[&str] = &[
|
|
459
|
-
"HTTPS_PROXY",
|
|
460
|
-
"HTTP_PROXY",
|
|
461
|
-
"ALL_PROXY",
|
|
462
|
-
"NO_PROXY",
|
|
463
|
-
"https_proxy",
|
|
464
|
-
"http_proxy",
|
|
465
|
-
"all_proxy",
|
|
466
|
-
"no_proxy",
|
|
467
|
-
];
|
|
468
|
-
|
|
469
|
-
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
|
470
|
-
pub struct CursorProxyPresence {
|
|
471
|
-
pub https_proxy: bool,
|
|
472
|
-
pub no_proxy: bool,
|
|
473
|
-
}
|
|
474
|
-
|
|
475
|
-
/// ---
|
|
476
|
-
/// purpose: 给订阅制 cursor 席位显式补上父进程里的代理变量
|
|
477
|
-
/// params:
|
|
478
|
-
/// env: 就地补键,已有同名键不覆盖
|
|
479
|
-
/// returns: 记录是否存在 https 代理与 no_proxy,只记存在与否不记值
|
|
480
|
-
/// ---
|
|
481
|
-
pub fn apply_cursor_subscription_proxy_env(
|
|
482
|
-
env: &mut BTreeMap<String, String>,
|
|
483
|
-
) -> CursorProxyPresence {
|
|
484
|
-
let mut https_proxy = false;
|
|
485
|
-
let mut no_proxy = false;
|
|
486
|
-
for key in CURSOR_PROXY_KEYS {
|
|
487
|
-
let Ok(value) = std::env::var(key) else {
|
|
488
|
-
continue;
|
|
489
|
-
};
|
|
490
|
-
if value.is_empty() {
|
|
491
|
-
continue;
|
|
492
|
-
}
|
|
493
|
-
if key.eq_ignore_ascii_case("HTTPS_PROXY") {
|
|
494
|
-
https_proxy = true;
|
|
495
|
-
}
|
|
496
|
-
if key.eq_ignore_ascii_case("NO_PROXY") {
|
|
497
|
-
no_proxy = true;
|
|
498
|
-
}
|
|
499
|
-
env.entry((*key).to_string()).or_insert(value);
|
|
500
|
-
}
|
|
501
|
-
CursorProxyPresence {
|
|
502
|
-
https_proxy,
|
|
503
|
-
no_proxy,
|
|
504
|
-
}
|
|
505
|
-
}
|
|
506
|
-
|
|
507
|
-
pub(crate) fn apply_cursor_subscription_proxy_env_with_profile(
|
|
508
|
-
env: &mut BTreeMap<String, String>,
|
|
509
|
-
profile_launch: &crate::provider::ProviderProfileLaunch,
|
|
510
|
-
) -> CursorProxyPresence {
|
|
511
|
-
if crate::lifecycle::profile_launch::cursor_subscription_direct_mode(profile_launch) {
|
|
512
|
-
for key in &profile_launch.env_unset {
|
|
513
|
-
env.remove(key);
|
|
514
|
-
}
|
|
515
|
-
return CursorProxyPresence {
|
|
516
|
-
https_proxy: false,
|
|
517
|
-
no_proxy: env.keys().any(|key| key.eq_ignore_ascii_case("NO_PROXY")),
|
|
518
|
-
};
|
|
519
|
-
}
|
|
520
|
-
apply_cursor_subscription_proxy_env(env)
|
|
521
|
-
}
|
|
522
|
-
|
|
523
415
|
/// ---
|
|
524
416
|
/// purpose: 把 profile 推出的环境清除与覆盖套用到 spawn 环境上
|
|
525
417
|
/// params:
|
|
@@ -374,33 +374,15 @@ pub(crate) fn run_pi_catalog_preflight(
|
|
|
374
374
|
})
|
|
375
375
|
}
|
|
376
376
|
|
|
377
|
-
mod cursor_mcp_iso;
|
|
378
|
-
pub(crate) use cursor_mcp_iso::cursor_mcp_primary_matches_scope;
|
|
379
|
-
pub use cursor_mcp_iso::{
|
|
380
|
-
cursor_mcp_isolation_enabled, cursor_mcp_json_path, cursor_mcp_project_dir,
|
|
381
|
-
materialize_cursor_mcp_project,
|
|
382
|
-
};
|
|
383
|
-
mod cursor_mcp;
|
|
384
|
-
pub(crate) use cursor_mcp::apply_cursor_mcp_enable_profile_env;
|
|
385
|
-
pub use cursor_mcp::{
|
|
386
|
-
apply_cursor_mcp_overlay, apply_cursor_spawn_workspace_pointers,
|
|
387
|
-
apply_cursor_workspace_physical_path, cursor_mcp_enable_argv, cursor_mcp_enable_working_dir,
|
|
388
|
-
enable_cursor_workspace_mcp, enable_cursor_workspace_mcp_with_profile, physical_workspace_path,
|
|
389
|
-
prepare_cursor_seat_mcp, refuse_second_cursor_occupant,
|
|
390
|
-
};
|
|
391
|
-
|
|
392
|
-
mod cursor_create_chat;
|
|
393
|
-
|
|
394
377
|
mod worker_env;
|
|
395
378
|
pub(super) use worker_env::*;
|
|
396
379
|
pub(crate) use worker_env::{
|
|
397
|
-
apply_copilot_instructions_overlay,
|
|
398
|
-
|
|
380
|
+
apply_copilot_instructions_overlay,
|
|
381
|
+
apply_mcp_auto_approval_env,
|
|
399
382
|
apply_profile_launch_env, auth_mode_env_value, fill_spawn_placeholders,
|
|
400
383
|
fill_spawn_placeholders_full, inherited_env_with_team_overrides, persist_command_plan_state,
|
|
401
384
|
spawn_timestamp,
|
|
402
385
|
};
|
|
403
|
-
pub use worker_env::{apply_cursor_subscription_proxy_env, CursorProxyPresence};
|
|
404
386
|
|
|
405
387
|
mod identity;
|
|
406
388
|
pub(super) use identity::*;
|