@mailwoman/resolver 9.0.0 → 9.1.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.
@@ -53,6 +53,32 @@
53
53
  * geographic tie) both return `null`. The mechanism only ever speaks when exactly one country
54
54
  * makes the pair consistent, and only ever when the default country could not.
55
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, and any corroboration at home — the
80
+ * address's own city or its own postcode existing in the default country — stops the pass dead.
81
+ *
56
82
  * ## Evidence
57
83
  *
58
84
  * Prototyped out-of-tree against the live gazetteer over the public `findPlace` surface (2026-08-03):
@@ -82,7 +108,20 @@ import type { ResolvedPlace, ResolverBackend } from "@mailwoman/core/resolver";
82
108
  */
83
109
  export declare const POSTCODE_COUNTRY_COHERENCE_GATE_KM = 25;
84
110
  /**
85
- * A country in which the address's (postcode, locality) pair is geographically consistent.
111
+ * Which half (or halves) of the address bought the verdict — the firing receipt, so a reader of a scoped result can
112
+ * tell a two-sided agreement from a one-sided uniqueness claim without re-deriving it.
113
+ *
114
+ * - `pair` — postcode AND locality both resolve in this country, within the gate. The strongest rung and the only one
115
+ * that existed before #24.
116
+ * - `locality` — the locality names exactly one country in the whole gazetteer, and the postcode names none that
117
+ * contradict it. This is the CH/BE class: the gazetteer carries no Swiss or Belgian postcodes at all, so the pair
118
+ * test can never fire there no matter how good the locality evidence is.
119
+ * - `postcode` — the postcode is held in exactly one country and the locality is in no gazetteer at all. The `Praha 3`
120
+ * class: a municipal district nobody's admin gazetteer names.
121
+ */
122
+ export type PostcodeCountryScopeEvidence = "pair" | "locality" | "postcode";
123
+ /**
124
+ * A country in which the address's own evidence is geographically consistent.
86
125
  */
87
126
  export interface PostcodeCountryScope {
88
127
  /**
@@ -97,18 +136,24 @@ export interface PostcodeCountryScope {
97
136
  * The locality string the verdict was reached on.
98
137
  */
99
138
  locality: string;
139
+ /**
140
+ * Which evidence carried the verdict. See {@link PostcodeCountryScopeEvidence}.
141
+ */
142
+ evidence: PostcodeCountryScopeEvidence;
100
143
  /**
101
144
  * Distance between the resolved postcode point and the nearest same-named locality, in km. Always `<= gateKm`.
145
+ * Present ONLY for the `pair` rung — a single-sided verdict has no two points to measure between, and reporting a `0`
146
+ * there would assert an agreement nobody tested (the meaning-of-zero rule).
102
147
  */
103
- distanceKm: number;
148
+ distanceKm?: number;
104
149
  /**
105
- * The postcode place that anchored the verdict.
150
+ * The postcode place that anchored the verdict. Absent on the `locality` rung.
106
151
  */
107
- postcodePlace: ResolvedPlace;
152
+ postcodePlace?: ResolvedPlace;
108
153
  /**
109
- * The locality place that anchored the verdict.
154
+ * The locality place that anchored the verdict. Absent on the `postcode` rung.
110
155
  */
111
- localityPlace: ResolvedPlace;
156
+ localityPlace?: ResolvedPlace;
112
157
  }
