@team-agent/installer 0.5.122 → 0.5.124
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Cargo.lock +8 -1
- package/Cargo.toml +1 -1
- package/crates/team-agent/src/cli/diagnose.rs +176 -10
- package/crates/team-agent/src/cli/intent/runtime.rs +103 -43
- package/crates/team-agent/src/cli/intent/runtime_tests.rs +198 -0
- package/crates/team-agent/src/cli/intent/tests.rs +37 -0
- package/crates/team-agent/src/cli/intent.rs +22 -0
- package/crates/team-agent/src/cli/models.rs +54 -10
- package/crates/team-agent/src/contract_runtime/backend.rs +498 -2
- package/crates/team-agent/src/contract_runtime/commands.rs +38 -24
- package/crates/team-agent/src/contract_runtime/discovery.rs +46 -56
- package/crates/team-agent/src/contract_runtime/forward.rs +59 -0
- package/crates/team-agent/src/contract_runtime/framework.rs +23 -17
- package/crates/team-agent/src/contract_runtime/registry.rs +41 -3
- package/crates/team-agent/src/lifecycle/launch/pi_mcp.rs +19 -101
- package/crates/team-agent/src/lifecycle/launch/quick_start.rs +6 -17
- package/crates/team-agent/src/lifecycle/launch/quick_start_transport.rs +26 -19
- package/crates/team-agent/src/lifecycle/launch/spawn.rs +19 -2
- package/crates/team-agent/src/lifecycle/restart/rebuild.rs +95 -31
- package/crates/team-agent/src/lifecycle/restart.rs +1 -0
- package/crates/team-agent/src/lifecycle/tests/cli_argv_routing_red.rs +5 -6
- package/crates/team-agent/src/lifecycle/tests/launch_spawn.rs +7 -5
- package/crates/team-agent/src/lifecycle/tests/pi_catalog_red.rs +1 -3
- package/crates/team-agent/src/lifecycle/tests/pi_command_red.rs +4 -16
- package/crates/team-agent/src/lifecycle/tests/pi_compiler_red.rs +1 -3
- package/crates/team-agent/src/lifecycle/tests/pi_executable_mcp_red.rs +84 -53
- package/crates/team-agent/src/lifecycle/tests/pi_fork_session_inheritance_red.rs +19 -1
- package/crates/team-agent/src/lifecycle/tests/pi_session_delivery_red.rs +21 -0
- package/crates/team-agent/src/messaging/delivery.rs +5 -3
- package/crates/team-agent/src/provider/adapters/pi.rs +4 -4
- package/crates/team-agent/src/provider/session_scan/pi.rs +32 -19
- package/crates/team-agent/src/provider/tests/command_helpers.rs +2 -2
- package/crates/team-agent/src/provider/wire.rs +2 -1
- package/npm/install.mjs +56 -99
- package/package.json +4 -4
|
@@ -20,9 +20,7 @@ fn request(session: PiSessionSelector<'static>) -> PiCommandRequest<'static> {
|
|
|
20
20
|
|
|
21
21
|
#[test]
|
|
22
22
|
fn pi_command_omits_unset_model_and_thinking_flags() {
|
|
23
|
-
let mut request = request(PiSessionSelector::Fresh
|
|
24
|
-
session_id: "a2320d4e-7b3a-44ae-b3b8-d5de57033b01",
|
|
25
|
-
});
|
|
23
|
+
let mut request = request(PiSessionSelector::Fresh);
|
|
26
24
|
request.model = None;
|
|
27
25
|
request.effort = None;
|
|
28
26
|
let argv = build_pi_command_argv(request).expect("Pi provider defaults");
|
|
@@ -38,9 +36,7 @@ fn leader_request() -> PiCommandRequest<'static> {
|
|
|
38
36
|
effort: None,
|
|
39
37
|
system_prompt: "frozen leader prompt",
|
|
40
38
|
session_dir: None,
|
|
41
|
-
session: PiSessionSelector::Fresh
|
|
42
|
-
session_id: "da8c3622-2378-4d05-a26c-e826a6ef6d63",
|
|
43
|
-
},
|
|
39
|
+
session: PiSessionSelector::Fresh,
|
|
44
40
|
agent_id: "leader",
|
|
45
41
|
}
|
|
46
42
|
}
|
|
@@ -57,8 +53,6 @@ fn pi_interactive_leader_argv_preserves_native_session_discovery() {
|
|
|
57
53
|
"/workspace/.team/runtime/pi/current/leader/team-mcp.ts",
|
|
58
54
|
"--append-system-prompt",
|
|
59
55
|
"frozen leader prompt",
|
|
60
|
-
"--session-id",
|
|
61
|
-
"da8c3622-2378-4d05-a26c-e826a6ef6d63",
|
|
62
56
|
"--name",
|
|
63
57
|
"leader",
|
|
64
58
|
]
|
|
@@ -98,9 +92,7 @@ fn pi_leader_session_scope_keeps_explicit_and_external_routes_isolated() {
|
|
|
98
92
|
|
|
99
93
|
#[test]
|
|
100
94
|
fn pi_command_preserves_direct_pi_defaults_with_only_team_runtime_additions() {
|
|
101
|
-
let fresh = build_pi_command_argv(request(PiSessionSelector::Fresh
|
|
102
|
-
session_id: "da8c3622-2378-4d05-a26c-e826a6ef6d63",
|
|
103
|
-
}))
|
|
95
|
+
let fresh = build_pi_command_argv(request(PiSessionSelector::Fresh))
|
|
104
96
|
.expect("fresh Pi command");
|
|
105
97
|
assert_eq!(
|
|
106
98
|
fresh,
|
|
@@ -116,8 +108,6 @@ fn pi_command_preserves_direct_pi_defaults_with_only_team_runtime_additions() {
|
|
|
116
108
|
"frozen worker prompt",
|
|
117
109
|
"--session-dir",
|
|
118
110
|
"/workspace/.team/runtime/pi/team-a/worker-a/sessions",
|
|
119
|
-
"--session-id",
|
|
120
|
-
"da8c3622-2378-4d05-a26c-e826a6ef6d63",
|
|
121
111
|
"--name",
|
|
122
112
|
"worker-a",
|
|
123
113
|
]
|
|
@@ -178,9 +168,7 @@ fn pi_command_preserves_direct_pi_defaults_with_only_team_runtime_additions() {
|
|
|
178
168
|
|
|
179
169
|
#[test]
|
|
180
170
|
fn pi_command_keeps_direct_plugins_skills_context_auth_and_tools() {
|
|
181
|
-
let argv = build_pi_command_argv(request(PiSessionSelector::Fresh
|
|
182
|
-
session_id: "76f682b1-ecc3-4586-850f-ab2e2bb04cb3",
|
|
183
|
-
}))
|
|
171
|
+
let argv = build_pi_command_argv(request(PiSessionSelector::Fresh))
|
|
184
172
|
.expect("fresh Pi command");
|
|
185
173
|
|
|
186
174
|
for forbidden in [
|
|
@@ -58,9 +58,7 @@ fn command(_tools: &[&str], effort: ProviderEffort, model: &str) -> Result<Vec<S
|
|
|
58
58
|
session_dir: Some(Path::new(
|
|
59
59
|
"/workspace/.team/runtime/pi/t1/pi-worker/sessions",
|
|
60
60
|
)),
|
|
61
|
-
session: PiSessionSelector::Fresh
|
|
62
|
-
session_id: "c5ddf218-24a5-4e74-960c-ab6606ea7e8c",
|
|
63
|
-
},
|
|
61
|
+
session: PiSessionSelector::Fresh,
|
|
64
62
|
agent_id: "pi-worker",
|
|
65
63
|
})
|
|
66
64
|
.map_err(|error| error.to_string())
|
|
@@ -4,7 +4,7 @@ use std::sync::atomic::{AtomicU32, Ordering};
|
|
|
4
4
|
|
|
5
5
|
use crate::lifecycle::launch::launch_with_transport_in_workspace;
|
|
6
6
|
use crate::lifecycle::launch::pi_mcp::{
|
|
7
|
-
PiExecutableChain,
|
|
7
|
+
PiExecutableChain, PiMaterializeRequest, PiSessionScope,
|
|
8
8
|
PiWrapperRequest, materialize_pi_plan, materialize_pi_resume_plan,
|
|
9
9
|
parse_pi_list_models_table, pi_seat_paths, resolve_pi_executable_chain,
|
|
10
10
|
validate_pi_executable_chain, validate_pi_wrapper_source, write_pi_wrapper,
|
|
@@ -105,47 +105,35 @@ fn mcp_config(candidate: &Path, workspace: &Path, agent_id: &str) -> McpConfig {
|
|
|
105
105
|
}
|
|
106
106
|
|
|
107
107
|
#[test]
|
|
108
|
-
fn
|
|
108
|
+
fn pi_executable_chain_accepts_any_first_path_entry_and_freezes_catalog() {
|
|
109
109
|
let chain = PiExecutableChain {
|
|
110
110
|
path_entry: PathBuf::from("/Users/fixture/.local/bin/pi"),
|
|
111
|
-
path_entry_type: PiExecutableFileType::Wrapper,
|
|
112
|
-
launch_executable: PathBuf::from("/Users/fixture/.local/bin/pi"),
|
|
113
|
-
real_binary: PathBuf::from(
|
|
114
|
-
"/opt/homebrew/lib/node_modules/@earendil-works/pi-coding-agent/dist/bundle/cli.js",
|
|
115
|
-
),
|
|
116
111
|
pi_version: "0.84.3".to_string(),
|
|
117
112
|
catalog_sha256: CATALOG_DIGEST.to_string(),
|
|
118
113
|
};
|
|
119
|
-
validate_pi_executable_chain(&chain).expect("the
|
|
114
|
+
validate_pi_executable_chain(&chain).expect("the PATH wrapper entry is valid");
|
|
120
115
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
116
|
+
// A plain binary or compiled wrapper first on PATH is what bare `pi` runs.
|
|
117
|
+
let mut direct_binary = chain.clone();
|
|
118
|
+
direct_binary.path_entry = PathBuf::from("/opt/homebrew/bin/pi");
|
|
119
|
+
validate_pi_executable_chain(&direct_binary)
|
|
120
|
+
.expect("a direct binary first on PATH is the native launch entry");
|
|
125
121
|
|
|
126
|
-
let mut
|
|
127
|
-
|
|
128
|
-
validate_pi_executable_chain(&
|
|
122
|
+
let mut newer = chain.clone();
|
|
123
|
+
newer.pi_version = "0.84.4".to_string();
|
|
124
|
+
validate_pi_executable_chain(&newer)
|
|
129
125
|
.expect("an arbitrary newer Pi version with the same public protocol is valid");
|
|
130
126
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
127
|
+
for bad in ["", "pi", "/opt/homebrew/bin/pi-native"] {
|
|
128
|
+
let mut wrong = chain.clone();
|
|
129
|
+
wrong.path_entry = PathBuf::from(bad);
|
|
130
|
+
assert!(validate_pi_executable_chain(&wrong).is_err(), "{bad:?}");
|
|
131
|
+
}
|
|
134
132
|
|
|
135
133
|
let mut wrong_catalog = chain.clone();
|
|
136
134
|
wrong_catalog.catalog_sha256 = "00".repeat(32);
|
|
137
135
|
assert!(validate_pi_executable_chain(&wrong_catalog).is_err());
|
|
138
136
|
|
|
139
|
-
let mut direct_binary = chain.clone();
|
|
140
|
-
direct_binary.path_entry = PathBuf::from("/opt/homebrew/bin/pi");
|
|
141
|
-
direct_binary.path_entry_type = PiExecutableFileType::Binary;
|
|
142
|
-
direct_binary.launch_executable = direct_binary.path_entry.clone();
|
|
143
|
-
direct_binary.real_binary = direct_binary.path_entry.clone();
|
|
144
|
-
assert!(
|
|
145
|
-
validate_pi_executable_chain(&direct_binary).is_err(),
|
|
146
|
-
"a direct Homebrew binary must not replace the verified PATH wrapper launch entry"
|
|
147
|
-
);
|
|
148
|
-
|
|
149
137
|
assert!(parse_pi_list_models_table(b"provider model\nopenai-codex gpt-5.6-luna\n").is_ok());
|
|
150
138
|
assert!(parse_pi_list_models_table(b"provider model\n").is_err());
|
|
151
139
|
assert!(parse_pi_list_models_table(b"provider model\nmalformed\n").is_err());
|
|
@@ -178,14 +166,38 @@ fn pi_standard_npm_symlink_is_a_verified_launch_entry() {
|
|
|
178
166
|
|
|
179
167
|
let (chain, models) = resolve_pi_executable_chain()
|
|
180
168
|
.expect("the first PATH Pi entry must define direct Pi behavior");
|
|
181
|
-
assert_eq!(chain.path_entry, bin.join("pi"));
|
|
182
|
-
assert_eq!(
|
|
183
|
-
|
|
169
|
+
assert_eq!(chain.path_entry, bin.join("pi"), "the npm symlink is kept as found");
|
|
170
|
+
assert_eq!(models, ["team-agent/qwen3.8-27b"]);
|
|
171
|
+
|
|
172
|
+
// A user wrapper prepended to PATH is the entry, and every probe runs it.
|
|
173
|
+
let wrappers = root.join("wrappers");
|
|
174
|
+
std::fs::create_dir_all(&wrappers).expect("create wrapper dir");
|
|
175
|
+
let marker = root.join("wrapper-invocations");
|
|
176
|
+
std::fs::write(
|
|
177
|
+
wrappers.join("pi"),
|
|
178
|
+
format!(
|
|
179
|
+
"#!/bin/sh\nprintf '%s\\n' \"$*\" >> '{}'\nexec '{}' \"$@\"\n",
|
|
180
|
+
marker.display(),
|
|
181
|
+
bin.join("pi").display()
|
|
182
|
+
),
|
|
183
|
+
)
|
|
184
|
+
.expect("write user Pi wrapper");
|
|
185
|
+
std::fs::set_permissions(wrappers.join("pi"), std::fs::Permissions::from_mode(0o755))
|
|
186
|
+
.expect("make user Pi wrapper executable");
|
|
187
|
+
unsafe {
|
|
188
|
+
std::env::set_var(
|
|
189
|
+
"PATH",
|
|
190
|
+
std::env::join_paths([&wrappers, &bin, &later_bin]).expect("join wrapper PATH"),
|
|
191
|
+
);
|
|
192
|
+
}
|
|
193
|
+
let (chain, models) =
|
|
194
|
+
resolve_pi_executable_chain().expect("a user wrapper first on PATH is accepted");
|
|
195
|
+
assert_eq!(chain.path_entry, wrappers.join("pi"));
|
|
196
|
+
assert_eq!(models, ["team-agent/qwen3.8-27b"]);
|
|
184
197
|
assert_eq!(
|
|
185
|
-
|
|
186
|
-
|
|
198
|
+
std::fs::read_to_string(&marker).expect("the wrapper genuinely ran"),
|
|
199
|
+
"--version\n--list-models\n"
|
|
187
200
|
);
|
|
188
|
-
assert_eq!(models, ["team-agent/qwen3.8-27b"]);
|
|
189
201
|
std::fs::remove_dir_all(root).expect("remove symlink fixture");
|
|
190
202
|
});
|
|
191
203
|
}
|
|
@@ -678,13 +690,14 @@ fn pi_materializer_and_worker_routes_body(hermetic: &HermeticTestEnv) {
|
|
|
678
690
|
.any(|arg| arg.as_str() == other_candidate.to_string_lossy().as_ref())
|
|
679
691
|
);
|
|
680
692
|
|
|
681
|
-
|
|
682
|
-
.pending_session_id
|
|
683
|
-
|
|
684
|
-
|
|
693
|
+
assert!(
|
|
694
|
+
started_agent.pending_session_id.is_none(),
|
|
695
|
+
"fresh Pi assigns its own session id"
|
|
696
|
+
);
|
|
697
|
+
let foreign_session_id = format!("{worker}-foreign");
|
|
685
698
|
write_pi_session_header(
|
|
686
699
|
&home_candidate,
|
|
687
|
-
|
|
700
|
+
&foreign_session_id,
|
|
688
701
|
&worker_workspace,
|
|
689
702
|
"2099-01-01T00:00:00Z",
|
|
690
703
|
);
|
|
@@ -698,27 +711,45 @@ fn pi_materializer_and_worker_routes_body(hermetic: &HermeticTestEnv) {
|
|
|
698
711
|
.join("foreign.jsonl");
|
|
699
712
|
write_pi_session_header(
|
|
700
713
|
&cross_seat,
|
|
701
|
-
|
|
714
|
+
&foreign_session_id,
|
|
702
715
|
&worker_workspace,
|
|
703
716
|
"2099-01-01T00:00:00Z",
|
|
704
717
|
);
|
|
705
|
-
let
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
)
|
|
717
|
-
.expect("scan the recorded worker seat only");
|
|
718
|
+
let context = CaptureSessionContext {
|
|
719
|
+
agent_id: worker.to_string(),
|
|
720
|
+
spawn_cwd: worker_workspace.clone(),
|
|
721
|
+
pane_id: None,
|
|
722
|
+
pane_pid: None,
|
|
723
|
+
spawned_at: Some(started_agent.spawned_at.clone()),
|
|
724
|
+
expected_session_id: None,
|
|
725
|
+
provider_projects_root: Some(paths.sessions.clone()),
|
|
726
|
+
};
|
|
727
|
+
let candidates = scan_session_candidates_once(Provider::Pi, &context)
|
|
728
|
+
.expect("scan the recorded worker seat only");
|
|
718
729
|
assert!(
|
|
719
730
|
candidates.is_empty(),
|
|
720
731
|
"HOME and another worker seat must not become capture candidates: {candidates:?}"
|
|
721
732
|
);
|
|
733
|
+
// Positive control: Pi's own header inside the recorded seat is captured.
|
|
734
|
+
let own = paths.sessions.join("own.jsonl");
|
|
735
|
+
write_pi_session_header(
|
|
736
|
+
&own,
|
|
737
|
+
&format!("{worker}-own"),
|
|
738
|
+
&worker_workspace,
|
|
739
|
+
"2099-01-01T00:00:00Z",
|
|
740
|
+
);
|
|
741
|
+
let candidates = scan_session_candidates_once(Provider::Pi, &context)
|
|
742
|
+
.expect("scan the recorded worker seat only");
|
|
743
|
+
assert_eq!(candidates.len(), 1, "{candidates:?}");
|
|
744
|
+
assert_eq!(
|
|
745
|
+
candidates[0]
|
|
746
|
+
.captured
|
|
747
|
+
.session_id
|
|
748
|
+
.as_ref()
|
|
749
|
+
.map(SessionId::as_str),
|
|
750
|
+
Some(format!("{worker}-own").as_str())
|
|
751
|
+
);
|
|
752
|
+
std::fs::remove_file(&cross_seat).expect("clear foreign header from the other seat");
|
|
722
753
|
}
|
|
723
754
|
|
|
724
755
|
let restart_workspace = hermetic.workspace("worker-restart");
|
|
@@ -812,7 +812,25 @@ fn r05_bad_source_tuples_and_jsonl_fail_closed_without_a_fresh_target() {
|
|
|
812
812
|
}
|
|
813
813
|
_ => unreachable!(),
|
|
814
814
|
}
|
|
815
|
-
|
|
815
|
+
if case == "missing-tuple" {
|
|
816
|
+
// An ordinary save backfills the latest complete tuple (stale-writer
|
|
817
|
+
// protection), so only a capture-backfill-skipping writer can drop it.
|
|
818
|
+
team_agent::state::projection::save_team_scoped_state_with_lifecycle_topology_authority_and_capture_backfill_skip(
|
|
819
|
+
&fixture.run_workspace,
|
|
820
|
+
&state,
|
|
821
|
+
&fixture.team_key,
|
|
822
|
+
&[SOURCE],
|
|
823
|
+
&[],
|
|
824
|
+
)
|
|
825
|
+
.expect("persist the incomplete source tuple");
|
|
826
|
+
} else {
|
|
827
|
+
fixture.save_state(&state);
|
|
828
|
+
}
|
|
829
|
+
assert_eq!(
|
|
830
|
+
fixture.state()["agents"][SOURCE]["rollout_path"],
|
|
831
|
+
state["agents"][SOURCE]["rollout_path"],
|
|
832
|
+
"R05 ({case}): the adversarial source row must be what fork reads"
|
|
833
|
+
);
|
|
816
834
|
let transport = fixture.transport();
|
|
817
835
|
let result = fixture.fork(TARGET, None, &transport);
|
|
818
836
|
assert!(
|
|
@@ -133,6 +133,27 @@ fn pi_session_capture_requires_header_id_cwd_generation_and_unique_claim() {
|
|
|
133
133
|
std::fs::remove_dir_all(root).expect("remove session fixture");
|
|
134
134
|
}
|
|
135
135
|
|
|
136
|
+
#[test]
|
|
137
|
+
fn pi_fresh_capture_reads_the_header_id_pi_wrote() {
|
|
138
|
+
let root = temp_root("native-header");
|
|
139
|
+
let cwd = root.join("workspace");
|
|
140
|
+
let sessions = root.join("seat/sessions");
|
|
141
|
+
std::fs::create_dir_all(&cwd).expect("create cwd");
|
|
142
|
+
let native_id = "410271aa-2a95-46fe-a92e-41927688fb0c";
|
|
143
|
+
let path = sessions.join("pi-created.jsonl");
|
|
144
|
+
write_header(&path, native_id, &cwd, "2026-08-29T10:00:01Z");
|
|
145
|
+
let mut context = scan_context(&cwd, &sessions, "unused", "2026-08-29T10:00:00Z");
|
|
146
|
+
context.expected_session_id = None;
|
|
147
|
+
|
|
148
|
+
let candidates = scan_session_candidates_once(Provider::Pi, &context).expect("native header scan");
|
|
149
|
+
assert_eq!(candidates.len(), 1);
|
|
150
|
+
assert_eq!(
|
|
151
|
+
candidates[0].captured.session_id.as_ref().map(SessionId::as_str),
|
|
152
|
+
Some(native_id)
|
|
153
|
+
);
|
|
154
|
+
std::fs::remove_dir_all(root).expect("remove native header fixture");
|
|
155
|
+
}
|
|
156
|
+
|
|
136
157
|
#[test]
|
|
137
158
|
fn pi_restart_uses_exact_path_and_refuses_missing_backing() {
|
|
138
159
|
let root = temp_root("resume");
|
|
@@ -2587,9 +2587,11 @@ fn leader_rollout_path(state: &serde_json::Value) -> Option<std::path::PathBuf>
|
|
|
2587
2587
|
pane_id: None,
|
|
2588
2588
|
pane_pid: None,
|
|
2589
2589
|
spawned_at: Some(native.get("spawned_at")?.as_str()?.into()),
|
|
2590
|
-
expected_session_id:
|
|
2591
|
-
|
|
2592
|
-
|
|
2590
|
+
expected_session_id: native
|
|
2591
|
+
.get("expected_session_id")
|
|
2592
|
+
.and_then(|value| value.as_str())
|
|
2593
|
+
.filter(|value| !value.is_empty())
|
|
2594
|
+
.map(crate::provider::SessionId::new),
|
|
2593
2595
|
provider_projects_root: Some(native.get("provider_projects_root")?.as_str()?.into()),
|
|
2594
2596
|
};
|
|
2595
2597
|
if !context.spawn_cwd.is_absolute()
|
|
@@ -18,7 +18,9 @@ use crate::provider::command_helpers::{append_opt_pair, append_pair};
|
|
|
18
18
|
|
|
19
19
|
#[derive(Debug, Clone, Copy)]
|
|
20
20
|
pub(crate) enum PiSessionSelector<'a> {
|
|
21
|
-
|
|
21
|
+
/// Pi assigns the session id. Passing `--session-id` makes Pi warn and
|
|
22
|
+
/// then create, because the id is not a project session yet.
|
|
23
|
+
Fresh,
|
|
22
24
|
Resume { path: &'a Path },
|
|
23
25
|
}
|
|
24
26
|
|
|
@@ -74,9 +76,7 @@ pub(crate) fn build_pi_command_argv(
|
|
|
74
76
|
// Keep the pure argv builder usable before a fixture root is materialized, while
|
|
75
77
|
// refusing a missing exact file once the recorded path's parent exists.
|
|
76
78
|
match request.session {
|
|
77
|
-
PiSessionSelector::Fresh
|
|
78
|
-
append_pair(&mut argv, "--session-id", session_id);
|
|
79
|
-
}
|
|
79
|
+
PiSessionSelector::Fresh => {}
|
|
80
80
|
PiSessionSelector::Resume { path }
|
|
81
81
|
if !path.as_os_str().is_empty()
|
|
82
82
|
&& (!path.parent().is_some_and(Path::is_dir) || path.is_file()) =>
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
//! contract:
|
|
4
4
|
//! provides:
|
|
5
5
|
//! - name: scan_session_store
|
|
6
|
-
//! what: 只读每个 JSONL 的首个完整 header
|
|
6
|
+
//! what: 只读每个 JSONL 的首个完整 header;有预期 id 时按 id/cwd/spawned_at,否则按 cwd/spawned_at 读取 Pi 自己的 id
|
|
7
7
|
//! - name: validate_exact_backing
|
|
8
8
|
//! what: restart 前重验 exact path 的 id/cwd header
|
|
9
9
|
//! boundary:
|
|
@@ -49,13 +49,8 @@ fn read_header(path: &Path) -> Option<PiSessionHeader> {
|
|
|
49
49
|
(header.record_type == "session" && header.version == 3).then_some(header)
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
fn
|
|
53
|
-
|
|
54
|
-
expected_session_id: &SessionId,
|
|
55
|
-
spawn_cwd: &Path,
|
|
56
|
-
spawned_at: Option<&str>,
|
|
57
|
-
) -> bool {
|
|
58
|
-
if header.id != expected_session_id.as_str() || !paths_equal(&header.cwd, spawn_cwd) {
|
|
52
|
+
fn header_matches_spawn(header: &PiSessionHeader, spawn_cwd: &Path, spawned_at: Option<&str>) -> bool {
|
|
53
|
+
if !paths_equal(&header.cwd, spawn_cwd) {
|
|
59
54
|
return false;
|
|
60
55
|
}
|
|
61
56
|
let Ok(header_timestamp) = chrono::DateTime::parse_from_rfc3339(&header.timestamp) else {
|
|
@@ -70,6 +65,16 @@ fn header_matches(
|
|
|
70
65
|
header_timestamp >= spawned_at
|
|
71
66
|
}
|
|
72
67
|
|
|
68
|
+
fn header_matches(
|
|
69
|
+
header: &PiSessionHeader,
|
|
70
|
+
expected_session_id: &SessionId,
|
|
71
|
+
spawn_cwd: &Path,
|
|
72
|
+
spawned_at: Option<&str>,
|
|
73
|
+
) -> bool {
|
|
74
|
+
header.id == expected_session_id.as_str()
|
|
75
|
+
&& header_matches_spawn(header, spawn_cwd, spawned_at)
|
|
76
|
+
}
|
|
77
|
+
|
|
73
78
|
fn collect_jsonl(root: &Path, out: &mut Vec<PathBuf>) -> Result<(), ProviderError> {
|
|
74
79
|
let entries = std::fs::read_dir(root)
|
|
75
80
|
.map_err(|error| ProviderError::Io(format!("{}: {error}", root.display())))?;
|
|
@@ -125,15 +130,14 @@ pub(crate) fn validate_exact_backing(
|
|
|
125
130
|
|
|
126
131
|
/// ---
|
|
127
132
|
/// purpose: 仅在 recorded seat root 内递归捕获 Pi session header 候选
|
|
128
|
-
/// returns:
|
|
133
|
+
/// returns: 有预期 id 时按 id/cwd/timestamp 匹配;否则读取 Pi header 自己的 id,并按 cwd/timestamp 匹配
|
|
129
134
|
/// errors: root 内目录枚举失败时返回 ProviderError
|
|
130
135
|
/// ---
|
|
131
136
|
pub(super) fn scan_session_store(
|
|
132
137
|
context: &CaptureSessionContext,
|
|
133
138
|
) -> Result<Vec<CapturedSessionCandidate>, ProviderError> {
|
|
134
|
-
let (Some(root), Some(
|
|
139
|
+
let (Some(root), Some(spawned_at)) = (
|
|
135
140
|
context.provider_projects_root.as_deref(),
|
|
136
|
-
context.expected_session_id.as_ref(),
|
|
137
141
|
context.spawned_at.as_deref(),
|
|
138
142
|
) else {
|
|
139
143
|
return Ok(Vec::new());
|
|
@@ -149,15 +153,24 @@ pub(super) fn scan_session_store(
|
|
|
149
153
|
.into_iter()
|
|
150
154
|
.filter_map(|path| {
|
|
151
155
|
let header = read_header(&path)?;
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
156
|
+
let session_id = if let Some(expected_session_id) = context.expected_session_id.as_ref() {
|
|
157
|
+
if !header_matches(
|
|
158
|
+
&header,
|
|
159
|
+
expected_session_id,
|
|
160
|
+
&context.spawn_cwd,
|
|
161
|
+
Some(spawned_at),
|
|
162
|
+
) {
|
|
163
|
+
return None;
|
|
164
|
+
}
|
|
165
|
+
expected_session_id.clone()
|
|
166
|
+
} else if header_matches_spawn(&header, &context.spawn_cwd, Some(spawned_at)) {
|
|
167
|
+
SessionId::new(header.id)
|
|
168
|
+
} else {
|
|
169
|
+
return None;
|
|
170
|
+
};
|
|
171
|
+
Some(CapturedSessionCandidate {
|
|
159
172
|
captured: CapturedSession {
|
|
160
|
-
session_id: Some(
|
|
173
|
+
session_id: Some(session_id),
|
|
161
174
|
rollout_path: Some(RolloutPath::new(path)),
|
|
162
175
|
captured_via: CaptureVia::FsWatch,
|
|
163
176
|
attribution_confidence: Confidence::High,
|
|
@@ -36,8 +36,8 @@ fn command_helpers_keep_provider_argv_bytes_and_order() {
|
|
|
36
36
|
extension: std::path::Path::new("extension.ts"), model: Some("vendor/model"),
|
|
37
37
|
effort: Some(ProviderEffort::XHigh), system_prompt: raw,
|
|
38
38
|
session_dir: Some(std::path::Path::new("sessions")),
|
|
39
|
-
session: pi::PiSessionSelector::Fresh
|
|
40
|
-
}).expect("pi"), ["pi", "-e", "extension.ts", "--model", "vendor/model", "--thinking", "xhigh", "--append-system-prompt", raw, "--session-dir", "sessions", "--
|
|
39
|
+
session: pi::PiSessionSelector::Fresh, agent_id: "worker",
|
|
40
|
+
}).expect("pi"), ["pi", "-e", "extension.ts", "--model", "vendor/model", "--thinking", "xhigh", "--append-system-prompt", raw, "--session-dir", "sessions", "--name", "worker"]);
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
#[test]
|
|
@@ -116,7 +116,8 @@ pub(crate) fn aliases(provider: Provider) -> &'static [&'static str] {
|
|
|
116
116
|
/// Executable name we exec for the worker. `Claude` and `ClaudeCode` both
|
|
117
117
|
/// resolve to `claude` — the distinction is in state semantics
|
|
118
118
|
/// (`ClaudeCode` is the canonical CLI; `Claude` is a legacy alias kept for
|
|
119
|
-
/// older specs).
|
|
119
|
+
/// older specs). Spawn this public name. Do not replace it with a
|
|
120
|
+
/// canonicalized deep binary; that skips the user's wrapper.
|
|
120
121
|
pub(crate) fn command_name(provider: Provider) -> &'static str {
|
|
121
122
|
match provider {
|
|
122
123
|
Provider::Claude | Provider::ClaudeCode => "claude",
|