@team-agent/installer 0.5.125 → 0.5.127
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/crates/team-agent/src/cli/diagnose.rs +0 -137
- package/crates/team-agent/src/cli/emit.rs +13 -8
- package/crates/team-agent/src/cli/grok_slot.rs +88 -3
- package/crates/team-agent/src/cli/intent/runtime.rs +6 -4
- package/crates/team-agent/src/cli/intent/runtime_tests.rs +55 -10
- package/crates/team-agent/src/cli/mod.rs +35 -29
- package/crates/team-agent/src/cli/models.rs +33 -944
- package/crates/team-agent/src/cli/tests/leader_watch.rs +1 -1
- package/crates/team-agent/src/cli/tests/mod.rs +3 -3
- package/crates/team-agent/src/cli/tests/run_delegation.rs +8 -7
- package/crates/team-agent/src/cli/tests/status_send.rs +2 -2
- package/crates/team-agent/src/compiler/tests.rs +54 -12
- package/crates/team-agent/src/compiler.rs +7 -205
- package/crates/team-agent/src/contract_runtime/backend.rs +97 -38
- package/crates/team-agent/src/contract_runtime/commands.rs +335 -4
- package/crates/team-agent/src/contract_runtime/config.rs +12 -8
- package/crates/team-agent/src/contract_runtime/fork.rs +368 -0
- package/crates/team-agent/src/contract_runtime/framework.rs +8 -13
- package/crates/team-agent/src/contract_runtime/mod.rs +1 -0
- package/crates/team-agent/src/contract_runtime/registry.rs +100 -60
- package/crates/team-agent/src/coordinator/steps/abnormal.rs +45 -5
- package/crates/team-agent/src/coordinator/tests/api_error_recovery.rs +54 -16
- package/crates/team-agent/src/coordinator/tests/energy.rs +4 -4
- package/crates/team-agent/src/coordinator/tests/health_sync.rs +2 -44
- 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/leader/start.rs +1 -1
- package/crates/team-agent/src/lifecycle/launch/add_agent_state.rs +2 -195
- package/crates/team-agent/src/lifecycle/launch/clone_agent.rs +11 -27
- package/crates/team-agent/src/lifecycle/launch/fork_agent.rs +22 -200
- package/crates/team-agent/src/lifecycle/launch/fork_entry.rs +6 -87
- package/crates/team-agent/src/lifecycle/launch/mcp_config.rs +5 -496
- package/crates/team-agent/src/lifecycle/launch/pi_mcp.rs +74 -244
- package/crates/team-agent/src/lifecycle/launch/quick_start.rs +2 -26
- package/crates/team-agent/src/lifecycle/launch/role_source.rs +5 -0
- package/crates/team-agent/src/lifecycle/launch/spawn.rs +26 -51
- package/crates/team-agent/src/lifecycle/launch.rs +3 -34
- package/crates/team-agent/src/lifecycle/profile_launch.rs +18 -373
- package/crates/team-agent/src/lifecycle/restart/common.rs +45 -463
- 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 +0 -2
- package/crates/team-agent/src/lifecycle/role_config.rs +40 -13
- 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 +38 -236
- package/crates/team-agent/src/lifecycle/tests/claude_profile_launch_red.rs +8 -320
- package/crates/team-agent/src/lifecycle/tests/cli_argv_routing_red.rs +106 -186
- package/crates/team-agent/src/lifecycle/tests/clone_fork_copilot_perms_red.rs +4 -334
- package/crates/team-agent/src/lifecycle/tests/communication_mode_runtime_contract_red.rs +19 -15
- package/crates/team-agent/src/lifecycle/tests/copilot_provider_red.rs +2 -2
- package/crates/team-agent/src/lifecycle/tests/core.rs +33 -58
- package/crates/team-agent/src/lifecycle/tests/f032_startup_prompt_best_effort_red.rs +22 -8
- 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 +3 -51
- 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 +162 -284
- 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/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 +6 -18
- package/crates/team-agent/src/lifecycle/tests/pi_command_red.rs +52 -70
- package/crates/team-agent/src/lifecycle/tests/pi_dual_entry_red.rs +4 -157
- package/crates/team-agent/src/lifecycle/tests/pi_executable_mcp_red.rs +10 -302
- package/crates/team-agent/src/lifecycle/tests/pi_lifecycle_doctor_red.rs +1 -68
- package/crates/team-agent/src/lifecycle/tests/pi_native_mcp_capability_red.rs +1 -19
- package/crates/team-agent/src/lifecycle/tests/pi_session_delivery_red.rs +2 -100
- package/crates/team-agent/src/lifecycle/tests/quick_start_worker_readiness_red.rs +15 -14
- 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 -1478
- 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 +2 -254
- 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 +39 -38
- package/crates/team-agent/src/lifecycle/tests/worker_spawn_env_red.rs +42 -97
- package/crates/team-agent/src/lifecycle/tests.rs +0 -7
- package/crates/team-agent/src/lifecycle/types.rs +2 -21
- package/crates/team-agent/src/mcp_server/readiness_tests.rs +15 -17
- package/crates/team-agent/src/messaging/delivery.rs +14 -195
- package/crates/team-agent/src/messaging/delivery_consumption_tests.rs +5 -5
- package/crates/team-agent/src/messaging/tests/dup_inject.rs +68 -69
- package/crates/team-agent/src/messaging/tests/main_preserved.rs +2 -2
- package/crates/team-agent/src/messaging/tests/runtime.rs +5 -5
- package/crates/team-agent/src/messaging/tests/spine.rs +30 -32
- package/crates/team-agent/src/messaging/tests/wave2.rs +13 -20
- package/crates/team-agent/src/provider/adapter.rs +71 -572
- package/crates/team-agent/src/provider/adapters/mod.rs +6 -8
- package/crates/team-agent/src/provider/model_catalog.rs +13 -201
- package/crates/team-agent/src/provider/session/capture.rs +11 -211
- package/crates/team-agent/src/provider/session/context_fork/outcome.rs +8 -24
- package/crates/team-agent/src/provider/session/context_fork.rs +29 -240
- package/crates/team-agent/src/provider/session/mod.rs +2 -3
- package/crates/team-agent/src/provider/session_scan/common.rs +27 -87
- package/crates/team-agent/src/provider/session_scan/pi.rs +1 -34
- package/crates/team-agent/src/provider/session_scan.rs +7 -23
- package/crates/team-agent/src/provider/tests/adapter.rs +66 -204
- package/crates/team-agent/src/provider/tests/command_helpers.rs +3 -29
- package/crates/team-agent/src/provider/tests/idle.rs +0 -68
- package/crates/team-agent/src/provider/types.rs +0 -4
- package/crates/team-agent/src/provider/wire.rs +77 -23
- 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/repository/tests.rs +2 -2
- package/crates/team-agent/src/tmux_backend.rs +4 -3
- package/package.json +4 -4
- package/skills/team-agent/SKILL.md +8 -5
- package/skills/team-agent/command-coverage.json +29 -1
- package/skills/team-agent/docs/reference/team-agent-operator.md +7 -3
- package/skills/team-agent/references/team-agent-operator.md +7 -3
- package/crates/team-agent/src/lifecycle/launch/grok_per_seat.rs +0 -260
- package/crates/team-agent/src/lifecycle/restart/avatar.rs +0 -1805
- package/crates/team-agent/src/lifecycle/tests/claude_compatible_config_red.rs +0 -325
- 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/lifecycle/tests/pi_compiler_red.rs +0 -210
- package/crates/team-agent/src/lifecycle/tests/pi_fork_session_inheritance_red.rs +0 -1409
- package/crates/team-agent/src/provider/adapters/claude.rs +0 -78
- package/crates/team-agent/src/provider/adapters/claude_fork.rs +0 -131
- 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/adapters/pi.rs +0 -100
- package/crates/team-agent/src/provider/session/context_fork/claude.rs +0 -123
- package/crates/team-agent/src/provider/session/context_fork/codex.rs +0 -514
- package/crates/team-agent/src/provider/session_scan/claude.rs +0 -523
- package/crates/team-agent/src/provider/session_scan/codex.rs +0 -326
- package/crates/team-agent/src/provider/session_scan/grok.rs +0 -288
- package/crates/team-agent/src/test_support/models_timeout_fixture.rs +0 -144
|
@@ -275,6 +275,17 @@ pub(super) fn spawn_agent_window(
|
|
|
275
275
|
// (agent row → active_team_key) for back-compat with non-restart callers.
|
|
276
276
|
owner_team_id_override: Option<&str>,
|
|
277
277
|
) -> Result<SpawnedAgentWindow, LifecycleError> {
|
|
278
|
+
// A pre-upgrade Claude Code, Codex, Grok or Pi worker row has no legacy
|
|
279
|
+
// runtime left; refuse before any MCP file, profile or pane side effect.
|
|
280
|
+
if let Some(retired) = agent
|
|
281
|
+
.get("provider")
|
|
282
|
+
.and_then(serde_json::Value::as_str)
|
|
283
|
+
.filter(|provider| crate::provider::wire::is_retired_provider(provider))
|
|
284
|
+
{
|
|
285
|
+
return Err(LifecycleError::Provider(
|
|
286
|
+
crate::provider::wire::retired_provider_error(retired).into(),
|
|
287
|
+
));
|
|
288
|
+
}
|
|
278
289
|
let provider = agent_provider(agent);
|
|
279
290
|
let auth_mode = agent_auth_mode(agent);
|
|
280
291
|
let model = agent.get("model").and_then(|v| v.as_str());
|
|
@@ -337,16 +348,12 @@ pub(super) fn spawn_agent_window(
|
|
|
337
348
|
agent_id.as_str(),
|
|
338
349
|
team_id.as_deref().unwrap_or(""),
|
|
339
350
|
);
|
|
340
|
-
let mcp_config_path =
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
&mcp_config,
|
|
347
|
-
Some(provider),
|
|
348
|
-
)?)
|
|
349
|
-
};
|
|
351
|
+
let mcp_config_path = crate::lifecycle::launch::write_worker_mcp_config_for_provider(
|
|
352
|
+
workspace,
|
|
353
|
+
agent_id.as_str(),
|
|
354
|
+
&mcp_config,
|
|
355
|
+
Some(provider),
|
|
356
|
+
)?;
|
|
350
357
|
let profile_launch =
|
|
351
358
|
crate::lifecycle::profile_launch::prepare_provider_profile_launch_from_json(
|
|
352
359
|
workspace,
|
|
@@ -379,65 +386,18 @@ pub(super) fn spawn_agent_window(
|
|
|
379
386
|
agent_id_hint: Some(agent_id.as_str()),
|
|
380
387
|
effort: restart_effort,
|
|
381
388
|
};
|
|
382
|
-
let
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
.map(std::path::PathBuf::from)
|
|
389
|
-
})
|
|
390
|
-
.flatten();
|
|
391
|
-
let spawn_cwd = spawn_cwd_override
|
|
392
|
-
.or(pi_spawn_cwd.as_deref())
|
|
393
|
-
.unwrap_or(workspace);
|
|
394
|
-
let mut plan = if provider == crate::provider::Provider::Pi {
|
|
395
|
-
let request = crate::lifecycle::launch::pi_mcp::PiMaterializeRequest {
|
|
396
|
-
workspace,
|
|
397
|
-
team_id: team_id.as_deref().unwrap_or(""),
|
|
398
|
-
agent_id: agent_id.as_str(),
|
|
399
|
-
model: command_model,
|
|
400
|
-
effort: restart_effort,
|
|
401
|
-
system_prompt: &system_prompt,
|
|
402
|
-
team_mcp_tools: &["send_message", "report_result", "get_team_status"],
|
|
403
|
-
mcp_config: &mcp_config,
|
|
404
|
-
session_scope: crate::lifecycle::launch::pi_mcp::PiSessionScope::Isolated,
|
|
405
|
-
};
|
|
406
|
-
match resume_session_id {
|
|
407
|
-
Some(session_id) => {
|
|
408
|
-
let rollout_path = agent_rollout_path(agent).ok_or_else(|| {
|
|
409
|
-
LifecycleError::RequirementUnmet(
|
|
410
|
-
"Pi resume requires the persisted exact session path".to_string(),
|
|
411
|
-
)
|
|
412
|
-
})?;
|
|
413
|
-
crate::lifecycle::launch::pi_mcp::materialize_pi_resume_plan(
|
|
414
|
-
request,
|
|
415
|
-
session_id,
|
|
416
|
-
rollout_path.as_path(),
|
|
417
|
-
spawn_cwd,
|
|
418
|
-
)
|
|
419
|
-
}
|
|
420
|
-
None => crate::lifecycle::launch::pi_mcp::materialize_pi_plan(request),
|
|
421
|
-
}
|
|
422
|
-
.map_err(|e| LifecycleError::Provider(e.to_string()))?
|
|
423
|
-
} else {
|
|
424
|
-
match resume_session_id {
|
|
425
|
-
Some(session_id) => adapter
|
|
426
|
-
.build_resume_command_plan(Some(session_id), context)
|
|
427
|
-
.map_err(|e| LifecycleError::Provider(e.to_string()))?,
|
|
428
|
-
None => adapter
|
|
429
|
-
.build_command_plan(context)
|
|
430
|
-
.map_err(|e| LifecycleError::Provider(e.to_string()))?,
|
|
431
|
-
}
|
|
432
|
-
};
|
|
389
|
+
let spawn_cwd = spawn_cwd_override.unwrap_or(workspace);
|
|
390
|
+
let mut plan = match resume_session_id {
|
|
391
|
+
Some(session_id) => adapter.build_resume_command_plan(Some(session_id), context),
|
|
392
|
+
None => adapter.build_command_plan(context),
|
|
393
|
+
}
|
|
394
|
+
.map_err(|e| LifecycleError::Provider(e.to_string()))?;
|
|
433
395
|
if !plan.managed_mcp_config && !profile_launch.managed_mcp_config {
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
);
|
|
440
|
-
}
|
|
396
|
+
crate::lifecycle::launch::point_native_mcp_config_at_file(
|
|
397
|
+
&mut plan.argv,
|
|
398
|
+
provider,
|
|
399
|
+
&mcp_config_path,
|
|
400
|
+
);
|
|
441
401
|
}
|
|
442
402
|
crate::lifecycle::launch::fill_spawn_placeholders_full(
|
|
443
403
|
&mut plan.argv,
|
|
@@ -464,16 +424,8 @@ pub(super) fn spawn_agent_window(
|
|
|
464
424
|
&mut env,
|
|
465
425
|
)?;
|
|
466
426
|
}
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
crate::lifecycle::launch::apply_grok_mcp_overlay(workspace, &mcp_config)?;
|
|
470
|
-
}
|
|
471
|
-
// Non-Pi spawn cwd is override-or-workspace (E56: ignore drifted state
|
|
472
|
-
// `.team/runtime/<team_key>/`). Pi resume uses captured agent.spawn_cwd
|
|
473
|
-
// already resolved above so exact-path header checks match capture.
|
|
474
|
-
// 0.4.x provider effort MVP step 9: scrub CLAUDE_EFFORT for Claude
|
|
475
|
-
// worker spawn so a parent shell env cannot silently override the
|
|
476
|
-
// framework's effort decision.
|
|
427
|
+
// Spawn cwd is override-or-workspace (E56: ignore drifted state
|
|
428
|
+
// `.team/runtime/<team_key>/`).
|
|
477
429
|
let env_unset = crate::layout::worker_env::isolate_worker_spawn_env(
|
|
478
430
|
provider,
|
|
479
431
|
&mut env,
|
|
@@ -665,7 +617,7 @@ pub(super) fn spawn_agent_window(
|
|
|
665
617
|
profile_launch,
|
|
666
618
|
layout_placement: layout_placement.cloned(),
|
|
667
619
|
spawn_cwd: spawn_cwd.to_path_buf(),
|
|
668
|
-
mcp_config_path,
|
|
620
|
+
mcp_config_path: Some(mcp_config_path),
|
|
669
621
|
owner_team_id: team_id,
|
|
670
622
|
})
|
|
671
623
|
}
|
|
@@ -1197,7 +1149,7 @@ pub(super) fn session_live_or_default(
|
|
|
1197
1149
|
|
|
1198
1150
|
/// ---
|
|
1199
1151
|
/// purpose: 取席位行的 provider
|
|
1200
|
-
/// returns:
|
|
1152
|
+
/// returns: 解析成功用它,缺失或不认识时退到已退役的 legacy codex 键(其后一律拒绝,不会起席)
|
|
1201
1153
|
/// ---
|
|
1202
1154
|
pub(super) fn agent_provider(agent: &serde_json::Value) -> Provider {
|
|
1203
1155
|
agent
|
|
@@ -1318,11 +1270,11 @@ pub(crate) fn session_identity_probe_for_agent(
|
|
|
1318
1270
|
}
|
|
1319
1271
|
|
|
1320
1272
|
/// ---
|
|
1321
|
-
/// purpose:
|
|
1273
|
+
/// purpose: 共享会话身份判定(Pi fork 血统随遗留 Pi worker 运行时一并移除)
|
|
1322
1274
|
/// params:
|
|
1323
|
-
/// workspace/state/agent:
|
|
1275
|
+
/// workspace/state/agent: 保留调用形状
|
|
1324
1276
|
/// rollout_path: 当前席位的精确 backing
|
|
1325
|
-
/// returns:
|
|
1277
|
+
/// returns: 字面身份判定结果
|
|
1326
1278
|
/// ---
|
|
1327
1279
|
pub(crate) fn session_identity_probe_for_agent_with_fork_ancestry(
|
|
1328
1280
|
workspace: &Path,
|
|
@@ -1332,102 +1284,8 @@ pub(crate) fn session_identity_probe_for_agent_with_fork_ancestry(
|
|
|
1332
1284
|
provider: Provider,
|
|
1333
1285
|
rollout_path: Option<&RolloutPath>,
|
|
1334
1286
|
) -> SessionIdentityProbeResult {
|
|
1335
|
-
let
|
|
1336
|
-
|
|
1337
|
-
|| !pi_fork_ancestor_identity_is_valid(
|
|
1338
|
-
workspace,
|
|
1339
|
-
state,
|
|
1340
|
-
agent_id,
|
|
1341
|
-
agent,
|
|
1342
|
-
provider,
|
|
1343
|
-
rollout_path,
|
|
1344
|
-
probe.embedded_agent_id.as_deref(),
|
|
1345
|
-
)
|
|
1346
|
-
{
|
|
1347
|
-
return probe;
|
|
1348
|
-
}
|
|
1349
|
-
probe.identity_ok = Some(true);
|
|
1350
|
-
probe
|
|
1351
|
-
}
|
|
1352
|
-
|
|
1353
|
-
fn pi_fork_ancestor_identity_is_valid(
|
|
1354
|
-
workspace: &Path,
|
|
1355
|
-
state: &serde_json::Value,
|
|
1356
|
-
agent_id: &AgentId,
|
|
1357
|
-
agent: &serde_json::Value,
|
|
1358
|
-
provider: Provider,
|
|
1359
|
-
rollout_path: Option<&RolloutPath>,
|
|
1360
|
-
embedded_agent_id: Option<&str>,
|
|
1361
|
-
) -> bool {
|
|
1362
|
-
if provider != Provider::Pi
|
|
1363
|
-
|| agent.get("attribution_ambiguous").and_then(serde_json::Value::as_bool) == Some(true)
|
|
1364
|
-
|| agent.get("capture_state").and_then(serde_json::Value::as_str)
|
|
1365
|
-
== Some("attribution_ambiguous")
|
|
1366
|
-
|| !matches!(
|
|
1367
|
-
agent
|
|
1368
|
-
.get("attribution_confidence")
|
|
1369
|
-
.and_then(serde_json::Value::as_str),
|
|
1370
|
-
Some("high" | "medium")
|
|
1371
|
-
)
|
|
1372
|
-
{
|
|
1373
|
-
return false;
|
|
1374
|
-
}
|
|
1375
|
-
let (Some(embedded_agent_id), Some(forked_from), Some(target_path)) = (
|
|
1376
|
-
embedded_agent_id,
|
|
1377
|
-
agent
|
|
1378
|
-
.get("forked_from")
|
|
1379
|
-
.and_then(serde_json::Value::as_str)
|
|
1380
|
-
.filter(|value| !value.is_empty()),
|
|
1381
|
-
rollout_path.map(RolloutPath::as_path),
|
|
1382
|
-
) else {
|
|
1383
|
-
return false;
|
|
1384
|
-
};
|
|
1385
|
-
if forked_from != embedded_agent_id || forked_from == agent_id.as_str() {
|
|
1386
|
-
return false;
|
|
1387
|
-
}
|
|
1388
|
-
let Some(source_agent) = state
|
|
1389
|
-
.get("agents")
|
|
1390
|
-
.and_then(|agents| agents.get(forked_from))
|
|
1391
|
-
.filter(|source| agent_provider(source) == Provider::Pi)
|
|
1392
|
-
else {
|
|
1393
|
-
return false;
|
|
1394
|
-
};
|
|
1395
|
-
let Some(source_path) = agent_rollout_path(source_agent) else {
|
|
1396
|
-
return false;
|
|
1397
|
-
};
|
|
1398
|
-
if source_path.as_path() == target_path {
|
|
1399
|
-
return false;
|
|
1400
|
-
}
|
|
1401
|
-
let (Some(session_id), Ok(target_path), Some(target_root)) = (
|
|
1402
|
-
agent_session_id(agent),
|
|
1403
|
-
std::fs::canonicalize(target_path),
|
|
1404
|
-
agent
|
|
1405
|
-
.get("claude_projects_root")
|
|
1406
|
-
.and_then(serde_json::Value::as_str)
|
|
1407
|
-
.filter(|path| !path.is_empty())
|
|
1408
|
-
.map(std::path::PathBuf::from),
|
|
1409
|
-
) else {
|
|
1410
|
-
return false;
|
|
1411
|
-
};
|
|
1412
|
-
let Ok(target_root) = std::fs::canonicalize(target_root) else {
|
|
1413
|
-
return false;
|
|
1414
|
-
};
|
|
1415
|
-
if !target_path.starts_with(target_root)
|
|
1416
|
-
|| std::fs::canonicalize(source_path.as_path())
|
|
1417
|
-
.is_ok_and(|source_path| source_path == target_path)
|
|
1418
|
-
|| !resume_backing_probe_for_agent(
|
|
1419
|
-
workspace,
|
|
1420
|
-
agent_id,
|
|
1421
|
-
agent,
|
|
1422
|
-
provider,
|
|
1423
|
-
&session_id,
|
|
1424
|
-
rollout_path,
|
|
1425
|
-
)
|
|
1426
|
-
.exists
|
|
1427
|
-
{
|
|
1428
|
-
return false;
|
|
1429
|
-
}
|
|
1430
|
-
true
|
|
1287
|
+
let _ = (workspace, state, agent);
|
|
1288
|
+
session_identity_probe_for_agent(agent_id, provider, rollout_path)
|
|
1431
1289
|
}
|
|
1432
1290
|
|
|
1433
1291
|
/// ---
|
|
@@ -1456,69 +1314,20 @@ pub(super) fn resume_backing_probe_for_agent(
|
|
|
1456
1314
|
let _ = (workspace, agent_id, agent, session_id, rollout_path);
|
|
1457
1315
|
false
|
|
1458
1316
|
}
|
|
1459
|
-
Provider::Codex => {
|
|
1460
|
-
let rollout_ok = rollout_path_exists(rollout_path);
|
|
1461
|
-
let scan_roots = codex_session_transcript_scan_roots(agent, rollout_path);
|
|
1462
|
-
for root in &scan_roots {
|
|
1463
|
-
checked_paths.push(root.clone());
|
|
1464
|
-
}
|
|
1465
|
-
rollout_ok
|
|
1466
|
-
|| codex_session_transcript_exists_with_roots(session_id.as_str(), &scan_roots)
|
|
1467
|
-
}
|
|
1468
|
-
Provider::Claude | Provider::ClaudeCode => {
|
|
1469
|
-
let rollout_ok = rollout_path_exists(rollout_path);
|
|
1470
|
-
let projects_root = claude_projects_root_for_agent(agent);
|
|
1471
|
-
if let Some(root) = projects_root.as_ref() {
|
|
1472
|
-
checked_paths.push(root.clone());
|
|
1473
|
-
}
|
|
1474
|
-
let event_log_path = workspace.join(".team/logs/events.jsonl");
|
|
1475
|
-
checked_paths.push(event_log_path);
|
|
1476
|
-
rollout_ok
|
|
1477
|
-
|| event_log_transcript_exists(workspace, agent_id.as_str(), session_id.as_str())
|
|
1478
|
-
|| projects_root.is_some_and(|root| {
|
|
1479
|
-
claude_project_transcript_exists_under(&root, session_id.as_str())
|
|
1480
|
-
})
|
|
1481
|
-
}
|
|
1482
1317
|
Provider::Copilot => {
|
|
1483
1318
|
if let Some(home) = std::env::var_os("HOME").map(PathBuf::from) {
|
|
1484
1319
|
checked_paths.push(home.join(".copilot/session-store.db"));
|
|
1485
1320
|
}
|
|
1486
1321
|
copilot_session_store_has_session(session_id.as_str())
|
|
1487
1322
|
}
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
session_id.as_str(),
|
|
1497
|
-
) {
|
|
1498
|
-
Some(dir) => {
|
|
1499
|
-
checked_paths.push(dir.clone());
|
|
1500
|
-
crate::provider::session_scan::grok::grok_session_archive_present(&dir)
|
|
1501
|
-
}
|
|
1502
|
-
None => false,
|
|
1503
|
-
}
|
|
1504
|
-
}
|
|
1505
|
-
Provider::Pi => {
|
|
1506
|
-
let spawn_cwd = agent
|
|
1507
|
-
.get("spawn_cwd")
|
|
1508
|
-
.and_then(serde_json::Value::as_str)
|
|
1509
|
-
.filter(|value| !value.is_empty())
|
|
1510
|
-
.map(PathBuf::from)
|
|
1511
|
-
.unwrap_or_else(|| workspace.to_path_buf());
|
|
1512
|
-
rollout_path.is_some_and(|path| {
|
|
1513
|
-
crate::provider::session_scan::pi::validate_exact_backing(
|
|
1514
|
-
path.as_path(),
|
|
1515
|
-
session_id,
|
|
1516
|
-
&spawn_cwd,
|
|
1517
|
-
)
|
|
1518
|
-
.is_ok()
|
|
1519
|
-
})
|
|
1520
|
-
}
|
|
1521
|
-
Provider::GeminiCli | Provider::Fake => false,
|
|
1323
|
+
// Claude Code, Codex, Grok and Pi workers run only through their contract leaves.
|
|
1324
|
+
Provider::Claude
|
|
1325
|
+
| Provider::ClaudeCode
|
|
1326
|
+
| Provider::Codex
|
|
1327
|
+
| Provider::Grok
|
|
1328
|
+
| Provider::Pi
|
|
1329
|
+
| Provider::GeminiCli
|
|
1330
|
+
| Provider::Fake => false,
|
|
1522
1331
|
};
|
|
1523
1332
|
|
|
1524
1333
|
// Deduplicate while preserving order (HashSet would lose deterministic
|
|
@@ -1552,153 +1361,6 @@ pub(super) fn provider_wire_supports_resume(provider: &str) -> bool {
|
|
|
1552
1361
|
.unwrap_or(false)
|
|
1553
1362
|
}
|
|
1554
1363
|
|
|
1555
|
-
fn rollout_path_exists(rollout_path: Option<&RolloutPath>) -> bool {
|
|
1556
|
-
rollout_path
|
|
1557
|
-
.as_ref()
|
|
1558
|
-
.is_some_and(|path| path.as_path().exists())
|
|
1559
|
-
}
|
|
1560
|
-
|
|
1561
|
-
fn event_log_transcript_exists(workspace: &Path, agent_id: &str, session_id: &str) -> bool {
|
|
1562
|
-
let Ok(events) = crate::event_log::EventLog::new(workspace).tail(0) else {
|
|
1563
|
-
return false;
|
|
1564
|
-
};
|
|
1565
|
-
events.iter().rev().any(|event| {
|
|
1566
|
-
event.get("event").and_then(serde_json::Value::as_str) == Some("session.captured")
|
|
1567
|
-
&& ["agent_id", "worker_id"]
|
|
1568
|
-
.iter()
|
|
1569
|
-
.any(|key| event.get(*key).and_then(serde_json::Value::as_str) == Some(agent_id))
|
|
1570
|
-
&& event.get("session_id").and_then(serde_json::Value::as_str) == Some(session_id)
|
|
1571
|
-
&& event_transcript_path(event).is_some_and(|path| path.exists())
|
|
1572
|
-
})
|
|
1573
|
-
}
|
|
1574
|
-
|
|
1575
|
-
fn event_transcript_path(event: &serde_json::Value) -> Option<PathBuf> {
|
|
1576
|
-
event
|
|
1577
|
-
.get("rollout_path")
|
|
1578
|
-
.or_else(|| event.get("transcript_path"))
|
|
1579
|
-
.and_then(serde_json::Value::as_str)
|
|
1580
|
-
.filter(|path| !path.is_empty())
|
|
1581
|
-
.map(PathBuf::from)
|
|
1582
|
-
}
|
|
1583
|
-
|
|
1584
|
-
/// E36 fix-B: a real Claude worker writes its session transcript to
|
|
1585
|
-
/// `<claude_projects_root>/<workspace-slug>/<session_id>.jsonl` even when neither
|
|
1586
|
-
/// `rollout_path` was persisted to state nor a `session.captured` event was logged.
|
|
1587
|
-
/// That landed transcript is itself a valid resume backing — restart was wrongly
|
|
1588
|
-
/// refusing resumable workers because it only checked the two paths above. Scan the
|
|
1589
|
-
/// projects root recursively for `<session_id>.jsonl` (session_id is a unique UUID,
|
|
1590
|
-
/// so we avoid recomputing the project-dir slug, which is brittle for non-ASCII
|
|
1591
|
-
/// workspace paths).
|
|
1592
|
-
fn claude_project_transcript_exists(agent: &serde_json::Value, session_id: &str) -> bool {
|
|
1593
|
-
let Some(root) = claude_projects_root_for_agent(agent) else {
|
|
1594
|
-
return false;
|
|
1595
|
-
};
|
|
1596
|
-
claude_project_transcript_exists_under(&root, session_id)
|
|
1597
|
-
}
|
|
1598
|
-
|
|
1599
|
-
fn claude_projects_root_for_agent(agent: &serde_json::Value) -> Option<PathBuf> {
|
|
1600
|
-
agent
|
|
1601
|
-
.get("claude_projects_root")
|
|
1602
|
-
.and_then(serde_json::Value::as_str)
|
|
1603
|
-
.filter(|value| !value.is_empty())
|
|
1604
|
-
.map(PathBuf::from)
|
|
1605
|
-
.or_else(|| {
|
|
1606
|
-
std::env::var_os("HOME")
|
|
1607
|
-
.map(|home| PathBuf::from(home).join(".claude").join("projects"))
|
|
1608
|
-
})
|
|
1609
|
-
}
|
|
1610
|
-
|
|
1611
|
-
fn claude_project_transcript_exists_under(projects_root: &Path, session_id: &str) -> bool {
|
|
1612
|
-
if session_id.is_empty() {
|
|
1613
|
-
return false;
|
|
1614
|
-
}
|
|
1615
|
-
if !projects_root.is_dir() {
|
|
1616
|
-
return false;
|
|
1617
|
-
}
|
|
1618
|
-
let transcript_name = format!("{session_id}.jsonl");
|
|
1619
|
-
let Ok(project_dirs) = std::fs::read_dir(projects_root) else {
|
|
1620
|
-
return false;
|
|
1621
|
-
};
|
|
1622
|
-
project_dirs
|
|
1623
|
-
.flatten()
|
|
1624
|
-
.filter(|entry| entry.path().is_dir())
|
|
1625
|
-
.any(|entry| entry.path().join(&transcript_name).is_file())
|
|
1626
|
-
}
|
|
1627
|
-
|
|
1628
|
-
fn codex_session_transcript_exists(
|
|
1629
|
-
agent: &serde_json::Value,
|
|
1630
|
-
session_id: &str,
|
|
1631
|
-
rollout_path: Option<&RolloutPath>,
|
|
1632
|
-
) -> bool {
|
|
1633
|
-
let roots = codex_session_transcript_scan_roots(agent, rollout_path);
|
|
1634
|
-
codex_session_transcript_exists_with_roots(session_id, &roots)
|
|
1635
|
-
}
|
|
1636
|
-
|
|
1637
|
-
fn codex_session_transcript_scan_roots(
|
|
1638
|
-
agent: &serde_json::Value,
|
|
1639
|
-
rollout_path: Option<&RolloutPath>,
|
|
1640
|
-
) -> Vec<PathBuf> {
|
|
1641
|
-
let mut roots: Vec<PathBuf> = Vec::new();
|
|
1642
|
-
if let Some(parent) = rollout_path
|
|
1643
|
-
.map(RolloutPath::as_path)
|
|
1644
|
-
.and_then(Path::parent)
|
|
1645
|
-
.filter(|path| path.is_dir())
|
|
1646
|
-
{
|
|
1647
|
-
roots.push(parent.to_path_buf());
|
|
1648
|
-
}
|
|
1649
|
-
if let Some(root) = agent
|
|
1650
|
-
.get("codex_sessions_root")
|
|
1651
|
-
.and_then(serde_json::Value::as_str)
|
|
1652
|
-
.filter(|path| !path.is_empty())
|
|
1653
|
-
.map(PathBuf::from)
|
|
1654
|
-
.filter(|path| path.is_dir())
|
|
1655
|
-
{
|
|
1656
|
-
roots.push(root);
|
|
1657
|
-
}
|
|
1658
|
-
if let Some(root) = std::env::var_os("HOME")
|
|
1659
|
-
.map(PathBuf::from)
|
|
1660
|
-
.map(|home| home.join(".codex").join("sessions"))
|
|
1661
|
-
.filter(|path| path.is_dir())
|
|
1662
|
-
{
|
|
1663
|
-
roots.push(root);
|
|
1664
|
-
}
|
|
1665
|
-
roots.sort();
|
|
1666
|
-
roots.dedup();
|
|
1667
|
-
roots
|
|
1668
|
-
}
|
|
1669
|
-
|
|
1670
|
-
fn codex_session_transcript_exists_with_roots(session_id: &str, roots: &[PathBuf]) -> bool {
|
|
1671
|
-
if session_id.is_empty() {
|
|
1672
|
-
return false;
|
|
1673
|
-
}
|
|
1674
|
-
roots
|
|
1675
|
-
.iter()
|
|
1676
|
-
.any(|root| session_transcript_exists_under(root, session_id, 4))
|
|
1677
|
-
}
|
|
1678
|
-
|
|
1679
|
-
fn session_transcript_exists_under(root: &Path, session_id: &str, max_depth: usize) -> bool {
|
|
1680
|
-
let Ok(entries) = std::fs::read_dir(root) else {
|
|
1681
|
-
return false;
|
|
1682
|
-
};
|
|
1683
|
-
for entry in entries.flatten() {
|
|
1684
|
-
let path = entry.path();
|
|
1685
|
-
if path.is_file() {
|
|
1686
|
-
let Some(name) = path.file_name().and_then(|name| name.to_str()) else {
|
|
1687
|
-
continue;
|
|
1688
|
-
};
|
|
1689
|
-
if name.ends_with(".jsonl") && name.contains(session_id) {
|
|
1690
|
-
return true;
|
|
1691
|
-
}
|
|
1692
|
-
} else if max_depth > 0
|
|
1693
|
-
&& path.is_dir()
|
|
1694
|
-
&& session_transcript_exists_under(&path, session_id, max_depth.saturating_sub(1))
|
|
1695
|
-
{
|
|
1696
|
-
return true;
|
|
1697
|
-
}
|
|
1698
|
-
}
|
|
1699
|
-
false
|
|
1700
|
-
}
|
|
1701
|
-
|
|
1702
1364
|
fn copilot_session_store_has_session(session_id: &str) -> bool {
|
|
1703
1365
|
let Some(home) = std::env::var_os("HOME").map(PathBuf::from) else {
|
|
1704
1366
|
return false;
|
|
@@ -2387,84 +2049,4 @@ mod e36_transcript_backing_tests {
|
|
|
2387
2049
|
)
|
|
2388
2050
|
.is_err());
|
|
2389
2051
|
}
|
|
2390
|
-
|
|
2391
|
-
// E36 fix-B RED→GREEN: a real Claude worker that sent a message has its session
|
|
2392
|
-
// transcript landed at <projects_root>/<slug>/<session_id>.jsonl, but neither
|
|
2393
|
-
// rollout_path was persisted to state nor a session.captured event was logged.
|
|
2394
|
-
// Before the fix, claude_project_transcript_exists did not exist and restart
|
|
2395
|
-
// refused such a worker. This asserts the landed transcript is recognized.
|
|
2396
|
-
#[test]
|
|
2397
|
-
fn claude_project_transcript_is_recognized_without_rollout_or_capture_event() {
|
|
2398
|
-
let scratch = ScratchDir::new("recognized");
|
|
2399
|
-
let projects_root = scratch.path().join("projects");
|
|
2400
|
-
let slug_dir = projects_root.join("-Users-alauda-Documents-code---rust---9");
|
|
2401
|
-
std::fs::create_dir_all(&slug_dir).expect("mkdir slug");
|
|
2402
|
-
let session_id = "87742d3f-0b4e-4fc1-ad35-447ac2340b65";
|
|
2403
|
-
std::fs::write(slug_dir.join(format!("{session_id}.jsonl")), b"{}\n").expect("transcript");
|
|
2404
|
-
|
|
2405
|
-
let agent = serde_json::json!({
|
|
2406
|
-
"claude_projects_root": projects_root.to_string_lossy(),
|
|
2407
|
-
});
|
|
2408
|
-
assert!(
|
|
2409
|
-
claude_project_transcript_exists(&agent, session_id),
|
|
2410
|
-
"landed claude transcript must count as resume backing (E36 fix-B)"
|
|
2411
|
-
);
|
|
2412
|
-
}
|
|
2413
|
-
|
|
2414
|
-
#[test]
|
|
2415
|
-
fn missing_claude_transcript_is_not_backing() {
|
|
2416
|
-
let scratch = ScratchDir::new("missing");
|
|
2417
|
-
let projects_root = scratch.path().join("projects");
|
|
2418
|
-
std::fs::create_dir_all(&projects_root).expect("mkdir");
|
|
2419
|
-
let agent = serde_json::json!({
|
|
2420
|
-
"claude_projects_root": projects_root.to_string_lossy(),
|
|
2421
|
-
});
|
|
2422
|
-
assert!(
|
|
2423
|
-
!claude_project_transcript_exists(&agent, "deadbeef-0000-0000-0000-000000000000"),
|
|
2424
|
-
"no transcript file => no backing"
|
|
2425
|
-
);
|
|
2426
|
-
}
|
|
2427
|
-
|
|
2428
|
-
#[test]
|
|
2429
|
-
fn empty_session_id_is_not_backing() {
|
|
2430
|
-
let agent = serde_json::json!({});
|
|
2431
|
-
assert!(!claude_project_transcript_exists(&agent, ""));
|
|
2432
|
-
}
|
|
2433
|
-
|
|
2434
|
-
#[test]
|
|
2435
|
-
fn codex_session_transcript_is_recognized_when_rollout_path_is_stale() {
|
|
2436
|
-
let scratch = ScratchDir::new("codex-recognized");
|
|
2437
|
-
let sessions_root = scratch.path().join("sessions");
|
|
2438
|
-
let dated = sessions_root.join("2026").join("06").join("20");
|
|
2439
|
-
std::fs::create_dir_all(&dated).expect("mkdir dated sessions");
|
|
2440
|
-
let session_id = "019ee540-37ed-7a20-a141-1d654224d209";
|
|
2441
|
-
std::fs::write(
|
|
2442
|
-
dated.join(format!("rollout-2026-06-20T21-37-31-{session_id}.jsonl")),
|
|
2443
|
-
b"{}\n",
|
|
2444
|
-
)
|
|
2445
|
-
.expect("codex transcript");
|
|
2446
|
-
|
|
2447
|
-
let stale = RolloutPath::new(scratch.path().join("old").join("missing.jsonl"));
|
|
2448
|
-
let agent = serde_json::json!({
|
|
2449
|
-
"codex_sessions_root": sessions_root.to_string_lossy(),
|
|
2450
|
-
});
|
|
2451
|
-
assert!(
|
|
2452
|
-
codex_session_transcript_exists(&agent, session_id, Some(&stale)),
|
|
2453
|
-
"matching codex transcript under codex_sessions_root must count as resume backing"
|
|
2454
|
-
);
|
|
2455
|
-
}
|
|
2456
|
-
|
|
2457
|
-
#[test]
|
|
2458
|
-
fn missing_codex_session_transcript_is_not_backing() {
|
|
2459
|
-
let scratch = ScratchDir::new("codex-missing");
|
|
2460
|
-
let sessions_root = scratch.path().join("sessions");
|
|
2461
|
-
std::fs::create_dir_all(&sessions_root).expect("mkdir sessions");
|
|
2462
|
-
let agent = serde_json::json!({
|
|
2463
|
-
"codex_sessions_root": sessions_root.to_string_lossy(),
|
|
2464
|
-
});
|
|
2465
|
-
assert!(
|
|
2466
|
-
!codex_session_transcript_exists(&agent, "019ee540-ffff-7a20-a141-1d654224d209", None,),
|
|
2467
|
-
"no matching codex transcript => no backing"
|
|
2468
|
-
);
|
|
2469
|
-
}
|
|
2470
2052
|
}
|