113
158
  export interface PostcodeCountryScopeOpts {
114
159
  /**
@@ -125,6 +170,17 @@ export interface PostcodeCountryScopeOpts {
125
170
  * Consistency gate radius in km. Defaults to {@link POSTCODE_COUNTRY_COHERENCE_GATE_KM}.
126
171
  */
127
172
  gateKm?: number;
173
+ /**
174
+ * Optional narrowing of the SHAPE half of the candidate-country set — the shape-coherence pass's intersection for a
175
+ * CONFIRMED postcode span (see `resolver/postcode-shape-coherence.ts`, #31 Mechanism 1). When present it REPLACES
176
+ * `candidateSystemsForPostcode`'s own list; it is a pure subset of that list (codex systems ∩ confident sibling
177
+ * systems). Upper-case ISO-3166 alpha-2, e.g. `["US"]` for a 5-digit code whose siblings all say US.
178
+ *
179
+ * It narrows the shape half only. Since #24 the candidate set also carries the countries the GAZETTEER holds this
180
+ * postcode in, and that half is not narrowable — it is the artifact reporting what it contains, which is the same
181
+ * class of evidence the pair test itself runs on. Every candidate from either half still has to pass that test.
182
+ */
183
+ candidateSystems?: readonly string[];
128
184
  }
129
185
  /**
130
186
  * The address's locality string: the first `locality` node anywhere in the tree, else the first `dependent_locality`.
@@ -1 +1 @@
1
- {"version":3,"file":"postcode-country-coherence.d.ts","sourceRoot":"","sources":["../postcode-country-coherence.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2EG;AAKH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAA;AAC1D,OAAO,KAAK,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAA;AAG9E;;;GAGG;AACH,eAAO,MAAM,kCAAkC,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ly one country
54
54
  * makes the pair consistent, and only ever when the default country could not.
55
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, and any corroboration at home — the
80
+ * address's own city or its own postcode existing in the default country — stops the pass dead.
81
+ *
56
82
  * ## Evidence
57
83
  *
58
84
  * Prototyped out-of-tree against the live gazetteer over the public `findPlace` surface (2026-08-03):
@@ -106,19 +132,73 @@ export function firstLocalityValue(roots) {
106
132
  return undefined;
107
133
  }
108
134
  /**
109
- * Is the (postcode, locality) pair geographically consistent in `country`? Returns the winning pair and its distance,
110
- * or `null` when the postcode does not resolve there, no same-named locality exists there, or the nearest one is
111
- * outside the gate. Costs one postcode lookup plus (only if that hit) one locality lookup.
135
+ * Over-fetch for the UNSCOPED holder probes (#24). Postcodes are bounded and small — the 2026-08-10 candidate
136
+ * gazetteer's most-shared code carries 12 rows across 8 countries — so 20 sees every bearer and the postcode holder set
137
+ * is COMPLETE, not a sample. Locality names are not bounded that way (`rampur` has 1,096 rows, `bara` spans 42
138
+ * countries), so 30 is a population-first WINDOW: it can only ever hide a country, which turns a "more than one
139
+ * country" abstention into a false "exactly one". The explicit default-country probe below is what closes that gap for
140
+ * the case that matters (the address is domestic after all).
141
+ */
142
+ const POSTCODE_HOLDER_FETCH = 20;
143
+ const LOCALITY_HOLDER_FETCH = 30;
144
+ /**
145
+ * Upper bound on countries the pair rung will test, so a pathological name can't turn one incoherent parse into a
146
+ * hundred lookups. The postcode holder set is ≤8 countries in the measured artifact and the codex shape list is ≤8, so
147
+ * this only ever binds on a gazetteer very unlike today's.
112
148
  */
