@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.
Files changed (145) hide show
  1. package/Cargo.lock +1 -1
  2. package/Cargo.toml +1 -1
  3. package/README.md +11 -0
  4. package/crates/team-agent/src/cli/adapters.rs +3 -13
  5. package/crates/team-agent/src/cli/arguments.rs +4 -0
  6. package/crates/team-agent/src/cli/diagnose.rs +68 -22
  7. package/crates/team-agent/src/cli/emit.rs +58 -26
  8. package/crates/team-agent/src/cli/intent/runtime.rs +32 -5
  9. package/crates/team-agent/src/cli/intent/runtime_tests.rs +102 -11
  10. package/crates/team-agent/src/cli/intent/tests.rs +10 -12
  11. package/crates/team-agent/src/cli/intent.rs +1 -1
  12. package/crates/team-agent/src/cli/mod.rs +25 -8
  13. package/crates/team-agent/src/cli/models.rs +764 -7
  14. package/crates/team-agent/src/cli/schedule.rs +175 -0
  15. package/crates/team-agent/src/cli/send/persist.rs +0 -36
  16. package/crates/team-agent/src/cli/send/presentation.rs +1 -1
  17. package/crates/team-agent/src/cli/send.rs +108 -110
  18. package/crates/team-agent/src/cli/spec.rs +6 -0
  19. package/crates/team-agent/src/cli/status_port/brief.rs +5 -67
  20. package/crates/team-agent/src/cli/tests/leader_watch.rs +12 -62
  21. package/crates/team-agent/src/cli/tests/mod.rs +1 -1
  22. package/crates/team-agent/src/cli/tests/named_address.rs +11 -10
  23. package/crates/team-agent/src/cli/tests/run_delegation.rs +9 -6
  24. package/crates/team-agent/src/cli/tests/status_send.rs +68 -271
  25. package/crates/team-agent/src/compiler/tests.rs +3 -18
  26. package/crates/team-agent/src/compiler.rs +205 -6
  27. package/crates/team-agent/src/contract_runtime/backend.rs +145 -11
  28. package/crates/team-agent/src/contract_runtime/commands.rs +7 -7
  29. package/crates/team-agent/src/contract_runtime/config.rs +26 -16
  30. package/crates/team-agent/src/contract_runtime/config_tests.rs +24 -4
  31. package/crates/team-agent/src/contract_runtime/discovery.rs +12 -1
  32. package/crates/team-agent/src/contract_runtime/fork.rs +3 -10
  33. package/crates/team-agent/src/contract_runtime/framework.rs +28 -11
  34. package/crates/team-agent/src/contract_runtime/mcp.rs +19 -24
  35. package/crates/team-agent/src/contract_runtime/prompt.rs +2 -2
  36. package/crates/team-agent/src/contract_runtime/registry.rs +56 -92
  37. package/crates/team-agent/src/coordinator/steps/abnormal.rs +11 -11
  38. package/crates/team-agent/src/coordinator/tests/api_error_recovery.rs +16 -54
  39. package/crates/team-agent/src/coordinator/tests/health_sync.rs +42 -0
  40. package/crates/team-agent/src/coordinator/tick.rs +1 -89
  41. package/crates/team-agent/src/db/message_store.rs +7 -65
  42. package/crates/team-agent/src/direct_delivery.rs +368 -0
  43. package/crates/team-agent/src/inbox_store.rs +169 -0
  44. package/crates/team-agent/src/leader/registry.rs +5 -0
  45. package/crates/team-agent/src/leader/start.rs +2 -1
  46. package/crates/team-agent/src/leader/tests/lease_api.rs +2 -2
  47. package/crates/team-agent/src/leader/tests/prompt_contract.rs +1 -0
  48. package/crates/team-agent/src/lib.rs +2 -0
  49. package/crates/team-agent/src/lifecycle/launch/add_agent.rs +33 -0
  50. package/crates/team-agent/src/lifecycle/launch/add_agent_state.rs +206 -1
  51. package/crates/team-agent/src/lifecycle/launch/clone_agent.rs +28 -2
  52. package/crates/team-agent/src/lifecycle/launch/fork_agent.rs +38 -13
  53. package/crates/team-agent/src/lifecycle/launch/fork_entry.rs +87 -6
  54. package/crates/team-agent/src/lifecycle/launch/mcp_config.rs +9 -1
  55. package/crates/team-agent/src/lifecycle/launch/pi_mcp.rs +351 -81
  56. package/crates/team-agent/src/lifecycle/launch/pi_mcp_extension.js +3 -4
  57. package/crates/team-agent/src/lifecycle/launch/quick_start.rs +24 -0
  58. package/crates/team-agent/src/lifecycle/launch/spawn.rs +36 -13
  59. package/crates/team-agent/src/lifecycle/launch.rs +24 -1
  60. package/crates/team-agent/src/lifecycle/profile_launch.rs +321 -11
  61. package/crates/team-agent/src/lifecycle/restart/agent.rs +1 -0
  62. package/crates/team-agent/src/lifecycle/restart/avatar.rs +1798 -0
  63. package/crates/team-agent/src/lifecycle/restart/claude_fork.rs +163 -0
  64. package/crates/team-agent/src/lifecycle/restart/common.rs +345 -35
  65. package/crates/team-agent/src/lifecycle/restart/selection.rs +5 -5
  66. package/crates/team-agent/src/lifecycle/restart.rs +4 -0
  67. package/crates/team-agent/src/lifecycle/role_config.rs +39 -14
  68. package/crates/team-agent/src/lifecycle/tests/claude_compatible_config_red.rs +325 -0
  69. package/crates/team-agent/src/lifecycle/tests/claude_profile_launch_red.rs +320 -8
  70. package/crates/team-agent/src/lifecycle/tests/cli_argv_routing_red.rs +236 -13
  71. package/crates/team-agent/src/lifecycle/tests/clone_fork_copilot_perms_red.rs +378 -4
  72. package/crates/team-agent/src/lifecycle/tests/communication_mode_runtime_contract_red.rs +5 -4
  73. package/crates/team-agent/src/lifecycle/tests/copilot_provider_red.rs +7 -11
  74. package/crates/team-agent/src/lifecycle/tests/core.rs +47 -18
  75. package/crates/team-agent/src/lifecycle/tests/fixtures/pi_native_mcp_host.mjs +2 -1
  76. package/crates/team-agent/src/lifecycle/tests/grok_require_explicit_model_red.rs +14 -14
  77. package/crates/team-agent/src/lifecycle/tests/harvest2_a_batch_red.rs +60 -20
  78. package/crates/team-agent/src/lifecycle/tests/launch_spawn.rs +28 -26
  79. package/crates/team-agent/src/lifecycle/tests/mcp_tool_name_format_red.rs +6 -6
  80. package/crates/team-agent/src/lifecycle/tests/pi_catalog_red.rs +18 -6
  81. package/crates/team-agent/src/lifecycle/tests/pi_command_red.rs +70 -52
  82. package/crates/team-agent/src/lifecycle/tests/pi_compiler_red.rs +210 -0
  83. package/crates/team-agent/src/lifecycle/tests/pi_dual_entry_red.rs +157 -4
  84. package/crates/team-agent/src/lifecycle/tests/pi_executable_mcp_red.rs +526 -10
  85. package/crates/team-agent/src/lifecycle/tests/pi_fork_session_inheritance_red.rs +1419 -0
  86. package/crates/team-agent/src/lifecycle/tests/pi_lifecycle_doctor_red.rs +68 -1
  87. package/crates/team-agent/src/lifecycle/tests/pi_native_mcp_capability_red.rs +34 -12
  88. package/crates/team-agent/src/lifecycle/tests/pi_session_delivery_red.rs +94 -2
  89. package/crates/team-agent/src/lifecycle/tests/quick_start_worker_readiness_red.rs +10 -11
  90. package/crates/team-agent/src/lifecycle/tests/status_credential_redaction_contract.rs +2 -2
  91. package/crates/team-agent/src/lifecycle/tests/swallow_batch4_semantics_red.rs +254 -2
  92. package/crates/team-agent/src/lifecycle/tests/upgrade_compat_0211_red.rs +4 -4
  93. package/crates/team-agent/src/lifecycle/tests/verify_rs031_window_consistency_red.rs +5 -6
  94. package/crates/team-agent/src/lifecycle/tests/worker_spawn_env_red.rs +16 -7
  95. package/crates/team-agent/src/lifecycle/tests.rs +3 -0
  96. package/crates/team-agent/src/lifecycle/types.rs +18 -2
  97. package/crates/team-agent/src/lifecycle/worker_command_context.rs +43 -50
  98. package/crates/team-agent/src/mcp_server/readiness.rs +130 -149
  99. package/crates/team-agent/src/mcp_server/readiness_tests.rs +98 -119
  100. package/crates/team-agent/src/mcp_server/tests/scoped.rs +21 -31
  101. package/crates/team-agent/src/mcp_server/tests/send.rs +72 -107
  102. package/crates/team-agent/src/mcp_server/tests/tools.rs +10 -12
  103. package/crates/team-agent/src/mcp_server/tools.rs +70 -196
  104. package/crates/team-agent/src/messaging/delivery.rs +160 -218
  105. package/crates/team-agent/src/messaging/delivery_consumption_tests.rs +5 -5
  106. package/crates/team-agent/src/messaging/helpers.rs +1 -19
  107. package/crates/team-agent/src/messaging/mod.rs +1 -0
  108. package/crates/team-agent/src/messaging/reminders.rs +316 -0
  109. package/crates/team-agent/src/messaging/scheduler.rs +7 -1
  110. package/crates/team-agent/src/messaging/tests/dup_inject.rs +191 -85
  111. package/crates/team-agent/src/messaging/tests/runtime.rs +4 -110
  112. package/crates/team-agent/src/messaging/tests/spine.rs +40 -24
  113. package/crates/team-agent/src/messaging/types.rs +1 -0
  114. package/crates/team-agent/src/provider/adapter.rs +303 -51
  115. package/crates/team-agent/src/provider/adapters/claude.rs +78 -0
  116. package/crates/team-agent/src/provider/adapters/claude_fork.rs +131 -0
  117. package/crates/team-agent/src/provider/adapters/mod.rs +7 -5
  118. package/crates/team-agent/src/provider/adapters/pi.rs +106 -0
  119. package/crates/team-agent/src/provider/classify.rs +1 -66
  120. package/crates/team-agent/src/provider/model_catalog.rs +201 -13
  121. package/crates/team-agent/src/provider/session/capture.rs +106 -6
  122. package/crates/team-agent/src/provider/session/context_fork/claude.rs +123 -0
  123. package/crates/team-agent/src/provider/session/context_fork/outcome.rs +4 -0
  124. package/crates/team-agent/src/provider/session/context_fork.rs +150 -18
  125. package/crates/team-agent/src/provider/session_scan/claude.rs +523 -0
  126. package/crates/team-agent/src/provider/session_scan/common.rs +44 -8
  127. package/crates/team-agent/src/provider/session_scan/pi.rs +34 -1
  128. package/crates/team-agent/src/provider/session_scan.rs +16 -6
  129. package/crates/team-agent/src/provider/tests/adapter.rs +104 -17
  130. package/crates/team-agent/src/provider/tests/classify.rs +0 -53
  131. package/crates/team-agent/src/provider/tests/command_helpers.rs +12 -3
  132. package/crates/team-agent/src/provider/tests/idle.rs +37 -0
  133. package/crates/team-agent/src/provider/wire.rs +22 -34
  134. package/crates/team-agent/src/state/abnormal_watch/tests/mod.rs +1 -1
  135. package/crates/team-agent/src/state/persist.rs +6 -6
  136. package/crates/team-agent/src/state/projection.rs +1 -1
  137. package/crates/team-agent/src/state/repository/tests.rs +2 -2
  138. package/crates/team-agent/src/test_support/models_timeout_fixture.rs +144 -0
  139. package/crates/team-agent/src/tmux_backend/tests.rs +0 -151
  140. package/crates/team-agent/src/tmux_backend.rs +5 -40
  141. package/package.json +4 -4
  142. package/skills/team-agent/SKILL.md +5 -7
  143. package/skills/team-agent/command-coverage.json +1 -1
  144. package/skills/team-agent/docs/reference/team-agent-operator.md +3 -3
  145. package/skills/team-agent/references/team-agent-operator.md +3 -3
