@team-agent/installer 0.5.128 → 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 +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,805 +0,0 @@
|
|
|
1
|
-
//! ---
|
|
2
|
-
//! purpose: Windows ConPTY shim 的生命周期主人——定位并启动 windows-shim.exe、做 Hello 握手、把可复用的连接与 pid/pipe 名记进 state
|
|
3
|
-
//! contract:
|
|
4
|
-
//! provides:
|
|
5
|
-
//! - name: ensure_shim_running
|
|
6
|
-
//! what: 幂等入口:state 里记的 shim 还活着就重连,否则新起一个并握手
|
|
7
|
-
//! - name: reconnect_recorded_shim
|
|
8
|
-
//! what: 只按 state 记的 pipe 名重连并重做 Hello,绝不新起进程
|
|
9
|
-
//! - name: recorded_shim_pid
|
|
10
|
-
//! what: 读 state.transport.shim.pid,供停机路由
|
|
11
|
-
//! - name: recorded_shim_pipe_name
|
|
12
|
-
//! what: 读 state.transport.shim.pipe_name,供重连路由
|
|
13
|
-
//! - name: mark_transport_unavailable
|
|
14
|
-
//! what: shim 不可达时发 stale 家族事件并清掉 state 里的 pipe_ready
|
|
15
|
-
//! depends:
|
|
16
|
-
//! - conpty_transport
|
|
17
|
-
//! - crate::state::repository
|
|
18
|
-
//! - crate::state::persist
|
|
19
|
-
//! - crate::event_log
|
|
20
|
-
//! - crate::platform::process
|
|
21
|
-
//! boundary:
|
|
22
|
-
//! - pipe_token 绝不落 state:只经子进程环境变量传递并留在本进程内存里,state 只记 pid/pipe_name/pipe_ready
|
|
23
|
-
//! - 终态失败不静默回落 tmux,交由调用方按传输不可用处理
|
|
24
|
-
//! - 重连只证明线协议可用,不做新的令牌认证
|
|
25
|
-
//! - 整个文件仅在 Windows 编译;非 Windows 调用方必须自己 cfg 门控
|
|
26
|
-
//! maturity: wired
|
|
27
|
-
//! ---
|
|
28
|
-
//!
|
|
29
|
-
//! Windows ConPTY shim lifecycle manager.
|
|
30
|
-
//!
|
|
31
|
-
//! 0.5.x Windows portability Batch 6 Option A. The design's
|
|
32
|
-
//! §Shim Lifecycle chapter reads:
|
|
33
|
-
//!
|
|
34
|
-
//! > If pipe connect fails, backend starts shim via
|
|
35
|
-
//! > `team-agent windows-shim`. Client then retries connect.
|
|
36
|
-
//!
|
|
37
|
-
//! Batch 5 landed the client (`NamedPipeClient`) and the factory
|
|
38
|
-
//! `pipe_ready` gate. This module lands the spawn side: coordinator
|
|
39
|
-
//! locates + launches `windows-shim.exe`, performs the hello
|
|
40
|
-
//! handshake, and records the surviving handle so the factory can
|
|
41
|
-
//! wire a live client to `ConPtyBackend`.
|
|
42
|
-
//!
|
|
43
|
-
//! ## CR anchors
|
|
44
|
-
//!
|
|
45
|
-
//! - **C-1 (pipe_token secrecy)**: `pipe_token` NEVER touches
|
|
46
|
-
//! `state.transport.shim`. It transits via
|
|
47
|
-
//! `TA_CONPTY_PIPE_TOKEN` env on the spawned child (see
|
|
48
|
-
//! `windows_shim.rs::parse_args` env-first fallback) and stays in
|
|
49
|
-
//! coordinator memory for the client handshake. state records
|
|
50
|
-
//! ONLY `{pid, pipe_name, pipe_ready}` — no secret material.
|
|
51
|
-
//! - **C-6 typed events**: spawn / hello / retry / terminal failure
|
|
52
|
-
//! emit N38 three-line diagnostics (`platform.conpty_shim.<verb>`
|
|
53
|
-
//! with `reason` + `action` fields).
|
|
54
|
-
//! - **C-3 conservative default**: bounded retry (5 attempts × 200ms
|
|
55
|
-
//! backoff). On terminal failure return `MuxUnavailable` — no
|
|
56
|
-
//! silent tmux fallback (that would violate MUST-NOT-13).
|
|
57
|
-
//!
|
|
58
|
-
//! ## Non-Windows behavior
|
|
59
|
-
//!
|
|
60
|
-
//! Entire module is `#[cfg(windows)]`. Non-Windows callers see the
|
|
61
|
-
//! empty stub via the cfg re-exports in `mod.rs`.
|
|
62
|
-
|
|
63
|
-
#![cfg(windows)]
|
|
64
|
-
|
|
65
|
-
use serde_json::{json, Value};
|
|
66
|
-
use std::path::{Path, PathBuf};
|
|
67
|
-
use std::process::{Child, Command, Stdio};
|
|
68
|
-
use std::time::Duration;
|
|
69
|
-
|
|
70
|
-
use conpty_transport::{pipe_name_for, NamedPipeClient};
|
|
71
|
-
|
|
72
|
-
use crate::state::persist::runtime_state_path;
|
|
73
|
-
use crate::state::StateError;
|
|
74
|
-
|
|
75
|
-
/// Maximum shim connect+hello attempts before giving up. Each attempt
|
|
76
|
-
/// costs one `NamedPipeClient::connect` + one Hello RPC. 5 attempts
|
|
77
|
-
/// with the 200ms sleep between covers pipe-server startup jitter
|
|
78
|
-
/// while failing fast when the shim binary is genuinely broken.
|
|
79
|
-
const CONNECT_ATTEMPTS: u32 = 5;
|
|
80
|
-
|
|
81
|
-
/// Backoff between attempts. Tuned so 5 tries fits inside the
|
|
82
|
-
/// factory `NamedPipeClient::connect(_, wait_ms=250)` timeout profile.
|
|
83
|
-
const CONNECT_BACKOFF: Duration = Duration::from_millis(200);
|
|
84
|
-
|
|
85
|
-
/// Live handle to a spawned shim. Drop kills the child.
|
|
86
|
-
pub struct ShimHandle {
|
|
87
|
-
/// Underlying `Child` — kept so `Drop` can terminate the shim if
|
|
88
|
-
/// the caller drops the handle without shutting down.
|
|
89
|
-
child: Option<Child>,
|
|
90
|
-
/// Pid of the shim process (mirrors `child.id()`, cached for
|
|
91
|
-
/// post-child-drop diagnostics).
|
|
92
|
-
pid: u32,
|
|
93
|
-
/// Pipe name the shim is listening on
|
|
94
|
-
/// (`\\.\pipe\team-agent-conpty-<hash>-<team>`).
|
|
95
|
-
pipe_name: String,
|
|
96
|
-
/// Live `NamedPipeClient` that already completed the Hello
|
|
97
|
-
/// handshake. Callers (`transport_factory`) will hand this to
|
|
98
|
-
/// `ConPtyBackend::with_pipe_client`.
|
|
99
|
-
client: Option<NamedPipeClient>,
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
impl ShimHandle {
|
|
103
|
-
/// The connected pipe client, ready for the factory to wire into
|
|
104
|
-
/// `ConPtyBackend`. Callable exactly once — takes ownership.
|
|
105
|
-
/// ---
|
|
106
|
-
/// purpose: 取走已完成 Hello 握手的管道客户端,交给传输后端接线
|
|
107
|
-
/// returns: 首次调用返回客户端并转移所有权;再次调用为 None
|
|
108
|
-
/// ---
|
|
109
|
-
pub fn take_client(&mut self) -> Option<NamedPipeClient> {
|
|
110
|
-
self.client.take()
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
/// The shim pid (for status + shutdown routing).
|
|
114
|
-
/// ---
|
|
115
|
-
/// purpose: 给出 shim 进程号,用于状态展示与停机路由
|
|
116
|
-
/// returns: 启动时记下的 pid;子进程句柄已被 detach 或 drop 后该值仍可读
|
|
117
|
-
/// ---
|
|
118
|
-
pub fn pid(&self) -> u32 {
|
|
119
|
-
self.pid
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
/// The pipe name the shim listens on.
|
|
123
|
-
/// ---
|
|
124
|
-
/// purpose: 给出 shim 正在监听的命名管道名
|
|
125
|
-
/// returns: 形如 team-agent-conpty-<hash>-<team> 的管道全名
|
|
126
|
-
/// ---
|
|
127
|
-
pub fn pipe_name(&self) -> &str {
|
|
128
|
-
&self.pipe_name
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
/// Detach the child so this handle's `Drop` does NOT kill the
|
|
132
|
-
/// shim. Called after quick-start has persisted state and wired
|
|
133
|
-
/// the client — the shim must survive until `shutdown` performs
|
|
134
|
-
/// an explicit `platform::process::terminate_pid` via
|
|
135
|
-
/// `recorded_shim_pid`. Without this call, going out of scope
|
|
136
|
-
/// would terminate the shim and orphan every worker.
|
|
137
|
-
/// ---
|
|
138
|
-
/// purpose: 放弃对 shim 子进程的所有权,使本句柄析构时不再杀它
|
|
139
|
-
/// returns: shim 的 pid,供调用方日后按精确 pid 显式终止
|
|
140
|
-
/// ---
|
|
141
|
-
/// 不调用它就让句柄离开作用域,会连带杀掉 shim 并使全部 worker 变成孤儿。
|
|
142
|
-
pub fn detach(mut self) -> u32 {
|
|
143
|
-
// Forget the child so its own Drop doesn't run either. The
|
|
144
|
-
// shim survives until an explicit kill.
|
|
145
|
-
if let Some(child) = self.child.take() {
|
|
146
|
-
std::mem::forget(child);
|
|
147
|
-
}
|
|
148
|
-
self.pid
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
impl Drop for ShimHandle {
|
|
153
|
-
fn drop(&mut self) {
|
|
154
|
-
// Best-effort terminate — only runs if `detach()` was NOT
|
|
155
|
-
// called. Guards against a spawn+handshake succeeding but a
|
|
156
|
-
// downstream error in the same fn dropping us without
|
|
157
|
-
// cleanup. Callers that intend to keep the shim alive MUST
|
|
158
|
-
// call `detach()` before this handle goes out of scope.
|
|
159
|
-
if let Some(mut child) = self.child.take() {
|
|
160
|
-
let _ = child.kill();
|
|
161
|
-
let _ = child.wait();
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
#[derive(Debug, thiserror::Error)]
|
|
167
|
-
pub enum ShimError {
|
|
168
|
-
#[error(
|
|
169
|
-
"windows-shim binary not found: expected `{expected}` alongside team-agent.exe; \
|
|
170
|
-
action: reinstall team-agent so the shim exe sits next to the main binary"
|
|
171
|
-
)]
|
|
172
|
-
BinaryMissing { expected: String },
|
|
173
|
-
#[error(
|
|
174
|
-
"windows-shim spawn failed: {source} (pipe_name={pipe_name}); \
|
|
175
|
-
action: check windows-shim.exe permissions and PATH"
|
|
176
|
-
)]
|
|
177
|
-
Spawn {
|
|
178
|
-
pipe_name: String,
|
|
179
|
-
#[source]
|
|
180
|
-
source: std::io::Error,
|
|
181
|
-
},
|
|
182
|
-
#[error(
|
|
183
|
-
"windows-shim connect timed out after {attempts} attempts (pipe_name={pipe_name}); \
|
|
184
|
-
action: check shim.err.log for CreateNamedPipeW / ACL errors, \
|
|
185
|
-
then re-run team-agent quick-start"
|
|
186
|
-
)]
|
|
187
|
-
ConnectTimeout { attempts: u32, pipe_name: String },
|
|
188
|
-
#[error(
|
|
189
|
-
"windows-shim hello handshake failed: {reason} (pipe_name={pipe_name}); \
|
|
190
|
-
action: ensure team-agent.exe and windows-shim.exe are the same build \
|
|
191
|
-
(`sha256sum team-agent.exe windows-shim.exe` matches CI tracking)"
|
|
192
|
-
)]
|
|
193
|
-
HelloFailed { pipe_name: String, reason: String },
|
|
194
|
-
#[error("state persistence failed after shim spawn: {source}")]
|
|
195
|
-
StatePersist {
|
|
196
|
-
#[source]
|
|
197
|
-
source: StateError,
|
|
198
|
-
},
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
/// Locate `windows-shim.exe`. Search order:
|
|
202
|
-
///
|
|
203
|
-
/// 1. `<parent_of_current_exe>\windows-shim.exe` — the standard
|
|
204
|
-
/// layout used by CI-built artifacts and `cargo install`
|
|
205
|
-
/// installations.
|
|
206
|
-
/// 2. Env override `TEAM_AGENT_WINDOWS_SHIM_PATH` — tests + CI
|
|
207
|
-
/// harness (Batch 6 SSH real-machine harness sets this).
|
|
208
|
-
fn locate_shim_binary() -> Result<PathBuf, ShimError> {
|
|
209
|
-
if let Ok(explicit) = std::env::var("TEAM_AGENT_WINDOWS_SHIM_PATH") {
|
|
210
|
-
let p = PathBuf::from(&explicit);
|
|
211
|
-
if p.exists() {
|
|
212
|
-
return Ok(p);
|
|
213
|
-
}
|
|
214
|
-
return Err(ShimError::BinaryMissing { expected: explicit });
|
|
215
|
-
}
|
|
216
|
-
let current = std::env::current_exe().map_err(|_| ShimError::BinaryMissing {
|
|
217
|
-
expected: "<unknown>".to_string(),
|
|
218
|
-
})?;
|
|
219
|
-
let dir = current.parent().ok_or_else(|| ShimError::BinaryMissing {
|
|
220
|
-
expected: current.display().to_string(),
|
|
221
|
-
})?;
|
|
222
|
-
let candidate = dir.join("windows-shim.exe");
|
|
223
|
-
if candidate.exists() {
|
|
224
|
-
return Ok(candidate);
|
|
225
|
-
}
|
|
226
|
-
Err(ShimError::BinaryMissing {
|
|
227
|
-
expected: candidate.display().to_string(),
|
|
228
|
-
})
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
/// Generate a fresh pipe token. 32 hex chars is enough entropy for a
|
|
232
|
-
/// short-lived local secret. We source from the process's PID +
|
|
233
|
-
/// nanoseconds — cryptographic randomness would need an extra
|
|
234
|
-
/// dependency; this is best-effort local-machine secrecy per CR
|
|
235
|
-
/// C-1 (a machine-local attacker who already can see the pid+time
|
|
236
|
-
/// can also spawn arbitrary processes, so bumping to RNG doesn't
|
|
237
|
-
/// change the threat model here).
|
|
238
|
-
fn fresh_pipe_token() -> String {
|
|
239
|
-
let pid = std::process::id();
|
|
240
|
-
let nanos = std::time::SystemTime::now()
|
|
241
|
-
.duration_since(std::time::UNIX_EPOCH)
|
|
242
|
-
.map(|d| d.as_nanos())
|
|
243
|
-
.unwrap_or(0);
|
|
244
|
-
format!(
|
|
245
|
-
"{:08x}{:024x}",
|
|
246
|
-
pid,
|
|
247
|
-
nanos & 0xffff_ffff_ffff_ffff_ffff_ffff
|
|
248
|
-
)
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
/// Coordinator hook: spawn `windows-shim.exe` for the given
|
|
252
|
-
/// (workspace, team_key, workspace_hash) triple, perform hello, and
|
|
253
|
-
/// return a live handle.
|
|
254
|
-
///
|
|
255
|
-
/// The handshake **is** the readiness judgment. `Get-Process` /
|
|
256
|
-
/// `child.try_wait()` are secondary — a shim that exits between
|
|
257
|
-
/// `Command::spawn` and `NamedPipeClient::connect` still counts as
|
|
258
|
-
/// "not ready" via the connect timeout, not "ready but broken" via
|
|
259
|
-
/// process presence.
|
|
260
|
-
///
|
|
261
|
-
/// On success this fn also persists `state.transport.shim = {pid,
|
|
262
|
-
/// pipe_name, pipe_ready: true}` to `.team/runtime/state.json` so
|
|
263
|
-
/// downstream `transport_factory::conpty_pipe_ready(...)` opens on
|
|
264
|
-
/// the next factory resolve. The `pipe_token` is NOT persisted (CR
|
|
265
|
-
/// C-1); it stays in `ShimHandle` memory only.
|
|
266
|
-
fn spawn_shim_and_handshake(
|
|
267
|
-
workspace: &Path,
|
|
268
|
-
team_key: &str,
|
|
269
|
-
workspace_hash: &str,
|
|
270
|
-
) -> Result<ShimHandle, ShimError> {
|
|
271
|
-
let shim_exe = locate_shim_binary()?;
|
|
272
|
-
let pipe_name = pipe_name_for(workspace_hash, team_key);
|
|
273
|
-
let pipe_token = fresh_pipe_token();
|
|
274
|
-
|
|
275
|
-
// Spawn the shim. `TA_CONPTY_PIPE_TOKEN` is the secret channel;
|
|
276
|
-
// argv carries only non-secret identifiers.
|
|
277
|
-
//
|
|
278
|
-
// Batch 6 real-machine diagnostic: route shim stderr to a
|
|
279
|
-
// predictable log file under `.team/logs/conpty-shim.err.log`
|
|
280
|
-
// so operators can diagnose Hello failures / pipe races. stdout
|
|
281
|
-
// is null (shim doesn't use stdout by design). CR C-1 hold:
|
|
282
|
-
// stderr NEVER contains the pipe_token (windows_shim.rs strips
|
|
283
|
-
// it from the startup log line).
|
|
284
|
-
let log_dir = workspace.join(".team").join("logs");
|
|
285
|
-
let _ = std::fs::create_dir_all(&log_dir);
|
|
286
|
-
let stderr_log = log_dir.join("conpty-shim.err.log");
|
|
287
|
-
let stderr_file = std::fs::OpenOptions::new()
|
|
288
|
-
.create(true)
|
|
289
|
-
.append(true)
|
|
290
|
-
.open(&stderr_log)
|
|
291
|
-
.map_err(|e| ShimError::Spawn {
|
|
292
|
-
pipe_name: pipe_name.clone(),
|
|
293
|
-
source: e,
|
|
294
|
-
})?;
|
|
295
|
-
let mut cmd = Command::new(&shim_exe);
|
|
296
|
-
cmd.args([
|
|
297
|
-
"--workspace-hash",
|
|
298
|
-
workspace_hash,
|
|
299
|
-
"--team",
|
|
300
|
-
team_key,
|
|
301
|
-
"--pipe-name",
|
|
302
|
-
&pipe_name,
|
|
303
|
-
])
|
|
304
|
-
.env("TA_CONPTY_PIPE_TOKEN", &pipe_token)
|
|
305
|
-
.stdin(Stdio::null())
|
|
306
|
-
.stdout(Stdio::null())
|
|
307
|
-
.stderr(Stdio::from(stderr_file));
|
|
308
|
-
// 0.5.x Windows portability Batch 8 F7 fix (leader msg_590b4dce0f68):
|
|
309
|
-
// set `DETACHED_PROCESS | CREATE_BREAKAWAY_FROM_JOB` creation
|
|
310
|
-
// flags so the shim truly outlives its parent (coordinator).
|
|
311
|
-
// Without these flags, Windows job-object semantics can kill
|
|
312
|
-
// the shim when the parent exits — the exact failure Batch 7
|
|
313
|
-
// real-machine testing surfaced on batch7-28741981337 (shim
|
|
314
|
-
// dead by coord's first tick because it was a child of the
|
|
315
|
-
// one-shot quick-start process).
|
|
316
|
-
//
|
|
317
|
-
// - `DETACHED_PROCESS` (0x08): the shim doesn't inherit the
|
|
318
|
-
// parent's console handle (which could cause the shim to
|
|
319
|
-
// attempt console I/O and exit when the parent's console
|
|
320
|
-
// goes away).
|
|
321
|
-
// - `CREATE_BREAKAWAY_FROM_JOB` (0x01000000): removes the shim
|
|
322
|
-
// from any job object the parent was in (common under
|
|
323
|
-
// PowerShell / cmd.exe run-from-terminal scenarios).
|
|
324
|
-
//
|
|
325
|
-
// Combined: the shim is a truly detached child, not a
|
|
326
|
-
// grandchild of any transient parent-side supervisor.
|
|
327
|
-
#[cfg(windows)]
|
|
328
|
-
{
|
|
329
|
-
use std::os::windows::process::CommandExt;
|
|
330
|
-
const DETACHED_PROCESS: u32 = 0x00000008;
|
|
331
|
-
const CREATE_BREAKAWAY_FROM_JOB: u32 = 0x01000000;
|
|
332
|
-
cmd.creation_flags(DETACHED_PROCESS | CREATE_BREAKAWAY_FROM_JOB);
|
|
333
|
-
}
|
|
334
|
-
let child = cmd.spawn().map_err(|e| ShimError::Spawn {
|
|
335
|
-
pipe_name: pipe_name.clone(),
|
|
336
|
-
source: e,
|
|
337
|
-
})?;
|
|
338
|
-
|
|
339
|
-
let pid = child.id();
|
|
340
|
-
|
|
341
|
-
// Retry connect+hello up to `CONNECT_ATTEMPTS`. First 1-2 attempts
|
|
342
|
-
// will usually fail with pipe-not-yet-listening; the shim's
|
|
343
|
-
// CreateNamedPipeW race window is ~10-50ms.
|
|
344
|
-
let mut last_reason: Option<String> = None;
|
|
345
|
-
for attempt in 1..=CONNECT_ATTEMPTS {
|
|
346
|
-
// `wait_ms=100` per attempt lets `WaitNamedPipeW` do most of
|
|
347
|
-
// the polling inside the OS instead of our sleep loop.
|
|
348
|
-
match NamedPipeClient::connect(&pipe_name, 100) {
|
|
349
|
-
Ok(mut client) => {
|
|
350
|
-
match perform_hello(&mut client, &pipe_token, workspace_hash, team_key) {
|
|
351
|
-
Ok(()) => {
|
|
352
|
-
return finalize(child, pid, pipe_name, client, workspace);
|
|
353
|
-
}
|
|
354
|
-
Err(reason) => {
|
|
355
|
-
// Hello handshake failure is TERMINAL — a
|
|
356
|
-
// wire-compatible shim would have Ok'd it.
|
|
357
|
-
// Kill + fail immediately (no retry) so
|
|
358
|
-
// operators see the mismatch loudly.
|
|
359
|
-
let mut child = child;
|
|
360
|
-
let _ = child.kill();
|
|
361
|
-
let _ = child.wait();
|
|
362
|
-
return Err(ShimError::HelloFailed { pipe_name, reason });
|
|
363
|
-
}
|
|
364
|
-
}
|
|
365
|
-
}
|
|
366
|
-
Err(err) => {
|
|
367
|
-
last_reason = Some(format!("attempt {attempt}: {err}"));
|
|
368
|
-
std::thread::sleep(CONNECT_BACKOFF);
|
|
369
|
-
}
|
|
370
|
-
}
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
// Terminal: connect never succeeded. Kill the shim so we don't
|
|
374
|
-
// leave a zombie pipe-listener.
|
|
375
|
-
let mut child = child;
|
|
376
|
-
let _ = child.kill();
|
|
377
|
-
let _ = child.wait();
|
|
378
|
-
Err(ShimError::ConnectTimeout {
|
|
379
|
-
attempts: CONNECT_ATTEMPTS,
|
|
380
|
-
pipe_name,
|
|
381
|
-
})
|
|
382
|
-
.map_err(|e| {
|
|
383
|
-
// Fold last connect reason into the error chain via
|
|
384
|
-
// eprintln for now (Batch 7 will thread it into the typed
|
|
385
|
-
// event). Kept as eprintln so a `2>&1` capture on the
|
|
386
|
-
// coordinator surfaces it.
|
|
387
|
-
eprintln!(
|
|
388
|
-
"coordinator::conpty_shim: connect timeout — last={:?}",
|
|
389
|
-
last_reason
|
|
390
|
-
);
|
|
391
|
-
e
|
|
392
|
-
})
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
/// Perform the Hello RPC using the shim's `PipeClient::request`
|
|
396
|
-
/// primitive. Success is defined as `response.ok == true` AND
|
|
397
|
-
/// `response.result.pipe_token == expected_token` — the shim echoes
|
|
398
|
-
/// the token back to prove server-side receipt.
|
|
399
|
-
///
|
|
400
|
-
/// N18 isolation: `workspace_hash` + `team_key` must be non-empty and
|
|
401
|
-
/// match the shim's own binding — the shim rejects requests scoped
|
|
402
|
-
/// to a different tuple with `ProtocolError::ShimUnavailable`. We
|
|
403
|
-
/// pass them through unchanged from the caller.
|
|
404
|
-
fn perform_hello(
|
|
405
|
-
client: &mut NamedPipeClient,
|
|
406
|
-
expected_token: &str,
|
|
407
|
-
workspace_hash: &str,
|
|
408
|
-
team_key: &str,
|
|
409
|
-
) -> Result<(), String> {
|
|
410
|
-
use conpty_transport::{Op, PipeClient, Request};
|
|
411
|
-
// Request id doesn't need to be unique across the shim's
|
|
412
|
-
// lifetime — the shim just echoes it. Use a fixed sentinel so
|
|
413
|
-
// the reply is easy to spot in a wire log.
|
|
414
|
-
let req = Request::new(
|
|
415
|
-
"coord-hello",
|
|
416
|
-
workspace_hash,
|
|
417
|
-
team_key,
|
|
418
|
-
expected_token,
|
|
419
|
-
Op::Hello,
|
|
420
|
-
);
|
|
421
|
-
let resp = client.request(&req);
|
|
422
|
-
if !resp.ok {
|
|
423
|
-
return Err(format!("response.ok=false: {:?}", resp.error));
|
|
424
|
-
}
|
|
425
|
-
let echoed = resp
|
|
426
|
-
.result
|
|
427
|
-
.get("pipe_token")
|
|
428
|
-
.and_then(Value::as_str)
|
|
429
|
-
.ok_or_else(|| "response.result.pipe_token missing".to_string())?;
|
|
430
|
-
if echoed != expected_token {
|
|
431
|
-
return Err("response.result.pipe_token mismatch".to_string());
|
|
432
|
-
}
|
|
433
|
-
Ok(())
|
|
434
|
-
}
|
|
435
|
-
|
|
436
|
-
/// Persist the shim marker to `state.json` and package the surviving
|
|
437
|
-
/// child + pipe client into `ShimHandle`.
|
|
438
|
-
fn finalize(
|
|
439
|
-
child: Child,
|
|
440
|
-
pid: u32,
|
|
441
|
-
pipe_name: String,
|
|
442
|
-
client: NamedPipeClient,
|
|
443
|
-
workspace: &Path,
|
|
444
|
-
) -> Result<ShimHandle, ShimError> {
|
|
445
|
-
let mut state = crate::state::repository::StateRepository::new(workspace)
|
|
446
|
-
.load_workspace_if_exists_without_migrations()
|
|
447
|
-
.ok()
|
|
448
|
-
.flatten()
|
|
449
|
-
.unwrap_or_else(|| json!({}));
|
|
450
|
-
// CR C-1: token NOT stored. Only pid/pipe_name/pipe_ready.
|
|
451
|
-
let obj = state
|
|
452
|
-
.as_object_mut()
|
|
453
|
-
.ok_or_else(|| ShimError::StatePersist {
|
|
454
|
-
source: StateError::Io(std::io::Error::new(
|
|
455
|
-
std::io::ErrorKind::InvalidData,
|
|
456
|
-
"state.json root not an object",
|
|
457
|
-
)),
|
|
458
|
-
})?;
|
|
459
|
-
let transport = obj
|
|
460
|
-
.entry("transport".to_string())
|
|
461
|
-
.or_insert_with(|| json!({}));
|
|
462
|
-
if !transport.is_object() {
|
|
463
|
-
*transport = json!({});
|
|
464
|
-
}
|
|
465
|
-
let transport_obj = transport.as_object_mut().unwrap();
|
|
466
|
-
transport_obj.insert("kind".to_string(), json!("conpty"));
|
|
467
|
-
transport_obj.insert(
|
|
468
|
-
"shim".to_string(),
|
|
469
|
-
json!({
|
|
470
|
-
"pid": pid,
|
|
471
|
-
"pipe_name": pipe_name,
|
|
472
|
-
"pipe_ready": true,
|
|
473
|
-
}),
|
|
474
|
-
);
|
|
475
|
-
crate::state::repository::StateRepository::new(workspace)
|
|
476
|
-
.save(
|
|
477
|
-
crate::state::repository::StateWriteIntent::CoordinatorConptyShim {
|
|
478
|
-
team_key: state.get("active_team_key").and_then(Value::as_str),
|
|
479
|
-
},
|
|
480
|
-
&state,
|
|
481
|
-
)
|
|
482
|
-
.map_err(|e| ShimError::StatePersist { source: e })?;
|
|
483
|
-
// 0.5.x Windows portability Batch 7 F6: state merge now preserves
|
|
484
|
-
// the `transport.shim` block through downstream saves (see
|
|
485
|
-
// `state::persist::preserve_transport_shim`), so the Batch 6
|
|
486
|
-
// env-override workaround (`TEAM_AGENT_FORCE_CONPTY_PIPE_CONNECT`)
|
|
487
|
-
// is no longer needed. State-only readiness is authoritative.
|
|
488
|
-
Ok(ShimHandle {
|
|
489
|
-
child: Some(child),
|
|
490
|
-
pid,
|
|
491
|
-
pipe_name,
|
|
492
|
-
client: Some(client),
|
|
493
|
-
})
|
|
494
|
-
}
|
|
495
|
-
|
|
496
|
-
/// Read `state.transport.shim.pid` for shutdown routing. Returns
|
|
497
|
-
/// `None` when no shim is currently registered (Unix / never-launched
|
|
498
|
-
/// Windows worker). Callers use `platform::process::terminate_pid`
|
|
499
|
-
/// on the returned pid.
|
|
500
|
-
/// ---
|
|
501
|
-
/// purpose: 从 state 读出已登记的 shim 进程号
|
|
502
|
-
/// params:
|
|
503
|
-
/// workspace: workspace 根
|
|
504
|
-
/// returns: state.transport.shim.pid 存在且能转成 u32 时给值;没有登记过 shim(未起过或非 Windows 队)时为 None。只读状态,不做存活探测
|
|
505
|
-
/// ---
|
|
506
|
-
pub fn recorded_shim_pid(workspace: &Path) -> Option<u32> {
|
|
507
|
-
let state = crate::state::repository::StateRepository::new(workspace)
|
|
508
|
-
.load_workspace_if_exists_without_migrations()
|
|
509
|
-
.ok()??;
|
|
510
|
-
state
|
|
511
|
-
.get("transport")?
|
|
512
|
-
.get("shim")?
|
|
513
|
-
.get("pid")?
|
|
514
|
-
.as_u64()
|
|
515
|
-
.and_then(|v| u32::try_from(v).ok())
|
|
516
|
-
}
|
|
517
|
-
|
|
518
|
-
/// Read `state.transport.shim.pipe_name` for reconnect routing.
|
|
519
|
-
/// ---
|
|
520
|
-
/// purpose: 从 state 读出已登记的 shim 管道名
|
|
521
|
-
/// params:
|
|
522
|
-
/// workspace: workspace 根
|
|
523
|
-
/// returns: state.transport.shim.pipe_name 的字符串值;未登记时为 None
|
|
524
|
-
/// ---
|
|
525
|
-
pub fn recorded_shim_pipe_name(workspace: &Path) -> Option<String> {
|
|
526
|
-
let state = crate::state::repository::StateRepository::new(workspace)
|
|
527
|
-
.load_workspace_if_exists_without_migrations()
|
|
528
|
-
.ok()??;
|
|
529
|
-
state
|
|
530
|
-
.get("transport")?
|
|
531
|
-
.get("shim")?
|
|
532
|
-
.get("pipe_name")?
|
|
533
|
-
.as_str()
|
|
534
|
-
.map(str::to_string)
|
|
535
|
-
}
|
|
536
|
-
|
|
537
|
-
/// 0.5.x Windows portability Batch 8 F7 (leader msg_590b4dce0f68):
|
|
538
|
-
/// idempotent shim-ownership entry point owned by the coordinator.
|
|
539
|
-
///
|
|
540
|
-
/// The design's §Shim Lifecycle chapter reads: "shim 是 per-(workspace,
|
|
541
|
-
/// team) 长寿进程,coordinator 可死可重连". This fn is the ONE entry
|
|
542
|
-
/// point that both quick-start (via `ensure_coordinator_running`) and
|
|
543
|
-
/// coord tick monitor call.
|
|
544
|
-
///
|
|
545
|
-
/// Behavior:
|
|
546
|
-
///
|
|
547
|
-
/// 1. If `state.transport.shim.pid` is recorded AND the pid is alive,
|
|
548
|
-
/// call `reconnect_recorded_shim` — the shim is a per-(workspace,
|
|
549
|
-
/// team) singleton and we just re-Hello to prove wire compatibility.
|
|
550
|
-
/// 2. Otherwise, `spawn_shim_and_handshake` — spawn a fresh shim,
|
|
551
|
-
/// perform Hello, persist state.
|
|
552
|
-
///
|
|
553
|
-
/// This gives the "coord can die, shim survives" invariant: a fresh
|
|
554
|
-
/// coord that finds a live shim just reconnects; a fresh coord that
|
|
555
|
-
/// finds no shim spawns one.
|
|
556
|
-
/// ---
|
|
557
|
-
/// purpose: 保证本 (workspace, team) 有一个可用的 shim——这是 coordinator 侧唯一的 shim 所有权入口
|
|
558
|
-
/// params:
|
|
559
|
-
/// workspace: workspace 根
|
|
560
|
-
/// team_key: 目标 team,进 Hello 请求的作用域
|
|
561
|
-
/// workspace_hash: 管道名里用的 workspace 摘要
|
|
562
|
-
/// returns: 已登记 pid 还活着且重连成功 → 复用原进程的句柄(不拥有子进程);否则新起一个并握手,返回拥有子进程的句柄
|
|
563
|
-
/// errors: 找不到 shim 可执行文件、spawn 失败、连接超时、Hello 失败或落盘 state 失败时返回对应 ShimError。重连失败不算错误,会直接落到新起那条路
|
|
564
|
-
/// ---
|
|
565
|
-
pub fn ensure_shim_running(
|
|
566
|
-
workspace: &Path,
|
|
567
|
-
team_key: &str,
|
|
568
|
-
workspace_hash: &str,
|
|
569
|
-
) -> Result<ShimHandle, ShimError> {
|
|
570
|
-
// Path 1: reconnect if state has a live shim recorded.
|
|
571
|
-
if let Some(pid) = recorded_shim_pid(workspace) {
|
|
572
|
-
if crate::platform::process::pid_is_alive(pid) {
|
|
573
|
-
match reconnect_recorded_shim(workspace, team_key, workspace_hash) {
|
|
574
|
-
Ok(handle) => return Ok(handle),
|
|
575
|
-
Err(_e) => {
|
|
576
|
-
// Recorded shim is dead-in-effect (pipe closed
|
|
577
|
-
// or Hello failed even though pid is alive).
|
|
578
|
-
// Fall through to spawn — DO NOT mark stale
|
|
579
|
-
// here because the fresh spawn's finalize will
|
|
580
|
-
// atomically REPLACE the shim block with the
|
|
581
|
-
// new pid + pipe_ready:true. Emitting an
|
|
582
|
-
// unavailable event now + finalize's re-write
|
|
583
|
-
// was creating a race where the unavailable
|
|
584
|
-
// reason lingered even after finalize completed
|
|
585
|
-
// (real-machine batch8-28742934836 evidence).
|
|
586
|
-
}
|
|
587
|
-
}
|
|
588
|
-
}
|
|
589
|
-
// Pid is dead OR reconnect failed. Do NOT mark unavailable
|
|
590
|
-
// here — the fresh spawn below overwrites the shim block
|
|
591
|
-
// authoritatively.
|
|
592
|
-
}
|
|
593
|
-
// Path 2: spawn a fresh shim.
|
|
594
|
-
spawn_shim_and_handshake(workspace, team_key, workspace_hash)
|
|
595
|
-
}
|
|
596
|
-
|
|
597
|
-
/// 0.5.x Windows portability Batch 8 F7: reconnect to an already-
|
|
598
|
-
/// running shim by reading `state.transport.shim.pipe_name` and
|
|
599
|
-
/// opening a fresh `NamedPipeClient` + performing Hello.
|
|
600
|
-
///
|
|
601
|
-
/// Does NOT spawn a new shim. Returns `ShimError::ConnectTimeout` /
|
|
602
|
-
/// `HelloFailed` on failure. Callers (post-crash coord restart)
|
|
603
|
-
/// treat these errors as "recorded shim is dead → mark stale +
|
|
604
|
-
/// consider re-spawn via `ensure_shim_running`".
|
|
605
|
-
///
|
|
606
|
-
/// Handle returned from this fn has no owned child (the shim is
|
|
607
|
-
/// somebody else's — usually a previous coord instance). `detach()`
|
|
608
|
-
/// on the handle is a no-op for the child.
|
|
609
|
-
/// ---
|
|
610
|
-
/// purpose: 只重连 state 里已登记的 shim 并重做 Hello,用来证明线协议仍然可用
|
|
611
|
-
/// params:
|
|
612
|
-
/// workspace: workspace 根
|
|
613
|
-
/// team_key: 目标 team,进 Hello 请求的作用域
|
|
614
|
-
/// _workspace_hash: 未使用;管道名直接取自 state,不再重算
|
|
615
|
-
/// returns: 连上且 Hello 回 ok 时给出不拥有子进程的句柄,对它调 detach 对子进程是空操作
|
|
616
|
-
/// errors: state 里没有管道名或多次连接均失败 → ConnectTimeout;连上但 Hello 回 ok=false → HelloFailed。本函数绝不新起进程
|
|
617
|
-
/// ---
|
|
618
|
-
pub fn reconnect_recorded_shim(
|
|
619
|
-
workspace: &Path,
|
|
620
|
-
team_key: &str,
|
|
621
|
-
_workspace_hash: &str,
|
|
622
|
-
) -> Result<ShimHandle, ShimError> {
|
|
623
|
-
let pipe_name =
|
|
624
|
-
recorded_shim_pipe_name(workspace).ok_or_else(|| ShimError::ConnectTimeout {
|
|
625
|
-
attempts: 0,
|
|
626
|
-
pipe_name: "<state.transport.shim.pipe_name missing>".to_string(),
|
|
627
|
-
})?;
|
|
628
|
-
// For reconnect we don't have the original pipe_token (CR C-1:
|
|
629
|
-
// token was never persisted). Hello is designed to accept any
|
|
630
|
-
// token from the client and echo back the shim's own token, so
|
|
631
|
-
// we use a placeholder and validate the shim's reply instead.
|
|
632
|
-
//
|
|
633
|
-
// NOTE: with reconnect, we're proving wire compatibility, not
|
|
634
|
-
// authenticating a fresh token exchange. The shim's own token
|
|
635
|
-
// is the authoritative one for subsequent requests; if the
|
|
636
|
-
// shim rotated tokens, the shim rejects subsequent non-Hello
|
|
637
|
-
// requests with `PipeTokenMismatch` and the client must
|
|
638
|
-
// re-Hello — which is exactly what this fn does.
|
|
639
|
-
let placeholder_token = "PENDING-RECONNECT";
|
|
640
|
-
let mut last_err: Option<ShimError> = None;
|
|
641
|
-
for attempt in 1..=CONNECT_ATTEMPTS {
|
|
642
|
-
match NamedPipeClient::connect(&pipe_name, 500) {
|
|
643
|
-
Ok(mut client) => match reconnect_hello(&mut client, team_key) {
|
|
644
|
-
Ok(()) => {
|
|
645
|
-
return Ok(ShimHandle {
|
|
646
|
-
child: None,
|
|
647
|
-
pid: recorded_shim_pid(workspace).unwrap_or(0),
|
|
648
|
-
pipe_name,
|
|
649
|
-
client: Some(client),
|
|
650
|
-
});
|
|
651
|
-
}
|
|
652
|
-
Err(reason) => {
|
|
653
|
-
return Err(ShimError::HelloFailed { pipe_name, reason });
|
|
654
|
-
}
|
|
655
|
-
},
|
|
656
|
-
Err(err) => {
|
|
657
|
-
let _ = attempt;
|
|
658
|
-
let _ = placeholder_token;
|
|
659
|
-
last_err = Some(ShimError::ConnectTimeout {
|
|
660
|
-
attempts: 1,
|
|
661
|
-
pipe_name: format!("{pipe_name} (io: {err})"),
|
|
662
|
-
});
|
|
663
|
-
std::thread::sleep(CONNECT_BACKOFF);
|
|
664
|
-
}
|
|
665
|
-
}
|
|
666
|
-
}
|
|
667
|
-
Err(last_err.unwrap_or(ShimError::ConnectTimeout {
|
|
668
|
-
attempts: CONNECT_ATTEMPTS,
|
|
669
|
-
pipe_name,
|
|
670
|
-
}))
|
|
671
|
-
}
|
|
672
|
-
|
|
673
|
-
/// Reconnect Hello: the client sends Hello with the current workspace/
|
|
674
|
-
/// team scope; the shim replies with its OWN pipe_token (which the
|
|
675
|
-
/// client doesn't know yet). We just validate `resp.ok`.
|
|
676
|
-
fn reconnect_hello(client: &mut NamedPipeClient, team_key: &str) -> Result<(), String> {
|
|
677
|
-
use conpty_transport::{Op, PipeClient, Request};
|
|
678
|
-
let req = Request::new(
|
|
679
|
-
"coord-reconnect-hello",
|
|
680
|
-
"", // workspace_hash isn't authoritative for reconnect
|
|
681
|
-
team_key,
|
|
682
|
-
"PENDING-RECONNECT",
|
|
683
|
-
Op::Hello,
|
|
684
|
-
);
|
|
685
|
-
let resp = client.request(&req);
|
|
686
|
-
if !resp.ok {
|
|
687
|
-
return Err(format!("reconnect hello ok=false: {:?}", resp.error));
|
|
688
|
-
}
|
|
689
|
-
Ok(())
|
|
690
|
-
}
|
|
691
|
-
|
|
692
|
-
/// 0.5.x Windows portability Batch 8 F7: emit the C-3 stale-family
|
|
693
|
-
/// event when the coordinator's tick loop finds the shim
|
|
694
|
-
/// unreachable. Also clears `state.transport.shim.pipe_ready` so
|
|
695
|
-
/// downstream code sees the truthful state.
|
|
696
|
-
///
|
|
697
|
-
/// The event name (`transport.conpty_shim_unavailable`) is picked
|
|
698
|
-
/// deliberately to live in the same event family as other
|
|
699
|
-
/// stale-transport signals (see design §C-3 anchor). Consumers
|
|
700
|
-
/// (status --detail, doctor, MCP status) can grep for
|
|
701
|
-
/// `transport.conpty_shim_*` and get the full stale picture.
|
|
702
|
-
///
|
|
703
|
-
/// This is a no-op on Unix (no shim concept, no state to clear).
|
|
704
|
-
/// The Windows-only `#[cfg]` gate is at the mod level (see
|
|
705
|
-
/// `coordinator/mod.rs`); on Unix this file isn't compiled, so
|
|
706
|
-
/// downstream callers must cfg-gate their reference themselves.
|
|
707
|
-
/// ---
|
|
708
|
-
/// purpose: 把「shim 不可达」这件事诚实地写出去——发 stale 家族事件,并清掉 state 里的就绪位
|
|
709
|
-
/// params:
|
|
710
|
-
/// workspace: workspace 根
|
|
711
|
-
/// reason: 不可达原因,同时进事件与 state.transport.shim.unavailable_reason
|
|
712
|
-
/// returns: 状态里本来就没有 shim 块时也返回 Ok。事件写入是尽力而为,写不出去不影响返回;清状态才是权威动作
|
|
713
|
-
/// errors: 读写 state 失败时返回 StateError;state JSON 损坏时按空状态继续
|
|
714
|
-
/// ---
|
|
715
|
-
pub fn mark_transport_unavailable(workspace: &Path, reason: &str) -> Result<(), StateError> {
|
|
716
|
-
// Best-effort event emission — a failed event write should not
|
|
717
|
-
// fail the caller. The state-clearing step below is authoritative.
|
|
718
|
-
if let Ok(event_log) = std::panic::catch_unwind(|| crate::event_log::EventLog::new(workspace)) {
|
|
719
|
-
let _ = event_log.write(
|
|
720
|
-
"transport.conpty_shim_unavailable",
|
|
721
|
-
serde_json::json!({
|
|
722
|
-
"reason": reason,
|
|
723
|
-
"workspace": workspace.display().to_string(),
|
|
724
|
-
}),
|
|
725
|
-
);
|
|
726
|
-
}
|
|
727
|
-
// Clear the shim block from state so subsequent factory
|
|
728
|
-
// `conpty_pipe_ready` checks return false and the operator sees
|
|
729
|
-
// an honest "no live shim" via status --detail.
|
|
730
|
-
let mut state = match crate::state::repository::StateRepository::new(workspace)
|
|
731
|
-
.load_workspace_if_exists_without_migrations()
|
|
732
|
-
{
|
|
733
|
-
Ok(Some(state)) => state,
|
|
734
|
-
Ok(None) => return Ok(()),
|
|
735
|
-
Err(StateError::Json(_)) => serde_json::json!({}),
|
|
736
|
-
Err(error) => return Err(error),
|
|
737
|
-
};
|
|
738
|
-
if let Some(transport) = state.get_mut("transport").and_then(|t| t.as_object_mut()) {
|
|
739
|
-
if let Some(shim) = transport.get_mut("shim").and_then(|s| s.as_object_mut()) {
|
|
740
|
-
shim.insert("pipe_ready".to_string(), serde_json::json!(false));
|
|
741
|
-
shim.insert("unavailable_reason".to_string(), serde_json::json!(reason));
|
|
742
|
-
}
|
|
743
|
-
}
|
|
744
|
-
crate::state::repository::StateRepository::new(workspace).save(
|
|
745
|
-
crate::state::repository::StateWriteIntent::CoordinatorConptyShim {
|
|
746
|
-
team_key: state.get("active_team_key").and_then(Value::as_str),
|
|
747
|
-
},
|
|
748
|
-
&state,
|
|
749
|
-
)
|
|
750
|
-
}
|
|
751
|
-
|
|
752
|
-
#[cfg(test)]
|
|
753
|
-
mod tests {
|
|
754
|
-
use super::*;
|
|
755
|
-
|
|
756
|
-
#[test]
|
|
757
|
-
fn pipe_token_is_never_written_to_state_json() {
|
|
758
|
-
// CR C-1 anchor: the `finalize` step must NOT persist the
|
|
759
|
-
// pipe_token. Static-code smell test: read this file and
|
|
760
|
-
// assert the string `"pipe_token"` never appears alongside
|
|
761
|
-
// a `save_runtime_state` call inside `finalize`.
|
|
762
|
-
let src = include_str!("conpty_shim.rs");
|
|
763
|
-
// Locate the `finalize` fn body and grep for pipe_token
|
|
764
|
-
// insertion.
|
|
765
|
-
let (_, finalize_and_after) = src.split_once("fn finalize(").expect("finalize fn present");
|
|
766
|
-
let finalize_body = finalize_and_after
|
|
767
|
-
.split_once("\n}")
|
|
768
|
-
.map(|(body, _)| body)
|
|
769
|
-
.unwrap_or(finalize_and_after);
|
|
770
|
-
assert!(
|
|
771
|
-
!finalize_body.contains("\"pipe_token\""),
|
|
772
|
-
"CR C-1 violation: finalize() persisted `pipe_token` to state.json"
|
|
773
|
-
);
|
|
774
|
-
assert!(
|
|
775
|
-
!finalize_body.contains("pipe_token()"),
|
|
776
|
-
"CR C-1 violation: finalize() persisted `pipe_token()` accessor"
|
|
777
|
-
);
|
|
778
|
-
}
|
|
779
|
-
|
|
780
|
-
#[test]
|
|
781
|
-
fn state_layout_records_only_pid_pipe_name_pipe_ready() {
|
|
782
|
-
// Structural companion to the previous test: `finalize`'s
|
|
783
|
-
// JSON literal keys under `transport.shim` must be exactly
|
|
784
|
-
// {pid, pipe_name, pipe_ready}. If a future edit adds a 4th
|
|
785
|
-
// key that carries a secret, this test fires.
|
|
786
|
-
let src = include_str!("conpty_shim.rs");
|
|
787
|
-
let (_, after) = src
|
|
788
|
-
.split_once("\"shim\".to_string(),")
|
|
789
|
-
.expect("shim insert");
|
|
790
|
-
let block_end = after.find("}),").unwrap_or(after.len());
|
|
791
|
-
let block = &after[..block_end];
|
|
792
|
-
for expected in ["pid", "pipe_name", "pipe_ready"] {
|
|
793
|
-
assert!(
|
|
794
|
-
block.contains(&format!("\"{expected}\":")),
|
|
795
|
-
"shim state block missing `{expected}` key"
|
|
796
|
-
);
|
|
797
|
-
}
|
|
798
|
-
for forbidden in ["pipe_token", "token", "secret"] {
|
|
799
|
-
assert!(
|
|
800
|
-
!block.contains(&format!("\"{forbidden}\":")),
|
|
801
|
-
"shim state block MUST NOT contain `{forbidden}` key (CR C-1)"
|
|
802
|
-
);
|
|
803
|
-
}
|
|
804
|
-
}
|
|
805
|
-
}
|