@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
|
@@ -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,91 +1,37 @@
|
|
|
1
1
|
//! ---
|
|
2
|
-
//! purpose: legacy
|
|
2
|
+
//! purpose: legacy 席位的 fork 入口:Pi 以完整会话快照、Claude 以原生 --fork-session 创建独立席位;其余 legacy 席位拒绝
|
|
3
3
|
//! contract:
|
|
4
4
|
//! provides:
|
|
5
5
|
//! - name: fork_agent_with_transport
|
|
6
|
-
//! what:
|
|
7
|
-
//! - name: in_window_fork
|
|
8
|
-
//! what: 已验证的 provider+subscription 给出 command+screen_mark;未验证返回 None
|
|
6
|
+
//! what: 持席位生命周期锁读取源席;Pi 走锁内快照新席位;Claude 走锁内原生 fork 新席位,不再原地 /branch;升级前遗留的 codex/grok worker 行按退役拒绝,其余 legacy provider 报未验证
|
|
9
7
|
//! depends:
|
|
10
8
|
//! - crate::lifecycle::lock
|
|
11
|
-
//! - crate::lifecycle::pane_input_lock
|
|
12
9
|
//! - crate::lifecycle::profile_launch
|
|
13
|
-
//! - crate::transport::Transport
|
|
14
10
|
//! boundary:
|
|
15
|
-
//! -
|
|
16
|
-
//! -
|
|
17
|
-
//! - 重试只重按回车,不重粘 /fork
|
|
18
|
-
//! - 不把 pane 锁超时从 200ms 调大
|
|
11
|
+
//! - 仅 Pi 与 Claude 的锁内专用管道注册并启动新席位;contract 席位只由 contract_runtime::fork 管道 fork
|
|
12
|
+
//! - 不注入窗口,不改 TEAM_AGENT_ID / MCP / 席位名
|
|
19
13
|
//! - 未验证的 provider 不猜斜杠命令
|
|
20
14
|
//! maturity: wired
|
|
21
15
|
//! ---
|
|
22
16
|
|
|
23
17
|
use super::*;
|
|
24
|
-
use crate::lifecycle::
|
|
25
|
-
|
|
26
|
-
};
|
|
27
|
-
use crate::lifecycle::profile_launch::{parse_auth_mode, parse_provider};
|
|
28
|
-
use crate::model::enums::{AuthMode, Provider};
|
|
29
|
-
|
|
30
|
-
const MAX_ENTER_RETRIES: u32 = 8;
|
|
31
|
-
|
|
32
|
-
/// Injected slash command + the screen mark that proves it landed.
|
|
33
|
-
/// Difference between providers lives only in this data.
|
|
34
|
-
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
|
35
|
-
pub struct InWindowFork {
|
|
36
|
-
pub command: &'static str,
|
|
37
|
-
pub screen_mark: &'static str,
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/// ---
|
|
41
|
-
/// purpose: 给出该 provider 与鉴权方式下窗口内 fork 用的斜杠命令与成功标记
|
|
42
|
-
/// returns: 已实测验证的组合返回命令与屏幕标记,其余一律 None
|
|
43
|
-
/// ---
|
|
44
|
-
/// Official in-window fork. None = unverified or unsupported-auth.
|
|
45
|
-
/// grok `/fork` mark `forked from` (2026-08-17).
|
|
46
|
-
/// Claude's `/branch` is retired here: it moves the SOURCE process onto the
|
|
47
|
-
/// branch (renamed "<title> (Branch)") while the seat's captured tuple still
|
|
48
|
-
/// names the old session, and creates no seat. Claude Code and Pi fork only
|
|
49
|
-
/// into a new seat through the contract pipeline (`contract_runtime::fork`).
|
|
50
|
-
pub fn in_window_fork(provider: Provider, auth: AuthMode) -> Option<InWindowFork> {
|
|
51
|
-
match (provider, auth) {
|
|
52
|
-
(Provider::Grok, AuthMode::Subscription) => Some(InWindowFork {
|
|
53
|
-
command: "/fork",
|
|
54
|
-
screen_mark: "forked from",
|
|
55
|
-
}),
|
|
56
|
-
_ => None,
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/// ---
|
|
61
|
-
/// purpose: 只取窗口内 fork 的斜杠命令
|
|
62
|
-
/// returns: 有已验证组合时返回命令,否则 None
|
|
63
|
-
/// ---
|
|
64
|
-
pub fn in_window_fork_command(provider: Provider, auth: AuthMode) -> Option<&'static str> {
|
|
65
|
-
in_window_fork(provider, auth).map(|spec| spec.command)
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
fn refuse_missing_in_window_fork(provider: Provider, provider_raw: &str) -> LifecycleError {
|
|
69
|
-
if matches!(provider, Provider::Grok | Provider::Pi) {
|
|
70
|
-
LifecycleError::Provider(format!(
|
|
71
|
-
"{provider_raw} does not support native session fork"
|
|
72
|
-
))
|
|
73
|
-
} else {
|
|
74
|
-
LifecycleError::Provider(format!(
|
|
75
|
-
"{provider_raw} in-window fork is unverified (未验证)"
|
|
76
|
-
))
|
|
77
|
-
}
|
|
78
|
-
}
|
|
18
|
+
use crate::lifecycle::profile_launch::parse_provider;
|
|
19
|
+
use crate::model::enums::Provider;
|
|
79
20
|
|
|
80
21
|
/// ---
|
|
81
|
-
/// purpose:
|
|
22
|
+
/// purpose: legacy 席位的 fork:Pi / Claude 在锁内创建独立新席位,其余只读源席后拒绝
|
|
82
23
|
/// params:
|
|
83
24
|
/// source_agent_id: 被 fork 的席位
|
|
84
25
|
/// as_agent_id: 新席位名
|
|
85
26
|
/// transport: 目标 team 实际使用的 transport
|
|
86
|
-
/// returns: fork
|
|
87
|
-
/// errors: 选不到 team 返回 TeamSelect
|
|
27
|
+
/// returns: Pi / Claude 的新席位 fork 报告;contract 席位在此之前已由 contract 管道处理
|
|
28
|
+
/// errors: 选不到 team 返回 TeamSelect,退役 provider 行与其余 legacy provider 返回 Provider
|
|
88
29
|
/// ---
|
|
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
|
|
34
|
+
/// (`contract_runtime::fork`).
|
|
89
35
|
pub fn fork_agent_with_transport(
|
|
90
36
|
workspace: &Path,
|
|
91
37
|
source_agent_id: &AgentId,
|
|
@@ -115,7 +61,6 @@ pub fn fork_agent_with_transport(
|
|
|
115
61
|
crate::state::selector::SelectorMode::RequireSpec,
|
|
116
62
|
)
|
|
117
63
|
.map_err(|e| LifecycleError::TeamSelect(e.to_string()))?;
|
|
118
|
-
let run_ws = selected.run_workspace.clone();
|
|
119
64
|
let agent = selected
|
|
120
65
|
.state
|
|
121
66
|
.get("agents")
|
|
@@ -127,124 +72,36 @@ pub fn fork_agent_with_transport(
|
|
|
127
72
|
.get("provider")
|
|
128
73
|
.and_then(serde_json::Value::as_str)
|
|
129
74
|
.unwrap_or("unknown");
|
|
130
|
-
|
|
131
|
-
.get("auth_mode")
|
|
132
|
-
.and_then(serde_json::Value::as_str)
|
|
133
|
-
.unwrap_or("subscription");
|
|
134
|
-
// A pre-upgrade Claude Code or Pi row has no legacy runtime to fork from;
|
|
75
|
+
// A pre-upgrade Codex or Grok row has no legacy runtime to fork from;
|
|
135
76
|
// contract seats fork through the contract pipeline before this point.
|
|
136
77
|
if crate::provider::wire::is_retired_provider(provider_raw) {
|
|
137
78
|
return Err(LifecycleError::Provider(
|
|
138
79
|
crate::provider::wire::retired_provider_error(provider_raw).into(),
|
|
139
80
|
));
|
|
140
81
|
}
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
)));
|
|
151
|
-
}
|
|
152
|
-
let pane_raw = agent
|
|
153
|
-
.get("pane_id")
|
|
154
|
-
.and_then(serde_json::Value::as_str)
|
|
155
|
-
.filter(|s| !s.is_empty())
|
|
156
|
-
.ok_or_else(|| {
|
|
157
|
-
LifecycleError::RequirementUnmet(format!(
|
|
158
|
-
"source agent {source_agent_id} has no pane_id"
|
|
159
|
-
))
|
|
160
|
-
})?;
|
|
161
|
-
let target = Target::Pane(PaneId::new(pane_raw));
|
|
162
|
-
let lock = acquire_or_proceed(PaneInputLockRequest {
|
|
163
|
-
workspace: Some(&run_ws),
|
|
164
|
-
target_key: pane_raw,
|
|
165
|
-
operation: "fork-inject",
|
|
166
|
-
});
|
|
167
|
-
if lock.is_none() {
|
|
168
|
-
let _ = crate::event_log::EventLog::new(&run_ws).write(
|
|
169
|
-
PANE_INPUT_LOCK_TIMEOUT_EVENT,
|
|
170
|
-
serde_json::json!({
|
|
171
|
-
"during": "fork-inject",
|
|
172
|
-
"agent_id": source_agent_id.as_str(),
|
|
173
|
-
"pane_id": pane_raw,
|
|
174
|
-
"observed_at": chrono::Utc::now().to_rfc3339(),
|
|
175
|
-
}),
|
|
176
|
-
);
|
|
177
|
-
}
|
|
178
|
-
inject_clean_command(transport, &target, spec.command)?;
|
|
179
|
-
wait_for_screen_mark(transport, &target, spec.screen_mark)?;
|
|
180
|
-
drop(lock);
|
|
181
|
-
crate::event_log::EventLog::new(&run_ws)
|
|
182
|
-
.write(
|
|
183
|
-
"lifecycle.fork.in_place",
|
|
184
|
-
serde_json::json!({
|
|
185
|
-
"source_agent_id": source_agent_id.as_str(),
|
|
186
|
-
"agent_id": source_agent_id.as_str(),
|
|
187
|
-
"pane_id": pane_raw,
|
|
188
|
-
"command": spec.command,
|
|
189
|
-
"screen_mark": spec.screen_mark,
|
|
190
|
-
}),
|
|
191
|
-
)
|
|
192
|
-
.map_err(|e| LifecycleError::StatePersist(format!("fork audit write failed: {e}")))?;
|
|
193
|
-
Ok(ForkAgentReport {
|
|
194
|
-
source_agent_id: source_agent_id.clone(),
|
|
195
|
-
new_agent_id: source_agent_id.clone(),
|
|
196
|
-
env: AgentActionEnvelope {
|
|
197
|
-
agent_id: source_agent_id.clone(),
|
|
198
|
-
state_file: crate::state::persist::runtime_state_path(&run_ws),
|
|
199
|
-
coordinator_started: false,
|
|
200
|
-
},
|
|
201
|
-
session_id: None,
|
|
202
|
-
backing_state: ForkBackingState::Verified,
|
|
203
|
-
})
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
fn inject_clean_command(
|
|
207
|
-
transport: &dyn Transport,
|
|
208
|
-
target: &Target,
|
|
209
|
-
command: &str,
|
|
210
|
-
) -> Result<(), LifecycleError> {
|
|
211
|
-
transport
|
|
212
|
-
.inject(
|
|
213
|
-
target,
|
|
214
|
-
&crate::transport::InjectPayload::TextSkipConsumptionPoll(command.to_string()),
|
|
215
|
-
crate::transport::Key::Enter,
|
|
216
|
-
false,
|
|
217
|
-
)
|
|
218
|
-
.map_err(|e| LifecycleError::Transport(e.to_string()))?;
|
|
219
|
-
Ok(())
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
const NO_CONVERSATION_TO_BRANCH: &str = "Failed to branch conversation: No conversation to branch";
|
|
223
|
-
|
|
224
|
-
fn wait_for_screen_mark(
|
|
225
|
-
transport: &dyn Transport,
|
|
226
|
-
target: &Target,
|
|
227
|
-
screen_mark: &str,
|
|
228
|
-
) -> Result<(), LifecycleError> {
|
|
229
|
-
for attempt in 0..MAX_ENTER_RETRIES {
|
|
230
|
-
let cap = transport
|
|
231
|
-
.capture(target, crate::transport::CaptureRange::Tail(40))
|
|
232
|
-
.map_err(|e| LifecycleError::Transport(e.to_string()))?;
|
|
233
|
-
if cap.text.contains(screen_mark) {
|
|
234
|
-
return Ok(());
|
|
235
|
-
}
|
|
236
|
-
if cap.text.contains(NO_CONVERSATION_TO_BRANCH) {
|
|
237
|
-
return Err(LifecycleError::RequirementUnmet(
|
|
238
|
-
NO_CONVERSATION_TO_BRANCH.to_string(),
|
|
239
|
-
));
|
|
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
|
+
);
|
|
240
91
|
}
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
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
|
+
);
|
|
245
101
|
}
|
|
102
|
+
_ => {}
|
|
246
103
|
}
|
|
247
|
-
Err(LifecycleError::
|
|
248
|
-
"fork
|
|
104
|
+
Err(LifecycleError::Provider(format!(
|
|
105
|
+
"{provider_raw} native session fork is unverified (未验证); no legacy fork or fresh replacement was performed"
|
|
249
106
|
)))
|
|
250
107
|
}
|
|
@@ -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
|
+
}
|