@team-agent/installer 0.5.128 → 0.6.1
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 +4 -4
- package/README.zh.md +1 -1
- package/package.json +4 -8
- package/skills/team-agent/SKILL.md +37 -20
- package/skills/team-agent/command-coverage.json +169 -183
- package/skills/team-agent/docs/reference/team-agent-operator.md +64 -30
- package/skills/team-agent/references/recovery-runbook.md +1 -1
- package/skills/team-agent/references/team-agent-operator.md +64 -30
- 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 -1288
- package/crates/team-agent/src/cli/arguments.rs +0 -405
- package/crates/team-agent/src/cli/attach_app_server_leader.rs +0 -98
- package/crates/team-agent/src/cli/diagnose.rs +0 -1721
- package/crates/team-agent/src/cli/emit.rs +0 -2930
- 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 -1216
- package/crates/team-agent/src/cli/intent/runtime_tests.rs +0 -912
- package/crates/team-agent/src/cli/intent/tests.rs +0 -689
- 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 -6545
- package/crates/team-agent/src/cli/models.rs +0 -1206
- 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/schedule.rs +0 -175
- 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 -156
- 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 -199
- package/crates/team-agent/src/cli/shutdown_socket.rs +0 -288
- package/crates/team-agent/src/cli/spec.rs +0 -165
- 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 -1981
- 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 -322
- 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 -761
- package/crates/team-agent/src/cli/tests/parser_safety.rs +0 -383
- package/crates/team-agent/src/cli/tests/run_delegation.rs +0 -484
- 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 -888
- 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 -827
- package/crates/team-agent/src/compiler.rs +0 -890
- 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 -1744
- package/crates/team-agent/src/contract_runtime/commands.rs +0 -671
- package/crates/team-agent/src/contract_runtime/config.rs +0 -364
- package/crates/team-agent/src/contract_runtime/config_tests.rs +0 -76
- package/crates/team-agent/src/contract_runtime/discovery.rs +0 -449
- package/crates/team-agent/src/contract_runtime/fork.rs +0 -361
- package/crates/team-agent/src/contract_runtime/forward.rs +0 -288
- package/crates/team-agent/src/contract_runtime/framework.rs +0 -367
- package/crates/team-agent/src/contract_runtime/mcp.rs +0 -394
- 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 -553
- 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 -300
- 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 -503
- 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 -3024
- 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 -1527
- 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/direct_delivery.rs +0 -368
- 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/inbox_store.rs +0 -169
- 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 -888
- package/crates/team-agent/src/leader/start.rs +0 -4501
- 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 -268
- 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 -147
- package/crates/team-agent/src/lifecycle/helpers.rs +0 -212
- package/crates/team-agent/src/lifecycle/launch/add_agent.rs +0 -881
- package/crates/team-agent/src/lifecycle/launch/add_agent_state.rs +0 -598
- package/crates/team-agent/src/lifecycle/launch/agent_state.rs +0 -332
- package/crates/team-agent/src/lifecycle/launch/clone_agent.rs +0 -204
- package/crates/team-agent/src/lifecycle/launch/fork_agent.rs +0 -107
- package/crates/team-agent/src/lifecycle/launch/fork_entry.rs +0 -144
- 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 -160
- package/crates/team-agent/src/lifecycle/launch/ownership.rs +0 -105
- package/crates/team-agent/src/lifecycle/launch/pi_mcp.rs +0 -899
- package/crates/team-agent/src/lifecycle/launch/pi_mcp_extension.js +0 -225
- package/crates/team-agent/src/lifecycle/launch/plan.rs +0 -269
- package/crates/team-agent/src/lifecycle/launch/quick_start.rs +0 -5200
- 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 -473
- 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 -557
- 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 -1067
- package/crates/team-agent/src/lifecycle/profile_smoke.rs +0 -557
- package/crates/team-agent/src/lifecycle/restart/agent.rs +0 -2199
- package/crates/team-agent/src/lifecycle/restart/avatar.rs +0 -1798
- package/crates/team-agent/src/lifecycle/restart/claude_fork.rs +0 -163
- package/crates/team-agent/src/lifecycle/restart/common.rs +0 -2362
- 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 -227
- package/crates/team-agent/src/lifecycle/role_config.rs +0 -1230
- 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_compatible_config_red.rs +0 -325
- package/crates/team-agent/src/lifecycle/tests/claude_profile_launch_red.rs +0 -447
- package/crates/team-agent/src/lifecycle/tests/cli_argv_routing_red.rs +0 -1638
- 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 -770
- package/crates/team-agent/src/lifecycle/tests/communication_mode_runtime_contract_red.rs +0 -419
- package/crates/team-agent/src/lifecycle/tests/copilot_provider_red.rs +0 -2035
- package/crates/team-agent/src/lifecycle/tests/core.rs +0 -1327
- 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 -72
- 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 -512
- 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 -3983
- 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 -164
- package/crates/team-agent/src/lifecycle/tests/pi_command_red.rs +0 -200
- package/crates/team-agent/src/lifecycle/tests/pi_compiler_red.rs +0 -210
- package/crates/team-agent/src/lifecycle/tests/pi_dual_entry_red.rs +0 -527
- package/crates/team-agent/src/lifecycle/tests/pi_executable_mcp_red.rs +0 -1062
- package/crates/team-agent/src/lifecycle/tests/pi_fork_session_inheritance_red.rs +0 -1419
- package/crates/team-agent/src/lifecycle/tests/pi_lifecycle_doctor_red.rs +0 -98
- package/crates/team-agent/src/lifecycle/tests/pi_native_mcp_capability_red.rs +0 -550
- package/crates/team-agent/src/lifecycle/tests/pi_session_delivery_red.rs +0 -226
- package/crates/team-agent/src/lifecycle/tests/quick_start_worker_readiness_red.rs +0 -332
- 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 -342
- 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 -995
- package/crates/team-agent/src/lifecycle/tests/worker_spawn_env_red.rs +0 -836
- package/crates/team-agent/src/lifecycle/tests.rs +0 -105
- package/crates/team-agent/src/lifecycle/types.rs +0 -877
- package/crates/team-agent/src/lifecycle/worker_command_context.rs +0 -363
- 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 -527
- package/crates/team-agent/src/mcp_server/readiness_tests.rs +0 -348
- 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 -158
- package/crates/team-agent/src/mcp_server/tests/send.rs +0 -353
- package/crates/team-agent/src/mcp_server/tests/tools.rs +0 -341
- 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 -889
- 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 -3727
- 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 -336
- 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 -167
- 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/reminders.rs +0 -316
- 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 -223
- 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 -657
- 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 -3549
- package/crates/team-agent/src/messaging/tests/spine.rs +0 -853
- 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 -472
- 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 -1150
- package/crates/team-agent/src/provider/adapters/claude.rs +0 -78
- package/crates/team-agent/src/provider/adapters/claude_fork.rs +0 -131
- package/crates/team-agent/src/provider/adapters/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 -30
- package/crates/team-agent/src/provider/adapters/pi.rs +0 -106
- 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 -708
- 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 -910
- package/crates/team-agent/src/provider/session/capture.rs +0 -2731
- package/crates/team-agent/src/provider/session/context_fork/claude.rs +0 -123
- package/crates/team-agent/src/provider/session/context_fork/outcome.rs +0 -172
- package/crates/team-agent/src/provider/session/context_fork.rs +0 -396
- 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/claude.rs +0 -523
- package/crates/team-agent/src/provider/session_scan/common/tests.rs +0 -316
- package/crates/team-agent/src/provider/session_scan/common.rs +0 -654
- package/crates/team-agent/src/provider/session_scan/copilot.rs +0 -280
- package/crates/team-agent/src/provider/session_scan/pi.rs +0 -185
- package/crates/team-agent/src/provider/session_scan.rs +0 -71
- 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 -441
- package/crates/team-agent/src/provider/tests/classify.rs +0 -148
- package/crates/team-agent/src/provider/tests/command_helpers.rs +0 -35
- 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 -177
- 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 -394
- 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/test_support/models_timeout_fixture.rs +0 -144
- 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 -4103
- package/crates/team-agent/src/tmux_backend.rs +0 -4492
- 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,234 +0,0 @@
|
|
|
1
|
-
#![allow(clippy::unwrap_used)]
|
|
2
|
-
|
|
3
|
-
use super::*;
|
|
4
|
-
use crate::transport::{native_input::InputFrame, test_support::OfflineTransport};
|
|
5
|
-
use std::sync::atomic::{AtomicU64, Ordering};
|
|
6
|
-
|
|
7
|
-
struct Fixture {
|
|
8
|
-
workspace: std::path::PathBuf,
|
|
9
|
-
store: MessageStore,
|
|
10
|
-
state: serde_json::Value,
|
|
11
|
-
}
|
|
12
|
-
impl Fixture {
|
|
13
|
-
fn new(provider: &str) -> Self {
|
|
14
|
-
static NEXT: AtomicU64 = AtomicU64::new(0);
|
|
15
|
-
let workspace = std::env::temp_dir().join(format!(
|
|
16
|
-
"ta-consumption-{}-{}",
|
|
17
|
-
std::process::id(),
|
|
18
|
-
NEXT.fetch_add(1, Ordering::Relaxed)
|
|
19
|
-
));
|
|
20
|
-
std::fs::create_dir_all(&workspace).unwrap();
|
|
21
|
-
let store = MessageStore::open(&workspace).unwrap();
|
|
22
|
-
let conn = crate::db::schema::open_db(store.db_path()).unwrap();
|
|
23
|
-
conn.execute("insert into messages(message_id,owner_team_id,sender,recipient,content,status,created_at,updated_at,delivery_attempts) values('msg_one','team','operator','worker','body','accepted','old','old',0)", []).unwrap();
|
|
24
|
-
let state = serde_json::json!({"team_key":"team","session_name":"session","agents":{"worker":{
|
|
25
|
-
"status":"running","provider":provider,"pane_id":"%1","pane_pid":2,"window":"worker"
|
|
26
|
-
}}});
|
|
27
|
-
Self {
|
|
28
|
-
workspace,
|
|
29
|
-
store,
|
|
30
|
-
state,
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
fn transport(&self) -> OfflineTransport {
|
|
34
|
-
OfflineTransport::new()
|
|
35
|
-
.with_session_present(true)
|
|
36
|
-
.with_targets(vec![PaneInfo {
|
|
37
|
-
pane_id: PaneId::new("%1"),
|
|
38
|
-
session: SessionName::new("session"),
|
|
39
|
-
window_index: Some(1),
|
|
40
|
-
window_name: Some(WindowName::new("worker")),
|
|
41
|
-
pane_index: Some(0),
|
|
42
|
-
tty: None,
|
|
43
|
-
current_command: None,
|
|
44
|
-
current_path: Some(self.workspace.clone()),
|
|
45
|
-
active: true,
|
|
46
|
-
pane_pid: Some(2),
|
|
47
|
-
leader_env: Default::default(),
|
|
48
|
-
}])
|
|
49
|
-
.with_default_liveness(crate::transport::PaneLiveness::Live)
|
|
50
|
-
}
|
|
51
|
-
fn deliver(&self, transport: &OfflineTransport) -> DeliveryOutcome {
|
|
52
|
-
let message = message_for_delivery(&self.store, "msg_one")
|
|
53
|
-
.unwrap()
|
|
54
|
-
.unwrap();
|
|
55
|
-
deliver_prepared_message(
|
|
56
|
-
&self.workspace,
|
|
57
|
-
&self.store,
|
|
58
|
-
transport,
|
|
59
|
-
"msg_one",
|
|
60
|
-
&EventLog::new(&self.workspace),
|
|
61
|
-
&self.state,
|
|
62
|
-
message,
|
|
63
|
-
PreparedMessageState {
|
|
64
|
-
scoped: None,
|
|
65
|
-
canonical_owner_team_id: Some("team".into()),
|
|
66
|
-
},
|
|
67
|
-
)
|
|
68
|
-
.unwrap()
|
|
69
|
-
}
|
|
70
|
-
fn receipt(&self) -> (String, i64) {
|
|
71
|
-
let conn = crate::db::schema::open_db(self.store.db_path()).unwrap();
|
|
72
|
-
(
|
|
73
|
-
conn.query_row(
|
|
74
|
-
"select status from messages where message_id='msg_one'",
|
|
75
|
-
[],
|
|
76
|
-
|r| r.get(0),
|
|
77
|
-
)
|
|
78
|
-
.unwrap(),
|
|
79
|
-
conn.query_row(
|
|
80
|
-
"select count(*) from scheduled_events where kind='enter_rescue'",
|
|
81
|
-
[],
|
|
82
|
-
|r| r.get(0),
|
|
83
|
-
)
|
|
84
|
-
.unwrap(),
|
|
85
|
-
)
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
impl Drop for Fixture {
|
|
89
|
-
fn drop(&mut self) {
|
|
90
|
-
let _ = std::fs::remove_dir_all(&self.workspace);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
fn frame(composer: &str, transcript: &str) -> InputFrame {
|
|
94
|
-
InputFrame {
|
|
95
|
-
composer: composer.into(),
|
|
96
|
-
transcript: transcript.into(),
|
|
97
|
-
identity: "known-current-ui".into(),
|
|
98
|
-
footer: "owned cwd".into(),
|
|
99
|
-
busy: false,
|
|
100
|
-
capsule: None,
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
#[test]
|
|
105
|
-
fn current_token_in_composer_is_not_duplicate_delivered_or_repasted() {
|
|
106
|
-
let f = Fixture::new("pi");
|
|
107
|
-
let marker = message_token_marker("msg_one");
|
|
108
|
-
let t = f
|
|
109
|
-
.transport()
|
|
110
|
-
.with_capture_for_pane("%1", &marker)
|
|
111
|
-
.with_native_input_observation(frame(&marker, &marker));
|
|
112
|
-
let out = f.deliver(&t);
|
|
113
|
-
assert!(!out.ok);
|
|
114
|
-
assert_eq!(f.receipt(), ("submitted_unverified".into(), 1));
|
|
115
|
-
assert!(t.inject_payloads().is_empty());
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
#[test]
|
|
119
|
-
fn successful_transport_report_does_not_override_unconsumed_composer() {
|
|
120
|
-
for composer in [
|
|
121
|
-
"[team-agent-token:msg_one]",
|
|
122
|
-
"[Pasted text #1 +25 lines]",
|
|
123
|
-
"foreign draft",
|
|
124
|
-
] {
|
|
125
|
-
let mut f = Fixture::new("pi");
|
|
126
|
-
#[cfg(unix)]
|
|
127
|
-
let panes = vec![crate::mcp_server::readiness::test_ready_worker(
|
|
128
|
-
&f.workspace,
|
|
129
|
-
&mut f.state,
|
|
130
|
-
"team",
|
|
131
|
-
"worker",
|
|
132
|
-
"%1",
|
|
133
|
-
)];
|
|
134
|
-
#[cfg(not(unix))]
|
|
135
|
-
let panes = f.transport().list_targets().unwrap();
|
|
136
|
-
let t = f
|
|
137
|
-
.transport()
|
|
138
|
-
.with_targets(panes)
|
|
139
|
-
.with_native_input_observation(frame(composer, ""));
|
|
140
|
-
let out = f.deliver(&t);
|
|
141
|
-
assert!(!out.ok, "composer={composer}");
|
|
142
|
-
assert_eq!(f.receipt(), ("submitted_unverified".into(), 1));
|
|
143
|
-
assert_eq!(t.inject_payloads().len(), 1);
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
#[test]
|
|
148
|
-
fn unknown_current_native_surface_is_unverified_not_success() {
|
|
149
|
-
let f = Fixture::new("pi");
|
|
150
|
-
let t = f
|
|
151
|
-
.transport()
|
|
152
|
-
.with_native_input_error("native_surface_unknown");
|
|
153
|
-
assert!(!f.deliver(&t).ok);
|
|
154
|
-
assert_eq!(f.receipt(), ("submitted_unverified".into(), 1));
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
#[test]
|
|
158
|
-
fn pane_visibility_without_an_observation_protocol_is_not_duplicate_acceptance() {
|
|
159
|
-
let f = Fixture::new("fake");
|
|
160
|
-
let t = f
|
|
161
|
-
.transport()
|
|
162
|
-
.with_capture_for_pane("%1", message_token_marker("msg_one"));
|
|
163
|
-
assert!(!f.deliver(&t).ok);
|
|
164
|
-
assert_eq!(f.receipt(), ("submitted_unverified".into(), 1));
|
|
165
|
-
assert!(t.inject_payloads().is_empty());
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
#[test]
|
|
169
|
-
fn current_empty_composer_and_unique_transcript_token_prove_consumption() {
|
|
170
|
-
let f = Fixture::new("pi");
|
|
171
|
-
let marker = message_token_marker("msg_one");
|
|
172
|
-
let t = f
|
|
173
|
-
.transport()
|
|
174
|
-
.with_capture_for_pane("%1", &marker)
|
|
175
|
-
.with_native_input_observation(frame("", &marker));
|
|
176
|
-
assert!(f.deliver(&t).ok);
|
|
177
|
-
assert_eq!(f.receipt(), ("delivered".into(), 0));
|
|
178
|
-
assert!(t.inject_payloads().is_empty());
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
#[test]
|
|
182
|
-
fn busy_answers_or_duplicate_history_tokens_do_not_prove_consumption() {
|
|
183
|
-
let f = Fixture::new("pi");
|
|
184
|
-
let target = Target::Pane(PaneId::new("%1"));
|
|
185
|
-
for transcript in [
|
|
186
|
-
"answer is 5535",
|
|
187
|
-
"[team-agent-token:msg_one]\n[team-agent-token:msg_one]",
|
|
188
|
-
] {
|
|
189
|
-
let mut view = frame("", transcript);
|
|
190
|
-
view.busy = true;
|
|
191
|
-
let t = f.transport().with_native_input_observation(view);
|
|
192
|
-
assert_eq!(
|
|
193
|
-
observed_token_consumed(&t, &f.state, "worker", &target, "msg_one"),
|
|
194
|
-
Some(false)
|
|
195
|
-
);
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
#[test]
|
|
200
|
-
fn unsupported_observation_keeps_existing_positive_transport_receipt() {
|
|
201
|
-
let f = Fixture::new("fake");
|
|
202
|
-
assert!(f.deliver(&f.transport()).ok);
|
|
203
|
-
assert_eq!(f.receipt(), ("delivered".into(), 0));
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
#[test]
|
|
207
|
-
fn mark_unverified_schedules_once_and_insert_failure_rolls_back_status() {
|
|
208
|
-
let f = Fixture::new("fake");
|
|
209
|
-
f.store
|
|
210
|
-
.mark("msg_one", "submitted_unverified", Some("opaque no proof"))
|
|
211
|
-
.unwrap();
|
|
212
|
-
f.store
|
|
213
|
-
.mark("msg_one", "submitted_unverified", Some("again"))
|
|
214
|
-
.unwrap();
|
|
215
|
-
assert_eq!(f.receipt(), ("submitted_unverified".into(), 1));
|
|
216
|
-
let conn = crate::db::schema::open_db(f.store.db_path()).unwrap();
|
|
217
|
-
let payload: String = conn
|
|
218
|
-
.query_row("select payload_json from scheduled_events", [], |r| {
|
|
219
|
-
r.get(0)
|
|
220
|
-
})
|
|
221
|
-
.unwrap();
|
|
222
|
-
let job: serde_json::Value = serde_json::from_str(&payload).unwrap();
|
|
223
|
-
assert!(job["context"]["target"].is_null());
|
|
224
|
-
assert!(job["context"]["proof"].is_null());
|
|
225
|
-
|
|
226
|
-
let g = Fixture::new("fake");
|
|
227
|
-
let conn = crate::db::schema::open_db(g.store.db_path()).unwrap();
|
|
228
|
-
conn.execute_batch("create trigger refuse_rescue before insert on scheduled_events begin select raise(abort,'fixture failure'); end;").unwrap();
|
|
229
|
-
assert!(g
|
|
230
|
-
.store
|
|
231
|
-
.mark("msg_one", "submitted_unverified", None)
|
|
232
|
-
.is_err());
|
|
233
|
-
assert_eq!(g.receipt(), ("accepted".into(), 0));
|
|
234
|
-
}
|
|
@@ -1,362 +0,0 @@
|
|
|
1
|
-
//! Durable independent Enter-only watchdog. An uncertain effect is never replayed.
|
|
2
|
-
|
|
3
|
-
use std::path::Path;
|
|
4
|
-
|
|
5
|
-
use chrono::{DateTime, Duration, Utc};
|
|
6
|
-
use rusqlite::{params, OptionalExtension, Transaction};
|
|
7
|
-
use serde::{Deserialize, Serialize};
|
|
8
|
-
use sha2::{Digest, Sha256};
|
|
9
|
-
|
|
10
|
-
use super::delivery::{render_message, top_level_state_matches_owner_team};
|
|
11
|
-
use super::MessagingError;
|
|
12
|
-
use crate::event_log::EventLog;
|
|
13
|
-
use crate::message_store::MessageStore;
|
|
14
|
-
use crate::transport::enter_rescue::{EnterRescueContext, EnterRescueOutcome};
|
|
15
|
-
use crate::transport::Transport;
|
|
16
|
-
|
|
17
|
-
#[cfg(test)]
|
|
18
|
-
#[path = "enter_rescue_tests.rs"]
|
|
19
|
-
mod tests;
|
|
20
|
-
|
|
21
|
-
const DELAY_SECONDS: i64 = 90;
|
|
22
|
-
const EXPIRE_SECONDS: i64 = 120;
|
|
23
|
-
|
|
24
|
-
#[derive(Debug, Serialize, Deserialize)]
|
|
25
|
-
struct RescueJob {
|
|
26
|
-
schema: u8,
|
|
27
|
-
context: EnterRescueContext,
|
|
28
|
-
registered_at: String,
|
|
29
|
-
expires_at: String,
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
fn digest(text: &str) -> String {
|
|
33
|
-
format!("{:x}", Sha256::digest(text.as_bytes()))
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
fn timestamp(value: &str) -> Result<DateTime<Utc>, MessagingError> {
|
|
37
|
-
DateTime::parse_from_rfc3339(value)
|
|
38
|
-
.map(|value| value.with_timezone(&Utc))
|
|
39
|
-
.map_err(|_| MessagingError::Validation("enter_rescue: invalid timestamp".into()))
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/// Called in the message-status transaction, even when no carrier/proof exists.
|
|
43
|
-
/// One original registration survives duplicates, unknown effects and restarts.
|
|
44
|
-
pub(crate) fn schedule_in_tx(
|
|
45
|
-
tx: &Transaction<'_>,
|
|
46
|
-
message_id: &str,
|
|
47
|
-
now: DateTime<Utc>,
|
|
48
|
-
) -> Result<(), rusqlite::Error> {
|
|
49
|
-
let row = tx.query_row(
|
|
50
|
-
"select owner_team_id,coalesce(recipient,''),coalesce(sender,''),task_id,coalesce(content,'')
|
|
51
|
-
from messages where message_id=?1 and status='submitted_unverified'",
|
|
52
|
-
[message_id],
|
|
53
|
-
|row| Ok((row.get::<_, Option<String>>(0)?, row.get::<_, String>(1)?,
|
|
54
|
-
row.get::<_, String>(2)?, row.get::<_, Option<String>>(3)?, row.get::<_, String>(4)?)),
|
|
55
|
-
).optional()?;
|
|
56
|
-
let Some((owner, recipient, sender, task, content)) = row else {
|
|
57
|
-
return Ok(());
|
|
58
|
-
};
|
|
59
|
-
let job = RescueJob {
|
|
60
|
-
schema: 1,
|
|
61
|
-
context: EnterRescueContext {
|
|
62
|
-
message_id: message_id.into(),
|
|
63
|
-
owner_team_id: owner.clone().unwrap_or_default(),
|
|
64
|
-
recipient: recipient.clone(),
|
|
65
|
-
payload_sha256: digest(&render_message(
|
|
66
|
-
&sender,
|
|
67
|
-
task.as_deref(),
|
|
68
|
-
&content,
|
|
69
|
-
message_id,
|
|
70
|
-
)),
|
|
71
|
-
target: None,
|
|
72
|
-
proof: None,
|
|
73
|
-
},
|
|
74
|
-
registered_at: now.to_rfc3339(),
|
|
75
|
-
expires_at: (now + Duration::seconds(EXPIRE_SECONDS)).to_rfc3339(),
|
|
76
|
-
};
|
|
77
|
-
let payload = serde_json::to_string(&job)
|
|
78
|
-
.map_err(|error| rusqlite::Error::ToSqlConversionFailure(Box::new(error)))?;
|
|
79
|
-
tx.execute(
|
|
80
|
-
"insert into scheduled_events(kind,target,payload_json,due_at,status,owner_team_id,created_at)
|
|
81
|
-
select 'enter_rescue',?1,?2,?3,'pending',?4,?5 where not exists(
|
|
82
|
-
select 1 from scheduled_events where kind='enter_rescue' and case when json_valid(payload_json)
|
|
83
|
-
then coalesce(json_extract(payload_json,'$.context.message_id'),json_extract(payload_json,'$.evidence.request.message_id')) end=?6)",
|
|
84
|
-
params![recipient, payload, (now + Duration::seconds(DELAY_SECONDS)).to_rfc3339(), owner,
|
|
85
|
-
now.to_rfc3339(), message_id],
|
|
86
|
-
)?;
|
|
87
|
-
Ok(())
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
/// Supplement the original job at the original delivery boundary, never at fire.
|
|
91
|
-
/// This cannot change its scope, message digest, initial clock, or a bound carrier.
|
|
92
|
-
pub(crate) fn bind_pending_context(
|
|
93
|
-
store: &MessageStore,
|
|
94
|
-
context: &EnterRescueContext,
|
|
95
|
-
) -> Result<bool, MessagingError> {
|
|
96
|
-
let conn = crate::db::schema::open_db(store.db_path())?;
|
|
97
|
-
let row = conn.query_row(
|
|
98
|
-
"select id,payload_json from scheduled_events where kind='enter_rescue' and status='pending'
|
|
99
|
-
and case when json_valid(payload_json) then json_extract(payload_json,'$.context.message_id') end=?1",
|
|
100
|
-
[&context.message_id], |row| Ok((row.get::<_, i64>(0)?, row.get::<_, String>(1)?)),
|
|
101
|
-
).optional()?;
|
|
102
|
-
let Some((id, previous)) = row else {
|
|
103
|
-
return Ok(false);
|
|
104
|
-
};
|
|
105
|
-
let mut job: RescueJob = serde_json::from_str(&previous)?;
|
|
106
|
-
if job.schema != 1
|
|
107
|
-
|| job.context.message_id != context.message_id
|
|
108
|
-
|| job.context.owner_team_id != context.owner_team_id
|
|
109
|
-
|| job.context.recipient != context.recipient
|
|
110
|
-
|| job.context.payload_sha256 != context.payload_sha256
|
|
111
|
-
|| job.context.target.as_ref().is_some_and(|target| {
|
|
112
|
-
!context
|
|
113
|
-
.target
|
|
114
|
-
.as_ref()
|
|
115
|
-
.is_some_and(|next| target.same_selection(next))
|
|
116
|
-
|| (target.bound() && job.context != *context)
|
|
117
|
-
})
|
|
118
|
-
{
|
|
119
|
-
return Ok(false);
|
|
120
|
-
}
|
|
121
|
-
job.context = context.clone();
|
|
122
|
-
Ok(conn.execute(
|
|
123
|
-
"update scheduled_events set payload_json=?2 where id=?1 and status='pending' and payload_json=?3
|
|
124
|
-
and exists(select 1 from messages where message_id=?4 and status='submitted_unverified'
|
|
125
|
-
and owner_team_id=?5 and recipient=?6)",
|
|
126
|
-
params![id, serde_json::to_string(&job)?, previous, context.message_id,
|
|
127
|
-
context.owner_team_id, context.recipient],
|
|
128
|
-
)? == 1)
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
fn canonical_valid(
|
|
132
|
-
workspace: &Path,
|
|
133
|
-
store: &MessageStore,
|
|
134
|
-
job: &RescueJob,
|
|
135
|
-
) -> Result<bool, MessagingError> {
|
|
136
|
-
let context = &job.context;
|
|
137
|
-
let registered = timestamp(&job.registered_at)?;
|
|
138
|
-
let expires = timestamp(&job.expires_at)?;
|
|
139
|
-
let now = Utc::now();
|
|
140
|
-
if job.schema != 1
|
|
141
|
-
|| !context.valid_message()
|
|
142
|
-
|| expires != registered + Duration::seconds(EXPIRE_SECONDS)
|
|
143
|
-
|| now < registered + Duration::seconds(DELAY_SECONDS)
|
|
144
|
-
|| now > expires
|
|
145
|
-
{
|
|
146
|
-
return Ok(false);
|
|
147
|
-
}
|
|
148
|
-
let conn = crate::db::schema::open_db(store.db_path())?;
|
|
149
|
-
let original = conn
|
|
150
|
-
.query_row(
|
|
151
|
-
"select sender,task_id,content,created_at from messages where message_id=?1
|
|
152
|
-
and owner_team_id=?2 and recipient=?3 and status='submitted_unverified'",
|
|
153
|
-
params![context.message_id, context.owner_team_id, context.recipient],
|
|
154
|
-
|row| {
|
|
155
|
-
Ok((
|
|
156
|
-
row.get::<_, String>(0)?,
|
|
157
|
-
row.get::<_, Option<String>>(1)?,
|
|
158
|
-
row.get::<_, String>(2)?,
|
|
159
|
-
row.get::<_, String>(3)?,
|
|
160
|
-
))
|
|
161
|
-
},
|
|
162
|
-
)
|
|
163
|
-
.optional()?;
|
|
164
|
-
let Some((sender, task, content, created_at)) = original else {
|
|
165
|
-
return Ok(false);
|
|
166
|
-
};
|
|
167
|
-
if digest(&render_message(
|
|
168
|
-
&sender,
|
|
169
|
-
task.as_deref(),
|
|
170
|
-
&content,
|
|
171
|
-
&context.message_id,
|
|
172
|
-
)) != context.payload_sha256
|
|
173
|
-
{
|
|
174
|
-
return Ok(false);
|
|
175
|
-
}
|
|
176
|
-
let newer: bool = conn.query_row(
|
|
177
|
-
"select exists(select 1 from messages where owner_team_id=?1 and recipient=?2
|
|
178
|
-
and message_id<>?3 and created_at>=?4 and delivery_attempts>0)",
|
|
179
|
-
params![
|
|
180
|
-
context.owner_team_id,
|
|
181
|
-
context.recipient,
|
|
182
|
-
context.message_id,
|
|
183
|
-
created_at
|
|
184
|
-
],
|
|
185
|
-
|row| row.get(0),
|
|
186
|
-
)?;
|
|
187
|
-
if newer {
|
|
188
|
-
return Ok(false);
|
|
189
|
-
}
|
|
190
|
-
let raw = crate::state::persist::load_runtime_state(workspace)?;
|
|
191
|
-
if !matches!(crate::state::projection::resolve_owner_team_id(&raw, &context.owner_team_id),
|
|
192
|
-
crate::state::projection::OwnerTeamResolution::Canonical(team) if team == context.owner_team_id)
|
|
193
|
-
{
|
|
194
|
-
return Ok(false);
|
|
195
|
-
}
|
|
196
|
-
let state = if raw
|
|
197
|
-
.get("teams")
|
|
198
|
-
.and_then(serde_json::Value::as_object)
|
|
199
|
-
.is_some_and(|teams| teams.contains_key(&context.owner_team_id))
|
|
200
|
-
{
|
|
201
|
-
crate::state::projection::project_top_level_view(&raw, &context.owner_team_id)
|
|
202
|
-
} else if top_level_state_matches_owner_team(&raw, &context.owner_team_id) {
|
|
203
|
-
raw
|
|
204
|
-
} else {
|
|
205
|
-
return Ok(false);
|
|
206
|
-
};
|
|
207
|
-
let Some(agent) = state
|
|
208
|
-
.get("agents")
|
|
209
|
-
.and_then(|agents| agents.get(&context.recipient))
|
|
210
|
-
else {
|
|
211
|
-
return Ok(false);
|
|
212
|
-
};
|
|
213
|
-
if agent.get("status").and_then(serde_json::Value::as_str) != Some("running")
|
|
214
|
-
|| agent
|
|
215
|
-
.get("explicit_stop")
|
|
216
|
-
.and_then(serde_json::Value::as_bool)
|
|
217
|
-
== Some(true)
|
|
218
|
-
{
|
|
219
|
-
return Ok(false);
|
|
220
|
-
}
|
|
221
|
-
// An unbound job is still an observable scheduled job, but never key authority.
|
|
222
|
-
let Some(target) = context.target.as_ref() else {
|
|
223
|
-
return Ok(true);
|
|
224
|
-
};
|
|
225
|
-
Ok(
|
|
226
|
-
agent.get("pane_id").and_then(serde_json::Value::as_str) == Some(target.pane_id.as_str())
|
|
227
|
-
&& agent.get("pane_pid").and_then(serde_json::Value::as_u64)
|
|
228
|
-
== Some(u64::from(target.pane_pid))
|
|
229
|
-
&& state
|
|
230
|
-
.get("session_name")
|
|
231
|
-
.and_then(serde_json::Value::as_str)
|
|
232
|
-
== Some(target.session.as_str())
|
|
233
|
-
&& agent
|
|
234
|
-
.get("window")
|
|
235
|
-
.and_then(serde_json::Value::as_str)
|
|
236
|
-
.unwrap_or(&context.recipient)
|
|
237
|
-
== target.window
|
|
238
|
-
&& agent.get("provider").cloned().and_then(|value| {
|
|
239
|
-
serde_json::from_value::<crate::model::enums::Provider>(value).ok()
|
|
240
|
-
}) == Some(target.provider),
|
|
241
|
-
)
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
pub(super) fn fire(
|
|
245
|
-
workspace: &Path,
|
|
246
|
-
store: &MessageStore,
|
|
247
|
-
transport: &dyn Transport,
|
|
248
|
-
log: &EventLog,
|
|
249
|
-
id: i64,
|
|
250
|
-
payload: &str,
|
|
251
|
-
) -> Result<bool, MessagingError> {
|
|
252
|
-
fire_with(workspace, store, log, id, payload, &|context, authorize| {
|
|
253
|
-
super::delivery::with_rescue_submit_observer(workspace, store, context, log, |observer| {
|
|
254
|
-
transport
|
|
255
|
-
.rescue_enter_guarded(context, authorize, Some(observer))
|
|
256
|
-
.map_err(Into::into)
|
|
257
|
-
})
|
|
258
|
-
})
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
type Executor<'a> = dyn Fn(&EnterRescueContext, &dyn Fn() -> bool) -> Result<EnterRescueOutcome, MessagingError>
|
|
262
|
-
+ 'a;
|
|
263
|
-
|
|
264
|
-
fn fire_with(
|
|
265
|
-
workspace: &Path,
|
|
266
|
-
store: &MessageStore,
|
|
267
|
-
log: &EventLog,
|
|
268
|
-
id: i64,
|
|
269
|
-
payload: &str,
|
|
270
|
-
execute: &Executor<'_>,
|
|
271
|
-
) -> Result<bool, MessagingError> {
|
|
272
|
-
let conn = crate::db::schema::open_db(store.db_path())?;
|
|
273
|
-
if conn.execute(
|
|
274
|
-
"update scheduled_events set status='claimed',fired_at=?2 where id=?1 and kind='enter_rescue'
|
|
275
|
-
and status='pending' and due_at<=?2 and payload_json=?3",
|
|
276
|
-
params![id, Utc::now().to_rfc3339(), payload],
|
|
277
|
-
)? != 1 { return Ok(false); }
|
|
278
|
-
log.write("enter_rescue.claimed", serde_json::json!({"event_id":id}))?;
|
|
279
|
-
let result = (|| -> Result<(String, serde_json::Value, Option<String>), MessagingError> {
|
|
280
|
-
let job: RescueJob = serde_json::from_str(payload)?;
|
|
281
|
-
let context = &job.context;
|
|
282
|
-
let scope_matches: bool = conn.query_row(
|
|
283
|
-
"select coalesce(owner_team_id,'')=?2 and target=?3 and created_at=?4 from scheduled_events where id=?1",
|
|
284
|
-
params![id, context.owner_team_id, context.recipient, job.registered_at], |row| row.get(0),
|
|
285
|
-
)?;
|
|
286
|
-
if !scope_matches {
|
|
287
|
-
return Ok((
|
|
288
|
-
"refused".into(),
|
|
289
|
-
serde_json::json!({"reason":"job_scope_changed"}),
|
|
290
|
-
None,
|
|
291
|
-
));
|
|
292
|
-
}
|
|
293
|
-
if !canonical_valid(workspace, store, &job)? {
|
|
294
|
-
return Ok((
|
|
295
|
-
"refused".into(),
|
|
296
|
-
serde_json::json!({"reason":"canonical_changed_or_expired"}),
|
|
297
|
-
None,
|
|
298
|
-
));
|
|
299
|
-
}
|
|
300
|
-
if !context.target.as_ref().is_some_and(|target| target.bound()) || !context.valid_proof() {
|
|
301
|
-
return Ok((
|
|
302
|
-
"refused".into(),
|
|
303
|
-
serde_json::json!({"reason":"proof_missing","effect":"none"}),
|
|
304
|
-
None,
|
|
305
|
-
));
|
|
306
|
-
}
|
|
307
|
-
let authorize = || {
|
|
308
|
-
let still_claimed: bool = conn.query_row(
|
|
309
|
-
"select exists(select 1 from scheduled_events where id=?1 and kind='enter_rescue'
|
|
310
|
-
and status='claimed' and payload_json=?2 and owner_team_id=?3 and target=?4)",
|
|
311
|
-
params![id, payload, context.owner_team_id, context.recipient], |row| row.get(0),
|
|
312
|
-
).unwrap_or(false);
|
|
313
|
-
still_claimed && canonical_valid(workspace, store, &job).unwrap_or(false)
|
|
314
|
-
};
|
|
315
|
-
match execute(context, &authorize)? {
|
|
316
|
-
EnterRescueOutcome::NoEffect { reason, reobserve } => {
|
|
317
|
-
let next = Utc::now() + Duration::seconds(5);
|
|
318
|
-
let due =
|
|
319
|
-
(reobserve && next <= timestamp(&job.expires_at)?).then(|| next.to_rfc3339());
|
|
320
|
-
Ok((
|
|
321
|
-
if due.is_some() { "pending" } else { "refused" }.into(),
|
|
322
|
-
serde_json::json!({"reason":reason,"effect":"none"}),
|
|
323
|
-
due,
|
|
324
|
-
))
|
|
325
|
-
}
|
|
326
|
-
EnterRescueOutcome::Consumed | EnterRescueOutcome::Entered { accepted: true } => {
|
|
327
|
-
let changed = conn.execute(
|
|
328
|
-
"update messages set status='delivered',delivered_at=?2,updated_at=?2,error=null
|
|
329
|
-
where message_id=?1 and status='submitted_unverified' and owner_team_id=?3 and recipient=?4",
|
|
330
|
-
params![context.message_id, Utc::now().to_rfc3339(), context.owner_team_id, context.recipient],
|
|
331
|
-
)?;
|
|
332
|
-
Ok((
|
|
333
|
-
"done".into(),
|
|
334
|
-
serde_json::json!({"accepted":true,"message_updated":changed==1}),
|
|
335
|
-
None,
|
|
336
|
-
))
|
|
337
|
-
}
|
|
338
|
-
EnterRescueOutcome::Entered { accepted: false } => Ok((
|
|
339
|
-
"unknown".into(),
|
|
340
|
-
serde_json::json!({"accepted":false,"effect":"may_have_submitted"}),
|
|
341
|
-
None,
|
|
342
|
-
)),
|
|
343
|
-
}
|
|
344
|
-
})();
|
|
345
|
-
let (status, result, due) = result.unwrap_or_else(|error| {
|
|
346
|
-
(
|
|
347
|
-
"unknown".into(),
|
|
348
|
-
serde_json::json!({"error":error.to_string(),"retry":false}),
|
|
349
|
-
None,
|
|
350
|
-
)
|
|
351
|
-
});
|
|
352
|
-
conn.execute(
|
|
353
|
-
"update scheduled_events set status=?2,result_json=?3,due_at=coalesce(?4,due_at)
|
|
354
|
-
where id=?1 and kind='enter_rescue' and status='claimed'",
|
|
355
|
-
params![id, status, result.to_string(), due],
|
|
356
|
-
)?;
|
|
357
|
-
log.write(
|
|
358
|
-
"enter_rescue.result",
|
|
359
|
-
serde_json::json!({"event_id":id,"status":status,"result":result}),
|
|
360
|
-
)?;
|
|
361
|
-
Ok(true)
|
|
362
|
-
}
|