@mailwoman/core 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.
Files changed (96) hide show
  1. package/coarse-placer/tools/build-dataset.ts +2 -2
  2. package/coarse-placer/tools/build-outlier-exposure.ts +2 -2
  3. package/coarse-placer/tools/build-outlier-latin.ts +2 -2
  4. package/coarse-placer/tools/build-outlier-oa.ts +2 -2
  5. package/coarse-placer/tools/eval-latin-offmap.ts +2 -4
  6. package/coarse-placer/tools/eval-openset.ts +2 -3
  7. package/coarse-placer/tools/eval-quant-compare.ts +2 -3
  8. package/coarse-placer/tools/eval.ts +2 -3
  9. package/coarse-placer/tools/probe-frontier.ts +2 -4
  10. package/coarse-placer/tools/quantize.ts +3 -2
  11. package/coarse-placer/tools/train.ts +1 -2
  12. package/decoder/build-tree.ts +19 -0
  13. package/env/schema.ts +9 -0
  14. package/fs/zip.ts +297 -0
  15. package/out/coarse-placer/tools/build-dataset.js +1 -2
  16. package/out/coarse-placer/tools/build-dataset.js.map +1 -1
  17. package/out/coarse-placer/tools/build-outlier-exposure.js +1 -2
  18. package/out/coarse-placer/tools/build-outlier-exposure.js.map +1 -1
  19. package/out/coarse-placer/tools/build-outlier-latin.js +1 -2
  20. package/out/coarse-placer/tools/build-outlier-latin.js.map +1 -1
  21. package/out/coarse-placer/tools/build-outlier-oa.js +1 -2
  22. package/out/coarse-placer/tools/build-outlier-oa.js.map +1 -1
  23. package/out/coarse-placer/tools/eval-latin-offmap.d.ts.map +1 -1
  24. package/out/coarse-placer/tools/eval-latin-offmap.js +2 -4
  25. package/out/coarse-placer/tools/eval-latin-offmap.js.map +1 -1
  26. package/out/coarse-placer/tools/eval-openset.d.ts.map +1 -1
  27. package/out/coarse-placer/tools/eval-openset.js +2 -3
  28. package/out/coarse-placer/tools/eval-openset.js.map +1 -1
  29. package/out/coarse-placer/tools/eval-quant-compare.d.ts.map +1 -1
  30. package/out/coarse-placer/tools/eval-quant-compare.js +2 -3
  31. package/out/coarse-placer/tools/eval-quant-compare.js.map +1 -1
  32. package/out/coarse-placer/tools/eval.d.ts.map +1 -1
  33. package/out/coarse-placer/tools/eval.js +2 -3
  34. package/out/coarse-placer/tools/eval.js.map +1 -1
  35. package/out/coarse-placer/tools/probe-frontier.d.ts.map +1 -1
  36. package/out/coarse-placer/tools/probe-frontier.js +2 -4
  37. package/out/coarse-placer/tools/probe-frontier.js.map +1 -1
  38. package/out/coarse-placer/tools/quantize.d.ts.map +1 -1
  39. package/out/coarse-placer/tools/quantize.js +2 -2
  40. package/out/coarse-placer/tools/quantize.js.map +1 -1
  41. package/out/coarse-placer/tools/train.d.ts.map +1 -1
  42. package/out/coarse-placer/tools/train.js +1 -2
  43. package/out/coarse-placer/tools/train.js.map +1 -1
  44. package/out/decoder/build-tree.d.ts.map +1 -1
  45. package/out/decoder/build-tree.js +17 -0
  46. package/out/decoder/build-tree.js.map +1 -1
  47. package/out/env/index.d.ts +3 -0
  48. package/out/env/index.d.ts.map +1 -1
  49. package/out/env/schema.d.ts +3 -0
  50. package/out/env/schema.d.ts.map +1 -1
  51. package/out/env/schema.js +8 -0
  52. package/out/env/schema.js.map +1 -1
  53. package/out/fs/zip.d.ts +116 -0
  54. package/out/fs/zip.d.ts.map +1 -0
  55. package/out/fs/zip.js +216 -0
  56. package/out/fs/zip.js.map +1 -0
  57. package/out/pipeline/index.d.ts +2 -2
  58. package/out/pipeline/index.d.ts.map +1 -1
  59. package/out/pipeline/index.js +1 -1
  60. package/out/pipeline/index.js.map +1 -1
  61. package/out/pipeline/runtime-pipeline.d.ts.map +1 -1
  62. package/out/pipeline/runtime-pipeline.js +17 -1
  63. package/out/pipeline/runtime-pipeline.js.map +1 -1
  64. package/out/pipeline/types.d.ts +115 -2
  65. package/out/pipeline/types.d.ts.map +1 -1
  66. package/out/pipeline/types.js +30 -0
  67. package/out/pipeline/types.js.map +1 -1
  68. package/out/resolver/index.d.ts +3 -1
  69. package/out/resolver/index.d.ts.map +1 -1
  70. package/out/resolver/index.js +1 -0
  71. package/out/resolver/index.js.map +1 -1
  72. package/out/resolver/referential.d.ts +73 -0
  73. package/out/resolver/referential.d.ts.map +1 -0
  74. package/out/resolver/referential.js +71 -0
  75. package/out/resolver/referential.js.map +1 -0
  76. package/out/resolver/types.d.ts +163 -0
  77. package/out/resolver/types.d.ts.map +1 -1
  78. package/out/resolver/types.js.map +1 -1
  79. package/out/resources/whosonfirst/placetypes/Placetype.d.ts.map +1 -1
  80. package/out/resources/whosonfirst/placetypes/Placetype.js +2 -2
  81. package/out/resources/whosonfirst/placetypes/Placetype.js.map +1 -1
  82. package/out/resources/whosonfirst/sharded-repo.js +1 -1
  83. package/out/resources/whosonfirst/sharded-repo.js.map +1 -1
  84. package/out/scripting/utils/index.d.ts.map +1 -1
  85. package/out/scripting/utils/index.js +2 -2
  86. package/out/scripting/utils/index.js.map +1 -1
  87. package/package.json +16 -5
  88. package/pipeline/index.ts +2 -1
  89. package/pipeline/runtime-pipeline.ts +19 -1
  90. package/pipeline/types.ts +117 -1
  91. package/resolver/index.ts +13 -0
  92. package/resolver/referential.ts +84 -0
  93. package/resolver/types.ts +166 -0
  94. package/resources/whosonfirst/placetypes/Placetype.ts +2 -2
  95. package/resources/whosonfirst/sharded-repo.ts +1 -1
  96. package/scripting/utils/index.ts +2 -3