113
- async function coherenceIn(country, postcode, locality, backend, gateKm) {
114
- let postcodeHits;
149
+ const MAX_CANDIDATE_COUNTRIES = 12;
150
+ /**
151
+ * Countries that hold an exact, coordinate-bearing row for `text` at `placetype`, mapped to their best (first) such
152
+ * row. One UNSCOPED lookup.
153
+ *
154
+ * This is the #24 candidate source, and it replaces a proxy with the thing itself. The pass used to ask codex "which
155
+ * address SYSTEMS could this shape be?" — a model-free shape test over the eight slices codex specifies. That answer is
156
+ * correct and useless for two thirds of Europe: `13000` shapes as `[us, de, fr]`, the gazetteer holds it in exactly one
157
+ * country (CZ), and CZ has no codex slice, so the pass could not propose the only country that could possibly be right.
158
+ * Membership in the gazetteer is positive evidence of the same kind the pair test already runs on, available for one
159
+ * lookup, and it is EXHAUSTIVE for postcodes at the measured cardinality.
160
+ *
161
+ * `exactMatch !== false` is the admission bar: a fuzzy postcode hit is a DIFFERENT postcode (the 2026-08-05 Code-Point
162
+ * lesson — `BT3 9QQ` trigram-matching Sheffield's `S3 9QQ`), and a fuzzy locality hit is evidence about the index, not
163
+ * about the country. Backends that do not stamp the flag leave it undefined and still contribute.
164
+ */
165
+ async function countriesHolding(backend, text, placetype, limit) {
166
+ const out = new Map();
167
+ let hits;
115
168
  try {
116
- postcodeHits = await backend.findPlace({ text: postcode, placetype: "postalcode", country, limit: 3 });
169
+ hits = await backend.findPlace({ text, placetype, limit });
117
170
  }
118
171
  catch {
119
- return null; // a backend hiccup degrades to "no evidence here", never to a crashed resolve
172
+ return out; // a backend hiccup degrades to "no evidence", never to a crashed resolve
173
+ }
174
+ for (const hit of hits) {
175
+ const country = hit.country?.trim().toUpperCase();
176
+ if (!country || hit.exactMatch === false || !hasCoord(hit))
177
+ continue;
178
+ if (!out.has(country)) {
179
+ out.set(country, hit);
180
+ }
181
+ }
182
+ return out;
183
+ }
184
+ /**
185
+ * Is the (postcode, locality) pair geographically consistent in `country`? Returns the winning pair and its distance,
186
+ * 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).
189
+ */
190
+ async function coherenceIn(country, postcode, locality, backend, gateKm, knownPostcodePlace) {
191
+ let postcodePlace = knownPostcodePlace;
192
+ if (!postcodePlace) {
193
+ let postcodeHits;
194
+ try {
195
+ postcodeHits = await backend.findPlace({ text: postcode, placetype: "postalcode", country, limit: 3 });
196
+ }
197
+ catch {
198
+ return null; // a backend hiccup degrades to "no evidence here", never to a crashed resolve
199
+ }
200
+ postcodePlace = postcodeHits.find(hasCoord);
120
201
  }
121
- const postcodePlace = postcodeHits.find(hasCoord);
122
202
  if (!postcodePlace)
123
203
  return null;
124
204
  let localityHits;
@@ -174,22 +254,93 @@ export async function findPostcodeCountryScope(roots, backend, opts) {
174
254
  // no override, and the common domestic path costs two lookups and changes nothing.
175
255
  if (await coherenceIn(defaultCountry, postcode, locality, backend, gateKm))
176
256
  return null;
177
- // 2. The default could not place this pair. Which other country the SHAPE allows can?
178
- const candidates = candidateSystemsForPostcode(postcode)
179
- .map((system) => system.toUpperCase())
180
- .filter((country) => country !== defaultCountry);
181
- if (!candidates.length)
182
- return null;
257
+ // 2. The default could not place this pair. Which countries could? Two sources, unioned:
258
+ //
259
+ // - the SHAPE list (`candidateSystemsForPostcode`, or the shape-coherence pass's narrowing when #31
260
+ // Mechanism 1 supplied one — a pure subset of it), and
261
+ // - the countries the GAZETTEER actually holds this postcode in (#24). Exhaustive at the measured
262
+ // cardinality, and the only source that can name a country codex has no slice for — which was the
263
+ // whole reason the CZ/CH/BE/DK/AT/NL block of the 2026-08-09 panel resolved to US namesakes while
264
+ // their own postcodes sat in the shipped gazetteer within 4 km of truth.
265
+ //
266
+ // The union can only ADD countries, and every added one must still pass the same geometric pair test,
267
+ // so this widens recall without weakening the verdict: a second coherent country turns a verdict into
268
+ // an abstention (safe), never into a wrong answer.
269
+ const pcHolders = await countriesHolding(backend, postcode, "postalcode", POSTCODE_HOLDER_FETCH);
270
+ const shapeSystems = (opts.candidateSystems ?? candidateSystemsForPostcode(postcode).map((system) => system.toUpperCase())).map((country) => country.trim().toUpperCase());
271
+ const candidates = [...new Set([...shapeSystems, ...pcHolders.keys()])]
272
+ .filter((country) => country !== defaultCountry)
273
+ .slice(0, MAX_CANDIDATE_COUNTRIES);
183
274
  const coherent = [];
184
275
  for (const country of candidates) {
185
- const hit = await coherenceIn(country, postcode, locality, backend, gateKm);
276
+ const hit = await coherenceIn(country, postcode, locality, backend, gateKm, pcHolders.get(country));
186
277
  if (hit) {
187
- coherent.push({ country, postcode, locality, ...hit });
278
+ coherent.push({ country, postcode, locality, evidence: "pair", ...hit });
279
+ }
280
+ }
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)
287
+ return null;
288
+ // 4. No country makes the PAIR consistent. On the 2026-08-09 panel that happened 10 times for two opposite
289
+ // reasons, and in both the address's country was never in doubt — only unrepresentable as a pair:
290
+ //
291
+ // - the gazetteer holds no postcodes for the country at all (CH, BE), so the postcode half can never
292
+ // agree with anything no matter how good the locality evidence is; or
293
+ // - the locality is a name no admin gazetteer carries (`Praha 3`, `Praha 9` — municipal districts).
294
+ //
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.
301
+ if (pcHolders.has(defaultCountry))
302
+ 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) {
311
+ const [country, localityPlace] = [...locHolders.entries()][0];
312
+ const ownPostcode = pcHolders.get(country);
313
+ 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 };
188
317
  }
