@mailwoman/resolver 9.1.0 → 9.3.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 (142) hide show
  1. package/README.md +89 -0
  2. package/lib/admin/coherence-passes.ts +435 -0
  3. package/lib/admin/containment.ts +92 -0
  4. package/lib/admin/index.ts +10 -0
  5. package/lib/admin/jp-municipality.ts +97 -0
  6. package/lib/admin/winner.ts +189 -0
  7. package/lib/backend-capabilities.ts +88 -0
  8. package/lib/bare-toponym-race.ts +129 -0
  9. package/lib/decorate-node.ts +127 -0
  10. package/lib/fold-name.ts +36 -0
  11. package/{index.ts → lib/index.ts} +27 -18
  12. package/{plausibility.ts → lib/plausibility.ts} +5 -4
  13. package/{postcode-country-coherence.ts → lib/postcode/country-coherence.ts} +173 -86
  14. package/lib/postcode/index.ts +9 -0
  15. package/{postcode-prefix.ts → lib/postcode/prefix.ts} +7 -6
  16. package/{postcode-shape-coherence.ts → lib/postcode/shape-coherence.ts} +10 -24
  17. package/{remote-resolver.ts → lib/remote-resolver.ts} +13 -4
  18. package/{rerank.ts → lib/rerank.ts} +2 -2
  19. package/lib/resolve/index.ts +982 -0
  20. package/lib/resolve/passes.ts +544 -0
  21. package/{span-rescore.ts → lib/span-rescore.ts} +114 -99
  22. package/{street-evidence.ts → lib/street/evidence.ts} +40 -7
  23. package/lib/street/index.ts +8 -0
  24. package/{street-tier.ts → lib/street/tier.ts} +138 -99
  25. package/{toponym-prior.ts → lib/toponym-prior.ts} +97 -8
  26. package/out/admin/coherence-passes.d.ts +70 -0
  27. package/out/admin/coherence-passes.d.ts.map +1 -0
  28. package/out/admin/coherence-passes.js +327 -0
  29. package/out/admin/coherence-passes.js.map +1 -0
  30. package/out/admin/containment.d.ts +48 -0
  31. package/out/admin/containment.d.ts.map +1 -0
  32. package/out/admin/containment.js +76 -0
  33. package/out/admin/containment.js.map +1 -0
  34. package/out/admin/index.d.ts +10 -0
  35. package/out/admin/index.d.ts.map +1 -0
  36. package/out/admin/index.js +10 -0
  37. package/out/admin/index.js.map +1 -0
  38. package/out/admin/jp-municipality.d.ts +50 -0
  39. package/out/admin/jp-municipality.d.ts.map +1 -0
  40. package/out/admin/jp-municipality.js +54 -0
  41. package/out/admin/jp-municipality.js.map +1 -0
  42. package/out/admin/winner.d.ts +114 -0
  43. package/out/admin/winner.d.ts.map +1 -0
  44. package/out/admin/winner.js +130 -0
  45. package/out/admin/winner.js.map +1 -0
  46. package/out/backend-capabilities.d.ts +37 -0
  47. package/out/backend-capabilities.d.ts.map +1 -0
  48. package/out/backend-capabilities.js +75 -0
  49. package/out/backend-capabilities.js.map +1 -0
  50. package/out/bare-toponym-race.d.ts +55 -0
  51. package/out/bare-toponym-race.d.ts.map +1 -0
  52. package/out/bare-toponym-race.js +110 -0
  53. package/out/bare-toponym-race.js.map +1 -0
  54. package/out/decorate-node.d.ts +24 -0
  55. package/out/decorate-node.d.ts.map +1 -0
  56. package/out/decorate-node.js +103 -0
  57. package/out/decorate-node.js.map +1 -0
  58. package/out/fold-name.d.ts +18 -3
  59. package/out/fold-name.d.ts.map +1 -1
  60. package/out/fold-name.js +19 -3
  61. package/out/fold-name.js.map +1 -1
  62. package/out/index.d.ts +15 -12
  63. package/out/index.d.ts.map +1 -1
  64. package/out/index.js +9 -7
  65. package/out/index.js.map +1 -1
  66. package/out/plausibility.d.ts +5 -4
  67. package/out/plausibility.d.ts.map +1 -1
  68. package/out/plausibility.js +5 -4
  69. package/out/plausibility.js.map +1 -1
  70. package/out/{postcode-country-coherence.d.ts → postcode/country-coherence.d.ts} +46 -25
  71. package/out/postcode/country-coherence.d.ts.map +1 -0
  72. package/out/{postcode-country-coherence.js → postcode/country-coherence.js} +157 -77
  73. package/out/postcode/country-coherence.js.map +1 -0
  74. package/out/postcode/index.d.ts +9 -0
  75. package/out/postcode/index.d.ts.map +1 -0
  76. package/out/postcode/index.js +9 -0
  77. package/out/postcode/index.js.map +1 -0
  78. package/out/{postcode-prefix.d.ts → postcode/prefix.d.ts} +4 -4
  79. package/out/postcode/prefix.d.ts.map +1 -0
  80. package/out/{postcode-prefix.js → postcode/prefix.js} +7 -6
  81. package/out/postcode/prefix.js.map +1 -0
  82. package/out/{postcode-shape-coherence.d.ts → postcode/shape-coherence.d.ts} +3 -3
  83. package/out/postcode/shape-coherence.d.ts.map +1 -0
  84. package/out/{postcode-shape-coherence.js → postcode/shape-coherence.js} +11 -20
  85. package/out/postcode/shape-coherence.js.map +1 -0
  86. package/out/remote-resolver.d.ts +18 -3
  87. package/out/remote-resolver.d.ts.map +1 -1
  88. package/out/remote-resolver.js +2 -2
  89. package/out/remote-resolver.js.map +1 -1
  90. package/out/rerank.d.ts +1 -1
  91. package/out/rerank.d.ts.map +1 -1
  92. package/out/rerank.js +2 -2
  93. package/out/rerank.js.map +1 -1
  94. package/out/{resolve.d.ts → resolve/index.d.ts} +2 -2
  95. package/out/resolve/index.d.ts.map +1 -0
  96. package/out/resolve/index.js +795 -0
  97. package/out/resolve/index.js.map +1 -0
  98. package/out/resolve/passes.d.ts +218 -0
  99. package/out/resolve/passes.d.ts.map +1 -0
  100. package/out/resolve/passes.js +333 -0
  101. package/out/resolve/passes.js.map +1 -0
  102. package/out/span-rescore.d.ts +16 -16
  103. package/out/span-rescore.d.ts.map +1 -1
  104. package/out/span-rescore.js +87 -71
  105. package/out/span-rescore.js.map +1 -1
  106. package/out/{street-evidence.d.ts → street/evidence.d.ts} +18 -3
  107. package/out/street/evidence.d.ts.map +1 -0
  108. package/out/{street-evidence.js → street/evidence.js} +23 -7
  109. package/out/street/evidence.js.map +1 -0
  110. package/out/street/index.d.ts +8 -0
  111. package/out/street/index.d.ts.map +1 -0
  112. package/out/street/index.js +8 -0
  113. package/out/street/index.js.map +1 -0
  114. package/out/{street-tier.d.ts → street/tier.d.ts} +14 -3
  115. package/out/street/tier.d.ts.map +1 -0
  116. package/out/{street-tier.js → street/tier.js} +127 -90
  117. package/out/street/tier.js.map +1 -0
  118. package/out/toponym-prior.d.ts +43 -19
  119. package/out/toponym-prior.d.ts.map +1 -1
  120. package/out/toponym-prior.js +76 -8
  121. package/out/toponym-prior.js.map +1 -1
  122. package/package.json +167 -19
  123. package/vitest.config.ts +5 -6
  124. package/fold-name.ts +0 -20
  125. package/out/postcode-country-coherence.d.ts.map +0 -1
  126. package/out/postcode-country-coherence.js.map +0 -1
  127. package/out/postcode-prefix.d.ts.map +0 -1
  128. package/out/postcode-prefix.js.map +0 -1
  129. package/out/postcode-shape-coherence.d.ts.map +0 -1
  130. package/out/postcode-shape-coherence.js.map +0 -1
  131. package/out/resolve.d.ts.map +0 -1
  132. package/out/resolve.js +0 -1049
  133. package/out/resolve.js.map +0 -1
  134. package/out/street-evidence.d.ts.map +0 -1
  135. package/out/street-evidence.js.map +0 -1
  136. package/out/street-tier.d.ts.map +0 -1
  137. package/out/street-tier.js.map +0 -1
  138. package/out/vitest.config.d.ts +0 -16
  139. package/out/vitest.config.d.ts.map +0 -1
  140. package/out/vitest.config.js +0 -36
  141. package/out/vitest.config.js.map +0 -1
  142. package/resolve.ts +0 -1369
