@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.
Files changed (187) 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 -91
  7. package/crates/team-agent/src/cli/emit.rs +61 -28
  8. package/crates/team-agent/src/cli/grok_slot.rs +88 -3
  9. package/crates/team-agent/src/cli/intent/runtime.rs +38 -9
  10. package/crates/team-agent/src/cli/intent/runtime_tests.rs +147 -11
  11. package/crates/team-agent/src/cli/intent/tests.rs +10 -12
  12. package/crates/team-agent/src/cli/intent.rs +1 -1
  13. package/crates/team-agent/src/cli/mod.rs +38 -9
  14. package/crates/team-agent/src/cli/models.rs +789 -186
  15. package/crates/team-agent/src/cli/schedule.rs +175 -0
  16. package/crates/team-agent/src/cli/send/persist.rs +0 -36
  17. package/crates/team-agent/src/cli/send/presentation.rs +1 -1
  18. package/crates/team-agent/src/cli/send.rs +108 -110
  19. package/crates/team-agent/src/cli/spec.rs +6 -0
  20. package/crates/team-agent/src/cli/status_port/brief.rs +5 -67
  21. package/crates/team-agent/src/cli/tests/leader_watch.rs +12 -62
  22. package/crates/team-agent/src/cli/tests/mod.rs +3 -3
  23. package/crates/team-agent/src/cli/tests/named_address.rs +11 -10
  24. package/crates/team-agent/src/cli/tests/run_delegation.rs +12 -9
  25. package/crates/team-agent/src/cli/tests/status_send.rs +70 -273
  26. package/crates/team-agent/src/compiler/tests.rs +39 -27
  27. package/crates/team-agent/src/compiler.rs +206 -6
  28. package/crates/team-agent/src/contract_runtime/backend.rs +181 -11
  29. package/crates/team-agent/src/contract_runtime/commands.rs +338 -7
  30. package/crates/team-agent/src/contract_runtime/config.rs +30 -19
  31. package/crates/team-agent/src/contract_runtime/config_tests.rs +24 -4
  32. package/crates/team-agent/src/contract_runtime/discovery.rs +12 -1
  33. package/crates/team-agent/src/contract_runtime/fork.rs +3 -10
  34. package/crates/team-agent/src/contract_runtime/framework.rs +28 -14
  35. package/crates/team-agent/src/contract_runtime/mcp.rs +19 -24
  36. package/crates/team-agent/src/contract_runtime/prompt.rs +2 -2
  37. package/crates/team-agent/src/contract_runtime/registry.rs +93 -130
  38. package/crates/team-agent/src/coordinator/steps/abnormal.rs +45 -5
  39. package/crates/team-agent/src/coordinator/tests/api_error_recovery.rs +8 -29
  40. package/crates/team-agent/src/coordinator/tests/energy.rs +4 -4
  41. package/crates/team-agent/src/coordinator/tests/health_sync.rs +44 -2
  42. package/crates/team-agent/src/coordinator/tests/main_preserved.rs +2 -2
  43. package/crates/team-agent/src/coordinator/tests/spine.rs +1 -1
  44. package/crates/team-agent/src/coordinator/tests/takeover.rs +3 -3
  45. package/crates/team-agent/src/coordinator/tick.rs +1 -89
  46. package/crates/team-agent/src/db/message_store.rs +7 -65
  47. package/crates/team-agent/src/direct_delivery.rs +368 -0
  48. package/crates/team-agent/src/inbox_store.rs +169 -0
  49. package/crates/team-agent/src/leader/registry.rs +5 -0
  50. package/crates/team-agent/src/leader/start.rs +2 -1
  51. package/crates/team-agent/src/leader/tests/lease_api.rs +2 -2
  52. package/crates/team-agent/src/leader/tests/prompt_contract.rs +1 -0
  53. package/crates/team-agent/src/lib.rs +2 -0
  54. package/crates/team-agent/src/lifecycle/launch/add_agent.rs +33 -0
  55. package/crates/team-agent/src/lifecycle/launch/add_agent_state.rs +206 -1
  56. package/crates/team-agent/src/lifecycle/launch/clone_agent.rs +28 -2
  57. package/crates/team-agent/src/lifecycle/launch/fork_agent.rs +36 -179
  58. package/crates/team-agent/src/lifecycle/launch/fork_entry.rs +87 -6
  59. package/crates/team-agent/src/lifecycle/launch/mcp_config.rs +13 -488
  60. package/crates/team-agent/src/lifecycle/launch/pi_mcp.rs +351 -81
  61. package/crates/team-agent/src/lifecycle/launch/pi_mcp_extension.js +3 -4
  62. package/crates/team-agent/src/lifecycle/launch/quick_start.rs +26 -2
  63. package/crates/team-agent/src/lifecycle/launch/spawn.rs +41 -31
  64. package/crates/team-agent/src/lifecycle/launch.rs +27 -12
  65. package/crates/team-agent/src/lifecycle/profile_launch.rs +318 -64
  66. package/crates/team-agent/src/lifecycle/restart/agent.rs +1 -0
  67. package/crates/team-agent/src/lifecycle/restart/avatar.rs +1798 -0
  68. package/crates/team-agent/src/lifecycle/restart/claude_fork.rs +163 -0
  69. package/crates/team-agent/src/lifecycle/restart/common.rs +298 -133
  70. package/crates/team-agent/src/lifecycle/restart/remove.rs +129 -0
  71. package/crates/team-agent/src/lifecycle/restart/selection.rs +5 -5
  72. package/crates/team-agent/src/lifecycle/restart.rs +4 -0
  73. package/crates/team-agent/src/lifecycle/role_config.rs +79 -27
  74. package/crates/team-agent/src/lifecycle/tests/acceptance_b_batch_red.rs +1 -1
  75. package/crates/team-agent/src/lifecycle/tests/agent_ops.rs +8 -12
  76. package/crates/team-agent/src/lifecycle/tests/behavioral_diff_264_red.rs +37 -240
  77. package/crates/team-agent/src/lifecycle/tests/claude_compatible_config_red.rs +325 -0
  78. package/crates/team-agent/src/lifecycle/tests/claude_profile_launch_red.rs +320 -8
  79. package/crates/team-agent/src/lifecycle/tests/cli_argv_routing_red.rs +329 -70
  80. package/crates/team-agent/src/lifecycle/tests/clone_fork_copilot_perms_red.rs +378 -4
  81. package/crates/team-agent/src/lifecycle/tests/communication_mode_runtime_contract_red.rs +25 -39
  82. package/crates/team-agent/src/lifecycle/tests/copilot_provider_red.rs +7 -11
  83. package/crates/team-agent/src/lifecycle/tests/core.rs +39 -36
  84. package/crates/team-agent/src/lifecycle/tests/f032_startup_prompt_best_effort_red.rs +22 -8
  85. package/crates/team-agent/src/lifecycle/tests/fixtures/pi_native_mcp_host.mjs +2 -1
  86. package/crates/team-agent/src/lifecycle/tests/grok_require_explicit_model_red.rs +15 -133
  87. package/crates/team-agent/src/lifecycle/tests/harvest2_a_batch_red.rs +60 -20
  88. package/crates/team-agent/src/lifecycle/tests/host_cotenant_death_p0_contract.rs +30 -67
  89. package/crates/team-agent/src/lifecycle/tests/issue238_codex_effort_contract.rs +3 -31
  90. package/crates/team-agent/src/lifecycle/tests/lane_ops.rs +194 -169
  91. package/crates/team-agent/src/lifecycle/tests/launch_spawn.rs +164 -282
  92. package/crates/team-agent/src/lifecycle/tests/lifecycle_rollback_red.rs +15 -78
  93. package/crates/team-agent/src/lifecycle/tests/main_preserved.rs +7 -7
  94. package/crates/team-agent/src/lifecycle/tests/mcp_tool_name_format_red.rs +6 -6
  95. package/crates/team-agent/src/lifecycle/tests/phase_b_contracts.rs +75 -69
  96. package/crates/team-agent/src/lifecycle/tests/phase_golden.rs +2 -10
  97. package/crates/team-agent/src/lifecycle/tests/pi_catalog_red.rs +18 -6
  98. package/crates/team-agent/src/lifecycle/tests/pi_command_red.rs +70 -52
  99. package/crates/team-agent/src/lifecycle/tests/pi_compiler_red.rs +210 -0
  100. package/crates/team-agent/src/lifecycle/tests/pi_dual_entry_red.rs +157 -4
  101. package/crates/team-agent/src/lifecycle/tests/pi_executable_mcp_red.rs +526 -10
  102. package/crates/team-agent/src/lifecycle/tests/pi_fork_session_inheritance_red.rs +1419 -0
  103. package/crates/team-agent/src/lifecycle/tests/pi_lifecycle_doctor_red.rs +68 -1
  104. package/crates/team-agent/src/lifecycle/tests/pi_native_mcp_capability_red.rs +34 -12
  105. package/crates/team-agent/src/lifecycle/tests/pi_session_delivery_red.rs +94 -2
  106. package/crates/team-agent/src/lifecycle/tests/quick_start_worker_readiness_red.rs +14 -15
  107. package/crates/team-agent/src/lifecycle/tests/restart.rs +12 -153
  108. package/crates/team-agent/src/lifecycle/tests/restart_build_before_destroy_0540_contract.rs +27 -5
  109. package/crates/team-agent/src/lifecycle/tests/restart_liveness_red.rs +59 -10
  110. package/crates/team-agent/src/lifecycle/tests/restart_rebind_hotfix_252_red.rs +47 -6
  111. package/crates/team-agent/src/lifecycle/tests/restart_session_capture_red.rs +3 -1374
  112. package/crates/team-agent/src/lifecycle/tests/resume_recover_red.rs +27 -10
  113. package/crates/team-agent/src/lifecycle/tests/status_credential_redaction_contract.rs +7 -7
  114. package/crates/team-agent/src/lifecycle/tests/subprep_codex_trust_roundtrip_red.rs +67 -313
  115. package/crates/team-agent/src/lifecycle/tests/swallow_batch4_semantics_red.rs +254 -2
  116. package/crates/team-agent/src/lifecycle/tests/team_in_team_identity_scope_red.rs +2 -2
  117. package/crates/team-agent/src/lifecycle/tests/team_in_team_sibling_quick_start_red.rs +1 -1
  118. package/crates/team-agent/src/lifecycle/tests/team_in_team_state_scope_red.rs +2 -2
  119. package/crates/team-agent/src/lifecycle/tests/team_key_retirement_txn_red.rs +4 -4
  120. package/crates/team-agent/src/lifecycle/tests/upgrade_compat_0211_red.rs +74 -19
  121. package/crates/team-agent/src/lifecycle/tests/verify_rs031_window_consistency_red.rs +38 -39
  122. package/crates/team-agent/src/lifecycle/tests/worker_spawn_env_red.rs +51 -88
  123. package/crates/team-agent/src/lifecycle/tests.rs +3 -4
  124. package/crates/team-agent/src/lifecycle/types.rs +18 -5
  125. package/crates/team-agent/src/lifecycle/worker_command_context.rs +43 -50
  126. package/crates/team-agent/src/mcp_server/readiness.rs +130 -149
  127. package/crates/team-agent/src/mcp_server/readiness_tests.rs +86 -109
  128. package/crates/team-agent/src/mcp_server/tests/scoped.rs +21 -31
  129. package/crates/team-agent/src/mcp_server/tests/send.rs +72 -107
  130. package/crates/team-agent/src/mcp_server/tests/tools.rs +10 -12
  131. package/crates/team-agent/src/mcp_server/tools.rs +70 -196
  132. package/crates/team-agent/src/messaging/delivery.rs +143 -253
  133. package/crates/team-agent/src/messaging/delivery_consumption_tests.rs +5 -5
  134. package/crates/team-agent/src/messaging/helpers.rs +1 -19
  135. package/crates/team-agent/src/messaging/mod.rs +1 -0
  136. package/crates/team-agent/src/messaging/reminders.rs +316 -0
  137. package/crates/team-agent/src/messaging/scheduler.rs +7 -1
  138. package/crates/team-agent/src/messaging/tests/dup_inject.rs +255 -150
  139. package/crates/team-agent/src/messaging/tests/main_preserved.rs +2 -2
  140. package/crates/team-agent/src/messaging/tests/runtime.rs +9 -115
  141. package/crates/team-agent/src/messaging/tests/spine.rs +44 -24
  142. package/crates/team-agent/src/messaging/tests/wave2.rs +13 -20
  143. package/crates/team-agent/src/messaging/types.rs +1 -0
  144. package/crates/team-agent/src/provider/adapter.rs +208 -254
  145. package/crates/team-agent/src/provider/adapters/claude.rs +78 -0
  146. package/crates/team-agent/src/provider/adapters/claude_fork.rs +131 -0
  147. package/crates/team-agent/src/provider/adapters/mod.rs +7 -7
  148. package/crates/team-agent/src/provider/adapters/pi.rs +106 -0
  149. package/crates/team-agent/src/provider/classify.rs +1 -66
  150. package/crates/team-agent/src/provider/model_catalog.rs +201 -13
  151. package/crates/team-agent/src/provider/session/capture.rs +111 -111
  152. package/crates/team-agent/src/provider/session/context_fork/claude.rs +123 -0
  153. package/crates/team-agent/src/provider/session/context_fork/outcome.rs +10 -18
  154. package/crates/team-agent/src/provider/session/context_fork.rs +87 -74
  155. package/crates/team-agent/src/provider/session/mod.rs +2 -3
  156. package/crates/team-agent/src/provider/session_scan/claude.rs +523 -0
  157. package/crates/team-agent/src/provider/session_scan/common.rs +47 -47
  158. package/crates/team-agent/src/provider/session_scan/pi.rs +34 -1
  159. package/crates/team-agent/src/provider/session_scan.rs +13 -13
  160. package/crates/team-agent/src/provider/tests/adapter.rs +127 -121
  161. package/crates/team-agent/src/provider/tests/classify.rs +0 -53
  162. package/crates/team-agent/src/provider/tests/command_helpers.rs +11 -19
  163. package/crates/team-agent/src/provider/tests/idle.rs +13 -19
  164. package/crates/team-agent/src/provider/types.rs +0 -4
  165. package/crates/team-agent/src/provider/wire.rs +34 -20
  166. package/crates/team-agent/src/state/abnormal_watch/tests/mod.rs +1 -1
  167. package/crates/team-agent/src/state/persist.rs +6 -6
  168. package/crates/team-agent/src/state/projection.rs +1 -1
  169. package/crates/team-agent/src/state/repository/tests.rs +2 -2
  170. package/crates/team-agent/src/test_support/models_timeout_fixture.rs +144 -0
  171. package/crates/team-agent/src/tmux_backend/tests.rs +0 -151
  172. package/crates/team-agent/src/tmux_backend.rs +9 -43
  173. package/package.json +4 -4
  174. package/skills/team-agent/SKILL.md +7 -8
  175. package/skills/team-agent/command-coverage.json +15 -1
  176. package/skills/team-agent/docs/reference/team-agent-operator.md +5 -3
  177. package/skills/team-agent/references/team-agent-operator.md +5 -3
  178. package/crates/team-agent/src/lifecycle/launch/grok_per_seat.rs +0 -260
  179. package/crates/team-agent/src/lifecycle/tests/codex_weak_window_attribution_red.rs +0 -683
  180. package/crates/team-agent/src/lifecycle/tests/grok_effort_argv_red.rs +0 -247
  181. package/crates/team-agent/src/lifecycle/tests/grok_mcp_overlay_red.rs +0 -507
  182. package/crates/team-agent/src/lifecycle/tests/grok_restart_resume_red.rs +0 -300
  183. package/crates/team-agent/src/provider/adapters/codex.rs +0 -101
  184. package/crates/team-agent/src/provider/adapters/grok.rs +0 -67
  185. package/crates/team-agent/src/provider/session/context_fork/codex.rs +0 -514
  186. package/crates/team-agent/src/provider/session_scan/codex.rs +0 -326
  187. package/crates/team-agent/src/provider/session_scan/grok.rs +0 -288
