@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,802 +0,0 @@
1
- //!
2
- //! step 2 · model — `simple_yaml` 方言移植(真相源 `src/team_agent/simple_yaml.py`)。
3
- //!
4
- //! Team Agent **不**用标准 YAML:它有一份零依赖、字节级特判的子集 `loads`/`dumps`,
5
- //! spec / role-doc front-matter / team_state 全靠它解析与回写。**禁用 serde_yaml**——
6
- //! 标准 YAML 在空白 / 引号 / `|` block scalar / `[...]`(`ast.literal_eval`)/ int 解析 /
7
- //! dict-vs-list-上下文 dump 的诸多怪癖上都会漂移 → spec 解析不一致 → 下游全错(§7)。
8
- //! 这里移植的是**那份方言本身**,golden 字节由 Python 真相源双跑锁死(§4.2)。
9
- //!
10
- //! 与 Python `Any` 语义对齐的 [`Value`]:
11
- //! - `dict` 保持插入顺序 → `Map(Vec<(String, Value)>)`(非 `BTreeMap`,否则 JSON 路径乱序)。
12
- //! - int 用 `i64`(真相源 Python 任意精度;实际语料只有 version/priority/timeout 等小整数)。
13
- //! - float 仅经 JSON 顶层路径出现(`{`/`[` 开头 → `json.loads`),`dumps` 时按 Python
14
- //! `json.dumps(str(f))` 走带引号字符串分支。
15
- //!
16
- //! §10:纯层无 panic —— `loads` 校验失败返 [`ModelError`];`dumps` 不会失败。
17
-
18
- use serde::de::{self, Deserialize, Deserializer, MapAccess, SeqAccess, Visitor};
19
-
20
- use crate::model::errors::ModelError;
21
-
22
- /// 与 Python `simple_yaml` 的 `Any` 一一对应的动态值。
23
- ///
24
- /// `Map` 用有序 `Vec<(String, Value)>` 复刻 Python dict 的插入顺序(`dumps` 按此顺序输出,
25
- /// 字节对拍依赖它)。
26
- #[derive(Debug, Clone, PartialEq)]
27
- pub enum Value {
28
- Null,
29
- Bool(bool),
30
- Int(i64),
31
- /// 仅经 JSON 顶层路径产生(`loads("{...}")`)。`dumps` 走 `json.dumps(str(f))` 分支。
32
- Float(f64),
33
- Str(String),
34
- List(Vec<Value>),
35
- /// 有序键值对(复刻 Python dict 插入顺序)。
36
- Map(Vec<(String, Value)>),
37
- }
38
-
39
- impl Value {
40
- fn is_empty_list(&self) -> bool {
41
- matches!(self, Value::List(v) if v.is_empty())
42
- }
43
- fn is_empty_map(&self) -> bool {
44
- matches!(self, Value::Map(m) if m.is_empty())
45
- }
46
- fn is_collection(&self) -> bool {
47
- matches!(self, Value::List(_) | Value::Map(_))
48
- }
49
-
50
- // --- 公开访问器(spec/compiler/routing/state 遍历 spec Value 用;对应 Python dict/list 取值)---
51
-
52
- /// `Str` → `&str`,否则 `None`。
53
- pub fn as_str(&self) -> Option<&str> {
54
- if let Value::Str(s) = self {
55
- Some(s)
56
- } else {
57
- None
58
- }
59
- }
60
- /// `Map` 的有序键值对切片,否则 `None`。
61
- pub fn as_map(&self) -> Option<&[(String, Value)]> {
62
- if let Value::Map(m) = self {
63
- Some(m)
64
- } else {
65
- None
66
- }
67
- }
68
- /// `List` 切片,否则 `None`。
69
- pub fn as_list(&self) -> Option<&[Value]> {
70
- if let Value::List(l) = self {
71
- Some(l)
72
- } else {
73
- None
74
- }
75
- }
76
- /// 是否 `Map`(对应 Python `isinstance(x, dict)`)。
77
- pub fn is_map(&self) -> bool {
78
- matches!(self, Value::Map(_))
79
- }
80
- /// `Int` → `i64`,否则 `None`。
81
- pub fn as_i64(&self) -> Option<i64> {
82
- if let Value::Int(i) = self {
83
- Some(*i)
84
- } else {
85
- None
86
- }
87
- }
88
- /// dict get:首个匹配 key 的值(`insert_ordered` 已去重 → 首即唯一)。非 Map → `None`。
89
- pub fn get(&self, key: &str) -> Option<&Value> {
90
- self.as_map()?
91
- .iter()
92
- .find(|(k, _)| k == key)
93
- .map(|(_, v)| v)
94
- }
95
- /// Python 真值语义:None/Null/false/0/""/空集 → false。
96
- pub fn is_truthy(&self) -> bool {
97
- match self {
98
- Value::Null => false,
99
- Value::Bool(b) => *b,
100
- Value::Int(i) => *i != 0,
101
- Value::Float(f) => *f != 0.0,
102
- Value::Str(s) => !s.is_empty(),
103
- Value::List(l) => !l.is_empty(),
104
- Value::Map(m) => !m.is_empty(),
105
- }
106
- }
107
- }
108
-
109
- // ---------------------------------------------------------------------------
110
- // loads
111
- // ---------------------------------------------------------------------------
112
-
113
- /// 移植 `simple_yaml.loads`。
114
- ///
115
- /// `text.lstrip()` 以 `{`/`[` 开头 → 整段走 `json.loads`(JSON 子集,保持键序)。
116
- /// 否则按 Python 的缩进块方言解析。无法解析返 [`ModelError::Validation`]。
117
- pub fn loads(text: &str) -> Result<Value, ModelError> {
118
- let stripped = text.trim_start();
119
- if stripped.starts_with('{') || stripped.starts_with('[') {
120
- return loads_json(text);
121
- }
122
- let lines: Vec<&str> = split_lines(text);
123
- let p = Parser { lines: &lines };
124
- let (value, mut index) = p.parse_block(0, 0)?;
125
- while index < lines.len() && !content(lines[index]) {
126
- index += 1;
127
- }
128
- if index != lines.len() {
129
- return Err(ModelError::Validation(format!(
130
- "unexpected content at line {}: {}",
131
- index + 1,
132
- lines[index]
133
- )));
134
- }
135
- Ok(value)
136
- }
137
-
138
- /// Python `str.splitlines()`:无尾随空行(末尾 `\n` 不产生空元素),`\r\n`/`\r` 也算行界。
139
- /// 真相源语料是 `\n` 结尾的 UTF-8 文本;这里按 `\n` 切并剥掉每行尾随 `\r`,与 Python 对齐。
140
- fn split_lines(text: &str) -> Vec<&str> {
141
- if text.is_empty() {
142
- return Vec::new();
143
- }
144
- let mut out: Vec<&str> = Vec::new();
145
- for part in text.split('\n') {
146
- out.push(part.strip_suffix('\r').unwrap_or(part));
147
- }
148
- // split('\n') 在尾随 '\n' 时产生一个末尾空串 —— Python splitlines 不会,去掉它。
149
- if text.ends_with('\n') {
150
- out.pop();
151
- }
152
- out
153
- }
154
-
155
- fn loads_json(text: &str) -> Result<Value, ModelError> {
156
- let mut de = serde_json::Deserializer::from_str(text);
157
- let value =
158
- Value::deserialize(&mut de).map_err(|e| ModelError::Validation(format!("json: {e}")))?;
159
- de.end()
160
- .map_err(|e| ModelError::Validation(format!("json: {e}")))?;
161
- Ok(value)
162
- }
163
-
164
- struct Parser<'a> {
165
- lines: &'a [&'a str],
166
- }
167
-
168
- impl<'a> Parser<'a> {
169
- fn parse_block(&self, mut index: usize, indent: usize) -> Result<(Value, usize), ModelError> {
170
- index = skip_blank(self.lines, index);
171
- if index >= self.lines.len() {
172
- return Ok((Value::Null, index));
173
- }
174
- let current_indent = line_indent(self.lines[index]);
175
- if current_indent < indent {
176
- return Ok((Value::Null, index));
177
- }
178
- if self.lines[index].trim().starts_with("- ") {
179
- self.parse_list(index, current_indent)
180
- } else {
181
- self.parse_dict(index, current_indent)
182
- }
183
- }
184
-
185
- fn parse_dict(&self, mut index: usize, indent: usize) -> Result<(Value, usize), ModelError> {
186
- let mut obj: Vec<(String, Value)> = Vec::new();
187
- while index < self.lines.len() {
188
- if !content(self.lines[index]) {
189
- index += 1;
190
- continue;
191
- }
192
- let line_ind = line_indent(self.lines[index]);
193
- if line_ind < indent {
194
- break;
195
- }
196
- if line_ind > indent {
197
- return Err(ModelError::Validation(format!(
198
- "unexpected indentation at line {}: {}",
199
- index + 1,
200
- self.lines[index]
201
- )));
202
- }
203
- let stripped = self.lines[index].trim();
204
- if stripped.starts_with("- ") {
205
- break;
206
- }
207
- let (key, raw) = split_key_value(stripped, index)?;
208
- let value = if raw == "|" {
209
- let (v, ni) = self.parse_block_scalar(index + 1, indent + 2);
210
- index = ni;
211
- v
212
- } else if raw.is_empty() {
213
- let (v, ni) = self.parse_block(index + 1, indent + 2)?;
214
- index = ni;
215
- v
216
- } else {
217
- index += 1;
218
- parse_scalar(&raw)
219
- };
220
- insert_ordered(&mut obj, key, value);
221
- }
222
- Ok((Value::Map(obj), index))
223
- }
224
-
225
- fn parse_list(&self, mut index: usize, indent: usize) -> Result<(Value, usize), ModelError> {
226
- let mut items: Vec<Value> = Vec::new();
227
- while index < self.lines.len() {
228
- if !content(self.lines[index]) {
229
- index += 1;
230
- continue;
231
- }
232
- let line_ind = line_indent(self.lines[index]);
233
- if line_ind < indent {
234
- break;
235
- }
236
- if line_ind != indent {
237
- return Err(ModelError::Validation(format!(
238
- "unexpected list indentation at line {}: {}",
239
- index + 1,
240
- self.lines[index]
241
- )));
242
- }
243
- let stripped = self.lines[index].trim();
244
- if !stripped.starts_with("- ") {
245
- break;
246
- }
247
- let item_text = stripped[2..].trim();
248
- if item_text.is_empty() {
249
- let (value, ni) = self.parse_block(index + 1, indent + 2)?;
250
- items.push(value);
251
- index = ni;
252
- continue;
253
- }
254
- if looks_like_key_value(item_text) {
255
- let (key, raw) = split_key_value(item_text, index)?;
256
- let mut item: Vec<(String, Value)> = Vec::new();
257
- let (value, mut next_index) = if raw == "|" {
258
- self.parse_block_scalar(index + 1, indent + 2)
259
- } else if raw.is_empty() {
260
- self.parse_block(index + 1, indent + 2)?
261
- } else {
262
- (parse_scalar(&raw), index + 1)
263
- };
264
- insert_ordered(&mut item, key, value);
265
- if next_index < self.lines.len()
266
- && line_indent(self.lines[next_index]) == indent + 2
267
- {
268
- let (extra, ni) = self.parse_dict(next_index, indent + 2)?;
269
- if let Value::Map(pairs) = extra {
270
- for (k, v) in pairs {
271
- insert_ordered(&mut item, k, v);
272
- }
273
- }
274
- next_index = ni;
275
- }
276
- items.push(Value::Map(item));
277
- index = next_index;
278
- } else {
279
- items.push(parse_scalar(item_text));
280
- index += 1;
281
- }
282
- }
283
- Ok((Value::List(items), index))
284
- }
285
-
286
- /// `|` block scalar:取 `indent` 之后的内容,空行记为 `""`,末尾 `rstrip()` + `"\n"`。
287
- fn parse_block_scalar(&self, mut index: usize, indent: usize) -> (Value, usize) {
288
- let mut block: Vec<String> = Vec::new();
289
- while index < self.lines.len() {
290
- if self.lines[index].trim().is_empty() {
291
- block.push(String::new());
292
- index += 1;
293
- continue;
294
- }
295
- let line_ind = line_indent(self.lines[index]);
296
- if line_ind < indent {
297
- break;
298
- }
299
- block.push(slice_from_byte(self.lines[index], indent));
300
- index += 1;
301
- }
302
- let joined = block.join("\n");
303
- (Value::Str(format!("{}\n", py_rstrip(&joined))), index)
304
- }
305
- }
306
-
307
- /// Python dict 赋值语义:键已存在则覆盖**值**但保留原插入位置。
308
- fn insert_ordered(map: &mut Vec<(String, Value)>, key: String, value: Value) {
309
- if let Some(slot) = map.iter_mut().find(|(k, _)| *k == key) {
310
- slot.1 = value;
311
- } else {
312
- map.push((key, value));
313
- }
314
- }
315
-
316
- /// 移植 `_parse_scalar`。
317
- fn parse_scalar(raw: &str) -> Value {
318
- match raw {
319
- "null" | "Null" | "NULL" | "~" => return Value::Null,
320
- "true" | "True" | "TRUE" => return Value::Bool(true),
321
- "false" | "False" | "FALSE" => return Value::Bool(false),
322
- _ => {}
323
- }
324
- if let Some(n) = py_int(raw) {
325
- return Value::Int(n);
326
- }
327
- if raw.starts_with('[') && raw.ends_with(']') {
328
- // ast.literal_eval(raw):成功 → list,失败(SyntaxError/ValueError)→ 原样 str。
329
- return match literal_eval_list(raw) {
330
- Some(list) => list,
331
- None => Value::Str(raw.to_string()),
332
- };
333
- }
334
- if raw == "{}" {
335
- return Value::Map(Vec::new());
336
- }
337
- if (raw.starts_with('"') && raw.ends_with('"'))
338
- || (raw.starts_with('\'') && raw.ends_with('\''))
339
- {
340
- if raw.len() < 2 {
341
- // 单个引号字符:不是合法的成对引号,落到末尾 return raw。
342
- return Value::Str(raw.to_string());
343
- }
344
- return match literal_eval_quoted(raw) {
345
- Some(s) => Value::Str(s),
346
- // ast.literal_eval 失败 → Python 退化为 raw[1:-1](剥首尾各一字节)。
347
- None => Value::Str(strip_one_each_end(raw)),
348
- };
349
- }
350
- Value::Str(raw.to_string())
351
- }
352
-
353
- /// 移植 Python `int(raw)`:十进制,允许前导 `+`/`-`、内部单下划线(不可前/尾/连续),
354
- /// 拒绝空、浮点、十六进制、`e` 记数等。失败返 `None`(→ 落到字符串)。
355
- /// 任意精度退化为 `i64`:语料只有小整数,超出 `i64` 时返 `None`(回退字符串)以免 panic。
356
- fn py_int(raw: &str) -> Option<i64> {
357
- let bytes = raw.as_bytes();
358
- if bytes.is_empty() {
359
- return None;
360
- }
361
- let mut i = 0usize;
362
- let neg = match bytes[0] {
363
- b'+' => {
364
- i = 1;
365
- false
366
- }
367
- b'-' => {
368
- i = 1;
369
- true
370
- }
371
- _ => false,
372
- };
373
- let digits = &raw[i..];
374
- if digits.is_empty() {
375
- return None;
376
- }
377
- // 下划线规则:不能开头/结尾,不能连续,两侧必须是数字。
378
- let db = digits.as_bytes();
379
- let mut prev_underscore = false;
380
- for (idx, &c) in db.iter().enumerate() {
381
- if c == b'_' {
382
- if idx == 0 || idx == db.len() - 1 || prev_underscore {
383
- return None;
384
- }
385
- prev_underscore = true;
386
- } else if c.is_ascii_digit() {
387
- prev_underscore = false;
388
- } else {
389
- return None;
390
- }
391
- }
392
- let cleaned: String = digits.chars().filter(|&c| c != '_').collect();
393
- let magnitude: i64 = cleaned.parse().ok()?;
394
- Some(if neg { -magnitude } else { magnitude })
395
- }
396
-
397
- /// `ast.literal_eval` 子集,仅覆盖 `[...]` 中由标量(int / 引号字符串 / bool / None)
398
- /// 组成的列表 —— 这是真相源唯一会命中此路径的形态(如 `tools: ['a', 'b']`)。
399
- /// 任何无法以此子集解析的输入返 `None`(→ 调用方回退为原始字符串,与 Python 一致)。
400
- fn literal_eval_list(raw: &str) -> Option<Value> {
401
- let inner = &raw[1..raw.len() - 1];
402
- let inner_trim = inner.trim();
403
- if inner_trim.is_empty() {
404
- return Some(Value::List(Vec::new()));
405
- }
406
- let mut items: Vec<Value> = Vec::new();
407
- for part in split_top_level_commas(inner_trim)? {
408
- items.push(literal_eval_atom(part.trim())?);
409
- }
410
- Some(Value::List(items))
411
- }
412
-
413
- /// 按顶层逗号切分(不进入引号 / 不处理嵌套,够覆盖语料中的扁平列表)。
414
- /// 末尾允许一个尾随逗号(Python 列表字面量允许)。
415
- fn split_top_level_commas(s: &str) -> Option<Vec<&str>> {
416
- let bytes = s.as_bytes();
417
- let mut parts: Vec<&str> = Vec::new();
418
- let mut start = 0usize;
419
- let mut quote: Option<u8> = None;
420
- let mut i = 0usize;
421
- while i < bytes.len() {
422
- let c = bytes[i];
423
- match quote {
424
- Some(q) => {
425
- if c == q {
426
- quote = None;
427
- }
428
- }
429
- None => {
430
- if c == b'\'' || c == b'"' {
431
- quote = Some(c);
432
- } else if c == b'[' || c == b']' || c == b'{' || c == b'}' {
433
- // 嵌套结构超出本子集 → 让 ast 在 Python 里也可能成功但这里保守失败。
434
- return None;
435
- } else if c == b',' {
436
- parts.push(&s[start..i]);
437
- start = i + 1;
438
- }
439
- }
440
- }
441
- i += 1;
442
- }
443
- if quote.is_some() {
444
- return None;
445
- }
446
- let tail = s[start..].trim();
447
- if !tail.is_empty() {
448
- parts.push(&s[start..]);
449
- }
450
- Some(parts)
451
- }
452
-
453
- fn literal_eval_atom(tok: &str) -> Option<Value> {
454
- if tok.is_empty() {
455
- return None;
456
- }
457
- match tok {
458
- "None" => return Some(Value::Null),
459
- "True" => return Some(Value::Bool(true)),
460
- "False" => return Some(Value::Bool(false)),
461
- _ => {}
462
- }
463
- let bytes = tok.as_bytes();
464
- let first = bytes[0];
465
- if (first == b'"' || first == b'\'') && tok.len() >= 2 && bytes[bytes.len() - 1] == first {
466
- return literal_eval_quoted(tok).map(Value::Str);
467
- }
468
- // Python int literal(literal_eval 允许下划线/正负号)。
469
- if let Some(n) = py_int(tok) {
470
- return Some(Value::Int(n));
471
- }
472
- None
473
- }
474
-
475
- /// `ast.literal_eval` 一个引号字符串字面量。支持 `\n \t \" \' \\` 等常见转义;
476
- /// 解析失败返 `None`。
477
- fn literal_eval_quoted(raw: &str) -> Option<String> {
478
- let bytes = raw.as_bytes();
479
- if raw.len() < 2 {
480
- return None;
481
- }
482
- let q = bytes[0];
483
- if (q != b'"' && q != b'\'') || bytes[raw.len() - 1] != q {
484
- return None;
485
- }
486
- let inner = &raw[1..raw.len() - 1];
487
- let mut out = String::with_capacity(inner.len());
488
- let mut chars = inner.chars().peekable();
489
- while let Some(c) = chars.next() {
490
- if c == '\\' {
491
- match chars.next() {
492
- Some('n') => out.push('\n'),
493
- Some('t') => out.push('\t'),
494
- Some('r') => out.push('\r'),
495
- Some('\\') => out.push('\\'),
496
- Some('\'') => out.push('\''),
497
- Some('"') => out.push('"'),
498
- Some('0') => out.push('\0'),
499
- Some(other) => {
500
- out.push('\\');
501
- out.push(other);
502
- }
503
- None => return None,
504
- }
505
- } else if c == q as char {
506
- // 未转义的同种引号出现在内部 → 非法字面量。
507
- return None;
508
- } else {
509
- out.push(c);
510
- }
511
- }
512
- Some(out)
513
- }
514
-
515
- /// `raw[1:-1]`:按字节剥掉首尾各一字节(Python 切片语义)。语料中引号为 ASCII。
516
- fn strip_one_each_end(raw: &str) -> String {
517
- let mut chars = raw.chars();
518
- chars.next();
519
- chars.next_back();
520
- chars.as_str().to_string()
521
- }
522
-
523
- // ---------------------------------------------------------------------------
524
- // dumps
525
- // ---------------------------------------------------------------------------
526
-
527
- /// 移植 `simple_yaml.dumps`:`"\n".join(_dump(value, indent)) + "\n"`。
528
- pub fn dumps(value: &Value) -> String {
529
- let lines = dump(value, 0);
530
- let mut out = lines.join("\n");
531
- out.push('\n');
532
- out
533
- }
534
-
535
- fn dump(value: &Value, indent: usize) -> Vec<String> {
536
- let pad = " ".repeat(indent);
537
- match value {
538
- Value::Map(pairs) => {
539
- let mut lines: Vec<String> = Vec::new();
540
- for (key, item) in pairs {
541
- if item.is_empty_list() {
542
- lines.push(format!("{pad}{key}: []"));
543
- } else if item.is_empty_map() {
544
- lines.push(format!("{pad}{key}: {{}}"));
545
- } else if item.is_collection() {
546
- lines.push(format!("{pad}{key}:"));
547
- lines.extend(dump(item, indent + 2));
548
- } else if let Value::Str(s) = item {
549
- if s.contains('\n') {
550
- lines.push(format!("{pad}{key}: |"));
551
- for block_line in py_splitlines(py_rstrip_newlines(s)) {
552
- lines.push(format!("{pad} {block_line}"));
553
- }
554
- } else {
555
- lines.push(format!("{pad}{key}: {}", format_scalar(item)));
556
- }
557
- } else {
558
- lines.push(format!("{pad}{key}: {}", format_scalar(item)));
559
- }
560
- }
561
- lines
562
- }
563
- Value::List(items) => {
564
- let mut lines: Vec<String> = Vec::new();
565
- for item in items {
566
- match item {
567
- Value::Map(pairs) => {
568
- if pairs.is_empty() {
569
- lines.push(format!("{pad}- {{}}"));
570
- continue;
571
- }
572
- let mut first = true;
573
- for (key, child) in pairs {
574
- let prefix = if first { "- " } else { " " };
575
- if child.is_empty_list() {
576
- lines.push(format!("{pad}{prefix}{key}: []"));
577
- } else if child.is_empty_map() {
578
- lines.push(format!("{pad}{prefix}{key}: {{}}"));
579
- } else if child.is_collection() {
580
- lines.push(format!("{pad}{prefix}{key}:"));
581
- lines.extend(dump(child, indent + 4));
582
- } else {
583
- // 注意:此分支**不**对多行字符串做 `|`,与 Python 一致。
584
- lines.push(format!("{pad}{prefix}{key}: {}", format_scalar(child)));
585
- }
586
- first = false;
587
- }
588
- }
589
- Value::List(_) => {
590
- lines.push(format!("{pad}-"));
591
- lines.extend(dump(item, indent + 2));
592
- }
593
- _ => {
594
- lines.push(format!("{pad}- {}", format_scalar(item)));
595
- }
596
- }
597
- }
598
- lines
599
- }
600
- _ => vec![format!("{pad}{}", format_scalar(value))],
601
- }
602
- }
603
-
604
- /// 移植 `_format_scalar`。非 None/bool/int → `json.dumps(str(value), ensure_ascii=False)`。
605
- fn format_scalar(value: &Value) -> String {
606
- match value {
607
- Value::Null => "null".to_string(),
608
- Value::Bool(true) => "true".to_string(),
609
- Value::Bool(false) => "false".to_string(),
610
- Value::Int(n) => n.to_string(),
611
- Value::Float(f) => json_quote(&py_float_str(*f)),
612
- Value::Str(s) => json_quote(s),
613
- // collection / empty 由 dump() 的上层分支拦截;此处理论不可达,保守按 str 化。
614
- Value::List(_) | Value::Map(_) => json_quote("[object]"),
615
- }
616
- }
617
-
618
- /// `json.dumps(s, ensure_ascii=False)`:Rust `serde_json` 的字符串转义与 Python 对齐
619
- /// (`\b \f \n \r \t`、控制字符 `\uXXXX`、`/` 不转义、非 ASCII 原样保留)。
620
- fn json_quote(s: &str) -> String {
621
- // serde_json::to_string 对 &str 不会失败(无 IO),但 §10 禁 unwrap:回退为手工引号。
622
- serde_json::to_string(s).unwrap_or_else(|_| format!("\"{s}\""))
623
- }
624
-
625
- /// Python `str(float)`:对本语料(仅 JSON 路径偶发)足够。整数值浮点带 `.0`。
626
- fn py_float_str(f: f64) -> String {
627
- if f.is_nan() {
628
- return "nan".to_string();
629
- }
630
- if f.is_infinite() {
631
- return if f > 0.0 { "inf" } else { "-inf" }.to_string();
632
- }
633
- if f == f.trunc() && f.abs() < 1e16 {
634
- return format!("{f:.1}");
635
- }
636
- // Rust 默认 `{}` 浮点格式化给最短往返表示,与 Python repr/str 在常见小数上一致。
637
- format!("{f}")
638
- }
639
-
640
- // ---------------------------------------------------------------------------
641
- // helpers
642
- // ---------------------------------------------------------------------------
643
-
644
- /// `_content`:非空且非 `#` 开头(`strip()` 后)。
645
- fn content(line: &str) -> bool {
646
- let s = line.trim();
647
- !s.is_empty() && !s.starts_with('#')
648
- }
649
-
650
- fn skip_blank(lines: &[&str], mut index: usize) -> usize {
651
- while index < lines.len() && !content(lines[index]) {
652
- index += 1;
653
- }
654
- index
655
- }
656
-
657
- /// `_indent`:前导**空格**数(`lstrip(" ")` 只剥空格,不含 tab)。
658
- fn line_indent(line: &str) -> usize {
659
- line.len() - line.trim_start_matches(' ').len()
660
- }
661
-
662
- /// `_split_key_value`:无 `:` 报错;否则按首个 `:` 切,两侧 strip。
663
- fn split_key_value(stripped: &str, index: usize) -> Result<(String, String), ModelError> {
664
- match stripped.split_once(':') {
665
- None => Err(ModelError::Validation(format!(
666
- "expected key: value at line {}",
667
- index + 1
668
- ))),
669
- Some((key, raw)) => Ok((key.trim().to_string(), raw.trim().to_string())),
670
- }
671
- }
672
-
673
- /// `_looks_like_key_value`:含 `:`,且首个 `:` 之前的 key 非空且只由
674
- /// 字母数字 / `_` / `-` 组成。
675
- fn looks_like_key_value(text: &str) -> bool {
676
- match text.split_once(':') {
677
- None => false,
678
- Some((key, _)) => {
679
- !key.is_empty()
680
- && key
681
- .chars()
682
- .all(|c| c.is_alphanumeric() || c == '_' || c == '-')
683
- }
684
- }
685
- }
686
-
687
- /// Python `str.rstrip()`(无参):剥尾随空白(空格 / `\t` / `\n` / `\r` / `\f` / `\v` 等)。
688
- fn py_rstrip(s: &str) -> &str {
689
- s.trim_end_matches(|c: char| c.is_whitespace())
690
- }
691
-
692
- /// Python `str.rstrip("\n")`:仅剥尾随换行符。
693
- fn py_rstrip_newlines(s: &str) -> &str {
694
- s.trim_end_matches('\n')
695
- }
696
-
697
- /// Python `str.splitlines()`(用于 `_dump` 的 block scalar 拆行)。
698
- fn py_splitlines(s: &str) -> Vec<&str> {
699
- if s.is_empty() {
700
- return Vec::new();
701
- }
702
- let mut out: Vec<&str> = Vec::new();
703
- for part in s.split('\n') {
704
- out.push(part.strip_suffix('\r').unwrap_or(part));
705
- }
706
- if s.ends_with('\n') {
707
- out.pop();
708
- }
709
- out
710
- }
711
-
712
- /// 取 `line[indent:]`(字节切片,复刻 Python 切片)。语料缩进与正文为 ASCII/UTF-8,
713
- /// 缩进位为空格 → `indent` 落在字符边界。越界则返空串。
714
- fn slice_from_byte(line: &str, indent: usize) -> String {
715
- if indent >= line.len() {
716
- return String::new();
717
- }
718
- if line.is_char_boundary(indent) {
719
- line[indent..].to_string()
720
- } else {
721
- // 不在字符边界(理论上不会发生,因缩进恒为空格):保守按字符跳过 indent 个码点。
722
- line.chars().skip(indent).collect()
723
- }
724
- }
725
-
726
- // ---------------------------------------------------------------------------
727
- // JSON 顶层路径:用 serde 访问者把 JSON 直接读成有序 Value(保留键序)
728
- // ---------------------------------------------------------------------------
729
-
730
- impl<'de> Deserialize<'de> for Value {
731
- fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
732
- where
733
- D: Deserializer<'de>,
734
- {
735
- struct ValueVisitor;
736
-
737
- impl<'de> Visitor<'de> for ValueVisitor {
738
- type Value = Value;
739
-
740
- fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
741
- f.write_str("a JSON value")
742
- }
743
-
744
- fn visit_unit<E>(self) -> Result<Value, E> {
745
- Ok(Value::Null)
746
- }
747
- fn visit_none<E>(self) -> Result<Value, E> {
748
- Ok(Value::Null)
749
- }
750
- fn visit_bool<E>(self, v: bool) -> Result<Value, E> {
751
- Ok(Value::Bool(v))
752
- }
753
- fn visit_i64<E>(self, v: i64) -> Result<Value, E> {
754
- Ok(Value::Int(v))
755
- }
756
- fn visit_u64<E>(self, v: u64) -> Result<Value, E>
757
- where
758
- E: de::Error,
759
- {
760
- i64::try_from(v)
761
- .map(Value::Int)
762
- .map_err(|_| de::Error::custom("integer out of i64 range"))
763
- }
764
- fn visit_f64<E>(self, v: f64) -> Result<Value, E> {
765
- Ok(Value::Float(v))
766
- }
767
- fn visit_str<E>(self, v: &str) -> Result<Value, E> {
768
- Ok(Value::Str(v.to_string()))
769
- }
770
- fn visit_string<E>(self, v: String) -> Result<Value, E> {
771
- Ok(Value::Str(v))
772
- }
773
- fn visit_seq<A>(self, mut seq: A) -> Result<Value, A::Error>
774
- where
775
- A: SeqAccess<'de>,
776
- {
777
- let mut items: Vec<Value> = Vec::new();
778
- while let Some(v) = seq.next_element()? {
779
- items.push(v);
780
- }
781
- Ok(Value::List(items))
782
- }
783
- fn visit_map<A>(self, mut map: A) -> Result<Value, A::Error>
784
- where
785
- A: MapAccess<'de>,
786
- {
787
- // 访问者按源文档顺序遍历 → 保留 JSON 键序(serde_json 默认 BTreeMap
788
- // 会乱序,故此处不经 serde_json::Value)。
789
- let mut pairs: Vec<(String, Value)> = Vec::new();
790
- while let Some((k, v)) = map.next_entry::<String, Value>()? {
791
- insert_ordered(&mut pairs, k, v);
792
- }
793
- Ok(Value::Map(pairs))
794
- }
795
- }
796
-
797
- deserializer.deserialize_any(ValueVisitor)
798
- }
799
- }
800
-
801
- #[cfg(test)]
802
- mod tests;