189
318
  }
190
- // 3. Exactly one country makes the pair consistent, or we abstain. Two coherent countries would mean the geometry
191
- // genuinely does not decide, and guessing between them is precisely what this mechanism exists not to do.
192
- return coherent.length === 1 ? coherent[0] : null;
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) {
322
+ const [country, postcodePlace] = [...pcHolders.entries()][0];
323
+ if (country !== defaultCountry) {
324
+ return { country, postcode, locality, evidence: "postcode", postcodePlace };
325
+ }
326
+ }
327
+ return null;
328
+ }
329
+ /**
330
+ * Does `country` hold an exact, coordinate-bearing locality row for `locality`? One scoped lookup — deliberately NOT
331
+ * read off the unscoped holder window, which is population-first and truncated, so a small domestic bearer could fall
332
+ * below its fold and let a foreign scope through.
333
+ */
334
+ async function holdsLocality(backend, locality, country) {
335
+ try {
336
+ const hits = await backend.findPlace({ text: locality, placetype: "locality", country, limit: 3 });
337
+ return hits.some((hit) => hit.exactMatch && hasCoord(hit));
338
+ }
339
+ catch {
340
+ // A backend hiccup must not be read as "the default country has nothing" — that would license a foreign
341
+ // scope on no evidence. Treat it as corroboration and abstain.
342
+ return true;
343
+ }
193
344
  }
