@team-agent/installer 0.5.125 → 0.5.126
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Cargo.lock +1 -1
- package/Cargo.toml +1 -1
- package/crates/team-agent/src/cli/diagnose.rs +0 -68
- package/crates/team-agent/src/cli/emit.rs +6 -2
- package/crates/team-agent/src/cli/intent/runtime_tests.rs +10 -10
- package/crates/team-agent/src/cli/mod.rs +22 -28
- package/crates/team-agent/src/cli/models.rs +7 -764
- package/crates/team-agent/src/cli/tests/mod.rs +1 -1
- package/crates/team-agent/src/cli/tests/run_delegation.rs +5 -4
- package/crates/team-agent/src/compiler/tests.rs +18 -3
- package/crates/team-agent/src/compiler.rs +4 -203
- package/crates/team-agent/src/contract_runtime/backend.rs +61 -38
- package/crates/team-agent/src/contract_runtime/config.rs +7 -4
- package/crates/team-agent/src/contract_runtime/fork.rs +368 -0
- package/crates/team-agent/src/contract_runtime/framework.rs +8 -10
- package/crates/team-agent/src/contract_runtime/mod.rs +1 -0
- package/crates/team-agent/src/contract_runtime/registry.rs +60 -19
- package/crates/team-agent/src/coordinator/tests/api_error_recovery.rs +29 -8
- package/crates/team-agent/src/coordinator/tests/health_sync.rs +0 -42
- package/crates/team-agent/src/leader/start.rs +1 -1
- package/crates/team-agent/src/lifecycle/launch/add_agent_state.rs +2 -195
- package/crates/team-agent/src/lifecycle/launch/clone_agent.rs +11 -27
- package/crates/team-agent/src/lifecycle/launch/fork_agent.rs +18 -28
- package/crates/team-agent/src/lifecycle/launch/fork_entry.rs +6 -87
- package/crates/team-agent/src/lifecycle/launch/mcp_config.rs +1 -9
- package/crates/team-agent/src/lifecycle/launch/pi_mcp.rs +74 -244
- package/crates/team-agent/src/lifecycle/launch/quick_start.rs +0 -24
- package/crates/team-agent/src/lifecycle/launch/role_source.rs +5 -0
- package/crates/team-agent/src/lifecycle/launch/spawn.rs +21 -33
- package/crates/team-agent/src/lifecycle/launch.rs +0 -23
- package/crates/team-agent/src/lifecycle/profile_launch.rs +18 -317
- package/crates/team-agent/src/lifecycle/restart/common.rs +42 -315
- package/crates/team-agent/src/lifecycle/restart/selection.rs +5 -5
- package/crates/team-agent/src/lifecycle/restart.rs +0 -2
- package/crates/team-agent/src/lifecycle/tests/behavioral_diff_264_red.rs +11 -6
- package/crates/team-agent/src/lifecycle/tests/claude_profile_launch_red.rs +8 -320
- package/crates/team-agent/src/lifecycle/tests/cli_argv_routing_red.rs +22 -138
- package/crates/team-agent/src/lifecycle/tests/clone_fork_copilot_perms_red.rs +4 -334
- package/crates/team-agent/src/lifecycle/tests/communication_mode_runtime_contract_red.rs +30 -11
- package/crates/team-agent/src/lifecycle/tests/copilot_provider_red.rs +2 -2
- package/crates/team-agent/src/lifecycle/tests/core.rs +17 -16
- package/crates/team-agent/src/lifecycle/tests/grok_require_explicit_model_red.rs +12 -12
- package/crates/team-agent/src/lifecycle/tests/harvest2_a_batch_red.rs +3 -51
- package/crates/team-agent/src/lifecycle/tests/launch_spawn.rs +26 -28
- package/crates/team-agent/src/lifecycle/tests/pi_catalog_red.rs +6 -18
- package/crates/team-agent/src/lifecycle/tests/pi_command_red.rs +52 -70
- package/crates/team-agent/src/lifecycle/tests/pi_dual_entry_red.rs +4 -157
- package/crates/team-agent/src/lifecycle/tests/pi_executable_mcp_red.rs +10 -302
- package/crates/team-agent/src/lifecycle/tests/pi_lifecycle_doctor_red.rs +1 -68
- package/crates/team-agent/src/lifecycle/tests/pi_native_mcp_capability_red.rs +1 -19
- package/crates/team-agent/src/lifecycle/tests/pi_session_delivery_red.rs +2 -100
- package/crates/team-agent/src/lifecycle/tests/quick_start_worker_readiness_red.rs +11 -10
- package/crates/team-agent/src/lifecycle/tests/restart_session_capture_red.rs +2 -106
- package/crates/team-agent/src/lifecycle/tests/status_credential_redaction_contract.rs +2 -2
- package/crates/team-agent/src/lifecycle/tests/swallow_batch4_semantics_red.rs +2 -254
- package/crates/team-agent/src/lifecycle/tests/upgrade_compat_0211_red.rs +4 -4
- package/crates/team-agent/src/lifecycle/tests/verify_rs031_window_consistency_red.rs +6 -5
- package/crates/team-agent/src/lifecycle/tests/worker_spawn_env_red.rs +7 -16
- package/crates/team-agent/src/lifecycle/tests.rs +0 -3
- package/crates/team-agent/src/lifecycle/types.rs +2 -18
- package/crates/team-agent/src/mcp_server/readiness_tests.rs +1 -1
- package/crates/team-agent/src/messaging/delivery.rs +12 -141
- package/crates/team-agent/src/messaging/delivery_consumption_tests.rs +5 -5
- package/crates/team-agent/src/messaging/tests/dup_inject.rs +3 -3
- package/crates/team-agent/src/messaging/tests/spine.rs +26 -32
- package/crates/team-agent/src/provider/adapter.rs +35 -238
- package/crates/team-agent/src/provider/adapters/mod.rs +4 -4
- package/crates/team-agent/src/provider/model_catalog.rs +13 -201
- package/crates/team-agent/src/provider/session/capture.rs +6 -106
- package/crates/team-agent/src/provider/session/context_fork/outcome.rs +0 -4
- package/crates/team-agent/src/provider/session/context_fork.rs +15 -107
- package/crates/team-agent/src/provider/session_scan/common.rs +10 -34
- package/crates/team-agent/src/provider/session_scan/pi.rs +1 -34
- package/crates/team-agent/src/provider/session_scan.rs +4 -10
- package/crates/team-agent/src/provider/tests/adapter.rs +34 -91
- package/crates/team-agent/src/provider/tests/command_helpers.rs +3 -12
- package/crates/team-agent/src/provider/tests/idle.rs +0 -25
- package/crates/team-agent/src/provider/wire.rs +51 -23
- package/crates/team-agent/src/state/abnormal_watch/tests/mod.rs +1 -1
- package/crates/team-agent/src/state/persist.rs +6 -6
- package/crates/team-agent/src/state/repository/tests.rs +2 -2
- package/package.json +4 -4
- package/skills/team-agent/SKILL.md +6 -4
- package/skills/team-agent/command-coverage.json +15 -1
- package/skills/team-agent/docs/reference/team-agent-operator.md +5 -3
- package/skills/team-agent/references/team-agent-operator.md +5 -3
- package/crates/team-agent/src/lifecycle/restart/avatar.rs +0 -1805
- package/crates/team-agent/src/lifecycle/tests/claude_compatible_config_red.rs +0 -325
- package/crates/team-agent/src/lifecycle/tests/pi_compiler_red.rs +0 -210
- package/crates/team-agent/src/lifecycle/tests/pi_fork_session_inheritance_red.rs +0 -1409
- package/crates/team-agent/src/provider/adapters/claude.rs +0 -78
- package/crates/team-agent/src/provider/adapters/claude_fork.rs +0 -131
- package/crates/team-agent/src/provider/adapters/pi.rs +0 -100
- package/crates/team-agent/src/provider/session/context_fork/claude.rs +0 -123
- package/crates/team-agent/src/provider/session_scan/claude.rs +0 -523
- package/crates/team-agent/src/test_support/models_timeout_fixture.rs +0 -144
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
//! ---
|
|
2
|
-
//! purpose: Pi executable/catalog
|
|
2
|
+
//! purpose: Pi leader 的 executable/catalog 验证、MCP 能力注册与 fresh 启动计划物化
|
|
3
3
|
//! contract:
|
|
4
4
|
//! provides:
|
|
5
5
|
//! - name: materialize_pi_plan
|
|
6
|
-
//! what: 为 leader
|
|
6
|
+
//! what: 为 `team-agent pi` leader 生成 fresh Pi CommandPlan
|
|
7
7
|
//! - name: write_pi_wrapper
|
|
8
8
|
//! what: 原子写入 0600 per-seat runtime MCP registration extension
|
|
9
|
+
//! - name: pi_cleanup_plan
|
|
10
|
+
//! what: 移除升级前遗留的 legacy Pi worker 席位时只删 wrapper
|
|
9
11
|
//! boundary:
|
|
10
|
-
//! -
|
|
11
|
-
//! -
|
|
12
|
+
//! - Pi worker 席位只走 contract `pi_tui` leaf;这里不再 spawn/resume/fork worker
|
|
13
|
+
//! - 不枚举 Pi session;不投递消息、不执行 doctor 判定
|
|
12
14
|
//! - 不读取 credentials 或 provider settings 值
|
|
13
15
|
//! maturity: wired
|
|
14
16
|
//! ---
|
|
@@ -16,18 +18,15 @@
|
|
|
16
18
|
use std::collections::BTreeSet;
|
|
17
19
|
use std::fs::OpenOptions;
|
|
18
20
|
use std::io::Write;
|
|
19
|
-
#[cfg(test)]
|
|
20
|
-
use std::cell::RefCell;
|
|
21
21
|
use std::os::unix::fs::{OpenOptionsExt, PermissionsExt};
|
|
22
22
|
use std::path::{Path, PathBuf};
|
|
23
23
|
use std::process::Command;
|
|
24
|
-
use std::time::Duration;
|
|
25
24
|
|
|
26
25
|
use sha2::{Digest, Sha256};
|
|
27
26
|
|
|
28
27
|
use crate::model::enums::{Provider, ProviderEffort};
|
|
29
|
-
use crate::provider::
|
|
30
|
-
use crate::provider::{CommandPlan, McpConfig, ProviderError
|
|
28
|
+
use crate::provider::command_helpers::{append_opt_pair, append_pair};
|
|
29
|
+
use crate::provider::{CommandPlan, McpConfig, ProviderError};
|
|
31
30
|
|
|
32
31
|
/// The first executable `pi` on PATH, exactly what the worker's bare `pi`
|
|
33
32
|
/// runs: a wrapper, npm symlink or plain binary alike. No inner binary is probed.
|
|
@@ -95,14 +94,6 @@ pub(crate) fn pi_seat_paths(workspace: &Path, team_id: &str, agent_id: &str) ->
|
|
|
95
94
|
}
|
|
96
95
|
}
|
|
97
96
|
|
|
98
|
-
/// ---
|
|
99
|
-
/// purpose: 为 Pi fresh 启动生成框架预分配 UUID
|
|
100
|
-
/// returns: 新 SessionId
|
|
101
|
-
/// ---
|
|
102
|
-
pub(crate) fn new_pi_session_id() -> SessionId {
|
|
103
|
-
SessionId::new(crate::provider::adapter::next_session_token())
|
|
104
|
-
}
|
|
105
|
-
|
|
106
97
|
/// ---
|
|
107
98
|
/// purpose: 解析 pi --list-models 未过滤表格为 provider/model exact ids
|
|
108
99
|
/// returns: 保序且无重复的 exact ids
|
|
@@ -146,20 +137,6 @@ pub(crate) fn select_exact_pi_model(
|
|
|
146
137
|
Ok(selected.clone())
|
|
147
138
|
}
|
|
148
139
|
|
|
149
|
-
/// ---
|
|
150
|
-
/// purpose: 对比选定与启动后客观观测到的 Pi model identity
|
|
151
|
-
/// returns: 完全相等且非空时成功
|
|
152
|
-
/// errors: 缺失或不匹配时返回 ProviderError
|
|
153
|
-
/// ---
|
|
154
|
-
pub(crate) fn verify_started_pi_model(selected: &str, observed: &str) -> Result<(), ProviderError> {
|
|
155
|
-
if observed.is_empty() || selected != observed {
|
|
156
|
-
return Err(ProviderError::Command(format!(
|
|
157
|
-
"Pi started model mismatch: selected={selected:?} observed={observed:?}"
|
|
158
|
-
)));
|
|
159
|
-
}
|
|
160
|
-
Ok(())
|
|
161
|
-
}
|
|
162
|
-
|
|
163
140
|
/// ---
|
|
164
141
|
/// purpose: 校验 Pi PATH entry 与 live catalog;MCP 能力在实际 Pi context 验证
|
|
165
142
|
/// returns: PATH entry 与 catalog receipt 完整时成功
|
|
@@ -464,136 +441,6 @@ fn sha256(bytes: &[u8]) -> String {
|
|
|
464
441
|
format!("{:x}", Sha256::digest(bytes))
|
|
465
442
|
}
|
|
466
443
|
|
|
467
|
-
#[cfg(test)]
|
|
468
|
-
#[derive(Debug, Default)]
|
|
469
|
-
pub(crate) struct PiCatalogTestObservation {
|
|
470
|
-
pub(crate) spawn_count: usize,
|
|
471
|
-
pub(crate) argv: Vec<String>,
|
|
472
|
-
pub(crate) parent_pid: Option<u32>,
|
|
473
|
-
pub(crate) parent_exit_success: Option<bool>,
|
|
474
|
-
pub(crate) parent_exit_code: Option<i32>,
|
|
475
|
-
pub(crate) reader_timeout: bool,
|
|
476
|
-
}
|
|
477
|
-
|
|
478
|
-
#[cfg(test)]
|
|
479
|
-
struct PiCatalogTestContext {
|
|
480
|
-
receipt: PathBuf,
|
|
481
|
-
helper_mode: Option<String>,
|
|
482
|
-
observation: PiCatalogTestObservation,
|
|
483
|
-
}
|
|
484
|
-
|
|
485
|
-
#[cfg(test)]
|
|
486
|
-
thread_local! {
|
|
487
|
-
static PI_CATALOG_TEST_CONTEXT: RefCell<Option<PiCatalogTestContext>> = RefCell::new(None);
|
|
488
|
-
}
|
|
489
|
-
|
|
490
|
-
#[cfg(test)]
|
|
491
|
-
pub(crate) fn with_pi_catalog_test_observation<T>(
|
|
492
|
-
receipt: &Path,
|
|
493
|
-
helper_mode: Option<&str>,
|
|
494
|
-
action: impl FnOnce() -> T,
|
|
495
|
-
) -> (T, PiCatalogTestObservation) {
|
|
496
|
-
PI_CATALOG_TEST_CONTEXT.with(|slot| {
|
|
497
|
-
assert!(slot
|
|
498
|
-
.replace(Some(PiCatalogTestContext {
|
|
499
|
-
receipt: receipt.to_path_buf(),
|
|
500
|
-
helper_mode: helper_mode.map(str::to_owned),
|
|
501
|
-
observation: PiCatalogTestObservation::default(),
|
|
502
|
-
}))
|
|
503
|
-
.is_none());
|
|
504
|
-
let result = action();
|
|
505
|
-
let context = slot.take().expect("Pi catalog test context");
|
|
506
|
-
(result, context.observation)
|
|
507
|
-
})
|
|
508
|
-
}
|
|
509
|
-
|
|
510
|
-
#[cfg(test)]
|
|
511
|
-
fn observe_pi_catalog_test(f: impl FnOnce(&mut PiCatalogTestContext)) {
|
|
512
|
-
PI_CATALOG_TEST_CONTEXT.with(|slot| {
|
|
513
|
-
if let Some(context) = slot.borrow_mut().as_mut() {
|
|
514
|
-
f(context);
|
|
515
|
-
}
|
|
516
|
-
});
|
|
517
|
-
}
|
|
518
|
-
|
|
519
|
-
#[cfg(test)]
|
|
520
|
-
pub(crate) fn run_pi_catalog_after_parent_exit_for_test(
|
|
521
|
-
stdout: std::process::ChildStdout,
|
|
522
|
-
parent_pid: u32,
|
|
523
|
-
status: std::process::ExitStatus,
|
|
524
|
-
timeout: Duration,
|
|
525
|
-
max_bytes: u64,
|
|
526
|
-
) -> Result<Vec<u8>, String> {
|
|
527
|
-
observe_pi_catalog_test(|context| {
|
|
528
|
-
context.observation.parent_pid = Some(parent_pid);
|
|
529
|
-
context.observation.parent_exit_success = Some(status.success());
|
|
530
|
-
context.observation.parent_exit_code = status.code();
|
|
531
|
-
});
|
|
532
|
-
crate::provider::model_catalog::finish_stdout_after_exit(
|
|
533
|
-
stdout, status, timeout, max_bytes, &mut PiCatalogObserver,
|
|
534
|
-
)
|
|
535
|
-
.map_err(|error| error.pi_legacy_message())
|
|
536
|
-
}
|
|
537
|
-
|
|
538
|
-
/// Shared bounded native-command runner; launch preflight keeps its exact model gate.
|
|
539
|
-
pub(crate) fn run_pi_catalog(
|
|
540
|
-
executable: &Path,
|
|
541
|
-
timeout: Duration,
|
|
542
|
-
max_bytes: u64,
|
|
543
|
-
) -> Result<Vec<u8>, String> {
|
|
544
|
-
let mut extra_env = Vec::new();
|
|
545
|
-
#[cfg(test)]
|
|
546
|
-
observe_pi_catalog_test(|context| {
|
|
547
|
-
context.observation.spawn_count += 1;
|
|
548
|
-
context.observation.argv.push("--list-models".to_string());
|
|
549
|
-
extra_env.push(("TEAM_AGENT_MODELS_TIMEOUT_RECEIPT".into(), context.receipt.as_os_str().into()));
|
|
550
|
-
if let Some(mode) = context.helper_mode.as_deref() {
|
|
551
|
-
extra_env.push(("TEAM_AGENT_MODELS_TIMEOUT_MODE".into(), mode.into()));
|
|
552
|
-
}
|
|
553
|
-
});
|
|
554
|
-
crate::provider::model_catalog::run_command(
|
|
555
|
-
executable, &["--list-models"], None, None, &[], &extra_env, timeout, max_bytes,
|
|
556
|
-
&mut PiCatalogObserver,
|
|
557
|
-
)
|
|
558
|
-
.map_err(|error| error.pi_legacy_message())
|
|
559
|
-
}
|
|
560
|
-
|
|
561
|
-
struct PiCatalogObserver;
|
|
562
|
-
impl crate::provider::model_catalog::CatalogObserver for PiCatalogObserver {
|
|
563
|
-
#[cfg(test)]
|
|
564
|
-
fn spawned(&mut self, pid: u32) {
|
|
565
|
-
observe_pi_catalog_test(|context| context.observation.parent_pid = Some(pid));
|
|
566
|
-
}
|
|
567
|
-
|
|
568
|
-
#[cfg(test)]
|
|
569
|
-
fn exited(&mut self, status: &std::process::ExitStatus) {
|
|
570
|
-
observe_pi_catalog_test(|context| {
|
|
571
|
-
context.observation.parent_exit_success = Some(status.success());
|
|
572
|
-
context.observation.parent_exit_code = status.code();
|
|
573
|
-
});
|
|
574
|
-
}
|
|
575
|
-
|
|
576
|
-
#[cfg(test)]
|
|
577
|
-
fn output_timeout(&mut self) {
|
|
578
|
-
observe_pi_catalog_test(|context| context.observation.reader_timeout = true);
|
|
579
|
-
}
|
|
580
|
-
}
|
|
581
|
-
|
|
582
|
-
pub(crate) fn pi_model_candidates(requested: &str) -> Result<Vec<String>, ProviderError> {
|
|
583
|
-
let executable = pi_path_entry()?;
|
|
584
|
-
let catalog = run_pi_catalog(&executable, Duration::from_secs(10), 1024 * 1024)
|
|
585
|
-
.map_err(ProviderError::Command)?;
|
|
586
|
-
let models = parse_pi_list_models_table(&catalog)?;
|
|
587
|
-
Ok(models
|
|
588
|
-
.into_iter()
|
|
589
|
-
.filter(|model| {
|
|
590
|
-
model
|
|
591
|
-
.rsplit_once('/')
|
|
592
|
-
.is_some_and(|(_, name)| name == requested)
|
|
593
|
-
})
|
|
594
|
-
.collect())
|
|
595
|
-
}
|
|
596
|
-
|
|
597
444
|
/// The shell's own PATH choice: the first executable `pi`, kept as found.
|
|
598
445
|
fn pi_path_entry() -> Result<PathBuf, ProviderError> {
|
|
599
446
|
let path = std::env::var_os("PATH")
|
|
@@ -683,34 +530,13 @@ pub(crate) struct PiMaterializeRequest<'a> {
|
|
|
683
530
|
}
|
|
684
531
|
|
|
685
532
|
/// ---
|
|
686
|
-
/// purpose:
|
|
687
|
-
/// returns: fresh Pi CommandPlan 不传 --session-id;isolated
|
|
688
|
-
/// interactive leader preserves Pi's native default root
|
|
533
|
+
/// purpose: 物化 Pi leader 的 wrapper 和 fresh CommandPlan
|
|
534
|
+
/// returns: fresh Pi CommandPlan 不传 --session-id;an isolated leader carries its session root,
|
|
535
|
+
/// while the interactive leader preserves Pi's native default root
|
|
689
536
|
/// errors: resolver、exact model、wrapper 或 argv 构造失败时返回 ProviderError
|
|
690
537
|
/// ---
|
|
691
538
|
pub(crate) fn materialize_pi_plan(
|
|
692
539
|
request: PiMaterializeRequest<'_>,
|
|
693
|
-
) -> Result<CommandPlan, ProviderError> {
|
|
694
|
-
materialize_pi_plan_with_session(request, None)
|
|
695
|
-
}
|
|
696
|
-
|
|
697
|
-
/// ---
|
|
698
|
-
/// purpose: 用上游已验证的 captured id/path 物化 Pi exact-path resume 计划
|
|
699
|
-
/// returns: 与 fresh 共用 resolver/wrapper/argv builder,且不再生成 session id
|
|
700
|
-
/// errors: backing 缺失或越出席位 root 时拒绝;header id/cwd 由 session scanner 在调用前验证
|
|
701
|
-
/// ---
|
|
702
|
-
pub(crate) fn materialize_pi_resume_plan(
|
|
703
|
-
request: PiMaterializeRequest<'_>,
|
|
704
|
-
session_id: &SessionId,
|
|
705
|
-
session_path: &Path,
|
|
706
|
-
spawn_cwd: &Path,
|
|
707
|
-
) -> Result<CommandPlan, ProviderError> {
|
|
708
|
-
materialize_pi_plan_with_session(request, Some((session_id, session_path, spawn_cwd)))
|
|
709
|
-
}
|
|
710
|
-
|
|
711
|
-
fn materialize_pi_plan_with_session(
|
|
712
|
-
request: PiMaterializeRequest<'_>,
|
|
713
|
-
resume: Option<(&SessionId, &Path, &Path)>,
|
|
714
540
|
) -> Result<CommandPlan, ProviderError> {
|
|
715
541
|
let (_chain, catalog) = resolve_pi_executable_chain()?;
|
|
716
542
|
let model = request
|
|
@@ -722,41 +548,10 @@ fn materialize_pi_plan_with_session(
|
|
|
722
548
|
PiSessionScope::Isolated => Some(paths.sessions.as_path()),
|
|
723
549
|
PiSessionScope::NativeDefault => None,
|
|
724
550
|
};
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
ProviderError::
|
|
728
|
-
|
|
729
|
-
paths.sessions.display()
|
|
730
|
-
))
|
|
731
|
-
})?;
|
|
732
|
-
let session_root = std::fs::canonicalize(session_dir).map_err(|error| {
|
|
733
|
-
ProviderError::ResumeUnavailable(format!(
|
|
734
|
-
"Pi session root is unavailable {}: {error}",
|
|
735
|
-
paths.sessions.display()
|
|
736
|
-
))
|
|
737
|
-
})?;
|
|
738
|
-
let exact_path = std::fs::canonicalize(session_path).map_err(|error| {
|
|
739
|
-
ProviderError::ResumeUnavailable(format!(
|
|
740
|
-
"Pi exact session backing is unavailable {}: {error}",
|
|
741
|
-
session_path.display()
|
|
742
|
-
))
|
|
743
|
-
})?;
|
|
744
|
-
if !exact_path.starts_with(&session_root) {
|
|
745
|
-
return Err(ProviderError::ResumeUnavailable(format!(
|
|
746
|
-
"Pi exact session backing is outside the recorded seat root: {}",
|
|
747
|
-
exact_path.display()
|
|
748
|
-
)));
|
|
749
|
-
}
|
|
750
|
-
let _ = spawn_cwd;
|
|
751
|
-
Some((session_id, exact_path))
|
|
752
|
-
} else {
|
|
753
|
-
if let Some(session_dir) = session_dir {
|
|
754
|
-
std::fs::create_dir_all(session_dir).map_err(|error| {
|
|
755
|
-
ProviderError::Io(format!("{}: {error}", session_dir.display()))
|
|
756
|
-
})?;
|
|
757
|
-
}
|
|
758
|
-
None
|
|
759
|
-
};
|
|
551
|
+
if let Some(session_dir) = session_dir {
|
|
552
|
+
std::fs::create_dir_all(session_dir)
|
|
553
|
+
.map_err(|error| ProviderError::Io(format!("{}: {error}", session_dir.display())))?;
|
|
554
|
+
}
|
|
760
555
|
let candidate = candidate_from_mcp_config(request.mcp_config)?;
|
|
761
556
|
let wrapper = write_pi_wrapper(PiWrapperRequest {
|
|
762
557
|
destination: &paths.wrapper,
|
|
@@ -767,33 +562,68 @@ fn materialize_pi_plan_with_session(
|
|
|
767
562
|
workspace: request.workspace,
|
|
768
563
|
include_tools: request.team_mcp_tools,
|
|
769
564
|
})?;
|
|
770
|
-
let
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
agent_id: request.agent_id,
|
|
779
|
-
})?;
|
|
780
|
-
(argv, None)
|
|
781
|
-
} else {
|
|
782
|
-
let argv = build_pi_command_argv(PiCommandRequest {
|
|
783
|
-
extension: &wrapper,
|
|
784
|
-
model: model.as_deref(),
|
|
785
|
-
effort: request.effort,
|
|
786
|
-
system_prompt: request.system_prompt,
|
|
787
|
-
session_dir,
|
|
788
|
-
session: PiSessionSelector::Fresh,
|
|
789
|
-
agent_id: request.agent_id,
|
|
790
|
-
})?;
|
|
791
|
-
(argv, None)
|
|
792
|
-
};
|
|
565
|
+
let argv = build_pi_command_argv(PiCommandRequest {
|
|
566
|
+
extension: &wrapper,
|
|
567
|
+
model: model.as_deref(),
|
|
568
|
+
effort: request.effort,
|
|
569
|
+
system_prompt: request.system_prompt,
|
|
570
|
+
session_dir,
|
|
571
|
+
agent_id: request.agent_id,
|
|
572
|
+
})?;
|
|
793
573
|
Ok(CommandPlan {
|
|
794
574
|
argv,
|
|
795
|
-
expected_session_id,
|
|
575
|
+
expected_session_id: None,
|
|
796
576
|
provider_projects_root: session_dir.map(Path::to_path_buf),
|
|
797
577
|
managed_mcp_config: false,
|
|
798
578
|
})
|
|
799
579
|
}
|
|
580
|
+
|
|
581
|
+
pub(crate) struct PiCommandRequest<'a> {
|
|
582
|
+
pub extension: &'a Path,
|
|
583
|
+
pub model: Option<&'a str>,
|
|
584
|
+
pub effort: Option<ProviderEffort>,
|
|
585
|
+
pub system_prompt: &'a str,
|
|
586
|
+
/// Team-owned session root for an isolated leader; `None` preserves Pi's native default.
|
|
587
|
+
pub session_dir: Option<&'a Path>,
|
|
588
|
+
pub agent_id: &'a str,
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
/// ---
|
|
592
|
+
/// purpose: 从已验证 semantic request 构造仅追加 Team Agent MCP/提示/session root 的 fresh Pi argv
|
|
593
|
+
/// returns: exact ordered argv,argv[0] 固定为裸 `pi`;Pi 自己分配 session id
|
|
594
|
+
/// errors: 必需字段为空时返回 ProviderError
|
|
595
|
+
/// ---
|
|
596
|
+
pub(crate) fn build_pi_command_argv(
|
|
597
|
+
request: PiCommandRequest<'_>,
|
|
598
|
+
) -> Result<Vec<String>, ProviderError> {
|
|
599
|
+
if request.extension.as_os_str().is_empty()
|
|
600
|
+
|| request
|
|
601
|
+
.session_dir
|
|
602
|
+
.is_some_and(|session_dir| session_dir.as_os_str().is_empty())
|
|
603
|
+
|| request.model.is_some_and(|model| model.trim().is_empty())
|
|
604
|
+
|| request.system_prompt.trim().is_empty()
|
|
605
|
+
|| request.agent_id.trim().is_empty()
|
|
606
|
+
{
|
|
607
|
+
return Err(ProviderError::Command(
|
|
608
|
+
"Pi command requires extension, prompt, and agent id".to_string(),
|
|
609
|
+
));
|
|
610
|
+
}
|
|
611
|
+
// The command stays PATH-resolved at spawn time, so a user wrapper runs.
|
|
612
|
+
let mut argv = vec![
|
|
613
|
+
"pi".to_string(),
|
|
614
|
+
"-e".to_string(),
|
|
615
|
+
request.extension.to_string_lossy().into_owned(),
|
|
616
|
+
];
|
|
617
|
+
append_opt_pair(&mut argv, "--model", request.model);
|
|
618
|
+
if let Some(effort) = request.effort {
|
|
619
|
+
argv.push("--thinking".to_string());
|
|
620
|
+
argv.push(effort.as_str().to_string());
|
|
621
|
+
}
|
|
622
|
+
append_pair(&mut argv, "--append-system-prompt", request.system_prompt);
|
|
623
|
+
if let Some(session_dir) = request.session_dir {
|
|
624
|
+
append_pair(&mut argv, "--session-dir", session_dir.to_string_lossy().into_owned());
|
|
625
|
+
}
|
|
626
|
+
// Passing `--session-id` makes Pi warn and then create: Pi names a fresh session.
|
|
627
|
+
append_pair(&mut argv, "--name", request.agent_id);
|
|
628
|
+
Ok(argv)
|
|
629
|
+
}
|
|
@@ -1239,29 +1239,6 @@ pub(crate) fn quick_start_with_transport_in_workspace(
|
|
|
1239
1239
|
yes: bool,
|
|
1240
1240
|
team_id: Option<&str>,
|
|
1241
1241
|
transport: &dyn Transport,
|
|
1242
|
-
) -> Result<QuickStartReport, LifecycleError> {
|
|
1243
|
-
let mut discover = |requested: &str| {
|
|
1244
|
-
crate::lifecycle::launch::pi_mcp::pi_model_candidates(requested).map_err(|_| ())
|
|
1245
|
-
};
|
|
1246
|
-
quick_start_with_transport_in_workspace_pi_preflight(
|
|
1247
|
-
workspace,
|
|
1248
|
-
agents_dir,
|
|
1249
|
-
name,
|
|
1250
|
-
yes,
|
|
1251
|
-
team_id,
|
|
1252
|
-
transport,
|
|
1253
|
-
&mut discover,
|
|
1254
|
-
)
|
|
1255
|
-
}
|
|
1256
|
-
|
|
1257
|
-
pub(crate) fn quick_start_with_transport_in_workspace_pi_preflight(
|
|
1258
|
-
workspace: &Path,
|
|
1259
|
-
agents_dir: &Path,
|
|
1260
|
-
name: Option<&str>,
|
|
1261
|
-
yes: bool,
|
|
1262
|
-
team_id: Option<&str>,
|
|
1263
|
-
transport: &dyn Transport,
|
|
1264
|
-
discover: &mut dyn FnMut(&str) -> Result<Vec<String>, ()>,
|
|
1265
1242
|
) -> Result<QuickStartReport, LifecycleError> {
|
|
1266
1243
|
// B-7 / 036b N38 三行 fail-fast — TEAM_AGENT_LEADER_PANE_ID 主动路径在 quick-start
|
|
1267
1244
|
// 入口验活;死/缺(Dead)的 pane 必须明确报错,不可 silent bind 到 spawner /
|
|
@@ -1277,7 +1254,6 @@ pub(crate) fn quick_start_with_transport_in_workspace_pi_preflight(
|
|
|
1277
1254
|
agents_dir.display()
|
|
1278
1255
|
)));
|
|
1279
1256
|
}
|
|
1280
|
-
crate::lifecycle::launch::run_pi_catalog_preflight(agents_dir, discover)?;
|
|
1281
1257
|
#[cfg(unix)]
|
|
1282
1258
|
{
|
|
1283
1259
|
let input = crate::cli::QuickStartArgs {
|
|
@@ -151,6 +151,11 @@ pub(crate) fn materialize_latest_role(
|
|
|
151
151
|
"name",
|
|
152
152
|
Value::Str(as_agent_id.as_str().to_string()),
|
|
153
153
|
)?;
|
|
154
|
+
// `agent_id` outranks `name` when compiling: the new seat must not keep
|
|
155
|
+
// compiling to the source's id.
|
|
156
|
+
if let Value::Map(pairs) = &mut meta {
|
|
157
|
+
pairs.retain(|(key, _)| key != "agent_id");
|
|
158
|
+
}
|
|
154
159
|
if let Some(label) = label
|
|
155
160
|
.map(strip_label_quotes)
|
|
156
161
|
.filter(|value| !value.is_empty())
|
|
@@ -111,6 +111,17 @@ pub(super) fn spawn_agents(
|
|
|
111
111
|
// persist_spawn_agent_state projects the actual K3 seat separately.
|
|
112
112
|
continue;
|
|
113
113
|
}
|
|
114
|
+
// A pre-upgrade Claude Code or Pi worker spec has no legacy runtime
|
|
115
|
+
// left; refuse before any MCP file, profile or pane side effect.
|
|
116
|
+
if let Some(retired) = agent
|
|
117
|
+
.get("provider")
|
|
118
|
+
.and_then(Value::as_str)
|
|
119
|
+
.filter(|provider| crate::provider::wire::is_retired_provider(provider))
|
|
120
|
+
{
|
|
121
|
+
return Err(LifecycleError::Provider(
|
|
122
|
+
crate::provider::wire::retired_provider_error(retired).into(),
|
|
123
|
+
));
|
|
124
|
+
}
|
|
114
125
|
let agent_id = AgentId::new(agent_id_raw);
|
|
115
126
|
let provider = agent
|
|
116
127
|
.get("provider")
|
|
@@ -144,16 +155,12 @@ pub(super) fn spawn_agents(
|
|
|
144
155
|
.mcp_config(auth_mode)
|
|
145
156
|
.map_err(|e| LifecycleError::Provider(e.to_string()))?;
|
|
146
157
|
let mcp_config = resolve_mcp_config(mcp_config, workspace, agent_id_raw, &mcp_team_id);
|
|
147
|
-
let mcp_config_path =
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
&mcp_config,
|
|
154
|
-
Some(provider),
|
|
155
|
-
)?)
|
|
156
|
-
};
|
|
158
|
+
let mcp_config_path = write_worker_mcp_config_for_provider(
|
|
159
|
+
workspace,
|
|
160
|
+
agent_id_raw,
|
|
161
|
+
&mcp_config,
|
|
162
|
+
Some(provider),
|
|
163
|
+
)?;
|
|
157
164
|
let profile_dir = team_dir.join("profiles");
|
|
158
165
|
let profile_launch =
|
|
159
166
|
crate::lifecycle::profile_launch::prepare_provider_profile_launch_with_profile_dir(
|
|
@@ -189,30 +196,11 @@ pub(super) fn spawn_agents(
|
|
|
189
196
|
agent_id_hint: Some(agent_id_raw),
|
|
190
197
|
effort: agent_effort,
|
|
191
198
|
};
|
|
192
|
-
let mut plan =
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
workspace,
|
|
196
|
-
team_id: &mcp_team_id,
|
|
197
|
-
agent_id: agent_id_raw,
|
|
198
|
-
model: command_model,
|
|
199
|
-
effort: agent_effort,
|
|
200
|
-
system_prompt: &system_prompt,
|
|
201
|
-
team_mcp_tools: &["send_message", "report_result", "get_team_status"],
|
|
202
|
-
mcp_config: &mcp_config,
|
|
203
|
-
session_scope: crate::lifecycle::launch::pi_mcp::PiSessionScope::Isolated,
|
|
204
|
-
},
|
|
205
|
-
)
|
|
206
|
-
.map_err(|e| LifecycleError::Provider(e.to_string()))?
|
|
207
|
-
} else {
|
|
208
|
-
adapter
|
|
209
|
-
.build_command_plan(command_context)
|
|
210
|
-
.map_err(|e| LifecycleError::Provider(e.to_string()))?
|
|
211
|
-
};
|
|
199
|
+
let mut plan = adapter
|
|
200
|
+
.build_command_plan(command_context)
|
|
201
|
+
.map_err(|e| LifecycleError::Provider(e.to_string()))?;
|
|
212
202
|
if !plan.managed_mcp_config && !profile_launch.managed_mcp_config {
|
|
213
|
-
|
|
214
|
-
point_native_mcp_config_at_file(&mut plan.argv, provider, mcp_config_path);
|
|
215
|
-
}
|
|
203
|
+
point_native_mcp_config_at_file(&mut plan.argv, provider, &mcp_config_path);
|
|
216
204
|
}
|
|
217
205
|
// C-A-4 cr verdict v2 — Copilot BYOK(compatible_api)硬性校验:
|
|
218
206
|
// "A model is required for BYOK"(help-providers 原文)。检查 agent
|
|
@@ -23,15 +23,6 @@ use crate::transport::{PaneId, SessionName, Target, Transport, WindowName};
|
|
|
23
23
|
|
|
24
24
|
use crate::lifecycle::lock::{acquire_agent_lifecycle_lock, LifecycleLockRequest};
|
|
25
25
|
|
|
26
|
-
#[derive(Clone, Debug)]
|
|
27
|
-
pub(crate) struct ForkCaptureSeed {
|
|
28
|
-
pub source_agent_id: AgentId,
|
|
29
|
-
pub captured: crate::provider::CapturedSession,
|
|
30
|
-
pub captured_at: String,
|
|
31
|
-
pub pi_sessions_root: PathBuf,
|
|
32
|
-
pub profile_dir: PathBuf,
|
|
33
|
-
}
|
|
34
|
-
|
|
35
26
|
use super::*;
|
|
36
27
|
|
|
37
28
|
// ── lifecycle::launch —— 冷启 / quick-start / 危险审批探测 ──────────────────
|
|
@@ -360,20 +351,6 @@ pub(crate) use mcp_config::{
|
|
|
360
351
|
|
|
361
352
|
pub(crate) mod pi_mcp;
|
|
362
353
|
|
|
363
|
-
pub(crate) fn run_pi_catalog_preflight(
|
|
364
|
-
agents_dir: &std::path::Path,
|
|
365
|
-
discover: &mut dyn FnMut(&str) -> Result<Vec<String>, ()>,
|
|
366
|
-
) -> Result<(), crate::lifecycle::LifecycleError> {
|
|
367
|
-
crate::compiler::preflight_pi_models_in_team_with(agents_dir, discover).map_err(|error| {
|
|
368
|
-
crate::lifecycle::LifecycleError::PiModelPreflight {
|
|
369
|
-
requested: error.requested,
|
|
370
|
-
candidates: error.candidates,
|
|
371
|
-
action: error.action,
|
|
372
|
-
not_ready: error.not_ready,
|
|
373
|
-
}
|
|
374
|
-
})
|
|
375
|
-
}
|
|
376
|
-
|
|
377
354
|
mod worker_env;
|
|
378
355
|
pub(super) use worker_env::*;
|
|
379
356
|
pub(crate) use worker_env::{
|