package/resolver/types.ts CHANGED
@@ -65,6 +65,41 @@ export interface ResolvedPlace {
65
65
  * to score-based ordering.
66
66
  */
67
67
  prominence?: number
68
+ /**
69
+ * REFERENTIAL likelihood in [0, 1] — population-anchored, the named form of the key namesake ranking has always used
70
+ * (ROAD_TO_V9 §2, ratified 2026-08-06: "the importance of a knowledge-base article is not the probability that this
71
+ * is the place the user means"). Absent when the backend has no population for the place.
72
+ */
73
+ referential?: number
74
+ /**
75
+ * STRICT encyclopedia-evidence importance in [0, 1] — CARRIED FOR CONSUMERS, NEVER RANKED ON.
76
+ *
77
+ * RESERVED SLOT: it awaits a strict-channel source. Only a backend reading a post-split `place_importance` table can
78
+ * populate it, and today the FTS backend's clauses emit NULL for everything (no shipped admin DB carries the split
79
+ * columns), so nothing produces it and nothing consumes it. The BLENDED prior the ranking reads is
80
+ * {@link ResolvedPlace.importance} — keep the two apart.
81
+ *
82
+ * Ranking on this channel is forbidden even once populated. The canonical reason is Saint-Denis: the
83
+ * Seine-Saint-Denis suburb (pop 96,128) scores 0.1173 while the Aude hamlet (pop 418) scores 0.5683, so ranking on it
84
+ * inverts the answer every user means.
85
+ *
86
+ * Absent means "no encyclopedia entry" OR "this gazetteer predates the two-score split" — both absence, neither 0.
87
+ */
88
+ encyclopedic?: number
89
+ /**
90
+ * BLENDED global toponym prior in [0, 1] (#28) — the fame key the bare-toponym class is decided on.
91
+ *
92
+ * The value is the score source's legacy blended importance: the concordance's encyclopedia-derived channel where a
93
+ * concordance matched, a population-derived proxy everywhere else. The blend is deliberate — it is the only scale on
94
+ * which EVERY bearer of a name is scored comparably (the strict channel reaches eleven countries and is blind on
95
+ * CA/AU/RU, exactly the homonym contests the prior exists to settle; see `candidate-schema.ts` →
96
+ * `CandidateTable.importance`). Consumed by `rankByImportance` (`resolver/toponym-prior.ts`), a soft tier-safe
97
+ * re-rank, never a gate.
98
+ *
99
+ * Absent means UNMEASURED — the score source had no row, the join refused it, or the artifact predates the column —
100
+ * and an unmeasured candidate holds the rank population gave it (meaning-of-zero: never fill a 0 in).
101
+ */
102
+ importance?: number
68
103
  /**
69
104
  * Set by the backend when this candidate is an EXACT name/alias match for the query (vs a partial token match). The
70
105
  * postcode-anchor re-rank (#369) uses it as the PRIMARY key so a country posterior can pin the country WITHOUT
@@ -202,6 +237,13 @@ export interface ResolverBackend {
202
237
  * recovering localities the name-match alone misses. Backends without postcode support ignore it.
203
238
  */
204
239
  postcode?: string
240
+ /**
241
+ * Postcode-containment coherence (#31, Mechanism 2) — when set, a coordinate-first backend may re-rank locality
242
+ * candidates by distance to the sibling postcode's own centroid (bounded by a 25 km containment gate) instead of
243
+ * answering blind population-first. Opt-in, strictly beneath the #741 exact `(name_key, postcode)` probe; backends
244
+ * without postcode support ignore it.
245
+ */
246
+ postcodeContainmentCoherence?: boolean
205
247
  /**
206
248
  * Proximity-bias points — a SOFT prominence re-rank; backends without support ignore it.
207
249
  */
@@ -374,6 +416,42 @@ export interface StreetCentroidLookup {
374
416
  find(query: { street: string; postcode?: string; locality?: string }): StreetCentroidHit | null
375
417
  }
376
418
 
419
+ /**
420
+ * One admin-ancestry entry a PFX1 node asserts (coarsest-first: country → constituent country → district).
421
+ */
422
+ export interface PostcodePrefixAncestor {
423
+ placetype: string
424
+ wofID: number
425
+ name: string
426
+ }
427
+
428
+ /**
429
+ * A PFX1 postcode-prefix node — the partial-code prior's payload ({@link ResolveOpts.postcodePrefixPrior}, #31
430
+ * Mechanism 3). The coordinate is OPTIONAL and its absence is meaningful: an ancestry-only tier (NI's 80 BT districts)
431
+ * carries `ancestors` and no `lat`/`lon` — representable as absence, never as `0,0` (the meaning-of-zero rule).
432
+ * `radiusP95Km` is mandatory whenever a coordinate is present (M-3's receipt: a 1-digit US band and a GB outward code
433
+ * are both "a prefix with a centroid" and differ by 200×).
434
+ */
435
+ export interface PostcodePrefixNode {
436
+ prefix: string
437
+ ancestors: readonly PostcodePrefixAncestor[]
438
+ lat?: number
439
+ lon?: number
440
+ radiusP95Km?: number
441
+ unitCount: number
442
+ }
443
+
444
+ /**
445
+ * The PFX1 index the resolver probes — minimal, structural (`probe` + optional `country`), so `@mailwoman/resolver`
446
+ * consumes an index built in `@mailwoman/neural` without depending on it (B3-5: the partial-code prior touches zero
447
+ * model inputs). `country` is the ISO-3166 alpha-2 the index was built for (upper-case); the resolver only probes an
448
+ * index whose country matches the query's country scope.
449
+ */
450
+ export interface PostcodePrefixIndexLike {
451
+ probe(prefix: string): PostcodePrefixNode | null
452
+ readonly country?: string
453
+ }
454
+
377
455
  export interface ResolveOpts {
378
456
  /**
379
457
  * Hard cap on how many backend lookups one tree may issue. Default 10. Prevents a tree with dozens of candidate nodes
@@ -440,6 +518,39 @@ export interface ResolveOpts {
440
518
  * Only consulted when `anchorPosterior` is set.
441
519
  */
442
520
  anchorWeight?: number
521
+ /**
522
+ * #27 — the LOCALE's country as a SOFT ranking prior on the admin walk, for the one query shape that has no other
523
+ * country signal: a bare toponym.
524
+ *
525
+ * `--locale en-GB "Whitby"` and `--default-country GB "Whitby"` should not disagree, and they do: the second is gold
526
+ * and the first answers Whitby, Ontario, 5,508 km away. The #912 guard in the CLI is why — it drops the
527
+ * locale-inferred country entirely for a bare-locality tree, because as a HARD filter that country is a disaster
528
+ * (`--locale en-US "Zürich"` hard-scoped to US returns Zurich, Kansas, population 81). Dropping it is the right call
529
+ * for a filter and the wrong call for a prior, and this field is the third option: `rankByCountryPrior`
530
+ * (`resolver/toponym-prior.ts`) adds {@link localeCountryPriorWeight} to an in-country candidate's prominence, within
531
+ * the exact tier, never as a filter.
532
+ *
533
+ * **Undefined by default, and the CLI leaves it undefined** — this is an OPT-IN lever (`--locale-country-prior`), not
534
+ * a shipped default, and the reason is measured rather than cautious. In log10-population units the weight needed to
535
+ * flip the four bare GB panel rows is ≥ 0.99 (Whitby CA 5.11 over GB 4.12), and the weight that leaves the en-US
536
+ * board intact is < 0.07 (Cambridge CA 5.14 over US 5.07). The two intervals are disjoint, and they interleave:
537
+ * `Athens` (GR over US, gap 0.38) and `Cambridge` (0.07) sit BELOW `Warwick` (0.41) and `Epping` (0.41), so no
538
+ * threshold, margin or rank rule separates the class either. Population plus a locale cannot answer this question.
539
+ * The key that can is `importance` — the blended global toponym prior, which ranks all four the right way round and
540
+ * whose consumer (`rankByImportance`) is already wired here; the #28 candidate build produces it. See
541
+ * `scratchpad/resolver-plumbing-receipt-2026-08-10.md`.
542
+ *
543
+ * Ignored whenever a {@link defaultCountry} or an {@link anchorPosterior} is in force: a hard scope makes the prior a
544
+ * no-op by construction, and a posterior derived from the address's own postcode is EVIDENCE, which outranks a guess
545
+ * about where the user is sitting.
546
+ */
547
+ localeCountryPrior?: string
548
+ /**
549
+ * Weight of {@link localeCountryPrior}, in log10(population + 1) — the candidate backend's own `prominence` scale.
550
+ * Default `DEFAULT_COUNTRY_PRIOR_WEIGHT` (2): "the in-country place may be up to 100x smaller and still win". Only
551
+ * consulted when `localeCountryPrior` is set.
552
+ */
553
+ localeCountryPriorWeight?: number
443
554
  /**
444
555
  * #743/#194 — a CONFIDENT coarse-placer country applied as a HARD candidate filter (`query.country`), not the soft
445
556
  * {@link anchorPosterior} boost. This collapses the off-continent tail for LOW-population places the soft prior can't
@@ -626,6 +737,61 @@ export interface ResolveOpts {
626
737
  * returned identical verdicts at 15, 25 and 50, so the pass is not gate-tuned).
627
738
  */
628
739
  postcodeCountryCoherenceGateKm?: number
740
+ /**
741
+ * Postcode-shape coherence (#31, Mechanism 1, `resolver/postcode-shape-coherence.ts`) — shape as CONFIDENCE and
742
+ * EXCLUSION, downstream of the siblings. The decoder sometimes tags a HOUSE NUMBER as `postcode` when its digits form
743
+ * a foreign postcode shape ("1200" in a Longmont CO address is accepted only by the AU/NZ 4-digit shape while every
744
+ * sibling placetype says US). This pre-walk pass intersects each postcode span's codex candidate systems with the
745
+ * systems the tree's country / region / `country_hint` siblings assert: a non-empty intersection CONFIRMS the span
746
+ * (additive `postcode_shape_systems` stamp, byte-identical resolution); an empty intersection with confident siblings
747
+ * EXCLUDES it (a digit-only span is demoted to `house_number`, a letter-bearing one keeps its tag with a
748
+ * `postcode_shape_excluded` stamp — either way the span's contribution to the resolve is stripped); no confident
749
+ * siblings ABSTAIN. `defaultCountry` is never evidence (B1-3's confound: "Sydney NSW 2000, Australia" reached with a
750
+ * US default must not have its 2000 excluded — that row is exactly what {@link postcodeCountryCoherence} rescues).
751
+ * Confirmed spans narrow the country-scope pass's candidate list to the intersection (a pure subset, safe).
752
+ *
753
+ * **Default OFF** (D-rule: demotion is the failure mode with teeth — a default-on promotion needs the full B1 gate
754
+ * set from `docs/superpowers/plans/2026-08-05-postcode-structure-arc.md`: B1-1 byte-stability, B1-2 exclusion board
755
+ * ≥90% with the correct sibling tag surviving, B1-3 confound ≤2% false exclusions, kill on any δ).
756
+ */
757
+ postcodeShapeCoherence?: boolean
758
+ /**
759
+ * Postcode-containment coherence (#31, Mechanism 2) — the reverse arrow, generalized. When a locality-wanting query
760
+ * carries a postcode and the #741 exact `(name_key, postcode)` probe misses, a coordinate-first backend resolves the
761
+ * postcode's centroid once and re-ranks the name candidates by distance to it, bounded by a 25 km containment gate —
762
+ * "Paris TX 75460" and "Paris 75001" differ by which candidate the postcode is near, and the population ranking
763
+ * cannot see that. Strictly beneath the #741 short-circuit (B2-1: byte-identical wherever the fast path fires); no
764
+ * in-gate candidate → unchanged (B2-2's postcode-removed arm). Rides `FindPlaceQuery.postcodeContainmentCoherence` to
765
+ * the backend.
766
+ *
767
+ * **Default OFF.** The promotion decision must measure it JOINTLY with {@link postcodeConsistency} (B2-3: the arms
768
+ * agree on ≥98%), because this rung partially subsumes #370 — the compliant outcome may be that mechanism 2 replaces
769
+ * it rather than joining it. B2-4: one postcode lookup per locality miss, ≤15% p95 latency.
770
+ */
771
+ postcodeContainmentCoherence?: boolean
772
+ /**
773
+ * Postcode-prefix prior (#31, Mechanism 3) — the partial-code prior for postcodes the full-code gazetteer does not
774
+ * carry (#1480's abstention, e.g. a BT unit with no permissive source behind it). When a `postalcode` lookup misses
775
+ * AND a {@link postcodePrefixIndex} for the query's country is supplied, derive the code's prefix (GB: outward — the
776
+ * compact form minus its trailing 3 unit chars; US: the first 3 digits) and probe the index. A hit resolves the node
777
+ * from the prefix's centroid and/or ancestry: `metadata.postcode_prefix`, `postcode_prefix_ancestors` (+
778
+ * `postcode_prefix_radius_p95_km` when the artifact measured one), and `coordinate_source: "postcode_prefix"` only
779
+ * when the node actually carries a coordinate — an ancestry-only tier (NI's 80 BT districts) contributes its DISTRICT
780
+ * and stays coordinate-free (the meaning-of-zero rule; inventing a BT centroid would reproduce the `BT3 9QQ` →
781
+ * Sheffield defect #1480 just fixed).
782
+ *
783
+ * **Default OFF** (D-rule + the PCN1 posture: data + loader + offline probe, no decode wiring; the header ships
784
+ * without `delta` until a calibration measures one). B3-5: the probe touches zero model inputs — the index is a
785
+ * structural type (`PostcodePrefixIndexLike`), injected, never imported from `@mailwoman/neural`.
786
+ */
787
+ postcodePrefixPrior?: boolean
788
+ /**
789
+ * The PFX1 postcode-prefix index to probe when {@link postcodePrefixPrior} is on — injected by the pipeline (loaded
790
+ * from `$MAILWOMAN_DATA_ROOT/postcode-prefix/postcode-prefix-<cc>.bin`), never constructed here. Structural
791
+ * (`PostcodePrefixIndexLike`), so the resolver consumes an index built in `@mailwoman/neural` without depending on it
792
+ * (B3-5).
793
+ */
794
+ postcodePrefixIndex?: PostcodePrefixIndexLike
629
795
  /**
630
796
  * Admin descendant-consistency (#263). When a region resolved but its child locality did NOT — the greedy region pick
631
797
  * (name + population) chose a foreign namesake whose descendants hold no such locality ("Portland, ME" → Messina IT;
@@ -6,12 +6,12 @@
6
6
 
7
7
  import * as fs from "node:fs/promises"
8
8
 
9
+ import { parseJSONStrict } from "@mailwoman/core/objects"
10
+ import { prepareRepositoryDirectories, type RepositorySource } from "@mailwoman/core/resources"
9
11
  import FastGlob from "fast-glob"
10
12
  import type { PathBuilder } from "path-ts"
11
13
  import { parallelMap } from "spliterator"
12
14
 
13
- import { parseJSONStrict } from "../../../objects.ts"
14
- import { prepareRepositoryDirectories, type RepositorySource } from "../../git.ts"
15
15
  import {
16
16
  normalizePlacetypeDefinition,
17
17
  type PlacetypeDefinition,
@@ -13,9 +13,9 @@
13
13
 
14
14
  import { existsSync, readFileSync } from "node:fs"
15
15
 
16
+ import { tryParsingJSON } from "@mailwoman/core/objects"
16
17
  import { resolvePath } from "path-ts"
17
18
 
18
- import { tryParsingJSON } from "../../objects.ts"
19
19
  import type { WOFFeature } from "./placetypes/admin.ts"
20
20
 
21
21
  /**
@@ -1,8 +1,7 @@
1
+ import { ResourceError } from "@mailwoman/core/errors"
2
+ import { ConsoleLogger } from "@mailwoman/core/logging"
1
3
  import { defaultRegistry } from "async-init"
2
4
 
3
- import { ResourceError } from "../../errors/index.ts"
4
- import { ConsoleLogger } from "../../logging/index.ts"
5
-
6
5
  /**
7
6
  * Logs an error that occurred while running a script.
8
7
  */