@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.
- 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 -22
- package/crates/team-agent/src/cli/emit.rs +58 -26
- package/crates/team-agent/src/cli/intent/runtime.rs +32 -5
- package/crates/team-agent/src/cli/intent/runtime_tests.rs +102 -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 +25 -8
- package/crates/team-agent/src/cli/models.rs +764 -7
- 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 +1 -1
- package/crates/team-agent/src/cli/tests/named_address.rs +11 -10
- package/crates/team-agent/src/cli/tests/run_delegation.rs +9 -6
- package/crates/team-agent/src/cli/tests/status_send.rs +68 -271
- package/crates/team-agent/src/compiler/tests.rs +3 -18
- package/crates/team-agent/src/compiler.rs +205 -6
- package/crates/team-agent/src/contract_runtime/backend.rs +145 -11
- package/crates/team-agent/src/contract_runtime/commands.rs +7 -7
- package/crates/team-agent/src/contract_runtime/config.rs +26 -16
- 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 -11
- 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 +56 -92
- package/crates/team-agent/src/coordinator/steps/abnormal.rs +11 -11
- package/crates/team-agent/src/coordinator/tests/api_error_recovery.rs +16 -54
- package/crates/team-agent/src/coordinator/tests/health_sync.rs +42 -0
- 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 +38 -13
- package/crates/team-agent/src/lifecycle/launch/fork_entry.rs +87 -6
- package/crates/team-agent/src/lifecycle/launch/mcp_config.rs +9 -1
- 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 +24 -0
- package/crates/team-agent/src/lifecycle/launch/spawn.rs +36 -13
- package/crates/team-agent/src/lifecycle/launch.rs +24 -1
- package/crates/team-agent/src/lifecycle/profile_launch.rs +321 -11
- 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 +345 -35
- 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 +39 -14
- 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 +236 -13
- 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 +5 -4
- package/crates/team-agent/src/lifecycle/tests/copilot_provider_red.rs +7 -11
- package/crates/team-agent/src/lifecycle/tests/core.rs +47 -18
- 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 +14 -14
- package/crates/team-agent/src/lifecycle/tests/harvest2_a_batch_red.rs +60 -20
- package/crates/team-agent/src/lifecycle/tests/launch_spawn.rs +28 -26
- package/crates/team-agent/src/lifecycle/tests/mcp_tool_name_format_red.rs +6 -6
- 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 +10 -11
- package/crates/team-agent/src/lifecycle/tests/status_credential_redaction_contract.rs +2 -2
- package/crates/team-agent/src/lifecycle/tests/swallow_batch4_semantics_red.rs +254 -2
- package/crates/team-agent/src/lifecycle/tests/upgrade_compat_0211_red.rs +4 -4
- package/crates/team-agent/src/lifecycle/tests/verify_rs031_window_consistency_red.rs +5 -6
- package/crates/team-agent/src/lifecycle/tests/worker_spawn_env_red.rs +16 -7
- package/crates/team-agent/src/lifecycle/tests.rs +3 -0
- package/crates/team-agent/src/lifecycle/types.rs +18 -2
- 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 +98 -119
- 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 +160 -218
- 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 +191 -85
- package/crates/team-agent/src/messaging/tests/runtime.rs +4 -110
- package/crates/team-agent/src/messaging/tests/spine.rs +40 -24
- package/crates/team-agent/src/messaging/types.rs +1 -0
- package/crates/team-agent/src/provider/adapter.rs +303 -51
- 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 -5
- 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 +106 -6
- package/crates/team-agent/src/provider/session/context_fork/claude.rs +123 -0
- package/crates/team-agent/src/provider/session/context_fork/outcome.rs +4 -0
- package/crates/team-agent/src/provider/session/context_fork.rs +150 -18
- package/crates/team-agent/src/provider/session_scan/claude.rs +523 -0
- package/crates/team-agent/src/provider/session_scan/common.rs +44 -8
- package/crates/team-agent/src/provider/session_scan/pi.rs +34 -1
- package/crates/team-agent/src/provider/session_scan.rs +16 -6
- package/crates/team-agent/src/provider/tests/adapter.rs +104 -17
- package/crates/team-agent/src/provider/tests/classify.rs +0 -53
- package/crates/team-agent/src/provider/tests/command_helpers.rs +12 -3
- package/crates/team-agent/src/provider/tests/idle.rs +37 -0
- package/crates/team-agent/src/provider/wire.rs +22 -34
- 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 +5 -40
- package/package.json +4 -4
- package/skills/team-agent/SKILL.md +5 -7
- package/skills/team-agent/command-coverage.json +1 -1
- package/skills/team-agent/docs/reference/team-agent-operator.md +3 -3
- package/skills/team-agent/references/team-agent-operator.md +3 -3
|
@@ -2,15 +2,19 @@ use std::os::unix::fs::PermissionsExt;
|
|
|
2
2
|
use std::path::{Path, PathBuf};
|
|
3
3
|
use std::sync::atomic::{AtomicU32, Ordering};
|
|
4
4
|
|
|
5
|
+
use crate::lifecycle::launch::launch_with_transport_in_workspace;
|
|
5
6
|
use crate::lifecycle::launch::pi_mcp::{
|
|
6
7
|
PiExecutableChain, PiMaterializeRequest, PiSessionScope,
|
|
7
|
-
PiWrapperRequest, materialize_pi_plan,
|
|
8
|
+
PiWrapperRequest, materialize_pi_plan, materialize_pi_resume_plan,
|
|
8
9
|
parse_pi_list_models_table, pi_seat_paths, resolve_pi_executable_chain,
|
|
9
10
|
validate_pi_executable_chain, validate_pi_wrapper_source, write_pi_wrapper,
|
|
10
11
|
write_pi_wrapper_with_publish,
|
|
11
12
|
};
|
|
13
|
+
use crate::lifecycle::start_agent_with_transport;
|
|
12
14
|
use crate::model::enums::ProviderEffort;
|
|
13
|
-
use crate::provider::
|
|
15
|
+
use crate::provider::session_scan::{CaptureSessionContext, scan_session_candidates_once};
|
|
16
|
+
use crate::provider::{McpConfig, Provider, SessionId};
|
|
17
|
+
use crate::transport::test_support::OfflineTransport;
|
|
14
18
|
|
|
15
19
|
#[path = "../../../tests/support/hermetic.rs"]
|
|
16
20
|
mod hermetic_guard;
|
|
@@ -37,7 +41,7 @@ const PI_SYMLINK_TEST: &str = concat!(
|
|
|
37
41
|
const PI_MATERIALIZER_CHILD: &str = "TEAM_AGENT_TEST_PI_MATERIALIZER_CHILD";
|
|
38
42
|
const PI_MATERIALIZER_TEST: &str = concat!(
|
|
39
43
|
"lifecycle::tests::pi_executable_mcp_red::",
|
|
40
|
-
"
|
|
44
|
+
"pi_materializer_and_worker_routes_use_the_recorded_scope"
|
|
41
45
|
);
|
|
42
46
|
|
|
43
47
|
fn run_process_isolated(marker: &str, test_name: &str, body: impl FnOnce()) {
|
|
@@ -448,15 +452,15 @@ fn pi_wrapper_import_failure_body(hermetic: &HermeticTestEnv) {
|
|
|
448
452
|
}
|
|
449
453
|
|
|
450
454
|
#[test]
|
|
451
|
-
fn
|
|
455
|
+
fn pi_materializer_and_worker_routes_use_the_recorded_scope() {
|
|
452
456
|
run_process_isolated(PI_MATERIALIZER_CHILD, PI_MATERIALIZER_TEST, || {
|
|
453
457
|
let hermetic = HermeticTestEnv::enter("pi-materializer-scope");
|
|
454
458
|
assert_isolated_child();
|
|
455
|
-
|
|
459
|
+
pi_materializer_and_worker_routes_body(&hermetic);
|
|
456
460
|
});
|
|
457
461
|
}
|
|
458
462
|
|
|
459
|
-
fn
|
|
463
|
+
fn pi_materializer_and_worker_routes_body(hermetic: &HermeticTestEnv) {
|
|
460
464
|
let fixture_root = hermetic.root().join("materializer-fixture");
|
|
461
465
|
let bin = fixture_root.join("bin");
|
|
462
466
|
let candidate = fixture_root.join("candidate/team-agent");
|
|
@@ -491,6 +495,7 @@ fn pi_leader_materializer_body(hermetic: &HermeticTestEnv) {
|
|
|
491
495
|
team_mcp_tools: &["send_message"],
|
|
492
496
|
mcp_config: &native_config,
|
|
493
497
|
session_scope: PiSessionScope::NativeDefault,
|
|
498
|
+
session_dir: None,
|
|
494
499
|
})
|
|
495
500
|
.expect("NativeDefault materializer");
|
|
496
501
|
assert!(
|
|
@@ -511,18 +516,58 @@ fn pi_leader_materializer_body(hermetic: &HermeticTestEnv) {
|
|
|
511
516
|
}
|
|
512
517
|
|
|
513
518
|
let isolated_workspace = hermetic.workspace("isolated");
|
|
514
|
-
let isolated_paths = pi_seat_paths(&isolated_workspace, "team-a", "
|
|
515
|
-
|
|
519
|
+
let isolated_paths = pi_seat_paths(&isolated_workspace, "team-a", "worker-a");
|
|
520
|
+
assert_eq!(
|
|
521
|
+
isolated_paths.sessions.parent(),
|
|
522
|
+
Some(
|
|
523
|
+
hermetic
|
|
524
|
+
.home()
|
|
525
|
+
.canonicalize()
|
|
526
|
+
.unwrap()
|
|
527
|
+
.join(".pi/agent/sessions")
|
|
528
|
+
.as_path()
|
|
529
|
+
)
|
|
530
|
+
);
|
|
531
|
+
assert!(!isolated_paths.sessions.starts_with(&isolated_workspace));
|
|
532
|
+
assert!(isolated_paths
|
|
533
|
+
.wrapper
|
|
534
|
+
.starts_with(isolated_workspace.join(".team")));
|
|
535
|
+
assert_eq!(
|
|
536
|
+
isolated_paths.sessions,
|
|
537
|
+
pi_seat_paths(&isolated_workspace, "team-a", "worker-b").sessions
|
|
538
|
+
);
|
|
539
|
+
assert_eq!(
|
|
540
|
+
isolated_paths.sessions,
|
|
541
|
+
pi_seat_paths(&isolated_workspace, "team-b", "worker-a").sessions
|
|
542
|
+
);
|
|
543
|
+
let encoded_cwd = format!(
|
|
544
|
+
"--{}--",
|
|
545
|
+
isolated_workspace
|
|
546
|
+
.to_string_lossy()
|
|
547
|
+
.trim_start_matches('/')
|
|
548
|
+
.replace(['/', '\\', ':'], "-")
|
|
549
|
+
);
|
|
550
|
+
assert_eq!(
|
|
551
|
+
isolated_paths.sessions.file_name().unwrap(),
|
|
552
|
+
encoded_cwd.as_str()
|
|
553
|
+
);
|
|
554
|
+
assert_ne!(
|
|
555
|
+
isolated_paths.sessions,
|
|
556
|
+
pi_seat_paths(&native_workspace, "team-a", "worker-a").sessions
|
|
557
|
+
);
|
|
558
|
+
assert!(!isolated_paths.runtime_root.join("sessions").exists());
|
|
559
|
+
let isolated_config = mcp_config(&candidate, &isolated_workspace, "worker-a");
|
|
516
560
|
let isolated = materialize_pi_plan(PiMaterializeRequest {
|
|
517
561
|
workspace: &isolated_workspace,
|
|
518
562
|
team_id: "team-a",
|
|
519
|
-
agent_id: "
|
|
563
|
+
agent_id: "worker-a",
|
|
520
564
|
model: Some("team-agent/qwen3.8-27b"),
|
|
521
565
|
effort: Some(ProviderEffort::Medium),
|
|
522
|
-
system_prompt: "isolated
|
|
566
|
+
system_prompt: "isolated worker fixture",
|
|
523
567
|
team_mcp_tools: &["send_message"],
|
|
524
568
|
mcp_config: &isolated_config,
|
|
525
569
|
session_scope: PiSessionScope::Isolated,
|
|
570
|
+
session_dir: None,
|
|
526
571
|
})
|
|
527
572
|
.expect("Isolated materializer");
|
|
528
573
|
assert_eq!(
|
|
@@ -531,8 +576,467 @@ fn pi_leader_materializer_body(hermetic: &HermeticTestEnv) {
|
|
|
531
576
|
);
|
|
532
577
|
assert_eq!(isolated.argv.first().map(String::as_str), Some("pi"));
|
|
533
578
|
assert_session_pair(&isolated.argv, &isolated_paths.sessions);
|
|
579
|
+
let fresh_id = isolated
|
|
580
|
+
.expected_session_id
|
|
581
|
+
.as_ref()
|
|
582
|
+
.expect("native UUID selector");
|
|
583
|
+
assert!(isolated
|
|
584
|
+
.argv
|
|
585
|
+
.windows(2)
|
|
586
|
+
.any(|pair| pair == ["--session-id", fresh_id.as_str()]));
|
|
534
587
|
assert!(!isolated.argv.iter().any(|arg| arg == "--cwd"));
|
|
535
588
|
assert!(!isolated.argv.iter().any(|arg| arg == "--workspace"));
|
|
589
|
+
|
|
590
|
+
let session_id = SessionId::new("pi-materializer-resume");
|
|
591
|
+
let exact = isolated_paths.sessions.join("2026/09/exact.jsonl");
|
|
592
|
+
std::fs::create_dir_all(exact.parent().expect("exact session parent"))
|
|
593
|
+
.expect("create exact session parent");
|
|
594
|
+
write_pi_session_header(
|
|
595
|
+
&exact,
|
|
596
|
+
session_id.as_str(),
|
|
597
|
+
&isolated_workspace,
|
|
598
|
+
"2026-09-01T00:00:01Z",
|
|
599
|
+
);
|
|
600
|
+
let resumed = materialize_pi_resume_plan(
|
|
601
|
+
PiMaterializeRequest {
|
|
602
|
+
workspace: &isolated_workspace,
|
|
603
|
+
team_id: "team-a",
|
|
604
|
+
agent_id: "worker-a",
|
|
605
|
+
model: None,
|
|
606
|
+
effort: None,
|
|
607
|
+
system_prompt: "isolated resume fixture",
|
|
608
|
+
team_mcp_tools: &["send_message"],
|
|
609
|
+
mcp_config: &isolated_config,
|
|
610
|
+
session_scope: PiSessionScope::Isolated,
|
|
611
|
+
session_dir: None,
|
|
612
|
+
},
|
|
613
|
+
&session_id,
|
|
614
|
+
&exact,
|
|
615
|
+
&isolated_workspace,
|
|
616
|
+
)
|
|
617
|
+
.expect("Isolated exact-path resume materializer");
|
|
618
|
+
assert_eq!(
|
|
619
|
+
resumed.provider_projects_root.as_deref(),
|
|
620
|
+
Some(isolated_paths.sessions.as_path())
|
|
621
|
+
);
|
|
622
|
+
assert_eq!(resumed.argv.first().map(String::as_str), Some("pi"));
|
|
623
|
+
assert_session_pair(&resumed.argv, &isolated_paths.sessions);
|
|
624
|
+
assert!(
|
|
625
|
+
resumed
|
|
626
|
+
.argv
|
|
627
|
+
.windows(2)
|
|
628
|
+
.any(|pair| { pair == ["--session", exact.to_string_lossy().as_ref()] })
|
|
629
|
+
);
|
|
630
|
+
|
|
631
|
+
// Existing installations keep their exact backing; changing the native
|
|
632
|
+
// home must not force a new session or strand previously captured seats.
|
|
633
|
+
let legacy_root = isolated_paths.runtime_root.join("sessions");
|
|
634
|
+
let legacy_exact = legacy_root.join("legacy.jsonl");
|
|
635
|
+
std::fs::create_dir_all(&legacy_root).unwrap();
|
|
636
|
+
write_pi_session_header(
|
|
637
|
+
&legacy_exact,
|
|
638
|
+
session_id.as_str(),
|
|
639
|
+
&isolated_workspace,
|
|
640
|
+
"2026-09-01T00:00:01Z",
|
|
641
|
+
);
|
|
642
|
+
{
|
|
643
|
+
let _override = hermetic.with_env("PI_CODING_AGENT_DIR", "~/custom-pi");
|
|
644
|
+
let customized = pi_seat_paths(&isolated_workspace, "team-a", "worker-a");
|
|
645
|
+
assert_eq!(
|
|
646
|
+
customized.sessions.parent(),
|
|
647
|
+
Some(
|
|
648
|
+
hermetic
|
|
649
|
+
.home()
|
|
650
|
+
.canonicalize()
|
|
651
|
+
.unwrap()
|
|
652
|
+
.join("custom-pi/sessions")
|
|
653
|
+
.as_path()
|
|
654
|
+
)
|
|
655
|
+
);
|
|
656
|
+
assert_eq!(
|
|
657
|
+
customized.sessions.file_name(),
|
|
658
|
+
isolated_paths.sessions.file_name()
|
|
659
|
+
);
|
|
660
|
+
for (path, root) in [
|
|
661
|
+
(&exact, &isolated_paths.sessions),
|
|
662
|
+
(&legacy_exact, &legacy_root),
|
|
663
|
+
] {
|
|
664
|
+
let resumed = materialize_pi_resume_plan(
|
|
665
|
+
PiMaterializeRequest {
|
|
666
|
+
workspace: &isolated_workspace,
|
|
667
|
+
team_id: "team-a",
|
|
668
|
+
agent_id: "worker-a",
|
|
669
|
+
model: None,
|
|
670
|
+
effort: None,
|
|
671
|
+
system_prompt: "retained backing",
|
|
672
|
+
team_mcp_tools: &["send_message"],
|
|
673
|
+
mcp_config: &isolated_config,
|
|
674
|
+
session_scope: PiSessionScope::Isolated,
|
|
675
|
+
session_dir: Some(root),
|
|
676
|
+
},
|
|
677
|
+
&session_id,
|
|
678
|
+
path,
|
|
679
|
+
&isolated_workspace,
|
|
680
|
+
)
|
|
681
|
+
.expect("resume exact backing across native storage migration/home changes");
|
|
682
|
+
assert_eq!(resumed.provider_projects_root.as_ref(), Some(root));
|
|
683
|
+
assert_session_pair(&resumed.argv, root);
|
|
684
|
+
assert!(resumed
|
|
685
|
+
.argv
|
|
686
|
+
.windows(2)
|
|
687
|
+
.any(|pair| pair == ["--session", path.to_string_lossy().as_ref()]));
|
|
688
|
+
}
|
|
689
|
+
}
|
|
690
|
+
{
|
|
691
|
+
let _override = hermetic.with_env("PI_CODING_AGENT_DIR", "relative-pi");
|
|
692
|
+
let customized = pi_seat_paths(&isolated_workspace, "team-a", "worker-a");
|
|
693
|
+
assert_eq!(
|
|
694
|
+
customized.sessions.parent(),
|
|
695
|
+
Some(isolated_workspace.join("relative-pi/sessions").as_path())
|
|
696
|
+
);
|
|
697
|
+
}
|
|
698
|
+
|
|
699
|
+
let global_settings = hermetic.home().join(".pi/agent/settings.json");
|
|
700
|
+
let project_settings = isolated_workspace.join(".pi/settings.json");
|
|
701
|
+
std::fs::create_dir_all(project_settings.parent().unwrap()).unwrap();
|
|
702
|
+
std::fs::write(&global_settings, r#"{"sessionDir":"global-sessions"}"#).unwrap();
|
|
703
|
+
for (project, expected) in [
|
|
704
|
+
("{}", isolated_workspace.join("global-sessions")),
|
|
705
|
+
(
|
|
706
|
+
r#"{"sessionDir":"project-sessions"}"#,
|
|
707
|
+
isolated_workspace.join("project-sessions"),
|
|
708
|
+
),
|
|
709
|
+
("invalid JSON", isolated_workspace.join("global-sessions")),
|
|
710
|
+
(r#"{"sessionDir":""}"#, isolated_paths.sessions.clone()),
|
|
711
|
+
(r#"{"sessionDir":null}"#, isolated_paths.sessions.clone()),
|
|
712
|
+
] {
|
|
713
|
+
std::fs::write(&project_settings, project).unwrap();
|
|
714
|
+
let plan = materialize_pi_plan(PiMaterializeRequest {
|
|
715
|
+
workspace: &isolated_workspace,
|
|
716
|
+
team_id: "team-a",
|
|
717
|
+
agent_id: "worker-a",
|
|
718
|
+
model: None,
|
|
719
|
+
effort: None,
|
|
720
|
+
system_prompt: "native settings precedence",
|
|
721
|
+
team_mcp_tools: &["send_message"],
|
|
722
|
+
mcp_config: &isolated_config,
|
|
723
|
+
session_scope: PiSessionScope::Isolated,
|
|
724
|
+
session_dir: None,
|
|
725
|
+
})
|
|
726
|
+
.expect("native settings sessionDir");
|
|
727
|
+
assert_eq!(plan.provider_projects_root.as_ref(), Some(&expected));
|
|
728
|
+
assert_session_pair(&plan.argv, &expected);
|
|
729
|
+
}
|
|
730
|
+
{
|
|
731
|
+
let custom_agent = isolated_workspace.join("custom-agent");
|
|
732
|
+
std::fs::create_dir_all(&custom_agent).unwrap();
|
|
733
|
+
std::fs::write(
|
|
734
|
+
custom_agent.join("settings.json"),
|
|
735
|
+
r#"{"sessionDir":"custom-global"}"#,
|
|
736
|
+
)
|
|
737
|
+
.unwrap();
|
|
738
|
+
std::fs::write(&project_settings, "{}").unwrap();
|
|
739
|
+
let _agent_dir = hermetic.with_env("PI_CODING_AGENT_DIR", custom_agent.to_str().unwrap());
|
|
740
|
+
assert_eq!(
|
|
741
|
+
pi_seat_paths(&isolated_workspace, "team-a", "worker-a").sessions,
|
|
742
|
+
isolated_workspace.join("custom-global")
|
|
743
|
+
);
|
|
744
|
+
}
|
|
745
|
+
std::fs::write(&project_settings, r#"{"sessionDir":"project-sessions"}"#).unwrap();
|
|
746
|
+
{
|
|
747
|
+
let _agent_dir = hermetic.with_env("PI_CODING_AGENT_DIR", "~/ignored-agent-dir");
|
|
748
|
+
let _session_dir =
|
|
749
|
+
hermetic.with_env("PI_CODING_AGENT_SESSION_DIR", "~/native-session-override");
|
|
750
|
+
let expected = hermetic
|
|
751
|
+
.home()
|
|
752
|
+
.canonicalize()
|
|
753
|
+
.unwrap()
|
|
754
|
+
.join("native-session-override");
|
|
755
|
+
assert_eq!(
|
|
756
|
+
pi_seat_paths(&isolated_workspace, "team-a", "worker-a").sessions,
|
|
757
|
+
expected
|
|
758
|
+
);
|
|
759
|
+
let explicit = isolated_workspace.join("explicit-sessions");
|
|
760
|
+
let parsed = crate::lifecycle::launch::pi_mcp::parse_pi_leader_args(&[
|
|
761
|
+
"--session-dir".into(),
|
|
762
|
+
explicit.to_string_lossy().into_owned(),
|
|
763
|
+
])
|
|
764
|
+
.expect("native --session-dir accepted");
|
|
765
|
+
for root in [None, parsed.session_dir.as_deref()] {
|
|
766
|
+
let plan = materialize_pi_plan(PiMaterializeRequest {
|
|
767
|
+
workspace: &isolated_workspace,
|
|
768
|
+
team_id: "team-a",
|
|
769
|
+
agent_id: "worker-a",
|
|
770
|
+
model: None,
|
|
771
|
+
effort: None,
|
|
772
|
+
system_prompt: "native directory precedence",
|
|
773
|
+
team_mcp_tools: &["send_message"],
|
|
774
|
+
mcp_config: &isolated_config,
|
|
775
|
+
session_scope: PiSessionScope::Isolated,
|
|
776
|
+
session_dir: root,
|
|
777
|
+
})
|
|
778
|
+
.expect("native session directory override");
|
|
779
|
+
let expected_root = root.unwrap_or(&expected);
|
|
780
|
+
assert_eq!(plan.provider_projects_root.as_deref(), Some(expected_root));
|
|
781
|
+
assert_session_pair(&plan.argv, expected_root);
|
|
782
|
+
assert_ne!(plan.expected_session_id, isolated.expected_session_id);
|
|
783
|
+
}
|
|
784
|
+
}
|
|
785
|
+
|
|
786
|
+
std::fs::remove_file(&project_settings).unwrap();
|
|
787
|
+
std::fs::remove_file(&global_settings).unwrap();
|
|
788
|
+
|
|
789
|
+
let native_resume = materialize_pi_resume_plan(
|
|
790
|
+
PiMaterializeRequest {
|
|
791
|
+
workspace: &native_workspace,
|
|
792
|
+
team_id: "team-a",
|
|
793
|
+
agent_id: "leader",
|
|
794
|
+
model: None,
|
|
795
|
+
effort: None,
|
|
796
|
+
system_prompt: "native resume fixture",
|
|
797
|
+
team_mcp_tools: &["send_message"],
|
|
798
|
+
mcp_config: &native_config,
|
|
799
|
+
session_scope: PiSessionScope::NativeDefault,
|
|
800
|
+
session_dir: None,
|
|
801
|
+
},
|
|
802
|
+
&session_id,
|
|
803
|
+
&exact,
|
|
804
|
+
&native_workspace,
|
|
805
|
+
);
|
|
806
|
+
assert!(
|
|
807
|
+
matches!(
|
|
808
|
+
native_resume,
|
|
809
|
+
Err(crate::provider::ProviderError::ResumeUnavailable(_))
|
|
810
|
+
),
|
|
811
|
+
"NativeDefault resume must fail closed before emitting a native HOME path: {native_resume:?}"
|
|
812
|
+
);
|
|
813
|
+
|
|
814
|
+
let home_candidate = hermetic.home().join(".pi/agent/sessions/home.jsonl");
|
|
815
|
+
std::fs::create_dir_all(home_candidate.parent().expect("home session parent"))
|
|
816
|
+
.expect("create home session parent");
|
|
817
|
+
std::fs::write(&home_candidate, b"{}\n").expect("write home candidate");
|
|
818
|
+
let other_paths = pi_seat_paths(&isolated_workspace, "team-a", "worker-b");
|
|
819
|
+
let other_candidate = other_paths.sessions.join("other.jsonl");
|
|
820
|
+
std::fs::create_dir_all(other_candidate.parent().expect("other session parent"))
|
|
821
|
+
.expect("create other session parent");
|
|
822
|
+
write_pi_session_header(
|
|
823
|
+
&other_candidate,
|
|
824
|
+
"other-seat-session",
|
|
825
|
+
&isolated_workspace,
|
|
826
|
+
"2026-09-01T00:00:01Z",
|
|
827
|
+
);
|
|
828
|
+
for (label, outside) in [("HOME", &home_candidate), ("other seat", &other_candidate)] {
|
|
829
|
+
let refused = materialize_pi_resume_plan(
|
|
830
|
+
PiMaterializeRequest {
|
|
831
|
+
workspace: &isolated_workspace,
|
|
832
|
+
team_id: "team-a",
|
|
833
|
+
agent_id: "worker-a",
|
|
834
|
+
model: None,
|
|
835
|
+
effort: None,
|
|
836
|
+
system_prompt: "isolated negative resume fixture",
|
|
837
|
+
team_mcp_tools: &["send_message"],
|
|
838
|
+
mcp_config: &isolated_config,
|
|
839
|
+
session_scope: PiSessionScope::Isolated,
|
|
840
|
+
session_dir: None,
|
|
841
|
+
},
|
|
842
|
+
&session_id,
|
|
843
|
+
&outside,
|
|
844
|
+
&isolated_workspace,
|
|
845
|
+
);
|
|
846
|
+
assert!(
|
|
847
|
+
matches!(
|
|
848
|
+
refused,
|
|
849
|
+
Err(crate::provider::ProviderError::ResumeUnavailable(_))
|
|
850
|
+
),
|
|
851
|
+
"{label} candidate must be refused by the exact root/id/cwd check: {refused:?}"
|
|
852
|
+
);
|
|
853
|
+
}
|
|
854
|
+
|
|
855
|
+
let worker_workspace = hermetic.workspace("worker-spawn");
|
|
856
|
+
let spec_path = worker_workspace
|
|
857
|
+
.join(".team")
|
|
858
|
+
.join("team-a")
|
|
859
|
+
.join("team.spec.yaml");
|
|
860
|
+
std::fs::create_dir_all(spec_path.parent().expect("worker Pi spec parent"))
|
|
861
|
+
.expect("create worker Pi spec parent");
|
|
862
|
+
let spec = crate::model::yaml::loads(
|
|
863
|
+
"team:\n name: team-a\nruntime:\n session_name: team-workers\nagents:\n - id: worker-a\n role: Worker A\n provider: pi\n model: team-agent/qwen3.8-27b\n auth_mode: subscription\n dangerously_skip_permissions: false\n tools:\n - mcp_team\n - id: worker-b\n role: Worker B\n provider: pi\n model: team-agent/qwen3.8-27b\n auth_mode: subscription\n dangerously_skip_permissions: false\n tools:\n - mcp_team\n",
|
|
864
|
+
)
|
|
865
|
+
.expect("parse worker Pi spec");
|
|
866
|
+
std::fs::write(&spec_path, crate::model::yaml::dumps(&spec)).expect("write worker Pi spec");
|
|
867
|
+
let transport = OfflineTransport::new();
|
|
868
|
+
let started = launch_with_transport_in_workspace(
|
|
869
|
+
&worker_workspace,
|
|
870
|
+
&spec_path,
|
|
871
|
+
false,
|
|
872
|
+
true,
|
|
873
|
+
true,
|
|
874
|
+
&transport,
|
|
875
|
+
)
|
|
876
|
+
.expect("worker fresh spawn construction")
|
|
877
|
+
.started;
|
|
878
|
+
assert_eq!(started.len(), 2, "both Pi worker seats must be spawned");
|
|
879
|
+
for worker in ["worker-a", "worker-b"] {
|
|
880
|
+
let paths = pi_seat_paths(&worker_workspace, "team-a", worker);
|
|
881
|
+
let started_agent = started
|
|
882
|
+
.iter()
|
|
883
|
+
.find(|entry| entry.agent_id.as_str() == worker)
|
|
884
|
+
.expect("started worker entry");
|
|
885
|
+
assert_eq!(
|
|
886
|
+
started_agent.provider_projects_root.as_deref(),
|
|
887
|
+
Some(paths.sessions.as_path()),
|
|
888
|
+
"fresh worker must expose its exact seat capture root"
|
|
889
|
+
);
|
|
890
|
+
let record = transport
|
|
891
|
+
.spawn_records()
|
|
892
|
+
.into_iter()
|
|
893
|
+
.find(|(_, argv)| {
|
|
894
|
+
argv.iter()
|
|
895
|
+
.any(|arg| arg.as_str() == paths.wrapper.to_string_lossy().as_ref())
|
|
896
|
+
})
|
|
897
|
+
.expect("transport spawn record for worker seat");
|
|
898
|
+
assert_eq!(record.1.first().map(String::as_str), Some("pi"));
|
|
899
|
+
assert_session_pair(&record.1, &paths.sessions);
|
|
900
|
+
assert!(
|
|
901
|
+
!record
|
|
902
|
+
.1
|
|
903
|
+
.iter()
|
|
904
|
+
.any(|arg| arg.as_str() == home_candidate.to_string_lossy().as_ref())
|
|
905
|
+
);
|
|
906
|
+
assert!(
|
|
907
|
+
!record
|
|
908
|
+
.1
|
|
909
|
+
.iter()
|
|
910
|
+
.any(|arg| arg.as_str() == other_candidate.to_string_lossy().as_ref())
|
|
911
|
+
);
|
|
912
|
+
|
|
913
|
+
let pending_id = started_agent
|
|
914
|
+
.pending_session_id
|
|
915
|
+
.as_ref()
|
|
916
|
+
.expect("fresh Pi UUID selector");
|
|
917
|
+
assert!(record
|
|
918
|
+
.1
|
|
919
|
+
.windows(2)
|
|
920
|
+
.any(|pair| pair == ["--session-id", pending_id.as_str()]));
|
|
921
|
+
let foreign_session_id = format!("{worker}-foreign");
|
|
922
|
+
write_pi_session_header(
|
|
923
|
+
&home_candidate,
|
|
924
|
+
&foreign_session_id,
|
|
925
|
+
&worker_workspace,
|
|
926
|
+
"2099-01-01T00:00:00Z",
|
|
927
|
+
);
|
|
928
|
+
let other_worker = if worker == "worker-a" {
|
|
929
|
+
"worker-b"
|
|
930
|
+
} else {
|
|
931
|
+
"worker-a"
|
|
932
|
+
};
|
|
933
|
+
let cross_seat = pi_seat_paths(&worker_workspace, "team-a", other_worker)
|
|
934
|
+
.sessions
|
|
935
|
+
.join("foreign.jsonl");
|
|
936
|
+
write_pi_session_header(
|
|
937
|
+
&cross_seat,
|
|
938
|
+
&foreign_session_id,
|
|
939
|
+
&worker_workspace,
|
|
940
|
+
"2099-01-01T00:00:00Z",
|
|
941
|
+
);
|
|
942
|
+
let context = CaptureSessionContext {
|
|
943
|
+
agent_id: worker.to_string(),
|
|
944
|
+
spawn_cwd: worker_workspace.clone(),
|
|
945
|
+
pane_id: None,
|
|
946
|
+
pane_pid: None,
|
|
947
|
+
spawned_at: Some(started_agent.spawned_at.clone()),
|
|
948
|
+
expected_session_id: Some(pending_id.clone()),
|
|
949
|
+
provider_projects_root: Some(paths.sessions.clone()),
|
|
950
|
+
};
|
|
951
|
+
let candidates = scan_session_candidates_once(Provider::Pi, &context)
|
|
952
|
+
.expect("scan the recorded worker seat only");
|
|
953
|
+
assert!(
|
|
954
|
+
candidates.is_empty(),
|
|
955
|
+
"HOME and another worker seat must not become capture candidates: {candidates:?}"
|
|
956
|
+
);
|
|
957
|
+
// Positive control: Pi's own header inside the recorded seat is captured.
|
|
958
|
+
let own = paths.sessions.join("own.jsonl");
|
|
959
|
+
write_pi_session_header(
|
|
960
|
+
&own,
|
|
961
|
+
pending_id.as_str(),
|
|
962
|
+
&worker_workspace,
|
|
963
|
+
"2099-01-01T00:00:00Z",
|
|
964
|
+
);
|
|
965
|
+
let candidates = scan_session_candidates_once(Provider::Pi, &context)
|
|
966
|
+
.expect("scan the recorded worker seat only");
|
|
967
|
+
assert_eq!(candidates.len(), 1, "{candidates:?}");
|
|
968
|
+
assert_eq!(
|
|
969
|
+
candidates[0]
|
|
970
|
+
.captured
|
|
971
|
+
.session_id
|
|
972
|
+
.as_ref()
|
|
973
|
+
.map(SessionId::as_str),
|
|
974
|
+
Some(pending_id.as_str())
|
|
975
|
+
);
|
|
976
|
+
std::fs::remove_file(&cross_seat).expect("clear foreign header from the other seat");
|
|
977
|
+
}
|
|
978
|
+
|
|
979
|
+
let restart_workspace = hermetic.workspace("worker-restart");
|
|
980
|
+
let restart_paths = pi_seat_paths(&restart_workspace, "team-a", "worker-a");
|
|
981
|
+
let restart_exact = restart_paths.sessions.join("2026/09/restart.jsonl");
|
|
982
|
+
write_pi_session_header(
|
|
983
|
+
&restart_exact,
|
|
984
|
+
"pi-restart-session",
|
|
985
|
+
&restart_workspace,
|
|
986
|
+
"2026-09-01T00:00:01Z",
|
|
987
|
+
);
|
|
988
|
+
crate::state::persist::save_runtime_state(
|
|
989
|
+
&restart_workspace,
|
|
990
|
+
&serde_json::json!({
|
|
991
|
+
"session_name": "team-workers",
|
|
992
|
+
"active_team_key": "team-a",
|
|
993
|
+
"agents": {
|
|
994
|
+
"worker-a": {
|
|
995
|
+
"id": "worker-a",
|
|
996
|
+
"status": "running",
|
|
997
|
+
"provider": "pi",
|
|
998
|
+
"role": "Worker A",
|
|
999
|
+
"model": "team-agent/qwen3.8-27b",
|
|
1000
|
+
"auth_mode": "subscription",
|
|
1001
|
+
"tools": ["mcp_team"],
|
|
1002
|
+
"session_id": "pi-restart-session",
|
|
1003
|
+
"rollout_path": restart_exact.to_string_lossy(),
|
|
1004
|
+
"spawn_cwd": restart_workspace.to_string_lossy(),
|
|
1005
|
+
"first_send_at": "2026-09-01T00:00:00Z"
|
|
1006
|
+
}
|
|
1007
|
+
}
|
|
1008
|
+
}),
|
|
1009
|
+
)
|
|
1010
|
+
.expect("write restart state");
|
|
1011
|
+
let restart_transport = OfflineTransport::new();
|
|
1012
|
+
let _ = start_agent_with_transport(
|
|
1013
|
+
&restart_workspace,
|
|
1014
|
+
&crate::model::ids::AgentId::new("worker-a"),
|
|
1015
|
+
false,
|
|
1016
|
+
false,
|
|
1017
|
+
false,
|
|
1018
|
+
None,
|
|
1019
|
+
&restart_transport,
|
|
1020
|
+
);
|
|
1021
|
+
let restart_record = restart_transport
|
|
1022
|
+
.spawn_records()
|
|
1023
|
+
.into_iter()
|
|
1024
|
+
.next()
|
|
1025
|
+
.expect("restart must reach the worker spawn construction");
|
|
1026
|
+
assert_eq!(restart_record.1.first().map(String::as_str), Some("pi"));
|
|
1027
|
+
assert_session_pair(&restart_record.1, &restart_paths.sessions);
|
|
1028
|
+
assert!(
|
|
1029
|
+
restart_record
|
|
1030
|
+
.1
|
|
1031
|
+
.windows(2)
|
|
1032
|
+
.any(|pair| { pair == ["--session", restart_exact.to_string_lossy().as_ref()] })
|
|
1033
|
+
);
|
|
1034
|
+
assert!(
|
|
1035
|
+
!restart_record
|
|
1036
|
+
.1
|
|
1037
|
+
.iter()
|
|
1038
|
+
.any(|arg| arg.as_str() == home_candidate.to_string_lossy().as_ref())
|
|
1039
|
+
);
|
|
536
1040
|
}
|
|
537
1041
|
|
|
538
1042
|
fn assert_session_pair(argv: &[String], session_root: &Path) {
|
|
@@ -544,3 +1048,15 @@ fn assert_session_pair(argv: &[String], session_root: &Path) {
|
|
|
544
1048
|
session_root.display()
|
|
545
1049
|
);
|
|
546
1050
|
}
|
|
1051
|
+
|
|
1052
|
+
fn write_pi_session_header(path: &Path, id: &str, cwd: &Path, timestamp: &str) {
|
|
1053
|
+
std::fs::create_dir_all(path.parent().expect("session parent")).expect("create session parent");
|
|
1054
|
+
let header = serde_json::json!({
|
|
1055
|
+
"type": "session",
|
|
1056
|
+
"version": 3,
|
|
1057
|
+
"id": id,
|
|
1058
|
+
"cwd": cwd,
|
|
1059
|
+
"timestamp": timestamp,
|
|
1060
|
+
});
|
|
1061
|
+
std::fs::write(path, format!("{header}\n")).expect("write Pi session header");
|
|
1062
|
+
}
|