@htilabs/platform-common-models 0.19.0 → 0.21.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 (59) hide show
  1. package/dist/cvcs/index.cjs +4867 -639
  2. package/dist/cvcs/index.cjs.map +1 -1
  3. package/dist/cvcs/index.d.cts +5145 -609
  4. package/dist/cvcs/index.d.ts +5145 -609
  5. package/dist/cvcs/index.js +4867 -639
  6. package/dist/cvcs/index.js.map +1 -1
  7. package/dist/enums/index.cjs +74 -1
  8. package/dist/enums/index.cjs.map +1 -1
  9. package/dist/enums/index.d.cts +77 -4
  10. package/dist/enums/index.d.ts +77 -4
  11. package/dist/enums/index.js +74 -1
  12. package/dist/enums/index.js.map +1 -1
  13. package/dist/{index-I-DiX9eQ.d.ts → index-CDoqrfc1.d.ts} +1 -1
  14. package/dist/{index-CoVr1jIV.d.cts → index-Zu_mOJRn.d.cts} +1 -1
  15. package/dist/index.cjs +5382 -588
  16. package/dist/index.cjs.map +1 -1
  17. package/dist/index.d.cts +3 -2
  18. package/dist/index.d.ts +3 -2
  19. package/dist/index.js +5371 -588
  20. package/dist/index.js.map +1 -1
  21. package/dist/information-scope/index.cjs +521 -0
  22. package/dist/information-scope/index.cjs.map +1 -0
  23. package/dist/information-scope/index.d.cts +442 -0
  24. package/dist/information-scope/index.d.ts +442 -0
  25. package/dist/information-scope/index.js +484 -0
  26. package/dist/information-scope/index.js.map +1 -0
  27. package/dist/models/index.d.cts +2 -2
  28. package/dist/models/index.d.ts +2 -2
  29. package/dist/schemas/index.d.cts +25 -25
  30. package/dist/schemas/index.d.ts +25 -25
  31. package/dist/services/index.cjs +495 -2
  32. package/dist/services/index.cjs.map +1 -1
  33. package/dist/services/index.d.cts +1 -0
  34. package/dist/services/index.d.ts +1 -0
  35. package/dist/services/index.js +483 -1
  36. package/dist/services/index.js.map +1 -1
  37. package/package.json +32 -26
  38. package/src/__tests__/__snapshots__/cvc-sot.snap +3 -3
  39. package/src/__tests__/core-information-scope-invariant.test.ts +835 -456
  40. package/src/__tests__/cvc-sot-snapshot.test.ts +17 -17
  41. package/src/__tests__/cvc-structural.test.ts +2 -2
  42. package/src/__tests__/location-type-routing-invariant.test.ts +25 -8
  43. package/src/cvcs/coreInformationScope.v2.1.0.json +5498 -0
  44. package/src/cvcs/index.ts +2 -2
  45. package/src/cvcs/roiScope.v1.4.0.json +360 -0
  46. package/src/generated/cvc-enums.ts +77 -4
  47. package/src/services/__tests__/fixtures/infoscope-v4/information_scope_v3_placements.projection.csv +12 -0
  48. package/src/services/__tests__/fixtures/infoscope-v4/information_scope_v4.migrations.csv +106 -0
  49. package/src/services/__tests__/fixtures/infoscope-v4/information_scope_v4.rows.csv +117 -0
  50. package/src/services/__tests__/fixtures/infoscope-v4/loadInfoscopeV4Fixtures.ts +187 -0
  51. package/src/services/__tests__/informationScopeResolver.test.ts +1278 -0
  52. package/src/services/index.ts +10 -3
  53. package/src/services/informationScope.ts +10 -0
  54. package/src/services/informationScopeResolver.ts +879 -0
  55. package/src/services/informationScopeSot.ts +203 -0
  56. package/src/cvcs/coreInformationScope.v1.1.0.json +0 -1290
  57. package/src/cvcs/roiScope.v1.2.0.json +0 -340
  58. package/dist/{cvcEntry-BCj1OWqL.d.cts → cvcEntry-0BIB9sen.d.cts} +8 -8
  59. package/dist/{cvcEntry-BCj1OWqL.d.ts → cvcEntry-0BIB9sen.d.ts} +8 -8