@@ -11,13 +11,13 @@
11
11
  * turns THAT into a hard `spr.country = 'US'` WHERE clause. The candidate pool is all-US before
12
12
  * ranking begins, so a coarse placer that already called this address FR at confidence
13
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 shards attached
14
+ * construction. Population then picks Paris, Texas (pop 24,969). With the postal extracts attached
15
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 gate (the nearest is
16
+ * Addison TX), `applyPostcodeConsistency` finds no Paris within its 50 km check (the nearest is
17
17
  * 143.8 km), and falls the locality coordinate back to the ZIP point. See
18
18
  * `docs/records/evals/2026-08-03-postcode-locality-scoping.md` for the instrumented diagnosis.
19
19
  *
20
- * No pattern-only lever can fix this. `75001` is NOT unambiguously French:
20
+ * No pattern-only change can fix this. `75001` is NOT unambiguously French:
21
21
  * `candidateSystemsForPostcode("75001")` returns `["us", "de", "fr"]`, and the 2026-08-04
22
22
  * candidate gazetteer holds the literal string in FOUR countries — FR 48.863,2.336 (Paris 1er),
23
23
  * US 32.960,-96.838 (Addison TX), DE 48.844,9.367, PL 54.190,16.188 (×2 rows). The SHAPE is
@@ -40,7 +40,7 @@
40
40
  * `state.defaultCountry` for the whole walk. Everything downstream — including the three post-walk
41
41
  * coherence passes and the street/rooftop tiers — then sees the corrected country.
42
42
  *
43
- * ## Why it is not a hard veto (the doctrine gate)
43
+ * ## Why it is not a hard veto (the doctrine check)
44
44
  *
45
45
  * Registries are SOFT priors here, positive evidence only. Two properties keep this one honest:
46
46
  *
@@ -76,26 +76,28 @@
76
76
  * the whole gazetteer. See {@link PostcodeCountryScopeEvidence}.
77
77
  *
78
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, and any corroboration at home — the
80
- * address's own city or its own postcode existing in the default country — stops the pass dead.
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).
81
83
  *
82
84
  * ## Evidence
83
85
  *
84
86
  * Prototyped out-of-tree against the live gazetteer over the public `findPlace` surface (2026-08-03):
85
87
  * 400 real US (ZIP, city) pairs from `postalcode-us.db` + 400 real FR (CP, commune) pairs from
86
88
  * `postcode-locality-fr.db` — 800 pairs, **zero** border crossings, at both the 15 km and 25 km
87
- * gates. The 22 US abstentions were pairs whose ZIP parent name is not an exact-matching locality
89
+ * checks. The 22 US abstentions were pairs whose ZIP parent name is not an exact-matching locality
88
90
  * in the admin gazetteer (a recall gap; abstention is the safe outcome). The confound board's
89
- * verdicts were identical at 15, 25 AND 50 km, so the mechanism is not gate-tuned; the default
91
+ * verdicts were identical at 15, 25 AND 50 km, so the mechanism is not check-tuned; the default
90
92
  * below is the 25 km the scale run measured.
91
93
  *
92
94
  * Cost: 2 lookups on the byte-stable path (postcode + locality under the default country), and at
93
- * most `2 × |candidateSystems|` — bounded at 8, since a numeric shape matches at most `us`/`de`/`fr`
94
- * — when the default is incoherent. Nothing runs at all unless a `defaultCountry` is in force AND
95
- * the tree carries both a postcode and a locality.
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.
96
98
  *