@@ -0,0 +1,163 @@
1
+ //! Claude 的锁内新席位 fork:同一运行时、同一 cwd,新席位首次 spawn 以原生
2
+ //! `--session-id <child> --resume <parent> --fork-session` 继承源会话;源只读。
3
+ use crate::lifecycle::launch::role_source::materialize_latest_role;
4
+ use crate::lifecycle::{ForkAgentReport, ForkBackingState, LifecycleError};
5
+ use crate::model::enums::AuthMode;
6
+ use crate::model::ids::AgentId;
7
+ use crate::model::yaml::Value as YamlValue;
8
+ use crate::provider::SessionId;
9
+ use crate::state::selector::SelectedTeam;
10
+ use crate::transport::Transport;
11
+
12
+ use super::common::{
13
+ agent_auth_mode, agent_provider, agent_rollout_path, agent_session_id,
14
+ resume_backing_exists_for_agent,
15
+ };
16
+
17
+ /// `fork-agent <claude seat> --as <new>` under the source's lifecycle lock.
18
+ /// The target is an ordinary add-agent seat of the parent's provider whose
19
+ /// first spawn forks the parent's captured session; the parent's transcript,
20
+ /// row and role are never written. Claude has no admitted in-place branch
21
+ /// (`/branch` moves the parent itself), so the same id is refused.
22
+ pub(crate) fn fork_claude_new_seat_locked(
23
+ selected: &SelectedTeam,
24
+ source: &AgentId,
25
+ target: &AgentId,
26
+ label: Option<&str>,
27
+ open_display: bool,
28
+ transport: &dyn Transport,
29
+ ) -> Result<ForkAgentReport, LifecycleError> {
30
+ let run_workspace = selected.run_workspace.as_path();
31
+ let team_key = selected.team_key.as_str();
32
+ let row = selected
33
+ .state
34
+ .get("agents")
35
+ .and_then(|agents| agents.get(source.as_str()))
36
+ .ok_or_else(|| {
37
+ LifecycleError::RequirementUnmet(format!("unknown worker agent id: {source}"))
38
+ })?;
39
+ let provider_raw = row
40
+ .get("provider")
41
+ .and_then(serde_json::Value::as_str)
42
+ .unwrap_or("claude");
43
+ if agent_auth_mode(row) == AuthMode::CompatibleApi {
44
+ return Err(LifecycleError::Provider(format!(
45
+ "{provider_raw} does not support native session fork"
46
+ )));
47
+ }
48
+ if target == source {
49
+ return Err(LifecycleError::RequirementUnmet(format!(
50
+ "{source} forks into a new seat: pass --as <new agent id>; an in-place branch would move {source}'s own session"
51
+ )));
52
+ }
53
+ if target.as_str() == "leader" {
54
+ return Err(LifecycleError::RequirementUnmet(
55
+ "fork target id `leader` is reserved".to_string(),
56
+ ));
57
+ }
58
+ crate::lifecycle::launch::ensure_owner_allowed_for_state(&selected.state, Some(source))?;
59
+ let provider = agent_provider(row);
60
+ let parent = agent_session_id(row).ok_or_else(|| {
61
+ LifecycleError::RequirementUnmet(format!(
62
+ "{source} has no captured {provider_raw} session to fork"
63
+ ))
64
+ })?;
65
+ if !resume_backing_exists_for_agent(
66
+ run_workspace,
67
+ source,
68
+ row,
69
+ provider,
70
+ &parent,
71
+ agent_rollout_path(row).as_ref(),
72
+ ) {
73
+ return Err(LifecycleError::RequirementUnmet(format!(
74
+ "{source} session {} has no transcript to fork; nothing was created",
75
+ parent.as_str()
76
+ )));
77
+ }
78
+ let mut role = materialize_latest_role(
79
+ run_workspace,
80
+ &selected.team_dir,
81
+ &selected.state,
82
+ source,
83
+ target,
84
+ label,
85
+ )?;
86
+ // A fork keeps the parent's provider: a role since edited to another one
87
+ // (or to the contract leaf) would silently start a fresh seat instead.
88
+ let team_meta = crate::compiler::read_front_matter(&selected.team_dir.join("TEAM.md"))
89
+ .map(|(meta, _)| meta)
90
+ .unwrap_or(YamlValue::Null);
91
+ let compiled = crate::compiler::compile_role_agent(
92
+ role.path(),
93
+ &team_meta,
94
+ &run_workspace.to_string_lossy(),
95
+ )
96
+ .map_err(|error| LifecycleError::Compile(error.to_string()))?;
97
+ if compiled.agent.get("provider").and_then(YamlValue::as_str) != Some(provider_raw) {
98
+ return Err(LifecycleError::Compile(format!(
99
+ "{source}'s role no longer declares provider {provider_raw}; a fork keeps the parent's provider"
100
+ )));
101
+ }
102
+ let added = crate::lifecycle::launch::add_forked_agent_locked(
103
+ run_workspace,
104
+ &selected.team_dir,
105
+ target,
106
+ role.path(),
107
+ open_display,
108
+ Some(team_key),
109
+ transport,
110
+ &parent,
111
+ )?;
112
+ role.keep();
113
+ // Verified only once the child transcript exists; until then the seat runs
114
+ // and the ordinary capture binds its preassigned child session.
115
+ let state = crate::state::projection::select_runtime_state(run_workspace, Some(team_key))
116
+ .map_err(|error| LifecycleError::TeamSelect(error.to_string()))?;
117
+ let child = state
118
+ .get("agents")
119
+ .and_then(|agents| agents.get(target.as_str()))
120
+ .and_then(|row| {
121
+ let child = ["session_id", "_pending_session_id"]
122
+ .iter()
123
+ .find_map(|key| {
124
+ row.get(*key)
125
+ .and_then(serde_json::Value::as_str)
126
+ .filter(|child| !child.is_empty())
127
+ })
128
+ .filter(|child| *child != parent.as_str())
129
+ .map(SessionId::new)?;
130
+ resume_backing_exists_for_agent(
131
+ run_workspace,
132
+ target,
133
+ row,
134
+ provider,
135
+ &child,
136
+ agent_rollout_path(row).as_ref(),
137
+ )
138
+ .then_some(child)
139
+ });
140
+ let _ = crate::event_log::EventLog::new(run_workspace).write(
141
+ "lifecycle.fork.native_new_seat",
142
+ serde_json::json!({
143
+ "team": team_key,
144
+ "source_agent_id": source.as_str(),
145
+ "agent_id": target.as_str(),
146
+ "provider": provider_raw,
147
+ "source_session_id": parent.as_str(),
148
+ "session_id": child.as_ref().map(SessionId::as_str),
149
+ }),
150
+ );
151
+ Ok(ForkAgentReport {
152
+ source_agent_id: source.clone(),
153
+ new_agent_id: target.clone(),
154
+ env: added.env,
155
+ backing_state: if child.is_some() {
156
+ ForkBackingState::Verified
157
+ } else {
158
+ ForkBackingState::PendingContextFork
159
+ },
160
+ session_id: child,
161
+ pi_fork: None,
162
+ })
163
+ }
@@ -275,8 +275,8 @@ pub(super) fn spawn_agent_window(
275
275
  // (agent row → active_team_key) for back-compat with non-restart callers.
276
276
  owner_team_id_override: Option<&str>,
277
277
  ) -> Result<SpawnedAgentWindow, LifecycleError> {
278
- // A pre-upgrade Claude Code, Codex, Grok or Pi worker row has no legacy
279
- // runtime left; refuse before any MCP file, profile or pane side effect.
278
+ // A pre-upgrade Codex or Grok worker row has no legacy runtime left;
279
+ // refuse before any MCP file, profile or pane side effect.
280
280
  if let Some(retired) = agent
281
281
  .get("provider")
282
282
  .and_then(serde_json::Value::as_str)
@@ -295,6 +295,11 @@ pub(super) fn spawn_agent_window(
295
295
  } else {
296
296
  None
297
297
  };
298
+ let fork_parent = agent
299
+ .get(crate::lifecycle::launch::add_agent_state::FORK_PARENT_SESSION_ID)
300
+ .and_then(serde_json::Value::as_str)
301
+ .filter(|parent| !parent.is_empty())
302
+ .map(SessionId::new);
298
303
  // Contract C / F6.4: thread compiled role/tools/MCP context through restart as well —
299
304
  // a restarted worker must come back up with the SAME callable MCP capability + role
300
305
  // prompt as a fresh launch, else `report_result` becomes unreachable after every restart.
@@ -348,12 +353,16 @@ pub(super) fn spawn_agent_window(
348
353
  agent_id.as_str(),
349
354
  team_id.as_deref().unwrap_or(""),
350
355
  );
351
- let mcp_config_path = crate::lifecycle::launch::write_worker_mcp_config_for_provider(
352
- workspace,
353
- agent_id.as_str(),
354
- &mcp_config,
355
- Some(provider),
356
- )?;
356
+ let mcp_config_path = if provider == crate::provider::Provider::Pi {
357
+ None
358
+ } else {
359
+ Some(crate::lifecycle::launch::write_worker_mcp_config_for_provider(
360
+ workspace,
361
+ agent_id.as_str(),
362
+ &mcp_config,
363
+ Some(provider),
364
+ )?)
365
+ };
357
366
  let profile_launch =
358
367
  crate::lifecycle::profile_launch::prepare_provider_profile_launch_from_json(
359
368
  workspace,
@@ -386,18 +395,66 @@ pub(super) fn spawn_agent_window(
386
395
  agent_id_hint: Some(agent_id.as_str()),
387
396
  effort: restart_effort,
388
397
  };
389
- let spawn_cwd = spawn_cwd_override.unwrap_or(workspace);
390
- let mut plan = match resume_session_id {
391
- Some(session_id) => adapter.build_resume_command_plan(Some(session_id), context),
392
- None => adapter.build_command_plan(context),
393
- }
394
- .map_err(|e| LifecycleError::Provider(e.to_string()))?;
398
+ let pi_spawn_cwd = (provider == crate::provider::Provider::Pi)
399
+ .then(|| {
400
+ agent
401
+ .get("spawn_cwd")
402
+ .and_then(serde_json::Value::as_str)
403
+ .filter(|value| !value.is_empty())
404
+ .map(std::path::PathBuf::from)
405
+ })
406
+ .flatten();
407
+ let spawn_cwd = spawn_cwd_override
408
+ .or(pi_spawn_cwd.as_deref())
409
+ .unwrap_or(workspace);
410
+ let mut plan = if provider == crate::provider::Provider::Pi {
411
+ let request = crate::lifecycle::launch::pi_mcp::PiMaterializeRequest {
412
+ workspace,
413
+ team_id: team_id.as_deref().unwrap_or(""),
414
+ agent_id: agent_id.as_str(),
415
+ model: command_model,
416
+ effort: restart_effort,
417
+ system_prompt: &system_prompt,
418
+ team_mcp_tools: &["send_message", "report_result", "get_team_status"],
419
+ mcp_config: &mcp_config,
420
+ session_scope: crate::lifecycle::launch::pi_mcp::PiSessionScope::Isolated,
421
+ session_dir: resume_session_id
422
+ .and_then(|_| agent.get("claude_projects_root").and_then(serde_json::Value::as_str))
423
+ .map(Path::new),
424
+ };
425
+ match resume_session_id {
426
+ Some(session_id) => {
427
+ let rollout_path = agent_rollout_path(agent).ok_or_else(|| {
428
+ LifecycleError::RequirementUnmet(
429
+ "Pi resume requires the persisted exact session path".to_string(),
430
+ )
431
+ })?;
432
+ crate::lifecycle::launch::pi_mcp::materialize_pi_resume_plan(
433
+ request,
434
+ session_id,
435
+ rollout_path.as_path(),
436
+ spawn_cwd,
437
+ )
438
+ }
439
+ None => crate::lifecycle::launch::pi_mcp::materialize_pi_plan(request),
440
+ }
441
+ .map_err(|e| LifecycleError::Provider(e.to_string()))?
442
+ } else {
443
+ match (resume_session_id, fork_parent.as_ref()) {
444
+ (Some(session_id), _) => adapter.build_resume_command_plan(Some(session_id), context),
445
+ (None, Some(parent)) => adapter.fork_plan(Some(parent), context),
446
+ (None, None) => adapter.build_command_plan(context),
447
+ }
448
+ .map_err(|e| LifecycleError::Provider(e.to_string()))?
449
+ };
395
450
  if !plan.managed_mcp_config && !profile_launch.managed_mcp_config {
396
- crate::lifecycle::launch::point_native_mcp_config_at_file(
397
- &mut plan.argv,
398
- provider,
399
- &mcp_config_path,
400
- );
451
+ if let Some(mcp_config_path) = mcp_config_path.as_ref() {
452
+ crate::lifecycle::launch::point_native_mcp_config_at_file(
453
+ &mut plan.argv,
454
+ provider,
455
+ mcp_config_path,
456
+ );
457
+ }
401
458
  }
402
459
  crate::lifecycle::launch::fill_spawn_placeholders_full(
403
460
  &mut plan.argv,
@@ -424,8 +481,12 @@ pub(super) fn spawn_agent_window(
424
481
  &mut env,
425
482
  )?;
426
483
  }
427
- // Spawn cwd is override-or-workspace (E56: ignore drifted state
428
- // `.team/runtime/<team_key>/`).
484
+ // Non-Pi spawn cwd is override-or-workspace (E56: ignore drifted state
485
+ // `.team/runtime/<team_key>/`). Pi resume uses captured agent.spawn_cwd
486
+ // already resolved above so exact-path header checks match capture.
487
+ // 0.4.x provider effort MVP step 9: scrub CLAUDE_EFFORT for Claude
488
+ // worker spawn so a parent shell env cannot silently override the
489
+ // framework's effort decision.
429
490
  let env_unset = crate::layout::worker_env::isolate_worker_spawn_env(
430
491
  provider,
431
492
  &mut env,
@@ -435,6 +496,21 @@ pub(super) fn spawn_agent_window(
435
496
  restart_effort.is_some(),
436
497
  ),
437
498
  );
499
+ // Apply this owned fork policy after inherited Claude identity is scrubbed.
500
+ if resume_session_id.is_none()
501
+ && fork_parent.is_some()
502
+ && matches!(
503
+ provider,
504
+ crate::provider::Provider::Claude | crate::provider::Provider::ClaudeCode
505
+ )
506
+ {
507
+ // A fork keeps the whole parent history: a new seat never stops on
508
+ // Claude's stale-resume "summary or full session" modal.
509
+ env.insert(
510
+ "CLAUDE_CODE_RESUME_THRESHOLD_MINUTES".to_string(),
511
+ "1000000000".to_string(),
512
+ );
513
+ }
438
514
  // Keep the launcher-known typed provider independent from inherited
439
515
  // LEADER_* identity. The tmux wrapper binds pane/socket at invocation time.
440
516
  crate::layout::worker_env::inject_current_caller_provider(&mut env, provider);
@@ -617,7 +693,7 @@ pub(super) fn spawn_agent_window(
617
693
  profile_launch,
618
694
  layout_placement: layout_placement.cloned(),
619
695
  spawn_cwd: spawn_cwd.to_path_buf(),
620
- mcp_config_path: Some(mcp_config_path),
696
+ mcp_config_path,
621
697
  owner_team_id: team_id,
622
698
  })
623
699
  }