@@ -0,0 +1,879 @@
1
+ /**
2
+ * @htilabs/platform-common-models — Information scope resolver (CVC-236 v4)
3
+ *
4
+ * The ONE implementation of how a stored information-scope selection reads
5
+ * against the v4 tree, so Thread and PAVE (preview and send, picker and door)
6
+ * cannot disagree. Pure and dependency-free: no imports, no I/O, never
7
+ * mutates its inputs. Browser-safe entry: `@htilabs/platform-common-models/information-scope`.
8
+ *
9
+ * Spec (canon, read-only): htilabstech/prototype
10
+ * docs/share-roi/INFOSCOPE_V4_DEV_HANDOFF_2026-10-09.md
11
+ * @ 7ca7e586ae487c608da657d426598a65d5b06111 (merge of the SIGNED-GRAIN
12
+ * content commit e86dd89cdba5cbb39ccfc7fb35aff8cbf0774790, which amends
13
+ * § 3 only and re-labels the migrations CSV; § 2, § 7, § 8 and the rows CSV
14
+ * are unchanged from 6dab8a95 / 00179edc)
15
+ * - § 2 rules 1–7 ("the resolver contract — build exactly this, nothing
16
+ * cleverer") — every behaviour below cites its rule;
17
+ * - § 3 the migration rules (identity · row · category · subtract ·
18
+ * retired before v4) and `scopeVersion`; a signed release keeps its list
19
+ * as signed and its current reading is DERIVED at read time; a retired
20
+ * code "stays recognisable in stored data forever";
21
+ * - § 7 row 6 a branch-grain pick is expanded to the ceiling's grain
22
+ * before clamping; a sender can never widen;
23
+ * - § 8 the enums.
24
+ * Release grain (Crysta, 2026-10-09; SOT v2.1.0 `migrations.ruling`, quoted
25
+ * verbatim there): "a SIGNED RELEASE keeps the grain it was signed at ...
26
+ * Policies and presets (agency-authored, not consent) take the merged
27
+ * successor with a dated version row." Canon carries it since SIGNED-GRAIN
28
+ * (prototype e86dd89c: `signed_release_grain: keep` on the nine `rows` merge
29
+ * folds; handoff § 3 amended). So `readSelection` takes WHOSE list it is
30
+ * (`subject`): a release or a share (frozen at send, § 3) naming a code on a
31
+ * `releaseReading: "retain"` line at scopeVersion 3 is NOT mapped — the code
32
+ * comes back under `retained` with its v3 field membership, for the builder
33
+ * to deliver read-only; a policy takes the successor (`widened`) and the
34
+ * reading says a dated version row is due. The widening identity line canon
35
+ * leaves unmarked (`immigration_status`, `releaseReading: "successor"`) reads
36
+ * as itself for every subject.
37
+ * Reference implementation of rule-1 kind-row resolution:
38
+ * tools/infoscope/phase4_stress_test.py `resolve_home` (same SHA).
39
+ *
40
+ * WHAT A SELECTION STORES. `information_scope: string[]` holds canon's scope
41
+ * codes as canon spells them — `names`, `identifying.other`,
42
+ * `offenders.risk` (handoff § 8: "lowercase snake, or `<kind>.<row>`") —
43
+ * NOT the package's SOT keys (`offenders__risk`) and NOT seven-segment wire
44
+ * codes (`236-016-001-002-…`). `ScopeRow.scopeCode` / `parentScopeCode` are
45
+ * in that space; `scopeRowsFromSot` maps the SOT into it.
46
+ *
47
+ * ALWAYS COVERED. `system_info` and its ancestor `system` ("System metadata —
48
+ * always included, never a choice", handoff § 1; the field placements home
49
+ * the system fields on `system`) are covered by every selection.
50
+ *
51
+ * Two kinds of call:
52
+ * - READS (`isCovered`, `isIncludedOnShare`, `shareVerdict`,
53
+ * `isVisibleAtLevel`, `readSelection`, `readRestriction`,
54
+ * `expandBranchPickToGrain`, `clampToCeiling`) are total: they never
55
+ * throw on stored data. An unknown code, a null list or an unsupported
56
+ * `scopeVersion` (absent, 2, or anything but 3 / 4) includes nothing
57
+ * (fail closed). `readSelection`'s `subject` is the caller's, not stored
58
+ * data: a missing or unknown one throws (no silent default).
59
+ * - PICKER WRITES (`selectAll`, `deselectChild`, `expandSelectAll`), the
60
+ * build-time `rowForSubject`, and the constructor throw on programming
61
+ * errors (an unknown or non-selectable code, a malformed tree).
62
+ */
63
+
64
+ // ─── Constants ───────────────────────────────────────────────────────────────
65
+
66
+ /** The tree version this resolver reads to (handoff § 3: "today 3, after this round 4"). */
67
+ export const INFORMATION_SCOPE_VERSION = 4 as const;
68
+
69
+ /**
70
+ * The `scopeVersion` stamps a stored list may carry and still be read: 3
71
+ * (through the v3 → v4 table) and 4. A 2 list, and an UNSTAMPED list (which
72
+ * is v2-era), must go through canon's conjunctive v2 → v3 table first (SOT
73
+ * v2.1.0 `migrations.readAt` / `migrations.unstamped`: the `retired before
74
+ * v4` lines name "the flattened v3 reading, not an unconditional one"); this
75
+ * package ships no v2 → v3 table, so those lists are unsupported and include
76
+ * nothing (fail closed). None was ever persisted (`migrations.unstamped`).
77
+ */
78
+ export const INFORMATION_SCOPE_READABLE_VERSIONS: readonly number[] = Object.freeze([3, 4]);
79
+
80
+ /** Required on every stored selection and always included (handoff § 2 rule 1; § 6). */
81
+ export const INFORMATION_SCOPE_SYSTEM_INFO = "system_info" as const;
82
+
83
+ // ─── Row and migration input shapes ─────────────────────────────────────────
84
+
85
+ /** A kind of other named person (handoff § 1; § 8 `kind_branch`). */
86
+ export type ScopePersonKind = "offenders" | "family" | "others";
87
+
88
+ /** Whose record a record is: the client, or another named person's kind (rule 1). */
89
+ export type ScopeSubjectKind = "client" | ScopePersonKind;
90
+
91
+ /** `kind_branch` (§ 8); `null` on System and Notes rows (blank in the CSV). */
92
+ export type ScopeKindBranch = ScopeSubjectKind | "leads" | null;
93
+
94
+ /**
95
+ * `row_type` (§ 8). The tree also carries `branch` (`primary_client`,
96
+ * `other_named_persons`) and the LEADS spelling `sub-category`, which § 8's
97
+ * list omits; both are accepted as written.
98
+ */
99
+ export type ScopeRowType =
100
+ | "branch"
101
+ | "category"
102
+ | "subcategory"
103
+ | "sub-category"
104
+ | "person_type"
105
+ | "category_rest"
106
+ | "instrument row";
107
+
108
+ /** `status` (§ 8). */
109
+ export type ScopeRowStatus = "as_today" | "new" | "retired";
110
+
111
+ /** `special_data_type` (§ 8, plus `evidence`, which the tree carries on `case_attachments`). */
112
+ export type ScopeSpecialDataType =
113
+ | "none"
114
+ | "survivor_confidential"
115
+ | "criminal_intelligence"
116
+ | "evidence";
117
+
118
+ /** The three app-relevance columns (§ 4). */
119
+ export type ScopeApp = "pave" | "thread" | "leads";
120
+ export type ScopeApps = Readonly<Record<ScopeApp, boolean>>;
121
+
122
+ /**
123
+ * One tree row, in the selection-code space (see header). Bind the SOT with
124
+ * `scopeRowsFromSot`. Extra fields on a caller's row type are carried through
125
+ * (`row(code)` returns the caller's row).
126
+ */
127
+ export interface ScopeRow {
128
+ /** The code a selection stores (canon's spelling: `offenders.risk`). */
129
+ scopeCode: string;
130
+ parentScopeCode: string | null;
131
+ rowType: ScopeRowType;
132
+ kindBranch: ScopeKindBranch;
133
+ /** On a per-kind row (`offenders.risk`): the client row it copies (`risk`). Required there. */
134
+ kindRow?: string;
135
+ /** App relevance (§ 4). Informational: no resolver decision reads it. */
136
+ apps: ScopeApps;
137
+ selectable: boolean;
138
+ /** `shareable_default = on` (rule 4: `false` = off by default). */
139
+ shareableDefault: boolean;
140
+ platformFloor: boolean;
141
+ levelFloor: 1 | 3;
142
+ specialDataType: ScopeSpecialDataType;
143
+ /** A `retired` row is never covered, offered or written. */
144
+ status: ScopeRowStatus;
145
+ replacesV3?: readonly string[];
146
+ }
147
+
148
+ /** The four migration rules of handoff § 3, plus the pre-v4 retirement reading. */
149
+ export type ScopeMigrationRule = "identity" | "row" | "category" | "subtract" | "retired before v4";
150
+
151
+ /** One from-to line (selection-code space); `to` is empty for "(nothing)". */
152
+ export interface ScopeMigration {
153
+ from: string;
154
+ to: readonly string[];
155
+ rule: ScopeMigrationRule;
156
+ note?: string;
157
+ /** The line reads WIDER than v3 did (SOT `widens: true`). A policy takes it; see `releaseReading`. */
158
+ widens?: boolean;
159
+ /**
160
+ * On every `widens` line (SOT; ruling 2026-10-09, canon SIGNED-GRAIN).
161
+ * `retain` — canon's nine merge folds (`signed_release_grain: keep`): a
162
+ * release or share at scopeVersion 3 keeps the code at its v3 grain instead
163
+ * of reading `to`; requires exactly one `to` and `v3Fields` / `v3Domains`.
164
+ * `successor` — a widening identity line canon leaves unmarked
165
+ * (`immigration_status`): every subject reads `to` (`releaseReadingNote`).
166
+ * Absent: `to` is every subject's reading.
167
+ */
168
+ releaseReading?: "retain" | "successor";
169
+ /** Why a widening line is read as its successor by a release too. */
170
+ releaseReadingNote?: string;
171
+ /** `successor` (SOT, on every `widens` line): a policy or preset reads `to`. */
172
+ policyReading?: "successor";
173
+ /** A `retired before v4` line (ruling 2): a stated reading only a v2-era list can need. */
174
+ informational?: boolean;
175
+ /**
176
+ * On a `retain` line: the fields whose v3 home was the `from` unit (canon
177
+ * field placements `home_unit_today`) — what a retained release delivers,
178
+ * read-only. Field ids (`capture.hiv_status`), not scope codes. Empty = the
179
+ * unit homed no field, so a release retaining it delivers nothing.
180
+ */
181
+ v3Fields?: readonly string[];
182
+ /**
183
+ * On a `retain` line: the distinct `assertion_domain` of `v3Fields`. CATEGORY
184
+ * grain in v3 (`access_accommodations`, `immigration_legal_status` each span
185
+ * every unit of their category): the field family, NOT the unit's membership.
186
+ * Deliver by `v3Fields`.
187
+ */
188
+ v3Domains?: readonly string[];
189
+ /** On a `retain` line: why the membership is what it is (an empty unit; a derivation under veto). */
190
+ v3FieldsNote?: string;
191
+ }
192
+
193
+ // ─── Output shapes ───────────────────────────────────────────────────────────
194
+
195
+ /** How one stored code was read. `unknown` = no row, no table line: it includes nothing. */
196
+ export type ScopeReadingRule = ScopeMigrationRule | "unknown";
197
+
198
+ export interface ScopeCodeReading {
199
+ readonly from: string;
200
+ readonly rule: ScopeReadingRule;
201
+ /** The v4 codes it reads as; empty for a retained code (see `ScopeReading.retained`). */
202
+ readonly reads: readonly string[];
203
+ /** It read through a line flagged as wider than v3 (never true for a retained code). */
204
+ readonly widens: boolean;
205
+ /** A release or share kept it at its v3 grain (`releaseReading: "retain"`). */
206
+ readonly retained: boolean;
207
+ }
208
+
209
+ /**
210
+ * Whose stored list is being read (handoff § 3; ruling 2026-10-09):
211
+ * - `release` — a signed ROI / release;
212
+ * - `share` — a share, which freezes the list it was sent with AND the
213
+ * `scopeVersion` of the release it was composed under (handoff § 3: "A
214
+ * share freezes the list it was sent with ... and its version"), so it
215
+ * reads like a release: a share frozen under a v3 release is a stamp-3
216
+ * list and retains;
217
+ * - `policy` — everything agency-authored: a policy, a PRESET or a PARTNER
218
+ * RULE (canon SIGNED-GRAIN: "policies / presets / partner rules take the
219
+ * successor whole"), migrated with a dated version row.
220
+ */
221
+ export type ScopeReadingSubject = "release" | "share" | "policy";
222
+
223
+ export interface ScopeReadOptions {
224
+ subject: ScopeReadingSubject;
225
+ }
226
+
227
+ /**
228
+ * A stored code a release or share keeps at the grain it was signed at
229
+ * (ruling 2026-10-09): not mapped to `successor`, not in `informationScope`.
230
+ * The builder delivers exactly `v3Fields`, read-only — never offered, never
231
+ * widened, never narrowed — until the survivor re-signs on v4.
232
+ *
233
+ * Only a STAMP-3 list retains. A v4-stamped release or share can only hold
234
+ * live v4 codes (the picker never offers a tombstone); if one nonetheless
235
+ * names a code on a `retain` line, that code is recognised as retired and
236
+ * includes NOTHING (fail closed) — never its successor, and not retained.
237
+ */
238
+ export interface ScopeRetainedReading {
239
+ readonly code: string;
240
+ /** The fields the code delivered in v3 (field ids). Empty: it delivers nothing (`note`). */
241
+ readonly v3Fields: readonly string[];
242
+ /** Their assertion domains — CATEGORY grain in v3, the field family; deliver by `v3Fields`. */
243
+ readonly v3Domains: readonly string[];
244
+ /** What a policy reads it as, and what a v4 re-signature would name. */
245
+ readonly successor: string;
246
+ /** Present when the membership needs explaining (an empty unit; a derivation under veto). */
247
+ readonly note?: string;
248
+ }
249
+
250
+ /**
251
+ * The current (v4) reading of a stored list. `stored` and `storedVersion` are
252
+ * the list as signed, copied, never rewritten (§ 3: "a signed release keeps
253
+ * its list as signed, at the version signed; its current reading is derived
254
+ * through the table at read time").
255
+ */
256
+ export interface ScopeReading {
257
+ /** The stamp as stored; `null` when it was absent or not a number. */
258
+ readonly storedVersion: number | null;
259
+ readonly stored: readonly string[];
260
+ readonly version: typeof INFORMATION_SCOPE_VERSION;
261
+ /** The stamp is not in `INFORMATION_SCOPE_READABLE_VERSIONS`: every code reads `unknown`. */
262
+ readonly unsupportedVersion: boolean;
263
+ /**
264
+ * The derived v4 list: unique, in tree order. A selection reading always
265
+ * contains `system_info`; a restriction reading contains only what it restricts.
266
+ */
267
+ readonly informationScope: readonly string[];
268
+ /** One entry per distinct stored code, in stored order. */
269
+ readonly codes: readonly ScopeCodeReading[];
270
+ /** Stored codes that are retired (read by `row`, `subtract` or `retired before v4`). */
271
+ readonly retired: readonly string[];
272
+ /** Stored codes with no live row and no table line; they include nothing. */
273
+ readonly unknown: readonly string[];
274
+ /** Stored codes whose reading is wider than v3's (`widens`): surface, never hide. */
275
+ readonly widened: readonly string[];
276
+ /** `readSelection`'s subject; `null` on a restriction reading. */
277
+ readonly subject: ScopeReadingSubject | null;
278
+ /** Release / share codes kept at v3 grain, in stored order (always empty for a policy). */
279
+ readonly retained: readonly ScopeRetainedReading[];
280
+ /**
281
+ * A policy read across versions (stamp 3) — `readSelection` with subject
282
+ * `policy`, and every `readRestriction` (a restriction is a policy's):
283
+ * handoff § 3 — "a policy is migrated with a new version row on the record,
284
+ * dated" — so the app writes that dated row before acting on
285
+ * `informationScope`. `false` otherwise.
286
+ */
287
+ readonly versionRowRequired: boolean;
288
+ /** Says why, when `versionRowRequired`; otherwise `null`. */
289
+ readonly note: string | null;
290
+ }
291
+
292
+ export type ScopeShareVerdict =
293
+ | { readonly included: true; readonly reason: "included" }
294
+ | { readonly included: false; readonly reason: "not_covered" | "platform_floor" | "unknown_code" }
295
+ | {
296
+ readonly included: false;
297
+ readonly reason: "off_by_default";
298
+ /** The off-by-default rows in the chain the account has not enabled. */
299
+ readonly notEnabled: readonly string[];
300
+ };
301
+
302
+ export type ScopeShareReason = ScopeShareVerdict["reason"];
303
+
304
+ export interface ScopeShareOptions {
305
+ /** The off-by-default rows the account's policy has enabled for sharing (rule 4). */
306
+ enabledOffByDefault?: ReadonlySet<string> | readonly string[];
307
+ }
308
+
309
+ export interface CreateInformationScopeResolverInput<R extends ScopeRow> {
310
+ rows: readonly R[];
311
+ migrations?: readonly ScopeMigration[];
312
+ }
313
+
314
+ /** A stored list as it may arrive from storage (reads are total). */
315
+ export type StoredScopeList = readonly string[] | null | undefined;
316
+
317
+ export interface InformationScopeResolver<R extends ScopeRow = ScopeRow> {
318
+ readonly version: typeof INFORMATION_SCOPE_VERSION;
319
+ /** Every row in input order. */
320
+ readonly rows: readonly R[];
321
+ row(code: string): R | undefined;
322
+ /** The live (non-retired) children of `code`, in input order (a copy). */
323
+ childrenOf(code: string): string[];
324
+ /** `code` first, then its parent, up to the root (a copy). Empty for an unknown code. */
325
+ ancestorsOf(code: string): string[];
326
+
327
+ /** Rules 2 + 3. */
328
+ isCovered(selection: StoredScopeList, code: string): boolean;
329
+ /** Rules 2–5. */
330
+ isIncludedOnShare(selection: StoredScopeList, code: string, options?: ScopeShareOptions): boolean;
331
+ /** `isIncludedOnShare` with the reason, for "held back and counted". */
332
+ shareVerdict(
333
+ selection: StoredScopeList,
334
+ code: string,
335
+ options?: ScopeShareOptions,
336
+ ): ScopeShareVerdict;
337
+ /** Rule 7 (the viewing side). */
338
+ isVisibleAtLevel(level: number, code: string): boolean;
339
+
340
+ /** Rules 3 + 6: the codes a picker writes when it expands `code` (its live children, rest row included). */
341
+ expandSelectAll(code: string): string[];
342
+ /** Rule 6: select-all at `code` (the code itself is stored; its now-redundant descendants drop). */
343
+ selectAll(selection: readonly string[], code: string): string[];
344
+ /** Rules 3 + 6: de-select one child; every selected ancestor is replaced by its other children. */
345
+ deselectChild(selection: readonly string[], childCode: string): string[];
346
+
347
+ /**
348
+ * § 3: the current v4 reading of a stored selection, for its `subject`
349
+ * (required; throws when missing or unknown). A release or share keeps a
350
+ * `retain` code at its v3 grain (`retained`); a policy reads the successor.
351
+ */
352
+ readSelection(
353
+ list: StoredScopeList,
354
+ scopeVersion: number | null | undefined,
355
+ options: ScopeReadOptions,
356
+ ): ScopeReading;
357
+ /**
358
+ * § 3 `subtract`: the current v4 reading of a stored RESTRICTION. A
359
+ * restriction is a policy's, so a stamp-3 one sets `versionRowRequired`.
360
+ */
361
+ readRestriction(list: StoredScopeList, scopeVersion: number | null | undefined): ScopeReading;
362
+
363
+ /** Rule 1: the row a record is included under, given its field's home row and its subject. */
364
+ rowForSubject(homeRow: string, kind: ScopeSubjectKind): string;
365
+
366
+ /** § 7 row 6: expand every pick that sits above the ceiling's grain into its children. */
367
+ expandBranchPickToGrain(selection: StoredScopeList, ceiling: StoredScopeList): string[];
368
+ /** § 7 row 6: expand, then keep only what the ceiling covers. A sender can never widen. */
369
+ clampToCeiling(selection: StoredScopeList, ceiling: StoredScopeList): string[];
370
+ }
371
+
372
+ // ─── Pure row guards ─────────────────────────────────────────────────────────
373
+
374
+ /** A row a picker offers as a choice (§ 8 `selectable`; never a retired row). */
375
+ export const isSelectableScopeRow = (row: ScopeRow | undefined): boolean =>
376
+ row !== undefined && row.selectable && row.status !== "retired";
377
+
378
+ /** The `category_rest` row (rule 3): never offered, covered with its category. */
379
+ export const isScopeRestRow = (row: ScopeRow | undefined): boolean =>
380
+ row !== undefined && row.rowType === "category_rest";
381
+
382
+ /** One of the 28 `summary_<x>` / `full_<x>` rows (§ 8 `instrument row`). */
383
+ export const isScopeInstrumentRow = (row: ScopeRow | undefined): boolean =>
384
+ row !== undefined && row.rowType === "instrument row";
385
+
386
+ // ─── Person kind (rule 1, Phase 3 D5) ───────────────────────────────────────
387
+
388
+ /**
389
+ * Which kind of other named person someone is (handoff § 2 rule 1; § 8; Phase
390
+ * 3 D5): "This person caused harm" wins; "Eligible family member" (asserted
391
+ * by the advocate, never derived from the relationship) otherwise; neither →
392
+ * `others`. A person with both switches is listed under `offenders`; the
393
+ * caller keeps the family-member VAWA handling, which rides `efmAsserted` on
394
+ * the person, not the kind.
395
+ */
396
+ export function kindForPerson(person: {
397
+ causedHarm: boolean;
398
+ efmAsserted: boolean;
399
+ }): ScopePersonKind {
400
+ if (person.causedHarm) return "offenders";
401
+ if (person.efmAsserted) return "family";
402
+ return "others";
403
+ }
404
+
405
+ // ─── The resolver ────────────────────────────────────────────────────────────
406
+
407
+ const PERSON_KINDS: ReadonlySet<string> = new Set<ScopePersonKind>(["offenders", "family", "others"]);
408
+ const SPECIAL_DATA_TYPES: ReadonlySet<string> = new Set<ScopeSpecialDataType>([
409
+ "none",
410
+ "survivor_confidential",
411
+ "criminal_intelligence",
412
+ "evidence",
413
+ ]);
414
+ const MIGRATION_RULES: ReadonlySet<string> = new Set<ScopeMigrationRule>([
415
+ "identity",
416
+ "row",
417
+ "category",
418
+ "subtract",
419
+ "retired before v4",
420
+ ]);
421
+ const RETIRED_RULES: ReadonlySet<ScopeReadingRule> = new Set<ScopeReadingRule>([
422
+ "row",
423
+ "subtract",
424
+ "retired before v4",
425
+ ]);
426
+
427
+ /** Reading precedence per code (§ 3): a stated category line, then identity, row, pre-v4. */
428
+ const SELECTION_PRECEDENCE: readonly ScopeMigrationRule[] = [
429
+ "category",
430
+ "identity",
431
+ "row",
432
+ "retired before v4",
433
+ ];
434
+ const RESTRICTION_PRECEDENCE: readonly ScopeMigrationRule[] = [
435
+ "subtract",
436
+ ...SELECTION_PRECEDENCE,
437
+ ];
438
+
439
+ const READING_SUBJECTS: ReadonlySet<string> = new Set<ScopeReadingSubject>([
440
+ "release",
441
+ "share",
442
+ "policy",
443
+ ]);
444
+
445
+ /** The `note` on a policy reading across versions (handoff § 3). */
446
+ export const INFORMATION_SCOPE_POLICY_VERSION_ROW_NOTE =
447
+ "Handoff § 3: a policy is migrated with a new version row on the record, dated, so a Member " +
448
+ "Admin sees a change in history, not a silent rewrite. Write that row before acting on this " +
449
+ "reading; the stored list itself is never rewritten.";
450
+
451
+ const asList = (list: StoredScopeList): readonly string[] => (Array.isArray(list) ? list : []);
452
+
453
+ /**
454
+ * Bind the resolver to one tree (and its migration table). Throws on a
455
+ * malformed tree: a duplicate code, a parent that is not a row, a cycle, no
456
+ * `system_info` row, a live row whose `specialDataType` is missing or not in
457
+ * § 8 (rule 1 routes on it — absence fails closed by refusing to bind), a
458
+ * per-kind row without a `kindRow` that names a row, an unknown migration
459
+ * rule, a migration successor that is not a live row, two different
460
+ * readings for the same code and rule, or a `releaseReading: "retain"` line
461
+ * without exactly one successor and its `v3Fields` / `v3Domains`.
462
+ */
463
+ export function createInformationScopeResolver<R extends ScopeRow>(
464
+ input: CreateInformationScopeResolverInput<R>,
465
+ ): InformationScopeResolver<R> {
466
+ const rows = Object.freeze([...input.rows]);
467
+ const byCode = new Map<string, R>();
468
+ const order = new Map<string, number>();
469
+ for (const r of rows) {
470
+ if (byCode.has(r.scopeCode)) {
471
+ throw new Error(`information scope: duplicate code "${r.scopeCode}"`);
472
+ }
473
+ byCode.set(r.scopeCode, r);
474
+ order.set(r.scopeCode, order.size);
475
+ }
476
+ const isLive = (code: string): boolean => {
477
+ const r = byCode.get(code);
478
+ return r !== undefined && r.status !== "retired";
479
+ };
480
+ const children = new Map<string, string[]>();
481
+ for (const r of rows) {
482
+ if (r.status !== "retired" && !SPECIAL_DATA_TYPES.has(r.specialDataType)) {
483
+ throw new Error(
484
+ `information scope: "${r.scopeCode}" has specialDataType ${JSON.stringify(r.specialDataType)}`,
485
+ );
486
+ }
487
+ if (r.parentScopeCode === null || r.parentScopeCode === "") continue;
488
+ if (!byCode.has(r.parentScopeCode)) {
489
+ throw new Error(
490
+ `information scope: "${r.scopeCode}" names unknown parent "${r.parentScopeCode}"`,
491
+ );
492
+ }
493
+ if (r.status === "retired") continue;
494
+ const list = children.get(r.parentScopeCode) ?? [];
495
+ list.push(r.scopeCode);
496
+ children.set(r.parentScopeCode, list);
497
+ }
498
+ const ancestorCache = new Map<string, readonly string[]>();
499
+ const ancestors = (code: string): readonly string[] => {
500
+ const hit = ancestorCache.get(code);
501
+ if (hit) return hit;
502
+ const out: string[] = [];
503
+ let cur: string | null = code;
504
+ while (cur !== null && cur !== "") {
505
+ const r = byCode.get(cur);
506
+ if (!r) break;
507
+ if (out.includes(cur)) throw new Error(`information scope: cycle at "${cur}"`);
508
+ out.push(cur);
509
+ cur = r.parentScopeCode;
510
+ }
511
+ ancestorCache.set(code, out);
512
+ return out;
513
+ };
514
+ for (const r of rows) ancestors(r.scopeCode);
515
+ if (!isLive(INFORMATION_SCOPE_SYSTEM_INFO)) {
516
+ throw new Error(`information scope: the tree has no "${INFORMATION_SCOPE_SYSTEM_INFO}" row`);
517
+ }
518
+ /** `system_info` and its ancestors (`system`): covered by every selection. */
519
+ const alwaysCovered: ReadonlySet<string> = new Set(ancestors(INFORMATION_SCOPE_SYSTEM_INFO));
520
+
521
+ const kids = (code: string): readonly string[] => children.get(code) ?? [];
522
+ const descendantsOf = (code: string): string[] => {
523
+ const out: string[] = [];
524
+ const stack = [...kids(code)];
525
+ while (stack.length > 0) {
526
+ const c = stack.pop() as string;
527
+ out.push(c);
528
+ stack.push(...kids(c));
529
+ }
530
+ return out;
531
+ };
532
+ const restRowOf = (code: string): string | undefined =>
533
+ kids(code).find((c) => isScopeRestRow(byCode.get(c)));
534
+
535
+ // Rule 1 kind rows, read off the tree: each kind's `person_type` root, and
536
+ // each per-kind row by (kind, the client row it copies).
537
+ const kindRoot = new Map<string, string>();
538
+ const perKindRow = new Map<string, string>();
539
+ for (const r of rows) {
540
+ if (r.status === "retired" || r.kindBranch === null || !PERSON_KINDS.has(r.kindBranch)) continue;
541
+ if (r.rowType === "person_type") {
542
+ kindRoot.set(r.kindBranch, r.scopeCode);
543
+ continue;
544
+ }
545
+ if (r.kindRow === undefined || !isLive(r.kindRow)) {
546
+ throw new Error(
547
+ `information scope: per-kind row "${r.scopeCode}" has no live kindRow (${String(r.kindRow)})`,
548
+ );
549
+ }
550
+ perKindRow.set(`${r.kindBranch}\u0000${r.kindRow}`, r.scopeCode);
551
+ }
552
+
553
+ // Migration table, indexed by code then rule.
554
+ const migrations = new Map<string, Map<ScopeMigrationRule, ScopeMigration>>();
555
+ for (const m of input.migrations ?? []) {
556
+ if (!MIGRATION_RULES.has(m.rule)) {
557
+ throw new Error(`information scope: unknown migration rule "${m.rule}" on "${m.from}"`);
558
+ }
559
+ for (const to of m.to) {
560
+ if (!isLive(to)) {
561
+ throw new Error(
562
+ `information scope: migration "${m.from}" (${m.rule}) reads as "${to}", not a live row`,
563
+ );
564
+ }
565
+ }
566
+ if (
567
+ m.releaseReading !== undefined &&
568
+ m.releaseReading !== "retain" &&
569
+ m.releaseReading !== "successor"
570
+ ) {
571
+ throw new Error(`information scope: "${m.from}" has releaseReading "${String(m.releaseReading)}"`);
572
+ }
573
+ if (m.policyReading !== undefined && m.policyReading !== "successor") {
574
+ throw new Error(`information scope: "${m.from}" has policyReading "${String(m.policyReading)}"`);
575
+ }
576
+ if (
577
+ m.releaseReading === "retain" &&
578
+ (m.to.length !== 1 || !Array.isArray(m.v3Fields) || !Array.isArray(m.v3Domains))
579
+ ) {
580
+ throw new Error(
581
+ `information scope: retained line "${m.from}" needs one successor and its v3Fields / v3Domains`,
582
+ );
583
+ }
584
+ const perCode = migrations.get(m.from) ?? new Map<ScopeMigrationRule, ScopeMigration>();
585
+ const prior = perCode.get(m.rule);
586
+ if (prior && prior.to.join(" ") !== m.to.join(" ")) {
587
+ throw new Error(`information scope: two "${m.rule}" readings for "${m.from}"`);
588
+ }
589
+ // The resolver reads only `to`, `widens` and a `retain` line's v3 membership;
590
+ // the other line fields stay on the caller's `ScopeMigration` / the SOT.
591
+ const retain = m.releaseReading === "retain" ? m : prior?.releaseReading === "retain" ? prior : null;
592
+ perCode.set(m.rule, {
593
+ from: m.from,
594
+ rule: m.rule,
595
+ to: Object.freeze([...m.to]),
596
+ widens: m.widens === true || prior?.widens === true,
597
+ ...(retain === null
598
+ ? {}
599
+ : {
600
+ releaseReading: "retain" as const,
601
+ v3Fields: Object.freeze([...(retain.v3Fields ?? [])]),
602
+ v3Domains: Object.freeze([...(retain.v3Domains ?? [])]),
603
+ ...(retain.v3FieldsNote === undefined ? {} : { v3FieldsNote: retain.v3FieldsNote }),
604
+ }),
605
+ });
606
+ migrations.set(m.from, perCode);
607
+ }
608
+
609
+ /**
610
+ * Unique, tree order for known codes, unknown codes kept after in first-seen
611
+ * order; a selection always carries `system_info` (a restriction does not).
612
+ */
613
+ const normalize = (codes: Iterable<string>, withSystemInfo = true): string[] => {
614
+ const seen = new Set<string>();
615
+ const known: string[] = [];
616
+ const unknown: string[] = [];
617
+ const all = withSystemInfo ? [INFORMATION_SCOPE_SYSTEM_INFO, ...codes] : [...codes];
618
+ for (const c of all) {
619
+ if (seen.has(c)) continue;
620
+ seen.add(c);
621
+ (byCode.has(c) ? known : unknown).push(c);
622
+ }
623
+ known.sort((a, b) => (order.get(a) as number) - (order.get(b) as number));
624
+ return [...known, ...unknown];
625
+ };
626
+
627
+ const requirePickable = (code: string, op: string): void => {
628
+ if (!byCode.has(code)) throw new RangeError(`information scope ${op}: unknown code "${code}"`);
629
+ if (!isSelectableScopeRow(byCode.get(code))) {
630
+ throw new RangeError(`information scope ${op}: "${code}" is not selectable`);
631
+ }
632
+ };
633
+
634
+ // Rule 2 (self or any ancestor in the flat list) + rule 3 (a record homed on a
635
+ // category is covered when the category OR its rest row is). `system_info` and
636
+ // `system` are always covered (header).
637
+ const isCovered = (selection: StoredScopeList, code: string): boolean => {
638
+ if (!isLive(code)) return false;
639
+ if (alwaysCovered.has(code)) return true;
640
+ const sel = new Set(asList(selection));
641
+ if (ancestors(code).some((a) => sel.has(a))) return true;
642
+ const rest = restRowOf(code);
643
+ return rest !== undefined && sel.has(rest);
644
+ };
645
+
646
+ const shareVerdict = (
647
+ selection: StoredScopeList,
648
+ code: string,
649
+ options: ScopeShareOptions = {},
650
+ ): ScopeShareVerdict => {
651
+ if (!isLive(code)) return { included: false, reason: "unknown_code" };
652
+ if (!isCovered(selection, code)) return { included: false, reason: "not_covered" };
653
+ const chain = ancestors(code).map((c) => byCode.get(c) as R);
654
+ // Rule 5: the floor (or a floor ancestor) never leaves, whatever the list says.
655
+ if (chain.some((r) => r.platformFloor)) return { included: false, reason: "platform_floor" };
656
+ // Rule 4: every off-by-default row in the chain must be enabled by the account
657
+ // (the reference runner's `included`: enabling an ancestor does not enable an
658
+ // off-by-default child of it).
659
+ const enabled = new Set(options.enabledOffByDefault ?? []);
660
+ const notEnabled = chain
661
+ .filter((r) => !r.shareableDefault && !enabled.has(r.scopeCode))
662
+ .map((r) => r.scopeCode);
663
+ if (notEnabled.length > 0) return { included: false, reason: "off_by_default", notEnabled };
664
+ return { included: true, reason: "included" };
665
+ };
666
+
667
+ const expandSelectAll = (code: string): string[] => {
668
+ if (!byCode.has(code)) throw new RangeError(`information scope expand: unknown code "${code}"`);
669
+ return [...kids(code)];
670
+ };
671
+
672
+ const selectAll = (selection: readonly string[], code: string): string[] => {
673
+ requirePickable(code, "selectAll");
674
+ const drop = new Set(descendantsOf(code));
675
+ return normalize([...selection.filter((c) => !drop.has(c)), code]);
676
+ };
677
+
678
+ const deselectChild = (selection: readonly string[], childCode: string): string[] => {
679
+ requirePickable(childCode, "deselectChild");
680
+ if (alwaysCovered.has(childCode)) {
681
+ throw new RangeError(`information scope deselectChild: "${childCode}" is always included`);
682
+ }
683
+ const sel = new Set(selection);
684
+ const path = ancestors(childCode); // [child, parent, …, root]
685
+ let top = 0;
686
+ for (let i = 1; i < path.length; i += 1) if (sel.has(path[i])) top = i;
687
+ // Replace every selected ancestor by its OTHER children, all the way down the
688
+ // path (rule 3: the rest row is one of those children, so it is written too).
689
+ for (let i = 1; i <= top; i += 1) {
690
+ sel.delete(path[i]);
691
+ for (const c of kids(path[i])) if (c !== path[i - 1]) sel.add(c);
692
+ }
693
+ sel.delete(childCode);
694
+ for (const d of descendantsOf(childCode)) sel.delete(d);
695
+ return normalize(sel);
696
+ };
697
+
698
+ const readOne = (
699
+ from: string,
700
+ scopeVersion: number,
701
+ precedence: readonly ScopeMigrationRule[],
702
+ keepsGrain: boolean,
703
+ ): ScopeCodeReading => {
704
+ // A v4 list names live codes as written.
705
+ if (scopeVersion === INFORMATION_SCOPE_VERSION && isLive(from)) {
706
+ return { from, rule: "identity", reads: [from], widens: false, retained: false };
707
+ }
708
+ // Every other code reads through the table — including a retired code in a
709
+ // v4 list (§ 3 (c): it "stays recognisable in stored data forever").
710
+ const lines = migrations.get(from);
711
+ if (lines) {
712
+ for (const rule of precedence) {
713
+ if (scopeVersion === INFORMATION_SCOPE_VERSION && (rule === "identity" || rule === "category")) {
714
+ continue; // a v4 code that is not live has no identity reading
715
+ }
716
+ const line = lines.get(rule);
717
+ if (!line) continue;
718
+ // Ruling 2026-10-09: a release / share signed at v3 keeps the v3 grain.
719
+ if (keepsGrain && line.releaseReading === "retain") {
720
+ // A v4-stamped release / share cannot legitimately hold this tombstone
721
+ // (never offered): recognised as retired, includes nothing — never the
722
+ // successor (see `ScopeRetainedReading`).
723
+ return scopeVersion === 3
724
+ ? { from, rule, reads: [], widens: false, retained: true }
725
+ : { from, rule, reads: [], widens: false, retained: false };
726
+ }
727
+ return { from, rule, reads: [...line.to], widens: line.widens === true, retained: false };
728
+ }
729
+ }
730
+ return { from, rule: "unknown", reads: [], widens: false, retained: false };
731
+ };
732
+
733
+ const retainedOf = (c: ScopeCodeReading): ScopeRetainedReading => {
734
+ const line = migrations.get(c.from)?.get(c.rule as ScopeMigrationRule) as ScopeMigration;
735
+ return {
736
+ code: c.from,
737
+ v3Fields: [...(line.v3Fields ?? [])],
738
+ v3Domains: [...(line.v3Domains ?? [])],
739
+ successor: line.to[0],
740
+ ...(line.v3FieldsNote === undefined ? {} : { note: line.v3FieldsNote }),
741
+ };
742
+ };
743
+
744
+ const read = (
745
+ list: StoredScopeList,
746
+ scopeVersion: number | null | undefined,
747
+ precedence: readonly ScopeMigrationRule[],
748
+ subject: ScopeReadingSubject | null,
749
+ ): ScopeReading => {
750
+ const isRestriction = subject === null;
751
+ const keepsGrain = subject === "release" || subject === "share";
752
+ // A restriction is a policy's (handoff § 3 `subtract`: "a policy that forbids
753
+ // a code"), so it carries the same dated-version-row signal.
754
+ const isPolicyLike = subject === "policy" || isRestriction;
755
+ const stored = [...asList(list)];
756
+ const supported =
757
+ typeof scopeVersion === "number" && INFORMATION_SCOPE_READABLE_VERSIONS.includes(scopeVersion);
758
+ const versionRowRequired =
759
+ isPolicyLike && supported && scopeVersion !== INFORMATION_SCOPE_VERSION;
760
+ const codes: ScopeCodeReading[] = [];
761
+ const seen = new Set<string>();
762
+ for (const from of stored) {
763
+ if (seen.has(from)) continue;
764
+ seen.add(from);
765
+ codes.push(
766
+ supported
767
+ ? readOne(from, scopeVersion as number, precedence, keepsGrain)
768
+ : { from, rule: "unknown", reads: [], widens: false, retained: false },
769
+ );
770
+ }
771
+ return {
772
+ storedVersion: typeof scopeVersion === "number" ? scopeVersion : null,
773
+ stored,
774
+ version: INFORMATION_SCOPE_VERSION,
775
+ unsupportedVersion: !supported,
776
+ informationScope: normalize(
777
+ codes.flatMap((c) => c.reads),
778
+ !isRestriction,
779
+ ),
780
+ codes,
781
+ retired: codes.filter((c) => RETIRED_RULES.has(c.rule)).map((c) => c.from),
782
+ unknown: codes.filter((c) => c.rule === "unknown").map((c) => c.from),
783
+ widened: codes.filter((c) => c.widens).map((c) => c.from),
784
+ subject,
785
+ retained: codes.filter((c) => c.retained).map(retainedOf),
786
+ versionRowRequired,
787
+ note: versionRowRequired ? INFORMATION_SCOPE_POLICY_VERSION_ROW_NOTE : null,
788
+ };
789
+ };
790
+
791
+ const readSelection = (
792
+ list: StoredScopeList,
793
+ scopeVersion: number | null | undefined,
794
+ options: ScopeReadOptions,
795
+ ): ScopeReading => {
796
+ const subject = (options as Partial<ScopeReadOptions> | undefined)?.subject;
797
+ if (subject === undefined || !READING_SUBJECTS.has(subject)) {
798
+ throw new TypeError(
799
+ `information scope readSelection: options.subject must be "release", "share" or "policy" ` +
800
+ `(got ${JSON.stringify(subject)}) — there is no default`,
801
+ );
802
+ }
803
+ return read(list, scopeVersion, SELECTION_PRECEDENCE, subject);
804
+ };
805
+
806
+ const rowForSubject = (homeRow: string, kind: ScopeSubjectKind): string => {
807
+ const home = byCode.get(homeRow);
808
+ if (!home) throw new RangeError(`information scope rowForSubject: unknown home "${homeRow}"`);
809
+ if (kind === "client") return homeRow;
810
+ const chain = ancestors(homeRow);
811
+ // System, Notes and the LEADS groups sit under no `branch` row: the record stays home.
812
+ if (byCode.get(chain[chain.length - 1])?.rowType !== "branch") return homeRow;
813
+ // A criminal-intelligence row under the client (`derived_risk_signals`) stays home:
814
+ // every per-kind row is survivor_confidential, so re-branching would move CI
815
+ // content across a handling class. The reference keeps it home the same way
816
+ // (`resolve_home` / `leads_codes`).
817
+ if (home.specialDataType === "criminal_intelligence") return homeRow;
818
+ const root = kindRoot.get(kind);
819
+ if (!root) throw new RangeError(`information scope rowForSubject: the tree has no "${kind}" kind`);
820
+ if (chain.includes(root)) return homeRow;
821
+ // The deepest row the kind defines for the home (D15).
822
+ for (const anc of chain) {
823
+ const perKind = perKindRow.get(`${kind}\u0000${anc}`);
824
+ if (perKind !== undefined) return perKind;
825
+ }
826
+ return root;
827
+ };
828
+
829
+ const expandBranchPickToGrain = (
830
+ selection: StoredScopeList,
831
+ ceiling: StoredScopeList,
832
+ ): string[] => {
833
+ const ceil = asList(ceiling);
834
+ const ceilSet = new Set(ceil);
835
+ const isWithin = (c: string): boolean => ancestors(c).some((a) => ceilSet.has(a));
836
+ const isAbove = (c: string): boolean => ceil.some((k) => k !== c && ancestors(k).includes(c));
837
+ const out: string[] = [];
838
+ const stack = [...asList(selection)];
839
+ while (stack.length > 0) {
840
+ const c = stack.pop() as string;
841
+ if (isLive(c) && !isWithin(c) && isAbove(c)) stack.push(...kids(c));
842
+ else out.push(c);
843
+ }
844
+ return normalize(out);
845
+ };
846
+
847
+ const clampToCeiling = (selection: StoredScopeList, ceiling: StoredScopeList): string[] => {
848
+ const ceil = new Set(asList(ceiling));
849
+ return normalize(
850
+ expandBranchPickToGrain(selection, ceiling).filter(
851
+ (c) => isLive(c) && ancestors(c).some((a) => ceil.has(a)),
852
+ ),
853
+ );
854
+ };
855
+
856
+ return {
857
+ version: INFORMATION_SCOPE_VERSION,
858
+ rows,
859
+ row: (code) => byCode.get(code),
860
+ childrenOf: (code) => [...kids(code)],
861
+ ancestorsOf: (code) => [...ancestors(code)],
862
+ isCovered,
863
+ isIncludedOnShare: (selection, code, options) =>
864
+ shareVerdict(selection, code, options).included,
865
+ shareVerdict,
866
+ // Rule 7: the lowest internal viewing level that sees the row. Level 2
867
+ // (autocomplete) sees the level-1 stub (§ 5). Sharing ignores this.
868
+ isVisibleAtLevel: (level, code) =>
869
+ typeof level === "number" && isLive(code) && level >= (byCode.get(code) as R).levelFloor,
870
+ expandSelectAll,
871
+ selectAll,
872
+ deselectChild,
873
+ readSelection,
874
+ readRestriction: (list, scopeVersion) => read(list, scopeVersion, RESTRICTION_PRECEDENCE, null),
875
+ rowForSubject,
876
+ expandBranchPickToGrain,
877
+ clampToCeiling,
878
+ };
879
+ }