@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,629 +0,0 @@
|
|
|
1
|
-
//! ---
|
|
2
|
-
//! purpose: Pi leader 的 executable/catalog 验证、MCP 能力注册与 fresh 启动计划物化
|
|
3
|
-
//! contract:
|
|
4
|
-
//! provides:
|
|
5
|
-
//! - name: materialize_pi_plan
|
|
6
|
-
//! what: 为 `team-agent pi` leader 生成 fresh Pi CommandPlan
|
|
7
|
-
//! - name: write_pi_wrapper
|
|
8
|
-
//! what: 原子写入 0600 per-seat runtime MCP registration extension
|
|
9
|
-
//! - name: pi_cleanup_plan
|
|
10
|
-
//! what: 移除升级前遗留的 legacy Pi worker 席位时只删 wrapper
|
|
11
|
-
//! boundary:
|
|
12
|
-
//! - Pi worker 席位只走 contract `pi_tui` leaf;这里不再 spawn/resume/fork worker
|
|
13
|
-
//! - 不枚举 Pi session;不投递消息、不执行 doctor 判定
|
|
14
|
-
//! - 不读取 credentials 或 provider settings 值
|
|
15
|
-
//! maturity: wired
|
|
16
|
-
//! ---
|
|
17
|
-
|
|
18
|
-
use std::collections::BTreeSet;
|
|
19
|
-
use std::fs::OpenOptions;
|
|
20
|
-
use std::io::Write;
|
|
21
|
-
use std::os::unix::fs::{OpenOptionsExt, PermissionsExt};
|
|
22
|
-
use std::path::{Path, PathBuf};
|
|
23
|
-
use std::process::Command;
|
|
24
|
-
|
|
25
|
-
use sha2::{Digest, Sha256};
|
|
26
|
-
|
|
27
|
-
use crate::model::enums::{Provider, ProviderEffort};
|
|
28
|
-
use crate::provider::command_helpers::{append_opt_pair, append_pair};
|
|
29
|
-
use crate::provider::{CommandPlan, McpConfig, ProviderError};
|
|
30
|
-
|
|
31
|
-
/// The first executable `pi` on PATH, exactly what the worker's bare `pi`
|
|
32
|
-
/// runs: a wrapper, npm symlink or plain binary alike. No inner binary is probed.
|
|
33
|
-
#[derive(Debug, Clone, PartialEq, Eq)]
|
|
34
|
-
pub(crate) struct PiExecutableChain {
|
|
35
|
-
pub path_entry: PathBuf,
|
|
36
|
-
pub pi_version: String,
|
|
37
|
-
pub catalog_sha256: String,
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
#[derive(Debug, Clone, PartialEq, Eq)]
|
|
41
|
-
pub(crate) struct PiSeatPaths {
|
|
42
|
-
pub runtime_root: PathBuf,
|
|
43
|
-
pub wrapper: PathBuf,
|
|
44
|
-
pub sessions: PathBuf,
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
|
48
|
-
pub(crate) enum PiCleanupAction {
|
|
49
|
-
Stop,
|
|
50
|
-
Remove,
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
#[derive(Debug, Clone, PartialEq, Eq)]
|
|
54
|
-
pub(crate) struct PiCleanupPlan {
|
|
55
|
-
pub delete_paths: Vec<PathBuf>,
|
|
56
|
-
pub retain_paths: Vec<PathBuf>,
|
|
57
|
-
pub process_name_scan: Option<String>,
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/// ---
|
|
61
|
-
/// purpose: 给 stop/remove 生成 Pi 席位 exact cleanup 计划
|
|
62
|
-
/// returns: stop 全保留;remove 只删 wrapper 并保留 session backing
|
|
63
|
-
/// ---
|
|
64
|
-
pub(crate) fn pi_cleanup_plan(action: PiCleanupAction, paths: &PiSeatPaths) -> PiCleanupPlan {
|
|
65
|
-
match action {
|
|
66
|
-
PiCleanupAction::Stop => PiCleanupPlan {
|
|
67
|
-
delete_paths: Vec::new(),
|
|
68
|
-
retain_paths: vec![paths.wrapper.clone(), paths.sessions.clone()],
|
|
69
|
-
process_name_scan: None,
|
|
70
|
-
},
|
|
71
|
-
PiCleanupAction::Remove => PiCleanupPlan {
|
|
72
|
-
delete_paths: vec![paths.wrapper.clone()],
|
|
73
|
-
retain_paths: vec![paths.sessions.clone()],
|
|
74
|
-
process_name_scan: None,
|
|
75
|
-
},
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/// ---
|
|
80
|
-
/// purpose: 计算一个 Pi 席位唯一的 Team-owned runtime 路径
|
|
81
|
-
/// returns: runtime root、wrapper 与 sessions 路径
|
|
82
|
-
/// ---
|
|
83
|
-
pub(crate) fn pi_seat_paths(workspace: &Path, team_id: &str, agent_id: &str) -> PiSeatPaths {
|
|
84
|
-
let runtime_root = workspace
|
|
85
|
-
.join(".team")
|
|
86
|
-
.join("runtime")
|
|
87
|
-
.join("pi")
|
|
88
|
-
.join(team_id)
|
|
89
|
-
.join(agent_id);
|
|
90
|
-
PiSeatPaths {
|
|
91
|
-
wrapper: runtime_root.join("team-mcp.ts"),
|
|
92
|
-
sessions: runtime_root.join("sessions"),
|
|
93
|
-
runtime_root,
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
/// ---
|
|
98
|
-
/// purpose: 解析 pi --list-models 未过滤表格为 provider/model exact ids
|
|
99
|
-
/// returns: 保序且无重复的 exact ids
|
|
100
|
-
/// errors: 非 UTF-8、header/row 异常、重复或空 catalog 时返回 ProviderError
|
|
101
|
-
/// ---
|
|
102
|
-
pub(crate) fn parse_pi_list_models_table(bytes: &[u8]) -> Result<Vec<String>, ProviderError> {
|
|
103
|
-
crate::provider::model_catalog::parse_pi_catalog(bytes)
|
|
104
|
-
.map(|records| records.into_iter().map(|record| record.id).collect())
|
|
105
|
-
.map_err(|error| ProviderError::Command(error.pi_legacy_message()))
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
/// ---
|
|
109
|
-
/// purpose: 在动态 catalog 中只接受一个字节精确的 qualified model
|
|
110
|
-
/// returns: exact catalog id
|
|
111
|
-
/// errors: 非 qualified、wildcard、缺失或重复时返回 ProviderError
|
|
112
|
-
/// ---
|
|
113
|
-
pub(crate) fn select_exact_pi_model(
|
|
114
|
-
models: &[String],
|
|
115
|
-
requested: &str,
|
|
116
|
-
) -> Result<String, ProviderError> {
|
|
117
|
-
if requested.trim() != requested
|
|
118
|
-
|| requested.is_empty()
|
|
119
|
-
|| requested.contains('*')
|
|
120
|
-
|| !requested
|
|
121
|
-
.split_once('/')
|
|
122
|
-
.is_some_and(|(provider, model)| !provider.is_empty() && !model.is_empty())
|
|
123
|
-
{
|
|
124
|
-
return Err(ProviderError::Command(format!(
|
|
125
|
-
"Pi model must be a qualified exact catalog id: {requested:?}"
|
|
126
|
-
)));
|
|
127
|
-
}
|
|
128
|
-
let mut matches = models.iter().filter(|model| model.as_str() == requested);
|
|
129
|
-
let selected = matches.next().ok_or_else(|| {
|
|
130
|
-
ProviderError::Command(format!("Pi model is not in the live catalog: {requested}"))
|
|
131
|
-
})?;
|
|
132
|
-
if matches.next().is_some() {
|
|
133
|
-
return Err(ProviderError::Command(format!(
|
|
134
|
-
"Pi model catalog selection is ambiguous: {requested}"
|
|
135
|
-
)));
|
|
136
|
-
}
|
|
137
|
-
Ok(selected.clone())
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
/// ---
|
|
141
|
-
/// purpose: 校验 Pi PATH entry 与 live catalog;MCP 能力在实际 Pi context 验证
|
|
142
|
-
/// returns: PATH entry 与 catalog receipt 完整时成功
|
|
143
|
-
/// errors: 缺路径或 catalog receipt 时返回 ProviderError
|
|
144
|
-
/// ---
|
|
145
|
-
pub(crate) fn validate_pi_executable_chain(chain: &PiExecutableChain) -> Result<(), ProviderError> {
|
|
146
|
-
if !chain.path_entry.is_absolute()
|
|
147
|
-
|| chain.path_entry.file_name().is_none_or(|name| name != "pi")
|
|
148
|
-
|| chain.catalog_sha256.len() != 64
|
|
149
|
-
|| !chain
|
|
150
|
-
.catalog_sha256
|
|
151
|
-
.bytes()
|
|
152
|
-
.all(|byte| byte.is_ascii_hexdigit())
|
|
153
|
-
|| chain.catalog_sha256.bytes().all(|byte| byte == b'0')
|
|
154
|
-
{
|
|
155
|
-
return Err(ProviderError::Command(
|
|
156
|
-
"Pi executable chain does not provide the required public protocol".to_string(),
|
|
157
|
-
));
|
|
158
|
-
}
|
|
159
|
-
Ok(())
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
pub(crate) struct PiWrapperRequest<'a> {
|
|
163
|
-
pub destination: &'a Path,
|
|
164
|
-
pub candidate_executable: &'a Path,
|
|
165
|
-
pub mcp_config: &'a McpConfig,
|
|
166
|
-
pub team_id: &'a str,
|
|
167
|
-
pub agent_id: &'a str,
|
|
168
|
-
pub workspace: &'a Path,
|
|
169
|
-
pub include_tools: &'a [&'a str],
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
fn team_server(
|
|
173
|
-
config: &McpConfig,
|
|
174
|
-
) -> Result<serde_json::Map<String, serde_json::Value>, ProviderError> {
|
|
175
|
-
let server = config
|
|
176
|
-
.raw
|
|
177
|
-
.get("team_orchestrator")
|
|
178
|
-
.or_else(|| config.raw.pointer("/mcpServers/team_orchestrator"))
|
|
179
|
-
.and_then(serde_json::Value::as_object)
|
|
180
|
-
.cloned()
|
|
181
|
-
.ok_or_else(|| {
|
|
182
|
-
ProviderError::Command("resolved MCP config is missing team_orchestrator".to_string())
|
|
183
|
-
})?;
|
|
184
|
-
Ok(server)
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
fn candidate_from_mcp_config(config: &McpConfig) -> Result<PathBuf, ProviderError> {
|
|
188
|
-
let server = team_server(config)?;
|
|
189
|
-
let command = server
|
|
190
|
-
.get("command")
|
|
191
|
-
.and_then(serde_json::Value::as_str)
|
|
192
|
-
.filter(|value| !value.is_empty())
|
|
193
|
-
.map(PathBuf::from)
|
|
194
|
-
.ok_or_else(|| {
|
|
195
|
-
ProviderError::Command("resolved team_orchestrator MCP command is missing".to_string())
|
|
196
|
-
})?;
|
|
197
|
-
if !command.is_absolute() {
|
|
198
|
-
return Err(ProviderError::Command(
|
|
199
|
-
"resolved team_orchestrator MCP command must be absolute".to_string(),
|
|
200
|
-
));
|
|
201
|
-
}
|
|
202
|
-
Ok(command)
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
fn render_pi_wrapper(request: &PiWrapperRequest<'_>) -> Result<String, ProviderError> {
|
|
206
|
-
let allowed = request.include_tools.iter().copied().collect::<BTreeSet<_>>();
|
|
207
|
-
if allowed.is_empty()
|
|
208
|
-
|| allowed.len() != request.include_tools.len()
|
|
209
|
-
|| allowed
|
|
210
|
-
.iter()
|
|
211
|
-
.any(|tool| !["send_message", "report_result", "get_team_status"].contains(tool))
|
|
212
|
-
{
|
|
213
|
-
return Err(ProviderError::Command(
|
|
214
|
-
"Pi MCP tools must be a non-empty subset of the three Team tools".to_string(),
|
|
215
|
-
));
|
|
216
|
-
}
|
|
217
|
-
let configured_candidate = candidate_from_mcp_config(request.mcp_config)?;
|
|
218
|
-
let expected = std::fs::canonicalize(request.candidate_executable)
|
|
219
|
-
.unwrap_or_else(|_| request.candidate_executable.to_path_buf());
|
|
220
|
-
let configured = std::fs::canonicalize(&configured_candidate).unwrap_or(configured_candidate);
|
|
221
|
-
if configured != expected {
|
|
222
|
-
return Err(ProviderError::Command(format!(
|
|
223
|
-
"Pi wrapper candidate mismatch: expected {} got {}",
|
|
224
|
-
expected.display(),
|
|
225
|
-
configured.display()
|
|
226
|
-
)));
|
|
227
|
-
}
|
|
228
|
-
let mut server = team_server(request.mcp_config)?;
|
|
229
|
-
server.insert(
|
|
230
|
-
"command".to_string(),
|
|
231
|
-
serde_json::Value::String(expected.to_string_lossy().into_owned()),
|
|
232
|
-
);
|
|
233
|
-
server.insert(
|
|
234
|
-
"includeTools".to_string(),
|
|
235
|
-
serde_json::Value::Array(
|
|
236
|
-
request
|
|
237
|
-
.include_tools
|
|
238
|
-
.iter()
|
|
239
|
-
.map(|tool| serde_json::Value::String((*tool).to_string()))
|
|
240
|
-
.collect(),
|
|
241
|
-
),
|
|
242
|
-
);
|
|
243
|
-
let env = server
|
|
244
|
-
.entry("env".to_string())
|
|
245
|
-
.or_insert_with(|| serde_json::Value::Object(serde_json::Map::new()))
|
|
246
|
-
.as_object_mut()
|
|
247
|
-
.ok_or_else(|| ProviderError::Command("Pi MCP server env must be an object".to_string()))?;
|
|
248
|
-
env.insert(
|
|
249
|
-
"TEAM_AGENT_WORKSPACE".to_string(),
|
|
250
|
-
serde_json::Value::String(request.workspace.to_string_lossy().into_owned()),
|
|
251
|
-
);
|
|
252
|
-
env.insert(
|
|
253
|
-
"TEAM_AGENT_ID".to_string(),
|
|
254
|
-
serde_json::Value::String(request.agent_id.to_string()),
|
|
255
|
-
);
|
|
256
|
-
env.insert(
|
|
257
|
-
"TEAM_AGENT_AGENT_ID".to_string(),
|
|
258
|
-
serde_json::Value::String(request.agent_id.to_string()),
|
|
259
|
-
);
|
|
260
|
-
env.insert(
|
|
261
|
-
"TEAM_AGENT_OWNER_TEAM_ID".to_string(),
|
|
262
|
-
serde_json::Value::String(request.team_id.to_string()),
|
|
263
|
-
);
|
|
264
|
-
let definition = serde_json::to_string(&serde_json::Value::Object(server))
|
|
265
|
-
.map_err(|error| ProviderError::Command(format!("serialize Pi MCP server: {error}")))?;
|
|
266
|
-
let receipt_root = request
|
|
267
|
-
.destination
|
|
268
|
-
.parent()
|
|
269
|
-
.filter(|path| path.is_absolute())
|
|
270
|
-
.ok_or_else(|| {
|
|
271
|
-
ProviderError::Command("Pi MCP wrapper requires an absolute seat directory".to_string())
|
|
272
|
-
})?;
|
|
273
|
-
let receipt_root = serde_json::to_string(&receipt_root.to_string_lossy())
|
|
274
|
-
.map_err(|error| ProviderError::Command(format!("serialize Pi MCP seat directory: {error}")))?;
|
|
275
|
-
Ok(format!(
|
|
276
|
-
"const teamMcpDefinition = {definition};\nconst teamMcpReceiptRoot = {receipt_root};\n\n{}",
|
|
277
|
-
include_str!("pi_mcp_extension.js")
|
|
278
|
-
))
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
/// ---
|
|
282
|
-
/// purpose: 静态核对 wrapper 使用原生/公共 MCP 能力模板与指定 candidate
|
|
283
|
-
/// returns: 模板完整且 candidate、seat 目录正确时成功
|
|
284
|
-
/// errors: 模板、candidate 或 seat 目录不匹配时返回 ProviderError
|
|
285
|
-
/// ---
|
|
286
|
-
pub(crate) fn validate_pi_wrapper_source(
|
|
287
|
-
source: &str,
|
|
288
|
-
candidate_executable: &Path,
|
|
289
|
-
) -> Result<(), ProviderError> {
|
|
290
|
-
let invalid = || {
|
|
291
|
-
ProviderError::Command(
|
|
292
|
-
"Pi wrapper source is not the owned MCP capability template".to_string(),
|
|
293
|
-
)
|
|
294
|
-
};
|
|
295
|
-
let prefix = source
|
|
296
|
-
.strip_suffix(include_str!("pi_mcp_extension.js"))
|
|
297
|
-
.ok_or_else(invalid)?;
|
|
298
|
-
let (definition, root) = prefix
|
|
299
|
-
.strip_prefix("const teamMcpDefinition = ")
|
|
300
|
-
.and_then(|value| value.split_once(";\nconst teamMcpReceiptRoot = "))
|
|
301
|
-
.ok_or_else(invalid)?;
|
|
302
|
-
let definition: serde_json::Value = serde_json::from_str(definition).map_err(|_| invalid())?;
|
|
303
|
-
let command = definition
|
|
304
|
-
.get("command")
|
|
305
|
-
.and_then(serde_json::Value::as_str)
|
|
306
|
-
.ok_or_else(invalid)?;
|
|
307
|
-
let root: String = serde_json::from_str(root.strip_suffix(";\n\n").ok_or_else(invalid)?)
|
|
308
|
-
.map_err(|_| invalid())?;
|
|
309
|
-
let expected = std::fs::canonicalize(candidate_executable)
|
|
310
|
-
.unwrap_or_else(|_| candidate_executable.to_path_buf());
|
|
311
|
-
if Path::new(command) != expected || !Path::new(&root).is_absolute() {
|
|
312
|
-
return Err(invalid());
|
|
313
|
-
}
|
|
314
|
-
Ok(())
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
/// ---
|
|
318
|
-
/// purpose: 在 seat root 原子写入 mode 0600 的 runtime MCP registration extension
|
|
319
|
-
/// returns: 最终 wrapper 路径
|
|
320
|
-
/// errors: identity、序列化、目录、写盘或 rename 失败时返回 ProviderError
|
|
321
|
-
/// ---
|
|
322
|
-
pub(crate) fn write_pi_wrapper(request: PiWrapperRequest<'_>) -> Result<PathBuf, ProviderError> {
|
|
323
|
-
write_pi_wrapper_with_publish(request, |from, to| std::fs::rename(from, to))
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
pub(crate) fn write_pi_wrapper_with_publish(
|
|
327
|
-
request: PiWrapperRequest<'_>,
|
|
328
|
-
publish: impl FnOnce(&Path, &Path) -> std::io::Result<()>,
|
|
329
|
-
) -> Result<PathBuf, ProviderError> {
|
|
330
|
-
let source = render_pi_wrapper(&request)?;
|
|
331
|
-
validate_pi_wrapper_source(&source, request.candidate_executable)?;
|
|
332
|
-
let parent = request.destination.parent().ok_or_else(|| {
|
|
333
|
-
ProviderError::Io("Pi wrapper destination has no parent directory".to_string())
|
|
334
|
-
})?;
|
|
335
|
-
std::fs::create_dir_all(parent).map_err(|error| {
|
|
336
|
-
ProviderError::Io(format!(
|
|
337
|
-
"Pi wrapper atomic write stage=create_parent path={}: {error}",
|
|
338
|
-
parent.display()
|
|
339
|
-
))
|
|
340
|
-
})?;
|
|
341
|
-
let temp = parent.join(format!(".team-mcp.ts.{}.tmp", std::process::id()));
|
|
342
|
-
let write_result = (|| {
|
|
343
|
-
let mut file = OpenOptions::new()
|
|
344
|
-
.create_new(true)
|
|
345
|
-
.write(true)
|
|
346
|
-
.mode(0o600)
|
|
347
|
-
.open(&temp)
|
|
348
|
-
.map_err(|error| {
|
|
349
|
-
ProviderError::Io(format!(
|
|
350
|
-
"Pi wrapper atomic write stage=open_temp path={}: {error}",
|
|
351
|
-
temp.display()
|
|
352
|
-
))
|
|
353
|
-
})?;
|
|
354
|
-
file.write_all(source.as_bytes()).map_err(|error| {
|
|
355
|
-
ProviderError::Io(format!(
|
|
356
|
-
"Pi wrapper atomic write stage=write_temp path={}: {error}",
|
|
357
|
-
temp.display()
|
|
358
|
-
))
|
|
359
|
-
})?;
|
|
360
|
-
file.set_permissions(std::fs::Permissions::from_mode(0o600))
|
|
361
|
-
.map_err(|error| {
|
|
362
|
-
ProviderError::Io(format!(
|
|
363
|
-
"Pi wrapper atomic write stage=chmod_temp_fd path={}: {error}",
|
|
364
|
-
temp.display()
|
|
365
|
-
))
|
|
366
|
-
})?;
|
|
367
|
-
file.sync_all().map_err(|error| {
|
|
368
|
-
ProviderError::Io(format!(
|
|
369
|
-
"Pi wrapper atomic write stage=fsync_temp path={}: {error}",
|
|
370
|
-
temp.display()
|
|
371
|
-
))
|
|
372
|
-
})?;
|
|
373
|
-
publish(&temp, request.destination).map_err(|error| {
|
|
374
|
-
ProviderError::Io(format!(
|
|
375
|
-
"Pi wrapper atomic write stage=rename_publish from={} to={}: {error}",
|
|
376
|
-
temp.display(),
|
|
377
|
-
request.destination.display()
|
|
378
|
-
))
|
|
379
|
-
})?;
|
|
380
|
-
Ok(request.destination.to_path_buf())
|
|
381
|
-
})();
|
|
382
|
-
if write_result.is_err() {
|
|
383
|
-
let _ = std::fs::remove_file(&temp);
|
|
384
|
-
}
|
|
385
|
-
write_result
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
#[derive(Debug, Clone, PartialEq, Eq)]
|
|
389
|
-
pub(crate) struct PiLeaderArgs {
|
|
390
|
-
pub model: Option<String>,
|
|
391
|
-
pub effort: Option<ProviderEffort>,
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
/// ---
|
|
395
|
-
/// purpose: 解析 Pi leader 唯一允许的 model/thinking 输入
|
|
396
|
-
/// returns: 仅保留调用方显式给出的 qualified model 与 effort
|
|
397
|
-
/// errors: 重复、未知或 materializer-owned flag 时返回 ProviderError
|
|
398
|
-
/// ---
|
|
399
|
-
pub(crate) fn parse_pi_leader_args(args: &[String]) -> Result<PiLeaderArgs, ProviderError> {
|
|
400
|
-
let args = args.strip_prefix(&["--".to_string()]).unwrap_or(args);
|
|
401
|
-
let mut model = None;
|
|
402
|
-
let mut effort = None;
|
|
403
|
-
let mut index = 0;
|
|
404
|
-
while index < args.len() {
|
|
405
|
-
let flag = args[index].as_str();
|
|
406
|
-
let value = args.get(index + 1).ok_or_else(|| {
|
|
407
|
-
ProviderError::Command(format!("Pi leader argument {flag} requires a value"))
|
|
408
|
-
})?;
|
|
409
|
-
match flag {
|
|
410
|
-
"--model" if model.is_none() => model = Some(value.clone()),
|
|
411
|
-
"--thinking" if effort.is_none() => {
|
|
412
|
-
let parsed = ProviderEffort::parse(value).ok_or_else(|| {
|
|
413
|
-
ProviderError::Command(format!("unknown Pi thinking effort {value:?}"))
|
|
414
|
-
})?;
|
|
415
|
-
effort = parsed
|
|
416
|
-
.resolve_for_provider(Provider::Pi)
|
|
417
|
-
.map_err(|reason| ProviderError::Command(reason.to_string()))?;
|
|
418
|
-
}
|
|
419
|
-
_ => {
|
|
420
|
-
return Err(ProviderError::Command(format!(
|
|
421
|
-
"Pi leader accepts only one --model and one --thinking; got {flag:?}"
|
|
422
|
-
)));
|
|
423
|
-
}
|
|
424
|
-
}
|
|
425
|
-
index += 2;
|
|
426
|
-
}
|
|
427
|
-
if model.as_ref().is_some_and(|model| {
|
|
428
|
-
model.contains('*')
|
|
429
|
-
|| !model
|
|
430
|
-
.split_once('/')
|
|
431
|
-
.is_some_and(|(provider, name)| !provider.is_empty() && !name.is_empty())
|
|
432
|
-
}) {
|
|
433
|
-
return Err(ProviderError::Command(
|
|
434
|
-
"Pi leader --model must be a qualified exact id".to_string(),
|
|
435
|
-
));
|
|
436
|
-
}
|
|
437
|
-
Ok(PiLeaderArgs { model, effort })
|
|
438
|
-
}
|
|
439
|
-
|
|
440
|
-
fn sha256(bytes: &[u8]) -> String {
|
|
441
|
-
format!("{:x}", Sha256::digest(bytes))
|
|
442
|
-
}
|
|
443
|
-
|
|
444
|
-
/// The shell's own PATH choice: the first executable `pi`, kept as found.
|
|
445
|
-
fn pi_path_entry() -> Result<PathBuf, ProviderError> {
|
|
446
|
-
let path = std::env::var_os("PATH")
|
|
447
|
-
.ok_or_else(|| ProviderError::Command("PATH is not set".to_string()))?;
|
|
448
|
-
team_agent_contract::host::command::PublicCommand::resolve("pi", &path)
|
|
449
|
-
.map(|command| command.entry)
|
|
450
|
-
.map_err(|_| ProviderError::Command("Pi executable not found on PATH".to_string()))
|
|
451
|
-
}
|
|
452
|
-
|
|
453
|
-
fn command_stdout(executable: &Path, args: &[&str]) -> Result<Vec<u8>, ProviderError> {
|
|
454
|
-
let output = Command::new(executable)
|
|
455
|
-
.args(args)
|
|
456
|
-
.output()
|
|
457
|
-
.map_err(|error| {
|
|
458
|
-
ProviderError::Io(format!(
|
|
459
|
-
"{} {}: {error}",
|
|
460
|
-
executable.display(),
|
|
461
|
-
args.join(" ")
|
|
462
|
-
))
|
|
463
|
-
})?;
|
|
464
|
-
if !output.status.success() {
|
|
465
|
-
return Err(ProviderError::Command(format!(
|
|
466
|
-
"{} {} exited {}",
|
|
467
|
-
executable.display(),
|
|
468
|
-
args.join(" "),
|
|
469
|
-
output.status
|
|
470
|
-
)));
|
|
471
|
-
}
|
|
472
|
-
Ok(output.stdout)
|
|
473
|
-
}
|
|
474
|
-
|
|
475
|
-
/// ---
|
|
476
|
-
/// purpose: 从当前 PATH 环境测量 Pi launch/real executable 与 live catalog,不检查 Pi packages
|
|
477
|
-
/// returns: 已验证的 chain 与同次 live catalog exact ids
|
|
478
|
-
/// errors: 缺失、命令失败或任一公共 protocol capability 缺失时返回 ProviderError
|
|
479
|
-
/// ---
|
|
480
|
-
pub(crate) fn resolve_pi_executable_chain(
|
|
481
|
-
) -> Result<(PiExecutableChain, Vec<String>), ProviderError> {
|
|
482
|
-
// Probe through the PATH entry itself so a user wrapper sees every probe.
|
|
483
|
-
let path_entry = pi_path_entry()?;
|
|
484
|
-
let version =
|
|
485
|
-
String::from_utf8(command_stdout(&path_entry, &["--version"])?).map_err(|error| {
|
|
486
|
-
ProviderError::Command(format!("Pi version output is not UTF-8: {error}"))
|
|
487
|
-
})?;
|
|
488
|
-
let catalog = command_stdout(&path_entry, &["--list-models"])?;
|
|
489
|
-
let models = parse_pi_list_models_table(&catalog)?;
|
|
490
|
-
let chain = PiExecutableChain {
|
|
491
|
-
path_entry,
|
|
492
|
-
pi_version: version.trim().to_string(),
|
|
493
|
-
catalog_sha256: sha256(&catalog),
|
|
494
|
-
};
|
|
495
|
-
validate_pi_executable_chain(&chain)?;
|
|
496
|
-
Ok((chain, models))
|
|
497
|
-
}
|
|
498
|
-
|
|
499
|
-
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
|
500
|
-
pub(crate) enum PiSessionScope {
|
|
501
|
-
Isolated,
|
|
502
|
-
NativeDefault,
|
|
503
|
-
}
|
|
504
|
-
|
|
505
|
-
/// Zero-argument managed Pi is the interactive leader entry. Only that route
|
|
506
|
-
/// may use Pi's cwd-keyed native session root; every explicit or worker route
|
|
507
|
-
/// remains Team Agent session-isolated.
|
|
508
|
-
pub(crate) fn pi_leader_session_scope(
|
|
509
|
-
provider_args: &[String],
|
|
510
|
-
external_path: bool,
|
|
511
|
-
allow_nested_attach: bool,
|
|
512
|
-
) -> PiSessionScope {
|
|
513
|
-
if provider_args.is_empty() && !external_path && !allow_nested_attach {
|
|
514
|
-
PiSessionScope::NativeDefault
|
|
515
|
-
} else {
|
|
516
|
-
PiSessionScope::Isolated
|
|
517
|
-
}
|
|
518
|
-
}
|
|
519
|
-
|
|
520
|
-
pub(crate) struct PiMaterializeRequest<'a> {
|
|
521
|
-
pub workspace: &'a Path,
|
|
522
|
-
pub team_id: &'a str,
|
|
523
|
-
pub agent_id: &'a str,
|
|
524
|
-
pub model: Option<&'a str>,
|
|
525
|
-
pub effort: Option<ProviderEffort>,
|
|
526
|
-
pub system_prompt: &'a str,
|
|
527
|
-
pub team_mcp_tools: &'a [&'a str],
|
|
528
|
-
pub mcp_config: &'a McpConfig,
|
|
529
|
-
pub session_scope: PiSessionScope,
|
|
530
|
-
}
|
|
531
|
-
|
|
532
|
-
/// ---
|
|
533
|
-
/// purpose: 物化 Pi leader 的 wrapper 和 fresh CommandPlan
|
|
534
|
-
/// returns: fresh Pi CommandPlan 不传 --session-id;an isolated leader carries its session root,
|
|
535
|
-
/// while the interactive leader preserves Pi's native default root
|
|
536
|
-
/// errors: resolver、exact model、wrapper 或 argv 构造失败时返回 ProviderError
|
|
537
|
-
/// ---
|
|
538
|
-
pub(crate) fn materialize_pi_plan(
|
|
539
|
-
request: PiMaterializeRequest<'_>,
|
|
540
|
-
) -> Result<CommandPlan, ProviderError> {
|
|
541
|
-
let (_chain, catalog) = resolve_pi_executable_chain()?;
|
|
542
|
-
let model = request
|
|
543
|
-
.model
|
|
544
|
-
.map(|model| select_exact_pi_model(&catalog, model))
|
|
545
|
-
.transpose()?;
|
|
546
|
-
let paths = pi_seat_paths(request.workspace, request.team_id, request.agent_id);
|
|
547
|
-
let session_dir = match request.session_scope {
|
|
548
|
-
PiSessionScope::Isolated => Some(paths.sessions.as_path()),
|
|
549
|
-
PiSessionScope::NativeDefault => None,
|
|
550
|
-
};
|
|
551
|
-
if let Some(session_dir) = session_dir {
|
|
552
|
-
std::fs::create_dir_all(session_dir)
|
|
553
|
-
.map_err(|error| ProviderError::Io(format!("{}: {error}", session_dir.display())))?;
|
|
554
|
-
}
|
|
555
|
-
let candidate = candidate_from_mcp_config(request.mcp_config)?;
|
|
556
|
-
let wrapper = write_pi_wrapper(PiWrapperRequest {
|
|
557
|
-
destination: &paths.wrapper,
|
|
558
|
-
candidate_executable: &candidate,
|
|
559
|
-
mcp_config: request.mcp_config,
|
|
560
|
-
team_id: request.team_id,
|
|
561
|
-
agent_id: request.agent_id,
|
|
562
|
-
workspace: request.workspace,
|
|
563
|
-
include_tools: request.team_mcp_tools,
|
|
564
|
-
})?;
|
|
565
|
-
let argv = build_pi_command_argv(PiCommandRequest {
|
|
566
|
-
extension: &wrapper,
|
|
567
|
-
model: model.as_deref(),
|
|
568
|
-
effort: request.effort,
|
|
569
|
-
system_prompt: request.system_prompt,
|
|
570
|
-
session_dir,
|
|
571
|
-
agent_id: request.agent_id,
|
|
572
|
-
})?;
|
|
573
|
-
Ok(CommandPlan {
|
|
574
|
-
argv,
|
|
575
|
-
expected_session_id: None,
|
|
576
|
-
provider_projects_root: session_dir.map(Path::to_path_buf),
|
|
577
|
-
managed_mcp_config: false,
|
|
578
|
-
})
|
|
579
|
-
}
|
|
580
|
-
|
|
581
|
-
pub(crate) struct PiCommandRequest<'a> {
|
|
582
|
-
pub extension: &'a Path,
|
|
583
|
-
pub model: Option<&'a str>,
|
|
584
|
-
pub effort: Option<ProviderEffort>,
|
|
585
|
-
pub system_prompt: &'a str,
|
|
586
|
-
/// Team-owned session root for an isolated leader; `None` preserves Pi's native default.
|
|
587
|
-
pub session_dir: Option<&'a Path>,
|
|
588
|
-
pub agent_id: &'a str,
|
|
589
|
-
}
|
|
590
|
-
|
|
591
|
-
/// ---
|
|
592
|
-
/// purpose: 从已验证 semantic request 构造仅追加 Team Agent MCP/提示/session root 的 fresh Pi argv
|
|
593
|
-
/// returns: exact ordered argv,argv[0] 固定为裸 `pi`;Pi 自己分配 session id
|
|
594
|
-
/// errors: 必需字段为空时返回 ProviderError
|
|
595
|
-
/// ---
|
|
596
|
-
pub(crate) fn build_pi_command_argv(
|
|
597
|
-
request: PiCommandRequest<'_>,
|
|
598
|
-
) -> Result<Vec<String>, ProviderError> {
|
|
599
|
-
if request.extension.as_os_str().is_empty()
|
|
600
|
-
|| request
|
|
601
|
-
.session_dir
|
|
602
|
-
.is_some_and(|session_dir| session_dir.as_os_str().is_empty())
|
|
603
|
-
|| request.model.is_some_and(|model| model.trim().is_empty())
|
|
604
|
-
|| request.system_prompt.trim().is_empty()
|
|
605
|
-
|| request.agent_id.trim().is_empty()
|
|
606
|
-
{
|
|
607
|
-
return Err(ProviderError::Command(
|
|
608
|
-
"Pi command requires extension, prompt, and agent id".to_string(),
|
|
609
|
-
));
|
|
610
|
-
}
|
|
611
|
-
// The command stays PATH-resolved at spawn time, so a user wrapper runs.
|
|
612
|
-
let mut argv = vec![
|
|
613
|
-
"pi".to_string(),
|
|
614
|
-
"-e".to_string(),
|
|
615
|
-
request.extension.to_string_lossy().into_owned(),
|
|
616
|
-
];
|
|
617
|
-
append_opt_pair(&mut argv, "--model", request.model);
|
|
618
|
-
if let Some(effort) = request.effort {
|
|
619
|
-
argv.push("--thinking".to_string());
|
|
620
|
-
argv.push(effort.as_str().to_string());
|
|
621
|
-
}
|
|
622
|
-
append_pair(&mut argv, "--append-system-prompt", request.system_prompt);
|
|
623
|
-
if let Some(session_dir) = request.session_dir {
|
|
624
|
-
append_pair(&mut argv, "--session-dir", session_dir.to_string_lossy().into_owned());
|
|
625
|
-
}
|
|
626
|
-
// Passing `--session-id` makes Pi warn and then create: Pi names a fresh session.
|
|
627
|
-
append_pair(&mut argv, "--name", request.agent_id);
|
|
628
|
-
Ok(argv)
|
|
629
|
-
}
|