@@ -1270,11 +1346,11 @@ pub(crate) fn session_identity_probe_for_agent(
1270
1346
  }
1271
1347
 
1272
1348
  /// ---
1273
- /// purpose: 共享会话身份判定(Pi fork 血统随遗留 Pi worker 运行时一并移除)
1349
+ /// purpose: 将合法 Pi fork 血统纳入共享会话身份判定
1274
1350
  /// params:
1275
- /// workspace/state/agent: 保留调用形状
1351
+ /// workspace/state/agent: 当前被验证席位及同队来源记录
1276
1352
  /// rollout_path: 当前席位的精确 backing
1277
- /// returns: 字面身份判定结果
1353
+ /// returns: 字面身份一致,或经独立 Pi backing 与 fork 血统验证后合法继承时为 true
1278
1354
  /// ---
1279
1355
  pub(crate) fn session_identity_probe_for_agent_with_fork_ancestry(
1280
1356
  workspace: &Path,
@@ -1284,8 +1360,102 @@ pub(crate) fn session_identity_probe_for_agent_with_fork_ancestry(
1284
1360
  provider: Provider,
1285
1361
  rollout_path: Option<&RolloutPath>,
1286
1362
  ) -> SessionIdentityProbeResult {
1287
- let _ = (workspace, state, agent);
1288
- session_identity_probe_for_agent(agent_id, provider, rollout_path)
1363
+ let mut probe = session_identity_probe_for_agent(agent_id, provider, rollout_path);
1364
+ if probe.identity_ok != Some(false)
1365
+ || !pi_fork_ancestor_identity_is_valid(
1366
+ workspace,
1367
+ state,
1368
+ agent_id,
1369
+ agent,
1370
+ provider,
1371
+ rollout_path,
1372
+ probe.embedded_agent_id.as_deref(),
1373
+ )
1374
+ {
1375
+ return probe;
1376
+ }
1377
+ probe.identity_ok = Some(true);
1378
+ probe
1379
+ }
1380
+
1381
+ fn pi_fork_ancestor_identity_is_valid(
1382
+ workspace: &Path,
1383
+ state: &serde_json::Value,
1384
+ agent_id: &AgentId,
1385
+ agent: &serde_json::Value,
1386
+ provider: Provider,
1387
+ rollout_path: Option<&RolloutPath>,
1388
+ embedded_agent_id: Option<&str>,
1389
+ ) -> bool {
1390
+ if provider != Provider::Pi
1391
+ || agent.get("attribution_ambiguous").and_then(serde_json::Value::as_bool) == Some(true)
1392
+ || agent.get("capture_state").and_then(serde_json::Value::as_str)
1393
+ == Some("attribution_ambiguous")
1394
+ || !matches!(
1395
+ agent
1396
+ .get("attribution_confidence")
1397
+ .and_then(serde_json::Value::as_str),
1398
+ Some("high" | "medium")
1399
+ )
1400
+ {
1401
+ return false;
1402
+ }
1403
+ let (Some(embedded_agent_id), Some(forked_from), Some(target_path)) = (
1404
+ embedded_agent_id,
1405
+ agent
1406
+ .get("forked_from")
1407
+ .and_then(serde_json::Value::as_str)
1408
+ .filter(|value| !value.is_empty()),
1409
+ rollout_path.map(RolloutPath::as_path),
1410
+ ) else {
1411
+ return false;
1412
+ };
1413
+ if forked_from != embedded_agent_id || forked_from == agent_id.as_str() {
1414
+ return false;
1415
+ }
1416
+ let Some(source_agent) = state
1417
+ .get("agents")
1418
+ .and_then(|agents| agents.get(forked_from))
1419
+ .filter(|source| agent_provider(source) == Provider::Pi)
1420
+ else {
1421
+ return false;
1422
+ };
1423
+ let Some(source_path) = agent_rollout_path(source_agent) else {
1424
+ return false;
1425
+ };
1426
+ if source_path.as_path() == target_path {
1427
+ return false;
1428
+ }
1429
+ let (Some(session_id), Ok(target_path), Some(target_root)) = (
1430
+ agent_session_id(agent),
1431
+ std::fs::canonicalize(target_path),
1432
+ agent
1433
+ .get("claude_projects_root")
1434
+ .and_then(serde_json::Value::as_str)
1435
+ .filter(|path| !path.is_empty())
1436
+ .map(std::path::PathBuf::from),
1437
+ ) else {
1438
+ return false;
1439
+ };
1440
+ let Ok(target_root) = std::fs::canonicalize(target_root) else {
1441
+ return false;
1442
+ };
1443
+ if !target_path.starts_with(target_root)
1444
+ || std::fs::canonicalize(source_path.as_path())
1445
+ .is_ok_and(|source_path| source_path == target_path)
1446
+ || !resume_backing_probe_for_agent(
1447
+ workspace,
1448
+ agent_id,
1449
+ agent,
1450
+ provider,
1451
+ &session_id,
1452
+ rollout_path,
1453
+ )
1454
+ .exists
1455
+ {
1456
+ return false;
1457
+ }
1458
+ true
1289
1459
  }
1290
1460
 
1291
1461
  /// ---
@@ -1314,20 +1484,44 @@ pub(super) fn resume_backing_probe_for_agent(
1314
1484
  let _ = (workspace, agent_id, agent, session_id, rollout_path);
1315
1485
  false
1316
1486
  }
1487
+ Provider::Claude | Provider::ClaudeCode => {
1488
+ let rollout_ok = rollout_path_exists(rollout_path);
1489
+ let projects_root = claude_projects_root_for_agent(agent);
1490
+ if let Some(root) = projects_root.as_ref() {
1491
+ checked_paths.push(root.clone());
1492
+ }
1493
+ let event_log_path = workspace.join(".team/logs/events.jsonl");
1494
+ checked_paths.push(event_log_path);
1495
+ rollout_ok
1496
+ || event_log_transcript_exists(workspace, agent_id.as_str(), session_id.as_str())
1497
+ || projects_root.is_some_and(|root| {
1498
+ claude_project_transcript_exists_under(&root, session_id.as_str())
1499
+ })
1500
+ }
1317
1501
  Provider::Copilot => {
1318
1502
  if let Some(home) = std::env::var_os("HOME").map(PathBuf::from) {
1319
1503
  checked_paths.push(home.join(".copilot/session-store.db"));
1320
1504
  }
1321
1505
  copilot_session_store_has_session(session_id.as_str())
1322
1506
  }
1323
- // Claude Code, Codex, Grok and Pi workers run only through their contract leaves.
1324
- Provider::Claude
1325
- | Provider::ClaudeCode
1326
- | Provider::Codex
1327
- | Provider::Grok
1328
- | Provider::Pi
1329
- | Provider::GeminiCli
1330
- | Provider::Fake => false,
1507
+ Provider::Pi => {
1508
+ let spawn_cwd = agent
1509
+ .get("spawn_cwd")
1510
+ .and_then(serde_json::Value::as_str)
1511
+ .filter(|value| !value.is_empty())
1512
+ .map(PathBuf::from)
1513
+ .unwrap_or_else(|| workspace.to_path_buf());
1514
+ rollout_path.is_some_and(|path| {
1515
+ crate::provider::session_scan::pi::validate_exact_backing(
1516
+ path.as_path(),
1517
+ session_id,
1518
+ &spawn_cwd,
1519
+ )
1520
+ .is_ok()
1521
+ })
1522
+ }
1523
+ // Codex and Grok workers run only through their contract leaves.
1524
+ Provider::Codex | Provider::Grok | Provider::GeminiCli | Provider::Fake => false,
1331
1525
  };
