@mailwoman/resolver 10.0.0 → 10.2.0

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 (134) hide show
  1. package/README.md +9 -7
  2. package/lib/admin/coherence-passes.ts +31 -172
  3. package/lib/admin/containment.ts +15 -33
  4. package/lib/admin/jp-municipality.ts +21 -14
  5. package/lib/admin/winner.ts +37 -69
  6. package/lib/backend-capabilities.ts +28 -27
  7. package/lib/bare-toponym-race.ts +69 -37
  8. package/lib/decorate-node.ts +25 -49
  9. package/lib/fold-name.ts +5 -18
  10. package/lib/index.ts +5 -9
  11. package/lib/plausibility.ts +41 -68
  12. package/lib/postcode/country-coherence.ts +92 -296
  13. package/lib/postcode/prefix.ts +24 -86
  14. package/lib/postcode/shape-coherence.ts +26 -116
  15. package/lib/remote-resolver.ts +38 -33
  16. package/lib/rerank.ts +41 -54
  17. package/lib/resolve/passes.ts +188 -177
  18. package/lib/resolve.ts +744 -0
  19. package/lib/span-rescore.ts +219 -175
  20. package/lib/street/evidence.ts +65 -73
  21. package/lib/street/tier.ts +51 -194
  22. package/lib/toponym-prior.ts +54 -180
  23. package/out/admin/coherence-passes.d.ts +18 -69
  24. package/out/admin/coherence-passes.d.ts.map +1 -1
  25. package/out/admin/coherence-passes.js +24 -166
  26. package/out/admin/coherence-passes.js.map +1 -1
  27. package/out/admin/containment.d.ts +13 -31
  28. package/out/admin/containment.d.ts.map +1 -1
  29. package/out/admin/containment.js +13 -31
  30. package/out/admin/containment.js.map +1 -1
  31. package/out/admin/jp-municipality.d.ts +21 -14
  32. package/out/admin/jp-municipality.d.ts.map +1 -1
  33. package/out/admin/jp-municipality.js +18 -12
  34. package/out/admin/jp-municipality.js.map +1 -1
  35. package/out/admin/winner.d.ts +32 -64
  36. package/out/admin/winner.d.ts.map +1 -1
  37. package/out/admin/winner.js +23 -56
  38. package/out/admin/winner.js.map +1 -1
  39. package/out/{admin/index.d.ts → admin.d.ts} +1 -1
  40. package/out/admin.d.ts.map +1 -0
  41. package/out/{admin/index.js → admin.js} +1 -1
  42. package/out/admin.js.map +1 -0
  43. package/out/backend-capabilities.d.ts +19 -20
  44. package/out/backend-capabilities.d.ts.map +1 -1
  45. package/out/backend-capabilities.js +28 -26
  46. package/out/backend-capabilities.js.map +1 -1
  47. package/out/bare-toponym-race.d.ts +54 -27
  48. package/out/bare-toponym-race.d.ts.map +1 -1
  49. package/out/bare-toponym-race.js +69 -37
  50. package/out/bare-toponym-race.js.map +1 -1
  51. package/out/decorate-node.d.ts +6 -8
  52. package/out/decorate-node.d.ts.map +1 -1
  53. package/out/decorate-node.js +25 -49
  54. package/out/decorate-node.js.map +1 -1
  55. package/out/fold-name.d.ts +5 -18
  56. package/out/fold-name.d.ts.map +1 -1
  57. package/out/fold-name.js +5 -18
  58. package/out/fold-name.js.map +1 -1
  59. package/out/index.d.ts +5 -6
  60. package/out/index.d.ts.map +1 -1
  61. package/out/index.js +5 -8
  62. package/out/index.js.map +1 -1
  63. package/out/plausibility.d.ts +30 -60
  64. package/out/plausibility.d.ts.map +1 -1
  65. package/out/plausibility.js +19 -52
  66. package/out/plausibility.js.map +1 -1
  67. package/out/postcode/country-coherence.d.ts +53 -167
  68. package/out/postcode/country-coherence.d.ts.map +1 -1
  69. package/out/postcode/country-coherence.js +42 -259
  70. package/out/postcode/country-coherence.js.map +1 -1
  71. package/out/postcode/prefix.d.ts +18 -69
  72. package/out/postcode/prefix.d.ts.map +1 -1
  73. package/out/postcode/prefix.js +11 -78
  74. package/out/postcode/prefix.js.map +1 -1
  75. package/out/postcode/shape-coherence.d.ts +18 -85
  76. package/out/postcode/shape-coherence.d.ts.map +1 -1
  77. package/out/postcode/shape-coherence.js +11 -107
  78. package/out/postcode/shape-coherence.js.map +1 -1
  79. package/out/{postcode/index.d.ts → postcode.d.ts} +1 -1
  80. package/out/postcode.d.ts.map +1 -0
  81. package/out/{postcode/index.js → postcode.js} +1 -1
  82. package/out/postcode.js.map +1 -0
  83. package/out/remote-resolver.d.ts +32 -31
  84. package/out/remote-resolver.d.ts.map +1 -1
  85. package/out/remote-resolver.js +12 -20
  86. package/out/remote-resolver.js.map +1 -1
  87. package/out/rerank.d.ts +32 -46
  88. package/out/rerank.d.ts.map +1 -1
  89. package/out/rerank.js +16 -41
  90. package/out/rerank.js.map +1 -1
  91. package/out/resolve/passes.d.ts +108 -95
  92. package/out/resolve/passes.d.ts.map +1 -1
  93. package/out/resolve/passes.js +67 -126
  94. package/out/resolve/passes.js.map +1 -1
  95. package/out/resolve.d.ts +15 -0
  96. package/out/resolve.d.ts.map +1 -0
  97. package/out/resolve.js +557 -0
  98. package/out/resolve.js.map +1 -0
  99. package/out/span-rescore.d.ts +56 -65
  100. package/out/span-rescore.d.ts.map +1 -1
  101. package/out/span-rescore.js +134 -132
  102. package/out/span-rescore.js.map +1 -1
  103. package/out/street/evidence.d.ts +56 -61
  104. package/out/street/evidence.d.ts.map +1 -1
  105. package/out/street/evidence.js +22 -46
  106. package/out/street/evidence.js.map +1 -1
  107. package/out/street/tier.d.ts +18 -30
  108. package/out/street/tier.d.ts.map +1 -1
  109. package/out/street/tier.js +43 -191
  110. package/out/street/tier.js.map +1 -1
  111. package/out/{street/index.d.ts → street.d.ts} +1 -1
  112. package/out/street.d.ts.map +1 -0
  113. package/out/{street/index.js → street.js} +1 -1
  114. package/out/street.js.map +1 -0
  115. package/out/toponym-prior.d.ts +22 -110
  116. package/out/toponym-prior.d.ts.map +1 -1
  117. package/out/toponym-prior.js +41 -170
  118. package/out/toponym-prior.js.map +1 -1
  119. package/package.json +44 -147
  120. package/lib/resolve/index.ts +0 -989
  121. package/out/admin/index.d.ts.map +0 -1
  122. package/out/admin/index.js.map +0 -1
  123. package/out/postcode/index.d.ts.map +0 -1
  124. package/out/postcode/index.js.map +0 -1
  125. package/out/resolve/index.d.ts +0 -20
  126. package/out/resolve/index.d.ts.map +0 -1
  127. package/out/resolve/index.js +0 -808
  128. package/out/resolve/index.js.map +0 -1
  129. package/out/street/index.d.ts.map +0 -1
  130. package/out/street/index.js.map +0 -1
  131. package/vitest.config.ts +0 -38
  132. /package/lib/{admin/index.ts → admin.ts} +0 -0
  133. /package/lib/{postcode/index.ts → postcode.ts} +0 -0
  134. /package/lib/{street/index.ts → street.ts} +0 -0
