@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,905 +0,0 @@
|
|
|
1
|
-
//! Host-global supplemental text, read only by new Leader launch plans.
|
|
2
|
-
//! Native argv adaptation is pure; no Worker path reads this configuration.
|
|
3
|
-
|
|
4
|
-
use crate::provider::{wire::provider_wire, Provider};
|
|
5
|
-
use serde::Serialize;
|
|
6
|
-
use serde_json::{json, Value};
|
|
7
|
-
use std::fmt;
|
|
8
|
-
use std::fs::{self, File, OpenOptions};
|
|
9
|
-
use std::io::{self, Read, Write};
|
|
10
|
-
use std::path::{Path, PathBuf};
|
|
11
|
-
use std::time::{Duration, Instant};
|
|
12
|
-
|
|
13
|
-
#[derive(Debug, Clone, Serialize)]
|
|
14
|
-
pub struct PromptError {
|
|
15
|
-
pub reason: &'static str,
|
|
16
|
-
pub error: String,
|
|
17
|
-
pub config_path: Option<PathBuf>,
|
|
18
|
-
pub io_path: Option<PathBuf>,
|
|
19
|
-
pub io_kind: Option<String>,
|
|
20
|
-
pub provider: Option<&'static str>,
|
|
21
|
-
pub carrier: Option<&'static str>,
|
|
22
|
-
pub exit_code: Option<i32>,
|
|
23
|
-
pub action: &'static str,
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
impl PromptError {
|
|
27
|
-
pub(crate) fn new(reason: &'static str, error: &str, path: Option<&Path>) -> Self {
|
|
28
|
-
Self {
|
|
29
|
-
reason, error: error.to_string(), config_path: path.map(Path::to_path_buf),
|
|
30
|
-
io_path: None, io_kind: None, provider: None, carrier: None, exit_code: None,
|
|
31
|
-
action: "Inspect the reported path; use team-agent leader-prompt --help to set, append or clear the text",
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
pub(crate) fn io(reason: &'static str, path: &Path, error: io::Error) -> Self {
|
|
35
|
-
let mut result = Self::new(reason, "Leader prompt I/O failed", Some(path));
|
|
36
|
-
result.io_path = Some(path.to_path_buf());
|
|
37
|
-
result.io_kind = Some(format!("{:?}", error.kind()));
|
|
38
|
-
result
|
|
39
|
-
}
|
|
40
|
-
pub(crate) fn at_config(mut self, path: &Path) -> Self {
|
|
41
|
-
if self.io_path.is_none() && self.config_path.as_deref() != Some(path) {
|
|
42
|
-
self.io_path = self.config_path.clone();
|
|
43
|
-
}
|
|
44
|
-
self.config_path = Some(path.to_path_buf());
|
|
45
|
-
self
|
|
46
|
-
}
|
|
47
|
-
pub(crate) fn for_provider(mut self, provider: Provider) -> Self {
|
|
48
|
-
self.provider = Some(provider_wire(provider));
|
|
49
|
-
self.carrier = Some(carrier(provider));
|
|
50
|
-
self
|
|
51
|
-
}
|
|
52
|
-
pub(crate) fn report(&self) -> Value {
|
|
53
|
-
json!({"ok": false, "reason": self.reason, "error": self.error,
|
|
54
|
-
"config_path": self.config_path, "io_path": self.io_path,
|
|
55
|
-
"io_kind": self.io_kind, "provider": self.provider, "carrier": self.carrier,
|
|
56
|
-
"exit_code": self.exit_code, "action": self.action})
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
impl fmt::Display for PromptError {
|
|
60
|
-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
61
|
-
write!(f, "{}: {}; provider={:?}; carrier={:?}; config={:?}; io_path={:?}; io_kind={:?}; exit_code={:?}; action: {}",
|
|
62
|
-
self.reason, self.error, self.provider, self.carrier, self.config_path, self.io_path, self.io_kind, self.exit_code, self.action)
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
impl std::error::Error for PromptError {}
|
|
66
|
-
|
|
67
|
-
#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
|
|
68
|
-
pub struct PromptMetadata {
|
|
69
|
-
pub config_path: PathBuf,
|
|
70
|
-
pub carrier: &'static str,
|
|
71
|
-
pub bytes: usize,
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
pub(crate) struct StoredPrompt {
|
|
75
|
-
pub path: PathBuf,
|
|
76
|
-
pub text: String,
|
|
77
|
-
}
|
|
78
|
-
impl StoredPrompt {
|
|
79
|
-
pub(crate) fn metadata(&self, provider: Provider) -> PromptMetadata {
|
|
80
|
-
PromptMetadata {
|
|
81
|
-
config_path: self.path.clone(),
|
|
82
|
-
bytes: self.text.len(),
|
|
83
|
-
carrier: carrier(provider),
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
fn carrier(provider: Provider) -> &'static str {
|
|
89
|
-
match provider {
|
|
90
|
-
Provider::Pi | Provider::Claude | Provider::ClaudeCode => "--append-system-prompt",
|
|
91
|
-
Provider::Codex => "developer_instructions",
|
|
92
|
-
Provider::Grok => "--rules",
|
|
93
|
-
_ => "unsupported",
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
fn path_from_home(home: Option<std::ffi::OsString>) -> Result<PathBuf, PromptError> {
|
|
98
|
-
home.map(PathBuf::from)
|
|
99
|
-
.filter(|path| path.is_absolute())
|
|
100
|
-
.map(|path| path.join(".team-agent/leader-prompt.txt"))
|
|
101
|
-
.ok_or_else(|| {
|
|
102
|
-
PromptError::new(
|
|
103
|
-
"leader_prompt_home_unavailable",
|
|
104
|
-
"An absolute host HOME is required",
|
|
105
|
-
None,
|
|
106
|
-
)
|
|
107
|
-
})
|
|
108
|
-
}
|
|
109
|
-
pub(crate) fn config_path() -> Result<PathBuf, PromptError> {
|
|
110
|
-
let home = std::env::var_os("HOME");
|
|
111
|
-
#[cfg(windows)]
|
|
112
|
-
let home = home
|
|
113
|
-
.filter(|raw| Path::new(raw).is_absolute())
|
|
114
|
-
.or_else(|| std::env::var_os("USERPROFILE"));
|
|
115
|
-
path_from_home(home)
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
fn regular_target(path: &Path, reason: &'static str) -> Result<bool, PromptError> {
|
|
119
|
-
match fs::symlink_metadata(path) {
|
|
120
|
-
Ok(metadata) if metadata.file_type().is_file() => Ok(true),
|
|
121
|
-
Ok(_) => Err(PromptError::new(
|
|
122
|
-
reason,
|
|
123
|
-
"Expected a regular file, not a symlink or special file",
|
|
124
|
-
Some(path),
|
|
125
|
-
)),
|
|
126
|
-
Err(error) if error.kind() == io::ErrorKind::NotFound => Ok(false),
|
|
127
|
-
Err(error) => Err(PromptError::io(reason, path, error)),
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
fn private_options() -> OpenOptions {
|
|
131
|
-
let mut options = OpenOptions::new();
|
|
132
|
-
#[cfg(unix)]
|
|
133
|
-
{
|
|
134
|
-
use std::os::unix::fs::OpenOptionsExt;
|
|
135
|
-
options
|
|
136
|
-
.mode(0o600)
|
|
137
|
-
.custom_flags(libc::O_NOFOLLOW | libc::O_NONBLOCK);
|
|
138
|
-
}
|
|
139
|
-
options
|
|
140
|
-
}
|
|
141
|
-
pub(crate) fn validate_input(text: &str, path: &Path) -> Result<(), PromptError> {
|
|
142
|
-
if text.is_empty() || text.contains('\0') {
|
|
143
|
-
return Err(PromptError::new(
|
|
144
|
-
"leader_prompt_invalid_input",
|
|
145
|
-
"Text must be nonempty UTF-8 without NUL; use clear to remove it",
|
|
146
|
-
Some(path),
|
|
147
|
-
));
|
|
148
|
-
}
|
|
149
|
-
Ok(())
|
|
150
|
-
}
|
|
151
|
-
pub(crate) fn read(path: &Path) -> Result<Option<String>, PromptError> {
|
|
152
|
-
if !regular_target(path, "leader_prompt_unreadable")? {
|
|
153
|
-
return Ok(None);
|
|
154
|
-
}
|
|
155
|
-
let mut file = match private_options().read(true).open(path) {
|
|
156
|
-
Ok(file) => file,
|
|
157
|
-
Err(error)
|
|
158
|
-
if error.kind() == io::ErrorKind::NotFound
|
|
159
|
-
&& !regular_target(path, "leader_prompt_unreadable")? =>
|
|
160
|
-
{
|
|
161
|
-
return Ok(None)
|
|
162
|
-
}
|
|
163
|
-
Err(error) => return Err(PromptError::io("leader_prompt_unreadable", path, error)),
|
|
164
|
-
};
|
|
165
|
-
if !file
|
|
166
|
-
.metadata()
|
|
167
|
-
.map_err(|error| PromptError::io("leader_prompt_unreadable", path, error))?
|
|
168
|
-
.is_file()
|
|
169
|
-
{
|
|
170
|
-
return Err(PromptError::new(
|
|
171
|
-
"leader_prompt_unreadable",
|
|
172
|
-
"Expected a regular prompt file",
|
|
173
|
-
Some(path),
|
|
174
|
-
));
|
|
175
|
-
}
|
|
176
|
-
let mut text = String::new();
|
|
177
|
-
file.read_to_string(&mut text)
|
|
178
|
-
.map_err(|error| PromptError::io("leader_prompt_unreadable", path, error))?;
|
|
179
|
-
if text.contains('\0') {
|
|
180
|
-
return Err(PromptError::new(
|
|
181
|
-
"leader_prompt_unreadable",
|
|
182
|
-
"Prompt file contains NUL; set or clear it",
|
|
183
|
-
Some(path),
|
|
184
|
-
));
|
|
185
|
-
}
|
|
186
|
-
Ok((!text.is_empty()).then_some(text))
|
|
187
|
-
}
|
|
188
|
-
/// Missing HOME retains historical launch behavior. A determined, bad file does not.
|
|
189
|
-
pub(crate) fn load() -> Result<Option<StoredPrompt>, PromptError> {
|
|
190
|
-
let path = match config_path() {
|
|
191
|
-
Ok(path) => path,
|
|
192
|
-
Err(_) => return Ok(None),
|
|
193
|
-
};
|
|
194
|
-
read(&path).map(|text| text.map(|text| StoredPrompt { path, text }))
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
pub(crate) enum Mutation {
|
|
198
|
-
Set(String),
|
|
199
|
-
Append(String),
|
|
200
|
-
Clear,
|
|
201
|
-
}
|
|
202
|
-
struct Lock(File);
|
|
203
|
-
impl Drop for Lock {
|
|
204
|
-
fn drop(&mut self) {
|
|
205
|
-
let _ = crate::platform::file_lock::unlock(&self.0);
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
fn acquire_lock(path: &Path) -> Result<Lock, PromptError> {
|
|
209
|
-
let parent = path.parent().ok_or_else(|| {
|
|
210
|
-
PromptError::new(
|
|
211
|
-
"leader_prompt_write_failed",
|
|
212
|
-
"Configuration has no parent directory",
|
|
213
|
-
Some(path),
|
|
214
|
-
)
|
|
215
|
-
})?;
|
|
216
|
-
let mut builder = fs::DirBuilder::new();
|
|
217
|
-
#[cfg(unix)]
|
|
218
|
-
{
|
|
219
|
-
use std::os::unix::fs::DirBuilderExt;
|
|
220
|
-
builder.mode(0o700);
|
|
221
|
-
}
|
|
222
|
-
match builder.create(parent) {
|
|
223
|
-
Ok(()) => {}
|
|
224
|
-
Err(error) if error.kind() == io::ErrorKind::AlreadyExists && parent.is_dir() => {}
|
|
225
|
-
Err(error) => {
|
|
226
|
-
return Err(PromptError::io("leader_prompt_write_failed", parent, error).at_config(path))
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
let lock_path = parent.join("leader-prompt.lock");
|
|
230
|
-
regular_target(&lock_path, "leader_prompt_write_failed")
|
|
231
|
-
.map_err(|error| error.at_config(path))?;
|
|
232
|
-
let file = private_options()
|
|
233
|
-
.read(true)
|
|
234
|
-
.write(true)
|
|
235
|
-
.create(true)
|
|
236
|
-
.truncate(false)
|
|
237
|
-
.open(&lock_path)
|
|
238
|
-
.map_err(|error| {
|
|
239
|
-
PromptError::io("leader_prompt_write_failed", &lock_path, error).at_config(path)
|
|
240
|
-
})?;
|
|
241
|
-
if !file
|
|
242
|
-
.metadata()
|
|
243
|
-
.map_err(|error| {
|
|
244
|
-
PromptError::io("leader_prompt_write_failed", &lock_path, error).at_config(path)
|
|
245
|
-
})?
|
|
246
|
-
.is_file()
|
|
247
|
-
{
|
|
248
|
-
return Err(PromptError::new(
|
|
249
|
-
"leader_prompt_write_failed",
|
|
250
|
-
"Expected a regular lock file",
|
|
251
|
-
Some(&lock_path),
|
|
252
|
-
)
|
|
253
|
-
.at_config(path));
|
|
254
|
-
}
|
|
255
|
-
let started = Instant::now();
|
|
256
|
-
loop {
|
|
257
|
-
match crate::platform::file_lock::try_lock_once_nonblocking(&file) {
|
|
258
|
-
Ok(true) => return Ok(Lock(file)),
|
|
259
|
-
Ok(false) if started.elapsed() < Duration::from_secs(5) => {
|
|
260
|
-
std::thread::sleep(Duration::from_millis(25))
|
|
261
|
-
}
|
|
262
|
-
Ok(false) => {
|
|
263
|
-
return Err(PromptError::new(
|
|
264
|
-
"leader_prompt_lock_timeout",
|
|
265
|
-
"Leader prompt write lock timed out",
|
|
266
|
-
Some(path),
|
|
267
|
-
))
|
|
268
|
-
}
|
|
269
|
-
Err(error) => {
|
|
270
|
-
return Err(
|
|
271
|
-
PromptError::io("leader_prompt_write_failed", &lock_path, error)
|
|
272
|
-
.at_config(path),
|
|
273
|
-
)
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
fn write_atomic(path: &Path, text: &str) -> Result<(), PromptError> {
|
|
279
|
-
static COUNTER: std::sync::atomic::AtomicU64 = std::sync::atomic::AtomicU64::new(0);
|
|
280
|
-
let nanos = std::time::SystemTime::now()
|
|
281
|
-
.duration_since(std::time::UNIX_EPOCH)
|
|
282
|
-
.map_or(0, |time| time.as_nanos());
|
|
283
|
-
let id = COUNTER.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
|
|
284
|
-
let temp = path.with_file_name(format!(
|
|
285
|
-
".leader-prompt-{}-{nanos}-{id}.tmp",
|
|
286
|
-
std::process::id()
|
|
287
|
-
));
|
|
288
|
-
let mut file = private_options()
|
|
289
|
-
.write(true)
|
|
290
|
-
.create_new(true)
|
|
291
|
-
.open(&temp)
|
|
292
|
-
.map_err(|error| {
|
|
293
|
-
PromptError::io("leader_prompt_write_failed", &temp, error).at_config(path)
|
|
294
|
-
})?;
|
|
295
|
-
let result = (|| {
|
|
296
|
-
file.write_all(text.as_bytes())
|
|
297
|
-
.and_then(|_| file.flush())
|
|
298
|
-
.and_then(|_| file.sync_all())
|
|
299
|
-
.map_err(|error| {
|
|
300
|
-
PromptError::io("leader_prompt_write_failed", &temp, error).at_config(path)
|
|
301
|
-
})?;
|
|
302
|
-
drop(file);
|
|
303
|
-
// Rename replaces this directory entry; it never follows a target symlink.
|
|
304
|
-
regular_target(path, "leader_prompt_write_failed")?;
|
|
305
|
-
fs::rename(&temp, path)
|
|
306
|
-
.map_err(|error| PromptError::io("leader_prompt_write_failed", path, error))
|
|
307
|
-
})();
|
|
308
|
-
if result.is_err() {
|
|
309
|
-
let _ = fs::remove_file(&temp);
|
|
310
|
-
}
|
|
311
|
-
result
|
|
312
|
-
}
|
|
313
|
-
pub(crate) fn concatenate(old: &str, input: &str) -> String {
|
|
314
|
-
if old.is_empty() {
|
|
315
|
-
input.to_string()
|
|
316
|
-
} else {
|
|
317
|
-
format!("{old}\n\n{input}")
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
pub(crate) fn mutate(path: &Path, mutation: Mutation) -> Result<bool, PromptError> {
|
|
321
|
-
if let Mutation::Set(text) | Mutation::Append(text) = &mutation {
|
|
322
|
-
validate_input(text, path)?;
|
|
323
|
-
}
|
|
324
|
-
let present = regular_target(path, "leader_prompt_write_failed")?;
|
|
325
|
-
if !present && matches!(mutation, Mutation::Clear) {
|
|
326
|
-
return Ok(false);
|
|
327
|
-
}
|
|
328
|
-
// A bad append source does not create lock apparatus; set/clear can repair bytes.
|
|
329
|
-
if matches!(mutation, Mutation::Append(_)) {
|
|
330
|
-
read(path)?;
|
|
331
|
-
}
|
|
332
|
-
let _lock = acquire_lock(path)?;
|
|
333
|
-
regular_target(path, "leader_prompt_write_failed")?;
|
|
334
|
-
match mutation {
|
|
335
|
-
Mutation::Set(text) => write_atomic(path, &text)?,
|
|
336
|
-
Mutation::Append(text) => write_atomic(
|
|
337
|
-
path,
|
|
338
|
-
&concatenate(read(path)?.as_deref().unwrap_or(""), &text),
|
|
339
|
-
)?,
|
|
340
|
-
Mutation::Clear => match fs::remove_file(path) {
|
|
341
|
-
Ok(()) => return Ok(false),
|
|
342
|
-
Err(error) if error.kind() == io::ErrorKind::NotFound => return Ok(false),
|
|
343
|
-
Err(error) => return Err(PromptError::io("leader_prompt_write_failed", path, error)),
|
|
344
|
-
},
|
|
345
|
-
}
|
|
346
|
-
Ok(true)
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
fn conflict(provider: Provider, path: &Path) -> PromptError {
|
|
350
|
-
let mut error = PromptError::new(
|
|
351
|
-
"leader_prompt_conflict",
|
|
352
|
-
"Ambiguous or unsupported native supplemental prompt argument",
|
|
353
|
-
Some(path),
|
|
354
|
-
)
|
|
355
|
-
.for_provider(provider);
|
|
356
|
-
error.action = "Move the supplemental text into team-agent leader-prompt and remove conflicting native arguments";
|
|
357
|
-
error
|
|
358
|
-
}
|
|
359
|
-
/// Returns the value token and whether the flag/value share that token.
|
|
360
|
-
fn inline_slot(
|
|
361
|
-
argv: &[String],
|
|
362
|
-
flag: &str,
|
|
363
|
-
provider: Provider,
|
|
364
|
-
path: &Path,
|
|
365
|
-
) -> Result<Option<(usize, bool)>, PromptError> {
|
|
366
|
-
let end = argv
|
|
367
|
-
.iter()
|
|
368
|
-
.position(|arg| arg == "--")
|
|
369
|
-
.unwrap_or(argv.len());
|
|
370
|
-
let mut slot = None;
|
|
371
|
-
let mut i = 1;
|
|
372
|
-
while i < end {
|
|
373
|
-
let token = &argv[i];
|
|
374
|
-
// Claude's core prompt fields own the following literal token. It is
|
|
375
|
-
// not a sibling flag even when the text begins with our append flag.
|
|
376
|
-
if matches!(provider, Provider::Claude | Provider::ClaudeCode)
|
|
377
|
-
&& matches!(token.as_str(), "--system-prompt" | "--system-prompt-file")
|
|
378
|
-
{
|
|
379
|
-
if i + 1 >= end {
|
|
380
|
-
return Err(conflict(provider, path));
|
|
381
|
-
}
|
|
382
|
-
i += 2;
|
|
383
|
-
continue;
|
|
384
|
-
}
|
|
385
|
-
let candidate = if token == flag {
|
|
386
|
-
if i + 1 >= end || argv[i + 1].starts_with(flag) {
|
|
387
|
-
return Err(conflict(provider, path));
|
|
388
|
-
}
|
|
389
|
-
i += 1;
|
|
390
|
-
Some((i, false))
|
|
391
|
-
} else if token.starts_with(&format!("{flag}=")) {
|
|
392
|
-
Some((i, true))
|
|
393
|
-
} else if token.starts_with(&format!("{flag}-")) {
|
|
394
|
-
return Err(conflict(provider, path));
|
|
395
|
-
} else {
|
|
396
|
-
None
|
|
397
|
-
};
|
|
398
|
-
if let Some(candidate) = candidate {
|
|
399
|
-
if slot.replace(candidate).is_some() {
|
|
400
|
-
return Err(conflict(provider, path));
|
|
401
|
-
}
|
|
402
|
-
}
|
|
403
|
-
i += 1;
|
|
404
|
-
}
|
|
405
|
-
Ok(slot)
|
|
406
|
-
}
|
|
407
|
-
/// Validate routed Pi options before materializing any MCP files. The existing
|
|
408
|
-
/// Leader contract stays first, so arbitrary supplemental text is not a file carrier.
|
|
409
|
-
pub(crate) fn compose_pi_contract(
|
|
410
|
-
contract: &str,
|
|
411
|
-
routed: &[String],
|
|
412
|
-
text: &str,
|
|
413
|
-
path: &Path,
|
|
414
|
-
) -> Result<String, PromptError> {
|
|
415
|
-
let mut preview = routed.to_vec();
|
|
416
|
-
preview.extend(["--append-system-prompt".to_string(), contract.to_string()]);
|
|
417
|
-
let index = preview.len() - 1;
|
|
418
|
-
if inline_slot(&preview, "--append-system-prompt", Provider::Pi, path)? != Some((index, false))
|
|
419
|
-
{
|
|
420
|
-
return Err(conflict(Provider::Pi, path));
|
|
421
|
-
}
|
|
422
|
-
inject(Provider::Pi, &mut preview, text, path)?;
|
|
423
|
-
Ok(preview[index].clone())
|
|
424
|
-
}
|
|
425
|
-
pub(crate) fn inject(
|
|
426
|
-
provider: Provider,
|
|
427
|
-
argv: &mut Vec<String>,
|
|
428
|
-
text: &str,
|
|
429
|
-
path: &Path,
|
|
430
|
-
) -> Result<(), PromptError> {
|
|
431
|
-
validate_input(text, path).map_err(|error| error.for_provider(provider))?;
|
|
432
|
-
if provider == Provider::Codex {
|
|
433
|
-
return inject_codex(argv, text, path);
|
|
434
|
-
}
|
|
435
|
-
let flag = match provider {
|
|
436
|
-
Provider::Pi | Provider::Claude | Provider::ClaudeCode => "--append-system-prompt",
|
|
437
|
-
Provider::Grok => "--rules",
|
|
438
|
-
_ => {
|
|
439
|
-
let mut error = PromptError::new(
|
|
440
|
-
"leader_prompt_unsupported",
|
|
441
|
-
"This Leader provider has no admitted process-local append carrier",
|
|
442
|
-
Some(path),
|
|
443
|
-
)
|
|
444
|
-
.for_provider(provider);
|
|
445
|
-
error.action = "Use pi, claude, codex or grok, or clear leader-prompt";
|
|
446
|
-
return Err(error);
|
|
447
|
-
}
|
|
448
|
-
};
|
|
449
|
-
if let Some((index, joined)) = inline_slot(argv, flag, provider, path)? {
|
|
450
|
-
let old = if joined {
|
|
451
|
-
&argv[index][flag.len() + 1..]
|
|
452
|
-
} else {
|
|
453
|
-
&argv[index]
|
|
454
|
-
};
|
|
455
|
-
let combined = concatenate(old, text);
|
|
456
|
-
argv[index] = if joined {
|
|
457
|
-
format!("{flag}={combined}")
|
|
458
|
-
} else {
|
|
459
|
-
combined
|
|
460
|
-
};
|
|
461
|
-
} else if argv.is_empty() {
|
|
462
|
-
return Err(conflict(provider, path));
|
|
463
|
-
} else {
|
|
464
|
-
argv.splice(1..1, [flag.to_string(), text.to_string()]);
|
|
465
|
-
}
|
|
466
|
-
Ok(())
|
|
467
|
-
}
|
|
468
|
-
fn inject_codex(argv: &mut Vec<String>, text: &str, path: &Path) -> Result<(), PromptError> {
|
|
469
|
-
let provider = Provider::Codex;
|
|
470
|
-
let end = argv
|
|
471
|
-
.iter()
|
|
472
|
-
.position(|arg| arg == "--")
|
|
473
|
-
.unwrap_or(argv.len());
|
|
474
|
-
let mut slot = None;
|
|
475
|
-
let mut i = 1;
|
|
476
|
-
while i < end {
|
|
477
|
-
let token = &argv[i];
|
|
478
|
-
let (index, value, joined) = if matches!(token.as_str(), "-c" | "--config") {
|
|
479
|
-
if i + 1 >= end {
|
|
480
|
-
return Err(conflict(provider, path));
|
|
481
|
-
}
|
|
482
|
-
i += 1;
|
|
483
|
-
(i, argv[i].as_str(), false)
|
|
484
|
-
} else if let Some(value) = token.strip_prefix("--config=") {
|
|
485
|
-
(i, value, true)
|
|
486
|
-
} else if token.strip_prefix("-c").is_some_and(|value| {
|
|
487
|
-
let key = value
|
|
488
|
-
.trim_start_matches('=')
|
|
489
|
-
.split('=')
|
|
490
|
-
.next()
|
|
491
|
-
.unwrap_or("")
|
|
492
|
-
.trim();
|
|
493
|
-
matches!(
|
|
494
|
-
key,
|
|
495
|
-
"developer_instructions"
|
|
496
|
-
| "\"developer_instructions\""
|
|
497
|
-
| "'developer_instructions'"
|
|
498
|
-
)
|
|
499
|
-
}) {
|
|
500
|
-
return Err(conflict(provider, path));
|
|
501
|
-
} else {
|
|
502
|
-
i += 1;
|
|
503
|
-
continue;
|
|
504
|
-
};
|
|
505
|
-
let (key, rhs) = value.split_once('=').unwrap_or((value, ""));
|
|
506
|
-
if matches!(
|
|
507
|
-
key.trim(),
|
|
508
|
-
"\"developer_instructions\"" | "'developer_instructions'"
|
|
509
|
-
) {
|
|
510
|
-
return Err(conflict(provider, path));
|
|
511
|
-
}
|
|
512
|
-
if key.trim() == "developer_instructions" {
|
|
513
|
-
let old: String = serde_json::from_str(rhs).map_err(|_| conflict(provider, path))?;
|
|
514
|
-
if old.contains('\0') || slot.replace((index, joined, old)).is_some() {
|
|
515
|
-
return Err(conflict(provider, path));
|
|
516
|
-
}
|
|
517
|
-
}
|
|
518
|
-
i += 1;
|
|
519
|
-
}
|
|
520
|
-
let (old, index) = match slot {
|
|
521
|
-
Some((index, joined, old)) => (old, Some((index, joined))),
|
|
522
|
-
None => (String::new(), None),
|
|
523
|
-
};
|
|
524
|
-
let combined = concatenate(&old, text);
|
|
525
|
-
let encoded = serde_json::to_string(&combined).map_err(|_| conflict(provider, path))?;
|
|
526
|
-
let value = format!("developer_instructions={encoded}");
|
|
527
|
-
if let Some((index, joined)) = index {
|
|
528
|
-
argv[index] = if joined {
|
|
529
|
-
format!("--config={value}")
|
|
530
|
-
} else {
|
|
531
|
-
value
|
|
532
|
-
};
|
|
533
|
-
} else if argv.is_empty() {
|
|
534
|
-
return Err(conflict(provider, path));
|
|
535
|
-
} else {
|
|
536
|
-
argv.splice(1..1, ["-c".to_string(), value]);
|
|
537
|
-
}
|
|
538
|
-
Ok(())
|
|
539
|
-
}
|
|
540
|
-
|
|
541
|
-
#[cfg(test)]
|
|
542
|
-
#[allow(clippy::unwrap_used, clippy::expect_used, clippy::panic)]
|
|
543
|
-
mod tests {
|
|
544
|
-
use super::*;
|
|
545
|
-
use std::sync::atomic::{AtomicU64, Ordering};
|
|
546
|
-
static ID: AtomicU64 = AtomicU64::new(0);
|
|
547
|
-
struct Fixture(PathBuf);
|
|
548
|
-
impl Fixture {
|
|
549
|
-
fn new() -> Self {
|
|
550
|
-
let path = std::env::temp_dir().join(format!(
|
|
551
|
-
"ta-leader-prompt-{}-{}",
|
|
552
|
-
std::process::id(),
|
|
553
|
-
ID.fetch_add(1, Ordering::Relaxed)
|
|
554
|
-
));
|
|
555
|
-
fs::create_dir(&path).unwrap();
|
|
556
|
-
Self(path)
|
|
557
|
-
}
|
|
558
|
-
fn path(&self) -> PathBuf {
|
|
559
|
-
self.0.join(".team-agent/leader-prompt.txt")
|
|
560
|
-
}
|
|
561
|
-
}
|
|
562
|
-
impl Drop for Fixture {
|
|
563
|
-
fn drop(&mut self) {
|
|
564
|
-
let _ = fs::remove_dir_all(&self.0);
|
|
565
|
-
}
|
|
566
|
-
}
|
|
567
|
-
fn args(tokens: &[&str]) -> Vec<String> {
|
|
568
|
-
tokens.iter().map(|text| text.to_string()).collect()
|
|
569
|
-
}
|
|
570
|
-
|
|
571
|
-
#[test]
|
|
572
|
-
fn leader_prompt_storage_bytes_clear_and_repair() {
|
|
573
|
-
let f = Fixture::new();
|
|
574
|
-
let path = f.path();
|
|
575
|
-
assert!(!mutate(&path, Mutation::Clear).unwrap());
|
|
576
|
-
assert!(!path.parent().unwrap().exists());
|
|
577
|
-
let text = " rulesš\r\nquote\"\\\t--help\n";
|
|
578
|
-
mutate(&path, Mutation::Set(text.into())).unwrap();
|
|
579
|
-
assert_eq!(read(&path).unwrap().as_deref(), Some(text));
|
|
580
|
-
mutate(&path, Mutation::Append(" \n ".into())).unwrap();
|
|
581
|
-
assert_eq!(
|
|
582
|
-
fs::read(&path).unwrap(),
|
|
583
|
-
format!("{text}\n\n \n ").as_bytes()
|
|
584
|
-
);
|
|
585
|
-
let old = fs::read(&path).unwrap();
|
|
586
|
-
for input in ["", "bad\0text"] {
|
|
587
|
-
assert!(mutate(&path, Mutation::Set(input.into())).is_err());
|
|
588
|
-
assert_eq!(fs::read(&path).unwrap(), old);
|
|
589
|
-
}
|
|
590
|
-
fs::write(&path, [0xff]).unwrap();
|
|
591
|
-
assert_eq!(read(&path).unwrap_err().reason, "leader_prompt_unreadable");
|
|
592
|
-
assert!(mutate(&path, Mutation::Append("new".into())).is_err());
|
|
593
|
-
assert_eq!(fs::read(&path).unwrap(), [0xff]);
|
|
594
|
-
mutate(&path, Mutation::Set("repaired".into())).unwrap();
|
|
595
|
-
fs::write(&path, b"nul\0").unwrap();
|
|
596
|
-
assert!(read(&path).is_err());
|
|
597
|
-
mutate(&path, Mutation::Clear).unwrap();
|
|
598
|
-
fs::write(&path, []).unwrap();
|
|
599
|
-
assert!(read(&path).unwrap().is_none());
|
|
600
|
-
}
|
|
601
|
-
#[test]
|
|
602
|
-
fn leader_prompt_concurrent_appends_do_not_lose_updates() {
|
|
603
|
-
let f = Fixture::new();
|
|
604
|
-
let path = f.path();
|
|
605
|
-
let threads: Vec<_> = (0..12)
|
|
606
|
-
.map(|id| {
|
|
607
|
-
let path = path.clone();
|
|
608
|
-
std::thread::spawn(move || {
|
|
609
|
-
mutate(&path, Mutation::Append(format!("entry-{id}"))).unwrap()
|
|
610
|
-
})
|
|
611
|
-
})
|
|
612
|
-
.collect();
|
|
613
|
-
for thread in threads {
|
|
614
|
-
thread.join().unwrap();
|
|
615
|
-
}
|
|
616
|
-
let text = read(&path).unwrap().unwrap();
|
|
617
|
-
let entries: std::collections::BTreeSet<String> =
|
|
618
|
-
text.split("\n\n").map(str::to_string).collect();
|
|
619
|
-
assert_eq!(entries, (0..12).map(|id| format!("entry-{id}")).collect());
|
|
620
|
-
assert_eq!(text.split("\n\n").count(), 12);
|
|
621
|
-
}
|
|
622
|
-
#[test]
|
|
623
|
-
fn leader_prompt_temp_io_error_identifies_the_actual_operation_path() {
|
|
624
|
-
let f = Fixture::new();
|
|
625
|
-
let path = f.0.join("missing-parent/leader-prompt.txt");
|
|
626
|
-
let error = write_atomic(&path, "new").unwrap_err();
|
|
627
|
-
assert_eq!(error.config_path.as_deref(), Some(path.as_path()));
|
|
628
|
-
assert_eq!(error.io_kind.as_deref(), Some("NotFound"));
|
|
629
|
-
let actual = error.io_path.unwrap();
|
|
630
|
-
assert_eq!(actual.parent(), path.parent());
|
|
631
|
-
assert!(actual
|
|
632
|
-
.file_name()
|
|
633
|
-
.unwrap()
|
|
634
|
-
.to_string_lossy()
|
|
635
|
-
.starts_with(".leader-prompt-"));
|
|
636
|
-
assert_ne!(actual, path);
|
|
637
|
-
}
|
|
638
|
-
#[test]
|
|
639
|
-
fn leader_prompt_bounded_lock_timeout_preserves_body_and_foreign_temp() {
|
|
640
|
-
let f = Fixture::new();
|
|
641
|
-
let path = f.path();
|
|
642
|
-
mutate(&path, Mutation::Set("old".into())).unwrap();
|
|
643
|
-
let foreign = path.parent().unwrap().join(".leader-prompt-foreign.tmp");
|
|
644
|
-
fs::write(&foreign, "foreign").unwrap();
|
|
645
|
-
let _held = acquire_lock(&path).unwrap();
|
|
646
|
-
let started = Instant::now();
|
|
647
|
-
assert_eq!(
|
|
648
|
-
mutate(&path, Mutation::Append("new".into()))
|
|
649
|
-
.unwrap_err()
|
|
650
|
-
.reason,
|
|
651
|
-
"leader_prompt_lock_timeout"
|
|
652
|
-
);
|
|
653
|
-
assert!(started.elapsed() >= Duration::from_secs(5));
|
|
654
|
-
assert!(started.elapsed() < Duration::from_secs(10));
|
|
655
|
-
assert_eq!(fs::read_to_string(path).unwrap(), "old");
|
|
656
|
-
assert_eq!(fs::read_to_string(foreign).unwrap(), "foreign");
|
|
657
|
-
}
|
|
658
|
-
#[cfg(unix)]
|
|
659
|
-
#[test]
|
|
660
|
-
fn leader_prompt_private_modes_and_symlink_refusal() {
|
|
661
|
-
use std::os::unix::fs::{symlink, PermissionsExt};
|
|
662
|
-
let f = Fixture::new();
|
|
663
|
-
let path = f.path();
|
|
664
|
-
mutate(&path, Mutation::Set("private".into())).unwrap();
|
|
665
|
-
assert_eq!(
|
|
666
|
-
fs::metadata(&path).unwrap().permissions().mode() & 0o777,
|
|
667
|
-
0o600
|
|
668
|
-
);
|
|
669
|
-
assert_eq!(
|
|
670
|
-
fs::metadata(path.parent().unwrap())
|
|
671
|
-
.unwrap()
|
|
672
|
-
.permissions()
|
|
673
|
-
.mode()
|
|
674
|
-
& 0o777,
|
|
675
|
-
0o700
|
|
676
|
-
);
|
|
677
|
-
let target = f.0.join("foreign");
|
|
678
|
-
fs::write(&target, "unchanged").unwrap();
|
|
679
|
-
fs::remove_file(&path).unwrap();
|
|
680
|
-
symlink(&target, &path).unwrap();
|
|
681
|
-
assert!(read(&path).is_err());
|
|
682
|
-
for mutation in [
|
|
683
|
-
Mutation::Set("new".into()),
|
|
684
|
-
Mutation::Append("new".into()),
|
|
685
|
-
Mutation::Clear,
|
|
686
|
-
] {
|
|
687
|
-
assert!(mutate(&path, mutation).is_err());
|
|
688
|
-
assert_eq!(fs::read_to_string(&target).unwrap(), "unchanged");
|
|
689
|
-
}
|
|
690
|
-
fs::remove_file(&path).unwrap();
|
|
691
|
-
let lock = path.parent().unwrap().join("leader-prompt.lock");
|
|
692
|
-
fs::remove_file(&lock).unwrap();
|
|
693
|
-
symlink(&target, &lock).unwrap();
|
|
694
|
-
let error = mutate(&path, Mutation::Set("new".into())).unwrap_err();
|
|
695
|
-
assert_eq!(error.config_path.as_deref(), Some(path.as_path()));
|
|
696
|
-
assert_eq!(error.io_path.as_deref(), Some(lock.as_path()));
|
|
697
|
-
assert_eq!(fs::read_to_string(&target).unwrap(), "unchanged");
|
|
698
|
-
fs::remove_file(&lock).unwrap();
|
|
699
|
-
fs::set_permissions(path.parent().unwrap(), fs::Permissions::from_mode(0o755)).unwrap();
|
|
700
|
-
mutate(&path, Mutation::Set("new".into())).unwrap();
|
|
701
|
-
assert_eq!(
|
|
702
|
-
fs::metadata(path.parent().unwrap())
|
|
703
|
-
.unwrap()
|
|
704
|
-
.permissions()
|
|
705
|
-
.mode()
|
|
706
|
-
& 0o777,
|
|
707
|
-
0o755
|
|
708
|
-
);
|
|
709
|
-
}
|
|
710
|
-
#[test]
|
|
711
|
-
fn leader_prompt_home_requires_absolute_path() {
|
|
712
|
-
for home in [None, Some("".into()), Some("relative".into())] {
|
|
713
|
-
assert!(path_from_home(home).is_err());
|
|
714
|
-
}
|
|
715
|
-
assert!(path_from_home(Some(std::env::temp_dir().into_os_string()))
|
|
716
|
-
.unwrap()
|
|
717
|
-
.is_absolute());
|
|
718
|
-
}
|
|
719
|
-
#[test]
|
|
720
|
-
fn leader_prompt_inline_append_preserves_tokens_and_delimiter_data() {
|
|
721
|
-
let path = Path::new("/home/example/.team-agent/leader-prompt.txt");
|
|
722
|
-
for (provider, flag) in [
|
|
723
|
-
(Provider::Pi, "--append-system-prompt"),
|
|
724
|
-
(Provider::Claude, "--append-system-prompt"),
|
|
725
|
-
(Provider::Grok, "--rules"),
|
|
726
|
-
] {
|
|
727
|
-
let mut argv = args(&[
|
|
728
|
-
"native", "--model", "model", flag, "old", "--", flag, "literal",
|
|
729
|
-
]);
|
|
730
|
-
inject(provider, &mut argv, "newš\n", path).unwrap();
|
|
731
|
-
assert_eq!(
|
|
732
|
-
argv,
|
|
733
|
-
args(&[
|
|
734
|
-
"native",
|
|
735
|
-
"--model",
|
|
736
|
-
"model",
|
|
737
|
-
flag,
|
|
738
|
-
"old\n\nnewš\n",
|
|
739
|
-
"--",
|
|
740
|
-
flag,
|
|
741
|
-
"literal"
|
|
742
|
-
])
|
|
743
|
-
);
|
|
744
|
-
let mut joined = args(&["native", &format!("{flag}=old"), "resume"]);
|
|
745
|
-
inject(provider, &mut joined, "new", path).unwrap();
|
|
746
|
-
assert_eq!(
|
|
747
|
-
joined,
|
|
748
|
-
args(&["native", &format!("{flag}=old\n\nnew"), "resume"])
|
|
749
|
-
);
|
|
750
|
-
for tail in [
|
|
751
|
-
args(&[flag]),
|
|
752
|
-
args(&[flag, flag, "two"]),
|
|
753
|
-
args(&[flag, "one", flag, "two"]),
|
|
754
|
-
args(&[&format!("{flag}-file"), "file"]),
|
|
755
|
-
] {
|
|
756
|
-
let mut bad = args(&["native"]);
|
|
757
|
-
bad.extend(tail);
|
|
758
|
-
let before = bad.clone();
|
|
759
|
-
assert_eq!(
|
|
760
|
-
inject(provider, &mut bad, "new", path).unwrap_err().reason,
|
|
761
|
-
"leader_prompt_conflict"
|
|
762
|
-
);
|
|
763
|
-
assert_eq!(bad, before);
|
|
764
|
-
}
|
|
765
|
-
}
|
|
766
|
-
}
|
|
767
|
-
#[test]
|
|
768
|
-
fn leader_prompt_pi_preserves_contract_and_refuses_route_override() {
|
|
769
|
-
let path = Path::new("/home/example/.team-agent/leader-prompt.txt");
|
|
770
|
-
let contract = "Team Agent Leader contract\nKeep team-local tools.";
|
|
771
|
-
assert_eq!(
|
|
772
|
-
compose_pi_contract(
|
|
773
|
-
contract,
|
|
774
|
-
&args(&["pi", "--verbose"]),
|
|
775
|
-
"/looks/like/file",
|
|
776
|
-
path
|
|
777
|
-
)
|
|
778
|
-
.unwrap(),
|
|
779
|
-
format!("{contract}\n\n/looks/like/file")
|
|
780
|
-
);
|
|
781
|
-
for routed in [
|
|
782
|
-
args(&["pi", "--append-system-prompt", "other"]),
|
|
783
|
-
args(&["pi", "--append-system-prompt-file", "file"]),
|
|
784
|
-
args(&["pi", "--", "literal"]),
|
|
785
|
-
] {
|
|
786
|
-
assert_eq!(
|
|
787
|
-
compose_pi_contract(contract, &routed, "supplement", path)
|
|
788
|
-
.unwrap_err()
|
|
789
|
-
.reason,
|
|
790
|
-
"leader_prompt_conflict"
|
|
791
|
-
);
|
|
792
|
-
}
|
|
793
|
-
}
|
|
794
|
-
#[test]
|
|
795
|
-
fn leader_prompt_claude_core_prompt_values_are_not_supplemental_sibling_flags() {
|
|
796
|
-
let path = Path::new("/home/example/.team-agent/leader-prompt.txt");
|
|
797
|
-
for provider in [Provider::Claude, Provider::ClaudeCode] {
|
|
798
|
-
for flag in ["--system-prompt", "--system-prompt-file"] {
|
|
799
|
-
for literal in [
|
|
800
|
-
"--append-system-prompt",
|
|
801
|
-
"--append-system-prompt=literal",
|
|
802
|
-
"--append-system-prompt-file",
|
|
803
|
-
] {
|
|
804
|
-
let original = args(&["claude", flag, literal, "Initial task"]);
|
|
805
|
-
let mut argv = original.clone();
|
|
806
|
-
inject(provider, &mut argv, "GLOBAL_309", path).unwrap();
|
|
807
|
-
assert_eq!(
|
|
808
|
-
&argv[..3],
|
|
809
|
-
args(&["claude", "--append-system-prompt", "GLOBAL_309"])
|
|
810
|
-
);
|
|
811
|
-
assert_eq!(&argv[3..], &original[1..]);
|
|
812
|
-
}
|
|
813
|
-
}
|
|
814
|
-
}
|
|
815
|
-
}
|
|
816
|
-
#[test]
|
|
817
|
-
fn leader_prompt_codex_owns_one_slot_and_preserves_resume() {
|
|
818
|
-
let path = Path::new("/home/example/.team-agent/leader-prompt.txt");
|
|
819
|
-
let text = "quote\"\\\r\n\tš";
|
|
820
|
-
for (flag, joined) in [("-c", false), ("--config", false), ("--config", true)] {
|
|
821
|
-
let value = "developer_instructions=\"old\"";
|
|
822
|
-
let mut argv = if joined {
|
|
823
|
-
args(&[
|
|
824
|
-
"codex",
|
|
825
|
-
&format!("{flag}={value}"),
|
|
826
|
-
"resume",
|
|
827
|
-
"--last",
|
|
828
|
-
"--",
|
|
829
|
-
"literal",
|
|
830
|
-
])
|
|
831
|
-
} else {
|
|
832
|
-
args(&["codex", flag, value, "resume", "--last", "--", "literal"])
|
|
833
|
-
};
|
|
834
|
-
let tail = argv[if joined { 2 } else { 3 }..].to_vec();
|
|
835
|
-
inject(Provider::Codex, &mut argv, text, path).unwrap();
|
|
836
|
-
let encoded = argv[if joined { 1 } else { 2 }]
|
|
837
|
-
.split_once("developer_instructions=")
|
|
838
|
-
.unwrap()
|
|
839
|
-
.1;
|
|
840
|
-
assert_eq!(
|
|
841
|
-
serde_json::from_str::<String>(encoded).unwrap(),
|
|
842
|
-
format!("old\n\n{text}")
|
|
843
|
-
);
|
|
844
|
-
assert_eq!(&argv[if joined { 2 } else { 3 }..], tail);
|
|
845
|
-
}
|
|
846
|
-
let mut fresh = args(&[
|
|
847
|
-
"codex",
|
|
848
|
-
"resume",
|
|
849
|
-
"--last",
|
|
850
|
-
"--",
|
|
851
|
-
"developer_instructions='literal'",
|
|
852
|
-
]);
|
|
853
|
-
inject(Provider::Codex, &mut fresh, text, path).unwrap();
|
|
854
|
-
assert_eq!(
|
|
855
|
-
&fresh[3..],
|
|
856
|
-
args(&["resume", "--last", "--", "developer_instructions='literal'"])
|
|
857
|
-
);
|
|
858
|
-
for tokens in [
|
|
859
|
-
args(&["codex", "-c", "developer_instructions='raw'"]),
|
|
860
|
-
args(&[
|
|
861
|
-
"codex",
|
|
862
|
-
"-c",
|
|
863
|
-
"developer_instructions=\"one\"",
|
|
864
|
-
"--config=developer_instructions=\"two\"",
|
|
865
|
-
]),
|
|
866
|
-
args(&["codex", "-cdeveloper_instructions=\"attached\""]),
|
|
867
|
-
args(&["codex", "-c=developer_instructions=\"attached\""]),
|
|
868
|
-
args(&[
|
|
869
|
-
"codex",
|
|
870
|
-
"--config",
|
|
871
|
-
"\"developer_instructions\"=\"quoted key\"",
|
|
872
|
-
]),
|
|
873
|
-
args(&[
|
|
874
|
-
"codex",
|
|
875
|
-
"--config",
|
|
876
|
-
"'developer_instructions'=\"quoted key\"",
|
|
877
|
-
]),
|
|
878
|
-
] {
|
|
879
|
-
let mut argv = tokens.clone();
|
|
880
|
-
assert_eq!(
|
|
881
|
-
inject(Provider::Codex, &mut argv, text, path)
|
|
882
|
-
.unwrap_err()
|
|
883
|
-
.reason,
|
|
884
|
-
"leader_prompt_conflict"
|
|
885
|
-
);
|
|
886
|
-
assert_eq!(argv, tokens);
|
|
887
|
-
}
|
|
888
|
-
}
|
|
889
|
-
#[test]
|
|
890
|
-
fn leader_prompt_unadmitted_providers_fail_without_argv_mutation() {
|
|
891
|
-
let path = Path::new("/home/example/.team-agent/leader-prompt.txt");
|
|
892
|
-
for provider in [
|
|
893
|
-
Provider::Copilot,
|
|
894
|
-
Provider::GeminiCli,
|
|
895
|
-
Provider::Fake,
|
|
896
|
-
] {
|
|
897
|
-
let mut argv = args(&["native", "--model", "model"]);
|
|
898
|
-
let before = argv.clone();
|
|
899
|
-
let error = inject(provider, &mut argv, "do not echo this sentinel", path).unwrap_err();
|
|
900
|
-
assert_eq!(error.reason, "leader_prompt_unsupported");
|
|
901
|
-
assert!(!error.to_string().contains("sentinel"));
|
|
902
|
-
assert_eq!(argv, before);
|
|
903
|
-
}
|
|
904
|
-
}
|
|
905
|
-
}
|