1332
1526
 
1333
1527
  // Deduplicate while preserving order (HashSet would lose deterministic
@@ -1361,6 +1555,79 @@ pub(super) fn provider_wire_supports_resume(provider: &str) -> bool {
1361
1555
  .unwrap_or(false)
1362
1556
  }
1363
1557
 
1558
+ fn rollout_path_exists(rollout_path: Option<&RolloutPath>) -> bool {
1559
+ rollout_path
1560
+ .as_ref()
1561
+ .is_some_and(|path| path.as_path().exists())
1562
+ }
1563
+
1564
+ fn event_log_transcript_exists(workspace: &Path, agent_id: &str, session_id: &str) -> bool {
1565
+ let Ok(events) = crate::event_log::EventLog::new(workspace).tail(0) else {
1566
+ return false;
1567
+ };
1568
+ events.iter().rev().any(|event| {
1569
+ event.get("event").and_then(serde_json::Value::as_str) == Some("session.captured")
1570
+ && ["agent_id", "worker_id"]
1571
+ .iter()
1572
+ .any(|key| event.get(*key).and_then(serde_json::Value::as_str) == Some(agent_id))
1573
+ && event.get("session_id").and_then(serde_json::Value::as_str) == Some(session_id)
1574
+ && event_transcript_path(event).is_some_and(|path| path.exists())
1575
+ })
1576
+ }
1577
+
1578
+ fn event_transcript_path(event: &serde_json::Value) -> Option<PathBuf> {
1579
+ event
1580
+ .get("rollout_path")
1581
+ .or_else(|| event.get("transcript_path"))
1582
+ .and_then(serde_json::Value::as_str)
1583
+ .filter(|path| !path.is_empty())
1584
+ .map(PathBuf::from)
1585
+ }
1586
+
1587
+ /// E36 fix-B: a real Claude worker writes its session transcript to
1588
+ /// `<claude_projects_root>/<workspace-slug>/<session_id>.jsonl` even when neither
1589
+ /// `rollout_path` was persisted to state nor a `session.captured` event was logged.
1590
+ /// That landed transcript is itself a valid resume backing — restart was wrongly
1591
+ /// refusing resumable workers because it only checked the two paths above. Scan the
1592
+ /// projects root recursively for `<session_id>.jsonl` (session_id is a unique UUID,
1593
+ /// so we avoid recomputing the project-dir slug, which is brittle for non-ASCII
1594
+ /// workspace paths).
1595
+ fn claude_project_transcript_exists(agent: &serde_json::Value, session_id: &str) -> bool {
1596
+ let Some(root) = claude_projects_root_for_agent(agent) else {
1597
+ return false;
1598
+ };
1599
+ claude_project_transcript_exists_under(&root, session_id)
1600
+ }
1601
+
1602
+ fn claude_projects_root_for_agent(agent: &serde_json::Value) -> Option<PathBuf> {
1603
+ agent
1604
+ .get("claude_projects_root")
1605
+ .and_then(serde_json::Value::as_str)
1606
+ .filter(|value| !value.is_empty())
1607
+ .map(PathBuf::from)
1608
+ .or_else(|| {
1609
+ std::env::var_os("HOME")
1610
+ .map(|home| PathBuf::from(home).join(".claude").join("projects"))
1611
+ })
1612
+ }
1613
+
1614
+ fn claude_project_transcript_exists_under(projects_root: &Path, session_id: &str) -> bool {
1615
+ if session_id.is_empty() {
1616
+ return false;
1617
+ }
1618
+ if !projects_root.is_dir() {
1619
+ return false;
1620
+ }
1621
+ let transcript_name = format!("{session_id}.jsonl");
1622
+ let Ok(project_dirs) = std::fs::read_dir(projects_root) else {
1623
+ return false;
1624
+ };
1625
+ project_dirs
1626
+ .flatten()
1627
+ .filter(|entry| entry.path().is_dir())
1628
+ .any(|entry| entry.path().join(&transcript_name).is_file())
1629
+ }
1630
+
1364
1631
  fn copilot_session_store_has_session(session_id: &str) -> bool {
1365
1632
  let Some(home) = std::env::var_os("HOME").map(PathBuf::from) else {
1366
1633
  return false;
@@ -2049,4 +2316,47 @@ mod e36_transcript_backing_tests {
2049
2316
  )
2050
2317
  .is_err());
2051
2318
  }
