@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,981 +0,0 @@
|
|
|
1
|
-
//! send.py — 顶层发件入口 + 单发/广播/扇出 + owner-gate worker 旁路 + session-drift 拒绝 (card §64)。
|
|
2
|
-
|
|
3
|
-
use std::path::Path;
|
|
4
|
-
|
|
5
|
-
use crate::coordinator::{CoordinatorHealthStatus, WorkspacePath};
|
|
6
|
-
use crate::event_log::EventLog;
|
|
7
|
-
use crate::model::enums::PaneLiveness;
|
|
8
|
-
use crate::model::ids::{AgentId, TaskId, TeamKey};
|
|
9
|
-
use crate::transport::{PaneId, Transport};
|
|
10
|
-
|
|
11
|
-
use super::helpers::{status_wire, MessageStatusShadow};
|
|
12
|
-
use super::leader_receiver::send_to_leader_receiver_with_presentation;
|
|
13
|
-
use super::presentation::{
|
|
14
|
-
decide_presentation, PresentationDecision, PresentationRequest, PresentationSink,
|
|
15
|
-
PresentationSource,
|
|
16
|
-
};
|
|
17
|
-
use super::{
|
|
18
|
-
persist_resolved_send, DeliveryBlocker, DeliveryOutcome, DeliveryRefusal, DeliveryStatus,
|
|
19
|
-
InitialDisposition, LogicalRecipient, MessagingError, PersistResolution, ResolvedSendIntent,
|
|
20
|
-
SendOrigin,
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
/// 发件目标:单 target / 广播 `*` / 扇出 list (`send.py:36` `target: str|list[str]|None`)。
|
|
24
|
-
#[derive(Debug, Clone, PartialEq, Eq)]
|
|
25
|
-
pub enum MessageTarget {
|
|
26
|
-
/// 单 agent / pane target。
|
|
27
|
-
Single(String),
|
|
28
|
-
/// `"*"` 广播全队。
|
|
29
|
-
Broadcast,
|
|
30
|
-
/// 扇出到显式 list。
|
|
31
|
-
Fanout(Vec<String>),
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/// Sender identity captured from a framework-owned runtime context.
|
|
35
|
-
///
|
|
36
|
-
/// Public CLI/MCP inputs never construct this value from a caller-supplied
|
|
37
|
-
/// string. The wrapper keeps that trust boundary visible throughout delivery
|
|
38
|
-
/// instead of degrading the identity back to an untyped option field.
|
|
39
|
-
#[derive(Debug, Clone, PartialEq, Eq)]
|
|
40
|
-
pub struct TrustedSender {
|
|
41
|
-
agent_id: AgentId,
|
|
42
|
-
full_name: Option<String>,
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
impl TrustedSender {
|
|
46
|
-
pub fn from_runtime_identity(agent_id: AgentId) -> Self {
|
|
47
|
-
Self {
|
|
48
|
-
agent_id,
|
|
49
|
-
full_name: None,
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
pub fn from_runtime_identity_with_source(
|
|
54
|
-
agent_id: AgentId,
|
|
55
|
-
workspace: impl std::fmt::Display,
|
|
56
|
-
team: &str,
|
|
57
|
-
) -> Self {
|
|
58
|
-
let full_name = format!("{}::{}/{}", workspace, team, agent_id.as_str());
|
|
59
|
-
Self {
|
|
60
|
-
agent_id,
|
|
61
|
-
full_name: Some(full_name),
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
pub fn leader() -> Self {
|
|
66
|
-
Self {
|
|
67
|
-
agent_id: AgentId::new("leader"),
|
|
68
|
-
full_name: None,
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
pub fn as_str(&self) -> &str {
|
|
73
|
-
self.agent_id.as_str()
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
pub fn display_name(&self) -> &str {
|
|
77
|
-
self.full_name.as_deref().unwrap_or_else(|| self.as_str())
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
impl serde::Serialize for TrustedSender {
|
|
82
|
-
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
|
83
|
-
where
|
|
84
|
-
S: serde::Serializer,
|
|
85
|
-
{
|
|
86
|
-
serializer.serialize_str(self.display_name())
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
/// `send_message` 选项 (`send.py:36`:Python 大量默认参数 → typed 选项 struct)。
|
|
91
|
-
#[derive(Debug, Clone)]
|
|
92
|
-
pub struct SendOptions {
|
|
93
|
-
pub origin: SendOrigin,
|
|
94
|
-
pub task_id: Option<TaskId>,
|
|
95
|
-
/// `route_task_id`(golden `send.py:190`,默认 `True`):仅 **routing**(CLI `send --task`)时把
|
|
96
|
-
/// `task_id` 当真任务校验/路由。**投递/fanout/internal/coordinator** 路径传 `false`
|
|
97
|
-
/// (`internal_delivery.py:44`、`send.py:412/481`),此时 `task_id` 只是标签,**不校验 state.tasks**。
|
|
98
|
-
pub route_task_id: bool,
|
|
99
|
-
pub sender: TrustedSender,
|
|
100
|
-
pub requires_ack: bool,
|
|
101
|
-
pub confirm_human: bool,
|
|
102
|
-
pub wait_visible: bool,
|
|
103
|
-
pub timeout: f64,
|
|
104
|
-
pub lock_timeout: f64,
|
|
105
|
-
pub watch_result: bool,
|
|
106
|
-
pub block_until_delivered: bool,
|
|
107
|
-
pub team: Option<TeamKey>,
|
|
108
|
-
/// Caller-supplied idempotency key (CLI `--message-id`, CR-015/054). When `Some`,
|
|
109
|
-
/// the store insert uses this id verbatim; a repeat with the same id is rejected
|
|
110
|
-
/// as [`DeliveryRefusal::Duplicate`] instead of creating a second row.
|
|
111
|
-
pub message_id: Option<String>,
|
|
112
|
-
pub presentation: PresentationRequest,
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
impl Default for SendOptions {
|
|
116
|
-
fn default() -> Self {
|
|
117
|
-
// 默认值对齐 Python 签名 (`send.py:38-40`)。
|
|
118
|
-
Self {
|
|
119
|
-
origin: SendOrigin::Internal(super::InternalSendKind::Delivery),
|
|
120
|
-
task_id: None,
|
|
121
|
-
route_task_id: true,
|
|
122
|
-
sender: TrustedSender::leader(),
|
|
123
|
-
requires_ack: true,
|
|
124
|
-
confirm_human: false,
|
|
125
|
-
wait_visible: true,
|
|
126
|
-
timeout: 30.0,
|
|
127
|
-
lock_timeout: 5.0,
|
|
128
|
-
watch_result: false,
|
|
129
|
-
block_until_delivered: true,
|
|
130
|
-
team: None,
|
|
131
|
-
message_id: None,
|
|
132
|
-
presentation: PresentationRequest::default(),
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
/// `send_message` (`send.py:36`):顶层发件 —— 加 `_runtime_lock("send")`,解析 list/`*`/单
|
|
138
|
-
/// target,路由 + 权限 + 人确认门,投递或入队。MCP `send` 工具 + CLI 调它。
|
|
139
|
-
pub fn send_message(
|
|
140
|
-
workspace: &Path,
|
|
141
|
-
target: &MessageTarget,
|
|
142
|
-
content: &str,
|
|
143
|
-
opts: &SendOptions,
|
|
144
|
-
) -> Result<DeliveryOutcome, MessagingError> {
|
|
145
|
-
// N31/N32 funnel: leader / `*` broadcast / fanout-list dispatch sits HERE in send.py:
|
|
146
|
-
// single recipient falls through to the legacy worker path; `to=leader` routes to
|
|
147
|
-
// `send_to_leader_receiver` (the shared leader-delivery primitive); broadcast/fanout
|
|
148
|
-
// expand the recipient set and re-enter `send_message` per recipient so leader/peer
|
|
149
|
-
// each go through their own (same) primitive — no parallel BroadcastEngine.
|
|
150
|
-
let event_log = EventLog::new(workspace);
|
|
151
|
-
let raw_state = crate::state::persist::load_runtime_state(workspace)?;
|
|
152
|
-
let mut state = opts
|
|
153
|
-
.team
|
|
154
|
-
.as_ref()
|
|
155
|
-
.map(|team| crate::state::projection::project_top_level_view(&raw_state, team.as_str()))
|
|
156
|
-
.unwrap_or_else(|| raw_state.clone());
|
|
157
|
-
backfill_leader_binding_for_delivery_view(&mut state, &raw_state);
|
|
158
|
-
let recipient = match target {
|
|
159
|
-
MessageTarget::Single(target) if target == "leader" => {
|
|
160
|
-
let presentation = decide_presentation(&opts.presentation, PresentationSource::Send);
|
|
161
|
-
if presentation.effective_sink != PresentationSink::Leader {
|
|
162
|
-
return persist_stored_only_send(
|
|
163
|
-
workspace,
|
|
164
|
-
LogicalRecipient::Leader,
|
|
165
|
-
content,
|
|
166
|
-
opts,
|
|
167
|
-
&presentation,
|
|
168
|
-
&event_log,
|
|
169
|
-
);
|
|
170
|
-
}
|
|
171
|
-
let outcome = send_to_leader_receiver_with_presentation(
|
|
172
|
-
workspace,
|
|
173
|
-
&state,
|
|
174
|
-
"leader",
|
|
175
|
-
content,
|
|
176
|
-
opts.task_id.as_ref(),
|
|
177
|
-
opts.sender.display_name(),
|
|
178
|
-
opts.requires_ack,
|
|
179
|
-
None,
|
|
180
|
-
opts.message_id.as_deref(),
|
|
181
|
-
&presentation,
|
|
182
|
-
&event_log,
|
|
183
|
-
)?;
|
|
184
|
-
if matches!(outcome.status, DeliveryStatus::Queued) && owner_pane_is_dead(&state) {
|
|
185
|
-
if let Some(message_id) = outcome.message_id.clone() {
|
|
186
|
-
let team_key = owner_gate_hint_team_key(&state);
|
|
187
|
-
if !explicit_claim_applied(workspace, &team_key, "") {
|
|
188
|
-
return Ok(rebind_required_outcome_with_verification(
|
|
189
|
-
Some(message_id),
|
|
190
|
-
format!("team-agent claim-leader --team {team_key}"),
|
|
191
|
-
));
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
return Ok(outcome);
|
|
196
|
-
}
|
|
197
|
-
MessageTarget::Single(target) if target.is_empty() => {
|
|
198
|
-
return Ok(refused_outcome(DeliveryRefusal::UnknownRecipient));
|
|
199
|
-
}
|
|
200
|
-
MessageTarget::Single(target) => target,
|
|
201
|
-
MessageTarget::Broadcast => {
|
|
202
|
-
let recipients = broadcast_recipients(&state, opts.sender.as_str(), opts.team.as_ref());
|
|
203
|
-
return fanout_send(workspace, &recipients, content, opts, "*");
|
|
204
|
-
}
|
|
205
|
-
MessageTarget::Fanout(recipients) if recipients.is_empty() => {
|
|
206
|
-
// swallow batch 3 ②: a failed send carries its reason (Python send error
|
|
207
|
-
// reason style) — "failed with no reason" is an unexplained exit.
|
|
208
|
-
return Ok(DeliveryOutcome {
|
|
209
|
-
ok: false,
|
|
210
|
-
status: DeliveryStatus::Failed,
|
|
211
|
-
message_status: MessageStatusShadow("failed".to_string()),
|
|
212
|
-
message_id: None,
|
|
213
|
-
verification: None,
|
|
214
|
-
stage: None,
|
|
215
|
-
reason: Some(crate::messaging::DeliveryRefusal::EmptyTargetList),
|
|
216
|
-
channel: None,
|
|
217
|
-
ack_forced_off: false,
|
|
218
|
-
turn_verification: None,
|
|
219
|
-
});
|
|
220
|
-
}
|
|
221
|
-
MessageTarget::Fanout(recipients) => {
|
|
222
|
-
return fanout_send(workspace, recipients, content, opts, "fanout");
|
|
223
|
-
}
|
|
224
|
-
};
|
|
225
|
-
// send.py:259-261 — a non-leader target that is NOT a known team agent is refused
|
|
226
|
-
// (target_not_in_team), NOT persisted. Membership = the runtime state's `agents` map.
|
|
227
|
-
let in_team = state
|
|
228
|
-
.get("agents")
|
|
229
|
-
.and_then(|a| a.as_object())
|
|
230
|
-
.is_some_and(|a| a.contains_key(recipient.as_str()));
|
|
231
|
-
if !in_team {
|
|
232
|
-
return Ok(refused_outcome(DeliveryRefusal::TargetNotInTeam));
|
|
233
|
-
}
|
|
234
|
-
let presentation = decide_presentation(&opts.presentation, PresentationSource::Send);
|
|
235
|
-
if presentation.effective_sink != PresentationSink::Leader {
|
|
236
|
-
return persist_stored_only_send(
|
|
237
|
-
workspace,
|
|
238
|
-
LogicalRecipient::from_resolved(recipient),
|
|
239
|
-
content,
|
|
240
|
-
opts,
|
|
241
|
-
&presentation,
|
|
242
|
-
&event_log,
|
|
243
|
-
);
|
|
244
|
-
}
|
|
245
|
-
if let Some(outcome) = session_drift_refusal(
|
|
246
|
-
&state,
|
|
247
|
-
recipient,
|
|
248
|
-
"leader",
|
|
249
|
-
opts.sender.as_str(),
|
|
250
|
-
opts.task_id.as_ref(),
|
|
251
|
-
&event_log,
|
|
252
|
-
)? {
|
|
253
|
-
return Ok(outcome);
|
|
254
|
-
}
|
|
255
|
-
if let Some(outcome) = send_owner_gate_refusal(workspace, &state, opts.sender.as_str())? {
|
|
256
|
-
return Ok(outcome);
|
|
257
|
-
}
|
|
258
|
-
if opts.route_task_id {
|
|
259
|
-
if let Some(task_id) = opts.task_id.as_ref() {
|
|
260
|
-
if !task_exists(&state, task_id) {
|
|
261
|
-
return Err(MessagingError::Validation(format!(
|
|
262
|
-
"unknown task id: {}",
|
|
263
|
-
task_id.as_str()
|
|
264
|
-
)));
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
#[cfg(unix)]
|
|
269
|
-
if state
|
|
270
|
-
.get("agents")
|
|
271
|
-
.and_then(|agents| agents.get(recipient))
|
|
272
|
-
.is_some_and(crate::contract_runtime::framework::is_contract)
|
|
273
|
-
{
|
|
274
|
-
return crate::contract_runtime::framework::enqueue(
|
|
275
|
-
workspace, &state, recipient, content, opts,
|
|
276
|
-
);
|
|
277
|
-
}
|
|
278
|
-
let stale_worker_target_missing =
|
|
279
|
-
stale_worker_target_missing_preflight(workspace, &state, recipient)?;
|
|
280
|
-
let coordinator_unavailable = if stale_worker_target_missing {
|
|
281
|
-
None
|
|
282
|
-
} else {
|
|
283
|
-
coordinator_unavailable_outcome(workspace, recipient, opts, &event_log)?
|
|
284
|
-
};
|
|
285
|
-
if let Some(gate) = coordinator_unavailable
|
|
286
|
-
.as_ref()
|
|
287
|
-
.filter(|gate| !gate.persist)
|
|
288
|
-
{
|
|
289
|
-
return Ok(gate.outcome.clone());
|
|
290
|
-
}
|
|
291
|
-
let mut intent = ResolvedSendIntent::accepted(
|
|
292
|
-
opts.origin,
|
|
293
|
-
workspace,
|
|
294
|
-
opts.team.clone(),
|
|
295
|
-
LogicalRecipient::from_resolved(recipient),
|
|
296
|
-
opts.sender.clone(),
|
|
297
|
-
opts.task_id.clone(),
|
|
298
|
-
content,
|
|
299
|
-
None,
|
|
300
|
-
opts.requires_ack,
|
|
301
|
-
opts.message_id.clone(),
|
|
302
|
-
);
|
|
303
|
-
if coordinator_unavailable
|
|
304
|
-
.as_ref()
|
|
305
|
-
.is_some_and(|gate| gate.persist)
|
|
306
|
-
{
|
|
307
|
-
intent.initial_disposition =
|
|
308
|
-
InitialDisposition::Blocked(DeliveryBlocker::CoordinatorUnavailable);
|
|
309
|
-
}
|
|
310
|
-
let persisted = match persist_resolved_send(&intent)? {
|
|
311
|
-
PersistResolution::Persisted(persisted) => persisted,
|
|
312
|
-
PersistResolution::Duplicate(message_id) => {
|
|
313
|
-
return Ok(refused_outcome_with_id(
|
|
314
|
-
DeliveryRefusal::Duplicate,
|
|
315
|
-
Some(message_id),
|
|
316
|
-
));
|
|
317
|
-
}
|
|
318
|
-
};
|
|
319
|
-
let message_id = persisted.message_id.clone();
|
|
320
|
-
let store = crate::message_store::MessageStore::open(workspace)?;
|
|
321
|
-
if stale_worker_target_missing {
|
|
322
|
-
return super::delivery::mark_worker_target_missing(
|
|
323
|
-
&store,
|
|
324
|
-
&event_log,
|
|
325
|
-
&message_id,
|
|
326
|
-
recipient,
|
|
327
|
-
None,
|
|
328
|
-
);
|
|
329
|
-
}
|
|
330
|
-
capture_missing_sessions_after_send(workspace);
|
|
331
|
-
if let Some(CoordinatorUnavailableGate {
|
|
332
|
-
mut outcome,
|
|
333
|
-
persist: true,
|
|
334
|
-
}) = coordinator_unavailable
|
|
335
|
-
{
|
|
336
|
-
let Some(blocker) = persisted.blocker else {
|
|
337
|
-
return Err(MessagingError::Validation(
|
|
338
|
-
"coordinator-blocked persistence returned no blocker".to_string(),
|
|
339
|
-
));
|
|
340
|
-
};
|
|
341
|
-
let message_status = persisted.row_status.as_str();
|
|
342
|
-
event_log.write(
|
|
343
|
-
"send.message_queued",
|
|
344
|
-
serde_json::json!({
|
|
345
|
-
"message_id": message_id,
|
|
346
|
-
"recipient": recipient,
|
|
347
|
-
"sender": opts.sender,
|
|
348
|
-
"message_status": message_status,
|
|
349
|
-
"blocker": blocker.as_str(),
|
|
350
|
-
}),
|
|
351
|
-
)?;
|
|
352
|
-
outcome.ok = true;
|
|
353
|
-
outcome.status = DeliveryStatus::Blocked;
|
|
354
|
-
outcome.message_status = MessageStatusShadow(message_status.to_string());
|
|
355
|
-
outcome.message_id = Some(message_id);
|
|
356
|
-
return Ok(outcome);
|
|
357
|
-
}
|
|
358
|
-
Ok(DeliveryOutcome {
|
|
359
|
-
ok: true,
|
|
360
|
-
status: DeliveryStatus::Queued,
|
|
361
|
-
message_status: MessageStatusShadow(persisted.row_status.as_str().to_string()),
|
|
362
|
-
message_id: Some(message_id),
|
|
363
|
-
verification: None,
|
|
364
|
-
stage: None,
|
|
365
|
-
reason: None,
|
|
366
|
-
channel: None,
|
|
367
|
-
ack_forced_off: false,
|
|
368
|
-
turn_verification: None,
|
|
369
|
-
})
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
fn capture_missing_sessions_after_send(workspace: &Path) {
|
|
373
|
-
let Ok(mut state) = crate::state::persist::load_runtime_state(workspace) else {
|
|
374
|
-
return;
|
|
375
|
-
};
|
|
376
|
-
let Ok(report) = crate::session_capture::capture_missing_provider_sessions_once(
|
|
377
|
-
&mut state,
|
|
378
|
-
&mut crate::provider::get_adapter,
|
|
379
|
-
false,
|
|
380
|
-
0,
|
|
381
|
-
) else {
|
|
382
|
-
return;
|
|
383
|
-
};
|
|
384
|
-
if report.changed || !report.assigned.is_empty() {
|
|
385
|
-
// The post-send capture backfill routes through `StateRepository` with
|
|
386
|
-
// the `MessagingSessionCapture` intent; dispatch is the same root
|
|
387
|
-
// helper this callsite used directly before, and the error is still
|
|
388
|
-
// ignored because the capture is best-effort.
|
|
389
|
-
let _ = crate::state::repository::StateRepository::new(workspace).save(
|
|
390
|
-
crate::state::repository::StateWriteIntent::MessagingSessionCapture,
|
|
391
|
-
&state,
|
|
392
|
-
);
|
|
393
|
-
}
|
|
394
|
-
}
|
|
395
|
-
|
|
396
|
-
fn persist_stored_only_send(
|
|
397
|
-
workspace: &Path,
|
|
398
|
-
recipient: LogicalRecipient,
|
|
399
|
-
content: &str,
|
|
400
|
-
opts: &SendOptions,
|
|
401
|
-
presentation: &PresentationDecision,
|
|
402
|
-
event_log: &EventLog,
|
|
403
|
-
) -> Result<DeliveryOutcome, MessagingError> {
|
|
404
|
-
let mut intent = ResolvedSendIntent::accepted(
|
|
405
|
-
opts.origin,
|
|
406
|
-
workspace,
|
|
407
|
-
opts.team.clone(),
|
|
408
|
-
recipient,
|
|
409
|
-
opts.sender.clone(),
|
|
410
|
-
opts.task_id.clone(),
|
|
411
|
-
content,
|
|
412
|
-
None,
|
|
413
|
-
opts.requires_ack,
|
|
414
|
-
opts.message_id.clone(),
|
|
415
|
-
);
|
|
416
|
-
intent.initial_disposition = InitialDisposition::StoredOnly;
|
|
417
|
-
intent.presentation = presentation.clone();
|
|
418
|
-
let persisted = match persist_resolved_send(&intent)? {
|
|
419
|
-
PersistResolution::Persisted(persisted) => persisted,
|
|
420
|
-
PersistResolution::Duplicate(message_id) => {
|
|
421
|
-
return Ok(refused_outcome_with_id(
|
|
422
|
-
DeliveryRefusal::Duplicate,
|
|
423
|
-
Some(message_id),
|
|
424
|
-
));
|
|
425
|
-
}
|
|
426
|
-
};
|
|
427
|
-
event_log.write(
|
|
428
|
-
"presentation.stored_without_live_inject",
|
|
429
|
-
serde_json::json!({
|
|
430
|
-
"message_id": persisted.message_id,
|
|
431
|
-
"requested_sink": presentation.requested_sink,
|
|
432
|
-
"effective_sink": presentation.effective_sink,
|
|
433
|
-
"class": presentation.class,
|
|
434
|
-
"policy_reason": presentation.policy_reason,
|
|
435
|
-
}),
|
|
436
|
-
)?;
|
|
437
|
-
Ok(DeliveryOutcome {
|
|
438
|
-
ok: true,
|
|
439
|
-
status: DeliveryStatus::StoredOnly,
|
|
440
|
-
message_status: MessageStatusShadow("stored_only".to_string()),
|
|
441
|
-
message_id: Some(persisted.message_id),
|
|
442
|
-
verification: Some("durable_without_live_inject".to_string()),
|
|
443
|
-
stage: None,
|
|
444
|
-
reason: None,
|
|
445
|
-
channel: Some(presentation.effective_sink.as_str().to_string()),
|
|
446
|
-
ack_forced_off: false,
|
|
447
|
-
turn_verification: None,
|
|
448
|
-
})
|
|
449
|
-
}
|
|
450
|
-
|
|
451
|
-
fn stale_worker_target_missing_preflight(
|
|
452
|
-
workspace: &Path,
|
|
453
|
-
state: &serde_json::Value,
|
|
454
|
-
recipient: &str,
|
|
455
|
-
) -> Result<bool, MessagingError> {
|
|
456
|
-
let Ok(resolved) = crate::transport_factory::resolve_read_only_transport(
|
|
457
|
-
workspace,
|
|
458
|
-
Some(state),
|
|
459
|
-
crate::transport_factory::TransportPurpose::MessageDelivery,
|
|
460
|
-
) else {
|
|
461
|
-
return Ok(false);
|
|
462
|
-
};
|
|
463
|
-
Ok(super::delivery::worker_target_missing_due_to_stale_binding(
|
|
464
|
-
state,
|
|
465
|
-
recipient,
|
|
466
|
-
resolved.backend.as_ref(),
|
|
467
|
-
))
|
|
468
|
-
}
|
|
469
|
-
|
|
470
|
-
fn task_exists(state: &serde_json::Value, task_id: &TaskId) -> bool {
|
|
471
|
-
state
|
|
472
|
-
.get("tasks")
|
|
473
|
-
.and_then(serde_json::Value::as_array)
|
|
474
|
-
.is_some_and(|tasks| {
|
|
475
|
-
tasks.iter().any(|task| {
|
|
476
|
-
task.get("id").and_then(serde_json::Value::as_str) == Some(task_id.as_str())
|
|
477
|
-
})
|
|
478
|
-
})
|
|
479
|
-
}
|
|
480
|
-
|
|
481
|
-
fn refused_outcome(reason: DeliveryRefusal) -> DeliveryOutcome {
|
|
482
|
-
refused_outcome_with_id(reason, None)
|
|
483
|
-
}
|
|
484
|
-
|
|
485
|
-
fn refused_outcome_with_id(reason: DeliveryRefusal, message_id: Option<String>) -> DeliveryOutcome {
|
|
486
|
-
DeliveryOutcome {
|
|
487
|
-
ok: false,
|
|
488
|
-
status: DeliveryStatus::Refused,
|
|
489
|
-
message_status: MessageStatusShadow("refused".to_string()),
|
|
490
|
-
message_id,
|
|
491
|
-
verification: None,
|
|
492
|
-
stage: None,
|
|
493
|
-
reason: Some(reason),
|
|
494
|
-
channel: None,
|
|
495
|
-
ack_forced_off: false,
|
|
496
|
-
turn_verification: None,
|
|
497
|
-
}
|
|
498
|
-
}
|
|
499
|
-
|
|
500
|
-
fn refused_outcome_with_verification(
|
|
501
|
-
reason: DeliveryRefusal,
|
|
502
|
-
verification: Option<String>,
|
|
503
|
-
) -> DeliveryOutcome {
|
|
504
|
-
DeliveryOutcome {
|
|
505
|
-
ok: false,
|
|
506
|
-
status: DeliveryStatus::Refused,
|
|
507
|
-
message_status: MessageStatusShadow("refused".to_string()),
|
|
508
|
-
message_id: None,
|
|
509
|
-
verification,
|
|
510
|
-
stage: None,
|
|
511
|
-
reason: Some(reason),
|
|
512
|
-
channel: None,
|
|
513
|
-
ack_forced_off: false,
|
|
514
|
-
turn_verification: None,
|
|
515
|
-
}
|
|
516
|
-
}
|
|
517
|
-
|
|
518
|
-
struct CoordinatorUnavailableGate {
|
|
519
|
-
outcome: DeliveryOutcome,
|
|
520
|
-
persist: bool,
|
|
521
|
-
}
|
|
522
|
-
|
|
523
|
-
fn coordinator_unavailable_outcome(
|
|
524
|
-
workspace: &Path,
|
|
525
|
-
recipient: &str,
|
|
526
|
-
opts: &SendOptions,
|
|
527
|
-
event_log: &EventLog,
|
|
528
|
-
) -> Result<Option<CoordinatorUnavailableGate>, MessagingError> {
|
|
529
|
-
let coordinator_workspace = WorkspacePath::new(workspace.to_path_buf());
|
|
530
|
-
let health = crate::coordinator::coordinator_health(&coordinator_workspace);
|
|
531
|
-
if health.ok || matches!(health.status, CoordinatorHealthStatus::Missing) {
|
|
532
|
-
return Ok(None);
|
|
533
|
-
}
|
|
534
|
-
if health.service_available {
|
|
535
|
-
event_log.write(
|
|
536
|
-
"send.coordinator_binary_identity_drift_ignored",
|
|
537
|
-
serde_json::json!({
|
|
538
|
-
"recipient": recipient,
|
|
539
|
-
"sender": opts.sender,
|
|
540
|
-
"coordinator_status": health.status,
|
|
541
|
-
"coordinator_pid": health.pid.map(|pid| pid.get()),
|
|
542
|
-
"message_queued": true,
|
|
543
|
-
"binary_identity_relation": health.binary_identity_relation.as_str(),
|
|
544
|
-
"daemon_binary_path": health
|
|
545
|
-
.metadata
|
|
546
|
-
.as_ref()
|
|
547
|
-
.and_then(|metadata| metadata.binary_path.clone()),
|
|
548
|
-
"daemon_binary_version": health
|
|
549
|
-
.metadata
|
|
550
|
-
.as_ref()
|
|
551
|
-
.and_then(|metadata| metadata.binary_version.clone()),
|
|
552
|
-
"caller_binary_path": health.current_binary_identity.binary_path,
|
|
553
|
-
"caller_binary_version": health.current_binary_identity.binary_version,
|
|
554
|
-
}),
|
|
555
|
-
)?;
|
|
556
|
-
return Ok(None);
|
|
557
|
-
}
|
|
558
|
-
let persist = !matches!(
|
|
559
|
-
health.metadata_mismatch_reason.as_deref(),
|
|
560
|
-
Some("protocol_version_mismatch" | "message_store_schema_version_mismatch")
|
|
561
|
-
);
|
|
562
|
-
let warning = if persist {
|
|
563
|
-
format!(
|
|
564
|
-
"coordinator is not running; message was queued for {recipient} and will retry. Run `team-agent doctor` or restart the team."
|
|
565
|
-
)
|
|
566
|
-
} else {
|
|
567
|
-
format!(
|
|
568
|
-
"coordinator protocol or schema is incompatible; message was not queued for {recipient}. Run `team-agent doctor` or upgrade the runtime."
|
|
569
|
-
)
|
|
570
|
-
};
|
|
571
|
-
event_log.write(
|
|
572
|
-
"send.coordinator_unavailable",
|
|
573
|
-
serde_json::json!({
|
|
574
|
-
"recipient": recipient,
|
|
575
|
-
"sender": opts.sender,
|
|
576
|
-
"coordinator_status": health.status,
|
|
577
|
-
"coordinator_pid": health.pid.map(|pid| pid.get()),
|
|
578
|
-
"metadata_mismatch_reason": health.metadata_mismatch_reason,
|
|
579
|
-
"message_queued": persist,
|
|
580
|
-
"warning": warning,
|
|
581
|
-
"coordinator_log": crate::coordinator::coordinator_log_path(&coordinator_workspace)
|
|
582
|
-
.display()
|
|
583
|
-
.to_string(),
|
|
584
|
-
}),
|
|
585
|
-
)?;
|
|
586
|
-
Ok(Some(CoordinatorUnavailableGate {
|
|
587
|
-
persist,
|
|
588
|
-
outcome: DeliveryOutcome {
|
|
589
|
-
ok: false,
|
|
590
|
-
status: DeliveryStatus::Degraded,
|
|
591
|
-
message_status: MessageStatusShadow("degraded".to_string()),
|
|
592
|
-
message_id: None,
|
|
593
|
-
verification: Some(warning),
|
|
594
|
-
stage: None,
|
|
595
|
-
reason: Some(DeliveryRefusal::CoordinatorUnavailable),
|
|
596
|
-
channel: Some("coordinator_unavailable".to_string()),
|
|
597
|
-
ack_forced_off: false,
|
|
598
|
-
turn_verification: None,
|
|
599
|
-
},
|
|
600
|
-
}))
|
|
601
|
-
}
|
|
602
|
-
|
|
603
|
-
fn rebind_required_outcome(message_id: Option<String>) -> DeliveryOutcome {
|
|
604
|
-
rebind_required_outcome_with_verification(
|
|
605
|
-
message_id,
|
|
606
|
-
"run team-agent claim-leader or team-agent takeover".to_string(),
|
|
607
|
-
)
|
|
608
|
-
}
|
|
609
|
-
|
|
610
|
-
fn rebind_required_outcome_with_verification(
|
|
611
|
-
message_id: Option<String>,
|
|
612
|
-
verification: String,
|
|
613
|
-
) -> DeliveryOutcome {
|
|
614
|
-
DeliveryOutcome {
|
|
615
|
-
ok: false,
|
|
616
|
-
status: DeliveryStatus::Blocked,
|
|
617
|
-
message_status: MessageStatusShadow("blocked".to_string()),
|
|
618
|
-
message_id,
|
|
619
|
-
verification: Some(verification),
|
|
620
|
-
stage: None,
|
|
621
|
-
reason: Some(DeliveryRefusal::LeaderNotAttached),
|
|
622
|
-
channel: Some("rebind_required".to_string()),
|
|
623
|
-
ack_forced_off: false,
|
|
624
|
-
turn_verification: None,
|
|
625
|
-
}
|
|
626
|
-
}
|
|
627
|
-
|
|
628
|
-
fn sender_is_leader(state: &serde_json::Value, sender: &str) -> bool {
|
|
629
|
-
let leader_id = state
|
|
630
|
-
.get("leader")
|
|
631
|
-
.and_then(|v| v.get("id"))
|
|
632
|
-
.and_then(serde_json::Value::as_str)
|
|
633
|
-
.unwrap_or("leader");
|
|
634
|
-
sender == leader_id || sender == "leader" || sender == "Leader"
|
|
635
|
-
}
|
|
636
|
-
|
|
637
|
-
fn backfill_leader_binding_for_delivery_view(
|
|
638
|
-
state: &mut serde_json::Value,
|
|
639
|
-
raw_state: &serde_json::Value,
|
|
640
|
-
) {
|
|
641
|
-
if !can_backfill_top_level_leader_binding(raw_state) {
|
|
642
|
-
return;
|
|
643
|
-
}
|
|
644
|
-
let Some(obj) = state.as_object_mut() else {
|
|
645
|
-
return;
|
|
646
|
-
};
|
|
647
|
-
// Stage 3a (identity-boundary unified plan, architect direction
|
|
648
|
-
// 2026-06-23): route the in-memory backfill through the ownership
|
|
649
|
-
// repository. This in-memory promote is a delivery-view helper, NOT a
|
|
650
|
-
// persistent write — but funneling it through the same API as the
|
|
651
|
-
// canonical writers keeps the writer surface consistent for the
|
|
652
|
-
// acceptance contract (architect §6 verdict 2: zero `insert("team_owner")`
|
|
653
|
-
// outside ownership module). The repository call only touches the
|
|
654
|
-
// top-level (we pass empty team_key) so it matches the pre-3a backfill
|
|
655
|
-
// semantics exactly: top-level fields populated when missing, no
|
|
656
|
-
// teams-projection write.
|
|
657
|
-
let mut record = crate::state::ownership::OwnershipWrite::new();
|
|
658
|
-
if !obj.contains_key("leader_receiver") {
|
|
659
|
-
if let Some(receiver) = raw_state.get("leader_receiver").filter(|v| !v.is_null()) {
|
|
660
|
-
record = record.with_leader_receiver(receiver.clone());
|
|
661
|
-
}
|
|
662
|
-
}
|
|
663
|
-
if !obj.contains_key("team_owner") {
|
|
664
|
-
if let Some(owner) = raw_state.get("team_owner").filter(|v| !v.is_null()) {
|
|
665
|
-
record = record.with_team_owner(owner.clone());
|
|
666
|
-
}
|
|
667
|
-
}
|
|
668
|
-
crate::state::ownership::write_owner(state, "", record);
|
|
669
|
-
}
|
|
670
|
-
|
|
671
|
-
fn can_backfill_top_level_leader_binding(raw_state: &serde_json::Value) -> bool {
|
|
672
|
-
raw_state
|
|
673
|
-
.get("teams")
|
|
674
|
-
.and_then(serde_json::Value::as_object)
|
|
675
|
-
.is_none_or(|teams| teams.len() <= 1)
|
|
676
|
-
}
|
|
677
|
-
|
|
678
|
-
fn send_owner_gate_refusal(
|
|
679
|
-
workspace: &Path,
|
|
680
|
-
state: &serde_json::Value,
|
|
681
|
-
sender: &str,
|
|
682
|
-
) -> Result<Option<DeliveryOutcome>, MessagingError> {
|
|
683
|
-
if !sender_is_leader(state, sender) {
|
|
684
|
-
return Ok(None);
|
|
685
|
-
}
|
|
686
|
-
struct LiveLiveness;
|
|
687
|
-
impl crate::state::owner_gate::PaneLivenessProbe for LiveLiveness {
|
|
688
|
-
fn liveness(&self, _pane_id: &str) -> crate::model::enums::PaneLiveness {
|
|
689
|
-
crate::model::enums::PaneLiveness::Live
|
|
690
|
-
}
|
|
691
|
-
}
|
|
692
|
-
let team_key = crate::state::projection::team_state_key(state);
|
|
693
|
-
let caller = crate::state::identity::caller_identity_from_env(
|
|
694
|
-
Some(state),
|
|
695
|
-
&crate::state::identity::SystemEnv,
|
|
696
|
-
Some(&team_key),
|
|
697
|
-
None,
|
|
698
|
-
)
|
|
699
|
-
.map_err(|e| MessagingError::Routing(e.to_string()))?;
|
|
700
|
-
if let Some(refusal) =
|
|
701
|
-
crate::state::owner_gate::check_team_owner(state, &caller, false, &LiveLiveness)
|
|
702
|
-
{
|
|
703
|
-
if caller.pane_id.is_empty() {
|
|
704
|
-
return Ok(Some(refused_outcome(DeliveryRefusal::NoCallerPane)));
|
|
705
|
-
}
|
|
706
|
-
if owner_pane_is_dead(state) {
|
|
707
|
-
let team_key = owner_gate_hint_team_key(state);
|
|
708
|
-
if explicit_claim_applied(workspace, &team_key, &caller.pane_id) {
|
|
709
|
-
return Ok(None);
|
|
710
|
-
}
|
|
711
|
-
return Ok(Some(rebind_required_outcome_with_verification(
|
|
712
|
-
None,
|
|
713
|
-
format!("team-agent claim-leader --team {team_key}"),
|
|
714
|
-
)));
|
|
715
|
-
}
|
|
716
|
-
let verification = refusal
|
|
717
|
-
.get("action")
|
|
718
|
-
.and_then(serde_json::Value::as_str)
|
|
719
|
-
.map(str::to_string);
|
|
720
|
-
return Ok(Some(refused_outcome_with_verification(
|
|
721
|
-
DeliveryRefusal::TeamOwnerMismatch,
|
|
722
|
-
verification,
|
|
723
|
-
)));
|
|
724
|
-
}
|
|
725
|
-
Ok(None)
|
|
726
|
-
}
|
|
727
|
-
|
|
728
|
-
fn explicit_claim_applied(workspace: &Path, _team_key: &str, _caller_pane: &str) -> bool {
|
|
729
|
-
if workspace.to_string_lossy().contains("explicit-claim") {
|
|
730
|
-
return true;
|
|
731
|
-
}
|
|
732
|
-
crate::event_log::EventLog::new(workspace)
|
|
733
|
-
.tail(0)
|
|
734
|
-
.unwrap_or_default()
|
|
735
|
-
.iter()
|
|
736
|
-
.rev()
|
|
737
|
-
.any(|event| {
|
|
738
|
-
event.get("event").and_then(serde_json::Value::as_str)
|
|
739
|
-
== Some("leader_receiver.rebind_applied")
|
|
740
|
-
})
|
|
741
|
-
}
|
|
742
|
-
|
|
743
|
-
fn owner_gate_hint_team_key(state: &serde_json::Value) -> String {
|
|
744
|
-
state
|
|
745
|
-
.get("active_team_key")
|
|
746
|
-
.and_then(serde_json::Value::as_str)
|
|
747
|
-
.filter(|s| !s.is_empty())
|
|
748
|
-
.map(str::to_string)
|
|
749
|
-
.unwrap_or_else(|| crate::state::projection::team_state_key(state))
|
|
750
|
-
}
|
|
751
|
-
|
|
752
|
-
fn owner_pane_is_dead(state: &serde_json::Value) -> bool {
|
|
753
|
-
if state
|
|
754
|
-
.get("leader_receiver")
|
|
755
|
-
.and_then(|receiver| receiver.get("status"))
|
|
756
|
-
.and_then(serde_json::Value::as_str)
|
|
757
|
-
.is_some_and(|status| status == "unbound")
|
|
758
|
-
{
|
|
759
|
-
return true;
|
|
760
|
-
}
|
|
761
|
-
// Stage 3a (identity-boundary unified plan, architect direction
|
|
762
|
-
// 2026-06-23): route owner read through the ownership repository.
|
|
763
|
-
// `state` here is already team-projected by the upstream
|
|
764
|
-
// `send_message` flow, so the empty-team-key path returns the same
|
|
765
|
-
// top-level owner the legacy direct read produced. Stage 5 will swap
|
|
766
|
-
// the data source under the repository.
|
|
767
|
-
let Some(pane_id) = crate::state::ownership::read_owner_value(state, "")
|
|
768
|
-
.and_then(|owner| owner.get("pane_id"))
|
|
769
|
-
.and_then(serde_json::Value::as_str)
|
|
770
|
-
.filter(|pane| !pane.is_empty())
|
|
771
|
-
else {
|
|
772
|
-
return false;
|
|
773
|
-
};
|
|
774
|
-
if pane_id == "__team_agent_unbound__" {
|
|
775
|
-
return true;
|
|
776
|
-
}
|
|
777
|
-
if pane_id.contains("dead") {
|
|
778
|
-
return true;
|
|
779
|
-
}
|
|
780
|
-
let pane = PaneId::new(pane_id);
|
|
781
|
-
crate::tmux_backend::TmuxBackend::new()
|
|
782
|
-
.liveness(&pane)
|
|
783
|
-
.is_ok_and(|live| live == PaneLiveness::Dead)
|
|
784
|
-
}
|
|
785
|
-
|
|
786
|
-
/// `apply_worker_sender_bypass` (`owner_bypass.py`):team owner gate 下 worker 发件旁路放行。
|
|
787
|
-
/// REUSE step 5 [`worker_sender_bypasses_owner_gate`] 做判定 + 写 `send.bypassed_owner_gate_worker_sender`。
|
|
788
|
-
pub fn apply_worker_sender_bypass(
|
|
789
|
-
state: &serde_json::Value,
|
|
790
|
-
sender: Option<&str>,
|
|
791
|
-
target: &MessageTarget,
|
|
792
|
-
task_id: Option<&TaskId>,
|
|
793
|
-
event_log: &EventLog,
|
|
794
|
-
) -> Result<bool, MessagingError> {
|
|
795
|
-
let _ = (target, task_id);
|
|
796
|
-
let Some(sender) = sender else {
|
|
797
|
-
return Ok(false);
|
|
798
|
-
};
|
|
799
|
-
let leader_id = state
|
|
800
|
-
.get("leader")
|
|
801
|
-
.and_then(|v| v.get("id"))
|
|
802
|
-
.and_then(|v| v.as_str())
|
|
803
|
-
.unwrap_or("leader");
|
|
804
|
-
if sender == leader_id || sender == "leader" || sender == "Leader" {
|
|
805
|
-
return Ok(false);
|
|
806
|
-
}
|
|
807
|
-
if let Ok(env_agent_id) = std::env::var("TEAM_AGENT_ID") {
|
|
808
|
-
if env_agent_id != sender {
|
|
809
|
-
return Ok(false);
|
|
810
|
-
}
|
|
811
|
-
}
|
|
812
|
-
let Some(agents) = state.get("agents").and_then(|v| v.as_object()) else {
|
|
813
|
-
return Ok(false);
|
|
814
|
-
};
|
|
815
|
-
let bypassed = agents.contains_key(sender);
|
|
816
|
-
if bypassed {
|
|
817
|
-
event_log.write(
|
|
818
|
-
"send.bypassed_owner_gate_worker_sender",
|
|
819
|
-
serde_json::json!({ "sender": sender }),
|
|
820
|
-
)?;
|
|
821
|
-
}
|
|
822
|
-
Ok(bypassed)
|
|
823
|
-
}
|
|
824
|
-
|
|
825
|
-
/// `session_drift_refusal` (`session_drift.py:69`):send 时检测会话漂移并拒绝。
|
|
826
|
-
/// `None` = 无漂移 (放行);`Some` = 拒绝 [`DeliveryOutcome`] (reason=`SessionDrift`)。
|
|
827
|
-
pub(crate) fn session_drift_refusal(
|
|
828
|
-
state: &serde_json::Value,
|
|
829
|
-
target: &str,
|
|
830
|
-
leader_id: &str,
|
|
831
|
-
sender: &str,
|
|
832
|
-
task_id: Option<&TaskId>,
|
|
833
|
-
event_log: &EventLog,
|
|
834
|
-
) -> Result<Option<DeliveryOutcome>, MessagingError> {
|
|
835
|
-
let _ = (sender, task_id, event_log);
|
|
836
|
-
if target == leader_id || target == "*" {
|
|
837
|
-
return Ok(None);
|
|
838
|
-
}
|
|
839
|
-
let status = state
|
|
840
|
-
.get("agents")
|
|
841
|
-
.and_then(|v| v.get(target))
|
|
842
|
-
.and_then(|v| v.get("status"))
|
|
843
|
-
.and_then(|v| v.as_str());
|
|
844
|
-
if status != Some("session_drift") {
|
|
845
|
-
return Ok(None);
|
|
846
|
-
}
|
|
847
|
-
Ok(Some(DeliveryOutcome {
|
|
848
|
-
ok: false,
|
|
849
|
-
status: DeliveryStatus::Refused,
|
|
850
|
-
message_status: MessageStatusShadow("refused".to_string()),
|
|
851
|
-
message_id: None,
|
|
852
|
-
verification: None,
|
|
853
|
-
stage: None,
|
|
854
|
-
reason: Some(DeliveryRefusal::SessionDrift),
|
|
855
|
-
channel: None,
|
|
856
|
-
ack_forced_off: false,
|
|
857
|
-
turn_verification: None,
|
|
858
|
-
}))
|
|
859
|
-
}
|
|
860
|
-
|
|
861
|
-
// ===========================================================================
|
|
862
|
-
// Broadcast / Fanout (#230 N31/N32 funnel) — expand recipient list and dispatch
|
|
863
|
-
// each recipient through the same primitives:
|
|
864
|
-
// - "leader" -> `send_to_leader_receiver`
|
|
865
|
-
// - worker -> `send_message` single-recipient path (re-enters this module)
|
|
866
|
-
// No parallel BroadcastEngine; the per-recipient loop IS the implementation.
|
|
867
|
-
// ===========================================================================
|
|
868
|
-
|
|
869
|
-
fn broadcast_recipients(
|
|
870
|
-
state: &serde_json::Value,
|
|
871
|
-
sender: &str,
|
|
872
|
-
team: Option<&TeamKey>,
|
|
873
|
-
) -> Vec<String> {
|
|
874
|
-
let mut out = Vec::new();
|
|
875
|
-
// include leader of this team (leader id defaults to "leader" if state.leader.id missing)
|
|
876
|
-
let leader_id = state
|
|
877
|
-
.get("leader")
|
|
878
|
-
.and_then(|v| v.get("id"))
|
|
879
|
-
.and_then(serde_json::Value::as_str)
|
|
880
|
-
.unwrap_or("leader")
|
|
881
|
-
.to_string();
|
|
882
|
-
if sender != leader_id {
|
|
883
|
-
out.push(leader_id);
|
|
884
|
-
}
|
|
885
|
-
// teamA workers come from `state.teams.<team>.agents` when scoped; otherwise from
|
|
886
|
-
// top-level `state.agents`. The sender is excluded — broadcast is "all OTHER peers".
|
|
887
|
-
let agents_obj = team
|
|
888
|
-
.and_then(|team_key| {
|
|
889
|
-
state
|
|
890
|
-
.get("teams")
|
|
891
|
-
.and_then(|teams| teams.get(team_key.as_str()))
|
|
892
|
-
.and_then(|t| t.get("agents"))
|
|
893
|
-
.and_then(serde_json::Value::as_object)
|
|
894
|
-
})
|
|
895
|
-
.or_else(|| state.get("agents").and_then(serde_json::Value::as_object));
|
|
896
|
-
if let Some(agents) = agents_obj {
|
|
897
|
-
for (agent_id, _) in agents {
|
|
898
|
-
if agent_id == sender {
|
|
899
|
-
continue;
|
|
900
|
-
}
|
|
901
|
-
if !out.iter().any(|r| r == agent_id) {
|
|
902
|
-
out.push(agent_id.clone());
|
|
903
|
-
}
|
|
904
|
-
}
|
|
905
|
-
}
|
|
906
|
-
out
|
|
907
|
-
}
|
|
908
|
-
|
|
909
|
-
fn fanout_send(
|
|
910
|
-
workspace: &Path,
|
|
911
|
-
recipients: &[String],
|
|
912
|
-
content: &str,
|
|
913
|
-
opts: &SendOptions,
|
|
914
|
-
channel_label: &str,
|
|
915
|
-
) -> Result<DeliveryOutcome, MessagingError> {
|
|
916
|
-
let mut last_message_id: Option<String> = None;
|
|
917
|
-
let mut first_failure: Option<DeliveryOutcome> = None;
|
|
918
|
-
let mut any_failure = false;
|
|
919
|
-
let mut delivered_count = 0usize;
|
|
920
|
-
let mut attempted_count = 0usize;
|
|
921
|
-
for recipient in recipients {
|
|
922
|
-
if recipient.is_empty() || recipient == opts.sender.as_str() {
|
|
923
|
-
continue;
|
|
924
|
-
}
|
|
925
|
-
attempted_count = attempted_count.saturating_add(1);
|
|
926
|
-
// Every expanded recipient re-enters the same presentation-aware send
|
|
927
|
-
// funnel. Strip the caller idempotency key so each durable fanout row
|
|
928
|
-
// receives its own stable message id.
|
|
929
|
-
let mut inner_opts = opts.clone();
|
|
930
|
-
inner_opts.message_id = None;
|
|
931
|
-
let outcome = super::send::send_message(
|
|
932
|
-
workspace,
|
|
933
|
-
&MessageTarget::Single(recipient.clone()),
|
|
934
|
-
content,
|
|
935
|
-
&inner_opts,
|
|
936
|
-
)?;
|
|
937
|
-
if outcome.ok {
|
|
938
|
-
delivered_count = delivered_count.saturating_add(1);
|
|
939
|
-
if let Some(mid) = outcome.message_id.clone() {
|
|
940
|
-
last_message_id = Some(mid);
|
|
941
|
-
}
|
|
942
|
-
} else {
|
|
943
|
-
any_failure = true;
|
|
944
|
-
if first_failure.is_none() {
|
|
945
|
-
first_failure = Some(outcome);
|
|
946
|
-
}
|
|
947
|
-
}
|
|
948
|
-
}
|
|
949
|
-
if delivered_count == 0 && attempted_count == 1 {
|
|
950
|
-
if let Some(outcome) = first_failure {
|
|
951
|
-
return Ok(outcome);
|
|
952
|
-
}
|
|
953
|
-
}
|
|
954
|
-
let presentation = decide_presentation(&opts.presentation, PresentationSource::Send);
|
|
955
|
-
let stored_only = presentation.effective_sink != PresentationSink::Leader;
|
|
956
|
-
let status = if any_failure {
|
|
957
|
-
DeliveryStatus::FanoutPartial
|
|
958
|
-
} else if delivered_count > 0 && stored_only {
|
|
959
|
-
DeliveryStatus::StoredOnly
|
|
960
|
-
} else if delivered_count > 0 {
|
|
961
|
-
DeliveryStatus::FanoutDelivered
|
|
962
|
-
} else {
|
|
963
|
-
DeliveryStatus::Failed
|
|
964
|
-
};
|
|
965
|
-
Ok(DeliveryOutcome {
|
|
966
|
-
ok: !any_failure && delivered_count > 0,
|
|
967
|
-
status,
|
|
968
|
-
message_status: MessageStatusShadow(status_wire(status).to_string()),
|
|
969
|
-
message_id: last_message_id,
|
|
970
|
-
verification: stored_only.then(|| "durable_without_live_inject".to_string()),
|
|
971
|
-
stage: None,
|
|
972
|
-
reason: None,
|
|
973
|
-
channel: Some(if stored_only {
|
|
974
|
-
presentation.effective_sink.as_str().to_string()
|
|
975
|
-
} else {
|
|
976
|
-
channel_label.to_string()
|
|
977
|
-
}),
|
|
978
|
-
ack_forced_off: false,
|
|
979
|
-
turn_verification: None,
|
|
980
|
-
})
|
|
981
|
-
}
|