@team-agent/installer 0.5.65 → 0.5.68
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 +8 -1
- package/Cargo.toml +1 -1
- package/crates/team-agent/Cargo.toml +6 -0
- package/crates/team-agent/src/cli/adapters.rs +6 -1
- package/crates/team-agent/src/cli/diagnose.rs +82 -0
- package/crates/team-agent/src/cli/emit.rs +3 -3
- package/crates/team-agent/src/cli/grok_slot.rs +299 -0
- package/crates/team-agent/src/cli/leader.rs +21 -7
- package/crates/team-agent/src/cli/leaders.rs +125 -1
- package/crates/team-agent/src/cli/mod.rs +20 -0
- package/crates/team-agent/src/cli/send/presentation.rs +7 -1
- package/crates/team-agent/src/cli/spec.rs +2 -0
- package/crates/team-agent/src/cli/status_port/compact.rs +28 -0
- package/crates/team-agent/src/cli/status_port/snapshot.rs +25 -1
- package/crates/team-agent/src/cli/tests/base.rs +26 -3
- package/crates/team-agent/src/cli/tests/compile.rs +1 -1
- package/crates/team-agent/src/cli/tests/missing_subcommands.rs +129 -19
- package/crates/team-agent/src/cli/tests/mod.rs +2 -2
- package/crates/team-agent/src/cli/tests/run_delegation.rs +1 -1
- package/crates/team-agent/src/cli/tests/shutdown_kill_plan.rs +387 -6
- package/crates/team-agent/src/cli/tests/status_send.rs +79 -10
- package/crates/team-agent/src/cli/tests/verb_validate.rs +1 -1
- package/crates/team-agent/src/communication_mode/mod.rs +6 -4
- package/crates/team-agent/src/compiler/tests.rs +23 -20
- package/crates/team-agent/src/compiler.rs +84 -5
- package/crates/team-agent/src/conpty/backend.rs +16 -0
- package/crates/team-agent/src/coordinator/backoff.rs +55 -0
- package/crates/team-agent/src/coordinator/conpty_shim.rs +82 -0
- package/crates/team-agent/src/coordinator/health.rs +173 -0
- package/crates/team-agent/src/coordinator/mod.rs +31 -0
- package/crates/team-agent/src/coordinator/orphan.rs +31 -0
- package/crates/team-agent/src/coordinator/runtime_detectors.rs +30 -0
- package/crates/team-agent/src/coordinator/runtime_observation.rs +25 -0
- package/crates/team-agent/src/coordinator/steps/abnormal.rs +59 -0
- package/crates/team-agent/src/coordinator/steps/delivery.rs +10 -0
- package/crates/team-agent/src/coordinator/steps/health_sync.rs +10 -0
- package/crates/team-agent/src/coordinator/steps/mod.rs +22 -0
- package/crates/team-agent/src/coordinator/steps/persist.rs +10 -0
- package/crates/team-agent/src/coordinator/steps/runtime_prompts.rs +10 -0
- package/crates/team-agent/src/coordinator/steps/session_gate.rs +10 -0
- package/crates/team-agent/src/coordinator/tick.rs +133 -22
- package/crates/team-agent/src/coordinator/types.rs +49 -0
- package/crates/team-agent/src/db/message_store.rs +39 -5
- package/crates/team-agent/src/layout/worker_env.rs +20 -3
- package/crates/team-agent/src/layout/worker_window_helpers.rs +2 -0
- package/crates/team-agent/src/leader/provider_attribution.rs +53 -0
- package/crates/team-agent/src/leader/registry.rs +65 -0
- package/crates/team-agent/src/leader/start.rs +1080 -58
- package/crates/team-agent/src/leader/tests/team_in_team_state_scope_red.rs +1 -1
- package/crates/team-agent/src/lifecycle/display.rs +56 -0
- package/crates/team-agent/src/lifecycle/helpers.rs +57 -0
- package/crates/team-agent/src/lifecycle/launch/add_agent.rs +332 -14
- package/crates/team-agent/src/lifecycle/launch/add_agent_state.rs +69 -2
- package/crates/team-agent/src/lifecycle/launch/agent_state.rs +196 -2
- package/crates/team-agent/src/lifecycle/launch/clone_agent.rs +101 -11
- package/crates/team-agent/src/lifecycle/launch/cursor_create_chat.rs +229 -0
- package/crates/team-agent/src/lifecycle/launch/cursor_mcp.rs +332 -0
- package/crates/team-agent/src/lifecycle/launch/fork_agent.rs +204 -457
- package/crates/team-agent/src/lifecycle/launch/fork_entry.rs +24 -0
- package/crates/team-agent/src/lifecycle/launch/grok_per_seat.rs +260 -0
- package/crates/team-agent/src/lifecycle/launch/identity.rs +146 -0
- package/crates/team-agent/src/lifecycle/launch/layout.rs +60 -0
- package/crates/team-agent/src/lifecycle/launch/leader_context.rs +112 -0
- package/crates/team-agent/src/lifecycle/launch/mcp_config.rs +530 -0
- package/crates/team-agent/src/lifecycle/launch/ownership.rs +40 -0
- package/crates/team-agent/src/lifecycle/launch/plan.rs +31 -0
- package/crates/team-agent/src/lifecycle/launch/quick_start.rs +66 -0
- package/crates/team-agent/src/lifecycle/launch/quick_start_transport.rs +78 -0
- package/crates/team-agent/src/lifecycle/launch/readiness.rs +85 -38
- package/crates/team-agent/src/lifecycle/launch/role_source.rs +44 -44
- package/crates/team-agent/src/lifecycle/launch/spawn.rs +101 -4
- package/crates/team-agent/src/lifecycle/launch/spec_state.rs +244 -48
- package/crates/team-agent/src/lifecycle/launch/state_projection.rs +109 -2
- package/crates/team-agent/src/lifecycle/launch/worker_env.rs +214 -1
- package/crates/team-agent/src/lifecycle/launch.rs +209 -43
- package/crates/team-agent/src/lifecycle/lock.rs +42 -1
- package/crates/team-agent/src/lifecycle/mod.rs +11 -0
- package/crates/team-agent/src/lifecycle/pane_input_lock.rs +161 -0
- package/crates/team-agent/src/lifecycle/profile_launch.rs +98 -0
- package/crates/team-agent/src/lifecycle/profile_smoke.rs +51 -1
- package/crates/team-agent/src/lifecycle/restart/agent.rs +213 -3
- package/crates/team-agent/src/lifecycle/restart/common.rs +373 -18
- package/crates/team-agent/src/lifecycle/restart/orchestrator.rs +27 -0
- package/crates/team-agent/src/lifecycle/restart/preflight.rs +25 -0
- package/crates/team-agent/src/lifecycle/restart/rebuild.rs +165 -15
- package/crates/team-agent/src/lifecycle/restart/remove.rs +196 -5
- package/crates/team-agent/src/lifecycle/restart/selection.rs +72 -0
- package/crates/team-agent/src/lifecycle/restart/team_state.rs +22 -0
- package/crates/team-agent/src/lifecycle/restart.rs +29 -0
- package/crates/team-agent/src/lifecycle/tests/acceptance_b_batch_red.rs +1 -1
- package/crates/team-agent/src/lifecycle/tests/agent_ops.rs +3 -4
- package/crates/team-agent/src/lifecycle/tests/behavioral_diff_264_red.rs +1 -1
- package/crates/team-agent/src/lifecycle/tests/claude_compatible_config_red.rs +2 -2
- package/crates/team-agent/src/lifecycle/tests/claude_profile_launch_red.rs +4 -4
- package/crates/team-agent/src/lifecycle/tests/clone_agent_preserves_source_tools.rs +309 -0
- package/crates/team-agent/src/lifecycle/tests/clone_fork_copilot_perms_red.rs +159 -174
- package/crates/team-agent/src/lifecycle/tests/communication_mode_runtime_contract_red.rs +2 -2
- package/crates/team-agent/src/lifecycle/tests/copilot_provider_red.rs +15 -13
- package/crates/team-agent/src/lifecycle/tests/core.rs +4 -18
- package/crates/team-agent/src/lifecycle/tests/core_034_real_red.rs +1 -1
- package/crates/team-agent/src/lifecycle/tests/cursor_mcp_overlay.rs +287 -0
- package/crates/team-agent/src/lifecycle/tests/cursor_require_explicit_model_red.rs +229 -0
- package/crates/team-agent/src/lifecycle/tests/cursor_restart_resume_red.rs +353 -0
- package/crates/team-agent/src/lifecycle/tests/display_adaptive_red.rs +1 -1
- package/crates/team-agent/src/lifecycle/tests/f032_startup_prompt_best_effort_red.rs +1 -1
- package/crates/team-agent/src/lifecycle/tests/g1_silent_faces.rs +784 -0
- package/crates/team-agent/src/lifecycle/tests/gate_fixtures.rs +562 -0
- package/crates/team-agent/src/lifecycle/tests/grok_effort_argv_red.rs +239 -0
- package/crates/team-agent/src/lifecycle/tests/grok_mcp_overlay_red.rs +498 -0
- package/crates/team-agent/src/lifecycle/tests/grok_require_explicit_model_red.rs +250 -0
- package/crates/team-agent/src/lifecycle/tests/grok_restart_resume_red.rs +293 -0
- package/crates/team-agent/src/lifecycle/tests/harvest2_a_batch_red.rs +3 -0
- package/crates/team-agent/src/lifecycle/tests/host_cotenant_death_p0_contract.rs +3 -3
- package/crates/team-agent/src/lifecycle/tests/lane_ops.rs +65 -40
- package/crates/team-agent/src/lifecycle/tests/launch_spawn.rs +20 -32
- package/crates/team-agent/src/lifecycle/tests/lifecycle_rollback_red.rs +17 -9
- package/crates/team-agent/src/lifecycle/tests/mcp_tool_name_format_red.rs +69 -0
- package/crates/team-agent/src/lifecycle/tests/phase_b_contracts.rs +24 -23
- package/crates/team-agent/src/lifecycle/tests/phase_golden.rs +98 -62
- package/crates/team-agent/src/lifecycle/tests/quick_start_worker_readiness_red.rs +2 -2
- package/crates/team-agent/src/lifecycle/tests/restart_build_before_destroy_0540_contract.rs +1 -1
- package/crates/team-agent/src/lifecycle/tests/restart_liveness_red.rs +1 -1
- package/crates/team-agent/src/lifecycle/tests/restart_rebind_hotfix_252_red.rs +3 -1
- package/crates/team-agent/src/lifecycle/tests/restart_session_capture_red.rs +2 -2
- package/crates/team-agent/src/lifecycle/tests/resume_recover_red.rs +1 -1
- package/crates/team-agent/src/lifecycle/tests/stale_team_saveconflict_contract.rs +1 -1
- package/crates/team-agent/src/lifecycle/tests/startup_latency_contract.rs +41 -8
- package/crates/team-agent/src/lifecycle/tests/status_credential_redaction_contract.rs +3 -3
- package/crates/team-agent/src/lifecycle/tests/subprep_codex_trust_roundtrip_red.rs +1 -1
- package/crates/team-agent/src/lifecycle/tests/swallow_batch4_semantics_red.rs +1 -1
- package/crates/team-agent/src/lifecycle/tests/team_in_team_identity_scope_red.rs +1 -1
- 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 +1 -1
- package/crates/team-agent/src/lifecycle/tests/team_key_retirement_txn_red.rs +1 -1
- package/crates/team-agent/src/lifecycle/tests/test_isolation_escape_contract.rs +60 -2
- package/crates/team-agent/src/lifecycle/tests/upgrade_compat_0211_red.rs +1 -1
- package/crates/team-agent/src/lifecycle/tests/verify_rs031_window_consistency_red.rs +2 -2
- package/crates/team-agent/src/lifecycle/tests/worker_spawn_env_red.rs +69 -26
- package/crates/team-agent/src/lifecycle/tests.rs +23 -15
- package/crates/team-agent/src/lifecycle/types.rs +61 -2
- package/crates/team-agent/src/lifecycle/worker_command_context.rs +200 -33
- package/crates/team-agent/src/mcp_server/tests/scoped.rs +100 -1
- package/crates/team-agent/src/mcp_server/tests.rs +196 -2
- package/crates/team-agent/src/messaging/delivery.rs +405 -40
- package/crates/team-agent/src/messaging/helpers.rs +2 -0
- package/crates/team-agent/src/messaging/leader_receiver.rs +53 -1
- package/crates/team-agent/src/messaging/results.rs +4 -0
- package/crates/team-agent/src/messaging/send.rs +34 -0
- package/crates/team-agent/src/messaging/tests/dup_inject.rs +406 -0
- package/crates/team-agent/src/messaging/tests/e23.rs +9 -0
- package/crates/team-agent/src/messaging/tests/leader_inject_acceptance.rs +66 -0
- package/crates/team-agent/src/messaging/tests/main_preserved.rs +1 -1
- package/crates/team-agent/src/messaging/tests/mod.rs +1 -0
- package/crates/team-agent/src/messaging/types.rs +4 -1
- package/crates/team-agent/src/model/enums.rs +14 -5
- package/crates/team-agent/src/model/permissions.rs +3 -0
- package/crates/team-agent/src/model/spec.rs +129 -6
- package/crates/team-agent/src/model/testdata/spec_invalid_a.yaml +3 -1
- package/crates/team-agent/src/model/testdata/team.spec.golden.yaml +3 -1
- package/crates/team-agent/src/model/testdata/team.spec.yaml +3 -1
- package/crates/team-agent/src/os_probe.rs +73 -2
- package/crates/team-agent/src/provider/adapter.rs +231 -4
- package/crates/team-agent/src/provider/adapters/claude.rs +5 -2
- package/crates/team-agent/src/provider/adapters/codex.rs +5 -2
- package/crates/team-agent/src/provider/adapters/copilot.rs +5 -2
- package/crates/team-agent/src/provider/adapters/cursor_agent.rs +86 -0
- package/crates/team-agent/src/provider/adapters/grok.rs +157 -0
- package/crates/team-agent/src/provider/adapters/mod.rs +2 -0
- package/crates/team-agent/src/provider/bypass_flags.rs +124 -0
- package/crates/team-agent/src/provider/classify.rs +4 -2
- package/crates/team-agent/src/provider/faults.rs +2 -1
- package/crates/team-agent/src/provider/mod.rs +13 -0
- package/crates/team-agent/src/provider/session/capture.rs +158 -20
- package/crates/team-agent/src/provider/session/context_fork/claude.rs +38 -1
- package/crates/team-agent/src/provider/session/context_fork/codex.rs +72 -1
- package/crates/team-agent/src/provider/session/context_fork/outcome.rs +57 -1
- package/crates/team-agent/src/provider/session/context_fork.rs +77 -3
- package/crates/team-agent/src/provider/session/mod.rs +18 -0
- package/crates/team-agent/src/provider/session/resume.rs +57 -0
- package/crates/team-agent/src/provider/session_scan/claude.rs +125 -1
- package/crates/team-agent/src/provider/session_scan/codex.rs +94 -1
- package/crates/team-agent/src/provider/session_scan/common.rs +204 -2
- package/crates/team-agent/src/provider/session_scan/copilot.rs +33 -1
- package/crates/team-agent/src/provider/session_scan/cursor.rs +538 -0
- package/crates/team-agent/src/provider/session_scan/grok.rs +288 -0
- package/crates/team-agent/src/provider/session_scan.rs +8 -0
- package/crates/team-agent/src/provider/submit_now.rs +94 -0
- package/crates/team-agent/src/provider/tests/adapter.rs +304 -0
- package/crates/team-agent/src/provider/types.rs +4 -2
- package/crates/team-agent/src/provider/wire.rs +23 -1
- package/crates/team-agent/src/state/persist.rs +301 -8
- package/crates/team-agent/src/state/repository.rs +5 -0
- package/crates/team-agent/src/tmux_backend/tests.rs +1737 -42
- package/crates/team-agent/src/tmux_backend.rs +1083 -75
- package/crates/team-agent/src/transport/test_support.rs +20 -0
- package/crates/team-agent/src/transport/tests/wire.rs +28 -2
- package/crates/team-agent/src/transport.rs +265 -1
- package/npm/install.mjs +129 -73
- package/package.json +4 -4
- package/skills/team-agent/SKILL.md +33 -238
- package/skills/team-agent/command-coverage.json +31 -0
- package/crates/team-agent/src/lifecycle/launch/approval.rs +0 -134
- package/crates/team-agent/src/lifecycle/launch/fork_agent/completion.rs +0 -59
- package/crates/team-agent/src/lifecycle/launch/fork_finalize.rs +0 -483
- package/crates/team-agent/src/lifecycle/launch/fork_pending.rs +0 -109
- package/crates/team-agent/src/lifecycle/launch/fork_state.rs +0 -447
- package/crates/team-agent/src/lifecycle/tests/codex_mcp_approval_inheritance_red.rs +0 -1187
- package/crates/team-agent/src/lifecycle/tests/worker_dangerous_bypass_argv_red.rs +0 -327
|
@@ -1,18 +1,105 @@
|
|
|
1
|
+
//! ---
|
|
2
|
+
//! purpose: 在当前席位窗口注入官方斜杠命令完成就地分身,不读 provider session 落盘
|
|
3
|
+
//! contract:
|
|
4
|
+
//! provides:
|
|
5
|
+
//! - name: fork_agent_with_transport
|
|
6
|
+
//! what: grok/claude subscription 注入纯净斜杠命令;屏幕出现该 provider 的实测标记才算成功
|
|
7
|
+
//! - name: in_window_fork
|
|
8
|
+
//! what: 已验证的 provider+subscription 给出 command+screen_mark;未验证返回 None
|
|
9
|
+
//! depends:
|
|
10
|
+
//! - crate::lifecycle::lock
|
|
11
|
+
//! - crate::lifecycle::pane_input_lock
|
|
12
|
+
//! - crate::lifecycle::profile_launch
|
|
13
|
+
//! - crate::transport::Transport
|
|
14
|
+
//! boundary:
|
|
15
|
+
//! - 不 spawn 新 pane,不改 TEAM_AGENT_ID / MCP / 席位名
|
|
16
|
+
//! - 不读 provider 会话落盘文件取会话身份
|
|
17
|
+
//! - 重试只重按回车,不重粘 /fork
|
|
18
|
+
//! - 不把 pane 锁超时从 200ms 调大
|
|
19
|
+
//! - 未验证的 provider 不猜斜杠命令
|
|
20
|
+
//! maturity: wired
|
|
21
|
+
//! ---
|
|
22
|
+
|
|
1
23
|
use super::*;
|
|
2
|
-
use crate::lifecycle::
|
|
24
|
+
use crate::lifecycle::pane_input_lock::{
|
|
25
|
+
acquire_or_proceed, PaneInputLockRequest, PANE_INPUT_LOCK_TIMEOUT_EVENT,
|
|
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 `/branch` mark `Branched conversation` (Claude Code v2.1.181, 2026-08-17).
|
|
47
|
+
/// claude `/fork` is a background-agent command (`Usage: /fork <directive>`), not the session split.
|
|
48
|
+
pub fn in_window_fork(provider: Provider, auth: AuthMode) -> Option<InWindowFork> {
|
|
49
|
+
match (provider, auth) {
|
|
50
|
+
(Provider::Grok, AuthMode::Subscription) => Some(InWindowFork {
|
|
51
|
+
command: "/fork",
|
|
52
|
+
screen_mark: "forked from",
|
|
53
|
+
}),
|
|
54
|
+
(Provider::Claude | Provider::ClaudeCode, AuthMode::Subscription) => Some(InWindowFork {
|
|
55
|
+
command: "/branch",
|
|
56
|
+
screen_mark: "Branched conversation",
|
|
57
|
+
}),
|
|
58
|
+
_ => None,
|
|
59
|
+
}
|
|
60
|
+
}
|
|
3
61
|
|
|
4
|
-
|
|
62
|
+
/// ---
|
|
63
|
+
/// purpose: 只取窗口内 fork 的斜杠命令
|
|
64
|
+
/// returns: 有已验证组合时返回命令,否则 None
|
|
65
|
+
/// ---
|
|
66
|
+
pub fn in_window_fork_command(provider: Provider, auth: AuthMode) -> Option<&'static str> {
|
|
67
|
+
in_window_fork(provider, auth).map(|spec| spec.command)
|
|
68
|
+
}
|
|
5
69
|
|
|
70
|
+
fn refuse_missing_in_window_fork(provider: Provider, provider_raw: &str) -> LifecycleError {
|
|
71
|
+
if matches!(
|
|
72
|
+
provider,
|
|
73
|
+
Provider::Grok | Provider::Claude | Provider::ClaudeCode | Provider::CursorAgent
|
|
74
|
+
) {
|
|
75
|
+
LifecycleError::Provider(format!(
|
|
76
|
+
"{provider_raw} does not support native session fork"
|
|
77
|
+
))
|
|
78
|
+
} else {
|
|
79
|
+
LifecycleError::Provider(format!(
|
|
80
|
+
"{provider_raw} in-window fork is unverified (未验证)"
|
|
81
|
+
))
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/// ---
|
|
86
|
+
/// purpose: 在源席窗口内注入官方斜杠命令完成就地分身
|
|
87
|
+
/// params:
|
|
88
|
+
/// source_agent_id: 被 fork 的席位
|
|
89
|
+
/// as_agent_id: 新席位名
|
|
90
|
+
/// transport: 目标 team 实际使用的 transport
|
|
91
|
+
/// returns: fork 报告,屏幕出现该 provider 的实测标记才记为已验证
|
|
92
|
+
/// errors: 选不到 team 返回 TeamSelect,provider 或鉴权方式未验证返回 Provider,注入失败返回 LifecycleError
|
|
93
|
+
/// ---
|
|
6
94
|
pub fn fork_agent_with_transport(
|
|
7
95
|
workspace: &Path,
|
|
8
96
|
source_agent_id: &AgentId,
|
|
9
97
|
as_agent_id: &AgentId,
|
|
10
|
-
|
|
11
|
-
|
|
98
|
+
_label: Option<&str>,
|
|
99
|
+
_open_display: bool,
|
|
12
100
|
team: Option<&str>,
|
|
13
101
|
transport: &dyn Transport,
|
|
14
102
|
) -> Result<ForkAgentReport, LifecycleError> {
|
|
15
|
-
let _ = open_display;
|
|
16
103
|
let selected = crate::state::selector::resolve_active_team(
|
|
17
104
|
workspace,
|
|
18
105
|
team,
|
|
@@ -21,11 +108,11 @@ pub fn fork_agent_with_transport(
|
|
|
21
108
|
.map_err(|e| LifecycleError::TeamSelect(e.to_string()))?;
|
|
22
109
|
let lock_workspace = selected.run_workspace.clone();
|
|
23
110
|
let lock_team_key = selected.team_key.clone();
|
|
24
|
-
let
|
|
111
|
+
let _lifecycle_lock = acquire_agent_lifecycle_lock(LifecycleLockRequest {
|
|
25
112
|
workspace: &lock_workspace,
|
|
26
113
|
operation: "fork-agent",
|
|
27
114
|
team: Some(lock_team_key.as_str()),
|
|
28
|
-
agent_id: Some(
|
|
115
|
+
agent_id: Some(source_agent_id),
|
|
29
116
|
})?;
|
|
30
117
|
let selected = crate::state::selector::resolve_active_team(
|
|
31
118
|
&lock_workspace,
|
|
@@ -33,468 +120,128 @@ pub fn fork_agent_with_transport(
|
|
|
33
120
|
crate::state::selector::SelectorMode::RequireSpec,
|
|
34
121
|
)
|
|
35
122
|
.map_err(|e| LifecycleError::TeamSelect(e.to_string()))?;
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
.
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
let
|
|
45
|
-
let state = selected.state;
|
|
46
|
-
ensure_owner_allowed_for_state(&state, Some(source_agent_id))?;
|
|
47
|
-
let spec_path = crate::model::paths::runtime_spec_path(&workspace, &fork_team);
|
|
48
|
-
let text = std::fs::read_to_string(&read_spec_path)
|
|
49
|
-
.map_err(|e| LifecycleError::Compile(format!("{}: {e}", read_spec_path.display())))?;
|
|
50
|
-
let spec = yaml::loads(&text).map_err(|e| LifecycleError::Compile(e.to_string()))?;
|
|
51
|
-
if fork_spec_agent(&spec, as_agent_id).is_some() || leader_id_matches(&spec, as_agent_id) {
|
|
52
|
-
return Err(LifecycleError::RequirementUnmet(format!(
|
|
53
|
-
"agent id already exists: {as_agent_id}"
|
|
54
|
-
)));
|
|
55
|
-
}
|
|
56
|
-
// Source existence authority: state.get("agents"), matching clone-agent.
|
|
57
|
-
let (session_id, source_backing) = fork_source_tuple(&state, source_agent_id)?;
|
|
58
|
-
let session_name = state
|
|
59
|
-
.get("session_name")
|
|
60
|
-
.and_then(|v| v.as_str())
|
|
61
|
-
.filter(|s| !s.is_empty())
|
|
62
|
-
.map(SessionName::new)
|
|
63
|
-
.unwrap_or_else(|| spec_session_name(&spec));
|
|
64
|
-
if transport
|
|
65
|
-
.list_windows(&session_name)
|
|
66
|
-
.map(|windows| windows.iter().any(|w| w.as_str() == as_agent_id.as_str()))
|
|
67
|
-
.unwrap_or(false)
|
|
68
|
-
{
|
|
69
|
-
return Err(LifecycleError::Transport(format!(
|
|
70
|
-
"tmux window already exists for fork target: {}:{}",
|
|
71
|
-
session_name.as_str(),
|
|
72
|
-
as_agent_id.as_str()
|
|
73
|
-
)));
|
|
74
|
-
}
|
|
75
|
-
let mut materialized_role = materialize_latest_role(
|
|
76
|
-
&workspace,
|
|
77
|
-
&fork_team_dir,
|
|
78
|
-
&state,
|
|
79
|
-
source_agent_id,
|
|
80
|
-
as_agent_id,
|
|
81
|
-
label,
|
|
82
|
-
)?;
|
|
83
|
-
clamp_materialized_role_to_leader(materialized_role.path(), &spec)?;
|
|
84
|
-
let team_meta = crate::compiler::read_front_matter(&fork_team_dir.join("TEAM.md"))
|
|
85
|
-
.map(|(meta, _)| meta)
|
|
86
|
-
.map_err(|error| LifecycleError::Compile(error.to_string()))?;
|
|
87
|
-
let workspace_s = workspace.to_string_lossy().to_string();
|
|
88
|
-
let compiled =
|
|
89
|
-
crate::compiler::compile_role_agent(materialized_role.path(), &team_meta, &workspace_s)
|
|
90
|
-
.map_err(|error| LifecycleError::Compile(error.to_string()))?;
|
|
91
|
-
let new_spec =
|
|
92
|
-
append_forked_agent(&spec, &compiled.agent, source_agent_id, as_agent_id, label)?;
|
|
93
|
-
// validate 用角色定义目录的 team_workspace(校验 working_directory),非 spec 落点。
|
|
94
|
-
let validate_ws =
|
|
95
|
-
crate::model::paths::team_workspace(&fork_team_dir).unwrap_or_else(|_| workspace.clone());
|
|
96
|
-
crate::model::spec::validate_spec(&new_spec, &validate_ws)
|
|
97
|
-
.map_err(|e| LifecycleError::Compile(e.to_string()))?;
|
|
98
|
-
write_spec_atomic(&spec_path, &new_spec)?;
|
|
99
|
-
let new_agent = fork_spec_agent(&new_spec, as_agent_id).ok_or_else(|| {
|
|
100
|
-
LifecycleError::RequirementUnmet(format!("unknown worker agent id: {as_agent_id}"))
|
|
101
|
-
})?;
|
|
102
|
-
let provider = new_agent
|
|
123
|
+
let run_ws = selected.run_workspace.clone();
|
|
124
|
+
let agent = selected
|
|
125
|
+
.state
|
|
126
|
+
.get("agents")
|
|
127
|
+
.and_then(|agents| agents.get(source_agent_id.as_str()))
|
|
128
|
+
.ok_or_else(|| {
|
|
129
|
+
LifecycleError::RequirementUnmet(format!("unknown worker agent id: {source_agent_id}"))
|
|
130
|
+
})?;
|
|
131
|
+
let provider_raw = agent
|
|
103
132
|
.get("provider")
|
|
104
|
-
.and_then(Value::as_str)
|
|
105
|
-
.
|
|
106
|
-
|
|
107
|
-
let auth_mode = new_agent
|
|
133
|
+
.and_then(serde_json::Value::as_str)
|
|
134
|
+
.unwrap_or("unknown");
|
|
135
|
+
let auth_raw = agent
|
|
108
136
|
.get("auth_mode")
|
|
109
|
-
.and_then(Value::as_str)
|
|
110
|
-
.
|
|
111
|
-
|
|
112
|
-
let
|
|
113
|
-
let
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
return Err(LifecycleError::Provider(format!(
|
|
120
|
-
"{provider_str} does not support native session fork"
|
|
137
|
+
.and_then(serde_json::Value::as_str)
|
|
138
|
+
.unwrap_or("subscription");
|
|
139
|
+
let provider = parse_provider(provider_raw).unwrap_or(Provider::Grok);
|
|
140
|
+
let auth = parse_auth_mode(auth_raw).unwrap_or(AuthMode::Subscription);
|
|
141
|
+
let Some(spec) = in_window_fork(provider, auth) else {
|
|
142
|
+
return Err(refuse_missing_in_window_fork(provider, provider_raw));
|
|
143
|
+
};
|
|
144
|
+
if as_agent_id.as_str() != source_agent_id.as_str() {
|
|
145
|
+
return Err(LifecycleError::RequirementUnmet(format!(
|
|
146
|
+
"in-place fork refuses --as {as_agent_id}: session stays on {source_agent_id}"
|
|
121
147
|
)));
|
|
122
148
|
}
|
|
123
|
-
let
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
crate::lifecycle::worker_command_context::compile_worker_system_prompt(&command_agent)?;
|
|
132
|
-
let tools = crate::lifecycle::worker_command_context::resolved_tool_strings_for_command(
|
|
133
|
-
&command_agent,
|
|
134
|
-
provider,
|
|
135
|
-
&safety,
|
|
136
|
-
)?;
|
|
137
|
-
let resolved_tool_refs: Vec<&str> = tools.iter().map(String::as_str).collect();
|
|
138
|
-
let mcp_config = adapter.mcp_config(auth_mode).map_err(|e| {
|
|
139
|
-
let _ = std::fs::write(&spec_path, text.as_bytes());
|
|
140
|
-
LifecycleError::Provider(e.to_string())
|
|
141
|
-
})?;
|
|
142
|
-
let mcp_config = resolve_mcp_config(mcp_config, &workspace, as_agent_id.as_str(), &fork_team);
|
|
143
|
-
let mcp_config_path = write_worker_mcp_config_for_provider(
|
|
144
|
-
&workspace,
|
|
145
|
-
as_agent_id.as_str(),
|
|
146
|
-
&mcp_config,
|
|
147
|
-
Some(provider),
|
|
148
|
-
)
|
|
149
|
-
.map_err(|e| {
|
|
150
|
-
let _ = std::fs::write(&spec_path, text.as_bytes());
|
|
151
|
-
e
|
|
152
|
-
})?;
|
|
153
|
-
// E5 §3:profiles 随角色定义目录(team_dir),不随已迁出的 spec。
|
|
154
|
-
let profile_dir = fork_team_dir.join("profiles");
|
|
155
|
-
let mut profile_launch =
|
|
156
|
-
match crate::lifecycle::profile_launch::prepare_provider_profile_launch_with_profile_dir(
|
|
157
|
-
&workspace,
|
|
158
|
-
as_agent_id.as_str(),
|
|
159
|
-
new_agent,
|
|
160
|
-
Some(&profile_dir),
|
|
161
|
-
Some(&mcp_config),
|
|
162
|
-
) {
|
|
163
|
-
Ok(profile_launch) => profile_launch,
|
|
164
|
-
Err(error) => {
|
|
165
|
-
let _ = std::fs::write(&spec_path, text.as_bytes());
|
|
166
|
-
let _ = std::fs::remove_file(&mcp_config_path);
|
|
167
|
-
return Err(error);
|
|
168
|
-
}
|
|
169
|
-
};
|
|
170
|
-
let mut copilot_fork = None;
|
|
171
|
-
if provider == Provider::Copilot {
|
|
172
|
-
let materialized = crate::provider::adapters::copilot_fork::materialize_copilot_fork(
|
|
173
|
-
&workspace,
|
|
174
|
-
as_agent_id.as_str(),
|
|
175
|
-
&session_id,
|
|
176
|
-
)
|
|
177
|
-
.map_err(|error| {
|
|
178
|
-
let _ = std::fs::write(&spec_path, text.as_bytes());
|
|
179
|
-
cleanup_fork_mcp_artifacts(&workspace, as_agent_id, &mcp_config_path, &profile_launch);
|
|
180
|
-
LifecycleError::Provider(error.to_string())
|
|
149
|
+
let pane_raw = agent
|
|
150
|
+
.get("pane_id")
|
|
151
|
+
.and_then(serde_json::Value::as_str)
|
|
152
|
+
.filter(|s| !s.is_empty())
|
|
153
|
+
.ok_or_else(|| {
|
|
154
|
+
LifecycleError::RequirementUnmet(format!(
|
|
155
|
+
"source agent {source_agent_id} has no pane_id"
|
|
156
|
+
))
|
|
181
157
|
})?;
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
158
|
+
let target = Target::Pane(PaneId::new(pane_raw));
|
|
159
|
+
let lock = acquire_or_proceed(PaneInputLockRequest {
|
|
160
|
+
workspace: Some(&run_ws),
|
|
161
|
+
target_key: pane_raw,
|
|
162
|
+
operation: "fork-inject",
|
|
163
|
+
});
|
|
164
|
+
if lock.is_none() {
|
|
165
|
+
let _ = crate::event_log::EventLog::new(&run_ws).write(
|
|
166
|
+
PANE_INPUT_LOCK_TIMEOUT_EVENT,
|
|
167
|
+
serde_json::json!({
|
|
168
|
+
"during": "fork-inject",
|
|
169
|
+
"agent_id": source_agent_id.as_str(),
|
|
170
|
+
"pane_id": pane_raw,
|
|
171
|
+
"observed_at": chrono::Utc::now().to_rfc3339(),
|
|
172
|
+
}),
|
|
185
173
|
);
|
|
186
|
-
profile_launch.env_overlay.insert(
|
|
187
|
-
"TEAM_AGENT_INTERNAL_COPILOT_FORK_SESSION_ID".to_string(),
|
|
188
|
-
materialized.session_id().as_str().to_string(),
|
|
189
|
-
);
|
|
190
|
-
copilot_fork = Some(materialized);
|
|
191
|
-
}
|
|
192
|
-
let command_model = profile_launch.command_overrides.model.as_deref().or(model);
|
|
193
|
-
// 0.4.x provider effort MVP: fork inherits effort from the new agent JSON
|
|
194
|
-
// (compiler.rs propagated the role/team effort into the agent at fork-spawn).
|
|
195
|
-
let fork_effort = provider_effort_for_spawn(new_agent, provider);
|
|
196
|
-
if let Some(event_value) =
|
|
197
|
-
provider_effort_event_if_dropped(new_agent, provider, as_agent_id.as_str())
|
|
198
|
-
{
|
|
199
|
-
let _ = crate::event_log::EventLog::new(&workspace)
|
|
200
|
-
.write("provider.effort_unsupported", event_value);
|
|
201
|
-
}
|
|
202
|
-
let mut plan = adapter
|
|
203
|
-
.fork_plan(
|
|
204
|
-
Some(&session_id),
|
|
205
|
-
crate::provider::ProviderCommandContext {
|
|
206
|
-
auth_mode,
|
|
207
|
-
mcp_config: Some(&mcp_config),
|
|
208
|
-
system_prompt: Some(system_prompt.as_str()),
|
|
209
|
-
model: command_model,
|
|
210
|
-
tools: &resolved_tool_refs,
|
|
211
|
-
profile_launch: Some(&profile_launch),
|
|
212
|
-
agent_id_hint: Some(as_agent_id.as_str()),
|
|
213
|
-
effort: fork_effort,
|
|
214
|
-
},
|
|
215
|
-
)
|
|
216
|
-
.map_err(|e| {
|
|
217
|
-
let _ = std::fs::write(&spec_path, text.as_bytes());
|
|
218
|
-
cleanup_fork_mcp_artifacts(&workspace, as_agent_id, &mcp_config_path, &profile_launch);
|
|
219
|
-
LifecycleError::Provider(e.to_string())
|
|
220
|
-
})?;
|
|
221
|
-
profile_launch
|
|
222
|
-
.env_overlay
|
|
223
|
-
.remove("TEAM_AGENT_INTERNAL_COPILOT_FORK_SESSION_ID");
|
|
224
|
-
if !plan.managed_mcp_config && !profile_launch.managed_mcp_config {
|
|
225
|
-
point_native_mcp_config_at_file(&mut plan.argv, provider, &mcp_config_path);
|
|
226
|
-
}
|
|
227
|
-
fill_spawn_placeholders_full(
|
|
228
|
-
&mut plan.argv,
|
|
229
|
-
&workspace,
|
|
230
|
-
as_agent_id.as_str(),
|
|
231
|
-
Some(&fork_team),
|
|
232
|
-
);
|
|
233
|
-
let spawned_at = spawn_timestamp_for_agent(1);
|
|
234
|
-
let mut fork_backing = adapter
|
|
235
|
-
.materialize_fork_backing(
|
|
236
|
-
&source_backing,
|
|
237
|
-
&session_id,
|
|
238
|
-
source_agent_id.as_str(),
|
|
239
|
-
as_agent_id.as_str(),
|
|
240
|
-
&mut plan,
|
|
241
|
-
)
|
|
242
|
-
.map_err(|error| {
|
|
243
|
-
let _ = std::fs::write(&spec_path, text.as_bytes());
|
|
244
|
-
cleanup_fork_mcp_artifacts(&workspace, as_agent_id, &mcp_config_path, &profile_launch);
|
|
245
|
-
LifecycleError::Provider(error.to_string())
|
|
246
|
-
})?;
|
|
247
|
-
let mut expected_backing_path = fork_backing
|
|
248
|
-
.as_ref()
|
|
249
|
-
.map(|materialized| materialized.path().to_path_buf());
|
|
250
|
-
if matches!(provider, Provider::Claude | Provider::ClaudeCode) {
|
|
251
|
-
plan.provider_projects_root = source_backing.parent().map(Path::to_path_buf);
|
|
252
|
-
}
|
|
253
|
-
let window = WindowName::new(as_agent_id.as_str());
|
|
254
|
-
let mut claude_fork = prepare_claude_fork_backing(
|
|
255
|
-
provider,
|
|
256
|
-
&plan,
|
|
257
|
-
&source_backing,
|
|
258
|
-
&session_id,
|
|
259
|
-
source_agent_id,
|
|
260
|
-
as_agent_id,
|
|
261
|
-
)
|
|
262
|
-
.map_err(|error| {
|
|
263
|
-
let _ = std::fs::write(&spec_path, text.as_bytes());
|
|
264
|
-
cleanup_fork_mcp_artifacts(&workspace, as_agent_id, &mcp_config_path, &profile_launch);
|
|
265
|
-
error
|
|
266
|
-
})?;
|
|
267
|
-
if expected_backing_path.is_none() {
|
|
268
|
-
expected_backing_path = claude_fork
|
|
269
|
-
.as_ref()
|
|
270
|
-
.map(|materialized| materialized.path().to_path_buf());
|
|
271
174
|
}
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
&mut env,
|
|
175
|
+
inject_clean_command(transport, &target, spec.command)?;
|
|
176
|
+
wait_for_screen_mark(transport, &target, spec.screen_mark)?;
|
|
177
|
+
drop(lock);
|
|
178
|
+
crate::event_log::EventLog::new(&run_ws)
|
|
179
|
+
.write(
|
|
180
|
+
"lifecycle.fork.in_place",
|
|
181
|
+
serde_json::json!({
|
|
182
|
+
"source_agent_id": source_agent_id.as_str(),
|
|
183
|
+
"agent_id": source_agent_id.as_str(),
|
|
184
|
+
"pane_id": pane_raw,
|
|
185
|
+
"command": spec.command,
|
|
186
|
+
"screen_mark": spec.screen_mark,
|
|
187
|
+
}),
|
|
286
188
|
)
|
|
287
|
-
.map_err(|
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
&mut reserved_state,
|
|
296
|
-
source_agent_id,
|
|
297
|
-
as_agent_id,
|
|
298
|
-
new_agent,
|
|
299
|
-
materialized_role.path(),
|
|
300
|
-
)?;
|
|
301
|
-
if let Err(error) = crate::state::repository::StateRepository::new(&workspace).save(
|
|
302
|
-
crate::state::repository::StateWriteIntent::ForkAgent {
|
|
303
|
-
team_key: &fork_team,
|
|
304
|
-
agent_id: as_agent_id.as_str(),
|
|
189
|
+
.map_err(|e| LifecycleError::StatePersist(format!("fork audit write failed: {e}")))?;
|
|
190
|
+
Ok(ForkAgentReport {
|
|
191
|
+
source_agent_id: source_agent_id.clone(),
|
|
192
|
+
new_agent_id: source_agent_id.clone(),
|
|
193
|
+
env: AgentActionEnvelope {
|
|
194
|
+
agent_id: source_agent_id.clone(),
|
|
195
|
+
state_file: crate::state::persist::runtime_state_path(&run_ws),
|
|
196
|
+
coordinator_started: false,
|
|
305
197
|
},
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
// Release the metadata lock before per-seat provider convergence; finalize reacquires it.
|
|
323
|
-
drop(_lock);
|
|
324
|
-
let spawn_epoch = 1_u64;
|
|
325
|
-
let spawn_result = if session_live {
|
|
326
|
-
transport.spawn_into_with_env_unset(
|
|
327
|
-
&session_name,
|
|
328
|
-
&window,
|
|
329
|
-
&plan.argv,
|
|
330
|
-
&workspace,
|
|
331
|
-
&env,
|
|
332
|
-
&env_unset,
|
|
333
|
-
)
|
|
334
|
-
} else {
|
|
335
|
-
transport.spawn_first_with_env_unset(
|
|
336
|
-
&session_name,
|
|
337
|
-
&window,
|
|
338
|
-
&plan.argv,
|
|
339
|
-
&workspace,
|
|
340
|
-
&env,
|
|
341
|
-
&env_unset,
|
|
198
|
+
session_id: None,
|
|
199
|
+
backing_state: ForkBackingState::Verified,
|
|
200
|
+
})
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
fn inject_clean_command(
|
|
204
|
+
transport: &dyn Transport,
|
|
205
|
+
target: &Target,
|
|
206
|
+
command: &str,
|
|
207
|
+
) -> Result<(), LifecycleError> {
|
|
208
|
+
transport
|
|
209
|
+
.inject(
|
|
210
|
+
target,
|
|
211
|
+
&crate::transport::InjectPayload::TextSkipConsumptionPoll(command.to_string()),
|
|
212
|
+
crate::transport::Key::Enter,
|
|
213
|
+
false,
|
|
342
214
|
)
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
)
|
|
357
|
-
|
|
215
|
+
.map_err(|e| LifecycleError::Transport(e.to_string()))?;
|
|
216
|
+
Ok(())
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
const NO_CONVERSATION_TO_BRANCH: &str = "Failed to branch conversation: No conversation to branch";
|
|
220
|
+
|
|
221
|
+
fn wait_for_screen_mark(
|
|
222
|
+
transport: &dyn Transport,
|
|
223
|
+
target: &Target,
|
|
224
|
+
screen_mark: &str,
|
|
225
|
+
) -> Result<(), LifecycleError> {
|
|
226
|
+
for attempt in 0..MAX_ENTER_RETRIES {
|
|
227
|
+
let cap = transport
|
|
228
|
+
.capture(target, crate::transport::CaptureRange::Tail(40))
|
|
229
|
+
.map_err(|e| LifecycleError::Transport(e.to_string()))?;
|
|
230
|
+
if cap.text.contains(screen_mark) {
|
|
231
|
+
return Ok(());
|
|
358
232
|
}
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
ensure_fork_spawn_live(ForkPostSpawnInput {
|
|
364
|
-
workspace: &workspace,
|
|
365
|
-
transport,
|
|
366
|
-
session_name: &session_name,
|
|
367
|
-
window: &window,
|
|
368
|
-
mcp_config_path: &mcp_config_path,
|
|
369
|
-
agent_id: as_agent_id,
|
|
370
|
-
profile_launch: &profile_launch,
|
|
371
|
-
team_key: &fork_team,
|
|
372
|
-
spawn: &spawn,
|
|
373
|
-
})?;
|
|
374
|
-
let convergence_deadline =
|
|
375
|
-
crate::provider::session::context_fork_convergence_deadline(provider);
|
|
376
|
-
let context_outcome = crate::provider::session::observe_context_fork(
|
|
377
|
-
provider,
|
|
378
|
-
&session_id,
|
|
379
|
-
&plan,
|
|
380
|
-
&backing_before,
|
|
381
|
-
expected_backing_path.as_deref(),
|
|
382
|
-
source_agent_id.as_str(),
|
|
383
|
-
as_agent_id.as_str(),
|
|
384
|
-
&workspace,
|
|
385
|
-
&spawned_at,
|
|
386
|
-
convergence_deadline,
|
|
387
|
-
);
|
|
388
|
-
let context_proof = match context_outcome {
|
|
389
|
-
crate::provider::session::ContextForkOutcome::Verified(proof) => Some(proof),
|
|
390
|
-
crate::provider::session::ContextForkOutcome::Pending(pending) => {
|
|
391
|
-
if let Err(error) = finalize_pending_fork_state(ForkPendingFinalizeInput {
|
|
392
|
-
workspace: &workspace,
|
|
393
|
-
team_key: &fork_team,
|
|
394
|
-
source_agent_id,
|
|
395
|
-
agent_id: as_agent_id,
|
|
396
|
-
spec_agent: new_agent,
|
|
397
|
-
safety: &safety,
|
|
398
|
-
plan: &plan,
|
|
399
|
-
profile_launch: &profile_launch,
|
|
400
|
-
spawn: &spawn,
|
|
401
|
-
profile_dir: &profile_dir,
|
|
402
|
-
dynamic_role_file: materialized_role.path(),
|
|
403
|
-
pending: &pending,
|
|
404
|
-
spawn_epoch,
|
|
405
|
-
}) {
|
|
406
|
-
rollback_fork_after_spawn(
|
|
407
|
-
&workspace,
|
|
408
|
-
transport,
|
|
409
|
-
&session_name,
|
|
410
|
-
&window,
|
|
411
|
-
&mcp_config_path,
|
|
412
|
-
as_agent_id,
|
|
413
|
-
&profile_launch,
|
|
414
|
-
&fork_team,
|
|
415
|
-
);
|
|
416
|
-
return Err(error);
|
|
417
|
-
}
|
|
418
|
-
None
|
|
233
|
+
if cap.text.contains(NO_CONVERSATION_TO_BRANCH) {
|
|
234
|
+
return Err(LifecycleError::RequirementUnmet(
|
|
235
|
+
NO_CONVERSATION_TO_BRANCH.to_string(),
|
|
236
|
+
));
|
|
419
237
|
}
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
&session_name,
|
|
425
|
-
&window,
|
|
426
|
-
&mcp_config_path,
|
|
427
|
-
as_agent_id,
|
|
428
|
-
&profile_launch,
|
|
429
|
-
&fork_team,
|
|
430
|
-
);
|
|
431
|
-
return Err(LifecycleError::Provider(error.to_string()));
|
|
238
|
+
if attempt + 1 < MAX_ENTER_RETRIES {
|
|
239
|
+
// Mixed text in the box is not failure. Retry Enter only — never re-paste the slash command.
|
|
240
|
+
let _ = transport.send_keys(target, &[crate::transport::Key::Enter]);
|
|
241
|
+
std::thread::sleep(std::time::Duration::from_millis(80));
|
|
432
242
|
}
|
|
433
|
-
};
|
|
434
|
-
if let Some(context_proof) = context_proof.as_ref() {
|
|
435
|
-
let finalized = match finalize_fork_state(ForkFinalizeInput {
|
|
436
|
-
workspace: &workspace,
|
|
437
|
-
team_key: &fork_team,
|
|
438
|
-
source_agent_id,
|
|
439
|
-
agent_id: as_agent_id,
|
|
440
|
-
spec_agent: new_agent,
|
|
441
|
-
safety: &safety,
|
|
442
|
-
plan: &plan,
|
|
443
|
-
profile_launch: &profile_launch,
|
|
444
|
-
spawn: &spawn,
|
|
445
|
-
profile_dir: &profile_dir,
|
|
446
|
-
dynamic_role_file: materialized_role.path(),
|
|
447
|
-
context_proof: &context_proof,
|
|
448
|
-
spawned_at: &spawned_at,
|
|
449
|
-
spawn_epoch,
|
|
450
|
-
}) {
|
|
451
|
-
Ok(finalized) => finalized,
|
|
452
|
-
Err(error) => {
|
|
453
|
-
rollback_fork_after_spawn(
|
|
454
|
-
&workspace,
|
|
455
|
-
transport,
|
|
456
|
-
&session_name,
|
|
457
|
-
&window,
|
|
458
|
-
&mcp_config_path,
|
|
459
|
-
as_agent_id,
|
|
460
|
-
&profile_launch,
|
|
461
|
-
&fork_team,
|
|
462
|
-
);
|
|
463
|
-
return Err(error);
|
|
464
|
-
}
|
|
465
|
-
};
|
|
466
|
-
finalized
|
|
467
|
-
.write_audit(&crate::event_log::EventLog::new(&workspace))
|
|
468
|
-
.map_err(|error| LifecycleError::StatePersist(error.to_string()))?;
|
|
469
243
|
}
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
agent_id: as_agent_id,
|
|
474
|
-
spawn: &spawn,
|
|
475
|
-
window: &window,
|
|
476
|
-
transport,
|
|
477
|
-
session_name: &session_name,
|
|
478
|
-
mcp_config_path: &mcp_config_path,
|
|
479
|
-
profile_launch: &profile_launch,
|
|
480
|
-
materialized_role: &mut materialized_role,
|
|
481
|
-
claude_fork: &mut claude_fork,
|
|
482
|
-
copilot_fork: &mut copilot_fork,
|
|
483
|
-
})?;
|
|
484
|
-
let backing_state = if context_proof.is_some() {
|
|
485
|
-
ForkBackingState::Verified
|
|
486
|
-
} else {
|
|
487
|
-
ForkBackingState::PendingContextFork
|
|
488
|
-
};
|
|
489
|
-
Ok(ForkAgentReport {
|
|
490
|
-
source_agent_id: source_agent_id.clone(),
|
|
491
|
-
new_agent_id: as_agent_id.clone(),
|
|
492
|
-
env: AgentActionEnvelope {
|
|
493
|
-
agent_id: as_agent_id.clone(),
|
|
494
|
-
state_file: crate::state::persist::runtime_state_path(&workspace),
|
|
495
|
-
coordinator_started,
|
|
496
|
-
},
|
|
497
|
-
session_id: context_proof.map(|proof| proof.new_session_id),
|
|
498
|
-
backing_state,
|
|
499
|
-
})
|
|
244
|
+
Err(LifecycleError::RequirementUnmet(format!(
|
|
245
|
+
"fork inject did not produce {screen_mark:?} on screen"
|
|
246
|
+
)))
|
|
500
247
|
}
|