194
345
  /**
195
346
  * Stamp the adopted scope onto the tree's postcode and locality nodes, so a consumer can see that the walk's country
@@ -206,7 +357,12 @@ export function stampPostcodeCountryScope(roots, scope) {
206
357
  n.metadata = {
207
358
  ...n.metadata,
208
359
  postcode_country_scope: scope.country,
209
- postcode_country_scope_km: scope.distanceKm,
360
+ // WHICH rung spoke — a two-sided agreement and a one-sided uniqueness claim are different evidence,
361
+ // and a consumer that cannot tell them apart cannot weight them differently.
362
+ postcode_country_scope_evidence: scope.evidence,
363
+ // Only the `pair` rung measured a distance. Writing a 0 for the single-sided rungs would assert an
364
+ // agreement nobody tested.
365
+ ...(scope.distanceKm !== undefined ? { postcode_country_scope_km: scope.distanceKm } : {}),
210
366
  };
211
367
  }
212
368
  }
@@ -1 +1 @@
1
- {"version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AAC;AACF,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,yBAAyB,CAAC,KAA6B,EAAE,KAA2B;IACnG,MAAM,KAAK,GAAkB,CAAC,GAAG,KAAK,CAAC,CAAA;IAEvC,OAAO,KAAK,CAAC,MAAM,EAAE,CAAC;QACrB,MAAM,CAAC,GAAG,KAAK,CAAC,GAAG,EAAG,CAAA;QAEtB,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC,CAAA;QAEzB,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,101 @@
1
+ /**
2
+ * @copyright Sister Software
3
+ * @license AGPL-3.0
4
+ * @author Teffen Ellis, et al.
5
+ *
6
+ * Postcode-prefix prior (#31, Mechanism 3) — the partial-code prior for postcodes the full-code
7
+ * gazetteer does not carry. #1480's abstention is the defect: a BT unit with no permissive source
8
+ * behind it (the NI half of Code-Point Open) misses the gazetteer, and the tree contributes
9
+ * NOTHING for it — no country scope, no district, no coordinate. This module derives the code's
10
+ * PREFIX and probes the PFX1 index (`postcode-prefix-<cc>.bin`), so the resolve "abstains on the
11
+ * UNIT and still contributes its DISTRICT": the node resolves from the prefix's centroid and/or
12
+ * ancestry, whichever the artifact carries.
13
+ *
14
+ * The index is a structural type (`PostcodePrefixIndexLike`, declared in `core/resolver/types.ts`),
15
+ * injected by the pipeline and never imported from `@mailwoman/neural` — B3-5: the probe touches
16
+ * zero model inputs. The loader lives in `@mailwoman/neural/postcode-prefix-index.ts` (PFX1 format:
17
+ * magic, header, dictionary, quantized i16 coordinates, `radiusP95Km`, ancestry); the resolver
18
+ * side only defines the derivation law and the probe.
19
+ *
20
+ * ## The derivation law (per artifact country)
21
+ *
22
+ * - **GB** — the OUTWARD code: the compact (whitespace-stripped) form minus its trailing 3 unit
23
+ * characters ("SW1A 2AA" → "SW1A", "BT9 5GS" → "BT9"). Never a greedy regex — the unit is
24
+ * exactly 3 chars in the compact form, and `outwardOf` in `mailwoman/gazetteer-pipeline/
25
+ * postcode-prefix.ts` is the build-side twin of this law.
26
+ * - **US** — the 3-digit section ("94043" → "940"). M-3 measured 3 digits as the first length
27
+ * where the ZIP prefix stops being free (145 km p95 median); a 5-digit artifact would be the
28
+ * full code the gazetteer already carries. No US artifact ships yet (B3-4 needs a ZCTA
29
+ * acquisition) — the branch exists so the law is tested before the data.
30
+ * - **Anything else** — abstain (null).
31
+ *
32
+ * ## The probe's country gate
33
+ *
34
+ * The index is country-specific EVIDENCE: it is only probed when its `country` matches the
35
+ * query's country scope (or the scope is absent). A GB index must not speak under a US scope —
36
+ * the pipeline passes the locale's index, and the walk's country filter is the caller's declared
37
+ * universe.
38
+ *
39
+ * ## Metadata contract (what the node carries afterward)
40
+ *
41
+ * - `postcode_prefix` — the prefix string that resolved it.
42
+ * - `postcode_prefix_ancestors` — the ancestry the prefix asserts (coarsest-first; GB outward
43
+ * nodes carry country → constituent-country → district).
44
+ * - `postcode_prefix_radius_p95_km` — the artifact's measured p95 radius, when the node carries a
45
+ * coordinate (M-3's receipt: a 1-digit US band and a GB outward code differ by 200×; never read
46
+ * a coordinate without its radius).
47
+ * - `coordinate_source: "postcode_prefix"` — ONLY when the node actually carries a coordinate.
48
+ * The ancestry-only tier (NI's 80 BT districts) stays coordinate-free — the meaning-of-zero
49
+ * rule, and the half that decides B3-3: inventing a BT centroid would reproduce the `BT3 9QQ` →
50
+ * Sheffield defect #1480 just fixed.
51
+ *
52
+ * **D-rule: opt-in behind `ResolveOpts.postcodePrefixPrior`, default-OFF** (the PCN1 posture:
53
+ * data + loader + offline probe, no decode wiring; the header ships without `delta` until a
54
+ * calibration measures one). Bars: B3-2 (≥60% of held-out units within 10 km, zero worse than the
55
+ * abstention arm), B3-3 (NI ≥95% country scope GB + NIR ancestry + correct district named, 0%
56
+ * coordinate), B3-5 (structural — no model inputs touched).
57
+ */
58
+ import type { PostcodePrefixIndexLike, PostcodePrefixNode, ResolvedPlace } from "@mailwoman/core/resolver";
59
+ /**
60
+ * A resolved place that may carry NO coordinate. `ResolvedPlace` requires `lat`/`lon` (every gazetteer row has a value,
61
+ * even the 0,0 unlocated sentinel), and the prefix prior's ancestry-only tier must express absence as `undefined`
62
+ * instead — B3-3: inventing a centroid would reproduce the `BT3 9QQ` → Sheffield defect #1480. `decorateNode` copies
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`.
65
+ */
66
+ export type CoordinateOptionalPlace = Omit<ResolvedPlace, "lat" | "lon"> & {
67
+ lat?: number;
68
+ lon?: number;
69
+ };
70
+ /**
71
+ * Derive the prefix the index is keyed by, per the artifact's own country law. Returns null (abstain) for a country
72
+ * with no derivation law, or a code too short to carry a prefix.
73
+ */
74
+ export declare function derivePostcodePrefix(code: string, country?: string): string | null;
75
+ /**
76
+ * The outcome of a successful prefix probe.
77
+ */
78
+ export interface PostcodePrefixProbeResult {
79
+ /**
80
+ * The prefix string that hit.
81
+ */
82
+ prefix: string;
83
+ /**
84
+ * The index node — its `ancestors` and optional coordinate/radius are the prior's payload.
85
+ */
86
+ node: PostcodePrefixNode;
87
+ }
88
+ /**
89
+ * Probe the index for `code`'s prefix. Two abstention gates, in order: the index's country must match the query's
90
+ * country scope (or the scope is absent), and the derivation law must yield a prefix the index carries. Returns null to
91
+ * abstain — never throws, never guesses.
92
+ */
93
+ export declare function probePostcodePrefix(code: string, index: PostcodePrefixIndexLike, queryCountry?: string): PostcodePrefixProbeResult | null;
94
+ /**
95
+ * Build the synthetic `ResolvedPlace` a prefix hit resolves a `postalcode` node to. `id: 0` — it is NOT a gazetteer row
96
+ * (the same sentinel `applyPostcodeConsistency` uses for its displaced place, resolve.ts) — and the coordinate is
97
+ * present ONLY when the node carries one, so an ancestry-only hit stays coordinate-free by construction (B3-3's 0%
98
+ * half).
99
+ */
100
+ export declare function postcodePrefixResolvedPlace(prefix: string, node: PostcodePrefixNode, index: PostcodePrefixIndexLike): CoordinateOptionalPlace;
101
+ //# sourceMappingURL=postcode-prefix.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"postcode-prefix.d.ts","sourceRoot":"","sources":["../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,CAiBlF;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"}
@@ -0,0 +1,124 @@
1
+ /**
2
+ * @copyright Sister Software
3
+ * @license AGPL-3.0
4
+ * @author Teffen Ellis, et al.
5
+ *
6
+ * Postcode-prefix prior (#31, Mechanism 3) — the partial-code prior for postcodes the full-code
7
+ * gazetteer does not carry. #1480's abstention is the defect: a BT unit with no permissive source
8
+ * behind it (the NI half of Code-Point Open) misses the gazetteer, and the tree contributes
9
+ * NOTHING for it — no country scope, no district, no coordinate. This module derives the code's
10
+ * PREFIX and probes the PFX1 index (`postcode-prefix-<cc>.bin`), so the resolve "abstains on the
11
+ * UNIT and still contributes its DISTRICT": the node resolves from the prefix's centroid and/or
12
+ * ancestry, whichever the artifact carries.
13
+ *
14
+ * The index is a structural type (`PostcodePrefixIndexLike`, declared in `core/resolver/types.ts`),
15
+ * injected by the pipeline and never imported from `@mailwoman/neural` — B3-5: the probe touches
16
+ * zero model inputs. The loader lives in `@mailwoman/neural/postcode-prefix-index.ts` (PFX1 format:
17
+ * magic, header, dictionary, quantized i16 coordinates, `radiusP95Km`, ancestry); the resolver
18
+ * side only defines the derivation law and the probe.
19
+ *
20
+ * ## The derivation law (per artifact country)
21
+ *
22
+ * - **GB** — the OUTWARD code: the compact (whitespace-stripped) form minus its trailing 3 unit
23
+ * characters ("SW1A 2AA" → "SW1A", "BT9 5GS" → "BT9"). Never a greedy regex — the unit is
24
+ * exactly 3 chars in the compact form, and `outwardOf` in `mailwoman/gazetteer-pipeline/
25
+ * postcode-prefix.ts` is the build-side twin of this law.
26
+ * - **US** — the 3-digit section ("94043" → "940"). M-3 measured 3 digits as the first length
27
+ * where the ZIP prefix stops being free (145 km p95 median); a 5-digit artifact would be the
28
+ * full code the gazetteer already carries. No US artifact ships yet (B3-4 needs a ZCTA
29
+ * acquisition) — the branch exists so the law is tested before the data.
30
+ * - **Anything else** — abstain (null).
31
+ *
32
+ * ## The probe's country gate
33
+ *
34
+ * The index is country-specific EVIDENCE: it is only probed when its `country` matches the
35
+ * query's country scope (or the scope is absent). A GB index must not speak under a US scope —
36
+ * the pipeline passes the locale's index, and the walk's country filter is the caller's declared
37
+ * universe.
38
+ *
39
+ * ## Metadata contract (what the node carries afterward)
40
+ *
41
+ * - `postcode_prefix` — the prefix string that resolved it.
42
+ * - `postcode_prefix_ancestors` — the ancestry the prefix asserts (coarsest-first; GB outward
43
+ * nodes carry country → constituent-country → district).
44
+ * - `postcode_prefix_radius_p95_km` — the artifact's measured p95 radius, when the node carries a
45
+ * coordinate (M-3's receipt: a 1-digit US band and a GB outward code differ by 200×; never read
46
+ * a coordinate without its radius).
47
+ * - `coordinate_source: "postcode_prefix"` — ONLY when the node actually carries a coordinate.
48
+ * The ancestry-only tier (NI's 80 BT districts) stays coordinate-free — the meaning-of-zero
49
+ * rule, and the half that decides B3-3: inventing a BT centroid would reproduce the `BT3 9QQ` →
50
+ * Sheffield defect #1480 just fixed.
51
+ *
52
+ * **D-rule: opt-in behind `ResolveOpts.postcodePrefixPrior`, default-OFF** (the PCN1 posture:
53
+ * data + loader + offline probe, no decode wiring; the header ships without `delta` until a
54
+ * calibration measures one). Bars: B3-2 (≥60% of held-out units within 10 km, zero worse than the
55
+ * abstention arm), B3-3 (NI ≥95% country scope GB + NIR ancestry + correct district named, 0%
56
+ * coordinate), B3-5 (structural — no model inputs touched).
57
+ */
58
+ /**
59
+ * The MINIMUM compact code length for a GB outward derivation — a shorter code has no 3-character unit to strip ("B3"
60
+ * is a GB area, not a unit-bearing code).
61
+ */
62
+ const MIN_GB_OUTWARD_CODE_LENGTH = 5;
63
+ /**
64
+ * The MINIMUM code length for a US section derivation.
65
+ */
66
+ const MIN_US_SECTION_CODE_LENGTH = 3;
67
+ /**
68
+ * Derive the prefix the index is keyed by, per the artifact's own country law. Returns null (abstain) for a country
69
+ * with no derivation law, or a code too short to carry a prefix.
70
+ */
71
+ export function derivePostcodePrefix(code, country) {
72
+ if (!code || !country)
73
+ return null;
74
+ const compact = code.replaceAll(/\s+/g, "");
75
+ switch (country.toUpperCase()) {
76
+ // The outward-code law: compact minus the trailing 3 unit characters ("SW1A2AA" → "SW1A",
77
+ // "BT93GS" → "BT9"). Exactly 3 — never a greedy regex, the build-side twin is `outwardOf`.
78
+ case "GB":
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.
82
+ case "US":
83
+ return compact.length >= MIN_US_SECTION_CODE_LENGTH ? compact.slice(0, 3) : null;
84
+ default:
85
+ return null;
86
+ }
87
+ }
88
+ /**
89
+ * Probe the index for `code`'s prefix. Two abstention gates, in order: the index's country must match the query's
90
+ * country scope (or the scope is absent), and the derivation law must yield a prefix the index carries. Returns null to
91
+ * abstain — never throws, never guesses.
92
+ */
93
+ export function probePostcodePrefix(code, index, queryCountry) {
94
+ 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
+ // silent — the walk's country filter is the caller's declared universe.
97
+ if (queryCountry && indexCountry && queryCountry.toUpperCase() !== indexCountry)
98
+ return null;
99
+ const prefix = derivePostcodePrefix(code, indexCountry);
100
+ if (!prefix)
101
+ return null;
102
+ const node = index.probe(prefix);
103
+ return node ? { prefix, node } : null;
104
+ }
105
+ /**
106
+ * Build the synthetic `ResolvedPlace` a prefix hit resolves a `postalcode` node to. `id: 0` — it is NOT a gazetteer row
107
+ * (the same sentinel `applyPostcodeConsistency` uses for its displaced place, resolve.ts) — and the coordinate is
108
+ * present ONLY when the node carries one, so an ancestry-only hit stays coordinate-free by construction (B3-3's 0%
109
+ * half).
110
+ */
111
+ export function postcodePrefixResolvedPlace(prefix, node, index) {
112
+ return {
113
+ id: 0,
114
+ name: prefix,
115
+ placetype: "postalcode",
116
+ // `""` = country unknown — the same empty-string convention the candidate backend uses for a row
117
+ // whose country_id resolves to nothing.
118
+ country: index.country?.toUpperCase() ?? "",
119
+ ...(node.lat !== undefined && node.lon !== undefined ? { lat: node.lat, lon: node.lon } : {}),
120
+ score: 0,
121
+ exactMatch: false,
122
+ };
123
+ }
124
+ //# sourceMappingURL=postcode-prefix.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"postcode-prefix.js","sourceRoot":"","sources":["../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,8FAA8F;QAC9F,uCAAuC;QACvC,KAAK,IAAI;YACR,OAAO,OAAO,CAAC,MAAM,IAAI,0BAA0B,CAAC,CAAC,CAAC,OA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