@team-agent/installer 0.5.127 → 0.6.0
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/README.md +15 -4
- package/README.zh.md +1 -1
- package/package.json +4 -8
- package/skills/team-agent/SKILL.md +41 -26
- package/skills/team-agent/command-coverage.json +170 -184
- package/skills/team-agent/docs/reference/team-agent-operator.md +66 -32
- package/skills/team-agent/references/recovery-runbook.md +1 -1
- package/skills/team-agent/references/team-agent-operator.md +66 -32
- package/templates/team_state.md +1 -1
- package/Cargo.lock +0 -1063
- package/Cargo.toml +0 -36
- package/crates/team-agent/Cargo.toml +0 -69
- package/crates/team-agent/src/app_server_test_support.rs +0 -258
- package/crates/team-agent/src/cli/adapters.rs +0 -1298
- package/crates/team-agent/src/cli/arguments.rs +0 -401
- package/crates/team-agent/src/cli/attach_app_server_leader.rs +0 -98
- package/crates/team-agent/src/cli/diagnose.rs +0 -1675
- package/crates/team-agent/src/cli/emit.rs +0 -2898
- package/crates/team-agent/src/cli/grok_slot.rs +0 -384
- package/crates/team-agent/src/cli/helpers.rs +0 -91
- package/crates/team-agent/src/cli/intent/runtime.rs +0 -1189
- package/crates/team-agent/src/cli/intent/runtime_tests.rs +0 -821
- package/crates/team-agent/src/cli/intent/tests.rs +0 -691
- package/crates/team-agent/src/cli/intent.rs +0 -664
- package/crates/team-agent/src/cli/leader.rs +0 -300
- package/crates/team-agent/src/cli/leader_prompt.rs +0 -261
- package/crates/team-agent/src/cli/leaders.rs +0 -418
- package/crates/team-agent/src/cli/mod.rs +0 -6528
- package/crates/team-agent/src/cli/models.rs +0 -449
- package/crates/team-agent/src/cli/named_address.rs +0 -1651
- package/crates/team-agent/src/cli/profile.rs +0 -342
- package/crates/team-agent/src/cli/route.rs +0 -212
- package/crates/team-agent/src/cli/send/coordinator.rs +0 -164
- package/crates/team-agent/src/cli/send/mailbox.rs +0 -145
- package/crates/team-agent/src/cli/send/persist.rs +0 -192
- package/crates/team-agent/src/cli/send/presentation.rs +0 -370
- package/crates/team-agent/src/cli/send/resolve.rs +0 -573
- package/crates/team-agent/src/cli/send.rs +0 -201
- package/crates/team-agent/src/cli/shutdown_socket.rs +0 -288
- package/crates/team-agent/src/cli/spec.rs +0 -159
- package/crates/team-agent/src/cli/status.rs +0 -280
- package/crates/team-agent/src/cli/status_port/agents.rs +0 -358
- package/crates/team-agent/src/cli/status_port/approvals.rs +0 -79
- package/crates/team-agent/src/cli/status_port/brief.rs +0 -2043
- package/crates/team-agent/src/cli/status_port/compact.rs +0 -240
- package/crates/team-agent/src/cli/status_port/format.rs +0 -146
- package/crates/team-agent/src/cli/status_port/inbox.rs +0 -62
- package/crates/team-agent/src/cli/status_port/runtime.rs +0 -197
- package/crates/team-agent/src/cli/status_port/snapshot.rs +0 -208
- package/crates/team-agent/src/cli/status_port/store.rs +0 -416
- package/crates/team-agent/src/cli/status_port/tests.rs +0 -90
- package/crates/team-agent/src/cli/status_port.rs +0 -92
- package/crates/team-agent/src/cli/tests/base.rs +0 -885
- package/crates/team-agent/src/cli/tests/divergence.rs +0 -518
- package/crates/team-agent/src/cli/tests/lane_c.rs +0 -453
- package/crates/team-agent/src/cli/tests/leader_watch.rs +0 -372
- package/crates/team-agent/src/cli/tests/main_preserved.rs +0 -430
- package/crates/team-agent/src/cli/tests/missing_subcommands.rs +0 -336
- package/crates/team-agent/src/cli/tests/mod.rs +0 -137
- package/crates/team-agent/src/cli/tests/named_address.rs +0 -760
- package/crates/team-agent/src/cli/tests/parser_safety.rs +0 -383
- package/crates/team-agent/src/cli/tests/run_delegation.rs +0 -481
- package/crates/team-agent/src/cli/tests/shutdown_kill_plan.rs +0 -2179
- package/crates/team-agent/src/cli/tests/status_brief.rs +0 -1514
- package/crates/team-agent/src/cli/tests/status_send.rs +0 -1091
- package/crates/team-agent/src/cli/tests/verb_install_skill.rs +0 -93
- package/crates/team-agent/src/cli/tests/verb_profile.rs +0 -392
- package/crates/team-agent/src/cli/triage.rs +0 -234
- package/crates/team-agent/src/cli/types.rs +0 -591
- package/crates/team-agent/src/codex_app_server.rs +0 -546
- package/crates/team-agent/src/communication_mode/mod.rs +0 -56
- package/crates/team-agent/src/compiler/tests.rs +0 -842
- package/crates/team-agent/src/compiler.rs +0 -691
- package/crates/team-agent/src/conpty/backend.rs +0 -829
- package/crates/team-agent/src/conpty/mod.rs +0 -33
- package/crates/team-agent/src/contract_runtime/backend.rs +0 -1610
- package/crates/team-agent/src/contract_runtime/commands.rs +0 -671
- package/crates/team-agent/src/contract_runtime/config.rs +0 -354
- package/crates/team-agent/src/contract_runtime/config_tests.rs +0 -56
- package/crates/team-agent/src/contract_runtime/discovery.rs +0 -438
- package/crates/team-agent/src/contract_runtime/fork.rs +0 -368
- package/crates/team-agent/src/contract_runtime/forward.rs +0 -288
- package/crates/team-agent/src/contract_runtime/framework.rs +0 -350
- package/crates/team-agent/src/contract_runtime/mcp.rs +0 -399
- package/crates/team-agent/src/contract_runtime/mod.rs +0 -17
- package/crates/team-agent/src/contract_runtime/prompt.rs +0 -216
- package/crates/team-agent/src/contract_runtime/pump.rs +0 -271
- package/crates/team-agent/src/contract_runtime/registry.rs +0 -589
- package/crates/team-agent/src/contract_runtime/workspace.rs +0 -228
- package/crates/team-agent/src/coordinator/backoff.rs +0 -741
- package/crates/team-agent/src/coordinator/conpty_shim.rs +0 -805
- package/crates/team-agent/src/coordinator/health.rs +0 -1185
- package/crates/team-agent/src/coordinator/mod.rs +0 -119
- package/crates/team-agent/src/coordinator/orphan.rs +0 -110
- package/crates/team-agent/src/coordinator/runtime_detectors.rs +0 -798
- package/crates/team-agent/src/coordinator/runtime_observation.rs +0 -84
- package/crates/team-agent/src/coordinator/steps/abnormal.rs +0 -2309
- package/crates/team-agent/src/coordinator/steps/delivery.rs +0 -15
- package/crates/team-agent/src/coordinator/steps/health_sync.rs +0 -15
- package/crates/team-agent/src/coordinator/steps/mod.rs +0 -126
- package/crates/team-agent/src/coordinator/steps/persist.rs +0 -15
- package/crates/team-agent/src/coordinator/steps/runtime_prompts.rs +0 -15
- package/crates/team-agent/src/coordinator/steps/session_gate.rs +0 -16
- package/crates/team-agent/src/coordinator/tests/a0_lostupdate.rs +0 -158
- package/crates/team-agent/src/coordinator/tests/abnormal.rs +0 -312
- package/crates/team-agent/src/coordinator/tests/api_error_recovery.rs +0 -338
- package/crates/team-agent/src/coordinator/tests/basics.rs +0 -211
- package/crates/team-agent/src/coordinator/tests/daemon.rs +0 -514
- package/crates/team-agent/src/coordinator/tests/energy.rs +0 -549
- package/crates/team-agent/src/coordinator/tests/health_sync.rs +0 -461
- package/crates/team-agent/src/coordinator/tests/main_preserved.rs +0 -186
- package/crates/team-agent/src/coordinator/tests/mod.rs +0 -295
- package/crates/team-agent/src/coordinator/tests/s3_bounded.rs +0 -207
- package/crates/team-agent/src/coordinator/tests/spine.rs +0 -308
- package/crates/team-agent/src/coordinator/tests/takeover.rs +0 -286
- package/crates/team-agent/src/coordinator/tests/tick_core.rs +0 -237
- package/crates/team-agent/src/coordinator/tick.rs +0 -3112
- package/crates/team-agent/src/coordinator/types.rs +0 -540
- package/crates/team-agent/src/db/agent_health_capture.rs +0 -126
- package/crates/team-agent/src/db/message_store.rs +0 -1585
- package/crates/team-agent/src/db/migration.rs +0 -984
- package/crates/team-agent/src/db/mod.rs +0 -26
- package/crates/team-agent/src/db/schema.rs +0 -663
- package/crates/team-agent/src/diagnose/comms.rs +0 -242
- package/crates/team-agent/src/diagnose/mod.rs +0 -44
- package/crates/team-agent/src/diagnose/orphans.rs +0 -889
- package/crates/team-agent/src/event_log.rs +0 -502
- package/crates/team-agent/src/fake_worker.rs +0 -303
- package/crates/team-agent/src/kill_audit.rs +0 -106
- package/crates/team-agent/src/layout/manager.rs +0 -248
- package/crates/team-agent/src/layout/mod.rs +0 -36
- package/crates/team-agent/src/layout/overlay.rs +0 -134
- package/crates/team-agent/src/layout/placement.rs +0 -52
- package/crates/team-agent/src/layout/recovery.rs +0 -106
- package/crates/team-agent/src/layout/runtime_sessions.rs +0 -317
- package/crates/team-agent/src/layout/sessions.rs +0 -294
- package/crates/team-agent/src/layout/tmux_endpoint.rs +0 -165
- package/crates/team-agent/src/layout/worker_env.rs +0 -721
- package/crates/team-agent/src/layout/worker_window_helpers.rs +0 -37
- package/crates/team-agent/src/leader/helpers.rs +0 -178
- package/crates/team-agent/src/leader/incident.rs +0 -6
- package/crates/team-agent/src/leader/lease.rs +0 -3356
- package/crates/team-agent/src/leader/mod.rs +0 -104
- package/crates/team-agent/src/leader/owner_bind.rs +0 -400
- package/crates/team-agent/src/leader/prompt.rs +0 -905
- package/crates/team-agent/src/leader/provider_attribution.rs +0 -247
- package/crates/team-agent/src/leader/rediscover/tests.rs +0 -689
- package/crates/team-agent/src/leader/rediscover.rs +0 -1192
- package/crates/team-agent/src/leader/registry.rs +0 -883
- package/crates/team-agent/src/leader/start.rs +0 -4500
- package/crates/team-agent/src/leader/takeover.rs +0 -65
- package/crates/team-agent/src/leader/tests/basics.rs +0 -337
- package/crates/team-agent/src/leader/tests/byte_findings.rs +0 -355
- package/crates/team-agent/src/leader/tests/claim_leader_mailbox_flush_contract.rs +0 -544
- package/crates/team-agent/src/leader/tests/historical_inventory_upgrade_gate_red.rs +0 -624
- package/crates/team-agent/src/leader/tests/identity.rs +0 -465
- package/crates/team-agent/src/leader/tests/identity_session_names.rs +0 -42
- package/crates/team-agent/src/leader/tests/idle.rs +0 -113
- package/crates/team-agent/src/leader/tests/lease_api.rs +0 -520
- package/crates/team-agent/src/leader/tests/lease_claim.rs +0 -629
- package/crates/team-agent/src/leader/tests/mod.rs +0 -106
- package/crates/team-agent/src/leader/tests/prompt_contract.rs +0 -267
- package/crates/team-agent/src/leader/tests/rediscover.rs +0 -403
- package/crates/team-agent/src/leader/tests/rehomed_env.rs +0 -83
- package/crates/team-agent/src/leader/tests/team_in_team_state_scope_red.rs +0 -1273
- package/crates/team-agent/src/leader/tests/terminal_and_replay_vs_rerender_invariants_red.rs +0 -417
- package/crates/team-agent/src/leader/tests/wake_start_owner.rs +0 -168
- package/crates/team-agent/src/leader/types.rs +0 -534
- package/crates/team-agent/src/lib.rs +0 -145
- package/crates/team-agent/src/lifecycle/helpers.rs +0 -212
- package/crates/team-agent/src/lifecycle/launch/add_agent.rs +0 -848
- package/crates/team-agent/src/lifecycle/launch/add_agent_state.rs +0 -393
- package/crates/team-agent/src/lifecycle/launch/agent_state.rs +0 -332
- package/crates/team-agent/src/lifecycle/launch/clone_agent.rs +0 -178
- package/crates/team-agent/src/lifecycle/launch/fork_agent.rs +0 -82
- package/crates/team-agent/src/lifecycle/launch/fork_entry.rs +0 -63
- package/crates/team-agent/src/lifecycle/launch/identity.rs +0 -674
- package/crates/team-agent/src/lifecycle/launch/layout.rs +0 -350
- package/crates/team-agent/src/lifecycle/launch/leader_context.rs +0 -589
- package/crates/team-agent/src/lifecycle/launch/mcp_config.rs +0 -152
- package/crates/team-agent/src/lifecycle/launch/ownership.rs +0 -105
- package/crates/team-agent/src/lifecycle/launch/pi_mcp.rs +0 -629
- package/crates/team-agent/src/lifecycle/launch/pi_mcp_extension.js +0 -226
- package/crates/team-agent/src/lifecycle/launch/plan.rs +0 -269
- package/crates/team-agent/src/lifecycle/launch/quick_start.rs +0 -5176
- package/crates/team-agent/src/lifecycle/launch/quick_start_transport.rs +0 -368
- package/crates/team-agent/src/lifecycle/launch/readiness.rs +0 -519
- package/crates/team-agent/src/lifecycle/launch/role_source.rs +0 -287
- package/crates/team-agent/src/lifecycle/launch/spawn.rs +0 -450
- package/crates/team-agent/src/lifecycle/launch/spec_state.rs +0 -801
- package/crates/team-agent/src/lifecycle/launch/state_projection.rs +0 -624
- package/crates/team-agent/src/lifecycle/launch/worker_env.rs +0 -558
- package/crates/team-agent/src/lifecycle/launch.rs +0 -534
- package/crates/team-agent/src/lifecycle/lock.rs +0 -350
- package/crates/team-agent/src/lifecycle/mod.rs +0 -79
- package/crates/team-agent/src/lifecycle/pane_input_lock.rs +0 -239
- package/crates/team-agent/src/lifecycle/profile_launch.rs +0 -757
- package/crates/team-agent/src/lifecycle/profile_smoke.rs +0 -557
- package/crates/team-agent/src/lifecycle/restart/agent.rs +0 -2198
- package/crates/team-agent/src/lifecycle/restart/common.rs +0 -2052
- package/crates/team-agent/src/lifecycle/restart/orchestrator.rs +0 -65
- package/crates/team-agent/src/lifecycle/restart/preflight.rs +0 -113
- package/crates/team-agent/src/lifecycle/restart/rebuild.rs +0 -5135
- package/crates/team-agent/src/lifecycle/restart/remove.rs +0 -1504
- package/crates/team-agent/src/lifecycle/restart/selection.rs +0 -559
- package/crates/team-agent/src/lifecycle/restart/team_state.rs +0 -329
- package/crates/team-agent/src/lifecycle/restart.rs +0 -223
- package/crates/team-agent/src/lifecycle/role_config.rs +0 -1205
- package/crates/team-agent/src/lifecycle/tests/acceptance_b_batch_red.rs +0 -1021
- package/crates/team-agent/src/lifecycle/tests/agent_ops.rs +0 -1205
- package/crates/team-agent/src/lifecycle/tests/b0_legacy_snapshot_nonauthority_contract.rs +0 -265
- package/crates/team-agent/src/lifecycle/tests/b0_reader_hideone_audit_contract.rs +0 -490
- package/crates/team-agent/src/lifecycle/tests/behavioral_diff_264_red.rs +0 -656
- package/crates/team-agent/src/lifecycle/tests/claude_profile_launch_red.rs +0 -135
- package/crates/team-agent/src/lifecycle/tests/cli_argv_routing_red.rs +0 -1415
- package/crates/team-agent/src/lifecycle/tests/clone_agent_preserves_source_tools.rs +0 -427
- package/crates/team-agent/src/lifecycle/tests/clone_fork_copilot_perms_red.rs +0 -396
- package/crates/team-agent/src/lifecycle/tests/communication_mode_runtime_contract_red.rs +0 -418
- package/crates/team-agent/src/lifecycle/tests/copilot_provider_red.rs +0 -2039
- package/crates/team-agent/src/lifecycle/tests/core.rs +0 -1298
- package/crates/team-agent/src/lifecycle/tests/f032_startup_prompt_best_effort_red.rs +0 -315
- package/crates/team-agent/src/lifecycle/tests/fixtures/pi_list_models_g0.stdout.txt +0 -222
- package/crates/team-agent/src/lifecycle/tests/fixtures/pi_list_models_spaced_ids.stdout.txt +0 -9
- package/crates/team-agent/src/lifecycle/tests/fixtures/pi_native_mcp_host.mjs +0 -71
- package/crates/team-agent/src/lifecycle/tests/gate_fixtures.rs +0 -562
- package/crates/team-agent/src/lifecycle/tests/grok_require_explicit_model_red.rs +0 -110
- package/crates/team-agent/src/lifecycle/tests/harvest2_a_batch_red.rs +0 -472
- package/crates/team-agent/src/lifecycle/tests/host_cotenant_death_p0_contract.rs +0 -921
- package/crates/team-agent/src/lifecycle/tests/issue238_codex_effort_contract.rs +0 -68
- package/crates/team-agent/src/lifecycle/tests/lane_ops.rs +0 -1851
- package/crates/team-agent/src/lifecycle/tests/launch_spawn.rs +0 -3981
- package/crates/team-agent/src/lifecycle/tests/lifecycle_lock.rs +0 -339
- package/crates/team-agent/src/lifecycle/tests/lifecycle_rollback_red.rs +0 -596
- package/crates/team-agent/src/lifecycle/tests/main_preserved.rs +0 -513
- package/crates/team-agent/src/lifecycle/tests/mcp_tool_name_format_red.rs +0 -69
- package/crates/team-agent/src/lifecycle/tests/phase_b_contracts.rs +0 -824
- package/crates/team-agent/src/lifecycle/tests/phase_golden.rs +0 -723
- package/crates/team-agent/src/lifecycle/tests/pi_catalog_red.rs +0 -152
- package/crates/team-agent/src/lifecycle/tests/pi_command_red.rs +0 -182
- package/crates/team-agent/src/lifecycle/tests/pi_dual_entry_red.rs +0 -374
- package/crates/team-agent/src/lifecycle/tests/pi_executable_mcp_red.rs +0 -546
- package/crates/team-agent/src/lifecycle/tests/pi_lifecycle_doctor_red.rs +0 -31
- package/crates/team-agent/src/lifecycle/tests/pi_native_mcp_capability_red.rs +0 -528
- package/crates/team-agent/src/lifecycle/tests/pi_session_delivery_red.rs +0 -134
- package/crates/team-agent/src/lifecycle/tests/quick_start_worker_readiness_red.rs +0 -333
- package/crates/team-agent/src/lifecycle/tests/realmachine_clusters_1_6_red.rs +0 -786
- package/crates/team-agent/src/lifecycle/tests/realmachine_residual_g1_g4_red.rs +0 -648
- package/crates/team-agent/src/lifecycle/tests/restart.rs +0 -185
- package/crates/team-agent/src/lifecycle/tests/restart_build_before_destroy_0540_contract.rs +0 -1053
- package/crates/team-agent/src/lifecycle/tests/restart_liveness_red.rs +0 -679
- package/crates/team-agent/src/lifecycle/tests/restart_rebind_hotfix_252_red.rs +0 -1126
- package/crates/team-agent/src/lifecycle/tests/restart_session_capture_red.rs +0 -153
- package/crates/team-agent/src/lifecycle/tests/resume_recover_red.rs +0 -427
- package/crates/team-agent/src/lifecycle/tests/stale_team_saveconflict_contract.rs +0 -431
- package/crates/team-agent/src/lifecycle/tests/startup_latency_contract.rs +0 -1066
- package/crates/team-agent/src/lifecycle/tests/status_credential_redaction_contract.rs +0 -876
- package/crates/team-agent/src/lifecycle/tests/subprep_codex_trust_roundtrip_red.rs +0 -1026
- package/crates/team-agent/src/lifecycle/tests/swallow_batch4_semantics_red.rs +0 -90
- package/crates/team-agent/src/lifecycle/tests/team_in_team_identity_scope_red.rs +0 -543
- package/crates/team-agent/src/lifecycle/tests/team_in_team_sibling_quick_start_red.rs +0 -1103
- package/crates/team-agent/src/lifecycle/tests/team_in_team_state_scope_red.rs +0 -1276
- package/crates/team-agent/src/lifecycle/tests/team_key_retirement_roster_red.rs +0 -145
- package/crates/team-agent/src/lifecycle/tests/team_key_retirement_txn_red.rs +0 -603
- package/crates/team-agent/src/lifecycle/tests/test_isolation_escape_contract.rs +0 -936
- package/crates/team-agent/src/lifecycle/tests/upgrade_compat_0211_red.rs +0 -970
- package/crates/team-agent/src/lifecycle/tests/verify_rs031_window_consistency_red.rs +0 -996
- package/crates/team-agent/src/lifecycle/tests/worker_spawn_env_red.rs +0 -827
- package/crates/team-agent/src/lifecycle/tests.rs +0 -102
- package/crates/team-agent/src/lifecycle/types.rs +0 -861
- package/crates/team-agent/src/lifecycle/worker_command_context.rs +0 -370
- package/crates/team-agent/src/main.rs +0 -52
- package/crates/team-agent/src/mcp_server/helpers.rs +0 -510
- package/crates/team-agent/src/mcp_server/lifecycle_tools/mod.rs +0 -6
- package/crates/team-agent/src/mcp_server/lifecycle_tools/state_status.rs +0 -43
- package/crates/team-agent/src/mcp_server/mod.rs +0 -119
- package/crates/team-agent/src/mcp_server/normalize.rs +0 -485
- package/crates/team-agent/src/mcp_server/readiness.rs +0 -546
- package/crates/team-agent/src/mcp_server/readiness_tests.rs +0 -369
- package/crates/team-agent/src/mcp_server/tests/golden.rs +0 -285
- package/crates/team-agent/src/mcp_server/tests/normalize.rs +0 -247
- package/crates/team-agent/src/mcp_server/tests/scoped.rs +0 -168
- package/crates/team-agent/src/mcp_server/tests/send.rs +0 -388
- package/crates/team-agent/src/mcp_server/tests/tools.rs +0 -343
- package/crates/team-agent/src/mcp_server/tests/wire.rs +0 -254
- package/crates/team-agent/src/mcp_server/tests.rs +0 -43
- package/crates/team-agent/src/mcp_server/tools.rs +0 -1015
- package/crates/team-agent/src/mcp_server/types.rs +0 -396
- package/crates/team-agent/src/mcp_server/wire.rs +0 -867
- package/crates/team-agent/src/messaging/activity.rs +0 -461
- package/crates/team-agent/src/messaging/address.rs +0 -87
- package/crates/team-agent/src/messaging/delivery.rs +0 -3785
- package/crates/team-agent/src/messaging/delivery_consumption_tests.rs +0 -234
- package/crates/team-agent/src/messaging/enter_rescue.rs +0 -362
- package/crates/team-agent/src/messaging/enter_rescue_tests.rs +0 -633
- package/crates/team-agent/src/messaging/helpers.rs +0 -354
- package/crates/team-agent/src/messaging/leader_channel.rs +0 -287
- package/crates/team-agent/src/messaging/leader_receiver.rs +0 -786
- package/crates/team-agent/src/messaging/mod.rs +0 -166
- package/crates/team-agent/src/messaging/persist.rs +0 -377
- package/crates/team-agent/src/messaging/presentation.rs +0 -417
- package/crates/team-agent/src/messaging/results/collection_tests.rs +0 -719
- package/crates/team-agent/src/messaging/results.rs +0 -1415
- package/crates/team-agent/src/messaging/scheduler.rs +0 -217
- package/crates/team-agent/src/messaging/selftest.rs +0 -315
- package/crates/team-agent/src/messaging/send.rs +0 -981
- package/crates/team-agent/src/messaging/tests/basic.rs +0 -346
- package/crates/team-agent/src/messaging/tests/dup_inject.rs +0 -551
- package/crates/team-agent/src/messaging/tests/e23.rs +0 -49
- package/crates/team-agent/src/messaging/tests/leader_channel.rs +0 -169
- package/crates/team-agent/src/messaging/tests/leader_inject_acceptance.rs +0 -817
- package/crates/team-agent/src/messaging/tests/main_preserved.rs +0 -85
- package/crates/team-agent/src/messaging/tests/mod.rs +0 -306
- package/crates/team-agent/src/messaging/tests/runtime.rs +0 -3655
- package/crates/team-agent/src/messaging/tests/spine.rs +0 -837
- package/crates/team-agent/src/messaging/tests/wave2.rs +0 -381
- package/crates/team-agent/src/messaging/trust.rs +0 -215
- package/crates/team-agent/src/messaging/types.rs +0 -471
- package/crates/team-agent/src/messaging/wait.rs +0 -366
- package/crates/team-agent/src/messaging/watchers.rs +0 -916
- package/crates/team-agent/src/model/enums.rs +0 -356
- package/crates/team-agent/src/model/errors.rs +0 -18
- package/crates/team-agent/src/model/ids.rs +0 -165
- package/crates/team-agent/src/model/mod.rs +0 -29
- package/crates/team-agent/src/model/name_similarity.rs +0 -252
- package/crates/team-agent/src/model/pane_authority_refusal.rs +0 -359
- package/crates/team-agent/src/model/paths.rs +0 -257
- package/crates/team-agent/src/model/routing.rs +0 -387
- package/crates/team-agent/src/model/spec.rs +0 -1184
- package/crates/team-agent/src/model/task_graph.rs +0 -321
- package/crates/team-agent/src/model/testdata/fuzz.golden.yaml +0 -43
- package/crates/team-agent/src/model/testdata/fuzz.yaml +0 -43
- package/crates/team-agent/src/model/testdata/spec_invalid_a.yaml +0 -209
- package/crates/team-agent/src/model/testdata/team.spec.golden.yaml +0 -208
- package/crates/team-agent/src/model/testdata/team.spec.yaml +0 -208
- package/crates/team-agent/src/model/yaml/tests.rs +0 -188
- package/crates/team-agent/src/model/yaml.rs +0 -802
- package/crates/team-agent/src/os_probe.rs +0 -280
- package/crates/team-agent/src/packaging/install.rs +0 -219
- package/crates/team-agent/src/packaging/migrate.rs +0 -38
- package/crates/team-agent/src/packaging/mod.rs +0 -91
- package/crates/team-agent/src/packaging/repair.rs +0 -33
- package/crates/team-agent/src/packaging/tests.rs +0 -822
- package/crates/team-agent/src/packaging/types.rs +0 -417
- package/crates/team-agent/src/platform/argv.rs +0 -331
- package/crates/team-agent/src/platform/errors.rs +0 -104
- package/crates/team-agent/src/platform/file_lock.rs +0 -279
- package/crates/team-agent/src/platform/mod.rs +0 -5
- package/crates/team-agent/src/platform/process.rs +0 -545
- package/crates/team-agent/src/provider/adapter.rs +0 -898
- package/crates/team-agent/src/provider/adapters/copilot.rs +0 -75
- package/crates/team-agent/src/provider/adapters/copilot_fork.rs +0 -307
- package/crates/team-agent/src/provider/adapters/fake.rs +0 -18
- package/crates/team-agent/src/provider/adapters/mod.rs +0 -28
- package/crates/team-agent/src/provider/approvals/mod.rs +0 -3
- package/crates/team-agent/src/provider/approvals/parsing.rs +0 -586
- package/crates/team-agent/src/provider/approvals/runtime_prompts.rs +0 -205
- package/crates/team-agent/src/provider/argv_route.rs +0 -405
- package/crates/team-agent/src/provider/bypass_flags.rs +0 -116
- package/crates/team-agent/src/provider/classify.rs +0 -773
- package/crates/team-agent/src/provider/command_helpers.rs +0 -45
- package/crates/team-agent/src/provider/faults.rs +0 -165
- package/crates/team-agent/src/provider/helpers.rs +0 -52
- package/crates/team-agent/src/provider/mod.rs +0 -78
- package/crates/team-agent/src/provider/model_catalog.rs +0 -722
- package/crates/team-agent/src/provider/session/capture.rs +0 -2631
- package/crates/team-agent/src/provider/session/context_fork/outcome.rs +0 -168
- package/crates/team-agent/src/provider/session/context_fork.rs +0 -264
- package/crates/team-agent/src/provider/session/mod.rs +0 -36
- package/crates/team-agent/src/provider/session/resume.rs +0 -269
- package/crates/team-agent/src/provider/session_scan/common/tests.rs +0 -316
- package/crates/team-agent/src/provider/session_scan/common.rs +0 -618
- package/crates/team-agent/src/provider/session_scan/copilot.rs +0 -280
- package/crates/team-agent/src/provider/session_scan/pi.rs +0 -152
- package/crates/team-agent/src/provider/session_scan.rs +0 -61
- package/crates/team-agent/src/provider/startup_prompt.rs +0 -757
- package/crates/team-agent/src/provider/submit_now.rs +0 -71
- package/crates/team-agent/src/provider/testdata/copilot-ready-marker.txt +0 -5
- package/crates/team-agent/src/provider/testdata/copilot-trust-prompt.txt +0 -19
- package/crates/team-agent/src/provider/testdata/grok-models-authenticated.stdout +0 -9
- package/crates/team-agent/src/provider/testdata/grok-models-unauthenticated.stdout +0 -7
- package/crates/team-agent/src/provider/tests/adapter.rs +0 -354
- package/crates/team-agent/src/provider/tests/classify.rs +0 -201
- package/crates/team-agent/src/provider/tests/command_helpers.rs +0 -26
- package/crates/team-agent/src/provider/tests/copilot_fork.rs +0 -191
- package/crates/team-agent/src/provider/tests/faults.rs +0 -200
- package/crates/team-agent/src/provider/tests/idle.rs +0 -140
- package/crates/team-agent/src/provider/tests/wire.rs +0 -213
- package/crates/team-agent/src/provider/tests.rs +0 -32
- package/crates/team-agent/src/provider/types.rs +0 -529
- package/crates/team-agent/src/provider/wire.rs +0 -406
- package/crates/team-agent/src/redaction.rs +0 -259
- package/crates/team-agent/src/state/abnormal_watch/tests/mod.rs +0 -248
- package/crates/team-agent/src/state/abnormal_watch.rs +0 -144
- package/crates/team-agent/src/state/identity.rs +0 -914
- package/crates/team-agent/src/state/identity_keys.rs +0 -132
- package/crates/team-agent/src/state/mod.rs +0 -74
- package/crates/team-agent/src/state/owner_gate.rs +0 -482
- package/crates/team-agent/src/state/ownership.rs +0 -563
- package/crates/team-agent/src/state/paths.rs +0 -395
- package/crates/team-agent/src/state/persist.rs +0 -3811
- package/crates/team-agent/src/state/projection.rs +0 -1508
- package/crates/team-agent/src/state/repository/intent.rs +0 -14
- package/crates/team-agent/src/state/repository/tests.rs +0 -184
- package/crates/team-agent/src/state/repository.rs +0 -866
- package/crates/team-agent/src/state/selector.rs +0 -160
- package/crates/team-agent/src/state/testdata/state-rich.canonical.json +0 -133
- package/crates/team-agent/src/tmux_backend/enter_rescue.rs +0 -325
- package/crates/team-agent/src/tmux_backend/enter_rescue_tests.rs +0 -432
- package/crates/team-agent/src/tmux_backend/native_input.rs +0 -513
- package/crates/team-agent/src/tmux_backend/native_input_tests.rs +0 -742
- package/crates/team-agent/src/tmux_backend/tests.rs +0 -4254
- package/crates/team-agent/src/tmux_backend.rs +0 -4527
- package/crates/team-agent/src/topology.rs +0 -537
- package/crates/team-agent/src/transport/enter_rescue.rs +0 -166
- package/crates/team-agent/src/transport/native_input.rs +0 -491
- package/crates/team-agent/src/transport/test_support.rs +0 -743
- package/crates/team-agent/src/transport/tests/behavior.rs +0 -326
- package/crates/team-agent/src/transport/tests/mod.rs +0 -194
- package/crates/team-agent/src/transport/tests/wire.rs +0 -574
- package/crates/team-agent/src/transport.rs +0 -1655
- package/crates/team-agent/src/transport_factory.rs +0 -819
|
@@ -1,618 +0,0 @@
|
|
|
1
|
-
//! ---
|
|
2
|
-
//! purpose: 各 provider 共用的通用候选扫描与解析底座——枚举可能的会话文件、读头解析、按进程世代与身份 marker 过滤
|
|
3
|
-
//! contract:
|
|
4
|
-
//! provides:
|
|
5
|
-
//! - name: candidate_session_files
|
|
6
|
-
//! what: 枚举候选文件(隔离根 + spawn_cwd 递归),去重排序并按 mtime 截到 300 条
|
|
7
|
-
//! - name: parse_candidate_files
|
|
8
|
-
//! what: 逐个读头 64KB 解析成 CapturedSessionCandidate,途中套 cwd 匹配与 embedded 身份两道排除
|
|
9
|
-
//! - name: apply_spawned_at_filter
|
|
10
|
-
//! what: 剔除早于席位进程世代边界(spawned_at)的存档;spawned_at 存在但解析不了则清空候选
|
|
11
|
-
//! - name: apply_spawn_time_window_if_unique
|
|
12
|
-
//! what: 只有当"落在 spawn 之后"的候选恰好剩一条时才据此收窄,否则不动
|
|
13
|
-
//! - name: sort_expected_first_if_needed
|
|
14
|
-
//! what: 有 pending id 时把命中的候选排到最前
|
|
15
|
-
//! - name: read_head_text
|
|
16
|
-
//! what: 读文件头若干字节并截到最后一个完整行
|
|
17
|
-
//! - name: parse_session_records
|
|
18
|
-
//! what: 先按整体 JSON 解析(数组/单值),失败再按 JSONL 逐行解析
|
|
19
|
-
//! - name: embedded_team_agent_worker_id_from_text
|
|
20
|
-
//! what: 从正文里抽出 "You are Team Agent worker `<id>`" 的 id,字符集受限校验
|
|
21
|
-
//! - name: rollout_path_embedded_team_agent_worker_id
|
|
22
|
-
//! what: 上一条的按路径版本(读头后再抽)
|
|
23
|
-
//! - name: record_cwd
|
|
24
|
-
//! what: 从记录里取 cwd(顶层 cwd 或 session_meta.payload.cwd / payload.cwd)
|
|
25
|
-
//! - name: paths_equivalent
|
|
26
|
-
//! what: 路径等价判定:相等、canonicalize 后相等、或左的父目录等于右
|
|
27
|
-
//! - name: CAPTURE_HEAD_BYTES
|
|
28
|
-
//! what: 统一的读头窗口 64KB
|
|
29
|
-
//! requires:
|
|
30
|
-
//! - name: crate::provider::helpers
|
|
31
|
-
//! what: find_session_id 与 parse_jsonl_records
|
|
32
|
-
//! boundary:
|
|
33
|
-
//! - 一律只读:不写盘、不改 state、不发事件
|
|
34
|
-
//! - 只产出候选与事实;归属最终由上游分配器裁定,本文件不写会话
|
|
35
|
-
//! - spawn_cwd 递归最深 4 层,且跳过 .team 运行时目录
|
|
36
|
-
//! - 候选上限 300 条,超出按 mtime 由新到旧截断——截掉的部分不留痕迹
|
|
37
|
-
//! - "看起来像会话文件"的判据很宽(.json/.jsonl 后缀,或名字含 session/rollout/席位 id),收窄靠后续 provider 专属过滤
|
|
38
|
-
//! maturity: wired
|
|
39
|
-
//! ---
|
|
40
|
-
use std::path::{Path, PathBuf};
|
|
41
|
-
|
|
42
|
-
use crate::provider::helpers::{find_session_id, parse_jsonl_records};
|
|
43
|
-
use crate::provider::types::{
|
|
44
|
-
CaptureVia, CapturedSession, Confidence, ProviderError, RolloutPath, SessionId,
|
|
45
|
-
};
|
|
46
|
-
use crate::provider::Provider;
|
|
47
|
-
|
|
48
|
-
use super::{CaptureSessionContext, CapturedSessionCandidate};
|
|
49
|
-
|
|
50
|
-
pub(super) struct SessionCandidate {
|
|
51
|
-
pub(super) path: PathBuf,
|
|
52
|
-
requires_cwd_match: bool,
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/// P2 (C-P2-2/3) / Python claude.py:300 — candidates are capped to the newest `cap`
|
|
56
|
-
/// by mtime (descending priority: old candidates must not crowd out new ones).
|
|
57
|
-
const CAPTURE_CANDIDATE_CAP: usize = 300;
|
|
58
|
-
|
|
59
|
-
/// P2 (C-P2-1): head window >= Python's 200-line read.
|
|
60
|
-
pub(super) const CAPTURE_HEAD_BYTES: u64 = 65_536;
|
|
61
|
-
|
|
62
|
-
/// ---
|
|
63
|
-
/// purpose: 枚举本席位可能对应的会话文件,产出待解析的候选路径表
|
|
64
|
-
/// params:
|
|
65
|
-
/// _provider: 保留调用形状;不再有 provider HOME 目录分支
|
|
66
|
-
/// context: provider_projects_root(隔离根)、spawn_cwd(必扫)、agent_id(参与文件名匹配)
|
|
67
|
-
/// returns: 去重并排序后的候选;requires_cwd_match=false 的排前面,同组按路径字典序
|
|
68
|
-
/// errors: 只有 spawn_cwd 这一层根目录读不开才上抛 Io;隔离根读失败静默跳过
|
|
69
|
-
/// contract:
|
|
70
|
-
/// provides:
|
|
71
|
-
/// - name: candidate_session_files
|
|
72
|
-
/// what: 只列路径,不打开文件内容(截断时会取 mtime)
|
|
73
|
-
/// boundary:
|
|
74
|
-
/// - spawn_cwd 递归最深 4 层;工作区是用户代码仓,任何名含 session 的 json 都会被列进来
|
|
75
|
-
/// - .team 运行时目录一律排除,除非它就在 claude 的隔离根之下
|
|
76
|
-
/// - 超过 300 条按 mtime 由新到旧截断;被截掉的候选不产生任何信号
|
|
77
|
-
/// - 任何 provider 都不走 HOME 分支——Copilot / Pi 各有专属扫描,退役的 legacy 席位不扫描
|
|
78
|
-
/// ---
|
|
79
|
-
pub(super) fn candidate_session_files(
|
|
80
|
-
_provider: Provider,
|
|
81
|
-
context: &CaptureSessionContext,
|
|
82
|
-
) -> Result<Vec<SessionCandidate>, ProviderError> {
|
|
83
|
-
let mut out = Vec::new();
|
|
84
|
-
if let Some(root) = context.provider_projects_root.as_ref() {
|
|
85
|
-
collect_optional_candidate_files(root, &context.agent_id, None, &mut out)?;
|
|
86
|
-
}
|
|
87
|
-
collect_candidate_files(
|
|
88
|
-
&context.spawn_cwd,
|
|
89
|
-
&context.agent_id,
|
|
90
|
-
0,
|
|
91
|
-
false,
|
|
92
|
-
None,
|
|
93
|
-
&mut out,
|
|
94
|
-
)?;
|
|
95
|
-
out.sort_by(|a, b| {
|
|
96
|
-
a.requires_cwd_match
|
|
97
|
-
.cmp(&b.requires_cwd_match)
|
|
98
|
-
.then_with(|| a.path.to_string_lossy().cmp(&b.path.to_string_lossy()))
|
|
99
|
-
});
|
|
100
|
-
out.dedup_by(|a, b| a.path == b.path && a.requires_cwd_match == b.requires_cwd_match);
|
|
101
|
-
cap_candidates_by_mtime(&mut out, CAPTURE_CANDIDATE_CAP);
|
|
102
|
-
Ok(out)
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
/// ---
|
|
106
|
-
/// purpose: 把候选路径读头解析成结构化候选,并在解析途中就滤掉明显不属于本席位的
|
|
107
|
-
/// params:
|
|
108
|
-
/// _provider: 保留调用形状;不再有 provider 专属排除
|
|
109
|
-
/// context: 提供 spawn_cwd 与 agent_id 两个比对基准
|
|
110
|
-
/// candidates: candidate_session_files 的产物
|
|
111
|
-
/// returns: 通过全部排除的候选;每条带 embedded 身份、positive_agent_id_match 与 agent_path_match
|
|
112
|
-
/// contract:
|
|
113
|
-
/// provides:
|
|
114
|
-
/// - name: parse_candidate_files
|
|
115
|
-
/// what: 每个文件只读头 64KB,且只取到最后一个完整行
|
|
116
|
-
/// boundary:
|
|
117
|
-
/// - 三道排除:读不出头 / 解析不出记录 → 跳过;requires_cwd_match 的候选 cwd 对不上 → 跳过;embedded 身份存在且不等于本席位 → 跳过
|
|
118
|
-
/// - 无 session id 的候选不丢弃,降级为 FsMtimeFallback + Confidence::Low
|
|
119
|
-
/// - 身份判定用两套文本:正文 text 判 TEAM_AGENT_ID,未截行的原始字节判 embedded worker id
|
|
120
|
-
/// ---
|
|
121
|
-
pub(super) fn parse_candidate_files(
|
|
122
|
-
_provider: Provider,
|
|
123
|
-
context: &CaptureSessionContext,
|
|
124
|
-
candidates: Vec<SessionCandidate>,
|
|
125
|
-
) -> Vec<CapturedSessionCandidate> {
|
|
126
|
-
let mut out = Vec::new();
|
|
127
|
-
for candidate in candidates {
|
|
128
|
-
let path = candidate.path;
|
|
129
|
-
let Ok(head_bytes) = read_head_bytes(&path, CAPTURE_HEAD_BYTES) else {
|
|
130
|
-
continue;
|
|
131
|
-
};
|
|
132
|
-
let text = complete_head_text(&head_bytes);
|
|
133
|
-
let identity_text = String::from_utf8_lossy(&head_bytes);
|
|
134
|
-
let records = parse_session_records(&text);
|
|
135
|
-
if records.is_empty() {
|
|
136
|
-
continue;
|
|
137
|
-
}
|
|
138
|
-
if candidate.requires_cwd_match
|
|
139
|
-
&& !provider_home_records_match_spawn_cwd(&records, &context.spawn_cwd)
|
|
140
|
-
{
|
|
141
|
-
continue;
|
|
142
|
-
}
|
|
143
|
-
let session_id = records.iter().find_map(find_session_id);
|
|
144
|
-
let captured_via = if session_id.is_some() {
|
|
145
|
-
CaptureVia::FsWatch
|
|
146
|
-
} else {
|
|
147
|
-
CaptureVia::FsMtimeFallback
|
|
148
|
-
};
|
|
149
|
-
let attribution_confidence = if session_id.is_some() {
|
|
150
|
-
Confidence::High
|
|
151
|
-
} else {
|
|
152
|
-
Confidence::Low
|
|
153
|
-
};
|
|
154
|
-
let embedded_agent_id = embedded_team_agent_worker_id_from_text(&identity_text);
|
|
155
|
-
if embedded_agent_id
|
|
156
|
-
.as_deref()
|
|
157
|
-
.is_some_and(|id| id != context.agent_id.as_str())
|
|
158
|
-
{
|
|
159
|
-
continue;
|
|
160
|
-
}
|
|
161
|
-
let positive_agent_id_match = candidate_text_has_team_agent_id(&text, context)
|
|
162
|
-
|| embedded_agent_id.as_deref() == Some(context.agent_id.as_str());
|
|
163
|
-
let agent_path_match = candidate_path_matches_agent_id(&path, context);
|
|
164
|
-
out.push(CapturedSessionCandidate {
|
|
165
|
-
captured: CapturedSession {
|
|
166
|
-
session_id: session_id.map(SessionId::new),
|
|
167
|
-
rollout_path: Some(RolloutPath::new(path)),
|
|
168
|
-
captured_via,
|
|
169
|
-
attribution_confidence,
|
|
170
|
-
spawn_cwd: context.spawn_cwd.clone(),
|
|
171
|
-
},
|
|
172
|
-
embedded_agent_id,
|
|
173
|
-
positive_agent_id_match,
|
|
174
|
-
agent_path_match,
|
|
175
|
-
});
|
|
176
|
-
}
|
|
177
|
-
out
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
/// Reject provider files older than the persisted process-cohort boundary.
|
|
181
|
-
/// ---
|
|
182
|
-
/// purpose: 用席位的进程世代边界剔除上一代/别人留下的旧存档
|
|
183
|
-
/// params:
|
|
184
|
-
/// _provider: 保留调用形状;所有 provider 都按文件 mtime 判定
|
|
185
|
-
/// context: spawned_at 缺失则不过滤(legacy 行)
|
|
186
|
-
/// out: 就地过滤的候选列表
|
|
187
|
-
/// contract:
|
|
188
|
-
/// provides:
|
|
189
|
-
/// - name: apply_spawned_at_filter
|
|
190
|
-
/// what: fail-closed —— spawned_at 存在但解析不了时清空候选,绝不放行
|
|
191
|
-
/// boundary:
|
|
192
|
-
/// - 无 spawned_at 时整体跳过过滤,把守卫让给分配器的身份与唯一性判据
|
|
193
|
-
/// - 无 rollout_path、取不到时间的候选一律剔除
|
|
194
|
-
/// ---
|
|
195
|
-
pub(super) fn apply_spawned_at_filter(
|
|
196
|
-
_provider: Provider,
|
|
197
|
-
context: &CaptureSessionContext,
|
|
198
|
-
out: &mut Vec<CapturedSessionCandidate>,
|
|
199
|
-
) {
|
|
200
|
-
let Some(raw_spawned_at) = context.spawned_at.as_deref() else {
|
|
201
|
-
// Legacy direct capture_session_id callers have no cohort boundary;
|
|
202
|
-
// the canonical runtime capture path rejects such rows before scan.
|
|
203
|
-
return;
|
|
204
|
-
};
|
|
205
|
-
let Some(spawned_at) = parse_spawned_at(raw_spawned_at) else {
|
|
206
|
-
out.clear();
|
|
207
|
-
return;
|
|
208
|
-
};
|
|
209
|
-
out.retain(|candidate| {
|
|
210
|
-
let Some(path) = candidate.captured.rollout_path.as_ref() else {
|
|
211
|
-
return false;
|
|
212
|
-
};
|
|
213
|
-
candidate_mtime(path.as_path()).is_some_and(|mtime| mtime >= spawned_at)
|
|
214
|
-
});
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
/// RFC3339 only; the caller decides what `None` means (the filter clears).
|
|
218
|
-
pub(super) fn parse_spawned_at(raw: &str) -> Option<std::time::SystemTime> {
|
|
219
|
-
chrono::DateTime::parse_from_rfc3339(raw)
|
|
220
|
-
.ok()
|
|
221
|
-
.map(|dt| std::time::SystemTime::from(dt.with_timezone(&chrono::Utc)))
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
fn candidate_mtime(path: &Path) -> Option<std::time::SystemTime> {
|
|
225
|
-
std::fs::metadata(path)
|
|
226
|
-
.and_then(|meta| meta.modified())
|
|
227
|
-
.ok()
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
/// ---
|
|
231
|
-
/// purpose: 在时间窗只能唯一确定一条候选时才据此收窄,避免用弱判据在多条候选间乱挑
|
|
232
|
-
/// params:
|
|
233
|
-
/// _provider: 保留调用形状;所有 provider 都用 mtime
|
|
234
|
-
/// context: 需要 spawned_at;有 expected id 且候选不超过 1 条时直接不动
|
|
235
|
-
/// out: 就地可能被替换的候选列表
|
|
236
|
-
/// contract:
|
|
237
|
-
/// provides:
|
|
238
|
-
/// - name: apply_spawn_time_window_if_unique
|
|
239
|
-
/// what: 只在窗内恰好剩 1 条时替换整表;0 条或 ≥2 条一律保持原样
|
|
240
|
-
/// boundary:
|
|
241
|
-
/// - 无 spawned_at 或解析失败则不过滤(与 apply_spawned_at_filter 的 fail-closed 相反,此处是不作为)
|
|
242
|
-
/// - 不排序、不去重;只做"唯一即取"的收窄
|
|
243
|
-
/// ---
|
|
244
|
-
pub(super) fn apply_spawn_time_window_if_unique(
|
|
245
|
-
_provider: Provider,
|
|
246
|
-
context: &CaptureSessionContext,
|
|
247
|
-
out: &mut Vec<CapturedSessionCandidate>,
|
|
248
|
-
) {
|
|
249
|
-
if context.expected_session_id.is_some() && out.len() <= 1 {
|
|
250
|
-
return;
|
|
251
|
-
}
|
|
252
|
-
let Some(spawned_at) = context.spawned_at.as_deref().and_then(parse_spawned_at) else {
|
|
253
|
-
return;
|
|
254
|
-
};
|
|
255
|
-
let within: Vec<CapturedSessionCandidate> = out
|
|
256
|
-
.iter()
|
|
257
|
-
.filter(|candidate| {
|
|
258
|
-
candidate
|
|
259
|
-
.captured
|
|
260
|
-
.rollout_path
|
|
261
|
-
.as_ref()
|
|
262
|
-
.and_then(|p| candidate_mtime(p.as_path()))
|
|
263
|
-
.is_some_and(|created_at| created_at >= spawned_at)
|
|
264
|
-
})
|
|
265
|
-
.cloned()
|
|
266
|
-
.collect();
|
|
267
|
-
if within.len() == 1 {
|
|
268
|
-
*out = within;
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
/// ---
|
|
273
|
-
/// purpose: 有 pending id 时把命中的候选排到最前,让下游取首条即取到期望的那个
|
|
274
|
-
/// params:
|
|
275
|
-
/// context: 无 expected_session_id 则不动
|
|
276
|
-
/// out: 就地排序的候选切片
|
|
277
|
-
/// contract:
|
|
278
|
-
/// provides:
|
|
279
|
-
/// - name: sort_expected_first_if_needed
|
|
280
|
-
/// what: 稳定排序,只按"是否命中 expected"分两档,不改组内相对次序
|
|
281
|
-
/// boundary:
|
|
282
|
-
/// - 只排序不过滤——未命中的候选仍在表里
|
|
283
|
-
/// ---
|
|
284
|
-
pub(super) fn sort_expected_first_if_needed(
|
|
285
|
-
context: &CaptureSessionContext,
|
|
286
|
-
out: &mut [CapturedSessionCandidate],
|
|
287
|
-
) {
|
|
288
|
-
if let Some(expected) = context.expected_session_id.as_ref() {
|
|
289
|
-
out.sort_by_key(|candidate| {
|
|
290
|
-
candidate
|
|
291
|
-
.captured
|
|
292
|
-
.session_id
|
|
293
|
-
.as_ref()
|
|
294
|
-
.is_none_or(|session| session.as_str() != expected.as_str())
|
|
295
|
-
});
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
fn cap_candidates_by_mtime(out: &mut Vec<SessionCandidate>, cap: usize) {
|
|
300
|
-
if out.len() <= cap {
|
|
301
|
-
return;
|
|
302
|
-
}
|
|
303
|
-
let mut ranked: Vec<(std::time::SystemTime, usize)> = out
|
|
304
|
-
.iter()
|
|
305
|
-
.enumerate()
|
|
306
|
-
.map(|(index, candidate)| {
|
|
307
|
-
let mtime = std::fs::metadata(&candidate.path)
|
|
308
|
-
.and_then(|meta| meta.modified())
|
|
309
|
-
.unwrap_or(std::time::SystemTime::UNIX_EPOCH);
|
|
310
|
-
(mtime, index)
|
|
311
|
-
})
|
|
312
|
-
.collect();
|
|
313
|
-
ranked.sort_by(|a, b| b.0.cmp(&a.0));
|
|
314
|
-
let keep: std::collections::BTreeSet<usize> = ranked
|
|
315
|
-
.into_iter()
|
|
316
|
-
.take(cap)
|
|
317
|
-
.map(|(_, index)| index)
|
|
318
|
-
.collect();
|
|
319
|
-
let mut index = 0;
|
|
320
|
-
out.retain(|_| {
|
|
321
|
-
let kept = keep.contains(&index);
|
|
322
|
-
index += 1;
|
|
323
|
-
kept
|
|
324
|
-
});
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
/// ---
|
|
328
|
-
/// purpose: 读文件头若干字节并截到最后一个完整行,供各 provider 解析记录
|
|
329
|
-
/// params:
|
|
330
|
-
/// path: 待读文件
|
|
331
|
-
/// max_bytes: 读取上限;全模块统一用 CAPTURE_HEAD_BYTES(64KB)
|
|
332
|
-
/// returns: 到最后一个换行为止的文本;整段无换行时返回读到的全部
|
|
333
|
-
/// errors: 打不开或读失败时上抛 io::Error
|
|
334
|
-
/// contract:
|
|
335
|
-
/// provides:
|
|
336
|
-
/// - name: read_head_text
|
|
337
|
-
/// what: 只读、不加锁、不改 mtime
|
|
338
|
-
/// boundary:
|
|
339
|
-
/// - 刻意丢弃末尾不完整的一行——半条 JSON 会让解析器把整段判废
|
|
340
|
-
/// - 非 UTF-8 字节按 lossy 转换,不报错
|
|
341
|
-
/// - 只看头部;窗口之外的内容对所有基于本函数的判据都不可见
|
|
342
|
-
/// ---
|
|
343
|
-
pub(super) fn read_head_text(path: &Path, max_bytes: u64) -> std::io::Result<String> {
|
|
344
|
-
read_head_bytes(path, max_bytes).map(|bytes| complete_head_text(&bytes))
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
fn read_head_bytes(path: &Path, max_bytes: u64) -> std::io::Result<Vec<u8>> {
|
|
348
|
-
use std::io::Read;
|
|
349
|
-
let file = std::fs::File::open(path)?;
|
|
350
|
-
let mut bytes = Vec::new();
|
|
351
|
-
file.take(max_bytes).read_to_end(&mut bytes)?;
|
|
352
|
-
Ok(bytes)
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
fn complete_head_text(bytes: &[u8]) -> String {
|
|
356
|
-
let complete = match bytes.iter().rposition(|byte| *byte == b'\n') {
|
|
357
|
-
Some(last_newline) => &bytes[..=last_newline],
|
|
358
|
-
None => &bytes[..],
|
|
359
|
-
};
|
|
360
|
-
String::from_utf8_lossy(complete).into_owned()
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
fn collect_optional_candidate_files(
|
|
364
|
-
dir: &Path,
|
|
365
|
-
agent_id: &str,
|
|
366
|
-
allowed_team_root: Option<&Path>,
|
|
367
|
-
out: &mut Vec<SessionCandidate>,
|
|
368
|
-
) -> Result<(), ProviderError> {
|
|
369
|
-
if dir.exists() {
|
|
370
|
-
let _ = collect_candidate_files(dir, agent_id, 0, true, allowed_team_root, out);
|
|
371
|
-
}
|
|
372
|
-
Ok(())
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
fn collect_candidate_files(
|
|
376
|
-
dir: &Path,
|
|
377
|
-
agent_id: &str,
|
|
378
|
-
depth: usize,
|
|
379
|
-
requires_cwd_match: bool,
|
|
380
|
-
allowed_team_root: Option<&Path>,
|
|
381
|
-
out: &mut Vec<SessionCandidate>,
|
|
382
|
-
) -> Result<(), ProviderError> {
|
|
383
|
-
if depth > 4 || !may_traverse_session_directory(dir, allowed_team_root) {
|
|
384
|
-
return Ok(());
|
|
385
|
-
}
|
|
386
|
-
#[cfg(test)]
|
|
387
|
-
tests::record_directory_read(dir);
|
|
388
|
-
let entries = match std::fs::read_dir(dir) {
|
|
389
|
-
Ok(entries) => entries,
|
|
390
|
-
Err(e) if depth == 0 => return Err(ProviderError::Io(format!("{}: {e}", dir.display()))),
|
|
391
|
-
Err(_) => return Ok(()),
|
|
392
|
-
};
|
|
393
|
-
for entry in entries {
|
|
394
|
-
let Ok(entry) = entry else {
|
|
395
|
-
continue;
|
|
396
|
-
};
|
|
397
|
-
#[cfg(test)]
|
|
398
|
-
tests::record_entry();
|
|
399
|
-
let path = entry.path();
|
|
400
|
-
if !may_traverse_session_directory(&path, allowed_team_root) {
|
|
401
|
-
continue;
|
|
402
|
-
}
|
|
403
|
-
// read_dir already supplies the type for ordinary entries. Only links
|
|
404
|
-
// (or an unavailable type) need the old, following metadata lookup.
|
|
405
|
-
let is_dir = match entry.file_type() {
|
|
406
|
-
Ok(kind) if !kind.is_symlink() => kind.is_dir(),
|
|
407
|
-
_ => {
|
|
408
|
-
#[cfg(test)]
|
|
409
|
-
tests::record_following_metadata();
|
|
410
|
-
path.is_dir()
|
|
411
|
-
}
|
|
412
|
-
};
|
|
413
|
-
if is_dir {
|
|
414
|
-
collect_candidate_files(
|
|
415
|
-
&path,
|
|
416
|
-
agent_id,
|
|
417
|
-
depth.saturating_add(1),
|
|
418
|
-
requires_cwd_match,
|
|
419
|
-
allowed_team_root,
|
|
420
|
-
out,
|
|
421
|
-
)?;
|
|
422
|
-
} else if looks_like_session_file(&path, agent_id, allowed_team_root) {
|
|
423
|
-
out.push(SessionCandidate {
|
|
424
|
-
path,
|
|
425
|
-
requires_cwd_match,
|
|
426
|
-
});
|
|
427
|
-
}
|
|
428
|
-
}
|
|
429
|
-
Ok(())
|
|
430
|
-
}
|
|
431
|
-
|
|
432
|
-
fn may_traverse_session_directory(path: &Path, allowed_team_root: Option<&Path>) -> bool {
|
|
433
|
-
!path_is_under_team_runtime(path)
|
|
434
|
-
|| allowed_team_root.is_some_and(|root| path.starts_with(root) || root.starts_with(path))
|
|
435
|
-
}
|
|
436
|
-
|
|
437
|
-
fn looks_like_session_file(path: &Path, agent_id: &str, allowed_team_root: Option<&Path>) -> bool {
|
|
438
|
-
if path_is_under_team_runtime(path)
|
|
439
|
-
&& !allowed_team_root.is_some_and(|root| path.starts_with(root))
|
|
440
|
-
{
|
|
441
|
-
return false;
|
|
442
|
-
}
|
|
443
|
-
let Some(name) = path.file_name().and_then(|s| s.to_str()) else {
|
|
444
|
-
return false;
|
|
445
|
-
};
|
|
446
|
-
name.ends_with(".jsonl")
|
|
447
|
-
|| name.ends_with(".json")
|
|
448
|
-
|| name.contains("session")
|
|
449
|
-
|| name.contains("rollout")
|
|
450
|
-
|| (!agent_id.is_empty() && name.contains(agent_id))
|
|
451
|
-
}
|
|
452
|
-
|
|
453
|
-
/// ---
|
|
454
|
-
/// purpose: 把会话文本解析成记录数组,兼容整体 JSON 与 JSONL 两种存档形态
|
|
455
|
-
/// params:
|
|
456
|
-
/// text: 已读入的文本(通常是 read_head_text 的产物)
|
|
457
|
-
/// returns: JSON 数组则展开;JSON 单值则包成一条;都不是则按 JSONL 逐行解析
|
|
458
|
-
/// contract:
|
|
459
|
-
/// provides:
|
|
460
|
-
/// - name: parse_session_records
|
|
461
|
-
/// what: 纯解析,无 I/O
|
|
462
|
-
/// boundary:
|
|
463
|
-
/// - JSONL 分支跳过解析失败的行,不报错——因此"记录为空"不区分"文件空"与"全是坏行"
|
|
464
|
-
/// ---
|
|
465
|
-
pub(super) fn parse_session_records(text: &str) -> Vec<serde_json::Value> {
|
|
466
|
-
match serde_json::from_str::<serde_json::Value>(text) {
|
|
467
|
-
Ok(serde_json::Value::Array(items)) => items,
|
|
468
|
-
Ok(value) => vec![value],
|
|
469
|
-
Err(_) => parse_jsonl_records(text),
|
|
470
|
-
}
|
|
471
|
-
}
|
|
472
|
-
|
|
473
|
-
fn provider_home_records_match_spawn_cwd(records: &[serde_json::Value], spawn_cwd: &Path) -> bool {
|
|
474
|
-
let cwd_values: Vec<String> = records.iter().filter_map(record_cwd).collect();
|
|
475
|
-
!cwd_values.is_empty()
|
|
476
|
-
&& cwd_values
|
|
477
|
-
.iter()
|
|
478
|
-
.any(|cwd| paths_equivalent(Path::new(cwd), spawn_cwd))
|
|
479
|
-
}
|
|
480
|
-
|
|
481
|
-
fn candidate_text_has_team_agent_id(text: &str, context: &CaptureSessionContext) -> bool {
|
|
482
|
-
let id = context.agent_id.as_str();
|
|
483
|
-
if id.is_empty() {
|
|
484
|
-
return false;
|
|
485
|
-
}
|
|
486
|
-
[
|
|
487
|
-
format!("\"TEAM_AGENT_ID\":\"{id}\""),
|
|
488
|
-
format!("\"TEAM_AGENT_ID\": \"{id}\""),
|
|
489
|
-
format!("TEAM_AGENT_ID={id}"),
|
|
490
|
-
format!("env.TEAM_AGENT_ID=\"{id}\""),
|
|
491
|
-
format!("env.TEAM_AGENT_ID=\\\"{id}\\\""),
|
|
492
|
-
format!("\"TEAM_AGENT_AGENT_ID\":\"{id}\""),
|
|
493
|
-
format!("\"TEAM_AGENT_AGENT_ID\": \"{id}\""),
|
|
494
|
-
format!("TEAM_AGENT_AGENT_ID={id}"),
|
|
495
|
-
]
|
|
496
|
-
.iter()
|
|
497
|
-
.any(|needle| text.contains(needle))
|
|
498
|
-
}
|
|
499
|
-
|
|
500
|
-
/// ---
|
|
501
|
-
/// purpose: 从会话正文里抽出 team-agent 写进 prompt 的席位身份 marker,作为归属的强证据
|
|
502
|
-
/// params:
|
|
503
|
-
/// text: 待搜索的文本
|
|
504
|
-
/// returns: marker 后反引号之间的 id;未找到、为空或含非法字符时 None
|
|
505
|
-
/// contract:
|
|
506
|
-
/// provides:
|
|
507
|
-
/// - name: embedded_team_agent_worker_id_from_text
|
|
508
|
-
/// what: 纯文本查找,无 I/O
|
|
509
|
-
/// boundary:
|
|
510
|
-
/// - 只取第一处 marker;后续出现的一律忽略
|
|
511
|
-
/// - id 字符集限定为 ASCII 字母数字与 _ - .;越界即判无
|
|
512
|
-
/// - 找不到只说明"这段文本里没有",不等于该会话不属于任何席位
|
|
513
|
-
/// ---
|
|
514
|
-
pub(crate) fn embedded_team_agent_worker_id_from_text(text: &str) -> Option<String> {
|
|
515
|
-
const PREFIX: &str = "You are Team Agent worker `";
|
|
516
|
-
let start = text.find(PREFIX)? + PREFIX.len();
|
|
517
|
-
let rest = &text[start..];
|
|
518
|
-
let end = rest.find('`')?;
|
|
519
|
-
let id = &rest[..end];
|
|
520
|
-
if id.is_empty()
|
|
521
|
-
|| !id
|
|
522
|
-
.chars()
|
|
523
|
-
.all(|ch| ch.is_ascii_alphanumeric() || matches!(ch, '_' | '-' | '.'))
|
|
524
|
-
{
|
|
525
|
-
return None;
|
|
526
|
-
}
|
|
527
|
-
Some(id.to_string())
|
|
528
|
-
}
|
|
529
|
-
|
|
530
|
-
/// ---
|
|
531
|
-
/// purpose: 按路径取该存档的 embedded 席位身份,供捕获链外的调用方直接查归属
|
|
532
|
-
/// params:
|
|
533
|
-
/// path: 存档文件路径
|
|
534
|
-
/// returns: 读头 64KB 后抽到的席位 id;读失败或没抽到给 None
|
|
535
|
-
/// contract:
|
|
536
|
-
/// provides:
|
|
537
|
-
/// - name: rollout_path_embedded_team_agent_worker_id
|
|
538
|
-
/// what: read_head_text + embedded_team_agent_worker_id_from_text 的组合,只读
|
|
539
|
-
/// boundary:
|
|
540
|
-
/// - 读失败与"文件里确实没有 marker"都返回 None,两者不可区分
|
|
541
|
-
/// - marker 若出现在 64KB 之后则看不见
|
|
542
|
-
/// ---
|
|
543
|
-
pub(crate) fn rollout_path_embedded_team_agent_worker_id(path: &Path) -> Option<String> {
|
|
544
|
-
read_head_text(path, CAPTURE_HEAD_BYTES)
|
|
545
|
-
.ok()
|
|
546
|
-
.and_then(|text| embedded_team_agent_worker_id_from_text(&text))
|
|
547
|
-
}
|
|
548
|
-
|
|
549
|
-
fn candidate_path_matches_agent_id(path: &Path, context: &CaptureSessionContext) -> bool {
|
|
550
|
-
let id = context.agent_id.as_str();
|
|
551
|
-
if id.is_empty() {
|
|
552
|
-
return false;
|
|
553
|
-
}
|
|
554
|
-
let Some(name) = path.file_name().and_then(|value| value.to_str()) else {
|
|
555
|
-
return false;
|
|
556
|
-
};
|
|
557
|
-
let dashed = id.replace('_', "-");
|
|
558
|
-
name.contains(id) || name.contains(&dashed)
|
|
559
|
-
}
|
|
560
|
-
|
|
561
|
-
/// ---
|
|
562
|
-
/// purpose: 从一条会话记录里取工作目录,兼容 claude 顶层 cwd 与 codex session_meta.payload.cwd 两种形状
|
|
563
|
-
/// params:
|
|
564
|
-
/// record: 单条已解析记录
|
|
565
|
-
/// returns: 顶层 cwd 优先;否则取 session_meta.payload.cwd 或 payload.cwd;都没有则 None
|
|
566
|
-
/// contract:
|
|
567
|
-
/// provides:
|
|
568
|
-
/// - name: record_cwd
|
|
569
|
-
/// what: 纯取值,不做路径归一或存在性检查
|
|
570
|
-
/// boundary:
|
|
571
|
-
/// - 只认这三个位置;其它自定义字段一概不看
|
|
572
|
-
/// ---
|
|
573
|
-
pub(super) fn record_cwd(record: &serde_json::Value) -> Option<String> {
|
|
574
|
-
record
|
|
575
|
-
.get("cwd")
|
|
576
|
-
.and_then(serde_json::Value::as_str)
|
|
577
|
-
.or_else(|| {
|
|
578
|
-
record
|
|
579
|
-
.get("session_meta")
|
|
580
|
-
.and_then(|v| v.get("payload"))
|
|
581
|
-
.or_else(|| record.get("payload"))
|
|
582
|
-
.and_then(|v| v.get("cwd"))
|
|
583
|
-
.and_then(serde_json::Value::as_str)
|
|
584
|
-
})
|
|
585
|
-
.map(ToString::to_string)
|
|
586
|
-
}
|
|
587
|
-
|
|
588
|
-
/// ---
|
|
589
|
-
/// purpose: 判断记录里的 cwd 与席位 spawn_cwd 是不是同一个工作目录
|
|
590
|
-
/// params:
|
|
591
|
-
/// left: 记录里的 cwd
|
|
592
|
-
/// right: 席位 spawn_cwd
|
|
593
|
-
/// returns: 字面相等、canonicalize 后相等、或 left 的父目录等于 right 时为 true
|
|
594
|
-
/// contract:
|
|
595
|
-
/// provides:
|
|
596
|
-
/// - name: paths_equivalent
|
|
597
|
-
/// what: 会触发文件系统 canonicalize;失败则退回原路径继续比
|
|
598
|
-
/// boundary:
|
|
599
|
-
/// - 父目录等价是刻意放宽的一档:记录 cwd 是 spawn_cwd 的直接子目录也算同 cwd,嵌套 workspace 下会把子目录的存档收进来
|
|
600
|
-
/// - 不对称:只查 left 的父等于 right,反向不查
|
|
601
|
-
/// - 不解析符号链接之外的等价(如大小写不敏感文件系统的同名不同写)
|
|
602
|
-
/// ---
|
|
603
|
-
pub(super) fn paths_equivalent(left: &Path, right: &Path) -> bool {
|
|
604
|
-
if left == right {
|
|
605
|
-
return true;
|
|
606
|
-
}
|
|
607
|
-
let left = std::fs::canonicalize(left).unwrap_or_else(|_| left.to_path_buf());
|
|
608
|
-
let right = std::fs::canonicalize(right).unwrap_or_else(|_| right.to_path_buf());
|
|
609
|
-
left == right || left.parent().is_some_and(|parent| parent == right)
|
|
610
|
-
}
|
|
611
|
-
|
|
612
|
-
fn path_is_under_team_runtime(path: &Path) -> bool {
|
|
613
|
-
path.components()
|
|
614
|
-
.any(|c| c.as_os_str() == std::ffi::OsStr::new(".team"))
|
|
615
|
-
}
|
|
616
|
-
|
|
617
|
-
#[cfg(test)]
|
|
618
|
-
mod tests;
|