@@ -2,68 +2,37 @@
2
2
  * @copyright Sister Software
3
3
  * @license AGPL-3.0
4
4
  * @author Teffen Ellis, et al.
5
- *
6
- * Resolution-plausibility guard (#727 / v7 excision arc).
7
- *
8
- * The 2026-07-15 coordinate-parity study
9
- * (`docs/articles/evals/2026-07-15-v7-parity-floor-diagnosis.md`) found the neural parser is
10
- * coordinate-safe on well-formed input (98.6% within 1 km of the rules parser through the same
11
- * resolver) but produces a garbage-geocode tail on the bare-fragment / bare-state-name / US-highway
12
- * classes — inputs like `California` or `6000, NSW, Australia` that resolve to nothing finer than a
13
- * country centroid.
14
- *
15
- * This guard is the cheap post-resolve check for that tail: a resolved tree whose finest resolved
16
- * place is only a `country` centroid is implausible for a structured address. It reads only the
17
- * decorated tree — no gazetteer, no extra query — so it is free to run on every resolve. It is
18
- * deliberately DIRECTION-AGNOSTIC about what the caller does with the signal: serve the result with
19
- * a low-confidence marker, prefer a sibling parse hypothesis (the #727 k-best rerank), or decline to
20
- * emit a coordinate. It is NOT a rules-fallback trigger — the v7 excision deletes the rules parser
21
- * outright (operator ruling 2026-07-15), so no consumer may route through legacy rules on a trip.
22
- *
23
- * It deliberately does NOT flag region-tier resolutions: a US state or a province centroid
24
- * (`Texas` → the TX centroid) is a legitimate coarse geocode, not garbage. Only "resolved no finer
25
- * than a country" trips it.
26
5
  */
27
6
  import type { ComponentTag } from "@mailwoman/codex/component";
28
7
  import type { AddressTree } from "@mailwoman/core/decoder";
29
8
  import type { CountryBBoxFact } from "@mailwoman/core/resolver";
30
9
  /**
31
- * A resolved place lifted off the tree — the coordinate a caller would serve, plus its granularity tag.
10
+ * Holds the coordinate a caller would serve for a resolved tree, with the tag of the node that supplied it.
32
11
  */
33
12
  export interface ResolvedCoordinate {
34
13
  tag: ComponentTag;
35
14
  lat: number;
36
15
  lon: number;
37
16
  /**
38
- * Canonical place URI (`wof:…`) when the resolver supplied one.
17
+ * The canonical place URI, such as `wof:…`, when the resolver supplied one.
39
18
  */
40
- placeID?: string;
19
+ placeID: string | null;
41
20
  }
42
21
  /**
43
- * Walk a resolved {@link AddressTree} and return the FINEST resolved place — the node carrying a resolver-supplied
44
- * coordinate at the deepest granularity tier. Returns `null` when nothing resolved (no node carries a `lat`/`lon`).
45
- * Ties break toward the first node in document order.
22
+ * Returns the resolved coordinate at the finest granularity tier in the tree,
23
+ * preferring the earliest node on a tie.
24
+ * It returns `null` when no node has a `lat`/`lon`.
46
25
  */
47
26
  export declare function finestResolvedCoordinate(tree: AddressTree): ResolvedCoordinate | null;
48
27
  /**
49
- * Coarse per-country bounding boxes `[latMin, latMax, lonMin, lonMax]` for the cross-country guard (guard B). These are
50
- * DELIBERATELY rough — a guard needs "obviously the wrong country", not cartography — and they mirror the boxes the
51
- * 2026-07-15 coordinate-parity receipt harness measured with (`scratchpad/coord-parity.mjs`). The US box spans Alaska →
52
- * the mainland east coast; continental FR only; etc. A country absent here simply never trips the guard (fail-open).
53
- *
54
- * FALLBACK ROLE (survey candidate #2): these boxes are also baked into the candidate gazetteer's `country_bbox`
55
- * manifest table at build time (`mailwoman/gazetteer-pipeline/coverage-manifest.ts` owns the measured record). When a
56
- * caller supplies artifact-declared boxes ({@link PlausibilityOpts.countryBBoxes}), those REPLACE this table wholesale
57
- * — the artifact speaks for itself, and a country absent from the artifact's table fails open exactly like an absent
58
- * key here. This constant is the fallback for artifacts predating the manifest; grow the manifest record, not this.
28
+ * Lists coarse per-country bounding boxes, as `[latMin, latMax, lonMin, lonMax]`,
29
+ * for artifacts whose manifest declares none.
30
+ * A country without a box never trips the guard.
59
31
  */
60
32
  export declare const COUNTRY_BBOX: Readonly<Record<string, readonly [number, number, number, number]>>;
61
33
  /**
62
- * True when the coordinate lies outside `countryCode`'s coarse bbox. Unknown country codes are fail-open (false).
63
- *
64
- * When `bboxes` (artifact-declared boxes, {@link GazetteerArtifactCoverage.countryBBoxes}) is supplied it REPLACES the
65
- * built-in {@link COUNTRY_BBOX} table wholesale — absence from the artifact's table fails open, same semantic as an
66
- * absent constant key. Omitted → the constant, byte-identical to the pre-manifest behavior.
34
+ * Reports whether a coordinate lies outside the country's bounding box, using `bboxes` in
35
+ * place of {@link COUNTRY_BBOX} when supplied and returning `false` for a country with no box.
67
36
  */
68
37
  export declare function outsideExpectedCountry(countryCode: string, lat: number, lon: number, bboxes?: ReadonlyMap<string, CountryBBoxFact>): boolean;
69
38
  /**
@@ -72,37 +41,38 @@ export declare function outsideExpectedCountry(countryCode: string, lat: number,
72
41
  export interface PlausibilityVerdict {
73
42
  implausible: boolean;
74
43
  /**
75
- * Set when `implausible` is true. `country-centroid` = resolved no finer than a country (guard A);
76
- * `outside-expected-country` = the served coordinate lies outside the expected country's bbox (guard B).
44
+ * Why the resolution is implausible, set only when `implausible` is true:
45
+ * `country-centroid` or `outside-expected-country`.
77
46
  */
78
- reason?: "country-centroid" | "outside-expected-country";
47
+ reason: "country-centroid" | "outside-expected-country" | null;
79
48
  /**
80
- * The coordinate the verdict was drawn from, when anything resolved.
49
+ * The coordinate the verdict was based on, present when anything resolved.
81
50
  */
82
- coordinate?: ResolvedCoordinate;
51
+ coordinate: ResolvedCoordinate | null;
83
52
  }
53
+ /**
54
+ * Configures {@linkcode isImplausibleResolution} with the country the address should
55
+ * fall in and optional artifact-declared bounding boxes.
56
+ */
84
57
  export interface PlausibilityOpts {
85
58
  /**
86
- * ISO-2 country the resolution is EXPECTED to land in, when the caller knows it (a locale hint, a parsed country, a
87
- * fixture's gold country). Enables guard B: a coordinate outside this country's coarse bbox is implausible — the
88
- * cross-country-jump class guard A structurally cannot catch (`1210a IA 10 W IA` → a coordinate ~10,000 km from the
89
- * US was country-centroid-free and sailed through until guard B landed here, 2026-07-17; previously the check lived
90
- * only in the receipt harness, so the shipped residual read 5/321 while the receipt said 3/321).
59
+ * The ISO 3166-1 alpha-2 country the resolution should land in.
60
+ *
61
+ * A set `expectedCountry` enables the bounding-box check that catches cross-country
62
+ * jumps the country-centroid check cannot.
91
63
  */
92
64
  expectedCountry?: string;
93
65
  /**
94
- * Artifact-declared guard-B boxes (the loaded gazetteer's `country_bbox` manifest, via
95
- * `resolver.artifactCoverage?.countryBBoxes`). When supplied they replace the built-in {@link COUNTRY_BBOX} table
96
- * wholesale; omitted → the constant (byte-identical fallback for artifacts predating the manifest).
66
+ * Artifact-declared country bounding boxes that replace the built-in
67
+ * {@link COUNTRY_BBOX} table entirely when supplied.
97
68
  */
98
69
  countryBBoxes?: ReadonlyMap<string, CountryBBoxFact>;
99
70
  }
100
71
  /**
101
- * Decide whether a resolved tree's geocode is implausible for a structured address — the cheap guard the v7 hybrid
102
- * check runs after routing an input to the neural parser (#38). Trips when the finest resolved place is a bare
103
- * `country` centroid (guard A), or — when the caller supplies `expectedCountry` — when the served coordinate falls
104
- * outside that country's coarse bbox (guard B). An unresolved tree (nothing to serve) is plausible: there is no garbage
105
- * to serve.
72
+ * Decides whether a resolved tree's coordinate is implausible: a bare country centroid,
73
+ * or a point outside `expectedCountry`'s bounding box.
74
+ *
75
+ * An unresolved tree is plausible because it serves no coordinate.
106
76
  */
107
77
  export declare function isImplausibleResolution(tree: AddressTree, opts?: PlausibilityOpts): PlausibilityVerdict;
108
78
  //# sourceMappingURL=plausibility.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"plausibility.d.ts","sourceRoot":"","sources":["../lib/plausibility.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAA;AAC9D,OAAO,KAAK,EAAe,WAAW,EAAE,MAAM,yBAAyB,CAAA;AACvE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAA;AAqB/D;;GAEG;AAC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AgB3G"}
@@ -2,32 +2,6 @@
2
2
  * @copyright Sister Software
3
3
  * @license AGPL-3.0
4
4
  * @author Teffen Ellis, et al.
5
- *
6
- * Resolution-plausibility guard (#727 / v7 excision arc).
7
- *
8
- * The 2026-07-15 coordinate-parity study
9
- * (`docs/articles/evals/2026-07-15-v7-parity-floor-diagnosis.md`) found the neural parser is
10
- * coordinate-safe on well-formed input (98.6% within 1 km of the rules parser through the same
11
- * resolver) but produces a garbage-geocode tail on the bare-fragment / bare-state-name / US-highway
12
- * classes — inputs like `California` or `6000, NSW, Australia` that resolve to nothing finer than a
13
- * country centroid.
14
- *
15
- * This guard is the cheap post-resolve check for that tail: a resolved tree whose finest resolved
16
- * place is only a `country` centroid is implausible for a structured address. It reads only the
17
- * decorated tree — no gazetteer, no extra query — so it is free to run on every resolve. It is
18
- * deliberately DIRECTION-AGNOSTIC about what the caller does with the signal: serve the result with
19
- * a low-confidence marker, prefer a sibling parse hypothesis (the #727 k-best rerank), or decline to
20
- * emit a coordinate. It is NOT a rules-fallback trigger — the v7 excision deletes the rules parser
21
- * outright (operator ruling 2026-07-15), so no consumer may route through legacy rules on a trip.
22
- *
23
- * It deliberately does NOT flag region-tier resolutions: a US state or a province centroid
24
- * (`Texas` → the TX centroid) is a legitimate coarse geocode, not garbage. Only "resolved no finer
25
- * than a country" trips it.
26
- */
27
- /**
28
- * Resolution granularity, coarse → fine. A resolved node's {@link AddressNode.tag} places it on this ladder; the
29
- * geocode a caller serves comes from the FINEST resolved node. Tags absent here (unit, po_box, intersection halves, …)
30
- * are treated as street-tier specificity when resolved.
31
5
  */
32
6
  const RESOLUTION_TIER = {
33
7
  country: 0,
@@ -43,19 +17,19 @@ const RESOLUTION_TIER = {
43
17
  house_number: 5,
44
18
  };
45
19
  /**
46
- * Walk a resolved {@link AddressTree} and return the FINEST resolved place — the node carrying a resolver-supplied
47
- * coordinate at the deepest granularity tier. Returns `null` when nothing resolved (no node carries a `lat`/`lon`).
48
- * Ties break toward the first node in document order.
20
+ * Returns the resolved coordinate at the finest granularity tier in the tree,
21
+ * preferring the earliest node on a tie.
22
+ * It returns `null` when no node has a `lat`/`lon`.
49
23
  */
50
24
  export function finestResolvedCoordinate(tree) {
51
25
  let best = null;
52
26
  let bestTier = -1;
53
27
  const visit = (node) => {
54
- if (node.lat !== undefined && node.lon !== undefined) {
28
+ if (node.lat != null && node.lon != null) {
55
29
  const tier = RESOLUTION_TIER[node.tag] ?? 4;
56
30
  if (tier > bestTier) {
57
31
  bestTier = tier;
58
- best = { tag: node.tag, lat: node.lat, lon: node.lon, placeID: node.placeID };
32
+ best = { tag: node.tag, lat: node.lat, lon: node.lon, placeID: node.placeID ?? null };
59
33
  }
60
34
  }
61
35
  for (const child of node.children) {
@@ -68,21 +42,15 @@ export function finestResolvedCoordinate(tree) {
68
42
  return best;
69
43
  }
70
44
  /**
71
- * Coarse per-country bounding boxes `[latMin, latMax, lonMin, lonMax]` for the cross-country guard (guard B). These are
72
- * DELIBERATELY rough — a guard needs "obviously the wrong country", not cartography — and they mirror the boxes the
73
- * 2026-07-15 coordinate-parity receipt harness measured with (`scratchpad/coord-parity.mjs`). The US box spans Alaska →
74
- * the mainland east coast; continental FR only; etc. A country absent here simply never trips the guard (fail-open).
75
- *
76
- * FALLBACK ROLE (survey candidate #2): these boxes are also baked into the candidate gazetteer's `country_bbox`
77
- * manifest table at build time (`mailwoman/gazetteer-pipeline/coverage-manifest.ts` owns the measured record). When a
78
- * caller supplies artifact-declared boxes ({@link PlausibilityOpts.countryBBoxes}), those REPLACE this table wholesale
79
- * — the artifact speaks for itself, and a country absent from the artifact's table fails open exactly like an absent
80
- * key here. This constant is the fallback for artifacts predating the manifest; grow the manifest record, not this.
45
+ * Lists coarse per-country bounding boxes, as `[latMin, latMax, lonMin, lonMax]`,
46
+ * for artifacts whose manifest declares none.
47
+ * A country without a box never trips the guard.
81
48
  */
82
49
  export const COUNTRY_BBOX = {
83
50
  US: [18, 72, -180, -66],
84
51
  AU: [-44, -10, 112, 154],
85
52
  BR: [-34, 6, -74, -34],
53
+ CN: [15.7, 53.6, 73.4, 135.1],
86
54
  CZ: [48, 51.5, 12, 19],
87
55
  DE: [47, 55.5, 5.5, 15.5],
88
56
  ES: [35, 44, -10, 5],
@@ -90,8 +58,11 @@ export const COUNTRY_BBOX = {
90
58
  GB: [49, 61, -8.7, 2],
91
59
  HR: [42, 46.6, 13, 19.5],
92
60
  IN: [6, 36, 68, 98],
61
+ IT: [35.4, 47.1, 6.6, 18.6],
62
+ JP: [20.2, 45.7, 122.8, 154.1],
93
63
  NL: [50.7, 53.7, 3.3, 7.3],
94
64
  NO: [57, 71.5, 4, 31],
65
+ NZ: [-52.7, -29.1, -180, 180],
95
66
  PL: [49, 55, 14, 24.2],
96
67
  PT: [36.5, 42.2, -9.6, -6.1],
97
68
  RO: [43.5, 48.3, 20, 30],
@@ -100,11 +71,8 @@ export const COUNTRY_BBOX = {
100
71
  SI: [45.4, 46.9, 13.3, 16.6],
101
72
  };
102
73
  /**
103
- * True when the coordinate lies outside `countryCode`'s coarse bbox. Unknown country codes are fail-open (false).
104
- *
105
- * When `bboxes` (artifact-declared boxes, {@link GazetteerArtifactCoverage.countryBBoxes}) is supplied it REPLACES the
106
- * built-in {@link COUNTRY_BBOX} table wholesale — absence from the artifact's table fails open, same semantic as an
107
- * absent constant key. Omitted → the constant, byte-identical to the pre-manifest behavior.
74
+ * Reports whether a coordinate lies outside the country's bounding box, using `bboxes` in
75
+ * place of {@link COUNTRY_BBOX} when supplied and returning `false` for a country with no box.
108
76
  */
109
77
  export function outsideExpectedCountry(countryCode, lat, lon, bboxes) {
110
78
  const cc = countryCode.toUpperCase();
@@ -120,11 +88,10 @@ export function outsideExpectedCountry(countryCode, lat, lon, bboxes) {
120
88
  return lat < b[0] || lat > b[1] || lon < b[2] || lon > b[3];
121
89
  }
122
90
  /**
123
- * Decide whether a resolved tree's geocode is implausible for a structured address — the cheap guard the v7 hybrid
124
- * check runs after routing an input to the neural parser (#38). Trips when the finest resolved place is a bare
125
- * `country` centroid (guard A), or — when the caller supplies `expectedCountry` — when the served coordinate falls
126
- * outside that country's coarse bbox (guard B). An unresolved tree (nothing to serve) is plausible: there is no garbage
127
- * to serve.
91
+ * Decides whether a resolved tree's coordinate is implausible: a bare country centroid,
92
+ * or a point outside `expectedCountry`'s bounding box.
93
+ *
94
+ * An unresolved tree is plausible because it serves no coordinate.
128
95
  */
129
96
  export function isImplausibleResolution(tree, opts = {}) {
130
97
  const coordinate = finestResolvedCoordinate(tree);
@@ -136,6 +103,6 @@ export function isImplausibleResolution(tree, opts = {}) {
136
103
  outsideExpectedCountry(opts.expectedCountry, coordinate.lat, coordinate.lon, opts.countryBBoxes)) {
137
104
  return { implausible: true, reason: "outside-expected-country", coordinate };
138
105
  }
139
- return { implausible: false, coordinate: coordinate ?? undefined };
106
+ return { implausible: false, reason: null, coordinate: coordinate ?? null };
140
107
  }
141
108
  //# sourceMappingURL=plausibility.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"plausibility.js","sourceRoot":"","sources":["../lib/plausibility.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAMH;;;;GAIG;AACH,MAAM,eAAe,GAA0C;IAC9D,OAAO,EAAE,CAAC;IACV,MAAM,EAAE,CAAC;IACT,SAAS,EAAE,CAAC;IACZ,kBAAkB,EAAE,CAAC;IACrB,QAAQ,EAAE,CAAC;IACX,QAAQ,EAAE,CAAC;IACX,KAAK,EAAE,CAAC;IACR,MAAM,EAAE,CAAC;IACT,aAAa,EAAE,CAAC;IAChB,aAAa,EAAE,CAAC;IAChB,YAAY,EAAE,CAAC;CACf,CAAA;AAeD;;;;GAIG;AACH,MAAM,UAAU,wBAAwB,CAAC,IAAiB;IACzD,IAAI,IAAI,GAA8B,IAAI,CAAA;IAC1C,IAAI,QAAQ,GAAG,CAAC,CAAC,CAAA;IAEjB,MAAM,KAAK,GAAG,CAAC,IAAiB,EAAQ,EAAE;QACzC,IAAI,IAA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KG;AACH,MAAM,UAAU,uBAAuB,CAAC,IAAiB,EAAE,IAAI,GAAqB,EAAE;IACrF,MAAM,UAAU,GAAG,wBAAwB,CAAC,IAAI,CAAC,CAAA;IAEjD,IAAI,UAAU,IAAI,UAAU,CAAC,GAAG,KAAK,SAAS,EAAE,CAAC;QAChD,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,EAAE,kBAAkB,EAAE,UAAU,EAAE,CAAA;IACrE,CAAC;IAED,IACC,UAAU;QACV,IAAI,CAAC,eAAe;QACpB,sBAAsB,CAAC,IAAI,CAAC,eAAe,EAAE,UAAU,CAAC,GAAG,EAAE,UAAU,CAAC,GAAG,EAAE,IAAI,CAAC,aAAa,CAAC,EAC/F,CAAC;QACF,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,EAAE,0BAA0B,EAAE,UAAU,EAAE,CAAA;IAC7E,CAAC;IAED,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,UAAU,IAAI,IAAI,EAAE,CAAA;AAC5E,CAAC"}
@@ -2,124 +2,24 @@
2
2
  * @copyright Sister Software
3
3
  * @license AGPL-3.0
4
4
  * @author Teffen Ellis, et al.
5
- *
6
- * Postcode-country coherence (#42) — the joint-consistency resolve keyed on the (postcode, locality)
7
- * PAIR, and the first mechanism in the tree allowed to override `defaultCountry`.
8
- *
9
- * The failing case: `12 Rue de Rivoli, 75001 Paris` under the en-US locale. `--locale` defaults to
10
- * `en-US`, `localeToCountry` turns that into `ResolveOpts.defaultCountry = "US"`, and the backend
11
- * turns THAT into a hard `spr.country = 'US'` WHERE clause. The candidate pool is all-US before
12
- * ranking begins, so a coarse placer that already called this address FR at confidence
13
- * 0.9999908844 has nothing to promote — a soft re-rank downstream of a hard filter is inert by
14
- * construction. Population then picks Paris, Texas (pop 24,969). With the postal extracts attached
15
- * the answer gets WORSE, not merely wrong: the postcode resolves to the US row (ZIP 75001,
16
- * Addison TX), `applyPostcodeConsistency` finds no Paris within its 50 km check (the nearest is
17
- * 143.8 km), and falls the locality coordinate back to the ZIP point. See
18
- * `docs/records/evals/2026-08-03-postcode-locality-scoping.md` for the instrumented diagnosis.
19
- *
20
- * No pattern-only change can fix this. `75001` is NOT unambiguously French:
21
- * `candidateSystemsForPostcode("75001")` returns `["us", "de", "fr"]`, and the 2026-08-04
22
- * candidate gazetteer holds the literal string in FOUR countries — FR 48.863,2.336 (Paris 1er),
23
- * US 32.960,-96.838 (Addison TX), DE 48.844,9.367, PL 54.190,16.188 (×2 rows). The SHAPE is
24
- * ambiguous four ways. The GEOMETRY is not: Addison and Paris are ~8,000 km apart, and only one
25
- * of the four has a same-named locality next to its 75001.
26
- *
27
- * So this pass asks the question the shape cannot answer — _in which country are this postcode and
28
- * this locality geographically consistent?_ — over exactly the primitive the resolver already uses
29
- * three times (`applyAdminCoherence` #263, `applyExplicitCountryCoherence` #822,
30
- * `applyRegionCountryCoherence`), just keyed on the postcode instead of a region or country token.
31
- *
32
- * ## Why it runs BEFORE the walk, not after
33
- *
34
- * Its three siblings are post-walk re-picks: the walk resolves greedily, they swap the wrong node
35
- * pair for the right one. That shape cannot work here, because the thing to correct is the walk's
36
- * COUNTRY SCOPE, and the scope poisons three separate things a post-walk pass cannot reach — the
37
- * postcode node's own resolution (Addison, not Paris 1er), the `applyPostcodeConsistency` fallback
38
- * that then drags the locality onto it, and the `country` filter on every other admin lookup. So
39
- * this pass is a pre-walk SCOPE decision: it runs once, before the first lookup, and replaces
40
- * `state.defaultCountry` for the whole walk. Everything downstream — including the three post-walk
41
- * coherence passes and the street/rooftop tiers — then sees the corrected country.
42
- *
43
- * ## Why it is not a hard veto (the doctrine check)
44
- *
45
- * Registries are SOFT priors here, positive evidence only. Two properties keep this one honest:
46
- *
47
- * 1. **The default country is tested FIRST, and a coherent default always wins.** If (postcode,
48
- * locality) is consistent under `defaultCountry`, the pass returns `null` immediately, having
49
- * spent at most two lookups, and the walk is byte-identical. Every correctly-scoped domestic
50
- * parse exits here. It is not "US loses to FR"; it is "US had no answer".
51
- * 2. **Abstention is the default outcome.** Zero coherent countries (a wrong-for-the-city
52
- * postcode, or a recall gap in the gazetteer) and MORE than one coherent country (a genuine
53
- * geographic tie) both return `null`. The mechanism only ever speaks when exactly one country
54
- * makes the pair consistent, and only ever when the default country could not.
55
- *
56
- * ## What #24 changed (2026-08-10)
57
- *
58
- * Two structural gaps, both found by replaying the 420-row panel-v2 benchmark. The pass is default-ON,
59
- * the eu-mixed block gave it 29 chances, and it fired **zero** times — while the right answer sat in
60
- * the shipped gazetteer within 4 km of truth on 21 of them.
61
- *
62
- * 1. **The candidate countries came from a proxy.** `candidateSystemsForPostcode` is a shape test over
63
- * the eight slices codex specifies (`us de fr ca gb jp au nz`), so CZ, CH, BE, DK, AT, NL and IT
64
- * could never be PROPOSED, however good the evidence. `13000` shapes as `[us, de, fr]`; the
65
- * gazetteer holds it in exactly one country, and that country is CZ. The candidate set now unions
66
- * the shape list with the countries the gazetteer actually holds the postcode in — one unscoped
67
- * lookup, exhaustive at the measured cardinality (the most-shared code in the artifact carries 12
68
- * rows across 8 countries). Every candidate still has to pass the same geometric pair test, so the
69
- * widening can only convert an abstention into a verdict or a verdict into an abstention, never a
70
- * verdict into a different one.
71
- * 2. **The pair was all-or-nothing.** Ten panel rows had unimpeachable one-sided evidence and no pair:
72
- * the gazetteer carries no CH or BE postcodes at all (so `Sarnen` and `Kelmis` could never agree
73
- * with anything), and `Praha 3` / `Praha 9` are municipal districts no admin gazetteer names (so
74
- * `13000` had nothing to agree WITH). Each half may now speak alone — but only when the DEFAULT
75
- * country corroborates NEITHER half, and only when the speaking half names exactly one country in
76
- * the whole gazetteer. See {@link PostcodeCountryScopeEvidence}.
77
- *
78
- * The abstention doctrine is unchanged and is what bounds the new rungs: a two-country tie is a HARD
79
- * abstention that never falls through to the single-sided rungs. Corroboration at home bounds them
80
- * asymmetrically: the address's own POSTCODE existing in the default country stops the pass dead,
81
- * while a LOCALITY value at home neutralizes that value as a foreign witness without silencing its
82
- * siblings (the per-value rule in the single-sided section below).
83
- *
84
- * ## Evidence
85
- *
86
- * Prototyped out-of-tree against the live gazetteer over the public `findPlace` surface (2026-08-03):
87
- * 400 real US (ZIP, city) pairs from `postalcode-us.db` + 400 real FR (CP, commune) pairs from
88
- * `postcode-locality-fr.db` — 800 pairs, **zero** border crossings, at both the 15 km and 25 km
89
- * checks. The 22 US abstentions were pairs whose ZIP parent name is not an exact-matching locality
90
- * in the admin gazetteer (a recall gap; abstention is the safe outcome). The confound board's
91
- * verdicts were identical at 15, 25 AND 50 km, so the mechanism is not check-tuned; the default
92
- * below is the 25 km the scale run measured.
93
- *
94
- * Cost: 2 lookups on the byte-stable path (postcode + locality under the default country), and at
95
- * most `2 × |candidateSystems| × |localityValues|` — candidates bounded at 12, locality values at 3,
96
- * and the common tree carries exactly one — when the default is incoherent. Nothing runs at all
97
- * unless the tree carries both a postcode and a locality.
98
- *
99
- * **Default-ON** since the operator promotion of 2026-08-05 (#1477) — the resolver gauntlet, pinned
100
- * both ways, returned zero newly-failing conditional cases, and 56,000 pair evaluations across both
101
- * backends returned zero false positives. `ResolveOpts.postcodeCountryCoherence: false` opts out,
102
- * and the walk is byte-stable then. Receipts:
103
- * `docs/records/evals/2026-08-05-postcode-coherence-default-on-evidence.md`.
104
5
  */
105
6
  import { type AddressNode } from "@mailwoman/core/decoder";
106
7
  import type { ResolvedPlace, ResolverBackend } from "@mailwoman/core/resolver";
107
8
  /**
108
- * Default check radius (km) for the postcode↔locality consistency test. 25 km is what the 800-pair scale run measured;
109
- * the confound board returned identical verdicts at 15, 25 and 50, so this is a floor choice, not a tuned one.
9
+ * The default maximum distance, in kilometers, between a postcode and a locality
10
+ * for them to count as consistent.
11
+ *
12
+ * Verdicts did not change anywhere between 15 and 50 km, so the exact value matters little.
110
13
  */
111
14
  export declare const POSTCODE_COUNTRY_COHERENCE_THRESHOLD_KM = 25;
112
15
  /**
113
- * Which half (or halves) of the address bought the verdict — the firing receipt, so a reader of a scoped result can
114
- * tell a two-sided agreement from a one-sided uniqueness claim without re-deriving it.
16
+ * The part of the address that justified a country-scope verdict.
115
17
  *
116
- * - `pair` — postcode AND locality both resolve in this country, within the radius. The strongest rung and the only one
117
- * that existed before #24.
118
- * - `locality` — the locality names exactly one country in the whole gazetteer, and the postcode names none that
119
- * contradict it. This is the CH/BE class: the gazetteer carries no Swiss or Belgian postcodes at all, so the pair
120
- * test can never fire there no matter how good the locality evidence is.
121
- * - `postcode` — the postcode is held in exactly one country and the locality is in no gazetteer at all. The `Praha 3`
122
- * class: a municipal district nobody's admin gazetteer names.
18
+ * - `pair`: the postcode and the locality both resolve in the country, within the threshold distance.
19
+ * - `locality`: the locality exists in exactly one country.
20
+ * The postcode copy in that country does not contradict it.
21
+ * - `postcode`: the postcode exists in exactly one country.
22
+ * No gazetteer knows the locality.
123
23
  */
124
24
  export type PostcodeCountryScopeEvidence = "pair" | "locality" | "postcode";
125
25
  /**
@@ -127,106 +27,92 @@ export type PostcodeCountryScopeEvidence = "pair" | "locality" | "postcode";
127
27
  */
128
28
  export interface PostcodeCountryScope {
129
29
  /**
130
- * ISO-3166 alpha-2, upper-case.
30
+ * The upper-case ISO 3166-1 alpha-2 country code.
131
31
  */
132
32
  country: string;
133
33
  /**
134
- * The postcode string the verdict was reached on (as it appears in the tree).
34
+ * The postcode the verdict used.
135
35
  */
136
36
  postcode: string;
137
37
  /**
138
- * The locality string the verdict was reached on.
38
+ * The locality the verdict used.
139
39
  */
140
40
  locality: string;
141
41
  /**
142
- * Which evidence carried the verdict. See {@link PostcodeCountryScopeEvidence}.
42
+ * The evidence that supported the verdict.
143
43
  */
144
44
  evidence: PostcodeCountryScopeEvidence;
145
45
  /**
146
- * Distance between the resolved postcode point and the nearest same-named locality, in km. Always `<= thresholdKm`.
147
- * Present ONLY for the `pair` rung — a single-sided verdict has no two points to measure between, and reporting a `0`
148
- * there would assert an agreement nobody tested (the meaning-of-zero rule).
46
+ * The distance in kilometers between the postcode point and the nearest locality with the same name.
47
+ *
48
+ * It is set only for `pair` evidence, because the other verdicts compare no second point.
149
49
  */
150
- distanceKm?: number;
50
+ distanceKm: number | null;
151
51
  /**
152
- * The postcode place that anchored the verdict. Absent on the `locality` rung.
52
+ * The postcode place behind the verdict.
53
+ * It is absent for `locality` evidence.
153
54
  */
154
- postcodePlace?: ResolvedPlace;
55
+ postcodePlace: ResolvedPlace | null;
155
56
  /**
156
- * The locality place that anchored the verdict. Absent on the `postcode` rung.
57
+ * The locality place behind the verdict.
58
+ * It is absent for `postcode` evidence.
157
59
  */
158
- localityPlace?: ResolvedPlace;
60
+ localityPlace: ResolvedPlace | null;
159
61
  }
62
+ /**
63
+ * Options for {@linkcode findPostcodeCountryScope}.
64
+ */
160
65
  export interface PostcodeCountryScopeOpts {
161
66
  /**
162
- * The postcode string from the tree (the resolver already pre-scans for it — pass `state.postcode` so this pass and
163
- * the walk can never disagree about WHICH postcode is the address's).
67
+ * The address's postcode.
68
+ *
69
+ * Callers should pass the value from the resolver's own pre-scan, so that this pass
70
+ * and the walk use the same postcode.
164
71
  */
165
72
  postcode: string;
166
73
  /**
167
- * The country the caller's `defaultCountry` would hard-filter to — or `undefined` when no default is in force (the
168
- * browser cascade), where the pass CONSTRAINS instead of overriding: the default-coherence short-circuit is vacuous
169
- * and the exactly-one-country abstention carries the safety alone. Historically required: this pass was built to
170
- * correct a wrong one, so with no default there is nothing to correct and the caller should not be calling.
74
+ * The caller's default country filter, or null when no default applies.
75
+ *
76
+ * Without a default, only the `pair` test runs.
77
+ * The pass returns a scope when exactly one country qualifies.
171
78
  */
172
- defaultCountry: string | undefined;
79
+ defaultCountry: string | null;
173
80
  /**
174
- * Consistency check radius in km. Defaults to {@link POSTCODE_COUNTRY_COHERENCE_THRESHOLD_KM}.
81
+ * The consistency radius in kilometers.
82
+ *
83
+ * @defaultValue {@linkcode POSTCODE_COUNTRY_COHERENCE_THRESHOLD_KM}
175
84
  */
176
85
  thresholdKm?: number;
177
86
  /**
178
- * Optional narrowing of the SHAPE half of the candidate-country set — the shape-coherence pass's intersection for a
179
- * CONFIRMED postcode span (see `resolver/postcode-shape-coherence.ts`, #31 Mechanism 1). When present it REPLACES
180
- * `candidateSystemsForPostcode`'s own list; it is a pure subset of that list (codex systems ∩ confident sibling
181
- * systems). Upper-case ISO-3166 alpha-2, e.g. `["US"]` for a 5-digit code whose siblings all say US.
87
+ * Upper-case ISO 3166-1 alpha-2 codes that replace the countries inferred from the postcode's shape.
182
88
  *
183
- * It narrows the shape half only. Since #24 the candidate set also carries the countries the GAZETTEER holds this
184
- * postcode in, and that half is not narrowable — it is the artifact reporting what it contains, which is the same
185
- * class of evidence the pair test itself runs on. Every candidate from either half still has to pass that test.
89
+ * The pass still adds countries whose gazetteer holds the postcode.
90
+ * Every candidate must pass the pair test.
186
91
  */
187
92
  candidateSystems?: readonly string[];
188
93
  }
189
94
  /**
190
- * The address's locality strings in DOCUMENT ORDER — every `locality` value first, then every `dependent_locality`,
191
- * case-insensitively deduplicated. Two passes so a real locality always beats a dependent one regardless of tree
192
- * order.
193
- *
194
- * Document order is required, not cosmetic. The original stack-pop traversal visited the LAST node first, so on `92
195
- * Laurell Road, Gander, NL A1V 0A9` — where the model tags both `Gander` and the province abbreviation `NL` as
196
- * localities — the pass keyed its whole country verdict on "NL", whose only exact locality-band bearer is an alias of
197
- * Nal, Afghanistan, and the walk resolved a Newfoundland street 10,000 km away. The FIRST-written locality is the one
198
- * the address is about.
95
+ * Returns up to three distinct locality values in document order, listing every
96
+ * `locality` before any `dependent_locality`.
199
97
  *
200
- * ALL values matter, not just the first. On `Calle Mayor 12, Aravaca, 28023 Madrid` the model tags both `Aravaca` and
201
- * `Madrid` as localities; `Aravaca` is a neighbourhood the locality band cannot see, while `Madrid` carries the ES pair
202
- * verdict (the ES 28023 row sits 9.6 km from the Madrid locality row). A pass keyed on a single value bets the whole
203
- * country verdict on whichever one a traversal order happens to pick — first-only re-scoped that address to the US ZIP
204
- * 28023 centroid in North Carolina. So the verdict rungs try each value in order until one produces evidence.
98
+ * Order matters because the first locality written is the one the address is about.
205
99
  */
206
100
  export declare function localityValuesInDocumentOrder(roots: readonly AddressNode[]): string[];
207
101
  /**
208
- * The first of {@link localityValuesInDocumentOrder} — the locality the address is about.
102
+ * Returns the first value of {@link localityValuesInDocumentOrder}.
209
103
  */
210
- export declare function firstLocalityValue(roots: readonly AddressNode[]): string | undefined;
104
+ export declare function firstLocalityValue(roots: readonly AddressNode[]): string | null;
211
105
  /**
212
- * The country in which this address's postcode and locality are geographically consistent — or `null` to abstain.
213
- *
214
- * Order matters and is the whole safety argument. The caller's `defaultCountry` is tested FIRST; a coherent default
215
- * short-circuits with `null` (nothing to correct, ≤2 lookups spent, the walk unchanged). Only when the default cannot
216
- * make the pair consistent are the codex shape's other candidate systems tried, and only a UNIQUE coherent alternative
217
- * produces a verdict — zero (no evidence) and two-or-more (a genuine tie) both abstain.
106
+ * Finds the one country, other than the caller's default, in which the address's
107
+ * postcode and locality are consistent.
218
108
  *
219
- * The candidate set is `candidateSystemsForPostcode` — a model-free SHAPE test over each codex slice's own postcode
220
- * pattern, no safelist and no prior. Its `SystemCode` values are ISO-3166 alpha-2 in lower case, so the upper-casing
221
- * below is the whole conversion. Note the corollary: a country with no codex slice can never be proposed (the gazetteer
222
- * holds `75001` in PL, and this pass will never return PL), which bounds the mechanism to the systems whose postcode
223
- * shapes are actually specified.
109
+ * It returns `null` when the address has a country node, when the default country is
110
+ * already consistent, or when more than one alternative qualifies.
224
111
  */
225
112
  export declare function findPostcodeCountryScope(roots: readonly AddressNode[], backend: ResolverBackend, opts: PostcodeCountryScopeOpts): Promise<PostcodeCountryScope | null>;
226
113
  /**
227
- * Stamp the adopted scope onto the tree's postcode and locality nodes, so a consumer can see that the walk's country
228
- * was not the one the caller asked for — and which evidence bought the change. Additive: identity and coordinates are
229
- * untouched, this only writes `metadata`.
114
+ * Records an adopted country scope and its evidence in the `metadata` of the
115
+ * tree's postcode and locality nodes.
230
116
  */
231
117
  export declare function stampPostcodeCountryScope(roots: readonly AddressNode[], scope: PostcodeCountryScope): void;
232
118
  //# sourceMappingURL=country-coherence.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"country-coherence.d.ts","sourceRoot":"","sources":["../../lib/postcode/country-coherence.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuGG;AAKH,OAAO,EAAa,KAAK,WAAW,EAAE,MAAM,yBAAyB,CAAA;AACrE,OAAO,KAAK,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAA;AAG9E;;;GAGG;AACH,eAAO,MAAM,uCAAuC,KAAK,CAAA;AAEzD;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,4BAA4B,GAAG,MAAM,GAAG,UAAU,GAAG,UAAU,CAAA;AAE3E;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACpC;;OAEG;IACH,OAAO,EAAE,MAAM,CAAA;IACf;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAA;IAChB;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAA;IAChB;;OAEG;IACH,QAAQ,EAAE,4BAA4B,CAAA;IACtC;;;;OAIG;IACH,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB;;OAEG;IACH,aAAa,CAAC,EAAE,aAAa,CAAA;IAC7B;;OAEG;IACH,aAAa,CAAC,EAAE,aAAa,CAAA;CAC7B;AAED,MAAM,WAAW,wBAAwB;IACxC;;;OAGG;IACH,QAAQ,EAAE,MAAM,CAAA;IAChB;;;;;OAKG;IACH,cAAc,EAAE,MAAM,GAAG,SAAS,CAAA;IAClC;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB;;;;;;;;;OASG;IACH,gBAAgB,CAAC,EAAE,SAAS,MAAM,EAAE,CAAA;CACpC;AAeD;;;;;;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