@danceiny/gotry 0.0.1-rc.9 → 0.2.0-rc.28

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 (533) hide show
  1. package/README.md +172 -219
  2. package/README.zh-CN.md +222 -0
  3. package/bin/gotry-backend.js +53 -0
  4. package/bin/gotry-booking-copilot.js +53 -0
  5. package/bin/gotry-bootstrap.js +1788 -0
  6. package/bin/gotry-inner.js +733 -83
  7. package/bin/gotry-process-liveness.d.ts +27 -0
  8. package/bin/gotry-process-liveness.js +97 -0
  9. package/bin/gotry-runtime-resolution.d.ts +27 -0
  10. package/bin/gotry-runtime-resolution.js +49 -0
  11. package/bin/gotry.js +1 -1
  12. package/client/client.js +203 -0
  13. package/cordis.gotry-patch.yml +80 -56
  14. package/data/airline-airports.json +39 -0
  15. package/data/stations-12306-verify.json +524 -0
  16. package/dist/capabilities/agent-reach-deep.js +45 -122
  17. package/dist/capabilities/agent-reach.js +101 -146
  18. package/dist/capabilities/anything.js +161 -94
  19. package/dist/capabilities/artifacts.js +370 -0
  20. package/dist/capabilities/channel-health.js +131 -0
  21. package/dist/capabilities/channel-registry.js +256 -0
  22. package/dist/capabilities/doctor.js +553 -0
  23. package/dist/capabilities/effect.js +394 -0
  24. package/dist/capabilities/external-event.js +149 -0
  25. package/dist/capabilities/fact-log.js +55 -0
  26. package/dist/capabilities/flyai-config.js +337 -0
  27. package/dist/capabilities/flyai.js +947 -110
  28. package/dist/capabilities/fx-contract.js +293 -0
  29. package/dist/capabilities/geo-atlas.js +246 -0
  30. package/dist/capabilities/ground-transfer.js +676 -0
  31. package/dist/capabilities/hbcli.js +260 -123
  32. package/dist/capabilities/hotelbyte-transaction.js +194 -0
  33. package/dist/capabilities/incident-log.js +131 -61
  34. package/dist/capabilities/itinerary-artifact.js +190 -0
  35. package/dist/capabilities/itinerary-deck-artifact.js +194 -0
  36. package/dist/capabilities/itinerary-deck-export.js +339 -0
  37. package/dist/capabilities/lavish-local.js +924 -0
  38. package/dist/capabilities/model-override.js +38 -0
  39. package/dist/capabilities/opensky.js +54 -43
  40. package/dist/capabilities/provider-detail-sanitize.js +64 -0
  41. package/dist/capabilities/resilience.js +191 -0
  42. package/dist/capabilities/route-provider-conformance.js +341 -0
  43. package/dist/capabilities/session/action-cache.js +50 -44
  44. package/dist/capabilities/session/adapters/ctrip-flight.js +120 -62
  45. package/dist/capabilities/session/adapters/ctrip-hotel.js +222 -0
  46. package/dist/capabilities/session/adapters/dida-portal.js +274 -0
  47. package/dist/capabilities/session/adapters/meituan-local.js +35 -54
  48. package/dist/capabilities/session/adapters/rail-12306.js +342 -0
  49. package/dist/capabilities/session/benchmark.js +189 -0
  50. package/dist/capabilities/session/bridge-ledger.js +224 -0
  51. package/dist/capabilities/session/extension-bridge.js +636 -0
  52. package/dist/capabilities/session/extension-channel.js +109 -0
  53. package/dist/capabilities/session/extension-distribution.js +230 -0
  54. package/dist/capabilities/session/extract.js +31 -21
  55. package/dist/capabilities/session/golden-score.js +114 -0
  56. package/dist/capabilities/session/health-watch.js +215 -0
  57. package/dist/capabilities/session/read-guard.js +75 -24
  58. package/dist/capabilities/session/static-flight-golden.js +150 -0
  59. package/dist/capabilities/session/transport.js +97 -83
  60. package/dist/capabilities/session/wizard.js +117 -0
  61. package/dist/capabilities/session-consent.js +178 -0
  62. package/dist/capabilities/session-login.js +170 -0
  63. package/dist/capabilities/session-search.js +635 -44
  64. package/dist/capabilities/spawn-bounded.js +203 -0
  65. package/dist/capabilities/sponsor-plugin.js +341 -0
  66. package/dist/capabilities/visa-policy.js +140 -0
  67. package/dist/capabilities/weather.js +243 -138
  68. package/dist/data/session-golden-20.json +25 -0
  69. package/dist/data/sf-golden-manifest.json +103 -0
  70. package/dist/data/sf-static-routes.json +91 -0
  71. package/dist/scripts/action-cache-tests.js +24 -59
  72. package/dist/scripts/agent-planning-turn-deadline-e2e.js +242 -0
  73. package/dist/scripts/agent-planning-turn-deadline-tests.js +185 -0
  74. package/dist/scripts/agent-reach-deep-tests.js +30 -40
  75. package/dist/scripts/agent-reach-error-tests.js +354 -0
  76. package/dist/scripts/agent-reach-tests.js +26 -18
  77. package/dist/scripts/agent-reach-wrapper-tests.js +50 -50
  78. package/dist/scripts/anything-path-measure-tests.js +133 -0
  79. package/dist/scripts/anything-path-measure.js +150 -0
  80. package/dist/scripts/anything-tests.js +250 -60
  81. package/dist/scripts/artifact-client-contract-tests.js +220 -0
  82. package/dist/scripts/artifacts-capability-tests.js +727 -0
  83. package/dist/scripts/async-collect.js +50 -11
  84. package/dist/scripts/benchmark-environment-bridge-e2e.js +741 -0
  85. package/dist/scripts/benchmark-environment-bridge-tests.js +1452 -0
  86. package/dist/scripts/booking-copilot-availability-ledger-binding-tests.js +126 -0
  87. package/dist/scripts/booking-copilot-availability-policy-tests.js +265 -0
  88. package/dist/scripts/booking-copilot-bin-proof-tests.js +66 -0
  89. package/dist/scripts/booking-copilot-cleanup-proof-helper.js +76 -0
  90. package/dist/scripts/booking-copilot-crossrepo-fixture-server.js +144 -0
  91. package/dist/scripts/booking-copilot-dsh-core-proof-tests.js +424 -0
  92. package/dist/scripts/booking-copilot-dsh-planner-proof-tests.js +2839 -0
  93. package/dist/scripts/booking-copilot-dsh-plugin-proof-tests.js +309 -0
  94. package/dist/scripts/booking-copilot-dsh-readiness-proof.js +238 -0
  95. package/dist/scripts/booking-copilot-dsh-warmer-proof.js +126 -0
  96. package/dist/scripts/booking-copilot-event-sequence-concurrency-proof-tests.js +156 -0
  97. package/dist/scripts/booking-copilot-gap-code-contract-proof-tests.js +70 -0
  98. package/dist/scripts/booking-copilot-intent-proof-tests.js +422 -0
  99. package/dist/scripts/booking-copilot-operation-ledger-concurrency-proof-tests.js +184 -0
  100. package/dist/scripts/booking-copilot-planner-live-probe.js +95 -0
  101. package/dist/scripts/booking-copilot-proof-runtime.js +42 -0
  102. package/dist/scripts/booking-copilot-receipt-ledger-concurrency-proof-tests.js +210 -0
  103. package/dist/scripts/booking-copilot-runtime-proof-tests.js +2349 -0
  104. package/dist/scripts/booking-copilot-server-proof-tests.js +784 -0
  105. package/dist/scripts/booking-copilot-startup-proof-tests.js +94 -0
  106. package/dist/scripts/booking-executor-tests.js +80 -0
  107. package/dist/scripts/booking-recovery-chain-tests.js +182 -0
  108. package/dist/scripts/booking-saga-tests.js +125 -0
  109. package/dist/scripts/booking-surface-contract-proof-tests.js +212 -0
  110. package/dist/scripts/bootstrap-tests.js +1549 -0
  111. package/dist/scripts/bridge-events-tests.js +239 -0
  112. package/dist/scripts/bridge-ledger-tests.js +428 -0
  113. package/dist/scripts/build-changelog.js +238 -0
  114. package/dist/scripts/build-metrics-report.js +331 -0
  115. package/dist/scripts/changelog-tests.js +118 -0
  116. package/dist/scripts/channel-probe-tests.js +103 -0
  117. package/dist/scripts/channel-probe.js +169 -0
  118. package/dist/scripts/channel-registry-tests.js +208 -0
  119. package/dist/scripts/city-scenario-tier-tests.js +234 -0
  120. package/dist/scripts/companion-tests.js +25 -70
  121. package/dist/scripts/dida-cookie-probe.js +87 -0
  122. package/dist/scripts/dida-runner-stop-tests.js +311 -0
  123. package/dist/scripts/dida-sw-probe.js +114 -0
  124. package/dist/scripts/diff-test.js +17 -12
  125. package/dist/scripts/doctor-tests.js +600 -0
  126. package/dist/scripts/drill-multiuser-ledger-tests.js +1076 -0
  127. package/dist/scripts/drill-sdk-descendant-cleanup-tests.js +606 -0
  128. package/dist/scripts/drill-w2a-sensor-tests.js +788 -0
  129. package/dist/scripts/dsh-artifact-e2e.js +279 -0
  130. package/dist/scripts/dsh-artifact-web-e2e.js +675 -0
  131. package/dist/scripts/dsh-http-proxy-sse-proof.js +90 -0
  132. package/dist/scripts/dsh-llm-tests.js +437 -0
  133. package/dist/scripts/dsh-runtime-closure-tests.js +182 -0
  134. package/dist/scripts/dsh-runtime-closure.js +162 -0
  135. package/dist/scripts/dsh-session-v3-migration-proof.js +109 -0
  136. package/dist/scripts/dsh-subprocess-local-proof.js +150 -0
  137. package/dist/scripts/dsh-target-closure-proof.js +178 -0
  138. package/dist/scripts/effect-tests.js +539 -0
  139. package/dist/scripts/engine-run.js +1 -3
  140. package/dist/scripts/engine-tests.js +16 -10
  141. package/dist/scripts/evaluation-cadence-tests.js +174 -0
  142. package/dist/scripts/evaluation-contract-tests.js +268 -0
  143. package/dist/scripts/extension-distribution-cli.js +39 -0
  144. package/dist/scripts/extension-distribution-tests.js +443 -0
  145. package/dist/scripts/extension-tests.js +988 -0
  146. package/dist/scripts/external-event-tests.js +350 -0
  147. package/dist/scripts/fact-gate-tests.js +869 -0
  148. package/dist/scripts/fixtures/extension-bridge-unref-child.mjs +21 -0
  149. package/dist/scripts/flight-hotel-anchor-363-registered-e2e.js +169 -0
  150. package/dist/scripts/flight-malformed-tests.js +159 -0
  151. package/dist/scripts/flyai-setup-tests.js +228 -0
  152. package/dist/scripts/flyai-setup-tool-tests.js +54 -0
  153. package/dist/scripts/flyai-tests.js +692 -0
  154. package/dist/scripts/flyai-tool-registration-contract-tests.js +91 -0
  155. package/dist/scripts/fx-contract-tests.js +201 -0
  156. package/dist/scripts/g5-guard-tests.js +150 -0
  157. package/dist/scripts/g5-guard.js +193 -0
  158. package/dist/scripts/gen-lunar-anchors.js +106 -0
  159. package/dist/scripts/geo-atlas-tests.js +283 -0
  160. package/dist/scripts/gotry-backend-kernel-tests.js +206 -0
  161. package/dist/scripts/gotry-try-demo-tests.js +79 -0
  162. package/dist/scripts/gotry-try-demo.js +49 -0
  163. package/dist/scripts/ground-transfer-tests.js +956 -0
  164. package/dist/scripts/hbcli-e2e-tests.js +159 -0
  165. package/dist/scripts/hbcli-live-optin-tests.js +96 -0
  166. package/dist/scripts/hbcli-release-contract-tests.js +122 -0
  167. package/dist/scripts/hbcli-tests.js +121 -69
  168. package/dist/scripts/health-watch-cli.js +73 -0
  169. package/dist/scripts/hotel-date-gate-tests.js +496 -0
  170. package/dist/scripts/hotelbyte-reconcile-tests.js +141 -0
  171. package/dist/scripts/hotelbyte-spawn-e2e-tests.js +373 -0
  172. package/dist/scripts/i18n-tests.js +41 -0
  173. package/dist/scripts/incident-tests.js +281 -87
  174. package/dist/scripts/issue-194-job-id-guard-tests.js +106 -0
  175. package/dist/scripts/issue-233-cancel-refund-commission-tests.js +392 -0
  176. package/dist/scripts/issue-271-liveness-tests.js +569 -0
  177. package/dist/scripts/issue-289-model-retry-real-tests.js +296 -0
  178. package/dist/scripts/issue-289-model-retry-tests.js +441 -0
  179. package/dist/scripts/issue-289-web-retry-e2e.js +630 -0
  180. package/dist/scripts/issue-338-home-city-e2e.js +577 -0
  181. package/dist/scripts/issue343-real-entry-e2e.js +160 -0
  182. package/dist/scripts/issue436-persisted-routing-e2e.js +247 -0
  183. package/dist/scripts/itinerary-artifact-tests.js +368 -0
  184. package/dist/scripts/itinerary-deck-artifact-tests.js +416 -0
  185. package/dist/scripts/itinerary-deck-export-tests.js +552 -0
  186. package/dist/scripts/itinerary-deck-tests.js +435 -0
  187. package/dist/scripts/itinerary-html-tests.js +426 -0
  188. package/dist/scripts/journey-tests.js +22 -27
  189. package/dist/scripts/kernel-manifest-evidence.js +109 -0
  190. package/dist/scripts/kernel-manifest-gate.js +126 -0
  191. package/dist/scripts/kernel-manifest-tests.js +212 -0
  192. package/dist/scripts/kernel-manifest-trace-entry.js +7 -0
  193. package/dist/scripts/kernel-manifest-trace-hook.mjs +28 -0
  194. package/dist/scripts/kernel-manifest.js +369 -0
  195. package/dist/scripts/lavish-local-tests.js +1226 -0
  196. package/dist/scripts/lavish-product-tools-tests.js +537 -0
  197. package/dist/scripts/ledger-repair-apply-tests.js +316 -0
  198. package/dist/scripts/ledger-repair-plan-tests.js +375 -0
  199. package/dist/scripts/ledger-tests.js +382 -246
  200. package/dist/scripts/ledger-workflow-crash.js +10 -20
  201. package/dist/scripts/m3-cohort-tests.js +714 -0
  202. package/dist/scripts/m3-cohort.js +310 -0
  203. package/dist/scripts/managed-dsh-cleanup-diagnostic-proof.js +184 -0
  204. package/dist/scripts/managed-dsh-close-failure-proof.js +172 -0
  205. package/dist/scripts/managed-dsh-run-port-proof.js +153 -0
  206. package/dist/scripts/managed-dsh-terminal-proof.js +252 -0
  207. package/dist/scripts/map-tools-vendor-package-proof.js +365 -0
  208. package/dist/scripts/memory-capture-tests.js +242 -61
  209. package/dist/scripts/memory-decay-tests.js +18 -52
  210. package/dist/scripts/memory-lifecycle-tests.js +657 -0
  211. package/dist/scripts/memory-lifecycle.js +196 -0
  212. package/dist/scripts/memory-metrics.js +24 -12
  213. package/dist/scripts/memory-value-report.js +631 -0
  214. package/dist/scripts/memory-value-tests.js +328 -0
  215. package/dist/scripts/metrics-report-tests.js +151 -0
  216. package/dist/scripts/model-override-e2e.js +137 -0
  217. package/dist/scripts/nightly-evidence-tests.js +203 -0
  218. package/dist/scripts/nightly-evidence.js +303 -0
  219. package/dist/scripts/nudge-digest.js +39 -28
  220. package/dist/scripts/observability-tests.js +381 -0
  221. package/dist/scripts/onboarding-tests.js +161 -0
  222. package/dist/scripts/opensky-check.js +18 -13
  223. package/dist/scripts/opensky-tests.js +28 -28
  224. package/dist/scripts/outcome-projection-tests.js +427 -0
  225. package/dist/scripts/persona-sim-tests.js +603 -0
  226. package/dist/scripts/persona-sim.js +1081 -0
  227. package/dist/scripts/persona-surface-guard-tests.js +49 -0
  228. package/dist/scripts/pnpm-dsh-closure-proof.js +17 -0
  229. package/dist/scripts/policy-anchor-359-registered-e2e.js +214 -0
  230. package/dist/scripts/price-drift-tests.js +340 -0
  231. package/dist/scripts/price-drift-watch.js +447 -0
  232. package/dist/scripts/probe-poi-tests.js +53 -45
  233. package/dist/scripts/product-metrics.js +483 -0
  234. package/dist/scripts/publish-preverify.js +110 -0
  235. package/dist/scripts/realtime-pricing-tests.js +76 -0
  236. package/dist/scripts/recall-tests.js +513 -0
  237. package/dist/scripts/replay-async.js +22 -18
  238. package/dist/scripts/replay-real.js +18 -18
  239. package/dist/scripts/replay.js +54 -82
  240. package/dist/scripts/route-provider-conformance-tests.js +391 -0
  241. package/dist/scripts/session-attach-diagnose.js +20 -20
  242. package/dist/scripts/session-attach-poc.js +34 -37
  243. package/dist/scripts/session-benchmark.js +180 -0
  244. package/dist/scripts/session-dida-live-e2e.js +199 -0
  245. package/dist/scripts/session-extract-tests.js +14 -35
  246. package/dist/scripts/session-link-tests.js +478 -0
  247. package/dist/scripts/session-login.js +27 -46
  248. package/dist/scripts/session-tests.js +796 -96
  249. package/dist/scripts/session-zone-crash.js +49 -0
  250. package/dist/scripts/session-zone-ledger-tests.js +432 -0
  251. package/dist/scripts/session-zone-observation-tests.js +492 -0
  252. package/dist/scripts/session-zone-observe.js +135 -0
  253. package/dist/scripts/session-zone-wiring-tests.js +566 -0
  254. package/dist/scripts/session-zones-tests.js +374 -0
  255. package/dist/scripts/sf-live-benchmark.js +367 -0
  256. package/dist/scripts/sf-live-challenge-stop-tests.js +453 -0
  257. package/dist/scripts/sf-live-cli-tests.js +92 -0
  258. package/dist/scripts/sf-live-options.js +46 -0
  259. package/dist/scripts/sf-manifest-tests.js +30 -0
  260. package/dist/scripts/sf-manifest.js +33 -0
  261. package/dist/scripts/sf-soft-score-tests.js +67 -0
  262. package/dist/scripts/sf-summary-tests.js +324 -0
  263. package/dist/scripts/sf-summary.js +525 -0
  264. package/dist/scripts/share-tests.js +432 -0
  265. package/dist/scripts/skeleton-check.js +16 -14
  266. package/dist/scripts/skeleton-integration-test.js +28 -11
  267. package/dist/scripts/skills-contract-tests.js +51 -46
  268. package/dist/scripts/smoke-session-gate-tests.js +21 -0
  269. package/dist/scripts/smoke.js +690 -246
  270. package/dist/scripts/spawn-bounded-abort-tests.js +244 -0
  271. package/dist/scripts/sponsor-reuse-tests.js +262 -0
  272. package/dist/scripts/state-cli-tests.js +226 -101
  273. package/dist/scripts/state-cli.js +565 -198
  274. package/dist/scripts/state-repair-cli.js +66 -0
  275. package/dist/scripts/state-repair-tests.js +140 -0
  276. package/dist/scripts/static-golden-tests.js +165 -0
  277. package/dist/scripts/time-eval-tests.js +212 -192
  278. package/dist/scripts/travel-timeline-tests.js +29 -93
  279. package/dist/scripts/turn-handoff-collect-tests.js +169 -0
  280. package/dist/scripts/turn-handoff-collect.js +161 -0
  281. package/dist/scripts/turn-policy-tests.js +55 -0
  282. package/dist/scripts/typed-contract-canary.js +176 -0
  283. package/dist/scripts/tz-resolver-sanity.js +50 -0
  284. package/dist/scripts/tz-resolver-tests.js +584 -0
  285. package/dist/scripts/unified-tests.js +60 -20
  286. package/dist/scripts/visa-policy-tests.js +62 -0
  287. package/dist/scripts/weather-tests.js +276 -41
  288. package/dist/scripts/wish-channel-gate-tests.js +54 -0
  289. package/dist/scripts/write-gate-tests.js +522 -0
  290. package/dist/scripts/z3-lifecycle-fault-tests.js +188 -0
  291. package/dist/scripts/z3-lifecycle-tests.js +170 -0
  292. package/dist/scripts/z3-race-repeat-tests.js +39 -0
  293. package/dist/scripts/z3-race-tests.js +46 -0
  294. package/dist/src/artifact-gate.js +829 -0
  295. package/dist/src/backend/kernel.js +91 -0
  296. package/dist/src/backend/modules/booking-copilot.js +92 -0
  297. package/dist/src/backend/modules/booking-executor.js +124 -0
  298. package/dist/src/backend/modules/session-search.js +551 -0
  299. package/dist/src/benchmark-agent-conformance.js +578 -0
  300. package/dist/src/benchmark-environment-bridge.js +515 -0
  301. package/dist/src/benchmark-headless-child-diagnostics.js +166 -0
  302. package/dist/src/benchmark-tool-isolation.js +151 -0
  303. package/dist/src/bookable-facts.js +533 -0
  304. package/dist/src/booking-saga.js +97 -0
  305. package/dist/src/booking-surface/availability-policy.js +697 -0
  306. package/dist/src/booking-surface/booking-intent.js +43 -0
  307. package/dist/src/booking-surface/cancel-refund-commission.js +379 -0
  308. package/dist/src/booking-surface/canonical-schema.js +116 -0
  309. package/dist/src/booking-surface/contracts.js +75 -0
  310. package/dist/src/booking-surface/dsh-planner.js +1854 -0
  311. package/dist/src/booking-surface/dsh-plugin.js +378 -0
  312. package/dist/src/booking-surface/dsh-worker.js +98 -0
  313. package/dist/src/booking-surface/error-codes.js +231 -0
  314. package/dist/src/booking-surface/index.js +9 -0
  315. package/dist/src/booking-surface/managed-dsh-cleanup-diagnostic.js +97 -0
  316. package/dist/src/booking-surface/managed-dsh-run-port.js +244 -0
  317. package/dist/src/booking-surface/profile.js +24 -0
  318. package/dist/src/booking-surface/recovery-chain.js +367 -0
  319. package/dist/src/booking-surface/runtime.js +1968 -0
  320. package/dist/src/booking-surface/server.js +674 -0
  321. package/dist/src/booking-surface/startup.js +168 -0
  322. package/dist/src/booking-surface/validation.js +261 -0
  323. package/dist/src/bridge.js +20 -13
  324. package/dist/src/city-scenario-tier.js +378 -0
  325. package/dist/src/companions.js +48 -74
  326. package/dist/src/contracts.js +21 -43
  327. package/dist/src/dsh-llm.js +171 -115
  328. package/dist/src/engine.js +276 -193
  329. package/dist/src/evaluation-cadence.js +97 -0
  330. package/dist/src/evaluation-contracts.js +283 -0
  331. package/dist/src/flight-pack-adapter.js +54 -0
  332. package/dist/src/flight-pack-contract.js +2 -0
  333. package/dist/src/flyai-setup-tool.js +70 -0
  334. package/dist/src/gotry-backend.js +125 -0
  335. package/dist/src/hotel-date-gate.js +118 -0
  336. package/dist/src/i18n.js +88 -0
  337. package/dist/src/index.js +2385 -881
  338. package/dist/src/itinerary-deck.js +139 -0
  339. package/dist/src/itinerary-doc-shared.js +661 -0
  340. package/dist/src/itinerary-html.js +131 -0
  341. package/dist/src/journey.js +155 -108
  342. package/dist/src/lavish-tools.js +400 -0
  343. package/dist/src/ledger-repair-apply.js +538 -0
  344. package/dist/src/ledger-repair-plan.js +463 -0
  345. package/dist/src/loop.js +331 -161
  346. package/dist/src/m3-cohort.js +1577 -0
  347. package/dist/src/memory-capture.js +180 -32
  348. package/dist/src/memory-decay.js +30 -14
  349. package/dist/src/memory-lifecycle.js +1310 -0
  350. package/dist/src/memory-utility.js +27 -40
  351. package/dist/src/mock-llm.js +36 -61
  352. package/dist/src/model.js +81 -36
  353. package/dist/src/outcome-projection.js +746 -0
  354. package/dist/src/realtime-pricing.js +103 -0
  355. package/dist/src/recall/card.js +74 -0
  356. package/dist/src/recall/evaluator.js +140 -0
  357. package/dist/src/recall/integration.js +17 -0
  358. package/dist/src/recall/tick.js +166 -0
  359. package/dist/src/session-link/plan-it-action.js +48 -0
  360. package/dist/src/session-link/session-link.js +248 -0
  361. package/dist/src/session-zone-ledger.js +312 -0
  362. package/dist/src/session-zone-observation.js +354 -0
  363. package/dist/src/session-zone-wiring.js +658 -0
  364. package/dist/src/session-zones.js +510 -0
  365. package/dist/src/share/adapters.js +51 -0
  366. package/dist/src/share/share-consent.js +76 -0
  367. package/dist/src/share/share-deck.js +58 -0
  368. package/dist/src/share/share-token.js +146 -0
  369. package/dist/src/slot-spec.js +84 -106
  370. package/dist/src/state-ledger.js +696 -524
  371. package/dist/src/state-repair.js +299 -0
  372. package/dist/src/subagent-job-id-guard.js +58 -0
  373. package/dist/src/time-anchor.js +231 -33
  374. package/dist/src/tool-packet.js +20 -8
  375. package/dist/src/travel-slots.js +58 -35
  376. package/dist/src/travel-timeline.js +44 -63
  377. package/dist/src/turn-deadline.js +287 -0
  378. package/dist/src/turn-policy.js +118 -0
  379. package/dist/src/tz-resolver.js +143 -0
  380. package/dist/src/unified.js +600 -360
  381. package/dist/src/wish-pool.js +42 -12
  382. package/dist/src/write-gate.js +495 -0
  383. package/dist/src/z3-shared.js +284 -0
  384. package/extension/README.md +21 -0
  385. package/extension/README.zh-CN.md +21 -0
  386. package/extension/background.js +463 -0
  387. package/extension/content-bridge.js +270 -0
  388. package/extension/content-main.js +111 -0
  389. package/extension/manifest.json +60 -0
  390. package/package.json +407 -14
  391. package/schemas/booking.intent.schema.json +193 -0
  392. package/schemas/booking.surface.schema.json +2622 -0
  393. package/ts/capabilities/agent-reach-deep.ts +114 -0
  394. package/ts/capabilities/agent-reach.ts +198 -0
  395. package/ts/capabilities/anything.ts +282 -0
  396. package/ts/capabilities/artifacts.ts +428 -0
  397. package/ts/capabilities/fact-log.ts +54 -0
  398. package/ts/capabilities/flyai-config.ts +388 -0
  399. package/ts/capabilities/flyai.ts +1274 -0
  400. package/ts/capabilities/hbcli.ts +253 -71
  401. package/ts/capabilities/incident-log.ts +88 -59
  402. package/ts/capabilities/itinerary-artifact.ts +214 -0
  403. package/ts/capabilities/itinerary-deck-artifact.ts +218 -0
  404. package/ts/capabilities/itinerary-deck-export.ts +378 -0
  405. package/ts/capabilities/opensky.ts +121 -0
  406. package/ts/capabilities/session/action-cache.ts +148 -0
  407. package/ts/capabilities/session/adapters/ctrip-flight.ts +181 -0
  408. package/ts/capabilities/session/adapters/ctrip-hotel.ts +238 -0
  409. package/ts/capabilities/session/adapters/dida-portal.ts +338 -0
  410. package/ts/capabilities/session/adapters/meituan-local.ts +70 -0
  411. package/ts/capabilities/session/adapters/rail-12306.ts +392 -0
  412. package/ts/capabilities/session/benchmark.ts +276 -0
  413. package/ts/capabilities/session/bridge-ledger.ts +333 -0
  414. package/ts/capabilities/session/extension-bridge.ts +794 -0
  415. package/ts/capabilities/session/extension-channel.ts +144 -0
  416. package/ts/capabilities/session/extension-distribution.ts +266 -0
  417. package/ts/capabilities/session/extract.ts +54 -0
  418. package/ts/capabilities/session/golden-score.ts +139 -0
  419. package/ts/capabilities/session/health-watch.ts +264 -0
  420. package/ts/capabilities/session/read-guard.ts +141 -0
  421. package/ts/capabilities/session/static-flight-golden.ts +209 -0
  422. package/ts/capabilities/session/transport.ts +146 -0
  423. package/ts/capabilities/session/wizard.ts +140 -0
  424. package/ts/capabilities/session-consent.ts +211 -0
  425. package/ts/capabilities/session-login.ts +208 -0
  426. package/ts/capabilities/session-search.ts +893 -0
  427. package/ts/capabilities/weather.ts +330 -0
  428. package/ts/dsh-runtime/vendor/README.md +68 -0
  429. package/ts/dsh-runtime/vendor/dsh-map-tools/LICENSE +21 -0
  430. package/ts/dsh-runtime/vendor/dsh-map-tools/README.en.md +405 -0
  431. package/ts/dsh-runtime/vendor/dsh-map-tools/README.md +404 -0
  432. package/ts/dsh-runtime/vendor/dsh-map-tools/client/client.js +1584 -0
  433. package/ts/dsh-runtime/vendor/dsh-map-tools/cordis.patch.yml +5 -0
  434. package/ts/dsh-runtime/vendor/dsh-map-tools/icon.svg +5 -0
  435. package/ts/dsh-runtime/vendor/dsh-map-tools/lib/clients/amap.js +595 -0
  436. package/ts/dsh-runtime/vendor/dsh-map-tools/lib/clients/nominatim.js +63 -0
  437. package/ts/dsh-runtime/vendor/dsh-map-tools/lib/clients/osrm.js +58 -0
  438. package/ts/dsh-runtime/vendor/dsh-map-tools/lib/clients/photon.js +55 -0
  439. package/ts/dsh-runtime/vendor/dsh-map-tools/lib/config-file.js +87 -0
  440. package/ts/dsh-runtime/vendor/dsh-map-tools/lib/config-route.js +131 -0
  441. package/ts/dsh-runtime/vendor/dsh-map-tools/lib/config.js +16 -0
  442. package/ts/dsh-runtime/vendor/dsh-map-tools/lib/geo.js +232 -0
  443. package/ts/dsh-runtime/vendor/dsh-map-tools/lib/index.js +120 -0
  444. package/ts/dsh-runtime/vendor/dsh-map-tools/lib/settings-ns.js +40 -0
  445. package/ts/dsh-runtime/vendor/dsh-map-tools/lib/staticmap-route.js +115 -0
  446. package/ts/dsh-runtime/vendor/dsh-map-tools/lib/tools/geocode.js +127 -0
  447. package/ts/dsh-runtime/vendor/dsh-map-tools/lib/tools/poi.js +84 -0
  448. package/ts/dsh-runtime/vendor/dsh-map-tools/lib/tools/routes.js +267 -0
  449. package/ts/dsh-runtime/vendor/dsh-map-tools/lib/types/clients/amap.d.ts +90 -0
  450. package/ts/dsh-runtime/vendor/dsh-map-tools/lib/types/clients/nominatim.d.ts +17 -0
  451. package/ts/dsh-runtime/vendor/dsh-map-tools/lib/types/clients/osrm.d.ts +15 -0
  452. package/ts/dsh-runtime/vendor/dsh-map-tools/lib/types/clients/photon.d.ts +22 -0
  453. package/ts/dsh-runtime/vendor/dsh-map-tools/lib/types/config-file.d.ts +33 -0
  454. package/ts/dsh-runtime/vendor/dsh-map-tools/lib/types/config-route.d.ts +23 -0
  455. package/ts/dsh-runtime/vendor/dsh-map-tools/lib/types/config.d.ts +23 -0
  456. package/ts/dsh-runtime/vendor/dsh-map-tools/lib/types/geo.d.ts +61 -0
  457. package/ts/dsh-runtime/vendor/dsh-map-tools/lib/types/index.d.ts +18 -0
  458. package/ts/dsh-runtime/vendor/dsh-map-tools/lib/types/settings-ns.d.ts +14 -0
  459. package/ts/dsh-runtime/vendor/dsh-map-tools/lib/types/staticmap-route.d.ts +31 -0
  460. package/ts/dsh-runtime/vendor/dsh-map-tools/lib/types/tools/geocode.d.ts +11 -0
  461. package/ts/dsh-runtime/vendor/dsh-map-tools/lib/types/tools/poi.d.ts +9 -0
  462. package/ts/dsh-runtime/vendor/dsh-map-tools/lib/types/tools/routes.d.ts +75 -0
  463. package/ts/dsh-runtime/vendor/dsh-map-tools/lib/types/types.d.ts +68 -0
  464. package/ts/dsh-runtime/vendor/dsh-map-tools/lib/types.js +16 -0
  465. package/ts/dsh-runtime/vendor/dsh-map-tools/package.json +97 -0
  466. package/ts/package.json +293 -3
  467. package/ts/scripts/async-collect.ts +91 -0
  468. package/ts/scripts/map-tools-vendor-package-proof.ts +404 -0
  469. package/ts/scripts/skeleton-check.ts +1 -1
  470. package/ts/scripts/skeleton-integration-test.ts +23 -1
  471. package/ts/scripts/state-cli.ts +586 -0
  472. package/ts/scripts/turn-handoff-collect.ts +178 -0
  473. package/ts/src/artifact-gate.ts +991 -0
  474. package/ts/src/benchmark-agent-conformance.ts +619 -0
  475. package/ts/src/benchmark-environment-bridge.ts +538 -0
  476. package/ts/src/benchmark-headless-child-diagnostics.ts +184 -0
  477. package/ts/src/benchmark-tool-isolation.ts +166 -0
  478. package/ts/src/bookable-facts.ts +837 -0
  479. package/ts/src/booking-saga.ts +133 -0
  480. package/ts/src/booking-surface/availability-policy.ts +522 -0
  481. package/ts/src/booking-surface/booking-intent.ts +86 -0
  482. package/ts/src/booking-surface/cancel-refund-commission.ts +488 -0
  483. package/ts/src/booking-surface/canonical-schema.js +116 -0
  484. package/ts/src/booking-surface/contracts.ts +475 -0
  485. package/ts/src/booking-surface/dsh-planner.ts +1949 -0
  486. package/ts/src/booking-surface/dsh-plugin.js +378 -0
  487. package/ts/src/booking-surface/dsh-worker.ts +110 -0
  488. package/ts/src/booking-surface/error-codes.ts +241 -0
  489. package/ts/src/booking-surface/index.ts +9 -0
  490. package/ts/src/booking-surface/managed-dsh-cleanup-diagnostic.ts +151 -0
  491. package/ts/src/booking-surface/managed-dsh-run-port.ts +273 -0
  492. package/ts/src/booking-surface/profile.ts +42 -0
  493. package/ts/src/booking-surface/recovery-chain.ts +409 -0
  494. package/ts/src/booking-surface/runtime.ts +1793 -0
  495. package/ts/src/booking-surface/server.ts +733 -0
  496. package/ts/src/booking-surface/startup.ts +201 -0
  497. package/ts/src/booking-surface/validation.ts +217 -0
  498. package/ts/src/companions.ts +113 -0
  499. package/ts/src/contracts.ts +17 -3
  500. package/ts/src/dsh-llm.ts +152 -17
  501. package/ts/src/flyai-setup-tool.ts +77 -0
  502. package/ts/src/index.ts +2123 -200
  503. package/ts/src/itinerary-deck.ts +189 -0
  504. package/ts/src/itinerary-doc-shared.ts +741 -0
  505. package/ts/src/itinerary-html.ts +171 -0
  506. package/ts/src/loop.ts +234 -26
  507. package/ts/src/memory-capture.ts +283 -0
  508. package/ts/src/memory-decay.ts +55 -0
  509. package/ts/src/memory-utility.ts +70 -0
  510. package/ts/src/mock-llm.ts +4 -8
  511. package/ts/src/model.ts +88 -2
  512. package/ts/src/recall/card.ts +106 -0
  513. package/ts/src/recall/evaluator.ts +170 -0
  514. package/ts/src/recall/integration.ts +35 -0
  515. package/ts/src/recall/tick.ts +213 -0
  516. package/ts/src/session-link/plan-it-action.ts +78 -0
  517. package/ts/src/session-link/session-link.ts +275 -0
  518. package/ts/src/share/adapters.ts +93 -0
  519. package/ts/src/share/share-consent.ts +105 -0
  520. package/ts/src/share/share-deck.ts +85 -0
  521. package/ts/src/share/share-token.ts +166 -0
  522. package/ts/src/slot-spec.ts +172 -0
  523. package/ts/src/state-ledger.ts +1166 -0
  524. package/ts/src/subagent-job-id-guard.ts +72 -0
  525. package/ts/src/time-anchor.ts +338 -0
  526. package/ts/src/tool-packet.ts +32 -0
  527. package/ts/src/travel-slots.ts +219 -0
  528. package/ts/src/travel-timeline.ts +83 -0
  529. package/ts/src/turn-deadline.ts +366 -0
  530. package/ts/src/turn-policy.ts +154 -0
  531. package/ts/src/unified.ts +444 -105
  532. package/ts/src/wish-pool.ts +79 -0
  533. package/dist/scripts/session-attach-wait.js +0 -41