2319
+
2320
+ // E36 fix-B RED→GREEN: a real Claude worker that sent a message has its session
2321
+ // transcript landed at <projects_root>/<slug>/<session_id>.jsonl, but neither
2322
+ // rollout_path was persisted to state nor a session.captured event was logged.
2323
+ // Before the fix, claude_project_transcript_exists did not exist and restart
2324
+ // refused such a worker. This asserts the landed transcript is recognized.
2325
+ #[test]
2326
+ fn claude_project_transcript_is_recognized_without_rollout_or_capture_event() {
2327
+ let scratch = ScratchDir::new("recognized");
2328
+ let projects_root = scratch.path().join("projects");
2329
+ let slug_dir = projects_root.join("-Users-alauda-Documents-code---rust---9");
2330
+ std::fs::create_dir_all(&slug_dir).expect("mkdir slug");
2331
+ let session_id = "87742d3f-0b4e-4fc1-ad35-447ac2340b65";
2332
+ std::fs::write(slug_dir.join(format!("{session_id}.jsonl")), b"{}\n").expect("transcript");
2333
+
2334
+ let agent = serde_json::json!({
2335
+ "claude_projects_root": projects_root.to_string_lossy(),
2336
+ });
2337
+ assert!(
2338
+ claude_project_transcript_exists(&agent, session_id),
2339
+ "landed claude transcript must count as resume backing (E36 fix-B)"
2340
+ );
2341
+ }
2342
+
2343
+ #[test]
2344
+ fn missing_claude_transcript_is_not_backing() {
2345
+ let scratch = ScratchDir::new("missing");
2346
+ let projects_root = scratch.path().join("projects");
2347
+ std::fs::create_dir_all(&projects_root).expect("mkdir");
2348
+ let agent = serde_json::json!({
2349
+ "claude_projects_root": projects_root.to_string_lossy(),
2350
+ });
2351
+ assert!(
2352
+ !claude_project_transcript_exists(&agent, "deadbeef-0000-0000-0000-000000000000"),
2353
+ "no transcript file => no backing"
2354
+ );
2355
+ }
2356
+
2357
+ #[test]
2358
+ fn empty_session_id_is_not_backing() {
2359
+ let agent = serde_json::json!({});
2360
+ assert!(!claude_project_transcript_exists(&agent, ""));
2361
+ }
2052
2362
  }
