@team-agent/installer 0.5.127 → 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 -22
- package/crates/team-agent/src/cli/emit.rs +58 -26
- package/crates/team-agent/src/cli/intent/runtime.rs +32 -5
- package/crates/team-agent/src/cli/intent/runtime_tests.rs +102 -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 +25 -8
- package/crates/team-agent/src/cli/models.rs +764 -7
- 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 +1 -1
- package/crates/team-agent/src/cli/tests/named_address.rs +11 -10
- package/crates/team-agent/src/cli/tests/run_delegation.rs +9 -6
- package/crates/team-agent/src/cli/tests/status_send.rs +68 -271
- package/crates/team-agent/src/compiler/tests.rs +3 -18
- package/crates/team-agent/src/compiler.rs +205 -6
- package/crates/team-agent/src/contract_runtime/backend.rs +145 -11
- package/crates/team-agent/src/contract_runtime/commands.rs +7 -7
- package/crates/team-agent/src/contract_runtime/config.rs +26 -16
- 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 -11
- 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 +56 -92
- package/crates/team-agent/src/coordinator/steps/abnormal.rs +11 -11
- package/crates/team-agent/src/coordinator/tests/api_error_recovery.rs +16 -54
- package/crates/team-agent/src/coordinator/tests/health_sync.rs +42 -0
- 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 +38 -13
- package/crates/team-agent/src/lifecycle/launch/fork_entry.rs +87 -6
- package/crates/team-agent/src/lifecycle/launch/mcp_config.rs +9 -1
- 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 +24 -0
- package/crates/team-agent/src/lifecycle/launch/spawn.rs +36 -13
- package/crates/team-agent/src/lifecycle/launch.rs +24 -1
- package/crates/team-agent/src/lifecycle/profile_launch.rs +321 -11
- 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 +345 -35
- 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 +39 -14
- 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 +236 -13
- 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 +5 -4
- package/crates/team-agent/src/lifecycle/tests/copilot_provider_red.rs +7 -11
- package/crates/team-agent/src/lifecycle/tests/core.rs +47 -18
- 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 +14 -14
- package/crates/team-agent/src/lifecycle/tests/harvest2_a_batch_red.rs +60 -20
- package/crates/team-agent/src/lifecycle/tests/launch_spawn.rs +28 -26
- package/crates/team-agent/src/lifecycle/tests/mcp_tool_name_format_red.rs +6 -6
- 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 +10 -11
- 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 +254 -2
- 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 +5 -6
- package/crates/team-agent/src/lifecycle/tests/worker_spawn_env_red.rs +16 -7
- package/crates/team-agent/src/lifecycle/tests.rs +3 -0
- package/crates/team-agent/src/lifecycle/types.rs +18 -2
- 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 +98 -119
- 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 +160 -218
- 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 +191 -85
- package/crates/team-agent/src/messaging/tests/runtime.rs +4 -110
- package/crates/team-agent/src/messaging/tests/spine.rs +40 -24
- package/crates/team-agent/src/messaging/types.rs +1 -0
- package/crates/team-agent/src/provider/adapter.rs +303 -51
- 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 -5
- 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 +106 -6
- package/crates/team-agent/src/provider/session/context_fork/claude.rs +123 -0
- package/crates/team-agent/src/provider/session/context_fork/outcome.rs +4 -0
- package/crates/team-agent/src/provider/session/context_fork.rs +150 -18
- package/crates/team-agent/src/provider/session_scan/claude.rs +523 -0
- package/crates/team-agent/src/provider/session_scan/common.rs +44 -8
- package/crates/team-agent/src/provider/session_scan/pi.rs +34 -1
- package/crates/team-agent/src/provider/session_scan.rs +16 -6
- package/crates/team-agent/src/provider/tests/adapter.rs +104 -17
- package/crates/team-agent/src/provider/tests/classify.rs +0 -53
- package/crates/team-agent/src/provider/tests/command_helpers.rs +12 -3
- package/crates/team-agent/src/provider/tests/idle.rs +37 -0
- package/crates/team-agent/src/provider/wire.rs +22 -34
- 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 +5 -40
- package/package.json +4 -4
- package/skills/team-agent/SKILL.md +5 -7
- package/skills/team-agent/command-coverage.json +1 -1
- package/skills/team-agent/docs/reference/team-agent-operator.md +3 -3
- package/skills/team-agent/references/team-agent-operator.md +3 -3
|
@@ -147,6 +147,7 @@ pub(crate) fn rollback_add_agent_atomic(
|
|
|
147
147
|
/// params:
|
|
148
148
|
/// meta: 角色文档 front matter
|
|
149
149
|
/// dynamic_role_file: 角色文件路径,记进 state 供 restart 重建 spec 用
|
|
150
|
+
/// fork_parent: 给出时首次 spawn 以原生 fork 继承该会话,起成后即清除
|
|
150
151
|
/// returns: 成功返回空值,席位状态记为 starting
|
|
151
152
|
/// errors: 读或写 runtime state 失败时返回 StatePersist
|
|
152
153
|
/// ---
|
|
@@ -156,11 +157,22 @@ pub(super) fn upsert_agent_state_from_role(
|
|
|
156
157
|
agent_id: &AgentId,
|
|
157
158
|
meta: &Value,
|
|
158
159
|
dynamic_role_file: &Path,
|
|
160
|
+
fork_parent: Option<&crate::provider::SessionId>,
|
|
159
161
|
) -> Result<(), LifecycleError> {
|
|
160
|
-
let entry = starting_agent_entry(workspace, agent_id, meta, dynamic_role_file);
|
|
162
|
+
let mut entry = starting_agent_entry(workspace, agent_id, meta, dynamic_role_file);
|
|
163
|
+
if let (Some(parent), Some(object)) = (fork_parent, entry.as_object_mut()) {
|
|
164
|
+
object.insert(
|
|
165
|
+
FORK_PARENT_SESSION_ID.to_string(),
|
|
166
|
+
serde_json::json!(parent.as_str()),
|
|
167
|
+
);
|
|
168
|
+
}
|
|
161
169
|
upsert_agent_entry(workspace, canonical_team_key, agent_id, entry)
|
|
162
170
|
}
|
|
163
171
|
|
|
172
|
+
/// One-shot spawn instruction: the next fresh spawn of this row natively forks
|
|
173
|
+
/// this parent session instead of starting empty. Every start consumes it.
|
|
174
|
+
pub(crate) const FORK_PARENT_SESSION_ID: &str = "_fork_parent_session_id";
|
|
175
|
+
|
|
164
176
|
/// ---
|
|
165
177
|
/// purpose: 把一席的 starting 行写进团队 state 并落盘
|
|
166
178
|
/// errors: 读或写 runtime state 失败时返回 StatePersist
|
|
@@ -203,6 +215,199 @@ pub(crate) fn upsert_agent_entry(
|
|
|
203
215
|
)
|
|
204
216
|
}
|
|
205
217
|
|
|
218
|
+
/// ---
|
|
219
|
+
/// purpose: 首次登记 Pi fork 席位,原子带入目标角色与完整 fork capture seed
|
|
220
|
+
/// returns: 成功后 TARGET 已按 ForkAgent typed intent 登记为 starting
|
|
221
|
+
/// errors: 重复席位、无效 capture seed 或 state 写入失败时拒绝
|
|
222
|
+
/// ---
|
|
223
|
+
pub(crate) fn fork_upsert_agent_state_from_role(
|
|
224
|
+
workspace: &Path,
|
|
225
|
+
canonical_team_key: &str,
|
|
226
|
+
agent_id: &AgentId,
|
|
227
|
+
meta: &Value,
|
|
228
|
+
compiled_agent: &Value,
|
|
229
|
+
dynamic_role_file: &Path,
|
|
230
|
+
seed: &ForkCaptureSeed,
|
|
231
|
+
) -> Result<(), LifecycleError> {
|
|
232
|
+
if agent_id == &seed.source_agent_id {
|
|
233
|
+
return Err(LifecycleError::RequirementUnmet(
|
|
234
|
+
"fork target must differ from source".to_string(),
|
|
235
|
+
));
|
|
236
|
+
}
|
|
237
|
+
if seed.captured.captured_via != crate::provider::CaptureVia::ForkSnapshot
|
|
238
|
+
|| seed.captured.attribution_confidence != crate::provider::Confidence::High
|
|
239
|
+
|| seed.captured.session_id.is_none()
|
|
240
|
+
|| seed.captured.rollout_path.is_none()
|
|
241
|
+
|| seed.captured_at.is_empty()
|
|
242
|
+
{
|
|
243
|
+
return Err(LifecycleError::RequirementUnmet(
|
|
244
|
+
"fork capture seed is incomplete or not a verified Pi snapshot".to_string(),
|
|
245
|
+
));
|
|
246
|
+
}
|
|
247
|
+
if compiled_agent.get("id").and_then(Value::as_str) != Some(agent_id.as_str()) {
|
|
248
|
+
return Err(LifecycleError::Compile(
|
|
249
|
+
"compiled fork role id does not match target".to_string(),
|
|
250
|
+
));
|
|
251
|
+
}
|
|
252
|
+
let sessions_root = std::fs::canonicalize(&seed.pi_sessions_root)
|
|
253
|
+
.map_err(|e| LifecycleError::StatePersist(e.to_string()))?;
|
|
254
|
+
let backing = seed.captured.rollout_path.as_ref().ok_or_else(|| {
|
|
255
|
+
LifecycleError::RequirementUnmet("fork backing path is missing".to_string())
|
|
256
|
+
})?;
|
|
257
|
+
let backing_path = std::fs::canonicalize(&backing.0)
|
|
258
|
+
.map_err(|e| LifecycleError::StatePersist(e.to_string()))?;
|
|
259
|
+
if !backing_path.starts_with(&sessions_root) {
|
|
260
|
+
return Err(LifecycleError::RequirementUnmet(
|
|
261
|
+
"fork backing is outside the target Pi session root".to_string(),
|
|
262
|
+
));
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
let mut state =
|
|
266
|
+
crate::state::projection::select_runtime_state(workspace, Some(canonical_team_key))
|
|
267
|
+
.map_err(|e| LifecycleError::TeamSelect(e.to_string()))?;
|
|
268
|
+
if !state.is_object() {
|
|
269
|
+
state = serde_json::json!({});
|
|
270
|
+
}
|
|
271
|
+
let root = state.as_object_mut().ok_or_else(|| {
|
|
272
|
+
LifecycleError::StatePersist("runtime state root is not an object".to_string())
|
|
273
|
+
})?;
|
|
274
|
+
let agents = root
|
|
275
|
+
.entry("agents".to_string())
|
|
276
|
+
.or_insert_with(|| serde_json::json!({}));
|
|
277
|
+
if !agents.is_object() {
|
|
278
|
+
*agents = serde_json::json!({});
|
|
279
|
+
}
|
|
280
|
+
let agent_map = agents.as_object_mut().ok_or_else(|| {
|
|
281
|
+
LifecycleError::StatePersist("runtime state agents is not an object".to_string())
|
|
282
|
+
})?;
|
|
283
|
+
if agent_map.contains_key(agent_id.as_str()) {
|
|
284
|
+
return Err(LifecycleError::RequirementUnmet(format!(
|
|
285
|
+
"agent id already exists in selected team: {}",
|
|
286
|
+
agent_id
|
|
287
|
+
)));
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
let source_profile_dir = agent_map
|
|
291
|
+
.get(seed.source_agent_id.as_str())
|
|
292
|
+
.and_then(serde_json::Value::as_object)
|
|
293
|
+
.and_then(|source| source.get("_profile_dir"))
|
|
294
|
+
.and_then(serde_json::Value::as_str)
|
|
295
|
+
.filter(|path| !path.is_empty())
|
|
296
|
+
.map(|path| serde_json::json!(path));
|
|
297
|
+
let mut entry = starting_agent_entry(workspace, agent_id, meta, dynamic_role_file);
|
|
298
|
+
let entry_object = entry.as_object_mut().ok_or_else(|| {
|
|
299
|
+
LifecycleError::StatePersist("fork target entry is not an object".to_string())
|
|
300
|
+
})?;
|
|
301
|
+
for field in [
|
|
302
|
+
"provider",
|
|
303
|
+
"auth_mode",
|
|
304
|
+
"role",
|
|
305
|
+
"model",
|
|
306
|
+
"effort",
|
|
307
|
+
"profile",
|
|
308
|
+
"tools",
|
|
309
|
+
"system_prompt",
|
|
310
|
+
"output_contract",
|
|
311
|
+
"communication_mode",
|
|
312
|
+
"working_directory",
|
|
313
|
+
"cwd",
|
|
314
|
+
"config",
|
|
315
|
+
"name",
|
|
316
|
+
"dangerously_skip_permissions",
|
|
317
|
+
] {
|
|
318
|
+
if let Some(value) = compiled_agent.get(field) {
|
|
319
|
+
entry_object.insert(field.to_string(), yaml_value_to_json(value));
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
if compiled_agent.get("model").is_some() && !entry_object.contains_key("model_source") {
|
|
323
|
+
entry_object.insert("model_source".to_string(), serde_json::json!("team"));
|
|
324
|
+
}
|
|
325
|
+
entry_object.insert("agent_id".to_string(), serde_json::json!(agent_id.as_str()));
|
|
326
|
+
entry_object.insert("label".to_string(), serde_json::json!(agent_id.as_str()));
|
|
327
|
+
entry_object.insert(
|
|
328
|
+
"owner_team_id".to_string(),
|
|
329
|
+
serde_json::json!(canonical_team_key),
|
|
330
|
+
);
|
|
331
|
+
entry_object.insert(
|
|
332
|
+
"claude_projects_root".to_string(),
|
|
333
|
+
serde_json::json!(sessions_root.to_string_lossy().to_string()),
|
|
334
|
+
);
|
|
335
|
+
entry_object.insert(
|
|
336
|
+
"forked_from".to_string(),
|
|
337
|
+
serde_json::json!(seed.source_agent_id.as_str()),
|
|
338
|
+
);
|
|
339
|
+
entry_object.insert(
|
|
340
|
+
"spawn_cwd".to_string(),
|
|
341
|
+
serde_json::json!(seed.captured.spawn_cwd.to_string_lossy().to_string()),
|
|
342
|
+
);
|
|
343
|
+
entry_object.insert(
|
|
344
|
+
"session_id".to_string(),
|
|
345
|
+
serde_json::json!(seed.captured.session_id.as_ref().map(|id| id.as_str())),
|
|
346
|
+
);
|
|
347
|
+
let backing = seed.captured.rollout_path.as_ref().ok_or_else(|| {
|
|
348
|
+
LifecycleError::RequirementUnmet("fork backing path is missing".to_string())
|
|
349
|
+
})?;
|
|
350
|
+
entry_object.insert(
|
|
351
|
+
"rollout_path".to_string(),
|
|
352
|
+
serde_json::json!(backing.0.to_string_lossy().to_string()),
|
|
353
|
+
);
|
|
354
|
+
entry_object.insert(
|
|
355
|
+
"captured_at".to_string(),
|
|
356
|
+
serde_json::json!(seed.captured_at.as_str()),
|
|
357
|
+
);
|
|
358
|
+
entry_object.insert(
|
|
359
|
+
"captured_via".to_string(),
|
|
360
|
+
serde_json::to_value(seed.captured.captured_via)
|
|
361
|
+
.map_err(|e| LifecycleError::StatePersist(e.to_string()))?,
|
|
362
|
+
);
|
|
363
|
+
entry_object.insert(
|
|
364
|
+
"attribution_confidence".to_string(),
|
|
365
|
+
serde_json::to_value(seed.captured.attribution_confidence)
|
|
366
|
+
.map_err(|e| LifecycleError::StatePersist(e.to_string()))?,
|
|
367
|
+
);
|
|
368
|
+
entry_object.insert("capture_state".to_string(), serde_json::json!("captured"));
|
|
369
|
+
if let Some(profile_dir) = source_profile_dir {
|
|
370
|
+
entry_object.insert("_profile_dir".to_string(), profile_dir);
|
|
371
|
+
} else {
|
|
372
|
+
entry_object.insert(
|
|
373
|
+
"_profile_dir".to_string(),
|
|
374
|
+
serde_json::json!(seed.profile_dir.to_string_lossy().to_string()),
|
|
375
|
+
);
|
|
376
|
+
}
|
|
377
|
+
agent_map.insert(agent_id.as_str().to_string(), entry);
|
|
378
|
+
crate::lifecycle::restart::remove::clear_agent_retirement_in_state(&mut state, agent_id);
|
|
379
|
+
crate::state::repository::StateRepository::new(workspace)
|
|
380
|
+
.save(
|
|
381
|
+
crate::state::repository::StateWriteIntent::ForkAgent {
|
|
382
|
+
team_key: canonical_team_key,
|
|
383
|
+
agent_id: agent_id.as_str(),
|
|
384
|
+
},
|
|
385
|
+
&state,
|
|
386
|
+
)
|
|
387
|
+
.map_err(|e| LifecycleError::StatePersist(e.to_string()))
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
fn yaml_value_to_json(value: &Value) -> serde_json::Value {
|
|
391
|
+
match value {
|
|
392
|
+
Value::Null => serde_json::Value::Null,
|
|
393
|
+
Value::Bool(value) => serde_json::json!(value),
|
|
394
|
+
Value::Int(value) => serde_json::json!(value),
|
|
395
|
+
Value::Float(value) => serde_json::Number::from_f64(*value)
|
|
396
|
+
.map(serde_json::Value::Number)
|
|
397
|
+
.unwrap_or(serde_json::Value::Null),
|
|
398
|
+
Value::Str(value) => serde_json::json!(value),
|
|
399
|
+
Value::List(values) => {
|
|
400
|
+
serde_json::Value::Array(values.iter().map(yaml_value_to_json).collect())
|
|
401
|
+
}
|
|
402
|
+
Value::Map(values) => serde_json::Value::Object(
|
|
403
|
+
values
|
|
404
|
+
.iter()
|
|
405
|
+
.map(|(key, value)| (key.clone(), yaml_value_to_json(value)))
|
|
406
|
+
.collect(),
|
|
407
|
+
),
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
|
|
206
411
|
fn starting_agent_entry(
|
|
207
412
|
workspace: &Path,
|
|
208
413
|
agent_id: &AgentId,
|
|
@@ -47,7 +47,7 @@ pub fn clone_agent(
|
|
|
47
47
|
.ok_or_else(|| {
|
|
48
48
|
LifecycleError::RequirementUnmet(format!("unknown worker agent id: {source_agent_id}"))
|
|
49
49
|
})?;
|
|
50
|
-
// A pre-upgrade
|
|
50
|
+
// A pre-upgrade Codex or Grok row has no legacy runtime to clone onto.
|
|
51
51
|
if let Some(retired) = source_agent
|
|
52
52
|
.get("provider")
|
|
53
53
|
.and_then(serde_json::Value::as_str)
|
|
@@ -132,11 +132,37 @@ fn read_agent_session(
|
|
|
132
132
|
.get("rollout_path")
|
|
133
133
|
.and_then(serde_json::Value::as_str)
|
|
134
134
|
.filter(|value| !value.is_empty())
|
|
135
|
-
.map(std::path::PathBuf::from)
|
|
135
|
+
.map(std::path::PathBuf::from)
|
|
136
|
+
.or_else(|| find_claude_backing(agent, session))?;
|
|
136
137
|
let distinct = source_session_id.is_none_or(|source| source.as_str() != session);
|
|
137
138
|
(distinct && backing.is_file()).then(|| (SessionId::new(session), backing))
|
|
138
139
|
}
|
|
139
140
|
|
|
141
|
+
fn find_claude_backing(agent: &serde_json::Value, session: &str) -> Option<std::path::PathBuf> {
|
|
142
|
+
let root = agent
|
|
143
|
+
.get("claude_projects_root")
|
|
144
|
+
.and_then(serde_json::Value::as_str)
|
|
145
|
+
.map(std::path::PathBuf::from)
|
|
146
|
+
.or_else(|| {
|
|
147
|
+
std::env::var_os("HOME")
|
|
148
|
+
.map(|home| std::path::PathBuf::from(home).join(".claude/projects"))
|
|
149
|
+
})?;
|
|
150
|
+
let target = format!("{session}.jsonl");
|
|
151
|
+
let mut pending = vec![root];
|
|
152
|
+
while let Some(dir) = pending.pop() {
|
|
153
|
+
let entries = std::fs::read_dir(&dir).ok()?;
|
|
154
|
+
for entry in entries.flatten() {
|
|
155
|
+
let path = entry.path();
|
|
156
|
+
if path.is_dir() {
|
|
157
|
+
pending.push(path);
|
|
158
|
+
} else if path.file_name().and_then(|name| name.to_str()) == Some(target.as_str()) {
|
|
159
|
+
return Some(path);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
None
|
|
164
|
+
}
|
|
165
|
+
|
|
140
166
|
fn persist_clone_session(
|
|
141
167
|
workspace: &Path,
|
|
142
168
|
team_key: &str,
|
|
@@ -1,31 +1,36 @@
|
|
|
1
1
|
//! ---
|
|
2
|
-
//! purpose: legacy 席位的 fork
|
|
2
|
+
//! purpose: legacy 席位的 fork 入口:Pi 以完整会话快照、Claude 以原生 --fork-session 创建独立席位;其余 legacy 席位拒绝
|
|
3
3
|
//! contract:
|
|
4
4
|
//! provides:
|
|
5
5
|
//! - name: fork_agent_with_transport
|
|
6
|
-
//! what:
|
|
6
|
+
//! what: 持席位生命周期锁读取源席;Pi 走锁内快照新席位;Claude 走锁内原生 fork 新席位,不再原地 /branch;升级前遗留的 codex/grok worker 行按退役拒绝,其余 legacy provider 报未验证
|
|
7
7
|
//! depends:
|
|
8
8
|
//! - crate::lifecycle::lock
|
|
9
|
+
//! - crate::lifecycle::profile_launch
|
|
9
10
|
//! boundary:
|
|
10
|
-
//! -
|
|
11
|
-
//! -
|
|
11
|
+
//! - 仅 Pi 与 Claude 的锁内专用管道注册并启动新席位;contract 席位只由 contract_runtime::fork 管道 fork
|
|
12
|
+
//! - 不注入窗口,不改 TEAM_AGENT_ID / MCP / 席位名
|
|
12
13
|
//! - 未验证的 provider 不猜斜杠命令
|
|
13
14
|
//! maturity: wired
|
|
14
15
|
//! ---
|
|
15
16
|
|
|
16
17
|
use super::*;
|
|
18
|
+
use crate::lifecycle::profile_launch::parse_provider;
|
|
19
|
+
use crate::model::enums::Provider;
|
|
17
20
|
|
|
18
21
|
/// ---
|
|
19
|
-
/// purpose: legacy 席位的 fork
|
|
22
|
+
/// purpose: legacy 席位的 fork:Pi / Claude 在锁内创建独立新席位,其余只读源席后拒绝
|
|
20
23
|
/// params:
|
|
21
24
|
/// source_agent_id: 被 fork 的席位
|
|
22
25
|
/// as_agent_id: 新席位名
|
|
23
|
-
/// transport: 目标 team 实际使用的 transport
|
|
24
|
-
/// returns:
|
|
26
|
+
/// transport: 目标 team 实际使用的 transport
|
|
27
|
+
/// returns: Pi / Claude 的新席位 fork 报告;contract 席位在此之前已由 contract 管道处理
|
|
25
28
|
/// errors: 选不到 team 返回 TeamSelect,退役 provider 行与其余 legacy provider 返回 Provider
|
|
26
29
|
/// ---
|
|
27
|
-
///
|
|
28
|
-
///
|
|
30
|
+
/// Claude's in-window `/branch` and Grok's in-window `/fork` are retired:
|
|
31
|
+
/// Claude forks into a new seat through its native `--fork-session`
|
|
32
|
+
/// (restart::claude_fork), Pi through its full session snapshot
|
|
33
|
+
/// (restart::avatar); Codex and Grok fork only through the contract pipeline
|
|
29
34
|
/// (`contract_runtime::fork`).
|
|
30
35
|
pub fn fork_agent_with_transport(
|
|
31
36
|
workspace: &Path,
|
|
@@ -36,7 +41,6 @@ pub fn fork_agent_with_transport(
|
|
|
36
41
|
team: Option<&str>,
|
|
37
42
|
transport: &dyn Transport,
|
|
38
43
|
) -> Result<ForkAgentReport, LifecycleError> {
|
|
39
|
-
let _ = (as_agent_id, label, open_display, transport);
|
|
40
44
|
let selected = crate::state::selector::resolve_active_team(
|
|
41
45
|
workspace,
|
|
42
46
|
team,
|
|
@@ -68,14 +72,35 @@ pub fn fork_agent_with_transport(
|
|
|
68
72
|
.get("provider")
|
|
69
73
|
.and_then(serde_json::Value::as_str)
|
|
70
74
|
.unwrap_or("unknown");
|
|
71
|
-
// A pre-upgrade
|
|
72
|
-
//
|
|
73
|
-
// this point.
|
|
75
|
+
// A pre-upgrade Codex or Grok row has no legacy runtime to fork from;
|
|
76
|
+
// contract seats fork through the contract pipeline before this point.
|
|
74
77
|
if crate::provider::wire::is_retired_provider(provider_raw) {
|
|
75
78
|
return Err(LifecycleError::Provider(
|
|
76
79
|
crate::provider::wire::retired_provider_error(provider_raw).into(),
|
|
77
80
|
));
|
|
78
81
|
}
|
|
82
|
+
match parse_provider(provider_raw) {
|
|
83
|
+
Some(Provider::Pi) => {
|
|
84
|
+
return crate::lifecycle::restart::fork_pi_new_seat_locked(
|
|
85
|
+
&selected,
|
|
86
|
+
source_agent_id,
|
|
87
|
+
as_agent_id,
|
|
88
|
+
label,
|
|
89
|
+
transport,
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
Some(Provider::Claude | Provider::ClaudeCode) => {
|
|
93
|
+
return crate::lifecycle::restart::fork_claude_new_seat_locked(
|
|
94
|
+
&selected,
|
|
95
|
+
source_agent_id,
|
|
96
|
+
as_agent_id,
|
|
97
|
+
label,
|
|
98
|
+
open_display,
|
|
99
|
+
transport,
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
_ => {}
|
|
103
|
+
}
|
|
79
104
|
Err(LifecycleError::Provider(format!(
|
|
80
105
|
"{provider_raw} native session fork is unverified (未验证); no legacy fork or fresh replacement was performed"
|
|
81
106
|
)))
|
|
@@ -44,13 +44,39 @@ pub fn fork_agent(
|
|
|
44
44
|
.map_err(|e| LifecycleError::TeamSelect(e.to_string()))?;
|
|
45
45
|
// Fork-agent routes to the selected live team's persisted endpoint, not
|
|
46
46
|
// the workspace-hash fallback socket.
|
|
47
|
-
let
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
47
|
+
let is_pi = selected
|
|
48
|
+
.state
|
|
49
|
+
.get("agents")
|
|
50
|
+
.and_then(|agents| agents.get(source_agent_id.as_str()))
|
|
51
|
+
.and_then(|agent| agent.get("provider"))
|
|
52
|
+
.and_then(serde_json::Value::as_str)
|
|
53
|
+
== Some("pi");
|
|
54
|
+
let transport: Box<dyn crate::transport::Transport> = if is_pi {
|
|
55
|
+
#[cfg(test)]
|
|
56
|
+
{
|
|
57
|
+
test_fork_transport(&selected, source_agent_id)
|
|
58
|
+
}
|
|
59
|
+
#[cfg(not(test))]
|
|
60
|
+
{
|
|
61
|
+
Box::new(
|
|
62
|
+
crate::lifecycle::restart::lifecycle_worker_tmux_backend_selection_for_state(
|
|
63
|
+
&selected.run_workspace,
|
|
64
|
+
&selected.state,
|
|
65
|
+
)?
|
|
66
|
+
.backend,
|
|
67
|
+
)
|
|
68
|
+
}
|
|
69
|
+
} else {
|
|
70
|
+
Box::new(
|
|
71
|
+
crate::lifecycle::restart::lifecycle_worker_tmux_backend_for_selected_state(
|
|
72
|
+
&selected.run_workspace,
|
|
73
|
+
Some(selected.team_key.as_str()),
|
|
74
|
+
)
|
|
75
|
+
.unwrap_or_else(|_| {
|
|
76
|
+
crate::tmux_backend::TmuxBackend::for_workspace(&selected.run_workspace)
|
|
77
|
+
}),
|
|
51
78
|
)
|
|
52
|
-
|
|
53
|
-
);
|
|
79
|
+
};
|
|
54
80
|
fork_agent_with_transport(
|
|
55
81
|
workspace,
|
|
56
82
|
source_agent_id,
|
|
@@ -61,3 +87,58 @@ pub fn fork_agent(
|
|
|
61
87
|
transport.as_ref(),
|
|
62
88
|
)
|
|
63
89
|
}
|
|
90
|
+
|
|
91
|
+
#[cfg(test)]
|
|
92
|
+
fn test_fork_transport(
|
|
93
|
+
selected: &crate::state::selector::SelectedTeam,
|
|
94
|
+
source_agent_id: &AgentId,
|
|
95
|
+
) -> Box<dyn crate::transport::Transport> {
|
|
96
|
+
let state = &selected.state;
|
|
97
|
+
let session = state
|
|
98
|
+
.get("session_name")
|
|
99
|
+
.and_then(serde_json::Value::as_str)
|
|
100
|
+
.filter(|value| !value.is_empty())
|
|
101
|
+
.map(crate::transport::SessionName::new)
|
|
102
|
+
.unwrap_or_else(|| crate::transport::SessionName::new("offline"));
|
|
103
|
+
let source = state
|
|
104
|
+
.get("agents")
|
|
105
|
+
.and_then(|agents| agents.get(source_agent_id.as_str()));
|
|
106
|
+
let targets = source
|
|
107
|
+
.and_then(|agent| agent.get("pane_id"))
|
|
108
|
+
.and_then(serde_json::Value::as_str)
|
|
109
|
+
.filter(|pane| !pane.is_empty())
|
|
110
|
+
.map(|pane| {
|
|
111
|
+
let window = source
|
|
112
|
+
.and_then(|agent| agent.get("window"))
|
|
113
|
+
.and_then(serde_json::Value::as_str)
|
|
114
|
+
.filter(|value| !value.is_empty())
|
|
115
|
+
.unwrap_or(source_agent_id.as_str());
|
|
116
|
+
vec![crate::transport::PaneInfo {
|
|
117
|
+
pane_id: crate::transport::PaneId::new(pane),
|
|
118
|
+
session: session.clone(),
|
|
119
|
+
window_index: None,
|
|
120
|
+
window_name: Some(crate::transport::WindowName::new(window)),
|
|
121
|
+
pane_index: None,
|
|
122
|
+
tty: None,
|
|
123
|
+
current_command: None,
|
|
124
|
+
current_path: None,
|
|
125
|
+
active: false,
|
|
126
|
+
pane_pid: None,
|
|
127
|
+
leader_env: std::collections::BTreeMap::new(),
|
|
128
|
+
}]
|
|
129
|
+
})
|
|
130
|
+
.unwrap_or_default();
|
|
131
|
+
let endpoint = state
|
|
132
|
+
.get("tmux_endpoint")
|
|
133
|
+
.or_else(|| state.get("tmux_socket"))
|
|
134
|
+
.and_then(serde_json::Value::as_str)
|
|
135
|
+
.filter(|value| !value.is_empty())
|
|
136
|
+
.map(str::to_string)
|
|
137
|
+
.unwrap_or_else(|| "offline".to_string());
|
|
138
|
+
Box::new(
|
|
139
|
+
crate::transport::test_support::OfflineTransport::new()
|
|
140
|
+
.with_session_present(true)
|
|
141
|
+
.with_targets(targets)
|
|
142
|
+
.with_tmux_endpoint(endpoint),
|
|
143
|
+
)
|
|
144
|
+
}
|
|
@@ -127,7 +127,7 @@ pub(crate) fn write_worker_mcp_config_for_provider(
|
|
|
127
127
|
/// ---
|
|
128
128
|
/// purpose: 把 argv 里 provider 原生的 MCP 配置参数改指到已落盘的文件
|
|
129
129
|
/// params:
|
|
130
|
-
/// argv: 就地改写;copilot 改 --additional-mcp-config 并加 @ 前缀
|
|
130
|
+
/// argv: 就地改写;claude 系改 --mcp-config 的值,copilot 改 --additional-mcp-config 并加 @ 前缀
|
|
131
131
|
/// returns: argv 里没有对应参数时什么都不做
|
|
132
132
|
/// ---
|
|
133
133
|
pub(crate) fn point_native_mcp_config_at_file(
|
|
@@ -136,6 +136,14 @@ pub(crate) fn point_native_mcp_config_at_file(
|
|
|
136
136
|
path: &Path,
|
|
137
137
|
) {
|
|
138
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
|
+
}
|
|
139
147
|
// §C1 note: copilot `--additional-mcp-config` 接受 `@file`,直接指向既有
|
|
140
148
|
// `.team/runtime/mcp/<agent>.json`(launch 路径 write_worker_mcp_config 已写)。
|
|
141
149
|
// 既避免 inline JSON 包 mcpServers wrapper 的语义错位,也更利于 ps 验法。
|