@@ -0,0 +1,578 @@
1
+ /** Provider-neutral execution and terminal contract for benchmark agents. */
2
+ import { createUserMessage } from '@deepseek-ai/dsh-llm';
3
+ import { classifyBenchmarkTurnEnd, createBenchmarkDiagnosticArbiter, emitBenchmarkChildDiagnostic, } from './benchmark-headless-child-diagnostics.js';
4
+ export const MAX_CONFORMANCE_RETRIES = 1;
5
+ export const BENCHMARK_BRIDGE_CALL_REQUIRED = 'BENCHMARK_BRIDGE_CALL_REQUIRED';
6
+ export const BENCHMARK_BRIDGE_CALL_FAILED = 'BENCHMARK_BRIDGE_CALL_FAILED';
7
+ export const BENCHMARK_BRIDGE_TIMED_OUT = 'BENCHMARK_BRIDGE_TIMED_OUT';
8
+ export const BENCHMARK_BRIDGE_RUNNER_FAILED = 'BENCHMARK_BRIDGE_RUNNER_FAILED';
9
+ export const BENCHMARK_BRIDGE_SPAWN_FAILED = 'BENCHMARK_BRIDGE_SPAWN_FAILED';
10
+ export const BENCHMARK_BRIDGE_OUTPUT_TRUNCATED = 'BENCHMARK_BRIDGE_OUTPUT_TRUNCATED';
11
+ export const BENCHMARK_TERMINAL_INVALID = 'BENCHMARK_TERMINAL_INVALID';
12
+ export const BENCHMARK_BRIDGE_RETRY_CALL_NOT_ALLOWED = 'BENCHMARK_BRIDGE_RETRY_CALL_NOT_ALLOWED';
13
+ export const BENCHMARK_CONFORMANCE_STATE_UNAVAILABLE = 'BENCHMARK_CONFORMANCE_STATE_UNAVAILABLE';
14
+ const IDENTIFIER = /^[A-Za-z][A-Za-z0-9_.-]*$/;
15
+ const MAX_TERMINAL_BYTES = 1024 * 1024;
16
+ const BENCHMARK_TOOL_RESULT_SCHEMA_VERSION = 'gotry_benchmark_tool_result_v1';
17
+ const BENCHMARK_DOMAIN_RECOVERIES = new Set(['none', 'retry_same', 'revise_arguments', 'choose_alternative']);
18
+ // Round 12(issue #215):terminal body schema 是「无数据值的 closed 结构合同」——
19
+ // 只允许结构关键字(type/properties/required/additionalProperties/items),enum/
20
+ // const/example/default 等可夹带数据值的注解面一律禁止,对象必须 additionalProperties:
21
+ // false,大小/深度/节点数有界。校验语义 fail-closed:不补键、不删多余键、不转类型。
22
+ const TERMINAL_BODY_SCHEMA_MAX_BYTES = 16 * 1024;
23
+ const TERMINAL_BODY_SCHEMA_MAX_DEPTH = 8;
24
+ const TERMINAL_BODY_SCHEMA_MAX_NODES = 256;
25
+ const TERMINAL_BODY_SCHEMA_MAX_PROPERTIES = 256;
26
+ const TERMINAL_BODY_SCALAR_TYPES = new Set(['string', 'number', 'integer', 'boolean', 'null']);
27
+ const TERMINAL_BODY_VALUE_MAX_NODES = 10_000;
28
+ const TERMINAL_BODY_VALUE_MAX_DEPTH = 24;
29
+ function plainObject(value) {
30
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
31
+ }
32
+ export function validateTerminalOutputConfig(value) {
33
+ if (!plainObject(value))
34
+ return false;
35
+ const keys = Object.keys(value).sort();
36
+ return JSON.stringify(keys) === JSON.stringify(['body_schema', 'max_bytes', 'tag'])
37
+ && typeof value.tag === 'string'
38
+ && IDENTIFIER.test(value.tag)
39
+ && typeof value.max_bytes === 'number'
40
+ && Number.isInteger(value.max_bytes)
41
+ && value.max_bytes >= 1
42
+ && value.max_bytes <= MAX_TERMINAL_BYTES
43
+ && validateTerminalBodySchema(value.body_schema);
44
+ }
45
+ /** Accept only the closed structural dialect: exact keyword sets per node, bounded size. */
46
+ export function validateTerminalBodySchema(value) {
47
+ let serialized;
48
+ try {
49
+ serialized = JSON.stringify(value);
50
+ }
51
+ catch {
52
+ return false;
53
+ }
54
+ if (typeof serialized !== 'string' || Buffer.byteLength(serialized, 'utf8') > TERMINAL_BODY_SCHEMA_MAX_BYTES)
55
+ return false;
56
+ const pending = [{ node: value, depth: 0 }];
57
+ const seen = new Set();
58
+ let nodes = 0;
59
+ let properties = 0;
60
+ while (pending.length > 0) {
61
+ const { node, depth } = pending.pop();
62
+ if (!plainObject(node) || seen.has(node) || ++nodes > TERMINAL_BODY_SCHEMA_MAX_NODES || depth > TERMINAL_BODY_SCHEMA_MAX_DEPTH)
63
+ return false;
64
+ seen.add(node);
65
+ const type = node.type;
66
+ if (type === 'object') {
67
+ if (!exactKeys(node, ['type', 'properties', 'required', 'additionalProperties'])
68
+ || !plainObject(node.properties)
69
+ || !Array.isArray(node.required)
70
+ || node.additionalProperties !== false)
71
+ return false;
72
+ const entries = Object.entries(node.properties);
73
+ properties += entries.length;
74
+ if (properties > TERMINAL_BODY_SCHEMA_MAX_PROPERTIES
75
+ || entries.some(([key, child]) => key.length === 0 || key.length > 64 || !plainObject(child)))
76
+ return false;
77
+ if (node.required.length > entries.length
78
+ || new Set(node.required).size !== node.required.length
79
+ || node.required.some(key => typeof key !== 'string' || !Object.hasOwn(node.properties, key)))
80
+ return false;
81
+ for (const [, child] of entries)
82
+ pending.push({ node: child, depth: depth + 1 });
83
+ continue;
84
+ }
85
+ if (type === 'array') {
86
+ if (!exactKeys(node, ['type', 'items']) || !plainObject(node.items))
87
+ return false;
88
+ pending.push({ node: node.items, depth: depth + 1 });
89
+ continue;
90
+ }
91
+ if (typeof type !== 'string' || !TERMINAL_BODY_SCALAR_TYPES.has(type) || !exactKeys(node, ['type']))
92
+ return false;
93
+ }
94
+ return plainObject(value) && value.type === 'object';
95
+ }
96
+ function exactKeys(value, allowed) {
97
+ return Object.keys(value).every(key => allowed.includes(key));
98
+ }
99
+ /** Strict structural validation: exact keys, exact types, no coercion, no autofix. */
100
+ export function validateTerminalBodyValue(value, schema) {
101
+ const pending = [{ value, schema, depth: 0 }];
102
+ let nodes = 0;
103
+ while (pending.length > 0) {
104
+ const current = pending.pop();
105
+ if (++nodes > TERMINAL_BODY_VALUE_MAX_NODES || current.depth > TERMINAL_BODY_VALUE_MAX_DEPTH)
106
+ return false;
107
+ const { schema: node } = current;
108
+ if (node.type === 'object') {
109
+ const record = current.value;
110
+ if (!plainObject(record))
111
+ return false;
112
+ const properties = node.properties;
113
+ for (const key of node.required) {
114
+ if (!Object.hasOwn(record, key))
115
+ return false;
116
+ }
117
+ for (const [key, child] of Object.entries(record)) {
118
+ const childSchema = properties[key];
119
+ if (!childSchema)
120
+ return false;
121
+ pending.push({ value: child, schema: childSchema, depth: current.depth + 1 });
122
+ }
123
+ continue;
124
+ }
125
+ if (node.type === 'array') {
126
+ if (!Array.isArray(current.value))
127
+ return false;
128
+ for (const item of current.value)
129
+ pending.push({ value: item, schema: node.items, depth: current.depth + 1 });
130
+ continue;
131
+ }
132
+ if (node.type === 'string') {
133
+ if (typeof current.value !== 'string')
134
+ return false;
135
+ continue;
136
+ }
137
+ if (node.type === 'boolean') {
138
+ if (typeof current.value !== 'boolean')
139
+ return false;
140
+ continue;
141
+ }
142
+ if (node.type === 'null') {
143
+ if (current.value !== null)
144
+ return false;
145
+ continue;
146
+ }
147
+ if (node.type === 'integer') {
148
+ if (typeof current.value !== 'number' || !Number.isSafeInteger(current.value))
149
+ return false;
150
+ continue;
151
+ }
152
+ if (typeof current.value !== 'number' || !Number.isFinite(current.value))
153
+ return false;
154
+ }
155
+ return true;
156
+ }
157
+ /** Deterministic single-source structural outline projected into system prompt and correction alike. */
158
+ export function terminalSchemaOutline(schema) {
159
+ const render = (node, depth) => {
160
+ if (depth > TERMINAL_BODY_SCHEMA_MAX_DEPTH)
161
+ return '…';
162
+ if (node.type === 'object') {
163
+ const properties = node.properties;
164
+ const required = new Set(node.required);
165
+ const parts = Object.entries(properties).map(([key, child]) => `${required.has(key) ? '' : '?'}${key}:${render(child, depth + 1)}`);
166
+ return `object{${parts.join(',')}}`;
167
+ }
168
+ if (node.type === 'array')
169
+ return `array<${render(node.items, depth + 1)}>`;
170
+ return node.type;
171
+ };
172
+ return render(schema, 0);
173
+ }
174
+ function invalidTerminal() {
175
+ return { ok: false, error: 'invalid_terminal_output' };
176
+ }
177
+ /** 剥离推理模型的思考标签对(如 MiniMax/DeepSeek 的 <think>…</think>):当代模型
178
+ * 即便被明令「只回终态包」也会以思考块前缀输出——不剥则严格终态门对推理模型
179
+ * 结构性失效(Round 9 治理面实测)。只剥配对的推理标签本体,其余前后缀仍 fail-closed。 */
180
+ function stripReasoningBlocks(raw) {
181
+ return raw.replace(/<think>[\s\S]*?<\/think>\s*/gi, '');
182
+ }
183
+ /** Parse exactly one configured tag pair containing one JSON object. */
184
+ export function parseBenchmarkTerminal(raw, config) {
185
+ if (!validateTerminalOutputConfig(config))
186
+ return invalidTerminal();
187
+ if (Buffer.byteLength(raw, 'utf8') > config.max_bytes)
188
+ return invalidTerminal();
189
+ const trimmed = stripReasoningBlocks(raw).trim();
190
+ const opening = `<${config.tag}>`;
191
+ const closing = `</${config.tag}>`;
192
+ if (!trimmed.startsWith(opening) || !trimmed.endsWith(closing))
193
+ return invalidTerminal();
194
+ if (trimmed.indexOf(opening) !== trimmed.lastIndexOf(opening)
195
+ || trimmed.indexOf(closing) !== trimmed.lastIndexOf(closing))
196
+ return invalidTerminal();
197
+ const body = trimmed.slice(opening.length, -closing.length);
198
+ if (body.length === 0 || body.includes('```'))
199
+ return invalidTerminal();
200
+ try {
201
+ const value = JSON.parse(body);
202
+ if (!plainObject(value))
203
+ return invalidTerminal();
204
+ // Round 12(#215):同一份 closed body schema 在接受终态前 fail-closed 校验——
205
+ // 结构不合法的终态永不进入正式计分链,不做任何 autofix。
206
+ if (!validateTerminalBodyValue(value, config.body_schema))
207
+ return invalidTerminal();
208
+ return { ok: true, value };
209
+ }
210
+ catch {
211
+ return invalidTerminal();
212
+ }
213
+ }
214
+ /** Backward-compatible name used by the bridge contract tests. */
215
+ export const validateTerminalOutput = parseBenchmarkTerminal;
216
+ function eventData(event) {
217
+ if (!plainObject(event) || typeof event.type !== 'string' || !plainObject(event.data))
218
+ return undefined;
219
+ return { type: event.type, data: event.data };
220
+ }
221
+ function eventTurn(data) {
222
+ return typeof data.turn === 'number' && Number.isInteger(data.turn) ? data.turn : undefined;
223
+ }
224
+ function parseToolArguments(value) {
225
+ if (plainObject(value))
226
+ return value;
227
+ if (typeof value !== 'string')
228
+ return undefined;
229
+ try {
230
+ const parsed = JSON.parse(value);
231
+ return plainObject(parsed) ? parsed : undefined;
232
+ }
233
+ catch {
234
+ return undefined;
235
+ }
236
+ }
237
+ function assistantText(data) {
238
+ if (!plainObject(data.message) || !Array.isArray(data.message.content))
239
+ return undefined;
240
+ const text = data.message.content
241
+ .filter(block => plainObject(block) && block.type === 'text' && typeof block.text === 'string')
242
+ .map(block => String(block.text))
243
+ .join('');
244
+ return { text, interrupted: data.interrupted === true };
245
+ }
246
+ function bridgeResultStatus(data, callId) {
247
+ if (!plainObject(data.message) || !plainObject(data.message.source))
248
+ return undefined;
249
+ if (data.message.source.callId !== callId || !Array.isArray(data.message.content))
250
+ return undefined;
251
+ // 0.2.0-rc.2 线型:tool/result 的身份与错误位在 message 顶层
252
+ // (toolCallId/isError),content 是文本载荷块;旧线型的 {type:'tool-result'} 块已不存在。
253
+ if (data.message.toolCallId !== callId || data.message.isError === true)
254
+ return undefined;
255
+ const text = data.message.content
256
+ .filter(candidate => plainObject(candidate) && candidate.type === 'text' && typeof candidate.text === 'string')
257
+ .map(candidate => String(candidate.text))
258
+ .join('');
259
+ try {
260
+ const parsed = JSON.parse(text);
261
+ if (!plainObject(parsed))
262
+ return undefined;
263
+ const keys = Object.keys(parsed).sort().join(',');
264
+ if (parsed.ok === true && keys === 'ok,result' && (plainObject(parsed.result) || Array.isArray(parsed.result)))
265
+ return { kind: 'result' };
266
+ if (parsed.ok === true && keys === 'ok,outcome' && plainObject(parsed.outcome)) {
267
+ const outcomeKeys = Object.keys(parsed.outcome).sort().join(',');
268
+ if (outcomeKeys === 'code,recovery,schema_version,status'
269
+ && parsed.outcome.schema_version === BENCHMARK_TOOL_RESULT_SCHEMA_VERSION
270
+ && (parsed.outcome.status === 'miss' || parsed.outcome.status === 'error')
271
+ && typeof parsed.outcome.code === 'string'
272
+ && IDENTIFIER.test(parsed.outcome.code)
273
+ && typeof parsed.outcome.recovery === 'string'
274
+ && BENCHMARK_DOMAIN_RECOVERIES.has(parsed.outcome.recovery))
275
+ return { kind: 'domain' };
276
+ return undefined;
277
+ }
278
+ if (parsed.ok === false && typeof parsed.error === 'string') {
279
+ const exactFailure = parsed.error === 'runner_failed'
280
+ ? (keys === 'error,ok' || (keys === 'error,exit_code,ok,signal'
281
+ && (parsed.exit_code === null || (typeof parsed.exit_code === 'number' && Number.isInteger(parsed.exit_code)))
282
+ && (parsed.signal === null || typeof parsed.signal === 'string')))
283
+ : parsed.error === 'invalid_arguments'
284
+ ? keys === 'error,ok,reason' && typeof parsed.reason === 'string'
285
+ : keys === 'error,ok';
286
+ if (!exactFailure)
287
+ return undefined;
288
+ const code = parsed.error === 'timed_out'
289
+ ? BENCHMARK_BRIDGE_TIMED_OUT
290
+ : parsed.error === 'runner_failed'
291
+ ? BENCHMARK_BRIDGE_RUNNER_FAILED
292
+ : parsed.error === 'spawn_failed'
293
+ ? BENCHMARK_BRIDGE_SPAWN_FAILED
294
+ : parsed.error === 'output_truncated'
295
+ ? BENCHMARK_BRIDGE_OUTPUT_TRUNCATED
296
+ : BENCHMARK_BRIDGE_CALL_FAILED;
297
+ return { kind: 'failure', code };
298
+ }
299
+ return undefined;
300
+ }
301
+ catch {
302
+ return undefined;
303
+ }
304
+ }
305
+ export function benchmarkChildFailureForConformanceCode(code) {
306
+ if (code === BENCHMARK_BRIDGE_TIMED_OUT)
307
+ return 'child_bridge_timed_out';
308
+ if (code === BENCHMARK_BRIDGE_RUNNER_FAILED)
309
+ return 'child_bridge_runner_failed';
310
+ if (code === BENCHMARK_BRIDGE_SPAWN_FAILED)
311
+ return 'child_bridge_spawn_failed';
312
+ if (code === BENCHMARK_BRIDGE_OUTPUT_TRUNCATED)
313
+ return 'child_bridge_output_truncated';
314
+ if (code === BENCHMARK_BRIDGE_CALL_FAILED)
315
+ return 'child_bridge_failure';
316
+ return 'child_conformance_failure';
317
+ }
318
+ function newTurn(turn) {
319
+ return {
320
+ turn,
321
+ validCallIds: new Set(),
322
+ retryCount: 0,
323
+ retryMode: 'none',
324
+ bridgeCallFailed: false,
325
+ retryRedispatchAttempted: false,
326
+ };
327
+ }
328
+ /** Deterministic controller used by both runtime wiring and offline contracts. */
329
+ export function createBenchmarkAgentConformance(projection) {
330
+ let state;
331
+ const controller = {
332
+ get retryMode() { return state?.retryMode ?? 'none'; },
333
+ get retryCount() { return state?.retryCount ?? 0; },
334
+ observe(rawEvent) {
335
+ const event = eventData(rawEvent);
336
+ if (!event)
337
+ return;
338
+ const turn = eventTurn(event.data);
339
+ if (event.type === 'turn/start' && turn !== undefined) {
340
+ state = newTurn(turn);
341
+ return;
342
+ }
343
+ if (event.type === 'turn/end') {
344
+ if (state && turn === state.turn)
345
+ state = undefined;
346
+ return;
347
+ }
348
+ if (!state || turn !== state.turn)
349
+ return;
350
+ if (event.type === 'tool/call') {
351
+ if (event.data.name !== projection.toolName)
352
+ return;
353
+ if (state.retryMode === 'terminal') {
354
+ state.retryRedispatchAttempted = true;
355
+ return;
356
+ }
357
+ if (typeof event.data.callId !== 'string')
358
+ return;
359
+ const args = parseToolArguments(event.data.arguments);
360
+ // Round 8(issue #100/#102):bridge 工具 typed 泛化后,模型出参为平铺形态
361
+ const flat = args && plainObject(args) ? args : undefined;
362
+ if (flat?.action === 'call'
363
+ && typeof flat.tool === 'string'
364
+ && projection.allowedTools.includes(flat.tool)) {
365
+ state.validCallIds.add(event.data.callId);
366
+ }
367
+ return;
368
+ }
369
+ if (event.type === 'tool/result') {
370
+ if (!plainObject(event.data.message) || !plainObject(event.data.message.source))
371
+ return;
372
+ const callId = event.data.message.source.callId;
373
+ if (typeof callId !== 'string' || !state.validCallIds.has(callId))
374
+ return;
375
+ const resultStatus = bridgeResultStatus(event.data, callId);
376
+ if (typeof event.data.step === 'number')
377
+ state.lastBridgeResponseStep = event.data.step;
378
+ if (resultStatus?.kind === 'result') {
379
+ state.successfulResultStep = typeof event.data.step === 'number'
380
+ ? event.data.step
381
+ : state.successfulResultStep;
382
+ }
383
+ else if (resultStatus?.kind === 'domain') {
384
+ state.domainOutcomeStep = typeof event.data.step === 'number'
385
+ ? event.data.step
386
+ : state.domainOutcomeStep;
387
+ }
388
+ else {
389
+ state.bridgeCallFailed = true;
390
+ state.bridgeFailureCode = resultStatus?.code ?? BENCHMARK_BRIDGE_CALL_FAILED;
391
+ }
392
+ return;
393
+ }
394
+ if (event.type === 'assistant/message') {
395
+ const assistant = assistantText(event.data);
396
+ if (!assistant || typeof event.data.step !== 'number')
397
+ return;
398
+ state.lastAssistant = { step: event.data.step, ...assistant };
399
+ }
400
+ },
401
+ stopping(turn) {
402
+ if (!state || state.turn !== turn) {
403
+ return { kind: 'reject', code: BENCHMARK_CONFORMANCE_STATE_UNAVAILABLE };
404
+ }
405
+ if (state.retryRedispatchAttempted) {
406
+ return { kind: 'reject', code: BENCHMARK_BRIDGE_RETRY_CALL_NOT_ALLOWED };
407
+ }
408
+ if (state.bridgeCallFailed && state.successfulResultStep === undefined) {
409
+ return { kind: 'reject', code: state.bridgeFailureCode ?? BENCHMARK_BRIDGE_CALL_FAILED };
410
+ }
411
+ if (state.successfulResultStep === undefined && state.domainOutcomeStep === undefined) {
412
+ if (state.retryCount >= MAX_CONFORMANCE_RETRIES) {
413
+ return { kind: 'reject', code: BENCHMARK_BRIDGE_CALL_REQUIRED };
414
+ }
415
+ state.retryCount += 1;
416
+ state.retryMode = 'call';
417
+ return { kind: 'steer', mode: 'call' };
418
+ }
419
+ const terminal = state.lastAssistant;
420
+ const terminalIsValid = terminal !== undefined
421
+ && !terminal.interrupted
422
+ && terminal.step > state.lastBridgeResponseStep
423
+ && parseBenchmarkTerminal(terminal.text, projection.terminal).ok;
424
+ if (terminalIsValid)
425
+ return { kind: 'accept' };
426
+ if (state.retryCount >= MAX_CONFORMANCE_RETRIES) {
427
+ return { kind: 'reject', code: BENCHMARK_TERMINAL_INVALID };
428
+ }
429
+ state.retryCount += 1;
430
+ state.retryMode = 'terminal';
431
+ return { kind: 'steer', mode: 'terminal' };
432
+ },
433
+ guardBridgeExecution() {
434
+ return state?.retryMode === 'terminal'
435
+ ? BENCHMARK_BRIDGE_RETRY_CALL_NOT_ALLOWED
436
+ : undefined;
437
+ },
438
+ };
439
+ return controller;
440
+ }
441
+ function requireDisposer(value, capability) {
442
+ if (typeof value !== 'function')
443
+ throw new Error(`benchmark conformance ${capability} disposer unavailable`);
444
+ return value;
445
+ }
446
+ function correctionMessage(mode, projection) {
447
+ const text = mode === 'call'
448
+ ? `BENCHMARK_CONFORMANCE_CALL: Execute exactly one native ${projection.toolName} action:"call" now. Describing an intended CLI, shell, or Python command does not execute it.`
449
+ : `BENCHMARK_CONFORMANCE_TERMINAL: Reuse the existing successful tool result. Do not call any tool. Reply only <${projection.terminal.tag}> with one JSON object matching exactly ${terminalSchemaOutline(projection.terminal.body_schema)} — no extra keys, no missing keys, exact types.`;
450
+ return createUserMessage({
451
+ content: [{ type: 'text', text }],
452
+ // 0.2.0-rc.2 的 MessageSourceMap 移除了 'plugin' kind;基准纠偏消息是
453
+ // 插件注入的指令,归入 system-prompt(运行时自产注入),不冒充真实用户输入。
454
+ source: { kind: 'system-prompt' },
455
+ });
456
+ }
457
+ function systemSection(projection) {
458
+ const allowed = projection.allowedTools.join(', ');
459
+ const outline = terminalSchemaOutline(projection.terminal.body_schema);
460
+ return {
461
+ name: 'benchmark:agent-conformance',
462
+ text: [
463
+ 'Benchmark execution contract:',
464
+ `- Translate every task instruction to use a CLI, shell, Python, or agent_env.cli into the native tool ${projection.toolName}; do not merely describe the intended command.`,
465
+ `- Call it with exactly {"action":"call","tool":"<one of: ${allowed}>","arguments":{...}}.`,
466
+ '- action:"tools" is discovery only and does not satisfy the required environment call.',
467
+ `- After a successful tool result, reply only <${projection.terminal.tag}> with one JSON object matching exactly ${outline} — no extra keys, no missing keys, exact types; no prose or code fence.`,
468
+ '- If a terminal-format correction arrives, reuse the existing result and do not call the tool again.',
469
+ ].join('\n'),
470
+ };
471
+ }
472
+ /** Install conformance only after the exact benchmark bridge isolation layer. */
473
+ export function installBenchmarkAgentConformance(ctx, projection, diagnosticWriter = emitBenchmarkChildDiagnostic) {
474
+ const bus = ctx;
475
+ if (typeof bus.on !== 'function')
476
+ throw new Error('benchmark conformance event bus unavailable');
477
+ const byAgent = new WeakMap();
478
+ const bySession = new WeakMap();
479
+ const sessionKeys = new WeakMap();
480
+ let sessionOrdinal = 0;
481
+ const diagnostics = createBenchmarkDiagnosticArbiter(diagnosticWriter);
482
+ bus.on('agent/created', (payload) => {
483
+ const agent = payload.agent;
484
+ if (!agent || typeof agent !== 'object' || !agent.session) {
485
+ throw new Error('benchmark conformance created agent unavailable');
486
+ }
487
+ if (typeof agent.steer !== 'function')
488
+ throw new Error('benchmark conformance steering unavailable');
489
+ if (typeof agent.ctx?.tools?.guard !== 'function')
490
+ throw new Error('benchmark conformance scoped guard unavailable');
491
+ if (typeof agent.ctx.effect !== 'function')
492
+ throw new Error('benchmark conformance scoped effect unavailable');
493
+ if (typeof agent.ctx.on !== 'function')
494
+ throw new Error('benchmark conformance scoped event bus unavailable');
495
+ const controller = createBenchmarkAgentConformance(projection);
496
+ byAgent.set(agent, controller);
497
+ bySession.set(agent.session, controller);
498
+ sessionKeys.set(agent.session, `session-${++sessionOrdinal}`);
499
+ try {
500
+ requireDisposer(agent.ctx.effect.call(agent.ctx, function* () {
501
+ yield requireDisposer(agent.ctx.tools.guard(execution => {
502
+ if (execution.name !== projection.toolName)
503
+ return undefined;
504
+ return controller.guardBridgeExecution();
505
+ }), 'scoped guard');
506
+ yield requireDisposer(agent.ctx.on.call(agent.ctx, 'system-prompt/assemble', async (_assembly, _context, next) => {
507
+ if (typeof next !== 'function')
508
+ throw new Error('benchmark conformance assembly continuation unavailable');
509
+ const result = await next();
510
+ if (!plainObject(result))
511
+ throw new Error('benchmark conformance assembly result unavailable');
512
+ const sections = Array.isArray(result.sections) ? result.sections : [];
513
+ return { ...result, sections: [...sections, systemSection(projection)] };
514
+ }, { prepend: true }), 'scoped assembly listener');
515
+ }, 'benchmark-agent-conformance'), 'scoped effect');
516
+ }
517
+ catch (error) {
518
+ byAgent.delete(agent);
519
+ bySession.delete(agent.session);
520
+ throw error;
521
+ }
522
+ });
523
+ bus.on('session/event', (session, event) => {
524
+ bySession.get(session)?.observe(event);
525
+ if (typeof event === 'object' && event !== null && event.type === 'turn/end') {
526
+ const key = sessionKeys.get(session);
527
+ if (key !== undefined) {
528
+ diagnostics.offer(key, classifyBenchmarkTurnEnd(event.data?.reason));
529
+ diagnostics.flush(key);
530
+ }
531
+ }
532
+ });
533
+ bus.on('session/disposed', (session) => {
534
+ const key = sessionKeys.get(session);
535
+ if (key !== undefined)
536
+ diagnostics.flush(key);
537
+ sessionKeys.delete(session);
538
+ bySession.delete(session);
539
+ });
540
+ bus.on('agent/disposed', (payload) => {
541
+ const agent = payload.agent;
542
+ if (!agent || typeof agent !== 'object')
543
+ return;
544
+ byAgent.delete(agent);
545
+ if (agent.session)
546
+ bySession.delete(agent.session);
547
+ });
548
+ bus.on('agent/turn-stopping', (payload) => {
549
+ const agent = payload.agent;
550
+ const session = agent?.session ?? payload.session;
551
+ const key = session && typeof session === 'object' ? sessionKeys.get(session) : undefined;
552
+ if (!agent || typeof agent !== 'object' || typeof payload.turn !== 'number') {
553
+ if (key !== undefined)
554
+ diagnostics.offer(key, 'child_conformance_failure');
555
+ else
556
+ diagnosticWriter('child_conformance_failure');
557
+ throw new Error(BENCHMARK_CONFORMANCE_STATE_UNAVAILABLE);
558
+ }
559
+ const controller = byAgent.get(agent);
560
+ if (!controller) {
561
+ if (key !== undefined)
562
+ diagnostics.offer(key, 'child_conformance_failure');
563
+ else
564
+ diagnosticWriter('child_conformance_failure');
565
+ throw new Error(BENCHMARK_CONFORMANCE_STATE_UNAVAILABLE);
566
+ }
567
+ const decision = controller.stopping(payload.turn);
568
+ if (decision.kind === 'reject') {
569
+ if (key !== undefined)
570
+ diagnostics.offer(key, benchmarkChildFailureForConformanceCode(decision.code));
571
+ else
572
+ diagnosticWriter(benchmarkChildFailureForConformanceCode(decision.code));
573
+ throw new Error(decision.code);
574
+ }
575
+ if (decision.kind === 'steer')
576
+ agent.steer(correctionMessage(decision.mode, projection));
577
+ }, { prepend: true });
578
+ }