@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.
- package/README.md +172 -219
- package/README.zh-CN.md +222 -0
- package/bin/gotry-backend.js +53 -0
- package/bin/gotry-booking-copilot.js +53 -0
- package/bin/gotry-bootstrap.js +1788 -0
- package/bin/gotry-inner.js +733 -83
- package/bin/gotry-process-liveness.d.ts +27 -0
- package/bin/gotry-process-liveness.js +97 -0
- package/bin/gotry-runtime-resolution.d.ts +27 -0
- package/bin/gotry-runtime-resolution.js +49 -0
- package/bin/gotry.js +1 -1
- package/client/client.js +203 -0
- package/cordis.gotry-patch.yml +80 -56
- package/data/airline-airports.json +39 -0
- package/data/stations-12306-verify.json +524 -0
- package/dist/capabilities/agent-reach-deep.js +45 -122
- package/dist/capabilities/agent-reach.js +101 -146
- package/dist/capabilities/anything.js +161 -94
- package/dist/capabilities/artifacts.js +370 -0
- package/dist/capabilities/channel-health.js +131 -0
- package/dist/capabilities/channel-registry.js +256 -0
- package/dist/capabilities/doctor.js +553 -0
- package/dist/capabilities/effect.js +394 -0
- package/dist/capabilities/external-event.js +149 -0
- package/dist/capabilities/fact-log.js +55 -0
- package/dist/capabilities/flyai-config.js +337 -0
- package/dist/capabilities/flyai.js +947 -110
- package/dist/capabilities/fx-contract.js +293 -0
- package/dist/capabilities/geo-atlas.js +246 -0
- package/dist/capabilities/ground-transfer.js +676 -0
- package/dist/capabilities/hbcli.js +260 -123
- package/dist/capabilities/hotelbyte-transaction.js +194 -0
- package/dist/capabilities/incident-log.js +131 -61
- package/dist/capabilities/itinerary-artifact.js +190 -0
- package/dist/capabilities/itinerary-deck-artifact.js +194 -0
- package/dist/capabilities/itinerary-deck-export.js +339 -0
- package/dist/capabilities/lavish-local.js +924 -0
- package/dist/capabilities/model-override.js +38 -0
- package/dist/capabilities/opensky.js +54 -43
- package/dist/capabilities/provider-detail-sanitize.js +64 -0
- package/dist/capabilities/resilience.js +191 -0
- package/dist/capabilities/route-provider-conformance.js +341 -0
- package/dist/capabilities/session/action-cache.js +50 -44
- package/dist/capabilities/session/adapters/ctrip-flight.js +120 -62
- package/dist/capabilities/session/adapters/ctrip-hotel.js +222 -0
- package/dist/capabilities/session/adapters/dida-portal.js +274 -0
- package/dist/capabilities/session/adapters/meituan-local.js +35 -54
- package/dist/capabilities/session/adapters/rail-12306.js +342 -0
- package/dist/capabilities/session/benchmark.js +189 -0
- package/dist/capabilities/session/bridge-ledger.js +224 -0
- package/dist/capabilities/session/extension-bridge.js +636 -0
- package/dist/capabilities/session/extension-channel.js +109 -0
- package/dist/capabilities/session/extension-distribution.js +230 -0
- package/dist/capabilities/session/extract.js +31 -21
- package/dist/capabilities/session/golden-score.js +114 -0
- package/dist/capabilities/session/health-watch.js +215 -0
- package/dist/capabilities/session/read-guard.js +75 -24
- package/dist/capabilities/session/static-flight-golden.js +150 -0
- package/dist/capabilities/session/transport.js +97 -83
- package/dist/capabilities/session/wizard.js +117 -0
- package/dist/capabilities/session-consent.js +178 -0
- package/dist/capabilities/session-login.js +170 -0
- package/dist/capabilities/session-search.js +635 -44
- package/dist/capabilities/spawn-bounded.js +203 -0
- package/dist/capabilities/sponsor-plugin.js +341 -0
- package/dist/capabilities/visa-policy.js +140 -0
- package/dist/capabilities/weather.js +243 -138
- package/dist/data/session-golden-20.json +25 -0
- package/dist/data/sf-golden-manifest.json +103 -0
- package/dist/data/sf-static-routes.json +91 -0
- package/dist/scripts/action-cache-tests.js +24 -59
- package/dist/scripts/agent-planning-turn-deadline-e2e.js +242 -0
- package/dist/scripts/agent-planning-turn-deadline-tests.js +185 -0
- package/dist/scripts/agent-reach-deep-tests.js +30 -40
- package/dist/scripts/agent-reach-error-tests.js +354 -0
- package/dist/scripts/agent-reach-tests.js +26 -18
- package/dist/scripts/agent-reach-wrapper-tests.js +50 -50
- package/dist/scripts/anything-path-measure-tests.js +133 -0
- package/dist/scripts/anything-path-measure.js +150 -0
- package/dist/scripts/anything-tests.js +250 -60
- package/dist/scripts/artifact-client-contract-tests.js +220 -0
- package/dist/scripts/artifacts-capability-tests.js +727 -0
- package/dist/scripts/async-collect.js +50 -11
- package/dist/scripts/benchmark-environment-bridge-e2e.js +741 -0
- package/dist/scripts/benchmark-environment-bridge-tests.js +1452 -0
- package/dist/scripts/booking-copilot-availability-ledger-binding-tests.js +126 -0
- package/dist/scripts/booking-copilot-availability-policy-tests.js +265 -0
- package/dist/scripts/booking-copilot-bin-proof-tests.js +66 -0
- package/dist/scripts/booking-copilot-cleanup-proof-helper.js +76 -0
- package/dist/scripts/booking-copilot-crossrepo-fixture-server.js +144 -0
- package/dist/scripts/booking-copilot-dsh-core-proof-tests.js +424 -0
- package/dist/scripts/booking-copilot-dsh-planner-proof-tests.js +2839 -0
- package/dist/scripts/booking-copilot-dsh-plugin-proof-tests.js +309 -0
- package/dist/scripts/booking-copilot-dsh-readiness-proof.js +238 -0
- package/dist/scripts/booking-copilot-dsh-warmer-proof.js +126 -0
- package/dist/scripts/booking-copilot-event-sequence-concurrency-proof-tests.js +156 -0
- package/dist/scripts/booking-copilot-gap-code-contract-proof-tests.js +70 -0
- package/dist/scripts/booking-copilot-intent-proof-tests.js +422 -0
- package/dist/scripts/booking-copilot-operation-ledger-concurrency-proof-tests.js +184 -0
- package/dist/scripts/booking-copilot-planner-live-probe.js +95 -0
- package/dist/scripts/booking-copilot-proof-runtime.js +42 -0
- package/dist/scripts/booking-copilot-receipt-ledger-concurrency-proof-tests.js +210 -0
- package/dist/scripts/booking-copilot-runtime-proof-tests.js +2349 -0
- package/dist/scripts/booking-copilot-server-proof-tests.js +784 -0
- package/dist/scripts/booking-copilot-startup-proof-tests.js +94 -0
- package/dist/scripts/booking-executor-tests.js +80 -0
- package/dist/scripts/booking-recovery-chain-tests.js +182 -0
- package/dist/scripts/booking-saga-tests.js +125 -0
- package/dist/scripts/booking-surface-contract-proof-tests.js +212 -0
- package/dist/scripts/bootstrap-tests.js +1549 -0
- package/dist/scripts/bridge-events-tests.js +239 -0
- package/dist/scripts/bridge-ledger-tests.js +428 -0
- package/dist/scripts/build-changelog.js +238 -0
- package/dist/scripts/build-metrics-report.js +331 -0
- package/dist/scripts/changelog-tests.js +118 -0
- package/dist/scripts/channel-probe-tests.js +103 -0
- package/dist/scripts/channel-probe.js +169 -0
- package/dist/scripts/channel-registry-tests.js +208 -0
- package/dist/scripts/city-scenario-tier-tests.js +234 -0
- package/dist/scripts/companion-tests.js +25 -70
- package/dist/scripts/dida-cookie-probe.js +87 -0
- package/dist/scripts/dida-runner-stop-tests.js +311 -0
- package/dist/scripts/dida-sw-probe.js +114 -0
- package/dist/scripts/diff-test.js +17 -12
- package/dist/scripts/doctor-tests.js +600 -0
- package/dist/scripts/drill-multiuser-ledger-tests.js +1076 -0
- package/dist/scripts/drill-sdk-descendant-cleanup-tests.js +606 -0
- package/dist/scripts/drill-w2a-sensor-tests.js +788 -0
- package/dist/scripts/dsh-artifact-e2e.js +279 -0
- package/dist/scripts/dsh-artifact-web-e2e.js +675 -0
- package/dist/scripts/dsh-http-proxy-sse-proof.js +90 -0
- package/dist/scripts/dsh-llm-tests.js +437 -0
- package/dist/scripts/dsh-runtime-closure-tests.js +182 -0
- package/dist/scripts/dsh-runtime-closure.js +162 -0
- package/dist/scripts/dsh-session-v3-migration-proof.js +109 -0
- package/dist/scripts/dsh-subprocess-local-proof.js +150 -0
- package/dist/scripts/dsh-target-closure-proof.js +178 -0
- package/dist/scripts/effect-tests.js +539 -0
- package/dist/scripts/engine-run.js +1 -3
- package/dist/scripts/engine-tests.js +16 -10
- package/dist/scripts/evaluation-cadence-tests.js +174 -0
- package/dist/scripts/evaluation-contract-tests.js +268 -0
- package/dist/scripts/extension-distribution-cli.js +39 -0
- package/dist/scripts/extension-distribution-tests.js +443 -0
- package/dist/scripts/extension-tests.js +988 -0
- package/dist/scripts/external-event-tests.js +350 -0
- package/dist/scripts/fact-gate-tests.js +869 -0
- package/dist/scripts/fixtures/extension-bridge-unref-child.mjs +21 -0
- package/dist/scripts/flight-hotel-anchor-363-registered-e2e.js +169 -0
- package/dist/scripts/flight-malformed-tests.js +159 -0
- package/dist/scripts/flyai-setup-tests.js +228 -0
- package/dist/scripts/flyai-setup-tool-tests.js +54 -0
- package/dist/scripts/flyai-tests.js +692 -0
- package/dist/scripts/flyai-tool-registration-contract-tests.js +91 -0
- package/dist/scripts/fx-contract-tests.js +201 -0
- package/dist/scripts/g5-guard-tests.js +150 -0
- package/dist/scripts/g5-guard.js +193 -0
- package/dist/scripts/gen-lunar-anchors.js +106 -0
- package/dist/scripts/geo-atlas-tests.js +283 -0
- package/dist/scripts/gotry-backend-kernel-tests.js +206 -0
- package/dist/scripts/gotry-try-demo-tests.js +79 -0
- package/dist/scripts/gotry-try-demo.js +49 -0
- package/dist/scripts/ground-transfer-tests.js +956 -0
- package/dist/scripts/hbcli-e2e-tests.js +159 -0
- package/dist/scripts/hbcli-live-optin-tests.js +96 -0
- package/dist/scripts/hbcli-release-contract-tests.js +122 -0
- package/dist/scripts/hbcli-tests.js +121 -69
- package/dist/scripts/health-watch-cli.js +73 -0
- package/dist/scripts/hotel-date-gate-tests.js +496 -0
- package/dist/scripts/hotelbyte-reconcile-tests.js +141 -0
- package/dist/scripts/hotelbyte-spawn-e2e-tests.js +373 -0
- package/dist/scripts/i18n-tests.js +41 -0
- package/dist/scripts/incident-tests.js +281 -87
- package/dist/scripts/issue-194-job-id-guard-tests.js +106 -0
- package/dist/scripts/issue-233-cancel-refund-commission-tests.js +392 -0
- package/dist/scripts/issue-271-liveness-tests.js +569 -0
- package/dist/scripts/issue-289-model-retry-real-tests.js +296 -0
- package/dist/scripts/issue-289-model-retry-tests.js +441 -0
- package/dist/scripts/issue-289-web-retry-e2e.js +630 -0
- package/dist/scripts/issue-338-home-city-e2e.js +577 -0
- package/dist/scripts/issue343-real-entry-e2e.js +160 -0
- package/dist/scripts/issue436-persisted-routing-e2e.js +247 -0
- package/dist/scripts/itinerary-artifact-tests.js +368 -0
- package/dist/scripts/itinerary-deck-artifact-tests.js +416 -0
- package/dist/scripts/itinerary-deck-export-tests.js +552 -0
- package/dist/scripts/itinerary-deck-tests.js +435 -0
- package/dist/scripts/itinerary-html-tests.js +426 -0
- package/dist/scripts/journey-tests.js +22 -27
- package/dist/scripts/kernel-manifest-evidence.js +109 -0
- package/dist/scripts/kernel-manifest-gate.js +126 -0
- package/dist/scripts/kernel-manifest-tests.js +212 -0
- package/dist/scripts/kernel-manifest-trace-entry.js +7 -0
- package/dist/scripts/kernel-manifest-trace-hook.mjs +28 -0
- package/dist/scripts/kernel-manifest.js +369 -0
- package/dist/scripts/lavish-local-tests.js +1226 -0
- package/dist/scripts/lavish-product-tools-tests.js +537 -0
- package/dist/scripts/ledger-repair-apply-tests.js +316 -0
- package/dist/scripts/ledger-repair-plan-tests.js +375 -0
- package/dist/scripts/ledger-tests.js +382 -246
- package/dist/scripts/ledger-workflow-crash.js +10 -20
- package/dist/scripts/m3-cohort-tests.js +714 -0
- package/dist/scripts/m3-cohort.js +310 -0
- package/dist/scripts/managed-dsh-cleanup-diagnostic-proof.js +184 -0
- package/dist/scripts/managed-dsh-close-failure-proof.js +172 -0
- package/dist/scripts/managed-dsh-run-port-proof.js +153 -0
- package/dist/scripts/managed-dsh-terminal-proof.js +252 -0
- package/dist/scripts/map-tools-vendor-package-proof.js +365 -0
- package/dist/scripts/memory-capture-tests.js +242 -61
- package/dist/scripts/memory-decay-tests.js +18 -52
- package/dist/scripts/memory-lifecycle-tests.js +657 -0
- package/dist/scripts/memory-lifecycle.js +196 -0
- package/dist/scripts/memory-metrics.js +24 -12
- package/dist/scripts/memory-value-report.js +631 -0
- package/dist/scripts/memory-value-tests.js +328 -0
- package/dist/scripts/metrics-report-tests.js +151 -0
- package/dist/scripts/model-override-e2e.js +137 -0
- package/dist/scripts/nightly-evidence-tests.js +203 -0
- package/dist/scripts/nightly-evidence.js +303 -0
- package/dist/scripts/nudge-digest.js +39 -28
- package/dist/scripts/observability-tests.js +381 -0
- package/dist/scripts/onboarding-tests.js +161 -0
- package/dist/scripts/opensky-check.js +18 -13
- package/dist/scripts/opensky-tests.js +28 -28
- package/dist/scripts/outcome-projection-tests.js +427 -0
- package/dist/scripts/persona-sim-tests.js +603 -0
- package/dist/scripts/persona-sim.js +1081 -0
- package/dist/scripts/persona-surface-guard-tests.js +49 -0
- package/dist/scripts/pnpm-dsh-closure-proof.js +17 -0
- package/dist/scripts/policy-anchor-359-registered-e2e.js +214 -0
- package/dist/scripts/price-drift-tests.js +340 -0
- package/dist/scripts/price-drift-watch.js +447 -0
- package/dist/scripts/probe-poi-tests.js +53 -45
- package/dist/scripts/product-metrics.js +483 -0
- package/dist/scripts/publish-preverify.js +110 -0
- package/dist/scripts/realtime-pricing-tests.js +76 -0
- package/dist/scripts/recall-tests.js +513 -0
- package/dist/scripts/replay-async.js +22 -18
- package/dist/scripts/replay-real.js +18 -18
- package/dist/scripts/replay.js +54 -82
- package/dist/scripts/route-provider-conformance-tests.js +391 -0
- package/dist/scripts/session-attach-diagnose.js +20 -20
- package/dist/scripts/session-attach-poc.js +34 -37
- package/dist/scripts/session-benchmark.js +180 -0
- package/dist/scripts/session-dida-live-e2e.js +199 -0
- package/dist/scripts/session-extract-tests.js +14 -35
- package/dist/scripts/session-link-tests.js +478 -0
- package/dist/scripts/session-login.js +27 -46
- package/dist/scripts/session-tests.js +796 -96
- package/dist/scripts/session-zone-crash.js +49 -0
- package/dist/scripts/session-zone-ledger-tests.js +432 -0
- package/dist/scripts/session-zone-observation-tests.js +492 -0
- package/dist/scripts/session-zone-observe.js +135 -0
- package/dist/scripts/session-zone-wiring-tests.js +566 -0
- package/dist/scripts/session-zones-tests.js +374 -0
- package/dist/scripts/sf-live-benchmark.js +367 -0
- package/dist/scripts/sf-live-challenge-stop-tests.js +453 -0
- package/dist/scripts/sf-live-cli-tests.js +92 -0
- package/dist/scripts/sf-live-options.js +46 -0
- package/dist/scripts/sf-manifest-tests.js +30 -0
- package/dist/scripts/sf-manifest.js +33 -0
- package/dist/scripts/sf-soft-score-tests.js +67 -0
- package/dist/scripts/sf-summary-tests.js +324 -0
- package/dist/scripts/sf-summary.js +525 -0
- package/dist/scripts/share-tests.js +432 -0
- package/dist/scripts/skeleton-check.js +16 -14
- package/dist/scripts/skeleton-integration-test.js +28 -11
- package/dist/scripts/skills-contract-tests.js +51 -46
- package/dist/scripts/smoke-session-gate-tests.js +21 -0
- package/dist/scripts/smoke.js +690 -246
- package/dist/scripts/spawn-bounded-abort-tests.js +244 -0
- package/dist/scripts/sponsor-reuse-tests.js +262 -0
- package/dist/scripts/state-cli-tests.js +226 -101
- package/dist/scripts/state-cli.js +565 -198
- package/dist/scripts/state-repair-cli.js +66 -0
- package/dist/scripts/state-repair-tests.js +140 -0
- package/dist/scripts/static-golden-tests.js +165 -0
- package/dist/scripts/time-eval-tests.js +212 -192
- package/dist/scripts/travel-timeline-tests.js +29 -93
- package/dist/scripts/turn-handoff-collect-tests.js +169 -0
- package/dist/scripts/turn-handoff-collect.js +161 -0
- package/dist/scripts/turn-policy-tests.js +55 -0
- package/dist/scripts/typed-contract-canary.js +176 -0
- package/dist/scripts/tz-resolver-sanity.js +50 -0
- package/dist/scripts/tz-resolver-tests.js +584 -0
- package/dist/scripts/unified-tests.js +60 -20
- package/dist/scripts/visa-policy-tests.js +62 -0
- package/dist/scripts/weather-tests.js +276 -41
- package/dist/scripts/wish-channel-gate-tests.js +54 -0
- package/dist/scripts/write-gate-tests.js +522 -0
- package/dist/scripts/z3-lifecycle-fault-tests.js +188 -0
- package/dist/scripts/z3-lifecycle-tests.js +170 -0
- package/dist/scripts/z3-race-repeat-tests.js +39 -0
- package/dist/scripts/z3-race-tests.js +46 -0
- package/dist/src/artifact-gate.js +829 -0
- package/dist/src/backend/kernel.js +91 -0
- package/dist/src/backend/modules/booking-copilot.js +92 -0
- package/dist/src/backend/modules/booking-executor.js +124 -0
- package/dist/src/backend/modules/session-search.js +551 -0
- package/dist/src/benchmark-agent-conformance.js +578 -0
- package/dist/src/benchmark-environment-bridge.js +515 -0
- package/dist/src/benchmark-headless-child-diagnostics.js +166 -0
- package/dist/src/benchmark-tool-isolation.js +151 -0
- package/dist/src/bookable-facts.js +533 -0
- package/dist/src/booking-saga.js +97 -0
- package/dist/src/booking-surface/availability-policy.js +697 -0
- package/dist/src/booking-surface/booking-intent.js +43 -0
- package/dist/src/booking-surface/cancel-refund-commission.js +379 -0
- package/dist/src/booking-surface/canonical-schema.js +116 -0
- package/dist/src/booking-surface/contracts.js +75 -0
- package/dist/src/booking-surface/dsh-planner.js +1854 -0
- package/dist/src/booking-surface/dsh-plugin.js +378 -0
- package/dist/src/booking-surface/dsh-worker.js +98 -0
- package/dist/src/booking-surface/error-codes.js +231 -0
- package/dist/src/booking-surface/index.js +9 -0
- package/dist/src/booking-surface/managed-dsh-cleanup-diagnostic.js +97 -0
- package/dist/src/booking-surface/managed-dsh-run-port.js +244 -0
- package/dist/src/booking-surface/profile.js +24 -0
- package/dist/src/booking-surface/recovery-chain.js +367 -0
- package/dist/src/booking-surface/runtime.js +1968 -0
- package/dist/src/booking-surface/server.js +674 -0
- package/dist/src/booking-surface/startup.js +168 -0
- package/dist/src/booking-surface/validation.js +261 -0
- package/dist/src/bridge.js +20 -13
- package/dist/src/city-scenario-tier.js +378 -0
- package/dist/src/companions.js +48 -74
- package/dist/src/contracts.js +21 -43
- package/dist/src/dsh-llm.js +171 -115
- package/dist/src/engine.js +276 -193
- package/dist/src/evaluation-cadence.js +97 -0
- package/dist/src/evaluation-contracts.js +283 -0
- package/dist/src/flight-pack-adapter.js +54 -0
- package/dist/src/flight-pack-contract.js +2 -0
- package/dist/src/flyai-setup-tool.js +70 -0
- package/dist/src/gotry-backend.js +125 -0
- package/dist/src/hotel-date-gate.js +118 -0
- package/dist/src/i18n.js +88 -0
- package/dist/src/index.js +2385 -881
- package/dist/src/itinerary-deck.js +139 -0
- package/dist/src/itinerary-doc-shared.js +661 -0
- package/dist/src/itinerary-html.js +131 -0
- package/dist/src/journey.js +155 -108
- package/dist/src/lavish-tools.js +400 -0
- package/dist/src/ledger-repair-apply.js +538 -0
- package/dist/src/ledger-repair-plan.js +463 -0
- package/dist/src/loop.js +331 -161
- package/dist/src/m3-cohort.js +1577 -0
- package/dist/src/memory-capture.js +180 -32
- package/dist/src/memory-decay.js +30 -14
- package/dist/src/memory-lifecycle.js +1310 -0
- package/dist/src/memory-utility.js +27 -40
- package/dist/src/mock-llm.js +36 -61
- package/dist/src/model.js +81 -36
- package/dist/src/outcome-projection.js +746 -0
- package/dist/src/realtime-pricing.js +103 -0
- package/dist/src/recall/card.js +74 -0
- package/dist/src/recall/evaluator.js +140 -0
- package/dist/src/recall/integration.js +17 -0
- package/dist/src/recall/tick.js +166 -0
- package/dist/src/session-link/plan-it-action.js +48 -0
- package/dist/src/session-link/session-link.js +248 -0
- package/dist/src/session-zone-ledger.js +312 -0
- package/dist/src/session-zone-observation.js +354 -0
- package/dist/src/session-zone-wiring.js +658 -0
- package/dist/src/session-zones.js +510 -0
- package/dist/src/share/adapters.js +51 -0
- package/dist/src/share/share-consent.js +76 -0
- package/dist/src/share/share-deck.js +58 -0
- package/dist/src/share/share-token.js +146 -0
- package/dist/src/slot-spec.js +84 -106
- package/dist/src/state-ledger.js +696 -524
- package/dist/src/state-repair.js +299 -0
- package/dist/src/subagent-job-id-guard.js +58 -0
- package/dist/src/time-anchor.js +231 -33
- package/dist/src/tool-packet.js +20 -8
- package/dist/src/travel-slots.js +58 -35
- package/dist/src/travel-timeline.js +44 -63
- package/dist/src/turn-deadline.js +287 -0
- package/dist/src/turn-policy.js +118 -0
- package/dist/src/tz-resolver.js +143 -0
- package/dist/src/unified.js +600 -360
- package/dist/src/wish-pool.js +42 -12
- package/dist/src/write-gate.js +495 -0
- package/dist/src/z3-shared.js +284 -0
- package/extension/README.md +21 -0
- package/extension/README.zh-CN.md +21 -0
- package/extension/background.js +463 -0
- package/extension/content-bridge.js +270 -0
- package/extension/content-main.js +111 -0
- package/extension/manifest.json +60 -0
- package/package.json +407 -14
- package/schemas/booking.intent.schema.json +193 -0
- package/schemas/booking.surface.schema.json +2622 -0
- package/ts/capabilities/agent-reach-deep.ts +114 -0
- package/ts/capabilities/agent-reach.ts +198 -0
- package/ts/capabilities/anything.ts +282 -0
- package/ts/capabilities/artifacts.ts +428 -0
- package/ts/capabilities/fact-log.ts +54 -0
- package/ts/capabilities/flyai-config.ts +388 -0
- package/ts/capabilities/flyai.ts +1274 -0
- package/ts/capabilities/hbcli.ts +253 -71
- package/ts/capabilities/incident-log.ts +88 -59
- package/ts/capabilities/itinerary-artifact.ts +214 -0
- package/ts/capabilities/itinerary-deck-artifact.ts +218 -0
- package/ts/capabilities/itinerary-deck-export.ts +378 -0
- package/ts/capabilities/opensky.ts +121 -0
- package/ts/capabilities/session/action-cache.ts +148 -0
- package/ts/capabilities/session/adapters/ctrip-flight.ts +181 -0
- package/ts/capabilities/session/adapters/ctrip-hotel.ts +238 -0
- package/ts/capabilities/session/adapters/dida-portal.ts +338 -0
- package/ts/capabilities/session/adapters/meituan-local.ts +70 -0
- package/ts/capabilities/session/adapters/rail-12306.ts +392 -0
- package/ts/capabilities/session/benchmark.ts +276 -0
- package/ts/capabilities/session/bridge-ledger.ts +333 -0
- package/ts/capabilities/session/extension-bridge.ts +794 -0
- package/ts/capabilities/session/extension-channel.ts +144 -0
- package/ts/capabilities/session/extension-distribution.ts +266 -0
- package/ts/capabilities/session/extract.ts +54 -0
- package/ts/capabilities/session/golden-score.ts +139 -0
- package/ts/capabilities/session/health-watch.ts +264 -0
- package/ts/capabilities/session/read-guard.ts +141 -0
- package/ts/capabilities/session/static-flight-golden.ts +209 -0
- package/ts/capabilities/session/transport.ts +146 -0
- package/ts/capabilities/session/wizard.ts +140 -0
- package/ts/capabilities/session-consent.ts +211 -0
- package/ts/capabilities/session-login.ts +208 -0
- package/ts/capabilities/session-search.ts +893 -0
- package/ts/capabilities/weather.ts +330 -0
- package/ts/dsh-runtime/vendor/README.md +68 -0
- package/ts/dsh-runtime/vendor/dsh-map-tools/LICENSE +21 -0
- package/ts/dsh-runtime/vendor/dsh-map-tools/README.en.md +405 -0
- package/ts/dsh-runtime/vendor/dsh-map-tools/README.md +404 -0
- package/ts/dsh-runtime/vendor/dsh-map-tools/client/client.js +1584 -0
- package/ts/dsh-runtime/vendor/dsh-map-tools/cordis.patch.yml +5 -0
- package/ts/dsh-runtime/vendor/dsh-map-tools/icon.svg +5 -0
- package/ts/dsh-runtime/vendor/dsh-map-tools/lib/clients/amap.js +595 -0
- package/ts/dsh-runtime/vendor/dsh-map-tools/lib/clients/nominatim.js +63 -0
- package/ts/dsh-runtime/vendor/dsh-map-tools/lib/clients/osrm.js +58 -0
- package/ts/dsh-runtime/vendor/dsh-map-tools/lib/clients/photon.js +55 -0
- package/ts/dsh-runtime/vendor/dsh-map-tools/lib/config-file.js +87 -0
- package/ts/dsh-runtime/vendor/dsh-map-tools/lib/config-route.js +131 -0
- package/ts/dsh-runtime/vendor/dsh-map-tools/lib/config.js +16 -0
- package/ts/dsh-runtime/vendor/dsh-map-tools/lib/geo.js +232 -0
- package/ts/dsh-runtime/vendor/dsh-map-tools/lib/index.js +120 -0
- package/ts/dsh-runtime/vendor/dsh-map-tools/lib/settings-ns.js +40 -0
- package/ts/dsh-runtime/vendor/dsh-map-tools/lib/staticmap-route.js +115 -0
- package/ts/dsh-runtime/vendor/dsh-map-tools/lib/tools/geocode.js +127 -0
- package/ts/dsh-runtime/vendor/dsh-map-tools/lib/tools/poi.js +84 -0
- package/ts/dsh-runtime/vendor/dsh-map-tools/lib/tools/routes.js +267 -0
- package/ts/dsh-runtime/vendor/dsh-map-tools/lib/types/clients/amap.d.ts +90 -0
- package/ts/dsh-runtime/vendor/dsh-map-tools/lib/types/clients/nominatim.d.ts +17 -0
- package/ts/dsh-runtime/vendor/dsh-map-tools/lib/types/clients/osrm.d.ts +15 -0
- package/ts/dsh-runtime/vendor/dsh-map-tools/lib/types/clients/photon.d.ts +22 -0
- package/ts/dsh-runtime/vendor/dsh-map-tools/lib/types/config-file.d.ts +33 -0
- package/ts/dsh-runtime/vendor/dsh-map-tools/lib/types/config-route.d.ts +23 -0
- package/ts/dsh-runtime/vendor/dsh-map-tools/lib/types/config.d.ts +23 -0
- package/ts/dsh-runtime/vendor/dsh-map-tools/lib/types/geo.d.ts +61 -0
- package/ts/dsh-runtime/vendor/dsh-map-tools/lib/types/index.d.ts +18 -0
- package/ts/dsh-runtime/vendor/dsh-map-tools/lib/types/settings-ns.d.ts +14 -0
- package/ts/dsh-runtime/vendor/dsh-map-tools/lib/types/staticmap-route.d.ts +31 -0
- package/ts/dsh-runtime/vendor/dsh-map-tools/lib/types/tools/geocode.d.ts +11 -0
- package/ts/dsh-runtime/vendor/dsh-map-tools/lib/types/tools/poi.d.ts +9 -0
- package/ts/dsh-runtime/vendor/dsh-map-tools/lib/types/tools/routes.d.ts +75 -0
- package/ts/dsh-runtime/vendor/dsh-map-tools/lib/types/types.d.ts +68 -0
- package/ts/dsh-runtime/vendor/dsh-map-tools/lib/types.js +16 -0
- package/ts/dsh-runtime/vendor/dsh-map-tools/package.json +97 -0
- package/ts/package.json +293 -3
- package/ts/scripts/async-collect.ts +91 -0
- package/ts/scripts/map-tools-vendor-package-proof.ts +404 -0
- package/ts/scripts/skeleton-check.ts +1 -1
- package/ts/scripts/skeleton-integration-test.ts +23 -1
- package/ts/scripts/state-cli.ts +586 -0
- package/ts/scripts/turn-handoff-collect.ts +178 -0
- package/ts/src/artifact-gate.ts +991 -0
- package/ts/src/benchmark-agent-conformance.ts +619 -0
- package/ts/src/benchmark-environment-bridge.ts +538 -0
- package/ts/src/benchmark-headless-child-diagnostics.ts +184 -0
- package/ts/src/benchmark-tool-isolation.ts +166 -0
- package/ts/src/bookable-facts.ts +837 -0
- package/ts/src/booking-saga.ts +133 -0
- package/ts/src/booking-surface/availability-policy.ts +522 -0
- package/ts/src/booking-surface/booking-intent.ts +86 -0
- package/ts/src/booking-surface/cancel-refund-commission.ts +488 -0
- package/ts/src/booking-surface/canonical-schema.js +116 -0
- package/ts/src/booking-surface/contracts.ts +475 -0
- package/ts/src/booking-surface/dsh-planner.ts +1949 -0
- package/ts/src/booking-surface/dsh-plugin.js +378 -0
- package/ts/src/booking-surface/dsh-worker.ts +110 -0
- package/ts/src/booking-surface/error-codes.ts +241 -0
- package/ts/src/booking-surface/index.ts +9 -0
- package/ts/src/booking-surface/managed-dsh-cleanup-diagnostic.ts +151 -0
- package/ts/src/booking-surface/managed-dsh-run-port.ts +273 -0
- package/ts/src/booking-surface/profile.ts +42 -0
- package/ts/src/booking-surface/recovery-chain.ts +409 -0
- package/ts/src/booking-surface/runtime.ts +1793 -0
- package/ts/src/booking-surface/server.ts +733 -0
- package/ts/src/booking-surface/startup.ts +201 -0
- package/ts/src/booking-surface/validation.ts +217 -0
- package/ts/src/companions.ts +113 -0
- package/ts/src/contracts.ts +17 -3
- package/ts/src/dsh-llm.ts +152 -17
- package/ts/src/flyai-setup-tool.ts +77 -0
- package/ts/src/index.ts +2123 -200
- package/ts/src/itinerary-deck.ts +189 -0
- package/ts/src/itinerary-doc-shared.ts +741 -0
- package/ts/src/itinerary-html.ts +171 -0
- package/ts/src/loop.ts +234 -26
- package/ts/src/memory-capture.ts +283 -0
- package/ts/src/memory-decay.ts +55 -0
- package/ts/src/memory-utility.ts +70 -0
- package/ts/src/mock-llm.ts +4 -8
- package/ts/src/model.ts +88 -2
- package/ts/src/recall/card.ts +106 -0
- package/ts/src/recall/evaluator.ts +170 -0
- package/ts/src/recall/integration.ts +35 -0
- package/ts/src/recall/tick.ts +213 -0
- package/ts/src/session-link/plan-it-action.ts +78 -0
- package/ts/src/session-link/session-link.ts +275 -0
- package/ts/src/share/adapters.ts +93 -0
- package/ts/src/share/share-consent.ts +105 -0
- package/ts/src/share/share-deck.ts +85 -0
- package/ts/src/share/share-token.ts +166 -0
- package/ts/src/slot-spec.ts +172 -0
- package/ts/src/state-ledger.ts +1166 -0
- package/ts/src/subagent-job-id-guard.ts +72 -0
- package/ts/src/time-anchor.ts +338 -0
- package/ts/src/tool-packet.ts +32 -0
- package/ts/src/travel-slots.ts +219 -0
- package/ts/src/travel-timeline.ts +83 -0
- package/ts/src/turn-deadline.ts +366 -0
- package/ts/src/turn-policy.ts +154 -0
- package/ts/src/unified.ts +444 -105
- package/ts/src/wish-pool.ts +79 -0
- package/dist/scripts/session-attach-wait.js +0 -41
|
@@ -0,0 +1,566 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 会话双区记忆会话接线单测(P4-3,design/session-dual-zone-memory-design.md §5):
|
|
3
|
+
* - 总闸默认关:工具清单与注入面输出逐字节不变、零账本事件、读回空串(未知值同样关);
|
|
4
|
+
* - 捕获缝:白名单闭集内工具的结果信封只投影形状字段(verdict/条数/价格带),
|
|
5
|
+
* 零名称零 URL零自由文本;证据只走指针(摘要 session_ref + 观察序号);
|
|
6
|
+
* - 负面清单端到端:证件号/手机号/URL/凭证形态的载荷永不进任何一区;
|
|
7
|
+
* - 首访读回为空;有活笔记后读回有界(条数上界 + 字符上界);
|
|
8
|
+
* - 晋升:缺 owner 原话引用拒收;模型只可提议(propose 零落账);过期源拒收;
|
|
9
|
+
* - 路由规则(§3):preference→动机闸 / trip_fact→时间线闸 / 同行人约束→同行人闸,
|
|
10
|
+
* 缺路由载荷 routing_required 拒收(笔记本绝不私存该语义);既有闸拒绝即整笔回滚;
|
|
11
|
+
* - 更正即弃(drop)。
|
|
12
|
+
*
|
|
13
|
+
* 全离线:真实 apply() 注册面 + mkdtemp 隔离 stateRoot;零网络、零真实 LLM、
|
|
14
|
+
* 零对 ts/dsh-runtime/gotry-state 的写入(用前后快照断言)。
|
|
15
|
+
* 运行:cd ts && npx tsx scripts/session-zone-wiring-tests.ts
|
|
16
|
+
*/
|
|
17
|
+
import assert from 'node:assert/strict';
|
|
18
|
+
import { existsSync, mkdtempSync, readdirSync, rmSync, statSync } from 'node:fs';
|
|
19
|
+
import { tmpdir } from 'node:os';
|
|
20
|
+
import { join } from 'node:path';
|
|
21
|
+
import { apply } from '../src/index.js';
|
|
22
|
+
import { ensureLedger, openLedgerIfExists } from '../src/state-ledger.js';
|
|
23
|
+
import { readZoneLog } from '../src/session-zone-ledger.js';
|
|
24
|
+
import { ZONE_BRIEF_MAX_CHARS, ZONE_OBSERVABLE_TOOLS, classifyPromotionRouting, observeToolResult, projectToolObservation, promoteWithRouting, renderSessionZoneBrief, renderZoneBrief, resetZoneSessionBindingForTests, resolveZoneSwitch, routingEscapeViolation, zoneSessionRef, } from '../src/session-zone-wiring.js';
|
|
25
|
+
import { ZONE_EVENT_KINDS, readWorkingZone } from '../src/session-zones.js';
|
|
26
|
+
let n = 0;
|
|
27
|
+
function pass(name, body) {
|
|
28
|
+
return Promise.resolve(body()).then(() => {
|
|
29
|
+
console.log(` ${++n}. ${name} OK`);
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
const roots = [];
|
|
33
|
+
function freshRoot(tag) {
|
|
34
|
+
const root = mkdtempSync(join(tmpdir(), `gotry-zone-wire-${tag}-`));
|
|
35
|
+
roots.push(root);
|
|
36
|
+
return root;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* 离线检索夹具:注入 apply() 的 effect 缝,保证**绝不**触达真实 FlyAI
|
|
40
|
+
* (真实路径会从 homedir/env 读 key 并可能 spawn 真实 CLI,结果随机器而变)。
|
|
41
|
+
*/
|
|
42
|
+
const fixtureEffect = (async (fx) => {
|
|
43
|
+
if (fx.effect === 'FLYAI_SEARCH') {
|
|
44
|
+
return {
|
|
45
|
+
result: {
|
|
46
|
+
ok: true,
|
|
47
|
+
via: 'fixture',
|
|
48
|
+
evidence: '[fixture:zone-wiring] offline',
|
|
49
|
+
latencyMs: 0,
|
|
50
|
+
verdict: 'hit',
|
|
51
|
+
kind: fx.params?.kind ?? 'flight',
|
|
52
|
+
options: [
|
|
53
|
+
{ no: 'MU5111', name: '东方航空', depDateTime: '2027-11-11T07:35:00+08:00', arrDateTime: '2027-11-11T10:05:00+08:00', price: 880, jumpUrl: 'https://flights.example.com/a' },
|
|
54
|
+
{ no: 'CA1234', name: '国航', depDateTime: '2027-11-11T12:35:00+08:00', arrDateTime: '2027-11-11T15:05:00+08:00', price: 1260, jumpUrl: 'https://flights.example.com/b' },
|
|
55
|
+
],
|
|
56
|
+
},
|
|
57
|
+
trace: { effect: fx.effect, channel: 'fixture', attempts: 1, backoffMs: 0, breaker: 'off', evidence: ['[fixture:zone-wiring]'] },
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
return { result: null, trace: { effect: fx.effect, channel: 'fixture', attempts: 0, backoffMs: 0, breaker: 'off', evidence: ['[fixture:declined]'] } };
|
|
61
|
+
});
|
|
62
|
+
/** 真实 apply() 注册面(与 smoke 同款极简 ctx:只收工具与注入变量) */
|
|
63
|
+
function harness(cfg) {
|
|
64
|
+
const tools = [];
|
|
65
|
+
const variables = {};
|
|
66
|
+
const ctx = {
|
|
67
|
+
tools: { register: (t) => tools.push(t) },
|
|
68
|
+
systemPrompt: { variable: (name, provider) => { variables[name] = provider; } },
|
|
69
|
+
get: () => undefined,
|
|
70
|
+
on: () => () => { },
|
|
71
|
+
};
|
|
72
|
+
apply(ctx, {
|
|
73
|
+
timeoutMs: 30_000,
|
|
74
|
+
hbcliBin: 'hbcli-not-on-path',
|
|
75
|
+
sessionAccess: 'off',
|
|
76
|
+
...cfg,
|
|
77
|
+
}, { effect: fixtureEffect });
|
|
78
|
+
return {
|
|
79
|
+
tools,
|
|
80
|
+
variables,
|
|
81
|
+
tool: (name) => {
|
|
82
|
+
const t = tools.find(x => x.name === name);
|
|
83
|
+
if (!t)
|
|
84
|
+
throw new Error(`tool ${name} 未注册`);
|
|
85
|
+
return t;
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
const SESSION_ID = 'dsh-session-abcdef-0123456789';
|
|
90
|
+
/** scope 键 = dsh agent-loop 的 ScopeKey(agent 对象身份);exec.agent 是同一对象 */
|
|
91
|
+
const AGENT_A = { session: { id: SESSION_ID } };
|
|
92
|
+
const EXEC = { agent: AGENT_A };
|
|
93
|
+
const SESS = zoneSessionRef(SESSION_ID);
|
|
94
|
+
const SESSION_ID_B = 'dsh-session-999999-9876543210';
|
|
95
|
+
const AGENT_B = { session: { id: SESSION_ID_B } };
|
|
96
|
+
const EXEC_B = { agent: AGENT_B };
|
|
97
|
+
const SESS_B = zoneSessionRef(SESSION_ID_B);
|
|
98
|
+
const QUOTE = '对,我以后都不坐红眼航班,记着';
|
|
99
|
+
function zoneEventCount(root) {
|
|
100
|
+
const ledger = openLedgerIfExists(root);
|
|
101
|
+
if (!ledger)
|
|
102
|
+
return 0;
|
|
103
|
+
return ZONE_EVENT_KINDS.reduce((sum, k) => sum + ledger.readEvents(k, 10_000).length, 0);
|
|
104
|
+
}
|
|
105
|
+
/** 产品真实状态目录快照:本套件必须对它零写入 */
|
|
106
|
+
const RUNTIME_STATE = join(process.cwd(), 'dsh-runtime', 'gotry-state');
|
|
107
|
+
function runtimeSnapshot() {
|
|
108
|
+
if (!existsSync(RUNTIME_STATE))
|
|
109
|
+
return 'ABSENT';
|
|
110
|
+
return readdirSync(RUNTIME_STATE).sort().map(f => {
|
|
111
|
+
const s = statSync(join(RUNTIME_STATE, f));
|
|
112
|
+
return `${f}:${s.size}:${s.mtimeMs}`;
|
|
113
|
+
}).join('|');
|
|
114
|
+
}
|
|
115
|
+
const runtimeBefore = runtimeSnapshot();
|
|
116
|
+
async function main() {
|
|
117
|
+
// ---- 总闸语义 ----
|
|
118
|
+
await pass('总闸:仅明示 on 开启;缺省/未知值/大小写变体一律 fail-closed 关', () => {
|
|
119
|
+
assert.equal(resolveZoneSwitch('on'), 'on');
|
|
120
|
+
for (const raw of [undefined, null, '', 'off', 'ON', 'true', '1', 'enabled', 0, {}]) {
|
|
121
|
+
assert.equal(resolveZoneSwitch(raw), 'off', `未知值必须关:${JSON.stringify(raw)}`);
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
await pass('会话引用:单向摘要、不透明有界、绝不含宿主 session id 原文;无身份即无引用', () => {
|
|
125
|
+
assert.ok(SESS.startsWith('s-'));
|
|
126
|
+
assert.ok(SESS.length <= 64);
|
|
127
|
+
assert.equal(SESS.includes(SESSION_ID), false, '摘要不得回带原文');
|
|
128
|
+
assert.equal(zoneSessionRef(SESSION_ID), SESS, '同 id 同引用(确定性)');
|
|
129
|
+
assert.notEqual(zoneSessionRef('other-session'), SESS);
|
|
130
|
+
for (const bad of [undefined, null, '', ' ', 42])
|
|
131
|
+
assert.equal(zoneSessionRef(bad), null);
|
|
132
|
+
});
|
|
133
|
+
// ---- 关闸惰性 ----
|
|
134
|
+
await pass('关闸惰性:工具清单与注入面变量清单都与基线逐项一致(关闸与 main 不可区分)', async () => {
|
|
135
|
+
const offRoot = freshRoot('off');
|
|
136
|
+
const off = harness({ stateRoot: offRoot });
|
|
137
|
+
const onRoot = freshRoot('on');
|
|
138
|
+
const on = harness({ stateRoot: onRoot, sessionZones: 'on' });
|
|
139
|
+
const offNames = off.tools.map(t => t.name);
|
|
140
|
+
const onNames = on.tools.map(t => t.name);
|
|
141
|
+
assert.equal(offNames.includes('gotry_session_zone_note'), false, '关闸时模型看不到分区入口');
|
|
142
|
+
assert.equal(offNames.includes('gotry_session_zone_promote'), false);
|
|
143
|
+
assert.deepEqual(onNames.filter(x => !x.startsWith('gotry_session_zone')), offNames, '开关只增两件分区工具,其他工具清单逐项不变');
|
|
144
|
+
// 注入面:关闸时**连变量名都不得多出**——多一个名字就是可观测差异
|
|
145
|
+
// (§48 benchmark-environment-bridge-tests 对产品模式变量清单逐项断言)。
|
|
146
|
+
assert.deepEqual(Object.keys(off.variables), ['current_date', 'time_anchor_card', 'motivation_brief', 'channel_routing_card'], '关闸注入面与 main 逐项一致(session_zone_brief 未注册)');
|
|
147
|
+
assert.equal('session_zone_brief' in off.variables, false, '关闸不得注册分区读回变量');
|
|
148
|
+
assert.equal(typeof on.variables['session_zone_brief'], 'function', '开闸才注册分区读回变量');
|
|
149
|
+
assert.deepEqual(Object.keys(on.variables).filter(k => k !== 'session_zone_brief'), Object.keys(off.variables), '开闸只增 session_zone_brief 一个变量名,其余注入面顺序与内容不变');
|
|
150
|
+
assert.equal(existsSync(join(offRoot, 'gotry-state', 'gotry-state.db')), false, '关闸不得建库');
|
|
151
|
+
// 其他既有注入面输出不受影响(逐字节)。channel_routing_card 内含「卡生成于 <ISO 时间戳>」,两次渲染相隔数毫秒就不同——
|
|
152
|
+
// 先把 ISO 时间戳归一化再逐字节比较,否则这条断言取决于两次渲染是否落在同一毫秒(间歇性红,CI 上实测过)。
|
|
153
|
+
const stripStamp = (text) => text.replace(/\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?Z/g, '<ts>');
|
|
154
|
+
for (const key of ['current_date', 'time_anchor_card', 'motivation_brief', 'channel_routing_card']) {
|
|
155
|
+
assert.equal(stripStamp(off.variables[key]()), stripStamp(on.variables[key]()), `既有注入面 ${key} 输出逐字节不变(时间戳归一化后)`);
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
await pass('关闸惰性:白名单工具 execute 不被包裹——跑一次检索后账本零分区事件', async () => {
|
|
159
|
+
const root = freshRoot('off-observe');
|
|
160
|
+
const off = harness({ stateRoot: root });
|
|
161
|
+
const search = off.tool('gotry_flyai_search');
|
|
162
|
+
await search.execute({ kind: 'flight', from: '上海', to: '大理', date: '2027-11-11' }, EXEC);
|
|
163
|
+
assert.equal(zoneEventCount(root), 0, '关闸时检索不产生任何分区事件');
|
|
164
|
+
const ledger = openLedgerIfExists(root);
|
|
165
|
+
if (ledger) {
|
|
166
|
+
const kinds = new Set(ledger.readEvents(undefined, 200).map(e => e.kind));
|
|
167
|
+
for (const k of ZONE_EVENT_KINDS)
|
|
168
|
+
assert.equal(kinds.has(k), false, `关闸不得出现 ${k}`);
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
// ---- 捕获缝投影纯度 ----
|
|
172
|
+
await pass('捕获缝:白名单闭集外零捕获;投影只含形状字段(零名称/零 URL/零自由文本)', () => {
|
|
173
|
+
const base = { session_ref: SESS, turn: 3, ts: new Date().toISOString() };
|
|
174
|
+
assert.deepEqual(projectToolObservation({ ...base, tool: 'gotry_motivation_save', result: { ok: true } }), [], '白名单外工具零捕获');
|
|
175
|
+
assert.deepEqual(projectToolObservation({ ...base, tool: 'gotry_flyai_search', result: null }), []);
|
|
176
|
+
assert.deepEqual(projectToolObservation({ ...base, tool: 'gotry_flyai_search', result: 'string' }), []);
|
|
177
|
+
const result = {
|
|
178
|
+
ok: true,
|
|
179
|
+
verdict: 'hit',
|
|
180
|
+
summary: '用户说想去大理,联系人 13800138000',
|
|
181
|
+
evidence: '[实时API:flyai] https://example.com/trace?token=abc',
|
|
182
|
+
options: [
|
|
183
|
+
{ no: 'MU5111', name: '东方航空', price: 880, jumpUrl: 'https://flights.example.com/a?uid=42' },
|
|
184
|
+
{ no: 'CA1234', name: '国航', price: 1260, jumpUrl: 'https://flights.example.com/b' },
|
|
185
|
+
],
|
|
186
|
+
};
|
|
187
|
+
const captures = projectToolObservation({ ...base, tool: 'gotry_flyai_search', result });
|
|
188
|
+
assert.equal(captures.length, 2, 'availability + price_band');
|
|
189
|
+
assert.deepEqual(captures.map(c => c.kind), ['availability', 'price_band']);
|
|
190
|
+
assert.deepEqual(captures.map(c => c.tier), ['resource', 'resource']);
|
|
191
|
+
assert.deepEqual(captures[0].payload, { tool: 'gotry_flyai_search', verdict: 'hit', option_count: 2 });
|
|
192
|
+
assert.deepEqual(captures[1].payload, { tool: 'gotry_flyai_search', low: 880, high: 1260, samples: 2 });
|
|
193
|
+
const serialized = JSON.stringify(captures);
|
|
194
|
+
for (const forbidden of ['13800138000', 'https://', 'example.com', 'token=abc', '东方航空', '用户说想去大理']) {
|
|
195
|
+
assert.equal(serialized.includes(forbidden), false, `投影不得携带:${forbidden}`);
|
|
196
|
+
}
|
|
197
|
+
assert.deepEqual(captures.map(c => c.evidence_ref), [{ session_ref: SESS, turn: 3 }, { session_ref: SESS, turn: 3 }], '证据只走指针');
|
|
198
|
+
// 无价格的结果只产生 availability
|
|
199
|
+
const miss = projectToolObservation({ ...base, tool: 'gotry_session_search', result: { ok: true, verdict: 'miss', rates: [] } });
|
|
200
|
+
assert.equal(miss.length, 1);
|
|
201
|
+
assert.deepEqual(miss[0].payload, { tool: 'gotry_session_search', verdict: 'miss', option_count: 0 });
|
|
202
|
+
assert.deepEqual([...ZONE_OBSERVABLE_TOOLS].sort(), ['gotry_anything_search', 'gotry_flyai_search', 'gotry_hotel_search', 'gotry_session_search']);
|
|
203
|
+
});
|
|
204
|
+
await pass('开闸捕获:白名单工具跑完后 resource 层笔记落账,证据为指针,会话引用为摘要', async () => {
|
|
205
|
+
const root = freshRoot('on-observe');
|
|
206
|
+
const on = harness({ stateRoot: root, sessionZones: 'on' });
|
|
207
|
+
const search = on.tool('gotry_flyai_search');
|
|
208
|
+
const out = await search.execute({ kind: 'flight', from: '上海', to: '大理', date: '2027-11-11' }, EXEC);
|
|
209
|
+
assert.ok(out, '工具返回值不被捕获缝改写');
|
|
210
|
+
const ledger = openLedgerIfExists(root);
|
|
211
|
+
const { state } = readZoneLog(ledger);
|
|
212
|
+
const notes = Object.values(state.hot);
|
|
213
|
+
assert.ok(notes.length >= 1, `应落至少一条 resource 笔记:${JSON.stringify(notes)}`);
|
|
214
|
+
for (const note of notes) {
|
|
215
|
+
assert.equal(note.tier, 'resource');
|
|
216
|
+
assert.equal(note.session_ref, SESS);
|
|
217
|
+
assert.equal(note.evidence_ref.session_ref, SESS);
|
|
218
|
+
assert.ok(Number.isInteger(note.evidence_ref.turn) && note.evidence_ref.turn >= 0);
|
|
219
|
+
assert.equal(JSON.stringify(note).includes(SESSION_ID), false, '分区不得出现宿主 session id 原文');
|
|
220
|
+
}
|
|
221
|
+
// 投影出的形状来自离线夹具(两条候选 + 880/1260 价格带),不依赖任何真实供应商
|
|
222
|
+
const payloads = notes.map(x => JSON.stringify(x.payload)).sort();
|
|
223
|
+
assert.ok(payloads.some(p => p.includes('"option_count":2')), `应有 availability 形状:${payloads.join(' | ')}`);
|
|
224
|
+
assert.ok(payloads.some(p => p.includes('"low":880') && p.includes('"high":1260')), `应有价格带形状:${payloads.join(' | ')}`);
|
|
225
|
+
const serialized = JSON.stringify(notes);
|
|
226
|
+
for (const forbidden of ['https://', 'example.com', '东方航空', '国航']) {
|
|
227
|
+
assert.equal(serialized.includes(forbidden), false, `落账的笔记不得携带:${forbidden}`);
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
await pass('捕获缝续命:同一检索在 TTL 之后再跑一次 → 续 TTL 并回到读视图(不被 stale_rev 吞掉)', async () => {
|
|
231
|
+
const root = freshRoot('observe-touch');
|
|
232
|
+
const ledger = ensureLedger(root);
|
|
233
|
+
const t0 = new Date('2026-10-04T08:00:00.000Z');
|
|
234
|
+
const result = { ok: true, verdict: 'hit', options: [{ no: 'MU1', price: 880 }, { no: 'CA1', price: 1260 }] };
|
|
235
|
+
const first = observeToolResult(ledger, { tool: 'gotry_flyai_search', result, session_ref: SESS, ts: t0.toISOString() });
|
|
236
|
+
assert.deepEqual(first, { captured: 2, touched: 0, rejected: 0 }, '首次观察:两条形状笔记诞生');
|
|
237
|
+
const ids = Object.keys(readZoneLog(ledger).state.hot).sort();
|
|
238
|
+
assert.equal(ids.length, 2);
|
|
239
|
+
// 40 分钟后(resource 30min 已过期)同一检索再跑:必须续命,不得被默默丢掉
|
|
240
|
+
const later = new Date(t0.getTime() + 40 * 60_000).toISOString();
|
|
241
|
+
const second = observeToolResult(ledger, { tool: 'gotry_flyai_search', result, session_ref: SESS, ts: later });
|
|
242
|
+
assert.deepEqual(second, { captured: 0, touched: 2, rejected: 0 }, '同形观察 = 续命,不是 rejected');
|
|
243
|
+
assert.deepEqual(Object.keys(readZoneLog(ledger).state.hot).sort(), ids, '续命不新建主体');
|
|
244
|
+
const state = readZoneLog(ledger).state;
|
|
245
|
+
for (const id of ids) {
|
|
246
|
+
assert.equal(state.hot[id].rev, 2);
|
|
247
|
+
assert.equal(state.hot[id].last_touched_at, later);
|
|
248
|
+
}
|
|
249
|
+
assert.equal(readWorkingZone(state, { now: new Date(t0.getTime() + 41 * 60_000).toISOString(), session_ref: SESS }).length, 2, '续命后两条都回到读视图(未修复时这里是 0:工作区悄悄停供)');
|
|
250
|
+
});
|
|
251
|
+
// ---- 负面清单端到端 ----
|
|
252
|
+
await pass('负面清单端到端:证件号/手机号/URL/凭证形态的载荷永不进任何一区', async () => {
|
|
253
|
+
const root = freshRoot('negative');
|
|
254
|
+
const on = harness({ stateRoot: root, sessionZones: 'on' });
|
|
255
|
+
const note = on.tool('gotry_session_zone_note');
|
|
256
|
+
const payloads = [
|
|
257
|
+
{ city: '大理', id_no: '310101199001011234' },
|
|
258
|
+
{ city: '大理', contact: '13800138000' },
|
|
259
|
+
{ city: '大理', src: 'https://booking.example.com/x' },
|
|
260
|
+
{ city: '大理', cred: 'api_key: sk-abcdefghijklmnop' },
|
|
261
|
+
{ city: '大理', bearer: 'Bearer abcdefghijklmnop' },
|
|
262
|
+
];
|
|
263
|
+
for (const payload of payloads) {
|
|
264
|
+
const r = await note.execute({ action: 'capture', tier: 'intent', kind: 'destination', payload }, EXEC);
|
|
265
|
+
assert.equal(r.ok, false, `应被拒:${JSON.stringify(payload)}`);
|
|
266
|
+
assert.equal(r.code, 'negative_list', `应为负面清单码:${JSON.stringify(r)}`);
|
|
267
|
+
}
|
|
268
|
+
assert.equal(zoneEventCount(root), 0, '全部拒收路径零落账');
|
|
269
|
+
// 合法片段照常落账
|
|
270
|
+
const good = await note.execute({ action: 'capture', tier: 'intent', kind: 'destination', payload: { city: '大理' } }, EXEC);
|
|
271
|
+
assert.equal(good.ok, true);
|
|
272
|
+
assert.equal(zoneEventCount(root), 1);
|
|
273
|
+
});
|
|
274
|
+
// ---- 读回 ----
|
|
275
|
+
await pass('读回:首访空串;有活笔记后有界(条数上界 + 字符上界);关闸即空', async () => {
|
|
276
|
+
const root = freshRoot('brief');
|
|
277
|
+
const on = harness({ stateRoot: root, sessionZones: 'on' });
|
|
278
|
+
assert.equal(on.variables['session_zone_brief']({ scope: AGENT_A }), '', '首访(无账本)读回空串');
|
|
279
|
+
const note = on.tool('gotry_session_zone_note');
|
|
280
|
+
for (const city of ['大理', '丽江', '香格里拉']) {
|
|
281
|
+
await note.execute({ action: 'capture', tier: 'intent', kind: 'destination', payload: { city } }, EXEC);
|
|
282
|
+
}
|
|
283
|
+
const brief = on.variables['session_zone_brief']({ scope: AGENT_A });
|
|
284
|
+
assert.ok(brief.includes('会话双区记忆'), `读回应含分区标题:${brief}`);
|
|
285
|
+
assert.ok(brief.includes('大理'));
|
|
286
|
+
assert.ok(brief.length <= ZONE_BRIEF_MAX_CHARS, '读回字符有界');
|
|
287
|
+
// 同一账本在关闸配置下:变量压根不注册;纯函数层即便被直接调用也返回空串
|
|
288
|
+
const offSame = harness({ stateRoot: root });
|
|
289
|
+
assert.equal('session_zone_brief' in offSame.variables, false, '关闸即便账本里有活笔记也不注册读回变量');
|
|
290
|
+
assert.equal(renderSessionZoneBrief({ ledger: openLedgerIfExists(root), now: new Date().toISOString(), sessionRef: SESS, zoneSwitch: 'off' }), '', '纯函数层的总闸守卫仍在(防御纵深:绕过注册点直调也读不出东西)');
|
|
291
|
+
});
|
|
292
|
+
await pass('读回按 scope 隔离:两个会话同进程时 B 读不到 A 的 resource 层笔记(设计 §1.1)', async () => {
|
|
293
|
+
const root = freshRoot('two-sessions');
|
|
294
|
+
const on = harness({ stateRoot: root, sessionZones: 'on' });
|
|
295
|
+
const note = on.tool('gotry_session_zone_note');
|
|
296
|
+
// A 会话:一条 resource(本会话私有)+ 一条 intent(跨会话可读)
|
|
297
|
+
await note.execute({ action: 'capture', tier: 'resource', kind: 'availability', payload: { tool: 'gotry_flyai_search', verdict: 'hit', option_count: 7 } }, EXEC);
|
|
298
|
+
await note.execute({ action: 'capture', tier: 'intent', kind: 'destination', payload: { city: '大理' } }, EXEC);
|
|
299
|
+
// B 会话:自己的 resource
|
|
300
|
+
await note.execute({ action: 'capture', tier: 'resource', kind: 'availability', payload: { tool: 'gotry_session_search', verdict: 'miss', option_count: 0 } }, EXEC_B);
|
|
301
|
+
assert.notEqual(SESS, SESS_B);
|
|
302
|
+
const briefA = on.variables['session_zone_brief']({ scope: AGENT_A });
|
|
303
|
+
const briefB = on.variables['session_zone_brief']({ scope: AGENT_B });
|
|
304
|
+
assert.ok(briefA.includes('option_count=7'), `A 读到自己的 resource:${briefA}`);
|
|
305
|
+
assert.equal(briefB.includes('option_count=7'), false, 'B 绝不得读到 A 的 resource 层笔记');
|
|
306
|
+
assert.ok(briefB.includes('gotry_session_search'), `B 读到自己的 resource:${briefB}`);
|
|
307
|
+
assert.ok(briefA.includes('大理') && briefB.includes('大理'), 'intent 层按契约跨会话可读');
|
|
308
|
+
// 无 scope(轻量宿主/未绑定)→ 不出 resource 段,fail-closed
|
|
309
|
+
const briefNoScope = on.variables['session_zone_brief']();
|
|
310
|
+
assert.equal(briefNoScope.includes('本次会话查到的'), false, '取不到 scope 时不出 resource 段');
|
|
311
|
+
assert.ok(briefNoScope.includes('大理'), 'intent 段仍在(跨会话可读)');
|
|
312
|
+
});
|
|
313
|
+
await pass('读回纯函数:条数上界生效;无会话绑定时 resource 层不出现(intent 跨会话可读)', () => {
|
|
314
|
+
const now = new Date().toISOString();
|
|
315
|
+
const working = Array.from({ length: 20 }, (_, i) => ({
|
|
316
|
+
schema: 'session_zone_hot_note.v1',
|
|
317
|
+
note_id: `hn|${SESS}|intent|destination|${i}`,
|
|
318
|
+
zone: 'hot_context',
|
|
319
|
+
tier: 'intent',
|
|
320
|
+
kind: 'destination',
|
|
321
|
+
payload: { city: `城市${i}` },
|
|
322
|
+
evidence_ref: { session_ref: SESS, turn: i },
|
|
323
|
+
session_ref: SESS,
|
|
324
|
+
created_at: now,
|
|
325
|
+
last_touched_at: now,
|
|
326
|
+
ttl_expires_at: now,
|
|
327
|
+
rev: 1,
|
|
328
|
+
}));
|
|
329
|
+
const resourceNote = { ...working[0], note_id: 'hn|res', tier: 'resource', kind: 'availability', payload: { tool: 'gotry_flyai_search', verdict: 'hit', option_count: 2 } };
|
|
330
|
+
const bound = renderZoneBrief({ working: [...working, resourceNote], notebook: [], sessionRef: SESS });
|
|
331
|
+
assert.ok(bound.includes('本次会话查到的'), '绑定会话时 resource 层出现');
|
|
332
|
+
assert.ok(bound.length <= ZONE_BRIEF_MAX_CHARS);
|
|
333
|
+
const unbound = renderZoneBrief({ working: [...working, resourceNote], notebook: [], sessionRef: null });
|
|
334
|
+
assert.equal(unbound.includes('本次会话查到的'), false, '无会话绑定时 resource 层不出现');
|
|
335
|
+
assert.equal(renderZoneBrief({ working: [], notebook: [], sessionRef: SESS }), '', '无活笔记 = 空串');
|
|
336
|
+
});
|
|
337
|
+
// ---- 晋升纪律 ----
|
|
338
|
+
await pass('晋升:缺 owner 原话引用拒收;表面闭集外拒收;模型 propose 零落账', async () => {
|
|
339
|
+
const root = freshRoot('promote-gate');
|
|
340
|
+
const on = harness({ stateRoot: root, sessionZones: 'on' });
|
|
341
|
+
const note = on.tool('gotry_session_zone_note');
|
|
342
|
+
const promote = on.tool('gotry_session_zone_promote');
|
|
343
|
+
const captured = await note.execute({ action: 'capture', tier: 'intent', kind: 'budget_stance', payload: { redeye: 'never' } }, EXEC);
|
|
344
|
+
const noteId = captured.note_id;
|
|
345
|
+
const before = zoneEventCount(root);
|
|
346
|
+
const proposed = await note.execute({ action: 'propose', noteId, promoteKind: 'preference' }, EXEC);
|
|
347
|
+
assert.equal(proposed.ok, true);
|
|
348
|
+
assert.equal(proposed.requires_owner_confirm, true, '提议必须回「要 owner 确认」');
|
|
349
|
+
assert.equal(zoneEventCount(root), before, '提议零落账:模型永不自晋升');
|
|
350
|
+
// owner 引用闸(代码层类型化拒绝)
|
|
351
|
+
for (const bad of [
|
|
352
|
+
{ noteId, kind: 'preference', ownerQuote: '', surface: 'user_reply' },
|
|
353
|
+
{ noteId, kind: 'preference', ownerQuote: ' ', surface: 'user_reply' },
|
|
354
|
+
{ noteId, kind: 'preference', ownerQuote: 'x'.repeat(201), surface: 'user_reply' },
|
|
355
|
+
]) {
|
|
356
|
+
const r = await promote.execute(bad, EXEC);
|
|
357
|
+
assert.equal(r.ok, false, `应被拒:${JSON.stringify(bad)}`);
|
|
358
|
+
assert.equal(r.code, 'owner_confirm', `应为 owner_confirm:${JSON.stringify(r)}`);
|
|
359
|
+
}
|
|
360
|
+
// 闭集违规在宿主权 schema 闸即被拒(入口更前置;代码层闭集守卫是第二道)
|
|
361
|
+
for (const bad of [
|
|
362
|
+
{ noteId, kind: 'preference', ownerQuote: QUOTE, surface: 'model_said_so' },
|
|
363
|
+
{ noteId, kind: 'habit', ownerQuote: QUOTE, surface: 'user_reply' },
|
|
364
|
+
]) {
|
|
365
|
+
const r = await promote.execute(bad, EXEC);
|
|
366
|
+
assert.equal(r.ok, false, `应被拒:${JSON.stringify(bad)}`);
|
|
367
|
+
assert.match(String(r.summary ?? ''), /invalid arguments|must be one of/, `宿主权 schema 闸应报闭集违规:${JSON.stringify(r)}`);
|
|
368
|
+
}
|
|
369
|
+
// 直调纯函数层:绕过宿主 schema 后闭集守卫仍在(第二道)
|
|
370
|
+
const direct = promoteWithRouting(openLedgerIfExists(root), { noteId, kind: 'habit', ownerQuote: QUOTE, surface: 'user_reply', ts: new Date().toISOString() });
|
|
371
|
+
assert.equal(direct.ok, false);
|
|
372
|
+
assert.equal(direct.code, 'closed_set');
|
|
373
|
+
const directSurface = promoteWithRouting(openLedgerIfExists(root), { noteId, kind: 'preference', ownerQuote: QUOTE, surface: 'model_said_so', ts: new Date().toISOString() });
|
|
374
|
+
assert.equal(directSurface.code, 'closed_set');
|
|
375
|
+
assert.equal(zoneEventCount(root), before, '全部拒收路径零落账');
|
|
376
|
+
});
|
|
377
|
+
await pass('路由分类(§3):preference→动机 / trip_fact→时间线 / 点名同行人的约束→同行人 / 其余→笔记本', () => {
|
|
378
|
+
assert.equal(classifyPromotionRouting('preference', {}), 'motivation');
|
|
379
|
+
assert.equal(classifyPromotionRouting('trip_fact', {}), 'timeline');
|
|
380
|
+
assert.equal(classifyPromotionRouting('constraint', { companion_label: '爸爸' }), 'companion');
|
|
381
|
+
assert.equal(classifyPromotionRouting('constraint', { companion: '妈妈' }), 'companion');
|
|
382
|
+
assert.equal(classifyPromotionRouting('constraint', { redeye: 'never' }), 'notebook');
|
|
383
|
+
assert.equal(classifyPromotionRouting('lesson', {}), 'notebook');
|
|
384
|
+
});
|
|
385
|
+
await pass('路由 fail-closed:命中既有语义但缺路由载荷 → routing_required,零落账', async () => {
|
|
386
|
+
const root = freshRoot('routing-required');
|
|
387
|
+
const on = harness({ stateRoot: root, sessionZones: 'on' });
|
|
388
|
+
const note = on.tool('gotry_session_zone_note');
|
|
389
|
+
const promote = on.tool('gotry_session_zone_promote');
|
|
390
|
+
const pref = await note.execute({ action: 'capture', tier: 'intent', kind: 'budget_stance', payload: { redeye: 'never' } }, EXEC);
|
|
391
|
+
const trip = await note.execute({ action: 'capture', tier: 'intent', kind: 'destination', payload: { city: '大理', visited: true } }, EXEC);
|
|
392
|
+
const comp = await note.execute({ action: 'capture', tier: 'intent', kind: 'party_size', payload: { companion_label: '爸爸', adults: 2 } }, EXEC);
|
|
393
|
+
const before = zoneEventCount(root);
|
|
394
|
+
for (const bad of [
|
|
395
|
+
{ noteId: pref.note_id, kind: 'preference', ownerQuote: QUOTE, surface: 'user_reply' },
|
|
396
|
+
{ noteId: pref.note_id, kind: 'preference', ownerQuote: QUOTE, surface: 'user_reply', motivation: {} },
|
|
397
|
+
{ noteId: trip.note_id, kind: 'trip_fact', ownerQuote: QUOTE, surface: 'user_reply' },
|
|
398
|
+
{ noteId: comp.note_id, kind: 'constraint', ownerQuote: QUOTE, surface: 'user_reply' },
|
|
399
|
+
]) {
|
|
400
|
+
const r = await promote.execute(bad, EXEC);
|
|
401
|
+
assert.equal(r.ok, false, `应被拒:${JSON.stringify(bad)}`);
|
|
402
|
+
assert.equal(r.code, 'routing_required', `应 routing_required:${JSON.stringify(r)}`);
|
|
403
|
+
}
|
|
404
|
+
assert.equal(zoneEventCount(root), before, '路由缺料零落账:笔记本不私存该语义');
|
|
405
|
+
const ledger = openLedgerIfExists(root);
|
|
406
|
+
assert.equal(Object.keys(readZoneLog(ledger).state.notebook).length, 0);
|
|
407
|
+
});
|
|
408
|
+
await pass('路由逃逸:换个 kind 或抹掉 companion_label 都绕不过既有闸(模型选的 kind 不构成豁免)', async () => {
|
|
409
|
+
const root = freshRoot('routing-escape');
|
|
410
|
+
const on = harness({ stateRoot: root, sessionZones: 'on' });
|
|
411
|
+
const note = on.tool('gotry_session_zone_note');
|
|
412
|
+
const promote = on.tool('gotry_session_zone_promote');
|
|
413
|
+
const ledger = ensureLedger(root);
|
|
414
|
+
// ① 持久偏好声明成 lesson:源笔记 kind=budget_stance 属动机语义 → 拒
|
|
415
|
+
const pref = await note.execute({ action: 'capture', tier: 'intent', kind: 'budget_stance', payload: { redeye: 'never' } }, EXEC);
|
|
416
|
+
const asLesson = await promote.execute({ noteId: pref.note_id, kind: 'lesson', ownerQuote: QUOTE, surface: 'user_reply' }, EXEC);
|
|
417
|
+
assert.equal(asLesson.ok, false, '偏好换 kind=lesson 必须被拒');
|
|
418
|
+
assert.equal(asLesson.code, 'routing_required');
|
|
419
|
+
assert.match(String(asLesson.summary), /budget_stance|motivation/);
|
|
420
|
+
// ② 同行人约束抹掉 companion_label:载荷仍带 health → 拒
|
|
421
|
+
const comp = await note.execute({ action: 'capture', tier: 'intent', kind: 'destination', payload: { city: '大理' } }, EXEC);
|
|
422
|
+
const strippedLabel = await promote.execute({ noteId: comp.note_id, kind: 'constraint', ownerQuote: QUOTE, surface: 'user_reply', payload: { health: ['晕车'] } }, EXEC);
|
|
423
|
+
assert.equal(strippedLabel.ok, false, '抹掉 companion_label 仍不得绕过同行人闸');
|
|
424
|
+
assert.equal(strippedLabel.code, 'routing_required');
|
|
425
|
+
// ③ 备了动机载荷却声明成 constraint:路由载荷与分类不符 → 拒
|
|
426
|
+
const mismatch = await promote.execute({ noteId: comp.note_id, kind: 'constraint', ownerQuote: QUOTE, surface: 'user_reply', payload: { quiet: true }, motivation: { hard: { wake_not_before: '07:00' } } }, EXEC);
|
|
427
|
+
assert.equal(mismatch.ok, false);
|
|
428
|
+
assert.equal(mismatch.code, 'routing_required');
|
|
429
|
+
assert.equal(Object.keys(readZoneLog(ledger).state.notebook).length, 0, '三条逃逸路径零笔记本条目');
|
|
430
|
+
assert.equal(ledger.readMotivation(), null, '零动机写入');
|
|
431
|
+
// 纯函数层同口径(无源权威语义的 lesson 正常通过)
|
|
432
|
+
assert.equal(routingEscapeViolation({ kind: 'lesson', authority: 'notebook', payload: { lesson: 'too_tight' }, sourceKind: 'availability' }), null);
|
|
433
|
+
assert.ok(routingEscapeViolation({ kind: 'lesson', authority: 'notebook', payload: { weights: { x: 1 } }, sourceKind: 'availability' }));
|
|
434
|
+
assert.equal(routingEscapeViolation({ kind: 'preference', authority: 'motivation', payload: { weights: { x: 1 } }, sourceKind: 'budget_stance' }), null, '已走权威路由的不算逃逸');
|
|
435
|
+
});
|
|
436
|
+
await pass('动机闸拒绝即整笔回滚:被拒的偏好晋升不得留下笔记本条目(saved 二义性不可信)', async () => {
|
|
437
|
+
const root = freshRoot('motivation-refused');
|
|
438
|
+
const on = harness({ stateRoot: root, sessionZones: 'on' });
|
|
439
|
+
const note = on.tool('gotry_session_zone_note');
|
|
440
|
+
const promote = on.tool('gotry_session_zone_promote');
|
|
441
|
+
const ledger = ensureLedger(root);
|
|
442
|
+
// 先用同一条原话把 homeCity 写进画像:之后换城市但复用**同一条**原话 →
|
|
443
|
+
// mergeProfile 判为「无新证据」拒收,且 saved:false 不带任何 reason。
|
|
444
|
+
ledger.appendMotivationPatch({ homeCity: '上海', homeCityEvidence: QUOTE, evidence: [QUOTE] });
|
|
445
|
+
assert.equal(ledger.readMotivation()?.homeCityPreference?.value, '上海');
|
|
446
|
+
const captured = await note.execute({ action: 'capture', tier: 'intent', kind: 'budget_stance', payload: { home: 'moved' } }, EXEC);
|
|
447
|
+
const zoneBefore = zoneEventCount(root);
|
|
448
|
+
const r = await promote.execute({ noteId: captured.note_id, kind: 'preference', ownerQuote: QUOTE, surface: 'user_reply', motivation: { homeCity: '北京' } }, EXEC);
|
|
449
|
+
assert.equal(r.ok, false, `动机闸未落地该断言时必须拒绝整笔:${JSON.stringify(r)}`);
|
|
450
|
+
assert.equal(r.code, 'routed_rejected');
|
|
451
|
+
assert.equal(ledger.readMotivation()?.homeCityPreference?.value, '上海', '画像未被改写');
|
|
452
|
+
assert.equal(zoneEventCount(root), zoneBefore, '笔记本零新事件(同事务回滚)');
|
|
453
|
+
assert.equal(Object.keys(readZoneLog(ledger).state.notebook).length, 0);
|
|
454
|
+
// 带新证据的同一断言则正常落地
|
|
455
|
+
const freshQuote = '我搬到北京了,以后默认从北京出发';
|
|
456
|
+
const ok2 = await promote.execute({ noteId: captured.note_id, kind: 'preference', ownerQuote: freshQuote, surface: 'user_reply', motivation: { homeCity: '北京' } }, EXEC);
|
|
457
|
+
assert.equal(ok2.ok, true, JSON.stringify(ok2));
|
|
458
|
+
assert.equal(ok2.routed?.applied, true);
|
|
459
|
+
assert.equal(ledger.readMotivation()?.homeCityPreference?.value, '北京');
|
|
460
|
+
});
|
|
461
|
+
await pass('路由落地:preference 经动机闸 / trip_fact 经时间线闸 / 约束经同行人闸,笔记本同事务记断言+血缘', async () => {
|
|
462
|
+
const root = freshRoot('routing-apply');
|
|
463
|
+
const on = harness({ stateRoot: root, sessionZones: 'on' });
|
|
464
|
+
const note = on.tool('gotry_session_zone_note');
|
|
465
|
+
const promote = on.tool('gotry_session_zone_promote');
|
|
466
|
+
const ledger = ensureLedger(root);
|
|
467
|
+
const pref = await note.execute({ action: 'capture', tier: 'intent', kind: 'budget_stance', payload: { redeye: 'never' } }, EXEC);
|
|
468
|
+
const prefOut = await promote.execute({ noteId: pref.note_id, kind: 'preference', ownerQuote: QUOTE, surface: 'user_reply', motivation: { hard: { wake_not_before: '07:00' } } }, EXEC);
|
|
469
|
+
assert.equal(prefOut.ok, true, JSON.stringify(prefOut));
|
|
470
|
+
assert.equal(prefOut.authority, 'motivation');
|
|
471
|
+
assert.equal(prefOut.routed?.applied, true, '动机闸真的落地(单一写权威)');
|
|
472
|
+
const profile = ledger.readMotivation();
|
|
473
|
+
assert.deepEqual(profile?.hard, { wake_not_before: '07:00' }, '硬约束进动机画像');
|
|
474
|
+
assert.ok(profile?.evidence?.includes(QUOTE), '动机证据 = owner 原话');
|
|
475
|
+
const trip = await note.execute({ action: 'capture', tier: 'intent', kind: 'destination', payload: { city: '大理', visited: true } }, EXEC);
|
|
476
|
+
const tripOut = await promote.execute({ noteId: trip.note_id, kind: 'trip_fact', ownerQuote: QUOTE, surface: 'user_reply', trip: { destination: '大理', start: '2026-10-01', end: '2026-10-05' } }, EXEC);
|
|
477
|
+
assert.equal(tripOut.ok, true, JSON.stringify(tripOut));
|
|
478
|
+
assert.equal(tripOut.authority, 'timeline');
|
|
479
|
+
assert.equal(ledger.readTrips().length, 1, '行程进时间线');
|
|
480
|
+
assert.equal(ledger.readTrips()[0].evidence, QUOTE);
|
|
481
|
+
const comp = await note.execute({ action: 'capture', tier: 'intent', kind: 'party_size', payload: { companion_label: '爸爸', adults: 2 } }, EXEC);
|
|
482
|
+
const compOut = await promote.execute({ noteId: comp.note_id, kind: 'constraint', ownerQuote: QUOTE, surface: 'approval_card', companion: { label: '爸爸', constraints: { health: ['晕车'] } } }, EXEC);
|
|
483
|
+
assert.equal(compOut.ok, true, JSON.stringify(compOut));
|
|
484
|
+
assert.equal(compOut.authority, 'companion');
|
|
485
|
+
assert.deepEqual(ledger.readCompanions().map(c => c.label), ['爸爸'], '约束进同行人档案');
|
|
486
|
+
const notebook = Object.values(readZoneLog(ledger).state.notebook);
|
|
487
|
+
assert.equal(notebook.length, 3, '三条笔记本条目(断言 + 血缘)');
|
|
488
|
+
for (const entry of notebook) {
|
|
489
|
+
assert.equal(entry.owner_confirm.quote, QUOTE);
|
|
490
|
+
assert.equal(entry.origin.session_ref, SESS, '血缘指向源会话');
|
|
491
|
+
assert.ok(entry.origin.note_id, '血缘指向源笔记');
|
|
492
|
+
}
|
|
493
|
+
// 纯教训留在笔记本自身(源笔记 kind 无既有权威语义、载荷无权威形状键)
|
|
494
|
+
const lessonNote = await note.execute({ action: 'capture', tier: 'resource', kind: 'availability', payload: { lesson: 'too_tight' } }, EXEC);
|
|
495
|
+
const lessonOut = await promote.execute({ noteId: lessonNote.note_id, kind: 'lesson', ownerQuote: QUOTE, surface: 'user_reply' }, EXEC);
|
|
496
|
+
assert.equal(lessonOut.ok, true, JSON.stringify(lessonOut));
|
|
497
|
+
assert.equal(lessonOut.authority, 'notebook');
|
|
498
|
+
assert.equal(lessonOut.routed, null, 'notebook 路由无外部权威写');
|
|
499
|
+
});
|
|
500
|
+
await pass('路由拒绝即整笔回滚:时间线闸冲突 → 笔记本零条目、时间线零新行', async () => {
|
|
501
|
+
const root = freshRoot('routing-rollback');
|
|
502
|
+
const on = harness({ stateRoot: root, sessionZones: 'on' });
|
|
503
|
+
const note = on.tool('gotry_session_zone_note');
|
|
504
|
+
const promote = on.tool('gotry_session_zone_promote');
|
|
505
|
+
const ledger = ensureLedger(root);
|
|
506
|
+
ledger.appendTripEvent({ destination: '大理', start: '2026-10-01', end: '2026-10-05', source: 'user-verbatim', evidence: '去年去过大理' });
|
|
507
|
+
const trips = ledger.readTrips().length;
|
|
508
|
+
const captured = await note.execute({ action: 'capture', tier: 'intent', kind: 'destination', payload: { city: '大理' } }, EXEC);
|
|
509
|
+
const zoneBefore = zoneEventCount(root);
|
|
510
|
+
const r = await promote.execute({ noteId: captured.note_id, kind: 'trip_fact', ownerQuote: QUOTE, surface: 'user_reply', trip: { destination: '大理', start: '2026-10-03', end: '2026-10-08' } }, EXEC);
|
|
511
|
+
assert.equal(r.ok, false, `重叠行程应被时间线闸拒绝:${JSON.stringify(r)}`);
|
|
512
|
+
assert.equal(r.code, 'routed_rejected');
|
|
513
|
+
assert.equal(ledger.readTrips().length, trips, '时间线零新行');
|
|
514
|
+
assert.equal(zoneEventCount(root), zoneBefore, '笔记本零新事件(同事务回滚)');
|
|
515
|
+
assert.equal(Object.keys(readZoneLog(ledger).state.notebook).length, 0);
|
|
516
|
+
});
|
|
517
|
+
await pass('更正即弃:drop 后出读视图;过期源不得晋升(同一过期纯函数)', async () => {
|
|
518
|
+
const root = freshRoot('drop');
|
|
519
|
+
const on = harness({ stateRoot: root, sessionZones: 'on' });
|
|
520
|
+
const note = on.tool('gotry_session_zone_note');
|
|
521
|
+
const captured = await note.execute({ action: 'capture', tier: 'intent', kind: 'destination', payload: { city: '大理' } }, EXEC);
|
|
522
|
+
const dropped = await note.execute({ action: 'drop', noteId: captured.note_id }, EXEC);
|
|
523
|
+
assert.equal(dropped.ok, true);
|
|
524
|
+
assert.equal(dropped.appended, true);
|
|
525
|
+
const ledger = openLedgerIfExists(root);
|
|
526
|
+
assert.equal(Object.keys(readZoneLog(ledger).state.hot).length, 0, 'drop 后出状态');
|
|
527
|
+
// 过期源:注入未来时钟判定(晋升纯函数层的 source_expired)
|
|
528
|
+
const relive = await note.execute({ action: 'capture', tier: 'resource', kind: 'availability', payload: { tool: 'gotry_flyai_search', verdict: 'hit', option_count: 1 } }, EXEC);
|
|
529
|
+
const future = new Date(Date.now() + 61 * 60_000).toISOString();
|
|
530
|
+
const expired = promoteWithRouting(ledger, { noteId: relive.note_id, kind: 'lesson', ownerQuote: QUOTE, surface: 'user_reply', ts: future });
|
|
531
|
+
assert.equal(expired.ok, false);
|
|
532
|
+
assert.equal(expired.code, 'source_expired', `过期源必须拒收:${JSON.stringify(expired)}`);
|
|
533
|
+
});
|
|
534
|
+
await pass('CAS 修订经工具面:stale_rev 拒收;正确父 rev 推进到 rev 2', async () => {
|
|
535
|
+
const root = freshRoot('cas');
|
|
536
|
+
const on = harness({ stateRoot: root, sessionZones: 'on' });
|
|
537
|
+
const note = on.tool('gotry_session_zone_note');
|
|
538
|
+
const captured = await note.execute({ action: 'capture', tier: 'intent', kind: 'destination', payload: { city: '大理' } }, EXEC);
|
|
539
|
+
const stale = await note.execute({ action: 'revise', noteId: captured.note_id, expectedRev: 5, payload: { city: '丽江' } }, EXEC);
|
|
540
|
+
assert.equal(stale.ok, false);
|
|
541
|
+
assert.equal(stale.code, 'stale_rev');
|
|
542
|
+
const good = await note.execute({ action: 'revise', noteId: captured.note_id, expectedRev: 1, payload: { city: '丽江' } }, EXEC);
|
|
543
|
+
assert.equal(good.ok, true);
|
|
544
|
+
assert.equal(good.appended, true);
|
|
545
|
+
const ledger = openLedgerIfExists(root);
|
|
546
|
+
assert.equal(readZoneLog(ledger).state.hot[captured.note_id].rev, 2);
|
|
547
|
+
});
|
|
548
|
+
await pass('无会话身份:分区工具 fail-closed 拒绝(不记忆无主体片段),零落账', async () => {
|
|
549
|
+
const root = freshRoot('no-session');
|
|
550
|
+
const on = harness({ stateRoot: root, sessionZones: 'on' });
|
|
551
|
+
const note = on.tool('gotry_session_zone_note');
|
|
552
|
+
const r = await note.execute({ action: 'capture', tier: 'intent', kind: 'destination', payload: { city: '大理' } }, { agent: {} });
|
|
553
|
+
assert.equal(r.ok, false);
|
|
554
|
+
assert.equal(r.code, 'bad_session');
|
|
555
|
+
assert.equal(zoneEventCount(root), 0);
|
|
556
|
+
});
|
|
557
|
+
assert.equal(runtimeSnapshot(), runtimeBefore, '本套件必须对 ts/dsh-runtime/gotry-state 零写入(产品真实状态)');
|
|
558
|
+
console.log(`\nSESSION ZONE WIRING TESTS: ${n}/21 OK(P4-3 会话接线:默认关惰性/捕获缝形状投影/负面清单端到端/读回有界/propose 零落账/owner 引用闸/§3 路由 fail-closed 与同事务回滚;隔离 stateRoot,全离线)`);
|
|
559
|
+
}
|
|
560
|
+
main()
|
|
561
|
+
.catch(e => { console.error(e); process.exitCode = 1; })
|
|
562
|
+
.finally(() => {
|
|
563
|
+
resetZoneSessionBindingForTests();
|
|
564
|
+
for (const root of roots)
|
|
565
|
+
rmSync(root, { recursive: true, force: true });
|
|
566
|
+
});
|