@team-agent/installer 0.5.126 → 0.5.128
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Cargo.lock +1 -1
- package/Cargo.toml +1 -1
- package/README.md +11 -0
- package/crates/team-agent/src/cli/adapters.rs +3 -13
- package/crates/team-agent/src/cli/arguments.rs +4 -0
- package/crates/team-agent/src/cli/diagnose.rs +68 -91
- package/crates/team-agent/src/cli/emit.rs +61 -28
- package/crates/team-agent/src/cli/grok_slot.rs +88 -3
- package/crates/team-agent/src/cli/intent/runtime.rs +38 -9
- package/crates/team-agent/src/cli/intent/runtime_tests.rs +147 -11
- package/crates/team-agent/src/cli/intent/tests.rs +10 -12
- package/crates/team-agent/src/cli/intent.rs +1 -1
- package/crates/team-agent/src/cli/mod.rs +38 -9
- package/crates/team-agent/src/cli/models.rs +789 -186
- package/crates/team-agent/src/cli/schedule.rs +175 -0
- package/crates/team-agent/src/cli/send/persist.rs +0 -36
- package/crates/team-agent/src/cli/send/presentation.rs +1 -1
- package/crates/team-agent/src/cli/send.rs +108 -110
- package/crates/team-agent/src/cli/spec.rs +6 -0
- package/crates/team-agent/src/cli/status_port/brief.rs +5 -67
- package/crates/team-agent/src/cli/tests/leader_watch.rs +12 -62
- package/crates/team-agent/src/cli/tests/mod.rs +3 -3
- package/crates/team-agent/src/cli/tests/named_address.rs +11 -10
- package/crates/team-agent/src/cli/tests/run_delegation.rs +12 -9
- package/crates/team-agent/src/cli/tests/status_send.rs +70 -273
- package/crates/team-agent/src/compiler/tests.rs +39 -27
- package/crates/team-agent/src/compiler.rs +206 -6
- package/crates/team-agent/src/contract_runtime/backend.rs +181 -11
- package/crates/team-agent/src/contract_runtime/commands.rs +338 -7
- package/crates/team-agent/src/contract_runtime/config.rs +30 -19
- package/crates/team-agent/src/contract_runtime/config_tests.rs +24 -4
- package/crates/team-agent/src/contract_runtime/discovery.rs +12 -1
- package/crates/team-agent/src/contract_runtime/fork.rs +3 -10
- package/crates/team-agent/src/contract_runtime/framework.rs +28 -14
- package/crates/team-agent/src/contract_runtime/mcp.rs +19 -24
- package/crates/team-agent/src/contract_runtime/prompt.rs +2 -2
- package/crates/team-agent/src/contract_runtime/registry.rs +93 -130
- package/crates/team-agent/src/coordinator/steps/abnormal.rs +45 -5
- package/crates/team-agent/src/coordinator/tests/api_error_recovery.rs +8 -29
- package/crates/team-agent/src/coordinator/tests/energy.rs +4 -4
- package/crates/team-agent/src/coordinator/tests/health_sync.rs +44 -2
- package/crates/team-agent/src/coordinator/tests/main_preserved.rs +2 -2
- package/crates/team-agent/src/coordinator/tests/spine.rs +1 -1
- package/crates/team-agent/src/coordinator/tests/takeover.rs +3 -3
- package/crates/team-agent/src/coordinator/tick.rs +1 -89
- package/crates/team-agent/src/db/message_store.rs +7 -65
- package/crates/team-agent/src/direct_delivery.rs +368 -0
- package/crates/team-agent/src/inbox_store.rs +169 -0
- package/crates/team-agent/src/leader/registry.rs +5 -0
- package/crates/team-agent/src/leader/start.rs +2 -1
- package/crates/team-agent/src/leader/tests/lease_api.rs +2 -2
- package/crates/team-agent/src/leader/tests/prompt_contract.rs +1 -0
- package/crates/team-agent/src/lib.rs +2 -0
- package/crates/team-agent/src/lifecycle/launch/add_agent.rs +33 -0
- package/crates/team-agent/src/lifecycle/launch/add_agent_state.rs +206 -1
- package/crates/team-agent/src/lifecycle/launch/clone_agent.rs +28 -2
- package/crates/team-agent/src/lifecycle/launch/fork_agent.rs +36 -179
- package/crates/team-agent/src/lifecycle/launch/fork_entry.rs +87 -6
- package/crates/team-agent/src/lifecycle/launch/mcp_config.rs +13 -488
- package/crates/team-agent/src/lifecycle/launch/pi_mcp.rs +351 -81
- package/crates/team-agent/src/lifecycle/launch/pi_mcp_extension.js +3 -4
- package/crates/team-agent/src/lifecycle/launch/quick_start.rs +26 -2
- package/crates/team-agent/src/lifecycle/launch/spawn.rs +41 -31
- package/crates/team-agent/src/lifecycle/launch.rs +27 -12
- package/crates/team-agent/src/lifecycle/profile_launch.rs +318 -64
- package/crates/team-agent/src/lifecycle/restart/agent.rs +1 -0
- package/crates/team-agent/src/lifecycle/restart/avatar.rs +1798 -0
- package/crates/team-agent/src/lifecycle/restart/claude_fork.rs +163 -0
- package/crates/team-agent/src/lifecycle/restart/common.rs +298 -133
- package/crates/team-agent/src/lifecycle/restart/remove.rs +129 -0
- package/crates/team-agent/src/lifecycle/restart/selection.rs +5 -5
- package/crates/team-agent/src/lifecycle/restart.rs +4 -0
- package/crates/team-agent/src/lifecycle/role_config.rs +79 -27
- package/crates/team-agent/src/lifecycle/tests/acceptance_b_batch_red.rs +1 -1
- package/crates/team-agent/src/lifecycle/tests/agent_ops.rs +8 -12
- package/crates/team-agent/src/lifecycle/tests/behavioral_diff_264_red.rs +37 -240
- package/crates/team-agent/src/lifecycle/tests/claude_compatible_config_red.rs +325 -0
- package/crates/team-agent/src/lifecycle/tests/claude_profile_launch_red.rs +320 -8
- package/crates/team-agent/src/lifecycle/tests/cli_argv_routing_red.rs +329 -70
- package/crates/team-agent/src/lifecycle/tests/clone_fork_copilot_perms_red.rs +378 -4
- package/crates/team-agent/src/lifecycle/tests/communication_mode_runtime_contract_red.rs +25 -39
- package/crates/team-agent/src/lifecycle/tests/copilot_provider_red.rs +7 -11
- package/crates/team-agent/src/lifecycle/tests/core.rs +39 -36
- package/crates/team-agent/src/lifecycle/tests/f032_startup_prompt_best_effort_red.rs +22 -8
- package/crates/team-agent/src/lifecycle/tests/fixtures/pi_native_mcp_host.mjs +2 -1
- package/crates/team-agent/src/lifecycle/tests/grok_require_explicit_model_red.rs +15 -133
- package/crates/team-agent/src/lifecycle/tests/harvest2_a_batch_red.rs +60 -20
- package/crates/team-agent/src/lifecycle/tests/host_cotenant_death_p0_contract.rs +30 -67
- package/crates/team-agent/src/lifecycle/tests/issue238_codex_effort_contract.rs +3 -31
- package/crates/team-agent/src/lifecycle/tests/lane_ops.rs +194 -169
- package/crates/team-agent/src/lifecycle/tests/launch_spawn.rs +164 -282
- package/crates/team-agent/src/lifecycle/tests/lifecycle_rollback_red.rs +15 -78
- package/crates/team-agent/src/lifecycle/tests/main_preserved.rs +7 -7
- package/crates/team-agent/src/lifecycle/tests/mcp_tool_name_format_red.rs +6 -6
- package/crates/team-agent/src/lifecycle/tests/phase_b_contracts.rs +75 -69
- package/crates/team-agent/src/lifecycle/tests/phase_golden.rs +2 -10
- package/crates/team-agent/src/lifecycle/tests/pi_catalog_red.rs +18 -6
- package/crates/team-agent/src/lifecycle/tests/pi_command_red.rs +70 -52
- package/crates/team-agent/src/lifecycle/tests/pi_compiler_red.rs +210 -0
- package/crates/team-agent/src/lifecycle/tests/pi_dual_entry_red.rs +157 -4
- package/crates/team-agent/src/lifecycle/tests/pi_executable_mcp_red.rs +526 -10
- package/crates/team-agent/src/lifecycle/tests/pi_fork_session_inheritance_red.rs +1419 -0
- package/crates/team-agent/src/lifecycle/tests/pi_lifecycle_doctor_red.rs +68 -1
- package/crates/team-agent/src/lifecycle/tests/pi_native_mcp_capability_red.rs +34 -12
- package/crates/team-agent/src/lifecycle/tests/pi_session_delivery_red.rs +94 -2
- package/crates/team-agent/src/lifecycle/tests/quick_start_worker_readiness_red.rs +14 -15
- package/crates/team-agent/src/lifecycle/tests/restart.rs +12 -153
- package/crates/team-agent/src/lifecycle/tests/restart_build_before_destroy_0540_contract.rs +27 -5
- package/crates/team-agent/src/lifecycle/tests/restart_liveness_red.rs +59 -10
- package/crates/team-agent/src/lifecycle/tests/restart_rebind_hotfix_252_red.rs +47 -6
- package/crates/team-agent/src/lifecycle/tests/restart_session_capture_red.rs +3 -1374
- package/crates/team-agent/src/lifecycle/tests/resume_recover_red.rs +27 -10
- package/crates/team-agent/src/lifecycle/tests/status_credential_redaction_contract.rs +7 -7
- package/crates/team-agent/src/lifecycle/tests/subprep_codex_trust_roundtrip_red.rs +67 -313
- package/crates/team-agent/src/lifecycle/tests/swallow_batch4_semantics_red.rs +254 -2
- package/crates/team-agent/src/lifecycle/tests/team_in_team_identity_scope_red.rs +2 -2
- package/crates/team-agent/src/lifecycle/tests/team_in_team_sibling_quick_start_red.rs +1 -1
- package/crates/team-agent/src/lifecycle/tests/team_in_team_state_scope_red.rs +2 -2
- package/crates/team-agent/src/lifecycle/tests/team_key_retirement_txn_red.rs +4 -4
- package/crates/team-agent/src/lifecycle/tests/upgrade_compat_0211_red.rs +74 -19
- package/crates/team-agent/src/lifecycle/tests/verify_rs031_window_consistency_red.rs +38 -39
- package/crates/team-agent/src/lifecycle/tests/worker_spawn_env_red.rs +51 -88
- package/crates/team-agent/src/lifecycle/tests.rs +3 -4
- package/crates/team-agent/src/lifecycle/types.rs +18 -5
- package/crates/team-agent/src/lifecycle/worker_command_context.rs +43 -50
- package/crates/team-agent/src/mcp_server/readiness.rs +130 -149
- package/crates/team-agent/src/mcp_server/readiness_tests.rs +86 -109
- package/crates/team-agent/src/mcp_server/tests/scoped.rs +21 -31
- package/crates/team-agent/src/mcp_server/tests/send.rs +72 -107
- package/crates/team-agent/src/mcp_server/tests/tools.rs +10 -12
- package/crates/team-agent/src/mcp_server/tools.rs +70 -196
- package/crates/team-agent/src/messaging/delivery.rs +143 -253
- package/crates/team-agent/src/messaging/delivery_consumption_tests.rs +5 -5
- package/crates/team-agent/src/messaging/helpers.rs +1 -19
- package/crates/team-agent/src/messaging/mod.rs +1 -0
- package/crates/team-agent/src/messaging/reminders.rs +316 -0
- package/crates/team-agent/src/messaging/scheduler.rs +7 -1
- package/crates/team-agent/src/messaging/tests/dup_inject.rs +255 -150
- package/crates/team-agent/src/messaging/tests/main_preserved.rs +2 -2
- package/crates/team-agent/src/messaging/tests/runtime.rs +9 -115
- package/crates/team-agent/src/messaging/tests/spine.rs +44 -24
- package/crates/team-agent/src/messaging/tests/wave2.rs +13 -20
- package/crates/team-agent/src/messaging/types.rs +1 -0
- package/crates/team-agent/src/provider/adapter.rs +208 -254
- package/crates/team-agent/src/provider/adapters/claude.rs +78 -0
- package/crates/team-agent/src/provider/adapters/claude_fork.rs +131 -0
- package/crates/team-agent/src/provider/adapters/mod.rs +7 -7
- package/crates/team-agent/src/provider/adapters/pi.rs +106 -0
- package/crates/team-agent/src/provider/classify.rs +1 -66
- package/crates/team-agent/src/provider/model_catalog.rs +201 -13
- package/crates/team-agent/src/provider/session/capture.rs +111 -111
- package/crates/team-agent/src/provider/session/context_fork/claude.rs +123 -0
- package/crates/team-agent/src/provider/session/context_fork/outcome.rs +10 -18
- package/crates/team-agent/src/provider/session/context_fork.rs +87 -74
- package/crates/team-agent/src/provider/session/mod.rs +2 -3
- package/crates/team-agent/src/provider/session_scan/claude.rs +523 -0
- package/crates/team-agent/src/provider/session_scan/common.rs +47 -47
- package/crates/team-agent/src/provider/session_scan/pi.rs +34 -1
- package/crates/team-agent/src/provider/session_scan.rs +13 -13
- package/crates/team-agent/src/provider/tests/adapter.rs +127 -121
- package/crates/team-agent/src/provider/tests/classify.rs +0 -53
- package/crates/team-agent/src/provider/tests/command_helpers.rs +11 -19
- package/crates/team-agent/src/provider/tests/idle.rs +13 -19
- package/crates/team-agent/src/provider/types.rs +0 -4
- package/crates/team-agent/src/provider/wire.rs +34 -20
- package/crates/team-agent/src/state/abnormal_watch/tests/mod.rs +1 -1
- package/crates/team-agent/src/state/persist.rs +6 -6
- package/crates/team-agent/src/state/projection.rs +1 -1
- package/crates/team-agent/src/state/repository/tests.rs +2 -2
- package/crates/team-agent/src/test_support/models_timeout_fixture.rs +144 -0
- package/crates/team-agent/src/tmux_backend/tests.rs +0 -151
- package/crates/team-agent/src/tmux_backend.rs +9 -43
- package/package.json +4 -4
- package/skills/team-agent/SKILL.md +7 -8
- package/skills/team-agent/command-coverage.json +15 -1
- package/skills/team-agent/docs/reference/team-agent-operator.md +5 -3
- package/skills/team-agent/references/team-agent-operator.md +5 -3
- package/crates/team-agent/src/lifecycle/launch/grok_per_seat.rs +0 -260
- package/crates/team-agent/src/lifecycle/tests/codex_weak_window_attribution_red.rs +0 -683
- package/crates/team-agent/src/lifecycle/tests/grok_effort_argv_red.rs +0 -247
- package/crates/team-agent/src/lifecycle/tests/grok_mcp_overlay_red.rs +0 -507
- package/crates/team-agent/src/lifecycle/tests/grok_restart_resume_red.rs +0 -300
- package/crates/team-agent/src/provider/adapters/codex.rs +0 -101
- package/crates/team-agent/src/provider/adapters/grok.rs +0 -67
- package/crates/team-agent/src/provider/session/context_fork/codex.rs +0 -514
- package/crates/team-agent/src/provider/session_scan/codex.rs +0 -326
- package/crates/team-agent/src/provider/session_scan/grok.rs +0 -288
|
@@ -1,32 +1,33 @@
|
|
|
1
1
|
//! ---
|
|
2
|
-
//! purpose: Pi
|
|
2
|
+
//! purpose: Pi executable/catalog 验证、原生/公共 MCP 能力注册与共享启动计划物化
|
|
3
3
|
//! contract:
|
|
4
4
|
//! provides:
|
|
5
5
|
//! - name: materialize_pi_plan
|
|
6
|
-
//! what: 为
|
|
6
|
+
//! what: 为 leader 与 TeamMate 生成同一来源的 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
|
|
11
9
|
//! boundary:
|
|
12
|
-
//! - Pi
|
|
13
|
-
//! -
|
|
14
|
-
//! -
|
|
10
|
+
//! - 不枚举 Pi session;resume 只重验调用方给出的 exact backing
|
|
11
|
+
//! - 不投递消息、不执行 cleanup 或 doctor 判定
|
|
12
|
+
//! - 仅读取 settings.json 的 sessionDir,不读取 credentials
|
|
15
13
|
//! maturity: wired
|
|
16
14
|
//! ---
|
|
17
15
|
|
|
18
16
|
use std::collections::BTreeSet;
|
|
19
17
|
use std::fs::OpenOptions;
|
|
20
18
|
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;
|
|
24
25
|
|
|
25
26
|
use sha2::{Digest, Sha256};
|
|
26
27
|
|
|
27
28
|
use crate::model::enums::{Provider, ProviderEffort};
|
|
28
|
-
use crate::provider::
|
|
29
|
-
use crate::provider::{CommandPlan, McpConfig, ProviderError};
|
|
29
|
+
use crate::provider::adapters::pi::{build_pi_command_argv, PiCommandRequest, PiSessionSelector};
|
|
30
|
+
use crate::provider::{CommandPlan, McpConfig, ProviderError, SessionId};
|
|
30
31
|
|
|
31
32
|
/// The first executable `pi` on PATH, exactly what the worker's bare `pi`
|
|
32
33
|
/// runs: a wrapper, npm symlink or plain binary alike. No inner binary is probed.
|
|
@@ -87,13 +88,89 @@ pub(crate) fn pi_seat_paths(workspace: &Path, team_id: &str, agent_id: &str) ->
|
|
|
87
88
|
.join("pi")
|
|
88
89
|
.join(team_id)
|
|
89
90
|
.join(agent_id);
|
|
91
|
+
let workspace = workspace
|
|
92
|
+
.canonicalize()
|
|
93
|
+
.unwrap_or_else(|_| workspace.to_path_buf());
|
|
94
|
+
// Match Pi's getDefaultSessionDir: sessions/--<encoded absolute cwd>--.
|
|
95
|
+
// Identity comes from --session-id, not a private per-seat directory.
|
|
96
|
+
let sessions = if let Some(value) =
|
|
97
|
+
std::env::var_os("PI_CODING_AGENT_SESSION_DIR").filter(|value| !value.is_empty())
|
|
98
|
+
{
|
|
99
|
+
resolve_pi_path(&workspace, Path::new(&value))
|
|
100
|
+
} else {
|
|
101
|
+
let agent_dir = std::env::var_os("PI_CODING_AGENT_DIR")
|
|
102
|
+
.filter(|value| !value.is_empty())
|
|
103
|
+
.map(PathBuf::from)
|
|
104
|
+
.unwrap_or_else(|| std::env::home_dir().unwrap_or_default().join(".pi/agent"));
|
|
105
|
+
let agent_dir = resolve_pi_path(&workspace, &agent_dir);
|
|
106
|
+
// Pi reads sessionDir before project trust. A present project value
|
|
107
|
+
// shadows the global value, including an empty/null value (default).
|
|
108
|
+
let setting = [
|
|
109
|
+
workspace.join(".pi/settings.json"),
|
|
110
|
+
agent_dir.join("settings.json"),
|
|
111
|
+
]
|
|
112
|
+
.into_iter()
|
|
113
|
+
.find_map(|path| {
|
|
114
|
+
let value: serde_json::Value =
|
|
115
|
+
serde_json::from_slice(&std::fs::read(path).ok()?).ok()?;
|
|
116
|
+
value.get("sessionDir").cloned()
|
|
117
|
+
});
|
|
118
|
+
if let Some(path) = setting
|
|
119
|
+
.as_ref()
|
|
120
|
+
.and_then(serde_json::Value::as_str)
|
|
121
|
+
.filter(|path| !path.is_empty())
|
|
122
|
+
{
|
|
123
|
+
resolve_pi_path(&workspace, Path::new(path))
|
|
124
|
+
} else {
|
|
125
|
+
let encoded = workspace.to_string_lossy();
|
|
126
|
+
let encoded = encoded
|
|
127
|
+
.strip_prefix(['/', '\\'])
|
|
128
|
+
.unwrap_or(&encoded)
|
|
129
|
+
.replace(['/', '\\', ':'], "-");
|
|
130
|
+
agent_dir.join("sessions").join(format!("--{encoded}--"))
|
|
131
|
+
}
|
|
132
|
+
};
|
|
90
133
|
PiSeatPaths {
|
|
91
134
|
wrapper: runtime_root.join("team-mcp.ts"),
|
|
92
|
-
sessions
|
|
135
|
+
sessions,
|
|
93
136
|
runtime_root,
|
|
94
137
|
}
|
|
95
138
|
}
|
|
96
139
|
|
|
140
|
+
fn resolve_pi_path(workspace: &Path, path: &Path) -> PathBuf {
|
|
141
|
+
let home = std::env::home_dir().unwrap_or_default();
|
|
142
|
+
let path = path
|
|
143
|
+
.strip_prefix("~")
|
|
144
|
+
.map(|tail| home.join(tail))
|
|
145
|
+
.unwrap_or_else(|_| path.to_path_buf());
|
|
146
|
+
let path = if path.is_absolute() {
|
|
147
|
+
path
|
|
148
|
+
} else {
|
|
149
|
+
workspace.join(path)
|
|
150
|
+
};
|
|
151
|
+
// Canonicalize existing parents too (e.g. macOS /var), even for new roots.
|
|
152
|
+
if let Ok(canonical) = path.canonicalize() {
|
|
153
|
+
return canonical;
|
|
154
|
+
}
|
|
155
|
+
path.ancestors()
|
|
156
|
+
.skip(1)
|
|
157
|
+
.find_map(|ancestor| {
|
|
158
|
+
ancestor
|
|
159
|
+
.canonicalize()
|
|
160
|
+
.ok()
|
|
161
|
+
.map(|base| base.join(path.strip_prefix(ancestor).expect("ancestor prefix")))
|
|
162
|
+
})
|
|
163
|
+
.unwrap_or(path)
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/// ---
|
|
167
|
+
/// purpose: 为 Pi fresh 启动生成框架预分配 UUID
|
|
168
|
+
/// returns: 新 SessionId
|
|
169
|
+
/// ---
|
|
170
|
+
pub(crate) fn new_pi_session_id() -> SessionId {
|
|
171
|
+
SessionId::new(crate::provider::adapter::next_session_token())
|
|
172
|
+
}
|
|
173
|
+
|
|
97
174
|
/// ---
|
|
98
175
|
/// purpose: 解析 pi --list-models 未过滤表格为 provider/model exact ids
|
|
99
176
|
/// returns: 保序且无重复的 exact ids
|
|
@@ -137,6 +214,20 @@ pub(crate) fn select_exact_pi_model(
|
|
|
137
214
|
Ok(selected.clone())
|
|
138
215
|
}
|
|
139
216
|
|
|
217
|
+
/// ---
|
|
218
|
+
/// purpose: 对比选定与启动后客观观测到的 Pi model identity
|
|
219
|
+
/// returns: 完全相等且非空时成功
|
|
220
|
+
/// errors: 缺失或不匹配时返回 ProviderError
|
|
221
|
+
/// ---
|
|
222
|
+
pub(crate) fn verify_started_pi_model(selected: &str, observed: &str) -> Result<(), ProviderError> {
|
|
223
|
+
if observed.is_empty() || selected != observed {
|
|
224
|
+
return Err(ProviderError::Command(format!(
|
|
225
|
+
"Pi started model mismatch: selected={selected:?} observed={observed:?}"
|
|
226
|
+
)));
|
|
227
|
+
}
|
|
228
|
+
Ok(())
|
|
229
|
+
}
|
|
230
|
+
|
|
140
231
|
/// ---
|
|
141
232
|
/// purpose: 校验 Pi PATH entry 与 live catalog;MCP 能力在实际 Pi context 验证
|
|
142
233
|
/// returns: PATH entry 与 catalog receipt 完整时成功
|
|
@@ -389,17 +480,19 @@ pub(crate) fn write_pi_wrapper_with_publish(
|
|
|
389
480
|
pub(crate) struct PiLeaderArgs {
|
|
390
481
|
pub model: Option<String>,
|
|
391
482
|
pub effort: Option<ProviderEffort>,
|
|
483
|
+
pub session_dir: Option<PathBuf>,
|
|
392
484
|
}
|
|
393
485
|
|
|
394
486
|
/// ---
|
|
395
|
-
/// purpose: 解析 Pi leader
|
|
396
|
-
/// returns:
|
|
487
|
+
/// purpose: 解析 Pi leader 的 native model/thinking/session-dir 输入
|
|
488
|
+
/// returns: 调用方显式给出的 qualified model、effort 与 session directory
|
|
397
489
|
/// errors: 重复、未知或 materializer-owned flag 时返回 ProviderError
|
|
398
490
|
/// ---
|
|
399
491
|
pub(crate) fn parse_pi_leader_args(args: &[String]) -> Result<PiLeaderArgs, ProviderError> {
|
|
400
492
|
let args = args.strip_prefix(&["--".to_string()]).unwrap_or(args);
|
|
401
493
|
let mut model = None;
|
|
402
494
|
let mut effort = None;
|
|
495
|
+
let mut session_dir = None;
|
|
403
496
|
let mut index = 0;
|
|
404
497
|
while index < args.len() {
|
|
405
498
|
let flag = args[index].as_str();
|
|
@@ -408,6 +501,9 @@ pub(crate) fn parse_pi_leader_args(args: &[String]) -> Result<PiLeaderArgs, Prov
|
|
|
408
501
|
})?;
|
|
409
502
|
match flag {
|
|
410
503
|
"--model" if model.is_none() => model = Some(value.clone()),
|
|
504
|
+
"--session-dir" if session_dir.is_none() && !value.is_empty() => {
|
|
505
|
+
session_dir = Some(PathBuf::from(value));
|
|
506
|
+
}
|
|
411
507
|
"--thinking" if effort.is_none() => {
|
|
412
508
|
let parsed = ProviderEffort::parse(value).ok_or_else(|| {
|
|
413
509
|
ProviderError::Command(format!("unknown Pi thinking effort {value:?}"))
|
|
@@ -418,7 +514,7 @@ pub(crate) fn parse_pi_leader_args(args: &[String]) -> Result<PiLeaderArgs, Prov
|
|
|
418
514
|
}
|
|
419
515
|
_ => {
|
|
420
516
|
return Err(ProviderError::Command(format!(
|
|
421
|
-
"Pi leader accepts
|
|
517
|
+
"Pi leader accepts one --model, --thinking and --session-dir; got {flag:?}"
|
|
422
518
|
)));
|
|
423
519
|
}
|
|
424
520
|
}
|
|
@@ -434,13 +530,147 @@ pub(crate) fn parse_pi_leader_args(args: &[String]) -> Result<PiLeaderArgs, Prov
|
|
|
434
530
|
"Pi leader --model must be a qualified exact id".to_string(),
|
|
435
531
|
));
|
|
436
532
|
}
|
|
437
|
-
Ok(PiLeaderArgs {
|
|
533
|
+
Ok(PiLeaderArgs {
|
|
534
|
+
model,
|
|
535
|
+
effort,
|
|
536
|
+
session_dir,
|
|
537
|
+
})
|
|
438
538
|
}
|
|
439
539
|
|
|
440
540
|
fn sha256(bytes: &[u8]) -> String {
|
|
441
541
|
format!("{:x}", Sha256::digest(bytes))
|
|
442
542
|
}
|
|
443
543
|
|
|
544
|
+
#[cfg(test)]
|
|
545
|
+
#[derive(Debug, Default)]
|
|
546
|
+
pub(crate) struct PiCatalogTestObservation {
|
|
547
|
+
pub(crate) spawn_count: usize,
|
|
548
|
+
pub(crate) argv: Vec<String>,
|
|
549
|
+
pub(crate) parent_pid: Option<u32>,
|
|
550
|
+
pub(crate) parent_exit_success: Option<bool>,
|
|
551
|
+
pub(crate) parent_exit_code: Option<i32>,
|
|
552
|
+
pub(crate) reader_timeout: bool,
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
#[cfg(test)]
|
|
556
|
+
struct PiCatalogTestContext {
|
|
557
|
+
receipt: PathBuf,
|
|
558
|
+
helper_mode: Option<String>,
|
|
559
|
+
observation: PiCatalogTestObservation,
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
#[cfg(test)]
|
|
563
|
+
thread_local! {
|
|
564
|
+
static PI_CATALOG_TEST_CONTEXT: RefCell<Option<PiCatalogTestContext>> = RefCell::new(None);
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
#[cfg(test)]
|
|
568
|
+
pub(crate) fn with_pi_catalog_test_observation<T>(
|
|
569
|
+
receipt: &Path,
|
|
570
|
+
helper_mode: Option<&str>,
|
|
571
|
+
action: impl FnOnce() -> T,
|
|
572
|
+
) -> (T, PiCatalogTestObservation) {
|
|
573
|
+
PI_CATALOG_TEST_CONTEXT.with(|slot| {
|
|
574
|
+
assert!(slot
|
|
575
|
+
.replace(Some(PiCatalogTestContext {
|
|
576
|
+
receipt: receipt.to_path_buf(),
|
|
577
|
+
helper_mode: helper_mode.map(str::to_owned),
|
|
578
|
+
observation: PiCatalogTestObservation::default(),
|
|
579
|
+
}))
|
|
580
|
+
.is_none());
|
|
581
|
+
let result = action();
|
|
582
|
+
let context = slot.take().expect("Pi catalog test context");
|
|
583
|
+
(result, context.observation)
|
|
584
|
+
})
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
#[cfg(test)]
|
|
588
|
+
fn observe_pi_catalog_test(f: impl FnOnce(&mut PiCatalogTestContext)) {
|
|
589
|
+
PI_CATALOG_TEST_CONTEXT.with(|slot| {
|
|
590
|
+
if let Some(context) = slot.borrow_mut().as_mut() {
|
|
591
|
+
f(context);
|
|
592
|
+
}
|
|
593
|
+
});
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
#[cfg(test)]
|
|
597
|
+
pub(crate) fn run_pi_catalog_after_parent_exit_for_test(
|
|
598
|
+
stdout: std::process::ChildStdout,
|
|
599
|
+
parent_pid: u32,
|
|
600
|
+
status: std::process::ExitStatus,
|
|
601
|
+
timeout: Duration,
|
|
602
|
+
max_bytes: u64,
|
|
603
|
+
) -> Result<Vec<u8>, String> {
|
|
604
|
+
observe_pi_catalog_test(|context| {
|
|
605
|
+
context.observation.parent_pid = Some(parent_pid);
|
|
606
|
+
context.observation.parent_exit_success = Some(status.success());
|
|
607
|
+
context.observation.parent_exit_code = status.code();
|
|
608
|
+
});
|
|
609
|
+
crate::provider::model_catalog::finish_stdout_after_exit(
|
|
610
|
+
stdout, status, timeout, max_bytes, &mut PiCatalogObserver,
|
|
611
|
+
)
|
|
612
|
+
.map_err(|error| error.pi_legacy_message())
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
/// Shared bounded native-command runner; launch preflight keeps its exact model gate.
|
|
616
|
+
pub(crate) fn run_pi_catalog(
|
|
617
|
+
executable: &Path,
|
|
618
|
+
timeout: Duration,
|
|
619
|
+
max_bytes: u64,
|
|
620
|
+
) -> Result<Vec<u8>, String> {
|
|
621
|
+
let mut extra_env = Vec::new();
|
|
622
|
+
#[cfg(test)]
|
|
623
|
+
observe_pi_catalog_test(|context| {
|
|
624
|
+
context.observation.spawn_count += 1;
|
|
625
|
+
context.observation.argv.push("--list-models".to_string());
|
|
626
|
+
extra_env.push(("TEAM_AGENT_MODELS_TIMEOUT_RECEIPT".into(), context.receipt.as_os_str().into()));
|
|
627
|
+
if let Some(mode) = context.helper_mode.as_deref() {
|
|
628
|
+
extra_env.push(("TEAM_AGENT_MODELS_TIMEOUT_MODE".into(), mode.into()));
|
|
629
|
+
}
|
|
630
|
+
});
|
|
631
|
+
crate::provider::model_catalog::run_command(
|
|
632
|
+
executable, &["--list-models"], None, None, &[], &extra_env, timeout, max_bytes,
|
|
633
|
+
&mut PiCatalogObserver,
|
|
634
|
+
)
|
|
635
|
+
.map_err(|error| error.pi_legacy_message())
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
struct PiCatalogObserver;
|
|
639
|
+
impl crate::provider::model_catalog::CatalogObserver for PiCatalogObserver {
|
|
640
|
+
#[cfg(test)]
|
|
641
|
+
fn spawned(&mut self, pid: u32) {
|
|
642
|
+
observe_pi_catalog_test(|context| context.observation.parent_pid = Some(pid));
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
#[cfg(test)]
|
|
646
|
+
fn exited(&mut self, status: &std::process::ExitStatus) {
|
|
647
|
+
observe_pi_catalog_test(|context| {
|
|
648
|
+
context.observation.parent_exit_success = Some(status.success());
|
|
649
|
+
context.observation.parent_exit_code = status.code();
|
|
650
|
+
});
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
#[cfg(test)]
|
|
654
|
+
fn output_timeout(&mut self) {
|
|
655
|
+
observe_pi_catalog_test(|context| context.observation.reader_timeout = true);
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
|
|
659
|
+
pub(crate) fn pi_model_candidates(requested: &str) -> Result<Vec<String>, ProviderError> {
|
|
660
|
+
let executable = pi_path_entry()?;
|
|
661
|
+
let catalog = run_pi_catalog(&executable, Duration::from_secs(10), 1024 * 1024)
|
|
662
|
+
.map_err(ProviderError::Command)?;
|
|
663
|
+
let models = parse_pi_list_models_table(&catalog)?;
|
|
664
|
+
Ok(models
|
|
665
|
+
.into_iter()
|
|
666
|
+
.filter(|model| {
|
|
667
|
+
model
|
|
668
|
+
.rsplit_once('/')
|
|
669
|
+
.is_some_and(|(_, name)| name == requested)
|
|
670
|
+
})
|
|
671
|
+
.collect())
|
|
672
|
+
}
|
|
673
|
+
|
|
444
674
|
/// The shell's own PATH choice: the first executable `pi`, kept as found.
|
|
445
675
|
fn pi_path_entry() -> Result<PathBuf, ProviderError> {
|
|
446
676
|
let path = std::env::var_os("PATH")
|
|
@@ -527,31 +757,102 @@ pub(crate) struct PiMaterializeRequest<'a> {
|
|
|
527
757
|
pub team_mcp_tools: &'a [&'a str],
|
|
528
758
|
pub mcp_config: &'a McpConfig,
|
|
529
759
|
pub session_scope: PiSessionScope,
|
|
760
|
+
/// Explicit native --session-dir, or the recorded root for exact resume.
|
|
761
|
+
pub session_dir: Option<&'a Path>,
|
|
530
762
|
}
|
|
531
763
|
|
|
532
764
|
/// ---
|
|
533
|
-
/// purpose:
|
|
534
|
-
/// returns:
|
|
535
|
-
///
|
|
765
|
+
/// purpose: 共享物化 Pi leader 与 TeamMate 的 wrapper 和 CommandPlan
|
|
766
|
+
/// returns: isolated seats use native --session-id for exact capture in shared native roots;
|
|
767
|
+
/// the zero-argument interactive leader preserves Pi's defaults
|
|
536
768
|
/// errors: resolver、exact model、wrapper 或 argv 构造失败时返回 ProviderError
|
|
537
769
|
/// ---
|
|
538
770
|
pub(crate) fn materialize_pi_plan(
|
|
539
771
|
request: PiMaterializeRequest<'_>,
|
|
772
|
+
) -> Result<CommandPlan, ProviderError> {
|
|
773
|
+
materialize_pi_plan_with_session(request, None)
|
|
774
|
+
}
|
|
775
|
+
|
|
776
|
+
/// ---
|
|
777
|
+
/// purpose: 用上游已验证的 captured id/path 物化 Pi exact-path resume 计划
|
|
778
|
+
/// returns: 与 fresh 共用 resolver/wrapper/argv builder,且不再生成 session id
|
|
779
|
+
/// errors: backing 缺失、越出 recorded root 或 header id/cwd 不匹配时拒绝
|
|
780
|
+
/// ---
|
|
781
|
+
pub(crate) fn materialize_pi_resume_plan(
|
|
782
|
+
request: PiMaterializeRequest<'_>,
|
|
783
|
+
session_id: &SessionId,
|
|
784
|
+
session_path: &Path,
|
|
785
|
+
spawn_cwd: &Path,
|
|
786
|
+
) -> Result<CommandPlan, ProviderError> {
|
|
787
|
+
materialize_pi_plan_with_session(request, Some((session_id, session_path, spawn_cwd)))
|
|
788
|
+
}
|
|
789
|
+
|
|
790
|
+
fn materialize_pi_plan_with_session(
|
|
791
|
+
request: PiMaterializeRequest<'_>,
|
|
792
|
+
resume: Option<(&SessionId, &Path, &Path)>,
|
|
540
793
|
) -> Result<CommandPlan, ProviderError> {
|
|
541
794
|
let (_chain, catalog) = resolve_pi_executable_chain()?;
|
|
542
795
|
let model = request
|
|
543
796
|
.model
|
|
544
797
|
.map(|model| select_exact_pi_model(&catalog, model))
|
|
545
798
|
.transpose()?;
|
|
546
|
-
let paths = pi_seat_paths(request.workspace, request.team_id, request.agent_id);
|
|
799
|
+
let mut paths = pi_seat_paths(request.workspace, request.team_id, request.agent_id);
|
|
800
|
+
if let Some(session_dir) = request.session_dir {
|
|
801
|
+
paths.sessions = resolve_pi_path(request.workspace, session_dir);
|
|
802
|
+
} else if resume
|
|
803
|
+
.is_some_and(|(_, path, _)| path.starts_with(paths.runtime_root.join("sessions")))
|
|
804
|
+
{
|
|
805
|
+
// Older state may still point at the original Team-owned backing.
|
|
806
|
+
paths.sessions = paths.runtime_root.join("sessions");
|
|
807
|
+
}
|
|
547
808
|
let session_dir = match request.session_scope {
|
|
548
809
|
PiSessionScope::Isolated => Some(paths.sessions.as_path()),
|
|
549
810
|
PiSessionScope::NativeDefault => None,
|
|
550
811
|
};
|
|
551
|
-
if let Some(
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
812
|
+
let resume = if let Some((session_id, session_path, spawn_cwd)) = resume {
|
|
813
|
+
let session_dir = session_dir.ok_or_else(|| {
|
|
814
|
+
ProviderError::ResumeUnavailable(format!(
|
|
815
|
+
"Pi session root is unavailable {}",
|
|
816
|
+
paths.sessions.display()
|
|
817
|
+
))
|
|
818
|
+
})?;
|
|
819
|
+
let session_root = std::fs::canonicalize(session_dir).map_err(|error| {
|
|
820
|
+
ProviderError::ResumeUnavailable(format!(
|
|
821
|
+
"Pi session root is unavailable {}: {error}",
|
|
822
|
+
paths.sessions.display()
|
|
823
|
+
))
|
|
824
|
+
})?;
|
|
825
|
+
let exact_path = std::fs::canonicalize(session_path).map_err(|error| {
|
|
826
|
+
ProviderError::ResumeUnavailable(format!(
|
|
827
|
+
"Pi exact session backing is unavailable {}: {error}",
|
|
828
|
+
session_path.display()
|
|
829
|
+
))
|
|
830
|
+
})?;
|
|
831
|
+
if !exact_path.starts_with(&session_root) {
|
|
832
|
+
return Err(ProviderError::ResumeUnavailable(format!(
|
|
833
|
+
"Pi exact session backing is outside the recorded seat root: {}",
|
|
834
|
+
exact_path.display()
|
|
835
|
+
)));
|
|
836
|
+
}
|
|
837
|
+
crate::provider::session_scan::pi::validate_exact_backing(
|
|
838
|
+
&exact_path,
|
|
839
|
+
session_id,
|
|
840
|
+
spawn_cwd,
|
|
841
|
+
)?;
|
|
842
|
+
Some((session_id, exact_path))
|
|
843
|
+
} else {
|
|
844
|
+
if let Some(session_dir) = session_dir {
|
|
845
|
+
if !session_dir.is_absolute() {
|
|
846
|
+
return Err(ProviderError::Io(
|
|
847
|
+
"Pi sessions require an absolute PI_CODING_AGENT_DIR or user home".to_string(),
|
|
848
|
+
));
|
|
849
|
+
}
|
|
850
|
+
std::fs::create_dir_all(session_dir).map_err(|error| {
|
|
851
|
+
ProviderError::Io(format!("{}: {error}", session_dir.display()))
|
|
852
|
+
})?;
|
|
853
|
+
}
|
|
854
|
+
None
|
|
855
|
+
};
|
|
555
856
|
let candidate = candidate_from_mcp_config(request.mcp_config)?;
|
|
556
857
|
let wrapper = write_pi_wrapper(PiWrapperRequest {
|
|
557
858
|
destination: &paths.wrapper,
|
|
@@ -562,68 +863,37 @@ pub(crate) fn materialize_pi_plan(
|
|
|
562
863
|
workspace: request.workspace,
|
|
563
864
|
include_tools: request.team_mcp_tools,
|
|
564
865
|
})?;
|
|
565
|
-
let argv =
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
866
|
+
let (argv, expected_session_id) = if let Some((_session_id, exact_path)) = resume {
|
|
867
|
+
let argv = build_pi_command_argv(PiCommandRequest {
|
|
868
|
+
extension: &wrapper,
|
|
869
|
+
model: model.as_deref(),
|
|
870
|
+
effort: request.effort,
|
|
871
|
+
system_prompt: request.system_prompt,
|
|
872
|
+
session_dir,
|
|
873
|
+
session: PiSessionSelector::Resume { path: &exact_path },
|
|
874
|
+
agent_id: request.agent_id,
|
|
875
|
+
})?;
|
|
876
|
+
(argv, None)
|
|
877
|
+
} else {
|
|
878
|
+
let session_id =
|
|
879
|
+
(request.session_scope == PiSessionScope::Isolated).then(new_pi_session_id);
|
|
880
|
+
let argv = build_pi_command_argv(PiCommandRequest {
|
|
881
|
+
extension: &wrapper,
|
|
882
|
+
model: model.as_deref(),
|
|
883
|
+
effort: request.effort,
|
|
884
|
+
system_prompt: request.system_prompt,
|
|
885
|
+
session_dir,
|
|
886
|
+
session: session_id.as_ref().map_or(PiSessionSelector::Fresh, |id| {
|
|
887
|
+
PiSessionSelector::FreshWithId { id }
|
|
888
|
+
}),
|
|
889
|
+
agent_id: request.agent_id,
|
|
890
|
+
})?;
|
|
891
|
+
(argv, session_id)
|
|
892
|
+
};
|
|
573
893
|
Ok(CommandPlan {
|
|
574
894
|
argv,
|
|
575
|
-
expected_session_id
|
|
895
|
+
expected_session_id,
|
|
576
896
|
provider_projects_root: session_dir.map(Path::to_path_buf),
|
|
577
897
|
managed_mcp_config: false,
|
|
578
898
|
})
|
|
579
899
|
}
|
|
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
|
-
}
|
|
@@ -175,9 +175,8 @@ export default function teamAgentMcp(pi) {
|
|
|
175
175
|
if (stopped || !backend) throw fail(ctx, "wire-binding", new Error("No owned MCP registration"));
|
|
176
176
|
if (surface === "direct" && !directBinding()) throw fail(ctx, "wire-binding", new Error("Owned MCP tools became unreachable"));
|
|
177
177
|
if (surface === "proxy" && !proxyAvailable()) throw fail(ctx, "wire-binding", new Error("MCP proxy became unreachable"));
|
|
178
|
-
const examples =
|
|
179
|
-
const args = tool === "send_message" ? { to: "leader", content: "..." }
|
|
180
|
-
: tool === "report_result" ? { summary: "..." } : {};
|
|
178
|
+
const examples = ["send_message", "get_team_status"].map((tool) => {
|
|
179
|
+
const args = tool === "send_message" ? { to: "leader", content: "..." } : {};
|
|
181
180
|
return surface === "direct"
|
|
182
181
|
? `- ${tool}: mcp__${alias}__${tool}; arguments ${JSON.stringify(args)}`
|
|
183
182
|
: `- ${tool}: mcp(${JSON.stringify({ tool: `${alias}_${tool}`, args })})`;
|
|
@@ -185,7 +184,7 @@ export default function teamAgentMcp(pi) {
|
|
|
185
184
|
const base = wireSuffix && event.systemPrompt.endsWith(wireSuffix)
|
|
186
185
|
? event.systemPrompt.slice(0, -wireSuffix.length) : event.systemPrompt;
|
|
187
186
|
wireSuffix = "\n\n# Team Agent MCP wire binding\n"
|
|
188
|
-
+ "Use
|
|
187
|
+
+ "Use send_message exclusively for communication, using the binding below. Status lookup is optional. Do not pass sender, task_id or schema_version.\n"
|
|
189
188
|
+ examples.join("\n");
|
|
190
189
|
return { systemPrompt: base + wireSuffix };
|
|
191
190
|
});
|
|
@@ -1239,6 +1239,29 @@ 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>, ()>,
|
|
1242
1265
|
) -> Result<QuickStartReport, LifecycleError> {
|
|
1243
1266
|
// B-7 / 036b N38 三行 fail-fast — TEAM_AGENT_LEADER_PANE_ID 主动路径在 quick-start
|
|
1244
1267
|
// 入口验活;死/缺(Dead)的 pane 必须明确报错,不可 silent bind 到 spawner /
|
|
@@ -1254,6 +1277,7 @@ pub(crate) fn quick_start_with_transport_in_workspace(
|
|
|
1254
1277
|
agents_dir.display()
|
|
1255
1278
|
)));
|
|
1256
1279
|
}
|
|
1280
|
+
crate::lifecycle::launch::run_pi_catalog_preflight(agents_dir, discover)?;
|
|
1257
1281
|
#[cfg(unix)]
|
|
1258
1282
|
{
|
|
1259
1283
|
let input = crate::cli::QuickStartArgs {
|
|
@@ -1724,7 +1748,7 @@ mod fresh_quick_start_leader_binding_tests {
|
|
|
1724
1748
|
let team = workspace.join("roles");
|
|
1725
1749
|
std::fs::create_dir_all(team.join("agents")).unwrap();
|
|
1726
1750
|
std::fs::write(team.join("TEAM.md"), "---\nname: fresh\nobjective: test\nprovider: codex\n---\nTeam.\n").unwrap();
|
|
1727
|
-
std::fs::write(team.join("agents/worker.md"), "---\nname: worker\nrole: Worker\nprovider:
|
|
1751
|
+
std::fs::write(team.join("agents/worker.md"), "---\nname: worker\nrole: Worker\nprovider: fake\nmodel: fake\nauth_mode: subscription\ndangerously_skip_permissions: false\n---\nTest.\n").unwrap();
|
|
1728
1752
|
let transport = OfflineTransport::new();
|
|
1729
1753
|
let report = quick_start_with_transport_in_workspace(
|
|
1730
1754
|
&workspace, &team, None, true, Some("fresh"), &transport,
|
|
@@ -1849,7 +1873,7 @@ mod fresh_quick_start_leader_binding_tests {
|
|
|
1849
1873
|
"---\nname: current\nobjective: Bootstrap fixture.\n---\n",
|
|
1850
1874
|
)
|
|
1851
1875
|
.unwrap();
|
|
1852
|
-
std::fs::write(team.join("agents/worker.md"), "---\nname: worker\nrole: Worker\nprovider:
|
|
1876
|
+
std::fs::write(team.join("agents/worker.md"), "---\nname: worker\nrole: Worker\nprovider: fake\nmodel: fake\nauth_mode: subscription\ndangerously_skip_permissions: false\n---\nBounded fixture.\n").unwrap();
|
|
1853
1877
|
let state_path = crate::state::persist::runtime_state_path(&workspace);
|
|
1854
1878
|
std::fs::create_dir_all(state_path.parent().unwrap()).unwrap();
|
|
1855
1879
|
let state = json!({
|