@@ -653,6 +653,135 @@ fn remove_agent_at_paths(
653
653
  }
654
654
  }
655
655
 
656
+ struct ContractRemovalInputs {
657
+ paths: LifecyclePaths,
658
+ team: Option<String>,
659
+ transport: crate::tmux_backend::TmuxBackend,
660
+ state: serde_json::Value,
661
+ spec: YamlValue,
662
+ team_key: String,
663
+ }
664
+
665
+ impl ContractRemovalInputs {
666
+ fn resolve(workspace: &Path, agent_id: &AgentId, team: Option<&str>) -> Result<Self, LifecycleError> {
667
+ let paths = lifecycle_paths(workspace, team)?;
668
+ let team = paths.canonical_team(team).map(str::to_string);
669
+ let transport = paths.tmux_backend()?;
670
+ let state = resolve_team_scoped_state_or_refuse(&paths.run_workspace, team.as_deref())?;
671
+ crate::lifecycle::launch::ensure_owner_allowed_for_state(&state, Some(agent_id))?;
672
+ let spec = load_team_spec(&paths.spec_workspace)?;
673
+ let team_key = state
674
+ .get("active_team_key")
675
+ .and_then(serde_json::Value::as_str)
676
+ .filter(|key| !key.is_empty())
677
+ .map(str::to_string)
678
+ .unwrap_or_else(|| crate::state::projection::team_state_key(&state));
679
+ Ok(Self { paths, team, transport, state, spec, team_key })
680
+ }
681
+
682
+ fn refs(&self) -> LifecyclePathRefs<'_> {
683
+ LifecyclePathRefs {
684
+ run_workspace: &self.paths.run_workspace,
685
+ spec_workspace: &self.paths.spec_workspace,
686
+ }
687
+ }
688
+
689
+ fn rollback(&self, agent_id: &AgentId) -> Result<RemoveRollback, LifecycleError> {
690
+ RemoveRollback::capture(
691
+ &self.paths.run_workspace,
692
+ &self.paths.spec_workspace,
693
+ &self.spec,
694
+ &self.state,
695
+ &self.team_key,
696
+ agent_id,
697
+ )
698
+ }
699
+ }
700
+
701
+ /// ---
702
+ /// purpose: 契约席位摘除前的只读预检;在原生席位停机或退役之前,确认逻辑摘除所需输入都能解析
703
+ /// errors: 选不到 team、owner 门不过、spec 缺失或摘除后 spec 校验不过时返回 LifecycleError
704
+ /// ---
705
+ /// Deterministic failures surface while the native seat is still intact.
706
+ pub(crate) fn preflight_contract_removal(
707
+ workspace: &Path,
708
+ agent_id: &AgentId,
709
+ team: Option<&str>,
710
+ ) -> Result<(), LifecycleError> {
711
+ let inputs = ContractRemovalInputs::resolve(workspace, agent_id, team)?;
712
+ inputs.rollback(agent_id)?;
713
+ let removed = spec_without_agent(&inputs.spec, agent_id);
714
+ if should_validate_removed_spec(&removed, &inputs.refs()) {
715
+ crate::model::spec::validate_spec(&removed, &inputs.paths.run_workspace)
716
+ .map_err(|e| LifecycleError::Compile(e.to_string()))?;
717
+ }
718
+ Ok(())
719
+ }
720
+
721
+ /// ---
722
+ /// purpose: 契约席位的逻辑摘除;原生 store 的停机与退役已由调用方在同一把生命周期锁下完成
723
+ /// returns: 摘除结果
724
+ /// errors: 选不到 team、owner 门不过或写盘失败时返回 LifecycleError,并按快照回滚
725
+ /// ---
726
+ /// A contract seat has no workspace pane to resolve, so no legacy transport
727
+ /// identity is consulted. Only the shared logical records are removed.
728
+ pub(crate) fn remove_contract_records_locked(
729
+ workspace: &Path,
730
+ agent_id: &AgentId,
731
+ from_spec: bool,
732
+ force: bool,
733
+ stopped: bool,
734
+ team: Option<&str>,
735
+ ) -> Result<RemoveAgentOutcome, LifecycleError> {
736
+ let inputs = ContractRemovalInputs::resolve(workspace, agent_id, team)?;
737
+ let rollback = inputs.rollback(agent_id)?;
738
+ let refs = inputs.refs();
739
+ let team = inputs.team.as_deref();
740
+ let result = remove_agent_inner(
741
+ &refs,
742
+ agent_id,
743
+ &inputs.spec,
744
+ inputs.state.clone(),
745
+ None,
746
+ &inputs.team_key,
747
+ false,
748
+ team,
749
+ &inputs.transport,
750
+ );
751
+ match result {
752
+ Ok(success) => {
753
+ write_remove_complete_event(
754
+ refs.run_workspace,
755
+ agent_id,
756
+ from_spec,
757
+ force,
758
+ stopped,
759
+ success.role_file_removed,
760
+ success.cleared_locations,
761
+ )?;
762
+ Ok(success.outcome)
763
+ }
764
+ Err(error) => {
765
+ let restore_errors =
766
+ rollback.restore(refs.run_workspace, refs.spec_workspace, team, &inputs.transport);
767
+ let rollback_ok = restore_errors.is_empty();
768
+ let _ = write_remove_rollback_events(RemoveRollbackEvent {
769
+ agent_id,
770
+ workspace: refs.run_workspace,
771
+ from_spec,
772
+ force,
773
+ stopped,
774
+ error: &error,
775
+ rollback_ok,
776
+ restore_errors: &restore_errors,
777
+ });
778
+ Err(LifecycleError::StatePersist(format!(
779
+ "remove-agent failed for {agent_id}: {error}; rollback_ok={rollback_ok}"
780
+ )))
781
+ }
782
+ }
783
+ }
784
+
656
785
  fn remove_agent_inner(
657
786
  paths: &LifecyclePathRefs<'_>,
658
787
  agent_id: &AgentId,
@@ -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;
@@ -52,6 +52,20 @@ pub fn add_agent_from_role(
52
52
  })
