@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,502 +0,0 @@
|
|
|
1
|
-
//! step 4 · event_log — `events.jsonl` 唯一审计流(真相源 `events.py`)。
|
|
2
|
-
//!
|
|
3
|
-
//! 每行一个事件:`{"ts": iso8601_utc, "event": type, ...fields}`,经
|
|
4
|
-
//! `json.dumps(sort_keys=True, ensure_ascii=False)` 序列化。**字节对拍要点(对抗检查)**:
|
|
5
|
-
//! - Python `json.dumps` 默认分隔符是 `", "` / `": "`(**带空格**)→ 自定义 [`PythonFormatter`]
|
|
6
|
-
//! (serde_json 默认无空格)。
|
|
7
|
-
//! - `sort_keys=True` 是**递归**排序 → [`sort_value`](preserve_order 下按 sorted 序重建;
|
|
8
|
-
//! envelope/state 仍需插入序,故不全局改 serde_json)。
|
|
9
|
-
//! - `ensure_ascii=False` → serde_json 默认即不转义非 ASCII(UTF-8 字面)。
|
|
10
|
-
//! - 轮转:5 MiB × 保留 5 archives(`events.jsonl.1..5`)。
|
|
11
|
-
//!
|
|
12
|
-
//! §10:无 unwrap/expect/panic;rotation 的 rename 失败best-effort 忽略(对应 Python
|
|
13
|
-
//! `except OSError: pass`,bug-084 的 os.replace 崩溃教训)。
|
|
14
|
-
//!
|
|
15
|
-
//! **有意分歧/已知边界(对抗检查确认,事件流里不会触发或不复刻 Python bug)**:
|
|
16
|
-
//! - `tail` 用 `\n` 行分割(JSONL 正解),**不复刻** Python `splitlines()` 在 U+2028/U+2029/
|
|
17
|
-
//! NEL 上误切 JSON 行的潜在 bug(§11 不重蹈)。
|
|
18
|
-
//! - 事件字段**可含 float**(如 `waited_sec: 0.0`,见 bug_082 golden):正常小数 serde_json 与
|
|
19
|
-
//! Python 字节一致(`0.0`/`0.5`…),由真 fixture round-trip 锁死。**已知边界**:`|v|<1e-4` 的
|
|
20
|
-
//! 指数浮点(`1e-07` vs serde `1e-7`、`1e-05` vs `0.00001`)与 NaN/Infinity、超 i64 整数会漂移 ——
|
|
21
|
-
//! 实测事件流不出现这些值,故未启 serde_json `arbitrary_precision`(全局影响 Number/preserve_order)
|
|
22
|
-
//! 或自定义 CPython float_repr;若将来引入,需重审。
|
|
23
|
-
#![deny(clippy::unwrap_used, clippy::expect_used, clippy::panic)]
|
|
24
|
-
|
|
25
|
-
use std::io::Write as _;
|
|
26
|
-
use std::path::{Path, PathBuf};
|
|
27
|
-
|
|
28
|
-
use serde::Serialize as _;
|
|
29
|
-
use serde_json::Value;
|
|
30
|
-
use thiserror::Error;
|
|
31
|
-
|
|
32
|
-
use crate::model::paths::logs_dir;
|
|
33
|
-
|
|
34
|
-
/// `events.py:17`:5 MiB。
|
|
35
|
-
pub const EVENT_LOG_ROTATE_BYTES: u64 = 5 * 1024 * 1024;
|
|
36
|
-
/// `events.py:18`:保留 5 个 archive。
|
|
37
|
-
pub const EVENT_LOG_ARCHIVE_KEEP: u32 = 5;
|
|
38
|
-
pub(crate) const PROVIDER_SESSION_CONVERGING: &str = "provider.session.converging";
|
|
39
|
-
pub(crate) const PROVIDER_WORKER_SPAWN_ARGV: &str = "provider.worker.spawn_argv";
|
|
40
|
-
|
|
41
|
-
pub(crate) fn provider_worker_spawn_argv_fields(fields: Value) -> Value {
|
|
42
|
-
let object = fields.as_object();
|
|
43
|
-
let field = |key: &str| {
|
|
44
|
-
object
|
|
45
|
-
.and_then(|object| object.get(key))
|
|
46
|
-
.cloned()
|
|
47
|
-
.unwrap_or(Value::Null)
|
|
48
|
-
};
|
|
49
|
-
let array = |key: &str| match field(key) {
|
|
50
|
-
value @ Value::Array(_) => value,
|
|
51
|
-
_ => Value::Array(Vec::new()),
|
|
52
|
-
};
|
|
53
|
-
serde_json::json!({
|
|
54
|
-
"agent_id": field("agent_id"),
|
|
55
|
-
"provider": field("provider"),
|
|
56
|
-
"argv": array("argv"),
|
|
57
|
-
"session_id_in_argv": field("session_id_in_argv"),
|
|
58
|
-
"expected_session_id": field("expected_session_id"),
|
|
59
|
-
"spawn_cwd": field("spawn_cwd"),
|
|
60
|
-
"spawned_at": field("spawned_at"),
|
|
61
|
-
"source": field("source"),
|
|
62
|
-
"spawn_epoch": field("spawn_epoch"),
|
|
63
|
-
"env_overlay_keys": array("env_overlay_keys"),
|
|
64
|
-
"env_unset": array("env_unset"),
|
|
65
|
-
"tmux_start_mode": field("tmux_start_mode"),
|
|
66
|
-
"tmux_endpoint": field("tmux_endpoint"),
|
|
67
|
-
"tmux_endpoint_source": field("tmux_endpoint_source"),
|
|
68
|
-
})
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
#[derive(Debug, Error)]
|
|
72
|
-
pub enum EventLogError {
|
|
73
|
-
#[error("io: {0}")]
|
|
74
|
-
Io(#[from] std::io::Error),
|
|
75
|
-
#[error("json: {0}")]
|
|
76
|
-
Json(#[from] serde_json::Error),
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/// serde_json `Formatter`,复刻 Python `json.dumps` 默认分隔符 `", "` / `": "`。
|
|
80
|
-
struct PythonFormatter;
|
|
81
|
-
|
|
82
|
-
impl serde_json::ser::Formatter for PythonFormatter {
|
|
83
|
-
fn begin_array_value<W: ?Sized + std::io::Write>(
|
|
84
|
-
&mut self,
|
|
85
|
-
w: &mut W,
|
|
86
|
-
first: bool,
|
|
87
|
-
) -> std::io::Result<()> {
|
|
88
|
-
if first {
|
|
89
|
-
Ok(())
|
|
90
|
-
} else {
|
|
91
|
-
w.write_all(b", ")
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
fn begin_object_key<W: ?Sized + std::io::Write>(
|
|
95
|
-
&mut self,
|
|
96
|
-
w: &mut W,
|
|
97
|
-
first: bool,
|
|
98
|
-
) -> std::io::Result<()> {
|
|
99
|
-
if first {
|
|
100
|
-
Ok(())
|
|
101
|
-
} else {
|
|
102
|
-
w.write_all(b", ")
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
fn begin_object_value<W: ?Sized + std::io::Write>(&mut self, w: &mut W) -> std::io::Result<()> {
|
|
106
|
-
w.write_all(b": ")
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
/// 递归把 object 键排序(`sort_keys=True`)。preserve_order 下 `serde_json::Map` 是 IndexMap,
|
|
111
|
-
/// 按 sorted 序插入 → 序列化按插入序 = sorted。
|
|
112
|
-
fn sort_value(v: &Value) -> Value {
|
|
113
|
-
match v {
|
|
114
|
-
Value::Object(m) => {
|
|
115
|
-
let mut keys: Vec<&String> = m.keys().collect();
|
|
116
|
-
keys.sort_unstable();
|
|
117
|
-
let mut out = serde_json::Map::new();
|
|
118
|
-
for k in keys {
|
|
119
|
-
if let Some(val) = m.get(k) {
|
|
120
|
-
out.insert(k.clone(), sort_value(val));
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
Value::Object(out)
|
|
124
|
-
}
|
|
125
|
-
Value::Array(a) => Value::Array(a.iter().map(sort_value).collect()),
|
|
126
|
-
other => other.clone(),
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
/// `json.dumps(value, sort_keys=True, ensure_ascii=False)` 的字节等价(传入前先 [`sort_value`])。
|
|
131
|
-
fn to_python_json(value: &Value) -> String {
|
|
132
|
-
let mut buf = Vec::new();
|
|
133
|
-
let mut ser = serde_json::Serializer::with_formatter(&mut buf, PythonFormatter);
|
|
134
|
-
if value.serialize(&mut ser).is_err() {
|
|
135
|
-
return String::new();
|
|
136
|
-
}
|
|
137
|
-
String::from_utf8(buf).unwrap_or_default() // serde_json 必产合法 UTF-8
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
/// `datetime.now(utc).isoformat()` 字节等价:micros==0 省略小数秒(Python isoformat),否则 6 位微秒。
|
|
141
|
-
fn format_ts(dt: chrono::DateTime<chrono::Utc>) -> String {
|
|
142
|
-
if dt.timestamp_subsec_micros() == 0 {
|
|
143
|
-
dt.to_rfc3339_opts(chrono::SecondsFormat::Secs, false)
|
|
144
|
-
} else {
|
|
145
|
-
dt.to_rfc3339_opts(chrono::SecondsFormat::Micros, false)
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
/// `events.py:EventLog`。
|
|
150
|
-
pub struct EventLog {
|
|
151
|
-
path: PathBuf,
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
impl EventLog {
|
|
155
|
-
/// `EventLog(workspace)`:路径 = `<workspace>/.team/logs/events.jsonl`。
|
|
156
|
-
pub fn new(workspace: &Path) -> Self {
|
|
157
|
-
Self {
|
|
158
|
-
path: logs_dir(workspace).join("events.jsonl"),
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
/// 直接指定 events.jsonl 路径(测试 / 非标准布局)。
|
|
163
|
-
pub fn at(path: PathBuf) -> Self {
|
|
164
|
-
Self { path }
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
/// `EventLog.write`:追加一行 `{ts, event, **fields}`(sort_keys + Python 分隔符)。
|
|
168
|
-
/// 返回合并后的事件 Value。`fields` 应是 object;非 object 视作无字段。
|
|
169
|
-
pub fn write(&self, event_type: &str, fields: Value) -> Result<Value, EventLogError> {
|
|
170
|
-
if let Some(parent) = self.path.parent() {
|
|
171
|
-
std::fs::create_dir_all(parent)?;
|
|
172
|
-
}
|
|
173
|
-
let ts = format_ts(chrono::Utc::now());
|
|
174
|
-
let mut obj = serde_json::Map::new();
|
|
175
|
-
obj.insert("ts".to_string(), Value::String(ts));
|
|
176
|
-
obj.insert("event".to_string(), Value::String(event_type.to_string()));
|
|
177
|
-
if let Value::Object(f) = fields {
|
|
178
|
-
for (k, v) in f {
|
|
179
|
-
obj.insert(k, v);
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
let event = crate::redaction::redact_external_value(&Value::Object(obj));
|
|
183
|
-
self.maybe_rotate()?;
|
|
184
|
-
// 单次 write_all(line+"\n"):POSIX O_APPEND 对 <PIPE_BUF 写原子,避免并发写者交错(对抗 P1)。
|
|
185
|
-
let mut bytes = to_python_json(&sort_value(&event)).into_bytes();
|
|
186
|
-
bytes.push(b'\n');
|
|
187
|
-
let mut file = std::fs::OpenOptions::new()
|
|
188
|
-
.create(true)
|
|
189
|
-
.append(true)
|
|
190
|
-
.open(&self.path)?;
|
|
191
|
-
file.write_all(&bytes)?;
|
|
192
|
-
Ok(event)
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
/// `EventLog.tail`:末尾 `limit` 行,逐行 JSON parse;失败行 → `{"raw": line}`。
|
|
196
|
-
pub fn tail(&self, limit: usize) -> Result<Vec<Value>, EventLogError> {
|
|
197
|
-
if !self.path.exists() {
|
|
198
|
-
return Ok(Vec::new());
|
|
199
|
-
}
|
|
200
|
-
let text = std::fs::read_to_string(&self.path)?;
|
|
201
|
-
let lines: Vec<&str> = text.lines().collect();
|
|
202
|
-
// Python lines[-limit:]:limit==0 → lines[0:] = 全部(负零切片怪癖);limit>len → 全部。
|
|
203
|
-
let start = if limit == 0 {
|
|
204
|
-
0
|
|
205
|
-
} else {
|
|
206
|
-
lines.len().saturating_sub(limit)
|
|
207
|
-
};
|
|
208
|
-
let mut out = Vec::new();
|
|
209
|
-
for line in &lines[start..] {
|
|
210
|
-
match serde_json::from_str::<Value>(line) {
|
|
211
|
-
Ok(v) => out.push(crate::redaction::redact_external_value(&v)),
|
|
212
|
-
Err(_) => {
|
|
213
|
-
let mut m = serde_json::Map::new();
|
|
214
|
-
m.insert("raw".to_string(), Value::String((*line).to_string()));
|
|
215
|
-
out.push(crate::redaction::redact_external_value(&Value::Object(m)));
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
Ok(out)
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
/// `events.py:_maybe_rotate`:size >= 5 MiB → 丢最旧 + 移位 + current→.1。rename 失败忽略。
|
|
223
|
-
fn maybe_rotate(&self) -> Result<(), EventLogError> {
|
|
224
|
-
let size = match std::fs::metadata(&self.path) {
|
|
225
|
-
Ok(m) => m.len(),
|
|
226
|
-
Err(_) => return Ok(()), // 文件不存在 → 不轮转(对应 Python FileNotFoundError)
|
|
227
|
-
};
|
|
228
|
-
if size < EVENT_LOG_ROTATE_BYTES {
|
|
229
|
-
return Ok(());
|
|
230
|
-
}
|
|
231
|
-
let oldest = self.archive_path(EVENT_LOG_ARCHIVE_KEEP);
|
|
232
|
-
if oldest.exists() {
|
|
233
|
-
let _ = std::fs::remove_file(&oldest);
|
|
234
|
-
}
|
|
235
|
-
for idx in (1..EVENT_LOG_ARCHIVE_KEEP).rev() {
|
|
236
|
-
let src = self.archive_path(idx);
|
|
237
|
-
if src.exists() {
|
|
238
|
-
let _ = std::fs::rename(&src, self.archive_path(idx + 1));
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
let _ = std::fs::rename(&self.path, self.archive_path(1));
|
|
242
|
-
Ok(())
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
fn archive_path(&self, index: u32) -> PathBuf {
|
|
246
|
-
let name = self
|
|
247
|
-
.path
|
|
248
|
-
.file_name()
|
|
249
|
-
.map_or_else(String::new, |n| n.to_string_lossy().into_owned());
|
|
250
|
-
self.path.with_file_name(format!("{name}.{index}"))
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
#[cfg(test)]
|
|
255
|
-
mod tests {
|
|
256
|
-
#![allow(clippy::unwrap_used, clippy::panic, clippy::expect_used)]
|
|
257
|
-
use super::*;
|
|
258
|
-
use serde_json::json;
|
|
259
|
-
use std::sync::atomic::{AtomicU32, Ordering};
|
|
260
|
-
|
|
261
|
-
static SEQ: AtomicU32 = AtomicU32::new(0);
|
|
262
|
-
fn temp_ws() -> PathBuf {
|
|
263
|
-
let n = SEQ.fetch_add(1, Ordering::Relaxed);
|
|
264
|
-
let ws = std::env::temp_dir().join(format!("ta_rs_ev_{}_{}", std::process::id(), n));
|
|
265
|
-
std::fs::create_dir_all(&ws).unwrap();
|
|
266
|
-
ws
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
// 确定性字节对拍:to_python_json(sort_value(..)) == Python json.dumps(sort_keys,ensure_ascii=False)。
|
|
270
|
-
#[test]
|
|
271
|
-
fn python_json_format_byte_parity() {
|
|
272
|
-
let v = json!({"event":"u","msg":"héllo🦀\n世界","nested":{"b":2,"a":[1,2]}});
|
|
273
|
-
assert_eq!(
|
|
274
|
-
to_python_json(&sort_value(&v)),
|
|
275
|
-
r#"{"event": "u", "msg": "héllo🦀\n世界", "nested": {"a": [1, 2], "b": 2}}"#
|
|
276
|
-
);
|
|
277
|
-
// 空 fields。
|
|
278
|
-
assert_eq!(
|
|
279
|
-
to_python_json(&sort_value(&json!({"event":"empty"}))),
|
|
280
|
-
r#"{"event": "empty"}"#
|
|
281
|
-
);
|
|
282
|
-
// 类型:bool/null/int 与 Python 一致。
|
|
283
|
-
assert_eq!(
|
|
284
|
-
to_python_json(&sort_value(&json!({"missing":false,"x":null,"n":2}))),
|
|
285
|
-
r#"{"missing": false, "n": 2, "x": null}"#
|
|
286
|
-
);
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
#[test]
|
|
290
|
-
fn write_sorts_keys_and_has_ts_event() {
|
|
291
|
-
let ws = temp_ws();
|
|
292
|
-
let log = EventLog::new(&ws);
|
|
293
|
-
log.write(
|
|
294
|
-
"schema.layout_rebuild",
|
|
295
|
-
json!({"table":"messages","row_count_before":2,"row_count_after":2,"missing":false}),
|
|
296
|
-
)
|
|
297
|
-
.unwrap();
|
|
298
|
-
let line = std::fs::read_to_string(ws.join(".team/logs/events.jsonl")).unwrap();
|
|
299
|
-
let line = line.trim_end();
|
|
300
|
-
// 键全排序:event < missing < row_count_after < row_count_before < table < ts。
|
|
301
|
-
assert!(line.starts_with(r#"{"event": "schema.layout_rebuild", "missing": false, "row_count_after": 2, "row_count_before": 2, "table": "messages", "ts": "#));
|
|
302
|
-
// ts 是合法 rfc3339 UTC。
|
|
303
|
-
let v: Value = serde_json::from_str(line).unwrap();
|
|
304
|
-
let ts = v["ts"].as_str().unwrap();
|
|
305
|
-
assert!(
|
|
306
|
-
chrono::DateTime::parse_from_rfc3339(ts).is_ok(),
|
|
307
|
-
"ts 非合法 rfc3339: {ts}"
|
|
308
|
-
);
|
|
309
|
-
assert!(ts.ends_with("+00:00"));
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
#[test]
|
|
313
|
-
fn provider_spawn_fields_have_one_canonical_shape() {
|
|
314
|
-
let fields = provider_worker_spawn_argv_fields(json!({
|
|
315
|
-
"agent_id": "worker",
|
|
316
|
-
"provider": "fake",
|
|
317
|
-
"source": "restart",
|
|
318
|
-
"ignored": "not part of the schema",
|
|
319
|
-
}));
|
|
320
|
-
let object = fields.as_object().unwrap();
|
|
321
|
-
let keys = object
|
|
322
|
-
.keys()
|
|
323
|
-
.map(String::as_str)
|
|
324
|
-
.collect::<std::collections::BTreeSet<_>>();
|
|
325
|
-
assert_eq!(
|
|
326
|
-
keys,
|
|
327
|
-
[
|
|
328
|
-
"agent_id",
|
|
329
|
-
"argv",
|
|
330
|
-
"env_overlay_keys",
|
|
331
|
-
"env_unset",
|
|
332
|
-
"expected_session_id",
|
|
333
|
-
"provider",
|
|
334
|
-
"session_id_in_argv",
|
|
335
|
-
"source",
|
|
336
|
-
"spawn_cwd",
|
|
337
|
-
"spawn_epoch",
|
|
338
|
-
"spawned_at",
|
|
339
|
-
"tmux_endpoint",
|
|
340
|
-
"tmux_endpoint_source",
|
|
341
|
-
"tmux_start_mode",
|
|
342
|
-
]
|
|
343
|
-
.into_iter()
|
|
344
|
-
.collect::<std::collections::BTreeSet<_>>()
|
|
345
|
-
);
|
|
346
|
-
assert_eq!(fields["argv"], json!([]));
|
|
347
|
-
assert_eq!(fields["env_overlay_keys"], json!([]));
|
|
348
|
-
assert_eq!(fields["env_unset"], json!([]));
|
|
349
|
-
assert!(fields["spawn_cwd"].is_null());
|
|
350
|
-
assert!(fields.get("ignored").is_none());
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
#[test]
|
|
354
|
-
fn tail_returns_last_n_and_raw_on_bad_line() {
|
|
355
|
-
let ws = temp_ws();
|
|
356
|
-
let log = EventLog::new(&ws);
|
|
357
|
-
for i in 0..5 {
|
|
358
|
-
log.write("e", json!({"i":i})).unwrap();
|
|
359
|
-
}
|
|
360
|
-
// 追加一行坏 JSON。
|
|
361
|
-
let p = ws.join(".team/logs/events.jsonl");
|
|
362
|
-
let mut f = std::fs::OpenOptions::new().append(true).open(&p).unwrap();
|
|
363
|
-
f.write_all(b"not json\n").unwrap();
|
|
364
|
-
drop(f);
|
|
365
|
-
let t = log.tail(2).unwrap();
|
|
366
|
-
assert_eq!(t.len(), 2);
|
|
367
|
-
assert_eq!(t[0]["i"], json!(4));
|
|
368
|
-
assert_eq!(t[1]["raw"], json!("not json"));
|
|
369
|
-
// 不存在 → 空。
|
|
370
|
-
assert!(EventLog::new(&temp_ws()).tail(10).unwrap().is_empty());
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
#[test]
|
|
374
|
-
fn rotation_at_threshold_shifts_archives_and_drops_oldest() {
|
|
375
|
-
let ws = temp_ws();
|
|
376
|
-
let p = logs_dir(&ws).join("events.jsonl");
|
|
377
|
-
std::fs::create_dir_all(p.parent().unwrap()).unwrap();
|
|
378
|
-
let log = EventLog::at(p.clone());
|
|
379
|
-
// 预置 current >= 5MiB + 已有 .1..=.5 archive(各带标记内容)。
|
|
380
|
-
std::fs::write(&p, vec![b'x'; EVENT_LOG_ROTATE_BYTES as usize]).unwrap();
|
|
381
|
-
for i in 1..=EVENT_LOG_ARCHIVE_KEEP {
|
|
382
|
-
std::fs::write(
|
|
383
|
-
p.with_file_name(format!("events.jsonl.{i}")),
|
|
384
|
-
format!("arc{i}"),
|
|
385
|
-
)
|
|
386
|
-
.unwrap();
|
|
387
|
-
}
|
|
388
|
-
// 下一次 write 触发轮转:.5 丢弃,.4→.5 ... .1→.2,current→.1。
|
|
389
|
-
log.write("after.rotate", json!({})).unwrap();
|
|
390
|
-
// current 现在是轮转后的新文件,只含刚写的一条。
|
|
391
|
-
let new_current = std::fs::read_to_string(&p).unwrap();
|
|
392
|
-
assert_eq!(new_current.lines().count(), 1);
|
|
393
|
-
assert!(new_current.contains("after.rotate"));
|
|
394
|
-
// .1 = 旧 current(5MiB 的 x)。
|
|
395
|
-
assert_eq!(
|
|
396
|
-
std::fs::metadata(p.with_file_name("events.jsonl.1"))
|
|
397
|
-
.unwrap()
|
|
398
|
-
.len(),
|
|
399
|
-
EVENT_LOG_ROTATE_BYTES
|
|
400
|
-
);
|
|
401
|
-
// .2 = 旧 .1(内容 "arc1");.5 = 旧 .4("arc4");旧 .5("arc5")被丢弃。
|
|
402
|
-
assert_eq!(
|
|
403
|
-
std::fs::read_to_string(p.with_file_name("events.jsonl.2")).unwrap(),
|
|
404
|
-
"arc1"
|
|
405
|
-
);
|
|
406
|
-
assert_eq!(
|
|
407
|
-
std::fs::read_to_string(p.with_file_name("events.jsonl.5")).unwrap(),
|
|
408
|
-
"arc4"
|
|
409
|
-
);
|
|
410
|
-
}
|
|
411
|
-
|
|
412
|
-
#[test]
|
|
413
|
-
fn no_rotation_below_threshold() {
|
|
414
|
-
let ws = temp_ws();
|
|
415
|
-
let log = EventLog::new(&ws);
|
|
416
|
-
log.write("small", json!({})).unwrap();
|
|
417
|
-
log.write("small2", json!({})).unwrap();
|
|
418
|
-
// 未超阈值 → 无 .1 archive。
|
|
419
|
-
assert!(!ws.join(".team/logs/events.jsonl.1").exists());
|
|
420
|
-
assert_eq!(log.tail(10).unwrap().len(), 2);
|
|
421
|
-
}
|
|
422
|
-
|
|
423
|
-
// 对抗 P4:ts micros==0 省略小数秒(Python isoformat);否则 6 位微秒。golden 自 Python。
|
|
424
|
-
#[test]
|
|
425
|
-
fn format_ts_matches_python_isoformat() {
|
|
426
|
-
let m0 = chrono::DateTime::from_timestamp(1_780_000_000, 0).unwrap();
|
|
427
|
-
assert_eq!(format_ts(m0), "2026-05-28T20:26:40+00:00");
|
|
428
|
-
let m = chrono::DateTime::from_timestamp(1_780_000_000, 123_456_000).unwrap();
|
|
429
|
-
assert_eq!(format_ts(m), "2026-05-28T20:26:40.123456+00:00");
|
|
430
|
-
}
|
|
431
|
-
|
|
432
|
-
// 对抗 P7:tail(0) 复刻 Python lines[-0:] = 全部(负零切片怪癖)。
|
|
433
|
-
#[test]
|
|
434
|
-
fn tail_zero_returns_all_limit_clamps() {
|
|
435
|
-
let ws = temp_ws();
|
|
436
|
-
let log = EventLog::new(&ws);
|
|
437
|
-
for i in 0..3 {
|
|
438
|
-
log.write("e", json!({ "i": i })).unwrap();
|
|
439
|
-
}
|
|
440
|
-
assert_eq!(
|
|
441
|
-
log.tail(0).unwrap().len(),
|
|
442
|
-
3,
|
|
443
|
-
"tail(0) == 全部(Python [-0:])"
|
|
444
|
-
);
|
|
445
|
-
assert_eq!(log.tail(2).unwrap().len(), 2);
|
|
446
|
-
assert_eq!(log.tail(99).unwrap().len(), 3);
|
|
447
|
-
}
|
|
448
|
-
|
|
449
|
-
// 对抗 P1:多写者并发 append 不交错(单次 write_all 原子)。每行须是完整合法 JSON。
|
|
450
|
-
#[test]
|
|
451
|
-
fn concurrent_appends_do_not_interleave() {
|
|
452
|
-
let ws = temp_ws();
|
|
453
|
-
let path = logs_dir(&ws).join("events.jsonl");
|
|
454
|
-
std::fs::create_dir_all(path.parent().unwrap()).unwrap();
|
|
455
|
-
let threads: Vec<_> = (0..8)
|
|
456
|
-
.map(|t| {
|
|
457
|
-
let p = path.clone();
|
|
458
|
-
std::thread::spawn(move || {
|
|
459
|
-
let log = EventLog::at(p);
|
|
460
|
-
for i in 0..50 {
|
|
461
|
-
log.write("concurrent", json!({ "t": t, "i": i })).unwrap();
|
|
462
|
-
}
|
|
463
|
-
})
|
|
464
|
-
})
|
|
465
|
-
.collect();
|
|
466
|
-
for h in threads {
|
|
467
|
-
h.join().unwrap();
|
|
468
|
-
}
|
|
469
|
-
let text = std::fs::read_to_string(&path).unwrap();
|
|
470
|
-
let lines: Vec<&str> = text.lines().collect();
|
|
471
|
-
assert_eq!(lines.len(), 8 * 50, "无半行/丢行");
|
|
472
|
-
for line in &lines {
|
|
473
|
-
// 每行完整合法 JSON 且含 event 键 → 未交错。
|
|
474
|
-
let v: Value =
|
|
475
|
-
serde_json::from_str(line).unwrap_or_else(|e| panic!("交错坏行: {line:?} ({e})"));
|
|
476
|
-
assert_eq!(v["event"], json!("concurrent"));
|
|
477
|
-
}
|
|
478
|
-
}
|
|
479
|
-
|
|
480
|
-
// 对抗 P5:真 events.jsonl golden(60 行 Python 序列化)逐行 round-trip 字节对拍。
|
|
481
|
-
#[test]
|
|
482
|
-
fn real_events_jsonl_fixture_round_trips_byte_identical() {
|
|
483
|
-
let fixture = include_str!(concat!(
|
|
484
|
-
env!("CARGO_MANIFEST_DIR"),
|
|
485
|
-
"/../../snapshot/fixtures/bug_082_codex_trust/macmini_0210_own_events_after_corrected_send.jsonl"
|
|
486
|
-
));
|
|
487
|
-
let mut n = 0;
|
|
488
|
-
for line in fixture.lines() {
|
|
489
|
-
if line.is_empty() {
|
|
490
|
-
continue;
|
|
491
|
-
}
|
|
492
|
-
let v: Value = serde_json::from_str(line).unwrap();
|
|
493
|
-
assert_eq!(
|
|
494
|
-
to_python_json(&sort_value(&v)),
|
|
495
|
-
line,
|
|
496
|
-
"第 {n} 行 round-trip 不字节一致"
|
|
497
|
-
);
|
|
498
|
-
n += 1;
|
|
499
|
-
}
|
|
500
|
-
assert_eq!(n, 60, "fixture 应 60 行");
|
|
501
|
-
}
|
|
502
|
-
}
|