@@ -45,7 +45,7 @@ mod contract_route_tests {
45
45
  fn mixed_team_retains_legacy_classification_without_native_codex_fallback() {
46
46
  let state = serde_json::json!({"agents": {
47
47
  "native": {"provider":"cursor","status":"running","session_id":"native-id"},
48
- "legacy": {"provider":"copilot","status":"running"},
48
+ "legacy": {"provider":"pi","status":"running"},
49
49
  }});
50
50
  let plan = classify_restart_plan(&state, false).unwrap();
51
51
  assert_eq!(plan.decisions.len(), 1);
@@ -61,11 +61,11 @@ mod stopped_restart_tests {
61
61
  #[test]
62
62
  fn stopped_rows_never_enter_validation_or_fresh_spawn_even_with_allow_fresh() {
63
63
  let state = serde_json::json!({"agents": {
64
- "stopped": {"provider":"copilot","status":"stopped","explicit_stop":true,
64
+ "stopped": {"provider":"pi","status":"stopped","explicit_stop":true,
65
65
  "session_id":"preserved","generation":7,"first_send_at":false},
66
- "legacy_stopped": {"provider":"copilot","status":"stopped"},
67
- "marker": {"provider":"copilot","status":"running","explicit_stop":true},
68
- "active": {"provider":"copilot","status":"running"}
66
+ "legacy_stopped": {"provider":"pi","status":"stopped"},
67
+ "marker": {"provider":"pi","status":"running","explicit_stop":true},
68
+ "active": {"provider":"pi","status":"running"}
69
69
  }});
70
70
  let before = state.clone();
71
71
  for allow_fresh in [false, true] {
@@ -66,6 +66,10 @@ struct LifecyclePathRefs<'a> {
66
66
  }
67
67
 
68
68
  mod agent;
69
+ mod avatar;
70
+ pub(crate) use avatar::fork_pi_new_seat_locked;
71
+ mod claude_fork;
72
+ pub(crate) use claude_fork::fork_claude_new_seat_locked;
69
73
  mod common;
70
74
  mod orchestrator;
71
75
  pub mod preflight;