97
99
  * **Default-ON** since the operator promotion of 2026-08-05 (#1477) — the resolver gauntlet, pinned
98
- * both ways, returned zero newly-failing gated cases, and 56,000 pair evaluations across both
100
+ * both ways, returned zero newly-failing conditional cases, and 56,000 pair evaluations across both
99
101
  * backends returned zero false positives. `ResolveOpts.postcodeCountryCoherence: false` opts out,
100
102
  * and the walk is byte-stable then. Receipts:
101
103
  * `docs/records/evals/2026-08-05-postcode-coherence-default-on-evidence.md`.
@@ -103,33 +105,67 @@
103
105
  // `postcode-systems` has no dedicated export subpath; the barrel is where every other consumer
104
106
  // (`neural/postcode-anchor.ts`) reaches it from.
105
107
  import { candidateSystemsForPostcode } from "@mailwoman/codex";
108
+ import { walkNodes } from "@mailwoman/core/decoder";
106
109
  import { haversineKm } from "@mailwoman/spatial";
107
110
  /**
108
- * Default gate radius (km) for the postcode↔locality consistency test. 25 km is what the 800-pair scale run measured;
111
+ * Default check radius (km) for the postcode↔locality consistency test. 25 km is what the 800-pair scale run measured;
109
112
  * the confound board returned identical verdicts at 15, 25 and 50, so this is a floor choice, not a tuned one.
110
113
  */
111
- export const POSTCODE_COUNTRY_COHERENCE_GATE_KM = 25;
114
+ export const POSTCODE_COUNTRY_COHERENCE_THRESHOLD_KM = 25;
112
115
  /**
113
- * A usable coordinate — the gazetteer stores an unlocated row as 0,0, which haversine would happily measure against.
116
+ * A usable coordinate — the gazetteer stores an unlocated row as 0,0, which haversine would measure against.
114
117
  */
115
118
  function hasCoord(p) {
116
119
  return p.lat !== 0 || p.lon !== 0;
117
120
  }
118
121
  /**
119
- * The address's locality string: the first `locality` node anywhere in the tree, else the first `dependent_locality`.
120
- * Two passes so a real locality always beats a dependent one regardless of tree order.
122
+ * Upper bound on locality values the pass will consider. A parse rarely tags more than two; the cap keeps a
123
+ * pathological tree from multiplying the pair sweep.
121
124
  */
122
- export function firstLocalityValue(roots) {
125
+ const MAX_LOCALITY_VALUES = 3;
126
+ /**
127
+ * The address's locality strings in DOCUMENT ORDER — every `locality` value first, then every `dependent_locality`,
128
+ * case-insensitively deduplicated. Two passes so a real locality always beats a dependent one regardless of tree
129
+ * order.
130
+ *
131
+ * Document order is required, not cosmetic. The original stack-pop traversal visited the LAST node first, so on `92
132
+ * Laurell Road, Gander, NL A1V 0A9` — where the model tags both `Gander` and the province abbreviation `NL` as
133
+ * localities — the pass keyed its whole country verdict on "NL", whose only exact locality-band bearer is an alias of
134
+ * Nal, Afghanistan, and the walk resolved a Newfoundland street 10,000 km away. The FIRST-written locality is the one
135
+ * the address is about.
136
+ *
137
+ * ALL values matter, not just the first. On `Calle Mayor 12, Aravaca, 28023 Madrid` the model tags both `Aravaca` and
138
+ * `Madrid` as localities; `Aravaca` is a neighbourhood the locality band cannot see, while `Madrid` carries the ES pair
139
+ * verdict (the ES 28023 row sits 9.6 km from the Madrid locality row). A pass keyed on a single value bets the whole
140
+ * country verdict on whichever one a traversal order happens to pick — first-only re-scoped that address to the US ZIP
141
+ * 28023 centroid in North Carolina. So the verdict rungs try each value in order until one produces evidence.
142
+ */
143
+ export function localityValuesInDocumentOrder(roots) {
144
+ const out = [];
145
+ const seen = new Set();
123
146
  for (const tag of ["locality", "dependent_locality"]) {
124
- const stack = [...roots];
125
- while (stack.length) {
126
- const n = stack.pop();
127
- if (n.tag === tag && n.value.trim().length)
128
- return n.value.trim();
129
- stack.push(...n.children);
147
+ collectInDocumentOrder(roots, tag, out, seen);
148
+ }
149
+ return out.slice(0, MAX_LOCALITY_VALUES);
150
+ }
151
+ /**
152
+ * The first of {@link localityValuesInDocumentOrder} — the locality the address is about.
153
+ */
154
+ export function firstLocalityValue(roots) {
155
+ return localityValuesInDocumentOrder(roots)[0];
156
+ }
157
+ function collectInDocumentOrder(nodes, tag, out, seen) {
158
+ for (const n of nodes) {
159
+ if (n.tag === tag && n.value.trim().length) {
160
+ const value = n.value.trim();
161
+ const key = value.toLowerCase();
162
+ if (!seen.has(key)) {
163
+ seen.add(key);
164
+ out.push(value);
165
+ }
130
166
  }
167
+ collectInDocumentOrder(n.children, tag, out, seen);
131
168
  }
132
- return undefined;
133
169
  }
134
170
  /**
135
171
  * Over-fetch for the UNSCOPED holder probes (#24). Postcodes are bounded and small — the 2026-08-10 candidate
@@ -162,11 +198,11 @@ const MAX_CANDIDATE_COUNTRIES = 12;
162
198
  * lesson — `BT3 9QQ` trigram-matching Sheffield's `S3 9QQ`), and a fuzzy locality hit is evidence about the index, not
163
199
  * about the country. Backends that do not stamp the flag leave it undefined and still contribute.
164
200
  */
165
- async function countriesHolding(backend, text, placetype, limit) {
201
+ async function countriesHolding(backend, text, placetype, limit, opts) {
166
202
  const out = new Map();
167
203
  let hits;
168
204
  try {
169
- hits = await backend.findPlace({ text, placetype, limit });
205
+ hits = await backend.findPlace({ text, placetype, limit, ...(opts?.primaryOnly ? { primaryOnly: true } : {}) });
170
206
  }
171
207
  catch {
172
208
  return out; // a backend hiccup degrades to "no evidence", never to a crashed resolve
@@ -184,10 +220,11 @@ async function countriesHolding(backend, text, placetype, limit) {
184
220
  /**
185
221
  * Is the (postcode, locality) pair geographically consistent in `country`? Returns the winning pair and its distance,
186
222
  * or `null` when the postcode does not resolve there, no same-named locality exists there, or the nearest one is
187
- * outside the gate. Costs one postcode lookup plus (only if that hit) one locality lookup — or just the locality lookup
188
- * when the caller already knows the country's postcode row (`knownPostcodePlace`, from the exhaustive unscoped probe).
223
+ * outside the check. Costs one postcode lookup plus (only if that hit) one locality lookup — or just the locality
224
+ * lookup when the caller already knows the country's postcode row (`knownPostcodePlace`, from the exhaustive unscoped
225
+ * probe).
189
226
  */
190
- async function coherenceIn(country, postcode, locality, backend, gateKm, knownPostcodePlace) {
227
+ async function coherenceIn(country, postcode, locality, backend, thresholdKm, knownPostcodePlace) {
191
228
  let postcodePlace = knownPostcodePlace;
192
229
  if (!postcodePlace) {
193
230
  let postcodeHits;
@@ -216,7 +253,7 @@ async function coherenceIn(country, postcode, locality, backend, gateKm, knownPo
216
253
  if (!candidate.exactMatch || !hasCoord(candidate))
217
254
  continue;
218
255
  const distanceKm = haversineKm(postcodePlace.lat, postcodePlace.lon, candidate.lat, candidate.lon);
219
- if (distanceKm > gateKm)
256
+ if (distanceKm > thresholdKm)
220
257
  continue;
221
258
  if (!best || distanceKm < best.distanceKm) {
222
259
  best = { localityPlace: candidate, distanceKm };
@@ -240,20 +277,26 @@ async function coherenceIn(country, postcode, locality, backend, gateKm, knownPo
240
277
  */
241
278
  export async function findPostcodeCountryScope(roots, backend, opts) {
242
279
  const postcode = opts.postcode.trim();
243
- const defaultCountry = opts.defaultCountry.trim().toUpperCase();
244
- if (!postcode || !defaultCountry)
280
+ const defaultCountry = opts.defaultCountry?.trim().toUpperCase() || undefined;
281
+ if (!postcode)
245
282
  return null;
246
- const locality = firstLocalityValue(roots);
283
+ const localities = localityValuesInDocumentOrder(roots);
247
284
  // Both halves of the pair are required. A postcode with no locality has nothing to be coherent WITH, which is what
248
285
  // keeps this pass inert on "Springfield, IL 62701" (the parser tags Springfield as a `street` — a separate defect)
249
286
  // and on every bare-postcode query.
250
- if (!locality)
251
- return null;
252
- const gateKm = opts.gateKm ?? POSTCODE_COUNTRY_COHERENCE_GATE_KM;
253
- // 1. Is the caller's own default country coherent? If so we are done — positive evidence for the default,
254
- // no override, and the common domestic path costs two lookups and changes nothing.
255
- if (await coherenceIn(defaultCountry, postcode, locality, backend, gateKm))
287
+ if (!localities.length)
256
288
  return null;
289
+ const thresholdKm = opts.thresholdKm ?? POSTCODE_COUNTRY_COHERENCE_THRESHOLD_KM;
290
+ // 1. Is the caller's own default country coherent with ANY of the address's locality values? If so we are done —
291
+ // positive evidence for the default, no override, and the common domestic path (one locality value) costs two
292
+ // lookups and changes nothing. With no default in force (the browser cascade) there is nothing to test — the
293
+ // sweep below carries the whole verdict.
294
+ if (defaultCountry) {
295
+ for (const locality of localities) {
296
+ if (await coherenceIn(defaultCountry, postcode, locality, backend, thresholdKm))
297
+ return null;
298
+ }
299
+ }
257
300
  // 2. The default could not place this pair. Which countries could? Two sources, unioned:
258
301
  //
259
302
  // - the SHAPE list (`candidateSystemsForPostcode`, or the shape-coherence pass's narrowing when #31
@@ -271,19 +314,30 @@ export async function findPostcodeCountryScope(roots, backend, opts) {
271
314
  const candidates = [...new Set([...shapeSystems, ...pcHolders.keys()])]
272
315
  .filter((country) => country !== defaultCountry)
273
316
  .slice(0, MAX_CANDIDATE_COUNTRIES);
274
- const coherent = [];
275
- for (const country of candidates) {
276
- const hit = await coherenceIn(country, postcode, locality, backend, gateKm, pcHolders.get(country));
277
- if (hit) {
278
- coherent.push({ country, postcode, locality, evidence: "pair", ...hit });
317
+ // 3. The pair sweep, per locality value in document order: the first value that produces evidence decides. A value
318
+ // the band cannot see (`Aravaca`, a neighbourhood) yields zero coherent countries and the NEXT value gets its
319
+ // turn — betting the verdict on a single value re-scoped that address to a US ZIP centroid (see
320
+ // localityValuesInDocumentOrder). Exactly one coherent country is a verdict. Two coherent countries mean the
321
+ // geometry genuinely does not decide, and guessing between them is precisely what this mechanism exists not to
322
+ // do — a TIE is a hard abstention, never a fall-through to a later value or the weaker rungs below.
323
+ for (const locality of localities) {
324
+ const coherent = [];
325
+ for (const country of candidates) {
326
+ const hit = await coherenceIn(country, postcode, locality, backend, thresholdKm, pcHolders.get(country));
327
+ if (hit) {
328
+ coherent.push({ country, postcode, locality, evidence: "pair", ...hit });
329
+ }
279
330
  }
331
+ if (coherent.length === 1)
332
+ return coherent[0];
333
+ if (coherent.length > 1)
334
+ return null;
280
335
  }
281
- // 3. Exactly one country makes the pair consistent, or we fall through. Two coherent countries mean the geometry
282
- // genuinely does not decide, and guessing between them is precisely what this mechanism exists not to do — so a
283
- // TIE is a hard abstention, never a fall-through to the weaker rungs below.
284
- if (coherent.length === 1)
285
- return coherent[0];
286
- if (coherent.length > 1)
336
+ // The single-sided rungs below lean on the DEFAULT country as the domestic-plausibility guard
337
+ // ("Vienna, VA" stays in Virginia because the default corroborates a half). With no default there
338
+ // is no such anchor, so the no-default path ends at the pair rung: a pair verdict (Zabiče) is
339
+ // in-scope, a single-sided guess is not.
340
+ if (!defaultCountry)
287
341
  return null;
288
342
  // 4. No country makes the PAIR consistent. On the 2026-08-09 panel that happened 10 times for two opposite
289
343
  // reasons, and in both the address's country was never in doubt — only unrepresentable as a pair:
@@ -292,36 +346,65 @@ export async function findPostcodeCountryScope(roots, backend, opts) {
292
346
  // agree with anything no matter how good the locality evidence is; or
293
347
  // - the locality is a name no admin gazetteer carries (`Praha 3`, `Praha 9` — municipal districts).
294
348
  //
295
- // So each half gets to speak alone, under two conditions that keep this from becoming a guess. First, the
296
- // DEFAULT country must corroborate NEITHER half — if the address's own city or its own postcode exists at
297
- // home, the address is domestically plausible and nothing foreign may be proposed (this is what holds
298
- // `123 Main St, Vienna, VA 22180` in Virginia even though Wien is the vastly more prominent Vienna).
299
- // Second, the speaking half must name EXACTLY ONE country in the entire gazetteer — the same uniqueness bar
300
- // the pair rung uses, applied to one side.
349
+ // So each half gets to speak alone, under conditions that keep this from becoming a guess. The
350
+ // POSTCODE half is all-or-nothing: the default country holding this postcode makes the address
351
+ // domestically plausible outright, and nothing foreign may be proposed. The LOCALITY half is
352
+ // judged PER VALUE — a value the default country holds is domestic corroboration for THAT value
353
+ // (it is neutralized as a foreign witness) without silencing its siblings. `14 Long St, Green
354
+ // Point, Cape Town, 8001` is why: "Green Point" has pop-0 US namesakes, and letting that one
355
+ // value abstain the whole pass handed a uniquely-ZA "Cape Town" to a hard US filter (the walk
356
+ // answered Green Point, Pennsylvania). `123 Main St, Vienna, VA 22180` still holds in Virginia:
357
+ // its ONLY locality value is domestic, so no foreign witness remains. The speaking value must
358
+ // name EXACTLY ONE country in the entire gazetteer — the same uniqueness bar the pair rung uses,
359
+ // applied to one side — and all speaking values must AGREE on that country.
301
360
  if (pcHolders.has(defaultCountry))
302
361
  return null;
303
- if (await holdsLocality(backend, locality, defaultCountry))
304
- return null;
305
- // 4a. The locality names exactly one country. Stronger than the postcode rung — a place name is far more
306
- // discriminative than a four-digit code — so it is tried first. It stands down when that country's OWN
307
- // postcode row contradicts the locality (outside the gate): the two halves disagreeing inside one country
308
- // is exactly what the pair test exists to catch, and a single-sided rung must not launder it.
309
- const locHolders = await countriesHolding(backend, locality, "locality", LOCALITY_HOLDER_FETCH);
310
- if (locHolders.size === 1) {
362
+ // 4a. A locality value names exactly one country. Stronger than the postcode rung — a place name is far
363
+ // more discriminative than a four-digit code — so it is tried first. A verdict stands down when that
364
+ // country's OWN postcode row contradicts the locality (outside the check): the two halves disagreeing
365
+ // inside one country is exactly what the pair test exists to catch, and a single-sided rung must not
366
+ // launder it.
367
+ // PRIMARY-keyed rows only (#1626's re-reading discipline, applied to a country verdict): "the locality
368
+ // names exactly one country" must mean a place NAMED that, never a place aliased to it — "NL"'s only
369
+ // locality-band bearer was an exact ALIAS of Nal, Afghanistan, and a single alias row steered the whole
370
+ // walk's country. The pair rung keeps aliases: there the postcode's own geometry corroborates them.
371
+ let anyDomestic = false;
372
+ let anyLocalityKnown = false;
373
+ const verdicts = new Map();
374
+ for (const locality of localities) {
375
+ if (await holdsLocality(backend, locality, defaultCountry)) {
376
+ anyDomestic = true;
377
+ continue;
378
+ }
379
+ const locHolders = await countriesHolding(backend, locality, "locality", LOCALITY_HOLDER_FETCH, {
380
+ primaryOnly: true,
381
+ });
382
+ if (locHolders.size) {
383
+ anyLocalityKnown = true;
384
+ }
385
+ if (locHolders.size !== 1)
386
+ continue;
311
387
  const [country, localityPlace] = [...locHolders.entries()][0];
312
388
  const ownPostcode = pcHolders.get(country);
313
389
  const contradicted = ownPostcode !== undefined &&
314
- haversineKm(ownPostcode.lat, ownPostcode.lon, localityPlace.lat, localityPlace.lon) > gateKm;
315
- if (country !== defaultCountry && !contradicted) {
316
- return { country, postcode, locality, evidence: "locality", localityPlace };
390
+ haversineKm(ownPostcode.lat, ownPostcode.lon, localityPlace.lat, localityPlace.lon) > thresholdKm;
391
+ if (country !== defaultCountry && !contradicted && !verdicts.has(country)) {
392
+ verdicts.set(country, { country, postcode, locality, evidence: "locality", localityPlace });
317
393
  }
318
394
  }
319
- // 4b. The locality is in no gazetteer (or names several countries) and the postcode is held in exactly one.
320
- // `Biskupcova 1843/3, 13000 Praha 3`: `13000` is a CZ code and nothing else, anywhere.
321
- if (!locHolders.size && pcHolders.size === 1) {
395
+ // Every speaking value must agree: two values uniquely naming DIFFERENT countries is a genuine
396
+ // ambiguity, and guessing between them is what this mechanism exists not to do.
397
+ if (verdicts.size === 1)
398
+ return [...verdicts.values()][0];
399
+ if (verdicts.size > 1)
400
+ return null;
401
+ // 4b. The postcode is held in exactly one country and the locality half is silent EVERYWHERE — no value
402
+ // is domestic and no value names any country. `Biskupcova 1843/3, 13000 Praha 3`: `13000` is a CZ
403
+ // code and nothing else, anywhere, and `Praha 3` (a municipal district) is in no admin gazetteer.
404
+ if (!anyDomestic && !anyLocalityKnown && pcHolders.size === 1) {
322
405
  const [country, postcodePlace] = [...pcHolders.entries()][0];
323
406
  if (country !== defaultCountry) {
324
- return { country, postcode, locality, evidence: "postcode", postcodePlace };
407
+ return { country, postcode, locality: localities[0], evidence: "postcode", postcodePlace };
325
408
  }
326
409
  }
327
410
  return null;
@@ -348,10 +431,7 @@ async function holdsLocality(backend, locality, country) {
348
431
  * untouched, this only writes `metadata`.
349
432
  */
350
433
  export function stampPostcodeCountryScope(roots, scope) {
351
- const stack = [...roots];
352
- while (stack.length) {
353
- const n = stack.pop();
354
- stack.push(...n.children);
434
+ for (const n of walkNodes(roots)) {
355
435
  if (n.tag !== "postcode" && n.tag !== "locality" && n.tag !== "dependent_locality")
356
436
  continue;
357
437
  n.metadata = {
@@ -366,4 +446,4 @@ export function stampPostcodeCountryScope(roots, scope) {
366
446
  };
367
447
  }
368
448
  }
369
- //# sourceMappingURL=postcode-country-coherence.js.map
449
+ //# sourceMappingURL=country-coherence.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"country-coherence.js","sourceRoot":"","sources":["../../lib/postcode/country-coherence.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuGG;AAEH,+FAA+F;AAC/F,iDAAiD;AACjD,OAAO,EAAE,2BAA2B,EAAE,MAAM,kBAAkB,CAAA;AAC9D,OAAO,EAAE,SAAS,EAAoB,MAAM,yBAAyB,CAAA;AAErE,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAEhD;;;GAGG;AACH,MAAM,CAAC,MAAM,uCAAuC,GAAG,EAAE,CAAA;AAkFzD;;GAEG;AACH,SAAS,QAAQ,CAAC,CAAgB;IACjC,OAAO,CAAC,CAAC,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC,GAAG,KAAK,CAAC,CAAA;AAClC,CAAC;AAED;;;GAGG;AACH,MAAM,mBAAmB,GAAG,CAAC,CAAA;AAE7B;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,6BAA6B,CAAC,KAA6B;IAC1E,MAAM,GAAG,GAAa,EAAE,CAAA;IACxB,MAAM,IAAI,GAAG,IAAI,GAAG,EAAU,CAAA;IAE9B,KAAK,MAAM,GAAG,IAAI,CAAC,UAAU,EAAE,oBAAoB,CAAU,EAAE,CAAC;QAC/D,sBAAsB,CAAC,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,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AAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,UAAU,IAAI,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAA;IAC3D,CAAC;IAAC,MAAM,CAAC;QACR,wGAAwG;QACxG,+DAA+D;QAC/D,OAAO,IAAI,CAAA;IACZ,CAAC;AACF,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,yBAAyB,CAAC,KAA6B,EAAE,KAA2B;IACnG,KAAK,MAAM,CAAC,IAAI,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC;QAClC,IAAI,CAAC,CAAC,GAAG,KAAK,UAAU,IAAI,CAAC,CAAC,GAAG,KAAK,UAAU,IAAI,CAAC,CAAC,GAAG,KAAK,oBAAoB;YAAE,SAAQ;QAE5F,CAAC,CAAC,QAAQ,GAAG;YACZ,GAAG,CAAC,CAAC,QAAQ;YACb,sBAAsB,EAAE,KAAK,CAAC,OAAO;YACrC,oGAAoG;YACpG,6EAA6E;YAC7E,+BAA+B,EAAE,KAAK,CAAC,QAAQ;YAC/C,mGAAmG;YACnG,2BAA2B;YAC3B,GAAG,CAAC,KAAK,CAAC,UAAU,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,yBAAyB,EAAE,KAAK,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SAC1F,CAAA;IACF,CAAC;AACF,CAAC"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * @copyright Sister Software
3
+ * @license AGPL-3.0
4
+ * @author Teffen Ellis, et al.
5
+ */
6
+ export * from "#postcode/country-coherence";
7
+ export * from "#postcode/prefix";
8
+ export * from "#postcode/shape-coherence";
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../lib/postcode/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,cAAc,6BAA6B,CAAA;AAC3C,cAAc,kBAAkB,CAAA;AAChC,cAAc,2BAA2B,CAAA"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * @copyright Sister Software
3
+ * @license AGPL-3.0
4
+ * @author Teffen Ellis, et al.
5
+ */
6
+ export * from "#postcode/country-coherence";
7
+ export * from "#postcode/prefix";
8
+ export * from "#postcode/shape-coherence";
9
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../lib/postcode/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,cAAc,6BAA6B,CAAA;AAC3C,cAAc,kBAAkB,CAAA;AAChC,cAAc,2BAA2B,CAAA"}
@@ -29,7 +29,7 @@
29
29
  * acquisition) — the branch exists so the law is tested before the data.
30
30
  * - **Anything else** — abstain (null).
31
31
  *
32
- * ## The probe's country gate
32
+ * ## The probe's country restriction
33
33
  *
34
34
  * The index is country-specific EVIDENCE: it is only probed when its `country` matches the
35
35
  * query's country scope (or the scope is absent). A GB index must not speak under a US scope —
@@ -61,7 +61,7 @@ import type { PostcodePrefixIndexLike, PostcodePrefixNode, ResolvedPlace } from
61
61
  * even the 0,0 unlocated sentinel), and the prefix prior's ancestry-only tier must express absence as `undefined`
62
62
  * instead — B3-3: inventing a centroid would reproduce the `BT3 9QQ` → Sheffield defect #1480. `decorateNode` copies
63
63
  * `lat`/`lon` onto the node verbatim, so an undefined coordinate stays absent on the node — the meaning-of-zero rule.
64
- * Widened ONLY at this seam: gazetteer places (always coordinate-bearing) remain plain `ResolvedPlace`.
64
+ * Widened ONLY at this boundary: gazetteer places (always coordinate-bearing) remain plain `ResolvedPlace`.
65
65
  */
66
66
  export type CoordinateOptionalPlace = Omit<ResolvedPlace, "lat" | "lon"> & {
67
67
  lat?: number;
@@ -86,7 +86,7 @@ export interface PostcodePrefixProbeResult {
86
86
  node: PostcodePrefixNode;
87
87
  }
88
88
  /**
89
- * Probe the index for `code`'s prefix. Two abstention gates, in order: the index's country must match the query's
89
+ * Probe the index for `code`'s prefix. Two abstention checks, in order: the index's country must match the query's
90
90
  * country scope (or the scope is absent), and the derivation law must yield a prefix the index carries. Returns null to
91
91
  * abstain — never throws, never guesses.
92
92
  */
@@ -98,4 +98,4 @@ export declare function probePostcodePrefix(code: string, index: PostcodePrefixI
98
98
  * half).
99
99
  */
100
100
  export declare function postcodePrefixResolvedPlace(prefix: string, node: PostcodePrefixNode, index: PostcodePrefixIndexLike): CoordinateOptionalPlace;
101
- //# sourceMappingURL=postcode-prefix.d.ts.map
101
+ //# sourceMappingURL=prefix.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prefix.d.ts","sourceRoot":"","sources":["../../lib/postcode/prefix.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwDG;AAEH,OAAO,KAAK,EAAE,uBAAuB,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAA;AAE1G;;;;;;GAMG;AACH,MAAM,MAAM,uBAAuB,GAAG,IAAI,CAAC,aAAa,EAAE,KAAK,GAAG,KAAK,CAAC,GAAG;IAAE,GAAG,CAAC,EAAE,MAAM,CAAC;IAAC,GAAG,CAAC,EAAE,MAAM,CAAA;CAAE,CAAA;AAazG;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAkBlF;AAED;;GAEG;AACH,MAAM,WAAW,yBAAyB;IACzC;;OAEG;IACH,MAAM,EAAE,MAAM,CAAA;IACd;;OAEG;IACH,IAAI,EAAE,kBAAkB,CAAA;CACxB;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAClC,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,uBAAuB,EAC9B,YAAY,CAAC,EAAE,MAAM,GACnB,yBAAyB,GAAG,IAAI,CAclC;AAED;;;;;GAKG;AACH,wBAAgB,2BAA2B,CAC1C,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,kBAAkB,EACxB,KAAK,EAAE,uBAAuB,GAC5B,uBAAuB,CAYzB"}
@@ -29,7 +29,7 @@
29
29
  * acquisition) — the branch exists so the law is tested before the data.
30
30
  * - **Anything else** — abstain (null).
31
31
  *
32
- * ## The probe's country gate
32
+ * ## The probe's country restriction
33
33
  *
34
34
  * The index is country-specific EVIDENCE: it is only probed when its `country` matches the
35
35
  * query's country scope (or the scope is absent). A GB index must not speak under a US scope —
@@ -77,8 +77,9 @@ export function derivePostcodePrefix(code, country) {
77
77
  // "BT93GS" → "BT9"). Exactly 3 — never a greedy regex, the build-side twin is `outwardOf`.
78
78
  case "GB":
79
79
  return compact.length >= MIN_GB_OUTWARD_CODE_LENGTH ? compact.slice(0, -3) : null;
80
- // The 3-digit section ("94043" → "940"). No US artifact ships yet (B3-4 is ZCTA acquisition);
81
- // the law is tested ahead of the data.
80
+ // The 3-digit sectional centre ("94043" → "940"). Deliberately looser than the build side, which
81
+ // requires a real ZIP shape: a probe for something that is not a code simply misses, and a reader
82
+ // that re-derived the writer's validation would be a second copy of it.
82
83
  case "US":
83
84
  return compact.length >= MIN_US_SECTION_CODE_LENGTH ? compact.slice(0, 3) : null;
84
85
  default:
@@ -86,13 +87,13 @@ export function derivePostcodePrefix(code, country) {
86
87
  }
87
88
  }
88
89
  /**
89
- * Probe the index for `code`'s prefix. Two abstention gates, in order: the index's country must match the query's
90
+ * Probe the index for `code`'s prefix. Two abstention checks, in order: the index's country must match the query's
90
91
  * country scope (or the scope is absent), and the derivation law must yield a prefix the index carries. Returns null to
91
92
  * abstain — never throws, never guesses.
92
93
  */
93
94
  export function probePostcodePrefix(code, index, queryCountry) {
94
95
  const indexCountry = index.country?.toUpperCase();
95
- // Country gate: the index is evidence FOR its own country only. A GB index under a US scope stays
96
+ // Country check: the index is evidence FOR its own country only. A GB index under a US scope stays
96
97
  // silent — the walk's country filter is the caller's declared universe.
97
98
  if (queryCountry && indexCountry && queryCountry.toUpperCase() !== indexCountry)
98
99
  return null;
@@ -121,4 +122,4 @@ export function postcodePrefixResolvedPlace(prefix, node, index) {
121
122
  exactMatch: false,
122
123
  };
123
124
  }
124
- //# sourceMappingURL=postcode-prefix.js.map
125
+ //# sourceMappingURL=prefix.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prefix.js","sourceRoot":"","sources":["../../lib/postcode/prefix.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwDG;AAaH;;;GAGG;AACH,MAAM,0BAA0B,GAAG,CAAC,CAAA;AAEpC;;GAEG;AACH,MAAM,0BAA0B,GAAG,CAAC,CAAA;AAEpC;;;GAGG;AACH,MAAM,UAAU,oBAAoB,CAAC,IAAY,EAAE,OAAgB;IAClE,IAAI,CAAC,IAAI,IAAI,CAAC,OAAO;QAAE,OAAO,IAAI,CAAA;IAElC,MAAM,OAAO,GAAG,IAAI,CAAC,UAAU,CAAC,MAAM,EAAE,EAAE,CAAC,CAAA;IAE3C,QAAQ,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC;QAC/B,0FAA0F;QAC1F,2FAA2F;QAC3F,KAAK,IAAI;YACR,OAAO,OAAO,CAAC,MAAM,IAAI,0BAA0B,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAA;QAClF,iGAAiG;QACjG,kGAAkG;QAClG,wEAAwE;QACxE,KAAK,IAAI;YACR,OAAO,OAAO,CAAC,MAAM,IAAI,0BAA0B,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAA;QACjF;YACC,OAAO,IAAI,CAAA;IACb,CAAC;AACF,CAAC;AAgBD;;;;GAIG;AACH,MAAM,UAAU,mBAAmB,CAClC,IAAY,EACZ,KAA8B,EAC9B,YAAqB;IAErB,MAAM,YAAY,GAAG,KAAK,CAAC,OAAO,EAAE,WAAW,EAAE,CAAA;IAEjD,mGAAmG;IACnG,wEAAwE;IACxE,IAAI,YAAY,IAAI,YAAY,IAAI,YAAY,CAAC,WAAW,EAAE,KAAK,YAAY;QAAE,OAAO,IAAI,CAAA;IAE5F,MAAM,MAAM,GAAG,oBAAoB,CAAC,IAAI,EAAE,YAAY,CAAC,CAAA;IAEvD,IAAI,CAAC,MAAM;QAAE,OAAO,IAAI,CAAA;IAExB,MAAM,IAAI,GAAG,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,CAAA;IAEhC,OAAO,IAAI,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,CAAA;AACtC,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,2BAA2B,CAC1C,MAAc,EACd,IAAwB,EACxB,KAA8B;IAE9B,OAAO;QACN,EAAE,EAAE,CAAC;QACL,IAAI,EAAE,MAAM;QACZ,SAAS,EAAE,YAAY;QACvB,iGAAiG;QACjG,wCAAwC;QACxC,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE;QAC3C,GAAG,CAAC,IAAI,CAAC,GAAG,KAAK,SAAS,IAAI,IAAI,CAAC,GAAG,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC7F,KAAK,EAAE,CAAC;QACR,UAAU,EAAE,KAAK;KACjB,CAAA;AACF,CAAC"}
@@ -69,11 +69,11 @@
69
69
  * CONFIRMS it instead.
70
70
  *
71
71
  * **D-rule: opt-in behind `ResolveOpts.postcodeShapeCoherence`, default-OFF.** Demotion is the
72
- * failure mode with teeth, so a default-on promotion needs the full pre-registered gate (B1-1
72
+ * failure mode with teeth, so a default-on promotion needs the full pre-registered eval (B1-1
73
73
  * byte-stability, B1-2 exclusion ≥90% with the correct sibling tag surviving, B1-3 confound ≤2%
74
74
  * false exclusions; kill on any B1-3 δ).
75
75
  */
76
- import type { AddressNode } from "@mailwoman/core/decoder";
76
+ import { type AddressNode } from "@mailwoman/core/decoder";
77
77
  /**
78
78
  * The pass's per-tree verdict — the caller (and the B1 board tests) can see exactly which spans were confirmed,
79
79
  * excluded, or abstained, and which confirmed span's narrowed systems should bound the country-scope pass.
@@ -110,4 +110,4 @@ export declare function applyPostcodeShapeCoherence(roots: readonly AddressNode[
110
110
  * skip these, which is what "strip the postcode tag's contribution" means for a span that keeps its tag.
111
111
  */
112
112
  export declare function isShapeExcludedPostcode(node: AddressNode): boolean;
113
- //# sourceMappingURL=postcode-shape-coherence.d.ts.map
113
+ //# sourceMappingURL=shape-coherence.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shape-coherence.d.ts","sourceRoot":"","sources":["../../lib/postcode/shape-coherence.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0EG;AAKH,OAAO,EAA2B,KAAK,WAAW,EAAE,MAAM,yBAAyB,CAAA;AAWnF;;;GAGG;AACH,MAAM,WAAW,oBAAoB;IACpC;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,EAAE,CAAA;IACpB;;OAEG;IACH,SAAS,EAAE,MAAM,EAAE,CAAA;IACnB;;OAEG;IACH,QAAQ,EAAE,MAAM,EAAE,CAAA;IAClB;;OAEG;IACH,SAAS,EAAE,MAAM,EAAE,CAAA;CACnB;AA+CD;;;;GAIG;AACH,wBAAgB,2BAA2B,CAAC,KAAK,EAAE,SAAS,WAAW,EAAE,GAAG,oBAAoB,CA2D/F;AAED;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,WAAW,GAAG,OAAO,CAElE"}
@@ -69,20 +69,22 @@
69
69
  * CONFIRMS it instead.
70
70
  *
71
71
  * **D-rule: opt-in behind `ResolveOpts.postcodeShapeCoherence`, default-OFF.** Demotion is the
72
- * failure mode with teeth, so a default-on promotion needs the full pre-registered gate (B1-1
72
+ * failure mode with teeth, so a default-on promotion needs the full pre-registered eval (B1-1
73
73
  * byte-stability, B1-2 exclusion ≥90% with the correct sibling tag surviving, B1-3 confound ≤2%
74
74
  * false exclusions; kill on any B1-3 δ).
75
75
  */
76
- import { candidateSystemsForPostcode } from "@mailwoman/codex";
76
+ import { candidateSystemsForPostcode, SYSTEM_CODES } from "@mailwoman/codex";
77
77
  import { matchCountry, matchSubdivision } from "@mailwoman/codex/country";
78
78
  import { isUSStateAbbreviation } from "@mailwoman/codex/us";
79
+ import { collectNodes, walkNodes } from "@mailwoman/core/decoder";
79
80
  /**
80
81
  * The codex address systems a sibling signal can speak for — the universe `candidateSystemsForPostcode` can return, in
81
82
  * the upper-case ISO form this module's signals are emitted in (`SystemCode` itself is lower-case). Signals from
82
83
  * countries with no codex slice are filtered out BEFORE the intersection test, so a slice-less country can never
83
- * manufacture an empty intersection (the false-exclusion trap; see the header).
84
+ * manufacture an empty intersection (the false-exclusion trap; see the header). Derived from codex's own list so a
85
+ * system added there is admitted here in the same change.
84
86
  */
85
- const SYSTEM_UNIVERSE = new Set(["US", "DE", "FR", "CA", "GB", "JP", "AU", "NZ"]);
87
+ const SYSTEM_UNIVERSE = new Set(SYSTEM_CODES.map((system) => system.toUpperCase()));
86
88
  /**
87
89
  * Collect the sibling country signals: the country node (territory-mapped), the region node (`matchSubdivision` +
88
90
  * `country_hint`), each filtered to the codex SystemCode universe. The tree is walked once for ALL postcode spans —
@@ -90,10 +92,7 @@ const SYSTEM_UNIVERSE = new Set(["US", "DE", "FR", "CA", "GB", "JP", "AU", "NZ"]
90
92
  */
91
93
  function collectSiblingSystems(roots) {
92
94
  const out = new Set();
93
- const stack = [...roots];
94
- while (stack.length) {
95
- const n = stack.pop();
96
- stack.push(...n.children);
95
+ for (const n of walkNodes(roots)) {
97
96
  if (n.tag === "country") {
98
97
  const matched = matchCountry(n.value);
99
98
  if (!matched)
@@ -109,7 +108,7 @@ function collectSiblingSystems(roots) {
109
108
  if (n.tag === "region") {
110
109
  // (a) The region's value as a subdivision ("CA" → US, "ON" → CA — the US-wins tiebreak for
111
110
  // "CA" is matchSubdivision's own). (b) The `country_hint` stamp annotateUSRegions writes on
112
- // 2-letter US state abbreviations — the same evidence via the pipeline's other seam.
111
+ // 2-letter US state abbreviations — the same evidence via the pipeline's other path.
113
112
  const sub = matchSubdivision(n.value);
114
113
  if (sub && SYSTEM_UNIVERSE.has(sub.country.toUpperCase())) {
115
114
  out.add(sub.country.toUpperCase());
@@ -129,17 +128,9 @@ function collectSiblingSystems(roots) {
129
128
  */
130
129
  export function applyPostcodeShapeCoherence(roots) {
131
130
  const verdict = { confirmed: [], excluded: [], abstained: [] };
132
- // The postcode spans in tree order — the same DFS `firstPostcodeValue` uses, so the verdict's
131
+ // The postcode spans in document order — the same walk `firstPostcodeValue` uses, so the verdict's
133
132
  // "first confirmed" is the node `state.postcode` will read.
134
- const postcodes = [];
135
- const stack = [...roots];
136
- while (stack.length) {
137
- const n = stack.pop();
138
- if (n.tag === "postcode" && n.value.trim().length) {
139
- postcodes.push(n);
140
- }
141
- stack.push(...n.children);
142
- }
133
+ const postcodes = collectNodes(roots, (n) => n.tag === "postcode" && n.value.trim().length > 0);
143
134
  if (!postcodes.length)
144
135
  return verdict;
145
136
  const siblingSystems = collectSiblingSystems(roots);
@@ -190,4 +181,4 @@ export function applyPostcodeShapeCoherence(roots) {
190
181
  export function isShapeExcludedPostcode(node) {
191
182
  return node.tag === "postcode" && node.metadata?.["postcode_shape_excluded"] === true;
192
183
  }
193
- //# sourceMappingURL=postcode-shape-coherence.js.map
184
+ //# sourceMappingURL=shape-coherence.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shape-coherence.js","sourceRoot":"","sources":["../../lib/postcode/shape-coherence.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;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