@team-agent/installer 0.5.126 → 0.5.128
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Cargo.lock +1 -1
- package/Cargo.toml +1 -1
- package/README.md +11 -0
- package/crates/team-agent/src/cli/adapters.rs +3 -13
- package/crates/team-agent/src/cli/arguments.rs +4 -0
- package/crates/team-agent/src/cli/diagnose.rs +68 -91
- package/crates/team-agent/src/cli/emit.rs +61 -28
- package/crates/team-agent/src/cli/grok_slot.rs +88 -3
- package/crates/team-agent/src/cli/intent/runtime.rs +38 -9
- package/crates/team-agent/src/cli/intent/runtime_tests.rs +147 -11
- package/crates/team-agent/src/cli/intent/tests.rs +10 -12
- package/crates/team-agent/src/cli/intent.rs +1 -1
- package/crates/team-agent/src/cli/mod.rs +38 -9
- package/crates/team-agent/src/cli/models.rs +789 -186
- package/crates/team-agent/src/cli/schedule.rs +175 -0
- package/crates/team-agent/src/cli/send/persist.rs +0 -36
- package/crates/team-agent/src/cli/send/presentation.rs +1 -1
- package/crates/team-agent/src/cli/send.rs +108 -110
- package/crates/team-agent/src/cli/spec.rs +6 -0
- package/crates/team-agent/src/cli/status_port/brief.rs +5 -67
- package/crates/team-agent/src/cli/tests/leader_watch.rs +12 -62
- package/crates/team-agent/src/cli/tests/mod.rs +3 -3
- package/crates/team-agent/src/cli/tests/named_address.rs +11 -10
- package/crates/team-agent/src/cli/tests/run_delegation.rs +12 -9
- package/crates/team-agent/src/cli/tests/status_send.rs +70 -273
- package/crates/team-agent/src/compiler/tests.rs +39 -27
- package/crates/team-agent/src/compiler.rs +206 -6
- package/crates/team-agent/src/contract_runtime/backend.rs +181 -11
- package/crates/team-agent/src/contract_runtime/commands.rs +338 -7
- package/crates/team-agent/src/contract_runtime/config.rs +30 -19
- package/crates/team-agent/src/contract_runtime/config_tests.rs +24 -4
- package/crates/team-agent/src/contract_runtime/discovery.rs +12 -1
- package/crates/team-agent/src/contract_runtime/fork.rs +3 -10
- package/crates/team-agent/src/contract_runtime/framework.rs +28 -14
- package/crates/team-agent/src/contract_runtime/mcp.rs +19 -24
- package/crates/team-agent/src/contract_runtime/prompt.rs +2 -2
- package/crates/team-agent/src/contract_runtime/registry.rs +93 -130
- package/crates/team-agent/src/coordinator/steps/abnormal.rs +45 -5
- package/crates/team-agent/src/coordinator/tests/api_error_recovery.rs +8 -29
- package/crates/team-agent/src/coordinator/tests/energy.rs +4 -4
- package/crates/team-agent/src/coordinator/tests/health_sync.rs +44 -2
- package/crates/team-agent/src/coordinator/tests/main_preserved.rs +2 -2
- package/crates/team-agent/src/coordinator/tests/spine.rs +1 -1
- package/crates/team-agent/src/coordinator/tests/takeover.rs +3 -3
- package/crates/team-agent/src/coordinator/tick.rs +1 -89
- package/crates/team-agent/src/db/message_store.rs +7 -65
- package/crates/team-agent/src/direct_delivery.rs +368 -0
- package/crates/team-agent/src/inbox_store.rs +169 -0
- package/crates/team-agent/src/leader/registry.rs +5 -0
- package/crates/team-agent/src/leader/start.rs +2 -1
- package/crates/team-agent/src/leader/tests/lease_api.rs +2 -2
- package/crates/team-agent/src/leader/tests/prompt_contract.rs +1 -0
- package/crates/team-agent/src/lib.rs +2 -0
- package/crates/team-agent/src/lifecycle/launch/add_agent.rs +33 -0
- package/crates/team-agent/src/lifecycle/launch/add_agent_state.rs +206 -1
- package/crates/team-agent/src/lifecycle/launch/clone_agent.rs +28 -2
- package/crates/team-agent/src/lifecycle/launch/fork_agent.rs +36 -179
- package/crates/team-agent/src/lifecycle/launch/fork_entry.rs +87 -6
- package/crates/team-agent/src/lifecycle/launch/mcp_config.rs +13 -488
- package/crates/team-agent/src/lifecycle/launch/pi_mcp.rs +351 -81
- package/crates/team-agent/src/lifecycle/launch/pi_mcp_extension.js +3 -4
- package/crates/team-agent/src/lifecycle/launch/quick_start.rs +26 -2
- package/crates/team-agent/src/lifecycle/launch/spawn.rs +41 -31
- package/crates/team-agent/src/lifecycle/launch.rs +27 -12
- package/crates/team-agent/src/lifecycle/profile_launch.rs +318 -64
- package/crates/team-agent/src/lifecycle/restart/agent.rs +1 -0
- package/crates/team-agent/src/lifecycle/restart/avatar.rs +1798 -0
- package/crates/team-agent/src/lifecycle/restart/claude_fork.rs +163 -0
- package/crates/team-agent/src/lifecycle/restart/common.rs +298 -133
- package/crates/team-agent/src/lifecycle/restart/remove.rs +129 -0
- package/crates/team-agent/src/lifecycle/restart/selection.rs +5 -5
- package/crates/team-agent/src/lifecycle/restart.rs +4 -0
- package/crates/team-agent/src/lifecycle/role_config.rs +79 -27
- package/crates/team-agent/src/lifecycle/tests/acceptance_b_batch_red.rs +1 -1
- package/crates/team-agent/src/lifecycle/tests/agent_ops.rs +8 -12
- package/crates/team-agent/src/lifecycle/tests/behavioral_diff_264_red.rs +37 -240
- package/crates/team-agent/src/lifecycle/tests/claude_compatible_config_red.rs +325 -0
- package/crates/team-agent/src/lifecycle/tests/claude_profile_launch_red.rs +320 -8
- package/crates/team-agent/src/lifecycle/tests/cli_argv_routing_red.rs +329 -70
- package/crates/team-agent/src/lifecycle/tests/clone_fork_copilot_perms_red.rs +378 -4
- package/crates/team-agent/src/lifecycle/tests/communication_mode_runtime_contract_red.rs +25 -39
- package/crates/team-agent/src/lifecycle/tests/copilot_provider_red.rs +7 -11
- package/crates/team-agent/src/lifecycle/tests/core.rs +39 -36
- package/crates/team-agent/src/lifecycle/tests/f032_startup_prompt_best_effort_red.rs +22 -8
- package/crates/team-agent/src/lifecycle/tests/fixtures/pi_native_mcp_host.mjs +2 -1
- package/crates/team-agent/src/lifecycle/tests/grok_require_explicit_model_red.rs +15 -133
- package/crates/team-agent/src/lifecycle/tests/harvest2_a_batch_red.rs +60 -20
- package/crates/team-agent/src/lifecycle/tests/host_cotenant_death_p0_contract.rs +30 -67
- package/crates/team-agent/src/lifecycle/tests/issue238_codex_effort_contract.rs +3 -31
- package/crates/team-agent/src/lifecycle/tests/lane_ops.rs +194 -169
- package/crates/team-agent/src/lifecycle/tests/launch_spawn.rs +164 -282
- package/crates/team-agent/src/lifecycle/tests/lifecycle_rollback_red.rs +15 -78
- package/crates/team-agent/src/lifecycle/tests/main_preserved.rs +7 -7
- package/crates/team-agent/src/lifecycle/tests/mcp_tool_name_format_red.rs +6 -6
- package/crates/team-agent/src/lifecycle/tests/phase_b_contracts.rs +75 -69
- package/crates/team-agent/src/lifecycle/tests/phase_golden.rs +2 -10
- package/crates/team-agent/src/lifecycle/tests/pi_catalog_red.rs +18 -6
- package/crates/team-agent/src/lifecycle/tests/pi_command_red.rs +70 -52
- package/crates/team-agent/src/lifecycle/tests/pi_compiler_red.rs +210 -0
- package/crates/team-agent/src/lifecycle/tests/pi_dual_entry_red.rs +157 -4
- package/crates/team-agent/src/lifecycle/tests/pi_executable_mcp_red.rs +526 -10
- package/crates/team-agent/src/lifecycle/tests/pi_fork_session_inheritance_red.rs +1419 -0
- package/crates/team-agent/src/lifecycle/tests/pi_lifecycle_doctor_red.rs +68 -1
- package/crates/team-agent/src/lifecycle/tests/pi_native_mcp_capability_red.rs +34 -12
- package/crates/team-agent/src/lifecycle/tests/pi_session_delivery_red.rs +94 -2
- package/crates/team-agent/src/lifecycle/tests/quick_start_worker_readiness_red.rs +14 -15
- package/crates/team-agent/src/lifecycle/tests/restart.rs +12 -153
- package/crates/team-agent/src/lifecycle/tests/restart_build_before_destroy_0540_contract.rs +27 -5
- package/crates/team-agent/src/lifecycle/tests/restart_liveness_red.rs +59 -10
- package/crates/team-agent/src/lifecycle/tests/restart_rebind_hotfix_252_red.rs +47 -6
- package/crates/team-agent/src/lifecycle/tests/restart_session_capture_red.rs +3 -1374
- package/crates/team-agent/src/lifecycle/tests/resume_recover_red.rs +27 -10
- package/crates/team-agent/src/lifecycle/tests/status_credential_redaction_contract.rs +7 -7
- package/crates/team-agent/src/lifecycle/tests/subprep_codex_trust_roundtrip_red.rs +67 -313
- package/crates/team-agent/src/lifecycle/tests/swallow_batch4_semantics_red.rs +254 -2
- package/crates/team-agent/src/lifecycle/tests/team_in_team_identity_scope_red.rs +2 -2
- package/crates/team-agent/src/lifecycle/tests/team_in_team_sibling_quick_start_red.rs +1 -1
- package/crates/team-agent/src/lifecycle/tests/team_in_team_state_scope_red.rs +2 -2
- package/crates/team-agent/src/lifecycle/tests/team_key_retirement_txn_red.rs +4 -4
- package/crates/team-agent/src/lifecycle/tests/upgrade_compat_0211_red.rs +74 -19
- package/crates/team-agent/src/lifecycle/tests/verify_rs031_window_consistency_red.rs +38 -39
- package/crates/team-agent/src/lifecycle/tests/worker_spawn_env_red.rs +51 -88
- package/crates/team-agent/src/lifecycle/tests.rs +3 -4
- package/crates/team-agent/src/lifecycle/types.rs +18 -5
- package/crates/team-agent/src/lifecycle/worker_command_context.rs +43 -50
- package/crates/team-agent/src/mcp_server/readiness.rs +130 -149
- package/crates/team-agent/src/mcp_server/readiness_tests.rs +86 -109
- package/crates/team-agent/src/mcp_server/tests/scoped.rs +21 -31
- package/crates/team-agent/src/mcp_server/tests/send.rs +72 -107
- package/crates/team-agent/src/mcp_server/tests/tools.rs +10 -12
- package/crates/team-agent/src/mcp_server/tools.rs +70 -196
- package/crates/team-agent/src/messaging/delivery.rs +143 -253
- package/crates/team-agent/src/messaging/delivery_consumption_tests.rs +5 -5
- package/crates/team-agent/src/messaging/helpers.rs +1 -19
- package/crates/team-agent/src/messaging/mod.rs +1 -0
- package/crates/team-agent/src/messaging/reminders.rs +316 -0
- package/crates/team-agent/src/messaging/scheduler.rs +7 -1
- package/crates/team-agent/src/messaging/tests/dup_inject.rs +255 -150
- package/crates/team-agent/src/messaging/tests/main_preserved.rs +2 -2
- package/crates/team-agent/src/messaging/tests/runtime.rs +9 -115
- package/crates/team-agent/src/messaging/tests/spine.rs +44 -24
- package/crates/team-agent/src/messaging/tests/wave2.rs +13 -20
- package/crates/team-agent/src/messaging/types.rs +1 -0
- package/crates/team-agent/src/provider/adapter.rs +208 -254
- package/crates/team-agent/src/provider/adapters/claude.rs +78 -0
- package/crates/team-agent/src/provider/adapters/claude_fork.rs +131 -0
- package/crates/team-agent/src/provider/adapters/mod.rs +7 -7
- package/crates/team-agent/src/provider/adapters/pi.rs +106 -0
- package/crates/team-agent/src/provider/classify.rs +1 -66
- package/crates/team-agent/src/provider/model_catalog.rs +201 -13
- package/crates/team-agent/src/provider/session/capture.rs +111 -111
- package/crates/team-agent/src/provider/session/context_fork/claude.rs +123 -0
- package/crates/team-agent/src/provider/session/context_fork/outcome.rs +10 -18
- package/crates/team-agent/src/provider/session/context_fork.rs +87 -74
- package/crates/team-agent/src/provider/session/mod.rs +2 -3
- package/crates/team-agent/src/provider/session_scan/claude.rs +523 -0
- package/crates/team-agent/src/provider/session_scan/common.rs +47 -47
- package/crates/team-agent/src/provider/session_scan/pi.rs +34 -1
- package/crates/team-agent/src/provider/session_scan.rs +13 -13
- package/crates/team-agent/src/provider/tests/adapter.rs +127 -121
- package/crates/team-agent/src/provider/tests/classify.rs +0 -53
- package/crates/team-agent/src/provider/tests/command_helpers.rs +11 -19
- package/crates/team-agent/src/provider/tests/idle.rs +13 -19
- package/crates/team-agent/src/provider/types.rs +0 -4
- package/crates/team-agent/src/provider/wire.rs +34 -20
- package/crates/team-agent/src/state/abnormal_watch/tests/mod.rs +1 -1
- package/crates/team-agent/src/state/persist.rs +6 -6
- package/crates/team-agent/src/state/projection.rs +1 -1
- package/crates/team-agent/src/state/repository/tests.rs +2 -2
- package/crates/team-agent/src/test_support/models_timeout_fixture.rs +144 -0
- package/crates/team-agent/src/tmux_backend/tests.rs +0 -151
- package/crates/team-agent/src/tmux_backend.rs +9 -43
- package/package.json +4 -4
- package/skills/team-agent/SKILL.md +7 -8
- package/skills/team-agent/command-coverage.json +15 -1
- package/skills/team-agent/docs/reference/team-agent-operator.md +5 -3
- package/skills/team-agent/references/team-agent-operator.md +5 -3
- package/crates/team-agent/src/lifecycle/launch/grok_per_seat.rs +0 -260
- package/crates/team-agent/src/lifecycle/tests/codex_weak_window_attribution_red.rs +0 -683
- package/crates/team-agent/src/lifecycle/tests/grok_effort_argv_red.rs +0 -247
- package/crates/team-agent/src/lifecycle/tests/grok_mcp_overlay_red.rs +0 -507
- package/crates/team-agent/src/lifecycle/tests/grok_restart_resume_red.rs +0 -300
- package/crates/team-agent/src/provider/adapters/codex.rs +0 -101
- package/crates/team-agent/src/provider/adapters/grok.rs +0 -67
- package/crates/team-agent/src/provider/session/context_fork/codex.rs +0 -514
- package/crates/team-agent/src/provider/session_scan/codex.rs +0 -326
- package/crates/team-agent/src/provider/session_scan/grok.rs +0 -288
|
@@ -171,7 +171,7 @@ fn same_provider(left: &str, right: &str) -> bool {
|
|
|
171
171
|
crate::provider::wire::parse_provider(right),
|
|
172
172
|
) {
|
|
173
173
|
(Some(left), Some(right)) => left == right,
|
|
174
|
-
_ => left
|
|
174
|
+
_ => crate::contract_runtime::registry::same_provider(left, right),
|
|
175
175
|
}
|
|
176
176
|
}
|
|
177
177
|
fn drift(row: &Value, compiled: &Value) -> bool {
|
|
@@ -231,6 +231,7 @@ fn check_native_noop_settings(
|
|
|
231
231
|
&selected.run_workspace,
|
|
232
232
|
&selected.team_dir,
|
|
233
233
|
&selected.team_key,
|
|
234
|
+
Some(id),
|
|
234
235
|
))?
|
|
235
236
|
.ok_or_else(|| refusal("missing native configuration"))?;
|
|
236
237
|
let current = config
|
|
@@ -338,7 +339,7 @@ fn observe(selected: &SelectedTeam, id: &str, row: &Value) -> Result<Observation
|
|
|
338
339
|
))?;
|
|
339
340
|
let seat = checked(backend.store.seat(&checked(SeatId::new(id))?))?
|
|
340
341
|
.ok_or_else(|| refusal("missing canonical native seat"))?;
|
|
341
|
-
if provider(row)
|
|
342
|
+
if !same_provider(provider(row), seat.provider.as_str())
|
|
342
343
|
|| row.get("contract_scope").and_then(Value::as_str)
|
|
343
344
|
!= Some(seat.identity.scope.as_str())
|
|
344
345
|
|| row.get("contract_instance").and_then(Value::as_str)
|
|
@@ -425,7 +426,9 @@ fn observe(selected: &SelectedTeam, id: &str, row: &Value) -> Result<Observation
|
|
|
425
426
|
let command = matches[0].current_command.as_deref().unwrap_or("");
|
|
426
427
|
let positive_command = command == crate::provider::wire::command_name(native)
|
|
427
428
|
|| crate::leader::provider_attribution::command_matches_provider(native, command)
|
|
428
|
-
|
|
429
|
+
// A shell-supervised worker retains its native argv[0] in this exact
|
|
430
|
+
// pane's live process tree; shell-only/stale-screen carriers still fail.
|
|
431
|
+
|| (!command.is_empty() && launched_as_provider(pid, native));
|
|
429
432
|
let positive_surface = if !positive_command && !command.is_empty() {
|
|
430
433
|
let frame = checked(
|
|
431
434
|
backend.observe_native_input(&Target::Pane(PaneId::new(pane.unwrap_or(""))), native),
|
|
@@ -494,6 +497,18 @@ fn check_incarnation_cwd(selected: &SelectedTeam, row: &Value) -> Result<(), Cli
|
|
|
494
497
|
}
|
|
495
498
|
Ok(())
|
|
496
499
|
}
|
|
500
|
+
fn admit_seat_preflight(plan: &mut Plan, id: &str, team: bool, result: Result<(), CliError>) -> Result<bool, CliError> {
|
|
501
|
+
match result {
|
|
502
|
+
Ok(()) => Ok(true),
|
|
503
|
+
Err(error) if team && plan.intent.verb == Verb::Start => {
|
|
504
|
+
plan.skipped.push(json!({"agent":id,"reason":"preflight_blocked",
|
|
505
|
+
"error":crate::redaction::redact_external_text(&error.to_string())}));
|
|
506
|
+
Ok(false)
|
|
507
|
+
}
|
|
508
|
+
Err(error) => Err(error),
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
|
|
497
512
|
fn preflight_start(
|
|
498
513
|
selected: &SelectedTeam,
|
|
499
514
|
id: &str,
|
|
@@ -506,6 +521,7 @@ fn preflight_start(
|
|
|
506
521
|
&selected.run_workspace,
|
|
507
522
|
&selected.team_dir,
|
|
508
523
|
&selected.team_key,
|
|
524
|
+
Some(id),
|
|
509
525
|
))?
|
|
510
526
|
.ok_or_else(|| refusal("missing native role config"))?;
|
|
511
527
|
let role = config
|
|
@@ -609,15 +625,17 @@ fn add(
|
|
|
609
625
|
id: &str,
|
|
610
626
|
source: Option<PathBuf>,
|
|
611
627
|
) -> Result<(), CliError> {
|
|
628
|
+
// An explicit start re-admits a removed seat: the add consumes its retired
|
|
629
|
+
// tombstone. Only lifecycle history this planner cannot classify is refused.
|
|
612
630
|
if selected
|
|
613
631
|
.state
|
|
614
632
|
.get("agent_lifecycle")
|
|
615
633
|
.and_then(|lifecycle| lifecycle.get(id))
|
|
616
|
-
.
|
|
634
|
+
.is_some_and(|entry| entry.get("state").and_then(Value::as_str) != Some("retired"))
|
|
617
635
|
{
|
|
618
|
-
return Err(refusal(
|
|
619
|
-
"agent
|
|
620
|
-
));
|
|
636
|
+
return Err(refusal(format!(
|
|
637
|
+
"agent {id} has unrecognized lifecycle history; refusing to re-admit it"
|
|
638
|
+
)));
|
|
621
639
|
}
|
|
622
640
|
let patch = plan.intent.patch.clone();
|
|
623
641
|
let role_file = match source {
|
|
@@ -935,6 +953,11 @@ fn plan_with_observer(
|
|
|
935
953
|
let p = selected.team_dir.join("agents").join(format!("{id}.md"));
|
|
936
954
|
p.is_file().then_some(p)
|
|
937
955
|
});
|
|
956
|
+
let admission = checked(crate::contract_runtime::framework::team_config(
|
|
957
|
+
&selected.run_workspace, &selected.team_dir, &selected.team_key, Some(&id))).map(|_| ());
|
|
958
|
+
if !admit_seat_preflight(&mut plan, &id, team, admission)? {
|
|
959
|
+
continue;
|
|
960
|
+
}
|
|
938
961
|
add(&mut plan, &selected, &id, source)?;
|
|
939
962
|
continue;
|
|
940
963
|
};
|
|
@@ -966,7 +989,10 @@ fn plan_with_observer(
|
|
|
966
989
|
if actions.is_empty() {
|
|
967
990
|
if obs == Observation::Live && plan.intent.verb == Verb::Start {
|
|
968
991
|
let (_, compiled) = role(&mut plan, &selected, &id, None)?;
|
|
969
|
-
check_native_noop_settings(&selected, &id, row)
|
|
992
|
+
let admission = check_native_noop_settings(&selected, &id, row);
|
|
993
|
+
if !admit_seat_preflight(&mut plan, &id, team, admission)? {
|
|
994
|
+
continue;
|
|
995
|
+
}
|
|
970
996
|
if drift(row, &compiled) {
|
|
971
997
|
return Err(refusal(format!(
|
|
972
998
|
"known launch configuration drift for running {id}; stop before applying"
|
|
@@ -980,7 +1006,10 @@ fn plan_with_observer(
|
|
|
980
1006
|
if !same_provider(provider(row), provider(&compiled)) {
|
|
981
1007
|
return Err(refusal("registered provider cannot change"));
|
|
982
1008
|
}
|
|
983
|
-
preflight_start(&selected, &id, row, plan.intent.session)
|
|
1009
|
+
let admission = preflight_start(&selected, &id, row, plan.intent.session);
|
|
1010
|
+
if !admit_seat_preflight(&mut plan, &id, team, admission)? {
|
|
1011
|
+
continue;
|
|
1012
|
+
}
|
|
984
1013
|
}
|
|
985
1014
|
for action in actions {
|
|
986
1015
|
match action {
|
|
@@ -20,10 +20,10 @@ fn fixture(ids: &[&str]) -> (Sandbox, Intent) {
|
|
|
20
20
|
(root, intent)
|
|
21
21
|
}
|
|
22
22
|
fn write_role(root: &Path, id: &str) {
|
|
23
|
-
std::fs::write(root.join("agents").join(format!("{id}.md")),format!("---\nname: {id}\nprovider:
|
|
23
|
+
std::fs::write(root.join("agents").join(format!("{id}.md")),format!("---\nname: {id}\nprovider: pi\nmodel: openai-codex/gpt-6-luna\neffort: max\ndangerously_skip_permissions: true\n---\nFixture\n")).unwrap();
|
|
24
24
|
}
|
|
25
25
|
fn install(root: &Path, ids: &[(&str, &str, bool)]) {
|
|
26
|
-
let agents:serde_json::Map<String,Value>=ids.iter().map(|(id,status,explicit)|((*id).into(),json!({"provider":"
|
|
26
|
+
let agents:serde_json::Map<String,Value>=ids.iter().map(|(id,status,explicit)|((*id).into(),json!({"provider":"pi","status":status,"explicit_stop":explicit,"pane_pid":std::process::id(),"pane_id":format!("%{id}"),"window":id}))).collect();
|
|
27
27
|
let entry = json!({"team_key":"fixture","team_dir":root,"status":"alive","session_name":"team-fixture","agents":agents,"tasks":{}});
|
|
28
28
|
let mut raw = entry.clone();
|
|
29
29
|
raw["active_team_key"] = json!("fixture");
|
|
@@ -42,6 +42,33 @@ fn install(root: &Path, ids: &[(&str, &str, bool)]) {
|
|
|
42
42
|
fn actions(plan: &Plan) -> Vec<(&str, Option<&str>)> {
|
|
43
43
|
plan.steps.iter().map(|s| (s.name(), s.agent())).collect()
|
|
44
44
|
}
|
|
45
|
+
#[test]
|
|
46
|
+
fn owned_native_reconciliation_still_allows_the_original_fenced_stop() {
|
|
47
|
+
assert_eq!(seat_actions(Verb::Stop, Observation::NativeReconcile, false, false, false, false).unwrap(), ["stop"]);
|
|
48
|
+
assert!(seat_actions(Verb::Stop, Observation::Unknown, false, false, false, false).is_err());
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
#[test]
|
|
52
|
+
#[serial_test::serial(env)]
|
|
53
|
+
fn team_start_skips_bad_native_preflight_but_explicit_target_still_refuses() {
|
|
54
|
+
let (root, intent) = fixture(&["healthy", "invalid"]);
|
|
55
|
+
std::fs::write(root.path().join("agents/invalid.md"),
|
|
56
|
+
"---\nprovider: codex\nmodel: native-model\nprofile: codex-default\n---\nInvalid native profile\n").unwrap();
|
|
57
|
+
install(root.path(), &[("healthy", "stopped", true), ("invalid", "stopped", true)]);
|
|
58
|
+
let state = crate::state::persist::runtime_state_path(root.path());
|
|
59
|
+
let mut raw: Value = serde_json::from_slice(&std::fs::read(&state).unwrap()).unwrap();
|
|
60
|
+
raw["teams"]["fixture"]["agents"]["invalid"]["provider"] = json!("codex_tui");
|
|
61
|
+
std::fs::write(&state, serde_json::to_vec(&raw).unwrap()).unwrap();
|
|
62
|
+
let before = std::fs::read(&state).unwrap();
|
|
63
|
+
let plan = plan_with_observer(intent.clone(), |_, _, _| Ok(Observation::StoppedVerified)).unwrap();
|
|
64
|
+
assert_eq!(actions(&plan), [("start_agent", Some("healthy"))]);
|
|
65
|
+
assert!(plan.skipped.iter().any(|entry| entry["agent"] == "invalid" && entry["reason"] == "preflight_blocked"));
|
|
66
|
+
let mut single = intent;
|
|
67
|
+
single.subject = Subject::Agent("invalid".into());
|
|
68
|
+
assert!(plan_with_observer(single, |_, _, _| Ok(Observation::StoppedVerified)).is_err());
|
|
69
|
+
assert_eq!(std::fs::read(&state).unwrap(), before);
|
|
70
|
+
}
|
|
71
|
+
|
|
45
72
|
#[test]
|
|
46
73
|
#[serial_test::serial(env)]
|
|
47
74
|
fn absent_source_is_one_original_create_not_restart_or_probe() {
|
|
@@ -336,6 +363,51 @@ fn role_only_add_and_absent_creation_need_explicit_decisions() {
|
|
|
336
363
|
}
|
|
337
364
|
#[test]
|
|
338
365
|
#[serial_test::serial(env)]
|
|
366
|
+
fn issue391_start_readmits_a_removed_seat_from_its_left_behind_role_file() {
|
|
367
|
+
let (root, mut intent) = fixture(&["one"]);
|
|
368
|
+
install(root.path(), &[("one", "stopped", false)]);
|
|
369
|
+
// remove-agent keeps the user's role file and leaves a retired tombstone.
|
|
370
|
+
write_role(root.path(), "two");
|
|
371
|
+
let state = crate::state::persist::runtime_state_path(root.path());
|
|
372
|
+
let mut raw: Value = serde_json::from_slice(&std::fs::read(&state).unwrap()).unwrap();
|
|
373
|
+
let tombstone = json!({"two": {"state": "retired", "changed_at": "2026-10-27T15:25:48Z", "reason": "remove-agent"}});
|
|
374
|
+
raw["agent_lifecycle"] = tombstone.clone();
|
|
375
|
+
raw["teams"]["fixture"]["agent_lifecycle"] = tombstone;
|
|
376
|
+
std::fs::write(&state, serde_json::to_vec(&raw).unwrap()).unwrap();
|
|
377
|
+
intent.subject = Subject::Agent(AgentId::new("two"));
|
|
378
|
+
let plan = plan_with_observer(intent.clone(), |_, _, _| panic!("unregistered probe")).unwrap();
|
|
379
|
+
assert_eq!(actions(&plan), [("add_agent", Some("two"))]);
|
|
380
|
+
let Step::AddAgent(args) = &plan.steps[0] else {
|
|
381
|
+
panic!()
|
|
382
|
+
};
|
|
383
|
+
assert_eq!(
|
|
384
|
+
Path::new(&args.role_file),
|
|
385
|
+
root.path().join("agents/two.md"),
|
|
386
|
+
"the left-behind role file is the seat's definition"
|
|
387
|
+
);
|
|
388
|
+
// Team start still leaves a removed seat retired.
|
|
389
|
+
let mut team = intent.clone();
|
|
390
|
+
team.subject = Subject::Team { source: None };
|
|
391
|
+
let plan = plan_with_observer(team, |_, _, _| Ok(Observation::StoppedVerified)).unwrap();
|
|
392
|
+
assert_eq!(actions(&plan), [("start_agent", Some("one"))]);
|
|
393
|
+
assert!(plan
|
|
394
|
+
.skipped
|
|
395
|
+
.iter()
|
|
396
|
+
.any(|entry| entry["agent"] == "two" && entry["reason"] == "retired"));
|
|
397
|
+
// History the planner cannot classify is refused without naming a phantom command.
|
|
398
|
+
raw["agent_lifecycle"]["two"]["state"] = json!("quarantined");
|
|
399
|
+
raw["teams"]["fixture"]["agent_lifecycle"]["two"]["state"] = json!("quarantined");
|
|
400
|
+
std::fs::write(&state, serde_json::to_vec(&raw).unwrap()).unwrap();
|
|
401
|
+
let error = plan_with_observer(intent, |_, _, _| panic!())
|
|
402
|
+
.unwrap_err()
|
|
403
|
+
.to_string();
|
|
404
|
+
assert!(
|
|
405
|
+
error.contains("unrecognized lifecycle history") && !error.contains("recovery"),
|
|
406
|
+
"{error}"
|
|
407
|
+
);
|
|
408
|
+
}
|
|
409
|
+
#[test]
|
|
410
|
+
#[serial_test::serial(env)]
|
|
339
411
|
fn spec_only_state_only_and_missing_spec_do_not_fallback_to_creation() {
|
|
340
412
|
let (root, mut intent) = fixture(&["one", "two"]);
|
|
341
413
|
install(root.path(), &[("one", "stopped", false)]);
|
|
@@ -427,14 +499,14 @@ fn preserve_rejects_known_missing_backing_before_stop_auto_uses_existing_decisio
|
|
|
427
499
|
let selected =
|
|
428
500
|
resolve_active_team_readonly(root.path(), Some("fixture"), SelectorMode::RuntimeOnly)
|
|
429
501
|
.unwrap();
|
|
430
|
-
let row = json!({"provider":"
|
|
502
|
+
let row = json!({"provider":"pi","session_id":"missing-session","rollout_path":root.path().join("missing.jsonl"),"spawn_cwd":root.path()});
|
|
431
503
|
assert!(preflight_start(&selected, "one", &row, SessionPolicy::Preserve).is_err());
|
|
432
504
|
assert!(preflight_start(&selected, "one", &row, SessionPolicy::Auto).is_ok());
|
|
433
505
|
assert!(
|
|
434
506
|
preflight_start(
|
|
435
507
|
&selected,
|
|
436
508
|
"one",
|
|
437
|
-
&json!({"provider":"
|
|
509
|
+
&json!({"provider":"pi"}),
|
|
438
510
|
SessionPolicy::Preserve
|
|
439
511
|
)
|
|
440
512
|
.is_ok(),
|
|
@@ -488,7 +560,7 @@ fn stopped_text_without_physical_identity_is_unknown_and_standalone_source_keeps
|
|
|
488
560
|
observe(
|
|
489
561
|
&selected,
|
|
490
562
|
"one",
|
|
491
|
-
&json!({"status":"stopped","provider":"
|
|
563
|
+
&json!({"status":"stopped","provider":"pi"})
|
|
492
564
|
)
|
|
493
565
|
.unwrap(),
|
|
494
566
|
Observation::Unknown
|
|
@@ -497,7 +569,7 @@ fn stopped_text_without_physical_identity_is_unknown_and_standalone_source_keeps
|
|
|
497
569
|
observe(
|
|
498
570
|
&selected,
|
|
499
571
|
"one",
|
|
500
|
-
&json!({"status":"stopped","provider":"
|
|
572
|
+
&json!({"status":"stopped","provider":"pi","pane_pid":std::process::id()})
|
|
501
573
|
)
|
|
502
574
|
.unwrap(),
|
|
503
575
|
Observation::Unknown
|
|
@@ -521,11 +593,75 @@ fn stopped_text_without_physical_identity_is_unknown_and_standalone_source_keeps
|
|
|
521
593
|
);
|
|
522
594
|
}
|
|
523
595
|
|
|
596
|
+
#[test]
|
|
597
|
+
#[cfg(unix)]
|
|
598
|
+
#[serial_test::serial(env)]
|
|
599
|
+
fn shell_supervised_claude_is_live_for_both_team_start_spellings() {
|
|
600
|
+
use std::process::Command;
|
|
601
|
+
use std::time::{Duration, Instant};
|
|
602
|
+
let (root, _) = fixture(&["one"]);
|
|
603
|
+
std::fs::write(root.path().join("agents/one.md"),
|
|
604
|
+
"---\nprovider: claude\nmodel: claude-opus-4.6\n---\nFixture\n").unwrap();
|
|
605
|
+
install(root.path(), &[("one", "running", false)]);
|
|
606
|
+
let sleep = Command::new("which").arg("sleep").output().unwrap();
|
|
607
|
+
assert!(sleep.status.success());
|
|
608
|
+
std::os::unix::fs::symlink(String::from_utf8(sleep.stdout).unwrap().trim(), root.path().join("claude")).unwrap();
|
|
609
|
+
let socket = root.path().join("t.sock");
|
|
610
|
+
struct Server(std::path::PathBuf);
|
|
611
|
+
impl Drop for Server {
|
|
612
|
+
fn drop(&mut self) { let _ = Command::new("tmux").arg("-S").arg(&self.0).arg("kill-server").output(); }
|
|
613
|
+
}
|
|
614
|
+
let _server = Server(socket.clone());
|
|
615
|
+
let output = Command::new("tmux").arg("-S").arg(&socket)
|
|
616
|
+
.args(["new-session", "-d", "-P", "-F", "#{pane_id} #{pane_pid}", "-s", "team-fixture", "-n", "one"])
|
|
617
|
+
.arg(format!("sh -c '{} 60 & wait'", root.path().join("claude").display()))
|
|
618
|
+
.output().unwrap();
|
|
619
|
+
assert!(output.status.success(), "{}", String::from_utf8_lossy(&output.stderr));
|
|
620
|
+
let pane = String::from_utf8(output.stdout).unwrap();
|
|
621
|
+
let fields: Vec<_> = pane.split_whitespace().collect();
|
|
622
|
+
let pid: u32 = fields[1].parse().unwrap();
|
|
623
|
+
let deadline = Instant::now() + Duration::from_secs(5);
|
|
624
|
+
while !launched_as_provider(pid, crate::provider::Provider::Claude) {
|
|
625
|
+
assert!(Instant::now() < deadline, "controlled Claude child did not start");
|
|
626
|
+
std::thread::sleep(Duration::from_millis(20));
|
|
627
|
+
}
|
|
628
|
+
let state = crate::state::persist::runtime_state_path(root.path());
|
|
629
|
+
let mut raw: Value = serde_json::from_slice(&std::fs::read(&state).unwrap()).unwrap();
|
|
630
|
+
raw["tmux_socket"] = json!(socket);
|
|
631
|
+
raw["teams"]["fixture"]["tmux_socket"] = json!(socket);
|
|
632
|
+
raw["teams"]["fixture"]["generation"] = json!("fixture-generation");
|
|
633
|
+
raw["teams"]["fixture"]["agents"]["one"] = json!({
|
|
634
|
+
"provider":"claude", "status":"running", "pane_id":fields[0], "pane_pid":pid, "window":"one"
|
|
635
|
+
});
|
|
636
|
+
std::fs::write(&state, serde_json::to_vec(&raw).unwrap()).unwrap();
|
|
637
|
+
let before = std::fs::read(&state).unwrap();
|
|
638
|
+
let selected = resolve_active_team_readonly(root.path(), Some("fixture"), SelectorMode::RuntimeOnly).unwrap();
|
|
639
|
+
let backend = crate::lifecycle::restart::lifecycle_worker_tmux_backend_selection_for_state(
|
|
640
|
+
&selected.run_workspace, &selected.state).unwrap().backend;
|
|
641
|
+
backend.set_session_owner_with_generation(&crate::transport::SessionName::new("team-fixture"),
|
|
642
|
+
&selected.run_workspace, "fixture", "fixture-generation").unwrap();
|
|
643
|
+
let row = &selected.state["agents"]["one"];
|
|
644
|
+
assert_eq!(observe(&selected, "one", row).unwrap(), Observation::Live);
|
|
645
|
+
for (command, values) in [
|
|
646
|
+
("team", vec!["start".into(), root.path().to_string_lossy().into_owned(), "--dry-run".into(), "--json".into()]),
|
|
647
|
+
("start", vec!["--team".into(), "fixture".into(), "--dry-run".into(), "--json".into()]),
|
|
648
|
+
] {
|
|
649
|
+
let output = super::super::run(command, &values, root.path()).unwrap().unwrap();
|
|
650
|
+
let CmdOutput::Json(value) = output.output else { panic!() };
|
|
651
|
+
assert_eq!(value["ok"], true, "{value}");
|
|
652
|
+
assert!(value["skipped"].as_array().unwrap().iter().any(|row| row["reason"] == "already_running"), "{value}");
|
|
653
|
+
}
|
|
654
|
+
let mut wrong = row.clone();
|
|
655
|
+
wrong["provider"] = json!("copilot");
|
|
656
|
+
assert_eq!(observe(&selected, "one", &wrong).unwrap(), Observation::Unknown);
|
|
657
|
+
assert_eq!(std::fs::read(state).unwrap(), before);
|
|
658
|
+
}
|
|
659
|
+
|
|
524
660
|
#[test]
|
|
525
661
|
fn declared_provider_aliases_do_not_create_false_drift_or_absorb_native_routes() {
|
|
526
662
|
assert!(same_provider("claude-code", "claude_code"));
|
|
527
663
|
assert!(!same_provider("cursor", "cursor_agent"));
|
|
528
|
-
assert!(
|
|
664
|
+
assert!(same_provider("grok_build", "grok"));
|
|
529
665
|
}
|
|
530
666
|
|
|
531
667
|
#[test]
|
|
@@ -701,7 +837,7 @@ fn preserve_context_preflight_and_corrupt_metadata_refuse_before_stop() {
|
|
|
701
837
|
json!({"task_prompt_delivered":true}),
|
|
702
838
|
json!({"last_result_at":"2026-10-19T00:00:00Z"}),
|
|
703
839
|
] {
|
|
704
|
-
let mut row = json!({"provider":"
|
|
840
|
+
let mut row = json!({"provider":"pi"});
|
|
705
841
|
row.as_object_mut()
|
|
706
842
|
.unwrap()
|
|
707
843
|
.extend(signal.as_object().unwrap().clone());
|
|
@@ -716,7 +852,7 @@ fn preserve_context_preflight_and_corrupt_metadata_refuse_before_stop() {
|
|
|
716
852
|
"first_send_at",
|
|
717
853
|
"task_prompt_delivered",
|
|
718
854
|
] {
|
|
719
|
-
let mut row = json!({"provider":"
|
|
855
|
+
let mut row = json!({"provider":"pi"});
|
|
720
856
|
row[field] = json!([]);
|
|
721
857
|
for policy in [SessionPolicy::Auto, SessionPolicy::Preserve] {
|
|
722
858
|
assert!(
|
|
@@ -729,14 +865,14 @@ fn preserve_context_preflight_and_corrupt_metadata_refuse_before_stop() {
|
|
|
729
865
|
assert!(preflight_start(
|
|
730
866
|
&selected,
|
|
731
867
|
"one",
|
|
732
|
-
&json!({"provider":"
|
|
868
|
+
&json!({"provider":"pi", "spawn_cwd":outside.path()}),
|
|
733
869
|
SessionPolicy::Auto
|
|
734
870
|
)
|
|
735
871
|
.is_err());
|
|
736
872
|
assert!(preflight_start(
|
|
737
873
|
&selected,
|
|
738
874
|
"one",
|
|
739
|
-
&json!({"provider":"
|
|
875
|
+
&json!({"provider":"pi", "session_id":"captured"}),
|
|
740
876
|
SessionPolicy::Auto
|
|
741
877
|
)
|
|
742
878
|
.is_err());
|
|
@@ -26,7 +26,7 @@ impl Drop for Sandbox {
|
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
#[test]
|
|
29
|
-
fn
|
|
29
|
+
fn native_receipt_reconciliation_does_not_turn_start_into_stop_or_allow_restart() {
|
|
30
30
|
assert_eq!(
|
|
31
31
|
seat_actions(
|
|
32
32
|
Verb::Start,
|
|
@@ -39,17 +39,15 @@ fn native_receipt_reconciliation_is_start_only_not_implicit_stop_or_restart() {
|
|
|
39
39
|
.unwrap(),
|
|
40
40
|
vec!["start"]
|
|
41
41
|
);
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
.is_err());
|
|
52
|
-
}
|
|
42
|
+
assert!(seat_actions(
|
|
43
|
+
Verb::Restart,
|
|
44
|
+
Observation::NativeReconcile,
|
|
45
|
+
false,
|
|
46
|
+
false,
|
|
47
|
+
false,
|
|
48
|
+
false
|
|
49
|
+
)
|
|
50
|
+
.is_err());
|
|
53
51
|
assert!(seat_actions(
|
|
54
52
|
Verb::Restart,
|
|
55
53
|
Observation::NativeReconcile,
|
|
@@ -658,7 +658,7 @@ fn seat_actions(
|
|
|
658
658
|
"restart requires a registered, previously started agent",
|
|
659
659
|
)),
|
|
660
660
|
(Verb::Stop, Observation::StoppedVerified | Observation::Unstarted) => Ok(vec![]),
|
|
661
|
-
(Verb::Stop, Observation::Live) => Ok(vec!["stop"]),
|
|
661
|
+
(Verb::Stop, Observation::Live | Observation::NativeReconcile) => Ok(vec!["stop"]),
|
|
662
662
|
_ => Err(refusal("unsupported lifecycle observation")),
|
|
663
663
|
}
|
|
664
664
|
}
|
|
@@ -73,6 +73,7 @@ pub mod profile;
|
|
|
73
73
|
pub(crate) mod leader_prompt;
|
|
74
74
|
pub(crate) mod route;
|
|
75
75
|
pub mod send;
|
|
76
|
+
mod schedule;
|
|
76
77
|
pub(crate) mod spec;
|
|
77
78
|
pub mod status;
|
|
78
79
|
pub(crate) mod triage;
|
|
@@ -3414,6 +3415,12 @@ pub mod lifecycle_port {
|
|
|
3414
3415
|
discard_session: bool,
|
|
3415
3416
|
team: Option<&str>,
|
|
3416
3417
|
) -> Result<Value, CliError> {
|
|
3418
|
+
#[cfg(unix)]
|
|
3419
|
+
if let Some(receipt) =
|
|
3420
|
+
crate::contract_runtime::commands::reset_agent(workspace, team, agent, discard_session)?
|
|
3421
|
+
{
|
|
3422
|
+
return Ok(receipt);
|
|
3423
|
+
}
|
|
3417
3424
|
let agent_id = crate::model::ids::AgentId::new(agent);
|
|
3418
3425
|
#[cfg(unix)]
|
|
3419
3426
|
crate::contract_runtime::framework::require_legacy_lifecycle(
|
|
@@ -3551,14 +3558,30 @@ pub mod lifecycle_port {
|
|
|
3551
3558
|
"fork-agent",
|
|
3552
3559
|
)?;
|
|
3553
3560
|
match crate::lifecycle::fork_agent(workspace, &source, &dest, label, true, team) {
|
|
3554
|
-
Ok(report) =>
|
|
3555
|
-
|
|
3556
|
-
|
|
3557
|
-
|
|
3558
|
-
|
|
3559
|
-
|
|
3560
|
-
|
|
3561
|
-
|
|
3561
|
+
Ok(report) => {
|
|
3562
|
+
let mut value = json!({
|
|
3563
|
+
"ok": true,
|
|
3564
|
+
"source_agent_id": report.source_agent_id.as_str(),
|
|
3565
|
+
"new_agent_id": report.new_agent_id.as_str(),
|
|
3566
|
+
"session_id": report.session_id.as_ref().map(|session| session.as_str()),
|
|
3567
|
+
"new_session_id": report.session_id.as_ref().map(|session| session.as_str()),
|
|
3568
|
+
"backing_state": report.backing_state,
|
|
3569
|
+
});
|
|
3570
|
+
if let (Some(details), Some(object)) = (report.pi_fork, value.as_object_mut()) {
|
|
3571
|
+
object.insert("status".to_string(), json!("forked"));
|
|
3572
|
+
object.insert("target".to_string(), json!(report.new_agent_id.as_str()));
|
|
3573
|
+
object.insert(
|
|
3574
|
+
"source_session_id".to_string(),
|
|
3575
|
+
json!(details.source_session_id.as_str()),
|
|
3576
|
+
);
|
|
3577
|
+
object.insert("session_id".to_string(), json!(details.session_id.as_str()));
|
|
3578
|
+
object.insert(
|
|
3579
|
+
"backing_path".to_string(),
|
|
3580
|
+
json!(details.backing_path.0.to_string_lossy().to_string()),
|
|
3581
|
+
);
|
|
3582
|
+
}
|
|
3583
|
+
Ok(value)
|
|
3584
|
+
}
|
|
3562
3585
|
Err(e) => Ok(error_value(e)),
|
|
3563
3586
|
}
|
|
3564
3587
|
}
|
|
@@ -3602,6 +3625,12 @@ pub mod lifecycle_port {
|
|
|
3602
3625
|
force: bool,
|
|
3603
3626
|
team: Option<&str>,
|
|
3604
3627
|
) -> Result<Value, CliError> {
|
|
3628
|
+
#[cfg(unix)]
|
|
3629
|
+
if let Some(receipt) = crate::contract_runtime::commands::remove_agent(
|
|
3630
|
+
workspace, team, agent, from_spec, confirm, force,
|
|
3631
|
+
)? {
|
|
3632
|
+
return Ok(receipt);
|
|
3633
|
+
}
|
|
3605
3634
|
let agent_id = crate::model::ids::AgentId::new(agent);
|
|
3606
3635
|
#[cfg(unix)]
|
|
3607
3636
|
crate::contract_runtime::framework::require_legacy_lifecycle(
|
|
@@ -4486,7 +4515,7 @@ pub mod lifecycle_port {
|
|
|
4486
4515
|
.unwrap();
|
|
4487
4516
|
std::fs::write(
|
|
4488
4517
|
team_dir.join("agents").join("implementer.md"),
|
|
4489
|
-
"---\nname: implementer\nrole: Implementation Engineer\nprovider:
|
|
4518
|
+
"---\nname: implementer\nrole: Implementation Engineer\nprovider: fake\nmodel: fake\nauth_mode: subscription\ndangerously_skip_permissions: false\ntools:\n - mcp_team\n---\n\nImplement bounded tasks.\n",
|
|
4490
4519
|
)
|
|
4491
4520
|
.unwrap();
|
|
4492
4521
|
super::super::hermetic_test_support::seed_in_process_coordinator(&root);
|