@team-agent/installer 0.5.126 → 0.5.128
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Cargo.lock +1 -1
- package/Cargo.toml +1 -1
- package/README.md +11 -0
- package/crates/team-agent/src/cli/adapters.rs +3 -13
- package/crates/team-agent/src/cli/arguments.rs +4 -0
- package/crates/team-agent/src/cli/diagnose.rs +68 -91
- package/crates/team-agent/src/cli/emit.rs +61 -28
- package/crates/team-agent/src/cli/grok_slot.rs +88 -3
- package/crates/team-agent/src/cli/intent/runtime.rs +38 -9
- package/crates/team-agent/src/cli/intent/runtime_tests.rs +147 -11
- package/crates/team-agent/src/cli/intent/tests.rs +10 -12
- package/crates/team-agent/src/cli/intent.rs +1 -1
- package/crates/team-agent/src/cli/mod.rs +38 -9
- package/crates/team-agent/src/cli/models.rs +789 -186
- package/crates/team-agent/src/cli/schedule.rs +175 -0
- package/crates/team-agent/src/cli/send/persist.rs +0 -36
- package/crates/team-agent/src/cli/send/presentation.rs +1 -1
- package/crates/team-agent/src/cli/send.rs +108 -110
- package/crates/team-agent/src/cli/spec.rs +6 -0
- package/crates/team-agent/src/cli/status_port/brief.rs +5 -67
- package/crates/team-agent/src/cli/tests/leader_watch.rs +12 -62
- package/crates/team-agent/src/cli/tests/mod.rs +3 -3
- package/crates/team-agent/src/cli/tests/named_address.rs +11 -10
- package/crates/team-agent/src/cli/tests/run_delegation.rs +12 -9
- package/crates/team-agent/src/cli/tests/status_send.rs +70 -273
- package/crates/team-agent/src/compiler/tests.rs +39 -27
- package/crates/team-agent/src/compiler.rs +206 -6
- package/crates/team-agent/src/contract_runtime/backend.rs +181 -11
- package/crates/team-agent/src/contract_runtime/commands.rs +338 -7
- package/crates/team-agent/src/contract_runtime/config.rs +30 -19
- package/crates/team-agent/src/contract_runtime/config_tests.rs +24 -4
- package/crates/team-agent/src/contract_runtime/discovery.rs +12 -1
- package/crates/team-agent/src/contract_runtime/fork.rs +3 -10
- package/crates/team-agent/src/contract_runtime/framework.rs +28 -14
- package/crates/team-agent/src/contract_runtime/mcp.rs +19 -24
- package/crates/team-agent/src/contract_runtime/prompt.rs +2 -2
- package/crates/team-agent/src/contract_runtime/registry.rs +93 -130
- package/crates/team-agent/src/coordinator/steps/abnormal.rs +45 -5
- package/crates/team-agent/src/coordinator/tests/api_error_recovery.rs +8 -29
- package/crates/team-agent/src/coordinator/tests/energy.rs +4 -4
- package/crates/team-agent/src/coordinator/tests/health_sync.rs +44 -2
- package/crates/team-agent/src/coordinator/tests/main_preserved.rs +2 -2
- package/crates/team-agent/src/coordinator/tests/spine.rs +1 -1
- package/crates/team-agent/src/coordinator/tests/takeover.rs +3 -3
- package/crates/team-agent/src/coordinator/tick.rs +1 -89
- package/crates/team-agent/src/db/message_store.rs +7 -65
- package/crates/team-agent/src/direct_delivery.rs +368 -0
- package/crates/team-agent/src/inbox_store.rs +169 -0
- package/crates/team-agent/src/leader/registry.rs +5 -0
- package/crates/team-agent/src/leader/start.rs +2 -1
- package/crates/team-agent/src/leader/tests/lease_api.rs +2 -2
- package/crates/team-agent/src/leader/tests/prompt_contract.rs +1 -0
- package/crates/team-agent/src/lib.rs +2 -0
- package/crates/team-agent/src/lifecycle/launch/add_agent.rs +33 -0
- package/crates/team-agent/src/lifecycle/launch/add_agent_state.rs +206 -1
- package/crates/team-agent/src/lifecycle/launch/clone_agent.rs +28 -2
- package/crates/team-agent/src/lifecycle/launch/fork_agent.rs +36 -179
- package/crates/team-agent/src/lifecycle/launch/fork_entry.rs +87 -6
- package/crates/team-agent/src/lifecycle/launch/mcp_config.rs +13 -488
- package/crates/team-agent/src/lifecycle/launch/pi_mcp.rs +351 -81
- package/crates/team-agent/src/lifecycle/launch/pi_mcp_extension.js +3 -4
- package/crates/team-agent/src/lifecycle/launch/quick_start.rs +26 -2
- package/crates/team-agent/src/lifecycle/launch/spawn.rs +41 -31
- package/crates/team-agent/src/lifecycle/launch.rs +27 -12
- package/crates/team-agent/src/lifecycle/profile_launch.rs +318 -64
- package/crates/team-agent/src/lifecycle/restart/agent.rs +1 -0
- package/crates/team-agent/src/lifecycle/restart/avatar.rs +1798 -0
- package/crates/team-agent/src/lifecycle/restart/claude_fork.rs +163 -0
- package/crates/team-agent/src/lifecycle/restart/common.rs +298 -133
- package/crates/team-agent/src/lifecycle/restart/remove.rs +129 -0
- package/crates/team-agent/src/lifecycle/restart/selection.rs +5 -5
- package/crates/team-agent/src/lifecycle/restart.rs +4 -0
- package/crates/team-agent/src/lifecycle/role_config.rs +79 -27
- package/crates/team-agent/src/lifecycle/tests/acceptance_b_batch_red.rs +1 -1
- package/crates/team-agent/src/lifecycle/tests/agent_ops.rs +8 -12
- package/crates/team-agent/src/lifecycle/tests/behavioral_diff_264_red.rs +37 -240
- package/crates/team-agent/src/lifecycle/tests/claude_compatible_config_red.rs +325 -0
- package/crates/team-agent/src/lifecycle/tests/claude_profile_launch_red.rs +320 -8
- package/crates/team-agent/src/lifecycle/tests/cli_argv_routing_red.rs +329 -70
- package/crates/team-agent/src/lifecycle/tests/clone_fork_copilot_perms_red.rs +378 -4
- package/crates/team-agent/src/lifecycle/tests/communication_mode_runtime_contract_red.rs +25 -39
- package/crates/team-agent/src/lifecycle/tests/copilot_provider_red.rs +7 -11
- package/crates/team-agent/src/lifecycle/tests/core.rs +39 -36
- package/crates/team-agent/src/lifecycle/tests/f032_startup_prompt_best_effort_red.rs +22 -8
- package/crates/team-agent/src/lifecycle/tests/fixtures/pi_native_mcp_host.mjs +2 -1
- package/crates/team-agent/src/lifecycle/tests/grok_require_explicit_model_red.rs +15 -133
- package/crates/team-agent/src/lifecycle/tests/harvest2_a_batch_red.rs +60 -20
- package/crates/team-agent/src/lifecycle/tests/host_cotenant_death_p0_contract.rs +30 -67
- package/crates/team-agent/src/lifecycle/tests/issue238_codex_effort_contract.rs +3 -31
- package/crates/team-agent/src/lifecycle/tests/lane_ops.rs +194 -169
- package/crates/team-agent/src/lifecycle/tests/launch_spawn.rs +164 -282
- package/crates/team-agent/src/lifecycle/tests/lifecycle_rollback_red.rs +15 -78
- package/crates/team-agent/src/lifecycle/tests/main_preserved.rs +7 -7
- package/crates/team-agent/src/lifecycle/tests/mcp_tool_name_format_red.rs +6 -6
- package/crates/team-agent/src/lifecycle/tests/phase_b_contracts.rs +75 -69
- package/crates/team-agent/src/lifecycle/tests/phase_golden.rs +2 -10
- package/crates/team-agent/src/lifecycle/tests/pi_catalog_red.rs +18 -6
- package/crates/team-agent/src/lifecycle/tests/pi_command_red.rs +70 -52
- package/crates/team-agent/src/lifecycle/tests/pi_compiler_red.rs +210 -0
- package/crates/team-agent/src/lifecycle/tests/pi_dual_entry_red.rs +157 -4
- package/crates/team-agent/src/lifecycle/tests/pi_executable_mcp_red.rs +526 -10
- package/crates/team-agent/src/lifecycle/tests/pi_fork_session_inheritance_red.rs +1419 -0
- package/crates/team-agent/src/lifecycle/tests/pi_lifecycle_doctor_red.rs +68 -1
- package/crates/team-agent/src/lifecycle/tests/pi_native_mcp_capability_red.rs +34 -12
- package/crates/team-agent/src/lifecycle/tests/pi_session_delivery_red.rs +94 -2
- package/crates/team-agent/src/lifecycle/tests/quick_start_worker_readiness_red.rs +14 -15
- package/crates/team-agent/src/lifecycle/tests/restart.rs +12 -153
- package/crates/team-agent/src/lifecycle/tests/restart_build_before_destroy_0540_contract.rs +27 -5
- package/crates/team-agent/src/lifecycle/tests/restart_liveness_red.rs +59 -10
- package/crates/team-agent/src/lifecycle/tests/restart_rebind_hotfix_252_red.rs +47 -6
- package/crates/team-agent/src/lifecycle/tests/restart_session_capture_red.rs +3 -1374
- package/crates/team-agent/src/lifecycle/tests/resume_recover_red.rs +27 -10
- package/crates/team-agent/src/lifecycle/tests/status_credential_redaction_contract.rs +7 -7
- package/crates/team-agent/src/lifecycle/tests/subprep_codex_trust_roundtrip_red.rs +67 -313
- package/crates/team-agent/src/lifecycle/tests/swallow_batch4_semantics_red.rs +254 -2
- package/crates/team-agent/src/lifecycle/tests/team_in_team_identity_scope_red.rs +2 -2
- package/crates/team-agent/src/lifecycle/tests/team_in_team_sibling_quick_start_red.rs +1 -1
- package/crates/team-agent/src/lifecycle/tests/team_in_team_state_scope_red.rs +2 -2
- package/crates/team-agent/src/lifecycle/tests/team_key_retirement_txn_red.rs +4 -4
- package/crates/team-agent/src/lifecycle/tests/upgrade_compat_0211_red.rs +74 -19
- package/crates/team-agent/src/lifecycle/tests/verify_rs031_window_consistency_red.rs +38 -39
- package/crates/team-agent/src/lifecycle/tests/worker_spawn_env_red.rs +51 -88
- package/crates/team-agent/src/lifecycle/tests.rs +3 -4
- package/crates/team-agent/src/lifecycle/types.rs +18 -5
- package/crates/team-agent/src/lifecycle/worker_command_context.rs +43 -50
- package/crates/team-agent/src/mcp_server/readiness.rs +130 -149
- package/crates/team-agent/src/mcp_server/readiness_tests.rs +86 -109
- package/crates/team-agent/src/mcp_server/tests/scoped.rs +21 -31
- package/crates/team-agent/src/mcp_server/tests/send.rs +72 -107
- package/crates/team-agent/src/mcp_server/tests/tools.rs +10 -12
- package/crates/team-agent/src/mcp_server/tools.rs +70 -196
- package/crates/team-agent/src/messaging/delivery.rs +143 -253
- package/crates/team-agent/src/messaging/delivery_consumption_tests.rs +5 -5
- package/crates/team-agent/src/messaging/helpers.rs +1 -19
- package/crates/team-agent/src/messaging/mod.rs +1 -0
- package/crates/team-agent/src/messaging/reminders.rs +316 -0
- package/crates/team-agent/src/messaging/scheduler.rs +7 -1
- package/crates/team-agent/src/messaging/tests/dup_inject.rs +255 -150
- package/crates/team-agent/src/messaging/tests/main_preserved.rs +2 -2
- package/crates/team-agent/src/messaging/tests/runtime.rs +9 -115
- package/crates/team-agent/src/messaging/tests/spine.rs +44 -24
- package/crates/team-agent/src/messaging/tests/wave2.rs +13 -20
- package/crates/team-agent/src/messaging/types.rs +1 -0
- package/crates/team-agent/src/provider/adapter.rs +208 -254
- package/crates/team-agent/src/provider/adapters/claude.rs +78 -0
- package/crates/team-agent/src/provider/adapters/claude_fork.rs +131 -0
- package/crates/team-agent/src/provider/adapters/mod.rs +7 -7
- package/crates/team-agent/src/provider/adapters/pi.rs +106 -0
- package/crates/team-agent/src/provider/classify.rs +1 -66
- package/crates/team-agent/src/provider/model_catalog.rs +201 -13
- package/crates/team-agent/src/provider/session/capture.rs +111 -111
- package/crates/team-agent/src/provider/session/context_fork/claude.rs +123 -0
- package/crates/team-agent/src/provider/session/context_fork/outcome.rs +10 -18
- package/crates/team-agent/src/provider/session/context_fork.rs +87 -74
- package/crates/team-agent/src/provider/session/mod.rs +2 -3
- package/crates/team-agent/src/provider/session_scan/claude.rs +523 -0
- package/crates/team-agent/src/provider/session_scan/common.rs +47 -47
- package/crates/team-agent/src/provider/session_scan/pi.rs +34 -1
- package/crates/team-agent/src/provider/session_scan.rs +13 -13
- package/crates/team-agent/src/provider/tests/adapter.rs +127 -121
- package/crates/team-agent/src/provider/tests/classify.rs +0 -53
- package/crates/team-agent/src/provider/tests/command_helpers.rs +11 -19
- package/crates/team-agent/src/provider/tests/idle.rs +13 -19
- package/crates/team-agent/src/provider/types.rs +0 -4
- package/crates/team-agent/src/provider/wire.rs +34 -20
- package/crates/team-agent/src/state/abnormal_watch/tests/mod.rs +1 -1
- package/crates/team-agent/src/state/persist.rs +6 -6
- package/crates/team-agent/src/state/projection.rs +1 -1
- package/crates/team-agent/src/state/repository/tests.rs +2 -2
- package/crates/team-agent/src/test_support/models_timeout_fixture.rs +144 -0
- package/crates/team-agent/src/tmux_backend/tests.rs +0 -151
- package/crates/team-agent/src/tmux_backend.rs +9 -43
- package/package.json +4 -4
- package/skills/team-agent/SKILL.md +7 -8
- package/skills/team-agent/command-coverage.json +15 -1
- package/skills/team-agent/docs/reference/team-agent-operator.md +5 -3
- package/skills/team-agent/references/team-agent-operator.md +5 -3
- package/crates/team-agent/src/lifecycle/launch/grok_per_seat.rs +0 -260
- package/crates/team-agent/src/lifecycle/tests/codex_weak_window_attribution_red.rs +0 -683
- package/crates/team-agent/src/lifecycle/tests/grok_effort_argv_red.rs +0 -247
- package/crates/team-agent/src/lifecycle/tests/grok_mcp_overlay_red.rs +0 -507
- package/crates/team-agent/src/lifecycle/tests/grok_restart_resume_red.rs +0 -300
- package/crates/team-agent/src/provider/adapters/codex.rs +0 -101
- package/crates/team-agent/src/provider/adapters/grok.rs +0 -67
- package/crates/team-agent/src/provider/session/context_fork/codex.rs +0 -514
- package/crates/team-agent/src/provider/session_scan/codex.rs +0 -326
- package/crates/team-agent/src/provider/session_scan/grok.rs +0 -288
|
@@ -275,7 +275,7 @@ 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
|
|
278
|
+
// A pre-upgrade Codex or Grok worker row has no legacy runtime left;
|
|
279
279
|
// refuse before any MCP file, profile or pane side effect.
|
|
280
280
|
if let Some(retired) = agent
|
|
281
281
|
.get("provider")
|
|
@@ -295,6 +295,11 @@ pub(super) fn spawn_agent_window(
|
|
|
295
295
|
} else {
|
|
296
296
|
None
|
|
297
297
|
};
|
|
298
|
+
let fork_parent = agent
|
|
299
|
+
.get(crate::lifecycle::launch::add_agent_state::FORK_PARENT_SESSION_ID)
|
|
300
|
+
.and_then(serde_json::Value::as_str)
|
|
301
|
+
.filter(|parent| !parent.is_empty())
|
|
302
|
+
.map(SessionId::new);
|
|
298
303
|
// Contract C / F6.4: thread compiled role/tools/MCP context through restart as well —
|
|
299
304
|
// a restarted worker must come back up with the SAME callable MCP capability + role
|
|
300
305
|
// prompt as a fresh launch, else `report_result` becomes unreachable after every restart.
|
|
@@ -348,12 +353,16 @@ pub(super) fn spawn_agent_window(
|
|
|
348
353
|
agent_id.as_str(),
|
|
349
354
|
team_id.as_deref().unwrap_or(""),
|
|
350
355
|
);
|
|
351
|
-
let mcp_config_path = crate::
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
356
|
+
let mcp_config_path = if provider == crate::provider::Provider::Pi {
|
|
357
|
+
None
|
|
358
|
+
} else {
|
|
359
|
+
Some(crate::lifecycle::launch::write_worker_mcp_config_for_provider(
|
|
360
|
+
workspace,
|
|
361
|
+
agent_id.as_str(),
|
|
362
|
+
&mcp_config,
|
|
363
|
+
Some(provider),
|
|
364
|
+
)?)
|
|
365
|
+
};
|
|
357
366
|
let profile_launch =
|
|
358
367
|
crate::lifecycle::profile_launch::prepare_provider_profile_launch_from_json(
|
|
359
368
|
workspace,
|
|
@@ -386,18 +395,66 @@ pub(super) fn spawn_agent_window(
|
|
|
386
395
|
agent_id_hint: Some(agent_id.as_str()),
|
|
387
396
|
effort: restart_effort,
|
|
388
397
|
};
|
|
389
|
-
let
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
398
|
+
let pi_spawn_cwd = (provider == crate::provider::Provider::Pi)
|
|
399
|
+
.then(|| {
|
|
400
|
+
agent
|
|
401
|
+
.get("spawn_cwd")
|
|
402
|
+
.and_then(serde_json::Value::as_str)
|
|
403
|
+
.filter(|value| !value.is_empty())
|
|
404
|
+
.map(std::path::PathBuf::from)
|
|
405
|
+
})
|
|
406
|
+
.flatten();
|
|
407
|
+
let spawn_cwd = spawn_cwd_override
|
|
408
|
+
.or(pi_spawn_cwd.as_deref())
|
|
409
|
+
.unwrap_or(workspace);
|
|
410
|
+
let mut plan = if provider == crate::provider::Provider::Pi {
|
|
411
|
+
let request = crate::lifecycle::launch::pi_mcp::PiMaterializeRequest {
|
|
412
|
+
workspace,
|
|
413
|
+
team_id: team_id.as_deref().unwrap_or(""),
|
|
414
|
+
agent_id: agent_id.as_str(),
|
|
415
|
+
model: command_model,
|
|
416
|
+
effort: restart_effort,
|
|
417
|
+
system_prompt: &system_prompt,
|
|
418
|
+
team_mcp_tools: &["send_message", "report_result", "get_team_status"],
|
|
419
|
+
mcp_config: &mcp_config,
|
|
420
|
+
session_scope: crate::lifecycle::launch::pi_mcp::PiSessionScope::Isolated,
|
|
421
|
+
session_dir: resume_session_id
|
|
422
|
+
.and_then(|_| agent.get("claude_projects_root").and_then(serde_json::Value::as_str))
|
|
423
|
+
.map(Path::new),
|
|
424
|
+
};
|
|
425
|
+
match resume_session_id {
|
|
426
|
+
Some(session_id) => {
|
|
427
|
+
let rollout_path = agent_rollout_path(agent).ok_or_else(|| {
|
|
428
|
+
LifecycleError::RequirementUnmet(
|
|
429
|
+
"Pi resume requires the persisted exact session path".to_string(),
|
|
430
|
+
)
|
|
431
|
+
})?;
|
|
432
|
+
crate::lifecycle::launch::pi_mcp::materialize_pi_resume_plan(
|
|
433
|
+
request,
|
|
434
|
+
session_id,
|
|
435
|
+
rollout_path.as_path(),
|
|
436
|
+
spawn_cwd,
|
|
437
|
+
)
|
|
438
|
+
}
|
|
439
|
+
None => crate::lifecycle::launch::pi_mcp::materialize_pi_plan(request),
|
|
440
|
+
}
|
|
441
|
+
.map_err(|e| LifecycleError::Provider(e.to_string()))?
|
|
442
|
+
} else {
|
|
443
|
+
match (resume_session_id, fork_parent.as_ref()) {
|
|
444
|
+
(Some(session_id), _) => adapter.build_resume_command_plan(Some(session_id), context),
|
|
445
|
+
(None, Some(parent)) => adapter.fork_plan(Some(parent), context),
|
|
446
|
+
(None, None) => adapter.build_command_plan(context),
|
|
447
|
+
}
|
|
448
|
+
.map_err(|e| LifecycleError::Provider(e.to_string()))?
|
|
449
|
+
};
|
|
395
450
|
if !plan.managed_mcp_config && !profile_launch.managed_mcp_config {
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
451
|
+
if let Some(mcp_config_path) = mcp_config_path.as_ref() {
|
|
452
|
+
crate::lifecycle::launch::point_native_mcp_config_at_file(
|
|
453
|
+
&mut plan.argv,
|
|
454
|
+
provider,
|
|
455
|
+
mcp_config_path,
|
|
456
|
+
);
|
|
457
|
+
}
|
|
401
458
|
}
|
|
402
459
|
crate::lifecycle::launch::fill_spawn_placeholders_full(
|
|
403
460
|
&mut plan.argv,
|
|
@@ -424,12 +481,12 @@ pub(super) fn spawn_agent_window(
|
|
|
424
481
|
&mut env,
|
|
425
482
|
)?;
|
|
426
483
|
}
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
//
|
|
432
|
-
//
|
|
484
|
+
// Non-Pi spawn cwd is override-or-workspace (E56: ignore drifted state
|
|
485
|
+
// `.team/runtime/<team_key>/`). Pi resume uses captured agent.spawn_cwd
|
|
486
|
+
// already resolved above so exact-path header checks match capture.
|
|
487
|
+
// 0.4.x provider effort MVP step 9: scrub CLAUDE_EFFORT for Claude
|
|
488
|
+
// worker spawn so a parent shell env cannot silently override the
|
|
489
|
+
// framework's effort decision.
|
|
433
490
|
let env_unset = crate::layout::worker_env::isolate_worker_spawn_env(
|
|
434
491
|
provider,
|
|
435
492
|
&mut env,
|
|
@@ -439,6 +496,21 @@ pub(super) fn spawn_agent_window(
|
|
|
439
496
|
restart_effort.is_some(),
|
|
440
497
|
),
|
|
441
498
|
);
|
|
499
|
+
// Apply this owned fork policy after inherited Claude identity is scrubbed.
|
|
500
|
+
if resume_session_id.is_none()
|
|
501
|
+
&& fork_parent.is_some()
|
|
502
|
+
&& matches!(
|
|
503
|
+
provider,
|
|
504
|
+
crate::provider::Provider::Claude | crate::provider::Provider::ClaudeCode
|
|
505
|
+
)
|
|
506
|
+
{
|
|
507
|
+
// A fork keeps the whole parent history: a new seat never stops on
|
|
508
|
+
// Claude's stale-resume "summary or full session" modal.
|
|
509
|
+
env.insert(
|
|
510
|
+
"CLAUDE_CODE_RESUME_THRESHOLD_MINUTES".to_string(),
|
|
511
|
+
"1000000000".to_string(),
|
|
512
|
+
);
|
|
513
|
+
}
|
|
442
514
|
// Keep the launcher-known typed provider independent from inherited
|
|
443
515
|
// LEADER_* identity. The tmux wrapper binds pane/socket at invocation time.
|
|
444
516
|
crate::layout::worker_env::inject_current_caller_provider(&mut env, provider);
|
|
@@ -621,7 +693,7 @@ pub(super) fn spawn_agent_window(
|
|
|
621
693
|
profile_launch,
|
|
622
694
|
layout_placement: layout_placement.cloned(),
|
|
623
695
|
spawn_cwd: spawn_cwd.to_path_buf(),
|
|
624
|
-
mcp_config_path
|
|
696
|
+
mcp_config_path,
|
|
625
697
|
owner_team_id: team_id,
|
|
626
698
|
})
|
|
627
699
|
}
|
|
@@ -1153,7 +1225,7 @@ pub(super) fn session_live_or_default(
|
|
|
1153
1225
|
|
|
1154
1226
|
/// ---
|
|
1155
1227
|
/// purpose: 取席位行的 provider
|
|
1156
|
-
/// returns:
|
|
1228
|
+
/// returns: 解析成功用它,缺失或不认识时退到已退役的 legacy codex 键(其后一律拒绝,不会起席)
|
|
1157
1229
|
/// ---
|
|
1158
1230
|
pub(super) fn agent_provider(agent: &serde_json::Value) -> Provider {
|
|
1159
1231
|
agent
|
|
@@ -1274,11 +1346,11 @@ pub(crate) fn session_identity_probe_for_agent(
|
|
|
1274
1346
|
}
|
|
1275
1347
|
|
|
1276
1348
|
/// ---
|
|
1277
|
-
/// purpose:
|
|
1349
|
+
/// purpose: 将合法 Pi fork 血统纳入共享会话身份判定
|
|
1278
1350
|
/// params:
|
|
1279
|
-
/// workspace/state/agent:
|
|
1351
|
+
/// workspace/state/agent: 当前被验证席位及同队来源记录
|
|
1280
1352
|
/// rollout_path: 当前席位的精确 backing
|
|
1281
|
-
/// returns:
|
|
1353
|
+
/// returns: 字面身份一致,或经独立 Pi backing 与 fork 血统验证后合法继承时为 true
|
|
1282
1354
|
/// ---
|
|
1283
1355
|
pub(crate) fn session_identity_probe_for_agent_with_fork_ancestry(
|
|
1284
1356
|
workspace: &Path,
|
|
@@ -1288,8 +1360,102 @@ pub(crate) fn session_identity_probe_for_agent_with_fork_ancestry(
|
|
|
1288
1360
|
provider: Provider,
|
|
1289
1361
|
rollout_path: Option<&RolloutPath>,
|
|
1290
1362
|
) -> SessionIdentityProbeResult {
|
|
1291
|
-
let
|
|
1292
|
-
|
|
1363
|
+
let mut probe = session_identity_probe_for_agent(agent_id, provider, rollout_path);
|
|
1364
|
+
if probe.identity_ok != Some(false)
|
|
1365
|
+
|| !pi_fork_ancestor_identity_is_valid(
|
|
1366
|
+
workspace,
|
|
1367
|
+
state,
|
|
1368
|
+
agent_id,
|
|
1369
|
+
agent,
|
|
1370
|
+
provider,
|
|
1371
|
+
rollout_path,
|
|
1372
|
+
probe.embedded_agent_id.as_deref(),
|
|
1373
|
+
)
|
|
1374
|
+
{
|
|
1375
|
+
return probe;
|
|
1376
|
+
}
|
|
1377
|
+
probe.identity_ok = Some(true);
|
|
1378
|
+
probe
|
|
1379
|
+
}
|
|
1380
|
+
|
|
1381
|
+
fn pi_fork_ancestor_identity_is_valid(
|
|
1382
|
+
workspace: &Path,
|
|
1383
|
+
state: &serde_json::Value,
|
|
1384
|
+
agent_id: &AgentId,
|
|
1385
|
+
agent: &serde_json::Value,
|
|
1386
|
+
provider: Provider,
|
|
1387
|
+
rollout_path: Option<&RolloutPath>,
|
|
1388
|
+
embedded_agent_id: Option<&str>,
|
|
1389
|
+
) -> bool {
|
|
1390
|
+
if provider != Provider::Pi
|
|
1391
|
+
|| agent.get("attribution_ambiguous").and_then(serde_json::Value::as_bool) == Some(true)
|
|
1392
|
+
|| agent.get("capture_state").and_then(serde_json::Value::as_str)
|
|
1393
|
+
== Some("attribution_ambiguous")
|
|
1394
|
+
|| !matches!(
|
|
1395
|
+
agent
|
|
1396
|
+
.get("attribution_confidence")
|
|
1397
|
+
.and_then(serde_json::Value::as_str),
|
|
1398
|
+
Some("high" | "medium")
|
|
1399
|
+
)
|
|
1400
|
+
{
|
|
1401
|
+
return false;
|
|
1402
|
+
}
|
|
1403
|
+
let (Some(embedded_agent_id), Some(forked_from), Some(target_path)) = (
|
|
1404
|
+
embedded_agent_id,
|
|
1405
|
+
agent
|
|
1406
|
+
.get("forked_from")
|
|
1407
|
+
.and_then(serde_json::Value::as_str)
|
|
1408
|
+
.filter(|value| !value.is_empty()),
|
|
1409
|
+
rollout_path.map(RolloutPath::as_path),
|
|
1410
|
+
) else {
|
|
1411
|
+
return false;
|
|
1412
|
+
};
|
|
1413
|
+
if forked_from != embedded_agent_id || forked_from == agent_id.as_str() {
|
|
1414
|
+
return false;
|
|
1415
|
+
}
|
|
1416
|
+
let Some(source_agent) = state
|
|
1417
|
+
.get("agents")
|
|
1418
|
+
.and_then(|agents| agents.get(forked_from))
|
|
1419
|
+
.filter(|source| agent_provider(source) == Provider::Pi)
|
|
1420
|
+
else {
|
|
1421
|
+
return false;
|
|
1422
|
+
};
|
|
1423
|
+
let Some(source_path) = agent_rollout_path(source_agent) else {
|
|
1424
|
+
return false;
|
|
1425
|
+
};
|
|
1426
|
+
if source_path.as_path() == target_path {
|
|
1427
|
+
return false;
|
|
1428
|
+
}
|
|
1429
|
+
let (Some(session_id), Ok(target_path), Some(target_root)) = (
|
|
1430
|
+
agent_session_id(agent),
|
|
1431
|
+
std::fs::canonicalize(target_path),
|
|
1432
|
+
agent
|
|
1433
|
+
.get("claude_projects_root")
|
|
1434
|
+
.and_then(serde_json::Value::as_str)
|
|
1435
|
+
.filter(|path| !path.is_empty())
|
|
1436
|
+
.map(std::path::PathBuf::from),
|
|
1437
|
+
) else {
|
|
1438
|
+
return false;
|
|
1439
|
+
};
|
|
1440
|
+
let Ok(target_root) = std::fs::canonicalize(target_root) else {
|
|
1441
|
+
return false;
|
|
1442
|
+
};
|
|
1443
|
+
if !target_path.starts_with(target_root)
|
|
1444
|
+
|| std::fs::canonicalize(source_path.as_path())
|
|
1445
|
+
.is_ok_and(|source_path| source_path == target_path)
|
|
1446
|
+
|| !resume_backing_probe_for_agent(
|
|
1447
|
+
workspace,
|
|
1448
|
+
agent_id,
|
|
1449
|
+
agent,
|
|
1450
|
+
provider,
|
|
1451
|
+
&session_id,
|
|
1452
|
+
rollout_path,
|
|
1453
|
+
)
|
|
1454
|
+
.exists
|
|
1455
|
+
{
|
|
1456
|
+
return false;
|
|
1457
|
+
}
|
|
1458
|
+
true
|
|
1293
1459
|
}
|
|
1294
1460
|
|
|
1295
1461
|
/// ---
|
|
@@ -1318,14 +1484,19 @@ pub(super) fn resume_backing_probe_for_agent(
|
|
|
1318
1484
|
let _ = (workspace, agent_id, agent, session_id, rollout_path);
|
|
1319
1485
|
false
|
|
1320
1486
|
}
|
|
1321
|
-
Provider::
|
|
1487
|
+
Provider::Claude | Provider::ClaudeCode => {
|
|
1322
1488
|
let rollout_ok = rollout_path_exists(rollout_path);
|
|
1323
|
-
let
|
|
1324
|
-
|
|
1489
|
+
let projects_root = claude_projects_root_for_agent(agent);
|
|
1490
|
+
if let Some(root) = projects_root.as_ref() {
|
|
1325
1491
|
checked_paths.push(root.clone());
|
|
1326
1492
|
}
|
|
1493
|
+
let event_log_path = workspace.join(".team/logs/events.jsonl");
|
|
1494
|
+
checked_paths.push(event_log_path);
|
|
1327
1495
|
rollout_ok
|
|
1328
|
-
||
|
|
1496
|
+
|| event_log_transcript_exists(workspace, agent_id.as_str(), session_id.as_str())
|
|
1497
|
+
|| projects_root.is_some_and(|root| {
|
|
1498
|
+
claude_project_transcript_exists_under(&root, session_id.as_str())
|
|
1499
|
+
})
|
|
1329
1500
|
}
|
|
1330
1501
|
Provider::Copilot => {
|
|
1331
1502
|
if let Some(home) = std::env::var_os("HOME").map(PathBuf::from) {
|
|
@@ -1333,29 +1504,24 @@ pub(super) fn resume_backing_probe_for_agent(
|
|
|
1333
1504
|
}
|
|
1334
1505
|
copilot_session_store_has_session(session_id.as_str())
|
|
1335
1506
|
}
|
|
1336
|
-
Provider::
|
|
1507
|
+
Provider::Pi => {
|
|
1337
1508
|
let spawn_cwd = agent
|
|
1338
1509
|
.get("spawn_cwd")
|
|
1339
1510
|
.and_then(serde_json::Value::as_str)
|
|
1511
|
+
.filter(|value| !value.is_empty())
|
|
1340
1512
|
.map(PathBuf::from)
|
|
1341
1513
|
.unwrap_or_else(|| workspace.to_path_buf());
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
None => false,
|
|
1351
|
-
}
|
|
1514
|
+
rollout_path.is_some_and(|path| {
|
|
1515
|
+
crate::provider::session_scan::pi::validate_exact_backing(
|
|
1516
|
+
path.as_path(),
|
|
1517
|
+
session_id,
|
|
1518
|
+
&spawn_cwd,
|
|
1519
|
+
)
|
|
1520
|
+
.is_ok()
|
|
1521
|
+
})
|
|
1352
1522
|
}
|
|
1353
|
-
//
|
|
1354
|
-
Provider::
|
|
1355
|
-
| Provider::ClaudeCode
|
|
1356
|
-
| Provider::Pi
|
|
1357
|
-
| Provider::GeminiCli
|
|
1358
|
-
| Provider::Fake => false,
|
|
1523
|
+
// Codex and Grok workers run only through their contract leaves.
|
|
1524
|
+
Provider::Codex | Provider::Grok | Provider::GeminiCli | Provider::Fake => false,
|
|
1359
1525
|
};
|
|
1360
1526
|
|
|
1361
1527
|
// Deduplicate while preserving order (HashSet would lose deterministic
|
|
@@ -1395,78 +1561,71 @@ fn rollout_path_exists(rollout_path: Option<&RolloutPath>) -> bool {
|
|
|
1395
1561
|
.is_some_and(|path| path.as_path().exists())
|
|
1396
1562
|
}
|
|
1397
1563
|
|
|
1398
|
-
fn
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
)
|
|
1403
|
-
|
|
1404
|
-
|
|
1564
|
+
fn event_log_transcript_exists(workspace: &Path, agent_id: &str, session_id: &str) -> bool {
|
|
1565
|
+
let Ok(events) = crate::event_log::EventLog::new(workspace).tail(0) else {
|
|
1566
|
+
return false;
|
|
1567
|
+
};
|
|
1568
|
+
events.iter().rev().any(|event| {
|
|
1569
|
+
event.get("event").and_then(serde_json::Value::as_str) == Some("session.captured")
|
|
1570
|
+
&& ["agent_id", "worker_id"]
|
|
1571
|
+
.iter()
|
|
1572
|
+
.any(|key| event.get(*key).and_then(serde_json::Value::as_str) == Some(agent_id))
|
|
1573
|
+
&& event.get("session_id").and_then(serde_json::Value::as_str) == Some(session_id)
|
|
1574
|
+
&& event_transcript_path(event).is_some_and(|path| path.exists())
|
|
1575
|
+
})
|
|
1405
1576
|
}
|
|
1406
1577
|
|
|
1407
|
-
fn
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
)
|
|
1411
|
-
let mut roots: Vec<PathBuf> = Vec::new();
|
|
1412
|
-
if let Some(parent) = rollout_path
|
|
1413
|
-
.map(RolloutPath::as_path)
|
|
1414
|
-
.and_then(Path::parent)
|
|
1415
|
-
.filter(|path| path.is_dir())
|
|
1416
|
-
{
|
|
1417
|
-
roots.push(parent.to_path_buf());
|
|
1418
|
-
}
|
|
1419
|
-
if let Some(root) = agent
|
|
1420
|
-
.get("codex_sessions_root")
|
|
1578
|
+
fn event_transcript_path(event: &serde_json::Value) -> Option<PathBuf> {
|
|
1579
|
+
event
|
|
1580
|
+
.get("rollout_path")
|
|
1581
|
+
.or_else(|| event.get("transcript_path"))
|
|
1421
1582
|
.and_then(serde_json::Value::as_str)
|
|
1422
1583
|
.filter(|path| !path.is_empty())
|
|
1423
1584
|
.map(PathBuf::from)
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1585
|
+
}
|
|
1586
|
+
|
|
1587
|
+
/// E36 fix-B: a real Claude worker writes its session transcript to
|
|
1588
|
+
/// `<claude_projects_root>/<workspace-slug>/<session_id>.jsonl` even when neither
|
|
1589
|
+
/// `rollout_path` was persisted to state nor a `session.captured` event was logged.
|
|
1590
|
+
/// That landed transcript is itself a valid resume backing — restart was wrongly
|
|
1591
|
+
/// refusing resumable workers because it only checked the two paths above. Scan the
|
|
1592
|
+
/// projects root recursively for `<session_id>.jsonl` (session_id is a unique UUID,
|
|
1593
|
+
/// so we avoid recomputing the project-dir slug, which is brittle for non-ASCII
|
|
1594
|
+
/// workspace paths).
|
|
1595
|
+
fn claude_project_transcript_exists(agent: &serde_json::Value, session_id: &str) -> bool {
|
|
1596
|
+
let Some(root) = claude_projects_root_for_agent(agent) else {
|
|
1597
|
+
return false;
|
|
1598
|
+
};
|
|
1599
|
+
claude_project_transcript_exists_under(&root, session_id)
|
|
1600
|
+
}
|
|
1601
|
+
|
|
1602
|
+
fn claude_projects_root_for_agent(agent: &serde_json::Value) -> Option<PathBuf> {
|
|
1603
|
+
agent
|
|
1604
|
+
.get("claude_projects_root")
|
|
1605
|
+
.and_then(serde_json::Value::as_str)
|
|
1606
|
+
.filter(|value| !value.is_empty())
|
|
1429
1607
|
.map(PathBuf::from)
|
|
1430
|
-
.
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
}
|
|
1435
|
-
roots.sort();
|
|
1436
|
-
roots.dedup();
|
|
1437
|
-
roots
|
|
1608
|
+
.or_else(|| {
|
|
1609
|
+
std::env::var_os("HOME")
|
|
1610
|
+
.map(|home| PathBuf::from(home).join(".claude").join("projects"))
|
|
1611
|
+
})
|
|
1438
1612
|
}
|
|
1439
1613
|
|
|
1440
|
-
fn
|
|
1614
|
+
fn claude_project_transcript_exists_under(projects_root: &Path, session_id: &str) -> bool {
|
|
1441
1615
|
if session_id.is_empty() {
|
|
1442
1616
|
return false;
|
|
1443
1617
|
}
|
|
1444
|
-
|
|
1445
|
-
.iter()
|
|
1446
|
-
.any(|root| session_transcript_exists_under(root, session_id, 4))
|
|
1447
|
-
}
|
|
1448
|
-
|
|
1449
|
-
fn session_transcript_exists_under(root: &Path, session_id: &str, max_depth: usize) -> bool {
|
|
1450
|
-
let Ok(entries) = std::fs::read_dir(root) else {
|
|
1618
|
+
if !projects_root.is_dir() {
|
|
1451
1619
|
return false;
|
|
1452
|
-
};
|
|
1453
|
-
for entry in entries.flatten() {
|
|
1454
|
-
let path = entry.path();
|
|
1455
|
-
if path.is_file() {
|
|
1456
|
-
let Some(name) = path.file_name().and_then(|name| name.to_str()) else {
|
|
1457
|
-
continue;
|
|
1458
|
-
};
|
|
1459
|
-
if name.ends_with(".jsonl") && name.contains(session_id) {
|
|
1460
|
-
return true;
|
|
1461
|
-
}
|
|
1462
|
-
} else if max_depth > 0
|
|
1463
|
-
&& path.is_dir()
|
|
1464
|
-
&& session_transcript_exists_under(&path, session_id, max_depth.saturating_sub(1))
|
|
1465
|
-
{
|
|
1466
|
-
return true;
|
|
1467
|
-
}
|
|
1468
1620
|
}
|
|
1469
|
-
|
|
1621
|
+
let transcript_name = format!("{session_id}.jsonl");
|
|
1622
|
+
let Ok(project_dirs) = std::fs::read_dir(projects_root) else {
|
|
1623
|
+
return false;
|
|
1624
|
+
};
|
|
1625
|
+
project_dirs
|
|
1626
|
+
.flatten()
|
|
1627
|
+
.filter(|entry| entry.path().is_dir())
|
|
1628
|
+
.any(|entry| entry.path().join(&transcript_name).is_file())
|
|
1470
1629
|
}
|
|
1471
1630
|
|
|
1472
1631
|
fn copilot_session_store_has_session(session_id: &str) -> bool {
|
|
@@ -2158,40 +2317,46 @@ mod e36_transcript_backing_tests {
|
|
|
2158
2317
|
.is_err());
|
|
2159
2318
|
}
|
|
2160
2319
|
|
|
2320
|
+
// E36 fix-B RED→GREEN: a real Claude worker that sent a message has its session
|
|
2321
|
+
// transcript landed at <projects_root>/<slug>/<session_id>.jsonl, but neither
|
|
2322
|
+
// rollout_path was persisted to state nor a session.captured event was logged.
|
|
2323
|
+
// Before the fix, claude_project_transcript_exists did not exist and restart
|
|
2324
|
+
// refused such a worker. This asserts the landed transcript is recognized.
|
|
2161
2325
|
#[test]
|
|
2162
|
-
fn
|
|
2163
|
-
let scratch = ScratchDir::new("
|
|
2164
|
-
let
|
|
2165
|
-
let
|
|
2166
|
-
std::fs::create_dir_all(&
|
|
2167
|
-
let session_id = "
|
|
2168
|
-
std::fs::write(
|
|
2169
|
-
dated.join(format!("rollout-2026-06-20T21-37-31-{session_id}.jsonl")),
|
|
2170
|
-
b"{}\n",
|
|
2171
|
-
)
|
|
2172
|
-
.expect("codex transcript");
|
|
2326
|
+
fn claude_project_transcript_is_recognized_without_rollout_or_capture_event() {
|
|
2327
|
+
let scratch = ScratchDir::new("recognized");
|
|
2328
|
+
let projects_root = scratch.path().join("projects");
|
|
2329
|
+
let slug_dir = projects_root.join("-Users-alauda-Documents-code---rust---9");
|
|
2330
|
+
std::fs::create_dir_all(&slug_dir).expect("mkdir slug");
|
|
2331
|
+
let session_id = "87742d3f-0b4e-4fc1-ad35-447ac2340b65";
|
|
2332
|
+
std::fs::write(slug_dir.join(format!("{session_id}.jsonl")), b"{}\n").expect("transcript");
|
|
2173
2333
|
|
|
2174
|
-
let stale = RolloutPath::new(scratch.path().join("old").join("missing.jsonl"));
|
|
2175
2334
|
let agent = serde_json::json!({
|
|
2176
|
-
"
|
|
2335
|
+
"claude_projects_root": projects_root.to_string_lossy(),
|
|
2177
2336
|
});
|
|
2178
2337
|
assert!(
|
|
2179
|
-
|
|
2180
|
-
"
|
|
2338
|
+
claude_project_transcript_exists(&agent, session_id),
|
|
2339
|
+
"landed claude transcript must count as resume backing (E36 fix-B)"
|
|
2181
2340
|
);
|
|
2182
2341
|
}
|
|
2183
2342
|
|
|
2184
2343
|
#[test]
|
|
2185
|
-
fn
|
|
2186
|
-
let scratch = ScratchDir::new("
|
|
2187
|
-
let
|
|
2188
|
-
std::fs::create_dir_all(&
|
|
2344
|
+
fn missing_claude_transcript_is_not_backing() {
|
|
2345
|
+
let scratch = ScratchDir::new("missing");
|
|
2346
|
+
let projects_root = scratch.path().join("projects");
|
|
2347
|
+
std::fs::create_dir_all(&projects_root).expect("mkdir");
|
|
2189
2348
|
let agent = serde_json::json!({
|
|
2190
|
-
"
|
|
2349
|
+
"claude_projects_root": projects_root.to_string_lossy(),
|
|
2191
2350
|
});
|
|
2192
2351
|
assert!(
|
|
2193
|
-
!
|
|
2194
|
-
"no
|
|
2352
|
+
!claude_project_transcript_exists(&agent, "deadbeef-0000-0000-0000-000000000000"),
|
|
2353
|
+
"no transcript file => no backing"
|
|
2195
2354
|
);
|
|
2196
2355
|
}
|
|
2356
|
+
|
|
2357
|
+
#[test]
|
|
2358
|
+
fn empty_session_id_is_not_backing() {
|
|
2359
|
+
let agent = serde_json::json!({});
|
|
2360
|
+
assert!(!claude_project_transcript_exists(&agent, ""));
|
|
2361
|
+
}
|
|
2197
2362
|
}
|