@danceiny/gotry 0.0.1-rc.8 → 0.2.0-rc.27

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 (506) hide show
  1. package/README.md +172 -217
  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 +1744 -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 -49
  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 +135 -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 +546 -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 +968 -0
  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 +509 -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/resilience.js +191 -0
  41. package/dist/capabilities/session/action-cache.js +126 -0
  42. package/dist/capabilities/session/adapters/ctrip-flight.js +141 -0
  43. package/dist/capabilities/session/adapters/ctrip-hotel.js +222 -0
  44. package/dist/capabilities/session/adapters/dida-portal.js +274 -0
  45. package/dist/capabilities/session/adapters/meituan-local.js +54 -0
  46. package/dist/capabilities/session/adapters/rail-12306.js +342 -0
  47. package/dist/capabilities/session/benchmark.js +189 -0
  48. package/dist/capabilities/session/bridge-ledger.js +224 -0
  49. package/dist/capabilities/session/extension-bridge.js +636 -0
  50. package/dist/capabilities/session/extension-channel.js +109 -0
  51. package/dist/capabilities/session/extension-distribution.js +230 -0
  52. package/dist/capabilities/session/extract.js +50 -0
  53. package/dist/capabilities/session/golden-score.js +114 -0
  54. package/dist/capabilities/session/health-watch.js +215 -0
  55. package/dist/capabilities/session/read-guard.js +107 -0
  56. package/dist/capabilities/session/static-flight-golden.js +150 -0
  57. package/dist/capabilities/session/transport.js +109 -0
  58. package/dist/capabilities/session/wizard.js +117 -0
  59. package/dist/capabilities/session-consent.js +178 -0
  60. package/dist/capabilities/session-login.js +170 -0
  61. package/dist/capabilities/session-search.js +686 -0
  62. package/dist/capabilities/spawn-bounded.js +203 -0
  63. package/dist/capabilities/sponsor-plugin.js +341 -0
  64. package/dist/capabilities/visa-policy.js +140 -0
  65. package/dist/capabilities/weather.js +243 -138
  66. package/dist/data/session-golden-20.json +25 -0
  67. package/dist/data/sf-golden-manifest.json +103 -0
  68. package/dist/data/sf-static-routes.json +91 -0
  69. package/dist/scripts/action-cache-tests.js +72 -0
  70. package/dist/scripts/agent-planning-turn-deadline-e2e.js +242 -0
  71. package/dist/scripts/agent-planning-turn-deadline-tests.js +185 -0
  72. package/dist/scripts/agent-reach-deep-tests.js +30 -40
  73. package/dist/scripts/agent-reach-error-tests.js +354 -0
  74. package/dist/scripts/agent-reach-tests.js +26 -18
  75. package/dist/scripts/agent-reach-wrapper-tests.js +50 -50
  76. package/dist/scripts/anything-tests.js +116 -60
  77. package/dist/scripts/artifact-client-contract-tests.js +220 -0
  78. package/dist/scripts/artifacts-capability-tests.js +727 -0
  79. package/dist/scripts/async-collect.js +68 -10
  80. package/dist/scripts/benchmark-environment-bridge-e2e.js +741 -0
  81. package/dist/scripts/benchmark-environment-bridge-tests.js +1452 -0
  82. package/dist/scripts/booking-copilot-availability-ledger-binding-tests.js +126 -0
  83. package/dist/scripts/booking-copilot-availability-policy-tests.js +265 -0
  84. package/dist/scripts/booking-copilot-bin-proof-tests.js +66 -0
  85. package/dist/scripts/booking-copilot-cleanup-proof-helper.js +76 -0
  86. package/dist/scripts/booking-copilot-crossrepo-fixture-server.js +144 -0
  87. package/dist/scripts/booking-copilot-dsh-core-proof-tests.js +424 -0
  88. package/dist/scripts/booking-copilot-dsh-planner-proof-tests.js +2839 -0
  89. package/dist/scripts/booking-copilot-dsh-plugin-proof-tests.js +309 -0
  90. package/dist/scripts/booking-copilot-dsh-readiness-proof.js +238 -0
  91. package/dist/scripts/booking-copilot-dsh-warmer-proof.js +123 -0
  92. package/dist/scripts/booking-copilot-event-sequence-concurrency-proof-tests.js +156 -0
  93. package/dist/scripts/booking-copilot-gap-code-contract-proof-tests.js +70 -0
  94. package/dist/scripts/booking-copilot-intent-proof-tests.js +422 -0
  95. package/dist/scripts/booking-copilot-operation-ledger-concurrency-proof-tests.js +184 -0
  96. package/dist/scripts/booking-copilot-planner-live-probe.js +95 -0
  97. package/dist/scripts/booking-copilot-proof-runtime.js +42 -0
  98. package/dist/scripts/booking-copilot-receipt-ledger-concurrency-proof-tests.js +210 -0
  99. package/dist/scripts/booking-copilot-runtime-proof-tests.js +2349 -0
  100. package/dist/scripts/booking-copilot-server-proof-tests.js +784 -0
  101. package/dist/scripts/booking-copilot-startup-proof-tests.js +94 -0
  102. package/dist/scripts/booking-executor-tests.js +80 -0
  103. package/dist/scripts/booking-recovery-chain-tests.js +182 -0
  104. package/dist/scripts/booking-saga-tests.js +125 -0
  105. package/dist/scripts/booking-surface-contract-proof-tests.js +212 -0
  106. package/dist/scripts/bootstrap-tests.js +1479 -0
  107. package/dist/scripts/bridge-events-tests.js +239 -0
  108. package/dist/scripts/bridge-ledger-tests.js +428 -0
  109. package/dist/scripts/build-changelog.js +238 -0
  110. package/dist/scripts/build-metrics-report.js +331 -0
  111. package/dist/scripts/changelog-tests.js +118 -0
  112. package/dist/scripts/channel-probe-tests.js +103 -0
  113. package/dist/scripts/channel-probe.js +169 -0
  114. package/dist/scripts/channel-registry-tests.js +208 -0
  115. package/dist/scripts/companion-tests.js +67 -0
  116. package/dist/scripts/dida-cookie-probe.js +87 -0
  117. package/dist/scripts/dida-runner-stop-tests.js +311 -0
  118. package/dist/scripts/dida-sw-probe.js +114 -0
  119. package/dist/scripts/diff-test.js +17 -12
  120. package/dist/scripts/doctor-tests.js +564 -0
  121. package/dist/scripts/dsh-artifact-e2e.js +279 -0
  122. package/dist/scripts/dsh-artifact-web-e2e.js +675 -0
  123. package/dist/scripts/dsh-http-proxy-sse-proof.js +90 -0
  124. package/dist/scripts/dsh-runtime-closure-tests.js +182 -0
  125. package/dist/scripts/dsh-runtime-closure.js +162 -0
  126. package/dist/scripts/dsh-session-v3-migration-proof.js +109 -0
  127. package/dist/scripts/dsh-subprocess-local-proof.js +150 -0
  128. package/dist/scripts/dsh-target-closure-proof.js +178 -0
  129. package/dist/scripts/effect-tests.js +539 -0
  130. package/dist/scripts/engine-run.js +1 -3
  131. package/dist/scripts/engine-tests.js +16 -10
  132. package/dist/scripts/evaluation-cadence-tests.js +174 -0
  133. package/dist/scripts/evaluation-contract-tests.js +268 -0
  134. package/dist/scripts/extension-distribution-cli.js +39 -0
  135. package/dist/scripts/extension-distribution-tests.js +443 -0
  136. package/dist/scripts/extension-tests.js +988 -0
  137. package/dist/scripts/external-event-tests.js +350 -0
  138. package/dist/scripts/fact-gate-tests.js +869 -0
  139. package/dist/scripts/fixtures/extension-bridge-unref-child.mjs +21 -0
  140. package/dist/scripts/flight-hotel-anchor-363-registered-e2e.js +169 -0
  141. package/dist/scripts/flight-malformed-tests.js +159 -0
  142. package/dist/scripts/flyai-setup-tests.js +228 -0
  143. package/dist/scripts/flyai-setup-tool-tests.js +54 -0
  144. package/dist/scripts/flyai-tests.js +692 -0
  145. package/dist/scripts/flyai-tool-registration-contract-tests.js +91 -0
  146. package/dist/scripts/fx-contract-tests.js +201 -0
  147. package/dist/scripts/g5-guard-tests.js +131 -0
  148. package/dist/scripts/g5-guard.js +189 -0
  149. package/dist/scripts/gen-lunar-anchors.js +106 -0
  150. package/dist/scripts/geo-atlas-tests.js +283 -0
  151. package/dist/scripts/gotry-backend-kernel-tests.js +206 -0
  152. package/dist/scripts/gotry-try-demo-tests.js +79 -0
  153. package/dist/scripts/gotry-try-demo.js +49 -0
  154. package/dist/scripts/ground-transfer-tests.js +956 -0
  155. package/dist/scripts/hbcli-e2e-tests.js +159 -0
  156. package/dist/scripts/hbcli-live-optin-tests.js +96 -0
  157. package/dist/scripts/hbcli-release-contract-tests.js +122 -0
  158. package/dist/scripts/hbcli-tests.js +121 -69
  159. package/dist/scripts/health-watch-cli.js +73 -0
  160. package/dist/scripts/hotel-date-gate-tests.js +496 -0
  161. package/dist/scripts/hotelbyte-reconcile-tests.js +141 -0
  162. package/dist/scripts/hotelbyte-spawn-e2e-tests.js +373 -0
  163. package/dist/scripts/i18n-tests.js +41 -0
  164. package/dist/scripts/incident-tests.js +281 -87
  165. package/dist/scripts/issue-194-job-id-guard-tests.js +106 -0
  166. package/dist/scripts/issue-233-cancel-refund-commission-tests.js +392 -0
  167. package/dist/scripts/issue-271-liveness-tests.js +569 -0
  168. package/dist/scripts/issue-289-model-retry-real-tests.js +296 -0
  169. package/dist/scripts/issue-289-model-retry-tests.js +441 -0
  170. package/dist/scripts/issue-289-web-retry-e2e.js +630 -0
  171. package/dist/scripts/issue-338-home-city-e2e.js +577 -0
  172. package/dist/scripts/issue343-real-entry-e2e.js +160 -0
  173. package/dist/scripts/issue436-persisted-routing-e2e.js +247 -0
  174. package/dist/scripts/itinerary-artifact-tests.js +368 -0
  175. package/dist/scripts/itinerary-deck-artifact-tests.js +416 -0
  176. package/dist/scripts/itinerary-deck-export-tests.js +552 -0
  177. package/dist/scripts/itinerary-deck-tests.js +435 -0
  178. package/dist/scripts/itinerary-html-tests.js +426 -0
  179. package/dist/scripts/journey-tests.js +22 -27
  180. package/dist/scripts/kernel-manifest-evidence.js +109 -0
  181. package/dist/scripts/kernel-manifest-gate.js +126 -0
  182. package/dist/scripts/kernel-manifest-tests.js +212 -0
  183. package/dist/scripts/kernel-manifest-trace-entry.js +7 -0
  184. package/dist/scripts/kernel-manifest-trace-hook.mjs +28 -0
  185. package/dist/scripts/kernel-manifest.js +369 -0
  186. package/dist/scripts/lavish-local-tests.js +1226 -0
  187. package/dist/scripts/lavish-product-tools-tests.js +537 -0
  188. package/dist/scripts/ledger-repair-apply-tests.js +316 -0
  189. package/dist/scripts/ledger-repair-plan-tests.js +375 -0
  190. package/dist/scripts/ledger-tests.js +480 -0
  191. package/dist/scripts/ledger-workflow-crash.js +32 -0
  192. package/dist/scripts/managed-dsh-cleanup-diagnostic-proof.js +184 -0
  193. package/dist/scripts/managed-dsh-close-failure-proof.js +172 -0
  194. package/dist/scripts/managed-dsh-run-port-proof.js +153 -0
  195. package/dist/scripts/managed-dsh-terminal-proof.js +252 -0
  196. package/dist/scripts/map-tools-vendor-package-proof.js +365 -0
  197. package/dist/scripts/memory-capture-tests.js +242 -61
  198. package/dist/scripts/memory-decay-tests.js +49 -0
  199. package/dist/scripts/memory-lifecycle-tests.js +657 -0
  200. package/dist/scripts/memory-lifecycle.js +196 -0
  201. package/dist/scripts/memory-metrics.js +29 -31
  202. package/dist/scripts/memory-value-report.js +631 -0
  203. package/dist/scripts/memory-value-tests.js +328 -0
  204. package/dist/scripts/metrics-report-tests.js +151 -0
  205. package/dist/scripts/model-override-e2e.js +137 -0
  206. package/dist/scripts/nightly-evidence-tests.js +161 -0
  207. package/dist/scripts/nightly-evidence.js +286 -0
  208. package/dist/scripts/nudge-digest.js +43 -42
  209. package/dist/scripts/observability-tests.js +381 -0
  210. package/dist/scripts/onboarding-tests.js +161 -0
  211. package/dist/scripts/opensky-check.js +18 -13
  212. package/dist/scripts/opensky-tests.js +28 -28
  213. package/dist/scripts/persona-surface-guard-tests.js +49 -0
  214. package/dist/scripts/pnpm-dsh-closure-proof.js +17 -0
  215. package/dist/scripts/policy-anchor-359-registered-e2e.js +214 -0
  216. package/dist/scripts/price-drift-tests.js +340 -0
  217. package/dist/scripts/price-drift-watch.js +447 -0
  218. package/dist/scripts/probe-poi-tests.js +53 -45
  219. package/dist/scripts/product-metrics.js +483 -0
  220. package/dist/scripts/publish-preverify.js +110 -0
  221. package/dist/scripts/realtime-pricing-tests.js +76 -0
  222. package/dist/scripts/recall-tests.js +513 -0
  223. package/dist/scripts/replay-async.js +20 -18
  224. package/dist/scripts/replay-real.js +18 -18
  225. package/dist/scripts/replay.js +52 -82
  226. package/dist/scripts/session-attach-diagnose.js +31 -0
  227. package/dist/scripts/session-attach-poc.js +62 -0
  228. package/dist/scripts/session-benchmark.js +180 -0
  229. package/dist/scripts/session-dida-live-e2e.js +199 -0
  230. package/dist/scripts/session-extract-tests.js +60 -0
  231. package/dist/scripts/session-link-tests.js +478 -0
  232. package/dist/scripts/session-login.js +29 -0
  233. package/dist/scripts/session-tests.js +862 -0
  234. package/dist/scripts/session-zones-tests.js +358 -0
  235. package/dist/scripts/sf-live-benchmark.js +367 -0
  236. package/dist/scripts/sf-live-challenge-stop-tests.js +453 -0
  237. package/dist/scripts/sf-live-cli-tests.js +92 -0
  238. package/dist/scripts/sf-live-options.js +46 -0
  239. package/dist/scripts/sf-manifest-tests.js +30 -0
  240. package/dist/scripts/sf-manifest.js +33 -0
  241. package/dist/scripts/sf-soft-score-tests.js +67 -0
  242. package/dist/scripts/sf-summary-tests.js +324 -0
  243. package/dist/scripts/sf-summary.js +525 -0
  244. package/dist/scripts/share-tests.js +432 -0
  245. package/dist/scripts/skeleton-check.js +16 -14
  246. package/dist/scripts/skeleton-integration-test.js +28 -11
  247. package/dist/scripts/skills-contract-tests.js +51 -46
  248. package/dist/scripts/smoke-session-gate-tests.js +21 -0
  249. package/dist/scripts/smoke.js +703 -219
  250. package/dist/scripts/spawn-bounded-abort-tests.js +241 -0
  251. package/dist/scripts/sponsor-reuse-tests.js +262 -0
  252. package/dist/scripts/state-cli-tests.js +261 -0
  253. package/dist/scripts/state-cli.js +585 -0
  254. package/dist/scripts/state-repair-cli.js +66 -0
  255. package/dist/scripts/state-repair-tests.js +140 -0
  256. package/dist/scripts/static-golden-tests.js +165 -0
  257. package/dist/scripts/time-eval-tests.js +210 -192
  258. package/dist/scripts/travel-timeline-tests.js +59 -0
  259. package/dist/scripts/turn-handoff-collect-tests.js +169 -0
  260. package/dist/scripts/turn-handoff-collect.js +161 -0
  261. package/dist/scripts/turn-policy-tests.js +55 -0
  262. package/dist/scripts/typed-contract-canary.js +176 -0
  263. package/dist/scripts/tz-resolver-sanity.js +50 -0
  264. package/dist/scripts/tz-resolver-tests.js +584 -0
  265. package/dist/scripts/unified-tests.js +23 -19
  266. package/dist/scripts/visa-policy-tests.js +62 -0
  267. package/dist/scripts/weather-tests.js +276 -41
  268. package/dist/scripts/wish-channel-gate-tests.js +54 -0
  269. package/dist/scripts/write-gate-tests.js +522 -0
  270. package/dist/scripts/z3-lifecycle-fault-tests.js +188 -0
  271. package/dist/scripts/z3-lifecycle-tests.js +170 -0
  272. package/dist/scripts/z3-race-repeat-tests.js +39 -0
  273. package/dist/scripts/z3-race-tests.js +41 -0
  274. package/dist/src/artifact-gate.js +829 -0
  275. package/dist/src/backend/kernel.js +91 -0
  276. package/dist/src/backend/modules/booking-copilot.js +92 -0
  277. package/dist/src/backend/modules/booking-executor.js +124 -0
  278. package/dist/src/backend/modules/session-search.js +551 -0
  279. package/dist/src/benchmark-agent-conformance.js +578 -0
  280. package/dist/src/benchmark-environment-bridge.js +515 -0
  281. package/dist/src/benchmark-headless-child-diagnostics.js +166 -0
  282. package/dist/src/benchmark-tool-isolation.js +151 -0
  283. package/dist/src/bookable-facts.js +533 -0
  284. package/dist/src/booking-saga.js +97 -0
  285. package/dist/src/booking-surface/availability-policy.js +697 -0
  286. package/dist/src/booking-surface/booking-intent.js +43 -0
  287. package/dist/src/booking-surface/cancel-refund-commission.js +379 -0
  288. package/dist/src/booking-surface/canonical-schema.js +116 -0
  289. package/dist/src/booking-surface/contracts.js +75 -0
  290. package/dist/src/booking-surface/dsh-planner.js +1854 -0
  291. package/dist/src/booking-surface/dsh-plugin.js +378 -0
  292. package/dist/src/booking-surface/dsh-worker.js +98 -0
  293. package/dist/src/booking-surface/error-codes.js +231 -0
  294. package/dist/src/booking-surface/index.js +9 -0
  295. package/dist/src/booking-surface/managed-dsh-cleanup-diagnostic.js +97 -0
  296. package/dist/src/booking-surface/managed-dsh-run-port.js +244 -0
  297. package/dist/src/booking-surface/profile.js +24 -0
  298. package/dist/src/booking-surface/recovery-chain.js +367 -0
  299. package/dist/src/booking-surface/runtime.js +1968 -0
  300. package/dist/src/booking-surface/server.js +674 -0
  301. package/dist/src/booking-surface/startup.js +168 -0
  302. package/dist/src/booking-surface/validation.js +261 -0
  303. package/dist/src/bridge.js +20 -13
  304. package/dist/src/companions.js +86 -0
  305. package/dist/src/contracts.js +21 -43
  306. package/dist/src/dsh-llm.js +97 -111
  307. package/dist/src/engine.js +276 -193
  308. package/dist/src/evaluation-cadence.js +97 -0
  309. package/dist/src/evaluation-contracts.js +283 -0
  310. package/dist/src/flight-pack-adapter.js +54 -0
  311. package/dist/src/flight-pack-contract.js +2 -0
  312. package/dist/src/flyai-setup-tool.js +70 -0
  313. package/dist/src/gotry-backend.js +125 -0
  314. package/dist/src/hotel-date-gate.js +118 -0
  315. package/dist/src/i18n.js +88 -0
  316. package/dist/src/index.js +2305 -731
  317. package/dist/src/itinerary-deck.js +139 -0
  318. package/dist/src/itinerary-doc-shared.js +661 -0
  319. package/dist/src/itinerary-html.js +131 -0
  320. package/dist/src/journey.js +155 -108
  321. package/dist/src/lavish-tools.js +400 -0
  322. package/dist/src/ledger-repair-apply.js +538 -0
  323. package/dist/src/ledger-repair-plan.js +463 -0
  324. package/dist/src/loop.js +358 -162
  325. package/dist/src/memory-capture.js +180 -32
  326. package/dist/src/memory-decay.js +47 -0
  327. package/dist/src/memory-lifecycle.js +1310 -0
  328. package/dist/src/memory-utility.js +27 -40
  329. package/dist/src/mock-llm.js +36 -61
  330. package/dist/src/model.js +81 -36
  331. package/dist/src/realtime-pricing.js +103 -0
  332. package/dist/src/recall/card.js +74 -0
  333. package/dist/src/recall/evaluator.js +140 -0
  334. package/dist/src/recall/integration.js +17 -0
  335. package/dist/src/recall/tick.js +166 -0
  336. package/dist/src/session-link/plan-it-action.js +48 -0
  337. package/dist/src/session-link/session-link.js +248 -0
  338. package/dist/src/session-zones.js +507 -0
  339. package/dist/src/share/adapters.js +51 -0
  340. package/dist/src/share/share-consent.js +76 -0
  341. package/dist/src/share/share-deck.js +58 -0
  342. package/dist/src/share/share-token.js +146 -0
  343. package/dist/src/slot-spec.js +84 -106
  344. package/dist/src/state-ledger.js +767 -0
  345. package/dist/src/state-repair.js +299 -0
  346. package/dist/src/subagent-job-id-guard.js +58 -0
  347. package/dist/src/time-anchor.js +231 -33
  348. package/dist/src/tool-packet.js +20 -8
  349. package/dist/src/travel-slots.js +58 -35
  350. package/dist/src/travel-timeline.js +59 -0
  351. package/dist/src/turn-deadline.js +287 -0
  352. package/dist/src/turn-policy.js +118 -0
  353. package/dist/src/tz-resolver.js +143 -0
  354. package/dist/src/unified.js +538 -360
  355. package/dist/src/wish-pool.js +42 -12
  356. package/dist/src/write-gate.js +495 -0
  357. package/dist/src/z3-shared.js +284 -0
  358. package/extension/README.md +21 -0
  359. package/extension/README.zh-CN.md +21 -0
  360. package/extension/background.js +463 -0
  361. package/extension/content-bridge.js +270 -0
  362. package/extension/content-main.js +111 -0
  363. package/extension/manifest.json +60 -0
  364. package/package.json +407 -14
  365. package/schemas/booking.intent.schema.json +193 -0
  366. package/schemas/booking.surface.schema.json +2622 -0
  367. package/ts/capabilities/agent-reach-deep.ts +114 -0
  368. package/ts/capabilities/agent-reach.ts +198 -0
  369. package/ts/capabilities/anything.ts +255 -0
  370. package/ts/capabilities/artifacts.ts +428 -0
  371. package/ts/capabilities/fact-log.ts +54 -0
  372. package/ts/capabilities/flyai-config.ts +388 -0
  373. package/ts/capabilities/flyai.ts +1274 -0
  374. package/ts/capabilities/hbcli.ts +253 -71
  375. package/ts/capabilities/incident-log.ts +88 -59
  376. package/ts/capabilities/itinerary-artifact.ts +214 -0
  377. package/ts/capabilities/itinerary-deck-artifact.ts +218 -0
  378. package/ts/capabilities/itinerary-deck-export.ts +378 -0
  379. package/ts/capabilities/opensky.ts +121 -0
  380. package/ts/capabilities/session/action-cache.ts +148 -0
  381. package/ts/capabilities/session/adapters/ctrip-flight.ts +181 -0
  382. package/ts/capabilities/session/adapters/ctrip-hotel.ts +238 -0
  383. package/ts/capabilities/session/adapters/dida-portal.ts +338 -0
  384. package/ts/capabilities/session/adapters/meituan-local.ts +70 -0
  385. package/ts/capabilities/session/adapters/rail-12306.ts +392 -0
  386. package/ts/capabilities/session/benchmark.ts +276 -0
  387. package/ts/capabilities/session/bridge-ledger.ts +333 -0
  388. package/ts/capabilities/session/extension-bridge.ts +794 -0
  389. package/ts/capabilities/session/extension-channel.ts +144 -0
  390. package/ts/capabilities/session/extension-distribution.ts +266 -0
  391. package/ts/capabilities/session/extract.ts +54 -0
  392. package/ts/capabilities/session/golden-score.ts +139 -0
  393. package/ts/capabilities/session/health-watch.ts +264 -0
  394. package/ts/capabilities/session/read-guard.ts +141 -0
  395. package/ts/capabilities/session/static-flight-golden.ts +209 -0
  396. package/ts/capabilities/session/transport.ts +146 -0
  397. package/ts/capabilities/session/wizard.ts +140 -0
  398. package/ts/capabilities/session-consent.ts +211 -0
  399. package/ts/capabilities/session-login.ts +208 -0
  400. package/ts/capabilities/session-search.ts +893 -0
  401. package/ts/capabilities/weather.ts +330 -0
  402. package/ts/dsh-runtime/vendor/README.md +68 -0
  403. package/ts/dsh-runtime/vendor/dsh-map-tools/LICENSE +21 -0
  404. package/ts/dsh-runtime/vendor/dsh-map-tools/README.en.md +405 -0
  405. package/ts/dsh-runtime/vendor/dsh-map-tools/README.md +404 -0
  406. package/ts/dsh-runtime/vendor/dsh-map-tools/client/client.js +1584 -0
  407. package/ts/dsh-runtime/vendor/dsh-map-tools/cordis.patch.yml +5 -0
  408. package/ts/dsh-runtime/vendor/dsh-map-tools/icon.svg +5 -0
  409. package/ts/dsh-runtime/vendor/dsh-map-tools/lib/clients/amap.js +595 -0
  410. package/ts/dsh-runtime/vendor/dsh-map-tools/lib/clients/nominatim.js +63 -0
  411. package/ts/dsh-runtime/vendor/dsh-map-tools/lib/clients/osrm.js +58 -0
  412. package/ts/dsh-runtime/vendor/dsh-map-tools/lib/clients/photon.js +55 -0
  413. package/ts/dsh-runtime/vendor/dsh-map-tools/lib/config-file.js +87 -0
  414. package/ts/dsh-runtime/vendor/dsh-map-tools/lib/config-route.js +131 -0
  415. package/ts/dsh-runtime/vendor/dsh-map-tools/lib/config.js +16 -0
  416. package/ts/dsh-runtime/vendor/dsh-map-tools/lib/geo.js +232 -0
  417. package/ts/dsh-runtime/vendor/dsh-map-tools/lib/index.js +120 -0
  418. package/ts/dsh-runtime/vendor/dsh-map-tools/lib/settings-ns.js +40 -0
  419. package/ts/dsh-runtime/vendor/dsh-map-tools/lib/staticmap-route.js +115 -0
  420. package/ts/dsh-runtime/vendor/dsh-map-tools/lib/tools/geocode.js +127 -0
  421. package/ts/dsh-runtime/vendor/dsh-map-tools/lib/tools/poi.js +84 -0
  422. package/ts/dsh-runtime/vendor/dsh-map-tools/lib/tools/routes.js +267 -0
  423. package/ts/dsh-runtime/vendor/dsh-map-tools/lib/types/clients/amap.d.ts +90 -0
  424. package/ts/dsh-runtime/vendor/dsh-map-tools/lib/types/clients/nominatim.d.ts +17 -0
  425. package/ts/dsh-runtime/vendor/dsh-map-tools/lib/types/clients/osrm.d.ts +15 -0
  426. package/ts/dsh-runtime/vendor/dsh-map-tools/lib/types/clients/photon.d.ts +22 -0
  427. package/ts/dsh-runtime/vendor/dsh-map-tools/lib/types/config-file.d.ts +33 -0
  428. package/ts/dsh-runtime/vendor/dsh-map-tools/lib/types/config-route.d.ts +23 -0
  429. package/ts/dsh-runtime/vendor/dsh-map-tools/lib/types/config.d.ts +23 -0
  430. package/ts/dsh-runtime/vendor/dsh-map-tools/lib/types/geo.d.ts +61 -0
  431. package/ts/dsh-runtime/vendor/dsh-map-tools/lib/types/index.d.ts +18 -0
  432. package/ts/dsh-runtime/vendor/dsh-map-tools/lib/types/settings-ns.d.ts +14 -0
  433. package/ts/dsh-runtime/vendor/dsh-map-tools/lib/types/staticmap-route.d.ts +31 -0
  434. package/ts/dsh-runtime/vendor/dsh-map-tools/lib/types/tools/geocode.d.ts +11 -0
  435. package/ts/dsh-runtime/vendor/dsh-map-tools/lib/types/tools/poi.d.ts +9 -0
  436. package/ts/dsh-runtime/vendor/dsh-map-tools/lib/types/tools/routes.d.ts +75 -0
  437. package/ts/dsh-runtime/vendor/dsh-map-tools/lib/types/types.d.ts +68 -0
  438. package/ts/dsh-runtime/vendor/dsh-map-tools/lib/types.js +16 -0
  439. package/ts/dsh-runtime/vendor/dsh-map-tools/package.json +97 -0
  440. package/ts/package.json +296 -3
  441. package/ts/scripts/async-collect.ts +91 -0
  442. package/ts/scripts/map-tools-vendor-package-proof.ts +404 -0
  443. package/ts/scripts/skeleton-check.ts +1 -1
  444. package/ts/scripts/skeleton-integration-test.ts +23 -1
  445. package/ts/scripts/state-cli.ts +568 -0
  446. package/ts/scripts/turn-handoff-collect.ts +178 -0
  447. package/ts/src/artifact-gate.ts +991 -0
  448. package/ts/src/benchmark-agent-conformance.ts +619 -0
  449. package/ts/src/benchmark-environment-bridge.ts +538 -0
  450. package/ts/src/benchmark-headless-child-diagnostics.ts +184 -0
  451. package/ts/src/benchmark-tool-isolation.ts +166 -0
  452. package/ts/src/bookable-facts.ts +837 -0
  453. package/ts/src/booking-saga.ts +133 -0
  454. package/ts/src/booking-surface/availability-policy.ts +522 -0
  455. package/ts/src/booking-surface/booking-intent.ts +86 -0
  456. package/ts/src/booking-surface/cancel-refund-commission.ts +488 -0
  457. package/ts/src/booking-surface/canonical-schema.js +116 -0
  458. package/ts/src/booking-surface/contracts.ts +475 -0
  459. package/ts/src/booking-surface/dsh-planner.ts +1949 -0
  460. package/ts/src/booking-surface/dsh-plugin.js +378 -0
  461. package/ts/src/booking-surface/dsh-worker.ts +110 -0
  462. package/ts/src/booking-surface/error-codes.ts +241 -0
  463. package/ts/src/booking-surface/index.ts +9 -0
  464. package/ts/src/booking-surface/managed-dsh-cleanup-diagnostic.ts +151 -0
  465. package/ts/src/booking-surface/managed-dsh-run-port.ts +273 -0
  466. package/ts/src/booking-surface/profile.ts +42 -0
  467. package/ts/src/booking-surface/recovery-chain.ts +409 -0
  468. package/ts/src/booking-surface/runtime.ts +1793 -0
  469. package/ts/src/booking-surface/server.ts +733 -0
  470. package/ts/src/booking-surface/startup.ts +201 -0
  471. package/ts/src/booking-surface/validation.ts +217 -0
  472. package/ts/src/companions.ts +113 -0
  473. package/ts/src/contracts.ts +13 -3
  474. package/ts/src/dsh-llm.ts +44 -11
  475. package/ts/src/flyai-setup-tool.ts +77 -0
  476. package/ts/src/index.ts +2107 -224
  477. package/ts/src/itinerary-deck.ts +189 -0
  478. package/ts/src/itinerary-doc-shared.ts +741 -0
  479. package/ts/src/itinerary-html.ts +171 -0
  480. package/ts/src/loop.ts +278 -40
  481. package/ts/src/memory-capture.ts +283 -0
  482. package/ts/src/memory-decay.ts +55 -0
  483. package/ts/src/memory-utility.ts +70 -0
  484. package/ts/src/mock-llm.ts +4 -8
  485. package/ts/src/model.ts +88 -2
  486. package/ts/src/recall/card.ts +106 -0
  487. package/ts/src/recall/evaluator.ts +170 -0
  488. package/ts/src/recall/integration.ts +35 -0
  489. package/ts/src/recall/tick.ts +213 -0
  490. package/ts/src/session-link/plan-it-action.ts +78 -0
  491. package/ts/src/session-link/session-link.ts +275 -0
  492. package/ts/src/share/adapters.ts +93 -0
  493. package/ts/src/share/share-consent.ts +105 -0
  494. package/ts/src/share/share-deck.ts +85 -0
  495. package/ts/src/share/share-token.ts +166 -0
  496. package/ts/src/slot-spec.ts +172 -0
  497. package/ts/src/state-ledger.ts +912 -0
  498. package/ts/src/subagent-job-id-guard.ts +72 -0
  499. package/ts/src/time-anchor.ts +338 -0
  500. package/ts/src/tool-packet.ts +32 -0
  501. package/ts/src/travel-slots.ts +219 -0
  502. package/ts/src/travel-timeline.ts +83 -0
  503. package/ts/src/turn-deadline.ts +366 -0
  504. package/ts/src/turn-policy.ts +154 -0
  505. package/ts/src/unified.ts +360 -89
  506. package/ts/src/wish-pool.ts +79 -0
