@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,44 +1,25 @@
|
|
|
1
1
|
//! ---
|
|
2
|
-
//! purpose: 各 provider 的 MCP 配置落盘与 argv
|
|
2
|
+
//! purpose: 各 provider 的 MCP 配置落盘与 argv 指向
|
|
3
3
|
//! contract:
|
|
4
4
|
//! provides:
|
|
5
5
|
//! - name: resolve_mcp_config
|
|
6
6
|
//! what: 把 MCP 配置里的 workspace、agent_id 与 team_id 占位符替换掉
|
|
7
7
|
//! - name: write_worker_mcp_config_for_provider
|
|
8
8
|
//! what: 写出 per-agent 的 MCP 配置文件,copilot 走字段名翻译
|
|
9
|
-
//! - name: apply_grok_mcp_overlay
|
|
10
|
-
//! what: 写 workspace 下 grok 的项目作用域配置,是该文件的唯一写者
|
|
11
|
-
//! - name: reconcile_grok_toml_per_seat_keys
|
|
12
|
-
//! what: 起 grok 席前清掉共享 toml 里遗留的 per-seat 键并留审计事件
|
|
13
|
-
//! - name: ensure_grok_login_and_folder_trust
|
|
14
|
-
//! what: grok 未登录或目录未信任时拒绝起席
|
|
15
9
|
//! - name: point_native_mcp_config_at_file
|
|
16
10
|
//! what: 把 argv 里的 MCP 配置参数改指到已落盘的文件
|
|
17
11
|
//! depends:
|
|
18
12
|
//! - crate::provider::McpConfig
|
|
19
|
-
//! - crate::event_log::EventLog
|
|
20
|
-
//! - crate::lifecycle::profile_launch
|
|
21
13
|
//! - std::fs
|
|
22
14
|
//! boundary:
|
|
23
|
-
//! - 不读也不写 provider
|
|
24
|
-
//! -
|
|
25
|
-
//! - 清洗共享 toml 时不删未知键,未知不等于可删
|
|
26
|
-
//! - 清洗后校验失败一律拒绝起席,不带着脏配置继续
|
|
15
|
+
//! - 不读也不写 provider 的凭据文件
|
|
16
|
+
//! - Grok 的目录作用域 `.grok/config.toml` 写者已随 legacy grok worker 退役;grok_build 叶子自带 MCP 注入
|
|
27
17
|
//! maturity: wired
|
|
28
18
|
//! ---
|
|
29
|
-
use std::collections::{BTreeMap, BTreeSet};
|
|
30
19
|
use std::path::{Path, PathBuf};
|
|
31
|
-
use std::process::Command;
|
|
32
20
|
|
|
33
21
|
use crate::lifecycle::*;
|
|
34
|
-
use crate::model::enums::
|
|
35
|
-
use crate::model::yaml::{self, Value};
|
|
36
|
-
use crate::state::persist::load_runtime_state;
|
|
37
|
-
use crate::transport::{PaneId, SessionName, Target, Transport, WindowName};
|
|
38
|
-
|
|
39
|
-
use crate::lifecycle::lock::{acquire_agent_lifecycle_lock, LifecycleLockRequest};
|
|
40
|
-
|
|
41
|
-
use super::*;
|
|
22
|
+
use crate::model::enums::Provider;
|
|
42
23
|
|
|
43
24
|
/// ---
|
|
44
25
|
/// purpose: 把 MCP 配置里的占位符替换成本次 workspace、席位与团队
|
|
@@ -143,474 +124,10 @@ pub(crate) fn write_worker_mcp_config_for_provider(
|
|
|
143
124
|
Ok(path)
|
|
144
125
|
}
|
|
145
126
|
|
|
146
|
-
/// Grok MCP 是**目录作用域**(`mcp_injection: dir_scoped`):CLI 只读
|
|
147
|
-
/// `<cwd>/.grok/config.toml`。同目录后起席位会覆盖这份文件,先起席位的
|
|
148
|
-
/// 身份被回溯性改写且不报错。本版 worker cwd 恒为 workspace(D5),
|
|
149
|
-
/// exclusive 检查也不读 per-agent cwd ⇒ 一个 workspace 只支持一个 grok 席。
|
|
150
|
-
/// 这是 grok 的 provider 能力边界,不是框架通则(claude/codex 走 argv
|
|
151
|
-
/// `--mcp-config`,同目录多席没有这个问题)。
|
|
152
|
-
struct GrokOccupant {
|
|
153
|
-
id: String,
|
|
154
|
-
spawned_at: Option<String>,
|
|
155
|
-
status: String,
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
fn agent_is_grok(agent: &Value) -> bool {
|
|
159
|
-
agent
|
|
160
|
-
.get("provider")
|
|
161
|
-
.and_then(Value::as_str)
|
|
162
|
-
.and_then(crate::lifecycle::profile_launch::parse_provider)
|
|
163
|
-
== Some(Provider::Grok)
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
fn status_is_live(status: &str) -> bool {
|
|
167
|
-
!matches!(
|
|
168
|
-
status,
|
|
169
|
-
"stopped" | "stopping" | "removed" | "spawn_failed" | "failed"
|
|
170
|
-
)
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
fn occupant_from_state_row(id: &str, agent: &serde_json::Value) -> Option<GrokOccupant> {
|
|
174
|
-
let provider = agent
|
|
175
|
-
.get("provider")
|
|
176
|
-
.and_then(serde_json::Value::as_str)
|
|
177
|
-
.and_then(crate::lifecycle::profile_launch::parse_provider);
|
|
178
|
-
if provider != Some(Provider::Grok) {
|
|
179
|
-
return None;
|
|
180
|
-
}
|
|
181
|
-
let status = agent
|
|
182
|
-
.get("status")
|
|
183
|
-
.and_then(serde_json::Value::as_str)
|
|
184
|
-
.unwrap_or("running");
|
|
185
|
-
if !status_is_live(status) {
|
|
186
|
-
return None;
|
|
187
|
-
}
|
|
188
|
-
Some(GrokOccupant {
|
|
189
|
-
id: id.to_string(),
|
|
190
|
-
spawned_at: agent
|
|
191
|
-
.get("spawned_at")
|
|
192
|
-
.and_then(serde_json::Value::as_str)
|
|
193
|
-
.map(str::to_string),
|
|
194
|
-
status: status.to_string(),
|
|
195
|
-
})
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
fn live_grok_occupants_from_state(workspace: &Path) -> Result<Vec<GrokOccupant>, LifecycleError> {
|
|
199
|
-
let path = crate::state::persist::runtime_state_path(workspace);
|
|
200
|
-
if !path.exists() {
|
|
201
|
-
return Ok(Vec::new());
|
|
202
|
-
}
|
|
203
|
-
let state = crate::state::persist::load_runtime_state(workspace).map_err(|e| {
|
|
204
|
-
LifecycleError::StatePersist(format!(
|
|
205
|
-
"cannot count live grok seats (state unreadable): {e}"
|
|
206
|
-
))
|
|
207
|
-
})?;
|
|
208
|
-
let mut out = Vec::new();
|
|
209
|
-
if let Some(agents) = state.get("agents").and_then(serde_json::Value::as_object) {
|
|
210
|
-
for (id, agent) in agents {
|
|
211
|
-
if let Some(row) = occupant_from_state_row(id, agent) {
|
|
212
|
-
out.push(row);
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
if let Some(teams) = state.get("teams").and_then(serde_json::Value::as_object) {
|
|
217
|
-
for team in teams.values() {
|
|
218
|
-
let Some(agents) = team.get("agents").and_then(serde_json::Value::as_object) else {
|
|
219
|
-
continue;
|
|
220
|
-
};
|
|
221
|
-
for (id, agent) in agents {
|
|
222
|
-
if out.iter().any(|o| o.id == *id) {
|
|
223
|
-
continue;
|
|
224
|
-
}
|
|
225
|
-
if let Some(row) = occupant_from_state_row(id, agent) {
|
|
226
|
-
out.push(row);
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
Ok(out)
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
fn spec_grok_ids(spec: &Value) -> Vec<String> {
|
|
235
|
-
let mut ids = Vec::new();
|
|
236
|
-
for agent in spec_agent_values(spec) {
|
|
237
|
-
if agent_is_paused(agent) || !agent_is_grok(agent) {
|
|
238
|
-
continue;
|
|
239
|
-
}
|
|
240
|
-
if let Some(id) = agent.get("id").and_then(Value::as_str) {
|
|
241
|
-
if !ids.iter().any(|existing| existing == id) {
|
|
242
|
-
ids.push(id.to_string());
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
ids
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
/// ---
|
|
250
|
-
/// purpose: 清掉 grok 共享 toml 里遗留的 per-seat 键,并写一条只含键名的审计事件
|
|
251
|
-
/// returns: 文件不存在或本就没有 per-seat 键时直接成功
|
|
252
|
-
/// errors: 文件读不出、清洗后仍残留或审计事件写不出时返回 RequirementUnmet
|
|
253
|
-
/// ---
|
|
254
|
-
/// Reconcile `<cwd>/.grok/config.toml` before any grok start: drop leftover
|
|
255
|
-
/// framework per-seat keys (`is_per_seat_env_key`), leave user/shared keys,
|
|
256
|
-
/// emit an audit event with names only. Hung only from
|
|
257
|
-
/// [`apply_grok_mcp_overlay`] — the unique writer, so launch/restart/resume
|
|
258
|
-
/// all pass through. Clean-failure keeps the previous refuse shape.
|
|
259
|
-
pub(crate) fn reconcile_grok_toml_per_seat_keys(workspace: &Path) -> Result<(), LifecycleError> {
|
|
260
|
-
let path = workspace.join(".grok").join("config.toml");
|
|
261
|
-
if !path.exists() {
|
|
262
|
-
return Ok(());
|
|
263
|
-
}
|
|
264
|
-
let text = std::fs::read_to_string(&path).map_err(|error| {
|
|
265
|
-
LifecycleError::RequirementUnmet(format!(
|
|
266
|
-
"error: cannot judge grok shared slot (unreadable {})\n\
|
|
267
|
-
reason: {error}\n\
|
|
268
|
-
action: fix permissions on that file before adding another grok seat",
|
|
269
|
-
path.display()
|
|
270
|
-
))
|
|
271
|
-
})?;
|
|
272
|
-
let keys = super::per_seat_keys_in_toml(&text);
|
|
273
|
-
if keys.is_empty() {
|
|
274
|
-
return Ok(());
|
|
275
|
-
}
|
|
276
|
-
let (cleaned, removed) = super::strip_per_seat_keys_from_toml(&text);
|
|
277
|
-
let dir = workspace.join(".grok");
|
|
278
|
-
if let Err(_error) = write_grok_config_toml(&dir, &cleaned) {
|
|
279
|
-
return Err(refuse_dirty_grok_toml(workspace, &keys));
|
|
280
|
-
}
|
|
281
|
-
let after =
|
|
282
|
-
std::fs::read_to_string(&path).map_err(|_| refuse_dirty_grok_toml(workspace, &keys))?;
|
|
283
|
-
if !super::per_seat_keys_in_toml(&after).is_empty() {
|
|
284
|
-
return Err(refuse_dirty_grok_toml(workspace, &keys));
|
|
285
|
-
}
|
|
286
|
-
crate::event_log::EventLog::new(workspace)
|
|
287
|
-
.write(
|
|
288
|
-
crate::lifecycle::types::event_names::GROK_TOML_PER_SEAT_KEYS_CLEARED,
|
|
289
|
-
serde_json::json!({
|
|
290
|
-
"path": path.display().to_string(),
|
|
291
|
-
"keys": removed,
|
|
292
|
-
}),
|
|
293
|
-
)
|
|
294
|
-
.map_err(|error| {
|
|
295
|
-
LifecycleError::RequirementUnmet(format!(
|
|
296
|
-
"error: cannot audit grok shared-slot cleanup ({})\n\
|
|
297
|
-
reason: {error}\n\
|
|
298
|
-
action: fix permissions on .team/logs then retry",
|
|
299
|
-
path.display()
|
|
300
|
-
))
|
|
301
|
-
})?;
|
|
302
|
-
Ok(())
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
fn refuse_dirty_grok_toml(workspace: &Path, keys: &[(String, String)]) -> LifecycleError {
|
|
306
|
-
let named = keys
|
|
307
|
-
.iter()
|
|
308
|
-
.map(|(key, _value)| key.as_str())
|
|
309
|
-
.collect::<Vec<_>>()
|
|
310
|
-
.join(", ");
|
|
311
|
-
LifecycleError::RequirementUnmet(format!(
|
|
312
|
-
"error: grok shared slot still carries per-seat keys ({named})\n\
|
|
313
|
-
reason: .grok/config.toml is directory-scoped; per-seat keys would be inherited by every grok seat\n\
|
|
314
|
-
workspace: {}\n\
|
|
315
|
-
action: remove per-seat keys from the toml (identity belongs on pane env)",
|
|
316
|
-
workspace.display()
|
|
317
|
-
))
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
fn write_grok_config_toml(dir: &Path, body: &str) -> Result<PathBuf, std::io::Error> {
|
|
321
|
-
std::fs::create_dir_all(dir)?;
|
|
322
|
-
let path = dir.join("config.toml");
|
|
323
|
-
let tmp = dir.join("config.toml.tmp");
|
|
324
|
-
std::fs::write(&tmp, body.as_bytes())?;
|
|
325
|
-
std::fs::rename(&tmp, &path)?;
|
|
326
|
-
Ok(path)
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
/// ---
|
|
330
|
-
/// purpose: 构造同一 workspace 已被别的 grok 席占用的拒绝错误
|
|
331
|
-
/// params:
|
|
332
|
-
/// seats: 已占用该目录的席位名,写进错误正文
|
|
333
|
-
/// returns: 带 error/reason/workspace/grok_seats 的 RequirementUnmet
|
|
334
|
-
/// ---
|
|
335
|
-
pub(crate) fn grok_shared_cwd_error(cwd: &Path, seats: &[String]) -> LifecycleError {
|
|
336
|
-
LifecycleError::RequirementUnmet(format!(
|
|
337
|
-
"error: grok seat already occupies this workspace\n\
|
|
338
|
-
reason: grok MCP is directory-scoped (<cwd>/.grok/config.toml); a second seat overwrites TEAM_AGENT_ID\n\
|
|
339
|
-
workspace: {}\n\
|
|
340
|
-
grok_seats: {}",
|
|
341
|
-
cwd.display(),
|
|
342
|
-
seats.join(", "),
|
|
343
|
-
))
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
fn grok_occupied_cwd_error(
|
|
347
|
-
cwd: &Path,
|
|
348
|
-
incoming: &str,
|
|
349
|
-
occupants: &[GrokOccupant],
|
|
350
|
-
) -> LifecycleError {
|
|
351
|
-
let holder = occupants
|
|
352
|
-
.iter()
|
|
353
|
-
.find(|o| o.id != incoming)
|
|
354
|
-
.or_else(|| occupants.first());
|
|
355
|
-
let holder_id = holder.map(|o| o.id.as_str()).unwrap_or("unknown");
|
|
356
|
-
let started = holder
|
|
357
|
-
.and_then(|o| o.spawned_at.as_deref())
|
|
358
|
-
.unwrap_or("unknown");
|
|
359
|
-
let names = occupants
|
|
360
|
-
.iter()
|
|
361
|
-
.map(|o| {
|
|
362
|
-
if let Some(at) = &o.spawned_at {
|
|
363
|
-
format!("{} (status={}, started {})", o.id, o.status, at)
|
|
364
|
-
} else {
|
|
365
|
-
format!("{} (status={})", o.id, o.status)
|
|
366
|
-
}
|
|
367
|
-
})
|
|
368
|
-
.collect::<Vec<_>>()
|
|
369
|
-
.join(", ");
|
|
370
|
-
LifecycleError::RequirementUnmet(format!(
|
|
371
|
-
"error: grok seat {holder_id} already occupies this workspace (started {started})\n\
|
|
372
|
-
incoming: {incoming}\n\
|
|
373
|
-
reason: grok MCP is directory-scoped (<cwd>/.grok/config.toml); a second seat overwrites TEAM_AGENT_ID and the first seat's first turn would inherit the wrong identity\n\
|
|
374
|
-
workspace: {}\n\
|
|
375
|
-
grok_seats: {names}",
|
|
376
|
-
cwd.display(),
|
|
377
|
-
))
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
/// ---
|
|
381
|
-
/// purpose: 起 grok 席前确认已登录且该目录已被信任
|
|
382
|
-
/// params:
|
|
383
|
-
/// cwd: 席位的工作目录,用于判断目录信任
|
|
384
|
-
/// returns: 通过返回空值;关闭 folder-trust 的环境变量下跳过信任检查
|
|
385
|
-
/// errors: HOME 未设、登录态文件缺失或为空、目录未被信任时返回 RequirementUnmet
|
|
386
|
-
/// ---
|
|
387
|
-
/// 未登录 / 目录未信任时不许起出「能收信、没有手」的 grok 席。
|
|
388
|
-
/// 登录态看 `$HOME/.grok/auth.json`;目录信任看 `$HOME/.grok/trusted_folders.toml`
|
|
389
|
-
/// (与 grok `--trust` / `/hooks-trust` 同一份;未信任则项目作用域 MCP 不生效)。
|
|
390
|
-
/// `GROK_FOLDER_TRUST=0` 时 grok 自己关掉 folder-trust,本检查跟着放行。
|
|
391
|
-
pub(crate) fn ensure_grok_login_and_folder_trust(cwd: &Path) -> Result<(), LifecycleError> {
|
|
392
|
-
let home = std::env::var_os("HOME").map(PathBuf::from).ok_or_else(|| {
|
|
393
|
-
LifecycleError::RequirementUnmet(
|
|
394
|
-
"error: HOME is unset; cannot verify grok login or folder trust\n\
|
|
395
|
-
action: export HOME and retry"
|
|
396
|
-
.to_string(),
|
|
397
|
-
)
|
|
398
|
-
})?;
|
|
399
|
-
let grok_home = home.join(".grok");
|
|
400
|
-
if !grok_auth_present(&grok_home) {
|
|
401
|
-
return Err(LifecycleError::RequirementUnmet(format!(
|
|
402
|
-
"error: grok is not logged in (missing or empty {})\n\
|
|
403
|
-
action: run `grok login` then retry add-agent/launch",
|
|
404
|
-
grok_home.join("auth.json").display()
|
|
405
|
-
)));
|
|
406
|
-
}
|
|
407
|
-
if folder_trust_required() && !grok_folder_is_trusted(&grok_home, cwd) {
|
|
408
|
-
return Err(LifecycleError::RequirementUnmet(format!(
|
|
409
|
-
"error: grok folder is not trusted; project-scope MCP at {}/.grok/config.toml will not load\n\
|
|
410
|
-
cwd: {}\n\
|
|
411
|
-
action: from that directory run `grok --trust` (or `/hooks-trust` in a grok session), then retry",
|
|
412
|
-
cwd.display(),
|
|
413
|
-
cwd.display()
|
|
414
|
-
)));
|
|
415
|
-
}
|
|
416
|
-
Ok(())
|
|
417
|
-
}
|
|
418
|
-
|
|
419
|
-
fn grok_auth_present(grok_home: &Path) -> bool {
|
|
420
|
-
let path = grok_home.join("auth.json");
|
|
421
|
-
let Ok(text) = std::fs::read_to_string(path) else {
|
|
422
|
-
return false;
|
|
423
|
-
};
|
|
424
|
-
let Ok(value) = serde_json::from_str::<serde_json::Value>(&text) else {
|
|
425
|
-
return false;
|
|
426
|
-
};
|
|
427
|
-
value.as_object().is_some_and(|map| !map.is_empty())
|
|
428
|
-
}
|
|
429
|
-
|
|
430
|
-
fn folder_trust_required() -> bool {
|
|
431
|
-
!matches!(
|
|
432
|
-
std::env::var("GROK_FOLDER_TRUST").ok().as_deref(),
|
|
433
|
-
Some("0") | Some("false") | Some("off")
|
|
434
|
-
)
|
|
435
|
-
}
|
|
436
|
-
|
|
437
|
-
fn grok_folder_is_trusted(grok_home: &Path, cwd: &Path) -> bool {
|
|
438
|
-
let text = std::fs::read_to_string(grok_home.join("trusted_folders.toml")).unwrap_or_default();
|
|
439
|
-
let cwd = std::fs::canonicalize(cwd).unwrap_or_else(|_| cwd.to_path_buf());
|
|
440
|
-
grok_trusted_folders(&text).into_iter().any(|trusted| {
|
|
441
|
-
let trusted = std::fs::canonicalize(&trusted).unwrap_or(trusted);
|
|
442
|
-
cwd == trusted || cwd.starts_with(&trusted)
|
|
443
|
-
})
|
|
444
|
-
}
|
|
445
|
-
|
|
446
|
-
fn grok_trusted_folders(text: &str) -> Vec<PathBuf> {
|
|
447
|
-
let mut current = None;
|
|
448
|
-
let mut out = Vec::new();
|
|
449
|
-
for line in text.lines() {
|
|
450
|
-
let trimmed = line.trim();
|
|
451
|
-
if let Some(rest) = trimmed.strip_prefix("[folders.\"") {
|
|
452
|
-
current = rest.strip_suffix("\"]").map(str::to_string);
|
|
453
|
-
continue;
|
|
454
|
-
}
|
|
455
|
-
if trimmed.starts_with('[') {
|
|
456
|
-
current = None;
|
|
457
|
-
continue;
|
|
458
|
-
}
|
|
459
|
-
if trimmed == "trusted = true" {
|
|
460
|
-
if let Some(path) = current.take() {
|
|
461
|
-
out.push(PathBuf::from(path));
|
|
462
|
-
}
|
|
463
|
-
}
|
|
464
|
-
}
|
|
465
|
-
out
|
|
466
|
-
}
|
|
467
|
-
|
|
468
|
-
/// ---
|
|
469
|
-
/// purpose: 写 workspace 下 grok 的项目作用域 MCP 配置,服务名固定为 team_orchestrator
|
|
470
|
-
/// params:
|
|
471
|
-
/// mcp_config: 已解析的 MCP 配置,须含 team_orchestrator 条目与 command
|
|
472
|
-
/// returns: 成功返回空值;写前先清 per-seat 键,已有表里的未知环境键会被保留
|
|
473
|
-
/// errors: 缺条目或缺 command 时返回 StatePersist,清洗失败透传 RequirementUnmet,写文件失败返回 StatePersist
|
|
474
|
-
/// ---
|
|
475
|
-
/// Grok CLI 没有 `--mcp-config`。launch 路径写一份 provider 实际会读的文件。
|
|
476
|
-
/// Grok 只认项目作用域
|
|
477
|
-
/// `<cwd>/.grok/config.toml`(`grok mcp add --scope project` 的产物)。
|
|
478
|
-
///
|
|
479
|
-
/// Unique writer of `<cwd>/.grok/config.toml`. Reconcile leftover per-seat
|
|
480
|
-
/// keys here so restart/resume cannot skip the upgrade migration.
|
|
481
|
-
///
|
|
482
|
-
/// `McpConfig.raw` 与写出的 grok 表名都必须是 `team_orchestrator`,与
|
|
483
|
-
/// `worker_command_context` 契约(grok: `team_orchestrator__send_message`)对齐。
|
|
484
|
-
/// grok 按 server 名给工具加命名空间,写成 `team-agent` 会变成 `team-agent__*`。
|
|
485
|
-
pub fn apply_grok_mcp_overlay(
|
|
486
|
-
workspace: &Path,
|
|
487
|
-
mcp_config: &crate::provider::McpConfig,
|
|
488
|
-
) -> Result<(), LifecycleError> {
|
|
489
|
-
// adapter.rs 只产出 team_orchestrator。team-agent 是 0.5.67 overlay
|
|
490
|
-
// 误用的旧 inbound key,读侧留一版以免夹具还带旧名;0.5.68 若无引用再删。
|
|
491
|
-
let server = mcp_config
|
|
492
|
-
.raw
|
|
493
|
-
.get("team_orchestrator")
|
|
494
|
-
.or_else(|| mcp_config.raw.get("team-agent"))
|
|
495
|
-
.ok_or_else(|| {
|
|
496
|
-
LifecycleError::StatePersist(
|
|
497
|
-
"grok MCP overlay requires team_orchestrator in resolved mcp config".to_string(),
|
|
498
|
-
)
|
|
499
|
-
})?;
|
|
500
|
-
let command = server
|
|
501
|
-
.get("command")
|
|
502
|
-
.and_then(serde_json::Value::as_str)
|
|
503
|
-
.filter(|value| !value.is_empty())
|
|
504
|
-
.ok_or_else(|| {
|
|
505
|
-
LifecycleError::StatePersist("grok MCP overlay missing command".to_string())
|
|
506
|
-
})?;
|
|
507
|
-
let args = server
|
|
508
|
-
.get("args")
|
|
509
|
-
.and_then(serde_json::Value::as_array)
|
|
510
|
-
.map(|items| {
|
|
511
|
-
items
|
|
512
|
-
.iter()
|
|
513
|
-
.filter_map(serde_json::Value::as_str)
|
|
514
|
-
.map(str::to_string)
|
|
515
|
-
.collect::<Vec<_>>()
|
|
516
|
-
})
|
|
517
|
-
.unwrap_or_default();
|
|
518
|
-
let env = server
|
|
519
|
-
.get("env")
|
|
520
|
-
.and_then(serde_json::Value::as_object)
|
|
521
|
-
.map(|map| {
|
|
522
|
-
map.iter()
|
|
523
|
-
.filter_map(|(key, value)| {
|
|
524
|
-
value.as_str().map(|text| (key.clone(), text.to_string()))
|
|
525
|
-
})
|
|
526
|
-
.collect::<BTreeMap<_, _>>()
|
|
527
|
-
})
|
|
528
|
-
.unwrap_or_default();
|
|
529
|
-
|
|
530
|
-
// Per-seat keys live on the pane env. Unknown keys on the existing
|
|
531
|
-
// table stay: a full stanza rewrite must not treat "not in our list"
|
|
532
|
-
// as permission to delete.
|
|
533
|
-
reconcile_grok_toml_per_seat_keys(workspace)?;
|
|
534
|
-
let dir = workspace.join(".grok");
|
|
535
|
-
let path = dir.join("config.toml");
|
|
536
|
-
let existing = std::fs::read_to_string(&path).unwrap_or_default();
|
|
537
|
-
let preserved = super::non_per_seat_env_in_tables(
|
|
538
|
-
&existing,
|
|
539
|
-
&["mcp_servers.team_orchestrator", "mcp_servers.team-agent"],
|
|
540
|
-
);
|
|
541
|
-
let mut env = env;
|
|
542
|
-
env.retain(|key, value| !super::is_per_seat_env_key(key) && !value.trim().is_empty());
|
|
543
|
-
for (key, value) in preserved {
|
|
544
|
-
env.entry(key).or_insert(value);
|
|
545
|
-
}
|
|
546
|
-
|
|
547
|
-
let stanza = render_grok_team_agent_stanza(command, &args, &env);
|
|
548
|
-
// 同时摘掉新表和 0.5.67 误写的 [mcp_servers.team-agent],否则改名后两套
|
|
549
|
-
// team MCP 并存,grok 会列出两份指向同一进程的工具。
|
|
550
|
-
let body = upsert_toml_table_prefixes(
|
|
551
|
-
&existing,
|
|
552
|
-
&["mcp_servers.team_orchestrator", "mcp_servers.team-agent"],
|
|
553
|
-
&stanza,
|
|
554
|
-
);
|
|
555
|
-
write_grok_config_toml(&dir, &body)
|
|
556
|
-
.map_err(|e| LifecycleError::StatePersist(format!("{}: {e}", path.display())))?;
|
|
557
|
-
Ok(())
|
|
558
|
-
}
|
|
559
|
-
|
|
560
|
-
fn render_grok_team_agent_stanza(
|
|
561
|
-
command: &str,
|
|
562
|
-
args: &[String],
|
|
563
|
-
env: &BTreeMap<String, String>,
|
|
564
|
-
) -> String {
|
|
565
|
-
let mut out = String::from("[mcp_servers.team_orchestrator]\n");
|
|
566
|
-
out.push_str(&format!("command = {}\n", toml_quote(command)));
|
|
567
|
-
out.push_str("args = [\n");
|
|
568
|
-
for arg in args {
|
|
569
|
-
out.push_str(&format!(" {},\n", toml_quote(arg)));
|
|
570
|
-
}
|
|
571
|
-
out.push_str("]\n");
|
|
572
|
-
out.push_str("enabled = true\n");
|
|
573
|
-
if !env.is_empty() {
|
|
574
|
-
out.push_str("\n[mcp_servers.team_orchestrator.env]\n");
|
|
575
|
-
for (key, value) in env {
|
|
576
|
-
out.push_str(&format!("{key} = {}\n", toml_quote(value)));
|
|
577
|
-
}
|
|
578
|
-
}
|
|
579
|
-
out
|
|
580
|
-
}
|
|
581
|
-
|
|
582
|
-
fn toml_quote(value: &str) -> String {
|
|
583
|
-
format!("\"{}\"", value.replace('\\', "\\\\").replace('"', "\\\""))
|
|
584
|
-
}
|
|
585
|
-
|
|
586
|
-
fn upsert_toml_table_prefixes(existing: &str, tables: &[&str], stanza: &str) -> String {
|
|
587
|
-
let mut out = String::new();
|
|
588
|
-
let mut skip = false;
|
|
589
|
-
for line in existing.lines() {
|
|
590
|
-
let trimmed = line.trim();
|
|
591
|
-
if trimmed.starts_with('[') && trimmed.ends_with(']') {
|
|
592
|
-
let name = &trimmed[1..trimmed.len() - 1];
|
|
593
|
-
skip = tables
|
|
594
|
-
.iter()
|
|
595
|
-
.any(|table| name == *table || name.starts_with(&format!("{table}.")));
|
|
596
|
-
}
|
|
597
|
-
if !skip {
|
|
598
|
-
out.push_str(line);
|
|
599
|
-
out.push('\n');
|
|
600
|
-
}
|
|
601
|
-
}
|
|
602
|
-
let trimmed = out.trim_end();
|
|
603
|
-
if trimmed.is_empty() {
|
|
604
|
-
stanza.to_string()
|
|
605
|
-
} else {
|
|
606
|
-
format!("{trimmed}\n\n{stanza}")
|
|
607
|
-
}
|
|
608
|
-
}
|
|
609
|
-
|
|
610
127
|
/// ---
|
|
611
128
|
/// purpose: 把 argv 里 provider 原生的 MCP 配置参数改指到已落盘的文件
|
|
612
129
|
/// params:
|
|
613
|
-
/// argv: 就地改写;copilot 改 --additional-mcp-config 并加 @ 前缀
|
|
130
|
+
/// argv: 就地改写;claude 系改 --mcp-config 的值,copilot 改 --additional-mcp-config 并加 @ 前缀
|
|
614
131
|
/// returns: argv 里没有对应参数时什么都不做
|
|
615
132
|
/// ---
|
|
616
133
|
pub(crate) fn point_native_mcp_config_at_file(
|
|
@@ -619,6 +136,14 @@ pub(crate) fn point_native_mcp_config_at_file(
|
|
|
619
136
|
path: &Path,
|
|
620
137
|
) {
|
|
621
138
|
match provider {
|
|
139
|
+
Provider::Claude | Provider::ClaudeCode => {
|
|
140
|
+
let Some(index) = argv.iter().position(|arg| arg == "--mcp-config") else {
|
|
141
|
+
return;
|
|
142
|
+
};
|
|
143
|
+
if let Some(value) = argv.get_mut(index.saturating_add(1)) {
|
|
144
|
+
*value = path.to_string_lossy().to_string();
|
|
145
|
+
}
|
|
146
|
+
}
|
|
622
147
|
// §C1 note: copilot `--additional-mcp-config` 接受 `@file`,直接指向既有
|
|
623
148
|
// `.team/runtime/mcp/<agent>.json`(launch 路径 write_worker_mcp_config 已写)。
|
|
624
149
|
// 既避免 inline JSON 包 mcpServers wrapper 的语义错位,也更利于 ps 验法。
|