@team-agent/installer 0.5.128 → 0.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (436) hide show
  1. package/README.md +4 -4
  2. package/README.zh.md +1 -1
  3. package/package.json +4 -8
  4. package/skills/team-agent/SKILL.md +37 -20
  5. package/skills/team-agent/command-coverage.json +169 -183
  6. package/skills/team-agent/docs/reference/team-agent-operator.md +64 -30
  7. package/skills/team-agent/references/recovery-runbook.md +1 -1
  8. package/skills/team-agent/references/team-agent-operator.md +64 -30
  9. package/templates/team_state.md +1 -1
  10. package/Cargo.lock +0 -1063
  11. package/Cargo.toml +0 -36
  12. package/crates/team-agent/Cargo.toml +0 -69
  13. package/crates/team-agent/src/app_server_test_support.rs +0 -258
  14. package/crates/team-agent/src/cli/adapters.rs +0 -1288
  15. package/crates/team-agent/src/cli/arguments.rs +0 -405
  16. package/crates/team-agent/src/cli/attach_app_server_leader.rs +0 -98
  17. package/crates/team-agent/src/cli/diagnose.rs +0 -1721
  18. package/crates/team-agent/src/cli/emit.rs +0 -2930
  19. package/crates/team-agent/src/cli/grok_slot.rs +0 -384
  20. package/crates/team-agent/src/cli/helpers.rs +0 -91
  21. package/crates/team-agent/src/cli/intent/runtime.rs +0 -1216
  22. package/crates/team-agent/src/cli/intent/runtime_tests.rs +0 -912
  23. package/crates/team-agent/src/cli/intent/tests.rs +0 -689
  24. package/crates/team-agent/src/cli/intent.rs +0 -664
  25. package/crates/team-agent/src/cli/leader.rs +0 -300
  26. package/crates/team-agent/src/cli/leader_prompt.rs +0 -261
  27. package/crates/team-agent/src/cli/leaders.rs +0 -418
  28. package/crates/team-agent/src/cli/mod.rs +0 -6545
  29. package/crates/team-agent/src/cli/models.rs +0 -1206
  30. package/crates/team-agent/src/cli/named_address.rs +0 -1651
  31. package/crates/team-agent/src/cli/profile.rs +0 -342
  32. package/crates/team-agent/src/cli/route.rs +0 -212
  33. package/crates/team-agent/src/cli/schedule.rs +0 -175
  34. package/crates/team-agent/src/cli/send/coordinator.rs +0 -164
  35. package/crates/team-agent/src/cli/send/mailbox.rs +0 -145
  36. package/crates/team-agent/src/cli/send/persist.rs +0 -156
  37. package/crates/team-agent/src/cli/send/presentation.rs +0 -370
  38. package/crates/team-agent/src/cli/send/resolve.rs +0 -573
  39. package/crates/team-agent/src/cli/send.rs +0 -199
  40. package/crates/team-agent/src/cli/shutdown_socket.rs +0 -288
  41. package/crates/team-agent/src/cli/spec.rs +0 -165
  42. package/crates/team-agent/src/cli/status.rs +0 -280
  43. package/crates/team-agent/src/cli/status_port/agents.rs +0 -358
  44. package/crates/team-agent/src/cli/status_port/approvals.rs +0 -79
  45. package/crates/team-agent/src/cli/status_port/brief.rs +0 -1981
  46. package/crates/team-agent/src/cli/status_port/compact.rs +0 -240
  47. package/crates/team-agent/src/cli/status_port/format.rs +0 -146
  48. package/crates/team-agent/src/cli/status_port/inbox.rs +0 -62
  49. package/crates/team-agent/src/cli/status_port/runtime.rs +0 -197
  50. package/crates/team-agent/src/cli/status_port/snapshot.rs +0 -208
  51. package/crates/team-agent/src/cli/status_port/store.rs +0 -416
  52. package/crates/team-agent/src/cli/status_port/tests.rs +0 -90
  53. package/crates/team-agent/src/cli/status_port.rs +0 -92
  54. package/crates/team-agent/src/cli/tests/base.rs +0 -885
  55. package/crates/team-agent/src/cli/tests/divergence.rs +0 -518
  56. package/crates/team-agent/src/cli/tests/lane_c.rs +0 -453
  57. package/crates/team-agent/src/cli/tests/leader_watch.rs +0 -322
  58. package/crates/team-agent/src/cli/tests/main_preserved.rs +0 -430
  59. package/crates/team-agent/src/cli/tests/missing_subcommands.rs +0 -336
  60. package/crates/team-agent/src/cli/tests/mod.rs +0 -137
  61. package/crates/team-agent/src/cli/tests/named_address.rs +0 -761
  62. package/crates/team-agent/src/cli/tests/parser_safety.rs +0 -383
  63. package/crates/team-agent/src/cli/tests/run_delegation.rs +0 -484
  64. package/crates/team-agent/src/cli/tests/shutdown_kill_plan.rs +0 -2179
  65. package/crates/team-agent/src/cli/tests/status_brief.rs +0 -1514
  66. package/crates/team-agent/src/cli/tests/status_send.rs +0 -888
  67. package/crates/team-agent/src/cli/tests/verb_install_skill.rs +0 -93
  68. package/crates/team-agent/src/cli/tests/verb_profile.rs +0 -392
  69. package/crates/team-agent/src/cli/triage.rs +0 -234
  70. package/crates/team-agent/src/cli/types.rs +0 -591
  71. package/crates/team-agent/src/codex_app_server.rs +0 -546
  72. package/crates/team-agent/src/communication_mode/mod.rs +0 -56
  73. package/crates/team-agent/src/compiler/tests.rs +0 -827
  74. package/crates/team-agent/src/compiler.rs +0 -890
  75. package/crates/team-agent/src/conpty/backend.rs +0 -829
  76. package/crates/team-agent/src/conpty/mod.rs +0 -33
  77. package/crates/team-agent/src/contract_runtime/backend.rs +0 -1744
  78. package/crates/team-agent/src/contract_runtime/commands.rs +0 -671
  79. package/crates/team-agent/src/contract_runtime/config.rs +0 -364
  80. package/crates/team-agent/src/contract_runtime/config_tests.rs +0 -76
  81. package/crates/team-agent/src/contract_runtime/discovery.rs +0 -449
  82. package/crates/team-agent/src/contract_runtime/fork.rs +0 -361
  83. package/crates/team-agent/src/contract_runtime/forward.rs +0 -288
  84. package/crates/team-agent/src/contract_runtime/framework.rs +0 -367
  85. package/crates/team-agent/src/contract_runtime/mcp.rs +0 -394
  86. package/crates/team-agent/src/contract_runtime/mod.rs +0 -17
  87. package/crates/team-agent/src/contract_runtime/prompt.rs +0 -216
  88. package/crates/team-agent/src/contract_runtime/pump.rs +0 -271
  89. package/crates/team-agent/src/contract_runtime/registry.rs +0 -553
  90. package/crates/team-agent/src/contract_runtime/workspace.rs +0 -228
  91. package/crates/team-agent/src/coordinator/backoff.rs +0 -741
  92. package/crates/team-agent/src/coordinator/conpty_shim.rs +0 -805
  93. package/crates/team-agent/src/coordinator/health.rs +0 -1185
  94. package/crates/team-agent/src/coordinator/mod.rs +0 -119
  95. package/crates/team-agent/src/coordinator/orphan.rs +0 -110
  96. package/crates/team-agent/src/coordinator/runtime_detectors.rs +0 -798
  97. package/crates/team-agent/src/coordinator/runtime_observation.rs +0 -84
  98. package/crates/team-agent/src/coordinator/steps/abnormal.rs +0 -2309
  99. package/crates/team-agent/src/coordinator/steps/delivery.rs +0 -15
  100. package/crates/team-agent/src/coordinator/steps/health_sync.rs +0 -15
  101. package/crates/team-agent/src/coordinator/steps/mod.rs +0 -126
  102. package/crates/team-agent/src/coordinator/steps/persist.rs +0 -15
  103. package/crates/team-agent/src/coordinator/steps/runtime_prompts.rs +0 -15
  104. package/crates/team-agent/src/coordinator/steps/session_gate.rs +0 -16
  105. package/crates/team-agent/src/coordinator/tests/a0_lostupdate.rs +0 -158
  106. package/crates/team-agent/src/coordinator/tests/abnormal.rs +0 -312
  107. package/crates/team-agent/src/coordinator/tests/api_error_recovery.rs +0 -300
  108. package/crates/team-agent/src/coordinator/tests/basics.rs +0 -211
  109. package/crates/team-agent/src/coordinator/tests/daemon.rs +0 -514
  110. package/crates/team-agent/src/coordinator/tests/energy.rs +0 -549
  111. package/crates/team-agent/src/coordinator/tests/health_sync.rs +0 -503
  112. package/crates/team-agent/src/coordinator/tests/main_preserved.rs +0 -186
  113. package/crates/team-agent/src/coordinator/tests/mod.rs +0 -295
  114. package/crates/team-agent/src/coordinator/tests/s3_bounded.rs +0 -207
  115. package/crates/team-agent/src/coordinator/tests/spine.rs +0 -308
  116. package/crates/team-agent/src/coordinator/tests/takeover.rs +0 -286
  117. package/crates/team-agent/src/coordinator/tests/tick_core.rs +0 -237
  118. package/crates/team-agent/src/coordinator/tick.rs +0 -3024
  119. package/crates/team-agent/src/coordinator/types.rs +0 -540
  120. package/crates/team-agent/src/db/agent_health_capture.rs +0 -126
  121. package/crates/team-agent/src/db/message_store.rs +0 -1527
  122. package/crates/team-agent/src/db/migration.rs +0 -984
  123. package/crates/team-agent/src/db/mod.rs +0 -26
  124. package/crates/team-agent/src/db/schema.rs +0 -663
  125. package/crates/team-agent/src/diagnose/comms.rs +0 -242
  126. package/crates/team-agent/src/diagnose/mod.rs +0 -44
  127. package/crates/team-agent/src/diagnose/orphans.rs +0 -889
  128. package/crates/team-agent/src/direct_delivery.rs +0 -368
  129. package/crates/team-agent/src/event_log.rs +0 -502
  130. package/crates/team-agent/src/fake_worker.rs +0 -303
  131. package/crates/team-agent/src/inbox_store.rs +0 -169
  132. package/crates/team-agent/src/kill_audit.rs +0 -106
  133. package/crates/team-agent/src/layout/manager.rs +0 -248
  134. package/crates/team-agent/src/layout/mod.rs +0 -36
  135. package/crates/team-agent/src/layout/overlay.rs +0 -134
  136. package/crates/team-agent/src/layout/placement.rs +0 -52
  137. package/crates/team-agent/src/layout/recovery.rs +0 -106
  138. package/crates/team-agent/src/layout/runtime_sessions.rs +0 -317
  139. package/crates/team-agent/src/layout/sessions.rs +0 -294
  140. package/crates/team-agent/src/layout/tmux_endpoint.rs +0 -165
  141. package/crates/team-agent/src/layout/worker_env.rs +0 -721
  142. package/crates/team-agent/src/layout/worker_window_helpers.rs +0 -37
  143. package/crates/team-agent/src/leader/helpers.rs +0 -178
  144. package/crates/team-agent/src/leader/incident.rs +0 -6
  145. package/crates/team-agent/src/leader/lease.rs +0 -3356
  146. package/crates/team-agent/src/leader/mod.rs +0 -104
  147. package/crates/team-agent/src/leader/owner_bind.rs +0 -400
  148. package/crates/team-agent/src/leader/prompt.rs +0 -905
  149. package/crates/team-agent/src/leader/provider_attribution.rs +0 -247
  150. package/crates/team-agent/src/leader/rediscover/tests.rs +0 -689
  151. package/crates/team-agent/src/leader/rediscover.rs +0 -1192
  152. package/crates/team-agent/src/leader/registry.rs +0 -888
  153. package/crates/team-agent/src/leader/start.rs +0 -4501
  154. package/crates/team-agent/src/leader/takeover.rs +0 -65
  155. package/crates/team-agent/src/leader/tests/basics.rs +0 -337
  156. package/crates/team-agent/src/leader/tests/byte_findings.rs +0 -355
  157. package/crates/team-agent/src/leader/tests/claim_leader_mailbox_flush_contract.rs +0 -544
  158. package/crates/team-agent/src/leader/tests/historical_inventory_upgrade_gate_red.rs +0 -624
  159. package/crates/team-agent/src/leader/tests/identity.rs +0 -465
  160. package/crates/team-agent/src/leader/tests/identity_session_names.rs +0 -42
  161. package/crates/team-agent/src/leader/tests/idle.rs +0 -113
  162. package/crates/team-agent/src/leader/tests/lease_api.rs +0 -520
  163. package/crates/team-agent/src/leader/tests/lease_claim.rs +0 -629
  164. package/crates/team-agent/src/leader/tests/mod.rs +0 -106
  165. package/crates/team-agent/src/leader/tests/prompt_contract.rs +0 -268
  166. package/crates/team-agent/src/leader/tests/rediscover.rs +0 -403
  167. package/crates/team-agent/src/leader/tests/rehomed_env.rs +0 -83
  168. package/crates/team-agent/src/leader/tests/team_in_team_state_scope_red.rs +0 -1273
  169. package/crates/team-agent/src/leader/tests/terminal_and_replay_vs_rerender_invariants_red.rs +0 -417
  170. package/crates/team-agent/src/leader/tests/wake_start_owner.rs +0 -168
  171. package/crates/team-agent/src/leader/types.rs +0 -534
  172. package/crates/team-agent/src/lib.rs +0 -147
  173. package/crates/team-agent/src/lifecycle/helpers.rs +0 -212
  174. package/crates/team-agent/src/lifecycle/launch/add_agent.rs +0 -881
  175. package/crates/team-agent/src/lifecycle/launch/add_agent_state.rs +0 -598
  176. package/crates/team-agent/src/lifecycle/launch/agent_state.rs +0 -332
  177. package/crates/team-agent/src/lifecycle/launch/clone_agent.rs +0 -204
  178. package/crates/team-agent/src/lifecycle/launch/fork_agent.rs +0 -107
  179. package/crates/team-agent/src/lifecycle/launch/fork_entry.rs +0 -144
  180. package/crates/team-agent/src/lifecycle/launch/identity.rs +0 -674
  181. package/crates/team-agent/src/lifecycle/launch/layout.rs +0 -350
  182. package/crates/team-agent/src/lifecycle/launch/leader_context.rs +0 -589
  183. package/crates/team-agent/src/lifecycle/launch/mcp_config.rs +0 -160
  184. package/crates/team-agent/src/lifecycle/launch/ownership.rs +0 -105
  185. package/crates/team-agent/src/lifecycle/launch/pi_mcp.rs +0 -899
  186. package/crates/team-agent/src/lifecycle/launch/pi_mcp_extension.js +0 -225
  187. package/crates/team-agent/src/lifecycle/launch/plan.rs +0 -269
  188. package/crates/team-agent/src/lifecycle/launch/quick_start.rs +0 -5200
  189. package/crates/team-agent/src/lifecycle/launch/quick_start_transport.rs +0 -368
  190. package/crates/team-agent/src/lifecycle/launch/readiness.rs +0 -519
  191. package/crates/team-agent/src/lifecycle/launch/role_source.rs +0 -287
  192. package/crates/team-agent/src/lifecycle/launch/spawn.rs +0 -473
  193. package/crates/team-agent/src/lifecycle/launch/spec_state.rs +0 -801
  194. package/crates/team-agent/src/lifecycle/launch/state_projection.rs +0 -624
  195. package/crates/team-agent/src/lifecycle/launch/worker_env.rs +0 -558
  196. package/crates/team-agent/src/lifecycle/launch.rs +0 -557
  197. package/crates/team-agent/src/lifecycle/lock.rs +0 -350
  198. package/crates/team-agent/src/lifecycle/mod.rs +0 -79
  199. package/crates/team-agent/src/lifecycle/pane_input_lock.rs +0 -239
  200. package/crates/team-agent/src/lifecycle/profile_launch.rs +0 -1067
  201. package/crates/team-agent/src/lifecycle/profile_smoke.rs +0 -557
  202. package/crates/team-agent/src/lifecycle/restart/agent.rs +0 -2199
  203. package/crates/team-agent/src/lifecycle/restart/avatar.rs +0 -1798
  204. package/crates/team-agent/src/lifecycle/restart/claude_fork.rs +0 -163
  205. package/crates/team-agent/src/lifecycle/restart/common.rs +0 -2362
  206. package/crates/team-agent/src/lifecycle/restart/orchestrator.rs +0 -65
  207. package/crates/team-agent/src/lifecycle/restart/preflight.rs +0 -113
  208. package/crates/team-agent/src/lifecycle/restart/rebuild.rs +0 -5135
  209. package/crates/team-agent/src/lifecycle/restart/remove.rs +0 -1504
  210. package/crates/team-agent/src/lifecycle/restart/selection.rs +0 -559
  211. package/crates/team-agent/src/lifecycle/restart/team_state.rs +0 -329
  212. package/crates/team-agent/src/lifecycle/restart.rs +0 -227
  213. package/crates/team-agent/src/lifecycle/role_config.rs +0 -1230
  214. package/crates/team-agent/src/lifecycle/tests/acceptance_b_batch_red.rs +0 -1021
  215. package/crates/team-agent/src/lifecycle/tests/agent_ops.rs +0 -1205
  216. package/crates/team-agent/src/lifecycle/tests/b0_legacy_snapshot_nonauthority_contract.rs +0 -265
  217. package/crates/team-agent/src/lifecycle/tests/b0_reader_hideone_audit_contract.rs +0 -490
  218. package/crates/team-agent/src/lifecycle/tests/behavioral_diff_264_red.rs +0 -656
  219. package/crates/team-agent/src/lifecycle/tests/claude_compatible_config_red.rs +0 -325
  220. package/crates/team-agent/src/lifecycle/tests/claude_profile_launch_red.rs +0 -447
  221. package/crates/team-agent/src/lifecycle/tests/cli_argv_routing_red.rs +0 -1638
  222. package/crates/team-agent/src/lifecycle/tests/clone_agent_preserves_source_tools.rs +0 -427
  223. package/crates/team-agent/src/lifecycle/tests/clone_fork_copilot_perms_red.rs +0 -770
  224. package/crates/team-agent/src/lifecycle/tests/communication_mode_runtime_contract_red.rs +0 -419
  225. package/crates/team-agent/src/lifecycle/tests/copilot_provider_red.rs +0 -2035
  226. package/crates/team-agent/src/lifecycle/tests/core.rs +0 -1327
  227. package/crates/team-agent/src/lifecycle/tests/f032_startup_prompt_best_effort_red.rs +0 -315
  228. package/crates/team-agent/src/lifecycle/tests/fixtures/pi_list_models_g0.stdout.txt +0 -222
  229. package/crates/team-agent/src/lifecycle/tests/fixtures/pi_list_models_spaced_ids.stdout.txt +0 -9
  230. package/crates/team-agent/src/lifecycle/tests/fixtures/pi_native_mcp_host.mjs +0 -72
  231. package/crates/team-agent/src/lifecycle/tests/gate_fixtures.rs +0 -562
  232. package/crates/team-agent/src/lifecycle/tests/grok_require_explicit_model_red.rs +0 -110
  233. package/crates/team-agent/src/lifecycle/tests/harvest2_a_batch_red.rs +0 -512
  234. package/crates/team-agent/src/lifecycle/tests/host_cotenant_death_p0_contract.rs +0 -921
  235. package/crates/team-agent/src/lifecycle/tests/issue238_codex_effort_contract.rs +0 -68
  236. package/crates/team-agent/src/lifecycle/tests/lane_ops.rs +0 -1851
  237. package/crates/team-agent/src/lifecycle/tests/launch_spawn.rs +0 -3983
  238. package/crates/team-agent/src/lifecycle/tests/lifecycle_lock.rs +0 -339
  239. package/crates/team-agent/src/lifecycle/tests/lifecycle_rollback_red.rs +0 -596
  240. package/crates/team-agent/src/lifecycle/tests/main_preserved.rs +0 -513
  241. package/crates/team-agent/src/lifecycle/tests/mcp_tool_name_format_red.rs +0 -69
  242. package/crates/team-agent/src/lifecycle/tests/phase_b_contracts.rs +0 -824
  243. package/crates/team-agent/src/lifecycle/tests/phase_golden.rs +0 -723
  244. package/crates/team-agent/src/lifecycle/tests/pi_catalog_red.rs +0 -164
  245. package/crates/team-agent/src/lifecycle/tests/pi_command_red.rs +0 -200
  246. package/crates/team-agent/src/lifecycle/tests/pi_compiler_red.rs +0 -210
  247. package/crates/team-agent/src/lifecycle/tests/pi_dual_entry_red.rs +0 -527
  248. package/crates/team-agent/src/lifecycle/tests/pi_executable_mcp_red.rs +0 -1062
  249. package/crates/team-agent/src/lifecycle/tests/pi_fork_session_inheritance_red.rs +0 -1419
  250. package/crates/team-agent/src/lifecycle/tests/pi_lifecycle_doctor_red.rs +0 -98
  251. package/crates/team-agent/src/lifecycle/tests/pi_native_mcp_capability_red.rs +0 -550
  252. package/crates/team-agent/src/lifecycle/tests/pi_session_delivery_red.rs +0 -226
  253. package/crates/team-agent/src/lifecycle/tests/quick_start_worker_readiness_red.rs +0 -332
  254. package/crates/team-agent/src/lifecycle/tests/realmachine_clusters_1_6_red.rs +0 -786
  255. package/crates/team-agent/src/lifecycle/tests/realmachine_residual_g1_g4_red.rs +0 -648
  256. package/crates/team-agent/src/lifecycle/tests/restart.rs +0 -185
  257. package/crates/team-agent/src/lifecycle/tests/restart_build_before_destroy_0540_contract.rs +0 -1053
  258. package/crates/team-agent/src/lifecycle/tests/restart_liveness_red.rs +0 -679
  259. package/crates/team-agent/src/lifecycle/tests/restart_rebind_hotfix_252_red.rs +0 -1126
  260. package/crates/team-agent/src/lifecycle/tests/restart_session_capture_red.rs +0 -153
  261. package/crates/team-agent/src/lifecycle/tests/resume_recover_red.rs +0 -427
  262. package/crates/team-agent/src/lifecycle/tests/stale_team_saveconflict_contract.rs +0 -431
  263. package/crates/team-agent/src/lifecycle/tests/startup_latency_contract.rs +0 -1066
  264. package/crates/team-agent/src/lifecycle/tests/status_credential_redaction_contract.rs +0 -876
  265. package/crates/team-agent/src/lifecycle/tests/subprep_codex_trust_roundtrip_red.rs +0 -1026
  266. package/crates/team-agent/src/lifecycle/tests/swallow_batch4_semantics_red.rs +0 -342
  267. package/crates/team-agent/src/lifecycle/tests/team_in_team_identity_scope_red.rs +0 -543
  268. package/crates/team-agent/src/lifecycle/tests/team_in_team_sibling_quick_start_red.rs +0 -1103
  269. package/crates/team-agent/src/lifecycle/tests/team_in_team_state_scope_red.rs +0 -1276
  270. package/crates/team-agent/src/lifecycle/tests/team_key_retirement_roster_red.rs +0 -145
  271. package/crates/team-agent/src/lifecycle/tests/team_key_retirement_txn_red.rs +0 -603
  272. package/crates/team-agent/src/lifecycle/tests/test_isolation_escape_contract.rs +0 -936
  273. package/crates/team-agent/src/lifecycle/tests/upgrade_compat_0211_red.rs +0 -970
  274. package/crates/team-agent/src/lifecycle/tests/verify_rs031_window_consistency_red.rs +0 -995
  275. package/crates/team-agent/src/lifecycle/tests/worker_spawn_env_red.rs +0 -836
  276. package/crates/team-agent/src/lifecycle/tests.rs +0 -105
  277. package/crates/team-agent/src/lifecycle/types.rs +0 -877
  278. package/crates/team-agent/src/lifecycle/worker_command_context.rs +0 -363
  279. package/crates/team-agent/src/main.rs +0 -52
  280. package/crates/team-agent/src/mcp_server/helpers.rs +0 -510
  281. package/crates/team-agent/src/mcp_server/lifecycle_tools/mod.rs +0 -6
  282. package/crates/team-agent/src/mcp_server/lifecycle_tools/state_status.rs +0 -43
  283. package/crates/team-agent/src/mcp_server/mod.rs +0 -119
  284. package/crates/team-agent/src/mcp_server/normalize.rs +0 -485
  285. package/crates/team-agent/src/mcp_server/readiness.rs +0 -527
  286. package/crates/team-agent/src/mcp_server/readiness_tests.rs +0 -348
  287. package/crates/team-agent/src/mcp_server/tests/golden.rs +0 -285
  288. package/crates/team-agent/src/mcp_server/tests/normalize.rs +0 -247
  289. package/crates/team-agent/src/mcp_server/tests/scoped.rs +0 -158
  290. package/crates/team-agent/src/mcp_server/tests/send.rs +0 -353
  291. package/crates/team-agent/src/mcp_server/tests/tools.rs +0 -341
  292. package/crates/team-agent/src/mcp_server/tests/wire.rs +0 -254
  293. package/crates/team-agent/src/mcp_server/tests.rs +0 -43
  294. package/crates/team-agent/src/mcp_server/tools.rs +0 -889
  295. package/crates/team-agent/src/mcp_server/types.rs +0 -396
  296. package/crates/team-agent/src/mcp_server/wire.rs +0 -867
  297. package/crates/team-agent/src/messaging/activity.rs +0 -461
  298. package/crates/team-agent/src/messaging/address.rs +0 -87
  299. package/crates/team-agent/src/messaging/delivery.rs +0 -3727
  300. package/crates/team-agent/src/messaging/delivery_consumption_tests.rs +0 -234
  301. package/crates/team-agent/src/messaging/enter_rescue.rs +0 -362
  302. package/crates/team-agent/src/messaging/enter_rescue_tests.rs +0 -633
  303. package/crates/team-agent/src/messaging/helpers.rs +0 -336
  304. package/crates/team-agent/src/messaging/leader_channel.rs +0 -287
  305. package/crates/team-agent/src/messaging/leader_receiver.rs +0 -786
  306. package/crates/team-agent/src/messaging/mod.rs +0 -167
  307. package/crates/team-agent/src/messaging/persist.rs +0 -377
  308. package/crates/team-agent/src/messaging/presentation.rs +0 -417
  309. package/crates/team-agent/src/messaging/reminders.rs +0 -316
  310. package/crates/team-agent/src/messaging/results/collection_tests.rs +0 -719
  311. package/crates/team-agent/src/messaging/results.rs +0 -1415
  312. package/crates/team-agent/src/messaging/scheduler.rs +0 -223
  313. package/crates/team-agent/src/messaging/selftest.rs +0 -315
  314. package/crates/team-agent/src/messaging/send.rs +0 -981
  315. package/crates/team-agent/src/messaging/tests/basic.rs +0 -346
  316. package/crates/team-agent/src/messaging/tests/dup_inject.rs +0 -657
  317. package/crates/team-agent/src/messaging/tests/e23.rs +0 -49
  318. package/crates/team-agent/src/messaging/tests/leader_channel.rs +0 -169
  319. package/crates/team-agent/src/messaging/tests/leader_inject_acceptance.rs +0 -817
  320. package/crates/team-agent/src/messaging/tests/main_preserved.rs +0 -85
  321. package/crates/team-agent/src/messaging/tests/mod.rs +0 -306
  322. package/crates/team-agent/src/messaging/tests/runtime.rs +0 -3549
  323. package/crates/team-agent/src/messaging/tests/spine.rs +0 -853
  324. package/crates/team-agent/src/messaging/tests/wave2.rs +0 -381
  325. package/crates/team-agent/src/messaging/trust.rs +0 -215
  326. package/crates/team-agent/src/messaging/types.rs +0 -472
  327. package/crates/team-agent/src/messaging/wait.rs +0 -366
  328. package/crates/team-agent/src/messaging/watchers.rs +0 -916
  329. package/crates/team-agent/src/model/enums.rs +0 -356
  330. package/crates/team-agent/src/model/errors.rs +0 -18
  331. package/crates/team-agent/src/model/ids.rs +0 -165
  332. package/crates/team-agent/src/model/mod.rs +0 -29
  333. package/crates/team-agent/src/model/name_similarity.rs +0 -252
  334. package/crates/team-agent/src/model/pane_authority_refusal.rs +0 -359
  335. package/crates/team-agent/src/model/paths.rs +0 -257
  336. package/crates/team-agent/src/model/routing.rs +0 -387
  337. package/crates/team-agent/src/model/spec.rs +0 -1184
  338. package/crates/team-agent/src/model/task_graph.rs +0 -321
  339. package/crates/team-agent/src/model/testdata/fuzz.golden.yaml +0 -43
  340. package/crates/team-agent/src/model/testdata/fuzz.yaml +0 -43
  341. package/crates/team-agent/src/model/testdata/spec_invalid_a.yaml +0 -209
  342. package/crates/team-agent/src/model/testdata/team.spec.golden.yaml +0 -208
  343. package/crates/team-agent/src/model/testdata/team.spec.yaml +0 -208
  344. package/crates/team-agent/src/model/yaml/tests.rs +0 -188
  345. package/crates/team-agent/src/model/yaml.rs +0 -802
  346. package/crates/team-agent/src/os_probe.rs +0 -280
  347. package/crates/team-agent/src/packaging/install.rs +0 -219
  348. package/crates/team-agent/src/packaging/migrate.rs +0 -38
  349. package/crates/team-agent/src/packaging/mod.rs +0 -91
  350. package/crates/team-agent/src/packaging/repair.rs +0 -33
  351. package/crates/team-agent/src/packaging/tests.rs +0 -822
  352. package/crates/team-agent/src/packaging/types.rs +0 -417
  353. package/crates/team-agent/src/platform/argv.rs +0 -331
  354. package/crates/team-agent/src/platform/errors.rs +0 -104
  355. package/crates/team-agent/src/platform/file_lock.rs +0 -279
  356. package/crates/team-agent/src/platform/mod.rs +0 -5
  357. package/crates/team-agent/src/platform/process.rs +0 -545
  358. package/crates/team-agent/src/provider/adapter.rs +0 -1150
  359. package/crates/team-agent/src/provider/adapters/claude.rs +0 -78
  360. package/crates/team-agent/src/provider/adapters/claude_fork.rs +0 -131
  361. package/crates/team-agent/src/provider/adapters/copilot.rs +0 -75
  362. package/crates/team-agent/src/provider/adapters/copilot_fork.rs +0 -307
  363. package/crates/team-agent/src/provider/adapters/fake.rs +0 -18
  364. package/crates/team-agent/src/provider/adapters/mod.rs +0 -30
  365. package/crates/team-agent/src/provider/adapters/pi.rs +0 -106
  366. package/crates/team-agent/src/provider/approvals/mod.rs +0 -3
  367. package/crates/team-agent/src/provider/approvals/parsing.rs +0 -586
  368. package/crates/team-agent/src/provider/approvals/runtime_prompts.rs +0 -205
  369. package/crates/team-agent/src/provider/argv_route.rs +0 -405
  370. package/crates/team-agent/src/provider/bypass_flags.rs +0 -116
  371. package/crates/team-agent/src/provider/classify.rs +0 -708
  372. package/crates/team-agent/src/provider/command_helpers.rs +0 -45
  373. package/crates/team-agent/src/provider/faults.rs +0 -165
  374. package/crates/team-agent/src/provider/helpers.rs +0 -52
  375. package/crates/team-agent/src/provider/mod.rs +0 -78
  376. package/crates/team-agent/src/provider/model_catalog.rs +0 -910
  377. package/crates/team-agent/src/provider/session/capture.rs +0 -2731
  378. package/crates/team-agent/src/provider/session/context_fork/claude.rs +0 -123
  379. package/crates/team-agent/src/provider/session/context_fork/outcome.rs +0 -172
  380. package/crates/team-agent/src/provider/session/context_fork.rs +0 -396
  381. package/crates/team-agent/src/provider/session/mod.rs +0 -36
  382. package/crates/team-agent/src/provider/session/resume.rs +0 -269
  383. package/crates/team-agent/src/provider/session_scan/claude.rs +0 -523
  384. package/crates/team-agent/src/provider/session_scan/common/tests.rs +0 -316
  385. package/crates/team-agent/src/provider/session_scan/common.rs +0 -654
  386. package/crates/team-agent/src/provider/session_scan/copilot.rs +0 -280
  387. package/crates/team-agent/src/provider/session_scan/pi.rs +0 -185
  388. package/crates/team-agent/src/provider/session_scan.rs +0 -71
  389. package/crates/team-agent/src/provider/startup_prompt.rs +0 -757
  390. package/crates/team-agent/src/provider/submit_now.rs +0 -71
  391. package/crates/team-agent/src/provider/testdata/copilot-ready-marker.txt +0 -5
  392. package/crates/team-agent/src/provider/testdata/copilot-trust-prompt.txt +0 -19
  393. package/crates/team-agent/src/provider/testdata/grok-models-authenticated.stdout +0 -9
  394. package/crates/team-agent/src/provider/testdata/grok-models-unauthenticated.stdout +0 -7
  395. package/crates/team-agent/src/provider/tests/adapter.rs +0 -441
  396. package/crates/team-agent/src/provider/tests/classify.rs +0 -148
  397. package/crates/team-agent/src/provider/tests/command_helpers.rs +0 -35
  398. package/crates/team-agent/src/provider/tests/copilot_fork.rs +0 -191
  399. package/crates/team-agent/src/provider/tests/faults.rs +0 -200
  400. package/crates/team-agent/src/provider/tests/idle.rs +0 -177
  401. package/crates/team-agent/src/provider/tests/wire.rs +0 -213
  402. package/crates/team-agent/src/provider/tests.rs +0 -32
  403. package/crates/team-agent/src/provider/types.rs +0 -529
  404. package/crates/team-agent/src/provider/wire.rs +0 -394
  405. package/crates/team-agent/src/redaction.rs +0 -259
  406. package/crates/team-agent/src/state/abnormal_watch/tests/mod.rs +0 -248
  407. package/crates/team-agent/src/state/abnormal_watch.rs +0 -144
  408. package/crates/team-agent/src/state/identity.rs +0 -914
  409. package/crates/team-agent/src/state/identity_keys.rs +0 -132
  410. package/crates/team-agent/src/state/mod.rs +0 -74
  411. package/crates/team-agent/src/state/owner_gate.rs +0 -482
  412. package/crates/team-agent/src/state/ownership.rs +0 -563
  413. package/crates/team-agent/src/state/paths.rs +0 -395
  414. package/crates/team-agent/src/state/persist.rs +0 -3811
  415. package/crates/team-agent/src/state/projection.rs +0 -1508
  416. package/crates/team-agent/src/state/repository/intent.rs +0 -14
  417. package/crates/team-agent/src/state/repository/tests.rs +0 -184
  418. package/crates/team-agent/src/state/repository.rs +0 -866
  419. package/crates/team-agent/src/state/selector.rs +0 -160
  420. package/crates/team-agent/src/state/testdata/state-rich.canonical.json +0 -133
  421. package/crates/team-agent/src/test_support/models_timeout_fixture.rs +0 -144
  422. package/crates/team-agent/src/tmux_backend/enter_rescue.rs +0 -325
  423. package/crates/team-agent/src/tmux_backend/enter_rescue_tests.rs +0 -432
  424. package/crates/team-agent/src/tmux_backend/native_input.rs +0 -513
  425. package/crates/team-agent/src/tmux_backend/native_input_tests.rs +0 -742
  426. package/crates/team-agent/src/tmux_backend/tests.rs +0 -4103
  427. package/crates/team-agent/src/tmux_backend.rs +0 -4492
  428. package/crates/team-agent/src/topology.rs +0 -537
  429. package/crates/team-agent/src/transport/enter_rescue.rs +0 -166
  430. package/crates/team-agent/src/transport/native_input.rs +0 -491
  431. package/crates/team-agent/src/transport/test_support.rs +0 -743
  432. package/crates/team-agent/src/transport/tests/behavior.rs +0 -326
  433. package/crates/team-agent/src/transport/tests/mod.rs +0 -194
  434. package/crates/team-agent/src/transport/tests/wire.rs +0 -574
  435. package/crates/team-agent/src/transport.rs +0 -1655
  436. 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
- }