@@ -0,0 +1,215 @@
1
+ /**
2
+ * 扩展健康检查 + 自动重放(issue #21 onboarding UX,P3.6 gotry-session-onboarding-goal,
3
+ * RFC docs/rfc/user-session-data-rfc.md §3.3)。
4
+ *
5
+ * 动机:首次 `sessionFlightSearch` 遇 `needs-extension` 时,旧版要求用户装完扩展后**自己重跑命令**;
6
+ * 本模块把「用户手工重跑」改成「后台有界轮询 + 扩展一就位自动重放同一 query_id」——
7
+ * 用户装完扩展零后续动作,gotry 自己感知到 ready 后立刻跑同一条 query。
8
+ *
9
+ * 形态:
10
+ * - `startExtensionHealthWatch({ timeoutMs, intervalMs, probe })` 启后台轮询。
11
+ * probe 是异步检测函数(默认 GET http://127.0.0.1:{port}/status,扩展 ≤30s 心跳一次,
12
+ * 1.5 倍容差 EXTENSION_CONNECTED_WINDOW_MS=45s;§38 已经验证扩展心跳节奏)。
13
+ * - 命中 ready → 调用方自动重放(query_id / args 不变;同一证据文件覆盖)。
14
+ * - 超时(timeoutMs 默认 120_000)→ 返回 'timeout',调用方降级回 `needs-extension` 错误面。
15
+ *
16
+ * 离线合同(run-all §40 onboarding-tests 5/5):
17
+ * - 三时序分支:probe 0ms ready / 中途 ready / 120s+1ms 超时;
18
+ * - 同 query_id 重放语义(参数透传);
19
+ * - 取消语义(timeoutMs=0 立即 timeout;cancel() 立即返回 'cancelled');
20
+ * - 重放上限(防止 watch 反复 ready/抖动导致无限重放;maxRetries 默认 1)。
21
+ *
22
+ * 纪律:
23
+ * - 不引 GUI 依赖;只 spawn `node:http` 探活(已经在扩展桥验证过,§38 24 断言覆盖);
24
+ * - 不持锁、不轮询文件、不读 dsh-runtime 共享状态;
25
+ * - 不污染扩展桥 single-instance;probe 走独立短连接。
26
+ */
27
+ import { request } from 'node:http';
28
+ import { BRIDGE_PORTS, EXTENSION_CONNECTED_WINDOW_MS, } from './extension-bridge.js';
29
+ /**
30
+ * 双因子 probe(默认):心跳 + 业务探针(cookie-names)。
31
+ * 心跳通过只能证 SW 跑着;业务探针通过证 chrome.cookies 权限齐——二者同过才算
32
+ * 扩展真正 ready。wizard 必须双因子(用户刚装的扩展可能权限不全),上线 session
33
+ * 检索可传 `businessProbe:false` 跳业务探针(避免每次检索额外打一次 cookie-names)。
34
+ *
35
+ * 不直接 import extension-channel.ts(避免环)—用 dynamic import 懒拿。
36
+ */
37
+ export async function combinedProbe(opts, businessProbe) {
38
+ if (!(await defaultProbe(opts)))
39
+ return false;
40
+ if (!businessProbe)
41
+ return true;
42
+ try {
43
+ // 动态 import 避免 health-watch ↔ extension-channel 双向环
44
+ const channel = await import('./extension-channel.js');
45
+ const bridge = await import('./extension-bridge.js');
46
+ // 双因子探针需要常驻桥(wizard 期间):keepBridge=true 透传到 bridge 单例
47
+ bridge.getOrCreateSessionBridge({ keepBridge: opts.keepBridge === true });
48
+ // 心跳已 ready(刚 defaultProbe 通过)= 扩展一定在线;cookie-names 超时给 8s,
49
+ // 比心跳间隔 5s 长——保证 tick 间不会撞死 cookie job
50
+ const cookie = await channel.extensionCookieNames({
51
+ site: 'ctrip-flight',
52
+ domain: 'ctrip.com',
53
+ ticketNames: ['cticket', 'uid'],
54
+ timeoutMs: 8_000,
55
+ });
56
+ // cookie-names.ok = true 表示扩展 SW 真能调 chrome.cookies.getAll(权限齐全);
57
+ // cookie-names.ok = true + names = [] 也算 ok(用户没登携程但扩展权限齐)。
58
+ // cookie-names.ok = false 分两类:bridge-unavailable/extension-not-connected(心跳 false 时) / timeout(扩展没回包)——
59
+ // 后者更可能是 SW 卡了,不应当 ready。但 wizard 必须严格:让用户明确知道权限缺或登录缺。
60
+ return cookie.ok;
61
+ }
62
+ catch {
63
+ return false;
64
+ }
65
+ }
66
+ /**
67
+ * 默认 probe:GET http://127.0.0.1:{port}/status,看 extensionConnected: true
68
+ * (扩展心跳 ≤30s 一刷,窗口 EXTENSION_CONNECTED_WINDOW_MS=45s 容差)。
69
+ * 不在端口池内挑一个试——端口是已启动桥的事实,直接拿 opts.ports[0] 或 8791。
70
+ * 测试可注入 fake probe 跳过网络。
71
+ */
72
+ export async function defaultProbe(opts) {
73
+ const ports = opts.ports ?? [...BRIDGE_PORTS];
74
+ for (const port of ports) {
75
+ const ok = await new Promise((resolve) => {
76
+ const req = request({ host: '127.0.0.1', port, path: '/status', method: 'GET', timeout: 2_000 }, (res) => {
77
+ if (!res.statusCode || res.statusCode >= 400) {
78
+ resolve(false);
79
+ return;
80
+ }
81
+ let buf = '';
82
+ res.setEncoding('utf8');
83
+ res.on('data', (c) => { buf += c; });
84
+ res.on('end', () => {
85
+ try {
86
+ const payload = JSON.parse(buf);
87
+ resolve(payload.extensionConnected === true);
88
+ }
89
+ catch {
90
+ resolve(false);
91
+ }
92
+ });
93
+ res.on('error', () => resolve(false));
94
+ });
95
+ req.on('error', () => resolve(false));
96
+ req.on('timeout', () => { req.destroy(); resolve(false); });
97
+ req.end();
98
+ });
99
+ if (ok)
100
+ return true;
101
+ }
102
+ return false;
103
+ }
104
+ export function startExtensionHealthWatch(opts = {}) {
105
+ const timeoutMs = opts.timeoutMs ?? 120_000;
106
+ const intervalMs = opts.intervalMs ?? 5_000;
107
+ const maxRetries = opts.maxRetries ?? 1;
108
+ const businessProbe = opts.businessProbe ?? true;
109
+ // 关键:wizard 期间需要常驻桥(keepBridge=true 透传到 getOrCreateSessionBridge),
110
+ // 否则启桥后 wizard main 一退桥就退,扩展心跳发不进来。
111
+ // 用 dynamic import 避免与 extension-bridge 顶层环(channel 也引 bridge,但 health-watch 引 channel/bridge 双向会死循环)
112
+ const probe = opts.probe ?? (async () => {
113
+ // 先确保桥存在 + keepBridge
114
+ const bridge = await import('./extension-bridge.js');
115
+ const created = await bridge.getOrCreateSessionBridge({ keepBridge: opts.keepBridge === true, ports: opts.ports });
116
+ // The default path must keep scanning the canonical pool: another GoTry
117
+ // process may already own the extension-connected bridge. An explicit
118
+ // port override is an isolation boundary, so probe only the bridge that
119
+ // this process actually bound (including an ephemeral `0` request).
120
+ const probeOpts = created.ok && opts.ports
121
+ ? { ...opts, ports: [created.bridge.port] }
122
+ : opts;
123
+ return combinedProbe(probeOpts, businessProbe);
124
+ });
125
+ const now = opts.now ?? Date.now;
126
+ const state = { cancelled: false, readyCount: 0, resolveOutcome: null };
127
+ const finish = (outcome) => {
128
+ if (state.resolveOutcome) {
129
+ const resolve = state.resolveOutcome;
130
+ state.resolveOutcome = null;
131
+ resolve(outcome);
132
+ }
133
+ };
134
+ // 取消信号 -> 立刻 timeout-ish 终态(不进 ready 路径)
135
+ const onAbort = () => {
136
+ state.cancelled = true;
137
+ finish({ ready: false, reason: 'cancelled', attempts: state.readyCount, waitedMs: 0 });
138
+ };
139
+ opts.signal?.addEventListener('abort', onAbort, { once: true });
140
+ const waitReady = () => new Promise((resolve) => {
141
+ if (state.cancelled) {
142
+ resolve({ ready: false, reason: 'cancelled', attempts: 0, waitedMs: 0 });
143
+ return;
144
+ }
145
+ if (timeoutMs === 0) {
146
+ resolve({ ready: false, reason: 'timeout', attempts: 0, waitedMs: 0 });
147
+ return;
148
+ }
149
+ state.resolveOutcome = resolve;
150
+ const deadline = now() + timeoutMs;
151
+ let attempts = 0;
152
+ let waitedMs = 0;
153
+ const tick = async () => {
154
+ if (state.cancelled || state.resolveOutcome === null)
155
+ return;
156
+ attempts += 1;
157
+ try {
158
+ const ready = await probe();
159
+ if (ready && !state.cancelled) {
160
+ state.readyCount += 1;
161
+ waitedMs = timeoutMs - Math.max(0, deadline - now());
162
+ // readyCount > maxRetries → 视为抖动,继续等(避免一次性重放洪流)
163
+ if (state.readyCount <= maxRetries) {
164
+ finish({ ready: true, attempts, waitedMs: waitedMs > 0 ? waitedMs : 0 });
165
+ return;
166
+ }
167
+ }
168
+ }
169
+ catch { /* probe 失败继续轮询,不挡主流程 */ }
170
+ waitedMs = timeoutMs - Math.max(0, deadline - now());
171
+ if (now() >= deadline) {
172
+ finish({ ready: false, reason: 'timeout', attempts, waitedMs });
173
+ return;
174
+ }
175
+ // 间隔 = intervalMs;若剩余时间 < intervalMs 则最后一次等剩余时间
176
+ const remaining = deadline - now();
177
+ const delay = Math.min(intervalMs, Math.max(0, remaining));
178
+ if (delay <= 0) {
179
+ finish({ ready: false, reason: 'timeout', attempts, waitedMs });
180
+ return;
181
+ }
182
+ setTimeout(tick, delay);
183
+ };
184
+ void tick();
185
+ });
186
+ return {
187
+ waitReady,
188
+ cancel: () => onAbort(),
189
+ get readyCount() { return state.readyCount; },
190
+ };
191
+ }
192
+ /**
193
+ * 自动重放 wrapper:首次调用走 fetch(返回 needs-extension) → 启 watch →
194
+ * 扩展 ready → 同 query 重放。语义:用户侧**只看到一条 query 的最终结果**;
195
+ * 中间产物(query_id 标记 + 尝试次数)落 evidence 文件,便于离线追溯。
196
+ *
197
+ * 这是 §3.3「用户零手工重跑」的对外契约:调用方把 fetch 包成 withAutoRetryOnExtension,
198
+ * 用户装完扩展→自然出结果;用户不装→等 120s 后返回 needs-extension,而不是「再跑一次试试」。
199
+ */
200
+ export async function withAutoRetryOnExtension(args) {
201
+ const first = await args.fetch();
202
+ if (!args.isExtensionNeeded(first)) {
203
+ return { result: first, retried: false, attempts: 1, outcome: { ready: true, attempts: 0, waitedMs: 0 } };
204
+ }
205
+ const watch = startExtensionHealthWatch(args.watch ?? {});
206
+ const outcome = await watch.waitReady();
207
+ if (!outcome.ready) {
208
+ return { result: first, retried: false, attempts: 1, outcome };
209
+ }
210
+ const retriedResult = await (args.retry ?? args.fetch)();
211
+ return { result: retriedResult, retried: true, attempts: 2, outcome };
212
+ }
213
+ /** 留作运行时只读检查,防止扩展心跳节律假设漂移(§38 防漂移同款语义) */
214
+ export const HEALTH_WATCH_INTERVAL_FLOOR_MS = 1_000;
215
+ export const HEALTH_WATCH_INTERVAL_CEIL_MS = EXTENSION_CONNECTED_WINDOW_MS - 1_000;
@@ -0,0 +1,107 @@
1
+ /**
2
+ * ReadGuard:会话检索面的只读物理隔离(RFC docs/rfc/user-session-data-rfc.md §3.3)。
3
+ *
4
+ * 写不是「被禁止的行为」,是「不存在的原语」——WriteGate(L0-L4)的检索态前置:
5
+ * ① 网络层:route 拦截——命中硬支付模式(任意方法)或写方法+写URL模式 → abort + 审计落盘;
6
+ * ② DOM 层:提交类按钮文本黑名单,从快照/断言文本中剔除(模型看不到可点的提交件);
7
+ * ③ fail-closed:guard 未装上,session transport 不允许导航(openSession 装不上即整会话失败)。
8
+ *
9
+ * 审计:append-only JSONL(session-incidents.jsonl,对齐 incident-log 惯例),隔离 stateRoot。
10
+ * 注意:搜索接口多为 POST(如携程 batchSearch),因此写判定必须「方法 × URL 模式」双因子,
11
+ * 不能一刀切禁 POST——batchSearch 不含写词,放行。
12
+ */
13
+ import { mkdirSync, appendFileSync } from 'node:fs';
14
+ import { dirname } from 'node:path';
15
+ /** 硬支付模式:任意方法(含 GET)都视为写——进支付/收银面本身就是风险 */
16
+ const HARD_PAY_RE = /\/(pay|payment|cashier)(\/|\?|$)/i;
17
+ /** 驼峰复合写词(OTA 常见 /submitOrder、/createOrder):段式正则漏接,单列 */
18
+ const WRITE_COMPOUND_RE = /(submitorder|createorder|placeorder|cancelorder|refundorder|orderconfirm|orderpay|confirmpay)/i;
19
+ /** 写词 URL 模式:仅在写方法(POST/PUT/DELETE/PATCH)下触发 */
20
+ const WRITE_URL_RE = /\/(order|orders|submit|trade|booking|book|purchase|buy|create|cancel|refund)(\/|\?|$)/i;
21
+ const WRITE_METHODS = new Set(['POST', 'PUT', 'DELETE', 'PATCH']);
22
+ /** DOM 提交件文本黑名单(§3.3-②):命中即从可交互面剔除 */
23
+ export const SUBMIT_TEXT_RE = /下单|去支付|支付|预订|订票|购买|提交订单|确认订单/;
24
+ /** 网络层写判定(纯函数,测试锚点) */
25
+ export function classifyRequest(method, url) {
26
+ if (HARD_PAY_RE.test(url) || WRITE_COMPOUND_RE.test(url))
27
+ return 'block';
28
+ if (WRITE_METHODS.has(method.toUpperCase()) && WRITE_URL_RE.test(url))
29
+ return 'block';
30
+ return 'allow';
31
+ }
32
+ /** DOM 层提交件过滤(纯函数,测试锚点):true=剔除 */
33
+ export function isSubmitText(text) {
34
+ return SUBMIT_TEXT_RE.test(text ?? '');
35
+ }
36
+ /**
37
+ * 装上网络层守卫(fail-closed 的「closed」在调用方:openSession 装不上 guard 即失败,不给无 guard 的会话)。
38
+ * 审计落 auditPath(JSONL append);auditPath 缺省不落盘(仅内存计数)。
39
+ */
40
+ export async function attachReadGuard(ctx, auditPath) {
41
+ let blocked = 0;
42
+ let total = 0;
43
+ await ctx.route('**/*', async (route) => {
44
+ const req = route.request();
45
+ total += 1;
46
+ const verdict = classifyRequest(req.method(), req.url());
47
+ if (verdict === 'block') {
48
+ blocked += 1;
49
+ if (auditPath) {
50
+ const entry = { ts: new Date().toISOString(), kind: 'blocked-write-request', method: req.method(), url: req.url().slice(0, 400) };
51
+ try {
52
+ mkdirSync(dirname(auditPath), { recursive: true });
53
+ appendFileSync(auditPath, JSON.stringify(entry) + '\n');
54
+ }
55
+ catch { /* 审计失败不阻塞拦截本身 */ }
56
+ }
57
+ await route.abort('blockedbyclient');
58
+ return;
59
+ }
60
+ await route.continue();
61
+ });
62
+ return {
63
+ blockedCount: () => blocked,
64
+ requestCount: () => total,
65
+ };
66
+ }
67
+ /**
68
+ * puppeteer 版守卫:对既有页面与新建页面全部开启请求拦截,写请求 abort + 审计。
69
+ * 与 playwright 版共用 classifyRequest 判定与审计条目(单一事实源)。
70
+ */
71
+ export async function attachReadGuardPuppeteer(browser, auditPath) {
72
+ let blocked = 0;
73
+ let total = 0;
74
+ const wire = (page) => {
75
+ void (async () => {
76
+ try {
77
+ await page.setRequestInterception(true);
78
+ page.on('request', async (req) => {
79
+ total += 1;
80
+ const verdict = classifyRequest(req.method(), req.url());
81
+ if (verdict === 'block') {
82
+ blocked += 1;
83
+ if (auditPath) {
84
+ const entry = { ts: new Date().toISOString(), kind: 'blocked-write-request', method: req.method(), url: req.url().slice(0, 400) };
85
+ try {
86
+ mkdirSync(dirname(auditPath), { recursive: true });
87
+ appendFileSync(auditPath, JSON.stringify(entry) + '\n');
88
+ }
89
+ catch { /* 审计失败不阻塞拦截本身 */ }
90
+ }
91
+ await req.abort('blockedbyclient').catch(() => { });
92
+ return;
93
+ }
94
+ await req.continue().catch(() => { });
95
+ });
96
+ }
97
+ catch { /* 已关闭的 target 容忍 */ }
98
+ })();
99
+ };
100
+ for (const p of await browser.pages())
101
+ wire(p);
102
+ browser.on('targetcreated', (t) => {
103
+ if (t.type() === 'page')
104
+ void t.page().then(wire).catch(() => { });
105
+ });
106
+ return { blockedCount: () => blocked, requestCount: () => total };
107
+ }
@@ -0,0 +1,150 @@
1
+ import { readFileSync } from 'node:fs';
2
+ import { join } from 'node:path';
3
+ export function parseGoldenSource(args) {
4
+ const raw = args.find((arg) => arg.startsWith('--golden='))?.slice('--golden='.length) ?? 'manual';
5
+ if (raw === 'manual' || raw === 'flyai' || raw === 'static')
6
+ return raw;
7
+ throw new Error(`不支持的 golden vendor: ${raw}`);
8
+ }
9
+ export function loadStaticFlightSnapshot(path = join(import.meta.dirname, '..', '..', 'data', 'sf-static-routes.json')) {
10
+ const parsed = JSON.parse(readFileSync(path, 'utf8'));
11
+ if (!isRecord(parsed) || parsed.schema_version !== 'sf-static-routes.v1') {
12
+ throw new Error(`invalid static snapshot schema_version: ${String(isRecord(parsed) ? parsed.schema_version : undefined)}`);
13
+ }
14
+ const source = parsed.source;
15
+ if (!isRecord(source)
16
+ || !['name', 'url', 'revision', 'license', 'retrieved_at'].every((key) => typeof source[key] === 'string')
17
+ || !Array.isArray(source.limitations)
18
+ || !source.limitations.every((item) => typeof item === 'string')) {
19
+ throw new Error('invalid static snapshot source');
20
+ }
21
+ if (!Array.isArray(parsed.routes) || !parsed.routes.every(isStaticFlightRoute)) {
22
+ throw new Error('invalid static snapshot routes');
23
+ }
24
+ return parsed;
25
+ }
26
+ function isRecord(value) {
27
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
28
+ }
29
+ function isStaticFlightRoute(value) {
30
+ if (!isRecord(value)
31
+ || typeof value.query_id !== 'string'
32
+ || typeof value.from_city !== 'string'
33
+ || typeof value.to_city !== 'string'
34
+ || (value.route_kind !== 'direct' && value.route_kind !== 'transfer')
35
+ || !Array.isArray(value.legs)
36
+ || value.legs.length === 0)
37
+ return false;
38
+ return value.legs.every((leg) => isRecord(leg)
39
+ && typeof leg.from_iata === 'string'
40
+ && typeof leg.to_iata === 'string'
41
+ && Array.isArray(leg.carrier_codes)
42
+ && leg.carrier_codes.every((carrier) => typeof carrier === 'string'));
43
+ }
44
+ function provenance(snapshot) {
45
+ return {
46
+ route_source: snapshot?.source.url ?? '',
47
+ route_revision: snapshot?.source.revision ?? '',
48
+ route_license: snapshot?.source.license ?? '',
49
+ band_source: 'sf-golden-manifest.json',
50
+ };
51
+ }
52
+ function formatWithOffset(timestampMs, offset) {
53
+ const sign = offset.startsWith('-') ? -1 : 1;
54
+ const [hours, minutes] = offset.slice(1).split(':').map(Number);
55
+ const offsetMinutes = sign * ((hours ?? 0) * 60 + (minutes ?? 0));
56
+ const local = new Date(timestampMs + offsetMinutes * 60_000).toISOString().slice(0, 19);
57
+ return `${local}${offset}`;
58
+ }
59
+ function buildSegments(query, route, manualSegment) {
60
+ if (route.route_kind === 'direct' && route.legs.length === 1) {
61
+ return [{
62
+ from: query.from,
63
+ to: query.to,
64
+ departure_at: manualSegment.departure_at,
65
+ arrival_at: manualSegment.arrival_at,
66
+ transport_number: `${route.legs[0].carrier_codes[0]}-STATIC`,
67
+ }];
68
+ }
69
+ if (route.route_kind !== 'transfer' || route.legs.length !== 2)
70
+ return null;
71
+ const departureMs = Date.parse(manualSegment.departure_at);
72
+ const arrivalMs = Date.parse(manualSegment.arrival_at);
73
+ if (!Number.isFinite(departureMs) || !Number.isFinite(arrivalMs) || arrivalMs <= departureMs)
74
+ return null;
75
+ const offset = manualSegment.departure_at.match(/([+-]\d{2}:\d{2})$/)?.[1] ?? '+08:00';
76
+ const totalMinutes = Math.floor((arrivalMs - departureMs) / 60_000);
77
+ if (totalMinutes < 90)
78
+ return null;
79
+ const layoverMinutes = Math.min(60, Math.floor(totalMinutes / 3));
80
+ const travelMinutes = totalMinutes - layoverMinutes;
81
+ const firstTravelMinutes = Math.floor(travelMinutes / 2);
82
+ const secondDepartureMs = arrivalMs - (travelMinutes - firstTravelMinutes) * 60_000;
83
+ const middle = route.legs[0].to_iata;
84
+ return [
85
+ {
86
+ from: query.from,
87
+ to: middle,
88
+ departure_at: manualSegment.departure_at,
89
+ arrival_at: formatWithOffset(departureMs + firstTravelMinutes * 60_000, offset),
90
+ transport_number: `${route.legs[0].carrier_codes[0]}-STATIC`,
91
+ },
92
+ {
93
+ from: middle,
94
+ to: query.to,
95
+ departure_at: formatWithOffset(secondDepartureMs, offset),
96
+ arrival_at: manualSegment.arrival_at,
97
+ transport_number: `${route.legs[1].carrier_codes[0]}-STATIC`,
98
+ },
99
+ ];
100
+ }
101
+ export function resolveStaticGolden(input) {
102
+ const route = input.snapshot?.routes.find((candidate) => candidate.query_id === input.query.id);
103
+ let fallbackReason;
104
+ if (input.snapshotError) {
105
+ fallbackReason = `static snapshot unavailable: ${input.snapshotError}`;
106
+ }
107
+ else if (!route) {
108
+ fallbackReason = `static route missing for ${input.query.id}`;
109
+ }
110
+ else if (route.from_city !== input.query.from || route.to_city !== input.query.to) {
111
+ fallbackReason = `static route mismatch for ${input.query.id}`;
112
+ }
113
+ else if (route.legs.some((leg) => leg.carrier_codes.length === 0)) {
114
+ fallbackReason = `static carrier coverage missing for ${input.query.id}`;
115
+ }
116
+ const manualSegment = input.manualRecord.route_segments[0];
117
+ const segments = !fallbackReason && route && manualSegment
118
+ ? buildSegments(input.query, route, manualSegment)
119
+ : null;
120
+ if (!fallbackReason && !segments)
121
+ fallbackReason = `static route cannot form comparable record for ${input.query.id}`;
122
+ if (fallbackReason) {
123
+ input.warn?.(`[sf-live-benchmark] static vendor failed for ${input.query.id}: ${fallbackReason}; fallback=manual-golden`);
124
+ return {
125
+ requested_source: 'static',
126
+ effective_source: 'manual-golden',
127
+ record: input.manualRecord,
128
+ fallback_reason: fallbackReason,
129
+ estimated_fields: [],
130
+ provenance: provenance(input.snapshot),
131
+ };
132
+ }
133
+ return {
134
+ requested_source: 'static',
135
+ effective_source: 'static-openflights+manual-band',
136
+ record: {
137
+ ...input.manualRecord,
138
+ route_segments: segments,
139
+ journey_type: route.route_kind,
140
+ source: 'static-openflights+manual-band',
141
+ },
142
+ estimated_fields: [
143
+ 'route_segments[].departure_at',
144
+ 'route_segments[].arrival_at',
145
+ 'route_segments[].transport_number',
146
+ 'price',
147
+ ],
148
+ provenance: provenance(input.snapshot),
149
+ };
150
+ }
@@ -0,0 +1,109 @@
1
+ /**
2
+ * SessionTransport(会话检索传输层,RFC §3.2;2026-08-28 定案 puppeteer-core):
3
+ * - mode=cdp(默认):attach 用户日常 Chrome——Chrome 144+ 调试服务(chrome://inspect 开关)
4
+ * 与 playwright 不兼容(握手后 CDP 初始化悬挂,实测三轮),与 puppeteer 完全兼容(实测 2256 cookies)。
5
+ * 发现走 user-data-dir 的 DevToolsActivePort 文件(HTTP 发现面已硬化 404;Origin 头=403,安全设计)。
6
+ * close() 只 disconnect,绝不关用户浏览器。
7
+ * - mode=persistent(测试/后备):puppeteer.launch 专用 profile(测试用 mktemp 隔离匿名态)。
8
+ * fail-closed(RFC §3.3-④):guard 装不上 = 整个会话打不开——不存在「无守卫的会话」这一形态。
9
+ * 永不抛错:任何启动失败降级为 TransportFailure,由 session-search 编排层消费。
10
+ */
11
+ import { readFileSync } from 'node:fs';
12
+ import { homedir } from 'node:os';
13
+ import { attachReadGuardPuppeteer } from './read-guard.js';
14
+ /**
15
+ * puppeteer-core 为可选依赖(D-14:产品运行时零硬依赖,缺则优雅降级)。
16
+ * 顶层动态 import——npm 形态若未装 puppeteer-core,openSession 返回 TransportFailure
17
+ * 而非在模块加载期炸掉整个插件(2026-08-28 发布面实测:静态 import 会拖垮 index.ts 加载链)。
18
+ */
19
+ async function loadPuppeteer() {
20
+ try {
21
+ return await import('puppeteer-core');
22
+ }
23
+ catch {
24
+ return { missing: true };
25
+ }
26
+ }
27
+ function devtoolsWsEndpoint() {
28
+ try {
29
+ const udd = process.env.CHROME_USER_DATA_DIR ?? `${homedir()}/Library/Application Support/Google/Chrome`;
30
+ const [port, wsPath] = readFileSync(`${udd}/DevToolsActivePort`, 'utf8').trim().split('\n');
31
+ if (!port || !wsPath?.startsWith('/devtools/browser/')) {
32
+ return { err: `DevToolsActivePort 内容异常: ${String(port)}/${String(wsPath)}` };
33
+ }
34
+ return { ws: `ws://127.0.0.1:${port.trim()}${wsPath.trim()}` };
35
+ }
36
+ catch {
37
+ return { err: '日常 Chrome 未开调试端口。开启方法:Chrome 打开 chrome://inspect/#remote-debugging → 打开开关(Chrome 144+)' };
38
+ }
39
+ }
40
+ export async function openSession(opts = {}) {
41
+ const pp = await loadPuppeteer();
42
+ if ('missing' in pp) {
43
+ return { ok: false, summary: 'puppeteer-core 未安装(可选依赖):会话检索不可用,官方通道 gotry_flyai_search 仍可用。安装:npm i -D puppeteer-core' };
44
+ }
45
+ const puppeteer = pp.default;
46
+ const useCdp = opts.mode === 'cdp' || (opts.mode !== 'persistent' && !opts.profileDir);
47
+ let browser;
48
+ let isCdp = false;
49
+ if (useCdp) {
50
+ const d = devtoolsWsEndpoint();
51
+ if ('err' in d)
52
+ return { ok: false, summary: d.err };
53
+ try {
54
+ browser = await puppeteer.connect({ browserWSEndpoint: d.ws, defaultViewport: null });
55
+ isCdp = true;
56
+ }
57
+ catch (e) {
58
+ const msg = e instanceof Error ? e.message : e?.message ?? JSON.stringify(e).slice(0, 200);
59
+ return { ok: false, summary: `cdp attach 失败:${String(msg).split('\n')[0]}` };
60
+ }
61
+ }
62
+ else {
63
+ const { tmpdir } = await import('node:os');
64
+ const profileDir = opts.profileDir ?? `${tmpdir()}/gotry-session-profile`;
65
+ try {
66
+ browser = await puppeteer.launch({ channel: 'chrome', headless: opts.headless ?? true, userDataDir: profileDir });
67
+ }
68
+ catch (e) {
69
+ return { ok: false, summary: `chrome launch failed: ${e instanceof Error ? e.message.split('\n')[0] : String(e)}` };
70
+ }
71
+ }
72
+ // fail-closed:guard 装不上即断开返回失败——不给无守卫的检索会话形态
73
+ // (唯一豁免:登录 bootstrap 显式 guard:false,见 TransportOptions 注释)
74
+ let guard;
75
+ if (opts.guard !== false) {
76
+ try {
77
+ guard = await attachReadGuardPuppeteer(browser, opts.auditPath);
78
+ }
79
+ catch (e) {
80
+ await (isCdp ? browser.disconnect() : browser.close()).catch(() => { });
81
+ return { ok: false, summary: `read-guard attach failed: ${e instanceof Error ? e.message.split('\n')[0] : String(e)}` };
82
+ }
83
+ }
84
+ // 标签页纪律:ownPage=自己开的新页(newPage:true)——用它,收尾按 closeOwnPage 关;
85
+ // 否则沿用既有首页(仅 persistent 兼容形态;cdp 检索/登录一律 newPage)
86
+ let ownPage = false;
87
+ let page;
88
+ if (opts.newPage) {
89
+ page = await browser.newPage();
90
+ ownPage = true;
91
+ }
92
+ else {
93
+ page = (await browser.pages())[0] ?? await browser.newPage();
94
+ }
95
+ return {
96
+ ok: true,
97
+ browser,
98
+ page,
99
+ guard: guard ?? { blockedCount: () => 0, requestCount: () => 0 },
100
+ close: async () => {
101
+ // 自己开的标签页按 closeOwnPage 收尾(登录引导保持 false——登录页留给用户);
102
+ // cdp:只断开连接,绝不关用户浏览器;persistent:关自己拉起的实例
103
+ if (ownPage && (opts.closeOwnPage ?? true)) {
104
+ await page.close().catch(() => { });
105
+ }
106
+ await (isCdp ? browser.disconnect() : browser.close()).catch(() => { });
107
+ },
108
+ };
109
+ }