53
53
  }
54
54
 
55
+ #[cfg(test)]
56
+ pub(crate) fn add_agent_from_role_with_transport(
57
+ workspace: &Path,
58
+ agent_id: &AgentId,
59
+ source: Option<&Path>,
60
+ patch: &RoleConfigPatch,
61
+ force: bool,
62
+ transport: &dyn Transport,
63
+ ) -> Result<AddAgentReport, LifecycleError> {
64
+ with_selected(&select(workspace, None)?, agent_id, |selected| {
65
+ add_at_selected(selected, agent_id, source, patch, force, transport)
66
+ })
67
+ }
68
+
55
69
  pub fn start_agent_from_role(
56
70
  workspace: &Path,
57
71
  agent_id: &AgentId,
@@ -108,27 +122,38 @@ fn add_at_selected(
108
122
  )));
109
123
  }
110
124
  let role_path = role_path(selected, agent_id);
111
- if !recreate {
125
+ // --force re-adopts the role file a removed seat left behind (#391): CLI
126
+ // values override its frontmatter and its body is kept.
127
+ let adopted = !recreate
128
+ && force
129
+ && source.is_none()
130
+ && fs::symlink_metadata(&role_path).is_ok_and(|meta| meta.is_file());
131
+ if !recreate && !adopted {
112
132
  check_destination(&role_path, source)?;
113
133
  }
114
134
  let text = match source {
115
135
  Some(path) => read_text(path)?,
136
+ None if adopted => patched_role(&read_text(&role_path)?, agent_id, patch, false)?,
116
137
  None => String::new(),
117
138
  };
139
+ let generated = source.is_none() && !adopted;
118
140
  #[allow(unused_mut)]
119
141
  let mut reconciled = reconcile_creation(&text, patch)?;
120
142
  // A generated legacy role falls back to its id as instructions at compile
121
143
  // time; a contract role requires a body, so give it a neutral default.
122
144
  #[cfg(unix)]
123
- if source.is_none()
145
+ if generated
124
146
  && reconciled.prompt.is_none()
125
- && crate::contract_runtime::framework::declares_contract(None, reconciled.provider.as_deref())
147
+ && crate::contract_runtime::framework::declares_contract(
148
+ None,
149
+ reconciled.provider.as_deref(),
150
+ )
126
151
  {
127
152
  reconciled.prompt = Some(format!(
128
153
  "You are {agent_id}. Complete the tasks assigned by the leader.\n"
129
154
  ));
130
155
  }
131
- let next = patched_role(&text, agent_id, &reconciled, source.is_none())?;
156
+ let next = patched_role(&text, agent_id, &reconciled, generated)?;
132
157
  let snapshot = RoleSnapshot::capture(selected, &role_path)?;
133
158
  let result = (|| {
134
159
  if snapshot.role.bytes.as_deref() != Some(next.as_bytes()) {
@@ -315,7 +340,7 @@ fn start_at_selected(
315
340
  }
316
341
  }
317
342
 
318
- // A file is an explicit configuration source, not a template to silently override.
343
+ // Keep role-file values authoritative except for explicit CLI bypass intent.
319
344
  // Equal supplied values are omitted from the patch to preserve existing file bytes.
320
345
  fn reconcile_creation(
321
346
  text: &str,
@@ -342,12 +367,11 @@ fn reconcile_creation(
342
367
  .get("provider")
343
368
  .and_then(Value::as_str)
344
369
  .filter(|value| !value.trim().is_empty());
345
- let opted_in = matches!(meta.get("contract_runtime"), Some(Value::Bool(true)));
346
370
  if let Some(file_provider) = file_provider {
347
- let file_provider = declared_provider(file_provider, opted_in)
371
+ let file_provider = declared_provider(file_provider)
348
372
  .ok_or_else(|| LifecycleError::Compile("unknown role provider".into()))?;
349
373
  if let Some(provider) = &next.provider {
350
- if declared_provider(provider, opted_in) != Some(file_provider) {
374
+ if declared_provider(provider) != Some(file_provider) {
351
375
  return Err(conflict("provider"));
352
376
  }
353
377
  next.provider = None;
@@ -359,10 +383,7 @@ fn reconcile_creation(
359
383
  }
360
384
  match meta.get("dangerously_skip_permissions") {
361
385
  Some(Value::Bool(value)) => {
362
- if let Some(bypass) = next.bypass {
363
- if bypass != *value {
364
- return Err(conflict("bypass"));
365
- }
386
+ if next.bypass == Some(*value) {
366
387
  next.bypass = None;
367
388
  }
368
389
  }
@@ -371,11 +392,6 @@ fn reconcile_creation(
371
392
  "role dangerously_skip_permissions must be a boolean".into(),
372
393
  ))
373
394
  }
374
- None if next.bypass.is_none() => {
375
- return Err(LifecycleError::RequirementUnmet(
376
- "add-agent requires bypass in --role-file or --bypass <true|false>".into(),
377
- ))
378
- }
379
395
  None => {}
380
396
  }
381
397
  for (field, supplied) in [
@@ -415,13 +431,11 @@ fn reconcile_creation(
415
431
 
416
432
  /// One identity per declared provider: its contract leaf id, else its legacy
417
433
  /// wire form, so `agent` in a role file and `--provider cursor` agree.
418
- fn declared_provider(value: &str, contract_runtime: bool) -> Option<&'static str> {
434
+ fn declared_provider(value: &str) -> Option<&'static str> {
419
435
  #[cfg(unix)]
420
- if let Some(descriptor) = crate::contract_runtime::registry::declared(value, contract_runtime) {
436
+ if let Some(descriptor) = crate::contract_runtime::registry::declared(value) {
421
437
  return Some(descriptor.identity.id);
422
438
  }
423
- #[cfg(not(unix))]
424
- let _ = contract_runtime;
425
439
  crate::provider::wire::parse_provider(value).map(crate::provider::wire::provider_wire)
426
440
  }
427
441
 
@@ -449,8 +463,13 @@ fn check_destination(path: &Path, source: Option<&Path>) -> Result<(), Lifecycle
449
463
  .is_some_and(|(source, target)| source == target)
450
464
  }) {
451
465
  return Err(LifecycleError::RequirementUnmet(format!(
452
- "role file already exists: {}",
453
- path.display()
466
+ "role file already exists: {}{}",
467
+ path.display(),
468
+ if source.is_none() {
469
+ "; reuse it with --role-file or re-adopt it with --force"
470
+ } else {
471
+ ""
472
+ }
454
473
  )));
455
474
  }
456
475
  }
@@ -963,10 +982,6 @@ mod tests {
963
982
  provider: Some("pi".into()),
964
983
  ..Default::default()
965
984
  },
966
- RoleConfigPatch {
967
- bypass: Some(true),
968
- ..Default::default()
969
- },
970
985
  RoleConfigPatch {
971
986
  model: Some("other".into()),
972
987
  ..Default::default()
@@ -1015,6 +1030,43 @@ mod tests {
1015
1030
  }
1016
1031
  }
1017
1032
 
1033
+ #[test]
1034
+ fn explicit_bypass_overrides_role_file_in_both_directions() {
1035
+ for &provider in crate::provider::wire::all_providers() {
1036
+ let provider = crate::provider::wire::provider_wire(provider);
1037
+ for declared in [true, false] {
1038
+ let text = format!("---\nprovider: {provider}\ndangerously_skip_permissions: {declared}\n---\nbody");
1039
+ let patch = RoleConfigPatch {
1040
+ bypass: Some(!declared),
1041
+ ..Default::default()
1042
+ };
1043
+ let reconciled = reconcile_creation(&text, &patch).unwrap();
1044
+ let next = patched_role(&text, &AgentId::new("w"), &reconciled, false).unwrap();
1045
+ assert_eq!(
1046
+ role_parts(&next).unwrap().0.get("dangerously_skip_permissions"),
1047
+ Some(&Value::Bool(!declared))
1048
+ );
1049
+ }
1050
+ }
1051
+ }
1052
+
1053
+ #[test]
1054
+ fn omitted_bypass_preserves_native_default_and_invalid_boolean_is_rejected() {
1055
+ let patch = RoleConfigPatch {
1056
+ provider: Some("pi".into()),
1057
+ ..Default::default()
1058
+ };
1059
+ assert_eq!(reconcile_creation("", &patch).unwrap().bypass, None);
1060
+ assert_eq!(
1061
+ reconcile_creation("---\nprovider: pi\n---\n", &RoleConfigPatch::default())
1062
+ .unwrap().bypass,
1063
+ None
1064
+ );
1065
+ assert!(reconcile_creation(
1066
+ "---\nprovider: pi\ndangerously_skip_permissions: yes\n---\n", &patch
1067
+ ).is_err());
1068
+ }
1069
+
1018
1070
  #[test]
1019
1071
  fn legacy_cr_only_header_does_not_change_engine_when_patched() {
1020
1072
  let text = "---\rprovider: codex\ndangerously_skip_permissions: false\r---\r\rbody\r";
@@ -405,7 +405,7 @@ fn write_min_team(ws: &Path, name: &str) -> PathBuf {
405
405
  .unwrap();
406
406
  std::fs::write(
407
407
  team.join("agents/worker_a.md"),
408
- "---\nname: worker_a\nrole: Worker\nprovider: codex\nmodel: gpt-5.5\nauth_mode: subscription\ndangerously_skip_permissions: false\ntools:\n - mcp_team\n---\n\nWorker.\n",
408
+ "---\nname: worker_a\nrole: Worker\nprovider: fake\nmodel: fake\nauth_mode: subscription\ndangerously_skip_permissions: false\ntools:\n - mcp_team\n---\n\nWorker.\n",
409
409
  )
410
410
  .unwrap();
411
411
  team
@@ -1,3 +1,4 @@
1
+ use super::lane_ops::assert_legacy_fork_unverified;
1
2
  use super::launch_spawn::{
2
3
  quick_start_team_dir, restart_ws_two_resumable_workers, seed_healthy_coordinator,
3
4
  DELEG_ROLE_ALPHA, DELEG_ROLE_BRAVO, QS_VALID_ROLE,
@@ -43,8 +44,8 @@ pub(super) fn lanea_team_ws(status: &str) -> PathBuf {
43
44
  &json!({
44
45
  "session_name": "team-laneateam",
45
46
  "agents": {
46
- "alpha": {"status": status, "provider": "codex", "window": "alpha"},
47
- "bravo": {"status": status, "provider": "codex", "window": "bravo"}
47
+ "alpha": {"status": status, "provider": "fake", "window": "alpha"},
48
+ "bravo": {"status": status, "provider": "fake", "window": "bravo"}
48
49
  }
49
50
  }),
50
51
  )
@@ -264,14 +265,9 @@ fn lanea_fork_agent_unknown_source_is_unknown_worker_before_session_check() {
264
265
  fn lanea_fork_agent_duplicate_target_is_already_exists_before_session_check() {
265
266
  let ws = lanea_team_ws("stopped");
266
267
  // target 'bravo' already exists in the spec -> duplicate; source 'alpha' exists (its session_id is irrelevant).
267
- let text = format!(
268
- "{:?}",
269
- fork_agent(&ws, &aid("alpha"), &aid("bravo"), None, false, None)
270
- );
271
- assert!(
272
- text.contains("unverified") || text.contains("未验证") || text.contains("refuses --as"),
273
- "codex fork is unverified in-window; duplicate --as is not reached. got {text}"
274
- );
268
+ // The legacy fork entry refuses the fake source as unverified; duplicate --as is not reached.
269
+ let result = fork_agent(&ws, &aid("alpha"), &aid("bravo"), None, false, None);
270
+ assert_legacy_fork_unverified(&result, "fake");
275
271
  }
276
272
 
277
273
  // SEAM-GATED real-machine boundary (note to porter): stop_agent / reset_agent / fork_agent must drive a
@@ -320,7 +316,7 @@ fn add_agent_joins_w2_into_running_roster_and_existing_session() {
320
316
  workspace,
321
317
  &json!({
322
318
  "session_name": "team-implteam",
323
- "agents": {"w1": {"status": "running", "provider": "codex", "window": "w1"}}
319
+ "agents": {"w1": {"status": "running", "provider": "fake", "window": "w1"}}
324
320
  }),
325
321
  )
326
322
  .unwrap();
@@ -329,7 +325,7 @@ fn add_agent_joins_w2_into_running_roster_and_existing_session() {
329
325
  let role_file = team_dir.join("w2-role.md");
330
326
  std::fs::write(
331
327
  &role_file,
332
- "---\nname: w2\nrole: Worker Two\nprovider: codex\nmodel: gpt-5.5\nauth_mode: subscription\ndangerously_skip_permissions: false\ntools:\n - mcp_team\n---\n\nWorker two.\n",
328
+ "---\nname: w2\nrole: Worker Two\nprovider: fake\nmodel: fake\nauth_mode: subscription\ndangerously_skip_permissions: false\ntools:\n - mcp_team\n---\n\nWorker two.\n",
333
329
  )
334
330
  .unwrap();
335
331
  let transport = OfflineTransport::new().with_session_present(true);